X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_header_parser.c;h=e14b44333b1efe44b23b6f05fe2ba65f14bd3d11;hb=d01985309a42186e0c3ac1e8dd6e2d4a094d30c9;hp=df0837df2727430de080869760daa65f4f7b8969;hpb=b54d9ed0b0cd930f76754fe281e66f36a953085b;p=m6w6%2Fext-http diff --git a/php_http_header_parser.c b/php_http_header_parser.c index df0837d..e14b443 100644 --- a/php_http_header_parser.c +++ b/php_http_header_parser.c @@ -26,15 +26,13 @@ static const php_http_header_parser_state_spec_t php_http_header_parser_states[] {PHP_HTTP_HEADER_PARSER_STATE_DONE, 0} }; -php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_DC) +php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser) { if (!parser) { parser = emalloc(sizeof(*parser)); } memset(parser, 0, sizeof(*parser)); - TSRMLS_SET_CTX(parser->ts); - return parser; } @@ -92,14 +90,15 @@ void php_http_header_parser_free(php_http_header_parser_t **parser) } } -STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg) +php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg) { - TSRMLS_FETCH_FROM_CTX(parser->ts); - while (buffer->used || !php_http_header_parser_states[php_http_header_parser_state_is(parser)].need_data) { #if 0 - const char *state[] = {"START", "KEY", "VALUE", "HEADER_DONE", "DONE"}; - fprintf(stderr, "#HP: %s (avail:%zu, num:%d)\n", php_http_header_parser_state_is(parser) < 0 ? "FAILURE" : state[php_http_header_parser_state_is(parser)], buffer->used, headers?zend_hash_num_elements(headers):0); + const char *state[] = {"START", "KEY", "VALUE", "VALUE_EX", "HEADER_DONE", "DONE"}; + int num_headers = headers ? zend_hash_num_elements(headers) : 0; + fprintf(stderr, "#HP: (%d) %s (avail:%zu, num:%d)\n", php_http_header_parser_state_is(parser), + php_http_header_parser_state_is(parser) < 0 ? "FAILURE" : state[php_http_header_parser_state_is(parser)], + buffer->used, num_headers); _dpf(0, buffer->data, buffer->used); #endif switch (php_http_header_parser_state_pop(parser)) { @@ -126,10 +125,10 @@ STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_b /* end of headers */ php_http_buffer_cut(buffer, 0, eol_len); php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_DONE); - } else if (php_http_info_parse(&parser->info, php_http_buffer_fix(buffer)->data TSRMLS_CC)) { + } else if (php_http_info_parse(&parser->info, php_http_buffer_fix(buffer)->data)) { /* new message starting with request/response line */ if (callback_func) { - callback_func(callback_arg, &headers, &parser->info TSRMLS_CC); + callback_func(callback_arg, &headers, &parser->info); } php_http_info_dtor(&parser->info); php_http_buffer_cut(buffer, 0, eol_str + eol_len - buffer->data); @@ -214,19 +213,19 @@ STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_b case PHP_HTTP_HEADER_PARSER_STATE_HEADER_DONE: if (parser->_key.str && parser->_val.str) { - zval array, **exist; + zval tmp, *exist; if (!headers && callback_func) { - callback_func(callback_arg, &headers, NULL TSRMLS_CC); + callback_func(callback_arg, &headers, NULL); } - INIT_PZVAL_ARRAY(&array, headers); php_http_pretty_key(parser->_key.str, parser->_key.len, 1, 1); - if (SUCCESS == zend_symtable_find(headers, parser->_key.str, parser->_key.len + 1, (void *) &exist)) { - convert_to_array(*exist); - add_next_index_stringl(*exist, parser->_val.str, parser->_val.len, 0); + if ((exist = zend_symtable_str_find(headers, parser->_key.str, parser->_key.len))) { + convert_to_array(exist); + add_next_index_str(exist, php_http_cs2zs(parser->_val.str, parser->_val.len)); } else { - add_assoc_stringl_ex(&array, parser->_key.str, parser->_key.len + 1, parser->_val.str, parser->_val.len, 0); + ZVAL_STR(&tmp, php_http_cs2zs(parser->_val.str, parser->_val.len)); + zend_symtable_str_update(headers, parser->_key.str, parser->_key.len, &tmp); } parser->_val.str = NULL; }