Loading...
Searching...
No Matches
XrdHttpUtils.hh File Reference

Utility functions for XrdHTTP. More...

`#include "XProtocol/XPtypes.hh"`
`#include "XProtocol/XProtocol.hh"`
`#include "XrdSec/XrdSecEntity.hh"`
`#include "XrdOuc/XrdOucIOVec.hh"`
`#include "XrdOuc/XrdOucTUtils.hh"`
`#include <string>`
`#include <cstring>`
`#include <vector>`
`#include <memory>`
`#include <sstream>`
Include dependency graph for XrdHttpUtils.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Typedefs

typedef std::vector< XrdOucIOVec2 > | XrdHttpIOList

## Enumerations

enum

: int {
HTTP_CONTINUE = 100 ,
HTTP_SWITCHING_PROTOCOLS = 101 ,
HTTP_PROCESSING = 102 ,
HTTP_EARLY_HINTS = 103 ,
HTTP_OK = 200 ,
HTTP_CREATED = 201 ,
HTTP_ACCEPTED = 202 ,
HTTP_NON_AUTHORITATIVE_INFORMATION = 203 ,
HTTP_NO_CONTENT = 204 ,
HTTP_RESET_CONTENT = 205 ,
HTTP_PARTIAL_CONTENT = 206 ,
HTTP_MULTI_STATUS = 207 ,
HTTP_ALREADY_REPORTED = 208 ,
HTTP_IM_USED = 226 ,
HTTP_MULTIPLE_CHOICES = 300 ,
HTTP_MOVED_PERMANENTLY = 301 ,
HTTP_FOUND = 302 ,
HTTP_SEE_OTHER = 303 ,
HTTP_NOT_MODIFIED = 304 ,
HTTP_USE_PROXY = 305 ,
HTTP_TEMPORARY_REDIRECT = 307 ,
HTTP_PERMANENT_REDIRECT = 308 ,
HTTP_BAD_REQUEST = 400 ,
HTTP_UNAUTHORIZED = 401 ,
HTTP_PAYMENT_REQUIRED = 402 ,
HTTP_FORBIDDEN = 403 ,
HTTP_NOT_FOUND = 404 ,
HTTP_METHOD_NOT_ALLOWED = 405 ,
HTTP_NOT_ACCEPTABLE = 406 ,
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407 ,
HTTP_REQUEST_TIMEOUT = 408 ,
HTTP_CONFLICT = 409 ,
HTTP_GONE = 410 ,
HTTP_LENGTH_REQUIRED = 411 ,
HTTP_PRECONDITION_FAILED = 412 ,
HTTP_PAYLOAD_TOO_LARGE = 413 ,
HTTP_URI_TOO_LONG = 414 ,
HTTP_UNSUPPORTED_MEDIA_TYPE = 415 ,
HTTP_RANGE_NOT_SATISFIABLE = 416 ,
HTTP_EXPECTATION_FAILED = 417 ,
HTTP_IM_A_TEAPOT = 418 ,
HTTP_MISDIRECTED_REQUEST = 421 ,
HTTP_UNPROCESSABLE_ENTITY = 422 ,
HTTP_LOCKED = 423 ,
HTTP_FAILED_DEPENDENCY = 424 ,
HTTP_TOO_EARLY = 425 ,
HTTP_UPGRADE_REQUIRED = 426 ,
HTTP_PRECONDITION_REQUIRED = 428 ,
HTTP_TOO_MANY_REQUESTS = 429 ,
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431 ,
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451 ,
HTTP_INTERNAL_SERVER_ERROR = 500 ,
HTTP_NOT_IMPLEMENTED = 501 ,
HTTP_BAD_GATEWAY = 502 ,
HTTP_SERVICE_UNAVAILABLE = 503 ,
HTTP_GATEWAY_TIMEOUT = 504 ,
HTTP_HTTP_VERSION_NOT_SUPPORTED = 505 ,
HTTP_VARIANT_ALSO_NEGOTIATES = 506 ,
HTTP_INSUFFICIENT_STORAGE = 507 ,
HTTP_LOOP_DETECTED = 508 ,
HTTP_NOT_EXTENDED = 510 ,
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511
}

## Functions

void | calcHashes (char *hash, const char *fn, kXR_int16 req, XrdSecEntity *secent, time_t tim, const char *key)
int | compareHash (const char *h1, const char *h2)
char * | decode_raw (const std::string &str)
std::string | decode_str (const std::string &str)
std::string | encode_opaque (const std::string &opaque)
char * | encode_raw (const std::string &str)
std::string | encode_str (const std::string &str)
char * | escapeXML (const char *str)
bool | Fromhexdigest (const unsigned char *input, int length, unsigned char *out)
std::string | httpStatusToString (int status)
std::string | itos (long i)
int | mapErrNoToHttp (int err)
int | mapXrdErrToHttp (XErrorCode xrdError)
char * | mystrchrnul (const char *s, int c)
int | parseURL (char *url, char *host, int &port, char **path)
char * | quote (const char *str)
void | Tobase64 (const unsigned char *input, int length, char *out)
char * | unquote (char *str)

