XRootD
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< XrdOucIOVec2XrdHttpIOList
 

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.

52  : int {
53  HTTP_CONTINUE = 100,
55  HTTP_PROCESSING = 102,
56  HTTP_EARLY_HINTS = 103,
57 
58  // 2xx Success
59  HTTP_OK = 200,
60  HTTP_CREATED = 201,
61  HTTP_ACCEPTED = 202,
63  HTTP_NO_CONTENT = 204,
64  HTTP_RESET_CONTENT = 205,
66  HTTP_MULTI_STATUS = 207,
68  HTTP_IM_USED = 226,
69 
70  // 3xx Redirection
73  HTTP_FOUND = 302,
74  HTTP_SEE_OTHER = 303,
75  HTTP_NOT_MODIFIED = 304,
76  HTTP_USE_PROXY = 305,
79 
80  // 4xx Client Errors
81  HTTP_BAD_REQUEST = 400,
82  HTTP_UNAUTHORIZED = 401,
84  HTTP_FORBIDDEN = 403,
85  HTTP_NOT_FOUND = 404,
87  HTTP_NOT_ACCEPTABLE = 406,
90  HTTP_CONFLICT = 409,
91  HTTP_GONE = 410,
95  HTTP_URI_TOO_LONG = 414,
99  HTTP_IM_A_TEAPOT = 418, // RFC 2324
102  HTTP_LOCKED = 423,
104  HTTP_TOO_EARLY = 425,
105  HTTP_UPGRADE_REQUIRED = 426,
110 
111  // 5xx Server Errors
113  HTTP_NOT_IMPLEMENTED = 501,
114  HTTP_BAD_GATEWAY = 502,
116  HTTP_GATEWAY_TIMEOUT = 504,
120  HTTP_LOOP_DETECTED = 508,
121  HTTP_NOT_EXTENDED = 510,
123 };
@ HTTP_HTTP_VERSION_NOT_SUPPORTED
@ HTTP_INSUFFICIENT_STORAGE
@ HTTP_PRECONDITION_FAILED
Definition: XrdHttpUtils.hh:93
@ HTTP_BAD_REQUEST
Definition: XrdHttpUtils.hh:81
@ HTTP_NOT_EXTENDED
@ HTTP_FAILED_DEPENDENCY
@ HTTP_VARIANT_ALSO_NEGOTIATES
@ HTTP_CREATED
Definition: XrdHttpUtils.hh:60
@ HTTP_IM_A_TEAPOT
Definition: XrdHttpUtils.hh:99
@ HTTP_MULTIPLE_CHOICES
Definition: XrdHttpUtils.hh:71
@ HTTP_LOCKED
@ HTTP_OK
Definition: XrdHttpUtils.hh:59
@ HTTP_NOT_MODIFIED
Definition: XrdHttpUtils.hh:75
@ HTTP_NON_AUTHORITATIVE_INFORMATION
Definition: XrdHttpUtils.hh:62
@ HTTP_LOOP_DETECTED
@ HTTP_EXPECTATION_FAILED
Definition: XrdHttpUtils.hh:98
@ HTTP_SERVICE_UNAVAILABLE
@ HTTP_PROXY_AUTHENTICATION_REQUIRED
Definition: XrdHttpUtils.hh:88
@ HTTP_LENGTH_REQUIRED
Definition: XrdHttpUtils.hh:92
@ HTTP_URI_TOO_LONG
Definition: XrdHttpUtils.hh:95
@ HTTP_UNAVAILABLE_FOR_LEGAL_REASONS
@ HTTP_UNAUTHORIZED
Definition: XrdHttpUtils.hh:82
@ HTTP_UNSUPPORTED_MEDIA_TYPE
Definition: XrdHttpUtils.hh:96
@ HTTP_NOT_FOUND
Definition: XrdHttpUtils.hh:85
@ HTTP_FORBIDDEN
Definition: XrdHttpUtils.hh:84
@ HTTP_CONTINUE
Definition: XrdHttpUtils.hh:53
@ HTTP_MULTI_STATUS
Definition: XrdHttpUtils.hh:66
@ HTTP_PERMANENT_REDIRECT
Definition: XrdHttpUtils.hh:78
@ HTTP_FOUND
Definition: XrdHttpUtils.hh:73
@ HTTP_RESET_CONTENT
Definition: XrdHttpUtils.hh:64
@ HTTP_TEMPORARY_REDIRECT
Definition: XrdHttpUtils.hh:77
@ HTTP_NO_CONTENT
Definition: XrdHttpUtils.hh:63
@ HTTP_MISDIRECTED_REQUEST
@ HTTP_PARTIAL_CONTENT
Definition: XrdHttpUtils.hh:65
@ HTTP_BAD_GATEWAY
@ HTTP_GATEWAY_TIMEOUT
@ HTTP_NETWORK_AUTHENTICATION_REQUIRED
@ HTTP_TOO_EARLY
@ HTTP_METHOD_NOT_ALLOWED
Definition: XrdHttpUtils.hh:86
@ HTTP_NOT_ACCEPTABLE
Definition: XrdHttpUtils.hh:87
@ HTTP_ALREADY_REPORTED
Definition: XrdHttpUtils.hh:67
@ HTTP_EARLY_HINTS
Definition: XrdHttpUtils.hh:56
@ HTTP_GONE
Definition: XrdHttpUtils.hh:91
@ HTTP_INTERNAL_SERVER_ERROR
@ HTTP_UPGRADE_REQUIRED
@ HTTP_IM_USED
Definition: XrdHttpUtils.hh:68
@ HTTP_TOO_MANY_REQUESTS
@ HTTP_PAYLOAD_TOO_LARGE
Definition: XrdHttpUtils.hh:94
@ HTTP_NOT_IMPLEMENTED
@ HTTP_SEE_OTHER
Definition: XrdHttpUtils.hh:74
@ HTTP_PAYMENT_REQUIRED
Definition: XrdHttpUtils.hh:83
@ HTTP_REQUEST_TIMEOUT
Definition: XrdHttpUtils.hh:89
@ HTTP_UNPROCESSABLE_ENTITY
@ HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
@ HTTP_SWITCHING_PROTOCOLS
Definition: XrdHttpUtils.hh:54
@ HTTP_MOVED_PERMANENTLY
Definition: XrdHttpUtils.hh:72
@ HTTP_USE_PROXY
Definition: XrdHttpUtils.hh:76
@ HTTP_PRECONDITION_REQUIRED
@ HTTP_RANGE_NOT_SATISFIABLE
Definition: XrdHttpUtils.hh:97
@ HTTP_ACCEPTED
Definition: XrdHttpUtils.hh:61
@ HTTP_CONFLICT
Definition: XrdHttpUtils.hh:90
@ 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.

