commit 650d4685f7e9f8297df706d0c220fbd12e6e84d4
parent e0d851cee3ada233b7ede637fd9155dfa7756907
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Fri, 3 May 2019 19:06:19 +0300
Added MHD_get_connection_values_n() function to get keys and
values with size. Can get keys and values with binary zero.
Diffstat:
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
@@ -2493,7 +2493,8 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
* @param iterator callback to call on each header;
* maybe NULL (then just count headers)
* @param iterator_cls extra argument to @a iterator
- * @return number of entries iterated over
+ * @return number of entries iterated over,
+ * -1 if connection is NULL.
* @ingroup request
*/
_MHD_EXTERN int
@@ -2504,6 +2505,25 @@ MHD_get_connection_values (struct MHD_Connection *connection,
/**
+ * Get all of the headers from the request.
+ *
+ * @param connection connection to get values from
+ * @param kind types of values to iterate over, can be a bitmask
+ * @param iterator callback to call on each header;
+ * maybe NULL (then just count headers)
+ * @param iterator_cls extra argument to @a iterator
+ * @return number of entries iterated over,
+ * -1 if connection is NULL.
+ * @ingroup request
+ */
+_MHD_EXTERN int
+MHD_get_connection_values_n (struct MHD_Connection *connection,
+ enum MHD_ValueKind kind,
+ MHD_KeyValueIteratorN iterator,
+ void *iterator_cls);
+
+
+/**
* This function can be used to add an entry to the HTTP headers of a
* connection (so that the #MHD_get_connection_values function will
* return them -- and the `struct MHD_PostProcessor` will also see
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -684,6 +684,7 @@ socket_start_normal_buffering (struct MHD_Connection *connection)
* maybe NULL (then just count headers)
* @param iterator_cls extra argument to @a iterator
* @return number of entries iterated over
+ * -1 if connection is NULL.
* @ingroup request
*/
int
@@ -714,6 +715,52 @@ MHD_get_connection_values (struct MHD_Connection *connection,
/**
+ * Get all of the headers from the request.
+ *
+ * @param connection connection to get values from
+ * @param kind types of values to iterate over, can be a bitmask
+ * @param iterator callback to call on each header;
+ * maybe NULL (then just count headers)
+ * @param iterator_cls extra argument to @a iterator
+ * @return number of entries iterated over,
+ * -1 if connection is NULL.
+ * @ingroup request
+ */
+int
+MHD_get_connection_values_n (struct MHD_Connection *connection,
+ enum MHD_ValueKind kind,
+ MHD_KeyValueIteratorN iterator,
+ void *iterator_cls)
+{
+ int ret;
+ struct MHD_HTTP_Header *pos;
+
+ if (NULL == connection)
+ return -1;
+ ret = 0;
+
+ if (NULL == iterator)
+ for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+ if (kind == pos->kind)
+ ret++;
+ else
+ for (pos = connection->headers_received; NULL != pos; pos = pos->next)
+ if (kind == pos->kind)
+ {
+ ret++;
+ if (MHD_NO == iterator (iterator_cls,
+ pos->kind,
+ pos->header,
+ pos->header_size,
+ pos->value,
+ pos->value_size))
+ return ret;
+ }
+ return ret;
+}
+
+
+/**
* This function can be used to add an arbitrary entry to connection.
* Internal version of #MHD_set_connection_value_n() without checking
* of arguments values.