119 struct MHD_PostProcessor
142 const char *encoding;
147 const char *boundary;
152 char *nested_boundary;
167 char *content_filename;
172 char *content_transfer_encoding;
198 uint64_t value_offset;
273 struct MHD_PostProcessor *
279 struct MHD_PostProcessor *ret;
280 const char *encoding;
281 const char *boundary;
284 if ( (buffer_size < 256) ||
285 (
NULL == connection) ||
313 boundary = strstr (boundary,
"boundary=");
314 if (
NULL == boundary)
317 blen = strlen (boundary);
319 (blen * 2 + 2 > buffer_size) )
321 if ( (boundary[0] ==
'"') &&
322 (boundary[blen - 1] ==
'"') )
337 ret->connection = connection;
340 ret->encoding = encoding;
341 ret->buffer_size = buffer_size;
344 ret->boundary = boundary;
360 const char *post_data,
361 size_t post_data_len)
368 int end_of_value_found;
372 buf = (
char *) &pp[1];
374 while (poff < post_data_len)
386 while ((equals + poff < post_data_len) &&
387 (post_data[equals + poff] !=
'='))
389 if (equals + pp->buffer_pos > pp->buffer_size)
394 memcpy (&buf[pp->buffer_pos], &post_data[poff], equals);
395 pp->buffer_pos += equals;
396 if (equals + poff == post_data_len)
398 buf[pp->buffer_pos] =
'\0';
404 pp->value_offset = 0;
408 memcpy (xbuf, pp->xbuf, pp->xbuf_pos);
414 while ((amper + poff < post_data_len) &&
416 (post_data[amper + poff] !=
'&') &&
417 (post_data[amper + poff] !=
'\n') &&
418 (post_data[amper + poff] !=
'\r'))
420 end_of_value_found = ((amper + poff < post_data_len) &&
421 ((post_data[amper + poff] ==
'&') ||
422 (post_data[amper + poff] ==
'\n') ||
423 (post_data[amper + poff] ==
'\r')));
431 memcpy (&xbuf[xoff], &post_data[poff], delta);
440 (
'%' == xbuf[delta - 1]))
442 else if ((delta > 1) &&
443 (
'%' == xbuf[delta - 2]))
453 pp->xbuf_pos = xoff - delta;
461 (poff == post_data_len))
470 if (
MHD_NO == pp->ikvi (pp->cls,
472 (
const char *) &pp[1],
483 pp->value_offset += xoff;
486 if (end_of_value_found)
489 if ( (
'\n' == post_data[poff]) ||
490 (
'\r' == post_data[poff]) )
494 else if (
'&' == post_data[poff])
502 if ( (
'\n' == post_data[poff]) ||
503 (
'\r' == post_data[poff]) )
546 *suffix = strdup (&line[prefix_len]);
570 const char *boundary,
576 char *buf = (
char *) &pp[1];
579 if (pp->buffer_pos < 2 + blen)
581 if (pp->buffer_pos == pp->buffer_size)
586 if ( (0 != memcmp (
"--",
589 (0 != memcmp (&buf[2],
605 (*ioffptr) += pp->buffer_pos;
606 else if (dash == buf)
609 (*ioffptr) += dash - buf;
614 (*ioffptr) += 2 + blen;
617 pp->state = next_state;
618 pp->dash_state = next_dash_state;
640 if (
NULL != *destination)
644 while (
NULL != (spos = strstr (bpos, key)))
646 if ( (spos[klen] !=
'=') ||
648 (spos[-1] !=
' ') ) )
654 if (spos[klen + 1] !=
'"')
656 if (
NULL == (endv = strchr (&spos[klen + 2],
659 vlen = endv - spos - klen - 1;
660 *destination = malloc (vlen);
661 if (
NULL == *destination)
663 (*destination)[vlen - 1] =
'\0';
664 memcpy (*destination,
692 char *buf = (
char *) &pp[1];
696 while ( (newline < pp->buffer_pos) &&
697 (buf[newline] !=
'\r') &&
698 (buf[newline] !=
'\n') )
700 if (newline == pp->buffer_size)
705 if (newline == pp->buffer_pos)
711 pp->state = next_state;
715 if (buf[newline] ==
'\r')
727 &pp->content_filename);
738 &pp->content_transfer_encoding);
740 (*ioffptr) += newline + 1;
764 const char *boundary,
769 char *buf = (
char *) &pp[1];
778 while (newline + 4 < pp->buffer_pos)
780 r = memchr (&buf[newline],
782 pp->buffer_pos - newline - 4);
785 newline = pp->buffer_pos - 4;
789 if (0 == memcmp (
"\r\n--",
795 if (newline + blen + 4 <= pp->buffer_pos)
798 if (0 != memcmp (&buf[newline + 4],
811 pp->state = next_state;
812 pp->dash_state = next_dash_state;
813 (*ioffptr) += blen + 4;
823 if ( (0 == newline) &&
824 (pp->buffer_pos == pp->buffer_size) )
835 if ( ( (
MHD_YES == pp->must_ikvi) ||
837 (
MHD_NO == pp->ikvi (pp->cls,
840 pp->content_filename,
842 pp->content_transfer_encoding,
851 pp->value_offset += newline;
852 (*ioffptr) += newline;
864 if ( (
NULL != pp->content_name) &&
867 free (pp->content_name);
868 pp->content_name =
NULL;
870 if ( (
NULL != pp->content_type) &&
873 free (pp->content_type);
874 pp->content_type =
NULL;
876 if ( (
NULL != pp->content_filename) &&
879 free (pp->content_filename);
880 pp->content_filename =
NULL;
882 if ( (
NULL != pp->content_transfer_encoding) &&
885 free (pp->content_transfer_encoding);
886 pp->content_transfer_encoding =
NULL;
901 const char *post_data,
902 size_t post_data_len)
910 buf = (
char *) &pp[1];
914 while ( (poff < post_data_len) ||
915 ( (pp->buffer_pos > 0) &&
916 (0 != state_changed) ) )
920 max = pp->buffer_size - pp->buffer_pos;
921 if (max > post_data_len - poff)
922 max = post_data_len - poff;
923 memcpy (&buf[pp->buffer_pos],
927 pp->buffer_pos += max;
929 (0 == state_changed) &&
930 (poff < post_data_len) )
962 if ( (pp->buffer_pos > 1) &&
989 pp->state = pp->dash_state;
1051 if ( (
NULL != pp->content_type) &&
1056 pp->nested_boundary = strstr (pp->content_type,
1058 if (
NULL == pp->nested_boundary)
1063 pp->nested_boundary =
1065 if (
NULL == pp->nested_boundary)
1073 free (pp->content_type);
1074 pp->content_type =
NULL;
1075 pp->nlen = strlen (pp->nested_boundary);
1081 pp->value_offset = 0;
1101 if (
NULL != pp->nested_boundary)
1103 free (pp->nested_boundary);
1104 pp->nested_boundary =
NULL;
1110 if (
NULL == pp->nested_boundary)
1116 pp->nested_boundary,
1131 if (
NULL != pp->content_name)
1133 if (
NULL != pp->content_type)
1135 if (
NULL != pp->content_filename)
1137 if (
NULL != pp->content_transfer_encoding)
1143 pp->value_offset = 0;
1159 pp->nested_boundary,
1185 pp->buffer_pos - ioff);
1186 pp->buffer_pos -= ioff;
1196 pp->buffer_pos - ioff);
1197 pp->buffer_pos -= ioff;
1199 if (poff < post_data_len)
1223 const char *post_data,
1224 size_t post_data_len)
1226 if (0 == post_data_len)
1278 if ( (pp->xbuf_pos > 0) ||
1286 if (
NULL != pp->nested_boundary)
1287 free (pp->nested_boundary);