flush WIP
authorMichael Wallner <mike@php.net>
Thu, 15 Jan 2015 15:11:40 +0000 (16:11 +0100)
committerMichael Wallner <mike@php.net>
Thu, 15 Jan 2015 15:11:40 +0000 (16:11 +0100)
php_http_env.c
php_http_env.h
php_http_env_request.c
php_http_env_response.c
php_http_env_response.h
php_http_options.c
php_http_options.h
php_http_querystring.c

index e1ff585d72482ecea7d36faa673243b81d899e7b..a2390b3284f08e88387f9742eadcec283a8f42bd 100644 (file)
@@ -29,41 +29,33 @@ PHP_RINIT_FUNCTION(http_env)
                SG(request_info).content_type_dup = ct_str;
 
                ZEND_INIT_SYMTABLE(&params);
-               if (php_http_params_parse(&params, &opts TSRMLS_CC)) {
-                       char *key_str;
-                       uint key_len;
-                       ulong key_num;
+               if (php_http_params_parse(&params, &opts)) {
+                       zend_string *key_str;
+                       zend_ulong key_num;
 
-                       if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(&params, &key_str, &key_len, &key_num, 0, NULL)) {
+                       if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(&params, &key_str, &key_num, NULL)) {
                                sapi_post_entry *post_entry = NULL;
 
-                               if (SUCCESS == zend_hash_find(&SG(known_post_content_types), key_str, key_len, (void *) &post_entry)) {
-                                       zval *files = PG(http_globals)[TRACK_VARS_FILES];
-
+                               if ((post_entry = zend_hash_find_ptr(&SG(known_post_content_types), key_str))) {
                                        if (post_entry) {
                                                SG(request_info).post_entry = post_entry;
 
                                                if (post_entry->post_reader) {
-                                                       post_entry->post_reader(TSRMLS_C);
+                                                       post_entry->post_reader();
                                                }
                                        }
 
                                        if (sapi_module.default_post_reader) {
-                                               sapi_module.default_post_reader(TSRMLS_C);
+                                               sapi_module.default_post_reader();
                                        }
 
-                                       sapi_handle_post(PG(http_globals)[TRACK_VARS_POST] TSRMLS_CC);
+                                       sapi_handle_post(&PG(http_globals)[TRACK_VARS_POST]);
 
                                        /*
                                         * the rfc1867 handler is an awkward buddy
                                         */
-                                       if (files != PG(http_globals)[TRACK_VARS_FILES] && PG(http_globals)[TRACK_VARS_FILES]) {
-                                               Z_ADDREF_P(PG(http_globals)[TRACK_VARS_FILES]);
-                                               zend_hash_update(&EG(symbol_table), "_FILES", sizeof("_FILES"), &PG(http_globals)[TRACK_VARS_FILES], sizeof(zval *), NULL);
-                                               if (files) {
-                                                       zval_ptr_dtor(&files);
-                                               }
-                                       }
+                                       Z_TRY_ADDREF(PG(http_globals)[TRACK_VARS_FILES]);
+                                       zend_hash_str_update(&EG(symbol_table).ht, "_FILES", sizeof("_FILES"), &PG(http_globals)[TRACK_VARS_FILES]);
                                }
                        }
                        zend_hash_destroy(&params);
@@ -87,7 +79,7 @@ PHP_RSHUTDOWN_FUNCTION(http_env)
        }
 
        if (PHP_HTTP_G->env.server_var) {
-               zval_ptr_dtor(&PHP_HTTP_G->env.server_var);
+               zval_ptr_dtor(PHP_HTTP_G->env.server_var);
                PHP_HTTP_G->env.server_var = NULL;
        }
 
@@ -96,66 +88,63 @@ PHP_RSHUTDOWN_FUNCTION(http_env)
 
 void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC)
 {
-       php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
-       zval **hsv, **header;
-       HashPosition pos;
+       php_http_arrkey_t key;
+       zval *hsv, *header;
 
        if (!PHP_HTTP_G->env.request.headers) {
                ALLOC_HASHTABLE(PHP_HTTP_G->env.request.headers);
-               zend_hash_init(PHP_HTTP_G->env.request.headers, 0, NULL, ZVAL_PTR_DTOR, 0);
-
-               zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
+               ZEND_INIT_SYMTABLE(PHP_HTTP_G->env.request.headers);
 
-               if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv) && Z_TYPE_PP(hsv) == IS_ARRAY) {
-                       FOREACH_KEY(pos, *hsv, key) {
-                               if (key.type == HASH_KEY_IS_STRING && key.len > 6 && *key.str == 'H' && !strncmp(key.str, "HTTP_", 5)) {
-                                       key.len -= 5;
-                                       key.str = php_http_pretty_key(estrndup(key.str + 5, key.len - 1), key.len - 1, 1, 1);
+               if ((hsv = php_http_env_get_superglobal(ZEND_STRL("_SERVER")))) {
+                       ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(hsv), key.h, key.key, header)
+                       {
+                               if (key.key && key.key->len > 5 && *key.key->val == 'H' && !strncmp(key.key->val, "HTTP_", 5)) {
+                                       size_t key_len = key.key->len - 5;
+                                       char *key_str = php_http_pretty_key(estrndup(&key.key->val[5], key_len), key_len, 1, 1);
 
-                                       zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos);
-                                       Z_ADDREF_P(*header);
-                                       zend_symtable_update(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL);
+                                       Z_TRY_ADDREF_P(header);
+                                       zend_symtable_str_update(PHP_HTTP_G->env.request.headers, key_str, key_len, header);
 
-                                       efree(key.str);
-                               } else if (key.type == HASH_KEY_IS_STRING && key.len > 9 && *key.str == 'C' && !strncmp(key.str, "CONTENT_", 8)) {
-                                       key.str = php_http_pretty_key(estrndup(key.str, key.len - 1), key.len - 1, 1, 1);
+                                       efree(key_str);
+                               } else if (key.key && key.key->len > 8 && *key.key->val == 'C' && !strncmp(key.key->val, "CONTENT_", 8)) {
+                                       char *key_str = php_http_pretty_key(estrndup(key.key->val, key.key->len), key.key->len, 1, 1);
 
-                                       zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos);
-                                       Z_ADDREF_P(*header);
-                                       zend_symtable_update(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL);
+                                       Z_TRY_ADDREF_P(header);
+                                       zend_symtable_str_update(PHP_HTTP_G->env.request.headers, key_str, key.key->len, header);
 
-                                       efree(key.str);
+                                       efree(key_str);
                                }
                        }
+                       ZEND_HASH_FOREACH_END();
                }
        }
 
        if (headers) {
-               zend_hash_copy(headers, PHP_HTTP_G->env.request.headers, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+               array_copy(PHP_HTTP_G->env.request.headers, headers);
        }
 }
 
-char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request TSRMLS_DC)
+char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request)
 {
        HashTable *request_headers;
-       zval **zvalue = NULL;
+       zval *zvalue = NULL;
        char *val = NULL, *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
 
        if (request) {
                request_headers = &request->hdrs;
        } else {
-               php_http_env_get_request_headers(NULL TSRMLS_CC);
+               php_http_env_get_request_headers(NULL);
                request_headers = PHP_HTTP_G->env.request.headers;
        }
 
-       if (SUCCESS == zend_symtable_find(request_headers, key, name_len + 1, (void *) &zvalue)) {
-               zval *zcopy = php_http_ztyp(IS_STRING, *zvalue);
+       if ((zvalue == zend_symtable_str_find(request_headers, key, name_len))) {
+               zend_string *zs = zval_get_string(zvalue);
 
-               val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy));
+               val = estrndup(zs->val, zs->len);
                if (len) {
-                       *len = Z_STRLEN_P(zcopy);
+                       *len = zs->len;
                }
-               zval_ptr_dtor(&zcopy);
+               zend_string_release(zs);
        }
 
        efree(key);
@@ -163,45 +152,49 @@ char *php_http_env_get_request_header(const char *name_str, size_t name_len, siz
        return val;
 }
 
-int php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request TSRMLS_DC)
+zend_bool php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request)
 {
        HashTable *request_headers;
        char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
-       int got;
+       zend_bool got;
 
        if (request) {
                request_headers = &request->hdrs;
        } else {
-               php_http_env_get_request_headers(NULL TSRMLS_CC);
+               php_http_env_get_request_headers(NULL);
                request_headers = PHP_HTTP_G->env.request.headers;
        }
-       got = zend_symtable_exists(request_headers, key, name_len + 1);
+       got = zend_symtable_str_exists(request_headers, key, name_len);
        efree(key);
 
        return got;
 }
 
-zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC)
+zval *php_http_env_get_superglobal(const char *key, size_t key_len)
 {
-       zval **hsv;
+       zval *hsv;
+       zend_string *key_str = zend_string_init(key, key_len, 0);
 
-       zend_is_auto_global(key, key_len TSRMLS_CC);
+       zend_is_auto_global(key_str);
+       hsv = zend_hash_find(&EG(symbol_table).ht, key_str);
+       zend_string_release(key_str);
 
-       if ((SUCCESS != zend_hash_find(&EG(symbol_table), key, key_len + 1, (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
+       if (Z_TYPE_P(hsv) != IS_ARRAY) {
                return NULL;
        }
 
-       return *hsv;
+       return hsv;
 }
 
-zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
+zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check)
 {
-       zval *hsv, **var;
-       char *env;
+       zval *hsv, *var;
 
-       /* if available, this is a lot faster than accessing $_SERVER */
+       /* if available, this is a lot faster than accessing $_SERVER * /
        if (sapi_module.getenv) {
-               if ((!(env = sapi_module.getenv((char *) key, key_len TSRMLS_CC))) || (check && !*env)) {
+               char *env;
+
+               if ((!(env = sapi_module.getenv((char *) key, key_len))) || (check && !*env)) {
                        return NULL;
                }
                if (PHP_HTTP_G->env.server_var) {
@@ -211,60 +204,38 @@ zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool che
                ZVAL_STRING(PHP_HTTP_G->env.server_var, env, 1);
                return PHP_HTTP_G->env.server_var;
        }
+       / * */
 
-       if (!(hsv = php_http_env_get_superglobal(ZEND_STRL("_SERVER") TSRMLS_CC))) {
+       if (!(hsv = php_http_env_get_superglobal(ZEND_STRL("_SERVER")))) {
                return NULL;
        }
-       if ((SUCCESS != zend_symtable_find(Z_ARRVAL_P(hsv), key, key_len + 1, (void *) &var))) {
+       if (!(var = zend_symtable_str_find(Z_ARRVAL_P(hsv), key, key_len))) {
                return NULL;
        }
-       if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
+       if (check && !((Z_TYPE_P(var) == IS_STRING) && Z_STRVAL_P(var) && Z_STRLEN_P(var))) {
                return NULL;
        }
-       return *var;
+       return var;
 }
 
-php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D)
+php_http_message_body_t *php_http_env_get_request_body(void)
 {
        if (!PHP_HTTP_G->env.request.body) {
                php_stream *s = php_stream_temp_new();
-#if PHP_VERSION_ID >= 50600
                php_stream *input = php_stream_open_wrapper("php://input", "r", 0, NULL);
 
                /* php://input does not support stat */
                php_stream_copy_to_stream_ex(input, s, -1, NULL);
                php_stream_close(input);
-#else
-               if (SG(request_info).post_data || SG(request_info).raw_post_data) {
-                       /* php://input does not support seek() in PHP <= 5.5 */
-                       if (SG(request_info).raw_post_data) {
-                               php_stream_write(s, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length);
-                       } else {
-                               php_stream_write(s, SG(request_info).post_data, SG(request_info).post_data_length);
-                       }
-               } else if (sapi_module.read_post && !SG(read_post_bytes)) {
-                       char *buf = emalloc(4096);
-                       int len;
 
-                       while (0 < (len = sapi_module.read_post(buf, 4096 TSRMLS_CC))) {
-                               SG(read_post_bytes) += len;
-                               php_stream_write(s, buf, len);
-
-                               if (len < 4096) {
-                                       break;
-                               }
-                       }
-                       efree(buf);
-               }
-#endif
                php_stream_rewind(s);
-               PHP_HTTP_G->env.request.body = php_http_message_body_init(NULL, s TSRMLS_CC);
+               PHP_HTTP_G->env.request.body = php_http_message_body_init(NULL, s);
        }
 
        return PHP_HTTP_G->env.request.body;
 }
 
-const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_DC)
+const char *php_http_env_get_request_method(php_http_message_t *request)
 {
        const char *m;
 
@@ -277,13 +248,13 @@ const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_D
        return m ? m : "GET";
 }
 
-php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length, php_http_message_t *request TSRMLS_DC)
+php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length, php_http_message_t *request)
 {
-       zval *zentry;
+       zval zentry;
        char *range, *rp, c;
        long begin = -1, end = -1, *ptr;
 
-       if (!(range = php_http_env_get_request_header(ZEND_STRL("Range"), NULL, request TSRMLS_CC))) {
+       if (!(range = php_http_env_get_request_header(ZEND_STRL("Range"), NULL, request))) {
                return PHP_HTTP_RANGE_NO;
        }
        if (strncmp(range, "bytes=", lenof("bytes="))) {
@@ -402,11 +373,10 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
                                        }
                                }
 
-                               MAKE_STD_ZVAL(zentry);
-                               array_init(zentry);
-                               add_index_long(zentry, 0, begin);
-                               add_index_long(zentry, 1, end);
-                               zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL);
+                               array_init(&zentry);
+                               add_index_long(&zentry, 0, begin);
+                               add_index_long(&zentry, 1, end);
+                               zend_hash_next_index_insert(ranges, &zentry);
 
                                begin = -1;
                                end = -1;
@@ -424,88 +394,98 @@ php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_
        return PHP_HTTP_RANGE_OK;
 }
 
-static void grab_headers(void *data, void *arg TSRMLS_DC)
+static void grab_headers(void *data, void *arg)
 {
        php_http_buffer_appendl(PHP_HTTP_BUFFER(arg), ((sapi_header_struct *)data)->header);
        php_http_buffer_appends(PHP_HTTP_BUFFER(arg), PHP_HTTP_CRLF);
 }
 
-ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC)
+static void grab_header(void *data, void *arg)
+{
+       struct {
+               char *name_str;
+               size_t name_len;
+               char *value_ptr;
+       } *args = arg;
+       sapi_header_struct *header = data;
+
+       if (    header->header_len > args->name_len
+       && header->header[args->name_len] == ':'
+       && !strncmp(header->header, args->name_str, args->name_len)
+       ) {
+               args->value_ptr = &header->header[args->name_len + 1];
+       }
+}
+
+ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht)
 {
        ZEND_RESULT_CODE status;
        php_http_buffer_t headers;
 
        php_http_buffer_init(&headers);
-       zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers TSRMLS_CC);
+       zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers);
        php_http_buffer_fix(&headers);
 
-       status = php_http_header_parse(headers.data, headers.used, headers_ht, NULL, NULL TSRMLS_CC);
+       status = php_http_header_parse(headers.data, headers.used, headers_ht, NULL, NULL);
        php_http_buffer_dtor(&headers);
 
        return status;
 }
 
-char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC)
+char *php_http_env_get_response_header(const char *name_str, size_t name_len)
 {
-       char *val = NULL;
-       HashTable headers;
-
-       zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0);
-       if (SUCCESS == php_http_env_get_response_headers(&headers TSRMLS_CC)) {
-               zval **zvalue;
-               char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
-
-               if (SUCCESS == zend_symtable_find(&headers, key, name_len + 1, (void *) &zvalue)) {
-                       zval *zcopy = php_http_ztyp(IS_STRING, *zvalue);
-
-                       val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy));
-                       zval_ptr_dtor(&zcopy);
-               }
+       struct {
+               char *name_str;
+               size_t name_len;
+               char *value_ptr;
+       } args;
 
-               efree(key);
-       }
-       zend_hash_destroy(&headers);
+       args.name_str = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
+       args.name_len = name_len;
+       args.value_ptr = NULL;
+       zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_header, &args);
+       efree(args.name_str);
 
-       return val;
+       return args.value_ptr ? estrdup(args.value_ptr) : NULL;
 }
 
-long php_http_env_get_response_code(TSRMLS_D)
+long php_http_env_get_response_code(void)
 {
        long code = SG(sapi_headers).http_response_code;
        return code ? code : 200;
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_code(long http_code TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_code(long http_code)
 {
-       return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) http_code TSRMLS_CC);
+       return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (zend_intptr_t) http_code);
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_status_line(long code, php_http_version_t *v TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_status_line(long code, php_http_version_t *v)
 {
        sapi_header_line h = {NULL, 0, 0};
        ZEND_RESULT_CODE ret;
 
        h.line_len = spprintf(&h.line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code));
-       ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h TSRMLS_CC);
+       ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h);
        efree(h.line);
 
        return ret;
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v)
 {
-       return php_http_env_set_response_status_line(php_http_env_get_response_code(TSRMLS_C), v TSRMLS_CC);
+       return php_http_env_set_response_status_line(php_http_env_get_response_code(), v);
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace)
 {
        sapi_header_line h = {estrndup(header_str, header_len), header_len, http_code};
-       ZEND_RESULT_CODE ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
+       ZEND_RESULT_CODE ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
        efree(h.line);
        return ret;
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv)
 {
        ZEND_RESULT_CODE ret = FAILURE;
        sapi_header_line h = {NULL, 0, http_code};
@@ -514,65 +494,67 @@ ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool r
 
        if (h.line) {
                if (h.line_len) {
-                       ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
+                       ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
                }
                efree(h.line);
        }
        return ret;
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace TSRMLS_DC, const char *fmt, ...)
+ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace, const char *fmt, ...)
 {
        ZEND_RESULT_CODE ret;
        va_list args;
 
        va_start(args, fmt);
-       ret = php_http_env_set_response_header_va(http_code, replace, fmt, args TSRMLS_CC);
+       ret = php_http_env_set_response_header_va(http_code, replace, fmt, args);
        va_end(args);
 
        return ret;
 }
 
-ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace)
 {
        if (!value) {
                sapi_header_line h = {(char *) name_str, name_len, http_code};
 
-               return sapi_header_op(SAPI_HEADER_DELETE, (void *) &h TSRMLS_CC);
+               return sapi_header_op(SAPI_HEADER_DELETE, (void *) &h);
        }
 
-       if(Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
-               HashPosition pos;
+       if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
                int first = replace;
-               zval **data_ptr;
+               zval *data_ptr;
+               HashTable *ht = HASH_OF(value);
 
-               FOREACH_HASH_VAL(pos, HASH_OF(value), data_ptr) {
-                       if (SUCCESS != php_http_env_set_response_header_value(http_code, name_str, name_len, *data_ptr, first TSRMLS_CC)) {
+               ZEND_HASH_FOREACH_VAL(ht, data_ptr)
+               {
+                       if (SUCCESS != php_http_env_set_response_header_value(http_code, name_str, name_len, data_ptr, first)) {
                                return FAILURE;
                        }
                        first = 0;
                }
+               ZEND_HASH_FOREACH_END();
 
                return SUCCESS;
        } else {
-               zval *data = php_http_ztyp(IS_STRING, value);
+               zend_string *data = zval_get_string(value);
 
-               if (!Z_STRLEN_P(data)) {
-                       zval_ptr_dtor(&data);
-                       return php_http_env_set_response_header_value(http_code, name_str, name_len, NULL, replace TSRMLS_CC);
+               if (!data->len) {
+                       zend_string_release(data);
+                       return php_http_env_set_response_header_value(http_code, name_str, name_len, NULL, replace);
                } else {
                        sapi_header_line h;
                        ZEND_RESULT_CODE ret;
 
                        if (name_len > INT_MAX) {
-                               name_len = INT_MAX;
+                               return FAILURE;
                        }
                        h.response_code = http_code;
-                       h.line_len = spprintf(&h.line, 0, "%.*s: %.*s", (int) name_len, name_str, Z_STRLEN_P(data), Z_STRVAL_P(data));
+                       h.line_len = spprintf(&h.line, 0, "%.*s: %.*s", (int) name_len, name_str, data->len, data->val);
 
-                       ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
+                       ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
 
-                       zval_ptr_dtor(&data);
+                       zend_string_release(data);
                        PTR_FREE(h.line);
 
                        return ret;
@@ -682,21 +664,21 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getRequestHeader)
 {
        char *header_name_str = NULL;
-       int header_name_len = 0;
+       size_t header_name_len = 0;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
                return;
        }
        if (header_name_str && header_name_len) {
                size_t header_length;
-               char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length, NULL TSRMLS_CC);
+               char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length, NULL);
 
                if (header_value) {
-                       RETURN_STRINGL(header_value, header_length, 0);
+                       RETURN_STR(php_http_cs2zs(header_value, header_length));
                }
        } else {
                array_init(return_value);
-               php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
+               php_http_env_get_request_headers(Z_ARRVAL_P(return_value));
        }
 }
 
@@ -705,16 +687,16 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestBody, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getRequestBody)
 {
-       zend_object_value ov;
        php_http_message_body_t *body;
+       php_http_message_body_object_t *body_obj;
        zend_class_entry *class_entry = php_http_message_body_class_entry;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &class_entry), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &class_entry), invalid_arg, return);
 
-       body = php_http_env_get_request_body(TSRMLS_C);
-       if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body, NULL TSRMLS_CC)) {
+       body = php_http_env_get_request_body();
+       if (SUCCESS == php_http_new((void *) &body_obj, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body)) {
                php_http_message_body_addref(body);
-               RETVAL_OBJVAL(ov, 0);
+               RETVAL_OBJ(&body_obj->zo);
        }
 }
 
@@ -723,12 +705,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForCode, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getResponseStatusForCode)
 {
-       long code;
+       zend_long code;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
                return;
        }
-       RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
+       RETURN_STRING(php_http_env_get_response_status_for_code(code));
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForAllCodes, 0, 0, 0)
@@ -748,7 +730,7 @@ static PHP_METHOD(HttpEnv, getResponseStatusForAllCodes)
                        *(s = php_http_strlist_iterator_this(&i, &c));
                        php_http_strlist_iterator_next(&i)
        ) {
-               add_index_string(return_value, c, s, 1);
+               add_index_string(return_value, c, s);
        }
 }
 
