40 #define FILE_METHODS 1
43 {
"$Id: Connect.cc 24370 2011-03-28 16:21:32Z 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);
194 Connect::parse_mime(Response *rs)
196 rs->set_version(
"dods/0.0");
197 rs->set_protocol(
"2.0");
199 FILE *data_source = rs->get_stream();
201 while (!mime.empty()) {
202 string header, value;
206 if (header ==
"content-description:") {
207 DBG(cout << header <<
": " << value << endl);
211 else if (header ==
"xdods-server:"
212 && rs->get_version() ==
"dods/0.0") {
213 DBG(cout << header <<
": " << value << endl);
214 rs->set_version(value);
217 else if (header ==
"xopendap-server:") {
218 DBG(cout << header <<
": " << value << endl);
219 rs->set_version(value);
221 else if (header ==
"xdap:") {
222 DBG(cout << header <<
": " << value << endl);
223 rs->set_protocol(value);
226 else if (rs->get_version() ==
"dods/0.0" && header ==
"server:") {
227 DBG(cout << header <<
": " << value << endl);
228 rs->set_version(value);
246 : d_http(0), d_version(
"unknown"), d_protocol(
"2.0")
252 if (name.find(
"http") == 0) {
253 DBG(cerr <<
"Connect: The identifier is an http URL" << endl);
257 string::size_type dotpos = name.find(
'?');
258 if (dotpos != name.npos) {
259 _URL = name.substr(0, dotpos);
260 string expr = name.substr(dotpos + 1);
262 dotpos = expr.find(
'&');
263 if (dotpos != expr.npos) {
264 _proj = expr.substr(0, dotpos);
265 _sel = expr.substr(dotpos);
281 DBG(cerr <<
"Connect: The identifier is a local data source." << endl);
288 set_credentials(uname, password);
293 DBG2(cerr <<
"Entering the Connect dtor" << endl);
296 delete d_http; d_http = 0;
298 DBG2(cerr <<
"Leaving the Connect dtor" << endl);
311 string version_url = _URL +
".ver";
312 if (_proj.length() + _sel.length())
313 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
346 string version_url = _URL +
".ver";
347 if (_proj.length() + _sel.length())
348 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
377 string das_url = _URL +
".das";
378 if (_proj.length() + _sel.length())
379 das_url = das_url +
"?" +
id2www_ce(_proj + _sel);
399 "Could not parse error returned from server.");
440 string use_url = _URL +
"?" + _proj + _sel ;
459 "Could not parse error returned from server.");
504 string::size_type dotpos = expr.find(
'&');
505 if (dotpos != expr.npos) {
506 proj = expr.substr(0, dotpos);
507 sel = expr.substr(dotpos);
514 string dds_url = _URL +
".dds" +
"?"
535 "Could not parse error returned from server.");
581 string use_url = _URL +
"?" + _proj + _sel ;
600 "Could not parse error returned from server.");
642 string::size_type dotpos = expr.find(
'&');
643 if (dotpos != expr.npos) {
644 proj = expr.substr(0, dotpos);
645 sel = expr.substr(dotpos);
652 string ddx_url = _URL +
".ddx" +
"?"
673 "Could not parse error returned from server.");
700 throw Error(
"The site did not return a valid response (it lacked the\n\
701 expected content description header value of 'dap4-ddx' and\n\
703 This may indicate that the server at the site is not correctly\n\
704 configured, or that the URL has changed.");
715 string use_url = _URL +
"?" + _proj + _sel ;
735 "Could not parse error returned from server.");
762 throw Error(
"The site did not return a valid response (it lacked the\n\
763 expected content description header value of 'dap4-ddx' and\n\
765 This may indicate that the server at the site is not correctly\n\
766 configured, or that the URL has changed.");
791 string::size_type dotpos = expr.find(
'&');
792 if (dotpos != expr.npos) {
793 proj = expr.substr(0, dotpos);
794 sel = expr.substr(dotpos);
801 string data_url = _URL +
".dods?"
812 process_data(data, rs);
841 string use_url = _URL +
"?" + _proj + _sel ;
850 process_data(data, rs);
863 string::size_type dotpos = expr.find(
'&');
864 if (dotpos != expr.npos) {
865 proj = expr.substr(0, dotpos);
866 sel = expr.substr(dotpos);
873 string data_url = _URL +
".dap?"
884 process_data(data, rs);
896 string use_url = _URL +
"?" + _proj + _sel ;
905 process_data(data, rs);
931 throw InternalErr(__FILE__, __LINE__,
"Response object is null.");
945 divine_type_information(
Response *rs)
967 throw InternalErr(__FILE__, __LINE__,
"Could not determine type of response object in stream.");
989 divine_type_information(rs);
995 process_data(data, rs);
998 process_data(data, rs);
1003 throw InternalErr(__FILE__, __LINE__,
"Should have been a DataDDS or DataDDX.");
1034 "URL(): This call is only valid for a DAP data source.");
1037 return _URL +
"?" + _proj + _sel;
1055 "CE(): This call is only valid for a DAP data source.");
1057 return _proj + _sel;
1108 DBG(cerr <<
"Entering is_cache_enabled (" << hex << d_http << dec
1114 DBGN(cerr <<
"exiting" << endl);