less intrusive fix
[m6w6/ext-http] / php_http_querystring.c
index ab2bc3d384c89099cc301f3a8d7882d1f9305f72..177701b8fc29fb26bfd46c3b0babc8a36bb2f5f2 100644 (file)
@@ -6,23 +6,76 @@
     | 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)
 {
@@ -79,6 +132,12 @@ PHP_HTTP_API STATUS php_http_querystring_xlate(zval *dst, zval *src, const char
 }
 #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 */
@@ -148,23 +207,22 @@ PHP_HTTP_API STATUS php_http_querystring_update(zval *qarray, zval *params, zval
                                                }
                                        }
                                } 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);
                                        }
                                }
                        }
@@ -317,60 +375,6 @@ PHP_MINIT_FUNCTION(http_querystring)
        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;
@@ -599,7 +603,7 @@ PHP_METHOD(HttpQueryString, offsetGet)
                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);
                }
@@ -634,7 +638,7 @@ PHP_METHOD(HttpQueryString, offsetExists)
                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;