@@ -758,20 +740,20 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getResponseHeader)
 {
        char *header_name_str = NULL;
-       int header_name_len = 0;
+       size_t header_name_len = 0;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
                return;
        }
        if (header_name_str && header_name_len) {
-               char *header_value = php_http_env_get_response_header(header_name_str, header_name_len TSRMLS_CC);
+               char *header_value = php_http_env_get_response_header(header_name_str, header_name_len);
 
                if (header_value) {
-                       RETURN_STRING(header_value, 0);
+                       RETURN_STR(php_http_cs2zs(header_value, strlen(header_value)));
                }
        } else {
                array_init(return_value);
-               php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
+               php_http_env_get_response_headers(Z_ARRVAL_P(return_value));
        }
 }
 
@@ -782,7 +764,7 @@ static PHP_METHOD(HttpEnv, getResponseCode)
        if (SUCCESS != zend_parse_parameters_none()) {
                return;
        }
-       RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
+       RETURN_LONG(php_http_env_get_response_code());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseHeader, 0, 0, 1)
@@ -799,7 +781,7 @@ static PHP_METHOD(HttpEnv, setResponseHeader)
        long code = 0;
        zend_bool replace_header = 1;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
                return;
        }
        RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
@@ -810,12 +792,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, setResponseCode)
 {
-       long code;
+       zend_long code;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code)) {
                return;
        }
-       RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC));
+       RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code));
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateLanguage, 0, 0, 1)
@@ -847,7 +829,7 @@ static PHP_METHOD(HttpEnv, negotiateCharset)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
                return;
        }
        if (rs_array) {
@@ -866,7 +848,7 @@ static PHP_METHOD(HttpEnv, negotiateEncoding)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
                return;
        }
        if (rs_array) {
@@ -885,7 +867,7 @@ static PHP_METHOD(HttpEnv, negotiateContentType)
        HashTable *supported;
        zval *rs_array = NULL;
 
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
                return;
        }
        if (rs_array) {
@@ -906,7 +888,7 @@ static PHP_METHOD(HttpEnv, negotiate)
        HashTable *supported, *rs;
        zval *rs_array = NULL;
        char *value_str, *sep_str = NULL;
-       int value_len, sep_len = 0;
+       size_t value_len, sep_len = 0;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) {
                return;
@@ -918,7 +900,7 @@ static PHP_METHOD(HttpEnv, negotiate)
                array_init(rs_array);
        }
 
-       if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len TSRMLS_CC))) {
+       if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len))) {
                PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
        } else {
                PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
@@ -952,36 +934,30 @@ static zend_function_entry php_http_env_methods[] = {
 static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler)
 {
        zval *zarg = arg;
-       char *json_str = NULL;
-       size_t json_len = 0;
+       zend_string *json = NULL;
 
-#if PHP_VERSION_ID >= 50600
        if (SG(request_info).request_body) {
                /* FG(stream_wrappers) not initialized yet, so we cannot use php://input */
                php_stream_rewind(SG(request_info).request_body);
-               json_len = php_stream_copy_to_mem(SG(request_info).request_body, &json_str, PHP_STREAM_COPY_ALL, 0);
+               json = php_stream_copy_to_mem(SG(request_info).request_body, PHP_STREAM_COPY_ALL, 0);
        }
-#else
-       json_str = SG(request_info).raw_post_data;
-       json_len = SG(request_info).raw_post_data_length;
-#endif
 
-       if (json_len) {
-               zval zjson;
+       if (json) {
+               if (json->len) {
+                       zval zjson;
 
-               INIT_ZVAL(zjson);
-               php_json_decode(&zjson, json_str, json_len, 1, PG(max_input_nesting_level) TSRMLS_CC);
-               if (Z_TYPE(zjson) != IS_NULL) {
-                       zval_dtor(zarg);
-                       ZVAL_COPY_VALUE(zarg, (&zjson));
+                       ZVAL_NULL(&zjson);
+                       php_json_decode(&zjson, json->val, json->len, 1, PG(max_input_nesting_level));
+                       if (Z_TYPE(zjson) != IS_NULL) {
+                               zval_dtor(zarg);
+                               ZVAL_COPY_VALUE(zarg, (&zjson));
+                       }
                }
+               zend_string_release(json);
        }
-#if PHP_VERSION_ID >= 50600
-       PTR_FREE(json_str);
-#endif
 }
 
-static void php_http_env_register_json_handler(TSRMLS_D)
+static void php_http_env_register_json_handler(void)
 {
        sapi_post_entry entry = {NULL, 0, NULL, NULL};
 
@@ -990,11 +966,11 @@ static void php_http_env_register_json_handler(TSRMLS_D)
 
        entry.content_type = "text/json";
        entry.content_type_len = lenof("text/json");
-       sapi_register_post_entry(&entry TSRMLS_CC);
+       sapi_register_post_entry(&entry);
 
        entry.content_type = "application/json";
        entry.content_type_len = lenof("application/json");
-       sapi_register_post_entry(&entry TSRMLS_CC);
+       sapi_register_post_entry(&entry);
 }
 #endif
 
@@ -1005,10 +981,10 @@ PHP_MINIT_FUNCTION(http_env)
        zend_class_entry ce = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "http", "Env", php_http_env_methods);
-       php_http_env_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+       php_http_env_class_entry = zend_register_internal_class(&ce);
 
 #ifdef PHP_HTTP_HAVE_JSON
-       php_http_env_register_json_handler(TSRMLS_C);
+       php_http_env_register_json_handler();
 #endif
 
        return SUCCESS;
index 8d2d1bb8507c956f9298b00c3972bb6c687829e2..1cb302d13a3665cd11613e33f06e4765242b37b7 100644 (file)
@@ -37,12 +37,12 @@ typedef enum php_http_range_status {
        PHP_HTTP_RANGE_ERR
 } php_http_range_status_t;
 
-PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t entity_length, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC);
-PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API int php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D);
-PHP_HTTP_API const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_DC);
+PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t entity_length, php_http_message_t *request);
+PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers);
+PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request);
+PHP_HTTP_API zend_bool php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request);
+PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(void);
+PHP_HTTP_API const char *php_http_env_get_request_method(php_http_message_t *request);
 
 typedef enum php_http_content_disposition {
        PHP_HTTP_CONTENT_DISPOSITION_NONE,
@@ -56,20 +56,24 @@ typedef enum php_http_cache_status {
        PHP_HTTP_CACHE_MISS
 } php_http_cache_status_t;
 
-PHP_HTTP_API long php_http_env_get_response_code(TSRMLS_D);
+PHP_HTTP_API long php_http_env_get_response_code(void);
 PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC);
-PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_code(long http_code TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace TSRMLS_DC, const char *fmt, ...);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv TSRMLS_DC);
-
-PHP_HTTP_API zval *php_http_env_get_server_var(const char *key_str, size_t key_len, zend_bool check TSRMLS_DC);
-#define php_http_env_got_server_var(v) (NULL != php_http_env_get_server_var((v), strlen(v), 1 TSRMLS_CC))
-PHP_HTTP_API zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht);
+PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_code(long http_code);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace, const char *fmt, ...);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv);
+
+PHP_HTTP_API zval *php_http_env_get_server_var(const char *key_str, size_t key_len, zend_bool check);
+PHP_HTTP_API zval *php_http_env_get_superglobal(const char *key, size_t key_len);
+
+static inline zend_bool php_http_env_got_server_var(const char *v)
+{
+       return NULL != php_http_env_get_server_var(v, strlen(v), 1);
+}
 
 PHP_HTTP_API zend_class_entry *php_http_env_class_entry;
 PHP_MINIT_FUNCTION(http_env);
index ac0a5e4d23ebe31400f180b4c36512b764736c72..6e2af5379c9ce415583dc561444484f1bf3ba58d 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_ADDREF_P(tmp_name);
+               add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp_name);
+               Z_ADDREF_P(zname);
+               add_assoc_zval_ex(&entry, ZEND_STRL("name"), zname);
+               Z_ADDREF_P(zsize);
+               add_assoc_zval_ex(&entry, ZEND_STRL("size"), zsize);
+               Z_ADDREF_P(ztype);
+               add_assoc_zval_ex(&entry, ZEND_STRL("type"), ztype);
+               Z_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 TSRMLS_DC, 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;
+
+                       SEPARATE_ZVAL(val);
+                       if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("tmp_name")))) {
+                               Z_ADDREF_P(tmp);
+                               add_assoc_zval_ex(val, ZEND_STRL("file"), tmp);
+                               zend_hash_str_del(Z_ARRVAL_P(val), 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, val);
                        } 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, val);
                        }
                }
        }
@@ -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,22 +162,22 @@ static PHP_METHOD(HttpEnvRequest, __construct)
        do {\
                zend_fcall_info fci; \
                zend_fcall_info_cache fcc; \
-               zval *rv, 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 = zend_read_property(Z_OBJCE_P(this_ptr), this_ptr, ZEND_STRL(prop), 0); \
                 \
-               INIT_PZVAL(&mn); \
                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_call(&fci, &fcc, &rv, NULL); \
                zend_fcall_info_args_clear(&fci, 1); \
                efree(args); \
                zval_dtor(&mn); \
-               RETVAL_ZVAL(rv, 0, 1); \
+               RETVAL_ZVAL(&rv, 0, 1); \
        } while(0);
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getForm, 0, 0, 0)
@@ -201,8 +191,8 @@ 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);
-               RETURN_ZVAL(zform, 1, 0);
+               zval *zform = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), 0);
+               RETURN_ZVAL_FAST(zform);
        }
 }
 
@@ -217,8 +207,8 @@ 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);
-               RETURN_ZVAL(zquery, 1, 0);
+               zval *zquery = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), 0);
+               RETURN_ZVAL_FAST(zquery);
        }
 }
 
@@ -233,8 +223,8 @@ 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);
-               RETURN_ZVAL(zcookie, 1, 0);
+               zval *zcookie = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), 0);
+               RETURN_ZVAL_FAST(zcookie);
        }
 }
 
@@ -243,8 +233,8 @@ 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);
-               RETURN_ZVAL(zfiles, 1, 0);
+               zval *zfiles = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), 0);
+               RETURN_ZVAL_FAST(zfiles);
        }
 }
 
@@ -264,12 +254,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;
 }
index 3d8c36d84291832eb00abd2fa2c04b80793a08fd..f9e8c4cb43ce7045679a3963810e5ac06270df9c 100644 (file)
 
 #include "php_http_api.h"
 
-static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len TSRMLS_DC)
+static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len)
 {
        if (Z_TYPE_P(options) == IS_OBJECT) {
                if (value_ptr) {
                        switch (type) {
                                case IS_DOUBLE:
-                                       zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr TSRMLS_CC);
+                                       zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr);
                                        break;
                                case IS_LONG:
-                                       zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(long *)value_ptr TSRMLS_CC);
+                                       zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(zend_long *)value_ptr);
                                        break;
                                case IS_STRING:
-                                       zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len TSRMLS_CC);
+                                       zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len);
                                        break;
                                case IS_ARRAY:
                                case IS_OBJECT:
-                                       zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr TSRMLS_CC);
+                                       zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr);
                                        break;
                        }
                } else {
-                       zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len TSRMLS_CC);
+                       zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len);
                }
        } else {
                convert_to_array(options);
                if (value_ptr) {
                        switch (type) {
                                case IS_DOUBLE:
-                                       add_assoc_double_ex(options, name_str, name_len + 1, *(double *)value_ptr);
+                                       add_assoc_double_ex(options, name_str, name_len, *(double *)value_ptr);
                                        break;
                                case IS_LONG:
-                                       add_assoc_long_ex(options, name_str, name_len + 1, *(long *)value_ptr);
+                                       add_assoc_long_ex(options, name_str, name_len, *(zend_long *)value_ptr);
                                        break;
                                case IS_STRING: {
-                                       char *value = estrndup(value_ptr, value_len);
-                                       add_assoc_stringl_ex(options, name_str, name_len + 1, value, value_len, 0);
+                                       zend_string *value = zend_string_init(value_ptr, value_len, 0);
+                                       add_assoc_str_ex(options, name_str, name_len, value);
                                        break;
                                case IS_ARRAY:
                                case IS_OBJECT:
                                        Z_ADDREF_P(value_ptr);
-                                       add_assoc_zval_ex(options, name_str, name_len + 1, value_ptr);
+                                       add_assoc_zval_ex(options, name_str, name_len, value_ptr);
                                        break;
                                }
                        }
                } else {
-                       add_assoc_null_ex(options, name_str, name_len + 1);
+                       add_assoc_null_ex(options, name_str, name_len);
                }
        }
 }
-static zval *get_option(zval *options, const char *name_str, size_t name_len TSRMLS_DC)
+static zval *get_option(zval *options, const char *name_str, size_t name_len)
 {
-       zval *val, **valptr;
+       zval *val;
 
        if (Z_TYPE_P(options) == IS_OBJECT) {
-               val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0 TSRMLS_CC);
+               val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0);
        } else {
-               if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(options), name_str, name_len + 1, (void *) &valptr)) {
-                       val = *valptr;
-               } else {
-                       val = NULL;
-               }
+               val = zend_symtable_str_find(Z_ARRVAL_P(options), name_str, name_len);
        }
        if (val) {
-               Z_ADDREF_P(val);
+               Z_TRY_ADDREF_P(val);
        }
        return val;
 }
-static php_http_message_body_t *get_body(zval *options TSRMLS_DC)
+static php_http_message_body_t *get_body(zval *options)
 {
        zval *zbody;
        php_http_message_body_t *body = NULL;
 
-       if ((zbody = get_option(options, ZEND_STRL("body") TSRMLS_CC))) {
-               if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) {
-                       php_http_message_body_object_t *body_obj = zend_object_store_get_object(zbody TSRMLS_CC);
+       if ((zbody = get_option(options, ZEND_STRL("body")))) {
+               if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry)) {
+                       php_http_message_body_object_t *body_obj = PHP_HTTP_OBJ(NULL, zbody);
 
                        body = body_obj->body;
                }
-               zval_ptr_dtor(&zbody);
+               zval_ptr_dtor(zbody);
        }
 
        return body;
 }
-static php_http_message_t *get_request(zval *options TSRMLS_DC)
+static php_http_message_t *get_request(zval *options)
 {
        zval *zrequest;
        php_http_message_t *request = NULL;
 
-       if ((zrequest = get_option(options, ZEND_STRL("request") TSRMLS_CC))) {
-               if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry TSRMLS_CC)) {
-                       php_http_message_object_t *request_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
+       if ((zrequest = get_option(options, ZEND_STRL("request")))) {
+               if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry)) {
+                       php_http_message_object_t *request_obj = PHP_HTTP_OBJ(NULL, zrequest);
 
                        request = request_obj->message;
                }
-               zval_ptr_dtor(&zrequest);
+               zval_ptr_dtor(zrequest);
        }
 
        return request;
 }
 static void set_cookie(zval *options, zval *zcookie_new TSRMLS_DC)
 {
-       HashPosition pos;
        zval *zcookies_set;
-       php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
-       php_http_cookie_object_t *obj = zend_object_store_get_object(zcookie_new TSRMLS_CC);
+       php_http_arrkey_t key;
+       php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie_new);
 
-       zcookies_set = get_option(options, ZEND_STRL("cookies") TSRMLS_CC);
+       zcookies_set = get_option(options, ZEND_STRL("cookies"));
        if (!zcookies_set || Z_TYPE_P(zcookies_set) != IS_ARRAY) {
                if (zcookies_set) {
-                       zval_ptr_dtor(&zcookies_set);
+                       zval_ptr_dtor(zcookies_set);
                }
-               MAKE_STD_ZVAL(zcookies_set);
                array_init_size(zcookies_set, zend_hash_num_elements(&obj->list->cookies));
        } else {
-               SEPARATE_ZVAL(&zcookies_set);
+               SEPARATE_ZVAL(zcookies_set);
        }
 
