diff options
Diffstat (limited to 'src/daemon/internal.c')
-rw-r--r-- | src/daemon/internal.c | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/daemon/internal.c b/src/daemon/internal.c index b4cabe68..fba19551 100644 --- a/src/daemon/internal.c +++ b/src/daemon/internal.c | |||
@@ -118,24 +118,42 @@ MHD_tls_log_func (int level, const char *str) | |||
118 | /** | 118 | /** |
119 | * Process escape sequences ('+'=space, %HH) | 119 | * Process escape sequences ('+'=space, %HH) |
120 | */ | 120 | */ |
121 | void | 121 | unsigned int |
122 | MHD_http_unescape (char *val) | 122 | MHD_http_unescape (char *val) |
123 | { | 123 | { |
124 | char *esc; | 124 | char *rpos = val; |
125 | char *wpos = val; | ||
125 | unsigned int num; | 126 | unsigned int num; |
126 | 127 | ||
127 | while (NULL != (esc = strstr (val, "+"))) | 128 | while ('\0' != *rpos) |
128 | *esc = ' '; | ||
129 | while (NULL != (esc = strstr (val, "%"))) | ||
130 | { | 129 | { |
131 | if ((1 == SSCANF (&esc[1], | 130 | switch (*rpos) |
132 | "%2x", &num)) || (1 == SSCANF (&esc[1], "%2X", &num))) | 131 | { |
133 | { | 132 | case '+': |
134 | esc[0] = (unsigned char) num; | 133 | *wpos = ' '; |
135 | memmove (&esc[1], &esc[3], strlen (&esc[3]) + 1); | 134 | wpos++; |
136 | } | 135 | rpos++; |
137 | val = esc + 1; | 136 | break; |
137 | case '%': | ||
138 | if ( (1 == SSCANF (&rpos[1], | ||
139 | "%2x", &num)) || | ||
140 | (1 == SSCANF (&rpos[1], | ||
141 | "%2X", &num)) ) | ||
142 | { | ||
143 | *wpos = (unsigned char) num; | ||
144 | wpos++; | ||
145 | rpos += 3; | ||
146 | break; | ||
147 | } | ||
148 | /* intentional fall through! */ | ||
149 | default: | ||
150 | *wpos = *rpos; | ||
151 | wpos++; | ||
152 | rpos++; | ||
153 | } | ||
138 | } | 154 | } |
155 | *wpos = '\0'; /* add 0-terminator */ | ||
156 | return wpos - val; /* = strlen(val) */ | ||
139 | } | 157 | } |
140 | 158 | ||
141 | /* end of internal.c */ | 159 | /* end of internal.c */ |