gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8175 - libmicrohttpd/src/daemon


From: gnunet
Subject: [GNUnet-SVN] r8175 - libmicrohttpd/src/daemon
Date: Mon, 2 Feb 2009 22:21:31 -0700 (MST)

Author: grothoff
Date: 2009-02-02 22:21:31 -0700 (Mon, 02 Feb 2009)
New Revision: 8175

Modified:
   libmicrohttpd/src/daemon/internal.c
   libmicrohttpd/src/daemon/internal.h
   libmicrohttpd/src/daemon/postprocessor.c
Log:
fixing 1447

Modified: libmicrohttpd/src/daemon/internal.c
===================================================================
--- libmicrohttpd/src/daemon/internal.c 2009-02-03 05:06:41 UTC (rev 8174)
+++ libmicrohttpd/src/daemon/internal.c 2009-02-03 05:21:31 UTC (rev 8175)
@@ -118,24 +118,42 @@
 /**
  * Process escape sequences ('+'=space, %HH)
  */
-void
+unsigned int
 MHD_http_unescape (char *val)
 {
-  char *esc;
+  char *rpos = val;
+  char *wpos = val;
   unsigned int num;
 
-  while (NULL != (esc = strstr (val, "+")))
-    *esc = ' ';
-  while (NULL != (esc = strstr (val, "%")))
+  while ('\0' != *rpos)
     {
-      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]) + 1);
-        }
-      val = esc + 1;
+      switch (*rpos)
+       {
+       case '+':
+         *wpos = ' ';
+         wpos++;
+         rpos++;
+         break;
+       case '%':
+         if ( (1 == SSCANF (&rpos[1],
+                            "%2x", &num)) ||
+              (1 == SSCANF (&rpos[1],
+                            "%2X", &num)) )
+           {
+             *wpos = (unsigned char) num;
+             wpos++;
+             rpos += 3;
+             break;
+           }
+         /* intentional fall through! */
+       default:
+         *wpos = *rpos;
+         wpos++;
+         rpos++;
+       }
     }
+  *wpos = '\0'; /* add 0-terminator */
+  return wpos - val; /* = strlen(val) */
 }
 
 /* end of internal.c */

Modified: libmicrohttpd/src/daemon/internal.h
===================================================================
--- libmicrohttpd/src/daemon/internal.h 2009-02-03 05:06:41 UTC (rev 8174)
+++ libmicrohttpd/src/daemon/internal.h 2009-02-03 05:21:31 UTC (rev 8175)
@@ -58,8 +58,11 @@
 /**
  * Process escape sequences ('+'=space, %HH).
  * Updates val in place.
+ *
+ * @return length of the resulting val (strlen(val) maybe
+ *  shorter afterwards due to elimination of escape sequences)
  */
-void MHD_http_unescape (char *val);
+unsigned int MHD_http_unescape (char *val);
 
 /**
  * Header or cookie in HTTP request or response.

Modified: libmicrohttpd/src/daemon/postprocessor.c
===================================================================
--- libmicrohttpd/src/daemon/postprocessor.c    2009-02-03 05:06:41 UTC (rev 
8174)
+++ libmicrohttpd/src/daemon/postprocessor.c    2009-02-03 05:21:31 UTC (rev 
8175)
@@ -1,6 +1,6 @@
 /*
      This file is part of libmicrohttpd
-     (C) 2007 Daniel Pittman and Christian Grothoff
+     (C) 2007, 2009 Daniel Pittman and Christian Grothoff
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -403,8 +403,7 @@
 
           /* unescape */
           xbuf[xoff] = '\0';    /* 0-terminate in preparation */
-          MHD_http_unescape (xbuf);
-
+          xoff = MHD_http_unescape (xbuf);
           /* finally: call application! */
           if (MHD_NO == pp->ikvi (pp->cls, MHD_POSTDATA_KIND, (const char *) 
&pp[1],    /* key */
                                   NULL, NULL, NULL, xbuf, pp->value_offset,





reply via email to

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