forked from couchbase/php-ext-couchbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresget.h
178 lines (156 loc) · 5.09 KB
/
resget.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright 2012 Couchbase, Inc. |
+----------------------------------------------------------------------+
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| http://www.apache.org/licenses/LICENSE-2.0 |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Author: Mark Nunberg <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_COUCHBASE_H
#error "Include php_couchbase.h first"
#endif
#ifndef PCBC_RESGET_H_
#define PCBC_RESGET_H_
#include <stdarg.h>
/**
* Flags for various calling styles with PHP entry points
*/
enum {
/* no-op, but nice to have */
PHP_COUCHBASE_ARG_F_FUNCTIONAL,
/* this is a *multi variant */
PHP_COUCHBASE_ARG_F_MULTI = 1 << 0,
/* this is an oo variant */
PHP_COUCHBASE_ARG_F_OO = 1 << 1,
/* Specify that we expect an active async operation */
PHP_COUCHBASE_ARG_F_ASYNC = 1 << 2,
/* Specify that it's ok to not be connected */
PHP_COUCHBASE_ARG_F_NOCONN = 1 << 3
};
/** Only check that we have a valid pointer. Ignore any other checks */
#define PHP_COUCHBASE_ARG_F_ONLYVALID \
(PHP_COUCHBASE_ARG_F_NOCONN|PHP_COUCHBASE_ARG_F_ASYNC)
enum {
/* all ok */
PHP_COUCHBASE_RES_OK,
/* caller should return immediately */
PHP_COUCHBASE_RES_ERETURN,
/* resource is invalid */
PHP_COUCHBASE_RES_EINVAL,
/* resource is not yet connected */
PHP_COUCHBASE_RES_ENOTCONN,
/* async operations in progress */
PHP_COUCHBASE_RES_EBUSY,
};
/**
* Extract the resource from something.
* @param zvres (For functional only) - The zval which claims to be our resource
* @param argflags the argument/style flags
* @param A pointer to an error code (if we get an error)
* @param pres a pointer to a php_couchbase_res object. To be filled when we have
* a handle
*/
PHP_COUCHBASE_LOCAL
void php_couchbase_get_resource(INTERNAL_FUNCTION_PARAMETERS,
zval *zvres,
int argflags,
int *ec,
php_couchbase_res **pres);
/**
* Returns true on success, false on error
*/
PHP_COUCHBASE_LOCAL
int php_couchbase_res_ok(int ec TSRMLS_DC);
/**
* Gets a resource from a zval (or a getThis()). This macro must be called
* from within a zend entry point (or another function which has
* INTERNAL_FUNCTION_PARAMETERS in its prototype
*
* If an error is encountered, this macro will return from the calling code
* (i.e. the caller will return).
*
* @param cbres a pointer to a php_couchbase_res*. Will be populated
* @param zvres a pointer to a zval possibly containing the resource
* @param flags the argument flags for the style.
*/
#define PHP_COUCHBASE_GET_RESOURCE(cbres, zvres, flags) \
{ \
int pcbc__ec = -1; \
php_couchbase_get_resource(\
INTERNAL_FUNCTION_PARAM_PASSTHRU, \
zvres, \
flags,\
&pcbc__ec, \
&(cbres)\
); \
\
if (pcbc__ec == PHP_COUCHBASE_RES_ERETURN) { \
return; \
} else if (!php_couchbase_res_ok(pcbc__ec TSRMLS_CC)) { \
RETURN_FALSE; \
} \
}
/**
* Extracts the parameters and gets us a zval.
*
* If an error occurs in parsing the arguments or in extracting the couchbase
* resource, then the caller will return.
*
* @param zvres a zval* which will be assigned to contain the resource for the object
* @param resvar a php_couchbase_res * which will point to the object itself
* @param flags the argument flags
* @param fmt the argument format string
* @param ... extra pointers (dependent on format string)
*/
#define PHP_COUCHBASE_GET_PARAMS_WITH_ZV(zvres, resvar, flags, fmt, ...) \
{ \
if ( (flags) & PHP_COUCHBASE_ARG_F_OO) { \
if (zend_parse_parameters(\
ZEND_NUM_ARGS() TSRMLS_CC, fmt, \
## __VA_ARGS__) == FAILURE) { \
return; \
} \
\
zvres = getThis(); \
PHP_COUCHBASE_GET_RESOURCE(resvar, zvres, flags); \
\
} else { \
if (zend_parse_parameters(\
ZEND_NUM_ARGS() TSRMLS_CC, \
"r" fmt, &(zvres), ## __VA_ARGS__) == FAILURE) { \
return; \
} \
PHP_COUCHBASE_GET_RESOURCE(resvar, zvres, flags); \
} \
}
/**
* Wrapper around PHP_COUCHBASE_GET_PARAMS_WITH_ZV. Does not require to pass
* a zval* for a resource.
*/
#define PHP_COUCHBASE_GET_PARAMS(resvar, flags, fmt, ...) \
{ \
zval *pcbc__zv__res__dummy PHP_COUCHBASE_UNUSED; \
PHP_COUCHBASE_GET_PARAMS_WITH_ZV(\
pcbc__zv__res__dummy, \
resvar, flags, fmt, ## __VA_ARGS__); \
}
#endif /* PCBC_RESGET_H_ */
/*
* 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
*/