aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/internal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/internal.c')
-rw-r--r--src/microhttpd/internal.c290
1 files changed, 145 insertions, 145 deletions
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c
index ff861545..109ebfe2 100644
--- a/src/microhttpd/internal.c
+++ b/src/microhttpd/internal.c
@@ -36,50 +36,50 @@ const char *
36MHD_state_to_string (enum MHD_CONNECTION_STATE state) 36MHD_state_to_string (enum MHD_CONNECTION_STATE state)
37{ 37{
38 switch (state) 38 switch (state)
39 { 39 {
40 case MHD_CONNECTION_INIT: 40 case MHD_CONNECTION_INIT:
41 return "connection init"; 41 return "connection init";
42 case MHD_CONNECTION_URL_RECEIVED: 42 case MHD_CONNECTION_URL_RECEIVED:
43 return "connection url received"; 43 return "connection url received";
44 case MHD_CONNECTION_HEADER_PART_RECEIVED: 44 case MHD_CONNECTION_HEADER_PART_RECEIVED:
45 return "header partially received"; 45 return "header partially received";
46 case MHD_CONNECTION_HEADERS_RECEIVED: 46 case MHD_CONNECTION_HEADERS_RECEIVED:
47 return "headers received"; 47 return "headers received";
48 case MHD_CONNECTION_HEADERS_PROCESSED: 48 case MHD_CONNECTION_HEADERS_PROCESSED:
49 return "headers processed"; 49 return "headers processed";
50 case MHD_CONNECTION_CONTINUE_SENDING: 50 case MHD_CONNECTION_CONTINUE_SENDING:
51 return "continue sending"; 51 return "continue sending";
52 case MHD_CONNECTION_CONTINUE_SENT: 52 case MHD_CONNECTION_CONTINUE_SENT:
53 return "continue sent"; 53 return "continue sent";
54 case MHD_CONNECTION_BODY_RECEIVED: 54 case MHD_CONNECTION_BODY_RECEIVED:
55 return "body received"; 55 return "body received";
56 case MHD_CONNECTION_FOOTER_PART_RECEIVED: 56 case MHD_CONNECTION_FOOTER_PART_RECEIVED:
57 return "footer partially received"; 57 return "footer partially received";
58 case MHD_CONNECTION_FOOTERS_RECEIVED: 58 case MHD_CONNECTION_FOOTERS_RECEIVED:
59 return "footers received"; 59 return "footers received";
60 case MHD_CONNECTION_HEADERS_SENDING: 60 case MHD_CONNECTION_HEADERS_SENDING:
61 return "headers sending"; 61 return "headers sending";
62 case MHD_CONNECTION_HEADERS_SENT: 62 case MHD_CONNECTION_HEADERS_SENT:
63 return "headers sent"; 63 return "headers sent";
64 case MHD_CONNECTION_NORMAL_BODY_READY: 64 case MHD_CONNECTION_NORMAL_BODY_READY:
65 return "normal body ready"; 65 return "normal body ready";
66 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 66 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
67 return "normal body unready"; 67 return "normal body unready";
68 case MHD_CONNECTION_CHUNKED_BODY_READY: 68 case MHD_CONNECTION_CHUNKED_BODY_READY:
69 return "chunked body ready"; 69 return "chunked body ready";
70 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 70 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
71 return "chunked body unready"; 71 return "chunked body unready";
72 case MHD_CONNECTION_BODY_SENT: 72 case MHD_CONNECTION_BODY_SENT:
73 return "body sent"; 73 return "body sent";
74 case MHD_CONNECTION_FOOTERS_SENDING: 74 case MHD_CONNECTION_FOOTERS_SENDING:
75 return "footers sending"; 75 return "footers sending";
76 case MHD_CONNECTION_FOOTERS_SENT: 76 case MHD_CONNECTION_FOOTERS_SENT:
77 return "footers sent"; 77 return "footers sent";
78 case MHD_CONNECTION_CLOSED: 78 case MHD_CONNECTION_CLOSED:
79 return "closed"; 79 return "closed";
80 default: 80 default:
81 return "unrecognized connection state"; 81 return "unrecognized connection state";
82 } 82 }
83} 83}
84#endif 84#endif
85#endif 85#endif
@@ -118,7 +118,7 @@ MHD_unescape_plus (char *arg)
118{ 118{
119 char *p; 119 char *p;
120 120
121 for (p=strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+')) 121 for (p = strchr (arg, '+'); NULL != p; p = strchr (p + 1, '+'))
122 *p = ' '; 122 *p = ' ';
123} 123}
124 124
@@ -139,28 +139,28 @@ MHD_http_unescape (char *val)
139 char *wpos = val; 139 char *wpos = val;
140 140
141 while ('\0' != *rpos) 141 while ('\0' != *rpos)
142 {
143 uint32_t num;
144 switch (*rpos)
142 { 145 {
143 uint32_t num; 146 case '%':
144 switch (*rpos) 147 if (2 == MHD_strx_to_uint32_n_ (rpos + 1,
145 { 148 2,
146 case '%': 149 &num))
147 if (2 == MHD_strx_to_uint32_n_ (rpos + 1, 150 {
148 2, 151 *wpos = (char) ((unsigned char) num);
149 &num)) 152 wpos++;
150 { 153 rpos += 3;
151 *wpos = (char)((unsigned char) num); 154 break;
152 wpos++; 155 }
153 rpos += 3; 156 /* TODO: add bad sequence handling */
154 break; 157 /* intentional fall through! */
155 } 158 default:
156 /* TODO: add bad sequence handling */ 159 *wpos = *rpos;
157 /* intentional fall through! */ 160 wpos++;
158 default: 161 rpos++;
159 *wpos = *rpos;
160 wpos++;
161 rpos++;
162 }
163 } 162 }
163 }
164 *wpos = '\0'; /* add 0-terminator */ 164 *wpos = '\0'; /* add 0-terminator */
165 return wpos - val; 165 return wpos - val;
166} 166}
@@ -182,10 +182,10 @@ MHD_http_unescape (char *val)
182 */ 182 */
183int 183int
184MHD_parse_arguments_ (struct MHD_Connection *connection, 184MHD_parse_arguments_ (struct MHD_Connection *connection,
185 enum MHD_ValueKind kind, 185 enum MHD_ValueKind kind,
186 char *args, 186 char *args,
187 MHD_ArgumentIterator_ cb, 187 MHD_ArgumentIterator_ cb,
188 unsigned int *num_headers) 188 unsigned int *num_headers)
189{ 189{
190 struct MHD_Daemon *daemon = connection->daemon; 190 struct MHD_Daemon *daemon = connection->daemon;
191 char *equals; 191 char *equals;
@@ -193,78 +193,33 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
193 193
194 *num_headers = 0; 194 *num_headers = 0;
195 while ( (NULL != args) && 195 while ( (NULL != args) &&
196 ('\0' != args[0]) ) 196 ('\0' != args[0]) )
197 {
198 size_t key_len;
199 size_t value_len;
200 equals = strchr (args, '=');
201 amper = strchr (args, '&');
202 if (NULL == amper)
197 { 203 {
198 size_t key_len; 204 /* last argument */
199 size_t value_len; 205 if (NULL == equals)
200 equals = strchr (args, '='); 206 {
201 amper = strchr (args, '&'); 207 /* last argument, without '=' */
202 if (NULL == amper) 208 MHD_unescape_plus (args);
203 { 209 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
204 /* last argument */ 210 connection,
205 if (NULL == equals) 211 args);
206 { 212 if (MHD_YES != cb (connection,
207 /* last argument, without '=' */ 213 args,
208 MHD_unescape_plus (args); 214 key_len,
209 key_len = daemon->unescape_callback (daemon->unescape_callback_cls, 215 NULL,
210 connection, 216 0,
211 args); 217 kind))
212 if (MHD_YES != cb (connection, 218 return MHD_NO;
213 args, 219 (*num_headers)++;
214 key_len, 220 break;
215 NULL, 221 }
216 0, 222 /* got 'foo=bar' */
217 kind))
218 return MHD_NO;
219 (*num_headers)++;
220 break;
221 }
222 /* got 'foo=bar' */
223 equals[0] = '\0';
224 equals++;
225 MHD_unescape_plus (args);
226 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
227 connection,
228 args);
229 MHD_unescape_plus (equals);
230 value_len = daemon->unescape_callback (daemon->unescape_callback_cls,
231 connection,
232 equals);
233 if (MHD_YES != cb (connection,
234 args,
235 key_len,
236 equals,
237 value_len,
238 kind))
239 return MHD_NO;
240 (*num_headers)++;
241 break;
242 }
243 /* amper is non-NULL here */
244 amper[0] = '\0';
245 amper++;
246 if ( (NULL == equals) ||
247 (equals >= amper) )
248 {
249 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
250 MHD_unescape_plus (args);
251 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
252 connection,
253 args);
254 if (MHD_YES != cb (connection,
255 args,
256 key_len,
257 NULL,
258 0,
259 kind))
260 return MHD_NO;
261 /* continue with 'bar' */
262 (*num_headers)++;
263 args = amper;
264 continue;
265 }
266 /* equals and amper are non-NULL here, and equals < amper,
267 so we got regular 'foo=value&bar...'-kind of argument */
268 equals[0] = '\0'; 223 equals[0] = '\0';
269 equals++; 224 equals++;
270 MHD_unescape_plus (args); 225 MHD_unescape_plus (args);
@@ -276,15 +231,60 @@ MHD_parse_arguments_ (struct MHD_Connection *connection,
276 connection, 231 connection,
277 equals); 232 equals);
278 if (MHD_YES != cb (connection, 233 if (MHD_YES != cb (connection,
279 args, 234 args,
280 key_len, 235 key_len,
281 equals, 236 equals,
282 value_len, 237 value_len,
283 kind)) 238 kind))
284 return MHD_NO; 239 return MHD_NO;
285 (*num_headers)++; 240 (*num_headers)++;
241 break;
242 }
243 /* amper is non-NULL here */
244 amper[0] = '\0';
245 amper++;
246 if ( (NULL == equals) ||
247 (equals >= amper) )
248 {
249 /* got 'foo&bar' or 'foo&bar=val', add key 'foo' with NULL for value */
250 MHD_unescape_plus (args);
251 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
252 connection,
253 args);
254 if (MHD_YES != cb (connection,
255 args,
256 key_len,
257 NULL,
258 0,
259 kind))
260 return MHD_NO;
261 /* continue with 'bar' */
262 (*num_headers)++;
286 args = amper; 263 args = amper;
264 continue;
287 } 265 }
266 /* equals and amper are non-NULL here, and equals < amper,
267 so we got regular 'foo=value&bar...'-kind of argument */
268 equals[0] = '\0';
269 equals++;
270 MHD_unescape_plus (args);
271 key_len = daemon->unescape_callback (daemon->unescape_callback_cls,
272 connection,
273 args);
274 MHD_unescape_plus (equals);
275 value_len = daemon->unescape_callback (daemon->unescape_callback_cls,
276 connection,
277 equals);
278 if (MHD_YES != cb (connection,
279 args,
280 key_len,
281 equals,
282 value_len,
283 kind))
284 return MHD_NO;
285 (*num_headers)++;
286 args = amper;
287 }
288 return MHD_YES; 288 return MHD_YES;
289} 289}
290 290