27 static char rcsid[]
not_used = {
"$Id: ResponseBuilder.cc 23477 2010-09-02 21:02:59Z jimg $" };
45 #include <uuid/uuid.h>
61 #define CRLF "\r\n" // Change here, expr-test.cc
66 ResponseBuilder::~ResponseBuilder()
72 void ResponseBuilder::initialize()
81 #if 0 // Keyword support moved to Keywords class
83 d_known_keywords.insert(
"dap2");
84 d_known_keywords.insert(
"dap2.0");
86 d_known_keywords.insert(
"dap3.2");
87 d_known_keywords.insert(
"dap3.3");
89 d_known_keywords.insert(
"dap4");
90 d_known_keywords.insert(
"dap4.0");
96 _setmode(_fileno(stdout), _O_BINARY);
105 void ResponseBuilder::add_keyword(
const string &kw)
107 d_keywords.insert(kw);
118 return d_keywords.count(kw) != 0;
126 list<string> ResponseBuilder::get_keywords()
const
129 set<string>::const_iterator i;
130 for (i = d_keywords.begin(); i != d_keywords.end(); ++i)
140 bool ResponseBuilder::is_known_keyword(
const string &w)
const
142 return d_known_keywords.count(w) != 0;
152 string ResponseBuilder::get_ce()
const
157 void ResponseBuilder::set_ce(
string _ce)
159 d_ce =
www2id(_ce,
"%",
"%20");
163 string projection =
www2id(_ce,
"%",
"%20");
164 string selection =
"";
167 string::size_type amp = projection.find(
'&');
168 if (amp != string::npos) {
169 selection = projection.substr(amp);
170 projection = projection.substr(0, amp);
177 while (!projection.empty()) {
178 string::size_type i = projection.find(
',');
179 string next_word = projection.substr(0, i);
180 if (is_known_keyword(next_word)) {
181 add_keyword(next_word);
182 projection = projection.substr(i + 1);
190 d_ce = projection + selection;
202 string ResponseBuilder::get_dataset_name()
const
207 void ResponseBuilder::set_dataset_name(
const string ds)
209 d_dataset =
www2id(ds,
"%",
"%20");
216 void ResponseBuilder::set_timeout(
int t)
222 int ResponseBuilder::get_timeout()
const
237 void ResponseBuilder::establish_timeout(ostream &stream)
const
260 void ResponseBuilder::send_das(ostream &out,
DAS &das,
bool with_mime_headers)
const
262 if (with_mime_headers)
286 bool with_mime_headers)
const
293 throw Error(
"Function calls can only be used with data requests. To see the structure of the underlying data source, reissue the URL without the function.");
295 if (with_mime_headers)
319 if ((*i)->send_p()) {
320 DBG(cerr <<
"Sending " << (*i)->name() << endl);
321 (*i)->serialize(eval, dds, m, ce_eval);
330 const string &boundary,
const string &start,
bool ce_eval)
const
339 uuid_unparse(uu, &uuid[0]);
341 if (getdomainname(domain, 255) != 0 || strlen(domain) == 0)
342 strncpy(domain,
"opendap.org", 255);
344 string cid = string(&uuid[0]) +
"@" + string(&domain[0]);
358 if ((*i)->send_p()) {
359 DBG(cerr <<
"Sending " << (*i)->name() << endl);
360 (*i)->serialize(eval, dds, m, ce_eval);
384 void ResponseBuilder::send_data(ostream & data_stream,
DDS & dds,
ConstraintEvaluator & eval,
bool with_mime_headers)
const
387 establish_timeout(data_stream);
400 if (with_mime_headers)
403 dataset_constraint(data_stream, *fdds, eval,
false);
407 if (with_mime_headers)
410 dataset_constraint(data_stream, dds, eval);
413 data_stream << flush;
434 "Function calls can only be used with data requests. To see the structure of the underlying data source, reissue the URL without the function.");
436 if (with_mime_headers)
458 const string &boundary,
bool with_mime_headers)
const
461 establish_timeout(data_stream);
474 if (with_mime_headers)
476 data_stream << flush;
478 dataset_constraint(data_stream, *fdds, eval,
false);
482 if (with_mime_headers)
484 data_stream << flush;
485 dataset_constraint_ddx(data_stream, dds, eval, boundary, start);
488 data_stream << flush;
490 if (with_mime_headers)
491 data_stream <<
CRLF <<
"--" << boundary <<
"--" <<
CRLF;
494 static const char *descrip[] = {
"unknown",
"dods_das",
"dods_dds",
"dods_data",
"dods_error",
"web_error",
"dap4-ddx",
495 "dap4-data",
"dap4-error",
"dap4-data-ddx",
"dods_ddx" };
496 static const char *encoding[] = {
"unknown",
"deflate",
"x-plain",
"gzip",
"binary" };
512 const string &protocol)
const
514 strm <<
"HTTP/1.0 200 OK" <<
CRLF;
516 strm <<
"XDODS-Server: " <<
DVR <<
CRLF;
517 strm <<
"XOPeNDAP-Server: " <<
DVR <<
CRLF;
520 strm <<
"XDAP: " << d_default_protocol <<
CRLF;
522 strm <<
"XDAP: " << protocol <<
CRLF;
524 const time_t t = time(0);
527 strm <<
"Last-Modified: ";
528 if (last_modified > 0)
534 strm <<
"Content-Type: text/xml" <<
CRLF;
536 strm <<
"Content-Type: text/plain" <<
CRLF;
540 strm <<
"Content-Description: " << descrip[type] <<
CRLF;
542 strm <<
"Cache-Control: no-cache" <<
CRLF;
546 strm <<
"Content-Encoding: " << encoding[enc] <<
CRLF;
562 const string &protocol)
const
564 strm <<
"HTTP/1.0 200 OK" <<
CRLF;
566 strm <<
"XDODS-Server: " <<
DVR <<
CRLF;
567 strm <<
"XOPeNDAP-Server: " <<
DVR <<
CRLF;
570 strm <<
"XDAP: " << d_default_protocol <<
CRLF;
572 strm <<
"XDAP: " << protocol <<
CRLF;
574 const time_t t = time(0);
577 strm <<
"Last-Modified: ";
578 if (last_modified > 0)
583 strm <<
"Content-type: text/html" <<
CRLF;
585 strm <<
"Content-Description: " << descrip[type] <<
CRLF;
587 strm <<
"Cache-Control: no-cache" <<
CRLF;
591 strm <<
"Content-Encoding: " << encoding[enc] <<
CRLF;
610 const string &protocol)
const
612 strm <<
"HTTP/1.0 200 OK" <<
CRLF;
614 strm <<
"XDODS-Server: " <<
DVR <<
CRLF;
615 strm <<
"XOPeNDAP-Server: " <<
DVR <<
CRLF;
618 strm <<
"XDAP: " << d_default_protocol <<
CRLF;
620 strm <<
"XDAP: " << protocol <<
CRLF;
622 const time_t t = time(0);
625 strm <<
"Last-Modified: ";
626 if (last_modified > 0)
631 strm <<
"Content-Type: application/octet-stream" <<
CRLF;
632 strm <<
"Content-Description: " << descrip[type] <<
CRLF;
634 strm <<
"Content-Encoding: " << encoding[enc] <<
CRLF;
641 const time_t last_modified,
const string &protocol)
const
643 strm <<
"HTTP/1.0 200 OK" <<
CRLF;
645 strm <<
"XDODS-Server: " <<
DVR <<
CRLF;
646 strm <<
"XOPeNDAP-Server: " <<
DVR <<
CRLF;
649 strm <<
"XDAP: " << d_default_protocol <<
CRLF;
651 strm <<
"XDAP: " << protocol <<
CRLF;
653 const time_t t = time(0);
656 strm <<
"Last-Modified: ";
657 if (last_modified > 0)
662 strm <<
"Content-Type: Multipart/Related; boundary=" << boundary <<
"; start=\"<" << start
663 <<
">\"; type=\"Text/xml\"" <<
CRLF;
664 strm <<
"Content-Description: " << descrip[type] <<
CRLF;
666 strm <<
"Content-Encoding: " << encoding[enc] <<
CRLF;
674 strm <<
"--" << boundary <<
CRLF;
675 strm <<
"Content-Type: Text/xml; charset=iso-8859-1" <<
CRLF;
676 strm <<
"Content-Id: <" << cid <<
">" <<
CRLF;
677 strm <<
"Content-Description: " << descrip[type] <<
CRLF;
679 strm <<
"Content-Encoding: " << encoding[enc] <<
CRLF;
687 strm <<
"--" << boundary <<
CRLF;
688 strm <<
"Content-Type: application/octet-stream" <<
CRLF;
689 strm <<
"Content-Id: <" << cid <<
">" <<
CRLF;
690 strm <<
"Content-Description: " << descrip[type] <<
CRLF;
692 strm <<
"Content-Encoding: " << encoding[enc] <<
CRLF;
704 const string &protocol)
const
706 strm <<
"HTTP/1.0 " << code <<
" " << reason.c_str() <<
CRLF;
708 strm <<
"XDODS-Server: " <<
DVR <<
CRLF;
709 strm <<
"XOPeNDAP-Server: " <<
DVR <<
CRLF;
712 strm <<
"XDAP: " << d_default_protocol <<
CRLF;
714 strm <<
"XDAP: " << protocol <<
CRLF;
716 const time_t t = time(0);
718 strm <<
"Cache-Control: no-cache" <<
CRLF;