#include #include #include enum PP_State { PP_Error, PP_Done, PP_Init, PP_NextBoundary, PP_ProcessValue, PP_Callback, PP_ExpectNewLine, PP_ProcessEntryHeaders, PP_PerformCheckMultipart, PP_ProcessValueToBoundary, PP_PerformCleanup, PP_Nested_Init, PP_Nested_PerformMarking, PP_Nested_ProcessEntryHeaders, PP_Nested_ProcessValueToBoundary, PP_Nested_PerformCleanup }; enum RN_State { RN_Inactive = 0, RN_OptN = 1, RN_Full = 2, RN_Dash = 3, RN_Dash2 = 4 }; enum NE_State { NE_none = 0, NE_content_name = 1, NE_content_type = 2, NE_content_filename = 4, NE_content_transfer_encoding = 8 }; struct MHD_PostProcessor { struct MHD_Connection *connection; MHD_PostDataIterator ikvi; void *cls; const char *encoding; const char *boundary; char *nested_boundary; char *content_name; char *content_type; char *content_filename; char *content_transfer_encoding; char xbuf[2]; size_t buffer_size; size_t buffer_pos; size_t xbuf_pos; uint64_t value_offset; size_t blen; size_t nlen; bool must_ikvi; bool must_unescape_key; enum PP_State state; enum RN_State skip_rn; enum PP_State dash_state; enum NE_State have; }; static int post_data_iterator( 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 ) { printf("%s\t%s\n", key, data ); return MHD_YES; } int main( int argc, char *argv[] ) { struct MHD_PostProcessor *postprocessor = (struct MHD_PostProcessor *)calloc(1, sizeof(struct MHD_PostProcessor) + 0x1000+1); postprocessor->connection = nullptr; postprocessor->ikvi = post_data_iterator; postprocessor->cls = nullptr; postprocessor->encoding = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; postprocessor->buffer_size = 0x1000; postprocessor->state = PP_Init; postprocessor->blen = 0; postprocessor->boundary = nullptr; postprocessor->skip_rn = RN_Inactive; MHD_post_process( postprocessor, "xxxx=xxxx", 9 ); MHD_post_process( postprocessor, "&yyyy=yyyy&zzzz=&aaaa=", 22 ); MHD_post_process( postprocessor, "", 0 ); return EXIT_SUCCESS; }