diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 87 |
1 files changed, 55 insertions, 32 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index bc44e665..0df31992 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -254,8 +254,9 @@ MHD_http_unescape(char * val) { | |||
254 | } | 254 | } |
255 | 255 | ||
256 | static void | 256 | static void |
257 | MHD_parse_arguments(struct MHD_Connection * connection, | 257 | parse_arguments(enum MHD_ValueKind kind, |
258 | char * args) { | 258 | struct MHD_Connection * connection, |
259 | char * args) { | ||
259 | char * equals; | 260 | char * equals; |
260 | char * amper; | 261 | char * amper; |
261 | 262 | ||
@@ -273,9 +274,9 @@ MHD_parse_arguments(struct MHD_Connection * connection, | |||
273 | MHD_http_unescape(args); | 274 | MHD_http_unescape(args); |
274 | MHD_http_unescape(equals); | 275 | MHD_http_unescape(equals); |
275 | MHD_connection_add_header(connection, | 276 | MHD_connection_add_header(connection, |
276 | args, | 277 | args, |
277 | equals, | 278 | equals, |
278 | MHD_GET_ARGUMENT_KIND); | 279 | kind); |
279 | args = amper; | 280 | args = amper; |
280 | } | 281 | } |
281 | } | 282 | } |
@@ -336,6 +337,49 @@ MHD_parse_cookie_header(struct MHD_Connection * connection) { | |||
336 | free(cpy); | 337 | free(cpy); |
337 | } | 338 | } |
338 | 339 | ||
340 | /** | ||
341 | * Parse the first line of the HTTP HEADER. | ||
342 | * | ||
343 | * @param connection the connection (updated) | ||
344 | * @param line the first line | ||
345 | * @return MHD_YES if the line is ok, MHD_NO if it is malformed | ||
346 | */ | ||
347 | static int | ||
348 | parse_initial_message_line(struct MHD_Connection * connection, | ||
349 | char * line) { | ||
350 | char * uri; | ||
351 | char * httpVersion; | ||
352 | char * args; | ||
353 | |||
354 | uri = strstr(line, " "); | ||
355 | if (uri == NULL) | ||
356 | return MHD_NO; /* serious error */ | ||
357 | uri[0] = '\0'; | ||
358 | connection->method = strdup(line); | ||
359 | uri++; | ||
360 | while (uri[0] == ' ') | ||
361 | uri++; | ||
362 | httpVersion = strstr(uri, " "); | ||
363 | if (httpVersion != NULL) { | ||
364 | httpVersion[0] = '\0'; | ||
365 | httpVersion++; | ||
366 | } | ||
367 | args = strstr(uri, "?"); | ||
368 | if (args != NULL) { | ||
369 | args[0] = '\0'; | ||
370 | args++; | ||
371 | parse_arguments(MHD_GET_ARGUMENT_KIND, | ||
372 | connection, | ||
373 | args); | ||
374 | } | ||
375 | connection->url = strdup(uri); | ||
376 | if (httpVersion == NULL) | ||
377 | connection->version = strdup(""); | ||
378 | else | ||
379 | connection->version = strdup(httpVersion); | ||
380 | return MHD_YES; | ||
381 | } | ||
382 | |||
339 | 383 | ||
340 | /** | 384 | /** |
341 | * This function is designed to parse the input buffer of a given connection. | 385 | * This function is designed to parse the input buffer of a given connection. |
@@ -352,9 +396,6 @@ MHD_parse_connection_headers(struct MHD_Connection * connection) { | |||
352 | char * last; | 396 | char * last; |
353 | char * line; | 397 | char * line; |
354 | char * colon; | 398 | char * colon; |
355 | char * uri; | ||
356 | char * httpType; | ||
357 | char * args; | ||
358 | char * tmp; | 399 | char * tmp; |
359 | const char * clen; | 400 | const char * clen; |
360 | unsigned long long cval; | 401 | unsigned long long cval; |
@@ -401,30 +442,12 @@ MHD_parse_connection_headers(struct MHD_Connection * connection) { | |||
401 | } | 442 | } |
402 | } | 443 | } |
403 | if (connection->url == NULL) { | 444 | if (connection->url == NULL) { |
404 | /* line must be request line */ | 445 | /* line must be request line (first line of header) */ |
405 | uri = strstr(line, " "); | 446 | if (MHD_NO == parse_initial_message_line(connection, |
406 | if (uri == NULL) | 447 | line)) { |
448 | free(line); | ||
407 | goto DIE; | 449 | goto DIE; |
408 | uri[0] = '\0'; | ||
409 | connection->method = strdup(line); | ||
410 | uri++; | ||
411 | httpType = strstr(uri, " "); | ||
412 | if (httpType != NULL) { | ||
413 | httpType[0] = '\0'; | ||
414 | httpType++; | ||
415 | } | ||
416 | args = strstr(uri, "?"); | ||
417 | if (args != NULL) { | ||
418 | args[0] = '\0'; | ||
419 | args++; | ||
420 | MHD_parse_arguments(connection, | ||
421 | args); | ||
422 | } | 450 | } |
423 | connection->url = strdup(uri); | ||
424 | if (httpType == NULL) | ||
425 | connection->version = strdup(""); | ||
426 | else | ||
427 | connection->version = strdup(httpType); | ||
428 | free(line); | 451 | free(line); |
429 | continue; | 452 | continue; |
430 | } | 453 | } |
@@ -434,8 +457,8 @@ MHD_parse_connection_headers(struct MHD_Connection * connection) { | |||
434 | /* end of header */ | 457 | /* end of header */ |
435 | connection->headersReceived = 1; | 458 | connection->headersReceived = 1; |
436 | clen = MHD_lookup_connection_value(connection, | 459 | clen = MHD_lookup_connection_value(connection, |
437 | MHD_HEADER_KIND, | 460 | MHD_HEADER_KIND, |
438 | "Content-Length"); | 461 | "Content-Length"); |
439 | if (clen != NULL) { | 462 | if (clen != NULL) { |
440 | if (1 != sscanf(clen, | 463 | if (1 != sscanf(clen, |
441 | "%llu", | 464 | "%llu", |