Blame RCReader.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: Jose Garcia <jgarcia@ucar.edu>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 2001-2002
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//         jose  Jose Garcia <jgarcia@ucar.edu>
Packit a4aae4
Packit a4aae4
#ifndef _rc_reader_h_
Packit a4aae4
#define _rc_reader_h_
Packit a4aae4
Packit a4aae4
#include <iostream>
Packit a4aae4
#include <string>
Packit a4aae4
Packit a4aae4
#include "Error.h"
Packit a4aae4
#include "util.h"
Packit a4aae4
Packit a4aae4
using namespace std;
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
/** Read the .dodsrc file. By default the file ~/.dodsrc is read. If the
Packit a4aae4
    environment variable DODS_CONF is set, use that value as the pathname to
Packit a4aae4
    the configuration file. Else, if the environment variable DODS_CACHE_INIT
Packit a4aae4
    is set, use that value.
Packit a4aae4
Packit a4aae4
    NB: DODS_CACHE_INIT is deprecated and may be removed in the future.
Packit a4aae4
Packit a4aae4
    @author Jose Garcia <jgarcia@ucar.edu> */
Packit a4aae4
class RCReader
Packit a4aae4
{
Packit a4aae4
private:
Packit a4aae4
    string d_rc_file_path;
Packit a4aae4
    string d_cache_root;
Packit a4aae4
Packit a4aae4
    bool _dods_use_cache; // 0- Disabled 1- Enabled
Packit a4aae4
    unsigned int _dods_cache_max; // Max cache size in Mbytes
Packit a4aae4
    unsigned int _dods_cached_obj; // Max cache entry size in Mbytes
Packit a4aae4
    int _dods_ign_expires; // 0- Honor expires 1- Ignore them
Packit a4aae4
Packit a4aae4
    // NB: NEVER_DEFLATE: I added this (12/1/99 jhrg) because libwww 5.2.9
Packit a4aae4
    // cannot process compressed (i.e., deflated) documents in the cache.
Packit a4aae4
    // Users must be able to choose whether they want compressed data that
Packit a4aae4
    // will always be refreshed or uncompressed data that will be cached.
Packit a4aae4
    // When set this flag overrides the value passed into the Connect
Packit a4aae4
    // object's constructor. This gives users control over the value.
Packit a4aae4
    // Previously, this could only be set by the program that called
Packit a4aae4
    // Connect(...). Note that I've now (4/6/2000 jhrg) fixed libwww so this
Packit a4aae4
    // parameter is no longer needed.111
Packit a4aae4
    //
Packit a4aae4
    // Added back in, but with a better name (removed double negative).
Packit a4aae4
    // 6/27/2002 jhrg
Packit a4aae4
    bool _dods_deflate;  // 1- request comp responses, 0- don't
Packit a4aae4
Packit a4aae4
    int _dods_default_expires; // 24 hours in seconds
Packit a4aae4
    int _dods_always_validate; // Let libwww decide by default so set to 0
Packit a4aae4
Packit a4aae4
    // flags for PROXY_SERVER=<protocol>,<host url>
Packit a4aae4
    string d_dods_proxy_server_protocol;
Packit a4aae4
    string d_dods_proxy_server_host;
Packit a4aae4
    int d_dods_proxy_server_port;
Packit a4aae4
    string d_dods_proxy_server_userpw;
Packit a4aae4
Packit a4aae4
    // Should libcurl validate SSL hosts/certificates"
Packit a4aae4
    int d_validate_ssl;
Packit a4aae4
Packit a4aae4
    string _dods_proxy_server_host_url; // deprecated
Packit a4aae4
Packit a4aae4
    // The proxy-for stuff is all deprecated. 06/17/04 jhrg
Packit a4aae4
    // flags for PROXY_FOR=<regex>,<proxy host url>,<flags>
Packit a4aae4
    bool _dods_proxy_for; // true if proxy_for is used.
Packit a4aae4
    string _dods_proxy_for_regexp;
Packit a4aae4
    string _dods_proxy_for_proxy_host_url;
Packit a4aae4
    int _dods_proxy_for_regexp_flags; // not used w/libcurl. 6/27/2002 jhrg
Packit a4aae4
Packit a4aae4
    //flags for NO_PROXY_FOR=<protocol>,<host>,<port>
Packit a4aae4
    bool d_dods_no_proxy_for; // true if no_proxy_for is used.
Packit a4aae4
    string d_dods_no_proxy_for_protocol;
Packit a4aae4
    string d_dods_no_proxy_for_host;
Packit a4aae4
    int _dods_no_proxy_for_port; // not used w/libcurl. 6/27/2002 jhrg
Packit a4aae4
Packit a4aae4
    // Make this a vector of strings or support a PATH-style list. 02/26/03
Packit a4aae4
    // jhrg
Packit a4aae4
    string d_ais_database;
Packit a4aae4
Packit a4aae4
    string d_cookie_jar;
Packit a4aae4
Packit a4aae4
    static RCReader* _instance;
Packit a4aae4
Packit a4aae4
    RCReader();
Packit a4aae4
    ~RCReader();
Packit a4aae4
Packit a4aae4
    // File I/O methods
Packit a4aae4
    bool write_rc_file(const string &pathname);
Packit a4aae4
    bool read_rc_file(const string &pathname);
Packit a4aae4
Packit a4aae4
    // Look for the RC file
Packit a4aae4
    string check_env_var(const string &variable_name);
Packit a4aae4
    string check_string(string env_var);
Packit a4aae4
Packit a4aae4
    static void initialize_instance();
Packit a4aae4
    static void delete_instance();
Packit a4aae4
Packit a4aae4
    friend class RCReaderTest;
Packit a4aae4
    friend class HTTPConnectTest;
Packit a4aae4
Packit a4aae4
public:
Packit a4aae4
    static RCReader* instance();
Packit a4aae4
#if 0
Packit a4aae4
    static RCReader* instance(const string &rc_file_path);
Packit a4aae4
#endif
Packit a4aae4
    // GET METHODS
Packit a4aae4
    string get_dods_cache_root() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_cache_root;
Packit a4aae4
    }
