-
Notifications
You must be signed in to change notification settings - Fork 12
/
zookeeper_client_exceptions.c
98 lines (84 loc) · 3.47 KB
/
zookeeper_client_exceptions.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
/* $Id$ */
#include "zookeeper_client_exceptions.h"
#include "error_codes.h"
#include <Zend/zend_exceptions.h>
// ---- Core functions ----
void register_zookeeper_client_exception_classes(TSRMLS_D)
{
zend_class_entry class_entry;
zend_class_entry **runtime_exception_class_entry = NULL;
#if PHP_VERSION_ID >= 70000
zend_string *runtime_exception_class_name;
#else
#endif
INIT_CLASS_ENTRY(class_entry, "ZookeeperClientException", NULL);
#if PHP_VERSION_ID >= 70000
runtime_exception_class_name = zend_string_init("runtimeexception", strlen("runtimeexception"), 0);
if ((runtime_exception_class_entry = zend_hash_find_ptr(CG(class_table), runtime_exception_class_name)) != NULL) {
zookeeper_client_exception_class_entry = zend_register_internal_class_ex(&class_entry, runtime_exception_class_entry);
#else
if (zend_hash_find(CG(class_table), "runtimeexception", sizeof("RuntimeException"), (void **) &runtime_exception_class_entry) == SUCCESS) {
zookeeper_client_exception_class_entry = zend_register_internal_class_ex(&class_entry, *runtime_exception_class_entry, NULL TSRMLS_CC);
#endif
} else {
zookeeper_client_exception_class_entry = zend_register_internal_class_ex(&class_entry
#if PHP_VERSION_ID < 70000
, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC
#else
, zend_ce_exception
#endif
);
}
INIT_CLASS_ENTRY(class_entry, "ZookeeperClientCoreException", NULL);
zookeeper_client_core_exception_class_entry = zend_register_internal_class_ex(&class_entry, zookeeper_client_exception_class_entry
#if PHP_VERSION_ID < 70000
, "ZookeeperClientException" TSRMLS_CC
#endif
);
}
void register_zookeeper_client_exception_class_constants(INIT_FUNC_ARGS)
{
// ERR_*
zend_declare_class_constant_long(zookeeper_client_exception_class_entry, ZEND_STRS("ERR_INIT_FAILURE") - 1, LIBZOOKEEPER_ERROR_INIT_FAILURE TSRMLS_CC);
zend_declare_class_constant_long(zookeeper_client_exception_class_entry, ZEND_STRS("ERR_CONNECT_FIRST") - 1, LIBZOOKEEPER_ERROR_CONNECT_FIRST TSRMLS_CC);
zend_declare_class_constant_long(zookeeper_client_exception_class_entry, ZEND_STRS("ERR_CLOSE_FIRST") - 1, LIBZOOKEEPER_ERROR_CLOSE_FIRST TSRMLS_CC);
}
void throw_zookeeper_client_exception(char *message, int code TSRMLS_DC)
{
zend_throw_exception(zookeeper_client_exception_class_entry, message, code TSRMLS_CC);
}
void throw_zookeeper_client_core_exception(int code TSRMLS_DC)
{
char *message;
if (code == ZOK)
return;
message = (char *)zerror(code);
zend_throw_exception(zookeeper_client_core_exception_class_entry, message, (long)code TSRMLS_CC);
}
void throw_domain_exception(char *message, int code TSRMLS_DC)
{
zend_class_entry **domain_exception_class_entry_pp = NULL;
char *domain_exception_class_name = "domainexception";
domain_exception_class_entry_pp = (zend_class_entry **)zend_hash_str_find_ptr(CG(class_table), domain_exception_class_name, strlen(domain_exception_class_name)
#ifndef ZEND_ENGINE_3
+ 1
#endif
);
if (NULL == domain_exception_class_entry_pp) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not find class `DomainException`");
return;
}
zend_throw_exception(
#ifndef ZEND_ENGINE_3
*
#endif
domain_exception_class_entry_pp, message, code TSRMLS_CC);
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 expandtab fdm=marker
* vim<600: noet sw=4 ts=4 expandtab
*/