[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 05/11: MHD_parse_arguments_(): refactored, allow cls for
From: |
gnunet |
Subject: |
[libmicrohttpd] 05/11: MHD_parse_arguments_(): refactored, allow cls for the callback |
Date: |
Wed, 22 Jun 2022 20:00:11 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 6ccaa5da57dbfb74e6131ce0ff0165522ef501d6
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Jun 22 20:57:50 2022 +0300
MHD_parse_arguments_(): refactored, allow cls for the callback
---
src/microhttpd/connection.c | 9 ++++-----
src/microhttpd/digestauth.c | 23 +++++++++++++++++------
src/microhttpd/internal.c | 17 ++++++-----------
src/microhttpd/internal.h | 8 ++++----
4 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 2d58e35c..463fc88e 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2725,8 +2725,7 @@ get_next_header_line (struct MHD_Connection *connection,
* Add an entry to the HTTP headers of a connection. If this fails,
* transmit an error response (request too big).
*
- * @param connection the connection for which a
- * value should be set
+ * @param cls the context (connection)
* @param kind kind of the value
* @param key key for the value
* @param key_size number of bytes in @a key
@@ -2735,13 +2734,14 @@ get_next_header_line (struct MHD_Connection *connection,
* @return #MHD_NO on failure (out of memory), #MHD_YES for success
*/
static enum MHD_Result
-connection_add_header (struct MHD_Connection *connection,
+connection_add_header (void *cls,
const char *key,
size_t key_size,
const char *value,
size_t value_size,
enum MHD_ValueKind kind)
{
+ struct MHD_Connection *connection = (struct MHD_Connection *) cls;
if (MHD_NO ==
MHD_set_connection_value_n (connection,
kind,
@@ -3266,7 +3266,6 @@ parse_initial_message_line (struct MHD_Connection
*connection,
char *uri;
char *http_version;
char *args;
- unsigned int unused_num_headers;
if (NULL == (uri = memchr (line,
' ',
@@ -3362,7 +3361,7 @@ parse_initial_message_line (struct MHD_Connection
*connection,
MHD_GET_ARGUMENT_KIND,
args,
&connection_add_header,
- &unused_num_headers);
+ connection);
}
/* unescape URI *after* searching for arguments and log callback */
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 890fc129..114f72b8 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -1185,11 +1185,17 @@ calculate_add_nonce_with_retry (struct MHD_Connection
*const connection,
}
+struct test_header_param
+{
+ struct MHD_Connection *connection;
+ unsigned int num_headers;
+};
+
/**
* Test if the given key-value pair is in the headers for the
* given connection.
*
- * @param connection the connection
+ * @param cls the test context
* @param key the key
* @param key_size number of bytes in @a key
* @param value the value, can be NULL
@@ -1199,15 +1205,18 @@ calculate_add_nonce_with_retry (struct MHD_Connection
*const connection,
* #MHD_NO if not
*/
static enum MHD_Result
-test_header (struct MHD_Connection *connection,
+test_header (void *cls,
const char *key,
size_t key_size,
const char *value,
size_t value_size,
enum MHD_ValueKind kind)
{
+ struct test_header_param *const param = (struct test_header_param *) cls;
+ struct MHD_Connection *connection = param->connection;
struct MHD_HTTP_Req_Header *pos;
+ param->num_headers++;
for (pos = connection->headers_received; NULL != pos; pos = pos->next)
{
if (kind != pos->kind)
@@ -1251,8 +1260,8 @@ check_argument_match (struct MHD_Connection *connection,
{
struct MHD_HTTP_Req_Header *pos;
char *argb;
- unsigned int num_headers;
enum MHD_Result ret;
+ struct test_header_param param;
argb = strdup (args);
if (NULL == argb)
@@ -1263,11 +1272,13 @@ check_argument_match (struct MHD_Connection *connection,
#endif /* HAVE_MESSAGES */
return MHD_NO;
}
+ param.connection = connection;
+ param.num_headers = 0;
ret = MHD_parse_arguments_ (connection,
MHD_GET_ARGUMENT_KIND,
argb,
&test_header,
- &num_headers);
+ ¶m);
free (argb);
if (MHD_NO == ret)
{
@@ -1278,9 +1289,9 @@ check_argument_match (struct MHD_Connection *connection,
{
if (MHD_GET_ARGUMENT_KIND != pos->kind)
continue;
- num_headers--;
+ param.num_headers--;
}
- if (0 != num_headers)
+ if (0 != param.num_headers)
{
/* argument count mismatch */
return MHD_NO;
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c
index b1e2ad36..e9e92414 100644
--- a/src/microhttpd/internal.c
+++ b/src/microhttpd/internal.c
@@ -186,7 +186,7 @@ MHD_http_unescape (char *val)
* @param[in,out] args argument URI string (after "?" in URI),
* clobbered in the process!
* @param cb function to call on each key-value pair found
- * @param[out] num_headers set to the number of headers found
+ * @param cls the iterator context
* @return #MHD_NO on failure (@a cb returned #MHD_NO),
* #MHD_YES for success (parsing succeeded, @a cb always
* returned #MHD_YES)
@@ -196,13 +196,12 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
enum MHD_ValueKind kind,
char *args,
MHD_ArgumentIterator_ cb,
- unsigned int *num_headers)
+ void *cls)
{
struct MHD_Daemon *daemon = connection->daemon;
char *equals;
char *amper;
- *num_headers = 0;
while ( (NULL != args) &&
('\0' != args[0]) )
{
@@ -220,14 +219,13 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
connection,
args);
- if (MHD_NO == cb (connection,
+ if (MHD_NO == cb (cls,
args,
key_len,
NULL,
0,
kind))
return MHD_NO;
- (*num_headers)++;
break;
}
/* got 'foo=bar' */
@@ -241,14 +239,13 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
value_len = daemon->unescape_callback (daemon->unescape_callback_cls,
connection,
equals);
- if (MHD_NO == cb (connection,
+ if (MHD_NO == cb (cls,
args,
key_len,
equals,
value_len,
kind))
return MHD_NO;
- (*num_headers)++;
break;
}
/* amper is non-NULL here */
@@ -262,7 +259,7 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
connection,
args);
- if (MHD_NO == cb (connection,
+ if (MHD_NO == cb (cls,
args,
key_len,
NULL,
@@ -270,7 +267,6 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
kind))
return MHD_NO;
/* continue with 'bar' */
- (*num_headers)++;
args = amper;
continue;
}
@@ -286,14 +282,13 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
value_len = daemon->unescape_callback (daemon->unescape_callback_cls,
connection,
equals);
- if (MHD_NO == cb (connection,
+ if (MHD_NO == cb (cls,
args,
key_len,
equals,
value_len,
kind))
return MHD_NO;
- (*num_headers)++;
args = amper;
}
return MHD_YES;
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 79b93c80..1fbb6e65 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -2368,7 +2368,7 @@ MHD_unescape_plus (char *arg);
* Callback invoked when iterating over @a key / @a value
* argument pairs during parsing.
*
- * @param connection context of the iteration
+ * @param cls context of the iteration
* @param key 0-terminated key string, never NULL
* @param key_size number of bytes in key
* @param value 0-terminated binary data, may include binary zeros, may be NULL
@@ -2378,7 +2378,7 @@ MHD_unescape_plus (char *arg);
* #MHD_NO to signal failure (and abort iteration)
*/
typedef enum MHD_Result
-(*MHD_ArgumentIterator_)(struct MHD_Connection *connection,
+(*MHD_ArgumentIterator_)(void *cls,
const char *key,
size_t key_size,
const char *value,
@@ -2395,7 +2395,7 @@ typedef enum MHD_Result
* @param[in,out] args argument URI string (after "?" in URI),
* clobbered in the process!
* @param cb function to call on each key-value pair found
- * @param[out] num_headers set to the number of headers found
+ * @param cls the iterator context
* @return #MHD_NO on failure (@a cb returned #MHD_NO),
* #MHD_YES for success (parsing succeeded, @a cb always
* returned #MHD_YES)
@@ -2405,7 +2405,7 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
enum MHD_ValueKind kind,
char *args,
MHD_ArgumentIterator_ cb,
- unsigned int *num_headers);
+ void *cls);
/**
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (1c181be2 -> 8b01c152), gnunet, 2022/06/22
- [libmicrohttpd] 04/11: test_digestauth{._with_arguments}: do test really with arguments, gnunet, 2022/06/22
- [libmicrohttpd] 03/11: configure: removed unused variable, gnunet, 2022/06/22
- [libmicrohttpd] 07/11: Added tracking of the request URL length., gnunet, 2022/06/22
- [libmicrohttpd] 10/11: digestauth.h: added some doxy, gnunet, 2022/06/22
- [libmicrohttpd] 01/11: configure: removed unneeded special flags for Darwin, gnunet, 2022/06/22
- [libmicrohttpd] 06/11: digest_auth_check_all(): simplified, improved readability, gnunet, 2022/06/22
- [libmicrohttpd] 05/11: MHD_parse_arguments_(): refactored, allow cls for the callback,
gnunet <=
- [libmicrohttpd] 08/11: Fixed check for URL match to handle URLs with binary zero, gnunet, 2022/06/22
- [libmicrohttpd] 02/11: configure: added basic support for AIX XLC flags, gnunet, 2022/06/22
- [libmicrohttpd] 09/11: digestauth: removed now unused do-while scope, gnunet, 2022/06/22
- [libmicrohttpd] 11/11: mhd_str.h: fixed doxy, gnunet, 2022/06/22