-       FOREACH_HASH_KEY(pos, &obj->list->cookies, key) {
+       ZEND_HASH_FOREACH_KEY(&obj->list->cookies, key.h, key.key)
+       {
                Z_ADDREF_P(zcookie_new);
-               if (key.type == HASH_KEY_IS_STRING) {
-                       add_assoc_zval_ex(zcookies_set, key.str, key.len, zcookie_new);
+               if (key.key) {
+                       add_assoc_zval_ex(zcookies_set, key.key->val, key.key->len, zcookie_new);
                } else {
-                       add_index_zval(zcookies_set, key.num, zcookie_new);
+                       add_index_zval(zcookies_set, key.h, zcookie_new);
                }
        }
+       ZEND_HASH_FOREACH_END();
 
-       set_option(options, ZEND_STRL("cookies"), IS_ARRAY, zcookies_set, 0 TSRMLS_CC);
-       zval_ptr_dtor(&zcookies_set);
+       set_option(options, ZEND_STRL("cookies"), IS_ARRAY, zcookies_set, 0);
+       zval_ptr_dtor(zcookies_set);
 }
 
-php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request)
 {
        php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
-       int free_etag = 0;
-       char *header = NULL, *etag;
+       char *header = NULL, *etag = NULL;
        php_http_message_body_t *body;
        zval *zetag;
 
 
-       if (!(body = get_body(options TSRMLS_CC))) {
+       if (!(body = get_body(options))) {
                return ret;
        }
 
-       if ((zetag = get_option(options, ZEND_STRL("etag") TSRMLS_CC))) {
-               zval *zetag_copy = php_http_ztyp(IS_STRING, zetag);
-               zval_ptr_dtor(&zetag);
-               zetag = zetag_copy;
-       }
-
-       if (zetag && Z_STRLEN_P(zetag)) {
-               etag = Z_STRVAL_P(zetag);
-       } else if ((etag = php_http_message_body_etag(body))) {
-               set_option(options, ZEND_STRL("etag"), IS_STRING, etag, strlen(etag) TSRMLS_CC);
-               free_etag = 1;
+       if ((zetag = get_option(options, ZEND_STRL("etag")))) {
+               zend_string *zs = zval_get_string(zetag);
+               etag = estrndup(zs->val, zs->len);
+               zend_string_release(zs);
+               zval_ptr_dtor(zetag);
        }
 
-       if (zetag) {
-               zval_ptr_dtor(&zetag);
+       if (!etag && (etag = php_http_message_body_etag(body))) {
+               set_option(options, ZEND_STRL("etag"), IS_STRING, etag, strlen(etag));
        }
 
-       if (etag && (header = php_http_env_get_request_header(header_str, header_len, NULL, request TSRMLS_CC))) {
-               ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD)  ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS;
-       }
-
-       if (free_etag) {
-               efree(etag);
+       if (etag && (header = php_http_env_get_request_header(header_str, header_len, NULL, request))) {
+               ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD) ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS;
        }
 
+       PTR_FREE(etag);
        PTR_FREE(header);
+
        return ret;
 }
 
-php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request)
 {
        php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
        char *header;
@@ -191,28 +178,21 @@ php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *o
        php_http_message_body_t *body;
        zval *zlm;
 
-       if (!(body = get_body(options TSRMLS_CC))) {
+       if (!(body = get_body(options))) {
                return ret;
        }
 
-       if ((zlm = get_option(options, ZEND_STRL("lastModified") TSRMLS_CC))) {
-               zval *zlm_copy = php_http_ztyp(IS_LONG, zlm);
-               zval_ptr_dtor(&zlm);
-               zlm = zlm_copy;
+       if ((zlm = get_option(options, ZEND_STRL("lastModified")))) {
+               lm = zval_get_long(zlm);
+               zval_ptr_dtor(zlm);
        }
 
-       if (zlm && Z_LVAL_P(zlm) > 0) {
-               lm = Z_LVAL_P(zlm);
-       } else {
+       if (lm <= 0) {
                lm = php_http_message_body_mtime(body);
-               set_option(options, ZEND_STRL("lastModified"), IS_LONG, &lm, 0 TSRMLS_CC);
-       }
-
-       if (zlm) {
-               zval_ptr_dtor(&zlm);
+               set_option(options, ZEND_STRL("lastModified"), IS_LONG, &lm, 0);
        }
 
-       if ((header = php_http_env_get_request_header(header_str, header_len, NULL, request TSRMLS_CC))) {
+       if ((header = php_http_env_get_request_header(header_str, header_len, NULL, request))) {
                ums = php_parse_date(header, NULL);
 
                if (ums > 0 && ums >= lm) {
@@ -228,24 +208,22 @@ php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *o
 
 static zend_bool php_http_env_response_is_cacheable(php_http_env_response_t *r, php_http_message_t *request)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
-
        if (r->ops->get_status(r) >= 400) {
                return 0;
        }
 
-       if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request TSRMLS_CC)) {
+       if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request)) {
                return 0;
        }
 
-       if (-1 == php_http_select_str(php_http_env_get_request_method(request TSRMLS_CC), 2, "HEAD", "GET")) {
+       if (-1 == php_http_select_str(php_http_env_get_request_method(request), 2, "HEAD", "GET")) {
                return 0;
        }
 
        return 1;
 }
 
-static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
+static size_t output(void *context, char *buf, size_t len)
 {
        php_http_env_response_t *r = context;
 
@@ -262,11 +240,9 @@ static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
        return len;
 }
 
-#define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0)
 static ZEND_RESULT_CODE php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
 {
        size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (r->content.encoder) {
                char *enc_str = NULL;
@@ -285,16 +261,21 @@ static ZEND_RESULT_CODE php_http_env_response_send_data(php_http_env_response_t
                if (!enc_str) {
                        return SUCCESS;
                }
-               chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
+               chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r);
                PTR_FREE(enc_str);
        } else {
-               chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
+               chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r);
        }
 
        return chunks_sent != (size_t) -1 ? SUCCESS : FAILURE;
 }
 
-php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
+static inline ZEND_RESULT_CODE php_http_env_response_send_done(php_http_env_response_t *r)
+{
+       return php_http_env_response_send_data(r, NULL, 0);
+}
+
+php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg)
 {
        zend_bool free_r;
 
@@ -311,10 +292,7 @@ php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r,
 
        r->buffer = php_http_buffer_init(NULL);
 
-       Z_ADDREF_P(options);
-       r->options = options;
-
-       TSRMLS_SET_CTX(r->ts);
+       ZVAL_COPY(&r->options, options);
 
        if (r->ops->init && (SUCCESS != r->ops->init(r, init_arg))) {
                if (free_r) {
@@ -354,62 +332,60 @@ void php_http_env_response_free(php_http_env_response_t **r)
 static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t *r, php_http_message_t *request)
 {
        ZEND_RESULT_CODE ret = SUCCESS;
-       zval *zoption, *options = r->options;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
+       zval *zoption, *options = &r->options;
 
        if (r->done) {
                return ret;
        }
 
-       if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
+       if ((zoption = get_option(options, ZEND_STRL("headers")))) {
                if (Z_TYPE_P(zoption) == IS_ARRAY) {
-                       php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
+                       php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r);
                }
-               zval_ptr_dtor(&zoption);
+               zval_ptr_dtor(zoption);
        }
 
        if (ret != SUCCESS) {
                return ret;
        }
 
-       if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
-               zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
+       if ((zoption = get_option(options, ZEND_STRL("responseCode")))) {
+               zend_long rc = zval_get_long(zoption);
 
-               zval_ptr_dtor(&zoption);
-               if (Z_LVAL_P(zoption_copy) > 0) {
-                       ret = r->ops->set_status(r, Z_LVAL_P(zoption_copy));
+               zval_ptr_dtor(zoption);
+               if (rc > 0) {
+                       ret = r->ops->set_status(r, rc);
                }
-               zval_ptr_dtor(&zoption_copy);
        }
 
        if (ret != SUCCESS) {
                return ret;
        }
 
-       if ((zoption = get_option(options, ZEND_STRL("httpVersion") TSRMLS_CC))) {
+       if ((zoption = get_option(options, ZEND_STRL("httpVersion")))) {
                php_http_version_t v;
-               zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+               zend_string *zs = zval_get_string(zoption);
 
-               zval_ptr_dtor(&zoption);
-               if (Z_STRLEN_P(zoption_copy) && php_http_version_parse(&v, Z_STRVAL_P(zoption_copy) TSRMLS_CC)) {
+               zval_ptr_dtor(zoption);
+               if (zs->len && php_http_version_parse(&v, zs->val)) {
                        ret = r->ops->set_protocol_version(r, &v);
                        php_http_version_dtor(&v);
                }
-               zval_ptr_dtor(&zoption_copy);
+               zend_string_release(zs);
        }
 
        if (ret != SUCCESS) {
                return ret;
        }
 
-       if ((zoption = get_option(options, ZEND_STRL("cookies") TSRMLS_CC))) {
+       if ((zoption = get_option(options, ZEND_STRL("cookies")))) {
                if (Z_TYPE_P(zoption) == IS_ARRAY) {
-                       HashPosition pos;
-                       zval **zcookie;
+                       zval *zcookie;
 
-                       FOREACH_VAL(pos, zoption, zcookie) {
-                               if (Z_TYPE_PP(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(zcookie), php_http_cookie_class_entry TSRMLS_CC)) {
-                                       php_http_cookie_object_t *obj = zend_object_store_get_object(*zcookie TSRMLS_CC);
+                       ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zoption), zcookie)
+                       {
+                               if (Z_TYPE_P(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_class_entry)) {
+                                       php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie);
                                        char *str;
                                        size_t len;
 
@@ -421,24 +397,25 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                                        efree(str);
                                }
                        }
+                       ZEND_HASH_FOREACH_END();
                }
-               zval_ptr_dtor(&zoption);
+               zval_ptr_dtor(zoption);
        }
 
        if (ret != SUCCESS) {
                return ret;
        }
 
-       if ((zoption = get_option(options, ZEND_STRL("contentType") TSRMLS_CC))) {
-               zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+       if ((zoption = get_option(options, ZEND_STRL("contentType")))) {
+               zend_string *zs = zval_get_string(zoption);
 
-               zval_ptr_dtor(&zoption);
-               if (Z_STRLEN_P(zoption_copy) && strchr(Z_STRVAL_P(zoption_copy), '/')) {
-                       if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) {
-                               r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy));
+               zval_ptr_dtor(zoption);
+               if (zs->len && strchr(zs->val, '/')) {
+                       if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", zs->len, zs->val))) {
+                               r->content.type = estrndup(zs->val, zs->len);
                        }
                }
-               zval_ptr_dtor(&zoption_copy);
+               zend_string_release(zs);
        }
 
        if (ret != SUCCESS) {
@@ -447,13 +424,13 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
 
        if (r->range.status == PHP_HTTP_RANGE_OK) {
                if (zend_hash_num_elements(&r->range.values) == 1) {
-                       zval **range, **begin, **end;
+                       zval *range, *begin, *end;
 
-                       if (    1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range)
-                               &&      2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
+                       if (    1 == php_http_array_list(&r->range.values, 1, &range)
+                               &&      2 == php_http_array_list(Z_ARRVAL_P(range), 2, &begin, &end)
                        ) {
                                if (SUCCESS == (ret = r->ops->set_status(r, 206))) {
-                                       ret = r->ops->set_header(r, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), r->content.length);
+                                       ret = r->ops->set_header(r, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_P(begin), Z_LVAL_P(end), r->content.length);
                                }
                        } else {
                                /* this should never happen */
@@ -461,77 +438,82 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                                ret = FAILURE;
                        }
                } else {
-                       php_http_boundary(r->range.boundary, sizeof(r->range.boundary) TSRMLS_CC);
+                       php_http_boundary(r->range.boundary, sizeof(r->range.boundary));
                        if (SUCCESS == (ret = r->ops->set_status(r, 206))) {
                                ret = r->ops->set_header(r, "Content-Type: multipart/byteranges; boundary=%s", r->range.boundary);
                        }
                }
        } else {
-               if ((zoption = get_option(options, ZEND_STRL("cacheControl") TSRMLS_CC))) {
-                       zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+               if ((zoption = get_option(options, ZEND_STRL("cacheControl")))) {
+                       zend_string *zs = zval_get_string(zoption);
 
-                       zval_ptr_dtor(&zoption);
-                       if (Z_STRLEN_P(zoption_copy)) {
-                               ret = r->ops->set_header(r, "Cache-Control: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy));
+                       zval_ptr_dtor(zoption);
+                       if (zs->len) {
+                               ret = r->ops->set_header(r, "Cache-Control: %.*s", zs->len, zs->val);
                        }
-                       zval_ptr_dtor(&zoption_copy);
+                       zend_string_release(zs);
                }
 
                if (ret != SUCCESS) {
                        return ret;
                }
 
-               if ((zoption = get_option(options, ZEND_STRL("contentDisposition") TSRMLS_CC))) {
-                       zval *zoption_copy = php_http_ztyp(IS_ARRAY, zoption);
+               if ((zoption = get_option(options, ZEND_STRL("contentDisposition")))) {
                        php_http_buffer_t buf;
 
+                       if (Z_TYPE_P(zoption) != IS_ARRAY) {
+                               zval *tmp = zoption;
+                               SEPARATE_ZVAL(tmp);
+                               convert_to_array(tmp);
+                               zval_ptr_dtor(zoption);
+                               zoption = tmp;
+                       }
+
                        php_http_buffer_init(&buf);
-                       if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption_copy), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC)) {
+                       if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT)) {
                                if (buf.used) {
                                        ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data);
                                }
                        }
 
                        php_http_buffer_dtor(&buf);
-                       zval_ptr_dtor(&zoption_copy);
-                       zval_ptr_dtor(&zoption);
+                       zval_ptr_dtor(zoption);
                }
 
                if (ret != SUCCESS) {
                        return ret;
                }
 
-               if ((zoption = get_option(options, ZEND_STRL("contentEncoding") TSRMLS_CC))) {
-                       zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
+               if ((zoption = get_option(options, ZEND_STRL("contentEncoding")))) {
+                       zend_long ce = zval_get_long(zoption);
                        zval zsupported;
                        HashTable *result = NULL;
 
-                       zval_ptr_dtor(&zoption);
-                       switch (Z_LVAL_P(zoption_copy)) {
+                       zval_ptr_dtor(zoption);
+                       switch (ce) {
                                case PHP_HTTP_CONTENT_ENCODING_GZIP:
-                                       INIT_PZVAL(&zsupported);
                                        array_init(&zsupported);
-                                       add_next_index_stringl(&zsupported, ZEND_STRL("none"), 1);
-                                       add_next_index_stringl(&zsupported, ZEND_STRL("gzip"), 1);
-                                       add_next_index_stringl(&zsupported, ZEND_STRL("deflate"), 1);
+                                       add_next_index_stringl(&zsupported, ZEND_STRL("none"));
+                                       add_next_index_stringl(&zsupported, ZEND_STRL("gzip"));
+                                       add_next_index_stringl(&zsupported, ZEND_STRL("deflate"));
 
-                                       if ((result = php_http_negotiate_encoding(Z_ARRVAL(zsupported), request TSRMLS_CC))) {
-                                               char *key_str = NULL;
-                                               uint key_len = 0;
+                                       if ((result = php_http_negotiate_encoding(Z_ARRVAL(zsupported), request))) {
+                                               zend_string *key_str = NULL;
+                                               zend_ulong index = 0;
 
                                                zend_hash_internal_pointer_reset(result);
-                                               if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key_str, &key_len, NULL, 0, NULL)) {
-                                                       if (!strcmp(key_str, "gzip")) {
-                                                               if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC))) {
+                                               if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key_str, &index, NULL)) {
+                                                       if (zend_string_equals_literal(key_str, "gzip")) {
+                                                               if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP))) {
                                                                        ret = FAILURE;
                                                                } else if (SUCCESS == (ret = r->ops->set_header(r, "Content-Encoding: gzip"))) {
-                                                                       r->content.encoding = estrndup(key_str, key_len - 1);
+                                                                       r->content.encoding = estrndup(key_str->val, key_str->len);
                                                                }
-                                                       } else if (!strcmp(key_str, "deflate")) {
-                                                               if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC))) {
+                                                       } else if (zend_string_equals_literal(key_str, "deflate")) {
+                                                               if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB))) {
                                                                        ret = FAILURE;
                                                                } else if (SUCCESS == (ret = r->ops->set_header(r, "Content-Encoding: deflate"))) {
-                                                                       r->content.encoding = estrndup(key_str, key_len - 1);
+                                                                       r->content.encoding = estrndup(key_str->val, key_str->len);
                                                                }
                                                        } else {
                                                                ret = r->ops->del_header(r, ZEND_STRL("Content-Encoding"));
@@ -554,7 +536,6 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                                        ret = r->ops->del_header(r, ZEND_STRL("Content-Encoding"));
                                        break;
                        }
-                       zval_ptr_dtor(&zoption_copy);
                }
 
                if (SUCCESS != ret) {
@@ -562,12 +543,12 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                }
 
                if (php_http_env_response_is_cacheable(r, request)) {
-                       switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"), request TSRMLS_CC)) {
+                       switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"), request)) {
                                case PHP_HTTP_CACHE_MISS:
                                        break;
 
                                case PHP_HTTP_CACHE_NO:
-                                       if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since"), request TSRMLS_CC)) {
+                                       if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since"), request)) {
                                                break;
                                        }
                                        /*  no break */
@@ -578,29 +559,28 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                                        break;
                        }
 
