Merge branch 'master' into phpng
[m6w6/ext-http] / php_http_env_request.c
index a884d2f..0ee68f4 100644 (file)
 
 #include "php_http_api.h"
 
-static int grab_file(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int grab_file(zval *tmp_name, int argc, va_list argv, zend_hash_key *key)
 {
-       zval *zfiles, **name, **zname, **error, **zerror, **type, **ztype, **size, **zsize, **tmp_name = zpp;
+       zval *zfiles, *name, *zname, *error, *zerror, *type, *ztype, *size, *zsize;
        zend_hash_key *file_key;
 
        zfiles = (zval *) va_arg(argv, zval *);
        file_key = (zend_hash_key *) va_arg(argv, zend_hash_key *);
-       name = (zval **) va_arg(argv, zval **);
-       size = (zval **) va_arg(argv, zval **);
-       type = (zval **) va_arg(argv, zval **);
-       error = (zval **) va_arg(argv, zval **);
-
-       if (SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(name), key->h, (void *) &zname)
-       &&      SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(size), key->h, (void *) &zsize)
-       &&      SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(type), key->h, (void *) &ztype)
-       &&      SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(error), key->h, (void *) &zerror)
+       name = (zval *) va_arg(argv, zval *);
+       size = (zval *) va_arg(argv, zval *);
+       type = (zval *) va_arg(argv, zval *);
+       error = (zval *) va_arg(argv, zval *);
+
+       if ((zname = zend_hash_index_find(Z_ARRVAL_P(name), key->h))
+       &&      (zsize = zend_hash_index_find(Z_ARRVAL_P(size), key->h))
+       &&      (ztype = zend_hash_index_find(Z_ARRVAL_P(type), key->h))
+       &&      (zerror = zend_hash_index_find(Z_ARRVAL_P(error), key->h))
        ) {
-               zval *entry, **array;
-
-               MAKE_STD_ZVAL(entry);
-               array_init(entry);
-
-               Z_ADDREF_PP(tmp_name);
-               add_assoc_zval_ex(entry, ZEND_STRS("file"), *tmp_name);
-               Z_ADDREF_PP(zname);
-               add_assoc_zval_ex(entry, ZEND_STRS("name"), *zname);
-               Z_ADDREF_PP(zsize);
-               add_assoc_zval_ex(entry, ZEND_STRS("size"), *zsize);
-               Z_ADDREF_PP(ztype);
-               add_assoc_zval_ex(entry, ZEND_STRS("type"), *ztype);
-               Z_ADDREF_PP(zerror);
-               add_assoc_zval_ex(entry, ZEND_STRS("error"), *zerror);
-
-               if (SUCCESS == zend_hash_quick_find(Z_ARRVAL_P(zfiles), file_key->arKey, file_key->nKeyLength, file_key->h, (void *) &array)) {
-                       add_next_index_zval(*array, entry);
+               zval entry, *array;
+
+               array_init(&entry);
+
+               Z_TRY_ADDREF_P(tmp_name);
+               add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp_name);
+               Z_TRY_ADDREF_P(zname);
+               add_assoc_zval_ex(&entry, ZEND_STRL("name"), zname);
+               Z_TRY_ADDREF_P(zsize);
+               add_assoc_zval_ex(&entry, ZEND_STRL("size"), zsize);
+               Z_TRY_ADDREF_P(ztype);
+               add_assoc_zval_ex(&entry, ZEND_STRL("type"), ztype);
+               Z_TRY_ADDREF_P(zerror);
+               add_assoc_zval_ex(&entry, ZEND_STRL("error"), zerror);
+
+               if (file_key->key && (array = zend_hash_find(Z_ARRVAL_P(zfiles), file_key->key))) {
+                       add_next_index_zval(array, &entry);
+               } else if (!file_key->key && (array = zend_hash_index_find(Z_ARRVAL_P(zfiles), file_key->h))) {
+                       add_next_index_zval(array, &entry);
                } else {
-                       zval *tmp;
+                       zval tmp;
 
-                       MAKE_STD_ZVAL(tmp);
-                       array_init(tmp);
-                       add_next_index_zval(tmp, entry);
-                       zend_hash_quick_update(Z_ARRVAL_P(zfiles), file_key->arKey, file_key->nKeyLength, file_key->h, (void *) &tmp, sizeof(zval *), NULL);
+                       array_init(&tmp);
+                       add_next_index_zval(&tmp, &entry);
+                       if (file_key->key) {
+                               zend_hash_update(Z_ARRVAL_P(zfiles), file_key->key, &tmp);
+                       } else {
+                               zend_hash_index_update(Z_ARRVAL_P(zfiles), file_key->h, &tmp);
+                       }
                }
        }
 
        return ZEND_HASH_APPLY_KEEP;
 }
 
