40 #define FILE_METHODS 1 43 {
"$Id: Connect.cc 22703 2010-05-11 18:10:01Z 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 ) ;
130 (*i)->deserialize(um, &data);
143 data.parse(rs->get_stream());
145 XDRFileUnMarshaller um( rs->get_stream() ) ;
147 fpistream in ( rs->get_stream() );
148 XDRStreamUnMarshaller um( in ) ;
154 (*i)->deserialize(um, &data);
188 Connect::parse_mime(Response *rs)
190 rs->set_version(
"dods/0.0");
191 rs->set_protocol(
"2.0");
193 FILE *data_source = rs->get_stream();
195 while (!mime.empty()) {
196 string header, value;
200 if (header ==
"content-description:") {
201 DBG(cout << header <<
": " << value << endl);
205 else if (header ==
"xdods-server:" 206 && rs->get_version() ==
"dods/0.0") {
207 DBG(cout << header <<
": " << value << endl);
208 rs->set_version(value);
211 else if (header ==
"xopendap-server:") {
212 DBG(cout << header <<
": " << value << endl);
213 rs->set_version(value);
215 else if (header ==
"xdap:") {
216 DBG(cout << header <<
": " << value << endl);
217 rs->set_protocol(value);
220 else if (rs->get_version() ==
"dods/0.0" && header ==
"server:") {
221 DBG(cout << header <<
": " << value << endl);
222 rs->set_version(value);
240 : d_http(0), d_version(
"unknown"), d_protocol(
"2.0")
246 if (name.find(
"http") == 0) {
247 DBG(cerr <<
"Connect: The identifier is an http URL" << endl);
251 string::size_type dotpos = name.find(
'?');
252 if (dotpos != name.npos) {
253 _URL = name.substr(0, dotpos);
254 string expr = name.substr(dotpos + 1);
256 dotpos = expr.find(
'&');
257 if (dotpos != expr.npos) {
258 _proj = expr.substr(0, dotpos);
259 _sel = expr.substr(dotpos);
275 DBG(cerr <<
"Connect: The identifier is a local data source." << endl);
287 DBG2(cerr <<
"Entering the Connect dtor" << endl);
290 delete d_http; d_http = 0;
292 DBG2(cerr <<
"Leaving the Connect dtor" << endl);
305 string version_url = _URL +
".ver";
306 if (_proj.length() + _sel.length())
307 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
340 string version_url = _URL +
".ver";
341 if (_proj.length() + _sel.length())
342 version_url = version_url +
"?" +
id2www_ce(_proj + _sel);
371 string das_url = _URL +
".das";
372 if (_proj.length() + _sel.length())
373 das_url = das_url +
"?" +
id2www_ce(_proj + _sel);
392 "Could not parse error returned from server.");
434 string use_url = _URL +
"?" + _proj + _sel ;
452 "Could not parse error returned from server.");
498 string::size_type dotpos = expr.find(
'&');
499 if (dotpos != expr.npos) {
500 proj = expr.substr(0, dotpos);
501 sel = expr.substr(dotpos);
508 string dds_url = _URL +
".dds" +
"?" 528 "Could not parse error returned from server.");
575 string use_url = _URL +
"?" + _proj + _sel ;
593 "Could not parse error returned from server.");
636 string::size_type dotpos = expr.find(
'&');
637 if (dotpos != expr.npos) {
638 proj = expr.substr(0, dotpos);
639 sel = expr.substr(dotpos);
646 string ddx_url = _URL +
".ddx" +
"?" 666 "Could not parse error returned from server.");
693 throw Error(
"The site did not return a valid response (it lacked the\n\ 694 expected content description header value of 'dap4-ddx' and\n\ 696 This may indicate that the server at the site is not correctly\n\ 697 configured, or that the URL has changed.");
708 string use_url = _URL +
"?" + _proj + _sel ;
727 "Could not parse error returned from server.");
754 throw Error(
"The site did not return a valid response (it lacked the\n\ 755 expected content description header value of 'dap4-ddx' and\n\ 757 This may indicate that the server at the site is not correctly\n\ 758 configured, or that the URL has changed.");
783 string::size_type dotpos = expr.find(
'&');
784 if (dotpos != expr.npos) {
785 proj = expr.substr(0, dotpos);
786 sel = expr.substr(dotpos);
793 string data_url = _URL +
".dods?" 804 process_data(data, rs);
833 string use_url = _URL +
"?" + _proj + _sel ;
842 process_data(data, rs);
855 string::size_type dotpos = expr.find(
'&');
856 if (dotpos != expr.npos) {
857 proj = expr.substr(0, dotpos);
858 sel = expr.substr(dotpos);
865 string data_url = _URL +
".dap?" 876 process_data(data, rs);
888 string use_url = _URL +
"?" + _proj + _sel ;
897 process_data(data, rs);
923 throw InternalErr(__FILE__, __LINE__,
"Response object is null.");
937 divine_type_information(
Response *rs)
959 throw InternalErr(__FILE__, __LINE__,
"Could not determine type of response object in stream.");
981 divine_type_information(rs);
987 process_data(data, rs);
990 process_data(data, rs);
995 throw InternalErr(__FILE__, __LINE__,
"Should have been a DataDDS or DataDDX.");
1026 "URL(): This call is only valid for a DAP data source.");
1029 return _URL +
"?" + _proj + _sel;
1047 "CE(): This call is only valid for a DAP data source.");
1049 return _proj + _sel;
1100 DBG(cerr <<
"Entering is_cache_enabled (" << hex << d_http << dec
1106 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 get_protocol() const
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)
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...
ObjectType get_description_type(const string &value)
void set_cache_enabled(bool enabled)
virtual FILE * get_stream() const
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)
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="")
virtual ObjectType get_type() const
void set_credentials(string u, string p)
Set the credentials for responding to challenges while dereferencing URLs.
virtual string get_protocol() const
virtual string request_protocol()
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.
BaseTypeFactory * get_factory() const
virtual void request_ddx_url(DDS &dds)
The 'url' version of request_ddx.
virtual string get_version() const
static RCReader * instance()