1 2 // -*- mode: c++; c-basic-offset:4 -*- 3 4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 5 // Access Protocol. 6 7 // Copyright (c) 2002,2003 OPeNDAP, Inc. 8 // Author: James Gallagher <jgallagher@opendap.org> 9 // 10 // This library is free software; you can redistribute it and/or 11 // modify it under the terms of the GNU Lesser General Public 12 // License as published by the Free Software Foundation; either 13 // version 2.1 of the License, or (at your option) any later version. 14 // 15 // This library is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 // Lesser General Public License for more details. 19 // 20 // You should have received a copy of the GNU Lesser General Public 21 // License along with this library; if not, write to the Free Software 22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 // 24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 25 26 // (c) COPYRIGHT URI/MIT 1997-1999 27 // Please first read the full copyright statement in the file COPYRIGHT_URI. 28 // 29 // Authors: 30 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu> 31 32 #ifndef _dodsfilter_h 33 #define _dodsfilter_h 34 35 #include <string> 36 37 #ifndef _das_h 38 #include "DAS.h" 39 #endif 40 41 #ifndef _dds_h 42 #include "DDS.h" 43 #endif 44 45 #ifndef constraint_evaluator_h 46 #include "ConstraintEvaluator.h" 47 #endif 48 49 namespace libdap 50 { 51 52 /** When a DODS server receives a request from a DODS client, the 53 server CGI script dispatches the request to one of several 54 ``filter'' programs. Each filter is responsible for returning a 55 different aspect of the dataset information: one is for data, one 56 is for the dataset DDS, one is for the dataset DAS, and a fourth 57 is for a usage message describing the server itself. Some 58 installations may have additional optional filters. 59 60 The filter program receives a data request from the dispatch 61 script. It receives its operating parameters from the command 62 line, like any UNIX command, and it returns its output to standard 63 output, which the httpd server packages up into a reply to the 64 client. 65 66 This class contains some common functions for the filter programs 67 used to make up the DODS data servers. The filter programs do not 68 <i>have</i> to be called by a CGI program, but that is the normal 69 mechanism by which they are invoked. 70 71 @todo Add a test to make sure that the required arguments are given. 72 @todo We need to rethink the ancillary file/directory stuff. I don't 73 think it's ever been used... 74 75 @brief Common functions for DODS server filter programs. 76 @author jhrg 8/26/97 */ 77 78 class DODSFilter 79 { 80 public: 81 /** Types of responses DODSFilter know about. */ 82 enum Response { 83 Unknown_Response, 84 DAS_Response, 85 DDS_Response, 86 DataDDS_Response, 87 DDX_Response, 88 DataDDX_Response, 89 BLOB_Response, 90 Version_Response 91 }; 92 93 protected: 94 bool d_comp; // True if the output should be compressed. 95 bool d_bad_options; // True if the options (argc,argv) are bad. 96 bool d_conditional_request; 97 98 string d_program_name; // Name of the filter program 99 string d_dataset; // Name of the dataset/database 100 string d_dap2ce; // DAP2 Constraint expression 101 string d_cgi_ver; // Version of CGI script (caller) 102 string d_anc_dir; // Look here for ancillary files 103 string d_anc_file; // Use this for ancillary file name 104 string d_cache_dir; // Use this for cache files 105 string d_url; // URL minus CE. 106 107 Response d_response; // enum name of the response to generate 108 string d_action; // string name of the response to generate 109 110 int d_timeout; // Server timeout after N seconds 111 112 time_t d_anc_das_lmt; // Last modified time of the anc. DAS. 113 time_t d_anc_dds_lmt; // Last modified time of the anc. DDS. 114 time_t d_if_modified_since; // Time from a conditional request. 115 116 void initialize(); 117 void initialize(int argc, char *argv[]); 118 119 virtual int process_options(int argc, char *argv[]); 120 121 public: 122 /** Make an empty instance. Use the set_*() methods to load with needed 123 values. You must call at least set_dataset_name() or be requesting 124 version information. 125 126 @todo Add methods to provide a way to set all of the parameters 127 this class contains. They can currently only be set using the 128 argc/argv command line parameters. */ DODSFilter()129 DODSFilter() 130 { 131 initialize(); 132 } 133 DODSFilter(int argc, char *argv[]) throw(Error); 134 135 virtual ~DODSFilter(); 136 137 virtual bool is_conditional() const; 138 139 virtual string get_cgi_version() const; 140 virtual void set_cgi_version(string version); 141 142 virtual string get_ce() const; 143 virtual void set_ce(string _ce); 144 145 virtual string get_dataset_name() const; 146 virtual void set_dataset_name(const string _dataset); 147 148 virtual string get_URL() const; 149 virtual void set_URL(const string &url); 150 151 virtual string get_dataset_version() const; 152 153 virtual Response get_response() const; 154 virtual string get_action() const; 155 virtual void set_response(const string &r); 156 157 virtual time_t get_dataset_last_modified_time() const; 158 159 virtual time_t get_das_last_modified_time(const string &anc_location = "") const; 160 161 virtual time_t get_dds_last_modified_time(const string &anc_location = "") const; 162 163 virtual time_t get_data_last_modified_time(const string &anc_location = "") const; 164 165 virtual time_t get_request_if_modified_since() const; 166 167 virtual string get_cache_dir() const; 168 169 void set_timeout(int timeout = 0); 170 171 int get_timeout() const; 172 173 virtual void establish_timeout(ostream &stream) const; 174 175 virtual void print_usage() const; 176 177 virtual void send_version_info() const; 178 179 virtual void send_das(DAS &das, const string &anc_location = "", 180 bool with_mime_headers = true) const; 181 virtual void send_das(ostream &out, DAS &das, const string &anc_location = "", 182 bool with_mime_headers = true) const; 183 184 virtual void send_dds(DDS &dds, ConstraintEvaluator &eval, 185 bool constrained = false, 186 const string &anc_location = "", 187 bool with_mime_headers = true) const; 188 virtual void send_dds(ostream &out, DDS &dds, ConstraintEvaluator &eval, 189 bool constrained = false, 190 const string &anc_location = "", 191 bool with_mime_headers = true) const; 192 // deprecated 193 virtual void functional_constraint(BaseType &var, DDS &dds, 194 ConstraintEvaluator &eval, ostream &out) const; 195 196 virtual void dataset_constraint(DDS &dds, ConstraintEvaluator &eval, 197 ostream &out, bool ce_eval = true) const; 198 virtual void dataset_constraint_ddx(DDS & dds, ConstraintEvaluator & eval, 199 ostream &out, const string &boundary, 200 const string &start, 201 bool ce_eval = true) const; 202 203 virtual void send_data(DDS &dds, ConstraintEvaluator &eval, 204 ostream &data_stream, 205 const string &anc_location = "", 206 bool with_mime_headers = true) const; 207 virtual void send_ddx(DDS &dds, ConstraintEvaluator &eval, ostream &out, 208 bool with_mime_headers = true) const; 209 virtual void send_data_ddx(DDS &dds, ConstraintEvaluator &eval, 210 ostream &data_stream, const string &start, 211 const string &boundary, 212 const string &anc_location = "", 213 bool with_mime_headers = true) const; 214 215 virtual void establish_timeout(FILE *stream) const; 216 virtual void send_das(FILE *out, DAS &das, const string &anc_location = "", 217 bool with_mime_headers = true) const; 218 virtual void send_dds(FILE *out, DDS &dds, ConstraintEvaluator &eval, 219 bool constrained = false, 220 const string &anc_location = "", 221 bool with_mime_headers = true) const; 222 // deprecated 223 virtual void functional_constraint(BaseType &var, DDS &dds, 224 ConstraintEvaluator &eval, FILE *out) const; 225 226 virtual void dataset_constraint(DDS &dds, ConstraintEvaluator &eval, 227 FILE *out, bool ce_eval = true) const; 228 virtual void send_data(DDS &dds, ConstraintEvaluator &eval, 229 FILE *data_stream, 230 const string &anc_location = "", 231 bool with_mime_headers = true) const; 232 virtual void send_ddx(DDS &dds, ConstraintEvaluator &eval, FILE *out, 233 bool with_mime_headers = true) const; 234 }; 235 236 } // namespace libdap 237 238 #endif // _dodsfilter_h 239