From de4e13c7ae8bc7de22535948aec9ef6b699191ca Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Thu, 1 Aug 2024 15:44:46 +0200 Subject: [PATCH] Updated API and internal names for clarity --- src/include/microhttpd2.h | 6 +++--- src/include/microhttpd2_main.h.in | 6 +++--- src/mhd2/action.c | 23 +++++++++++++++-------- src/mhd2/mhd_action.h | 10 +++++----- src/mhd2/request_get_value.h | 2 +- src/mhd2/stream_process_request.c | 12 ++++++------ 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index 97b71750..2ed56454 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h @@ -4823,9 +4823,9 @@ enum MHD_FLAGS_ENUM_ MHD_ValueKind , /** * POST data. - * This is available only if a content encoding - * supported by MHD is used, and only if the posted content - * fits within the available memory pool. + * This is available only if #MHD_action_parse_post() action is used, + * a content encoding is supported by MHD, and only if the posted content + * fits within the specified memory buffers. * * @warning The encoding "multipart/form-data" has more fields than just * "name" and "value". See #MHD_request_get_post_data_cb() and diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in index 8e3e09c2..786c956f 100644 --- a/src/include/microhttpd2_main.h.in +++ b/src/include/microhttpd2_main.h.in @@ -539,9 +539,9 @@ enum MHD_FLAGS_ENUM_ MHD_ValueKind , /** * POST data. - * This is available only if a content encoding - * supported by MHD is used, and only if the posted content - * fits within the available memory pool. + * This is available only if #MHD_action_parse_post() action is used, + * a content encoding is supported by MHD, and only if the posted content + * fits within the specified memory buffers. * * @warning The encoding "multipart/form-data" has more fields than just * "name" and "value". See #MHD_request_get_post_data_cb() and diff --git a/src/mhd2/action.c b/src/mhd2/action.c index 1e561e01..c058df4f 100644 --- a/src/mhd2/action.c +++ b/src/mhd2/action.c @@ -116,6 +116,7 @@ MHD_action_parse_post (struct MHD_Request *request, MHD_PostDataFinished done_cb, void *done_cb_cls) { +#ifdef HAVE_POST_PARSER struct MHD_Action *const restrict head_act = &(request->app_act.head_act); if (mhd_ACTION_NO_ACTION != head_act->act) @@ -123,16 +124,22 @@ MHD_action_parse_post (struct MHD_Request *request, if (NULL == done_cb) return (const struct MHD_Action *) NULL; - head_act->act = mhd_ACTION_POST_PROCESS; - head_act->data.post_process.buffer_size = buffer_size; - head_act->data.post_process.auto_stream_size = auto_stream_size; - head_act->data.post_process.enc = enc; - head_act->data.post_process.stream_reader = stream_reader; - head_act->data.post_process.reader_cls = reader_cls; - head_act->data.post_process.done_cb = done_cb; - head_act->data.post_process.done_cb_cls = done_cb_cls; + head_act->act = mhd_ACTION_POST_PARSE; + head_act->data.post_parse.buffer_size = buffer_size; + head_act->data.post_parse.auto_stream_size = auto_stream_size; + head_act->data.post_parse.enc = enc; + head_act->data.post_parse.stream_reader = stream_reader; + head_act->data.post_parse.reader_cls = reader_cls; + head_act->data.post_parse.done_cb = done_cb; + head_act->data.post_parse.done_cb_cls = done_cb_cls; return head_act; +#else /* ! HAVE_POST_PARSER */ + (void) request; (void) buffer_size; (void) auto_stream_size; + (void) enc; (void) stream_reader; (void) reader_cls; + (void) done_cb; (void) done_cb_cls; + return NULL; +#endif /* ! HAVE_POST_PARSER */ } diff --git a/src/mhd2/mhd_action.h b/src/mhd2/mhd_action.h index 0059b8f9..395f67eb 100644 --- a/src/mhd2/mhd_action.h +++ b/src/mhd2/mhd_action.h @@ -55,9 +55,9 @@ enum mhd_ActionType mhd_ACTION_UPLOAD , /** - * Process clients upload by POST processor + * Process POST data clients upload by POST parser */ - mhd_ACTION_POST_PROCESS + mhd_ACTION_POST_PARSE , /** * Suspend requests (connection) @@ -190,7 +190,7 @@ enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_HTTP_PostEncoding // TODO: correct and describe -struct mhd_PostProcessorActionData +struct mhd_PostParseActionData { size_t buffer_size; size_t auto_stream_size; @@ -217,9 +217,9 @@ union mhd_ActionData struct mhd_UploadCallbacks upload; /** - * The data for the action #mhd_ACTION_POST_PROCESS + * The data for the action #mhd_ACTION_POST_PARSE */ - struct mhd_PostProcessorActionData post_process; + struct mhd_PostParseActionData post_parse; }; diff --git a/src/mhd2/request_get_value.h b/src/mhd2/request_get_value.h index 7917a7e7..20271b29 100644 --- a/src/mhd2/request_get_value.h +++ b/src/mhd2/request_get_value.h @@ -36,7 +36,7 @@ /** * Get specified field value from request - * If multiple values match the kind, return any one of them. + * If multiple values match the kind, return first found. * * The returned pointer is valid until the response is queued. * If the data is needed beyond this point, it should be copied. diff --git a/src/mhd2/stream_process_request.c b/src/mhd2/stream_process_request.c index ed77d423..d96a039b 100644 --- a/src/mhd2/stream_process_request.c +++ b/src/mhd2/stream_process_request.c @@ -2852,7 +2852,7 @@ static MHD_FN_PAR_NONNULL_ALL_ bool check_and_alloc_buf_for_upload_processing (struct MHD_Connection *restrict c) { mhd_assert ((mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act) || \ - (mhd_ACTION_POST_PROCESS == c->rq.app_act.head_act.act)); + (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act)); if (c->rq.have_chunked_upload) return true; /* The size is unknown, buffers will be dynamically allocated @@ -2952,7 +2952,7 @@ mhd_stream_call_app_request_cb (struct MHD_Connection *restrict c) } c->state = MHD_CONNECTION_FULL_REQ_RECEIVED; return true; - case mhd_ACTION_POST_PROCESS: + case mhd_ACTION_POST_PARSE: mhd_assert (0 && "Not implemented yet"); return true; case mhd_ACTION_SUSPEND: @@ -3232,7 +3232,7 @@ process_request_chunked_body (struct MHD_Connection *restrict c) } mhd_assert (c->rq.app_aware); - if (mhd_ACTION_POST_PROCESS == c->rq.app_act.head_act.act) + if (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act) { mhd_assert (0 && "Not implemented yet"); // TODO: implement POST return false; @@ -3344,7 +3344,7 @@ process_request_nonchunked_body (struct MHD_Connection *restrict c) else cntn_data_ready = c->read_buffer_offset; - if (mhd_ACTION_POST_PROCESS == c->rq.app_act.head_act.act) + if (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act) { mhd_assert (0 && "Not implemented yet"); // TODO: implement POST return false; @@ -3413,10 +3413,10 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool mhd_stream_call_app_final_upload_cb (struct MHD_Connection *restrict c) { const struct MHD_UploadAction *act; - mhd_assert (mhd_ACTION_POST_PROCESS == c->rq.app_act.head_act.act || \ + mhd_assert (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act || \ mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act); - if (mhd_ACTION_POST_PROCESS == c->rq.app_act.head_act.act) + if (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act) { mhd_assert (0 && "Not implemented yet"); // TODO: implement POST return false;