XRootD
XrdOucUri Class Reference

#include <XrdOucUri.hh>

+ Collaboration diagram for XrdOucUri:

Public Member Functions

 XrdOucUri ()
 
 ~XrdOucUri ()
 

Static Public Member Functions

static int Decode (const char *src, int len, char *dst)
 
static int Encode (const char *src, int len, char **dst)
 
static int Encode (const char *src, int len, char *dst)
 
static int Encoded (const char *src, int len)
 

Detailed Description

Definition at line 44 of file XrdOucUri.hh.

Constructor & Destructor Documentation

◆ XrdOucUri()

XrdOucUri::XrdOucUri ( )
inline

Definition at line 100 of file XrdOucUri.hh.

100 {}

◆ ~XrdOucUri()

XrdOucUri::~XrdOucUri ( )
inline

Definition at line 101 of file XrdOucUri.hh.

101 {}

Member Function Documentation

◆ Decode()

int XrdOucUri::Decode ( const char *  src,
int  len,
char *  dst 
)
static

Decode a url encoded string

Parameters
srcPointer to the source string to decode
lenThe length of src (i.e. strlen(src)).
dstPointer to the buffer where to put the result. The buffer should be at least as long as the src, including null byte.
Returns
The index of the null byte (i.e. end of string) in dst.

Definition at line 116 of file XrdOucUri.cc.

117 {
118  int i = 0, j = 0;
119  unsigned char v1, v2;
120 
121 // Run through looking for any sequences that need to be converted.
122 //
123  while(i < len)
124  {if(src[i] == '%' && i + 2 < len)
125  {v1 = hexval[ (unsigned char)src[i+1] ];
126  v2 = hexval[ (unsigned char)src[i+2] ];
127 
128  /* skip invalid hex sequences */
129  if ((v1 | v2) == 0xFF) dst[j++] = src[i++];
130  else {dst[j++] = (v1 << 4) | v2;
131  i += 3;
132  }
133  } else dst[j++] = src[i++];
134  }
135 
136 // All done, add null byte and return its index
137 //
138  dst[j] = '\0';
139  return j;
140 }

◆ Encode() [1/2]

int XrdOucUri::Encode ( const char *  src,
int  len,
char **  dst 
)
static

Encode an ASCII text string

Parameters
srcPointer to the source string to encode
lenThe length of src (i.e. strlen(src)).
dstPointer to where the allocated buffer pointer should be placed. This buffer holds the result and must be released using free() when no longer needed.
Returns
The index of the null byte (i.e. end of string) in dst.

Definition at line 146 of file XrdOucUri.cc.

147 {
148 
149 // Get the size of the destination buffer
150 //
151  int n = Encoded(src, len);
152 
153 // Allocate an output buffer
154 //
155  if (!(*dst = (char *)malloc(n))) return 0;
156 
157 // Return final result
158 //
159  return Encode(src, len, *dst);
160 }
static int Encode(const char *src, int len, char **dst)
Definition: XrdOucUri.cc:146
static int Encoded(const char *src, int len)
Definition: XrdOucUri.cc:190

References Encoded().

+ Here is the call graph for this function:

◆ Encode() [2/2]

int XrdOucUri::Encode ( const char *  src,
int  len,
char *  dst 
)
static

Encode an ASCII text string

Parameters
srcPointer to the source string to encode
lenThe length of src (i.e. strlen(src)).
dstPointer to the buffer where to put the result. The buffer should be long enough to hold the result. Use the Encoded() method to determine how many bytes will be needed.
Returns
The index of the null byte (i.e. end of string) in dst.

Definition at line 164 of file XrdOucUri.cc.

165 {
166  const unsigned char *code;
167  int j = 0;
168 
169 // Encode every character that needs to be encoded
170 //
171  for(int i = 0; i < len; i++)
172  {code = &uri_encode_tbl[((unsigned int)((unsigned char)src[i])) << 1];
173  if (*code)
174  {dst[j++] = '%';
175  memcpy(&dst[j], code, 2);
176  j += 2;
177  } else dst[j++] = src[i];
178  }
179 
180 // All done, end with null byte and return index to that byte
181 //
182  dst[j] = '\0';
183  return j;
184 }

◆ Encoded()

int XrdOucUri::Encoded ( const char *  src,
int  len 
)
static

Calculate the number of bytes an encoded string will occupy.

Parameters
srcPointer to the source string to encode
lenThe length of src (i.e. strlen(src)).
Returns
The number of bytes needed, including the ending null byte.

Definition at line 190 of file XrdOucUri.cc.

191 {
192  int totlen = 0;
193 
194 // Calculate the size that the destination buffer must have
195 //
196  for(int i = 0; i < len; i++)
197  {totlen += (uri_encode_tbl[((unsigned int)src[i]) << 1] ? 3 : 1);}
198 
199 // Return size needed for destination buffer
200 //
201  return totlen + 1;
202 }

Referenced by Encode().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: