safety guards for objects which di not set the intern pointer automatically
authorMichael Wallner <mike@php.net>
Sat, 22 Dec 2012 09:41:43 +0000 (09:41 +0000)
committerMichael Wallner <mike@php.net>
Sat, 22 Dec 2012 09:41:43 +0000 (09:41 +0000)
php_http_cookie.c
php_http_cookie.h
php_http_env.c
php_http_env_request.c
php_http_env_response.c
php_http_message.c
php_http_message_body.c
phpunit/DataShareTest.php

index b767bbbb7e83d974b716ff19ed435068536c9150..8dfc62c814e9f8048a9d059c05e433ee6a044b65 100644 (file)
@@ -70,30 +70,31 @@ PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list)
        }
 }
 
-
-
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len)
+PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zcookie)
 {
-       zval **cookie = NULL;
+       zval **cookie;
        if ((SUCCESS != zend_symtable_find(&list->cookies, name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) {
                return NULL;
        }
+       if (zcookie) {
+               *zcookie = *cookie;
+       }
        return Z_STRVAL_PP(cookie);
 }
 
-
-
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len)
+PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zextra)
 {
-       zval **extra = NULL;
+       zval **extra;
+
        if ((SUCCESS != zend_symtable_find(&list->extras, name, name_len + 1, (void *) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) {
                return NULL;
        }
+       if (zextra) {
+               *zextra = *extra;
+       }
        return Z_STRVAL_PP(extra);
 }
 
-
-
 PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
 {
        zval *cookie_value;
@@ -103,8 +104,6 @@ PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list,
        zend_symtable_update(&list->cookies, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
 }
 
-
-
 PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
 {
        zval *cookie_value;
@@ -200,7 +199,6 @@ PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_
        return list;
 }
 
-
 PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct)
 {
        zval array, *cookies, *extras;
@@ -268,8 +266,6 @@ PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_c
        return list;
 }
 
-
-
 static inline void append_encoded(php_http_buffer_t *buf, const char *key, size_t key_len, const char *val, size_t val_len)
 {
        char *enc_str[2];
@@ -287,8 +283,6 @@ static inline void append_encoded(php_http_buffer_t *buf, const char *key, size_
        efree(enc_str[1]);
 }
 
-
-
 PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len)
 {
        php_http_buffer_t buf;
@@ -478,14 +472,20 @@ zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_c
        return ov;
 }
 
+#define PHP_HTTP_COOKIE_OBJECT_INIT(obj) \
+       do { \
+               if (!obj->list) { \
+                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC); \
+               } \
+       } while(0)
+
 zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC)
 {
        php_http_cookie_object_t *new_obj, *old_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
        zend_object_value ov;
 
-       if (!old_obj->list) {
-               old_obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-       }
+       PHP_HTTP_COOKIE_OBJECT_INIT(old_obj);
+
        ov = php_http_cookie_object_new_ex(old_obj->o.ce, php_http_cookie_list_copy(old_obj->list, NULL), &new_obj TSRMLS_CC);
        zend_objects_clone_members((zend_object *) new_obj, ov, (zend_object *) old_obj, Z_OBJ_HANDLE_P(getThis()) TSRMLS_CC);
 
@@ -504,6 +504,7 @@ void php_http_cookie_object_free(void *object TSRMLS_DC)
 PHP_METHOD(HttpCookie, __construct)
 {
        with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+               php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                zval *zcookie = NULL;
                long flags = 0;
                HashTable *allowed_extras = NULL;
@@ -512,7 +513,7 @@ PHP_METHOD(HttpCookie, __construct)
                        if (zcookie) {
                                with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                        char **ae = NULL;
-                                       php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
 
                                        if (allowed_extras && zend_hash_num_elements(allowed_extras)) {
                                                char **ae_ptr = safe_emalloc(zend_hash_num_elements(allowed_extras) + 1, sizeof(char *), 0);
@@ -563,6 +564,7 @@ PHP_METHOD(HttpCookie, __construct)
                                } end_error_handling();
                        }
                }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
        } end_error_handling();
 }
 
@@ -571,9 +573,8 @@ PHP_METHOD(HttpCookie, getCookies)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                array_init(return_value);
                array_copy(&obj->list->cookies, Z_ARRVAL_P(return_value));
                return;