## Detailed Description

Utility functions for XrdHTTP.

Author
  Fabrizio Furano

Date
  April 2013

Definition in file XrdHttpUtils.hh.

## Typedef Documentation

## XrdHttpIOList

typedef std::vector<XrdOucIOVec2> XrdHttpIOList

Definition at line 252 of file XrdHttpUtils.hh.

## Enumeration Type Documentation

## anonymous enum

anonymous enum : int

Enumerator
HTTP_CONTINUE |
HTTP_SWITCHING_PROTOCOLS |
HTTP_PROCESSING |
HTTP_EARLY_HINTS |
HTTP_OK |
HTTP_CREATED |
HTTP_ACCEPTED |
HTTP_NON_AUTHORITATIVE_INFORMATION |
HTTP_NO_CONTENT |
HTTP_RESET_CONTENT |
HTTP_PARTIAL_CONTENT |
HTTP_MULTI_STATUS |
HTTP_ALREADY_REPORTED |
HTTP_IM_USED |
HTTP_MULTIPLE_CHOICES |
HTTP_MOVED_PERMANENTLY |
HTTP_FOUND |
HTTP_SEE_OTHER |
HTTP_NOT_MODIFIED |
HTTP_USE_PROXY |
HTTP_TEMPORARY_REDIRECT |
HTTP_PERMANENT_REDIRECT |
HTTP_BAD_REQUEST |
HTTP_UNAUTHORIZED |
HTTP_PAYMENT_REQUIRED |
HTTP_FORBIDDEN |
HTTP_NOT_FOUND |
HTTP_METHOD_NOT_ALLOWED |
HTTP_NOT_ACCEPTABLE |
HTTP_PROXY_AUTHENTICATION_REQUIRED |
HTTP_REQUEST_TIMEOUT |
HTTP_CONFLICT |
HTTP_GONE |
HTTP_LENGTH_REQUIRED |
HTTP_PRECONDITION_FAILED |
HTTP_PAYLOAD_TOO_LARGE |
HTTP_URI_TOO_LONG |
HTTP_UNSUPPORTED_MEDIA_TYPE |
HTTP_RANGE_NOT_SATISFIABLE |
HTTP_EXPECTATION_FAILED |
HTTP_IM_A_TEAPOT |
HTTP_MISDIRECTED_REQUEST |
HTTP_UNPROCESSABLE_ENTITY |
HTTP_LOCKED |
HTTP_FAILED_DEPENDENCY |
HTTP_TOO_EARLY |
HTTP_UPGRADE_REQUIRED |
HTTP_PRECONDITION_REQUIRED |
HTTP_TOO_MANY_REQUESTS |
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE |
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS |
HTTP_INTERNAL_SERVER_ERROR |
HTTP_NOT_IMPLEMENTED |
HTTP_BAD_GATEWAY |
HTTP_SERVICE_UNAVAILABLE |
HTTP_GATEWAY_TIMEOUT |
HTTP_HTTP_VERSION_NOT_SUPPORTED |
HTTP_VARIANT_ALSO_NEGOTIATES |
HTTP_INSUFFICIENT_STORAGE |
HTTP_LOOP_DETECTED |
HTTP_NOT_EXTENDED |
HTTP_NETWORK_AUTHENTICATION_REQUIRED |

Definition at line 52 of file XrdHttpUtils.hh.

