fix problem when finishing a chunked encoding stream
[m6w6/ext-http] / php_http_exception.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id: http_exception_object.c 292841 2009-12-31 08:48:57Z mike $ */
14
15 #include "php_http.h"
16
17
18 #ifndef PHP_HTTP_DBG_EXCEPTIONS
19 # define PHP_HTTP_DBG_EXCEPTIONS 0
20 #endif
21
22 zend_class_entry *PHP_HTTP_EX_DEF_CE;
23 zend_class_entry *PHP_HTTP_EX_CE(runtime);
24 zend_class_entry *PHP_HTTP_EX_CE(header);
25 zend_class_entry *PHP_HTTP_EX_CE(malformed_headers);
26 zend_class_entry *PHP_HTTP_EX_CE(request_method);
27 zend_class_entry *PHP_HTTP_EX_CE(message);
28 zend_class_entry *PHP_HTTP_EX_CE(message_type);
29 zend_class_entry *PHP_HTTP_EX_CE(invalid_param);
30 zend_class_entry *PHP_HTTP_EX_CE(encoding);
31 zend_class_entry *PHP_HTTP_EX_CE(request);
32 zend_class_entry *PHP_HTTP_EX_CE(request_pool);
33 zend_class_entry *PHP_HTTP_EX_CE(socket);
34 zend_class_entry *PHP_HTTP_EX_CE(response);
35 zend_class_entry *PHP_HTTP_EX_CE(url);
36 zend_class_entry *PHP_HTTP_EX_CE(querystring);
37 zend_class_entry *PHP_HTTP_EX_CE(cookie);
38
39 zend_function_entry php_http_exception_method_entry[] = {
40 EMPTY_FUNCTION_ENTRY
41 };
42
43 #if PHP_HTTP_DBG_EXCEPTIONS
44 static void php_http_exception_hook(zval *ex TSRMLS_DC)
45 {
46 if (ex) {
47 zval *m = zend_read_property(Z_OBJCE_P(ex), ex, "message", lenof("message"), 0 TSRMLS_CC);
48 fprintf(stderr, "*** Threw exception '%s'\n", Z_STRVAL_P(m));
49 } else {
50 fprintf(stderr, "*** Threw NULL exception\n");
51 }
52 }
53 #endif
54
55 PHP_MINIT_FUNCTION(http_exception)
56 {
57 PHP_HTTP_REGISTER_EXCEPTION(Exception, PHP_HTTP_EX_DEF_CE, zend_exception_get_default(TSRMLS_C));
58
59 PHP_HTTP_REGISTER_EXCEPTION(RuntimeException, PHP_HTTP_EX_CE(runtime), PHP_HTTP_EX_DEF_CE);
60 PHP_HTTP_REGISTER_EXCEPTION(InvalidParamException, PHP_HTTP_EX_CE(invalid_param), PHP_HTTP_EX_DEF_CE);
61 PHP_HTTP_REGISTER_EXCEPTION(HeaderException, PHP_HTTP_EX_CE(header), PHP_HTTP_EX_DEF_CE);
62 PHP_HTTP_REGISTER_EXCEPTION(MalformedHeadersException, PHP_HTTP_EX_CE(malformed_headers), PHP_HTTP_EX_DEF_CE);
63 PHP_HTTP_REGISTER_EXCEPTION(RequestMethodException, PHP_HTTP_EX_CE(request_method), PHP_HTTP_EX_DEF_CE);
64 PHP_HTTP_REGISTER_EXCEPTION(MessageException, PHP_HTTP_EX_CE(message), PHP_HTTP_EX_DEF_CE);
65 PHP_HTTP_REGISTER_EXCEPTION(MessageTypeException, PHP_HTTP_EX_CE(message_type), PHP_HTTP_EX_DEF_CE);
66 PHP_HTTP_REGISTER_EXCEPTION(EncodingException, PHP_HTTP_EX_CE(encoding), PHP_HTTP_EX_DEF_CE);
67 PHP_HTTP_REGISTER_EXCEPTION(RequestException, PHP_HTTP_EX_CE(request), PHP_HTTP_EX_DEF_CE);
68
69 zend_declare_property_long(PHP_HTTP_EX_CE(request), "curlCode", lenof("curlCode"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
70
71 PHP_HTTP_REGISTER_EXCEPTION(RequestPoolException, PHP_HTTP_EX_CE(request_pool), PHP_HTTP_EX_DEF_CE);
72 PHP_HTTP_REGISTER_EXCEPTION(SocketException, PHP_HTTP_EX_CE(socket), PHP_HTTP_EX_DEF_CE);
73 PHP_HTTP_REGISTER_EXCEPTION(ResponseException, PHP_HTTP_EX_CE(response), PHP_HTTP_EX_DEF_CE);
74 PHP_HTTP_REGISTER_EXCEPTION(UrlException, PHP_HTTP_EX_CE(url), PHP_HTTP_EX_DEF_CE);
75 PHP_HTTP_REGISTER_EXCEPTION(QueryStringException, PHP_HTTP_EX_CE(querystring), PHP_HTTP_EX_DEF_CE);
76 PHP_HTTP_REGISTER_EXCEPTION(CookieException, PHP_HTTP_EX_CE(cookie), PHP_HTTP_EX_DEF_CE);
77
78 #if PHP_HTTP_DBG_EXCEPTIONS
79 zend_throw_exception_hook = php_http_exception_hook;
80 #endif
81
82 return SUCCESS;
83 }
84
85 zend_class_entry *php_http_exception_get_default(void)
86 {
87 return PHP_HTTP_EX_DEF_CE;
88 }
89
90 zend_class_entry *php_http_exception_get_for_code(long code)
91 {
92 zend_class_entry *ex = PHP_HTTP_EX_DEF_CE;
93
94 switch (code) {
95 case PHP_HTTP_E_RUNTIME: ex = PHP_HTTP_EX_CE(runtime); break;
96 case PHP_HTTP_E_INVALID_PARAM: ex = PHP_HTTP_EX_CE(invalid_param); break;
97 case PHP_HTTP_E_HEADER: ex = PHP_HTTP_EX_CE(header); break;
98 case PHP_HTTP_E_MALFORMED_HEADERS: ex = PHP_HTTP_EX_CE(malformed_headers); break;
99 case PHP_HTTP_E_REQUEST_METHOD: ex = PHP_HTTP_EX_CE(request_method); break;
100 case PHP_HTTP_E_MESSAGE: ex = PHP_HTTP_EX_CE(message); break;
101 case PHP_HTTP_E_MESSAGE_TYPE: ex = PHP_HTTP_EX_CE(message_type); break;
102 case PHP_HTTP_E_ENCODING: ex = PHP_HTTP_EX_CE(encoding); break;
103 case PHP_HTTP_E_REQUEST: ex = PHP_HTTP_EX_CE(request); break;
104 case PHP_HTTP_E_REQUEST_POOL: ex = PHP_HTTP_EX_CE(request_pool); break;
105 case PHP_HTTP_E_SOCKET: ex = PHP_HTTP_EX_CE(socket); break;
106 case PHP_HTTP_E_RESPONSE: ex = PHP_HTTP_EX_CE(response); break;
107 case PHP_HTTP_E_URL: ex = PHP_HTTP_EX_CE(url); break;
108 case PHP_HTTP_E_QUERYSTRING: ex = PHP_HTTP_EX_CE(querystring); break;
109 case PHP_HTTP_E_COOKIE: ex = PHP_HTTP_EX_CE(cookie); break;
110 }
111
112 return ex;
113 }
114
115 /*
116 * Local variables:
117 * tab-width: 4
118 * c-basic-offset: 4
119 * End:
120 * vim600: noet sw=4 ts=4 fdm=marker
121 * vim<600: noet sw=4 ts=4
122 */
123