-                       if ((zoption = get_option(options, ZEND_STRL("etag") TSRMLS_CC))) {
-                               zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+                       if ((zoption = get_option(options, ZEND_STRL("etag")))) {
+                               zend_string *zs = zval_get_string(zoption);
 
-                               zval_ptr_dtor(&zoption);
-                               if (*Z_STRVAL_P(zoption_copy) != '"' && strncmp(Z_STRVAL_P(zoption_copy), "W/\"", 3)) {
-                                       ret = r->ops->set_header(r, "ETag: \"%s\"", Z_STRVAL_P(zoption_copy));
+                               zval_ptr_dtor(zoption);
+                               if (*zs->val != '"' && strncmp(zs->val, "W/\"", 3)) {
+                                       ret = r->ops->set_header(r, "ETag: \"%s\"", zs->val);
                                } else {
-                                       ret = r->ops->set_header(r, "ETag: %s", Z_STRVAL_P(zoption_copy));
+                                       ret = r->ops->set_header(r, "ETag: %s", zs->val);
                                }
-                               zval_ptr_dtor(&zoption_copy);
+                               zend_string_release(zs);
                        }
                        if ((zoption = get_option(options, ZEND_STRL("lastModified") TSRMLS_CC))) {
-                               zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
+                               zend_long lm = zval_get_long(zoption);
 
-                               zval_ptr_dtor(&zoption);
-                               if (Z_LVAL_P(zoption_copy)) {
-                                       char *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), Z_LVAL_P(zoption_copy), 0 TSRMLS_CC);
+                               zval_ptr_dtor(zoption);
+                               if (lm) {
+                                       zend_string *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), lm, 0);
                                        if (date) {
-                                               ret = r->ops->set_header(r, "Last-Modified: %s", date);
-                                               efree(date);
+                                               ret = r->ops->set_header(r, "Last-Modified: %s", date->val);
+                                               zend_string_release(date);
                                        }
                                }
-                               zval_ptr_dtor(&zoption_copy);
                        }
                }
        }
@@ -613,36 +593,31 @@ static ZEND_RESULT_CODE php_http_env_response_send_body(php_http_env_response_t
        ZEND_RESULT_CODE ret = SUCCESS;
        zval *zoption;
        php_http_message_body_t *body;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (r->done) {
                return ret;
        }
 
-       if ((body = get_body(r->options TSRMLS_CC))) {
-               if ((zoption = get_option(r->options, ZEND_STRL("throttleDelay") TSRMLS_CC))) {
-                       if (Z_TYPE_P(zoption) == IS_DOUBLE) {
-                               r->throttle.delay =  Z_DVAL_P(zoption);
-                       }
-                       zval_ptr_dtor(&zoption);
+       if ((body = get_body(&r->options))) {
+               if ((zoption = get_option(&r->options, ZEND_STRL("throttleDelay")))) {
+                       r->throttle.delay = zval_get_double(zoption);
+                       zval_ptr_dtor(zoption);
                }
-               if ((zoption = get_option(r->options, ZEND_STRL("throttleChunk") TSRMLS_CC))) {
-                       if (Z_TYPE_P(zoption) == IS_LONG) {
-                               r->throttle.chunk = Z_LVAL_P(zoption);
-                       }
-                       zval_ptr_dtor(&zoption);
+               if ((zoption = get_option(&r->options, ZEND_STRL("throttleChunk") TSRMLS_CC))) {
+                       r->throttle.chunk = zval_get_long(zoption);
+                       zval_ptr_dtor(zoption);
                }
 
                if (r->range.status == PHP_HTTP_RANGE_OK) {
                        if (zend_hash_num_elements(&r->range.values) == 1) {
                                /* single range */
-                               zval **range, **begin, **end;
+                               zval *range, *begin, *end;
 
-                               if (    1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range)
-                                       &&      2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
+                               if (    1 == php_http_array_list(&r->range.values, 1, &range)
+                                       &&      2 == php_http_array_list(Z_ARRVAL_P(range), 2, &begin, &end)
                                ) {
                                        /* send chunk */
-                                       ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+                                       ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_P(begin), Z_LVAL_P(end) - Z_LVAL_P(begin) + 1);
                                        if (ret == SUCCESS) {
                                                ret = php_http_env_response_send_done(r);
                                        }
@@ -656,13 +631,13 @@ static ZEND_RESULT_CODE php_http_env_response_send_body(php_http_env_response_t
 
                        } else {
                                /* send multipart/byte-ranges message */
-                               HashPosition pos;
-                               zval **chunk;
+                               zval *chunk;
 
-                               FOREACH_HASH_VAL(pos, &r->range.values, chunk) {
-                                       zval **begin, **end;
+                               ZEND_HASH_FOREACH_VAL(&r->range.values, chunk)
+                               {
+                                       zval *begin, *end;
 
-                                       if (2 == php_http_array_list(Z_ARRVAL_PP(chunk) TSRMLS_CC, 2, &begin, &end)) {
+                                       if (2 == php_http_array_list(Z_ARRVAL_P(chunk), 2, &begin, &end)) {
                                                php_http_buffer_appendf(r->buffer,
                                                                PHP_HTTP_CRLF
                                                                "--%s" PHP_HTTP_CRLF
@@ -671,13 +646,14 @@ static ZEND_RESULT_CODE php_http_env_response_send_body(php_http_env_response_t
                                                                /* - */
                                                                r->range.boundary,
                                                                r->content.type ? r->content.type : "application/octet-stream",
-                                                               Z_LVAL_PP(begin),
-                                                               Z_LVAL_PP(end),
+                                                               Z_LVAL_P(begin),
+                                                               Z_LVAL_P(end),
                                                                r->content.length
                                                );
-                                               ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+                                               ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_P(begin), Z_LVAL_P(end) - Z_LVAL_P(begin) + 1);
                                        }
                                }
+                               ZEND_HASH_FOREACH_END();
 
                                if (ret == SUCCESS) {
                                        php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary);
@@ -700,19 +676,18 @@ ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r)
 {
        php_http_message_t *request;
        php_http_message_body_t *body;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
-       request = get_request(r->options TSRMLS_CC);
+       request = get_request(&r->options);
 
        /* check for ranges */
-       if ((body = get_body(r->options TSRMLS_CC))) {
+       if ((body = get_body(&r->options))) {
                r->content.length = php_http_message_body_size(body);
 
                if (SUCCESS != r->ops->set_header(r, "Accept-Ranges: bytes")) {
                        return FAILURE;
                } else {
-                       zend_hash_init(&r->range.values, 0, NULL, ZVAL_PTR_DTOR, 0);
-                       r->range.status = php_http_env_get_request_ranges(&r->range.values, r->content.length, request TSRMLS_CC);
+                       ZEND_INIT_SYMTABLE_EX(&r->range.values, 0, 0);
+                       r->range.status = php_http_env_get_request_ranges(&r->range.values, r->content.length, request);
 
                        switch (r->range.status) {
                                case PHP_HTTP_RANGE_NO:
@@ -720,7 +695,7 @@ ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r)
                                        break;
 
                                case PHP_HTTP_RANGE_ERR:
-                                       if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request TSRMLS_CC)) {
+                                       if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request)) {
                                                r->range.status = PHP_HTTP_RANGE_NO;
                                                zend_hash_destroy(&r->range.values);
                                        } else {
@@ -736,16 +711,16 @@ ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r)
                                        break;
 
                                case PHP_HTTP_RANGE_OK:
-                                       if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(r->options, ZEND_STRL("If-Range"), request TSRMLS_CC)
-                                       ||      PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("If-Range"), request TSRMLS_CC)
+                                       if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(&r->options, ZEND_STRL("If-Range"), request)
+                                       ||      PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("If-Range"), request)
                                        ) {
                                                r->range.status = PHP_HTTP_RANGE_NO;
                                                zend_hash_destroy(&r->range.values);
                                                break;
                                        }
-                                       if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(r->options, ZEND_STRL("If-Match"), request TSRMLS_CC)
-                                       ||      PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("If-Unmodified-Since"), request TSRMLS_CC)
-                                       ||      PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("Unless-Modified-Since"), request TSRMLS_CC)
+                                       if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(&r->options, ZEND_STRL("If-Match"), request)
+                                       ||      PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("If-Unmodified-Since"), request)
+                                       ||      PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("Unless-Modified-Since"), request)
                                        ) {
                                                r->done = 1;
                                                zend_hash_destroy(&r->range.values);
@@ -761,17 +736,17 @@ ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r)
        }
 
        if (SUCCESS != php_http_env_response_send_head(r, request)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response headers");
+               php_error_docref(NULL, E_WARNING, "Failed to send response headers");
                return FAILURE;
        }
 
        if (SUCCESS != php_http_env_response_send_body(r)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response body");
+               php_error_docref(NULL, E_WARNING, "Failed to send response body");
                return FAILURE;
        }
 
        if (SUCCESS != r->ops->finish(r)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish response");
+               php_error_docref(NULL, E_WARNING, "Failed to finish response");
                return FAILURE;
        }
 
@@ -780,30 +755,24 @@ ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r)
 
 static long php_http_env_response_sapi_get_status(php_http_env_response_t *r)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
-
-       return php_http_env_get_response_code(TSRMLS_C);
+       return php_http_env_get_response_code();
 }
 static ZEND_RESULT_CODE php_http_env_response_sapi_set_status(php_http_env_response_t *r, long http_code)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
-
-       return php_http_env_set_response_code(http_code TSRMLS_CC);
+       return php_http_env_set_response_code(http_code);
 }
 static ZEND_RESULT_CODE php_http_env_response_sapi_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
-       return php_http_env_set_response_protocol_version(v TSRMLS_CC);
+       return php_http_env_set_response_protocol_version(v);
 }
 static ZEND_RESULT_CODE php_http_env_response_sapi_set_header(php_http_env_response_t *r, const char *fmt, ...)
 {
        ZEND_RESULT_CODE ret;
        va_list args;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        va_start(args, fmt);
-       ret = php_http_env_set_response_header_va(0, 1, fmt, args TSRMLS_CC);
+       ret = php_http_env_set_response_header_va(0, 1, fmt, args);
        va_end(args);
 
        return ret;
@@ -812,24 +781,19 @@ static ZEND_RESULT_CODE php_http_env_response_sapi_add_header(php_http_env_respo
 {
        ZEND_RESULT_CODE ret;
        va_list args;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        va_start(args, fmt);
-       ret = php_http_env_set_response_header_va(0, 0, fmt, args TSRMLS_CC);
+       ret = php_http_env_set_response_header_va(0, 0, fmt, args);
        va_end(args);
 
        return ret;
 }
 static ZEND_RESULT_CODE php_http_env_response_sapi_del_header(php_http_env_response_t *r, const char *header_str, size_t header_len)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
-
-       return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1 TSRMLS_CC);
+       return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1);
 }
 static ZEND_RESULT_CODE php_http_env_response_sapi_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
