aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/postprocessor.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-27 14:22:22 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-27 14:22:22 +0000
commit57b91a0399469dfccfa9c629d1f7173f87550858 (patch)
tree41ab69171ee2377fd82caa16a77bc7ae4ee9824d /src/microhttpd/postprocessor.c
parent00b30d5d457f0b7877f5a577d7141ea1a9afa0ba (diff)
downloadlibmicrohttpd-57b91a0399469dfccfa9c629d1f7173f87550858.tar.gz
libmicrohttpd-57b91a0399469dfccfa9c629d1f7173f87550858.zip
-improve POST processing performance
Diffstat (limited to 'src/microhttpd/postprocessor.c')
-rw-r--r--src/microhttpd/postprocessor.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 08b31a08..0fdf607f 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -308,7 +308,7 @@ MHD_create_post_processor (struct MHD_Connection *connection,
308 /* remove enclosing quotes */ 308 /* remove enclosing quotes */
309 ++boundary; 309 ++boundary;
310 blen -= 2; 310 blen -= 2;
311 } 311 }
312 } 312 }
313 else 313 else
314 blen = 0; 314 blen = 0;
@@ -564,8 +564,8 @@ find_boundary (struct MHD_PostProcessor *pp,
564 * If destination is already non-NULL, do nothing. 564 * If destination is already non-NULL, do nothing.
565 */ 565 */
566static void 566static void
567try_get_value (const char *buf, 567try_get_value (const char *buf,
568 const char *key, 568 const char *key,
569 char **destination) 569 char **destination)
570{ 570{
571 const char *spos; 571 const char *spos;
@@ -676,8 +676,8 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
676 * boundary was found 676 * boundary was found
677 * @param next_dash_state state to go into if the next 677 * @param next_dash_state state to go into if the next
678 * boundary ends with "--" 678 * boundary ends with "--"
679 * @return MHD_YES if we can continue processing, 679 * @return #MHD_YES if we can continue processing,
680 * MHD_NO on error or if we do not have 680 * #MHD_NO on error or if we do not have
681 * enough data yet 681 * enough data yet
682 */ 682 */
683static int 683static int
@@ -690,15 +690,26 @@ process_value_to_boundary (struct MHD_PostProcessor *pp,
690{ 690{
691 char *buf = (char *) &pp[1]; 691 char *buf = (char *) &pp[1];
692 size_t newline; 692 size_t newline;
693 const char *r;
693 694
694 /* all data in buf until the boundary 695 /* all data in buf until the boundary
695 (\r\n--+boundary) is part of the value */ 696 (\r\n--+boundary) is part of the value */
696 newline = 0; 697 newline = 0;
697 while (1) 698 while (1)
698 { 699 {
699 while ((newline + 4 < pp->buffer_pos) && 700 while (newline + 4 < pp->buffer_pos)
700 (0 != memcmp ("\r\n--", &buf[newline], 4))) 701 {
701 newline++; 702 r = memchr (&buf[newline], '\r', pp->buffer_pos - newline);
703 if (NULL == r)
704 {
705 newline = pp->buffer_pos - 4;
706 break;
707 }
708 newline = r - buf;
709 if (0 == memcmp ("\r\n--", &buf[newline], 4))
710 break;
711 newline++;
712 }
702 if (newline + pp->blen + 4 <= pp->buffer_pos) 713 if (newline + pp->blen + 4 <= pp->buffer_pos)
703 { 714 {
704 /* can check boundary */ 715 /* can check boundary */
@@ -794,7 +805,7 @@ free_unmarked (struct MHD_PostProcessor *pp)
794 * @param pp post processor context 805 * @param pp post processor context
795 * @param post_data data to decode 806 * @param post_data data to decode
796 * @param post_data_len number of bytes in @a post_data 807 * @param post_data_len number of bytes in @a post_data
797 * @return #MHD_NO on error, 808 * @return #MHD_NO on error,
798 */ 809 */
799static int 810static int
800post_process_multipart (struct MHD_PostProcessor *pp, 811post_process_multipart (struct MHD_PostProcessor *pp,
@@ -1147,7 +1158,7 @@ MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
1147 /* These internal strings need cleaning up since 1158 /* These internal strings need cleaning up since
1148 the post-processing may have been interrupted 1159 the post-processing may have been interrupted
1149 at any stage */ 1160 at any stage */
1150 if ((pp->xbuf_pos > 0) || 1161 if ((pp->xbuf_pos > 0) ||
1151 ( (pp->state != PP_Done) && 1162 ( (pp->state != PP_Done) &&
1152 (pp->state != PP_ExpectNewLine))) 1163 (pp->state != PP_ExpectNewLine)))
1153 ret = MHD_NO; 1164 ret = MHD_NO;