@@ -588,9 +589,8 @@ PHP_METHOD(HttpCookie, setCookies)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &cookies)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                zend_hash_clean(&obj->list->cookies);
                if (cookies) {
                        array_copy(cookies, &obj->list->cookies);
@@ -606,9 +606,8 @@ PHP_METHOD(HttpCookie, addCookies)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &cookies)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                array_join(cookies, &obj->list->cookies, 1, ARRAY_JOIN_STRONLY);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -620,9 +619,8 @@ PHP_METHOD(HttpCookie, getExtras)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                array_init(return_value);
                array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
                return;
@@ -637,9 +635,8 @@ PHP_METHOD(HttpCookie, setExtras)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &extras)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                zend_hash_clean(&obj->list->extras);
                if (extras) {
                        array_copy(extras, &obj->list->extras);
@@ -655,9 +652,8 @@ PHP_METHOD(HttpCookie, addExtras)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &extras)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                array_join(extras, &obj->list->extras, 1, ARRAY_JOIN_STRONLY);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -670,13 +666,12 @@ PHP_METHOD(HttpCookie, getCookie)
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               zval **zvalue;
+               zval *zvalue;
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
-               if (SUCCESS == zend_symtable_find(&obj->list->cookies, name_str, name_len + 1, (void *) &zvalue)) {
-                       RETURN_ZVAL(*zvalue, 1, 0);
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+               if (php_http_cookie_list_get_cookie(obj->list, name_str, name_len, &zvalue)) {
+                       RETURN_ZVAL(zvalue, 1, 0);
                }
        }
        RETURN_FALSE;
@@ -690,17 +685,12 @@ PHP_METHOD(HttpCookie, setCookie)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                if (!value_str) {
-                       zend_symtable_del(&obj->list->cookies, name_str, name_len + 1);
+                       php_http_cookie_list_del_cookie(obj->list, name_str, name_len);
                } else {
-                       zval *zvalue;
-
-                       MAKE_STD_ZVAL(zvalue);
-                       ZVAL_STRINGL(zvalue, value_str, value_len, 1);
-                       zend_symtable_update(&obj->list->cookies, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+                       php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
                }
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -713,14 +703,10 @@ PHP_METHOD(HttpCookie, addCookie)
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               zval *zvalue;
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
-               MAKE_STD_ZVAL(zvalue);
-               ZVAL_STRINGL(zvalue, value_str, value_len, 1);
-               zend_symtable_update(&obj->list->cookies, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+               php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
 }
@@ -732,13 +718,12 @@ PHP_METHOD(HttpCookie, getExtra)
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               zval **zvalue;
+               zval *zvalue;
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
-               if (SUCCESS == zend_symtable_find(&obj->list->extras, name_str, name_len + 1, (void *) &zvalue)) {
-                       RETURN_ZVAL(*zvalue, 1, 0);
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+               if (php_http_cookie_list_get_extra(obj->list, name_str, name_len, &zvalue)) {
+                       RETURN_ZVAL(zvalue, 1, 0);
                }
        }
        RETURN_FALSE;
@@ -752,17 +737,12 @@ PHP_METHOD(HttpCookie, setExtra)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                if (!value_str) {
-                       zend_symtable_del(&obj->list->extras, name_str, name_len + 1);
+                       php_http_cookie_list_del_extra(obj->list, name_str, name_len);
                } else {
-                       zval *zvalue;
-
-                       MAKE_STD_ZVAL(zvalue);
-                       ZVAL_STRINGL(zvalue, value_str, value_len, 1);
-                       zend_symtable_update(&obj->list->extras, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+                       php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
                }
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -775,14 +755,10 @@ PHP_METHOD(HttpCookie, addExtra)
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               zval *zvalue;
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
-               MAKE_STD_ZVAL(zvalue);
-               ZVAL_STRINGL(zvalue, value_str, value_len, 1);
-               zend_symtable_update(&obj->list->extras, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+               php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
 }
@@ -792,9 +768,8 @@ PHP_METHOD(HttpCookie, getDomain)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                if (obj->list->domain) {
                        RETURN_STRING(obj->list->domain, 1);
                }
@@ -811,9 +786,8 @@ PHP_METHOD(HttpCookie, setDomain)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &domain_str, &domain_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                STR_SET(obj->list->domain, domain_str ? estrndup(domain_str, domain_len) : NULL);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -824,9 +798,8 @@ PHP_METHOD(HttpCookie, getPath)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                if (obj->list->path) {
                        RETURN_STRING(obj->list->path, 1);
                }
@@ -843,9 +816,8 @@ PHP_METHOD(HttpCookie, setPath)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &path_str, &path_len)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                STR_SET(obj->list->path, path_str ? estrndup(path_str, path_len) : NULL);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -856,9 +828,8 @@ PHP_METHOD(HttpCookie, getExpires)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                RETURN_LONG(obj->list->expires);
        }
        RETURN_FALSE;
