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) ||
294 if (
NULL == encoding)
308 boundary = strstr (boundary,
"boundary=");
309 if (
NULL == boundary)
312 blen = strlen (boundary);
314 (blen * 2 + 2 > buffer_size) )
316 if ( (boundary[0] ==
'"') &&
317 (boundary[blen - 1] ==
'"') )
329 if (
NULL == (ret =
MHD_calloc_ (1,
sizeof (
struct MHD_PostProcessor) + buffer_size + 1)))
331 ret->connection = connection;
334 ret->encoding = encoding;
335 ret->buffer_size = buffer_size;
338 ret->boundary = boundary;
354 const char *post_data,
355 size_t post_data_len)
362 int end_of_value_found;
366 buf = (
char *) &pp[1];
368 while (poff < post_data_len)
380 while ((equals + poff < post_data_len) &&
381 (post_data[equals + poff] !=
'='))
383 if (equals + pp->buffer_pos > pp->buffer_size)
388 memcpy (&buf[pp->buffer_pos], &post_data[poff], equals);
389 pp->buffer_pos += equals;
390 if (equals + poff == post_data_len)
392 buf[pp->buffer_pos] =
'\0';
398 pp->value_offset = 0;
402 memcpy (xbuf, pp->xbuf, pp->xbuf_pos);
408 while ((amper + poff < post_data_len) &&
410 (post_data[amper + poff] !=
'&') &&
411 (post_data[amper + poff] !=
'\n') &&
412 (post_data[amper + poff] !=
'\r'))
414 end_of_value_found = ((amper + poff < post_data_len) &&
415 ((post_data[amper + poff] ==
'&') ||
416 (post_data[amper + poff] ==
'\n') ||
417 (post_data[amper + poff] ==
'\r')));
425 memcpy (&xbuf[xoff], &post_data[poff], delta);
434 (
'%' == xbuf[delta - 1]))
436 else if ((delta > 1) &&
437 (
'%' == xbuf[delta - 2]))
447 pp->xbuf_pos = xoff - delta;
455 (poff == post_data_len))
464 if (
MHD_NO == pp->ikvi (pp->cls,
466 (
const char *) &pp[1],
477 pp->value_offset += xoff;
480 if (end_of_value_found)
483 if ( (
'\n' == post_data[poff]) ||
484 (
'\r' == post_data[poff]) )
488 else if (
'&' == post_data[poff])
496 if ( (
'\n' == post_data[poff]) ||
497 (
'\r' == post_data[poff]) )
538 *suffix = strdup (&line[strlen (prefix)]);
562 const char *boundary,
568 char *buf = (
char *) &pp[1];
571 if (pp->buffer_pos < 2 + blen)
573 if (pp->buffer_pos == pp->buffer_size)
578 if ( (0 != memcmp (
"--",
581 (0 != memcmp (&buf[2],
597 (*ioffptr) += pp->buffer_pos;
602 (*ioffptr) += dash - buf;
607 (*ioffptr) += 2 + blen;
610 pp->state = next_state;
611 pp->dash_state = next_dash_state;
633 if (
NULL != *destination)
637 while (
NULL != (spos = strstr (bpos, key)))
639 if ( (spos[klen] !=
'=') ||
641 (spos[-1] !=
' ') ) )
647 if (spos[klen + 1] !=
'"')
649 if (
NULL == (endv = strchr (&spos[klen + 2],
652 vlen = endv - spos - klen - 1;
653 *destination = malloc (vlen);
654 if (
NULL == *destination)
656 (*destination)[vlen - 1] =
'\0';
657 memcpy (*destination,
685 char *buf = (
char *) &pp[1];
689 while ( (newline < pp->buffer_pos) &&
690 (buf[newline] !=
'\r') &&
691 (buf[newline] !=
'\n') )
693 if (newline == pp->buffer_size)
698 if (newline == pp->buffer_pos)
704 pp->state = next_state;
708 if (buf[newline] ==
'\r')
720 &pp->content_filename);
729 &pp->content_transfer_encoding);
731 (*ioffptr) += newline + 1;
755 const char *boundary,
760 char *buf = (
char *) &pp[1];
769 while (newline + 4 < pp->buffer_pos)
771 r = memchr (&buf[newline],
773 pp->buffer_pos - newline - 4);
776 newline = pp->buffer_pos - 4;
780 if (0 == memcmp (
"\r\n--",
786 if (newline + pp->blen + 4 <= pp->buffer_pos)
789 if (0 != memcmp (&buf[newline + 4],
802 pp->state = next_state;
803 pp->dash_state = next_dash_state;
804 (*ioffptr) += pp->blen + 4;
814 if ( (0 == newline) &&
815 (pp->buffer_pos == pp->buffer_size) )
826 if ( ( (
MHD_YES == pp->must_ikvi) ||
828 (
MHD_NO == pp->ikvi (pp->cls,
831 pp->content_filename,
833 pp->content_transfer_encoding,
842 pp->value_offset += newline;
843 (*ioffptr) += newline;
855 if ( (
NULL != pp->content_name) &&
858 free (pp->content_name);
859 pp->content_name =
NULL;
861 if ( (
NULL != pp->content_type) &&
864 free (pp->content_type);
865 pp->content_type =
NULL;
867 if ( (
NULL != pp->content_filename) &&
870 free (pp->content_filename);
871 pp->content_filename =
NULL;
873 if ( (
NULL != pp->content_transfer_encoding) &&
876 free (pp->content_transfer_encoding);
877 pp->content_transfer_encoding =
NULL;
892 const char *post_data,
893 size_t post_data_len)
901 buf = (
char *) &pp[1];
905 while ( (poff < post_data_len) ||
906 ( (pp->buffer_pos > 0) &&
907 (0 != state_changed) ) )
911 max = pp->buffer_size - pp->buffer_pos;
912 if (max > post_data_len - poff)
913 max = post_data_len - poff;
914 memcpy (&buf[pp->buffer_pos],
918 pp->buffer_pos += max;
920 (0 == state_changed) &&
921 (poff < post_data_len) )
953 if ( (pp->buffer_pos > 1) &&
980 pp->state = pp->dash_state;
1043 if ( (
NULL != pp->content_type) &&
1048 pp->nested_boundary = strstr (pp->content_type,
1050 if (
NULL == pp->nested_boundary)
1055 pp->nested_boundary =
1057 if (
NULL == pp->nested_boundary)
1065 free (pp->content_type);
1066 pp->content_type =
NULL;
1067 pp->nlen = strlen (pp->nested_boundary);
1073 pp->value_offset = 0;
1093 if (
NULL != pp->nested_boundary)
1095 free (pp->nested_boundary);
1096 pp->nested_boundary =
NULL;
1102 if (
NULL == pp->nested_boundary)
1108 pp->nested_boundary,
1123 if (
NULL != pp->content_name)
1125 if (
NULL != pp->content_type)
1127 if (
NULL != pp->content_filename)
1129 if (
NULL != pp->content_transfer_encoding)
1135 pp->value_offset = 0;
1151 pp->nested_boundary,
1177 pp->buffer_pos - ioff);
1178 pp->buffer_pos -= ioff;
1188 pp->buffer_pos - ioff);
1189 pp->buffer_pos -= ioff;
1191 if (poff < post_data_len)
1215 const char *post_data,
1216 size_t post_data_len)
1218 if (0 == post_data_len)
1268 if ( (pp->xbuf_pos > 0) ||
1276 if (
NULL != pp->nested_boundary)
1277 free (pp->nested_boundary);
void MHD_unescape_plus(char *arg)
enum MHD_CONNECTION_STATE state
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)
Header for platform missing functions.
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)
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)
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
#define MHD_STATICSTR_LEN_(macro)
struct MHD_PostProcessor * MHD_create_post_processor(struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iter, void *iter_cls)
const char * MHD_lookup_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
int MHD_post_process(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
static int post_process_urlencoded(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
internal shared structures
void * MHD_calloc_(size_t nelem, size_t elsize)
static int post_process_multipart(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
static int try_match_header(const char *prefix, char *line, char **suffix)
#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED
Header for string manipulating helpers.
static void free_unmarked(struct MHD_PostProcessor *pp)
MHD_PanicCallback mhd_panic
#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)
size_t MHD_http_unescape(char *val)
static void try_get_value(const char *buf, const char *key, char **destination)