X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_exception_object.c;h=c883863036ed74bfc28d86944b97e15992fbf2a2;hp=4562922bad76cd273187fba6a14b9b6f0b494e61;hb=ad5f896b03adaa073134a00108a9cdf00720673a;hpb=eae2e0b6f3ec09658c4e5ea54662a2221890fed7 diff --git a/http_exception_object.c b/http_exception_object.c index 4562922..c883863 100644 --- a/http_exception_object.c +++ b/http_exception_object.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2006, Michael Wallner | + | Copyright (c) 2004-2010, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -16,7 +16,12 @@ #ifdef ZEND_ENGINE_2 +#ifndef HTTP_DBG_EXCEPTIONS +# define HTTP_DBG_EXCEPTIONS 0 +#endif + #include "zend_interfaces.h" +#include "zend_exceptions.h" #include "php_http_exception_object.h" zend_class_entry *http_exception_object_ce; @@ -34,18 +39,29 @@ 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_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 }; +#if HTTP_DBG_EXCEPTIONS +static void http_exception_hook(zval *ex TSRMLS_DC) +{ + if (ex) { + zval *m = zend_read_property(Z_OBJCE_P(ex), ex, "message", lenof("message"), 0 TSRMLS_CC); + fprintf(stderr, "*** Threw exception '%s'\n", Z_STRVAL_P(m)); + } else { + fprintf(stderr, "*** Threw NULL exception\n"); + } +} +#endif + PHP_MINIT_FUNCTION(http_exception_object) { HTTP_REGISTER_CLASS(HttpException, http_exception_object, ZEND_EXCEPTION_GET_DEFAULT(), 0); @@ -60,6 +76,9 @@ PHP_MINIT_FUNCTION(http_exception_object) HTTP_REGISTER_EXCEPTION(HttpMessageTypeException, HTTP_EX_CE(message_type), HTTP_EX_DEF_CE); HTTP_REGISTER_EXCEPTION(HttpEncodingException, HTTP_EX_CE(encoding), HTTP_EX_DEF_CE); HTTP_REGISTER_EXCEPTION(HttpRequestException, HTTP_EX_CE(request), HTTP_EX_DEF_CE); + + zend_declare_property_long(HTTP_EX_CE(request), "curlCode", lenof("curlCode"), 0, ZEND_ACC_PUBLIC TSRMLS_CC); + HTTP_REGISTER_EXCEPTION(HttpRequestPoolException, HTTP_EX_CE(request_pool), HTTP_EX_DEF_CE); HTTP_REGISTER_EXCEPTION(HttpSocketException, HTTP_EX_CE(socket), HTTP_EX_DEF_CE); HTTP_REGISTER_EXCEPTION(HttpResponseException, HTTP_EX_CE(response), HTTP_EX_DEF_CE); @@ -80,6 +99,10 @@ PHP_MINIT_FUNCTION(http_exception_object) HTTP_LONG_CONSTANT("HTTP_E_URL", HTTP_E_URL); HTTP_LONG_CONSTANT("HTTP_E_QUERYSTRING", HTTP_E_QUERYSTRING); +#if HTTP_DBG_EXCEPTIONS + zend_throw_exception_hook=http_exception_hook; +#endif + return SUCCESS; } @@ -122,15 +145,15 @@ PHP_METHOD(HttpException, __toString) 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) { + if (zobj != getThis()) { + phpstr_appends(&full_str, " inner "); + } + 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) ); @@ -149,6 +172,7 @@ PHP_METHOD(HttpException, __toString) RETURN_PHPSTR_VAL(&full_str); } + #endif /*