libdap
Updated for version 3.17.0
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: Jose Garcia <jgarcia@ucar.edu> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 // (c) COPYRIGHT URI/MIT 2001-2002 00027 // Please read the full copyright statement in the file COPYRIGHT_URI. 00028 // 00029 // Authors: 00030 // jose Jose Garcia <jgarcia@ucar.edu> 00031 00032 #ifndef _rc_reader_h_ 00033 #define _rc_reader_h_ 00034 00035 #include <iostream> 00036 #include <string> 00037 00038 #include "Error.h" 00039 #include "util.h" 00040 00041 using namespace std; 00042 00043 namespace libdap 00044 { 00045 00054 class RCReader 00055 { 00056 private: 00057 string d_rc_file_path; 00058 string d_cache_root; 00059 00060 bool _dods_use_cache; // 0- Disabled 1- Enabled 00061 unsigned int _dods_cache_max; // Max cache size in Mbytes 00062 unsigned int _dods_cached_obj; // Max cache entry size in Mbytes 00063 int _dods_ign_expires; // 0- Honor expires 1- Ignore them 00064 00065 // NB: NEVER_DEFLATE: I added this (12/1/99 jhrg) because libwww 5.2.9 00066 // cannot process compressed (i.e., deflated) documents in the cache. 00067 // Users must be able to choose whether they want compressed data that 00068 // will always be refreshed or uncompressed data that will be cached. 00069 // When set this flag overrides the value passed into the Connect 00070 // object's constructor. This gives users control over the value. 00071 // Previously, this could only be set by the program that called 00072 // Connect(...). Note that I've now (4/6/2000 jhrg) fixed libwww so this 00073 // parameter is no longer needed.111 00074 // 00075 // Added back in, but with a better name (removed double negative). 00076 // 6/27/2002 jhrg 00077 bool _dods_deflate; // 1- request comp responses, 0- don't 00078 00079 int _dods_default_expires; // 24 hours in seconds 00080 int _dods_always_validate; // Let libwww decide by default so set to 0 00081 00082 // flags for PROXY_SERVER=<protocol>,<host url> 00083 string d_dods_proxy_server_protocol; 00084 string d_dods_proxy_server_host; 00085 int d_dods_proxy_server_port; 00086 string d_dods_proxy_server_userpw; 00087 00088 // Should libcurl validate SSL hosts/certificates" 00089 int d_validate_ssl; 00090 00091 string _dods_proxy_server_host_url; // deprecated 00092 00093 // The proxy-for stuff is all deprecated. 06/17/04 jhrg 00094 // flags for PROXY_FOR=<regex>,<proxy host url>,<flags> 00095 bool _dods_proxy_for; // true if proxy_for is used. 00096 string _dods_proxy_for_regexp; 00097 string _dods_proxy_for_proxy_host_url; 00098 int _dods_proxy_for_regexp_flags; // not used w/libcurl. 6/27/2002 jhrg 00099 00100 //flags for NO_PROXY_FOR=<protocol>,<host>,<port> 00101 bool d_dods_no_proxy_for; // true if no_proxy_for is used. 00102 string d_dods_no_proxy_for_protocol; 00103 string d_dods_no_proxy_for_host; 00104 int _dods_no_proxy_for_port; // not used w/libcurl. 6/27/2002 jhrg 00105 00106 // Make this a vector of strings or support a PATH-style list. 02/26/03 00107 // jhrg 00108 string d_ais_database; 00109 00110 string d_cookie_jar; 00111 00112 static RCReader* _instance; 00113 00114 RCReader(); 00115 ~RCReader(); 00116 00117 // File I/O methods 00118 bool write_rc_file(const string &pathname); 00119 bool read_rc_file(const string &pathname); 00120 00121 // Look for the RC file 00122 string check_env_var(const string &variable_name); 00123 string check_string(string env_var); 00124 00125 static void initialize_instance(); 00126 static void delete_instance(); 00127 00128 friend class RCReaderTest; 00129 friend class HTTPConnectTest; 00130 00131 public: 00132 static RCReader* instance(); 00133 #if 0 00134 static RCReader* instance(const string &rc_file_path); 00135 #endif 00136 // GET METHODS 00137 string get_dods_cache_root() const throw() 00138 { 00139 return d_cache_root; 00140 } 00141 bool get_use_cache() const throw() 00142 { 00143 return _dods_use_cache; 00144 } 00145 int get_max_cache_size() const throw() 00146 { 00147 return _dods_cache_max; 00148 } 00149 unsigned int get_max_cached_obj() const throw() 00150 { 00151 return _dods_cached_obj; 00152 } 00153 int get_ignore_expires() const throw() 00154 { 00155 return _dods_ign_expires; 00156 } 00157 int get_default_expires() const throw() 00158 { 00159 return _dods_default_expires; 00160 } 00161 int get_always_validate() const throw() 00162 { 00163 return _dods_always_validate; 00164 } 00165 int get_validate_ssl() const throw() 00166 { 00167 return d_validate_ssl; 00168 } 00169 00170 bool get_deflate() const throw() 00171 { 00172 return _dods_deflate; 00173 } 00174 00176 string get_proxy_server_protocol() const throw() 00177 { 00178 return d_dods_proxy_server_protocol; 00179 } 00181 string get_proxy_server_host() const throw() 00182 { 00183 return d_dods_proxy_server_host; 00184 } 00186 int get_proxy_server_port() const throw() 00187 { 00188 return d_dods_proxy_server_port; 00189 } 00191 string get_proxy_server_userpw() const throw() 00192 { 00193 return d_dods_proxy_server_userpw; 00194 } 00196 string get_proxy_server_host_url() const throw() 00197 { 00198 return (d_dods_proxy_server_userpw.empty() ? "" : d_dods_proxy_server_userpw + "@") 00199 + d_dods_proxy_server_host 00200 + ":" + long_to_string(d_dods_proxy_server_port); 00201 } 00202 00203 // The whole regex/proxy-for implementation needs reworking. We really 00204 // need a vector of structs which hold the information on a set of regexes 00205 // and matching proxies. Then in the code that derefs a URL, we should 00206 // check to see if the URL matches any of the regexs, et cetera. I'm 00207 // going to disable the entire feature and see if anyone complains. If 00208 // they do, we can fix it. If not, one less thing to do... 06/17/04 jhrg 00210 bool is_proxy_for_used() throw() 00211 { 00212 return _dods_proxy_for; 00213 } 00215 string get_proxy_for_regexp() const throw() 00216 { 00217 return _dods_proxy_for_regexp; 00218 } 00220 string get_proxy_for_proxy_host_url() const throw() 00221 { 00222 return _dods_proxy_for_proxy_host_url; 00223 } 00224 00226 int get_proxy_for_regexp_flags() const throw() 00227 { 00228 return _dods_proxy_for_regexp_flags; 00229 } 00230 00231 // The whole no_proxy implementation also needs a rewrite. However, it is 00232 // useful as it is since the user can give a domain and there's often a 00233 // real need for suppressing proxy access for the local domain. The 00234 // ..._port() method is bogus, however, so it is deprecated. There's no 00235 // code that uses it. 06/17/04 jhrg 00236 bool is_no_proxy_for_used() throw() 00237 { 00238 return d_dods_no_proxy_for; 00239 } 00240 string get_no_proxy_for_protocol() const throw() 00241 { 00242 return d_dods_no_proxy_for_protocol; 00243 } 00244 string get_no_proxy_for_host() const throw() 00245 { 00246 return d_dods_no_proxy_for_host; 00247 } 00248 00250 int get_no_proxy_for_port() const throw() 00251 { 00252 return _dods_no_proxy_for_port; 00253 } 00254 00255 string get_ais_database() const throw() 00256 { 00257 return d_ais_database; 00258 } 00259 00260 string get_cookie_jar() const throw() 00261 { 00262 return d_cookie_jar; 00263 } 00264 00265 // SET METHODS 00266 void set_use_cache(bool b) throw() 00267 { 00268 _dods_use_cache = b; 00269 } 00270 void set_max_cache_size(int i) throw() 00271 { 00272 _dods_cache_max = i; 00273 } 00274 void set_max_cached_obj(int i) throw() 00275 { 00276 _dods_cached_obj = i; 00277 } 00278 void set_ignore_expires(int i) throw() 00279 { 00280 _dods_ign_expires = i; 00281 } 00282 void set_default_expires(int i) throw() 00283 { 00284 _dods_default_expires = i; 00285 } 00286 void set_always_validate(int i) throw() 00287 { 00288 _dods_always_validate = i; 00289 } 00290 void set_validate_ssl(int i) throw() 00291 { 00292 d_validate_ssl = i; 00293 } 00294 00295 void set_deflate(bool b) throw() 00296 { 00297 _dods_deflate = b; 00298 } 00299 00300 void set_proxy_server_protocol(const string &s) throw() 00301 { 00302 d_dods_proxy_server_protocol = s; 00303 } 00304 void set_proxy_server_host(const string &s) throw() 00305 { 00306 d_dods_proxy_server_host = s; 00307 } 00308 void set_proxy_server_port(int l) throw() 00309 { 00310 d_dods_proxy_server_port = l; 00311 } 00312 void set_proxy_server_userpw(const string &s) throw() 00313 { 00314 d_dods_proxy_server_userpw = s; 00315 } 00316 00318 void set_proxy_server_host_url(const string &s) throw() 00319 { 00320 _dods_proxy_server_host_url = s; 00321 } 00322 00324 void set_proxy_for_regexp(const string &s) throw() 00325 { 00326 _dods_proxy_for_regexp = s; 00327 } 00329 void set_proxy_for_proxy_host_url(const string &s) throw() 00330 { 00331 _dods_proxy_for_proxy_host_url = s; 00332 } 00334 void set_proxy_for_regexp_flags(int i) throw() 00335 { 00336 _dods_proxy_for_regexp_flags = i; 00337 } 00338 00339 void set_no_proxy_for_protocol(const string &s) throw() 00340 { 00341 d_dods_no_proxy_for_protocol = s; 00342 } 00343 void set_no_proxy_for_host(const string &s) throw() 00344 { 00345 d_dods_no_proxy_for_host = s; 00346 } 00347 00349 void set_no_proxy_for_port(int i) throw() 00350 { 00351 _dods_no_proxy_for_port = i; 00352 } 00353 00354 void set_ais_database(const string &db) throw() 00355 { 00356 d_ais_database = db; 00357 } 00358 }; 00359 00360 } // namespace libdap 00361 00362 #endif // _RCReader_h_