gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r7658 - in libmicrohttpd: . src/daemon
Date: Fri, 5 Sep 2008 01:07:58 -0600 (MDT)

Author: grothoff
Date: 2008-09-05 01:07:58 -0600 (Fri, 05 Sep 2008)
New Revision: 7658

Modified:
   libmicrohttpd/AUTHORS
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/daemon/Makefile.am
   libmicrohttpd/src/daemon/connection.c
Log:
improving chunked connection handling

Modified: libmicrohttpd/AUTHORS
===================================================================
--- libmicrohttpd/AUTHORS       2008-09-04 14:26:49 UTC (rev 7657)
+++ libmicrohttpd/AUTHORS       2008-09-05 07:07:58 UTC (rev 7658)
@@ -10,6 +10,7 @@
 Nils Durner <address@hidden>
 Heikki Lindholm <address@hidden>
 Alex Sadovsky <address@hidden>
+Greg Schohn <address@hidden>
 
 Documentation contributions also came from:
 Marco Maggi <address@hidden>

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2008-09-04 14:26:49 UTC (rev 7657)
+++ libmicrohttpd/ChangeLog     2008-09-05 07:07:58 UTC (rev 7658)
@@ -1,3 +1,9 @@
+Thu Sep  4 23:37:18 MDT 2008
+        Fixed some boundary issues with processing
+        chunked requests; removed memmove from a 
+        number of spots, in favor of using an index into 
+        the current buffer instead. -GS
+
 Sun Aug 24 13:05:41 MDT 2008
         Now handling clients returning 0 from response callback
         as specified in the documentation (abort if internal

Modified: libmicrohttpd/src/daemon/Makefile.am
===================================================================
--- libmicrohttpd/src/daemon/Makefile.am        2008-09-04 14:26:49 UTC (rev 
7657)
+++ libmicrohttpd/src/daemon/Makefile.am        2008-09-05 07:07:58 UTC (rev 
7658)
@@ -15,7 +15,7 @@
 -I$(GCRYPT_CPPFLAGS)
 
 if HAVE_GNU_LD
- retaincommand=-Wl,--retain-symbols-file -Wl,$(srcdir)/SYMBOLS
+#  retaincommand=-Wl,--retain-symbols-file -Wl,$(srcdir)/SYMBOLS
 endif
 
 EXTRA_DIST = SYMBOLS

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2008-09-04 14:26:49 UTC (rev 
7657)
+++ libmicrohttpd/src/daemon/connection.c       2008-09-05 07:07:58 UTC (rev 
7658)
@@ -1065,27 +1065,30 @@
   int instant_retry;
   unsigned int i;
   int malformed;
+  char * buffer_head;
 
   if (connection->response != NULL)
     return;                     /* already queued a response */
+
+  buffer_head = connection->read_buffer;
+  available = connection->read_buffer_offset;
   do
     {
       instant_retry = MHD_NO;
-      available = connection->read_buffer_offset;
       if ((connection->have_chunked_upload == MHD_YES) &&
           (connection->remaining_upload_size == -1))
         {
-          if ((connection->current_chunk_offset ==
-               connection->current_chunk_size)
-              && (connection->current_chunk_offset != 0) && (available >= 2))
+          if ((connection->current_chunk_offset == 
connection->current_chunk_size) && 
+             (connection->current_chunk_offset != 0) && 
+             (available >= 2))
             {
               /* skip new line at the *end* of a chunk */
               i = 0;
-              if ((connection->read_buffer[i] == '\r') ||
-                  (connection->read_buffer[i] == '\n'))
+              if ((buffer_head[i] == '\r') ||
+                  (buffer_head[i] == '\n'))
                 i++;            /* skip 1st part of line feed */
-              if ((connection->read_buffer[i] == '\r') ||
-                  (connection->read_buffer[i] == '\n'))
+              if ((buffer_head[i] == '\r') ||
+                  (buffer_head[i] == '\n'))
                 i++;            /* skip 2nd part of line feed */
               if (i == 0)
                 {
@@ -1097,10 +1100,8 @@
                   connection_close_error (connection);
                   return;
                 }
-              connection->read_buffer_offset -= i;
               available -= i;
-              memmove (connection->read_buffer,
-                       &connection->read_buffer[i], available);
+             buffer_head += i;
               connection->current_chunk_offset = 0;
               connection->current_chunk_size = 0;
             }
@@ -1115,8 +1116,7 @@
                 connection->current_chunk_offset;
               if (processed > available)
                 processed = available;
-              available -= processed;
-              if (available > 0)
+              if (available > processed)
                 instant_retry = MHD_YES;
             }
           else
@@ -1125,25 +1125,31 @@
               i = 0;
               while (i < available)
                 {
-                  if ((connection->read_buffer[i] == '\r') ||
-                      (connection->read_buffer[i] == '\n'))
+                  if ((buffer_head[i] == '\r') ||
+                      (buffer_head[i] == '\n'))
                     break;
                   i++;
                   if (i >= 6)
                     break;
                 }
-              if (i >= available)
-                return;         /* need more data... */
+             /* take '\n' into account; if '\n'
+                is the unavailable character, we
+                will need to wait until we have it 
+                before going further */
+              if ( (i+1 >= available) &&
+                  ! ( (i == 1) &&
+                      (available == 2) &&
+                      (buffer_head[0] == '0') ) )              
+                break;         /* need more data... */
               malformed = (i >= 6);
               if (!malformed)
                 {
-                  connection->read_buffer[i] = '\0';
-                  malformed = (1 != sscanf (connection->read_buffer,
-                                            "%X",
-                                            &connection->current_chunk_size))
-                    && (1 !=
-                        sscanf (connection->read_buffer, "%x",
-                                &connection->current_chunk_size));
+                  buffer_head[i] = '\0';
+                  malformed =
+                   (1 != sscanf (buffer_head, "%X",
+                                 &connection->current_chunk_size)) &&
+                   (1 != sscanf (buffer_head, "%x",
+                                 &connection->current_chunk_size));
                 }
               if (malformed)
                 {
@@ -1156,18 +1162,21 @@
                   return;
                 }
               i++;
-              if ((connection->read_buffer[i] == '\r') ||
-                  (connection->read_buffer[i] == '\n'))
+              if ((i<available) &&
+                 ( (buffer_head[i] == '\r') ||
+                   (buffer_head[i] == '\n')) )
                 i++;            /* skip 2nd part of line feed */
-              memmove (connection->read_buffer,
-                       &connection->read_buffer[i], available - i);
-              connection->read_buffer_offset -= i;
+
+             buffer_head += i;
+             available -= i;
               connection->current_chunk_offset = 0;
-              instant_retry = MHD_YES;
+
+              if (available > 0)
+               instant_retry = MHD_YES;
               if (connection->current_chunk_size == 0)
                 {
                   connection->remaining_upload_size = 0;
-                  return;
+                  break;
                 }
               continue;
             }
@@ -1176,7 +1185,6 @@
         {
           /* no chunked encoding, give all to the client */
           processed = available;
-          available = 0;
         }
       used = processed;
       if (MHD_NO ==
@@ -1185,7 +1193,7 @@
                                                connection, connection->url,
                                                connection->method,
                                                connection->version,
-                                               connection->read_buffer,
+                                               buffer_head,
                                                &processed,
                                                &connection->client_context))
         {
@@ -1203,16 +1211,19 @@
         instant_retry = MHD_NO; /* client did not process everything */
       used -= processed;
       if (connection->have_chunked_upload == MHD_YES)
-        connection->current_chunk_offset += used;
+       connection->current_chunk_offset += used;
       /* dh left "processed" bytes in buffer for next time... */
-      if (used > 0)
-        memmove (connection->read_buffer,
-                 &connection->read_buffer[used], processed + available);
+      buffer_head += used;
+      available -= used;
       if (connection->remaining_upload_size != -1)
         connection->remaining_upload_size -= used;
-      connection->read_buffer_offset = processed + available;
     }
   while (instant_retry == MHD_YES);
+  if (available > 0)
+    memmove(connection->read_buffer,
+           buffer_head,
+           available);
+  connection->read_buffer_offset = available;
 }
 
 /**





reply via email to

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