aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-05-01 22:10:38 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-05-01 22:12:24 +0300
commit8aa7d23219052cde065b93adf04c5ded067a1fea (patch)
treefbf947885f56dd3f3da17a330c39178291ad53a7 /src/microhttpd/connection.c
parent08ea0cc894bfdd9aeddeb8bb113514c247d2c69e (diff)
downloadlibmicrohttpd-8aa7d23219052cde065b93adf04c5ded067a1fea.tar.gz
libmicrohttpd-8aa7d23219052cde065b93adf04c5ded067a1fea.zip
Partial revert of 1b610e5b13b7b96e7b3f372c8da1ec9d840f896a.
Implemented new functions for key and value with binary zero. Significantly speedup search for key by using key size.
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 0b040290..611d4141 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -706,8 +706,7 @@ MHD_get_connection_values (struct MHD_Connection *connection,
706 (MHD_YES != iterator (iterator_cls, 706 (MHD_YES != iterator (iterator_cls,
707 pos->kind, 707 pos->kind,
708 pos->header, 708 pos->header,
709 pos->value, 709 pos->value)) )
710 pos->value_size)) )
711 return ret; 710 return ret;
712 } 711 }
713 return ret; 712 return ret;
@@ -733,19 +732,21 @@ MHD_get_connection_values (struct MHD_Connection *connection,
733 * value should be set 732 * value should be set
734 * @param kind kind of the value 733 * @param kind kind of the value
735 * @param key key for the value 734 * @param key key for the value
735 * @param key_size number of bytes in @a key (excluding 0-terminator for C-strings)
736 * @param value the value itself 736 * @param value the value itself
737 * @param value_size number of bytes in @a value 737 * @param value_size number of bytes in @a value (excluding 0-terminator for C-strings)
738 * @return #MHD_NO if the operation could not be 738 * @return #MHD_NO if the operation could not be
739 * performed due to insufficient memory; 739 * performed due to insufficient memory;
740 * #MHD_YES on success 740 * #MHD_YES on success
741 * @ingroup request 741 * @ingroup request
742 */ 742 */
743int 743int
744MHD_set_connection_value2 (struct MHD_Connection *connection, 744MHD_set_connection_value_n (struct MHD_Connection *connection,
745 enum MHD_ValueKind kind, 745 enum MHD_ValueKind kind,
746 const char *key, 746 const char *key,
747 const char *value, 747 size_t key_size,
748 size_t value_size) 748 const char *value,
749 size_t value_size)
749{ 750{
750 struct MHD_HTTP_Header *pos; 751 struct MHD_HTTP_Header *pos;
751 752
@@ -755,6 +756,7 @@ MHD_set_connection_value2 (struct MHD_Connection *connection,
755 if (NULL == pos) 756 if (NULL == pos)
756 return MHD_NO; 757 return MHD_NO;
757 pos->header = (char *) key; 758 pos->header = (char *) key;
759 pos->header_size = key_size;
758 pos->value = (char *) value; 760 pos->value = (char *) value;
759 pos->value_size = value_size; 761 pos->value_size = value_size;
760 pos->kind = kind; 762 pos->kind = kind;
@@ -805,13 +807,16 @@ MHD_set_connection_value (struct MHD_Connection *connection,
805 const char *key, 807 const char *key,
806 const char *value) 808 const char *value)
807{ 809{
808 return MHD_set_connection_value2 (connection, 810 return MHD_set_connection_value_n (connection,
809 kind, 811 kind,
810 key, 812 key,
811 value, 813 NULL != key
812 NULL != value 814 ? strlen (key)
813 ? strlen (value) 815 : 0,
814 : 0); 816 value,
817 NULL != value
818 ? strlen (value)
819 : 0);
815} 820}
816 821
817 822
@@ -2105,6 +2110,7 @@ get_next_header_line (struct MHD_Connection *connection,
2105 * value should be set 2110 * value should be set
2106 * @param kind kind of the value 2111 * @param kind kind of the value
2107 * @param key key for the value 2112 * @param key key for the value
2113 * @param key_size number of bytes in @a key
2108 * @param value the value itself 2114 * @param value the value itself
2109 * @param value_size number of bytes in @a value 2115 * @param value_size number of bytes in @a value
2110 * @return #MHD_NO on failure (out of memory), #MHD_YES for success 2116 * @return #MHD_NO on failure (out of memory), #MHD_YES for success
@@ -2112,16 +2118,18 @@ get_next_header_line (struct MHD_Connection *connection,
2112static int 2118static int
2113connection_add_header (struct MHD_Connection *connection, 2119connection_add_header (struct MHD_Connection *connection,
2114 const char *key, 2120 const char *key,
2121 size_t key_size,
2115 const char *value, 2122 const char *value,
2116 size_t value_size, 2123 size_t value_size,
2117 enum MHD_ValueKind kind) 2124 enum MHD_ValueKind kind)
2118{ 2125{
2119 if (MHD_NO == 2126 if (MHD_NO ==
2120 MHD_set_connection_value2 (connection, 2127 MHD_set_connection_value_n (connection,
2121 kind, 2128 kind,
2122 key, 2129 key,
2123 value, 2130 key_size,
2124 value_size)) 2131 value,
2132 value_size))
2125 { 2133 {
2126#ifdef HAVE_MESSAGES 2134#ifdef HAVE_MESSAGES
2127 MHD_DLOG (connection->daemon, 2135 MHD_DLOG (connection->daemon,
@@ -2203,6 +2211,7 @@ parse_cookie_header (struct MHD_Connection *connection)
2203 if (MHD_NO == 2211 if (MHD_NO ==
2204 connection_add_header (connection, 2212 connection_add_header (connection,
2205 pos, 2213 pos,
2214 ekill - pos + 1,
2206 "", 2215 "",
2207 0, 2216 0,
2208 MHD_COOKIE_KIND)) 2217 MHD_COOKIE_KIND))
@@ -2243,6 +2252,7 @@ parse_cookie_header (struct MHD_Connection *connection)
2243 if (MHD_NO == 2252 if (MHD_NO ==
2244 connection_add_header (connection, 2253 connection_add_header (connection,
2245 pos, 2254 pos,
2255 ekill - pos + 1,
2246 equals, 2256 equals,
2247 end - equals, 2257 end - equals,
2248 MHD_COOKIE_KIND)) 2258 MHD_COOKIE_KIND))
@@ -2774,6 +2784,7 @@ process_broken_line (struct MHD_Connection *connection,
2774 if (MHD_NO == 2784 if (MHD_NO ==
2775 connection_add_header (connection, 2785 connection_add_header (connection,
2776 last, 2786 last,
2787 strlen (last),
2777 connection->colon, 2788 connection->colon,
2778 strlen (connection->colon), 2789 strlen (connection->colon),
2779 kind)) 2790 kind))