-static int grab_files(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int grab_files(zval *val, int argc, va_list argv, zend_hash_key *key)
 {
-       zval *zfiles, **name, **tmp_name, **error, **type, **size, **val = zpp;
+       zval *zfiles, *name, *tmp_name, *error, *type, *size;
 
        zfiles = (zval *) va_arg(argv, zval *);
 
-       if (Z_TYPE_PP(val) == IS_ARRAY
-       &&      SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("tmp_name"), (void *) &tmp_name)
-       &&      SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("name"), (void *) &name)
-       &&      SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("size"), (void *) &size)
-       &&      SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("type"), (void *) &type)
-       &&      SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("error"), (void *) &error)
+       if ((Z_TYPE_P(val) == IS_ARRAY)
+       &&      (tmp_name = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("tmp_name")))
+       &&      (name = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("name")))
+       &&      (size = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("size")))
+       &&      (type = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("type")))
+       &&      (error = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("error")))
        ) {
                int count;
 
-               if (Z_TYPE_PP(tmp_name) == IS_ARRAY && (count = zend_hash_num_elements(Z_ARRVAL_PP(tmp_name))) > 1) {
-                       if (count == zend_hash_num_elements(Z_ARRVAL_PP(name))
-                       &&      count == zend_hash_num_elements(Z_ARRVAL_PP(size))
-                       &&      count == zend_hash_num_elements(Z_ARRVAL_PP(type))
-                       &&      count == zend_hash_num_elements(Z_ARRVAL_PP(error))
+               if (Z_TYPE_P(tmp_name) == IS_ARRAY && (count = zend_hash_num_elements(Z_ARRVAL_P(tmp_name))) > 1) {
+                       if (count == zend_hash_num_elements(Z_ARRVAL_P(name))
+                       &&      count == zend_hash_num_elements(Z_ARRVAL_P(size))
+                       &&      count == zend_hash_num_elements(Z_ARRVAL_P(type))
+                       &&      count == zend_hash_num_elements(Z_ARRVAL_P(error))
                        ) {
-                               zend_hash_apply_with_arguments(Z_ARRVAL_PP(tmp_name) TSRMLS_CC, grab_file, 6, zfiles, key, name, size, type, error);
+                               zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp_name), grab_file, 6, zfiles, key, name, size, type, error);
                        } else {
                                /* wat?! */
                                return ZEND_HASH_APPLY_STOP;
                        }
                } else  {
-                       zval *cpy, **tmp;
-
-                       MAKE_STD_ZVAL(cpy);
-                       MAKE_COPY_ZVAL(val, cpy);
-                       if (SUCCESS == zend_hash_find(Z_ARRVAL_P(cpy), ZEND_STRS("tmp_name"), (void *) &tmp)) {
-                               Z_ADDREF_PP(tmp);
-                               add_assoc_zval_ex(cpy, ZEND_STRS("file"), *tmp);
-                               zend_hash_del_key_or_index(Z_ARRVAL_P(cpy), ZEND_STRS("tmp_name"), 0, HASH_DEL_KEY);
+                       zval *tmp, entry;
+
+                       ZVAL_DUP(&entry, val);
+                       if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("tmp_name")))) {
+                               Z_ADDREF_P(tmp);
+                               add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp);
+                               zend_hash_str_del(Z_ARRVAL(entry), ZEND_STRL("tmp_name"));
                        }
