forked from laruence/yar
-
Notifications
You must be signed in to change notification settings - Fork 8
/
yar_exception.c
171 lines (139 loc) · 6.36 KB
/
yar_exception.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
+----------------------------------------------------------------------+
| Yar - Light, concurrent RPC framework |
+----------------------------------------------------------------------+
| Copyright (c) 2012-2013 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Xinchen Hui <[email protected]> |
| Zhenyu Zhang <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "Zend/zend_exceptions.h"
#include "php_yar.h"
#include "yar_response.h"
#include "yar_exception.h"
zend_class_entry *yar_server_exception_ce;
zend_class_entry *yar_server_request_exception_ce;
zend_class_entry *yar_server_protocol_exception_ce;
zend_class_entry *yar_server_packager_exception_ce;
zend_class_entry *yar_server_output_exception_ce;
zend_class_entry *yar_client_exception_ce;
zend_class_entry *yar_client_transport_exception_ce;
zend_class_entry *yar_client_packager_exception_ce;
zend_class_entry *yar_client_protocol_exception_ce;
zend_class_entry * php_yar_get_exception_base(int root TSRMLS_DC) /* {{{ */ {
#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
if (!root) {
if (!spl_ce_RuntimeException) {
zend_class_entry **pce;
if (zend_hash_find(CG(class_table), "runtimeexception", sizeof("RuntimeException"), (void **) &pce) == SUCCESS) {
spl_ce_RuntimeException = *pce;
return *pce;
}
} else {
return spl_ce_RuntimeException;
}
}
#endif
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2)
return zend_exception_get_default();
#else
return zend_exception_get_default(TSRMLS_C);
#endif
}
/* }}} */
void php_yar_error_ex(yar_response_t *response, int type TSRMLS_DC, const char *format, va_list args) /* {{{ */ {
char *msg;
uint len;
len = vspprintf(&msg, 0, format, args);
php_yar_response_set_error(response, type, msg, len TSRMLS_CC);
efree(msg);
return;
} /* }}} */
void php_yar_error(yar_response_t *response, int type TSRMLS_DC, const char *format, ...) /* {{{ */ {
va_list ap;
va_start(ap, format);
php_yar_error_ex(response, type TSRMLS_CC, format, ap);
va_end(ap);
return;
}
/* }}} */
/* {{{ proto Yar_Exception_Server::getType()
*/
PHP_METHOD(yar_exception_server, getType)
{
zval *type;
type = zend_read_property(yar_server_exception_ce, getThis(), ZEND_STRL("_type"), 0 TSRMLS_CC);
RETURN_ZVAL(type, 1, 0);
}
/* }}} */
/* {{{ proto Yar_Exception_Client::getType()
*/
PHP_METHOD(yar_exception_client, getType)
{
RETURN_STRINGL("Yar_Exception_Client", sizeof("Yar_Exception_Client") - 1, 1);
}
/* }}} */
/* {{{ yar_exception_server_methods */
zend_function_entry yar_exception_server_methods[] = {
PHP_ME(yar_exception_server, getType, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
/* {{{ yar_exception_client_methods */
zend_function_entry yar_exception_client_methods[] = {
PHP_ME(yar_exception_client, getType, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
YAR_STARTUP_FUNCTION(exception) /* {{{ */ {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Yar_Server_Exception", yar_exception_server_methods);
yar_server_exception_ce = zend_register_internal_class_ex(&ce, php_yar_get_exception_base(0 TSRMLS_CC), NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Server_Request_Exception", NULL);
yar_server_request_exception_ce = zend_register_internal_class_ex(&ce, yar_server_exception_ce, NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Server_Protocol_Exception", NULL);
yar_server_protocol_exception_ce = zend_register_internal_class_ex(&ce, yar_server_exception_ce, NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Server_Packager_Exception", NULL);
yar_server_packager_exception_ce = zend_register_internal_class_ex(&ce, yar_server_exception_ce, NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Server_Output_Exception", NULL);
yar_server_output_exception_ce = zend_register_internal_class_ex(&ce, yar_server_exception_ce, NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Client_Exception", yar_exception_client_methods);
yar_client_exception_ce = zend_register_internal_class_ex(&ce, php_yar_get_exception_base(0 TSRMLS_CC), NULL TSRMLS_CC);
zend_declare_property_stringl(yar_server_exception_ce, ZEND_STRL("_type"), ZEND_STRL("Yar_Exception_Server"), ZEND_ACC_PROTECTED TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Client_Transport_Exception", NULL);
yar_client_transport_exception_ce = zend_register_internal_class_ex(&ce, yar_client_exception_ce, NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Client_Packager_Exception", NULL);
yar_client_packager_exception_ce = zend_register_internal_class_ex(&ce, yar_client_exception_ce, NULL TSRMLS_CC);
INIT_CLASS_ENTRY(ce, "Yar_Client_Protocol_Exception", NULL);
yar_client_protocol_exception_ce = zend_register_internal_class_ex(&ce, yar_client_exception_ce, NULL TSRMLS_CC);
REGISTER_LONG_CONSTANT("YAR_ERR_OKEY", YAR_ERR_OKEY, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("YAR_ERR_OUTPUT", YAR_ERR_OUTPUT, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("YAR_ERR_TRANSPORT", YAR_ERR_TRANSPORT, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("YAR_ERR_REQUEST", YAR_ERR_REQUEST, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("YAR_ERR_PROTOCOL", YAR_ERR_PROTOCOL, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("YAR_ERR_PACKAGER", YAR_ERR_EXCEPTION, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("YAR_ERR_EXCEPTION", YAR_ERR_EXCEPTION, CONST_CS|CONST_PERSISTENT);
return SUCCESS;
} /* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/