aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--html.c66
-rw-r--r--html.h2
2 files changed, 11 insertions, 57 deletions
diff --git a/html.c b/html.c
index d89df3a..e7e6e07 100644
--- a/html.c
+++ b/html.c
@@ -8,6 +8,7 @@
#include "cgit.h"
#include "html.h"
+#include "url.h"
/* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
static const char* url_escape_table[256] = {
@@ -337,64 +338,17 @@ int html_include(const char *filename)
return 0;
}
-static int hextoint(char c)
+void http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value))
{
- if (c >= 'a' && c <= 'f')
- return 10 + c - 'a';
- else if (c >= 'A' && c <= 'F')
- return 10 + c - 'A';
- else if (c >= '0' && c <= '9')
- return c - '0';
- else
- return -1;
-}
-
-static char *convert_query_hexchar(char *txt)
-{
- int d1, d2, n;
- n = strlen(txt);
- if (n < 3) {
- *txt = '\0';
- return txt-1;
- }
- d1 = hextoint(*(txt + 1));
- d2 = hextoint(*(txt + 2));
- if (d1 < 0 || d2 < 0) {
- memmove(txt, txt + 3, n - 2);
- return txt-1;
- } else {
- *txt = d1 * 16 + d2;
- memmove(txt + 1, txt + 3, n - 2);
- return txt;
- }
-}
+ const char *t = txt;
-int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value))
-{
- char *o, *t, *txt, *value = NULL, c;
-
- if (!txt_)
- return 0;
-
- o = t = txt = xstrdup(txt_);
- while ((c=*t) != '\0') {
- if (c == '=') {
- *t = '\0';
- value = t + 1;
- } else if (c == '+') {
- *t = ' ';
- } else if (c == '%') {
- t = convert_query_hexchar(t);
- } else if (c == '&') {
- *t = '\0';
- (*fn)(txt, value);
- txt = t + 1;
- value = NULL;
+ while (t && *t) {
+ char *name = url_decode_parameter_name(&t);
+ if (*name) {
+ char *value = url_decode_parameter_value(&t);
+ fn(name, value);
+ free(value);
}
- t++;
+ free(name);
}
- if (t != txt)
- (*fn)(txt, value);
- free(o);
- return 0;
}
diff --git a/html.h b/html.h
index c72e845..1b24e55 100644
--- a/html.h
+++ b/html.h
@@ -32,6 +32,6 @@ extern void html_link_close(void);
extern void html_fileperm(unsigned short mode);
extern int html_include(const char *filename);
-extern int http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value));
+extern void http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value));
#endif /* HTML_H */
href='#n223'>223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414