-                       if (key->nKeyLength > 0) {
-                               zend_hash_quick_update(Z_ARRVAL_P(zfiles), key->arKey, key->nKeyLength, key->h, (void *) &cpy, sizeof(zval *), NULL);
+                       if (key->key) {
+                               zend_hash_update(Z_ARRVAL_P(zfiles), key->key, &entry);
                        } else {
-                               zend_hash_index_update(Z_ARRVAL_P(zfiles), key->h, (void *) &cpy, sizeof(zval *), NULL);
+                               zend_hash_index_update(Z_ARRVAL_P(zfiles), key->h, &entry);
                        }
                }
        }
@@ -110,7 +113,7 @@ static int grab_files(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key
 #define PHP_HTTP_ENV_REQUEST_OBJECT_INIT(obj) \
        do { \
                if (!obj->message) { \
-                       obj->message = php_http_message_init_env(NULL, PHP_HTTP_REQUEST TSRMLS_CC); \
+                       obj->message = php_http_message_init_env(NULL, PHP_HTTP_REQUEST); \
                } \
        } while(0)
 
@@ -120,51 +123,38 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvRequest, __construct)
 {
        php_http_message_object_t *obj;
-       zval *zsg, *zqs;
+       zval *zsg, zqs;
 
        php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
 
-       obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       obj = PHP_HTTP_OBJ(NULL, getThis());
        obj->body = NULL;
 
-       php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC), unexpected_val, return);
+       php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST), unexpected_val, return);
 
-       zsg = php_http_env_get_superglobal(ZEND_STRL("_GET") TSRMLS_CC);
-       MAKE_STD_ZVAL(zqs);
-       object_init_ex(zqs, php_http_querystring_class_entry);
-       php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
-                       zval_ptr_dtor(&zqs);
-                       return;
-       );
-       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), zqs TSRMLS_CC);
+       zsg = php_http_env_get_superglobal(ZEND_STRL("_GET"));
+       object_init_ex(&zqs, php_http_querystring_class_entry);
+       php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return);
+       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), &zqs);
        zval_ptr_dtor(&zqs);
 
-       zsg = php_http_env_get_superglobal(ZEND_STRL("_POST") TSRMLS_CC);
-       MAKE_STD_ZVAL(zqs);
-       object_init_ex(zqs, php_http_querystring_class_entry);
-       php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
-                       zval_ptr_dtor(&zqs);
-                       return;
-       );
-       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), zqs TSRMLS_CC);
+       zsg = php_http_env_get_superglobal(ZEND_STRL("_POST"));
+       object_init_ex(&zqs, php_http_querystring_class_entry);
+       php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return);
+       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), &zqs);
        zval_ptr_dtor(&zqs);
 
-       zsg = php_http_env_get_superglobal(ZEND_STRL("_COOKIE") TSRMLS_CC);
-       MAKE_STD_ZVAL(zqs);
-       object_init_ex(zqs, php_http_querystring_class_entry);
-       php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
-                       zval_ptr_dtor(&zqs);
-                       return;
-       );
-       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), zqs TSRMLS_CC);
+       zsg = php_http_env_get_superglobal(ZEND_STRL("_COOKIE"));
+       object_init_ex(&zqs, php_http_querystring_class_entry);
+       php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return);
+       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), &zqs);
        zval_ptr_dtor(&zqs);
 
-       MAKE_STD_ZVAL(zqs);
-       array_init(zqs);
-       if ((zsg = php_http_env_get_superglobal(ZEND_STRL("_FILES") TSRMLS_CC))) {
-               zend_hash_apply_with_arguments(Z_ARRVAL_P(zsg) TSRMLS_CC, grab_files, 1, zqs);
+       array_init(&zqs);
+       if ((zsg = php_http_env_get_superglobal(ZEND_STRL("_FILES")))) {
+               zend_hash_apply_with_arguments(Z_ARRVAL_P(zsg), grab_files, 1, &zqs);
        }
-       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), zqs TSRMLS_CC);
+       zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), &zqs);
        zval_ptr_dtor(&zqs);
 }
 
