diff options
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/session.c | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/src/daemon/session.c b/src/daemon/session.c index 828b91a1..885d4d97 100644 --- a/src/daemon/session.c +++ b/src/daemon/session.c | |||
@@ -207,6 +207,69 @@ MHD_get_next_header_line(struct MHD_Session * session) { | |||
207 | return rbuf; | 207 | return rbuf; |
208 | } | 208 | } |
209 | 209 | ||
210 | static void | ||
211 | MHD_session_add_header(struct MHD_Session * session, | ||
212 | const char * key, | ||
213 | const char * value, | ||
214 | enum MHD_ValueKind kind) { | ||
215 | struct MHD_HTTP_Header * hdr; | ||
216 | |||
217 | hdr = malloc(sizeof(struct MHD_HTTP_Header)); | ||
218 | hdr->next = session->headers_received; | ||
219 | hdr->header = strdup(key); | ||
220 | hdr->value = strdup(value); | ||
221 | hdr->kind = kind; | ||
222 | session->headers_received = hdr; | ||
223 | } | ||
224 | |||
225 | static void | ||
226 | MHD_http_unescape(char * val) { | ||
227 | char * esc; | ||
228 | unsigned int num; | ||
229 | |||
230 | while (NULL != (esc = strstr(val, "%"))) { | ||
231 | if ( (1 == sscanf(&esc[1], | ||
232 | "%2x", | ||
233 | &num)) || | ||
234 | (1 == sscanf(&esc[1], | ||
235 | "%2X", | ||
236 | &num)) ) { | ||
237 | esc[0] = (unsigned char) num; | ||
238 | memmove(&esc[1], | ||
239 | &esc[3], | ||
240 | strlen(&esc[3])); | ||
241 | } | ||
242 | val = esc+1; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | static void | ||
247 | MHD_parse_arguments(struct MHD_Session * session, | ||
248 | char * args) { | ||
249 | char * equals; | ||
250 | char * amper; | ||
251 | |||
252 | while (args != NULL) { | ||
253 | equals = strstr(args, "="); | ||
254 | if (equals == NULL) | ||
255 | return; /* invalid, ignore */ | ||
256 | equals[0] = '\0'; | ||
257 | equals++; | ||
258 | amper = strstr(equals, "&"); | ||
259 | if (amper != NULL) { | ||
260 | amper[0] = '\0'; | ||
261 | amper++; | ||
262 | } | ||
263 | MHD_http_unescape(args); | ||
264 | MHD_http_unescape(equals); | ||
265 | MHD_session_add_header(session, | ||
266 | args, | ||
267 | equals, | ||
268 | MHD_GET_ARGUMENT_KIND); | ||
269 | args = amper; | ||
270 | } | ||
271 | } | ||
272 | |||
210 | /** | 273 | /** |
211 | * This function is designed to parse the input buffer of a given session. | 274 | * This function is designed to parse the input buffer of a given session. |
212 | * | 275 | * |
@@ -223,7 +286,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
223 | char * colon; | 286 | char * colon; |
224 | char * uri; | 287 | char * uri; |
225 | char * httpType; | 288 | char * httpType; |
226 | struct MHD_HTTP_Header * hdr; | 289 | char * args; |
227 | 290 | ||
228 | if (session->bodyReceived == 1) | 291 | if (session->bodyReceived == 1) |
229 | abort(); | 292 | abort(); |
@@ -239,6 +302,13 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
239 | httpType = strstr(uri, " "); | 302 | httpType = strstr(uri, " "); |
240 | if (httpType != NULL) | 303 | if (httpType != NULL) |
241 | httpType[0] = '\0'; | 304 | httpType[0] = '\0'; |
305 | args = strstr(uri, "?"); | ||
306 | if (args != NULL) { | ||
307 | args[0] = '\0'; | ||
308 | args++; | ||
309 | MHD_parse_arguments(session, | ||
310 | args); | ||
311 | } | ||
242 | /* FIXME: parse URI some more here */ | 312 | /* FIXME: parse URI some more here */ |
243 | session->url = strdup(uri); | 313 | session->url = strdup(uri); |
244 | /* do we want to do anything with httpType? */ | 314 | /* do we want to do anything with httpType? */ |
@@ -249,7 +319,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
249 | if (strlen(line) == 0) { | 319 | if (strlen(line) == 0) { |
250 | /* end of header */ | 320 | /* end of header */ |
251 | session->headersReceived = 1; | 321 | session->headersReceived = 1; |
252 | /* FIXME: check with methods may have a body, | 322 | /* FIXME: check which methods may have a body, |
253 | check headers to find out upload size */ | 323 | check headers to find out upload size */ |
254 | session->uploadSize = 0; | 324 | session->uploadSize = 0; |
255 | session->bodyReceived = 1; | 325 | session->bodyReceived = 1; |
@@ -267,12 +337,11 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
267 | /* zero-terminate header */ | 337 | /* zero-terminate header */ |
268 | colon[0] = '\0'; | 338 | colon[0] = '\0'; |
269 | colon += 2; /* advance to value */ | 339 | colon += 2; /* advance to value */ |
270 | hdr = malloc(sizeof(struct MHD_HTTP_Header)); | 340 | MHD_session_add_header(session, |
271 | hdr->next = session->headers_received; | 341 | line, |
272 | hdr->header = line; | 342 | colon, |
273 | hdr->value = strdup(colon); | 343 | MHD_HEADER_KIND); |
274 | hdr->kind = MHD_HEADER_KIND; | 344 | free(line); |
275 | session->headers_received = hdr; | ||
276 | } | 345 | } |
277 | /* FIXME: here: find cookie header and parse that! */ | 346 | /* FIXME: here: find cookie header and parse that! */ |
278 | return; | 347 | return; |