RCReader.h

Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 
00051 class RCReader
00052 {
00053 private:
00054     string d_rc_file_path;
00055     string d_cache_root;
00056 
00057     bool _dods_use_cache; // 0- Disabled 1- Enabled
00058     unsigned int _dods_cache_max; // Max cache size in Mbytes
00059     unsigned int _dods_cached_obj; // Max cache entry size in Mbytes
00060     int _dods_ign_expires; // 0- Honor expires 1- Ignore them
00061 
00062     // NB: NEVER_DEFLATE: I added this (12/1/99 jhrg) because libwww 5.2.9
00063     // cannot process compressed (i.e., deflated) documents in the cache.
00064     // Users must be able to choose whether they want compressed data that
00065     // will always be refreshed or uncompressed data that will be cached.
00066     // When set this flag overrides the value passed into the Connect
00067     // object's constructor. This gives users control over the value.
00068     // Previously, this could only be set by the program that called
00069     // Connect(...). Note that I've now (4/6/2000 jhrg) fixed libwww so this
00070     // parameter is no longer needed.111
00071     //
00072     // Added back in, but with a better name (removed double negative).
00073     // 6/27/2002 jhrg
00074     bool _dods_deflate;  // 1- request comp responses, 0- don't
00075 
00076     int _dods_default_expires; // 24 hours in seconds
00077     int _dods_always_validate; // Let libwww decide by default so set to 0
00078 
00079     // flags for PROXY_SERVER=<protocol>,<host url>
00080     string d_dods_proxy_server_protocol;
00081     string d_dods_proxy_server_host;
00082     int d_dods_proxy_server_port;
00083     string d_dods_proxy_server_userpw;
00084 
00085     // Should libcurl validate SSL hosts/certificates"
00086     int d_validate_ssl;
00087 
00088     string _dods_proxy_server_host_url; // deprecated
00089 
00090     // The proxy-for stuff is all deprecated. 06/17/04 jhrg
00091     // flags for PROXY_FOR=<regex>,<proxy host url>,<flags>
00092     bool _dods_proxy_for; // true if proxy_for is used.
00093     string _dods_proxy_for_regexp;
00094     string _dods_proxy_for_proxy_host_url;
00095     int _dods_proxy_for_regexp_flags; // not used w/libcurl. 6/27/2002 jhrg
00096 
00097     //flags for NO_PROXY_FOR=<protocol>,<host>,<port>
00098     bool d_dods_no_proxy_for; // true if no_proxy_for is used.
00099     string d_dods_no_proxy_for_protocol;
00100     string d_dods_no_proxy_for_host;
00101     int _dods_no_proxy_for_port; // not used w/libcurl. 6/27/2002 jhrg
00102 
00103     // Make this a vector of strings or support a PATH-style list. 02/26/03
00104     // jhrg
00105     string d_ais_database;
00106 
00107     static RCReader* _instance;
00108 
00109     RCReader() throw(Error);
00110     ~RCReader();
00111 
00112     // File I/O methods
00113     bool write_rc_file(const string &pathname);
00114     bool read_rc_file(const string &pathname);
00115 
00116     // Look for the RC file
00117     string check_env_var(const string &variable_name);
00118     string check_string(string env_var);
00119 
00120     static void initialize_instance();
00121     static void delete_instance();
00122 
00123     friend class RCReaderTest;
00124     friend class HTTPConnectTest;
00125 
00126 public:
00127     static RCReader* instance();
00128 
00129     // GET METHODS
00130     const string get_dods_cache_root()
00131     {
00132         return d_cache_root;
00133     }
00134     const bool get_use_cache() throw()
00135     {
00136         return _dods_use_cache;
00137     }
00138     const int get_max_cache_size()  throw()
00139     {
00140         return _dods_cache_max;
00141     }
00142     const unsigned int get_max_cached_obj() throw()
00143     {
00144         return _dods_cached_obj;
00145     }
00146     const int get_ignore_expires() throw()
00147     {
00148         return _dods_ign_expires;
00149     }
00150     const int get_default_expires() throw()
00151     {
00152         return _dods_default_expires;
00153     }
00154     const int get_always_validate() throw()
00155     {
00156         return _dods_always_validate;
00157     }
00158     int get_validate_ssl() const throw()
00159     {
00160         return d_validate_ssl;
00161     }
00162 
00163     const bool get_deflate() throw()
00164     {
00165         return _dods_deflate;
00166     }
00167 
00169     const string get_proxy_server_protocol() throw()
00170     {
00171         return d_dods_proxy_server_protocol;
00172     }
00174     const string get_proxy_server_host() throw()
00175     {
00176         return d_dods_proxy_server_host;
00177     }
00179     const int get_proxy_server_port() throw()
00180     {
00181         return d_dods_proxy_server_port;
00182     }
00184     const string get_proxy_server_userpw() throw()
00185     {
00186         return d_dods_proxy_server_userpw;
00187     }
00189     const string get_proxy_server_host_url()  throw()
00190     {
00191         return (d_dods_proxy_server_userpw.empty() ? "" : d_dods_proxy_server_userpw + "@")
00192                + d_dods_proxy_server_host
00193                + ":" + long_to_string(d_dods_proxy_server_port);
00194     }
00195 
00196     // The whole regex/proxy-for implementation needs reworking. We really
00197     // need a vector of structs which hold the information on a set of regexes
00198     // and matching proxies. Then in the code that derefs a URL, we should
00199     // check to see if the URL matches any of the regexs, et cetera. I'm
00200     // going to disable the entire feature and see if anyone complains. If
00201     // they do, we can fix it. If not, one less thing to do... 06/17/04 jhrg
00203     bool is_proxy_for_used() throw()
00204     {
00205         return _dods_proxy_for;
00206     }
00208     const string get_proxy_for_regexp() throw()
00209     {
00210         return _dods_proxy_for_regexp;
00211     }
00213     const string get_proxy_for_proxy_host_url() throw()
00214     {
00215         return _dods_proxy_for_proxy_host_url;
00216     }
00217 
00219     const int get_proxy_for_regexp_flags() throw()
00220     {
00221         return _dods_proxy_for_regexp_flags;
00222     }
00223 
00224     // The whole no_proxy implementation also needs a rewrite. However, it is
00225     // useful as it is since the user can give a domain and there's often a
00226     // real need for suppressing proxy access for the local domain. The
00227     // ..._port() method is bogus, however, so it is deprecated. There's no
00228     // code that uses it. 06/17/04 jhrg
00229     bool is_no_proxy_for_used() throw()
00230     {
00231         return d_dods_no_proxy_for;
00232     }
00233     const string get_no_proxy_for_protocol() throw()
00234     {
00235         return d_dods_no_proxy_for_protocol;
00236     }
00237     const string get_no_proxy_for_host() throw()
00238     {
00239         return d_dods_no_proxy_for_host;
00240     }
00241 
00243     const int    get_no_proxy_for_port() throw()
00244     {
00245         return _dods_no_proxy_for_port;
00246     }
00247 
00248     string get_ais_database() const throw()
00249     {
00250         return d_ais_database;
00251     }
00252 
00253     // SET METHODS
00254     void set_use_cache(bool b) throw()
00255     {
00256         _dods_use_cache = b;
00257     }
00258     void set_max_cache_size(int i) throw()
00259     {
00260         _dods_cache_max = i;
00261     }
00262     void set_max_cached_obj(int i) throw()
00263     {
00264         _dods_cached_obj = i;
00265     }
00266     void set_ignore_expires(int i) throw()
00267     {
00268         _dods_ign_expires = i;
00269     }
00270     void set_default_expires(int i) throw()
00271     {
00272         _dods_default_expires = i;
00273     }
00274     void set_always_validate(int i) throw()
00275     {
00276         _dods_always_validate = i;
00277     }
00278     void set_validate_ssl(int i) throw()
00279     {
00280         d_validate_ssl = i;
00281     }
00282 
00283     void set_deflate(bool b) throw()
00284     {
00285         _dods_deflate = b;
00286     }
00287 
00288     void set_proxy_server_protocol(const string &s) throw()
00289     {
00290         d_dods_proxy_server_protocol = s;
00291     }
00292     void set_proxy_server_host(const string &s) throw()
00293     {
00294         d_dods_proxy_server_host = s;
00295     }
00296     void set_proxy_server_port(int l) throw()
00297     {
00298         d_dods_proxy_server_port = l;
00299     }
00300     void set_proxy_server_userpw(const string &s) throw()
00301     {
00302         d_dods_proxy_server_userpw = s;
00303     }
00304 
00306     void set_proxy_server_host_url(const string &s) throw()
00307     {
00308         _dods_proxy_server_host_url = s;
00309     }
00310 
00312     void set_proxy_for_regexp(const string &s) throw()
00313     {
00314         _dods_proxy_for_regexp = s;
00315     }
00317     void set_proxy_for_proxy_host_url(const string &s) throw()
00318     {
00319         _dods_proxy_for_proxy_host_url = s;
00320     }
00322     void set_proxy_for_regexp_flags(int i) throw()
00323     {
00324         _dods_proxy_for_regexp_flags = i;
00325     }
00326 
00327     void set_no_proxy_for_protocol(const string &s) throw()
00328     {
00329         d_dods_no_proxy_for_protocol = s;
00330     }
00331     void set_no_proxy_for_host(const string &s) throw()
00332     {
00333         d_dods_no_proxy_for_host = s;
00334     }
00335 
00337     void set_no_proxy_for_port(int i) throw()
00338     {
00339         _dods_no_proxy_for_port = i;
00340     }
00341 
00342     void set_ais_database(const string &db) throw()
00343     {
00344         d_ais_database = db;
00345     }
00346 };
00347 
00348 #endif // _RCReader_h_

Generated on Wed Jun 27 12:56:39 2007 for libdap++ by  doxygen 1.4.7