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);
virtual string CE()
Get the Connect's constraint expression.
virtual void request_das_url(DAS &das)
Get the DAS from a server.
void intern_stream(FILE *in, DDS *dds, string &cid, const string &boundary="")
Read the DDX from a stream instead of a file.
virtual void request_ddx(DDS &dds, string expr="")
Get the DDX from a server.
virtual string URL(bool CE=true)
Get the object's URL.
string id2www_ce(string in, const string &allowable)
string prune_spaces(const string &name)
void set_credentials(const string &u, const string &p)
void set_xdap_protocol(int major, int minor)
void read_multipart_headers(FILE *in, const string &content_type, const ObjectType object_type, const string &cid)
virtual void set_type(ObjectType o)
virtual void request_dds_url(DDS &dds)
Get the DDS from a server.
bool parse(FILE *fp)
Parse an Error object.
void set_cache_enabled(bool enabled)
string cid_to_header_value(const string &cid)
virtual ObjectType get_type() const
HTTPResponse * fetch_url(const string &url)
A class for software fault reporting.
void parse(string fname)
Parse a DDS from a file with the given name.
void parse_mime_header(const string &header, string &name, string &value)
virtual void read_data(DataDDS &data, Response *rs)
Read data which is preceded by MIME headers. This method works for both data dds and data ddx respons...
virtual string get_protocol() const
ObjectType get_description_type(const string &value)
void set_cache_enabled(bool enabled)
std::vector< BaseType * >::iterator Vars_iter
virtual void request_dds(DDS &dds, string expr="")
Get the DDS from a server.
string get_next_mime_header(FILE *in)
void set_accept_deflate(bool deflate)
virtual void request_data(DataDDS &data, string expr="")
Get the DAS from a server.
string read_multipart_boundary(FILE *in, const string &boundary)
virtual void read_data_no_mime(DataDDS &data, Response *rs)
Read data from a file which does not have response MIME headers. This method is a companion to read_d...
virtual void request_das(DAS &das)
Get the DAS from a server.
void set_accept_deflate(bool defalte)
string long_to_string(long val, int base)
BaseTypeFactory * get_factory() const
void set_xdap_protocol(int major, int minor)
virtual void parse(string fname)
Reads a DAS from the named file.
virtual string request_version()
virtual void request_data_ddx_url(DataDDS &data)
virtual void request_data_ddx(DataDDS &data, string expr="")
void set_credentials(string u, string p)
Set the credentials for responding to challenges while dereferencing URLs.
virtual string request_protocol()
string get_protocol() const
Hold attribute data for a DAP2 dataset.
virtual void request_data_url(DataDDS &data)
Get the DAS from a server.
A class for error processing.
virtual string get_version() const
virtual void request_ddx_url(DDS &dds)
The 'url' version of request_ddx.
static RCReader * instance()
virtual FILE * get_stream() const