Packit a4aae4
    bool get_use_cache() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_use_cache;
Packit a4aae4
    }
Packit a4aae4
    int get_max_cache_size()  const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_cache_max;
Packit a4aae4
    }
Packit a4aae4
    unsigned int get_max_cached_obj() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_cached_obj;
Packit a4aae4
    }
Packit a4aae4
    int get_ignore_expires() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_ign_expires;
Packit a4aae4
    }
Packit a4aae4
    int get_default_expires() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_default_expires;
Packit a4aae4
    }
Packit a4aae4
    int get_always_validate() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_always_validate;
Packit a4aae4
    }
Packit a4aae4
    int get_validate_ssl() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_validate_ssl;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    bool get_deflate() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_deflate;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// Get the proxy server protocol
Packit a4aae4
    string get_proxy_server_protocol() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_proxy_server_protocol;
Packit a4aae4
    }
Packit a4aae4
    /// Get the proxy host
Packit a4aae4
    string get_proxy_server_host() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_proxy_server_host;
Packit a4aae4
    }
Packit a4aae4
    /// Get the proxy port
Packit a4aae4
    int get_proxy_server_port() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_proxy_server_port;
Packit a4aae4
    }
Packit a4aae4
    /// Get the proxy username and password
Packit a4aae4
    string get_proxy_server_userpw() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_proxy_server_userpw;
Packit a4aae4
    }
Packit a4aae4
    /// @deprecated
Packit a4aae4
    string get_proxy_server_host_url() const throw()
Packit a4aae4
    {
Packit a4aae4
        return (d_dods_proxy_server_userpw.empty() ? "" : d_dods_proxy_server_userpw + "@")
Packit a4aae4
               + d_dods_proxy_server_host
Packit a4aae4
               + ":" + long_to_string(d_dods_proxy_server_port);
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    // The whole regex/proxy-for implementation needs reworking. We really
Packit a4aae4
    // need a vector of structs which hold the information on a set of regexes
Packit a4aae4
    // and matching proxies. Then in the code that derefs a URL, we should
Packit a4aae4
    // check to see if the URL matches any of the regexs, et cetera. I'm
Packit a4aae4
    // going to disable the entire feature and see if anyone complains. If
Packit a4aae4
    // they do, we can fix it. If not, one less thing to do... 06/17/04 jhrg
Packit a4aae4
    /// @deprecated
Packit a4aae4
    bool is_proxy_for_used() throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_proxy_for;
Packit a4aae4
    }
