aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-05-03 16:48:57 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-05-03 16:48:57 +0300
commitcc5032b85365e567f02650f13ea6ad9a5bb5fef7 (patch)
treee84702ea064930c68d992292baa2444b6cc3e7cd /src
parent7e4885da25b58455452cd6dbcd167f761e3ff38e (diff)
downloadlibmicrohttpd-cc5032b85365e567f02650f13ea6ad9a5bb5fef7.tar.gz
libmicrohttpd-cc5032b85365e567f02650f13ea6ad9a5bb5fef7.zip
Added MHD_lookup_connection_value_n().
Diffstat (limited to 'src')
-rw-r--r--src/include/microhttpd.h31
-rw-r--r--src/microhttpd/connection.c86
2 files changed, 106 insertions, 11 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 6617dd98..3dbda318 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -128,7 +128,7 @@ typedef intptr_t ssize_t;
128 * Current version of the library. 128 * Current version of the library.
129 * 0x01093001 = 1.9.30-1. 129 * 0x01093001 = 1.9.30-1.
130 */ 130 */
131#define MHD_VERSION 0x00096303 131#define MHD_VERSION 0x00096304
132 132
133/** 133/**
134 * MHD-internal return code for "YES". 134 * MHD-internal return code for "YES".
@@ -2620,6 +2620,35 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
2620 2620
2621 2621
2622/** 2622/**
2623 * Get a particular header value. If multiple
2624 * values match the kind, return any one of them.
2625 * @note Since MHD_VERSION 0x00096304
2626 *
2627 * @param connection connection to get values from
2628 * @param kind what kind of value are we looking for
2629 * @param key the header to look for, NULL to lookup 'trailing' value without a key
2630 * @param key_size the length of @a key in bytes
2631 * @param[out] value_ptr the pointer to variable, which will be set to found value,
2632 * will not be updated if key not found,
2633 * could be NULL to just check for presence of @a key
2634 * @param[out] value_size_ptr the pointer variable, which will set to found value,
2635 * will not be updated if key not found,
2636 * could be NULL
2637 * @param key_size the length of @a key in bytes
2638 * @return #MHD_YES if key is found,
2639 * #MHD_NO otherwise.
2640 * @ingroup request
2641 */
2642_MHD_EXTERN int
2643MHD_lookup_connection_value_n (struct MHD_Connection *connection,
2644 enum MHD_ValueKind kind,
2645 const char *key,
2646 size_t key_size,
2647 const char **value,
2648 size_t *value_size);
2649
2650
2651/**
2623 * Queue a response to be transmitted to the client (as soon as 2652 * Queue a response to be transmitted to the client (as soon as
2624 * possible but after #MHD_AccessHandlerCallback returns). 2653 * possible but after #MHD_AccessHandlerCallback returns).
2625 * 2654 *
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index ef3228a7..3ad4dd7e 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -838,19 +838,85 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
838 enum MHD_ValueKind kind, 838 enum MHD_ValueKind kind,
839 const char *key) 839 const char *key)
840{ 840{
841 const char *value;
842
843 value = NULL;
844 MHD_lookup_connection_value_n (connection,
845 kind,
846 key,
847 (NULL == key) ? 0 : strlen(key),
848 &value,
849 NULL);
850 return value;
851}
852
853
854/**
855 * Get a particular header value. If multiple
856 * values match the kind, return any one of them.
857 * @note Since MHD_VERSION 0x00096304
858 *
859 * @param connection connection to get values from
860 * @param kind what kind of value are we looking for
861 * @param key the header to look for, NULL to lookup 'trailing' value without a key
862 * @param key_size the length of @a key in bytes
863 * @param[out] value_ptr the pointer to variable, which will be set to found value,
864 * will not be updated if key not found,
865 * could be NULL to just check for presence of @a key
866 * @param[out] value_size_ptr the pointer variable, which will set to found value,
867 * will not be updated if key not found,
868 * could be NULL
869 * @param key_size the length of @a key in bytes
870 * @return #MHD_YES if key is found,
871 * #MHD_NO otherwise.
872 * @ingroup request
873 */
874_MHD_EXTERN int
875MHD_lookup_connection_value_n (struct MHD_Connection *connection,
876 enum MHD_ValueKind kind,
877 const char *key,
878 size_t key_size,
879 const char **value_ptr,
880 size_t *value_size_ptr)
881{
841 struct MHD_HTTP_Header *pos; 882 struct MHD_HTTP_Header *pos;
842 883
843 if (NULL == connection) 884 if (NULL == connection)
844 return NULL; 885 return MHD_NO;
845 for (pos = connection->headers_received; NULL != pos; pos = pos->next) 886
846 if ((0 != (pos->kind & kind)) && 887 if (NULL == key)
847 ( (key == pos->header) || 888 {
848 ( (NULL != pos->header) && 889 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
849 (NULL != key) && 890 {
850 (MHD_str_equal_caseless_(key, 891 if ( (kind == pos->kind) &&
851 pos->header))))) 892 (NULL == pos->header) )
852 return pos->value; 893 break;
853 return NULL; 894 }
895 }
896 else
897 {
898 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
899 {
900 if ( (kind == pos->kind) &&
901 (key_size == pos->header_size) &&
902 ( (key == pos->header) ||
903 (MHD_str_equal_caseless_bin_n_ (key,
904 pos->header,
905 key_size) ) ) )
906 break;
907 }
908 }
909
910 if (NULL == pos)
911 return MHD_NO;
912
913 if (NULL != value_ptr)
914 *value_ptr = pos->value;
915
916 if (NULL != value_size_ptr)
917 *value_size_ptr = pos->value_size;
918
919 return MHD_YES;
854} 920}
855 921
856 922