X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_header_parser.c;h=0dbaf848f9e72f02d59f55f27e87ef7c4ba79eee;hp=d0b6c52e4d7aee512262976522c7bd70ae63d7be;hb=d926a12aeec96752456eddfbf9a04a002809a0d2;hpb=8d05291f42b3b42159b3fe91492aa4862f3d4405 diff --git a/php_http_header_parser.c b/php_http_header_parser.c index d0b6c52..0dbaf84 100644 --- a/php_http_header_parser.c +++ b/php_http_header_parser.c @@ -10,7 +10,7 @@ +--------------------------------------------------------------------+ */ -#include "php_http.h" +#include "php_http_api.h" typedef struct php_http_header_parser_state_spec { php_http_header_parser_state_t state; @@ -120,8 +120,8 @@ PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parse } case PHP_HTTP_HEADER_PARSER_STATE_KEY: { - const char *colon, *eol_str; - int eol_len; + const char *colon, *eol_str = NULL; + int eol_len = 0; if (buffer->data == (eol_str = php_http_locate_bin_eol(buffer->data, buffer->used, &eol_len))) { /* end of headers */ @@ -152,14 +152,18 @@ PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parse const char *eol_str; int eol_len; - do { + line_split: { + if ((eol_str = php_http_locate_bin_eol(buffer->data, buffer->used, &eol_len))) { if (eol_str + eol_len - buffer->data < buffer->used) { - char nextline = *(eol_str + eol_len); - - if (nextline == '\t' || nextline == ' ') { - php_http_buffer_cut(buffer, eol_str - buffer->data, eol_len); - continue; + char *nextline = eol_str + eol_len; + + if (*nextline == '\t' || *nextline == ' ') { + while (nextline < buffer->data + buffer->used && (*nextline == '\t' || *nextline == ' ')) { + ++nextline; + } + php_http_buffer_cut(buffer, eol_str - buffer->data, nextline - eol_str); + goto line_split; } } @@ -175,7 +179,7 @@ PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parse } else { return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_VALUE); } - } while (0); + } break; }