From: Michael Wallner Date: Sat, 14 Jan 2012 10:55:48 +0000 (+0000) Subject: make &$this->headers work; &$this->headers["foo"] still doesn't though X-Git-Tag: DEV_2-before-client~72 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8099f0bdec0a8731a3fbb350bf5a8e3320d1fc01;p=m6w6%2Fext-http make &$this->headers work; &$this->headers["foo"] still doesn't though --- diff --git a/php_http_message.c b/php_http_message.c index d6a7f75..066deca 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -1153,18 +1153,16 @@ static zval *php_http_message_object_read_prop(zval *object, zval *member, int t zval *return_value, *copy = php_http_ztyp(IS_STRING, member); if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) { - if (type == BP_VAR_W) { - zval_ptr_dtor(©); + if (type == BP_VAR_R) { + ALLOC_ZVAL(return_value); + Z_SET_REFCOUNT_P(return_value, 0); + Z_UNSET_ISREF_P(return_value); + + handler->read(obj, return_value TSRMLS_CC); + } else { zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index"); - return NULL; + return_value = NULL; } - - ALLOC_ZVAL(return_value); - Z_SET_REFCOUNT_P(return_value, 0); - Z_UNSET_ISREF_P(return_value); - - handler->read(obj, return_value TSRMLS_CC); - } else { return_value = zend_get_std_object_handlers()->read_property(object, member, type, literal_key TSRMLS_CC); } diff --git a/php_http_property_proxy.c b/php_http_property_proxy.c index fc75f6d..8fae2f1 100644 --- a/php_http_property_proxy.c +++ b/php_http_property_proxy.c @@ -12,6 +12,10 @@ #include "php_http_api.h" +#ifndef PHP_HTTP_PPDBG +# define PHP_HTTP_PPDBG 1 +#endif + php_http_property_proxy_t *php_http_property_proxy_init(php_http_property_proxy_t *proxy, zval *object, zval *member TSRMLS_DC) { if (!proxy) { @@ -25,6 +29,9 @@ php_http_property_proxy_t *php_http_property_proxy_init(php_http_property_proxy_ proxy->object = object; proxy->member = php_http_ztyp(IS_STRING, member); +#if PHP_HTTP_PPDBG + fprintf(stderr, "proxy_init: %s\n", Z_STRVAL_P(proxy->member)); +#endif return proxy; } @@ -98,14 +105,43 @@ static void php_http_property_proxy_object_set(zval **object, zval *value TSRMLS { php_http_property_proxy_object_t *obj = zend_object_store_get_object(*object TSRMLS_CC); - zend_update_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), value TSRMLS_CC); +#if PHP_HTTP_PPDBG + fprintf(stderr, "proxy_set: %s\n", Z_STRVAL_P(obj->proxy->member)); +#endif + if (Z_TYPE_P(obj->proxy->object) == IS_OBJECT) { + zend_update_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), value TSRMLS_CC); + } else { + Z_ADDREF_P(value); + zend_symtable_update(Z_ARRVAL_P(obj->proxy->object), Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member)+1, (void *) &value, sizeof(zval *), NULL); + } } static zval *php_http_property_proxy_object_get(zval *object TSRMLS_DC) { php_http_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); - return zend_read_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), 0 TSRMLS_CC); +#if PHP_HTTP_PPDBG + fprintf(stderr, "proxy_get: %s\n", Z_STRVAL_P(obj->proxy->member)); +#endif + if (Z_TYPE_P(obj->proxy->object) == IS_OBJECT) { + return zend_read_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), 0 TSRMLS_CC); + } else { + zval **data = NULL; + + if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(obj->proxy->object), Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member)+1, (void *) &data)) { + Z_ADDREF_PP(data); + } else { + zval *unset; + + MAKE_STD_ZVAL(unset); + ZVAL_NULL(unset); + zend_symtable_update(Z_ARRVAL_P(obj->proxy->object), Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member)+1, (void *) &unset, sizeof(zval *), (void *) &data); + } + + return *data; + } + + return NULL; } static STATUS php_http_property_proxy_object_cast(zval *object, zval *return_value, int type TSRMLS_DC) @@ -128,7 +164,16 @@ static zval *php_http_property_proxy_object_read_dimension(zval *object, zval *o { zval *retval = NULL, *property = php_http_property_proxy_object_get(object TSRMLS_CC); - if (Z_TYPE_P(property) == IS_ARRAY) { +#if PHP_HTTP_PPDBG + php_http_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + zval *ocpy = php_http_ztyp(IS_STRING, offset); + fprintf(stderr, "read_dimension: %s.%s (%d)\n", Z_STRVAL_P(obj->proxy->member), Z_STRVAL_P(ocpy), type); + zval_ptr_dtor(&ocpy); +#endif + if (type != BP_VAR_R) { + Z_ADDREF_P(property); + retval = php_http_property_proxy_init(NULL, property, offset TSRMLS_CC)->myself; + } else if (Z_TYPE_P(property) == IS_ARRAY) { zval **data = NULL; if (Z_TYPE_P(offset) == IS_LONG) { @@ -148,7 +193,7 @@ static zval *php_http_property_proxy_object_read_dimension(zval *object, zval *o } } zval_ptr_dtor(&property); - +if(retval)Z_SET_ISREF_P(retval); return retval; } @@ -156,6 +201,12 @@ static void php_http_property_proxy_object_write_dimension(zval *object, zval *o { zval *property = php_http_property_proxy_object_get(object TSRMLS_CC); +#if PHP_HTTP_PPDBG + php_http_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); + zval *ocpy = offset ? php_http_ztyp(IS_STRING, offset) : offset; + fprintf(stderr, "write_dimension: %s.%s (%d)\n", Z_STRVAL_P(obj->proxy->member), ocpy?Z_STRVAL_P(ocpy):"", Z_TYPE_P(property)); + if(ocpy)zval_ptr_dtor(&ocpy); +#endif switch (Z_TYPE_P(property)) { case IS_NULL: array_init(property);