diff options
Diffstat (limited to 'plugins/picohttpparser')
| -rw-r--r-- | plugins/picohttpparser/picohttpparser.c | 67 | ||||
| -rw-r--r-- | plugins/picohttpparser/picohttpparser.h | 2 |
2 files changed, 46 insertions, 23 deletions
diff --git a/plugins/picohttpparser/picohttpparser.c b/plugins/picohttpparser/picohttpparser.c index 6a2d872d..74ccc3ef 100644 --- a/plugins/picohttpparser/picohttpparser.c +++ b/plugins/picohttpparser/picohttpparser.c | |||
| @@ -36,8 +36,6 @@ | |||
| 36 | #endif | 36 | #endif |
| 37 | #include "picohttpparser.h" | 37 | #include "picohttpparser.h" |
| 38 | 38 | ||
| 39 | /* $Id: a707070d11d499609f99d09f97535642cec910a8 $ */ | ||
| 40 | |||
| 41 | #if __GNUC__ >= 3 | 39 | #if __GNUC__ >= 3 |
| 42 | #define likely(x) __builtin_expect(!!(x), 1) | 40 | #define likely(x) __builtin_expect(!!(x), 1) |
| 43 | #define unlikely(x) __builtin_expect(!!(x), 0) | 41 | #define unlikely(x) __builtin_expect(!!(x), 0) |
| @@ -73,9 +71,9 @@ | |||
| 73 | #define ADVANCE_TOKEN(tok, toklen) \ | 71 | #define ADVANCE_TOKEN(tok, toklen) \ |
| 74 | do { \ | 72 | do { \ |
| 75 | const char *tok_start = buf; \ | 73 | const char *tok_start = buf; \ |
| 76 | static const char ALIGNED(16) ranges2[] = "\000\040\177\177"; \ | 74 | static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; \ |
| 77 | int found2; \ | 75 | int found2; \ |
| 78 | buf = findchar_fast(buf, buf_end, ranges2, sizeof(ranges2) - 1, &found2); \ | 76 | buf = findchar_fast(buf, buf_end, ranges2, 4, &found2); \ |
| 79 | if (!found2) { \ | 77 | if (!found2) { \ |
| 80 | CHECK_EOF(); \ | 78 | CHECK_EOF(); \ |
| 81 | } \ | 79 | } \ |
| @@ -138,15 +136,11 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const | |||
| 138 | const char *token_start = buf; | 136 | const char *token_start = buf; |
| 139 | 137 | ||
| 140 | #ifdef __SSE4_2__ | 138 | #ifdef __SSE4_2__ |
| 141 | static const char ranges1[] = "\0\010" | 139 | static const char ALIGNED(16) ranges1[16] = "\0\010" /* allow HT */ |
| 142 | /* allow HT */ | 140 | "\012\037" /* allow SP and up to but not including DEL */ |
| 143 | "\012\037" | 141 | "\177\177"; /* allow chars w. MSB set */ |
| 144 | /* allow SP and up to but not including DEL */ | ||
| 145 | "\177\177" | ||
| 146 | /* allow chars w. MSB set */ | ||
| 147 | ; | ||
| 148 | int found; | 142 | int found; |
| 149 | buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found); | 143 | buf = findchar_fast(buf, buf_end, ranges1, 6, &found); |
| 150 | if (found) | 144 | if (found) |
| 151 | goto FOUND_CTL; | 145 | goto FOUND_CTL; |
| 152 | #else | 146 | #else |
| @@ -325,9 +319,21 @@ static const char *parse_headers(const char *buf, const char *buf_end, struct ph | |||
| 325 | headers[*num_headers].name = NULL; | 319 | headers[*num_headers].name = NULL; |
| 326 | headers[*num_headers].name_len = 0; | 320 | headers[*num_headers].name_len = 0; |
| 327 | } | 321 | } |
| 328 | if ((buf = get_token_to_eol(buf, buf_end, &headers[*num_headers].value, &headers[*num_headers].value_len, ret)) == NULL) { | 322 | const char *value; |
| 323 | size_t value_len; | ||
| 324 | if ((buf = get_token_to_eol(buf, buf_end, &value, &value_len, ret)) == NULL) { | ||
| 329 | return NULL; | 325 | return NULL; |
| 330 | } | 326 | } |
| 327 | /* remove trailing SPs and HTABs */ | ||
| 328 | const char *value_end = value + value_len; | ||
| 329 | for (; value_end != value; --value_end) { | ||
| 330 | const char c = *(value_end - 1); | ||
| 331 | if (!(c == ' ' || c == '\t')) { | ||
| 332 | break; | ||
| 333 | } | ||
| 334 | } | ||
| 335 | headers[*num_headers].value = value; | ||
| 336 | headers[*num_headers].value_len = value_end - value; | ||
| 331 | } | 337 | } |
| 332 | return buf; | 338 | return buf; |
| 333 | } | 339 | } |
| @@ -347,9 +353,17 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha | |||
| 347 | 353 | ||
| 348 | /* parse request line */ | 354 | /* parse request line */ |
| 349 | ADVANCE_TOKEN(*method, *method_len); | 355 | ADVANCE_TOKEN(*method, *method_len); |
| 350 | ++buf; | 356 | do { |
| 357 | ++buf; | ||
| 358 | } while (*buf == ' '); | ||
| 351 | ADVANCE_TOKEN(*path, *path_len); | 359 | ADVANCE_TOKEN(*path, *path_len); |
| 352 | ++buf; | 360 | do { |
| 361 | ++buf; | ||
| 362 | } while (*buf == ' '); | ||
| 363 | if (*method_len == 0 || *path_len == 0) { | ||
| 364 | *ret = -1; | ||
| 365 | return NULL; | ||
| 366 | } | ||
| 353 | if ((buf = parse_http_version(buf, buf_end, minor_version, ret)) == NULL) { | 367 | if ((buf = parse_http_version(buf, buf_end, minor_version, ret)) == NULL) { |
| 354 | return NULL; | 368 | return NULL; |
| 355 | } | 369 | } |
| @@ -402,10 +416,13 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min | |||
| 402 | return NULL; | 416 | return NULL; |
| 403 | } | 417 | } |
| 404 | /* skip space */ | 418 | /* skip space */ |
| 405 | if (*buf++ != ' ') { | 419 | if (*buf != ' ') { |
| 406 | *ret = -1; | 420 | *ret = -1; |
| 407 | return NULL; | 421 | return NULL; |
| 408 | } | 422 | } |
| 423 | do { | ||
| 424 | ++buf; | ||
| 425 | } while (*buf == ' '); | ||
| 409 | /* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse */ | 426 | /* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse */ |
| 410 | if (buf_end - buf < 4) { | 427 | if (buf_end - buf < 4) { |
| 411 | *ret = -2; | 428 | *ret = -2; |
| @@ -413,13 +430,21 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min | |||
| 413 | } | 430 | } |
| 414 | PARSE_INT_3(status); | 431 | PARSE_INT_3(status); |
| 415 | 432 | ||
| 416 | /* skip space */ | 433 | /* get message includig preceding space */ |
| 417 | if (*buf++ != ' ') { | 434 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { |
| 418 | *ret = -1; | ||
| 419 | return NULL; | 435 | return NULL; |
| 420 | } | 436 | } |
| 421 | /* get message */ | 437 | if (*msg_len == 0) { |
| 422 | if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) { | 438 | /* ok */ |
| 439 | } else if (**msg == ' ') { | ||
| 440 | /* remove preceding space */ | ||
| 441 | do { | ||
| 442 | ++*msg; | ||
| 443 | --*msg_len; | ||
| 444 | } while (**msg == ' '); | ||
| 445 | } else { | ||
| 446 | /* garbage found after status code */ | ||
| 447 | *ret = -1; | ||
| 423 | return NULL; | 448 | return NULL; |
| 424 | } | 449 | } |
| 425 | 450 | ||
diff --git a/plugins/picohttpparser/picohttpparser.h b/plugins/picohttpparser/picohttpparser.h index a8fad71d..0849f844 100644 --- a/plugins/picohttpparser/picohttpparser.h +++ b/plugins/picohttpparser/picohttpparser.h | |||
| @@ -33,8 +33,6 @@ | |||
| 33 | #define ssize_t intptr_t | 33 | #define ssize_t intptr_t |
| 34 | #endif | 34 | #endif |
| 35 | 35 | ||
| 36 | /* $Id: 67fd3ee74103ada60258d8a16e868f483abcca87 $ */ | ||
| 37 | |||
| 38 | #ifdef __cplusplus | 36 | #ifdef __cplusplus |
| 39 | extern "C" { | 37 | extern "C" { |
| 40 | #endif | 38 | #endif |
