forked from mkoppanen/php-tokyo_tyrant
-
Notifications
You must be signed in to change notification settings - Fork 1
/
php_tokyo_tyrant_private.h
152 lines (125 loc) · 4.64 KB
/
php_tokyo_tyrant_private.h
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
/*
+----------------------------------------------------------------------+
| PHP Version 5 / Tokyo tyrant |
+----------------------------------------------------------------------+
| Copyright (c) 2009 Mikko Koppanen |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 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_0.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. |
+----------------------------------------------------------------------+
| Authors: Mikko Koppanen <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef _PHP_TOKYO_TYRANT_PRIVATE_H_
# define _PHP_TOKYO_TYRANT_PRIVATE_H_
#include <tcrdb.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include "php_ini.h"
#include "ext/standard/url.h"
#include "SAPI.h"
#include "php_variables.h"
typedef struct _php_tt_conn {
TCRDB *rdb; /* database instance */
zend_bool connected; /* Are we connected to a db? */
zend_bool persistent; /* Is the instant persistent (?) */
} php_tt_conn;
/* {{{ typedef struct _php_tokyo_tyrant_object */
typedef struct _php_tokyo_tyrant_object {
zend_object zo;
php_tt_conn *conn; /* database connection */
} php_tokyo_tyrant_object;
/* }}} */
/* {{{ typedef struct _php_tokyo_tyrant_query_object */
typedef struct _php_tokyo_tyrant_query_object {
zend_object zo;
php_tt_conn *conn;
RDBQRY *qry;
zval *parent;
int pos;
TCLIST *res;
zend_bool executed;
} php_tokyo_tyrant_query_object;
/* }}} */
ZEND_BEGIN_MODULE_GLOBALS(tokyo_tyrant)
HashTable *connections;
HashTable *failures;
double default_timeout;
char *salt;
char *key_prefix;
int key_prefix_len;
zend_bool allow_failover;
long health_check_divisor;
long fail_threshold;
zend_bool php_expiration;
ZEND_END_MODULE_GLOBALS(tokyo_tyrant)
ZEND_EXTERN_MODULE_GLOBALS(tokyo_tyrant);
#ifdef ZTS
# define TOKYO_G(v) TSRMG(tokyo_tyrant_globals_id, zend_tokyo_tyrant_globals *, v)
#else
# define TOKYO_G(v) (tokyo_tyrant_globals.v)
#endif
#define PHP_TOKYO_OBJECT (php_tokyo_tyrant_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
#define PHP_TOKYO_QUERY_OBJECT (php_tokyo_tyrant_query_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
#define PHP_TOKYO_CHAIN_METHOD RETURN_ZVAL(getThis(), 1, 0);
#define PHP_TOKYO_TYRANT_DEFAULT_PORT 1978
#define PHP_TOKYO_TYRANT_OP_PUT 1
#define PHP_TOKYO_TYRANT_OP_PUTKEEP 2
#define PHP_TOKYO_TYRANT_OP_PUTCAT 3
#define PHP_TOKYO_TYRANT_OP_OUT 4
#define PHP_TOKYO_TYRANT_OP_TBLPUT 5
#define PHP_TOKYO_TYRANT_OP_TBLPUTKEEP 6
#define PHP_TOKYO_TYRANT_OP_TBLPUTCAT 7
#define PHP_TOKYO_TYRANT_OP_PUTNR 8
#define PHP_TOKYO_TYRANT_OP_TBLOUT 9
#define PHP_TOKYO_TYRANT_RECTYPE_INT 1
#define PHP_TOKYO_TYRANT_RECTYPE_DOUBLE 2
/* {{{ #define PHP_TOKYO_TYRANT_EXCEPTION(intern, format) */
#define PHP_TOKYO_TYRANT_EXCEPTION(intern, format) \
{ \
int error_code = tcrdbecode(intern->conn->rdb); \
if (error_code == TTENOREC) { \
RETURN_NULL(); \
} \
zend_throw_exception_ex(php_tokyo_tyrant_exception_sc_entry, error_code TSRMLS_CC, format, tcrdberrmsg(error_code)); \
return; \
}
/* }}} */
/* {{{ #define PHP_TOKYO_TYRANT_EXCEPTION_FREE(intern, format) */
#define PHP_TOKYO_TYRANT_EXCEPTION_FREE(intern, format) \
{ \
int error_code = tcrdbecode(intern->conn->rdb); \
zend_throw_exception_ex(php_tokyo_tyrant_exception_sc_entry, error_code TSRMLS_CC, format, tcrdberrmsg(error_code)); \
efree(format); \
return; \
}
/* }}} */
/* {{{ #define PHP_PHP_TOKYO_TYRANT_EXCEPTION_MSG(message) */
#define PHP_TOKYO_TYRANT_EXCEPTION_MSG(message) \
{ \
zend_throw_exception(php_tokyo_tyrant_exception_sc_entry, message, TTEMISC TSRMLS_CC); \
return; \
}
/* }}} */
/* {{{ #define PHP_TOKYO_CONNECTED_OBJECT(intern) */
#define PHP_TOKYO_CONNECTED_OBJECT(intern) \
{ \
intern = (php_tokyo_tyrant_object *)zend_object_store_get_object(getThis() TSRMLS_CC); \
if (!php_tt_is_connected(intern TSRMLS_CC)) \
PHP_TOKYO_TYRANT_EXCEPTION_MSG("Not connected to a database"); \
}
/* }}} */
#define DEBUG_M(args...) \
{ \
char *buf; \
spprintf(&buf, 1024, args); \
php_log_err(buf); \
efree(buf); \
} \
#endif /* _PHP_TOKYO_TYRANT_PRIVATE_H_ */