- ditch HttpMessage::__construct() and ::setRaw
authorMichael Wallner <mike@php.net>
Wed, 27 Apr 2005 15:25:52 +0000 (15:25 +0000)
committerMichael Wallner <mike@php.net>
Wed, 27 Apr 2005 15:25:52 +0000 (15:25 +0000)
- make HttpMessage::$nestedMessage public

http_message_api.c
http_message_object.c
http_methods.c
php_http_message_object.h

index 76e1d22dbe6a3ba17e3d4ab2467ba9b9eb51f247..dd2cfff2c55035cd949266aa6c37f5f984636940 100644 (file)
@@ -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)) {
index ffb319809ba6a1752b54b385d82a390e06be709b..244e29da292569359834051902169c13548f51e3 100644 (file)
@@ -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:
index dfbc712dd80d17e9a95c7618e3f7ce1d04b88ee4..e4023bc5a7c46d4b0b030af431997bf594cde198 100644 (file)
@@ -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.
index 46a1dd536283f0b7ed6ffb6647af40a4977abc5b..eba3019b88d1183c2661f1360554d1e47c12f7b2 100644 (file)
@@ -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);