cvs: pecl /http http.c http_message_object.c http_methods.c php_http.h php_http_message_object.h

From: Date: Tue, 12 Apr 2005 15:28:44 +0000
Subject: cvs: pecl /http http.c http_message_object.c http_methods.c php_http.h php_http_message_object.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2978@lists.php.net to get a copy of this message
mike Tue Apr 12 11:28:44 2005 EDT Modified files: /pecl/http http.c http_message_object.c http_methods.c php_http.h php_http_message_object.h Log: - add HttpMessage::setRaw(), ::getBody(), ::getHeaders() - using a global tmp zval for the property avoids memleaks http://cvs.php.net/diff.php/pecl/http/http.c?r1=1.62&r2=1.63&ty=u Index: pecl/http/http.c diff -u pecl/http/http.c:1.62 pecl/http/http.c:1.63 --- pecl/http/http.c:1.62 Tue Apr 12 10:44:48 2005 +++ pecl/http/http.c Tue Apr 12 11:28:44 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.62 2005/04/12 14:44:48 mike Exp $ */ +/* $Id: http.c,v 1.63 2005/04/12 15:28:44 mike Exp $ */ #ifdef HAVE_CONFIG_H @@ -283,6 +283,8 @@ phpstr_dtor(&HTTP_G(curlbuf)); #endif + zval_dtor(&HTTP_G(message_object_tmp_property)); + return SUCCESS; } /* }}} */ http://cvs.php.net/diff.php/pecl/http/http_message_object.c?r1=1.1&r2=1.2&ty=u Index: pecl/http/http_message_object.c diff -u pecl/http/http_message_object.c:1.1 pecl/http/http_message_object.c:1.2 --- pecl/http/http_message_object.c:1.1 Tue Apr 12 09:58:59 2005 +++ pecl/http/http_message_object.c Tue Apr 12 11:28:44 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_message_object.c,v 1.1 2005/04/12 13:58:59 mike Exp $ */ +/* $Id: http_message_object.c,v 1.2 2005/04/12 15:28:44 mike Exp $ */ #ifdef HAVE_CONFIG_H @@ -22,11 +22,14 @@ #include "php.h" +#include "php_http.h" #include "php_http_std_defs.h" #include "php_http_message_object.h" #ifdef ZEND_ENGINE_2 +ZEND_EXTERN_MODULE_GLOBALS(http); + #define http_message_object_declare_default_properties() _http_message_object_declare_default_properties(TSRMLS_C) static inline void _http_message_object_declare_default_properties(TSRMLS_D); #define http_message_object_read_prop _http_message_object_read_prop @@ -39,7 +42,9 @@ 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, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) + PHP_ME(HttpMessage, setRaw, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getBody, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getHeaders, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; static zend_object_handlers http_message_object_handlers; @@ -107,15 +112,14 @@ { getObjectEx(http_message_object, obj, object); http_message *msg = obj->message; - zval *return_value; + zval *return_value = &HTTP_G(message_object_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); } - ALLOC_ZVAL(return_value); - return_value->refcount = 0; + 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)), @@ -151,7 +155,7 @@ if (msg->len) { RETVAL_STRINGL(msg->raw, msg->len, 1); } else { - RETVAL_STRINGL(empty_string, 0, 0); + RETVAL_STRINGL(empty_string, 0, 1); } } else { RETVAL_NULL(); @@ -164,8 +168,8 @@ break; case HTTP_MSG_PROPHASH_HEADERS: - Z_TYPE_P(return_value) = IS_ARRAY; - Z_ARRVAL_P(return_value) = &msg->hdrs; + array_init(return_value); + zend_hash_copy(Z_ARRVAL_P(return_value), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); break; case HTTP_MSG_PROPHASH_NESTED_MESSAGE: http://cvs.php.net/diff.php/pecl/http/http_methods.c?r1=1.20&r2=1.21&ty=u Index: pecl/http/http_methods.c diff -u pecl/http/http_methods.c:1.20 pecl/http/http_methods.c:1.21 --- pecl/http/http_methods.c:1.20 Tue Apr 12 09:58:58 2005 +++ pecl/http/http_methods.c Tue Apr 12 11:28:44 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_methods.c,v 1.20 2005/04/12 13:58:58 mike Exp $ */ +/* $Id: http_methods.c,v 1.21 2005/04/12 15:28:44 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -523,31 +523,76 @@ /* {{{ HttpMessage */ -/* {{{ void HttpMessage::__construct([string raw_message]) */ +/* {{{ 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; int message_len; getObject(http_message_object, obj); - http_message *msg = obj->message; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/", &message)) { return; } if (message) { + convert_to_string(message); SET_PROP(obj, raw, message); } } /* }}} */ -/* {{{ void HttpMessage::__destruct() */ -PHP_METHOD(HttpMessage, __destruct) +/* {{{ 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); +} +/* }}} */ + +/* {{{ string HttpMessage::getBody() + * + * Get the body of the parsed Message. + */ +PHP_METHOD(HttpMessage, getBody) +{ + zval *body; + getObject(http_message_object, obj); + NO_ARGS; + body = GET_PROP(obj, body); + RETURN_STRINGL(Z_STRVAL_P(body), Z_STRLEN_P(body), 1); +} +/* }}} */ + +/* {{{ array HttpMessage::getHeaders() + * + * Get Message Headers. + */ +PHP_METHOD(HttpMessage, getHeaders) +{ + zval *headers; + getObject(http_message_object, obj); + + NO_ARGS; + + headers = GET_PROP(obj, headers); + array_init(return_value); + array_copy(headers, return_value); } /* }}} */ http://cvs.php.net/diff.php/pecl/http/php_http.h?r1=1.41&r2=1.42&ty=u Index: pecl/http/php_http.h diff -u pecl/http/php_http.h:1.41 pecl/http/php_http.h:1.42 --- pecl/http/php_http.h:1.41 Tue Apr 12 09:58:59 2005 +++ pecl/http/php_http.h Tue Apr 12 11:28:44 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http.h,v 1.41 2005/04/12 13:58:59 mike Exp $ */ +/* $Id: php_http.h,v 1.42 2005/04/12 15:28:44 mike Exp $ */ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H @@ -47,6 +47,7 @@ char curlerr[CURL_ERROR_SIZE + 1]; # endif zend_llist to_free; + zval message_object_tmp_property; #endif /* HTTP_HAVE_CURL */ ZEND_END_MODULE_GLOBALS(http) http://cvs.php.net/diff.php/pecl/http/php_http_message_object.h?r1=1.1&r2=1.2&ty=u Index: pecl/http/php_http_message_object.h diff -u pecl/http/php_http_message_object.h:1.1 pecl/http/php_http_message_object.h:1.2 --- pecl/http/php_http_message_object.h:1.1 Tue Apr 12 09:58:59 2005 +++ pecl/http/php_http_message_object.h Tue Apr 12 11:28:44 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http_message_object.h,v 1.1 2005/04/12 13:58:59 mike Exp $ */ +/* $Id: php_http_message_object.h,v 1.2 2005/04/12 15:28:44 mike Exp $ */ #ifndef PHP_HTTP_MESSAGE_OBJECT_H #define PHP_HTTP_MESSAGE_OBJECT_H @@ -47,7 +47,9 @@ #define HTTP_MSG_PROPHASH_RESPONSE_STATUS 3857097400LU PHP_METHOD(HttpMessage, __construct); -PHP_METHOD(HttpMessage, __destruct); +PHP_METHOD(HttpMessage, setRaw); +PHP_METHOD(HttpMessage, getBody); +PHP_METHOD(HttpMessage, getHeaders); #endif #endif

« previous php.pecl.cvs (#2978) next »