37 #include <curl/curl.h>
43 #include <BESCatalogUtils.h>
44 #include <BESCatalogList.h>
45 #include <BESCatalog.h>
47 #include <TheBESKeys.h>
48 #include <BESInternalError.h>
49 #include <BESDapError.h>
50 #include <BESNotFoundError.h>
51 #include <BESSyntaxUserError.h>
54 #include "HttpdCatalogNames.h"
55 #include "HttpdCatalogUtils.h"
60 namespace httpd_catalog {
63 map<string, string> HttpdCatalogUtils::MimeList;
64 string HttpdCatalogUtils::ProxyProtocol;
65 string HttpdCatalogUtils::ProxyHost;
66 string HttpdCatalogUtils::ProxyUser;
67 string HttpdCatalogUtils::ProxyPassword;
68 string HttpdCatalogUtils::ProxyUserPW;
70 int HttpdCatalogUtils::ProxyPort = 0;
71 int HttpdCatalogUtils::ProxyAuthType = 0;
72 bool HttpdCatalogUtils::useInternalCache =
false;
74 string HttpdCatalogUtils::NoProxyRegex;
76 #define prolog string("HttpCatalogUtils::").append(__func__).append("() - ")
80 void HttpdCatalogUtils::initialize()
84 string key = HTTPD_CATALOG_MIMELIST;
87 if (found && vals.size()) {
88 vector<string>::iterator i = vals.begin();
89 vector<string>::iterator e = vals.end();
91 size_t colon = (*i).find(
":");
92 if (colon == string::npos) {
93 string err = (string)
"Malformed " + HTTPD_CATALOG_MIMELIST +
" " + (*i) +
" specified in the gateway configuration";
96 string mod = (*i).substr(0, colon);
97 string mime = (*i).substr(colon + 1);
103 key = HTTPD_CATALOG_PROXYHOST;
105 if (found && !HttpdCatalogUtils::ProxyHost.empty()) {
109 key = HTTPD_CATALOG_PROXYPORT;
112 if (found && !port.empty()) {
113 HttpdCatalogUtils::ProxyPort = atoi(port.c_str());
114 if (!HttpdCatalogUtils::ProxyPort) {
115 string err = (string)
"httpd catalog proxy host is specified, but specified port is absent";
123 key = HTTPD_CATALOG_PROXYPROTOCOL;
125 if (!found || HttpdCatalogUtils::ProxyProtocol.empty()) {
126 HttpdCatalogUtils::ProxyProtocol =
"http";
132 key = HTTPD_CATALOG_PROXYUSER;
135 HttpdCatalogUtils::ProxyUser =
"";
141 key = HTTPD_CATALOG_PROXYPASSWORD;
144 HttpdCatalogUtils::ProxyPassword =
"";
150 key = HTTPD_CATALOG_PROXYUSERPW;
153 HttpdCatalogUtils::ProxyUserPW =
"";
159 key = HTTPD_CATALOG_PROXYAUTHTYPE;
164 if (authType ==
"basic") {
165 HttpdCatalogUtils::ProxyAuthType = CURLAUTH_BASIC;
166 BESDEBUG(MODULE, prolog <<
"ProxyAuthType BASIC set." << endl);
168 else if (authType ==
"digest") {
169 HttpdCatalogUtils::ProxyAuthType = CURLAUTH_DIGEST;
170 BESDEBUG(MODULE, prolog <<
"ProxyAuthType DIGEST set." << endl);
173 else if (authType ==
"ntlm") {
174 HttpdCatalogUtils::ProxyAuthType = CURLAUTH_NTLM;
175 BESDEBUG(MODULE, prolog <<
"ProxyAuthType NTLM set." << endl);
178 HttpdCatalogUtils::ProxyAuthType = CURLAUTH_BASIC;
180 prolog <<
"User supplied an invalid value '"<< authType <<
"' for Gateway.ProxyAuthType. Falling back to BASIC authentication scheme." << endl);
184 HttpdCatalogUtils::ProxyAuthType = CURLAUTH_BASIC;
189 key = HTTPD_CATALOG_USE_INTERNAL_CACHE;
193 if (use_cache ==
"true" || use_cache ==
"TRUE" || use_cache ==
"True" || use_cache ==
"yes" || use_cache ==
"YES" || use_cache ==
"Yes")
194 HttpdCatalogUtils::useInternalCache =
true;
196 HttpdCatalogUtils::useInternalCache =
false;
200 HttpdCatalogUtils::useInternalCache =
false;
207 void HttpdCatalogUtils::get_type_from_disposition(
const string &disp,
string &type)
209 size_t fnpos = disp.find(
"filename");
210 if (fnpos != string::npos) {
213 size_t pos = disp.find(
"#", fnpos);
214 if (pos == string::npos) pos = disp.find(
"=", fnpos);
215 if (pos != string::npos) {
221 size_t sp = disp.find(
" ", pos);
222 if (pos != string::npos) {
224 filename = disp.substr(pos + 1, sp - pos - 1);
228 filename = disp.substr(pos + 1);
232 if (filename[0] ==
'"') {
233 filename = filename.substr(1);
235 if (filename[filename.length() - 1] ==
'"') {
236 filename = filename.substr(0, filename.length() - 1);
248 void HttpdCatalogUtils::get_type_from_content_type(
const string &ctype,
string &type)
250 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
252 map<string, string>::iterator i = MimeList.begin();
253 map<string, string>::iterator e = MimeList.end();
255 for (; i != e && !done; i++) {
256 BESDEBUG(MODULE, prolog <<
"Comparing content type '" << ctype <<
"' against mime list element '" << (*i).second <<
"'"<< endl);
257 BESDEBUG(MODULE, prolog <<
"first: " << (*i).first <<
" second: " << (*i).second << endl);
259 if ((*i).second == ctype) {
261 BESDEBUG(MODULE, prolog <<
"MATCH" << endl);
268 BESDEBUG(MODULE, prolog <<
"END" << endl);
271 void HttpdCatalogUtils::get_type_from_url(
const string &url,
string &type)