| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
- | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
+ | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
+--------------------------------------------------------------------+
*/
-/* $Id$ */
+#include "php_http_api.h"
-#include "php_http.h"
-
-#include <main/php_variables.h>
+#include <php_variables.h>
#include <ext/spl/spl_array.h>
-#include <Zend/zend_interfaces.h>
#ifdef PHP_HTTP_HAVE_ICONV
# undef PHP_ATOM_INC
# include <ext/iconv/php_iconv.h>
#endif
+
+#define QS_MERGE 1
+
+static inline void php_http_querystring_set(zval *instance, zval *params, int flags TSRMLS_DC)
+{
+ zval *qa;
+
+ if (flags & QS_MERGE) {
+ qa = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC));
+ } else {
+ MAKE_STD_ZVAL(qa);
+ array_init(qa);
+ }
+
+ php_http_querystring_update(qa, params, NULL TSRMLS_CC);
+ zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), qa TSRMLS_CC);
+ zval_ptr_dtor(&qa);
+}
+
+static inline void php_http_querystring_str(zval *instance, zval *return_value TSRMLS_DC)
+{
+ zval *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+
+ if (Z_TYPE_P(qa) == IS_ARRAY) {
+ php_http_querystring_update(qa, NULL, return_value TSRMLS_CC);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+}
+
+static inline void php_http_querystring_get(zval *this_ptr, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC)
+{
+ zval **arrval, *qarray = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+
+ if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) {
+ if (type) {
+ zval *value = php_http_ztyp(type, *arrval);
+ RETVAL_ZVAL(value, 1, 1);
+ } else {
+ RETVAL_ZVAL(*arrval, 1, 0);
+ }
+
+ if (del) {
+ zval *delarr;
+
+ MAKE_STD_ZVAL(delarr);
+ array_init(delarr);
+ add_assoc_null_ex(delarr, name, name_len + 1);
+ php_http_querystring_set(this_ptr, delarr, QS_MERGE TSRMLS_CC);
+ zval_ptr_dtor(&delarr);
+ }
+ } else if(defval) {
+ RETURN_ZVAL(defval, 1, 0);
+ }
+}
+
#ifdef PHP_HTTP_HAVE_ICONV
PHP_HTTP_API STATUS php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe TSRMLS_DC)
{
}
#endif /* HAVE_ICONV */
+PHP_HTTP_API STATUS php_http_querystring_ctor(zval *instance, zval *params TSRMLS_DC)
+{
+ php_http_querystring_set(instance, params, 0 TSRMLS_CC);
+ return SUCCESS;
+}
+
PHP_HTTP_API STATUS php_http_querystring_update(zval *qarray, zval *params, zval *outstring TSRMLS_DC)
{
/* enforce proper type */
}
}
} else {
+ zval *entry;
/*
* add
*/
if (Z_TYPE_PP(params_entry) == IS_OBJECT) {
- zval *new_array;
-
- MAKE_STD_ZVAL(new_array);
- array_init(new_array);
- php_http_querystring_update(new_array, *params_entry, NULL TSRMLS_CC);
- *params_entry = new_array;
+ MAKE_STD_ZVAL(entry);
+ array_init(entry);
+ php_http_querystring_update(entry, *params_entry, NULL TSRMLS_CC);
} else {
Z_ADDREF_PP(params_entry);
+ entry = *params_entry;
}
if (key.type == HASH_KEY_IS_STRING) {
- add_assoc_zval_ex(qarray, key.str, key.len, *params_entry);
+ add_assoc_zval_ex(qarray, key.str, key.len, entry);
} else {
- add_index_zval(qarray, key.num, *params_entry);
+ add_index_zval(qarray, key.num, entry);
}
}
}
return SUCCESS;
}
-#define QS_MERGE 1
-
-static inline void php_http_querystring_set(zval *instance, zval *params, int flags TSRMLS_DC)
-{
- zval *qa;
-
- if (flags & QS_MERGE) {
- qa = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC));
- } else {
- MAKE_STD_ZVAL(qa);
- array_init(qa);
- }
-
- php_http_querystring_update(qa, params, NULL TSRMLS_CC);
- zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), qa TSRMLS_CC);
- zval_ptr_dtor(&qa);
-}
-
-static inline void php_http_querystring_str(zval *instance, zval *return_value TSRMLS_DC)
-{
- zval *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC);
-
- if (Z_TYPE_P(qa) == IS_ARRAY) {
- php_http_querystring_update(qa, NULL, return_value TSRMLS_CC);
- } else {
- RETURN_EMPTY_STRING();
- }
-}
-
-static inline void php_http_querystring_get(zval *this_ptr, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC)
-{
- zval **arrval, *qarray = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
-
- if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_hash_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) {
- if (type) {
- zval *value = php_http_ztyp(type, *arrval);
- RETVAL_ZVAL(value, 1, 1);
- } else {
- RETVAL_ZVAL(*arrval, 1, 0);
- }
-
- if (del) {
- zval *delarr;
-
- MAKE_STD_ZVAL(delarr);
- array_init(delarr);
- add_assoc_null_ex(delarr, name, name_len + 1);
- php_http_querystring_set(this_ptr, delarr, QS_MERGE TSRMLS_CC);
- zval_ptr_dtor(&delarr);
- }
- } else if(defval) {
- RETURN_ZVAL(defval, 1, 0);
- }
-}
PHP_METHOD(HttpQueryString, __construct)
{
zval *params = NULL;
zval *qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
if (Z_TYPE_P(qa) == IS_ARRAY
- && SUCCESS == zend_hash_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)
+ && SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)
) {
RETVAL_ZVAL(*value, 1, 0);
}
zval *qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
if (Z_TYPE_P(qa) == IS_ARRAY
- && SUCCESS == zend_hash_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)
+ && SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)
&& Z_TYPE_PP(value) != IS_NULL
) {
RETURN_TRUE;