@@ -871,9 +842,8 @@ PHP_METHOD(HttpCookie, setExpires)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                obj->list->expires = ts;
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -884,9 +854,8 @@ PHP_METHOD(HttpCookie, getFlags)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                RETURN_LONG(obj->list->flags);
        }
        RETURN_FALSE;
@@ -899,9 +868,8 @@ PHP_METHOD(HttpCookie, setFlags)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                obj->list->flags = flags;
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -914,9 +882,8 @@ PHP_METHOD(HttpCookie, toString)
                char *str;
                size_t len;
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                php_http_cookie_list_to_string(obj->list, &str, &len);
                RETURN_STRINGL(str, len, 0);
        }
@@ -928,9 +895,8 @@ PHP_METHOD(HttpCookie, toArray)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->list) {
-                       obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
-               }
+               PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
                array_init(return_value);
                php_http_cookie_list_to_struct(obj->list, return_value);
        }
index d524fee3580a2088e46c78a31816a33a629eca11..cda5b84840c43f120e5575955d28ad175497f3a2 100644 (file)
@@ -43,12 +43,14 @@ PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list);
 PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list);
 
 #define php_http_cookie_list_has_cookie(list, name, name_len) zend_symtable_exists(&(list)->cookies, (name), (name_len)+1)
+#define php_http_cookie_list_del_cookie(list, name, name_len) zend_symtable_del(&(list)->cookies, (name), (name_len)+1)
 PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len);
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len);
+PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **cookie);
 
 #define php_http_cookie_list_has_extra(list, name, name_len) zend_symtable_exists(&(list)->extras, (name), (name_len)+1)
+#define php_http_cookie_list_del_extra(list, name, name_len) zend_symtable_del(&(list)->extras, (name), (name_len)+1)
 PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len);
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len);
+PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **extra);
 
 PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len);
 PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC);
index c11e4fcca5d3e7c996b5dd3144bd8b07fd766cc9..4f239e509360aad962fcf129884701c85862d166 100644 (file)
@@ -42,8 +42,6 @@ PHP_RINIT_FUNCTION(http_env)
                                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];
 
-                                       zend_is_auto_global(ZEND_STRL("_POST") TSRMLS_CC);
-
                                        if (post_entry) {
                                                SG(request_info).post_entry = post_entry;
 
@@ -1021,6 +1019,8 @@ PHP_METHOD(HttpEnv, cleanPersistentHandles)
 static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler)
 {
        if (SG(request_info).raw_post_data) {
+               zval_dtor(arg);
+               ((zval *) arg)->type = IS_NULL;
                php_json_decode(arg, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1, PG(max_input_nesting_level) TSRMLS_CC);
        }
 }
index 4da183ec6fa144ac77be4cf3569d207d37fbce82..d9d33ef8a99b338c7647974937d3f1f12af6b6da 100644 (file)
@@ -144,11 +144,19 @@ static int grab_files(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key
        return ZEND_HASH_APPLY_KEEP;
 }
 
+#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); \
+               } \
+       } while(0)
+
 PHP_METHOD(HttpEnvRequest, __construct)
 {
        with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+               php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
                if (SUCCESS == zend_parse_parameters_none()) {
-                       php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                        zval *zsg, *zqs;
 
                        obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC);
@@ -179,6 +187,7 @@ PHP_METHOD(HttpEnvRequest, __construct)
                        zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), zqs TSRMLS_CC);
                        zval_ptr_dtor(&zqs);
                }
+               PHP_HTTP_ENV_REQUEST_OBJECT_INIT(obj);
        } end_error_handling();
 }
 
index 53af327c076ffc59c7991e36c4540f7538900c4f..43a7ea1c86f909f81e7ded17492679cff454bea3 100644 (file)
@@ -1134,17 +1134,24 @@ static zend_function_entry php_http_env_response_method_entry[] = {
        EMPTY_FUNCTION_ENTRY
 };
 
+#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); \
+               } \
+       } while (0)
 
 PHP_METHOD(HttpEnvResponse, __construct)
 {
        with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
-               if (SUCCESS == zend_parse_parameters_none()) {
-                       php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               if (SUCCESS == zend_parse_parameters_none()) {
                        with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC);
                        } end_error_handling();
                }
