X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_params.c;h=828eb9371177edd80bb7e2a452cb7fb242e91351;hb=d97755079e04b0fca303641092603dd1aea0585f;hp=ad32f0e58155a3dd83bde7109a28435f73979970;hpb=da63feb69bdf005bdf4b6657513c782a863bde70;p=m6w6%2Fext-http diff --git a/php_http_params.c b/php_http_params.c index ad32f0e..828eb93 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, "()<>@,;:\"[]?={} ")) { @@ -397,7 +397,7 @@ static void merge_param(HashTable *params, zval *zdata, zval **current_param, zv } #endif - zend_hash_get_current_key_ex(Z_ARRVAL_P(zdata), &hkey.key, &hkey.h, NULL); + zend_hash_get_current_key(Z_ARRVAL_P(zdata), &hkey.key, &hkey.h); if ((hkey.key && !zend_hash_exists(params, hkey.key)) || (!hkey.key && !zend_hash_index_exists(params, hkey.h)) @@ -444,10 +444,13 @@ static void merge_param(HashTable *params, zval *zdata, zval **current_param, zv while (Z_TYPE_P(zdata_ptr) == IS_ARRAY && (test_ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata_ptr)))) { if (Z_TYPE_P(test_ptr) == IS_ARRAY) { /* now find key in ptr */ - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h, NULL)) { + if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h)) { + zval *tmp_ptr = ptr; + if ((ptr = zend_hash_find(Z_ARRVAL_P(ptr), hkey.key))) { zdata_ptr = test_ptr; } else { + ptr = tmp_ptr; Z_TRY_ADDREF_P(test_ptr); ptr = zend_hash_update(Z_ARRVAL_P(ptr), hkey.key, test_ptr); break; @@ -472,7 +475,7 @@ static void merge_param(HashTable *params, zval *zdata, zval **current_param, zv zval_dtor(ptr); array_init(ptr); } - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h, NULL)) { + if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h)) { ptr = zend_hash_update(Z_ARRVAL_P(ptr), hkey.key, test_ptr); } else if (hkey.h) { ptr = zend_hash_index_update(Z_ARRVAL_P(ptr), hkey.h, test_ptr); @@ -543,10 +546,11 @@ static void push_param(HashTable *params, php_http_params_state_t *state, const ZVAL_NULL(&key); sanitize_key(opts->flags, state->param.str, state->param.len, &key, &rfc5987); state->rfc5987 = rfc5987; - if (Z_TYPE(key) != IS_STRING) { + if (Z_TYPE(key) == IS_ARRAY) { merge_param(params, &key, &state->current.val, &state->current.args); - } else if (Z_STRLEN(key)) { - array_init_size(&prm, 2); + } else if (Z_TYPE(key) == IS_STRING && Z_STRLEN(key)) { + //array_init_size(&prm, 2); + array_init(&prm); if (!Z_ISUNDEF(opts->defval)) { ZVAL_COPY_VALUE(&val, &opts->defval); @@ -559,8 +563,8 @@ static void push_param(HashTable *params, php_http_params_state_t *state, const } else { state->current.val = zend_hash_str_update(Z_ARRVAL(prm), "value", lenof("value"), &val); } - - array_init_size(&arg, 3); + //array_init_size(&arg, 3); + array_init(&arg); state->current.args = zend_hash_str_update(Z_ARRVAL(prm), "arguments", lenof("arguments"), &arg); state->current.param = zend_symtable_str_update(params, Z_STRVAL(key), Z_STRLEN(key), &prm); } @@ -712,7 +716,7 @@ static inline void shift_rfc5987(php_http_buffer_t *buf, zval *zvalue, const cha php_http_arrkey_t key = {0}; if ((zdata = zend_hash_get_current_data(ht)) - && HASH_KEY_NON_EXISTENT != zend_hash_get_current_key_ex(ht, &key.key, &key.h, NULL) + && HASH_KEY_NON_EXISTENT != zend_hash_get_current_key(ht, &key.key, &key.h) ) { php_http_arrkey_stringify(&key, NULL); php_http_buffer_appendf(buf, "*%.*sutf-8'%.*s'", @@ -842,8 +846,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) { @@ -870,15 +875,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; @@ -894,7 +901,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; @@ -956,6 +964,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)), @@ -964,19 +974,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); @@ -1093,7 +1108,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); } } @@ -1111,29 +1125,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); @@ -1152,9 +1159,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[] = {