libdap++  Updated for version 3.13.3
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 
41 using namespace std;
42 
43 namespace libdap
44 {
45 
54 class RCReader
55 {
56 private:
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() throw(Error);
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 
131 public:
132  static RCReader* instance();
133 
134  // GET METHODS
135  string get_dods_cache_root() const throw()
136  {
137  return d_cache_root;
138  }
139  bool get_use_cache() const throw()
140  {
141  return _dods_use_cache;
142  }
143  int get_max_cache_size() const throw()
144  {
145  return _dods_cache_max;
146  }
147  unsigned int get_max_cached_obj() const throw()
148  {
149  return _dods_cached_obj;
150  }
151  int get_ignore_expires() const throw()
152  {
153  return _dods_ign_expires;
154  }
155  int get_default_expires() const throw()
156  {
157  return _dods_default_expires;
158  }
159  int get_always_validate() const throw()
160  {
161  return _dods_always_validate;
162  }
163  int get_validate_ssl() const throw()
164  {
165  return d_validate_ssl;
166  }
167 
168  bool get_deflate() const throw()
169  {
170  return _dods_deflate;
171  }
172 
174  string get_proxy_server_protocol() const throw()
175  {
176  return d_dods_proxy_server_protocol;
177  }
179  string get_proxy_server_host() const throw()
180  {
181  return d_dods_proxy_server_host;
182  }
184  int get_proxy_server_port() const throw()
185  {
186  return d_dods_proxy_server_port;
187  }
189  string get_proxy_server_userpw() const throw()
190  {
191  return d_dods_proxy_server_userpw;
192  }
194  string get_proxy_server_host_url() const throw()
195  {
196  return (d_dods_proxy_server_userpw.empty() ? "" : d_dods_proxy_server_userpw + "@")
197  + d_dods_proxy_server_host
198  + ":" + long_to_string(d_dods_proxy_server_port);
199  }
200 
201  // The whole regex/proxy-for implementation needs reworking. We really
202  // need a vector of structs which hold the information on a set of regexes
203  // and matching proxies. Then in the code that derefs a URL, we should
204  // check to see if the URL matches any of the regexs, et cetera. I'm
205  // going to disable the entire feature and see if anyone complains. If
206  // they do, we can fix it. If not, one less thing to do... 06/17/04 jhrg
208  bool is_proxy_for_used() throw()
209  {
210  return _dods_proxy_for;
211  }
213  string get_proxy_for_regexp() const throw()
214  {
215  return _dods_proxy_for_regexp;
216  }
218  string get_proxy_for_proxy_host_url() const throw()
219  {
220  return _dods_proxy_for_proxy_host_url;
221  }
222 
224  int get_proxy_for_regexp_flags() const throw()
225  {
226  return _dods_proxy_for_regexp_flags;
227  }
228 
229  // The whole no_proxy implementation also needs a rewrite. However, it is
230  // useful as it is since the user can give a domain and there's often a
231  // real need for suppressing proxy access for the local domain. The
232  // ..._port() method is bogus, however, so it is deprecated. There's no
233  // code that uses it. 06/17/04 jhrg
234  bool is_no_proxy_for_used() throw()
235  {
236  return d_dods_no_proxy_for;
237  }
238  string get_no_proxy_for_protocol() const throw()
239  {
240  return d_dods_no_proxy_for_protocol;
241  }
242  string get_no_proxy_for_host() const throw()
243  {
244  return d_dods_no_proxy_for_host;
245  }
246 
248  int get_no_proxy_for_port() const throw()
249  {
250  return _dods_no_proxy_for_port;
251  }
252 
253  string get_ais_database() const throw()
254  {
255  return d_ais_database;
256  }
257 
258  string get_cookie_jar() const throw()
259  {
260  return d_cookie_jar;
261  }
262 
263  // SET METHODS
264  void set_use_cache(bool b) throw()
265  {
266  _dods_use_cache = b;
267  }
268  void set_max_cache_size(int i) throw()
269  {
270  _dods_cache_max = i;
271  }
272  void set_max_cached_obj(int i) throw()
273  {
274  _dods_cached_obj = i;
275  }
276  void set_ignore_expires(int i) throw()
277  {
278  _dods_ign_expires = i;
279  }
280  void set_default_expires(int i) throw()
281  {
282  _dods_default_expires = i;
283  }
284  void set_always_validate(int i) throw()
285  {
286  _dods_always_validate = i;
287  }
288  void set_validate_ssl(int i) throw()
289  {
290  d_validate_ssl = i;
291  }
292 
293  void set_deflate(bool b) throw()
294  {
295  _dods_deflate = b;
296  }
297 
298  void set_proxy_server_protocol(const string &s) throw()
299  {
300  d_dods_proxy_server_protocol = s;
301  }
302  void set_proxy_server_host(const string &s) throw()
303  {
304  d_dods_proxy_server_host = s;
305  }
306  void set_proxy_server_port(int l) throw()
307  {
308  d_dods_proxy_server_port = l;
309  }
310  void set_proxy_server_userpw(const string &s) throw()
311  {
312  d_dods_proxy_server_userpw = s;
313  }
314 
316  void set_proxy_server_host_url(const string &s) throw()
317  {
318  _dods_proxy_server_host_url = s;
319  }
320 
322  void set_proxy_for_regexp(const string &s) throw()
323  {
324  _dods_proxy_for_regexp = s;
325  }
327  void set_proxy_for_proxy_host_url(const string &s) throw()
328  {
329  _dods_proxy_for_proxy_host_url = s;
330  }
332  void set_proxy_for_regexp_flags(int i) throw()
333  {
334  _dods_proxy_for_regexp_flags = i;
335  }
336 
337  void set_no_proxy_for_protocol(const string &s) throw()
338  {
339  d_dods_no_proxy_for_protocol = s;
340  }
341  void set_no_proxy_for_host(const string &s) throw()
342  {
343  d_dods_no_proxy_for_host = s;
344  }
345 
347  void set_no_proxy_for_port(int i) throw()
348  {
349  _dods_no_proxy_for_port = i;
350  }
351 
352  void set_ais_database(const string &db) throw()
353  {
354  d_ais_database = db;
355  }
356 };
357 
358 } // namespace libdap
359 
360 #endif // _RCReader_h_
string get_proxy_server_userpw() const
Get the proxy username and password.
Definition: RCReader.h:189
bool is_proxy_for_used()
Definition: RCReader.h:208
int get_no_proxy_for_port() const
Definition: RCReader.h:248
void set_ais_database(const string &db)
Definition: RCReader.h:352
void set_proxy_for_regexp(const string &s)
Definition: RCReader.h:322
void set_validate_ssl(int i)
Definition: RCReader.h:288
string get_proxy_server_host() const
Get the proxy host.
Definition: RCReader.h:179
void set_proxy_for_proxy_host_url(const string &s)
Definition: RCReader.h:327
int get_ignore_expires() const
Definition: RCReader.h:151
int get_proxy_for_regexp_flags() const
Definition: RCReader.h:224
void set_proxy_server_host_url(const string &s)
Definition: RCReader.h:316
void set_default_expires(int i)
Definition: RCReader.h:280
void set_no_proxy_for_port(int i)
Definition: RCReader.h:347
string get_ais_database() const
Definition: RCReader.h:253
string get_cookie_jar() const
Definition: RCReader.h:258
void set_no_proxy_for_protocol(const string &s)
Definition: RCReader.h:337
int get_default_expires() const
Definition: RCReader.h:155
void set_proxy_server_userpw(const string &s)
Definition: RCReader.h:310
string get_proxy_for_proxy_host_url() const
Definition: RCReader.h:218
unsigned int get_max_cached_obj() const
Definition: RCReader.h:147
bool get_deflate() const
Definition: RCReader.h:168
int get_max_cache_size() const
Definition: RCReader.h:143
bool is_no_proxy_for_used()
Definition: RCReader.h:234
void set_proxy_for_regexp_flags(int i)
Definition: RCReader.h:332
void set_no_proxy_for_host(const string &s)
Definition: RCReader.h:341
void set_max_cache_size(int i)
Definition: RCReader.h:268
string get_no_proxy_for_protocol() const
Definition: RCReader.h:238
string get_proxy_server_protocol() const
Get the proxy server protocol.
Definition: RCReader.h:174
string long_to_string(long val, int base)
Definition: util.cc:773
void set_proxy_server_port(int l)
Definition: RCReader.h:306
void set_proxy_server_protocol(const string &s)
Definition: RCReader.h:298
int get_proxy_server_port() const
Get the proxy port.
Definition: RCReader.h:184
bool get_use_cache() const
Definition: RCReader.h:139
void set_always_validate(int i)
Definition: RCReader.h:284
int get_always_validate() const
Definition: RCReader.h:159
string get_proxy_for_regexp() const
Definition: RCReader.h:213
string get_proxy_server_host_url() const
Definition: RCReader.h:194
void set_max_cached_obj(int i)
Definition: RCReader.h:272
void set_deflate(bool b)
Definition: RCReader.h:293
int get_validate_ssl() const
Definition: RCReader.h:163
A class for error processing.
Definition: Error.h:90
void set_ignore_expires(int i)
Definition: RCReader.h:276
string get_dods_cache_root() const
Definition: RCReader.h:135
void set_use_cache(bool b)
Definition: RCReader.h:264
string get_no_proxy_for_host() const
Definition: RCReader.h:242
void set_proxy_server_host(const string &s)
Definition: RCReader.h:302