56#ifdef HAVE_UUID_UUID_H
58#elif defined(HAVE_UUID_H)
61#error "Could not find UUID library header"
89const string usage =
"Usage: <handler name> -o <response> -u <url> [options ...] [data set]\n\
91 options: -o <response>: DAS, DDS, DataDDS, DDX, BLOB or Version (Required)\n\
92 -u <url>: The complete URL minus the CE (required for DDX)\n\
93 -c: Compress the response using the deflate algorithm.\n\
94 -e <expr>: When returning a DataDDS, use <expr> as the constraint.\n\
95 -v <version>: Use <version> as the version number\n\
96 -d <dir>: Look for ancillary file in <dir> (deprecated).\n\
97 -f <file>: Look for ancillary data in <file> (deprecated).\n\
98 -r <dir>: Use <dir> as a cache directory\n\
99 -l <time>: Conditional request; if data source is unchanged since\n\
100 <time>, return an HTTP 304 response.\n\
101 -t <seconds>: Timeout the handler after <seconds>.\n\
171 DBG(cerr <<
"d_comp: " <<
d_comp << endl);
180 DBG(cerr <<
"d_url: " <<
d_url << endl);
213 _setmode(_fileno(stdout), _O_BINARY);
239 if (next_arg < argc) {
255 DBG(cerr <<
"Entering process_options... ");
258 GetOpt getopt(argc, argv,
"ce: v: d: f: r: l: o: u: t: ");
260 while ((option_char = getopt()) != -1) {
261 switch (option_char) {
306 DBGN(cerr <<
"exiting." << endl);
369 if (url.find(
'?') != url.npos)
391 if (r ==
"DAS" || r ==
"das") {
394 }
else if (r ==
"DDS" || r ==
"dds") {
397 }
else if (r ==
"DataDDS" || r ==
"dods") {
400 }
else if (r ==
"DDX" || r ==
"ddx") {
403 }
else if (r ==
"DataDDX" || r ==
"dataddx") {
406 }
else if (r ==
"Version") {
451 DBG(cerr <<
"DODSFilter::get_das_last_modified_time(anc_location=" << anc_location
468 DBG(cerr <<
"DODSFilter::get_das_last_modified_time(anc_location=" << anc_location
491 DBG(cerr <<
"DODSFilter::get_das_last_modified_time(anc_location=" << anc_location
566static const char *emessage =
"DODS internal server error; usage error. Please report this to the dataset maintainer, "
567 "or to the opendap-tech@opendap.org mailing list.";
582 throw Error(emessage);
605 send_das(oss, das, anc_location, with_mime_headers);
606 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
625 if (with_mime_headers)
633 send_das(cout, das, anc_location, with_mime_headers);
653 bool with_mime_headers)
const {
655 send_dds(oss, dds, eval, constrained, anc_location, with_mime_headers);
656 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
676 const string &anc_location,
bool with_mime_headers)
const {
682 throw Error(
"Function calls can only be used with data requests. To see the structure of the underlying data "
683 "source, reissue the URL without the function.");
689 if (with_mime_headers)
701 bool with_mime_headers)
const {
702 send_dds(cout, dds, eval, constrained, anc_location, with_mime_headers);
710 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
716 out <<
"Dataset {\n";
718 out <<
"} function_value;\n";
737 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
752 if ((*i)->send_p()) {
753 DBG(cerr <<
"Sending " << (*i)->name() << endl);
754 (*i)->serialize(eval, dds, m, ce_eval);
762 const string &start,
bool ce_eval)
const {
770 uuid_unparse(uu, uuid);
772 if (getdomainname(domain, 255) != 0 || strlen(domain) == 0)
773 strncpy(domain,
"opendap.org", 255);
775 string cid = string(uuid) +
"@" + string(domain);
789 if ((*i)->send_p()) {
790 DBG(cerr <<
"Sending " << (*i)->name() << endl);
791 (*i)->serialize(eval, dds, m, ce_eval);
815 bool with_mime_headers)
const {
817 send_data(dds, eval, oss, anc_location, with_mime_headers);
818 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), data_stream);
838 bool with_mime_headers)
const {
869 if (with_mime_headers)
872 data_stream << flush ;
881 if (with_mime_headers)
887 if (with_mime_headers)
893 data_stream << flush;
908 send_ddx(dds, eval, oss, with_mime_headers);
909 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
928 throw Error(
"Function calls can only be used with data requests. To see the structure of the underlying data "
929 "source, reissue the URL without the function.");
940 if (with_mime_headers)
967 const string &boundary,
const string &anc_location,
bool with_mime_headers)
const {
994 if (with_mime_headers)
997 data_stream << flush ;
999 DDS var_dds(&btf, var->
name());
1002 serialize_dap2_data_ddx(var_dds, eval, data_stream, boundary, start);
1011 if (with_mime_headers)
1013 data_stream << flush;
1017 if (with_mime_headers)
1019 data_stream << flush;
1023 data_stream << flush;
1025 if (with_mime_headers)
1026 data_stream <<
CRLF <<
"--" << boundary <<
"--" <<
CRLF;
#define unknown_error
Unknown error (the default code) (HTTP 400)
static string find_ancillary_file(const string &pathname, const string &ext, const string &dir, const string &file)
Find a file with ancillary data.
The basic data type for the DODS DAP types.
virtual string name() const
Returns the name of the class instance.
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
virtual void set_send_p(bool state)
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net, then remove them from the object.
Evaluate a constraint expression.
void parse_constraint(const std::string &constraint, DDS &dds)
Parse the constraint expression given the current DDS.
BaseType * eval_function(DDS &dds, const std::string &dataset)
Evaluate a function-valued constraint expression.
bool function_clauses()
Does the current constraint expression contain function clauses.
DDS * eval_function_clauses(DDS &dds)
Evaluate a function-valued constraint expression that contains several function calls.
bool functional_expression()
Does the current constraint expression return a BaseType pointer? This method does not evaluate the c...
Hold attribute data for a DAP2 dataset.
virtual void print(FILE *out, bool dereference=false)
void print(FILE *out)
Print the entire DDS to the specified file.
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
Vars_iter var_end()
Return an iterator.
void add_var(BaseType *bt)
Adds a copy of the variable to the DDS. Using the ptr_duplicate() method, perform a deep copy on the ...
std::vector< BaseType * >::iterator Vars_iter
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
virtual string get_ce() const
Get the constraint expression.
virtual void send_data(DDS &dds, ConstraintEvaluator &eval, ostream &data_stream, const string &anc_location="", bool with_mime_headers=true) const
Transmit data.
virtual time_t get_dds_last_modified_time(const string &anc_location="") const
virtual void send_dds(DDS &dds, ConstraintEvaluator &eval, bool constrained=false, const string &anc_location="", bool with_mime_headers=true) const
virtual Response get_response() const
virtual time_t get_dataset_last_modified_time() const
virtual int process_options(int argc, char *argv[])
bool d_conditional_request
virtual void establish_timeout(ostream &stream) const
virtual void set_URL(const string &url)
time_t d_if_modified_since
virtual string get_action() const
virtual void set_ce(string _ce)
virtual void functional_constraint(BaseType &var, DDS &dds, ConstraintEvaluator &eval, ostream &out) const
void set_timeout(int timeout=0)
virtual void send_das(DAS &das, const string &anc_location="", bool with_mime_headers=true) const
virtual void print_usage() const
Print usage information for a filter program.
virtual string get_dataset_version() const
Get the version information for the dataset.
virtual bool is_conditional() const
Is this request conditional?
virtual string get_dataset_name() const
Get the dataset name.
virtual void send_ddx(DDS &dds, ConstraintEvaluator &eval, ostream &out, bool with_mime_headers=true) const
virtual string get_cgi_version() const
virtual void set_dataset_name(const string _dataset)
virtual void dataset_constraint(DDS &dds, ConstraintEvaluator &eval, ostream &out, bool ce_eval=true) const
virtual void send_version_info() const
Send version information back to the client program.
virtual void send_data_ddx(DDS &dds, ConstraintEvaluator &eval, ostream &data_stream, const string &start, const string &boundary, const string &anc_location="", bool with_mime_headers=true) const
Transmit data.
virtual void set_response(const string &r)
virtual string get_URL() const
virtual void set_cgi_version(string version)
virtual string get_cache_dir() const
Get the cache directory.
virtual time_t get_das_last_modified_time(const string &anc_location="") const
virtual time_t get_request_if_modified_since() const
virtual void dataset_constraint_ddx(DDS &dds, ConstraintEvaluator &eval, ostream &out, const string &boundary, const string &start, bool ce_eval=true) const
virtual time_t get_data_last_modified_time(const string &anc_location="") const
A class for error processing.
static EventHandler * register_handler(int signum, EventHandler *eh, bool ignore_by_default=false)
static SignalHandler * instance()
Marshaller that knows how serialize dap data objects to a C++ iostream using XDR.
top level DAP object to house generic methods
void set_mime_data_boundary(ostream &strm, const string &boundary, const string &cid, ObjectType type, EncodingType enc)
string www2id(const string &in, const string &escape, const string &except)
void set_mime_ddx_boundary(ostream &strm, const string &boundary, const string &cid, ObjectType type, EncodingType enc)
time_t last_modified_time(const string &name)
void set_mime_not_modified(FILE *out)
Send a ‘Not Modified’ response.
void set_mime_binary(FILE *out, ObjectType type, const string &ver, EncodingType enc, const time_t last_modified)
bool do_version(const string &script_ver, const string &dataset_ver)
Send a version number.
void set_mime_multipart(ostream &strm, const string &boundary, const string &start, ObjectType type, const string &version, EncodingType enc, const time_t last_modified)
void ErrMsgT(const string &Msgt)
Logs an error message.
void set_mime_text(FILE *out, ObjectType type, const string &ver, EncodingType enc, const time_t last_modified)