230  {
231 
232 
233 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
234  EVP_MAC *mac;
235  EVP_MAC_CTX *ctx;
236  size_t len;
237 #else
238  HMAC_CTX *ctx;
239  unsigned int len;
240 #endif
241  unsigned char mdbuf[EVP_MAX_MD_SIZE];
242  char buf[64];
243  struct tm tms;
244 
245 
246  if (!hash) {
247  return;
248  }
249  hash[0] = '\0';
250 
251  if (!key) {
252  return;
253  }
254 
255  if (!fn || !secent) {
256  return;
257  }
258 
259 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
260 
261  mac = EVP_MAC_fetch(0, "sha256", 0);
262  ctx = EVP_MAC_CTX_new(mac);
263 
264  if (!ctx) {
265  return;
266  }
267 
268 
269  EVP_MAC_init(ctx, (const unsigned char *) key, strlen(key), 0);
270 
271 
272  if (fn)
273  EVP_MAC_update(ctx, (const unsigned char *) fn,
274  strlen(fn) + 1);
275 
276  EVP_MAC_update(ctx, (const unsigned char *) &request,
277  sizeof (request));
278 
279  if (secent->name)
280  EVP_MAC_update(ctx, (const unsigned char *) secent->name,
281  strlen(secent->name) + 1);
282 
283  if (secent->vorg)
284  EVP_MAC_update(ctx, (const unsigned char *) secent->vorg,
285  strlen(secent->vorg) + 1);
286 
287  if (secent->host)
288  EVP_MAC_update(ctx, (const unsigned char *) secent->host,
289  strlen(secent->host) + 1);
290 
291  if (secent->moninfo)
292  EVP_MAC_update(ctx, (const unsigned char *) secent->moninfo,
293  strlen(secent->moninfo) + 1);
294 
295  localtime_r(&tim, &tms);
296  strftime(buf, sizeof (buf), "%s", &tms);
297  EVP_MAC_update(ctx, (const unsigned char *) buf,
298  strlen(buf) + 1);
299 
300  EVP_MAC_final(ctx, mdbuf, &len, EVP_MAX_MD_SIZE);
301 
302  EVP_MAC_CTX_free(ctx);
303  EVP_MAC_free(mac);
304 
305 #else
306 
307  ctx = HMAC_CTX_new();
308 
309  if (!ctx) {
310  return;
311  }
312 
313 
314 
315  HMAC_Init_ex(ctx, (const void *) key, strlen(key), EVP_sha256(), 0);
316 
317 
318  if (fn)
319  HMAC_Update(ctx, (const unsigned char *) fn,
320  strlen(fn) + 1);
321 
322  HMAC_Update(ctx, (const unsigned char *) &request,
323  sizeof (request));
324 
325  if (secent->name)
326  HMAC_Update(ctx, (const unsigned char *) secent->name,
327  strlen(secent->name) + 1);
328 
329  if (secent->vorg)
330  HMAC_Update(ctx, (const unsigned char *) secent->vorg,
331  strlen(secent->vorg) + 1);
332 
333  if (secent->host)
334  HMAC_Update(ctx, (const unsigned char *) secent->host,
335  strlen(secent->host) + 1);
336 
337  if (secent->moninfo)
338  HMAC_Update(ctx, (const unsigned char *) secent->moninfo,
339  strlen(secent->moninfo) + 1);
340 
341  localtime_r(&tim, &tms);
342  strftime(buf, sizeof (buf), "%s", &tms);
343  HMAC_Update(ctx, (const unsigned char *) buf,
344  strlen(buf) + 1);
345 
346  HMAC_Final(ctx, mdbuf, &len);
347 
348  HMAC_CTX_free(ctx);
349 
350 #endif
351 
352  Tobase64(mdbuf, len / 2, hash);
353 }
void Tobase64(const unsigned char *input, int length, char *out)
static void HMAC_CTX_free(HMAC_CTX *ctx)
Definition: XrdHttpUtils.cc:65
static HMAC_CTX * HMAC_CTX_new()
Definition: XrdHttpUtils.cc:59
char * vorg
Entity's virtual organization(s)
Definition: XrdSecEntity.hh:71
char * name
Entity's name.
Definition: XrdSecEntity.hh:69
char * moninfo
Information for monitoring.
Definition: XrdSecEntity.hh:76
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.