+               PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
        } end_error_handling();
 
 }
@@ -1158,6 +1165,8 @@ PHP_METHOD(HttpEnvResponse, __invoke)
        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);
 
+               PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
+
                if (obj->body.handle || SUCCESS == php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), NULL TSRMLS_CC)) {
                        php_http_message_body_append(obj->message->body, ob_str, ob_len);
                        RETURN_TRUE;
index c0e60f29be326642eb49bae683a71edfcec3d641..88fc5a60daaeb6ce303c3070e101d1e99d537404 100644 (file)
@@ -862,11 +862,21 @@ PHP_MSHUTDOWN_FUNCTION(http_message)
        return SUCCESS;
 }
 
+#define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \
+       do { \
+               if (!obj->message) { \
+                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); \
+               } \
+       } while(0)
+
+
 void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC)
 {
        int i = 0;
        php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
        /* count */
        php_http_message_count(i, obj->message);
 
@@ -1004,6 +1014,9 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval
        msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
        msg_obj->body = Z_OBJVAL_P(zbody);
 
+       if (tmp) {
+               FREE_ZVAL(tmp);
+       }
        return SUCCESS;
 }
 
@@ -1096,6 +1109,8 @@ static zval *php_http_message_object_read_prop(zval *object, zval *member, int t
        php_http_message_object_prophandler_t *handler;
        zval *return_value, *copy = php_http_ztyp(IS_STRING, member);
 
+       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
        if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
                if (type == BP_VAR_R) {
                        ALLOC_ZVAL(return_value);
@@ -1122,6 +1137,8 @@ static void php_http_message_object_write_prop(zval *object, zval *member, zval
        php_http_message_object_prophandler_t *handler;
        zval *copy = php_http_ztyp(IS_STRING, member);
 
+       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
        if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
                handler->write(obj, value TSRMLS_CC);
        } else {
@@ -1141,6 +1158,8 @@ static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC)
        zval array, *parent, *body;
        char *version;
 
+       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
        INIT_PZVAL_ARRAY(&array, props);
 
 #define ASSOC_PROP(array, ptype, name, val) \
@@ -1254,9 +1273,7 @@ PHP_METHOD(HttpMessage, __construct)
                                }
                        }
                }
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
        } end_error_handling();
 
 }
@@ -1267,9 +1284,8 @@ PHP_METHOD(HttpMessage, getBody)
                if (SUCCESS == zend_parse_parameters_none()) {
                        php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-                       if (!obj->message) {
-                               obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-                       }
+                       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
                        if (!obj->body.handle) {
                                php_http_message_body_addref(obj->message->body);
                                php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, NULL TSRMLS_CC);
@@ -1288,9 +1304,7 @@ PHP_METHOD(HttpMessage, setBody)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_get_class_entry())) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
                php_http_message_object_prophandler_set_body(obj, zbody TSRMLS_CC);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -1304,6 +1318,7 @@ PHP_METHOD(HttpMessage, addBody)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                php_http_message_body_object_t *new_obj = zend_object_store_get_object(new_body TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
                php_http_message_body_to_callback(new_obj->body, (php_http_pass_callback_t) php_http_message_body_append, obj->message->body, 0, 0);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
@@ -1319,9 +1334,7 @@ PHP_METHOD(HttpMessage, getHeader)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                zval *header;
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) {
                        RETURN_ZVAL(header, 1, 1);
@@ -1335,9 +1348,7 @@ PHP_METHOD(HttpMessage, getHeaders)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                array_init(return_value);
                array_copy(&obj->message->hdrs, Z_ARRVAL_P(return_value));
@@ -1354,9 +1365,7 @@ PHP_METHOD(HttpMessage, setHeader)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                if (!zvalue) {
                        zend_symtable_del(&obj->message->hdrs, name, name_len + 1);
@@ -1376,9 +1385,7 @@ PHP_METHOD(HttpMessage, setHeaders)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &new_headers)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                zend_hash_clean(&obj->message->hdrs);
                if (new_headers) {
@@ -1399,9 +1406,7 @@ PHP_METHOD(HttpMessage, addHeader)
                char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
                zval *header;
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                Z_ADDREF_P(zvalue);
                if ((header = php_http_message_header(obj->message, name, name_len, 0))) {
@@ -1424,9 +1429,7 @@ PHP_METHOD(HttpMessage, addHeaders)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, append, ARRAY_JOIN_STRONLY|ARRAY_JOIN_PRETTIFY);
        }
@@ -1438,9 +1441,7 @@ PHP_METHOD(HttpMessage, getType)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                RETURN_LONG(obj->message->type);
        }
