X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_message_parser.c;h=fae3df3f46fc9021e5549bfd5ebfa8890984e2dd;hb=287edcbfb698ff402588f7057dae0bc994d6e8e4;hp=ca2027b5724eccff9ebac7318f56de787ba1fd5f;hpb=9de008496a220c769a745cd1eead0a3b3d7d6cca;p=m6w6%2Fext-http diff --git a/php_http_message_parser.c b/php_http_message_parser.c index ca2027b..fae3df3 100644 --- a/php_http_message_parser.c +++ b/php_http_message_parser.c @@ -46,11 +46,11 @@ PHP_HTTP_API php_http_message_parser_t *php_http_message_parser_init(php_http_me PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_push(php_http_message_parser_t *parser, unsigned argc, ...) { + php_http_message_parser_state_t state; va_list va_args; unsigned i; - va_start(va_args, argc); - php_http_message_parser_state_t state; + va_start(va_args, argc); for (i = 0; i < argc; ++i) { state = va_arg(va_args, php_http_message_parser_state_t); zend_stack_push(&parser->stack, &state, sizeof(state)); @@ -140,10 +140,11 @@ PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse_strea len -= read; } else { + php_http_buffer_resize(&buf, 24); php_stream_get_line(s, buf.data, buf.free, &len); php_http_buffer_account(&buf, len); - len = strtoul(buf.data - len, NULL, 16); + len = strtoul(buf.data + buf.used - len, NULL, 16); } break; @@ -169,10 +170,10 @@ PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse_strea PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, php_http_message_t **message) { - TSRMLS_FETCH_FROM_CTX(parser->ts); char *str = NULL; size_t len = 0; size_t cut = 0; + TSRMLS_FETCH_FROM_CTX(parser->ts); while (buffer->used || !php_http_message_parser_states[php_http_message_parser_state_is(parser)].need_data) { #if 0 @@ -298,10 +299,16 @@ PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_h if (h_cl) { char *stop; - parser->body_length = strtoul(Z_STRVAL_PP(h_cl), &stop, 10); + if (Z_TYPE_PP(h_cl) == IS_STRING) { + parser->body_length = strtoul(Z_STRVAL_PP(h_cl), &stop, 10); - if (stop != Z_STRVAL_PP(h_cl)) { - php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH); + if (stop != Z_STRVAL_PP(h_cl)) { + php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH); + break; + } + } else if (Z_TYPE_PP(h_cl) == IS_LONG) { + parser->body_length = Z_LVAL_PP(h_cl); + php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH); break; } } @@ -327,7 +334,7 @@ PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_h if (end >= start && (!total || end < total)) { parser->body_length = end + 1 - start; - php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH); + php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH); break; } }