commit 7c400e9e89cb344aac2ffa3a2b52e97b37f091ba
parent 6dbe4da5ed780b52914315945c6c73fa694d9d48
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 3 Feb 2009 05:21:31 +0000
fixing 1447
Diffstat:
3 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/src/daemon/internal.c b/src/daemon/internal.c
@@ -118,24 +118,42 @@ MHD_tls_log_func (int level, const char *str)
/**
* 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 */
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
@@ -58,8 +58,11 @@ void MHD_tls_log_func (int level, const char *str);
/**
* 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.
diff --git a/src/daemon/postprocessor.c b/src/daemon/postprocessor.c
@@ -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 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
/* 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,