aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-06-14 00:56:06 +0000
committerChristian Grothoff <christian@grothoff.org>2007-06-14 00:56:06 +0000
commite0084684983c71dc75891c966c64c62b35df376d (patch)
tree92e4a2b8f310da2c7c52e1ffe589877a213874a9
parenta01593e2f832856619bc2540ef4c135788cab24b (diff)
downloadlibmicrohttpd-e0084684983c71dc75891c966c64c62b35df376d.tar.gz
libmicrohttpd-e0084684983c71dc75891c966c64c62b35df376d.zip
added parsing of query
-rw-r--r--README8
-rw-r--r--src/daemon/session.c85
2 files changed, 77 insertions, 16 deletions
diff --git a/README b/README
index afcd9a53..ef46cb20 100644
--- a/README
+++ b/README
@@ -5,11 +5,6 @@ things need to be implemented (in list of importance)
5before certain features can be used at all: 5before certain features can be used at all:
6 6
7 7
8For GET args:
9=============
10session.c:
11- MHD_parse_session_headers: take URL apart
12
13For PUT/POST: 8For PUT/POST:
14============= 9=============
15session.c: 10session.c:
@@ -30,9 +25,6 @@ session.c:
30- http 1.0 compatibility (if 1.0, force connection 25- http 1.0 compatibility (if 1.0, force connection
31 close at the end!) 26 close at the end!)
32 27
33
34
35
36For IPv6: 28For IPv6:
37========= 29=========
38daemon.c: 30daemon.c:
diff --git a/src/daemon/session.c b/src/daemon/session.c
index 828b91a1..885d4d97 100644
--- a/src/daemon/session.c
+++ b/src/daemon/session.c
@@ -207,6 +207,69 @@ MHD_get_next_header_line(struct MHD_Session * session) {
207 return rbuf; 207 return rbuf;
208} 208}
209 209
210static void
211MHD_session_add_header(struct MHD_Session * session,
212 const char * key,
213 const char * value,
214 enum MHD_ValueKind kind) {
215 struct MHD_HTTP_Header * hdr;
216
217 hdr = malloc(sizeof(struct MHD_HTTP_Header));
218 hdr->next = session->headers_received;
219 hdr->header = strdup(key);
220 hdr->value = strdup(value);
221 hdr->kind = kind;
222 session->headers_received = hdr;
223}
224
225static void
226MHD_http_unescape(char * val) {
227 char * esc;
228 unsigned int num;
229
230 while (NULL != (esc = strstr(val, "%"))) {
231 if ( (1 == sscanf(&esc[1],
232 "%2x",
233 &num)) ||
234 (1 == sscanf(&esc[1],
235 "%2X",
236 &num)) ) {
237 esc[0] = (unsigned char) num;
238 memmove(&esc[1],
239 &esc[3],
240 strlen(&esc[3]));
241 }
242 val = esc+1;
243 }
244}
245
246static void
247MHD_parse_arguments(struct MHD_Session * session,
248 char * args) {
249 char * equals;
250 char * amper;
251
252 while (args != NULL) {
253 equals = strstr(args, "=");
254 if (equals == NULL)
255 return; /* invalid, ignore */
256 equals[0] = '\0';
257 equals++;
258 amper = strstr(equals, "&");
259 if (amper != NULL) {
260 amper[0] = '\0';
261 amper++;
262 }
263 MHD_http_unescape(args);
264 MHD_http_unescape(equals);
265 MHD_session_add_header(session,
266 args,
267 equals,
268 MHD_GET_ARGUMENT_KIND);
269 args = amper;
270 }
271}
272
210/** 273/**
211 * This function is designed to parse the input buffer of a given session. 274 * This function is designed to parse the input buffer of a given session.
212 * 275 *
@@ -223,7 +286,7 @@ MHD_parse_session_headers(struct MHD_Session * session) {
223 char * colon; 286 char * colon;
224 char * uri; 287 char * uri;
225 char * httpType; 288 char * httpType;
226 struct MHD_HTTP_Header * hdr; 289 char * args;
227 290
228 if (session->bodyReceived == 1) 291 if (session->bodyReceived == 1)
229 abort(); 292 abort();
@@ -239,6 +302,13 @@ MHD_parse_session_headers(struct MHD_Session * session) {
239 httpType = strstr(uri, " "); 302 httpType = strstr(uri, " ");
240 if (httpType != NULL) 303 if (httpType != NULL)
241 httpType[0] = '\0'; 304 httpType[0] = '\0';
305 args = strstr(uri, "?");
306 if (args != NULL) {
307 args[0] = '\0';
308 args++;
309 MHD_parse_arguments(session,
310 args);
311 }
242 /* FIXME: parse URI some more here */ 312 /* FIXME: parse URI some more here */
243 session->url = strdup(uri); 313 session->url = strdup(uri);
244 /* do we want to do anything with httpType? */ 314 /* do we want to do anything with httpType? */
@@ -249,7 +319,7 @@ MHD_parse_session_headers(struct MHD_Session * session) {
249 if (strlen(line) == 0) { 319 if (strlen(line) == 0) {
250 /* end of header */ 320 /* end of header */
251 session->headersReceived = 1; 321 session->headersReceived = 1;
252 /* FIXME: check with methods may have a body, 322 /* FIXME: check which methods may have a body,
253 check headers to find out upload size */ 323 check headers to find out upload size */
254 session->uploadSize = 0; 324 session->uploadSize = 0;
255 session->bodyReceived = 1; 325 session->bodyReceived = 1;
@@ -267,12 +337,11 @@ MHD_parse_session_headers(struct MHD_Session * session) {
267 /* zero-terminate header */ 337 /* zero-terminate header */
268 colon[0] = '\0'; 338 colon[0] = '\0';
269 colon += 2; /* advance to value */ 339 colon += 2; /* advance to value */
270 hdr = malloc(sizeof(struct MHD_HTTP_Header)); 340 MHD_session_add_header(session,
271 hdr->next = session->headers_received; 341 line,
272 hdr->header = line; 342 colon,
273 hdr->value = strdup(colon); 343 MHD_HEADER_KIND);
274 hdr->kind = MHD_HEADER_KIND; 344 free(line);
275 session->headers_received = hdr;
276 } 345 }
277 /* FIXME: here: find cookie header and parse that! */ 346 /* FIXME: here: find cookie header and parse that! */
278 return; 347 return;