aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r--src/daemon/connection.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index 7d973283..e3590d5e 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -144,8 +144,8 @@ MHD_get_connection_values (struct MHD_Connection *connection,
144 144
145 145
146/** 146/**
147 * This function can be used to add an entry to 147 * This function can be used to append an entry to
148 * the HTTP headers of a connection (so that the 148 * the list of HTTP headers of a connection (so that the
149 * MHD_get_connection_values function will return 149 * MHD_get_connection_values function will return
150 * them -- and the MHD PostProcessor will also 150 * them -- and the MHD PostProcessor will also
151 * see them). This maybe required in certain 151 * see them). This maybe required in certain
@@ -186,8 +186,18 @@ MHD_set_connection_value (struct MHD_Connection *connection,
186 pos->header = (char *) key; 186 pos->header = (char *) key;
187 pos->value = (char *) value; 187 pos->value = (char *) value;
188 pos->kind = kind; 188 pos->kind = kind;
189 pos->next = connection->headers_received; 189 pos->next = NULL;
190 connection->headers_received = pos; 190 /* append 'pos' to the linked list of headers */
191 if (NULL == connection->headers_received_tail)
192 {
193 connection->headers_received = pos;
194 connection->headers_received_tail = pos;
195 }
196 else
197 {
198 connection->headers_received_tail->next = pos;
199 connection->headers_received_tail = pos;
200 }
191 return MHD_YES; 201 return MHD_YES;
192} 202}
193 203
@@ -207,15 +217,11 @@ MHD_lookup_connection_value (struct MHD_Connection *connection,
207{ 217{
208 struct MHD_HTTP_Header *pos; 218 struct MHD_HTTP_Header *pos;
209 219
210 if (connection == NULL) 220 if (NULL == connection)
211 return NULL; 221 return NULL;
212 pos = connection->headers_received; 222 for (pos = connection->headers_received; NULL != pos; pos = pos->next)
213 while (pos != NULL) 223 if ((0 != (pos->kind & kind)) && (0 == strcasecmp (key, pos->header)))
214 { 224 return pos->value;
215 if ((0 != (pos->kind & kind)) && (0 == strcasecmp (key, pos->header)))
216 return pos->value;
217 pos = pos->next;
218 }
219 return NULL; 225 return NULL;
220} 226}
221 227
@@ -1036,18 +1042,25 @@ get_next_header_line (struct MHD_Connection *connection)
1036 return rbuf; 1042 return rbuf;
1037} 1043}
1038 1044
1045
1039/** 1046/**
1047 * Add an entry to the HTTP headers of a connection. If this fails,
1048 * transmit an error response (request too big).
1049 *
1050 * @param connection the connection for which a
1051 * value should be set
1052 * @param kind kind of the value
1053 * @param key key for the value
1054 * @param value the value itself
1040 * @return MHD_NO on failure (out of memory), MHD_YES for success 1055 * @return MHD_NO on failure (out of memory), MHD_YES for success
1041 */ 1056 */
1042static int 1057static int
1043connection_add_header (struct MHD_Connection *connection, 1058connection_add_header (struct MHD_Connection *connection,
1044 char *key, char *value, enum MHD_ValueKind kind) 1059 char *key, char *value, enum MHD_ValueKind kind)
1045{ 1060{
1046 struct MHD_HTTP_Header *hdr; 1061 if (MHD_NO == MHD_set_connection_value (connection,
1047 1062 kind,
1048 hdr = MHD_pool_allocate (connection->pool, 1063 key, value))
1049 sizeof (struct MHD_HTTP_Header), MHD_YES);
1050 if (hdr == NULL)
1051 { 1064 {
1052#if HAVE_MESSAGES 1065#if HAVE_MESSAGES
1053 MHD_DLOG (connection->daemon, 1066 MHD_DLOG (connection->daemon,
@@ -1057,14 +1070,10 @@ connection_add_header (struct MHD_Connection *connection,
1057 REQUEST_TOO_BIG); 1070 REQUEST_TOO_BIG);
1058 return MHD_NO; 1071 return MHD_NO;
1059 } 1072 }
1060 hdr->next = connection->headers_received;
1061 hdr->header = key;
1062 hdr->value = value;
1063 hdr->kind = kind;
1064 connection->headers_received = hdr;
1065 return MHD_YES; 1073 return MHD_YES;
1066} 1074}
1067 1075
1076
1068/** 1077/**
1069 * Parse and unescape the arguments given by the client as part 1078 * Parse and unescape the arguments given by the client as part
1070 * of the HTTP request URI. 1079 * of the HTTP request URI.
@@ -2289,6 +2298,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2289 connection->continue_message_write_offset = 0; 2298 connection->continue_message_write_offset = 0;
2290 connection->responseCode = 0; 2299 connection->responseCode = 0;
2291 connection->headers_received = NULL; 2300 connection->headers_received = NULL;
2301 connection->headers_received_tail = NULL;
2292 connection->response_write_position = 0; 2302 connection->response_write_position = 0;
2293 connection->have_chunked_upload = MHD_NO; 2303 connection->have_chunked_upload = MHD_NO;
2294 connection->method = NULL; 2304 connection->method = NULL;