From: Michael Wallner Date: Thu, 24 Aug 2006 14:41:45 +0000 (+0000) Subject: - added HttpException::__toString() which takes care about any inner exceptions X-Git-Tag: RELEASE_1_2_1~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=eae2e0b6f3ec09658c4e5ea54662a2221890fed7;p=m6w6%2Fext-http - added HttpException::__toString() which takes care about any inner exceptions --- diff --git a/KnownIssues.txt b/KnownIssues.txt index 19c593c..fac8a3c 100644 --- a/KnownIssues.txt +++ b/KnownIssues.txt @@ -20,3 +20,5 @@ not work as expected in a PHP version lower than 5.1.3. Internals: - our http_urlencode_hash() does not differentiate between prefixes for numeric or string keys. + - detaching a request from a pool in its progress callback causes + all sorts of memory errors diff --git a/http_exception_object.c b/http_exception_object.c index 9074005..4562922 100644 --- a/http_exception_object.c +++ b/http_exception_object.c @@ -16,6 +16,7 @@ #ifdef ZEND_ENGINE_2 +#include "zend_interfaces.h" #include "php_http_exception_object.h" zend_class_entry *http_exception_object_ce; @@ -33,9 +34,21 @@ zend_class_entry *HTTP_EX_CE(response); zend_class_entry *HTTP_EX_CE(url); zend_class_entry *HTTP_EX_CE(querystring); +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpException, method, 0) +#define HTTP_EXCEPTION_ME(method, visibility) PHP_ME(HttpException, method, HTTP_ARGS(HttpException, method), visibility) + +HTTP_EMPTY_ARGS(__toString); + +#define OBJ_PROP_CE http_deflatestream_object_ce +zend_function_entry http_exception_object_fe[] = { + HTTP_EXCEPTION_ME(__toString, ZEND_ACC_PUBLIC) + + EMPTY_FUNCTION_ENTRY +}; + PHP_MINIT_FUNCTION(http_exception_object) { - HTTP_REGISTER_EXCEPTION(HttpException, http_exception_object_ce, ZEND_EXCEPTION_GET_DEFAULT()); + HTTP_REGISTER_CLASS(HttpException, http_exception_object, ZEND_EXCEPTION_GET_DEFAULT(), 0); zend_declare_property_null(HTTP_EX_DEF_CE, "innerException", lenof("innerException"), ZEND_ACC_PUBLIC TSRMLS_CC); @@ -98,6 +111,44 @@ zend_class_entry *_http_exception_get_for_code(long code) return ex; } +PHP_METHOD(HttpException, __toString) +{ + phpstr full_str; + zend_class_entry *ce; + zval *zobj = getThis(), *retval = NULL, *m, *f, *l; + + phpstr_init(&full_str); + + do { + ce = Z_OBJCE_P(zobj); + + if (zobj != getThis()) { + phpstr_appends(&full_str, " inner "); + } + + m = zend_read_property(ce, zobj, "message", lenof("message"), 0 TSRMLS_CC); + f = zend_read_property(ce, zobj, "file", lenof("file"), 0 TSRMLS_CC); + l = zend_read_property(ce, zobj, "line", lenof("line"), 0 TSRMLS_CC); + + if (m && f && l && Z_TYPE_P(m) == IS_STRING && Z_TYPE_P(f) == IS_STRING && Z_TYPE_P(l) == IS_LONG) { + phpstr_appendf(&full_str, "exception '%.*s' with message '%.*s' in %.*s:%ld" PHP_EOL, + ce->name_length, ce->name, Z_STRLEN_P(m), Z_STRVAL_P(m), Z_STRLEN_P(f), Z_STRVAL_P(f), Z_LVAL_P(l) + ); + } else { + break; + } + + zobj = zend_read_property(ce, zobj, "innerException", lenof("innerException"), 0 TSRMLS_CC); + } while (Z_TYPE_P(zobj) == IS_OBJECT); + + if (zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "gettraceasstring", &retval) && Z_TYPE_P(retval) == IS_STRING) { + phpstr_appends(&full_str, "Stack trace:" PHP_EOL); + phpstr_append(&full_str, Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + zval_ptr_dtor(&retval); + } + + RETURN_PHPSTR_VAL(&full_str); +} #endif /* diff --git a/http_request_pool_api.c b/http_request_pool_api.c index e93a078..ae12525 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -216,7 +216,8 @@ PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool TSRMLS_DC) while (http_request_pool_perform(pool, 0)) { if (SUCCESS != http_request_pool_select(pool)) { #ifdef PHP_WIN32 - http_error(HE_WARNING, HTTP_E_SOCKET, WSAGetLastError()); + /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */ + http_error_ex(HE_WARNING, HTTP_E_SOCKET, "WinSock error: %d", WSAGetLastError()); #else http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno)); #endif diff --git a/package.xml b/package.xml index bd9a6a6..afc7bc7 100644 --- a/package.xml +++ b/package.xml @@ -23,14 +23,15 @@ support. Parallel requests are available for PHP 5 and greater. - 1.2.0 - 2006-08-18 + 1.2.1 + 2006-08-24 BSD, revised stable - + Improved response performance (HttpResponse, http_send API) -* Fixed http_parse_cookie() allowed_extras and flags parameters -* Added http_build_cookie() function -* Fixed configuration with shared dependencies + + Added HttpException::__toString() which takes care about any inner exceptions +* Fixed issues with inheritance and cloning of HttpDeflateStream, HttpInflateStream and HttpMessage + (Extending classes lose default properties on instantiation; Complex members ignored during cloning) +* Fixed suppression of nested exceptions in e.g. HttpRequestPool::send() (fixes bug #8535) +* Fixed crash on detaching requests from pool in request event callbacks @@ -114,6 +115,7 @@ support. Parallel requests are available for PHP 5 and greater. + diff --git a/package2.xml b/package2.xml index 406cada..fe7c749 100644 --- a/package2.xml +++ b/package2.xml @@ -28,7 +28,7 @@ support. Parallel requests are available for PHP 5 and greater. mike@php.net yes - 2006-08-00 + 2006-08-24 1.2.1 1.2.0 @@ -39,9 +39,10 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised diff --git a/php_http.h b/php_http.h index 5ba0311..66ecbcc 100644 --- a/php_http.h +++ b/php_http.h @@ -15,7 +15,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_EXT_HTTP_VERSION "1.2.1dev" +#define PHP_EXT_HTTP_VERSION "1.2.1" #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/php_http_exception_object.h b/php_http_exception_object.h index 9cf42cb..9afaaf7 100644 --- a/php_http_exception_object.h +++ b/php_http_exception_object.h @@ -44,6 +44,8 @@ extern zend_class_entry *_http_exception_get_default(); #define http_exception_get_for_code(c) _http_exception_get_for_code(c) extern zend_class_entry *_http_exception_get_for_code(long code); +PHP_METHOD(HttpException, __toString); + #endif #endif diff --git a/tests/HttpRequestPool_005.phpt b/tests/HttpRequestPool_005.phpt index 80a6c64..a36299a 100644 --- a/tests/HttpRequestPool_005.phpt +++ b/tests/HttpRequestPool_005.phpt @@ -32,11 +32,11 @@ echo "Done\n"; ?> --EXPECTF-- %sTEST -HttpRequestPoolException: Exception caused by inner exception(s) +HttpRequestPoolException: Exception caused by 2 inner exception(s) HttpInvalidParamException: Empty or too short HTTP message: '' HttpRequestException: couldn't resolve host name; Couldn't resolve host '_____' (http://_____/) int(3) -HttpRequestPoolException: Exception caused by inner exception(s) +HttpRequestPoolException: Exception caused by 4 inner exception(s) HttpInvalidParamException: Empty or too short HTTP message: '' HttpRequestException: couldn't resolve host name; Couldn't resolve host '_____' (http://_____/) HttpInvalidParamException: Empty or too short HTTP message: ''