: int {
HTTP_CONTINUE = 100,
HTTP_SWITCHING_PROTOCOLS = 101,
HTTP_PROCESSING = 102,
HTTP_EARLY_HINTS = 103,
// 2xx Success
HTTP_OK = 200,
HTTP_CREATED = 201,
HTTP_ACCEPTED = 202,
HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
HTTP_NO_CONTENT = 204,
HTTP_RESET_CONTENT = 205,
HTTP_PARTIAL_CONTENT = 206,
HTTP_MULTI_STATUS = 207,
HTTP_ALREADY_REPORTED = 208,
HTTP_IM_USED = 226,
// 3xx Redirection
HTTP_MULTIPLE_CHOICES = 300,
HTTP_MOVED_PERMANENTLY = 301,
HTTP_FOUND = 302,
HTTP_SEE_OTHER = 303,
HTTP_NOT_MODIFIED = 304,
HTTP_USE_PROXY = 305,
HTTP_TEMPORARY_REDIRECT = 307,
HTTP_PERMANENT_REDIRECT = 308,
// 4xx Client Errors
HTTP_BAD_REQUEST = 400,
HTTP_UNAUTHORIZED = 401,
HTTP_PAYMENT_REQUIRED = 402,
HTTP_FORBIDDEN = 403,
HTTP_NOT_FOUND = 404,
HTTP_METHOD_NOT_ALLOWED = 405,
HTTP_NOT_ACCEPTABLE = 406,
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
HTTP_REQUEST_TIMEOUT = 408,
HTTP_CONFLICT = 409,
HTTP_GONE = 410,
HTTP_LENGTH_REQUIRED = 411,
HTTP_PRECONDITION_FAILED = 412,
HTTP_PAYLOAD_TOO_LARGE = 413,
HTTP_URI_TOO_LONG = 414,
HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_RANGE_NOT_SATISFIABLE = 416,
HTTP_EXPECTATION_FAILED = 417,
HTTP_IM_A_TEAPOT = 418, // RFC 2324
HTTP_MISDIRECTED_REQUEST = 421,
HTTP_UNPROCESSABLE_ENTITY = 422,
HTTP_LOCKED = 423,
HTTP_FAILED_DEPENDENCY = 424,
HTTP_TOO_EARLY = 425,
HTTP_UPGRADE_REQUIRED = 426,
HTTP_PRECONDITION_REQUIRED = 428,
HTTP_TOO_MANY_REQUESTS = 429,
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
// 5xx Server Errors
HTTP_INTERNAL_SERVER_ERROR = 500,
HTTP_NOT_IMPLEMENTED = 501,
HTTP_BAD_GATEWAY = 502,
HTTP_SERVICE_UNAVAILABLE = 503,
HTTP_GATEWAY_TIMEOUT = 504,
HTTP_HTTP_VERSION_NOT_SUPPORTED = 505,
HTTP_VARIANT_ALSO_NEGOTIATES = 506,
HTTP_INSUFFICIENT_STORAGE = 507,
HTTP_LOOP_DETECTED = 508,
HTTP_NOT_EXTENDED = 510,
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
};
HTTP_HTTP_VERSION_NOT_SUPPORTED
@ HTTP_HTTP_VERSION_NOT_SUPPORTED
Definition XrdHttpUtils.hh:117
HTTP_INSUFFICIENT_STORAGE
@ HTTP_INSUFFICIENT_STORAGE
Definition XrdHttpUtils.hh:119
HTTP_PRECONDITION_FAILED
@ HTTP_PRECONDITION_FAILED
Definition XrdHttpUtils.hh:93
HTTP_BAD_REQUEST
@ HTTP_BAD_REQUEST
Definition XrdHttpUtils.hh:81
HTTP_NOT_EXTENDED
@ HTTP_NOT_EXTENDED
Definition XrdHttpUtils.hh:121
HTTP_FAILED_DEPENDENCY
@ HTTP_FAILED_DEPENDENCY
Definition XrdHttpUtils.hh:103
HTTP_VARIANT_ALSO_NEGOTIATES
@ HTTP_VARIANT_ALSO_NEGOTIATES
Definition XrdHttpUtils.hh:118
HTTP_CREATED
@ HTTP_CREATED
Definition XrdHttpUtils.hh:60
HTTP_IM_A_TEAPOT
@ HTTP_IM_A_TEAPOT
Definition XrdHttpUtils.hh:99
HTTP_MULTIPLE_CHOICES
@ HTTP_MULTIPLE_CHOICES
Definition XrdHttpUtils.hh:71
HTTP_LOCKED
@ HTTP_LOCKED
Definition XrdHttpUtils.hh:102
HTTP_OK
@ HTTP_OK
Definition XrdHttpUtils.hh:59
HTTP_NOT_MODIFIED
@ HTTP_NOT_MODIFIED
Definition XrdHttpUtils.hh:75
HTTP_NON_AUTHORITATIVE_INFORMATION
@ HTTP_NON_AUTHORITATIVE_INFORMATION
Definition XrdHttpUtils.hh:62
HTTP_LOOP_DETECTED
@ HTTP_LOOP_DETECTED
Definition XrdHttpUtils.hh:120
HTTP_EXPECTATION_FAILED
@ HTTP_EXPECTATION_FAILED
Definition XrdHttpUtils.hh:98
HTTP_SERVICE_UNAVAILABLE
@ HTTP_SERVICE_UNAVAILABLE
Definition XrdHttpUtils.hh:115
HTTP_PROXY_AUTHENTICATION_REQUIRED
@ HTTP_PROXY_AUTHENTICATION_REQUIRED
Definition XrdHttpUtils.hh:88
HTTP_LENGTH_REQUIRED
@ HTTP_LENGTH_REQUIRED
Definition XrdHttpUtils.hh:92
HTTP_URI_TOO_LONG
@ HTTP_URI_TOO_LONG
Definition XrdHttpUtils.hh:95
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS
@ HTTP_UNAVAILABLE_FOR_LEGAL_REASONS
Definition XrdHttpUtils.hh:109
HTTP_UNAUTHORIZED
@ HTTP_UNAUTHORIZED
Definition XrdHttpUtils.hh:82
HTTP_UNSUPPORTED_MEDIA_TYPE
@ HTTP_UNSUPPORTED_MEDIA_TYPE
Definition XrdHttpUtils.hh:96
HTTP_NOT_FOUND
@ HTTP_NOT_FOUND
Definition XrdHttpUtils.hh:85
HTTP_FORBIDDEN
@ HTTP_FORBIDDEN
Definition XrdHttpUtils.hh:84
HTTP_CONTINUE
@ HTTP_CONTINUE
Definition XrdHttpUtils.hh:53
HTTP_MULTI_STATUS
@ HTTP_MULTI_STATUS
Definition XrdHttpUtils.hh:66
HTTP_PERMANENT_REDIRECT
@ HTTP_PERMANENT_REDIRECT
Definition XrdHttpUtils.hh:78
HTTP_FOUND
@ HTTP_FOUND
Definition XrdHttpUtils.hh:73
HTTP_RESET_CONTENT
@ HTTP_RESET_CONTENT
Definition XrdHttpUtils.hh:64
HTTP_TEMPORARY_REDIRECT
@ HTTP_TEMPORARY_REDIRECT
Definition XrdHttpUtils.hh:77
HTTP_NO_CONTENT
@ HTTP_NO_CONTENT
Definition XrdHttpUtils.hh:63
HTTP_MISDIRECTED_REQUEST
@ HTTP_MISDIRECTED_REQUEST
Definition XrdHttpUtils.hh:100
HTTP_PARTIAL_CONTENT
@ HTTP_PARTIAL_CONTENT
Definition XrdHttpUtils.hh:65
HTTP_BAD_GATEWAY
@ HTTP_BAD_GATEWAY
Definition XrdHttpUtils.hh:114
HTTP_GATEWAY_TIMEOUT
@ HTTP_GATEWAY_TIMEOUT
Definition XrdHttpUtils.hh:116
HTTP_NETWORK_AUTHENTICATION_REQUIRED
@ HTTP_NETWORK_AUTHENTICATION_REQUIRED
Definition XrdHttpUtils.hh:122
HTTP_TOO_EARLY
@ HTTP_TOO_EARLY
Definition XrdHttpUtils.hh:104
HTTP_METHOD_NOT_ALLOWED
@ HTTP_METHOD_NOT_ALLOWED
Definition XrdHttpUtils.hh:86
HTTP_NOT_ACCEPTABLE
@ HTTP_NOT_ACCEPTABLE
Definition XrdHttpUtils.hh:87
HTTP_ALREADY_REPORTED
@ HTTP_ALREADY_REPORTED
Definition XrdHttpUtils.hh:67
HTTP_EARLY_HINTS
@ HTTP_EARLY_HINTS
Definition XrdHttpUtils.hh:56
HTTP_GONE
@ HTTP_GONE
Definition XrdHttpUtils.hh:91
HTTP_INTERNAL_SERVER_ERROR
@ HTTP_INTERNAL_SERVER_ERROR
Definition XrdHttpUtils.hh:112
HTTP_UPGRADE_REQUIRED
@ HTTP_UPGRADE_REQUIRED
Definition XrdHttpUtils.hh:105
HTTP_IM_USED
@ HTTP_IM_USED
Definition XrdHttpUtils.hh:68
HTTP_TOO_MANY_REQUESTS
@ HTTP_TOO_MANY_REQUESTS
Definition XrdHttpUtils.hh:107
HTTP_PAYLOAD_TOO_LARGE
@ HTTP_PAYLOAD_TOO_LARGE
Definition XrdHttpUtils.hh:94
HTTP_NOT_IMPLEMENTED
@ HTTP_NOT_IMPLEMENTED
Definition XrdHttpUtils.hh:113
HTTP_SEE_OTHER
@ HTTP_SEE_OTHER
Definition XrdHttpUtils.hh:74
HTTP_PAYMENT_REQUIRED
@ HTTP_PAYMENT_REQUIRED
Definition XrdHttpUtils.hh:83
HTTP_REQUEST_TIMEOUT
@ HTTP_REQUEST_TIMEOUT
Definition XrdHttpUtils.hh:89
HTTP_UNPROCESSABLE_ENTITY
@ HTTP_UNPROCESSABLE_ENTITY
Definition XrdHttpUtils.hh:101
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
@ HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
Definition XrdHttpUtils.hh:108
HTTP_SWITCHING_PROTOCOLS
@ HTTP_SWITCHING_PROTOCOLS
Definition XrdHttpUtils.hh:54
HTTP_MOVED_PERMANENTLY
@ HTTP_MOVED_PERMANENTLY
Definition XrdHttpUtils.hh:72
HTTP_USE_PROXY
@ HTTP_USE_PROXY
Definition XrdHttpUtils.hh:76
HTTP_PRECONDITION_REQUIRED
@ HTTP_PRECONDITION_REQUIRED
Definition XrdHttpUtils.hh:106
HTTP_RANGE_NOT_SATISFIABLE
@ HTTP_RANGE_NOT_SATISFIABLE
Definition XrdHttpUtils.hh:97
HTTP_ACCEPTED
@ HTTP_ACCEPTED
Definition XrdHttpUtils.hh:61
HTTP_CONFLICT
@ HTTP_CONFLICT
Definition XrdHttpUtils.hh:90
HTTP_PROCESSING
@ HTTP_PROCESSING
Definition XrdHttpUtils.hh:55

## Function Documentation

## calcHashes()

void calcHashes | ( | char * | hash,
|  | const char * | fn,
|  | kXR_int16 | req,
|  | XrdSecEntity * | secent,
|  | time_t | tim,
|  | const char * | key )

Definition at line 219 of file XrdHttpUtils.cc.

{
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
EVP_MAC *mac;
EVP_MAC_CTX *ctx;
size_t len;
#else
HMAC_CTX *ctx;
unsigned int len;
#endif
unsigned char mdbuf[EVP_MAX_MD_SIZE];
char buf[64];
struct tm tms;
if (!hash) {
return;
}
hash[0] = '\0';
if (!key) {
return;
}
if (!fn || !secent) {
return;
}
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
mac = EVP_MAC_fetch(0, "sha256", 0);
ctx = EVP_MAC_CTX_new(mac);
if (!ctx) {
return;
}
EVP_MAC_init(ctx, (const unsigned char *) key, strlen(key), 0);
if (fn)
EVP_MAC_update(ctx, (const unsigned char *) fn,
strlen(fn) + 1);
EVP_MAC_update(ctx, (const unsigned char *) &request,
sizeof (request));
if (secent->name)
EVP_MAC_update(ctx, (const unsigned char *) secent->name,
strlen(secent->name) + 1);
if (secent->vorg)
EVP_MAC_update(ctx, (const unsigned char *) secent->vorg,
strlen(secent->vorg) + 1);
if (secent->host)
EVP_MAC_update(ctx, (const unsigned char *) secent->host,
strlen(secent->host) + 1);
if (secent->moninfo)
EVP_MAC_update(ctx, (const unsigned char *) secent->moninfo,
strlen(secent->moninfo) + 1);
localtime_r(&tim, &tms);
strftime(buf, sizeof (buf), "%s", &tms);
EVP_MAC_update(ctx, (const unsigned char *) buf,
strlen(buf) + 1);
EVP_MAC_final(ctx, mdbuf, &len, EVP_MAX_MD_SIZE);
EVP_MAC_CTX_free(ctx);
EVP_MAC_free(mac);
#else
ctx = HMAC_CTX_new();
if (!ctx) {
return;
}
HMAC_Init_ex(ctx, (const void *) key, strlen(key), EVP_sha256(), 0);
if (fn)
HMAC_Update(ctx, (const unsigned char *) fn,
strlen(fn) + 1);
HMAC_Update(ctx, (const unsigned char *) &request,
sizeof (request));
if (secent->name)
HMAC_Update(ctx, (const unsigned char *) secent->name,
strlen(secent->name) + 1);
if (secent->vorg)
HMAC_Update(ctx, (const unsigned char *) secent->vorg,
strlen(secent->vorg) + 1);
if (secent->host)
HMAC_Update(ctx, (const unsigned char *) secent->host,
strlen(secent->host) + 1);
if (secent->moninfo)
HMAC_Update(ctx, (const unsigned char *) secent->moninfo,
strlen(secent->moninfo) + 1);
localtime_r(&tim, &tms);
strftime(buf, sizeof (buf), "%s", &tms);
HMAC_Update(ctx, (const unsigned char *) buf,
strlen(buf) + 1);
HMAC_Final(ctx, mdbuf, &len);
HMAC_CTX_free(ctx);
#endif
Tobase64(mdbuf, len / 2, hash);
}
Tobase64
void Tobase64(const unsigned char *input, int length, char *out)
Definition XrdHttpUtils.cc:121
HMAC_CTX_new
static HMAC_CTX * HMAC_CTX_new()
Definition XrdHttpUtils.cc:59
HMAC_CTX_free
static void HMAC_CTX_free(HMAC_CTX *ctx)
Definition XrdHttpUtils.cc:65
XrdSecEntity::vorg
char * vorg
Entity's virtual organization(s).
Definition XrdSecEntity.hh:71
XrdSecEntity::name
char * name
Entity's name.
Definition XrdSecEntity.hh:69
XrdSecEntity::moninfo
char * moninfo
Information for monitoring.
Definition XrdSecEntity.hh:76
XrdSecEntity::host
char * host
Entity's host name dnr dependent.
Definition XrdSecEntity.hh:70

