ATLAS Offline Software
Classes | Typedefs | Enumerations | Functions
urldecode Namespace Reference

Classes

struct  decoder_state_s
 

Typedefs

typedef struct urldecode::decoder_state_s decoder_state
 

Enumerations

enum  states { ST_SYM, ST_PERCENT, ST_PERCENT_AND_SYM }
 

Functions

int is_unreserved (char c)
 
ssize_t urldecode (decoder_state *state, char *data, size_t size)
 Decodes URL-encoded data. More...
 
std::pair< std::string, int > urldecode (decoder_state *state, const std::string &data, size_t size)
 

Typedef Documentation

◆ decoder_state

Enumeration Type Documentation

◆ states

Enumerator
ST_SYM 
ST_PERCENT 
ST_PERCENT_AND_SYM 

Definition at line 39 of file urldecode.h.

Function Documentation

◆ is_unreserved()

int urldecode::is_unreserved ( char  c)

Definition at line 47 of file urldecode.h.

48 {
49  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
50  (c >= '0' && c <= '9') || index("-_.~!*'();:@&=+$,/?%#[]", c);
51 }

◆ urldecode() [1/2]

ssize_t urldecode::urldecode ( decoder_state state,
char *  data,
size_t  size 
)

Decodes URL-encoded data.

Because encoded data is always bigger conversion is done in-place.

Returns
Number of decoded bytes written to data. Negative integer if data is not valid URL-encoded sequence.

Definition at line 59 of file urldecode.h.

60 {
61  size_t inpos = 0, outpos = 0;
62  int d1, d2;
63  while (inpos < size)
64  {
65  char in = data[inpos++];
66  switch (in)
67  {
68  case '%':
69  switch (state->state)
70  {
71  case ST_SYM:
72  state->state = ST_PERCENT;
73  break;
74  default:
75  return -1;
76  }
77  break;
78  case '+':
79  switch (state->state)
80  {
81  case ST_SYM:
82  data[outpos++] = ' ';
83  break;
84  default:
85  return -1;
86  }
87  break;
88  default:
89  switch (state->state)
90  {
91  case ST_PERCENT_AND_SYM:
92  d1 = hexdigit(state->sym), d2 = hexdigit(in);
93  if (d1 >= 0 && d2 >= 0)
94  {
95  data[outpos++] = (d1 << 4) | d2;
96  }
97  else
98  {
99  return -1;
100  }
101  state->state = ST_SYM;
102  break;
103  case ST_PERCENT:
104  state->sym = in;
105  state->state = ST_PERCENT_AND_SYM;
106  break;
107  case ST_SYM:
108  if (is_unreserved(in))
109  {
110  data[outpos++] = in;
111  }
112  else
113  {
114  return -1;
115  }
116  break;
117  }
118  }
119  }
120  return outpos;
121 }

◆ urldecode() [2/2]

std::pair<std::string,int> urldecode::urldecode ( decoder_state state,
const std::string &  data,
size_t  size 
)

Definition at line 124 of file urldecode.h.

125 {
126  size_t inpos = 0;
127  int outpos = 0;
128  int d1, d2;
129  std::stringstream output;
130  while (inpos < size)
131  {
132  char in = data[inpos++];
133  switch (in)
134  {
135  case '%':
136  switch (state->state)
137  {
138  case ST_SYM:
139  state->state = ST_PERCENT;
140  break;
141  default:
142  outpos=-1;
143  }
144  break;
145  case '+':
146  switch (state->state)
147  {
148  case ST_SYM:
149  //data[outpos++] = ' ';
150  output << ' ';
151  break;
152  default:
153  outpos=-1;
154  }
155  break;
156  default:
157  switch (state->state)
158  {
159  case ST_PERCENT_AND_SYM:
160  d1 = hexdigit(state->sym), d2 = hexdigit(in);
161  if (d1 >= 0 && d2 >= 0)
162  {
163  //data[outpos++] = (d1 << 4) | d2;
164  char temp = (d1 << 4) | d2;
165  output << temp;
166  }
167  else
168  {
169  outpos=-1;
170  }
171  state->state = ST_SYM;
172  break;
173  case ST_PERCENT:
174  state->sym = in;
175  state->state = ST_PERCENT_AND_SYM;
176  break;
177  case ST_SYM:
178  if (is_unreserved(in))
179  {
180  //data[outpos++] = in;
181  output << in;
182  }
183  else
184  {
185  outpos=-1;
186  }
187  break;
188  }
189  }
190  }
191  return std::make_pair(output.str(),outpos);
192 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
urldecode::ST_PERCENT_AND_SYM
@ ST_PERCENT_AND_SYM
Definition: urldecode.h:39
merge.output
output
Definition: merge.py:17
urldecode::ST_SYM
@ ST_SYM
Definition: urldecode.h:39
DeMoScan.index
string index
Definition: DeMoScan.py:364
urldecode::is_unreserved
int is_unreserved(char c)
Definition: urldecode.h:47
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
urldecode::ST_PERCENT
@ ST_PERCENT
Definition: urldecode.h:39
python.compressB64.c
def c
Definition: compressB64.py:93