-
        if (0 < PHPWRITE(data_str, data_len)) {
                return SUCCESS;
        }
@@ -837,19 +801,12 @@ static ZEND_RESULT_CODE php_http_env_response_sapi_write(php_http_env_response_t
 }
 static ZEND_RESULT_CODE php_http_env_response_sapi_flush(php_http_env_response_t *r)
 {
-       TSRMLS_FETCH_FROM_CTX(r->ts);
-
-#if PHP_VERSION_ID >= 50400
-       if (php_output_get_level(TSRMLS_C)) {
-               php_output_flush_all(TSRMLS_C);
+       if (php_output_get_level()) {
+               php_output_flush_all();
        }
-       if (!(php_output_get_status(TSRMLS_C) & PHP_OUTPUT_IMPLICITFLUSH)) {
-               sapi_flush(TSRMLS_C);
+       if (!(php_output_get_status() & PHP_OUTPUT_IMPLICITFLUSH)) {
+               sapi_flush();
        }
-#else
-       php_end_ob_buffer(1, 1 TSRMLS_CC);
-       sapi_flush(TSRMLS_C);
-#endif
 
        return SUCCESS;
 }
@@ -891,17 +848,13 @@ typedef struct php_http_env_response_stream_ctx {
 static ZEND_RESULT_CODE php_http_env_response_stream_init(php_http_env_response_t *r, void *init_arg)
 {
        php_http_env_response_stream_ctx_t *ctx;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        ctx = ecalloc(1, sizeof(*ctx));
 
        ctx->stream = init_arg;
-       if (SUCCESS != zend_list_addref(ctx->stream->rsrc_id)) {
-               efree(ctx);
-               return FAILURE;
-       }
-       zend_hash_init(&ctx->header, 0, NULL, ZVAL_PTR_DTOR, 0);
-       php_http_version_init(&ctx->version, 1, 1 TSRMLS_CC);
+       ++GC_REFCOUNT(ctx->stream->res);
+       ZEND_INIT_SYMTABLE(&ctx->header);
+       php_http_version_init(&ctx->version, 1, 1);
        ctx->status_code = 200;
 
        r->ctx = ctx;
@@ -911,38 +864,38 @@ static ZEND_RESULT_CODE php_http_env_response_stream_init(php_http_env_response_
 static void php_http_env_response_stream_dtor(php_http_env_response_t *r)
 {
        php_http_env_response_stream_ctx_t *ctx = r->ctx;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        zend_hash_destroy(&ctx->header);
-       zend_list_delete(ctx->stream->rsrc_id);
+       zend_list_delete(ctx->stream->res);
        efree(ctx);
        r->ctx = NULL;
 }
-static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t *ctx, HashTable *header TSRMLS_DC)
+static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t *ctx, HashTable *header)
 {
-       HashPosition pos;
-       zval **val;
+       zval *val;
 
-       FOREACH_HASH_VAL(pos, header, val) {
-               if (Z_TYPE_PP(val) == IS_ARRAY) {
-                       php_http_env_response_stream_header(ctx, Z_ARRVAL_PP(val) TSRMLS_CC);
+       ZEND_HASH_FOREACH_VAL(header, val)
+       {
+               if (Z_TYPE_P(val) == IS_ARRAY) {
+                       php_http_env_response_stream_header(ctx, Z_ARRVAL_P(val));
                } else {
-                       zval *tmp = php_http_ztyp(IS_STRING, *val);
+                       zend_string *zs = zval_get_string(val);
 
-                       php_stream_write(ctx->stream, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+                       php_stream_write(ctx->stream, zs->val, zs->len);
                        php_stream_write_string(ctx->stream, PHP_HTTP_CRLF);
-                       zval_ptr_dtor(&tmp);
+                       zend_string_release(zs);
                }
        }
+       ZEND_HASH_FOREACH_END();
 }
-static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx TSRMLS_DC)
+static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx)
 {
        if (ctx->started || ctx->finished) {
                return FAILURE;
        }
 
        php_stream_printf(ctx->stream TSRMLS_CC, "HTTP/%u.%u %ld %s" PHP_HTTP_CRLF, ctx->version.major, ctx->version.minor, ctx->status_code, php_http_env_get_response_status_for_code(ctx->status_code));
-       php_http_env_response_stream_header(ctx, &ctx->header TSRMLS_CC);
+       php_http_env_response_stream_header(ctx, &ctx->header);
        php_stream_write_string(ctx->stream, PHP_HTTP_CRLF);
        ctx->started = 1;
        return SUCCESS;
@@ -982,7 +935,7 @@ static ZEND_RESULT_CODE php_http_env_response_stream_set_header_ex(php_http_env_
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
        char *header_end, *header_str = NULL;
        size_t header_len = 0;
-       zval *zheader, **zheader_ptr;
+       zval zheader, *zheader_ptr;
 
        if (stream_ctx->started || stream_ctx->finished) {
                return FAILURE;
@@ -997,16 +950,14 @@ static ZEND_RESULT_CODE php_http_env_response_stream_set_header_ex(php_http_env_
 
        *header_end = '\0';
 
-       if (!replace && (SUCCESS == zend_hash_find(&stream_ctx->header, header_str, header_end - header_str + 1, (void *) &zheader_ptr))) {
-               convert_to_array(*zheader_ptr);
+       if (!replace && (zheader_ptr = zend_hash_str_find(&stream_ctx->header, header_str, header_end - header_str))) {
+               convert_to_array(zheader_ptr);
                *header_end = ':';
-               return add_next_index_stringl(*zheader_ptr, header_str, header_len, 0);
+               return add_next_index_str(zheader_ptr, php_http_cs2zs(header_str, header_len));
        } else {
-               MAKE_STD_ZVAL(zheader);
-               ZVAL_STRINGL(zheader, header_str, header_len, 0);
+               ZVAL_STR(&zheader, php_http_cs2zs(header_str, header_len));
 
-               if (SUCCESS != zend_hash_update(&stream_ctx->header, header_str, header_end - header_str + 1, (void *) &zheader, sizeof(zval *), NULL)) {
-                       zval_ptr_dtor(&zheader);
+               if (SUCCESS != zend_hash_str_update(&stream_ctx->header, header_str, header_end - header_str, &zheader)) {
                        return FAILURE;
                }
 
@@ -1044,19 +995,18 @@ static ZEND_RESULT_CODE php_http_env_response_stream_del_header(php_http_env_res
                return FAILURE;
        }
 
-       zend_hash_del(&stream_ctx->header, header_str, header_len + 1);
+       zend_hash_str_del(&stream_ctx->header, header_str, header_len);
        return SUCCESS;
 }
 static ZEND_RESULT_CODE php_http_env_response_stream_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (stream_ctx->finished) {
                return FAILURE;
        }
        if (!stream_ctx->started) {
-               if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+               if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
                        return FAILURE;
                }
        }
@@ -1070,13 +1020,12 @@ static ZEND_RESULT_CODE php_http_env_response_stream_write(php_http_env_response
 static ZEND_RESULT_CODE php_http_env_response_stream_flush(php_http_env_response_t *r)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (stream_ctx->finished) {
                return FAILURE;
        }
        if (!stream_ctx->started) {
-               if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+               if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
                        return FAILURE;
                }
        }
@@ -1086,13 +1035,12 @@ static ZEND_RESULT_CODE php_http_env_response_stream_flush(php_http_env_response
 static ZEND_RESULT_CODE php_http_env_response_stream_finish(php_http_env_response_t *r)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
-       TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (stream_ctx->finished) {
                return FAILURE;
        }
        if (!stream_ctx->started) {
-               if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+               if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
                        return FAILURE;
                }
        }
@@ -1124,7 +1072,7 @@ php_http_env_response_ops_t *php_http_env_response_get_stream_ops(void)
 #define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \
        do { \
                if (!obj->message) { \
-                       obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE TSRMLS_CC); \
+                       obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE); \
                } \
        } while (0)
 
@@ -1136,9 +1084,9 @@ static PHP_METHOD(HttpEnvResponse, __construct)
 
        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());
 
-       php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC), unexpected_val, return);
+       php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE), unexpected_val, return);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1)
@@ -1148,21 +1096,17 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, __invoke)
 {
        char *ob_str;
-       int ob_len;
-       long ob_flags = 0;
+       size_t ob_len;
+       zend_long ob_flags = 0;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ob_str, &ob_len, &ob_flags)) {
-               php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &ob_str, &ob_len, &ob_flags)) {
+               php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
 
                PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
 
                php_http_message_object_init_body_object(obj);
                php_http_message_body_append(obj->message->body, ob_str, ob_len);
-#if PHP_VERSION_ID >= 50400
                RETURN_TRUE;
-#else
-               RETURN_EMPTY_STRING();
-#endif
        }
 }
 
@@ -1173,10 +1117,10 @@ static PHP_METHOD(HttpEnvResponse, setEnvRequest)
 {
        zval *env_req = NULL;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req, php_http_message_class_entry), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType, 0, 0, 1)
@@ -1185,12 +1129,12 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setContentType)
 {
        char *ct_str = NULL;
-       int ct_len = 0;
+       size_t ct_len = 0;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &ct_str, &ct_len), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition, 0, 0, 1)
@@ -1200,10 +1144,10 @@ static PHP_METHOD(HttpEnvResponse, setContentDisposition)
 {
        zval *zdisposition;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zdisposition), invalid_arg, return);
 
-       zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1)
@@ -1211,12 +1155,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setContentEncoding)
 {
-       long ce;
+       zend_long ce;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ce), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl, 0, 0, 1)
@@ -1225,12 +1169,12 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setCacheControl)
 {
        char *cc_str = NULL;
-       int cc_len = 0;
+       size_t cc_len = 0;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &cc_str, &cc_len), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified, 0, 0, 1)
@@ -1238,12 +1182,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setLastModified)
 {
-       long last_modified;
+       zend_long last_modified;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &last_modified), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByLastModified, 0, 0, 0)
@@ -1252,15 +1196,15 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, isCachedByLastModified)
 {
        char *header_name_str = NULL;
-       int header_name_len = 0;
+       size_t header_name_len = 0;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
                if (!header_name_str || !header_name_len) {
                        header_name_str = "If-Modified-Since";
                        header_name_len = lenof("If-Modified-Since");
                }
 
-               RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC));
+               RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis())));
        }
 }
 
@@ -1270,12 +1214,12 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setEtag)
 {
        char *etag_str = NULL;
-       int etag_len = 0;
+       size_t etag_len = 0;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &etag_str, &etag_len), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByEtag, 0, 0, 0)
@@ -1284,14 +1228,14 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, isCachedByEtag)
 {
        char *header_name_str = NULL;
-       int header_name_len = 0;
+       size_t header_name_len = 0;
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
                if (!header_name_str || !header_name_len) {
                        header_name_str = "If-None-Match";
                        header_name_len = lenof("If-None-Match");
                }
-               RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC));
+               RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis())));
        }
 }
 
