aboutsummaryrefslogtreecommitdiff
path: root/src/lib/internal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/internal.c')
-rw-r--r--src/lib/internal.c288
1 files changed, 144 insertions, 144 deletions
diff --git a/src/lib/internal.c b/src/lib/internal.c
index 75eae8a4..04d83624 100644
--- a/src/lib/internal.c
+++ b/src/lib/internal.c
@@ -35,50 +35,50 @@ const char *
35MHD_state_to_string (enum MHD_CONNECTION_STATE state) 35MHD_state_to_string (enum MHD_CONNECTION_STATE state)
36{ 36{
37 switch (state) 37 switch (state)
38 { 38 {
39 case MHD_CONNECTION_INIT: 39 case MHD_CONNECTION_INIT:
40 return "connection init"; 40 return "connection init";
41 case MHD_CONNECTION_URL_RECEIVED: 41 case MHD_CONNECTION_URL_RECEIVED:
42 return "connection url received"; 42 return "connection url received";
43 case MHD_CONNECTION_HEADER_PART_RECEIVED: 43 case MHD_CONNECTION_HEADER_PART_RECEIVED:
44 return "header partially received"; 44 return "header partially received";
45 case MHD_CONNECTION_HEADERS_RECEIVED: 45 case MHD_CONNECTION_HEADERS_RECEIVED:
46 return "headers received"; 46 return "headers received";
47 case MHD_CONNECTION_HEADERS_PROCESSED: 47 case MHD_CONNECTION_HEADERS_PROCESSED:
48 return "headers processed"; 48 return "headers processed";
49 case MHD_CONNECTION_CONTINUE_SENDING: 49 case MHD_CONNECTION_CONTINUE_SENDING:
50 return "continue sending"; 50 return "continue sending";
51 case MHD_CONNECTION_CONTINUE_SENT: 51 case MHD_CONNECTION_CONTINUE_SENT:
52 return "continue sent"; 52 return "continue sent";
53 case MHD_CONNECTION_BODY_RECEIVED: 53 case MHD_CONNECTION_BODY_RECEIVED:
54 return "body received"; 54 return "body received";
55 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 55 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
56 return "footer partially received"; 56 return "footer partially received";
57 case MHD_CONNECTION_FOOTERS_RECEIVED: 57 case MHD_CONNECTION_FOOTERS_RECEIVED:
58 return "footers received"; 58 return "footers received";
59 case MHD_CONNECTION_HEADERS_SENDING: 59 case MHD_CONNECTION_HEADERS_SENDING:
60 return "headers sending"; 60 return "headers sending";
61 case MHD_CONNECTION_HEADERS_SENT: 61 case MHD_CONNECTION_HEADERS_SENT:
62 return "headers sent"; 62 return "headers sent";
63 case MHD_CONNECTION_NORMAL_BODY_READY: 63 case MHD_CONNECTION_NORMAL_BODY_READY:
64 return "normal body ready"; 64 return "normal body ready";
65 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 65 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
66 return "normal body unready"; 66 return "normal body unready";
67 case MHD_CONNECTION_CHUNKED_BODY_READY: 67 case MHD_CONNECTION_CHUNKED_BODY_READY:
68 return "chunked body ready"; 68 return "chunked body ready";
69 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 69 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
70 return "chunked body unready"; 70 return "chunked body unready";
71 case MHD_CONNECTION_BODY_SENT: 71 case MHD_CONNECTION_BODY_SENT:
72 return "body sent"; 72 return "body sent";
73 case MHD_CONNECTION_FOOTERS_SENDING: 73 case MHD_CONNECTION_FOOTERS_SENDING:
74 return "footers sending"; 74 return "footers sending";
75 case MHD_CONNECTION_FOOTERS_SENT: 75 case MHD_CONNECTION_FOOTERS_SENT:
76 return "footers sent"; 76 return "footers sent";
77 case MHD_CONNECTION_CLOSED: 77 case MHD_CONNECTION_CLOSED:
78 return "closed"; 78 return "closed";
79 default: 79 default:
80 return "unrecognized connection state"; 80 return "unrecognized connection state";
81 } 81 }
82} 82}
83#endif 83#endif
84#endif 84#endif
@@ -91,7 +91,7 @@ MHD_state_to_string (enum MHD_CONNECTION_STATE state)
91 */ 91 */
92void 92void
93MHD_DLOG (const struct MHD_Daemon *daemon, 93MHD_DLOG (const struct MHD_Daemon *daemon,
94 enum MHD_StatusCode sc, 94 enum MHD_StatusCode sc,
95 const char *format, 95 const char *format,
96 ...) 96 ...)
97{ 97{
@@ -100,11 +100,11 @@ MHD_DLOG (const struct MHD_Daemon *daemon,
100 if (NULL == daemon->logger) 100 if (NULL == daemon->logger)
101 return; 101 return;
102 va_start (va, 102 va_start (va,
103 format); 103 format);
104 daemon->logger (daemon->logger_cls, 104 daemon->logger (daemon->logger_cls,
105 sc, 105 sc,
106 format, 106 format,
107 va); 107 va);
108 va_end (va); 108 va_end (va);
109} 109}
110#endif 110#endif
@@ -120,7 +120,7 @@ MHD_unescape_plus (char *arg)
120{ 120{
121 char *p; 121 char *p;
122 122
123 for (p=strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+')) 123 for (p = strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+'))
124 *p = ' '; 124 *p = ' ';
125} 125}
126 126
@@ -141,28 +141,28 @@ MHD_http_unescape (char *val)
141 char *wpos = val; 141 char *wpos = val;
142 142
143 while ('\0' != *rpos) 143 while ('\0' != *rpos)
144 {
145 uint32_t num;
146 switch (*rpos)
144 { 147 {
145 uint32_t num; 148 case '%':
146 switch (*rpos) 149 if (2 == MHD_strx_to_uint32_n_ (rpos + 1,
147 { 150 2,
148 case '%': 151 &num))
149 if (2 == MHD_strx_to_uint32_n_ (rpos + 1, 152 {
150 2, 153 *wpos = (char) ((unsigned char) num);
151 &num)) 154 wpos++;
152 { 155 rpos += 3;
153 *wpos = (char)((unsigned char) num); 156 break;
154 wpos++; 157 }
155 rpos += 3; 158 /* TODO: add bad sequence handling */
156 break; 159 /* intentional fall through! */
157 } 160 default:
158 /* TODO: add bad sequence handling */ 161 *wpos = *rpos;
159 /* intentional fall through! */ 162 wpos++;
160 default: 163 rpos++;
161 *wpos = *rpos;
162 wpos++;
163 rpos++;
164 }
165 } 164 }
165 }
166 *wpos = '\0'; /* add 0-terminator */ 166 *wpos = '\0'; /* add 0-terminator */
167 return wpos - val; /* = strlen(val) */ 167 return wpos - val; /* = strlen(val) */
168} 168}
@@ -184,10 +184,10 @@ MHD_http_unescape (char *val)
184 */ 184 */
185bool 185bool
186MHD_parse_arguments_ (struct MHD_Request *request, 186MHD_parse_arguments_ (struct MHD_Request *request,
187 enum MHD_ValueKind kind, 187 enum MHD_ValueKind kind,
188 char *args, 188 char *args,
189 MHD_ArgumentIterator_ cb, 189 MHD_ArgumentIterator_ cb,
190 unsigned int *num_headers) 190 unsigned int *num_headers)
191{ 191{
192 struct MHD_Daemon *daemon = request->daemon; 192 struct MHD_Daemon *daemon = request->daemon;
193 char *equals; 193 char *equals;
@@ -195,88 +195,88 @@ MHD_parse_arguments_ (struct MHD_Request *request,
195 195
196 *num_headers = 0; 196 *num_headers = 0;
197 while ( (NULL != args) && 197 while ( (NULL != args) &&
198 ('\0' != args[0]) ) 198 ('\0' != args[0]) )
199 {
200 equals = strchr (args, '=');
201 amper = strchr (args, '&');
202 if (NULL == amper)
199 { 203 {
200 equals = strchr (args, '='); 204 /* last argument */
201 amper = strchr (args, '&'); 205 if (NULL == equals)
202 if (NULL == amper) 206 {
203 { 207 /* last argument, without '=' */
204 /* last argument */ 208 MHD_unescape_plus (args);
205 if (NULL == equals) 209 daemon->unescape_cb (daemon->unescape_cb_cls,
206 { 210 request,
207 /* last argument, without '=' */ 211 args);
208 MHD_unescape_plus (args); 212 if (! cb (request,
209 daemon->unescape_cb (daemon->unescape_cb_cls, 213 args,
210 request, 214 NULL,
211 args); 215 kind))
212 if (! cb (request, 216 return false;
213 args, 217 (*num_headers)++;
214 NULL, 218 break;
215 kind)) 219 }
216 return false; 220 /* got 'foo=bar' */
217 (*num_headers)++;
218 break;
219 }
220 /* got 'foo=bar' */
221 equals[0] = '\0';
222 equals++;
223 MHD_unescape_plus (args);
224 daemon->unescape_cb (daemon->unescape_cb_cls,
225 request,
226 args);
227 MHD_unescape_plus (equals);
228 daemon->unescape_cb (daemon->unescape_cb_cls,
229 request,
230 equals);
231 if (! cb (request,
232 args,
233 equals,
234 kind))
235 return false;
236 (*num_headers)++;
237 break;
238 }
239 /* amper is non-NULL here */
240 amper[0] = '\0';
241 amper++;
242 if ( (NULL == equals) ||
243 (equals >= amper) )
244 {
245 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
246 MHD_unescape_plus (args);
247 daemon->unescape_cb (daemon->unescape_cb_cls,
248 request,
249 args);
250 if (! cb (request,
251 args,
252 NULL,
253 kind))
254 return false;
255 /* continue with 'bar' */
256 (*num_headers)++;
257 args = amper;
258 continue;
259 }
260 /* equals and amper are non-NULL here, and equals < amper,
261 so we got regular 'foo=value&bar...'-kind of argument */
262 equals[0] = '\0'; 221 equals[0] = '\0';
263 equals++; 222 equals++;
264 MHD_unescape_plus (args); 223 MHD_unescape_plus (args);
265 daemon->unescape_cb (daemon->unescape_cb_cls, 224 daemon->unescape_cb (daemon->unescape_cb_cls,
266 request, 225 request,
267 args); 226 args);
268 MHD_unescape_plus (equals); 227 MHD_unescape_plus (equals);
269 daemon->unescape_cb (daemon->unescape_cb_cls, 228 daemon->unescape_cb (daemon->unescape_cb_cls,
270 request, 229 request,
271 equals); 230 equals);
231 if (! cb (request,
232 args,
233 equals,
234 kind))
235 return false;
236 (*num_headers)++;
237 break;
238 }
239 /* amper is non-NULL here */
240 amper[0] = '\0';
241 amper++;
242 if ( (NULL == equals) ||
243 (equals >= amper) )
244 {
245 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
246 MHD_unescape_plus (args);
247 daemon->unescape_cb (daemon->unescape_cb_cls,
248 request,
249 args);
272 if (! cb (request, 250 if (! cb (request,
273 args, 251 args,
274 equals, 252 NULL,
275 kind)) 253 kind))
276 return false; 254 return false;
255 /* continue with 'bar' */
277 (*num_headers)++; 256 (*num_headers)++;
278 args = amper; 257 args = amper;
258 continue;
279 } 259 }
260 /* equals and amper are non-NULL here, and equals < amper,
261 so we got regular 'foo=value&bar...'-kind of argument */
262 equals[0] = '\0';
263 equals++;
264 MHD_unescape_plus (args);
265 daemon->unescape_cb (daemon->unescape_cb_cls,
266 request,
267 args);
268 MHD_unescape_plus (equals);
269 daemon->unescape_cb (daemon->unescape_cb_cls,
270 request,
271 equals);
272 if (! cb (request,
273 args,
274 equals,
275 kind))
276 return false;
277 (*num_headers)++;
278 args = amper;
279 }
280 return true; 280 return true;
281} 281}
282 282