References HMAC_CTX_free(), HMAC_CTX_new(), XrdSecEntity::host, XrdSecEntity::moninfo, XrdSecEntity::name, Tobase64(), and XrdSecEntity::vorg.

Referenced by XrdHttpProtocol::Process(), and XrdHttpReq::Redir().

Here is the call graph for this function:
Here is the caller graph for this function:

## compareHash()

int compareHash | ( | const char * | h1,
|  | const char * | h2 )

Definition at line 355 of file XrdHttpUtils.cc.

{
if (h1 == h2) return 0;
if (!h1 || !h2)
return 1;
return strcmp(h1, h2);
}

Referenced by XrdHttpProtocol::Process().

Here is the caller graph for this function:

## decode_raw()

char * decode_raw | ( | const std::string & | str | ) |

inline

Creates a non-const copy of the string passed in parameter and calls unquote() on it before returning the pointer to the unquoted string

Parameters

  str | the string to unquote

Returns
  the malloc'd and unquoted string !!! IT MUST BE FREED AFTER USAGE USING free(...) !!!

Definition at line 172 of file XrdHttpUtils.hh.

{
size_t strLength = str.length();
// uniquely own the temporary copy
std::unique_ptr<char[]> buf(new char[strLength + 1]);
std::memcpy(buf.get(), str.c_str(), strLength + 1);
// unquote returns a fresh malloc()'d pointer
return unquote(buf.get());
}
unquote
char * unquote(char *str)
Definition XrdHttpUtils.cc:370