@@ -1453,9 +1454,7 @@ PHP_METHOD(HttpMessage, setType)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                php_http_message_set_type(obj->message, type);
        }
@@ -1467,9 +1466,7 @@ PHP_METHOD(HttpMessage, getInfo)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                switch (obj->message->type) {
                        case PHP_HTTP_REQUEST:
@@ -1498,9 +1495,7 @@ PHP_METHOD(HttpMessage, setInfo)
        &&              php_http_info_parse(&inf, str TSRMLS_CC)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                php_http_message_set_info(obj->message, &inf);
                php_http_info_dtor(&inf);
@@ -1515,9 +1510,7 @@ PHP_METHOD(HttpMessage, getHttpVersion)
                size_t len;
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL TSRMLS_CC);
                RETURN_STRINGL(str, len, 0);
@@ -1535,9 +1528,7 @@ PHP_METHOD(HttpMessage, setHttpVersion)
                php_http_version_t version;
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                if (php_http_version_parse(&version, v_str TSRMLS_CC)) {
                        obj->message->http.version = version;
@@ -1551,9 +1542,7 @@ PHP_METHOD(HttpMessage, getResponseCode)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
                RETURN_LONG(obj->message->http.info.response.code);
@@ -1569,9 +1558,7 @@ PHP_METHOD(HttpMessage, setResponseCode)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
                if (strict && (code < 100 || code > 599)) {
@@ -1590,9 +1577,7 @@ PHP_METHOD(HttpMessage, getResponseStatus)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
                if (obj->message->http.info.response.status) {
@@ -1613,9 +1598,7 @@ PHP_METHOD(HttpMessage, setResponseStatus)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
                STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
@@ -1628,9 +1611,7 @@ PHP_METHOD(HttpMessage, getRequestMethod)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
                if (obj->message->http.info.request.method) {
@@ -1651,9 +1632,7 @@ PHP_METHOD(HttpMessage, setRequestMethod)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
                if (method_len < 1) {
@@ -1671,9 +1650,7 @@ PHP_METHOD(HttpMessage, getRequestUrl)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
                if (obj->message->http.info.request.url) {
@@ -1694,9 +1671,7 @@ PHP_METHOD(HttpMessage, setRequestUrl)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url_str, &url_len)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
                if (url_len < 1) {
@@ -1715,9 +1690,7 @@ PHP_METHOD(HttpMessage, getParentMessage)
                if (SUCCESS == zend_parse_parameters_none()) {
                        php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-                       if (!obj->message) {
-                               obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-                       }
+                       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                        if (obj->message->parent) {
                                RETVAL_OBJVAL(obj->parent, 1);
@@ -1737,9 +1710,7 @@ PHP_METHOD(HttpMessage, toString)
                char *string;
                size_t length;
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                if (include_parent) {
                        php_http_message_serialize(obj->message, &string, &length);
@@ -1761,12 +1732,9 @@ PHP_METHOD(HttpMessage, toStream)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                php_stream *s;
 
-               php_stream_from_zval(s, &zstream);
-
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
+               php_stream_from_zval(s, &zstream);
                php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
        }
 }
@@ -1778,6 +1746,8 @@ PHP_METHOD(HttpMessage, toCallback)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &fcd.fci, &fcd.fcc)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
                fcd.fcz = getThis();
                Z_ADDREF_P(fcd.fcz);
                TSRMLS_SET_CTX(fcd.ts);
@@ -1798,9 +1768,7 @@ PHP_METHOD(HttpMessage, serialize)
                char *string;
                size_t length;
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                php_http_message_serialize(obj->message, &string, &length);
                RETURN_STRINGL(string, length, 0);
@@ -1836,9 +1804,7 @@ PHP_METHOD(HttpMessage, detach)
                if (SUCCESS == zend_parse_parameters_none()) {
                        php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-                       if (!obj->message) {
-                               obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-                       }
+                       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                        RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0);
                }
@@ -1855,9 +1821,8 @@ PHP_METHOD(HttpMessage, prepend)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
                if (!prepend_obj->message) {
                        prepend_obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
                }
@@ -1891,6 +1856,8 @@ PHP_METHOD(HttpMessage, isMultipart)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                char *boundary = NULL;
 
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
                RETVAL_BOOL(php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL));
 
                if (zboundary && boundary) {
@@ -1906,6 +1873,8 @@ PHP_METHOD(HttpMessage, splitMultipartBody)
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                char *boundary = NULL;
 
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
                if (php_http_message_is_multipart(obj->message, &boundary)) {
                        php_http_message_t *msg;
 
@@ -1923,9 +1892,7 @@ PHP_METHOD(HttpMessage, count)
                long i = 0;
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
-               if (!obj->message) {
-                       obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
-               }
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                php_http_message_count(i, obj->message);
                RETURN_LONG(i);
index b2fe39946b67acc8c69c229726785069cadc6633..cf2f0a97dac3e38470dc9869364fcb9a9578e442 100644 (file)
@@ -670,6 +670,13 @@ void php_http_message_body_object_free(void *object TSRMLS_DC)
        efree(obj);
 }
 
+#define PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj) \
+       do { \
+               if (!obj->body) { \
+                       obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC); \
+               } \
+       } while(0)
+
 PHP_METHOD(HttpMessageBody, __construct)
 {
        php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -688,9 +695,7 @@ PHP_METHOD(HttpMessageBody, __construct)
                                        obj->body = php_http_message_body_init(NULL, stream TSRMLS_CC);
                                }
                        }
-                       if (!obj->body) {
-                               obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC);
-                       }
+                       PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
                }
        } end_error_handling();
 }
