From 16ecea28f2bbcf20d69dedc6611a959923720656 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sun, 18 Jan 2015 17:48:09 +0100 Subject: [PATCH] fixup php_http_params --- php_http_client_request.c | 2 +- php_http_client_response.c | 1 - php_http_env_response.c | 2 +- php_http_message_parser.c | 6 +++-- php_http_params.c | 52 +++++++++++++++++++------------------- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/php_http_client_request.c b/php_http_client_request.c index f665b20..68f627e 100644 --- a/php_http_client_request.c +++ b/php_http_client_request.c @@ -98,7 +98,7 @@ static PHP_METHOD(HttpClientRequest, getContentType) php_http_message_update_headers(obj->message); zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type")); if (zct) { - RETURN_ZVAL(zct, 0, 1); + RETURN_ZVAL_FAST(zct); } } } diff --git a/php_http_client_response.c b/php_http_client_response.c index 1fcdca5..b8efb8b 100644 --- a/php_http_client_response.c +++ b/php_http_client_response.c @@ -74,7 +74,6 @@ static PHP_METHOD(HttpClientResponse, getCookies) } zend_string_release(zs); } - zval_ptr_dtor(header); } if (allowed_extras) { diff --git a/php_http_env_response.c b/php_http_env_response.c index 34bc753..c8a31e0 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -119,6 +119,7 @@ static void set_cookie(zval *options, zval *zcookie_new TSRMLS_DC) } array_init_size(zcookies_set, zend_hash_num_elements(&obj->list->cookies)); } else { + Z_ADDREF_P(zcookies_set); SEPARATE_ZVAL(zcookies_set); } @@ -465,7 +466,6 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t zval *tmp = zoption; SEPARATE_ZVAL(tmp); convert_to_array(tmp); - zval_ptr_dtor(zoption); zoption = tmp; } diff --git a/php_http_message_parser.c b/php_http_message_parser.c index fb5b26f..2438fc1 100644 --- a/php_http_message_parser.c +++ b/php_http_message_parser.c @@ -250,13 +250,16 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p zval h, *h_loc = NULL, *h_con = NULL, *h_cl, *h_cr, *h_te, *h_ce; if ((h_te = php_http_message_header(*message, ZEND_STRL("Transfer-Encoding")))) { + Z_TRY_ADDREF_P(h_te); zend_hash_str_update(&(*message)->hdrs, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), h_te); zend_hash_str_del(&(*message)->hdrs, "Transfer-Encoding", lenof("Transfer-Encoding")); } if ((h_cl = php_http_message_header(*message, ZEND_STRL("Content-Length")))) { + Z_TRY_ADDREF_P(h_cl); zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Length", lenof("X-Original-Content-Length"), h_cl); } if ((h_cr = php_http_message_header(*message, ZEND_STRL("Content-Range")))) { + Z_TRY_ADDREF_P(h_cr); zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Range", sizeof("X-Original-Content-Range"), h_cr); zend_hash_str_del(&(*message)->hdrs, "Content-Range", lenof("Content-Range")); } @@ -298,10 +301,9 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p } else { parser->inflate = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), 0); } + Z_TRY_ADDREF_P(h_ce); zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), h_ce); zend_hash_str_del(&(*message)->hdrs, "Content-Encoding", lenof("Content-Encoding")); - } else { - zval_ptr_dtor(h_ce); } } diff --git a/php_http_params.c b/php_http_params.c index 2f73cb9..1be8e55 100644 --- a/php_http_params.c +++ b/php_http_params.c @@ -67,7 +67,7 @@ static inline void prepare_escaped(zval *zv) { if (Z_TYPE_P(zv) == IS_STRING) { size_t len = Z_STRLEN_P(zv); - zend_string *stripped = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), 1, + zend_string *stripped = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), 0, ZEND_STRL("\0..\37\173\\\"")); if (len != stripped->len || strpbrk(stripped->val, "()<>@,;:\"[]?={} ")) { @@ -843,8 +843,9 @@ php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable * zvalue = tmp; } else if (zvalue == zparam) { continue; + } else { + zvalue = zparam; } - zvalue = zparam; } if (Z_TYPE_P(zvalue) == IS_ARRAY) { @@ -871,15 +872,17 @@ php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable * php_http_params_token_t **php_http_params_separator_init(zval *zv) { - zval *sep; + zval *sep, ztmp; php_http_params_token_t **ret, **tmp; if (!zv) { return NULL; } - SEPARATE_ZVAL(zv); + ZVAL_DUP(&ztmp, zv); + zv = &ztmp; convert_to_array(zv); + ret = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(zv)) + 1, sizeof(*ret)); tmp = ret; @@ -895,7 +898,8 @@ php_http_params_token_t **php_http_params_separator_init(zval *zv) zend_string_release(zs); } ZEND_HASH_FOREACH_END(); - zval_ptr_dtor(zv); + + zval_ptr_dtor(&ztmp); *tmp = NULL; return ret; @@ -957,6 +961,8 @@ PHP_METHOD(HttpParams, __construct) default: zs = zval_get_string(zparams); if (zs->len) { + zval tmp; + php_http_params_opts_t opts = { {zs->val, zs->len}, php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0)), @@ -965,19 +971,24 @@ PHP_METHOD(HttpParams, __construct) {{0}}, flags }; - array_init(zparams); - php_http_params_parse(Z_ARRVAL_P(zparams), &opts); - zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams); + array_init(&tmp); + php_http_params_parse(Z_ARRVAL(tmp), &opts); + zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp); + zval_ptr_dtor(&tmp); php_http_params_separator_free(opts.param); php_http_params_separator_free(opts.arg); php_http_params_separator_free(opts.val); } + zend_string_release(zs); break; } } else { - array_init(zparams); - zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams); + zval tmp; + + array_init(&tmp); + zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp); + zval_ptr_dtor(&tmp); } } zend_restore_error_handling(&zeh); @@ -1094,7 +1105,6 @@ PHP_METHOD(HttpParams, offsetUnset) if (Z_TYPE_P(zparams) == IS_ARRAY) { zend_symtable_del(Z_ARRVAL_P(zparams), name); - zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams); } } @@ -1112,29 +1122,22 @@ PHP_METHOD(HttpParams, offsetSet) } zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0); - SEPARATE_ZVAL(zparams); convert_to_array(zparams); if (name->len) { if (Z_TYPE_P(nvalue) == IS_ARRAY) { - zval *new_zparam; - if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) { - new_zparam = zparam; - SEPARATE_ZVAL(new_zparam); - convert_to_array(new_zparam); - array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(new_zparam), 0, 0); + convert_to_array(zparam); + array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(zparam), 0, 0); } else { - new_zparam = nvalue; - Z_TRY_ADDREF_P(new_zparam); + Z_TRY_ADDREF_P(nvalue); + add_assoc_zval_ex(zparams, name->val, name->len, nvalue); } - add_assoc_zval_ex(zparams, name->val, name->len, new_zparam); } else { zval tmp; if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) { - tmp = *zparam; - SEPARATE_ZVAL(&tmp); + ZVAL_DUP(&tmp, zparam); convert_to_array(&tmp); } else { array_init(&tmp); @@ -1153,9 +1156,6 @@ PHP_METHOD(HttpParams, offsetSet) add_assoc_zval_ex(zparams, zs->val, zs->len, &arr); zend_string_release(zs); } - - zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams); - zval_ptr_dtor(zparams); } static zend_function_entry php_http_params_methods[] = { -- 2.30.2