40 #include <curl/curl.h>
80 if (!found || WhiteList.size() == 0) {
82 +
" is not set or has no values in the gateway"
83 +
" configuration file";
93 if (found && vals.size()) {
94 vector<string>::iterator i = vals.begin();
95 vector<string>::iterator e = vals.end();
97 size_t colon = (*i).find(
":");
98 if (colon == string::npos) {
100 + (*i) +
" specified in the gateway configuration";
103 string mod = (*i).substr(0, colon);
104 string mime = (*i).substr(colon + 1);
105 MimeList[mod] = mime;
119 if (found && !port.empty()) {
122 string err = (string)
"gateway proxy host specified,"
123 +
" but proxy port specified is invalid";
175 if(authType ==
"basic"){
177 BESDEBUG(
"gateway",
"GatewayUtils::Initialize() - ProxyAuthType BASIC set." << endl);
179 else if(authType==
"digest"){
181 BESDEBUG(
"gateway",
"GatewayUtils::Initialize() - ProxyAuthType DIGEST set." << endl);
184 else if(authType==
"ntlm"){
186 BESDEBUG(
"gateway",
"GatewayUtils::Initialize() - ProxyAuthType NTLM set." << endl);
190 BESDEBUG(
"gateway",
"GatewayUtils::Initialize() - User supplied an invalid value '"<< authType <<
191 "' for Gateway.ProxyAuthType. Falling back to BASIC authentication scheme." << endl);
207 if (use_cache ==
"true" || use_cache ==
"TRUE" || use_cache ==
"True"
208 || use_cache ==
"yes" || use_cache ==
"YES"
209 || use_cache ==
"Yes")
242 GatewayUtils::Get_tempfile_template(
char *file_template )
246 Regex directory(
"[-a-zA-Z0-9_\\]*");
248 string c = getenv(
"TEMP") ? getenv(
"TEMP") :
"";
249 if (!c.empty() && directory.match(c.c_str(), c.length()) && (access(c.c_str(), 6) == 0))
250 goto valid_temp_directory;
252 c = getenv(
"TMP") ? getenv(
"TMP") :
"";
253 if (!c.empty() && directory.match(c.c_str(), c.length()) && (access(c.c_str(), 6) == 0))
254 goto valid_temp_directory;
257 Regex directory(
"[-a-zA-Z0-9_/]*");
259 string c = getenv(
"TMPDIR") ? getenv(
"TMPDIR") :
"";
260 if (!c.empty() && directory.match(c.c_str(), c.length())
261 && (access(c.c_str(), W_OK | R_OK) == 0))
262 goto valid_temp_directory;
265 if (access(P_tmpdir, W_OK | R_OK) == 0) {
267 goto valid_temp_directory;
274 valid_temp_directory:
281 c.append(file_template);
283 char *temp =
new char[c.length() + 1];
284 strncpy(temp, c.c_str(), c.length());
285 temp[c.length()] =
'\0';
291 size_t fnpos = disp.find(
"filename");
292 if (fnpos != string::npos) {
295 size_t pos = disp.find(
"#", fnpos);
296 if (pos == string::npos)
297 pos = disp.find(
"=", fnpos);
298 if (pos != string::npos) {
304 size_t sp = disp.find(
" ", pos);
305 if (pos != string::npos) {
307 filename = disp.substr(pos + 1, sp - pos - 1);
310 filename = disp.substr(pos + 1);
314 if (filename[0] ==
'"') {
315 filename = filename.substr(1);
317 if (filename[filename.length() - 1] ==
'"') {
318 filename = filename.substr(0, filename.length() - 1);
327 for (; i != ie && !done; i++) {
330 BESDEBUG(
"gateway",
" Comparing disp filename "
331 << filename <<
" against expr "
332 << match.
reg << endl );
334 if( reg_expr.match( filename.c_str(),
336 == static_cast<int>(filename.length()) )
344 string serr = (string)
"Unable to match data type, "
345 +
"malformed Catalog TypeMatch parameter "
346 +
"in bes configuration file around "
347 + match.
reg +
": " + e.get_error_message();
358 "GatewayUtils::Get_type_from_content_type() - BEGIN" << endl);
359 map<string, string>::iterator i = MimeList.begin();
360 map<string, string>::iterator e = MimeList.end();
362 for (; i != e && !done; i++) {
364 "GatewayUtils::Get_type_from_content_type() - Comparing content type '" << ctype <<
"' against mime list element '" << (*i).second <<
"'"<< endl);
366 "GatewayUtils::Get_type_from_content_type() - first: " << (*i).first <<
" second: " << (*i).second << endl);
368 if ((*i).second == ctype) {
371 "GatewayUtils::Get_type_from_content_type() - MATCH" << endl);
378 "GatewayUtils::Get_type_from_content_type() - END" << endl);
387 for (; i != ie && !done; i++) {
391 "GatewayUtils::Get_type_from_url() - Comparing url " << url <<
" against type match expr " << match.
reg << endl);
393 if (reg_expr.match(url.c_str(), url.length())
394 == static_cast<int>(url.length())) {
398 "GatewayUtils::Get_type_from_url() - MATCH type: " << type << endl);
401 string serr = (string)
"Unable to match data type, "
402 +
"malformed Catalog TypeMatch parameter "
403 +
"in bes configuration file around " + match.
reg +
": "
404 + e.get_error_message();
BESCatalogUtils::match_citer match_list_begin() const
#define Gateway_PROXYPASSWORD
BESCatalogUtils::match_citer match_list_end() const
exception thrown if inernal error encountered
static string lowercase(const string &s)
Convert a string to all lower case.
static map< string, string > MimeList
static string ProxyProtocol
a C++ interface to POSIX regular expression functions.
#define Gateway_PROXYPROTOCOL
static vector< string > WhiteList
#define Gateway_WHITELIST
static string NoProxyRegex
#define Gateway_PROXYAUTHTYPE
error thrown if there is a user syntax error in the request or any other user error ...
vector< type_reg >::const_iterator match_citer
static class NCMLUtil overview
#define Gateway_PROXYPORT
static void Get_type_from_content_type(const string &ctype, string &type)
static void Get_type_from_disposition(const string &disp, string &type)
#define Gateway_PROXYUSER
#define Gateway_USE_INTERNAL_CACHE
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
static void Get_type_from_url(const string &url, string &type)
#define Gateway_PROXYHOST
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
void get_values(const string &s, vector< string > &vals, bool &found)
Retrieve the values of a given key, if set.
static bool useInternalCache
static BESCatalogUtils * Utils(const string &name)
static BESKeys * TheKeys()
static string ProxyUserPW
#define Gateway_PROXYUSERPW
static string ProxyPassword