357  {
358 
359  if (h1 == h2) return 0;
360 
361  if (!h1 || !h2)
362  return 1;
363 
364  return strcmp(h1, h2);
365 
366 }

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
strthe 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.

172  {
173  size_t strLength = str.length();
174  // uniquely own the temporary copy
175  std::unique_ptr<char[]> buf(new char[strLength + 1]);
176  std::memcpy(buf.get(), str.c_str(), strLength + 1);
177  // unquote returns a fresh malloc()'d pointer
178  return unquote(buf.get());
179 }
char * unquote(char *str)

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.

210  {
211  char * decodedRaw = decode_raw(str);
212  std::string decoded { decodedRaw };
213  free(decodedRaw);
214  return decoded;
215 }
char * decode_raw(const std::string &str)

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
opaquethe opaque query string to encode
Returns
the opaque query string with encoded values

Definition at line 223 of file XrdHttpUtils.hh.

223  {
224  std::ostringstream output;
225  std::vector<std::string> allKeyValues;
226  XrdOucTUtils::splitString(allKeyValues,opaque,"&");
227  bool first = true;
228  for(auto & kv: allKeyValues) {
229  size_t equal = kv.find('=');
230  if(equal != std::string::npos) {
231  std::string key = kv.substr(0, equal);
232  std::string value = kv.substr(equal + 1);
233  if(!first) {
234  output << "&";
235  }
236  output << key << "=" << encode_str(value);
237  first = false;
238  }
239  }
240  return output.str();
241 }
std::string encode_str(const std::string &str)
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
strthe 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.

