aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon/daemontest_post.c7
-rw-r--r--src/daemon/daemontest_postform.c5
-rw-r--r--src/daemon/postprocessor.c89
3 files changed, 46 insertions, 55 deletions
diff --git a/src/daemon/daemontest_post.c b/src/daemon/daemontest_post.c
index 86fd67f9..e7ac257a 100644
--- a/src/daemon/daemontest_post.c
+++ b/src/daemon/daemontest_post.c
@@ -20,12 +20,7 @@
20 20
21/** 21/**
22 * @file daemontest_post.c 22 * @file daemontest_post.c
23 * @brief Testcase for libmicrohttpd POST operations 23 * @brief Testcase for libmicrohttpd POST operations using URL-encoding
24 * TODO: use curl_formadd to produce POST data and
25 * add that to the CURL operation; then check
26 * on the server side if the headers arrive
27 * nicely (need to implement parsing POST data
28 * first!)
29 * @author Christian Grothoff 24 * @author Christian Grothoff
30 */ 25 */
31 26
diff --git a/src/daemon/daemontest_postform.c b/src/daemon/daemontest_postform.c
index a82d4705..c94e2b06 100644
--- a/src/daemon/daemontest_postform.c
+++ b/src/daemon/daemontest_postform.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file daemontest_post.c 22 * @file daemontest_post.c
23 * @brief Testcase for libmicrohttpd POST operations 23 * @brief Testcase for libmicrohttpd POST operations using multipart/postform data
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26 26
@@ -107,6 +107,8 @@ ahc_echo (void *cls,
107 { 107 {
108 eok = 0; 108 eok = 0;
109 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok); 109 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
110 if (pp == NULL)
111 abort();
110 *unused = pp; 112 *unused = pp;
111 } 113 }
112 MHD_post_process (pp, upload_data, *upload_data_size); 114 MHD_post_process (pp, upload_data, *upload_data_size);
@@ -161,7 +163,6 @@ testInternalPost ()
161 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); 163 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
162 pd = make_form(); 164 pd = make_form();
163 curl_easy_setopt(c, CURLOPT_HTTPPOST, pd); 165 curl_easy_setopt(c, CURLOPT_HTTPPOST, pd);
164 curl_easy_setopt (c, CURLOPT_VERBOSE, 1L);
165 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); 166 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
166 curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L); 167 curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L);
167 if (oneone) 168 if (oneone)
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c
index 5fbf4068..3ce715ee 100644
--- a/src/daemon/postprocessor.c
+++ b/src/daemon/postprocessor.c
@@ -30,34 +30,20 @@
30 */ 30 */
31enum PP_State 31enum PP_State
32{ 32{
33
34 PP_Init = 0, 33 PP_Init = 0,
35
36 PP_HaveKey = 1, 34 PP_HaveKey = 1,
37
38 PP_ExpectNewLine = 2, 35 PP_ExpectNewLine = 2,
39
40 PP_ExpectNewLineR = 3, 36 PP_ExpectNewLineR = 3,
41
42 PP_ExpectNewLineN = 4, 37 PP_ExpectNewLineN = 4,
43 38 PP_ExpectNewLineNOPT = 5,
44 PP_Headers = 5, 39 PP_Headers = 6,
45 40 PP_SkipRN = 7,
46 PP_SkipRNRN = 6, 41 PP_SkipN = 8,
47 42 PP_ValueToBoundary = 9,
48 PP_SkipNRN = 7, 43 PP_FinalDash = 10,
49 44 PP_FinalRN = 11,
50 PP_SkipRN = 8, 45 PP_FinalN = 12,
51
52 PP_SkipN = 9,
53
54 PP_ValueToBoundary = 10,
55
56 PP_FinalDash = 11,
57
58 PP_Error = 9999, 46 PP_Error = 9999,
59
60
61}; 47};
62 48
63/** 49/**
@@ -177,7 +163,8 @@ MHD_create_post_processor (struct MHD_Connection *connection,
177 return NULL; 163 return NULL;
178 if ((0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED, 164 if ((0 != strcasecmp (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
179 encoding)) && 165 encoding)) &&
180 (0 != strcasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding))) 166 (0 != strncasecmp (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, encoding,
167 strlen(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA))))
181 return NULL; 168 return NULL;
182 ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1); 169 ret = malloc (sizeof (struct MHD_PostProcessor) + buffer_size + 1);
183 if (ret == NULL) 170 if (ret == NULL)
@@ -352,8 +339,6 @@ try_match_header (const char *prefix, char *line, char **suffix)
352 * apart and give them to the callback individually (will require some 339 * apart and give them to the callback individually (will require some
353 * additional states & state). 340 * additional states & state).
354 * 341 *
355 * TODO: this code has never been tested...
356 *
357 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4 342 * See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4
358 */ 343 */
359static int 344static int
@@ -386,16 +371,16 @@ post_process_multipart (struct MHD_PostProcessor *pp,
386 { 371 {
387 /* first, move data to our internal buffer */ 372 /* first, move data to our internal buffer */
388 max = pp->buffer_size - pp->buffer_pos; 373 max = pp->buffer_size - pp->buffer_pos;
389 if ((max < ioff) && (max < post_data_len)) 374 if ((max < ioff) && (max < post_data_len - poff))
390 { 375 {
391 memmove (buf, &buf[ioff], pp->buffer_pos - ioff); 376 memmove (buf, &buf[ioff], pp->buffer_pos - ioff);
392 pp->buffer_pos -= ioff; 377 pp->buffer_pos -= ioff;
393 ioff = 0; 378 ioff = 0;
394 max = pp->buffer_size - pp->buffer_pos; 379 max = pp->buffer_size - pp->buffer_pos;
395 } 380 }
396 if (max > post_data_len) 381 if (max > post_data_len - poff)
397 max = post_data_len; 382 max = post_data_len - poff;
398 memcpy (&buf[pp->buffer_pos], post_data, max); 383 memcpy (&buf[pp->buffer_pos], &post_data[poff], max);
399 poff += max; 384 poff += max;
400 pp->buffer_pos += max; 385 pp->buffer_pos += max;
401 386
@@ -426,7 +411,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
426 if (buf[ioff] == '\r') 411 if (buf[ioff] == '\r')
427 { 412 {
428 ioff++; 413 ioff++;
429 pp->state = PP_ExpectNewLineN; 414 pp->state = PP_ExpectNewLineNOPT;
430 break; 415 break;
431 } 416 }
432 /* fall through! */ 417 /* fall through! */
@@ -438,6 +423,14 @@ post_process_multipart (struct MHD_PostProcessor *pp,
438 break; 423 break;
439 } 424 }
440 return MHD_NO; 425 return MHD_NO;
426 case PP_ExpectNewLineNOPT:
427 if (buf[ioff] == '\n')
428 {
429 ioff++;
430 pp->state = PP_Headers;
431 break;
432 }
433 /* fall through! */
441 case PP_Headers: 434 case PP_Headers:
442 newline = 0; 435 newline = 0;
443 while ((newline + ioff < pp->buffer_pos) && 436 while ((newline + ioff < pp->buffer_pos) &&
@@ -456,7 +449,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
456 } 449 }
457 if (newline == 0) 450 if (newline == 0)
458 { 451 {
459 pp->state = PP_SkipRNRN; 452 pp->state = PP_SkipRN;
460 break; 453 break;
461 } 454 }
462 buf[ioff + newline] = '\0'; 455 buf[ioff + newline] = '\0';
@@ -483,23 +476,9 @@ post_process_multipart (struct MHD_PostProcessor *pp,
483 try_match_header ("Content-Type: ", &buf[ioff], &pp->content_type); 476 try_match_header ("Content-Type: ", &buf[ioff], &pp->content_type);
484 try_match_header ("Content-Transfer-Encoding: ", 477 try_match_header ("Content-Transfer-Encoding: ",
485 &buf[ioff], &pp->transfer_encoding); 478 &buf[ioff], &pp->transfer_encoding);
479 ioff += newline + 1;
480 pp->state = PP_ExpectNewLineNOPT;
486 break; 481 break;
487 case PP_SkipRNRN:
488 if (buf[ioff] == '\r')
489 {
490 ioff++;
491 pp->state = PP_SkipNRN;
492 break;
493 }
494 /* fall through! */
495 case PP_SkipNRN:
496 if (buf[ioff] == '\n')
497 {
498 ioff++;
499 pp->state = PP_SkipRN;
500 break;
501 }
502 return MHD_NO; /* parse error */
503 case PP_SkipRN: 482 case PP_SkipRN:
504 if (buf[ioff] == '\r') 483 if (buf[ioff] == '\r')
505 { 484 {
@@ -606,6 +585,22 @@ post_process_multipart (struct MHD_PostProcessor *pp,
606 { 585 {
607 /* last boundary ends with "--" */ 586 /* last boundary ends with "--" */
608 ioff++; 587 ioff++;
588 pp->state = PP_FinalRN;
589 break;
590 }
591 return MHD_NO; /* parse error */
592 case PP_FinalRN:
593 if (buf[ioff] == '\r')
594 {
595 ioff++;
596 pp->state = PP_FinalN;
597 break;
598 }
599 /* fall through! */
600 case PP_FinalN:
601 if (buf[ioff] == '\n')
602 {
603 ioff++;
609 pp->state = PP_Error; 604 pp->state = PP_Error;
610 break; 605 break;
611 } 606 }