#include <ext/spl/spl_array.h>
#ifdef PHP_HTTP_HAVE_ICONV
+# ifndef HAVE_ICONV
+# define HAVE_ICONV 1
+# endif
# undef PHP_ATOM_INC
# include <ext/iconv/php_iconv.h>
#endif
array_init(&qa);
if (flags & QS_MERGE) {
- zval *old = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0);
+ zval old_tmp, *old = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0, &old_tmp);
ZVAL_DEREF(old);
if (Z_TYPE_P(old) == IS_ARRAY) {
php_http_querystring_update(&qa, params, NULL);
zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), &qa);
+ zval_ptr_dtor(&qa);
}
static inline void php_http_querystring_str(zval *instance, zval *return_value)
{
- zval *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0);
+ zval qa_tmp, *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0, &qa_tmp);
ZVAL_DEREF(qa);
if (Z_TYPE_P(qa) == IS_ARRAY) {
}
}
-static inline void php_http_querystring_get(zval *instance, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC)
+static inline void php_http_querystring_get(zval *instance, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value)
{
- zval *arrval, *qarray = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ zval *arrval, qarray_tmp, *qarray = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0, &qarray_tmp);
ZVAL_DEREF(qarray);
if ((Z_TYPE_P(qarray) == IS_ARRAY) && (arrval = zend_symtable_str_find(Z_ARRVAL_P(qarray), name, name_len))) {
if (type && type != Z_TYPE_P(arrval)) {
- SEPARATE_ZVAL(arrval);
- convert_to_explicit_type(arrval, type);
- RETVAL_ZVAL(arrval, 1, 1);
+ zval tmp;
+
+ ZVAL_DUP(&tmp, arrval);
+ convert_to_explicit_type(&tmp, type);
+ RETVAL_ZVAL(&tmp, 0, 0);
} else {
- RETVAL_ZVAL_FAST(arrval);
+ RETVAL_ZVAL(arrval, 1, 0);
}
if (del) {
zval_ptr_dtor(&delarr);
}
} else if(defval) {
- RETURN_ZVAL_FAST(defval);
+ RETURN_ZVAL(defval, 1, 0);
}
}
opts.val = vsepp;
opts.flags = PHP_HTTP_PARAMS_QUERY;
- if (SUCCESS == php_http_ini_entry(ZEND_STRL("arg_separator.input"), &asi_str, &asi_len, 0 TSRMLS_CC) && asi_len) {
+ if (SUCCESS == php_http_ini_entry(ZEND_STRL("arg_separator.input"), &asi_str, &asi_len, 0) && asi_len) {
zval arr;
array_init_size(&arr, asi_len);
} while (*asi_str);
opts.param = php_http_params_separator_init(&arr);
-
zval_ptr_dtor(&arr);
}
/* squeeze the hash out of the zval */
if (Z_TYPE_P(params) == IS_OBJECT && instanceof_function(Z_OBJCE_P(params), php_http_querystring_class_entry)) {
- zval *qa = zend_read_property(php_http_querystring_class_entry, params, ZEND_STRL("queryArray"), 0);
+ zval qa_tmp, *qa = zend_read_property(php_http_querystring_class_entry, params, ZEND_STRL("queryArray"), 0, &qa_tmp);
ZVAL_DEREF(qa);
convert_to_array(qa);
ht = Z_ARRVAL(zv);
}
- ZEND_HASH_FOREACH_KEY_VAL(ht, key.h, key.key, params_entry)
+ ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key.h, key.key, params_entry)
{
/* only public properties */
if (!key.key || *key.key->val) {
/*
* update
*/
- zval equal, *entry = NULL;
+ zval equal, tmp, *entry = &tmp;
+ ZVAL_UNDEF(&tmp);
/* recursive */
if (Z_TYPE_P(params_entry) == IS_ARRAY || Z_TYPE_P(params_entry) == IS_OBJECT) {
- entry = qarray_entry;
- SEPARATE_ZVAL(entry);
+ ZVAL_DUP(entry, qarray_entry);
convert_to_array(entry);
php_http_querystring_update(entry, params_entry, NULL);
} else if ((FAILURE == is_equal_function(&equal, qarray_entry, params_entry)) || Z_TYPE(equal) != IS_TRUE) {
zval *params = NULL;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶ms), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z", ¶ms), invalid_arg, return);
zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh);
php_http_querystring_set(getThis(), params, 0);
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, getGlobalInstance)
{
- zval *instance;
+ zval *instance, *_GET;
zend_string *zs;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
instance = zend_std_get_static_property(php_http_querystring_class_entry, zs, 0);
zend_string_release(zs);
- if (Z_TYPE_P(instance) != IS_OBJECT) {
- zval *_GET = NULL;
-
- if ((_GET = php_http_env_get_superglobal(ZEND_STRL("_GET")))) {
- zval new_instance;
+ if (Z_TYPE_P(instance) == IS_OBJECT) {
+ RETVAL_ZVAL(instance, 1, 0);
+ } else if ((_GET = php_http_env_get_superglobal(ZEND_STRL("_GET")))) {
+ ZVAL_OBJ(return_value, php_http_querystring_object_new(php_http_querystring_class_entry));
- ZVAL_OBJ(&new_instance, php_http_querystring_object_new(php_http_querystring_class_entry));
+ ZVAL_MAKE_REF(_GET);
+ zend_update_property(php_http_querystring_class_entry, return_value, ZEND_STRL("queryArray"), _GET);
- ZVAL_MAKE_REF(_GET);
- zend_update_property(php_http_querystring_class_entry, &new_instance, ZEND_STRL("queryArray"), _GET);
-
- zend_update_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), instance);
- instance = &new_instance;
- } else {
- php_http_throw(unexpected_val, "Could not acquire reference to superglobal GET array", NULL);
- }
+ zend_update_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), return_value);
+ } else {
+ php_http_throw(unexpected_val, "Could not acquire reference to superglobal GET array", NULL);
}
- RETVAL_ZVAL_FAST(instance);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_getIterator, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, getIterator)
{
- zval *qa;
+ zval qa_tmp, *qa;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
object_init_ex(return_value, spl_ce_RecursiveArrayIterator);
zend_call_method_with_1_params(return_value, spl_ce_RecursiveArrayIterator, NULL, "__construct", NULL, qa);
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, toArray)
{
- zval *zqa;
+ zval zqa_tmp, *zqa;
if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0);
- RETURN_ZVAL_FAST(zqa);
+ zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &zqa_tmp);
+ RETURN_ZVAL(zqa, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_get, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, mod)
{
- zval *params, *instance = getThis();
+ zval qa_tmp, *params, *instance = getThis();
zend_error_handling zeh;
php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶ms), invalid_arg, return);
zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh);
ZVAL_OBJ(return_value, Z_OBJ_HT_P(instance)->clone_obj(instance));
+ /* make sure we do not inherit the reference to _GET */
+ SEPARATE_ZVAL(zend_read_property(Z_OBJCE_P(return_value), return_value, ZEND_STRL("queryArray"), 0, &qa_tmp));
php_http_querystring_set(return_value, params, QS_MERGE);
zend_restore_error_handling(&zeh);
}
{
char *ie, *oe;
size_t ie_len, oe_len;
- zval na, *qa;
+ zval na, qa_tmp, *qa;
php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &ie, &ie_len, &oe, &oe_len), invalid_arg, return);
array_init(&na);
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
ZVAL_DEREF(qa);
convert_to_array(qa);
);
php_http_querystring_set(getThis(), &na, 0);
- RETVAL_ZVAL_FAST(getThis());
+ RETVAL_ZVAL(getThis(), 1, 0);
zval_ptr_dtor(&na);
}
PHP_METHOD(HttpQueryString, offsetGet)
{
zend_string *offset;
- zval *value, *qa;
+ zval *value, qa_tmp, *qa;
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) {
return;
}
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
ZVAL_DEREF(qa);
if (Z_TYPE_P(qa) == IS_ARRAY) {
if ((value = zend_symtable_find(Z_ARRVAL_P(qa), offset))) {
- RETVAL_ZVAL_FAST(value);
+ RETVAL_ZVAL(value, 1, 0);
}
}
}
PHP_METHOD(HttpQueryString, offsetSet)
{
zend_string *offset;
- zval *value, param;
+ zval *value, param, znull;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz", &offset, &value)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &offset, &value)) {
return;
}
- array_init(¶m);
+ array_init_size(¶m, 1);
+ /* unset first */
+ ZVAL_NULL(&znull);
+ zend_symtable_update(Z_ARRVAL(param), offset, &znull);
+ php_http_querystring_set(getThis(), ¶m, QS_MERGE);
+ /* then update, else QS_MERGE would merge sub-arrrays */
Z_TRY_ADDREF_P(value);
zend_symtable_update(Z_ARRVAL(param), offset, value);
- php_http_querystring_set(getThis(), ¶m, 0);
+ php_http_querystring_set(getThis(), ¶m, QS_MERGE);
zval_ptr_dtor(¶m);
}
PHP_METHOD(HttpQueryString, offsetExists)
{
zend_string *offset;
- zval *value, *qa;
+ zval *value, qa_tmp, *qa;
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) {
return;
}
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
ZVAL_DEREF(qa);
if (Z_TYPE_P(qa) == IS_ARRAY) {
zend_string *offset;
zval param, znull;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &offset)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) {
return;
}