187  {
188  return quote(str.c_str());
189 }
char * quote(const char *str)

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.

197  {
198  char * encodedRaw = encode_raw(str);
199  std::string encoded { encodedRaw };
200  free(encodedRaw);
201  return encoded;
202 }
char * encode_raw(const std::string &str)

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 461 of file XrdHttpUtils.cc.

461  {
462  int l = strlen(str);
463  char *r = (char *) malloc(l*6 + 1);
464  r[0] = '\0';
465  int i, j = 0;
466 
467  for (i = 0; i < l; i++) {
468  char c = str[i];
469 
470  switch (c) {
471  case '"':
472  strcpy(r + j, "&quot;");
473  j += 6;
474  break;
475  case '&':
476  strcpy(r + j, "&amp;");
477  j += 5;
478  break;
479  case '<':
480  strcpy(r + j, "&lt;");
481  j += 4;
482  break;
483  case '>':
484  strcpy(r + j, "&gt;");
485  j += 4;
486  break;
487  case '\'':
488  strcpy(r + j, "&apos;");
489  j += 6;
490  break;
491 
492  default:
493  r[j++] = c;
494  }
495  }
496 
497  r[j] = '\0';
498 
499  return r;
500 }

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.

169  {
170  for (int idx=0; idx < length; idx += 2) {
171  int upper = char_to_int(input[idx]);
172  int lower = char_to_int(input[idx+1]);
173  if ((upper < 0) || (lower < 0)) {
174  return false;
175  }
176  out[idx/2] = (upper << 4) + lower;
177  }
178  return true;
179 }
static int char_to_int(int c)

References char_to_int().

+ Here is the call graph for this function:

◆ httpStatusToString()

std::string httpStatusToString ( int  status)

Definition at line 582 of file XrdHttpUtils.cc.

582  {
583  switch (status) {
584  // 1xx Informational
585  case 100: return "Continue";
586  case 101: return "Switching Protocols";
587  case 102: return "Processing";
588  case 103: return "Early Hints";
589 
590  // 2xx Success
591  case 200: return "OK";
592  case 201: return "Created";
593  case 202: return "Accepted";
594  case 203: return "Non-Authoritative Information";
595  case 204: return "No Content";
596  case 205: return "Reset Content";
597  case 206: return "Partial Content";
598  case 207: return "Multi-Status";
599  case 208: return "Already Reported";
600  case 226: return "IM Used";
601 
602  // 3xx Redirection
603  case 300: return "Multiple Choices";
604  case 301: return "Moved Permanently";
605  case 302: return "Found";
606  case 303: return "See Other";
607  case 304: return "Not Modified";
608  case 305: return "Use Proxy";
609  case 307: return "Temporary Redirect";
610  case 308: return "Permanent Redirect";
611 
612  // 4xx Client Errors
613  case 400: return "Bad Request";
614  case 401: return "Unauthorized";
615  case 402: return "Payment Required";
616  case 403: return "Forbidden";
617  case 404: return "Not Found";
618  case 405: return "Method Not Allowed";
619  case 406: return "Not Acceptable";
620  case 407: return "Proxy Authentication Required";
621  case 408: return "Request Timeout";
622  case 409: return "Conflict";
623  case 410: return "Gone";
624  case 411: return "Length Required";
625  case 412: return "Precondition Failed";
626  case 413: return "Payload Too Large";
627  case 414: return "URI Too Long";
628  case 415: return "Unsupported Media Type";
629  case 416: return "Range Not Satisfiable";
630  case 417: return "Expectation Failed";
631  case 418: return "I'm a teapot";
632  case 421: return "Misdirected Request";
633  case 422: return "Unprocessable Entity";
634  case 423: return "Locked";
635  case 424: return "Failed Dependency";
636  case 425: return "Too Early";
637  case 426: return "Upgrade Required";
638  case 428: return "Precondition Required";
639  case 429: return "Too Many Requests";
640  case 431: return "Request Header Fields Too Large";
641  case 451: return "Unavailable For Legal Reasons";
642 
643  // 5xx Server Errors
644  case 500: return "Internal Server Error";
645  case 501: return "Not Implemented";
646  case 502: return "Bad Gateway";
647  case 503: return "Service Unavailable";
648  case 504: return "Gateway Timeout";
649  case 505: return "HTTP Version Not Supported";
650  case 506: return "Variant Also Negotiates";
651  case 507: return "Insufficient Storage";
652  case 508: return "Loop Detected";
653  case 510: return "Not Extended";
654  case 511: return "Network Authentication Required";
655 
656  default:
657  switch (status) {
658  case 100 ... 199: return "Informational";
659  case 200 ... 299: return "Success";
660  case 300 ... 399: return "Redirection";
661  case 400 ... 499: return "Client Error";
662  case 500 ... 599: return "Server Error";
663  default: return "Unknown";
664  }
665  }
666 }

◆ itos()

std::string itos ( long  i)

Definition at line 183 of file XrdHttpUtils.cc.

183  {
184  char buf[128];
185  sprintf(buf, "%ld", i);
186 
187  return buf;
188 }

◆ mapErrNoToHttp()

int mapErrNoToHttp ( int  err)

Definition at line 509 of file XrdHttpUtils.cc.

509  {
510 
511  switch (errNo) {
512 
513  case EACCES:
514  case EROFS:
515  case EPERM:
516  return HTTP_FORBIDDEN;
517 
518  case EAUTH:
519  return HTTP_UNAUTHORIZED;
520 
521  case ENOENT:
522  return HTTP_NOT_FOUND;
523 
524  case EEXIST:
525  case EISDIR:
526  case ENOTDIR:
527  case ENOTEMPTY:
528  return HTTP_CONFLICT;
529 
530  case EXDEV:
532 
533  case ENAMETOOLONG:
534  return HTTP_URI_TOO_LONG;
535 
536  case ELOOP:
537  return HTTP_LOOP_DETECTED;
538 
539  case ENOSPC:
540  case EDQUOT:
542 
543  case EFBIG:
544  return HTTP_PAYLOAD_TOO_LARGE;
545 
546  case EINVAL:
547  case EBADF:
548  case EFAULT:
549  case ENXIO:
550  case ESPIPE:
551  case EOVERFLOW:
552  return HTTP_BAD_REQUEST;
553 
554  case ENOTSUP: // EOPNOTSUPP
555  return HTTP_NOT_IMPLEMENTED;
556 
557  case EBUSY:
558  case EAGAIN:
559  case EINTR:
560  case ENOMEM:
561  case EMFILE:
562  case ENFILE:
563  case ETXTBSY:
565 
566  case ETIMEDOUT:
567  return HTTP_GATEWAY_TIMEOUT;
568 
569  case ECONNREFUSED:
570  case ECONNRESET:
571  case ENETDOWN:
572  case ENETUNREACH:
573  case EHOSTUNREACH:
574  case EPIPE:
575  return HTTP_BAD_GATEWAY;
576 
577  default:
579  }
580 }
#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 502 of file XrdHttpUtils.cc.

502  {
503 
504  int errNo = XProtocol::toErrno(xrdError);
505  return mapErrNoToHttp(errNo);
506 
507 }
int mapErrNoToHttp(int errNo)
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.

193  {
194  char *ptr = strchr((char *)s, c);
195 
196  if (!ptr)
197  return strchr((char *)s, '\0');
198 
199  return ptr;
200 }

