commit dc426594a4224def23567add24ca9022204272ad
parent 00ba8288abfae809240ff8f3d35acb0028d64b3e
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sat, 15 Nov 2025 18:17:24 +0100
Internal refactoring: use MHD_Stream pointer instead of MHD_Connection for some relevant functions
Diffstat:
5 files changed, 37 insertions(+), 26 deletions(-)
diff --git a/src/mhd2/auth_digest.c b/src/mhd2/auth_digest.c
@@ -2396,7 +2396,7 @@ check_argument_match (struct MHD_Request *restrict req,
param.request = req;
param.num_get_params = 0;
- if (! mhd_parse_get_args (args_len,
+ if (! mhd_parse_uri_args (args_len,
args,
&test_header,
¶m))
diff --git a/src/mhd2/request_funcs.c b/src/mhd2/request_funcs.c
@@ -43,20 +43,27 @@
*/
#include "mhd_sys_options.h"
+
+#include "mhd_cntnr_ptr.h"
+
#include "mhd_request.h"
#include "mhd_connection.h"
-#include "request_funcs.h"
+
#include "stream_funcs.h"
#include "mhd_dlinked_list.h"
+#include "request_funcs.h"
+
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool
-mhd_stream_add_field_nullable (struct MHD_Connection *restrict c,
+mhd_stream_add_field_nullable (struct MHD_Stream *restrict s,
enum MHD_ValueKind kind,
const struct MHD_String *restrict name,
const struct MHD_StringNullable *restrict value)
{
struct mhd_RequestField *f;
+ struct MHD_Connection *const c =
+ mhd_CNTNR_PTR (s, struct MHD_Connection, h1_stream);
f = (struct mhd_RequestField *)
mhd_stream_alloc_memory (c, sizeof(struct mhd_RequestField));
@@ -75,7 +82,7 @@ mhd_stream_add_field_nullable (struct MHD_Connection *restrict c,
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool
-mhd_stream_add_field (struct MHD_Connection *restrict c,
+mhd_stream_add_field (struct MHD_Stream *restrict s,
enum MHD_ValueKind kind,
const struct MHD_String *restrict name,
const struct MHD_String *restrict value)
@@ -85,5 +92,5 @@ mhd_stream_add_field (struct MHD_Connection *restrict c,
value2.len = value->len;
value2.cstr = value->cstr;
- return mhd_stream_add_field_nullable (c, kind, name, &value2);
+ return mhd_stream_add_field_nullable (s, kind, name, &value2);
}
diff --git a/src/mhd2/request_funcs.h b/src/mhd2/request_funcs.h
@@ -50,13 +50,13 @@
#include "mhd_str_types.h"
#include "mhd_public_api.h"
-struct MHD_Connection; /* forward declaration */
+struct MHD_Stream; /* forward declaration */
/**
* Add field to the request.
* The memory allocated in the request memory pool
*
- * @param c the connection to use
+ * @param s the stream to use
* @param kind the kind of the field to add
* @param name the name of the field to add, the string is not copied,
* only copied the pointer value
@@ -66,7 +66,7 @@ struct MHD_Connection; /* forward declaration */
* false if memory cannot be allocated
*/
MHD_INTERNAL bool
-mhd_stream_add_field (struct MHD_Connection *restrict c,
+mhd_stream_add_field (struct MHD_Stream *restrict s,
enum MHD_ValueKind kind,
const struct MHD_String *restrict name,
const struct MHD_String *restrict value)
@@ -77,7 +77,7 @@ MHD_FN_PAR_NONNULL_ALL_;
* The memory allocated in the request memory pool
* The value can have NULL string ("no value").
*
- * @param c the connection to use
+ * @param s the stream to use
* @param kind the kind of the field to add
* @param name the name of the field to add, the string is not copied,
* only copied the pointer value
@@ -87,7 +87,7 @@ MHD_FN_PAR_NONNULL_ALL_;
* false if memory cannot be allocated
*/
MHD_INTERNAL bool
-mhd_stream_add_field_nullable (struct MHD_Connection *restrict c,
+mhd_stream_add_field_nullable (struct MHD_Stream *restrict s,
enum MHD_ValueKind kind,
const struct MHD_String *restrict name,
const struct MHD_StringNullable *restrict value)
diff --git a/src/mhd2/stream_process_request.c b/src/mhd2/stream_process_request.c
@@ -1218,9 +1218,9 @@ request_add_get_arg (void *restrict cls,
const struct MHD_String *restrict name,
const struct MHD_StringNullable *restrict value)
{
- struct MHD_Connection *c = (struct MHD_Connection *) cls;
+ struct MHD_Stream *s = (struct MHD_Stream *) cls;
- return mhd_stream_add_field_nullable (c, MHD_VK_URI_QUERY_PARAM, name, value);
+ return mhd_stream_add_field_nullable (s, MHD_VK_URI_QUERY_PARAM, name, value);
}
@@ -1228,7 +1228,7 @@ MHD_INTERNAL
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
MHD_FN_PAR_INOUT_SIZE_ (2, 1) bool
// TODO: detect and report errors
-mhd_parse_get_args (size_t args_len,
+mhd_parse_uri_args (size_t args_len,
char *restrict args,
mhd_GetArgumentInter cb,
void *restrict cls)
@@ -1352,10 +1352,10 @@ process_request_target (struct MHD_Connection *c)
c->rq.hdrs.rq_line.rq_tgt_qmark[0] = 0; /* Replace '?' with zero termination */
// TODO: support detection of decoding errors
- if (! mhd_parse_get_args (params_len - 1,
+ if (! mhd_parse_uri_args (params_len - 1,
c->rq.hdrs.rq_line.rq_tgt_qmark + 1,
&request_add_get_arg,
- c))
+ &(c->h1_stream)))
{
mhd_LOG_MSG (c->daemon, MHD_SC_CONNECTION_POOL_NO_MEM_GET_PARAM,
"Not enough memory in the pool to store GET parameter");
@@ -2152,7 +2152,7 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c,
mhd_assert ((hdr_value.len == 0) || \
(hdr_value.cstr[hdr_value.len - 1] != '\t'));
- if (! mhd_stream_add_field (c,
+ if (! mhd_stream_add_field (&(c->h1_stream),
process_footers ?
MHD_VK_TRAILER : MHD_VK_HEADER,
&hdr_name,
@@ -2341,20 +2341,21 @@ MHD_FN_PAR_CSTR_ (2)
MHD_FN_PAR_INOUT_SIZE_ (2,1) enum mhd_ParseCookie
parse_cookies_string (const size_t str_len,
char *restrict str,
- struct MHD_Connection *restrict connection)
+ enum MHD_ProtocolStrictLevel strictness,
+ struct MHD_Stream *restrict s)
{
size_t i;
bool non_strict;
/* Skip extra whitespaces and empty cookies */
- const bool allow_wsp_empty = (0 >= connection->daemon->req_cfg.strictness);
+ const bool allow_wsp_empty = (0 >= strictness);
/* Allow whitespaces around '=' character */
- const bool wsp_around_eq = (-3 >= connection->daemon->req_cfg.strictness);
+ const bool wsp_around_eq = (-3 >= strictness);
/* Allow whitespaces in quoted cookie value */
- const bool wsp_in_quoted = (-2 >= connection->daemon->req_cfg.strictness);
+ const bool wsp_in_quoted = (-2 >= strictness);
/* Allow tab as space after semicolon between cookies */
- const bool tab_as_sp = (0 >= connection->daemon->req_cfg.strictness);
+ const bool tab_as_sp = (0 >= strictness);
/* Allow no space after semicolon between cookies */
- const bool allow_no_space = (0 >= connection->daemon->req_cfg.strictness);
+ const bool allow_no_space = (0 >= strictness);
non_strict = false;
i = 0;
@@ -2484,7 +2485,7 @@ parse_cookies_string (const size_t str_len,
str[value_start + value_len] = 0; /* Zero-terminate the value */
value.cstr = str + value_start;
value.len = value_len;
- if (! mhd_stream_add_field (connection,
+ if (! mhd_stream_add_field (s,
MHD_VK_COOKIE,
&name,
&value))
@@ -2498,7 +2499,7 @@ parse_cookies_string (const size_t str_len,
name.len = name_len;
value.cstr = "";
value.len = 0;
- if (! mhd_stream_add_field (connection,
+ if (! mhd_stream_add_field (s,
MHD_VK_COOKIE,
&name,
&value))
@@ -2580,7 +2581,10 @@ parse_cookie_header (struct MHD_Connection *restrict connection,
mhd_assert ('\t' != cpy[0]);
i = 0;
- parse_res = parse_cookies_string (cookie_val->len - i, cpy + i, connection);
+ parse_res = parse_cookies_string (cookie_val->len - i,
+ cpy + i,
+ connection->daemon->req_cfg.strictness,
+ &(connection->h1_stream));
}
switch (parse_res)
diff --git a/src/mhd2/stream_process_request.h b/src/mhd2/stream_process_request.h
@@ -87,7 +87,7 @@ typedef bool
* true on success (parsing succeeded, @a cb always returned true)
*/
MHD_INTERNAL bool
-mhd_parse_get_args (size_t args_len,
+mhd_parse_uri_args (size_t args_len,
char *restrict args,
mhd_GetArgumentInter cb,
void *restrict cls)