gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r5284 - in libmicrohttpd: . src/daemon
Date: Sun, 8 Jul 2007 21:37:43 -0600 (MDT)

Author: grothoff
Date: 2007-07-08 21:37:43 -0600 (Sun, 08 Jul 2007)
New Revision: 5284

Modified:
   libmicrohttpd/README
   libmicrohttpd/src/daemon/connection.c
Log:
cleanup

Modified: libmicrohttpd/README
===================================================================
--- libmicrohttpd/README        2007-07-09 03:27:23 UTC (rev 5283)
+++ libmicrohttpd/README        2007-07-09 03:37:43 UTC (rev 5284)
@@ -30,17 +30,16 @@
 For SSL:
 ========
 microhttpd.h:
-- define appropriate APIs
-- everything else
+- define appropriate MHD_OPTIONs
+- actual implementation
 
 
 Other:
 ======
-- allow client to determine http 1.0 vs. 1.1
-  (API extension)
 - allow client to control size of input/output
-  buffers
+  buffers (add MHD_OPTION)
 - allow client to limit total number of connections
+  (add MHD_OPTION)
 
 
 

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2007-07-09 03:27:23 UTC (rev 
5283)
+++ libmicrohttpd/src/daemon/connection.c       2007-07-09 03:37:43 UTC (rev 
5284)
@@ -254,8 +254,9 @@
 }
 
 static void
-MHD_parse_arguments(struct MHD_Connection * connection,
-                   char * args) {
+parse_arguments(enum MHD_ValueKind kind,
+               struct MHD_Connection * connection,
+               char * args) {
   char * equals;
   char * amper;
 
@@ -273,9 +274,9 @@
     MHD_http_unescape(args);
     MHD_http_unescape(equals);
     MHD_connection_add_header(connection,
-                          args,
-                          equals,
-                          MHD_GET_ARGUMENT_KIND);
+                             args,
+                             equals,
+                             kind);
     args = amper;
   }
 }
@@ -336,7 +337,50 @@
   free(cpy);
 }
 
+/**
+ * Parse the first line of the HTTP HEADER.
+ *
+ * @param connection the connection (updated)
+ * @param line the first line
+ * @return MHD_YES if the line is ok, MHD_NO if it is malformed
+ */
+static int
+parse_initial_message_line(struct MHD_Connection * connection,
+                          char * line) {
+  char * uri;
+  char * httpVersion;
+  char * args;
 
+  uri = strstr(line, " ");
+  if (uri == NULL)
+    return MHD_NO; /* serious error */
+  uri[0] = '\0';
+  connection->method = strdup(line);
+  uri++;
+  while (uri[0] == ' ')
+    uri++;
+  httpVersion = strstr(uri, " ");
+  if (httpVersion != NULL) {
+    httpVersion[0] = '\0';
+    httpVersion++;
+  }
+  args = strstr(uri, "?");
+  if (args != NULL) {
+    args[0] = '\0';
+    args++;
+    parse_arguments(MHD_GET_ARGUMENT_KIND,
+                   connection,
+                   args);
+  }
+  connection->url = strdup(uri);
+  if (httpVersion == NULL)
+    connection->version = strdup("");
+  else
+    connection->version = strdup(httpVersion);
+  return MHD_YES;
+}
+
+
 /**
  * This function is designed to parse the input buffer of a given connection.
  *
@@ -352,9 +396,6 @@
   char * last;
   char * line;
   char * colon;
-  char * uri;
-  char * httpType;
-  char * args;
   char * tmp;
   const char * clen;
   unsigned long long cval;
@@ -401,30 +442,12 @@
       }
     }
     if (connection->url == NULL) {
-      /* line must be request line */
-      uri = strstr(line, " ");
-      if (uri == NULL)
+      /* line must be request line (first line of header) */
+      if (MHD_NO == parse_initial_message_line(connection,
+                                              line)) {
+       free(line);
        goto DIE;
-      uri[0] = '\0';
-      connection->method = strdup(line);
-      uri++;
-      httpType = strstr(uri, " ");
-      if (httpType != NULL) {
-       httpType[0] = '\0';
-       httpType++;
       }
-      args = strstr(uri, "?");
-      if (args != NULL) {
-       args[0] = '\0';
-       args++;
-       MHD_parse_arguments(connection,
-                           args);
-      }
-      connection->url = strdup(uri);
-      if (httpType == NULL)
-       connection->version = strdup("");
-      else
-       connection->version = strdup(httpType);
       free(line);
       continue;
     }
@@ -434,8 +457,8 @@
       /* end of header */
       connection->headersReceived = 1;
       clen = MHD_lookup_connection_value(connection,
-                                     MHD_HEADER_KIND,
-                                     "Content-Length");
+                                        MHD_HEADER_KIND,
+                                        "Content-Length");
       if (clen != NULL) {
        if (1 != sscanf(clen,
                        "%llu",





reply via email to

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