References unquote().

Referenced by decode_str().

Here is the call graph for this function:
Here is the caller graph for this function:

## decode_str()

std::string decode_str | ( | const std::string & | str | ) |

inline

Decodes the string passed in parameter (converts all XX codes to their 8bit versions) Calls unquote() Returns the std::string containing the decoded string.

Definition at line 210 of file XrdHttpUtils.hh.

{
char * decodedRaw = decode_raw(str);
std::string decoded { decodedRaw };
free(decodedRaw);
return decoded;
}
decode_raw
char * decode_raw(const std::string &str)
Definition XrdHttpUtils.hh:172

References decode_raw().

Referenced by XrdHttpProtocol::Process().

Here is the call graph for this function:
Here is the caller graph for this function:

## encode_opaque()

std::string encode_opaque | ( | const std::string & | opaque | ) |

inline

Encodes opaque query string parameters example: authz=Bearer token --> authz=Bearer%20token

Parameters

  opaque | the opaque query string to encode

Returns
  the opaque query string with encoded values

Definition at line 223 of file XrdHttpUtils.hh.

{
std::ostringstream output;
std::vector<std::string> allKeyValues;
XrdOucTUtils::splitString(allKeyValues,opaque,"&");
bool first = true;
for(auto & kv: allKeyValues) {
size_t equal = kv.find('=');
if(equal != std::string::npos) {
std::string key = kv.substr(0, equal);
std::string value = kv.substr(equal + 1);
if(!first) {
output << "&";
}
output << key << "=" << encode_str(value);
first = false;
}
}
return output.str();
}
encode_str
std::string encode_str(const std::string &str)
Definition XrdHttpUtils.hh:197
XrdOucTUtils::splitString
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
Definition XrdOucTUtils.hh:51

References encode_str(), and XrdOucTUtils::splitString().

Referenced by XrdHttpReq::appendOpaque(), XrdHttpReq::ProcessHTTPReq(), and XrdHttpReq::Redir().

Here is the call graph for this function:
Here is the caller graph for this function:

## encode_raw()

char * encode_raw | ( | const std::string & | str | ) |

inline

Calls quote() on the string passed in parameter

Parameters

  str | the string to quote

Returns
  the pointer to the quoted string !!! IT MUST BE FREED AFTER USAGE USING free(...) !!!

Definition at line 187 of file XrdHttpUtils.hh.

{
return quote(str.c_str());
}
quote
char * quote(const char *str)
Definition XrdHttpUtils.cc:399

References quote().

Referenced by encode_str().

Here is the call graph for this function:
Here is the caller graph for this function:

## encode_str()

std::string encode_str | ( | const std::string & | str | ) |

inline

Encodes the URL passed in parameter (converts all letters consider illegal in URLs to their XX versions). Calls quote() Returns a std::string containing the encoded string

Definition at line 197 of file XrdHttpUtils.hh.

{
char * encodedRaw = encode_raw(str);
std::string encoded { encodedRaw };
free(encodedRaw);
return encoded;
}
encode_raw
char * encode_raw(const std::string &str)
Definition XrdHttpUtils.hh:187

References encode_raw().

Referenced by XrdHttpReq::appendOpaque(), encode_opaque(), and XrdHttpReq::Redir().

Here is the call graph for this function:
Here is the caller graph for this function:

## escapeXML()

char * escapeXML | ( | const char * | str | ) |

Definition at line 458 of file XrdHttpUtils.cc.

{
int l = strlen(str);
char *r = (char *) malloc(l*6 + 1);
r[0] = '\0';
int i, j = 0;
for (i = 0; i < l; i++) {
char c = str[i];
switch (c) {
case '"':
strcpy(r + j, "&quot;");
j += 6;
break;
case '&':
strcpy(r + j, "&amp;");
j += 5;
break;
case '<':
strcpy(r + j, "&lt;");
j += 4;
break;
case '>':
strcpy(r + j, "&gt;");
j += 4;
break;
case '\'':
strcpy(r + j, "&apos;");
j += 6;
break;
default:
r[j++] = c;
}
}
r[j] = '\0';
return r;
}

Referenced by XrdHttpReq::Error().

Here is the caller graph for this function:

## Fromhexdigest()

bool Fromhexdigest | ( | const unsigned char * | input,
|  | int | length,
|  | unsigned char * | out )

Definition at line 169 of file XrdHttpUtils.cc.

{
for (int idx=0; idx < length; idx += 2) {
int upper = char_to_int(input[idx]);
int lower = char_to_int(input[idx+1]);
if ((upper < 0) || (lower < 0)) {
return false;
}
out[idx/2] = (upper << 4) + lower;
}
return true;
}
char_to_int
static int char_to_int(int c)
Definition XrdHttpUtils.cc:153

