From: Michael Wallner Date: Wed, 27 Apr 2005 15:25:52 +0000 (+0000) Subject: - ditch HttpMessage::__construct() and ::setRaw X-Git-Tag: RELEASE_0_8_0~50 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b7d46301e6a672db53cec3363ab0d2f31ccb6de9;p=m6w6%2Fext-http - ditch HttpMessage::__construct() and ::setRaw - make HttpMessage::$nestedMessage public --- diff --git a/http_message_api.c b/http_message_api.c index 76e1d22..dd2cfff 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -108,7 +108,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char char *decoded, *end; size_t decoded_len; - if (end = http_chunked_decode(body, message_length - header_length, &decoded, &decoded_len)) { + if (end = http_chunked_decode(body, message_length - header_length, &decoded, &decoded_len)) { phpstr_from_string_ex(PHPSTR(msg), decoded, decoded_len); efree(decoded); if (nested = http_message_parse_nested(msg, end, message + message_length - end)) { diff --git a/http_message_object.c b/http_message_object.c index ffb3198..244e29d 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -39,8 +39,6 @@ static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC); zend_class_entry *http_message_object_ce; zend_function_entry http_message_object_fe[] = { - PHP_ME(HttpMessage, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(HttpMessage, setRaw, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, getBody, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, getHeaders, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, setHeaders, NULL, ZEND_ACC_PUBLIC) @@ -55,7 +53,6 @@ zend_function_entry http_message_object_fe[] = { PHP_ME(HttpMessage, setRequestUri, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, getHttpVersion, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, setHttpVersion, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpMessage, getNestedMessage, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpMessage, toString, NULL, ZEND_ACC_PUBLIC) ZEND_MALIAS(HttpMessage, __toString, toString, NULL, ZEND_ACC_PUBLIC) @@ -90,7 +87,18 @@ zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message o = ecalloc(1, sizeof(http_message_object)); o->zo.ce = ce; - o->message = msg ? msg : http_message_new(); + + MAKE_STD_ZVAL(o->nested); + Z_TYPE_P(o->nested) = IS_OBJECT; + + if (msg) { + o->message = msg; + if (msg->nested) { + o->nested->value.obj = http_message_object_from_msg(msg->nested); + } + } else { + o->message = http_message_new(); + } ALLOC_HASHTABLE(OBJ_PROP(o)); zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); @@ -115,7 +123,8 @@ static inline void _http_message_object_declare_default_properties(TSRMLS_D) DCL_PROP_N(PROTECTED, httpVersion); DCL_PROP_N(PROTECTED, headers); - DCL_PROP_N(PROTECTED, nestedMessage); + + DCL_PROP_N(PUBLIC, nestedMessage); } static void _http_message_object_free(zend_object *object TSRMLS_DC) @@ -127,8 +136,10 @@ static void _http_message_object_free(zend_object *object TSRMLS_DC) FREE_HASHTABLE(OBJ_PROP(o)); } if (o->message) { - http_message_free(o->message); + http_message_dtor(o->message); + efree(o->message); } + FREE_ZVAL(o->nested); zval_dtor(&o->_tmp_property); efree(o); } @@ -139,12 +150,15 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type http_message *msg = obj->message; zval *return_value = &obj->_tmp_property; - if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); - return EG(uninitialized_zval_ptr); + /* public */ + if (strcmp(Z_STRVAL_P(member), "nestedMessage")) { + if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + return EG(uninitialized_zval_ptr); + } } - zval_ptr_dtor(&return_value); + zval_dtor(return_value); #if 0 fprintf(stderr, "Reading property: %s(%d==%d) (%lu)\n", Z_STRVAL_P(member), Z_STRLEN_P(member), strlen(Z_STRVAL_P(member)), @@ -186,11 +200,9 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type break; case HTTP_MSG_PROPHASH_NESTED_MESSAGE: + RETVAL_NULL(); if (msg->nested) { - Z_TYPE_P(return_value) = IS_OBJECT; - return_value->value.obj = http_message_object_from_msg(msg->nested); - } else { - RETVAL_NULL(); + return obj->nested; } break; @@ -231,8 +243,11 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va getObjectEx(http_message_object, obj, object); http_message *msg = obj->message; - if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + /* public */ + if (strcmp("nestedMessage", Z_STRVAL_P(member))) { + if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + } } #if 0 @@ -286,6 +301,9 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va break; case HTTP_MSG_PROPHASH_NESTED_MESSAGE: + zval_ptr_dtor(&obj->nested); + obj->nested->value.obj = value->value.obj; + zval_add_ref(&value); break; case HTTP_MSG_PROPHASH_REQUEST_METHOD: diff --git a/http_methods.c b/http_methods.c index dfbc712..e4023bc 100644 --- a/http_methods.c +++ b/http_methods.c @@ -532,6 +532,7 @@ PHP_METHOD(HttpMessage, fromString) char *string = NULL; int length = 0; http_message *msg = NULL; + http_message_object obj; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &length)) { RETURN_NULL(); @@ -546,45 +547,6 @@ PHP_METHOD(HttpMessage, fromString) } /* }}} */ -/* {{{ proto void HttpMessage::__construct([string raw_message]) - * - * Instantiate a new HttpMessage object based on the optionally provided - * raw message. An HTTP Message can be either a response or a request. - */ -PHP_METHOD(HttpMessage, __construct) -{ - zval *message = NULL; - getObject(http_message_object, obj); - - SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/", &message)) { - if (message) { - convert_to_string(message); - SET_PROP(obj, raw, message); - } - } - SET_EH_NORMAL(); -} -/* }}} */ - -/* {{{ proto void HttpMessage::setRaw(string raw_message) - * - * Parse a new raw message. - */ -PHP_METHOD(HttpMessage, setRaw) -{ - zval *message; - getObject(http_message_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &message)) { - return; - } - - convert_to_string(message); - SET_PROP(obj, raw, message); -} -/* }}} */ - /* {{{ proto string HttpMessage::getBody() * * Get the body of the parsed Message. @@ -890,29 +852,6 @@ PHP_METHOD(HttpMessage, setHttpVersion) } /* }}} */ -/* {{{ proto HttpMessage HttpMessage::getNestedMessage() - * - * Get nested HTTP Message. - */ -PHP_METHOD(HttpMessage, getNestedMessage) -{ - zval *nested; - getObject(http_message_object, obj); - - NO_ARGS; - - nested = GET_PROP(obj, nestedMessage); - if (Z_TYPE_P(nested) == IS_OBJECT) { - Z_TYPE_P(return_value) = IS_OBJECT; - return_value->is_ref = 1; - return_value->value.obj = nested->value.obj; - zval_add_ref(&return_value); - } else { - RETVAL_NULL(); - } -} -/* }}} */ - /* {{{ proto string HttpMessage::toString() * * Get the string representation of the Message. diff --git a/php_http_message_object.h b/php_http_message_object.h index 46a1dd5..eba3019 100644 --- a/php_http_message_object.h +++ b/php_http_message_object.h @@ -24,6 +24,7 @@ typedef struct { zend_object zo; http_message *message; + zval *nested; zval _tmp_property; } http_message_object; @@ -51,8 +52,6 @@ extern void _http_message_object_free(zend_object *object TSRMLS_DC); #define HTTP_MSG_PROPHASH_RESPONSE_STATUS 3857097400LU #define HTTP_MSG_PROPHASH_RESPONSE_CODE 1305615119LU -PHP_METHOD(HttpMessage, __construct); -PHP_METHOD(HttpMessage, setRaw); PHP_METHOD(HttpMessage, getBody); PHP_METHOD(HttpMessage, getHeaders); PHP_METHOD(HttpMessage, setHeaders); @@ -67,7 +66,6 @@ PHP_METHOD(HttpMessage, getRequestUri); PHP_METHOD(HttpMessage, setRequestUri); PHP_METHOD(HttpMessage, getHttpVersion); PHP_METHOD(HttpMessage, setHttpVersion); -PHP_METHOD(HttpMessage, getNestedMessage); PHP_METHOD(HttpMessage, toString); PHP_METHOD(HttpMessage, fromString);