aboutsummaryrefslogtreecommitdiff
path: root/src/lib/request.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/request.c')
-rw-r--r--src/lib/request.c109
1 files changed, 103 insertions, 6 deletions
diff --git a/src/lib/request.c b/src/lib/request.c
index 8af35b28..0e280efa 100644
--- a/src/lib/request.c
+++ b/src/lib/request.c
@@ -1,3 +1,31 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19*/
20/**
21 * @file requests.c
22 * @brief Methods for managing HTTP requests
23 * @author Daniel Pittman
24 * @author Christian Grothoff
25 * @author Karlson2k (Evgeny Grin)
26 */
27
28
1/** 29/**
2 * Get all of the headers from the request. 30 * Get all of the headers from the request.
3 * 31 *
@@ -9,11 +37,35 @@
9 * @return number of entries iterated over 37 * @return number of entries iterated over
10 * @ingroup request 38 * @ingroup request
11 */ 39 */
12_MHD_EXTERN unsigned int 40unsigned int
13MHD_request_get_values (struct MHD_Request *request, 41MHD_request_get_values (struct MHD_Request *request,
14 enum MHD_ValueKind kind, 42 enum MHD_ValueKind kind,
15 MHD_KeyValueIterator iterator, 43 MHD_KeyValueIterator iterator,
16 void *iterator_cls); 44 void *iterator_cls)
45{
46 int ret;
47 struct MHD_HTTP_Header *pos;
48
49 if (NULL == request)
50 return -1;
51 ret = 0;
52 for (pos = request->headers_received;
53 NULL != pos;
54 pos = pos->next)
55 {
56 if (0 != (pos->kind & kind))
57 {
58 ret++;
59 if ( (NULL != iterator) &&
60 (MHD_YES != iterator (iterator_cls,
61 pos->kind,
62 pos->header,
63 pos->value)) )
64 return ret;
65 }
66 }
67 return ret;
68}
17 69
18 70
19/** 71/**
@@ -41,11 +93,36 @@ MHD_request_get_values (struct MHD_Request *request,
41 * #MHD_YES on success 93 * #MHD_YES on success
42 * @ingroup request 94 * @ingroup request
43 */ 95 */
44_MHD_EXTERN enum MHD_Bool 96enum MHD_Bool
45MHD_request_set_value (struct MHD_Request *request, 97MHD_request_set_value (struct MHD_Request *request,
46 enum MHD_ValueKind kind, 98 enum MHD_ValueKind kind,
47 const char *key, 99 const char *key,
48 const char *value); 100 const char *value)
101{
102 struct MHD_HTTP_Header *pos;
103
104 pos = MHD_pool_allocate (request->pool,
105 sizeof (struct MHD_HTTP_Header),
106 MHD_YES);
107 if (NULL == pos)
108 return MHD_NO;
109 pos->header = (char *) key;
110 pos->value = (char *) value;
111 pos->kind = kind;
112 pos->next = NULL;
113 /* append 'pos' to the linked list of headers */
114 if (NULL == request->headers_received_tail)
115 {
116 request->headers_received = pos;
117 request->headers_received_tail = pos;
118 }
119 else
120 {
121 request->headers_received_tail->next = pos;
122 request->headers_received_tail = pos;
123 }
124 return MHD_YES;
125}
49 126
50 127
51/** 128/**
@@ -58,11 +135,31 @@ MHD_request_set_value (struct MHD_Request *request,
58 * @return NULL if no such item was found 135 * @return NULL if no such item was found
59 * @ingroup request 136 * @ingroup request
60 */ 137 */
61_MHD_EXTERN const char * 138const char *
62MHD_request_lookup_value (struct MHD_Request *request, 139MHD_request_lookup_value (struct MHD_Request *request,
63 enum MHD_ValueKind kind, 140 enum MHD_ValueKind kind,
64 const char *key); 141 const char *key)
142{
143 struct MHD_HTTP_Header *pos;
144
145 if (NULL == request)
146 return NULL;
147 for (pos = request->headers_received;
148 NULL != pos;
149 pos = pos->next)
150 {
151 if ((0 != (pos->kind & kind)) &&
152 ( (key == pos->header) ||
153 ( (NULL != pos->header) &&
154 (NULL != key) &&
155 (MHD_str_equal_caseless_(key,
156 pos->header)))))
157 return pos->value;
158 }
159 return NULL;
160}
65 161
66 162
163/* end of request.c */
67 164
68 165