38 #define FILE_UN_MARSHALLER 1
50 #if FILE_UN_MARSHALLER
53 #include "fdiostream.h"
68 void Connect::process_data(DataDDS &data, Response *rs)
70 DBG(cerr <<
"Entering Connect::process_data" << endl);
72 data.set_version(rs->get_version());
73 data.set_protocol(rs->get_protocol());
75 DBG(cerr <<
"Entering process_data: d_stream = " << rs << endl);
76 switch (rs->get_type()) {
79 if (!e.parse(rs->get_stream()))
80 throw InternalErr(__FILE__, __LINE__,
"Could not parse the Error object returned by the server!");
87 throw InternalErr(__FILE__, __LINE__,
88 "An error was reported by the remote httpd; this should have been processed by HTTPConnect..");
92 DDXParser ddx_parser(data.get_factory());
96 DBG(cerr <<
"MPM Boundary: " << boundary << endl);
102 ddx_parser.intern_stream(rs->get_stream(), &data, data_cid, boundary);
106 DBG(cerr <<
"Data CID: " << data_cid << endl);
113 #if FILE_UN_MARSHALLER
114 XDRFileUnMarshaller um(rs->get_stream());
116 fpistream in ( rs->get_stream() );
117 XDRStreamUnMarshaller um( in );
119 for (
DDS::Vars_iter i = data.var_begin(); i != data.var_end(); i++) {
120 (*i)->deserialize(um, &data);
128 data.parse(rs->get_stream());
129 #if FILE_UN_MARSHALLER
130 XDRFileUnMarshaller um(rs->get_stream());
132 fpistream in ( rs->get_stream() );
133 XDRStreamUnMarshaller um( in );
136 for (
DDS::Vars_iter i = data.var_begin(); i != data.var_end(); i++) {
137 (*i)->deserialize(um, &data);
147 Connect::process_data(DDS &data, Response *rs)
149 DBG(cerr <<
"Entering Connect::process_data" << endl);
152 data.set_version(rs->get_version());
153 data.set_protocol(rs->get_protocol());
156 data.set_dap_version(rs->get_protocol());
158 DBG(cerr <<
"Entering process_data: d_stream = " << rs << endl);
159 switch (rs->get_type()) {
162 if (!e.parse(rs->get_stream()))
163 throw InternalErr(__FILE__, __LINE__,
164 "Could not parse the Error object returned by the server!");
171 throw InternalErr(__FILE__, __LINE__,
"An error was reported by the remote httpd; this should have been processed by HTTPConnect..");
175 DDXParser ddx_parser(data.get_factory());
179 DBG(cerr <<
"MPM Boundary: " << boundary << endl);
185 ddx_parser.intern_stream(rs->get_stream(), &data, data_cid, boundary);
189 DBG(cerr <<
"Data CID: " << data_cid << endl);
194 "application/octet-stream",
dap4_data, data_cid);
197 #if FILE_UN_MARSHALLER
198 XDRFileUnMarshaller um( rs->get_stream() ) ;
200 fpistream in ( rs->get_stream() );
201 XDRStreamUnMarshaller um( in ) ;
208 (*i)->deserialize(um, &data);
222 data.parse(rs->get_stream());
223 #if FILE_UN_MARSHALLER
224 XDRFileUnMarshaller um( rs->get_stream() ) ;
226 fpistream in ( rs->get_stream() );
227 XDRStreamUnMarshaller um( in ) ;
235 (*i)->deserialize(um, &data);
269 void Connect::parse_mime(Response *rs)
271 rs->set_version(
"dods/0.0");
272 rs->set_protocol(
"2.0");
274 FILE *data_source = rs->get_stream();
276 while (!mime.empty()) {
277 string header, value;
281 if (header ==
"content-description:") {
282 DBG(cout << header <<
": " << value << endl);
286 else if (header ==
"xdods-server:" && rs->get_version() ==
"dods/0.0") {
287 DBG(cout << header <<
": " << value << endl);
288 rs->set_version(value);
291 else if (header ==
"xopendap-server:") {
292 DBG(cout << header <<
": " << value << endl);
293 rs->set_version(value);
295 else if (header ==
"xdap:") {
296 DBG(cout << header <<
": " << value << endl);
297 rs->set_protocol(value);
300 else if (rs->get_version() ==
"dods/0.0" && header ==
"server:") {
301 DBG(cout << header <<
": " << value << endl);
302 rs->set_version(value);
319 d_http(0), d_version(
"unknown"), d_protocol(
"2.0")
325 if (name.find(
"http") == 0) {
326 DBG(cerr <<
"Connect: The identifier is an http URL" << endl);
330 string::size_type dotpos = name.find(
'?');
331 if (dotpos != name.npos) {
332 _URL = name.substr(0, dotpos);
333 string expr = name.substr(dotpos + 1);
335 dotpos = expr.find(
'&');
336 if (dotpos != expr.npos) {
337 _proj = expr.substr(0, dotpos);
338 _sel = expr.substr(dotpos);
354 DBG(cerr <<
"Connect: The identifier is a local data source." << endl);
361 set_credentials(uname, password);
366 DBG2(cerr <<
"Entering the Connect dtor" << endl);
372 DBG2(cerr <<
"Leaving the Connect dtor" << endl);
384 string version_url = _URL +
".ver";
385 if (_proj.length() + _sel.length())
386 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
420 string version_url = _URL +
".ver";
421 if (_proj.length() + _sel.length())
422 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
452 string das_url = _URL +
".das";
453 if (_proj.length() + _sel.length())
454 das_url = das_url +
"?" +
id2www_ce(_proj + _sel);
475 throw InternalErr(__FILE__, __LINE__,
"Could not parse error returned from server.");
518 string use_url = _URL +
"?" + _proj + _sel;
538 throw InternalErr(__FILE__, __LINE__,
"Could not parse error returned from server.");
585 string::size_type dotpos = expr.find(
'&');
586 if (dotpos != expr.npos) {
587 proj = expr.substr(0, dotpos);
588 sel = expr.substr(dotpos);
595 string dds_url = _URL +
".dds" +
"?" +
id2www_ce(_proj + proj + _sel + sel);
616 throw InternalErr(__FILE__, __LINE__,
"Could not parse error returned from server.");
664 string use_url = _URL +
"?" + _proj + _sel;
684 throw InternalErr(__FILE__, __LINE__,
"Could not parse error returned from server.");
728 string::size_type dotpos = expr.find(
'&');
729 if (dotpos != expr.npos) {
730 proj = expr.substr(0, dotpos);
731 sel = expr.substr(dotpos);
738 string ddx_url = _URL +
".ddx" +
"?" +
id2www_ce(_proj + proj + _sel + sel);
759 throw InternalErr(__FILE__, __LINE__,
"Could not parse error returned from server.");
790 "The site did not return a valid response (it lacked the\n\
791 expected content description header value of 'dap4-ddx' and\n\
795 This may indicate that the server at the site is not correctly\n\
796 configured, or that the URL has changed.");
807 string use_url = _URL +
"?" + _proj + _sel;
828 throw InternalErr(__FILE__, __LINE__,
"Could not parse error returned from server.");
859 "The site did not return a valid response (it lacked the\n\
860 expected content description header value of 'dap4-ddx' and\n\
864 This may indicate that the server at the site is not correctly\n\
865 configured, or that the URL has changed.");
890 string::size_type dotpos = expr.find(
'&');
891 if (dotpos != expr.npos) {
892 proj = expr.substr(0, dotpos);
893 sel = expr.substr(dotpos);
900 string data_url = _URL +
".dods?" +
id2www_ce(_proj + proj + _sel + sel);
910 process_data(data, rs);
940 string use_url = _URL +
"?" + _proj + _sel;
949 process_data(data, rs);
963 string::size_type dotpos = expr.find(
'&');
964 if (dotpos != expr.npos) {
965 proj = expr.substr(0, dotpos);
966 sel = expr.substr(dotpos);
973 string data_url = _URL +
".dap?" +
id2www_ce(_proj + proj + _sel + sel);
983 process_data(data, rs);
996 string use_url = _URL +
"?" + _proj + _sel;
1005 process_data(data, rs);
1032 throw InternalErr(__FILE__, __LINE__,
"Response object is null.");
1043 throw InternalErr(__FILE__, __LINE__,
"Response object is null.");
1056 static void divine_type_information(
Response *rs)
1060 while (isspace(c)) {
1078 throw InternalErr(__FILE__, __LINE__,
"Could not determine type of response object in stream.");
1099 divine_type_information(rs);
1105 process_data(data, rs);
1108 process_data(data, rs);
1113 throw InternalErr(__FILE__, __LINE__,
"Should have been a DataDDS or DataDDX.");
1119 divine_type_information(rs);
1125 process_data(data, rs);
1128 process_data(data, rs);
1135 throw InternalErr(__FILE__, __LINE__,
"Should have been a DataDDS or DataDDX.");
1164 throw InternalErr(__FILE__, __LINE__,
"URL(): This call is only valid for a DAP data source.");
1167 return _URL +
"?" + _proj + _sel;
1183 throw InternalErr(__FILE__, __LINE__,
"CE(): This call is only valid for a DAP data source.");
1185 return _proj + _sel;
1231 DBG(cerr <<
"Entering is_cache_enabled (" << hex << d_http << dec
1237 DBGN(cerr <<
"exiting" << endl);