Packit a4aae4
    /// @deprecated
Packit a4aae4
    string get_proxy_for_regexp() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_proxy_for_regexp;
Packit a4aae4
    }
Packit a4aae4
    /// @deprecated
Packit a4aae4
    string get_proxy_for_proxy_host_url() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_proxy_for_proxy_host_url;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// @deprecated
Packit a4aae4
    int get_proxy_for_regexp_flags() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_proxy_for_regexp_flags;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    // The whole no_proxy implementation also needs a rewrite. However, it is
Packit a4aae4
    // useful as it is since the user can give a domain and there's often a
Packit a4aae4
    // real need for suppressing proxy access for the local domain. The
Packit a4aae4
    // ..._port() method is bogus, however, so it is deprecated. There's no
Packit a4aae4
    // code that uses it. 06/17/04 jhrg
Packit a4aae4
    bool is_no_proxy_for_used() throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_no_proxy_for;
Packit a4aae4
    }
Packit a4aae4
    string get_no_proxy_for_protocol() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_no_proxy_for_protocol;
Packit a4aae4
    }
Packit a4aae4
    string get_no_proxy_for_host() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_dods_no_proxy_for_host;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// @deprecated
Packit a4aae4
    int    get_no_proxy_for_port() const throw()
Packit a4aae4
    {
Packit a4aae4
        return _dods_no_proxy_for_port;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    string get_ais_database() const throw()
Packit a4aae4
    {
Packit a4aae4
        return d_ais_database;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    string get_cookie_jar() const throw()
Packit a4aae4
    {
Packit a4aae4
	return d_cookie_jar;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    // SET METHODS
Packit a4aae4
    void set_use_cache(bool b) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_use_cache = b;
Packit a4aae4
    }
Packit a4aae4
    void set_max_cache_size(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_cache_max = i;
Packit a4aae4
    }
Packit a4aae4
    void set_max_cached_obj(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_cached_obj = i;
Packit a4aae4
    }
Packit a4aae4
    void set_ignore_expires(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_ign_expires = i;
Packit a4aae4
    }
Packit a4aae4
    void set_default_expires(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_default_expires = i;
Packit a4aae4
    }
Packit a4aae4
    void set_always_validate(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_always_validate = i;
Packit a4aae4
    }
Packit a4aae4
    void set_validate_ssl(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        d_validate_ssl = i;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    void set_deflate(bool b) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_deflate = b;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    void set_proxy_server_protocol(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        d_dods_proxy_server_protocol = s;
Packit a4aae4
    }
Packit a4aae4
    void set_proxy_server_host(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        d_dods_proxy_server_host = s;
Packit a4aae4
    }
Packit a4aae4
    void set_proxy_server_port(int l) throw()
Packit a4aae4
    {
Packit a4aae4
        d_dods_proxy_server_port = l;
Packit a4aae4
    }
Packit a4aae4
    void set_proxy_server_userpw(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        d_dods_proxy_server_userpw = s;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// @deprecated
Packit a4aae4
    void set_proxy_server_host_url(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_proxy_server_host_url = s;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// @deprecated
Packit a4aae4
    void set_proxy_for_regexp(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_proxy_for_regexp = s;
Packit a4aae4
    }
Packit a4aae4
    /// @deprecated
Packit a4aae4
    void set_proxy_for_proxy_host_url(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_proxy_for_proxy_host_url = s;
Packit a4aae4
    }
Packit a4aae4
    /// @deprecated
Packit a4aae4
    void set_proxy_for_regexp_flags(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_proxy_for_regexp_flags = i;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    void set_no_proxy_for_protocol(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        d_dods_no_proxy_for_protocol = s;
Packit a4aae4
    }
Packit a4aae4
    void set_no_proxy_for_host(const string &s) throw()
Packit a4aae4
    {
Packit a4aae4
        d_dods_no_proxy_for_host = s;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// @deprecated
Packit a4aae4
    void set_no_proxy_for_port(int i) throw()
Packit a4aae4
    {
Packit a4aae4
        _dods_no_proxy_for_port = i;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    void set_ais_database(const string &db) throw()
Packit a4aae4
    {
Packit a4aae4
        d_ais_database = db;
Packit a4aae4
    }
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif // _RCReader_h_