libdap Updated for version 3.20.10
libdap4 is an implementation of OPeNDAP's DAP protocol.
RCReader.h
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{
45
55{
56private:
57 string d_rc_file_path;
58 string d_cache_root;
59
60 bool _dods_use_cache; // 0- Disabled 1- Enabled
61 unsigned int _dods_cache_max; // Max cache size in Mbytes
62 unsigned int _dods_cached_obj; // Max cache entry size in Mbytes
63 int _dods_ign_expires; // 0- Honor expires 1- Ignore them
64
65 // NB: NEVER_DEFLATE: I added this (12/1/99 jhrg) because libwww 5.2.9
66 // cannot process compressed (i.e., deflated) documents in the cache.
67 // Users must be able to choose whether they want compressed data that
68 // will always be refreshed or uncompressed data that will be cached.
69 // When set this flag overrides the value passed into the Connect
70 // object's constructor. This gives users control over the value.
71 // Previously, this could only be set by the program that called
72 // Connect(...). Note that I've now (4/6/2000 jhrg) fixed libwww so this
73 // parameter is no longer needed.111
74 //
75 // Added back in, but with a better name (removed double negative).
76 // 6/27/2002 jhrg
77 bool _dods_deflate; // 1- request comp responses, 0- don't
78
79 int _dods_default_expires; // 24 hours in seconds
80 int _dods_always_validate; // Let libwww decide by default so set to 0
81
82 // flags for PROXY_SERVER=<protocol>,<host url>
83 string d_dods_proxy_server_protocol;
84 string d_dods_proxy_server_host;
85 int d_dods_proxy_server_port;
86 string d_dods_proxy_server_userpw;
87
88 // Should libcurl validate SSL hosts/certificates"
89 int d_validate_ssl;
90
91 string _dods_proxy_server_host_url; // deprecated
92
93 // The proxy-for stuff is all deprecated. 06/17/04 jhrg
94 // flags for PROXY_FOR=<regex>,<proxy host url>,<flags>
95 bool _dods_proxy_for; // true if proxy_for is used.
96 string _dods_proxy_for_regexp;
97 string _dods_proxy_for_proxy_host_url;
98 int _dods_proxy_for_regexp_flags; // not used w/libcurl. 6/27/2002 jhrg
99
100 //flags for NO_PROXY_FOR=<protocol>,<host>,<port>
101 bool d_dods_no_proxy_for; // true if no_proxy_for is used.
102 string d_dods_no_proxy_for_protocol;
103 string d_dods_no_proxy_for_host;
104 int _dods_no_proxy_for_port; // not used w/libcurl. 6/27/2002 jhrg
105
106 // Make this a vector of strings or support a PATH-style list. 02/26/03
107 // jhrg
108 string d_ais_database;
109
110 string d_cookie_jar;
111
112 static RCReader* _instance;
113
114 RCReader();
115 ~RCReader();
116
117 // File I/O methods
118 bool write_rc_file(const string &pathname);
119 bool read_rc_file(const string &pathname);
120
121 // Look for the RC file
122 string check_env_var(const string &variable_name);
123 string check_string(string env_var);
124
125 static void initialize_instance();
126 static void delete_instance();
127
128 friend class RCReaderTest;
129 friend class HTTPConnectTest;
130
131public:
132 static RCReader* instance();
133#if 0
134 static RCReader* instance(const string &rc_file_path);
135#endif
136 // GET METHODS
137 string get_dods_cache_root() const throw()
138 {
139 return d_cache_root;
140 }
141 bool get_use_cache() const throw()
142 {
143 return _dods_use_cache;
144 }
145 int get_max_cache_size() const throw()
146 {
147 return _dods_cache_max;
148 }
149 unsigned int get_max_cached_obj() const throw()
150 {
151 return _dods_cached_obj;
152 }
153 int get_ignore_expires() const throw()
154 {
155 return _dods_ign_expires;
156 }
157 int get_default_expires() const throw()
158 {
159 return _dods_default_expires;
160 }
161 int get_always_validate() const throw()
162 {
163 return _dods_always_validate;
164 }
165 int get_validate_ssl() const throw()
166 {
167 return d_validate_ssl;
168 }
169
170 bool get_deflate() const throw()
171 {
172 return _dods_deflate;
173 }
174
176 string get_proxy_server_protocol() const throw()
177 {
178 return d_dods_proxy_server_protocol;
179 }
181 string get_proxy_server_host() const throw()
182 {
183 return d_dods_proxy_server_host;
184 }
186 int get_proxy_server_port() const throw()
187 {
188 return d_dods_proxy_server_port;
189 }
191 string get_proxy_server_userpw() const throw()
192 {
193 return d_dods_proxy_server_userpw;
194 }
196 string get_proxy_server_host_url() const throw()
197 {
198 return (d_dods_proxy_server_userpw.empty() ? "" : d_dods_proxy_server_userpw + "@")
199 + d_dods_proxy_server_host
200 + ":" + long_to_string(d_dods_proxy_server_port);
201 }
202
203 // The whole regex/proxy-for implementation needs reworking. We really
204 // need a vector of structs which hold the information on a set of regexes
205 // and matching proxies. Then in the code that derefs a URL, we should
206 // check to see if the URL matches any of the regexs, et cetera. I'm
207 // going to disable the entire feature and see if anyone complains. If
208 // they do, we can fix it. If not, one less thing to do... 06/17/04 jhrg
210 bool is_proxy_for_used() throw()
211 {
212 return _dods_proxy_for;
213 }
215 string get_proxy_for_regexp() const throw()
216 {
217 return _dods_proxy_for_regexp;
218 }
220 string get_proxy_for_proxy_host_url() const throw()
221 {
222 return _dods_proxy_for_proxy_host_url;
223 }
224
226 int get_proxy_for_regexp_flags() const throw()
227 {
228 return _dods_proxy_for_regexp_flags;
229 }
230
231 // The whole no_proxy implementation also needs a rewrite. However, it is
232 // useful as it is since the user can give a domain and there's often a
233 // real need for suppressing proxy access for the local domain. The
234 // ..._port() method is bogus, however, so it is deprecated. There's no
235 // code that uses it. 06/17/04 jhrg
236 bool is_no_proxy_for_used() throw()
237 {
238 return d_dods_no_proxy_for;
239 }
240 string get_no_proxy_for_protocol() const throw()
241 {
242 return d_dods_no_proxy_for_protocol;
243 }
244 string get_no_proxy_for_host() const throw()
245 {
246 return d_dods_no_proxy_for_host;
247 }
248
250 int get_no_proxy_for_port() const throw()
251 {
252 return _dods_no_proxy_for_port;
253 }
254
255 string get_ais_database() const throw()
256 {
257 return d_ais_database;
258 }
259
260 string get_cookie_jar() const throw()
261 {
262 return d_cookie_jar;
263 }
264
265 // SET METHODS
266 void set_use_cache(bool b) throw()
267 {
268 _dods_use_cache = b;
269 }
270 void set_max_cache_size(int i) throw()
271 {
272 _dods_cache_max = i;
273 }
274 void set_max_cached_obj(int i) throw()
275 {
276 _dods_cached_obj = i;
277 }
278 void set_ignore_expires(int i) throw()
279 {
280 _dods_ign_expires = i;
281 }
282 void set_default_expires(int i) throw()
283 {
284 _dods_default_expires = i;
285 }
286 void set_always_validate(int i) throw()
287 {
288 _dods_always_validate = i;
289 }
290 void set_validate_ssl(int i) throw()
291 {
292 d_validate_ssl = i;
293 }
294
295 void set_deflate(bool b) throw()
296 {
297 _dods_deflate = b;
298 }
299
300 void set_proxy_server_protocol(const string &s) throw()
301 {
302 d_dods_proxy_server_protocol = s;
303 }
304 void set_proxy_server_host(const string &s) throw()
305 {
306 d_dods_proxy_server_host = s;
307 }
308 void set_proxy_server_port(int l) throw()
309 {
310 d_dods_proxy_server_port = l;
311 }
312 void set_proxy_server_userpw(const string &s) throw()
313 {
314 d_dods_proxy_server_userpw = s;
315 }
316
318 void set_proxy_server_host_url(const string &s) throw()
319 {
320 _dods_proxy_server_host_url = s;
321 }
322
324 void set_proxy_for_regexp(const string &s) throw()
325 {
326 _dods_proxy_for_regexp = s;
327 }
329 void set_proxy_for_proxy_host_url(const string &s) throw()
330 {
331 _dods_proxy_for_proxy_host_url = s;
332 }
334 void set_proxy_for_regexp_flags(int i) throw()
335 {
336 _dods_proxy_for_regexp_flags = i;
337 }
338
339 void set_no_proxy_for_protocol(const string &s) throw()
340 {
341 d_dods_no_proxy_for_protocol = s;
342 }
343 void set_no_proxy_for_host(const string &s) throw()
344 {
345 d_dods_no_proxy_for_host = s;
346 }
347
349 void set_no_proxy_for_port(int i) throw()
350 {
351 _dods_no_proxy_for_port = i;
352 }
353
354 void set_ais_database(const string &db) throw()
355 {
356 d_ais_database = db;
357 }
358};
359
360} // namespace libdap
361
362#endif // _RCReader_h_
void set_no_proxy_for_port(int i)
Definition RCReader.h:349
string get_proxy_server_host() const
Get the proxy host.
Definition RCReader.h:181
void set_proxy_for_proxy_host_url(const string &s)
Definition RCReader.h:329
int get_no_proxy_for_port() const
Definition RCReader.h:250
void set_proxy_for_regexp(const string &s)
Definition RCReader.h:324
int get_proxy_server_port() const
Get the proxy port.
Definition RCReader.h:186
string get_proxy_server_userpw() const
Get the proxy username and password.
Definition RCReader.h:191
string get_proxy_for_regexp() const
Definition RCReader.h:215
void set_proxy_server_host_url(const string &s)
Definition RCReader.h:318
string get_proxy_server_host_url() const
Definition RCReader.h:196
string get_proxy_for_proxy_host_url() const
Definition RCReader.h:220
string get_proxy_server_protocol() const
Get the proxy server protocol.
Definition RCReader.h:176
int get_proxy_for_regexp_flags() const
Definition RCReader.h:226
bool is_proxy_for_used()
Definition RCReader.h:210
void set_proxy_for_regexp_flags(int i)
Definition RCReader.h:334
top level DAP object to house generic methods