libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
RCReader.h
Go to the documentation of this file.
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: Jose Garcia <jgarcia@ucar.edu>
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 2001-2002
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jose Jose Garcia <jgarcia@ucar.edu>
31
32#ifndef _rc_reader_h_
33#define _rc_reader_h_
34
35#include <iostream>
36#include <string>
37
38#include "Error.h"
39#include "util.h"
40
41using namespace std;
42
43namespace libdap {
44
53class RCReader {
54private:
55 string d_rc_file_path;
56 string d_cache_root;
57
58 bool _dods_use_cache; // 0- Disabled 1- Enabled
59 unsigned int _dods_cache_max; // Max cache size in Mbytes
60 unsigned int _dods_cached_obj; // Max cache entry size in Mbytes
61 int _dods_ign_expires; // 0- Honor expires 1- Ignore them
62
63 // NB: NEVER_DEFLATE: I added this (12/1/99 jhrg) because libwww 5.2.9
64 // cannot process compressed (i.e., deflated) documents in the cache.
65 // Users must be able to choose whether they want compressed data that
66 // will always be refreshed or uncompressed data that will be cached.
67 // When set this flag overrides the value passed into the Connect
68 // object's constructor. This gives users control over the value.
69 // Previously, this could only be set by the program that called
70 // Connect(...). Note that I've now (4/6/2000 jhrg) fixed libwww so this
71 // parameter is no longer needed.111
72 //
73 // Added back in, but with a better name (removed double negative).
74 // 6/27/2002 jhrg
75 bool _dods_deflate; // 1- request comp responses, 0- don't
76
77 int _dods_default_expires; // 24 hours in seconds
78 int _dods_always_validate; // Let libwww decide by default so set to 0
79
80 // flags for PROXY_SERVER=<protocol>,<host url>
81 string d_dods_proxy_server_protocol;
82 string d_dods_proxy_server_host;
83 int d_dods_proxy_server_port;
84 string d_dods_proxy_server_userpw;
85
86 // Should libcurl validate SSL hosts/certificates"
87 int d_validate_ssl;
88
89 string _dods_proxy_server_host_url; // deprecated
90
91 // The proxy-for stuff is all deprecated. 06/17/04 jhrg
92 // flags for PROXY_FOR=<regex>,<proxy host url>,<flags>
93 bool _dods_proxy_for; // true if proxy_for is used.
94 string _dods_proxy_for_regexp;
95 string _dods_proxy_for_proxy_host_url;
96 int _dods_proxy_for_regexp_flags; // not used w/libcurl. 6/27/2002 jhrg
97
98 // flags for NO_PROXY_FOR=<protocol>,<host>,<port>
99 bool d_dods_no_proxy_for; // true if no_proxy_for is used.
100 string d_dods_no_proxy_for_protocol;
101 string d_dods_no_proxy_for_host;
102 int _dods_no_proxy_for_port; // not used w/libcurl. 6/27/2002 jhrg
103
104 // Make this a vector of strings or support a PATH-style list. 02/26/03
105 // jhrg
106 string d_ais_database;
107
108 string d_cookie_jar;
109
110 static RCReader *_instance;
111
112 RCReader();
113 ~RCReader();
114
115 // File I/O methods
116 bool write_rc_file(const string &pathname);
117 bool read_rc_file(const string &pathname);
118
119 // Look for the RC file
120 string check_env_var(const string &variable_name);
121 string check_string(string env_var);
122
123 static void initialize_instance();
124 static void delete_instance();
125
126 friend class RCReaderTest;
127 friend class HTTPConnectTest;
128
129public:
130 static RCReader *instance();
131#if 0
132 static RCReader* instance(const string &rc_file_path);
133#endif
134 // GET METHODS
135 string get_dods_cache_root() const throw() { return d_cache_root; }
136 bool get_use_cache() const throw() { return _dods_use_cache; }
137 int get_max_cache_size() const throw() { return _dods_cache_max; }
138 unsigned int get_max_cached_obj() const throw() { return _dods_cached_obj; }
139 int get_ignore_expires() const throw() { return _dods_ign_expires; }
140 int get_default_expires() const throw() { return _dods_default_expires; }
141 int get_always_validate() const throw() { return _dods_always_validate; }
142 int get_validate_ssl() const throw() { return d_validate_ssl; }
143
144 bool get_deflate() const throw() { return _dods_deflate; }
145
147 string get_proxy_server_protocol() const throw() { return d_dods_proxy_server_protocol; }
149 string get_proxy_server_host() const throw() { return d_dods_proxy_server_host; }
151 int get_proxy_server_port() const throw() { return d_dods_proxy_server_port; }
153 string get_proxy_server_userpw() const throw() { return d_dods_proxy_server_userpw; }
155 string get_proxy_server_host_url() const throw() {
156 return (d_dods_proxy_server_userpw.empty() ? "" : d_dods_proxy_server_userpw + "@") + d_dods_proxy_server_host +
157 ":" + long_to_string(d_dods_proxy_server_port);
158 }
159
160 // The whole regex/proxy-for implementation needs reworking. We really
161 // need a vector of structs which hold the information on a set of regexes
162 // and matching proxies. Then in the code that derefs a URL, we should
163 // check to see if the URL matches any of the regexs, et cetera. I'm
164 // going to disable the entire feature and see if anyone complains. If
165 // they do, we can fix it. If not, one less thing to do... 06/17/04 jhrg
167 bool is_proxy_for_used() throw() { return _dods_proxy_for; }
169 string get_proxy_for_regexp() const throw() { return _dods_proxy_for_regexp; }
171 string get_proxy_for_proxy_host_url() const throw() { return _dods_proxy_for_proxy_host_url; }
172
174 int get_proxy_for_regexp_flags() const throw() { return _dods_proxy_for_regexp_flags; }
175
176 // The whole no_proxy implementation also needs a rewrite. However, it is
177 // useful as it is since the user can give a domain and there's often a
178 // real need for suppressing proxy access for the local domain. The
179 // ..._port() method is bogus, however, so it is deprecated. There's no
180 // code that uses it. 06/17/04 jhrg
181 bool is_no_proxy_for_used() throw() { return d_dods_no_proxy_for; }
182 string get_no_proxy_for_protocol() const throw() { return d_dods_no_proxy_for_protocol; }
183 string get_no_proxy_for_host() const throw() { return d_dods_no_proxy_for_host; }
184
186 int get_no_proxy_for_port() const throw() { return _dods_no_proxy_for_port; }
187
188 string get_ais_database() const throw() { return d_ais_database; }
189
190 string get_cookie_jar() const throw() { return d_cookie_jar; }
191
192 // SET METHODS
193 void set_use_cache(bool b) throw() { _dods_use_cache = b; }
194 void set_max_cache_size(int i) throw() { _dods_cache_max = i; }
195 void set_max_cached_obj(int i) throw() { _dods_cached_obj = i; }
196 void set_ignore_expires(int i) throw() { _dods_ign_expires = i; }
197 void set_default_expires(int i) throw() { _dods_default_expires = i; }
198 void set_always_validate(int i) throw() { _dods_always_validate = i; }
199 void set_validate_ssl(int i) throw() { d_validate_ssl = i; }
200
201 void set_deflate(bool b) throw() { _dods_deflate = b; }
202
203 void set_proxy_server_protocol(const string &s) throw() { d_dods_proxy_server_protocol = s; }
204 void set_proxy_server_host(const string &s) throw() { d_dods_proxy_server_host = s; }
205 void set_proxy_server_port(int l) throw() { d_dods_proxy_server_port = l; }
206 void set_proxy_server_userpw(const string &s) throw() { d_dods_proxy_server_userpw = s; }
207
209 void set_proxy_server_host_url(const string &s) throw() { _dods_proxy_server_host_url = s; }
210
212 void set_proxy_for_regexp(const string &s) throw() { _dods_proxy_for_regexp = s; }
214 void set_proxy_for_proxy_host_url(const string &s) throw() { _dods_proxy_for_proxy_host_url = s; }
216 void set_proxy_for_regexp_flags(int i) throw() { _dods_proxy_for_regexp_flags = i; }
217
218 void set_no_proxy_for_protocol(const string &s) throw() { d_dods_no_proxy_for_protocol = s; }
219 void set_no_proxy_for_host(const string &s) throw() { d_dods_no_proxy_for_host = s; }
220
222 void set_no_proxy_for_port(int i) throw() { _dods_no_proxy_for_port = i; }
223
224 void set_ais_database(const string &db) throw() { d_ais_database = db; }
225};
226
227} // namespace libdap
228
229#endif // _RCReader_h_
void set_no_proxy_for_port(int i)
Definition RCReader.h:222
bool get_use_cache() const
Definition RCReader.h:136
string get_no_proxy_for_host() const
Definition RCReader.h:183
int get_default_expires() const
Definition RCReader.h:140
string get_proxy_server_host() const
Get the proxy host.
Definition RCReader.h:149
bool is_no_proxy_for_used()
Definition RCReader.h:181
string get_dods_cache_root() const
Definition RCReader.h:135
void set_proxy_for_proxy_host_url(const string &s)
Definition RCReader.h:214
bool get_deflate() const
Definition RCReader.h:144
int get_no_proxy_for_port() const
Definition RCReader.h:186
void set_default_expires(int i)
Definition RCReader.h:197
void set_no_proxy_for_protocol(const string &s)
Definition RCReader.h:218
void set_proxy_for_regexp(const string &s)
Definition RCReader.h:212
int get_proxy_server_port() const
Get the proxy port.
Definition RCReader.h:151
string get_no_proxy_for_protocol() const
Definition RCReader.h:182
string get_ais_database() const
Definition RCReader.h:188
void set_always_validate(int i)
Definition RCReader.h:198
string get_proxy_server_userpw() const
Get the proxy username and password.
Definition RCReader.h:153
void set_proxy_server_port(int l)
Definition RCReader.h:205
void set_proxy_server_host(const string &s)
Definition RCReader.h:204
void set_ignore_expires(int i)
Definition RCReader.h:196
string get_proxy_for_regexp() const
Definition RCReader.h:169
void set_proxy_server_userpw(const string &s)
Definition RCReader.h:206
void set_proxy_server_host_url(const string &s)
Definition RCReader.h:209
void set_no_proxy_for_host(const string &s)
Definition RCReader.h:219
static RCReader * instance()
Definition RCReader.cc:427
int get_always_validate() const
Definition RCReader.h:141
void set_validate_ssl(int i)
Definition RCReader.h:199
int get_ignore_expires() const
Definition RCReader.h:139
string get_proxy_server_host_url() const
Definition RCReader.h:155
friend class HTTPConnectTest
Definition RCReader.h:127
string get_cookie_jar() const
Definition RCReader.h:190
string get_proxy_for_proxy_host_url() const
Definition RCReader.h:171
int get_validate_ssl() const
Definition RCReader.h:142
unsigned int get_max_cached_obj() const
Definition RCReader.h:138
void set_proxy_server_protocol(const string &s)
Definition RCReader.h:203
string get_proxy_server_protocol() const
Get the proxy server protocol.
Definition RCReader.h:147
int get_max_cache_size() const
Definition RCReader.h:137
int get_proxy_for_regexp_flags() const
Definition RCReader.h:174
bool is_proxy_for_used()
Definition RCReader.h:167
void set_max_cache_size(int i)
Definition RCReader.h:194
void set_ais_database(const string &db)
Definition RCReader.h:224
void set_max_cached_obj(int i)
Definition RCReader.h:195
void set_proxy_for_regexp_flags(int i)
Definition RCReader.h:216
void set_use_cache(bool b)
Definition RCReader.h:193
void set_deflate(bool b)
Definition RCReader.h:201
friend class RCReaderTest
Definition RCReader.h:126
top level DAP object to house generic methods
Definition AISConnect.cc:30
string long_to_string(long val, int base)
Definition util.cc:946