gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r5049 - in libmicrohttpd: . src/daemon


From: gnunet
Subject: [GNUnet-SVN] r5049 - in libmicrohttpd: . src/daemon
Date: Wed, 13 Jun 2007 18:56:06 -0600 (MDT)

Author: grothoff
Date: 2007-06-13 18:56:06 -0600 (Wed, 13 Jun 2007)
New Revision: 5049

Modified:
   libmicrohttpd/README
   libmicrohttpd/src/daemon/session.c
Log:
added parsing of query

Modified: libmicrohttpd/README
===================================================================
--- libmicrohttpd/README        2007-06-14 00:37:55 UTC (rev 5048)
+++ libmicrohttpd/README        2007-06-14 00:56:06 UTC (rev 5049)
@@ -5,11 +5,6 @@
 before certain features can be used at all:
 
 
-For GET args:
-=============
-session.c:
-- MHD_parse_session_headers: take URL apart
-
 For PUT/POST:
 =============
 session.c:
@@ -30,9 +25,6 @@
 - http 1.0 compatibility (if 1.0, force connection
   close at the end!)
 
-
-
-
 For IPv6:
 =========
 daemon.c:

Modified: libmicrohttpd/src/daemon/session.c
===================================================================
--- libmicrohttpd/src/daemon/session.c  2007-06-14 00:37:55 UTC (rev 5048)
+++ libmicrohttpd/src/daemon/session.c  2007-06-14 00:56:06 UTC (rev 5049)
@@ -207,6 +207,69 @@
   return rbuf;
 }
 
+static void 
+MHD_session_add_header(struct MHD_Session * session,
+                      const char * key,
+                      const char * value,
+                      enum MHD_ValueKind kind) {
+  struct MHD_HTTP_Header * hdr;
+
+  hdr = malloc(sizeof(struct MHD_HTTP_Header));
+  hdr->next = session->headers_received;
+  hdr->header = strdup(key);
+  hdr->value = strdup(value);
+  hdr->kind = kind;
+  session->headers_received = hdr;
+}
+
+static void 
+MHD_http_unescape(char * val) {
+  char * esc;
+  unsigned int num;
+
+  while (NULL != (esc = strstr(val, "%"))) {
+    if ( (1 == sscanf(&esc[1],
+                   "%2x",
+                   &num)) ||
+        (1 == sscanf(&esc[1],
+                     "%2X",
+                     &num)) ) {
+      esc[0] = (unsigned char) num;
+      memmove(&esc[1],
+             &esc[3],
+             strlen(&esc[3]));
+    }
+    val = esc+1;
+  }
+}
+
+static void 
+MHD_parse_arguments(struct MHD_Session * session,
+                   char * args) {
+  char * equals;
+  char * amper;
+
+  while (args != NULL) {
+    equals = strstr(args, "=");
+    if (equals == NULL)
+      return; /* invalid, ignore */
+    equals[0] = '\0';
+    equals++;
+    amper = strstr(equals, "&");
+    if (amper != NULL) {
+      amper[0] = '\0';
+      amper++;
+    }    
+    MHD_http_unescape(args);
+    MHD_http_unescape(equals);
+    MHD_session_add_header(session,
+                          args,
+                          equals,
+                          MHD_GET_ARGUMENT_KIND);
+    args = amper;
+  }
+}
+
 /**
  * This function is designed to parse the input buffer of a given session.
  *
@@ -223,7 +286,7 @@
   char * colon;
   char * uri;
   char * httpType;
-  struct MHD_HTTP_Header * hdr;
+  char * args;
 
   if (session->bodyReceived == 1)
     abort();
@@ -239,6 +302,13 @@
       httpType = strstr(uri, " ");
       if (httpType != NULL)
        httpType[0] = '\0';
+      args = strstr(uri, "?");
+      if (args != NULL) {
+       args[0] = '\0';
+       args++;
+       MHD_parse_arguments(session,
+                           args);
+      }
       /* FIXME: parse URI some more here */
       session->url = strdup(uri);
       /* do we want to do anything with httpType? */
@@ -249,7 +319,7 @@
     if (strlen(line) == 0) {
       /* end of header */
       session->headersReceived = 1;
-      /* FIXME: check with methods may have a body,
+      /* FIXME: check which methods may have a body,
         check headers to find out upload size */
       session->uploadSize = 0;
       session->bodyReceived = 1;
@@ -267,12 +337,11 @@
     /* zero-terminate header */
     colon[0] = '\0';
     colon += 2; /* advance to value */
-    hdr = malloc(sizeof(struct MHD_HTTP_Header));
-    hdr->next = session->headers_received;
-    hdr->header = line;
-    hdr->value = strdup(colon);
-    hdr->kind = MHD_HEADER_KIND;
-    session->headers_received = hdr;
+    MHD_session_add_header(session,
+                          line,
+                          colon,
+                          MHD_HEADER_KIND);
+    free(line);
   }
   /* FIXME: here: find cookie header and parse that! */
   return;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]