[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] 01/02: MHD_set_connection_value*(): optimiz
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] 01/02: MHD_set_connection_value*(): optimization to avoid double strlen(). |
Date: |
Fri, 03 May 2019 18:08:46 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit e0d851cee3ada233b7ede637fd9155dfa7756907
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Fri May 3 18:59:41 2019 +0300
MHD_set_connection_value*(): optimization to avoid double strlen().
---
src/microhttpd/connection.c | 98 ++++++++++++++++++++++++++++++---------------
1 file changed, 66 insertions(+), 32 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 3ad4dd7e..d77b023a 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -715,19 +715,11 @@ 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.
- *
- * 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.).
+ * 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 +731,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 +766,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 +844,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