From: Michael Wallner Date: Wed, 13 Apr 2005 13:35:46 +0000 (+0000) Subject: - added custom error function which is able to throw exceptions X-Git-Tag: RELEASE_0_8_0~67 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2253ca28b6a5699a8e2d62a0458ced3cb7a3107a;p=m6w6%2Fext-http - added custom error function which is able to throw exceptions --- diff --git a/http_api.c b/http_api.c index a548e13..9960f2b 100644 --- a/http_api.c +++ b/http_api.c @@ -32,10 +32,14 @@ #include "php_http_cache_api.h" #include "php_http_headers_api.h" +#ifdef ZEND_ENGINE_2 +# include "php_http_exception_object.h" +#endif + ZEND_EXTERN_MODULE_GLOBALS(http); /* char *pretty_key(char *, size_t, zend_bool, zebd_bool) */ -char *pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen) +char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen) { if (key && key_len) { unsigned i, wasalpha; @@ -58,6 +62,29 @@ char *pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen } /* }}} */ +/* {{{ void http_error(long, long, char*) */ +void _http_error_ex(long type, long code, const char *format, ...) +{ + va_list args; + TSRMLS_FETCH(); + + va_start(args, format); + if (type == E_THROW) { +#ifdef ZEND_ENGINE_2 + char *message; + vspprintf(&message, 0, format, args); + zend_throw_exception(http_exception_get_default(), message, code TSRMLS_CC); +#else + type = E_WARNING; +#endif + } + if (type != E_THROW) { + php_verror(NULL, "", type, format, args TSRMLS_CC); + } + va_end(args); +} +/* }}} */ + /* {{{ static STATUS http_ob_stack_get(php_ob_buffer *, php_ob_buffer **) */ static STATUS http_ob_stack_get(php_ob_buffer *o, php_ob_buffer **s) { @@ -186,8 +213,7 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len /* read in chunk size */ while (isxdigit(*e_ptr)) { if (i == 9) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Chunk size is too long: 0x%s...", hex_len); + http_error_ex(E_WARNING, HTTP_E_PARSE, "Chunk size is too long: 0x%s...", hex_len); efree(*decoded); return FAILURE; } @@ -201,9 +227,7 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len /* new line */ if (strncmp(e_ptr, HTTP_CRLF, 2)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Invalid character (expected 0x0D 0x0A; got: %x %x)", - *e_ptr, *(e_ptr + 1)); + http_error_ex(E_WARNING, HTTP_E_PARSE, "Invalid character (expected 0x0D 0x0A; got: %x %x)", *e_ptr, *(e_ptr + 1)); efree(*decoded); return FAILURE; } @@ -213,8 +237,7 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len char *error = NULL; chunk_len = strtol(hex_len, &error, 16); if (error == hex_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Invalid chunk size string: '%s'", hex_len); + http_error_ex(E_WARNING, HTTP_E_PARSE, "Invalid chunk size string: '%s'", hex_len); efree(*decoded); return FAILURE; } diff --git a/php_http_api.h b/php_http_api.h index b7327b4..d08a2a9 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -20,7 +20,12 @@ #include "php_http_std_defs.h" -char *pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen); +#define pretty_key(key, key_len, uctitle, xhyphen) _http_pretty_key(key, key_len, uctitle, xhyphen) +extern char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen); + +#define http_error(type, code, string) _http_error_ex(type, code, "%s", string) +#define http_error_ex _http_error_ex +extern void _http_error_ex(long type, long code, const char *format, ...); #define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret) #define HTTP_GSP(var, name, ret) \