120 struct MHD_PostProcessor
142 const char *encoding;
147 const char *boundary;
152 char *nested_boundary;
167 char *content_filename;
172 char *content_transfer_encoding;
197 uint64_t value_offset;
223 bool must_unescape_key;
278 struct MHD_PostProcessor *
284 struct MHD_PostProcessor *ret;
285 const char *encoding;
286 const char *boundary;
289 if ( (buffer_size < 256) ||
290 (
NULL == connection) ||
318 boundary = strstr (boundary,
"boundary=");
319 if (
NULL == boundary)
322 blen = strlen (boundary);
324 (blen * 2 + 2 > buffer_size) )
326 if ( (boundary[0] ==
'"') &&
327 (boundary[blen - 1] ==
'"') )
342 ret->connection = connection;
345 ret->encoding = encoding;
346 ret->buffer_size = buffer_size;
349 ret->boundary = boundary;
378 const char *value_start,
379 const char *value_end,
380 const char *last_escape)
391 if (
NULL != last_escape)
393 if (((
size_t) (value_end - last_escape)) <
sizeof (pp->xbuf))
395 pp->xbuf_pos = value_end - last_escape;
398 value_end - last_escape);
399 value_end = last_escape;
402 while ( (value_start != value_end) ||
406 size_t delta = value_end - value_start;
419 if ((xoff + delta > 0) &&
420 (
'%' == xbuf[xoff + delta - 1]))
422 else if ((xoff + delta > 1) &&
423 (
'%' == xbuf[xoff + delta - 2]))
427 value_start += delta;
434 pp->must_ikvi =
false;
435 if (
MHD_NO == pp->ikvi (pp->cls,
437 (
const char *) &pp[1],
448 pp->value_offset += xoff;
464 const char *post_data,
465 size_t post_data_len)
467 char *kbuf = (
char *) &pp[1];
469 const char *start_key =
NULL;
470 const char *end_key =
NULL;
471 const char *start_value =
NULL;
472 const char *end_value =
NULL;
473 const char *last_escape =
NULL;
476 while ( ( (poff < post_data_len) ||
488 if (
NULL == start_key)
489 start_key = &post_data[poff];
490 pp->must_ikvi =
true;
491 switch (post_data[poff])
495 end_key = &post_data[poff];
501 end_key = &post_data[poff];
510 end_key = &post_data[poff];
521 if (
NULL == start_value)
522 start_value = &post_data[poff];
523 switch (post_data[poff])
531 end_value = &post_data[poff];
534 (start_value != end_value) )
541 pp->value_offset = 0;
549 end_value = &post_data[poff];
557 last_escape = &post_data[poff];
581 switch (post_data[poff])
592 if ( (pp->buffer_pos + (end_key - start_key) >=
594 (pp->buffer_pos + (end_key - start_key) <
602 if (
NULL != start_key)
604 memcpy (&kbuf[pp->buffer_pos],
606 end_key - start_key);
607 pp->buffer_pos += end_key - start_key;
610 pp->must_unescape_key =
true;
612 if (pp->must_unescape_key)
614 kbuf[pp->buffer_pos] =
'\0';
617 pp->must_unescape_key =
false;
623 pp->value_offset = 0;
638 if (
NULL != start_key)
641 end_key = &post_data[poff];
642 if (pp->buffer_pos + (end_key - start_key) >= pp->buffer_size)
647 memcpy (&kbuf[pp->buffer_pos],
649 end_key - start_key);
650 pp->buffer_pos += end_key - start_key;
651 pp->must_unescape_key =
true;
655 if ( (
NULL != start_value) &&
659 if (pp->must_unescape_key)
661 kbuf[pp->buffer_pos] =
'\0';
664 pp->must_unescape_key =
false;
666 if (
NULL == end_value)
667 end_value = &post_data[poff];
672 pp->must_ikvi =
false;
707 *suffix = strdup (&line[prefix_len]);
731 const char *boundary,
737 char *buf = (
char *) &pp[1];
740 if (pp->buffer_pos < 2 + blen)
742 if (pp->buffer_pos == pp->buffer_size)
747 if ( (0 != memcmp (
"--",
750 (0 != memcmp (&buf[2],
766 (*ioffptr) += pp->buffer_pos;
767 else if (dash == buf)
770 (*ioffptr) += dash - buf;
775 (*ioffptr) += 2 + blen;
778 pp->state = next_state;
779 pp->dash_state = next_dash_state;
801 if (
NULL != *destination)
805 while (
NULL != (spos = strstr (bpos, key)))
807 if ( (spos[klen] !=
'=') ||
809 (spos[-1] !=
' ') ) )
815 if (spos[klen + 1] !=
'"')
817 if (
NULL == (endv = strchr (&spos[klen + 2],
820 vlen = endv - spos - klen - 1;
821 *destination = malloc (vlen);
822 if (
NULL == *destination)
824 (*destination)[vlen - 1] =
'\0';
825 memcpy (*destination,
853 char *buf = (
char *) &pp[1];
857 while ( (newline < pp->buffer_pos) &&
858 (buf[newline] !=
'\r') &&
859 (buf[newline] !=
'\n') )
861 if (newline == pp->buffer_size)
866 if (newline == pp->buffer_pos)
872 pp->state = next_state;
876 if (buf[newline] ==
'\r')
888 &pp->content_filename);
899 &pp->content_transfer_encoding);
901 (*ioffptr) += newline + 1;
925 const char *boundary,
930 char *buf = (
char *) &pp[1];
939 while (newline + 4 < pp->buffer_pos)
941 r = memchr (&buf[newline],
943 pp->buffer_pos - newline - 4);
946 newline = pp->buffer_pos - 4;
950 if (0 == memcmp (
"\r\n--",
956 if (newline + blen + 4 <= pp->buffer_pos)
959 if (0 != memcmp (&buf[newline + 4],
972 pp->state = next_state;
973 pp->dash_state = next_dash_state;
974 (*ioffptr) += blen + 4;
984 if ( (0 == newline) &&
985 (pp->buffer_pos == pp->buffer_size) )
996 if ( ( (pp->must_ikvi) ||
998 (
MHD_NO == pp->ikvi (pp->cls,
1001 pp->content_filename,
1003 pp->content_transfer_encoding,
1011 pp->must_ikvi =
false;
1012 pp->value_offset += newline;
1013 (*ioffptr) += newline;
1025 if ( (
NULL != pp->content_name) &&
1028 free (pp->content_name);
1029 pp->content_name =
NULL;
1031 if ( (
NULL != pp->content_type) &&
1034 free (pp->content_type);
1035 pp->content_type =
NULL;
1037 if ( (
NULL != pp->content_filename) &&
1040 free (pp->content_filename);
1041 pp->content_filename =
NULL;
1043 if ( (
NULL != pp->content_transfer_encoding) &&
1046 free (pp->content_transfer_encoding);
1047 pp->content_transfer_encoding =
NULL;
1062 const char *post_data,
1063 size_t post_data_len)
1071 buf = (
char *) &pp[1];
1075 while ( (poff < post_data_len) ||
1076 ( (pp->buffer_pos > 0) &&
1077 (0 != state_changed) ) )
1081 max = pp->buffer_size - pp->buffer_pos;
1082 if (max > post_data_len - poff)
1083 max = post_data_len - poff;
1084 memcpy (&buf[pp->buffer_pos],
1088 pp->buffer_pos += max;
1090 (0 == state_changed) &&
1091 (poff < post_data_len) )
1099 switch (pp->skip_rn)
1123 if ( (pp->buffer_pos > 1) &&
1150 pp->state = pp->dash_state;
1198 pp->must_ikvi =
true;
1212 if ( (
NULL != pp->content_type) &&
1217 pp->nested_boundary = strstr (pp->content_type,
1219 if (
NULL == pp->nested_boundary)
1224 pp->nested_boundary =
1226 if (
NULL == pp->nested_boundary)
1234 free (pp->content_type);
1235 pp->content_type =
NULL;
1236 pp->nlen = strlen (pp->nested_boundary);
1242 pp->value_offset = 0;
1262 if (
NULL != pp->nested_boundary)
1264 free (pp->nested_boundary);
1265 pp->nested_boundary =
NULL;
1271 if (
NULL == pp->nested_boundary)
1277 pp->nested_boundary,
1292 if (
NULL != pp->content_name)
1294 if (
NULL != pp->content_type)
1296 if (
NULL != pp->content_filename)
1298 if (
NULL != pp->content_transfer_encoding)
1304 pp->value_offset = 0;
1320 pp->nested_boundary,
1346 pp->buffer_pos - ioff);
1347 pp->buffer_pos -= ioff;
1357 pp->buffer_pos - ioff);
1358 pp->buffer_pos -= ioff;
1360 if (poff < post_data_len)
1384 const char *post_data,
1385 size_t post_data_len)
1387 if (0 == post_data_len)
1439 if ( (pp->xbuf_pos > 0) ||
1447 if (
NULL != pp->nested_boundary)
1448 free (pp->nested_boundary);