References char_to_int().

Here is the call graph for this function:

## httpStatusToString()

std::string httpStatusToString | ( | int | status | ) |

Definition at line 579 of file XrdHttpUtils.cc.

{
switch (status) {
// 1xx Informational
case 100: return "Continue";
case 101: return "Switching Protocols";
case 102: return "Processing";
case 103: return "Early Hints";
// 2xx Success
case 200: return "OK";
case 201: return "Created";
case 202: return "Accepted";
case 203: return "Non-Authoritative Information";
case 204: return "No Content";
case 205: return "Reset Content";
case 206: return "Partial Content";
case 207: return "Multi-Status";
case 208: return "Already Reported";
case 226: return "IM Used";
// 3xx Redirection
case 300: return "Multiple Choices";
case 301: return "Moved Permanently";
case 302: return "Found";
case 303: return "See Other";
case 304: return "Not Modified";
case 305: return "Use Proxy";
case 307: return "Temporary Redirect";
case 308: return "Permanent Redirect";
// 4xx Client Errors
case 400: return "Bad Request";
case 401: return "Unauthorized";
case 402: return "Payment Required";
case 403: return "Forbidden";
case 404: return "Not Found";
case 405: return "Method Not Allowed";
case 406: return "Not Acceptable";
case 407: return "Proxy Authentication Required";
case 408: return "Request Timeout";
case 409: return "Conflict";
case 410: return "Gone";
case 411: return "Length Required";
case 412: return "Precondition Failed";
case 413: return "Payload Too Large";
case 414: return "URI Too Long";
case 415: return "Unsupported Media Type";
case 416: return "Range Not Satisfiable";
case 417: return "Expectation Failed";
case 418: return "I'm a teapot";
case 421: return "Misdirected Request";
case 422: return "Unprocessable Entity";
case 423: return "Locked";
case 424: return "Failed Dependency";
case 425: return "Too Early";
case 426: return "Upgrade Required";
case 428: return "Precondition Required";
case 429: return "Too Many Requests";
case 431: return "Request Header Fields Too Large";
case 451: return "Unavailable For Legal Reasons";
// 5xx Server Errors
case 500: return "Internal Server Error";
case 501: return "Not Implemented";
case 502: return "Bad Gateway";
case 503: return "Service Unavailable";
case 504: return "Gateway Timeout";
case 505: return "HTTP Version Not Supported";
case 506: return "Variant Also Negotiates";
case 507: return "Insufficient Storage";
case 508: return "Loop Detected";
case 510: return "Not Extended";
case 511: return "Network Authentication Required";
default:
switch (status) {
case 100 ... 199: return "Informational";
case 200 ... 299: return "Success";
case 300 ... 399: return "Redirection";
case 400 ... 499: return "Client Error";
case 500 ... 599: return "Server Error";
default: return "Unknown";
}
}
}

## itos()

std::string itos | ( | long | i | ) |

Definition at line 183 of file XrdHttpUtils.cc.

{
char buf[128];
sprintf(buf, "%ld", i);
return buf;
}

## mapErrNoToHttp()

int mapErrNoToHttp | ( | int | err | ) |

Definition at line 506 of file XrdHttpUtils.cc.

{
switch (errNo) {
case EACCES:
case EROFS:
case EPERM:
return HTTP_FORBIDDEN;
case EAUTH:
return HTTP_UNAUTHORIZED;
case ENOENT:
return HTTP_NOT_FOUND;
case EEXIST:
case EISDIR:
case ENOTDIR:
case ENOTEMPTY:
return HTTP_CONFLICT;
case EXDEV:
return HTTP_UNPROCESSABLE_ENTITY;
case ENAMETOOLONG:
return HTTP_URI_TOO_LONG;
case ELOOP:
return HTTP_LOOP_DETECTED;
case ENOSPC:
case EDQUOT:
return HTTP_INSUFFICIENT_STORAGE;
case EFBIG:
return HTTP_PAYLOAD_TOO_LARGE;
case EINVAL:
case EBADF:
case EFAULT:
case ENXIO:
case ESPIPE:
case EOVERFLOW:
return HTTP_BAD_REQUEST;
case ENOTSUP: // EOPNOTSUPP
return HTTP_NOT_IMPLEMENTED;
case EBUSY:
case EAGAIN:
case EINTR:
case ENOMEM:
case EMFILE:
case ENFILE:
case ETXTBSY:
return HTTP_SERVICE_UNAVAILABLE;
case ETIMEDOUT:
return HTTP_GATEWAY_TIMEOUT;
case ECONNREFUSED:
case ECONNRESET:
case ENETDOWN:
case ENETUNREACH:
case EHOSTUNREACH:
case EPIPE:
return HTTP_BAD_GATEWAY;
default:
return HTTP_INTERNAL_SERVER_ERROR;
}
}
EAUTH
#define EAUTH
Definition XProtocol.hh:1351

