X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_message_object.c;h=121337bae962e0ad262a795a5448dda722b2057d;hp=6d271ba9b0c22f436de22e60b181eb450eb3b253;hb=04491f8ea81849ecb509b96c480ffe6f00d0cfd4;hpb=5ba379899fb1e05ede73674dc010ce8846e051c2 diff --git a/http_message_object.c b/http_message_object.c index 6d271ba..121337b 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -149,6 +149,8 @@ HTTP_EMPTY_ARGS(reverse); static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC); #define http_message_object_write_prop _http_message_object_write_prop static void _http_message_object_write_prop(zval *object, zval *member, zval *value TSRMLS_DC); +#define http_message_object_get_prop_ptr _http_message_object_get_prop_ptr +static zval **_http_message_object_get_prop_ptr(zval *object, zval *member TSRMLS_DC); #define http_message_object_get_props _http_message_object_get_props static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC); @@ -228,7 +230,7 @@ PHP_MINIT_FUNCTION(http_message_object) http_message_object_handlers.read_property = http_message_object_read_prop; http_message_object_handlers.write_property = http_message_object_write_prop; http_message_object_handlers.get_properties = http_message_object_get_props; - http_message_object_handlers.get_property_ptr_ptr = NULL; + http_message_object_handlers.get_property_ptr_ptr = http_message_object_get_prop_ptr; zend_declare_property_long(THIS_CE, ZEND_STRS("type")-1, HTTP_MSG_NONE, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_string(THIS_CE, ZEND_STRS("body")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC); @@ -412,6 +414,17 @@ void _http_message_object_free(zend_object *object TSRMLS_DC) freeObject(o); } +static zval **_http_message_object_get_prop_ptr(zval *object, zval *member TSRMLS_DC) { + getObjectEx(http_message_object, obj, object); + zend_property_info *pinfo = zend_get_property_info(obj->zo.ce, member, 1 TSRMLS_CC); + + if (!pinfo || pinfo->ce != http_message_object_ce) { + return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member TSRMLS_CC); + } + zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index"); + return NULL; +} + static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC) { getObjectEx(http_message_object, obj, object); @@ -422,7 +435,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type #else zend_property_info *pinfo = zend_get_property_info(obj->zo.ce, member, 1 TSRMLS_CC); - if (!pinfo) { + if (!pinfo || pinfo->ce != http_message_object_ce) { return zend_get_std_object_handlers()->read_property(object, member, type TSRMLS_CC); } #endif @@ -532,7 +545,7 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va #else zend_property_info *pinfo = zend_get_property_info(obj->zo.ce, member, 1 TSRMLS_CC); - if (!pinfo) { + if (!pinfo || pinfo->ce != http_message_object_ce) { zend_get_std_object_handlers()->write_property(object, member, value TSRMLS_CC); return; } @@ -802,7 +815,7 @@ PHP_METHOD(HttpMessage, setBody) if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &body, &len)) { phpstr_dtor(PHPSTR(obj->message)); - phpstr_from_string_ex(PHPSTR(obj->message), body, len); + phpstr_from_string_ex(PHPSTR(obj->message), body, len); } } /* }}} */ @@ -1276,6 +1289,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) zval_ptr_dtor(&array); if (PHPSTR_VAL(obj->message) && PHPSTR_LEN(obj->message)) { + phpstr_fix(PHPSTR(obj->message)); INIT_PZVAL(&body); ZVAL_STRINGL(&body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message), 0); if (method != HTTP_POST) { @@ -1287,6 +1301,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) zval_copy_ctor(&body); sapi_module.treat_data(PARSE_STRING, Z_STRVAL(body), &post TSRMLS_CC); zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setpostfields", NULL, &post); + zval_dtor(&post); } } #else