@@ -702,6 +707,8 @@ PHP_METHOD(HttpMessageBody, __toString)
                char *str;
                size_t len;
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                php_http_message_body_to_string(obj->body, &str, &len, 0, 0);
                if (str) {
                        RETURN_STRINGL(str, len, 0);
@@ -732,6 +739,8 @@ PHP_METHOD(HttpMessageBody, toStream)
                php_stream *stream;
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                php_stream_from_zval(stream, &zstream);
                php_http_message_body_to_stream(obj->body, stream, offset, forlen);
                RETURN_TRUE;
@@ -748,6 +757,8 @@ PHP_METHOD(HttpMessageBody, toCallback)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|ll", &fcd.fci, &fcd.fcc, &offset, &forlen)) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                fcd.fcz = getThis();
                Z_ADDREF_P(fcd.fcz);
                TSRMLS_SET_CTX(fcd.ts);
@@ -766,6 +777,8 @@ PHP_METHOD(HttpMessageBody, getResource)
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                zend_list_addref(obj->body->stream_id);
                RETVAL_RESOURCE(obj->body->stream_id);
        }
@@ -779,6 +792,8 @@ PHP_METHOD(HttpMessageBody, append)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                RETURN_LONG(php_http_message_body_append(obj->body, str, len));
        }
        RETURN_FALSE;
@@ -791,6 +806,8 @@ PHP_METHOD(HttpMessageBody, addForm)
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h!h!", &fields, &files)) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                RETURN_SUCCESS(php_http_message_body_add_form(obj->body, fields, files));
        }
        RETURN_FALSE;
@@ -804,6 +821,8 @@ PHP_METHOD(HttpMessageBody, addPart)
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                php_http_message_object_t *mobj = zend_object_store_get_object(zobj TSRMLS_CC);
 
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
                php_http_message_body_add_part(obj->body, mobj->message);
                RETURN_TRUE;
        }
@@ -814,9 +833,11 @@ PHP_METHOD(HttpMessageBody, etag)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               char *etag = php_http_message_body_etag(obj->body);
+               char *etag;
 
-               if (etag) {
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
+               if ((etag = php_http_message_body_etag(obj->body))) {
                        RETURN_STRING(etag, 0);
                }
        }
@@ -830,9 +851,11 @@ PHP_METHOD(HttpMessageBody, stat)
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &field_str, &field_len)) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               const php_stream_statbuf *sb = php_http_message_body_stat(obj->body);
+               const php_stream_statbuf *sb;
+
+               PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
 
-               if (sb) {
+               if ((sb = php_http_message_body_stat(obj->body))) {
                        if (field_str && field_len) {
                                        switch (*field_str) {
                                                case 's':
index f4a0453c6163c1d968b7ec5c5650774a879a08a5..6518ce129e771ecd04664bcdc0bb38a63bd9644d 100644 (file)
@@ -44,7 +44,7 @@ class DataShareTest extends PHPUnit_Framework_TestCase
     }
     
     function testCurl() {
-       $client = new http\Curl\Client;
+       $client = new http\Curl\Client(array("connecttimeout" => 10));
        $client->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
        $share = new http\Curl\Client\DataShare;
        $share->ssl = $share->dns = $share->cookie = true;