<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libdap++: RCReader.cc Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libdap++ <span id="projectnumber">Updated for version 3.8.2</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('RCReader_8cc.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>RCReader.cc</h1> </div> </div> <div class="contents"> <a href="RCReader_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00002"></a>00002 <span class="comment">// -*- mode: c++; c-basic-offset:4 -*-</span> <a name="l00003"></a>00003 <a name="l00004"></a>00004 <span class="comment">// This file is part of libdap, A C++ implementation of the OPeNDAP Data</span> <a name="l00005"></a>00005 <span class="comment">// Access Protocol.</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="comment">// Copyright (c) 2002,2003 OPeNDAP, Inc.</span> <a name="l00008"></a>00008 <span class="comment">// Author: Jose Garcia <jgarcia@ucar.edu></span> <a name="l00009"></a>00009 <span class="comment">//</span> <a name="l00010"></a>00010 <span class="comment">// This library is free software; you can redistribute it and/or</span> <a name="l00011"></a>00011 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span> <a name="l00012"></a>00012 <span class="comment">// License as published by the Free Software Foundation; either</span> <a name="l00013"></a>00013 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span> <a name="l00014"></a>00014 <span class="comment">//</span> <a name="l00015"></a>00015 <span class="comment">// This library is distributed in the hope that it will be useful,</span> <a name="l00016"></a>00016 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00017"></a>00017 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00018"></a>00018 <span class="comment">// Lesser General Public License for more details.</span> <a name="l00019"></a>00019 <span class="comment">//</span> <a name="l00020"></a>00020 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span> <a name="l00021"></a>00021 <span class="comment">// License along with this library; if not, write to the Free Software</span> <a name="l00022"></a>00022 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> <a name="l00023"></a>00023 <span class="comment">//</span> <a name="l00024"></a>00024 <span class="comment">// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="comment">// (c) COPYRIGHT URI/MIT 2001,2002</span> <a name="l00027"></a>00027 <span class="comment">// Please read the full copyright statement in the file COPYRIGHT_URI.</span> <a name="l00028"></a>00028 <span class="comment">//</span> <a name="l00029"></a>00029 <span class="comment">// Authors:</span> <a name="l00030"></a>00030 <span class="comment">// jose Jose Garcia <jgarcia@ucar.edu></span> <a name="l00031"></a>00031 <a name="l00037"></a>00037 <span class="comment">// #define DODS_DEBUG</span> <a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="config_8h.html">config.h</a>"</span> <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="preprocessor">#include <cstring></span> <a name="l00041"></a>00041 <span class="preprocessor">#include <cstdlib></span> <a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="preprocessor">#include <unistd.h></span> <span class="comment">// for stat</span> <a name="l00044"></a>00044 <span class="preprocessor">#include <sys/types.h></span> <a name="l00045"></a>00045 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="preprocessor">#ifdef WIN32</span> <a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define FALSE 0</span> <a name="l00049"></a>00049 <span class="preprocessor"></span><span class="comment">// Win32 does not define F_OK. 08/21/02 jhrg</span> <a name="l00050"></a>00050 <span class="preprocessor">#define F_OK 0</span> <a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#define DIR_SEP_STRING "\\"</span> <a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#define DIR_SEP_CHAR '\\'</span> <a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#include <direct.h></span> <a name="l00054"></a>00054 <span class="preprocessor">#else</span> <a name="l00055"></a><a class="code" href="RCReader_8cc.html#a08ea4c200c71b80d84d86f88bfa27799">00055</a> <span class="preprocessor"></span><span class="preprocessor">#define DIR_SEP_STRING "/"</span> <a name="l00056"></a><a class="code" href="RCReader_8cc.html#af0f71b00a9472b8a877b7158de47a891">00056</a> <span class="preprocessor"></span><span class="preprocessor">#define DIR_SEP_CHAR '/'</span> <a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00058"></a>00058 <span class="preprocessor"></span> <a name="l00059"></a>00059 <span class="preprocessor">#include <pthread.h></span> <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="preprocessor">#include <fstream></span> <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span> <a name="l00064"></a>00064 <span class="preprocessor">#include "<a class="code" href="RCReader_8h.html">RCReader.h</a>"</span> <a name="l00065"></a>00065 <span class="preprocessor">#include "<a class="code" href="Error_8h.html">Error.h</a>"</span> <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keyword">using namespace </span>std; <a name="l00068"></a>00068 <a name="l00069"></a>00069 <span class="keyword">namespace </span>libdap { <a name="l00070"></a>00070 <a name="l00071"></a>00071 RCReader* RCReader::_instance = 0; <a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="comment">// This variable (instance_control) is used to ensure that in a MT</span> <a name="l00074"></a>00074 <span class="comment">// environment _instance is correctly initialized. See the get_instance</span> <a name="l00075"></a>00075 <span class="comment">// method. 08/07/02 jhrg</span> <a name="l00076"></a>00076 <span class="keyword">static</span> pthread_once_t instance_control = PTHREAD_ONCE_INIT; <a name="l00077"></a>00077 <a name="l00082"></a>00082 <span class="keywordtype">bool</span> <a name="l00083"></a>00083 RCReader::write_rc_file(<span class="keyword">const</span> <span class="keywordtype">string</span> &pathname) <a name="l00084"></a>00084 { <a name="l00085"></a>00085 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Writing the RC file to "</span> << pathname << endl); <a name="l00086"></a>00086 ofstream fpo(pathname.c_str()); <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="comment">// If the file couldn't be created. Nothing needs to be done here,</span> <a name="l00089"></a>00089 <span class="comment">// the program will simply use the defaults.</span> <a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="keywordflow">if</span> (fpo) { <a name="l00092"></a>00092 <span class="comment">// This means we just created the file. We will now save</span> <a name="l00093"></a>00093 <span class="comment">// the defaults in it for future use.</span> <a name="l00094"></a>00094 fpo << <span class="stringliteral">"# OPeNDAP client configuration file. See the OPeNDAP"</span> << endl; <a name="l00095"></a>00095 fpo << <span class="stringliteral">"# users guide for information."</span> << endl; <a name="l00096"></a>00096 fpo << <span class="stringliteral">"USE_CACHE="</span> << _dods_use_cache << endl; <a name="l00097"></a>00097 fpo << <span class="stringliteral">"# Cache and object size are given in megabytes (20 ==> 20Mb)."</span> <a name="l00098"></a>00098 << endl; <a name="l00099"></a>00099 fpo << <span class="stringliteral">"MAX_CACHE_SIZE="</span> << _dods_cache_max << endl; <a name="l00100"></a>00100 fpo << <span class="stringliteral">"MAX_CACHED_OBJ="</span> << _dods_cached_obj << endl; <a name="l00101"></a>00101 fpo << <span class="stringliteral">"IGNORE_EXPIRES="</span> << _dods_ign_expires << endl; <a name="l00102"></a>00102 fpo << <span class="stringliteral">"CACHE_ROOT="</span> << d_cache_root << endl; <a name="l00103"></a>00103 fpo << <span class="stringliteral">"DEFAULT_EXPIRES="</span> << _dods_default_expires << endl; <a name="l00104"></a>00104 fpo << <span class="stringliteral">"ALWAYS_VALIDATE="</span> << _dods_always_validate << endl; <a name="l00105"></a>00105 fpo << <span class="stringliteral">"# Request servers compress responses if possible?"</span> << endl; <a name="l00106"></a>00106 fpo << <span class="stringliteral">"# 1 (yes) or 0 (false)."</span> << endl; <a name="l00107"></a>00107 fpo << <span class="stringliteral">"DEFLATE="</span> << _dods_deflate << endl; <a name="l00108"></a>00108 <a name="l00109"></a>00109 fpo << <span class="stringliteral">"# Should SSL certificates and hosts be validated? SSL"</span> << endl; <a name="l00110"></a>00110 fpo << <span class="stringliteral">"# will only work with signed certificates."</span> << endl; <a name="l00111"></a>00111 fpo << <span class="stringliteral">"VALIDATE_SSL="</span> << d_validate_ssl << endl; <a name="l00112"></a>00112 <a name="l00113"></a>00113 fpo << <span class="stringliteral">"# Proxy configuration (optional parts in []s)."</span> << endl; <a name="l00114"></a>00114 fpo << <span class="stringliteral">"# You may also use the 'http_proxy' environment variable"</span> <a name="l00115"></a>00115 << endl; <a name="l00116"></a>00116 fpo << <span class="stringliteral">"# but a value in this file will override that env variable."</span> <a name="l00117"></a>00117 << endl; <a name="l00118"></a>00118 fpo << <span class="stringliteral">"# PROXY_SERVER=[http://][username:password@]host[:port]"</span> <a name="l00119"></a>00119 << endl; <a name="l00120"></a>00120 <span class="keywordflow">if</span> (!d_dods_proxy_server_host.empty()) { <a name="l00121"></a>00121 fpo << <span class="stringliteral">"PROXY_SERVER="</span> << d_dods_proxy_server_protocol << <span class="stringliteral">"://"</span> <a name="l00122"></a>00122 << (d_dods_proxy_server_userpw.empty() <a name="l00123"></a>00123 ? <span class="stringliteral">""</span> <a name="l00124"></a>00124 : d_dods_proxy_server_userpw + <span class="stringliteral">"@"</span>) <a name="l00125"></a>00125 + d_dods_proxy_server_host <a name="l00126"></a>00126 + <span class="stringliteral">":"</span> + <a class="code" href="namespacelibdap.html#a317edea830aab50d2137a5bd313cc86a">long_to_string</a>(d_dods_proxy_server_port) << endl; <a name="l00127"></a>00127 } <a name="l00128"></a>00128 <a name="l00129"></a>00129 fpo << <span class="stringliteral">"# NO_PROXY_FOR=<host|domain>"</span> << endl; <a name="l00130"></a>00130 <span class="keywordflow">if</span> (!d_dods_no_proxy_for_host.empty()) { <a name="l00131"></a>00131 fpo << <span class="stringliteral">"NO_PROXY_FOR="</span> << d_dods_no_proxy_for_host << endl; <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <a name="l00134"></a>00134 fpo << <span class="stringliteral">"# AIS_DATABASE=<file or url>"</span> << endl; <a name="l00135"></a>00135 <a name="l00136"></a>00136 fpo << <span class="stringliteral">"# COOKIE_JAR=.dods_cookies"</span> << endl; <a name="l00137"></a>00137 fpo << <span class="stringliteral">"# The cookie jar is a file that holds cookies sent from"</span> <a name="l00138"></a>00138 << endl; <a name="l00139"></a>00139 fpo << <span class="stringliteral">"# servers such as single signon systems. Uncomment this"</span> <a name="l00140"></a>00140 << endl; <a name="l00141"></a>00141 fpo << <span class="stringliteral">"# option and provide a file name to activate this feature."</span> <a name="l00142"></a>00142 << endl; <a name="l00143"></a>00143 fpo << <span class="stringliteral">"# If the value is a filename, it will be created in this"</span> <a name="l00144"></a>00144 << endl; <a name="l00145"></a>00145 fpo << <span class="stringliteral">"# directory; a full pathname can be used to force a specific"</span> <a name="l00146"></a>00146 << endl; <a name="l00147"></a>00147 fpo << <span class="stringliteral">"# location."</span> << endl; <a name="l00148"></a>00148 <a name="l00149"></a>00149 fpo.close(); <a name="l00150"></a>00150 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <a name="l00153"></a>00153 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00154"></a>00154 } <a name="l00155"></a>00155 <a name="l00156"></a>00156 <span class="keywordtype">bool</span> <a name="l00157"></a>00157 RCReader::read_rc_file(<span class="keyword">const</span> <span class="keywordtype">string</span> &pathname) <a name="l00158"></a>00158 { <a name="l00159"></a>00159 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Reading the RC file from "</span> << pathname << endl); <a name="l00160"></a>00160 <a name="l00161"></a>00161 ifstream fpi(pathname.c_str()); <a name="l00162"></a>00162 <span class="keywordflow">if</span> (fpi) { <a name="l00163"></a>00163 <span class="comment">// The file exists and we may now begin to parse it.</span> <a name="l00164"></a>00164 <span class="comment">// Defaults are already stored in the variables, if the correct</span> <a name="l00165"></a>00165 <span class="comment">// tokens are found in the file then those defaults will be</span> <a name="l00166"></a>00166 <span class="comment">// overwritten.</span> <a name="l00167"></a>00167 <span class="keywordtype">char</span> *value; <a name="l00168"></a>00168 <span class="keywordtype">char</span> *tempstr = <span class="keyword">new</span> <span class="keywordtype">char</span>[1024];; <a name="l00169"></a>00169 <span class="keywordtype">int</span> tokenlength; <a name="l00170"></a>00170 <span class="keywordflow">while</span> (<span class="keyword">true</span>) { <a name="l00171"></a>00171 fpi.getline(tempstr, 1023); <a name="l00172"></a>00172 <span class="keywordflow">if</span> (!fpi.good()) <a name="l00173"></a>00173 <span class="keywordflow">break</span>; <a name="l00174"></a>00174 <a name="l00175"></a>00175 value = strchr(tempstr, <span class="charliteral">'='</span>); <a name="l00176"></a>00176 <span class="keywordflow">if</span> (!value) <a name="l00177"></a>00177 <span class="keywordflow">continue</span>; <a name="l00178"></a>00178 tokenlength = value - tempstr; <a name="l00179"></a>00179 value++; <a name="l00180"></a>00180 <a name="l00181"></a>00181 <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"USE_CACHE"</span>, 9) == 0) <a name="l00182"></a>00182 && tokenlength == 9) { <a name="l00183"></a>00183 _dods_use_cache = atoi(value) ? <span class="keyword">true</span> : <span class="keyword">false</span>; <a name="l00184"></a>00184 } <a name="l00185"></a>00185 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"MAX_CACHE_SIZE"</span>, 14) == 0) <a name="l00186"></a>00186 && tokenlength == 14) { <a name="l00187"></a>00187 _dods_cache_max = atoi(value); <a name="l00188"></a>00188 } <a name="l00189"></a>00189 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"MAX_CACHED_OBJ"</span>, 14) == 0) <a name="l00190"></a>00190 && tokenlength == 14) { <a name="l00191"></a>00191 _dods_cached_obj = atoi(value); <a name="l00192"></a>00192 } <a name="l00193"></a>00193 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"IGNORE_EXPIRES"</span>, 14) == 0) <a name="l00194"></a>00194 && tokenlength == 14) { <a name="l00195"></a>00195 _dods_ign_expires = atoi(value); <a name="l00196"></a>00196 } <a name="l00197"></a>00197 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"DEFLATE"</span>, 7) == 0) <a name="l00198"></a>00198 && tokenlength == 7) { <a name="l00199"></a>00199 _dods_deflate = atoi(value) ? <span class="keyword">true</span> : <span class="keyword">false</span>; <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"CACHE_ROOT"</span>, 10) == 0) <a name="l00202"></a>00202 && tokenlength == 10) { <a name="l00203"></a>00203 d_cache_root = value; <a name="l00204"></a>00204 <span class="keywordflow">if</span> (d_cache_root[d_cache_root.length() - 1] != <a class="code" href="RCReader_8cc.html#af0f71b00a9472b8a877b7158de47a891">DIR_SEP_CHAR</a>) <a name="l00205"></a>00205 d_cache_root += <span class="keywordtype">string</span>(<a class="code" href="RCReader_8cc.html#a08ea4c200c71b80d84d86f88bfa27799">DIR_SEP_STRING</a>); <a name="l00206"></a>00206 } <a name="l00207"></a>00207 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"DEFAULT_EXPIRES"</span>, 15) == 0) <a name="l00208"></a>00208 && tokenlength == 15) { <a name="l00209"></a>00209 _dods_default_expires = atoi(value); <a name="l00210"></a>00210 } <a name="l00211"></a>00211 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"ALWAYS_VALIDATE"</span>, 15) == 0) <a name="l00212"></a>00212 && tokenlength == 15) { <a name="l00213"></a>00213 _dods_always_validate = atoi(value); <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"VALIDATE_SSL"</span>, 12) == 0) <a name="l00216"></a>00216 && tokenlength == 12) { <a name="l00217"></a>00217 d_validate_ssl = atoi(value); <a name="l00218"></a>00218 } <a name="l00219"></a>00219 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(tempstr, <span class="stringliteral">"AIS_DATABASE"</span>, 12) == 0 <a name="l00220"></a>00220 && tokenlength == 12) { <a name="l00221"></a>00221 d_ais_database = value; <a name="l00222"></a>00222 } <a name="l00223"></a>00223 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(tempstr, <span class="stringliteral">"COOKIE_JAR"</span>, 10) == 0 <a name="l00224"></a>00224 && tokenlength == 10) { <a name="l00225"></a>00225 <span class="comment">// if the value of COOKIE_JAR starts with a slash, use it as</span> <a name="l00226"></a>00226 <span class="comment">// is. However, if it does not start with a slash, prefix it</span> <a name="l00227"></a>00227 <span class="comment">// with the directory that contains the .dodsrc file.</span> <a name="l00228"></a>00228 <span class="keywordflow">if</span> (value[0] == <span class="charliteral">'/'</span>) { <a name="l00229"></a>00229 d_cookie_jar = value; <a name="l00230"></a>00230 } <a name="l00231"></a>00231 <span class="keywordflow">else</span> { <a name="l00232"></a>00232 d_cookie_jar = d_rc_file_path.substr(0, d_rc_file_path.find(<span class="stringliteral">".dodsrc"</span>)) + <span class="keywordtype">string</span>(value); <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"set cookie jar to: "</span> << d_cookie_jar << endl); <a name="l00235"></a>00235 } <a name="l00236"></a>00236 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"PROXY_SERVER"</span>, 12) == 0) <a name="l00237"></a>00237 && tokenlength == 12) { <a name="l00238"></a>00238 <span class="comment">// Setup a proxy server for all requests.</span> <a name="l00239"></a>00239 <span class="comment">// The original syntax was <protocol>,<machine> where the</span> <a name="l00240"></a>00240 <span class="comment">// machine could also contain the user/pass and port info.</span> <a name="l00241"></a>00241 <span class="comment">// Support that but also support machine prefixed by</span> <a name="l00242"></a>00242 <span class="comment">// 'http://' with and without the '<protocol>,' prefix. jhrg</span> <a name="l00243"></a>00243 <span class="comment">// 4/21/08 (see bug 1095).</span> <a name="l00244"></a>00244 <span class="keywordtype">string</span> proxy = value; <a name="l00245"></a>00245 string::size_type comma = proxy.find(<span class="charliteral">','</span>); <a name="l00246"></a>00246 <a name="l00247"></a>00247 <span class="comment">// Since the <protocol> is now optional, the comma might be</span> <a name="l00248"></a>00248 <span class="comment">// here. If it is, check that the protocol given is http.</span> <a name="l00249"></a>00249 <span class="keywordflow">if</span> (comma != string::npos) { <a name="l00250"></a>00250 d_dods_proxy_server_protocol = proxy.substr(0, comma); <a name="l00251"></a>00251 <a class="code" href="namespacelibdap.html#a7edce266869606fc7bb46124f8d63809">downcase</a>(d_dods_proxy_server_protocol); <a name="l00252"></a>00252 <span class="keywordflow">if</span> (d_dods_proxy_server_protocol != <span class="stringliteral">"http"</span>) <a name="l00253"></a>00253 <span class="keywordflow">throw</span> Error(<span class="stringliteral">"The only supported protocol for a proxy server is \"HTTP\". Correct your \".dodsrc\" file."</span>); <a name="l00254"></a>00254 proxy = proxy.substr(comma + 1); <a name="l00255"></a>00255 } <a name="l00256"></a>00256 <span class="keywordflow">else</span> { <a name="l00257"></a>00257 d_dods_proxy_server_protocol = <span class="stringliteral">"http"</span>; <a name="l00258"></a>00258 } <a name="l00259"></a>00259 <a name="l00260"></a>00260 <span class="comment">// Look for a 'protocol://' prefix; skip if found</span> <a name="l00261"></a>00261 string::size_type protocol = proxy.find(<span class="stringliteral">"://"</span>); <a name="l00262"></a>00262 <span class="keywordflow">if</span> (protocol != string::npos) { <a name="l00263"></a>00263 proxy = proxy.substr(protocol + 3); <a name="l00264"></a>00264 } <a name="l00265"></a>00265 <a name="l00266"></a>00266 <span class="comment">// Break apart into userpw, host and port.</span> <a name="l00267"></a>00267 string::size_type at_sign = proxy.find(<span class="charliteral">'@'</span>); <a name="l00268"></a>00268 <span class="keywordflow">if</span> (at_sign != string::npos) { <span class="comment">// has userpw</span> <a name="l00269"></a>00269 d_dods_proxy_server_userpw = proxy.substr(0, at_sign); <a name="l00270"></a>00270 proxy = proxy.substr(at_sign + 1); <a name="l00271"></a>00271 } <a name="l00272"></a>00272 <span class="keywordflow">else</span> <a name="l00273"></a>00273 d_dods_proxy_server_userpw = <span class="stringliteral">""</span>; <a name="l00274"></a>00274 <a name="l00275"></a>00275 <span class="comment">// Get host and look for a port number</span> <a name="l00276"></a>00276 string::size_type colon = proxy.find(<span class="charliteral">':'</span>); <a name="l00277"></a>00277 <span class="keywordflow">if</span> (colon != string::npos) { <a name="l00278"></a>00278 d_dods_proxy_server_host = proxy.substr(0, colon); <a name="l00279"></a>00279 d_dods_proxy_server_port <a name="l00280"></a>00280 = strtol(proxy.substr(colon + 1).c_str(), 0, 0); <a name="l00281"></a>00281 } <a name="l00282"></a>00282 <span class="keywordflow">else</span> { <a name="l00283"></a>00283 d_dods_proxy_server_host = proxy; <a name="l00284"></a>00284 d_dods_proxy_server_port = 80; <a name="l00285"></a>00285 } <a name="l00286"></a>00286 } <a name="l00287"></a>00287 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strncmp(tempstr, <span class="stringliteral">"NO_PROXY_FOR"</span>, 12) == 0) <a name="l00288"></a>00288 && tokenlength == 12) { <a name="l00289"></a>00289 <span class="comment">// Setup a proxy server for all requests.</span> <a name="l00290"></a>00290 <span class="keywordtype">string</span> no_proxy = value; <a name="l00291"></a>00291 string::size_type comma = no_proxy.find(<span class="charliteral">','</span>); <a name="l00292"></a>00292 <a name="l00293"></a>00293 <span class="comment">// Since the protocol is required, the comma *must* be</span> <a name="l00294"></a>00294 <span class="comment">// present. We could throw an Error on the malformed line...</span> <a name="l00295"></a>00295 <span class="keywordflow">if</span> (comma == string::npos) { <a name="l00296"></a>00296 d_dods_no_proxy_for_protocol = <span class="stringliteral">"http"</span>; <a name="l00297"></a>00297 d_dods_no_proxy_for_host = no_proxy; <a name="l00298"></a>00298 d_dods_no_proxy_for = <span class="keyword">true</span>; <a name="l00299"></a>00299 } <a name="l00300"></a>00300 <span class="keywordflow">else</span> { <a name="l00301"></a>00301 d_dods_no_proxy_for_protocol = no_proxy.substr(0, comma); <a name="l00302"></a>00302 d_dods_no_proxy_for_host = no_proxy.substr(comma + 1); <a name="l00303"></a>00303 d_dods_no_proxy_for = <span class="keyword">true</span>; <a name="l00304"></a>00304 } <a name="l00305"></a>00305 } <a name="l00306"></a>00306 } <a name="l00307"></a>00307 <a name="l00308"></a>00308 <span class="keyword">delete</span> [] tempstr; tempstr = 0; <a name="l00309"></a>00309 <a name="l00310"></a>00310 fpi.close(); <span class="comment">// Close the .dodsrc file. 12/14/99 jhrg</span> <a name="l00311"></a>00311 <a name="l00312"></a>00312 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00313"></a>00313 } <span class="comment">// End of cache file parsing.</span> <a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00316"></a>00316 } <a name="l00317"></a>00317 <a name="l00318"></a>00318 <span class="comment">// Helper for check_env_var(). This is its main logic, separated out for the</span> <a name="l00319"></a>00319 <span class="comment">// cases under WIN32 where we don't use an environment variable. 09/19/03</span> <a name="l00320"></a>00320 <span class="comment">// jhrg</span> <a name="l00321"></a>00321 <span class="keywordtype">string</span> <a name="l00322"></a>00322 RCReader::check_string(<span class="keywordtype">string</span> env_var) <a name="l00323"></a>00323 { <a name="l00324"></a>00324 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Entering check_string... ("</span> << env_var << <span class="stringliteral">")"</span> << endl); <a name="l00325"></a>00325 <span class="keyword">struct </span>stat stat_info; <a name="l00326"></a>00326 <a name="l00327"></a>00327 <span class="keywordflow">if</span> (stat(env_var.c_str(), &stat_info) != 0) { <a name="l00328"></a>00328 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"stat returned non-zero"</span> << endl); <a name="l00329"></a>00329 <span class="keywordflow">return</span> <span class="stringliteral">""</span>; <span class="comment">// ENV VAR not a file or dir, bail</span> <a name="l00330"></a>00330 } <a name="l00331"></a>00331 <a name="l00332"></a>00332 <span class="keywordflow">if</span> (S_ISREG(stat_info.st_mode)) { <a name="l00333"></a>00333 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"S_ISREG: "</span> << S_ISREG(stat_info.st_mode) << endl); <a name="l00334"></a>00334 <span class="keywordflow">return</span> env_var; <span class="comment">// ENV VAR is a file, use it</span> <a name="l00335"></a>00335 } <a name="l00336"></a>00336 <a name="l00337"></a>00337 <span class="comment">// ENV VAR is a directory, does it contain .dodsrc? Can we create</span> <a name="l00338"></a>00338 <span class="comment">// .dodsrc if it's not there?</span> <a name="l00339"></a>00339 <span class="keywordflow">if</span> (S_ISDIR(stat_info.st_mode)) { <a name="l00340"></a>00340 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"S_ISDIR: "</span> << S_ISDIR(stat_info.st_mode) << endl); <a name="l00341"></a>00341 <span class="keywordflow">if</span> (*env_var.rbegin() != <a class="code" href="RCReader_8cc.html#af0f71b00a9472b8a877b7158de47a891">DIR_SEP_CHAR</a>) <span class="comment">// Add trailing / if missing</span> <a name="l00342"></a>00342 env_var += <a class="code" href="RCReader_8cc.html#a08ea4c200c71b80d84d86f88bfa27799">DIR_SEP_STRING</a>; <a name="l00343"></a>00343 <span class="comment">// Trick: set d_cache_root here in case we're going to create the</span> <a name="l00344"></a>00344 <span class="comment">// .dodsrc later on. If the .dodsrc file exists, its value will</span> <a name="l00345"></a>00345 <span class="comment">// overwrite this value, if not write_rc_file() will use the correct</span> <a name="l00346"></a>00346 <span class="comment">// value. 09/19/03 jhrg</span> <a name="l00347"></a>00347 d_cache_root = env_var + string(<span class="stringliteral">".dods_cache"</span>) + <a class="code" href="RCReader_8cc.html#a08ea4c200c71b80d84d86f88bfa27799">DIR_SEP_STRING</a>; <a name="l00348"></a>00348 env_var += <span class="stringliteral">".dodsrc"</span>; <a name="l00349"></a>00349 <span class="keywordflow">if</span> (stat(env_var.c_str(), &stat_info) == 0 && <a name="l00350"></a>00350 S_ISREG(stat_info.st_mode)) { <a name="l00351"></a>00351 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Found .dodsrc in \""</span> << env_var << <span class="stringliteral">"\""</span> << endl); <a name="l00352"></a>00352 <span class="keywordflow">return</span> env_var; <span class="comment">// Found .dodsrc in ENV VAR</span> <a name="l00353"></a>00353 } <a name="l00354"></a>00354 <a name="l00355"></a>00355 <span class="comment">// Didn't find .dodsrc in ENV VAR and ENV VAR is a directory; try to</span> <a name="l00356"></a>00356 <span class="comment">// create it. Note write_rc_file uses d_cache_root (set above) when</span> <a name="l00357"></a>00357 <span class="comment">// it creates the RC file's contents.</span> <a name="l00358"></a>00358 <span class="keywordflow">if</span> (write_rc_file(env_var)) { <a name="l00359"></a>00359 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Wrote .dodsrc in \""</span> << env_var << <span class="stringliteral">"\""</span> << endl); <a name="l00360"></a>00360 <span class="keywordflow">return</span> env_var; <a name="l00361"></a>00361 } <a name="l00362"></a>00362 } <a name="l00363"></a>00363 <a name="l00364"></a>00364 <span class="comment">// If we're here, then we've neither found nor created the RC file.</span> <a name="l00365"></a>00365 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"could neither find nor create a .dodsrc file"</span> << endl); <a name="l00366"></a>00366 <span class="keywordflow">return</span> <span class="stringliteral">""</span>; <a name="l00367"></a>00367 } <a name="l00368"></a>00368 <a name="l00378"></a>00378 <span class="keywordtype">string</span> <a name="l00379"></a>00379 RCReader::check_env_var(<span class="keyword">const</span> <span class="keywordtype">string</span> &variable_name) <a name="l00380"></a>00380 { <a name="l00381"></a>00381 <span class="keywordtype">char</span> *ev = getenv(variable_name.c_str()); <a name="l00382"></a>00382 <span class="keywordflow">if</span> (!ev || strlen(ev) == 0) <a name="l00383"></a>00383 <span class="keywordflow">return</span> <span class="stringliteral">""</span>; <a name="l00384"></a>00384 <a name="l00385"></a>00385 <span class="keywordflow">return</span> check_string(ev); <a name="l00386"></a>00386 } <a name="l00387"></a>00387 <a name="l00388"></a>00388 RCReader::RCReader() <span class="keywordflow">throw</span>(Error) <a name="l00389"></a>00389 { <a name="l00390"></a>00390 d_rc_file_path = <span class="stringliteral">""</span>; <a name="l00391"></a>00391 d_cache_root = <span class="stringliteral">""</span>; <a name="l00392"></a>00392 <a name="l00393"></a>00393 <span class="comment">// ** Set default values **</span> <a name="l00394"></a>00394 <span class="comment">// Users must explicitly turn caching on.</span> <a name="l00395"></a>00395 _dods_use_cache = <span class="keyword">false</span>; <a name="l00396"></a>00396 _dods_cache_max = 20; <a name="l00397"></a>00397 _dods_cached_obj = 5; <a name="l00398"></a>00398 _dods_ign_expires = 0; <a name="l00399"></a>00399 _dods_default_expires = 86400; <a name="l00400"></a>00400 _dods_always_validate = 0; <a name="l00401"></a>00401 <a name="l00402"></a>00402 _dods_deflate = 0; <a name="l00403"></a>00403 d_validate_ssl = 1; <a name="l00404"></a>00404 <a name="l00405"></a>00405 <span class="comment">//flags for PROXY_SERVER=<protocol>,<host url></span> <a name="l00406"></a>00406 <span class="comment">// New syntax PROXY_SERVER=[http://][user:pw@]host[:port]</span> <a name="l00407"></a>00407 d_dods_proxy_server_protocol = <span class="stringliteral">""</span>; <a name="l00408"></a>00408 d_dods_proxy_server_host = <span class="stringliteral">""</span>; <a name="l00409"></a>00409 d_dods_proxy_server_port = 0; <a name="l00410"></a>00410 d_dods_proxy_server_userpw = <span class="stringliteral">""</span>; <a name="l00411"></a>00411 <a name="l00412"></a>00412 _dods_proxy_server_host_url = <span class="stringliteral">""</span>; <span class="comment">// deprecated</span> <a name="l00413"></a>00413 <a name="l00414"></a>00414 <span class="comment">// PROXY_FOR is deprecated.</span> <a name="l00415"></a>00415 <span class="comment">// flags for PROXY_FOR=<regex>,<proxy host url>,<flags></span> <a name="l00416"></a>00416 _dods_proxy_for = <span class="keyword">false</span>; <span class="comment">// true if proxy_for is used.</span> <a name="l00417"></a>00417 _dods_proxy_for_regexp = <span class="stringliteral">""</span>; <a name="l00418"></a>00418 _dods_proxy_for_proxy_host_url = <span class="stringliteral">""</span>; <a name="l00419"></a>00419 _dods_proxy_for_regexp_flags = 0; <a name="l00420"></a>00420 <a name="l00421"></a>00421 <span class="comment">//flags for NO_PROXY_FOR=<protocol>,<host>,<port></span> <a name="l00422"></a>00422 <span class="comment">// New syntax NO_PROXY_FOR=<host|domain></span> <a name="l00423"></a>00423 d_dods_no_proxy_for = <span class="keyword">false</span>; <a name="l00424"></a>00424 d_dods_no_proxy_for_protocol = <span class="stringliteral">""</span>; <span class="comment">// deprecated</span> <a name="l00425"></a>00425 d_dods_no_proxy_for_host = <span class="stringliteral">""</span>; <a name="l00426"></a>00426 <span class="comment">// default to port 0 if not specified. This means all ports. Using 80</span> <a name="l00427"></a>00427 <span class="comment">// will fail when the URL does not contain the port number. That's</span> <a name="l00428"></a>00428 <span class="comment">// probably a bug in libwww. 10/23/2000 jhrg</span> <a name="l00429"></a>00429 _dods_no_proxy_for_port = 0; <span class="comment">// deprecated</span> <a name="l00430"></a>00430 <a name="l00431"></a>00431 d_cookie_jar = <span class="stringliteral">""</span>; <a name="l00432"></a>00432 <a name="l00433"></a>00433 <span class="preprocessor">#ifdef WIN32</span> <a name="l00434"></a>00434 <span class="preprocessor"></span> <span class="keywordtype">string</span> homedir = string(<span class="stringliteral">"C:"</span>) + string(<a class="code" href="RCReader_8cc.html#a08ea4c200c71b80d84d86f88bfa27799">DIR_SEP_STRING</a>) + string(<span class="stringliteral">"Dods"</span>); <a name="l00435"></a>00435 d_rc_file_path = check_string(homedir); <a name="l00436"></a>00436 <span class="keywordflow">if</span> (d_rc_file_path.empty()) { <a name="l00437"></a>00437 homedir = string(<span class="stringliteral">"C:"</span>) + string(<a class="code" href="RCReader_8cc.html#a08ea4c200c71b80d84d86f88bfa27799">DIR_SEP_STRING</a>) + string(<span class="stringliteral">"opendap"</span>); <a name="l00438"></a>00438 d_rc_file_path = check_string(homedir); <a name="l00439"></a>00439 } <a name="l00440"></a>00440 <span class="comment">// Normally, I'd prefer this for WinNT-based systems.</span> <a name="l00441"></a>00441 <span class="keywordflow">if</span> (d_rc_file_path.empty()) <a name="l00442"></a>00442 d_rc_file_path = check_env_var(<span class="stringliteral">"APPDATA"</span>); <a name="l00443"></a>00443 <span class="keywordflow">if</span> (d_rc_file_path.empty()) <a name="l00444"></a>00444 d_rc_file_path = check_env_var(<span class="stringliteral">"TEMP"</span>); <a name="l00445"></a>00445 <span class="keywordflow">if</span> (d_rc_file_path.empty()) <a name="l00446"></a>00446 d_rc_file_path = check_env_var(<span class="stringliteral">"TMP"</span>); <a name="l00447"></a>00447 <span class="preprocessor">#else</span> <a name="l00448"></a>00448 <span class="preprocessor"></span> d_rc_file_path = check_env_var(<span class="stringliteral">"DODS_CONF"</span>); <a name="l00449"></a>00449 <span class="keywordflow">if</span> (d_rc_file_path.empty()) <a name="l00450"></a>00450 d_rc_file_path = check_env_var(<span class="stringliteral">"HOME"</span>); <a name="l00451"></a>00451 <span class="preprocessor">#endif</span> <a name="l00452"></a>00452 <span class="preprocessor"></span> <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Looking for .dodsrc in: "</span> << d_rc_file_path << endl); <a name="l00453"></a>00453 <a name="l00454"></a>00454 <span class="keywordflow">if</span> (!d_rc_file_path.empty()) <a name="l00455"></a>00455 read_rc_file(d_rc_file_path); <a name="l00456"></a>00456 } <a name="l00457"></a>00457 <a name="l00458"></a>00458 RCReader::~RCReader() <a name="l00459"></a>00459 {} <a name="l00460"></a>00460 <a name="l00462"></a>00462 <span class="keywordtype">void</span> <a name="l00463"></a>00463 RCReader::delete_instance() <a name="l00464"></a>00464 { <a name="l00465"></a>00465 <span class="keywordflow">if</span> (RCReader::_instance) { <a name="l00466"></a>00466 <span class="keyword">delete</span> RCReader::_instance; <a name="l00467"></a>00467 RCReader::_instance = 0; <a name="l00468"></a>00468 } <a name="l00469"></a>00469 } <a name="l00470"></a>00470 <a name="l00472"></a>00472 <span class="keywordtype">void</span> <a name="l00473"></a>00473 RCReader::initialize_instance() <a name="l00474"></a>00474 { <a name="l00475"></a>00475 <a class="code" href="debug_8h.html#a0d28d57d1228cf13a4c1288cc4758344">DBGN</a>(cerr << <span class="stringliteral">"RCReader::initialize_instance() ... "</span>); <a name="l00476"></a>00476 <a name="l00477"></a>00477 RCReader::_instance = <span class="keyword">new</span> RCReader; <a name="l00478"></a>00478 atexit(RCReader::delete_instance); <a name="l00479"></a>00479 <a name="l00480"></a>00480 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"exiting."</span> << endl); <a name="l00481"></a>00481 } <a name="l00482"></a>00482 <a name="l00483"></a>00483 RCReader* <a name="l00484"></a><a class="code" href="classlibdap_1_1RCReader.html#a8272ec2f2eae73a038d21bfcd0c23fd3">00484</a> RCReader::instance() <a name="l00485"></a>00485 { <a name="l00486"></a>00486 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Entring RCReader::instance"</span> << endl); <a name="l00487"></a>00487 <span class="comment">// The instance_control variable is defined at the top of this file.</span> <a name="l00488"></a>00488 <span class="comment">// 08/07/02 jhrg</span> <a name="l00489"></a>00489 pthread_once(&instance_control, initialize_instance); <a name="l00490"></a>00490 <a name="l00491"></a>00491 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Instance value: "</span> << hex << _instance << dec << endl); <a name="l00492"></a>00492 <a name="l00493"></a>00493 <span class="keywordflow">return</span> _instance; <a name="l00494"></a>00494 } <a name="l00495"></a>00495 <a name="l00496"></a>00496 } <span class="comment">// namespace libdap</span> </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="RCReader_8cc.html">RCReader.cc</a> </li> <li class="footer">Generated on Tue Feb 8 2011 for libdap++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>