- forward until we find a digit
[m6w6/ext-http] / http_exception_object.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22 #include "php.h"
23
24 #ifdef ZEND_ENGINE_2
25
26 #include "zend_exceptions.h"
27
28 #include "php_http.h"
29 #include "php_http_std_defs.h"
30 #include "php_http_exception_object.h"
31
32 #define HTTP_EX_DEF_CE http_exception_object_ce
33 zend_class_entry *http_exception_object_ce;
34 #define HTTP_EX_CE(name) http_ ##name## _exception_object_ce
35 zend_class_entry *HTTP_EX_CE(runtime);
36 zend_class_entry *HTTP_EX_CE(header);
37 zend_class_entry *HTTP_EX_CE(malformed_headers);
38 zend_class_entry *HTTP_EX_CE(request_method);
39 zend_class_entry *HTTP_EX_CE(message_type);
40 zend_class_entry *HTTP_EX_CE(invalid_param);
41 zend_class_entry *HTTP_EX_CE(encoding);
42 zend_class_entry *HTTP_EX_CE(request);
43 zend_class_entry *HTTP_EX_CE(request_pool);
44 zend_class_entry *HTTP_EX_CE(socket);
45 zend_class_entry *HTTP_EX_CE(response);
46 zend_class_entry *HTTP_EX_CE(url);
47
48 void _http_exception_object_init(INIT_FUNC_ARGS)
49 {
50 HTTP_REGISTER_EXCEPTION(HttpException, http_exception_object_ce, zend_exception_get_default());
51 HTTP_REGISTER_EXCEPTION(HttpRuntimeException, HTTP_EX_CE(runtime), HTTP_EX_DEF_CE);
52 HTTP_REGISTER_EXCEPTION(HttpInvalidParamException, HTTP_EX_CE(invalid_param), HTTP_EX_DEF_CE);
53 HTTP_REGISTER_EXCEPTION(HttpHeaderException, HTTP_EX_CE(header), HTTP_EX_DEF_CE);
54 HTTP_REGISTER_EXCEPTION(HttpMalformedHeadersException, HTTP_EX_CE(malformed_headers), HTTP_EX_DEF_CE);
55 HTTP_REGISTER_EXCEPTION(HttpRequestMethodException, HTTP_EX_CE(request_method), HTTP_EX_DEF_CE);
56 HTTP_REGISTER_EXCEPTION(HttpMessageTypeException, HTTP_EX_CE(message_type), HTTP_EX_DEF_CE);
57 HTTP_REGISTER_EXCEPTION(HttpEncodingException, HTTP_EX_CE(encoding), HTTP_EX_DEF_CE);
58 HTTP_REGISTER_EXCEPTION(HttpRequestException, HTTP_EX_CE(request), HTTP_EX_DEF_CE);
59 HTTP_REGISTER_EXCEPTION(HttpRequestPoolException, HTTP_EX_CE(request_pool), HTTP_EX_DEF_CE);
60 HTTP_REGISTER_EXCEPTION(HttpSocketException, HTTP_EX_CE(socket), HTTP_EX_DEF_CE);
61 HTTP_REGISTER_EXCEPTION(HttpResponseException, HTTP_EX_CE(response), HTTP_EX_DEF_CE);
62 HTTP_REGISTER_EXCEPTION(HttpUrlException, HTTP_EX_CE(url), HTTP_EX_DEF_CE);
63
64 HTTP_LONG_CONSTANT("HTTP_E_RUNTIME", HTTP_E_RUNTIME);
65 HTTP_LONG_CONSTANT("HTTP_E_INVALID_PARAM", HTTP_E_INVALID_PARAM);
66 HTTP_LONG_CONSTANT("HTTP_E_HEADER", HTTP_E_HEADER);
67 HTTP_LONG_CONSTANT("HTTP_E_MALFORMED_HEADERS", HTTP_E_MALFORMED_HEADERS);
68 HTTP_LONG_CONSTANT("HTTP_E_REQUEST_METHOD", HTTP_E_REQUEST_METHOD);
69 HTTP_LONG_CONSTANT("HTTP_E_MESSAGE_TYPE", HTTP_E_MESSAGE_TYPE);
70 HTTP_LONG_CONSTANT("HTTP_E_ENCODING", HTTP_E_ENCODING);
71 HTTP_LONG_CONSTANT("HTTP_E_REQUEST", HTTP_E_REQUEST);
72 HTTP_LONG_CONSTANT("HTTP_E_REQUEST_POOL", HTTP_E_REQUEST_POOL);
73 HTTP_LONG_CONSTANT("HTTP_E_SOCKET", HTTP_E_SOCKET);
74 HTTP_LONG_CONSTANT("HTTP_E_RESPONSE", HTTP_E_RESPONSE);
75 HTTP_LONG_CONSTANT("HTTP_E_URL", HTTP_E_URL);
76 }
77
78 zend_class_entry *_http_exception_get_default()
79 {
80 return http_exception_object_ce;
81 }
82
83 zend_class_entry *_http_exception_get_for_code(long code)
84 {
85 zend_class_entry *ex = http_exception_object_ce;
86
87 switch (code)
88 {
89 case HTTP_E_RUNTIME: ex = HTTP_EX_CE(runtime); break;
90 case HTTP_E_INVALID_PARAM: ex = HTTP_EX_CE(invalid_param); break;
91 case HTTP_E_HEADER: ex = HTTP_EX_CE(header); break;
92 case HTTP_E_MALFORMED_HEADERS: ex = HTTP_EX_CE(malformed_headers); break;
93 case HTTP_E_REQUEST_METHOD: ex = HTTP_EX_CE(request_method); break;
94 case HTTP_E_MESSAGE_TYPE: ex = HTTP_EX_CE(message_type); break;
95 case HTTP_E_ENCODING: ex = HTTP_EX_CE(encoding); break;
96 case HTTP_E_REQUEST: ex = HTTP_EX_CE(request); break;
97 case HTTP_E_REQUEST_POOL: ex = HTTP_EX_CE(request_pool); break;
98 case HTTP_E_SOCKET: ex = HTTP_EX_CE(socket); break;
99 case HTTP_E_RESPONSE: ex = HTTP_EX_CE(response); break;
100 case HTTP_E_URL: ex = HTTP_EX_CE(url); break;
101 }
102
103 return ex;
104 }
105
106 #endif
107
108 /*
109 * Local variables:
110 * tab-width: 4
111 * c-basic-offset: 4
112 * End:
113 * vim600: noet sw=4 ts=4 fdm=marker
114 * vim<600: noet sw=4 ts=4
115 */
116