114 struct MHD_PostProcessor
137 const char *encoding;
142 const char *boundary;
147 char *nested_boundary;
162 char *content_filename;
167 char *content_transfer_encoding;
193 uint64_t value_offset;
251 struct MHD_PostProcessor *
256 struct MHD_PostProcessor *ret;
257 const char *encoding;
258 const char *boundary;
261 if ((buffer_size < 256) || (connection ==
NULL) || (ikvi ==
NULL))
266 if (encoding ==
NULL)
279 boundary = strstr (boundary,
"boundary=");
280 if (
NULL == boundary)
282 boundary += strlen (
"boundary=");
283 blen = strlen (boundary);
284 if ((blen == 0) || (blen * 2 + 2 > buffer_size))
286 if ( (boundary[0] ==
'"') && (boundary[blen - 1] ==
'"') )
295 ret = malloc (
sizeof (
struct MHD_PostProcessor) + buffer_size + 1);
298 memset (ret, 0,
sizeof (
struct MHD_PostProcessor) + buffer_size + 1);
299 ret->connection = connection;
302 ret->encoding = encoding;
303 ret->buffer_size = buffer_size;
306 ret->boundary = boundary;
316 const char *post_data,
317 size_t post_data_len)
324 int end_of_value_found;
328 buf = (
char *) &pp[1];
330 while (poff < post_data_len)
342 while ((equals + poff < post_data_len) &&
343 (post_data[equals + poff] !=
'='))
345 if (equals + pp->buffer_pos > pp->buffer_size)
350 memcpy (&buf[pp->buffer_pos], &post_data[poff], equals);
351 pp->buffer_pos += equals;
352 if (equals + poff == post_data_len)
354 buf[pp->buffer_pos] =
'\0';
359 pp->value_offset = 0;
363 memcpy (xbuf, pp->xbuf, pp->xbuf_pos);
369 while ((amper + poff < post_data_len) &&
371 (post_data[amper + poff] !=
'&') &&
372 (post_data[amper + poff] !=
'\n') &&
373 (post_data[amper + poff] !=
'\r'))
375 end_of_value_found = ((amper + poff < post_data_len) &&
376 ((post_data[amper + poff] ==
'&') ||
377 (post_data[amper + poff] ==
'\n') ||
378 (post_data[amper + poff] ==
'\r')));
386 memcpy (&xbuf[xoff], &post_data[poff], delta);
394 if ((delta > 0) && (xbuf[delta - 1] ==
'%'))
396 else if ((delta > 1) && (xbuf[delta - 2] ==
'%'))
403 memcpy (pp->xbuf, &xbuf[delta], xoff - delta);
404 pp->xbuf_pos = xoff - delta;
411 if ((xoff == 0) && (poff == post_data_len))
425 pp->value_offset += xoff;
428 if (end_of_value_found)
431 if ((post_data[poff] ==
'\n') || (post_data[poff] ==
'\r'))
443 if ((post_data[poff] ==
'\n') || (post_data[poff] ==
'\r'))
471 if (0 == strncasecmp (prefix, line, strlen (prefix)))
473 *suffix = strdup (&line[strlen (prefix)]);
483 const char *boundary,
488 char *buf = (
char *) &pp[1];
490 if (pp->buffer_pos < 2 + blen)
492 if (pp->buffer_pos == pp->buffer_size)
496 if ((0 != memcmp (
"--", buf, 2)) || (0 != memcmp (&buf[2], boundary, blen)))
503 (*ioffptr) += 2 + blen;
506 pp->state = next_state;
507 pp->dash_state = next_dash_state;
528 if (
NULL != *destination)
532 while (
NULL != (spos = strstr (bpos, key)))
534 if ((spos[klen] !=
'=') || ((spos != buf) && (spos[-1] !=
' ')))
540 if (spos[klen + 1] !=
'"')
542 if (
NULL == (endv = strchr (&spos[klen + 2],
'\"')))
544 vlen = endv - spos - klen - 1;
545 *destination = malloc (vlen);
546 if (
NULL == *destination)
548 (*destination)[vlen - 1] =
'\0';
549 memcpy (*destination, &spos[klen + 2], vlen - 1);
568 size_t *ioffptr,
enum PP_State next_state)
570 char *buf = (
char *) &pp[1];
574 while ((newline < pp->buffer_pos) &&
575 (buf[newline] !=
'\r') && (buf[newline] !=
'\n'))
577 if (newline == pp->buffer_size)
582 if (newline == pp->buffer_pos)
588 pp->state = next_state;
592 if (buf[newline] ==
'\r')
595 if (0 == strncasecmp (
"Content-disposition: ",
596 buf, strlen (
"Content-disposition: ")))
599 "name", &pp->content_name);
601 "filename", &pp->content_filename);
607 buf, &pp->content_transfer_encoding);
609 (*ioffptr) += newline + 1;
630 const char *boundary,
635 char *buf = (
char *) &pp[1];
643 while ((newline + 4 < pp->buffer_pos) &&
644 (0 != memcmp (
"\r\n--", &buf[newline], 4)))
646 if (newline + pp->blen + 4 <= pp->buffer_pos)
649 if (0 != memcmp (&buf[newline + 4], boundary, pp->blen))
660 pp->state = next_state;
661 pp->dash_state = next_dash_state;
662 (*ioffptr) += pp->blen + 4;
672 if ((newline == 0) && (pp->buffer_pos == pp->buffer_size))
683 if (
MHD_NO == pp->ikvi (pp->cls,
686 pp->content_filename,
688 pp->content_transfer_encoding,
689 buf, pp->value_offset, newline))
694 pp->value_offset += newline;
695 (*ioffptr) += newline;
704 free (pp->content_name);
705 pp->content_name =
NULL;
709 free (pp->content_type);
710 pp->content_type =
NULL;
712 if ((pp->content_filename !=
NULL) &&
715 free (pp->content_filename);
716 pp->content_filename =
NULL;
718 if ((pp->content_transfer_encoding !=
NULL) &&
721 free (pp->content_transfer_encoding);
722 pp->content_transfer_encoding =
NULL;
731 const char *post_data,
732 size_t post_data_len)
740 buf = (
char *) &pp[1];
744 while ((poff < post_data_len) ||
745 ((pp->buffer_pos > 0) && (state_changed != 0)))
749 max = pp->buffer_size - pp->buffer_pos;
750 if (max > post_data_len - poff)
751 max = post_data_len - poff;
752 memcpy (&buf[pp->buffer_pos], &post_data[poff], max);
754 pp->buffer_pos += max;
755 if ((max == 0) && (state_changed == 0) && (poff < post_data_len))
787 if ((pp->buffer_pos > 1) && (buf[1] ==
'\n'))
813 pp->state = pp->dash_state;
872 if ((pp->content_type !=
NULL) &&
873 (0 == strncasecmp (pp->content_type,
875 strlen (
"multipart/mixed"))))
877 pp->nested_boundary = strstr (pp->content_type,
"boundary=");
878 if (pp->nested_boundary ==
NULL)
883 pp->nested_boundary =
884 strdup (&pp->nested_boundary[strlen (
"boundary=")]);
885 if (pp->nested_boundary ==
NULL)
893 free (pp->content_type);
894 pp->content_type =
NULL;
895 pp->nlen = strlen (pp->nested_boundary);
901 pp->value_offset = 0;
921 if (pp->nested_boundary !=
NULL)
923 free (pp->nested_boundary);
924 pp->nested_boundary =
NULL;
930 if (pp->nested_boundary ==
NULL)
951 if (pp->content_name !=
NULL)
953 if (pp->content_type !=
NULL)
955 if (pp->content_filename !=
NULL)
957 if (pp->content_transfer_encoding !=
NULL)
963 pp->value_offset = 0;
999 memmove (buf, &buf[ioff], pp->buffer_pos - ioff);
1000 pp->buffer_pos -= ioff;
1008 memmove (buf, &buf[ioff], pp->buffer_pos - ioff);
1009 pp->buffer_pos -= ioff;
1011 if (poff < post_data_len)
1035 const char *post_data,
size_t post_data_len)
1037 if (post_data_len == 0)
1065 if ((pp->xbuf_pos > 0) || (pp->state !=
PP_Done))
1071 if (pp->nested_boundary !=
NULL)
1072 free (pp->nested_boundary);