40 #define FILE_METHODS 1
43 {
"$Id: Connect.cc 25920 2012-10-24 19:18:51Z jimg $"
59 #include "fdiostream.h"
75 Connect::process_data(DataDDS &data, Response *rs)
77 DBG(cerr <<
"Entering Connect::process_data" << endl);
79 data.set_version(rs->get_version());
80 data.set_protocol(rs->get_protocol());
82 DBG(cerr <<
"Entering process_data: d_stream = " << rs << endl);
83 switch (rs->get_type()) {
86 if (!e.parse(rs->get_stream()))
87 throw InternalErr(__FILE__, __LINE__,
88 "Could not parse the Error object returned by the server!");
95 throw InternalErr(__FILE__, __LINE__,
"An error was reported by the remote httpd; this should have been processed by HTTPConnect..");
99 DDXParser ddx_parser(data.get_factory());
103 DBG(cerr <<
"MPM Boundary: " << boundary << endl);
109 ddx_parser.intern_stream(rs->get_stream(), &data, data_cid, boundary);
113 DBG(cerr <<
"Data CID: " << data_cid << endl);
118 "application/octet-stream",
dap4_data, data_cid);
122 XDRFileUnMarshaller um( rs->get_stream() ) ;
124 fpistream in ( rs->get_stream() );
125 XDRStreamUnMarshaller um( in ) ;
132 (*i)->deserialize(um, &data);
146 data.parse(rs->get_stream());
148 XDRFileUnMarshaller um( rs->get_stream() ) ;
150 fpistream in ( rs->get_stream() );
151 XDRStreamUnMarshaller um( in ) ;
159 (*i)->deserialize(um, &data);
175 Connect::process_data(DDS &data, Response *rs)
177 DBG(cerr <<
"Entering Connect::process_data" << endl);
180 data.set_version(rs->get_version());
181 data.set_protocol(rs->get_protocol());
184 data.set_dap_version(rs->get_protocol());
186 DBG(cerr <<
"Entering process_data: d_stream = " << rs << endl);
187 switch (rs->get_type()) {
190 if (!e.parse(rs->get_stream()))
191 throw InternalErr(__FILE__, __LINE__,
192 "Could not parse the Error object returned by the server!");
199 throw InternalErr(__FILE__, __LINE__,
"An error was reported by the remote httpd; this should have been processed by HTTPConnect..");
203 DDXParser ddx_parser(data.get_factory());
207 DBG(cerr <<
"MPM Boundary: " << boundary << endl);
213 ddx_parser.intern_stream(rs->get_stream(), &data, data_cid, boundary);
217 DBG(cerr <<
"Data CID: " << data_cid << endl);
222 "application/octet-stream",
dap4_data, data_cid);
226 XDRFileUnMarshaller um( rs->get_stream() ) ;
228 fpistream in ( rs->get_stream() );
229 XDRStreamUnMarshaller um( in ) ;
236 (*i)->deserialize(um, &data);
250 data.parse(rs->get_stream());
252 XDRFileUnMarshaller um( rs->get_stream() ) ;
254 fpistream in ( rs->get_stream() );
255 XDRStreamUnMarshaller um( in ) ;
263 (*i)->deserialize(um, &data);
298 Connect::parse_mime(Response *rs)
300 rs->set_version(
"dods/0.0");
301 rs->set_protocol(
"2.0");
303 FILE *data_source = rs->get_stream();
305 while (!mime.empty()) {
306 string header, value;
310 if (header ==
"content-description:") {
311 DBG(cout << header <<
": " << value << endl);
315 else if (header ==
"xdods-server:"
316 && rs->get_version() ==
"dods/0.0") {
317 DBG(cout << header <<
": " << value << endl);
318 rs->set_version(value);
321 else if (header ==
"xopendap-server:") {
322 DBG(cout << header <<
": " << value << endl);
323 rs->set_version(value);
325 else if (header ==
"xdap:") {
326 DBG(cout << header <<
": " << value << endl);
327 rs->set_protocol(value);
330 else if (rs->get_version() ==
"dods/0.0" && header ==
"server:") {
331 DBG(cout << header <<
": " << value << endl);
332 rs->set_version(value);
350 : d_http(0), d_version(
"unknown"), d_protocol(
"2.0")
356 if (name.find(
"http") == 0) {
357 DBG(cerr <<
"Connect: The identifier is an http URL" << endl);
361 string::size_type dotpos = name.find(
'?');
362 if (dotpos != name.npos) {
363 _URL = name.substr(0, dotpos);
364 string expr = name.substr(dotpos + 1);
366 dotpos = expr.find(
'&');
367 if (dotpos != expr.npos) {
368 _proj = expr.substr(0, dotpos);
369 _sel = expr.substr(dotpos);
385 DBG(cerr <<
"Connect: The identifier is a local data source." << endl);
392 set_credentials(uname, password);
397 DBG2(cerr <<
"Entering the Connect dtor" << endl);
400 delete d_http; d_http = 0;
402 DBG2(cerr <<
"Leaving the Connect dtor" << endl);
415 string version_url = _URL +
".ver";
416 if (_proj.length() + _sel.length())
417 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
450 string version_url = _URL +
".ver";
451 if (_proj.length() + _sel.length())
452 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
481 string das_url = _URL +
".das";
482 if (_proj.length() + _sel.length())
483 das_url = das_url +
"?" +
id2www_ce(_proj + _sel);
503 "Could not parse error returned from server.");
544 string use_url = _URL +
"?" + _proj + _sel ;
563 "Could not parse error returned from server.");
608 string::size_type dotpos = expr.find(
'&');
609 if (dotpos != expr.npos) {
610 proj = expr.substr(0, dotpos);
611 sel = expr.substr(dotpos);
618 string dds_url = _URL +
".dds" +
"?"
639 "Could not parse error returned from server.");
685 string use_url = _URL +
"?" + _proj + _sel ;
704 "Could not parse error returned from server.");
746 string::size_type dotpos = expr.find(
'&');
747 if (dotpos != expr.npos) {
748 proj = expr.substr(0, dotpos);
749 sel = expr.substr(dotpos);
756 string ddx_url = _URL +
".ddx" +
"?"
777 "Could not parse error returned from server.");
804 throw Error(
"The site did not return a valid response (it lacked the\n\
805 expected content description header value of 'dap4-ddx' and\n\
807 This may indicate that the server at the site is not correctly\n\
808 configured, or that the URL has changed.");
819 string use_url = _URL +
"?" + _proj + _sel ;
839 "Could not parse error returned from server.");
866 throw Error(
"The site did not return a valid response (it lacked the\n\
867 expected content description header value of 'dap4-ddx' and\n\
869 This may indicate that the server at the site is not correctly\n\
870 configured, or that the URL has changed.");
895 string::size_type dotpos = expr.find(
'&');
896 if (dotpos != expr.npos) {
897 proj = expr.substr(0, dotpos);
898 sel = expr.substr(dotpos);
905 string data_url = _URL +
".dods?"
916 process_data(data, rs);
945 string use_url = _URL +
"?" + _proj + _sel ;
954 process_data(data, rs);
967 string::size_type dotpos = expr.find(
'&');
968 if (dotpos != expr.npos) {
969 proj = expr.substr(0, dotpos);
970 sel = expr.substr(dotpos);
977 string data_url = _URL +
".dap?"
988 process_data(data, rs);
1000 string use_url = _URL +
"?" + _proj + _sel ;
1009 process_data(data, rs);
1035 throw InternalErr(__FILE__, __LINE__,
"Response object is null.");
1046 throw InternalErr(__FILE__, __LINE__,
"Response object is null.");
1059 static void divine_type_information(
Response *rs)
1063 while (isspace(c)) {
1081 throw InternalErr(__FILE__, __LINE__,
"Could not determine type of response object in stream.");
1102 divine_type_information(rs);
1108 process_data(data, rs);
1111 process_data(data, rs);
1116 throw InternalErr(__FILE__, __LINE__,
"Should have been a DataDDS or DataDDX.");
1122 divine_type_information(rs);
1128 process_data(data, rs);
1131 process_data(data, rs);
1138 throw InternalErr(__FILE__, __LINE__,
"Should have been a DataDDS or DataDDX.");
1169 "URL(): This call is only valid for a DAP data source.");
1172 return _URL +
"?" + _proj + _sel;
1190 "CE(): This call is only valid for a DAP data source.");
1192 return _proj + _sel;
1243 DBG(cerr <<
"Entering is_cache_enabled (" << hex << d_http << dec
1249 DBGN(cerr <<
"exiting" << endl);