@@ -172,24 +162,23 @@ static PHP_METHOD(HttpEnvRequest, __construct)
        do {\
                zend_fcall_info fci; \
                zend_fcall_info_cache fcc; \
-               zval *rv = NULL, mn, ***args = ecalloc(sizeof(zval **), ZEND_NUM_ARGS()); \
-               zval *qs = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL(prop), 0 TSRMLS_CC); \
+               zval rv, mn, *args = ecalloc(sizeof(zval), ZEND_NUM_ARGS()); \
+               zval *this_ptr = getThis(); \
+               zval qs_tmp, *qs = zend_read_property(Z_OBJCE_P(this_ptr), this_ptr, ZEND_STRL(prop), 0, &qs_tmp); \
                 \
-               INIT_PZVAL(&mn); \
+               ZVAL_NULL(&rv); \
                array_init(&mn); \
-               Z_ADDREF_P(qs); \
+               Z_TRY_ADDREF_P(qs); \
                add_next_index_zval(&mn, qs); \
-               add_next_index_stringl(&mn, ZEND_STRL("get"), 1); \
-               zend_fcall_info_init(&mn, 0, &fci, &fcc, NULL, NULL TSRMLS_CC); \
+               add_next_index_stringl(&mn, ZEND_STRL("get")); \
+               zend_fcall_info_init(&mn, 0, &fci, &fcc, NULL, NULL); \
                zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args); \
-               zend_fcall_info_argp(&fci TSRMLS_CC, ZEND_NUM_ARGS(), args); \
-               zend_fcall_info_call(&fci, &fcc, &rv, NULL TSRMLS_CC); \
+               zend_fcall_info_argp(&fci, ZEND_NUM_ARGS(), args); \
+               zend_fcall_info_call(&fci, &fcc, &rv, NULL); \
                zend_fcall_info_args_clear(&fci, 1); \
                efree(args); \
                zval_dtor(&mn); \
-               if (rv) { \
-                       RETVAL_ZVAL(rv, 0, 1); \
-               } \
+               RETVAL_ZVAL(&rv, 0, 1); \
        } while(0);
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getForm, 0, 0, 0)
@@ -203,7 +192,7 @@ static PHP_METHOD(HttpEnvRequest, getForm)
        if (ZEND_NUM_ARGS()) {
                call_querystring_get("form");
        } else {
-               zval *zform = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), 0 TSRMLS_CC);
+               zval zform_tmp, *zform = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), 0, &zform_tmp);
                RETURN_ZVAL(zform, 1, 0);
        }
 }
@@ -219,7 +208,7 @@ static PHP_METHOD(HttpEnvRequest, getQuery)
        if (ZEND_NUM_ARGS()) {
                call_querystring_get("query");
        } else {
-               zval *zquery = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), 0 TSRMLS_CC);
+               zval zquery_tmp, *zquery = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), 0, &zquery_tmp);
                RETURN_ZVAL(zquery, 1, 0);
        }
 }
@@ -235,7 +224,7 @@ static PHP_METHOD(HttpEnvRequest, getCookie)
        if (ZEND_NUM_ARGS()) {
                call_querystring_get("cookie");
        } else {
-               zval *zcookie = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), 0 TSRMLS_CC);
+               zval zcookie_tmp, *zcookie = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), 0, &zcookie_tmp);
                RETURN_ZVAL(zcookie, 1, 0);
        }
 }
@@ -245,7 +234,7 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvRequest, getFiles)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
-               zval *zfiles = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), 0 TSRMLS_CC);
+               zval zfiles_tmp, *zfiles = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), 0, &zfiles_tmp);
                RETURN_ZVAL(zfiles, 1, 0);
        }
 }
@@ -266,12 +255,12 @@ PHP_MINIT_FUNCTION(http_env_request)
        zend_class_entry ce = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Request", php_http_env_request_methods);
-       php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
+       php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry);
 
-       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("query"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("form"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("cookie"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("files"), ZEND_ACC_PROTECTED TSRMLS_CC);
+       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("query"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("form"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("cookie"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("files"), ZEND_ACC_PROTECTED);
 
        return SUCCESS;
 }