References EAUTH, HTTP_BAD_GATEWAY, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_INSUFFICIENT_STORAGE, HTTP_INTERNAL_SERVER_ERROR, HTTP_LOOP_DETECTED, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_PAYLOAD_TOO_LARGE, HTTP_SERVICE_UNAVAILABLE, HTTP_UNAUTHORIZED, HTTP_UNPROCESSABLE_ENTITY, and HTTP_URI_TOO_LONG.

Referenced by mapXrdErrToHttp().

Here is the caller graph for this function:

## mapXrdErrToHttp()

int mapXrdErrToHttp | ( | XErrorCode | xrdError | ) |

Definition at line 499 of file XrdHttpUtils.cc.

{
int errNo = XProtocol::toErrno(xrdError);
return mapErrNoToHttp(errNo);
}
mapErrNoToHttp
int mapErrNoToHttp(int errNo)
Definition XrdHttpUtils.cc:506
XProtocol::toErrno
static int toErrno(int xerr)
Definition XProtocol.hh:1411

References mapErrNoToHttp(), and XProtocol::toErrno().

Here is the call graph for this function:

## mystrchrnul()

char * mystrchrnul | ( | const char * | s,
|  | int | c )

Definition at line 193 of file XrdHttpUtils.cc.

{
char *ptr = strchr((char *)s, c);
if (!ptr)
return strchr((char *)s, '\0');
return ptr;
}

## parseURL()

int parseURL | ( | char * | url,
|  | char * | host,
|  | int & | port,
|  | char ** | path )

Definition at line 77 of file XrdHttpUtils.cc.

{
// http://x.y.z.w:p/path
*path = 0;
// look for the second slash
char *p = strstr(url, "//");
if (!p) return -1;
p += 2;
// look for the end of the host:port
char *p2 = strchr(p, '/');
if (!p2) return -1;
*path = p2;
char buf[256];
int l = std::min((int)(p2 - p), (int)sizeof (buf));
strncpy(buf, p, l);
buf[l] = '\0';
// Now look for :
p = strchr(buf, ':');
if (p) {
int l = std::min((int)(p - buf), (int)sizeof (buf));
strncpy(host, buf, l);
host[l] = '\0';
port = atoi(p + 1);
} else {
port = 0;
strcpy(host, buf);
}
return 0;
}

Referenced by XrdHttpReq::ProcessHTTPReq().

Here is the caller graph for this function:

## quote()

char * quote | ( | const char * | str | ) |

Definition at line 399 of file XrdHttpUtils.cc.

{
int l = strlen(str);
char *r = (char *) malloc(l*3 + 1);
r[0] = '\0';
int i, j = 0;
for (i = 0; i < l; i++) {
char c = str[i];
switch (c) {
case ' ':
strcpy(r + j, "%20");
j += 3;
break;
case '[':
strcpy(r + j, "%5B");
j += 3;
break;
case ']':
strcpy(r + j, "%5D");
j += 3;
break;
case ':':
strcpy(r + j, "%3A");
j += 3;
break;
// case '/':
// strcpy(r + j, "%2F");
// j += 3;
// break;
case '#':
strcpy(r + j, "%23");
j += 3;
break;
case '\n':
strcpy(r + j, "%0A");
j += 3;
break;
case '\r':
strcpy(r + j, "%0D");
j += 3;
break;
case '=':
strcpy(r + j, "%3D");
j += 3;
break;
default:
r[j++] = c;
}
}
r[j] = '\0';
return r;
}

Referenced by encode_raw().

Here is the caller graph for this function:

## Tobase64()

void Tobase64 | ( | const unsigned char * | input,
|  | int | length,
|  | char * | out )

Definition at line 121 of file XrdHttpUtils.cc.

{
BIO *bmem, *b64;
BUF_MEM *bptr;
if (!out) return;
out[0] = '\0';
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new(BIO_s_mem());
BIO_push(b64, bmem);
BIO_write(b64, input, length);
if (BIO_flush(b64) <= 0) {
BIO_free_all(b64);
return;
}
BIO_get_mem_ptr(b64, &bptr);
memcpy(out, bptr->data, bptr->length);
out[bptr->length] = '\0';
BIO_free_all(b64);
return;
}
BIO_set_flags
void BIO_set_flags(BIO *bio, int flags)
Definition XrdHttpProtocol.cc:179

References BIO_set_flags().

Referenced by calcHashes().

Here is the call graph for this function:
Here is the caller graph for this function:

## unquote()

char * unquote | ( | char * | str | ) |

Definition at line 370 of file XrdHttpUtils.cc.

{
int l = strlen(str);
char *r = (char *) malloc(l + 1);
r[0] = '\0';
int i, j = 0;
for (i = 0; i < l; i++) {
if (str[i] == '%') {
char savec = str[i + 3];
str[i + 3] = '\0';
r[j] = strtol(str + i + 1, 0, 16);
str[i + 3] = savec;
i += 2;
} else r[j] = str[i];
j++;
}
r[j] = '\0';
return r;
}

Referenced by decode_raw().

Here is the caller graph for this function: