Utility functions for XrdHTTP.
More...
#include "XProtocol/XPtypes.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdOuc/XrdOucIOVec.hh"
#include <string>
#include <vector>
Go to the source code of this file.
|
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 * | escapeXML (const char *str) |
|
bool | Fromhexdigest (const unsigned char *input, int length, unsigned char *out) |
|
std::string | itos (long i) |
|
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) |
|
Utility functions for XrdHTTP.
- Author
- Fabrizio Furano
- Date
- April 2013
Definition in file XrdHttpUtils.hh.
◆ XrdHttpIOList
◆ 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.
233 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
241 unsigned char mdbuf[EVP_MAX_MD_SIZE];
255 if (!fn || !secent) {
259 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
261 mac = EVP_MAC_fetch(0,
"sha256", 0);
262 ctx = EVP_MAC_CTX_new(mac);
269 EVP_MAC_init(ctx, (
const unsigned char *) key, strlen(key), 0);
273 EVP_MAC_update(ctx, (
const unsigned char *) fn,
276 EVP_MAC_update(ctx, (
const unsigned char *) &request,
280 EVP_MAC_update(ctx, (
const unsigned char *) secent->
name,
281 strlen(secent->
name) + 1);
284 EVP_MAC_update(ctx, (
const unsigned char *) secent->
vorg,
285 strlen(secent->
vorg) + 1);
288 EVP_MAC_update(ctx, (
const unsigned char *) secent->
host,
289 strlen(secent->
host) + 1);
292 EVP_MAC_update(ctx, (
const unsigned char *) secent->
moninfo,
295 localtime_r(&tim, &tms);
296 strftime(buf,
sizeof (buf),
"%s", &tms);
297 EVP_MAC_update(ctx, (
const unsigned char *) buf,
300 EVP_MAC_final(ctx, mdbuf, &len, EVP_MAX_MD_SIZE);
302 EVP_MAC_CTX_free(ctx);
315 HMAC_Init_ex(ctx, (
const void *) key, strlen(key), EVP_sha256(), 0);
319 HMAC_Update(ctx, (
const unsigned char *) fn,
322 HMAC_Update(ctx, (
const unsigned char *) &request,
326 HMAC_Update(ctx, (
const unsigned char *) secent->
name,
327 strlen(secent->
name) + 1);
330 HMAC_Update(ctx, (
const unsigned char *) secent->
vorg,
331 strlen(secent->
vorg) + 1);
334 HMAC_Update(ctx, (
const unsigned char *) secent->
host,
335 strlen(secent->
host) + 1);
338 HMAC_Update(ctx, (
const unsigned char *) secent->
moninfo,
341 localtime_r(&tim, &tms);
342 strftime(buf,
sizeof (buf),
"%s", &tms);
343 HMAC_Update(ctx, (
const unsigned char *) buf,
346 HMAC_Final(ctx, mdbuf, &len);
void Tobase64(const unsigned char *input, int length, char *out)
static void HMAC_CTX_free(HMAC_CTX *ctx)
static HMAC_CTX * HMAC_CTX_new()
char * vorg
Entity's virtual organization(s)
char * name
Entity's name.
char * moninfo
Information for monitoring.
char * host
Entity's host name dnr dependent.
References HMAC_CTX_free(), HMAC_CTX_new(), XrdSecEntity::host, XrdSecEntity::moninfo, XrdSecEntity::name, Tobase64(), and XrdSecEntity::vorg.
Referenced by XrdHttpProtocol::Process(), and XrdHttpReq::Redir().
◆ compareHash()
int compareHash |
( |
const char * |
h1, |
|
|
const char * |
h2 |
|
) |
| |
◆ escapeXML()
char* escapeXML |
( |
const char * |
str | ) |
|
Definition at line 455 of file XrdHttpUtils.cc.
457 char *r = (
char *) malloc(l*6 + 1);
461 for (i = 0; i < l; i++) {
466 strcpy(r + j,
""");
470 strcpy(r + j,
"&");
474 strcpy(r + j,
"<");
478 strcpy(r + j,
">");
482 strcpy(r + j,
"'");
Referenced by XrdHttpReq::Error().
◆ Fromhexdigest()
bool Fromhexdigest |
( |
const unsigned char * |
input, |
|
|
int |
length, |
|
|
unsigned char * |
out |
|
) |
| |
Definition at line 169 of file XrdHttpUtils.cc.
170 for (
int idx=0; idx < length; idx += 2) {
173 if ((upper < 0) || (lower < 0)) {
176 out[idx/2] = (upper << 4) + lower;
static int char_to_int(int c)
References char_to_int().
◆ itos()
std::string itos |
( |
long |
i | ) |
|
◆ mystrchrnul()
char* mystrchrnul |
( |
const char * |
s, |
|
|
int |
c |
|
) |
| |
Definition at line 193 of file XrdHttpUtils.cc.
194 char *ptr = strchr((
char *)s, c);
197 return strchr((
char *)s,
'\0');
◆ parseURL()
int parseURL |
( |
char * |
url, |
|
|
char * |
host, |
|
|
int & |
port, |
|
|
char ** |
path |
|
) |
| |
Definition at line 77 of file XrdHttpUtils.cc.
83 char *p = strstr(url,
"//");
90 char *p2 = strchr(p,
'/');
96 int l = std::min((
int)(p2 - p), (
int)
sizeof (buf));
101 p = strchr(buf,
':');
103 int l = std::min((
int)(p - buf), (
int)
sizeof (buf));
104 strncpy(host, buf, l);
Referenced by XrdHttpReq::ProcessHTTPReq().
◆ quote()
char* quote |
( |
const char * |
str | ) |
|
◆ Tobase64()
void Tobase64 |
( |
const unsigned char * |
input, |
|
|
int |
length, |
|
|
char * |
out |
|
) |
| |
Definition at line 121 of file XrdHttpUtils.cc.
129 b64 = BIO_new(BIO_f_base64());
131 bmem = BIO_new(BIO_s_mem());
133 BIO_write(b64, input, length);
135 if (BIO_flush(b64) <= 0) {
140 BIO_get_mem_ptr(b64, &bptr);
143 memcpy(out, bptr->data, bptr->length);
144 out[bptr->length] =
'\0';
void BIO_set_flags(BIO *bio, int flags)
References BIO_set_flags().
Referenced by calcHashes().
◆ unquote()
char* unquote |
( |
char * |
str | ) |
|
Definition at line 375 of file XrdHttpUtils.cc.
377 char *r = (
char *) malloc(l + 1);
381 for (i = 0; i < l; i++) {
384 char savec = str[i + 3];
387 r[j] = strtol(str + i + 1, 0, 16);
391 }
else r[j] = str[i];
Referenced by XrdHttpProtocol::Process().