@@ -1301,14 +1245,14 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setThrottleRate, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setThrottleRate)
 {
-       long chunk_size;
+       zend_long chunk_size;
        double delay = 1;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l|d", &chunk_size, &delay), invalid_arg, return);
 
-       set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
-       set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
-       RETVAL_ZVAL(getThis(), 1, 0);
+       set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0);
+       set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCookie, 0, 0, 1)
@@ -1316,39 +1260,39 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCookie, 0, 0, 1)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnvResponse, setCookie)
 {
-       zval *zcookie_new;
+       zval *zcookie_new, tmp;
+       zend_string *zs;
        zend_error_handling zeh;
        php_http_cookie_list_t *list = NULL;
 
-       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcookie_new), invalid_arg, return);
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcookie_new), invalid_arg, return);
 
-       zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC);
+       zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh);
        switch (Z_TYPE_P(zcookie_new)) {
        case IS_OBJECT:
-               if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_class_entry TSRMLS_CC)) {
+               if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_class_entry)) {
                        Z_ADDREF_P(zcookie_new);
                        break;
                }
                /* no break */
        case IS_ARRAY:
-               list = php_http_cookie_list_from_struct(NULL, zcookie_new TSRMLS_CC);
-               MAKE_STD_ZVAL(zcookie_new);
-               ZVAL_OBJVAL(zcookie_new, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
+               list = php_http_cookie_list_from_struct(NULL, zcookie_new);
+               zcookie_new = &tmp;
+               ZVAL_OBJ(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo);
                break;
 
        default:
-               zcookie_new = php_http_ztyp(IS_STRING, zcookie_new);
-               list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(zcookie_new), Z_STRLEN_P(zcookie_new), 0, NULL TSRMLS_CC);
-               zval_ptr_dtor(&zcookie_new);
-               MAKE_STD_ZVAL(zcookie_new);
-               ZVAL_OBJVAL(zcookie_new, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
+               zs = zval_get_string(zcookie_new);
+               list = php_http_cookie_list_parse(NULL, zs->val, zs->len, 0, NULL);
+               zcookie_new = &tmp;
+               ZVAL_OBJ(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo);
        }
-       zend_restore_error_handling(&zeh TSRMLS_CC);
+       zend_restore_error_handling(&zeh);
 
-       set_cookie(getThis(), zcookie_new TSRMLS_CC);
-       zval_ptr_dtor(&zcookie_new);
+       set_cookie(getThis(), zcookie_new);
+       zval_ptr_dtor(zcookie_new);
 
-       RETVAL_ZVAL(getThis(), 1, 0);
+       RETVAL_ZVAL_FAST(getThis());
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_send, 0, 0, 0)
@@ -1359,19 +1303,16 @@ static PHP_METHOD(HttpEnvResponse, send)
        zval *zstream = NULL;
        php_stream *s = NULL;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &zstream)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &zstream)) {
                /* first flush the output layer to avoid conflicting headers and output;
                 * also, ob_start($thisEnvResponse) might have been called */
-#if PHP_VERSION_ID >= 50400
-               php_output_end_all(TSRMLS_C);
-#else
-               php_end_ob_buffers(1 TSRMLS_CC);
-#endif
+               php_output_end_all();
+
                if (zstream) {
                        php_http_env_response_t *r;
 
-                       php_stream_from_zval(s, &zstream);
-                       r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s TSRMLS_CC);
+                       php_stream_from_zval(s, zstream);
+                       r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s);
                        if (!r) {
                                RETURN_FALSE;
                        }
@@ -1381,7 +1322,7 @@ static PHP_METHOD(HttpEnvResponse, send)
                } else {
                        php_http_env_response_t r;
 
-                       if (!php_http_env_response_init(&r, getThis(), NULL, NULL TSRMLS_CC)) {
+                       if (!php_http_env_response_init(&r, getThis(), NULL, NULL)) {
                                RETURN_FALSE;
                        }
 
@@ -1416,25 +1357,25 @@ PHP_MINIT_FUNCTION(http_env_response)
        zend_class_entry ce = {0};
 
        INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Response", php_http_env_response_methods);
-       php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
-
-       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP TSRMLS_CC);
-
-       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS TSRMLS_CC);
-
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("request"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED TSRMLS_CC);
-       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED TSRMLS_CC);
+       php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry);
+
+       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE);
+       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP);
+
+       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO);
+       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT);
+       zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS);
+
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("request"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED);
+       zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED);
 
        return SUCCESS;
 }
index e6a112f5417fba84fc390f78b82a266372bdbb6d..ae1441d37fab8032ba577c14088bbbf4218ce051 100644 (file)
@@ -38,7 +38,7 @@ struct php_http_env_response {
 
        php_http_cookie_list_t *cookies;
        php_http_buffer_t *buffer;
-       zval *options;
+       zval options;
 
        struct {
                size_t chunk;
@@ -60,19 +60,15 @@ struct php_http_env_response {
        } content;
 
        zend_bool done;
-
-#ifdef ZTS
-       void ***ts;
-#endif
 };
 
-PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *ops_ctx TSRMLS_DC);
+PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *ops_ctx);
 PHP_HTTP_API ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r);
 PHP_HTTP_API void php_http_env_response_dtor(php_http_env_response_t *r);
 PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r);
 
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC);
+PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request);
+PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request);
 
 PHP_HTTP_API zend_class_entry *php_http_env_response_class_entry;
 PHP_MINIT_FUNCTION(http_env_response);
index 59b9c5f9fb6daa6fb66d6a23890f93f6f109bc29..ec7bd13fcfa6aff2323d0750c73b39f2949bd5fe 100644 (file)
 
 #include "php_http_api.h"
 
+static void php_http_options_hash_dtor(zval *pData)
+{
+       php_http_option_t *opt = Z_PTR_P(pData);
+
+       zend_hash_destroy(&opt->suboptions.options);
+       zend_string_release(opt->name);
+}
+
 php_http_options_t *php_http_options_init(php_http_options_t *registry, zend_bool persistent)
 {
        if (!registry) {
@@ -21,18 +29,19 @@ php_http_options_t *php_http_options_init(php_http_options_t *registry, zend_boo
        }
 
        registry->persistent = persistent;
-       zend_hash_init(&registry->options, 0, NULL, (dtor_func_t) zend_hash_destroy, persistent);
+       zend_hash_init(&registry->options, 0, NULL, php_http_options_hash_dtor, persistent);
 
        return registry;
 }
 
 ZEND_RESULT_CODE php_http_options_apply(php_http_options_t *registry, HashTable *options, void *userdata)
 {
-       HashPosition pos;
-       zval *val;
+       zval *entry, *val;
        php_http_option_t *opt;
 
-       FOREACH_HASH_VAL(pos, &registry->options, opt) {
+       ZEND_HASH_FOREACH_VAL(&registry->options, entry)
+       {
+               opt = Z_PTR_P(entry);
                if (!(val = registry->getter(opt, options, userdata))) {
                        val = &opt->defval;
                }
@@ -44,6 +53,8 @@ ZEND_RESULT_CODE php_http_options_apply(php_http_options_t *registry, HashTable
                        return FAILURE;
                }
        }
+       ZEND_HASH_FOREACH_END();
+
        return SUCCESS;
 }
 
@@ -63,7 +74,7 @@ void php_http_options_free(php_http_options_t **registry)
 
 php_http_option_t *php_http_option_register(php_http_options_t *registry, const char *name_str, size_t name_len, ulong option, zend_uchar type)
 {
-       php_http_option_t opt, *dst = NULL;
+       php_http_option_t opt;
 
        memset(&opt, 0, sizeof(opt));
 
@@ -71,14 +82,17 @@ php_http_option_t *php_http_option_register(php_http_options_t *registry, const
        opt.suboptions.getter = registry->getter;
        opt.suboptions.setter = registry->setter;
 
-       opt.name.h = zend_hash_func(opt.name.s = name_str, opt.name.l = name_len + 1);
+       opt.name = zend_string_init(name_str, name_len, registry->persistent);
        opt.type = type;
        opt.option = option;
 
-       INIT_ZVAL(opt.defval);
        switch ((opt.type = type)) {
-       case IS_BOOL:
-               ZVAL_BOOL(&opt.defval, 0);
+       case IS_TRUE:
+               ZVAL_TRUE(&opt.defval);
+               break;
+
+       case IS_FALSE:
+               ZVAL_FALSE(&opt.defval);
                break;
 
        case IS_LONG:
@@ -86,7 +100,7 @@ php_http_option_t *php_http_option_register(php_http_options_t *registry, const
                break;
 
        case IS_STRING:
-               ZVAL_STRINGL(&opt.defval, NULL, 0, 0);
+               ZVAL_EMPTY_STRING(&opt.defval);
                break;
 
        case IS_DOUBLE:
@@ -98,18 +112,13 @@ php_http_option_t *php_http_option_register(php_http_options_t *registry, const
                break;
        }
 
-       zend_hash_quick_update(&registry->options, opt.name.s, opt.name.l, opt.name.h, (void *) &opt, sizeof(opt), (void *) &dst);
-       return dst;
+       return zend_hash_update_mem(&registry->options, opt.name, &opt, sizeof(opt));
 }
 
 zval *php_http_option_get(php_http_option_t *opt, HashTable *options, void *userdata)
 {
        if (options) {
-               zval **zoption;
-
-               if (SUCCESS == zend_hash_quick_find(options, opt->name.s, opt->name.l, opt->name.h, (void *) &zoption)) {
-                       return *zoption;
-               }
+               return zend_hash_find(options, opt->name);
        }
 
        return NULL;
index 2475383c3800f303e026c35b6ca230734c9cd214..f685f8e6902f51f2910579c8d833737afa72e4f2 100644 (file)
@@ -31,12 +31,7 @@ struct php_http_options {
 struct php_http_option {
        php_http_options_t suboptions;
 
-       struct {
-               const char *s;
-               size_t l;
-               ulong h;
-       } name;
-
+       zend_string *name;
        ulong option;
        zend_uchar type;
        unsigned flags;
index 67df721b9015729fbbb030d903614ff0f92eef88..77df3215dfaa7daaf6fc009944b050eda8ea12dd 100644 (file)
@@ -349,13 +349,8 @@ PHP_METHOD(HttpQueryString, getGlobalInstance)
 
        if (Z_TYPE_P(instance) != IS_OBJECT) {
                zval *_GET = NULL;
-               zend_string *zs = zend_string_init("_GET", lenof("_GET"), 0);
 
-               zend_is_auto_global(zs);
-
-               if ((_GET = zend_hash_find(&EG(symbol_table).ht, zs))
-               &&      (Z_TYPE_P(_GET) == IS_ARRAY)
-               ) {
+               if ((_GET = php_http_env_get_superglobal(ZEND_STRL("_GET")))) {
                        zval new_instance;
 
                        ZVAL_OBJ(&new_instance, php_http_querystring_object_new(php_http_querystring_class_entry));
@@ -368,8 +363,6 @@ PHP_METHOD(HttpQueryString, getGlobalInstance)
                } else {
                        php_http_throw(unexpected_val, "Could not acquire reference to superglobal GET array", NULL);
                }
-
-               zend_string_release(zs);
        }
 
        RETVAL_ZVAL_FAST(instance);