◆ parseURL()

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

Definition at line 77 of file XrdHttpUtils.cc.

77  {
78  // http://x.y.z.w:p/path
79 
80  *path = 0;
81 
82  // look for the second slash
83  char *p = strstr(url, "//");
84  if (!p) return -1;
85 
86 
87  p += 2;
88 
89  // look for the end of the host:port
90  char *p2 = strchr(p, '/');
91  if (!p2) return -1;
92 
93  *path = p2;
94 
95  char buf[256];
96  int l = std::min((int)(p2 - p), (int)sizeof (buf) - 1);
97  strncpy(buf, p, l);
98  buf[l] = '\0';
99 
100  // Now look for :
101  p = strchr(buf, ':');
102  if (p) {
103  int l = std::min((int)(p - buf), (int)sizeof (buf) - 1);
104  strncpy(host, buf, l);
105  host[l] = '\0';
106 
107  port = atoi(p + 1);
108  } else {
109  port = 0;
110 
111 
112  strcpy(host, buf);
113  }
114 
115  return 0;
116 }

◆ quote()

char* quote ( const char *  str)

Definition at line 402 of file XrdHttpUtils.cc.

402  {
403  int l = strlen(str);
404  char *r = (char *) malloc(l*3 + 1);
405  r[0] = '\0';
406  int i, j = 0;
407 
408  for (i = 0; i < l; i++) {
409  char c = str[i];
410 
411  switch (c) {
412  case ' ':
413  strcpy(r + j, "%20");
414  j += 3;
415  break;
416  case '[':
417  strcpy(r + j, "%5B");
418  j += 3;
419  break;
420  case ']':
421  strcpy(r + j, "%5D");
422  j += 3;
423  break;
424  case ':':
425  strcpy(r + j, "%3A");
426  j += 3;
427  break;
428  // case '/':
429  // strcpy(r + j, "%2F");
430  // j += 3;
431  // break;
432  case '#':
433  strcpy(r + j, "%23");
434  j += 3;
435  break;
436  case '\n':
437  strcpy(r + j, "%0A");
438  j += 3;
439  break;
440  case '\r':
441  strcpy(r + j, "%0D");
442  j += 3;
443  break;
444  case '=':
445  strcpy(r + j, "%3D");
446  j += 3;
447  break;
448  default:
449  r[j++] = c;
450  }
451  }
452 
453  r[j] = '\0';
454 
455  return r;
456 }

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.

121  {
122  BIO *bmem, *b64;
123  BUF_MEM *bptr;
124 
125  if (!out) return;
126 
127  out[0] = '\0';
128 
129  b64 = BIO_new(BIO_f_base64());
130  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
131  bmem = BIO_new(BIO_s_mem());
132  BIO_push(b64, bmem);
133  BIO_write(b64, input, length);
134 
135  if (BIO_flush(b64) <= 0) {
136  BIO_free_all(b64);
137  return;
138  }
139 
140  BIO_get_mem_ptr(b64, &bptr);
141 
142 
143  memcpy(out, bptr->data, bptr->length);
144  out[bptr->length] = '\0';
145 
146  BIO_free_all(b64);
147 
148  return;
149 }
void BIO_set_flags(BIO *bio, int flags)

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.

370  {
371  int l = strlen(str);
372  char *r = (char *) malloc(l + 1);
373  r[0] = '\0';
374  int i, j = 0;
375 
376  for (i = 0; i < l; i++) {
377  if (str[i] == '%') {
378  if (i + 3 > l) {
379  r[j] = '\0';
380  return r;
381  }
382  char savec = str[i + 3];
383  str[i + 3] = '\0';
384 
385  r[j] = strtol(str + i + 1, 0, 16);
386  str[i + 3] = savec;
387 
388  i += 2;
389  } else r[j] = str[i];
390 
391  j++;
392  }
393 
394  r[j] = '\0';
395 
396  return r;
397 
398 }

Referenced by decode_raw().

+ Here is the caller graph for this function: