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)
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)
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);
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)
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);
}
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)),
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;
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
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:
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();
}
/* }}} */
-/* {{{ 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.
}
/* }}} */
-/* {{{ 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.
typedef struct {
zend_object zo;
http_message *message;
+ zval *nested;
zval _tmp_property;
} http_message_object;
#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);
PHP_METHOD(HttpMessage, setRequestUri);
PHP_METHOD(HttpMessage, getHttpVersion);
PHP_METHOD(HttpMessage, setHttpVersion);
-PHP_METHOD(HttpMessage, getNestedMessage);
PHP_METHOD(HttpMessage, toString);
PHP_METHOD(HttpMessage, fromString);