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) ||
310 boundary = strstr (boundary,
"boundary=");
311 if (
NULL == boundary)
314 blen = strlen (boundary);
316 (blen * 2 + 2 > buffer_size) )
318 if ( (boundary[0] ==
'"') &&
319 (boundary[blen - 1] ==
'"') )
331 if (
NULL == (ret =
MHD_calloc_ (1,
sizeof (
struct MHD_PostProcessor) + buffer_size + 1)))
333 ret->connection = connection;
336 ret->encoding = encoding;
337 ret->buffer_size = buffer_size;
340 ret->boundary = boundary;
356 const char *post_data,
357 size_t post_data_len)
364 int end_of_value_found;
368 buf = (
char *) &pp[1];
370 while (poff < post_data_len)
382 while ((equals + poff < post_data_len) &&
383 (post_data[equals + poff] !=
'='))
385 if (equals + pp->buffer_pos > pp->buffer_size)
390 memcpy (&buf[pp->buffer_pos], &post_data[poff], equals);
391 pp->buffer_pos += equals;
392 if (equals + poff == post_data_len)
394 buf[pp->buffer_pos] =
'\0';
400 pp->value_offset = 0;
404 memcpy (xbuf, pp->xbuf, pp->xbuf_pos);
410 while ((amper + poff < post_data_len) &&
412 (post_data[amper + poff] !=
'&') &&
413 (post_data[amper + poff] !=
'\n') &&
414 (post_data[amper + poff] !=
'\r'))
416 end_of_value_found = ((amper + poff < post_data_len) &&
417 ((post_data[amper + poff] ==
'&') ||
418 (post_data[amper + poff] ==
'\n') ||
419 (post_data[amper + poff] ==
'\r')));
427 memcpy (&xbuf[xoff], &post_data[poff], delta);
436 (
'%' == xbuf[delta - 1]))
438 else if ((delta > 1) &&
439 (
'%' == xbuf[delta - 2]))
449 pp->xbuf_pos = xoff - delta;
457 (poff == post_data_len))
466 if (
MHD_NO == pp->ikvi (pp->cls,
468 (
const char *) &pp[1],
479 pp->value_offset += xoff;
482 if (end_of_value_found)
485 if ( (
'\n' == post_data[poff]) ||
486 (
'\r' == post_data[poff]) )
490 else if (
'&' == post_data[poff])
498 if ( (
'\n' == post_data[poff]) ||
499 (
'\r' == post_data[poff]) )
542 *suffix = strdup (&line[prefix_len]);
566 const char *boundary,
572 char *buf = (
char *) &pp[1];
575 if (pp->buffer_pos < 2 + blen)
577 if (pp->buffer_pos == pp->buffer_size)
582 if ( (0 != memcmp (
"--",
585 (0 != memcmp (&buf[2],
601 (*ioffptr) += pp->buffer_pos;
606 (*ioffptr) += dash - buf;
611 (*ioffptr) += 2 + blen;
614 pp->state = next_state;
615 pp->dash_state = next_dash_state;
637 if (
NULL != *destination)
641 while (
NULL != (spos = strstr (bpos, key)))
643 if ( (spos[klen] !=
'=') ||
645 (spos[-1] !=
' ') ) )
651 if (spos[klen + 1] !=
'"')
653 if (
NULL == (endv = strchr (&spos[klen + 2],
656 vlen = endv - spos - klen - 1;
657 *destination = malloc (vlen);
658 if (
NULL == *destination)
660 (*destination)[vlen - 1] =
'\0';
661 memcpy (*destination,
689 char *buf = (
char *) &pp[1];
693 while ( (newline < pp->buffer_pos) &&
694 (buf[newline] !=
'\r') &&
695 (buf[newline] !=
'\n') )
697 if (newline == pp->buffer_size)
702 if (newline == pp->buffer_pos)
708 pp->state = next_state;
712 if (buf[newline] ==
'\r')
724 &pp->content_filename);
735 &pp->content_transfer_encoding);
737 (*ioffptr) += newline + 1;
761 const char *boundary,
766 char *buf = (
char *) &pp[1];
775 while (newline + 4 < pp->buffer_pos)
777 r = memchr (&buf[newline],
779 pp->buffer_pos - newline - 4);
782 newline = pp->buffer_pos - 4;
786 if (0 == memcmp (
"\r\n--",
792 if (newline + blen + 4 <= pp->buffer_pos)
795 if (0 != memcmp (&buf[newline + 4],
808 pp->state = next_state;
809 pp->dash_state = next_dash_state;
810 (*ioffptr) += blen + 4;
820 if ( (0 == newline) &&
821 (pp->buffer_pos == pp->buffer_size) )
832 if ( ( (
MHD_YES == pp->must_ikvi) ||
834 (
MHD_NO == pp->ikvi (pp->cls,
837 pp->content_filename,
839 pp->content_transfer_encoding,
848 pp->value_offset += newline;
849 (*ioffptr) += newline;
861 if ( (
NULL != pp->content_name) &&
864 free (pp->content_name);
865 pp->content_name =
NULL;
867 if ( (
NULL != pp->content_type) &&
870 free (pp->content_type);
871 pp->content_type =
NULL;
873 if ( (
NULL != pp->content_filename) &&
876 free (pp->content_filename);
877 pp->content_filename =
NULL;
879 if ( (
NULL != pp->content_transfer_encoding) &&
882 free (pp->content_transfer_encoding);
883 pp->content_transfer_encoding =
NULL;
898 const char *post_data,
899 size_t post_data_len)
907 buf = (
char *) &pp[1];
911 while ( (poff < post_data_len) ||
912 ( (pp->buffer_pos > 0) &&
913 (0 != state_changed) ) )
917 max = pp->buffer_size - pp->buffer_pos;
918 if (max > post_data_len - poff)
919 max = post_data_len - poff;
920 memcpy (&buf[pp->buffer_pos],
924 pp->buffer_pos += max;
926 (0 == state_changed) &&
927 (poff < post_data_len) )
959 if ( (pp->buffer_pos > 1) &&
986 pp->state = pp->dash_state;
1049 if ( (
NULL != pp->content_type) &&
1054 pp->nested_boundary = strstr (pp->content_type,
1056 if (
NULL == pp->nested_boundary)
1061 pp->nested_boundary =
1063 if (
NULL == pp->nested_boundary)
1071 free (pp->content_type);
1072 pp->content_type =
NULL;
1073 pp->nlen = strlen (pp->nested_boundary);
1079 pp->value_offset = 0;
1099 if (
NULL != pp->nested_boundary)
1101 free (pp->nested_boundary);
1102 pp->nested_boundary =
NULL;
1108 if (
NULL == pp->nested_boundary)
1114 pp->nested_boundary,
1129 if (
NULL != pp->content_name)
1131 if (
NULL != pp->content_type)
1133 if (
NULL != pp->content_filename)
1135 if (
NULL != pp->content_transfer_encoding)
1141 pp->value_offset = 0;
1157 pp->nested_boundary,
1183 pp->buffer_pos - ioff);
1184 pp->buffer_pos -= ioff;
1194 pp->buffer_pos - ioff);
1195 pp->buffer_pos -= ioff;
1197 if (poff < post_data_len)
1221 const char *post_data,
1222 size_t post_data_len)
1224 if (0 == post_data_len)
1274 if ( (pp->xbuf_pos > 0) ||
1282 if (
NULL != pp->nested_boundary)
1283 free (pp->nested_boundary);
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
Header for platform missing functions.
enum MHD_CONNECTION_STATE state
MHD_PanicCallback mhd_panic
void * MHD_calloc_(size_t nelem, size_t elsize)
int(* MHD_PostDataIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
static int find_boundary(struct MHD_PostProcessor *pp, const char *boundary, size_t blen, size_t *ioffptr, enum PP_State next_state, enum PP_State next_dash_state)
_MHD_EXTERN int MHD_destroy_post_processor(struct MHD_PostProcessor *pp)
static int process_multipart_headers(struct MHD_PostProcessor *pp, size_t *ioffptr, enum PP_State next_state)
_MHD_EXTERN struct MHD_PostProcessor * MHD_create_post_processor(struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iter, void *iter_cls)
static int try_match_header(const char *prefix, size_t prefix_len, char *line, char **suffix)
internal shared structures
Header for string manipulating helpers.
_MHD_EXTERN int MHD_post_process(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
#define MHD_STATICSTR_LEN_(macro)
static int post_process_urlencoded(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
static int post_process_multipart(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED
static void free_unmarked(struct MHD_PostProcessor *pp)
#define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA
static int process_value_to_boundary(struct MHD_PostProcessor *pp, size_t *ioffptr, const char *boundary, size_t blen, enum PP_State next_state, enum PP_State next_dash_state)
_MHD_EXTERN int MHD_lookup_connection_value_n(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, size_t key_size, const char **value_ptr, size_t *value_size_ptr)
void MHD_unescape_plus(char *arg)
_MHD_EXTERN size_t MHD_http_unescape(char *val)
static void try_get_value(const char *buf, const char *key, char **destination)