gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] branch master updated (203d885e -> 650d4685


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (203d885e -> 650d4685)
Date: Fri, 03 May 2019 18:08:45 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 203d885e test_postprocessor*: fixed to use updated struct 
MHD_HTTP_Header
     new e0d851ce MHD_set_connection_value*(): optimization to avoid double 
strlen().
     new 650d4685 Added MHD_get_connection_values_n() function to get keys and 
values with size. Can get keys and values with binary zero.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/microhttpd.h    |  22 ++++++-
 src/microhttpd/connection.c | 145 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 134 insertions(+), 33 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 3dbda318..a492071a 100644
--- 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
@@ -2503,6 +2504,25 @@ MHD_get_connection_values (struct MHD_Connection 
*connection,
                            void *iterator_cls);
 
 
+/**
+ * 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
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 3ad4dd7e..9e136b9d 100644
--- 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,20 +715,58 @@ MHD_get_connection_values (struct MHD_Connection 
*connection,
 
 
 /**
- * This function can be used to add an arbitrary entry to connection.
- * This function could add entry with binary zero, which is allowed
- * for #MHD_GET_ARGUMENT_KIND. For other kind on entries it is
- * recommended to use #MHD_set_connection_value.
+ * Get all of the headers from the request.
  *
- * This function MUST only be called from within the
- * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
- * synchronized).  Furthermore, the client must guarantee that the key
- * and value arguments are 0-terminated strings that are NOT freed
- * until the connection is closed.  (The easiest way to do this is by
- * passing only arguments to permanently allocated strings.).
+ * @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.
  *
  * @param connection the connection for which a
- *  value should be set
+ *                   value should be set
  * @param kind kind of the value
  * @param key key for the value, must be zero-terminated
  * @param key_size number of bytes in @a key (excluding 0-terminator)
@@ -739,20 +778,15 @@ MHD_get_connection_values (struct MHD_Connection 
*connection,
  * @ingroup request
  */
 int
-MHD_set_connection_value_n (struct MHD_Connection *connection,
-                            enum MHD_ValueKind kind,
-                            const char *key,
-                            size_t key_size,
-                            const char *value,
-                            size_t value_size)
+MHD_set_connection_value_n_nocheck_ (struct MHD_Connection *connection,
+                                     enum MHD_ValueKind kind,
+                                     const char *key,
+                                     size_t key_size,
+                                     const char *value,
+                                     size_t value_size)
 {
   struct MHD_HTTP_Header *pos;
 
-  if ( (MHD_GET_ARGUMENT_KIND != kind) &&
-       ( ((key ? strlen(key) : 0) != key_size) ||
-         ((value ? strlen(value) : 0) != value_size) ) )
-    return MHD_NO; /* binary zero is allowed only in GET arguments */
-
   pos = MHD_pool_allocate (connection->pool,
                            sizeof (struct MHD_HTTP_Header),
                            MHD_YES);
@@ -779,6 +813,53 @@ MHD_set_connection_value_n (struct MHD_Connection 
*connection,
 }
 
 
+/**
+ * This function can be used to add an arbitrary entry to connection.
+ * This function could add entry with binary zero, which is allowed
+ * for #MHD_GET_ARGUMENT_KIND. For other kind on entries it is
+ * recommended to use #MHD_set_connection_value.
+ *
+ * This function MUST only be called from within the
+ * #MHD_AccessHandlerCallback (otherwise, access maybe improperly
+ * synchronized).  Furthermore, the client must guarantee that the key
+ * and value arguments are 0-terminated strings that are NOT freed
+ * until the connection is closed.  (The easiest way to do this is by
+ * passing only arguments to permanently allocated strings.).
+ *
+ * @param connection the connection for which a
+ *  value should be set
+ * @param kind kind of the value
+ * @param key key for the value, must be zero-terminated
+ * @param key_size number of bytes in @a key (excluding 0-terminator)
+ * @param value the value itself, must be zero-terminated
+ * @param value_size number of bytes in @a value (excluding 0-terminator)
+ * @return #MHD_NO if the operation could not be
+ *         performed due to insufficient memory;
+ *         #MHD_YES on success
+ * @ingroup request
+ */
+int
+MHD_set_connection_value_n (struct MHD_Connection *connection,
+                            enum MHD_ValueKind kind,
+                            const char *key,
+                            size_t key_size,
+                            const char *value,
+                            size_t value_size)
+{
+  if ( (MHD_GET_ARGUMENT_KIND != kind) &&
+       ( ((key ? strlen(key) : 0) != key_size) ||
+         ((value ? strlen(value) : 0) != value_size) ) )
+    return MHD_NO; /* binary zero is allowed only in GET arguments */
+
+  return MHD_set_connection_value_n_nocheck_ (connection,
+                                              kind,
+                                              key,
+                                              key_size,
+                                              value,
+                                              value_size);
+}
+
+
 /**
  * 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
@@ -810,16 +891,16 @@ MHD_set_connection_value (struct MHD_Connection 
*connection,
                           const char *key,
                           const char *value)
 {
-  return MHD_set_connection_value_n (connection,
-                                    kind,
-                                    key,
-                                     NULL != key
-                                     ? strlen (key)
-                                     : 0,
-                                     value,
-                                    NULL != value
-                                    ? strlen (value)
-                                    : 0);
+  return MHD_set_connection_value_n_nocheck_ (connection,
+                                              kind,
+                                              key,
+                                              NULL != key
+                                              ? strlen (key)
+                                              : 0,
+                                              value,
+                                              NULL != value
+                                              ? strlen (value)
+                                              : 0);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]