- define TSRMLS_FETCH_FROM_CTX and TSRMLS_SET_CTX if not defined
[m6w6/ext-http] / php_http_std_defs.h
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 #ifndef PHP_HTTP_STD_DEFS_H
19 #define PHP_HTTP_STD_DEFS_H
20
21 #if defined(PHP_WIN32)
22 # if defined(HTTP_EXPORTS)
23 # define PHP_HTTP_API __declspec(dllexport)
24 # elif defined(COMPILE_DL_HTTP)
25 # define PHP_HTTP_API __declspec(dllimport)
26 # else
27 # define PHP_HTTP_API
28 # endif
29 #else
30 # define PHP_HTTP_API
31 #endif
32
33 /* make functions that return SUCCESS|FAILURE more obvious */
34 typedef int STATUS;
35
36 /* lenof() */
37 #define lenof(S) (sizeof(S) - 1)
38
39 /* STR_SET() */
40 #define STR_SET(target, source) \
41 if(target) efree(target); \
42 target = source
43
44 /* return bool (v == SUCCESS) */
45 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
46 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
47 /* return object(values) */
48 #define RETVAL_OBJECT(o) \
49 RETVAL_OBJVAL((o)->value.obj)
50 #define RETURN_OBJECT(o) \
51 RETVAL_OBJECT(o); \
52 return
53 #define RETVAL_OBJVAL(ov) \
54 return_value->is_ref = 1; \
55 return_value->type = IS_OBJECT; \
56 return_value->value.obj = (ov); \
57 zval_add_ref(&return_value); \
58 zend_objects_store_add_ref(return_value TSRMLS_CC)
59 #define RETURN_OBJVAL(ov) \
60 RETVAL_OBJVAL(ov); \
61 return
62
63 /* function accepts no args */
64 #define NO_ARGS \
65 if (ZEND_NUM_ARGS()) { \
66 zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \
67 }
68
69 /* check if return value is used */
70 #define IF_RETVAL_USED \
71 if (!return_value_used) { \
72 return; \
73 } else
74
75 /* CR LF */
76 #define HTTP_CRLF "\r\n"
77
78 /* default cache control */
79 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
80
81 /* max URL length */
82 #define HTTP_URL_MAXLEN 2048
83 #define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
84
85 /* def URL arg separator */
86 #define HTTP_URL_ARGSEP "&"
87 #define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
88
89 /* send buffer size */
90 #define HTTP_SENDBUF_SIZE 2097152
91
92 /* CURL buffer size */
93 #define HTTP_CURLBUF_SIZE 16384
94
95 /* known methods */
96 #define HTTP_KNOWN_METHODS \
97 /* HTTP 1.1 */ \
98 "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \
99 /* WebDAV - RFC 2518 */ \
100 "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \
101 /* WebDAV Versioning - RFC 3253 */ \
102 "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \
103 "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \
104 /* WebDAV Access Control - RFC 3744 */ \
105 "ACL, " \
106 /* END */
107
108
109 /* server vars shorthand */
110 #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
111
112 #define HTTP_PHP_INI_ENTRY(entry, default, scope, updater, global) \
113 STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_http_globals, http_globals)
114
115 /* {{{ arrays */
116 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
117 #define FOREACH_HASH_VAL(hash, val) \
118 for ( zend_hash_internal_pointer_reset(hash); \
119 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
120 zend_hash_move_forward(hash))
121
122 #define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey)
123 #define FOREACH_HASH_KEY(hash, strkey, numkey) \
124 for ( zend_hash_internal_pointer_reset(hash); \
125 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \
126 zend_hash_move_forward(hash)) \
127
128 #define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val)
129 #define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \
130 for ( zend_hash_internal_pointer_reset(hash); \
131 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \
132 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
133 zend_hash_move_forward(hash)) \
134
135 #define array_copy(src, dst) zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
136 #define array_merge(src, dst) zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1)
137 #define array_append(src, dst) \
138 { \
139 ulong idx; \
140 uint klen; \
141 char *key = NULL; \
142 zval **data; \
143 \
144 for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \
145 zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \
146 zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \
147 zend_hash_move_forward(Z_ARRVAL_P(src))) \
148 { \
149 if (key) { \
150 zval **tmp; \
151 \
152 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \
153 if (Z_TYPE_PP(tmp) != IS_ARRAY) { \
154 convert_to_array_ex(tmp); \
155 } \
156 add_next_index_zval(*tmp, *data); \
157 } else { \
158 add_assoc_zval(dst, key, *data); \
159 } \
160 zval_add_ref(data); \
161 key = NULL; \
162 } \
163 } \
164 }
165 /* }}} */
166
167 #define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT)
168
169 /* {{{ objects & properties */
170 #ifdef ZEND_ENGINE_2
171
172 # define HTTP_STATIC_ME_ALIAS(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
173
174 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
175 { \
176 zend_class_entry ce; \
177 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
178 ce.create_object = name## _new; \
179 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
180 name## _ce->ce_flags |= flags; \
181 memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
182 name## _declare_default_properties(); \
183 }
184
185 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
186 { \
187 zend_class_entry ce; \
188 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
189 ce.create_object = NULL; \
190 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
191 name## _ce->ce_flags |= flags; \
192 }
193
194 # define getObject(t, o) getObjectEx(t, o, getThis())
195 # define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
196 # define OBJ_PROP(o) o->zo.properties
197 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
198 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
199 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
200 # define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v)
201 # define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n), (v) TSRMLS_CC)
202 # define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z)
203 # define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n), (z) TSRMLS_CC)
204 # define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n)
205 # define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n), 0 TSRMLS_CC)
206
207 # define INIT_PARR(o, n) \
208 { \
209 zval *__tmp; \
210 MAKE_STD_ZVAL(__tmp); \
211 array_init(__tmp); \
212 SET_PROP(o, n, __tmp); \
213 }
214
215 # define FREE_PARR(o, p) \
216 { \
217 zval *__tmp = NULL; \
218 if (__tmp = GET_PROP(o, p)) { \
219 zval_dtor(__tmp); \
220 FREE_ZVAL(__tmp); \
221 __tmp = NULL; \
222 } \
223 }
224
225 # define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
226 # define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
227 # define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
228 # define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
229
230 #endif /* ZEND_ENGINE_2 */
231 /* }}} */
232
233 #ifndef E_THROW
234 # define E_THROW 0
235 #endif
236
237 #define HTTP_E_UNKOWN 0L
238 #define HTTP_E_PARSE 1L
239 #define HTTP_E_HEADER 2L
240 #define HTTP_E_OBUFFER 3L
241 #define HTTP_E_CURL 4L
242 #define HTTP_E_ENCODE 5L
243 #define HTTP_E_PARAM 6L
244 #define HTTP_E_URL 7L
245 #define HTTP_E_MSG 8L
246
247 #ifdef HTTP_HAVE_CURL
248 # ifdef ZEND_ENGINE_2
249 # define HTTP_DECLARE_ARG_PASS_INFO() \
250 static \
251 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \
252 ZEND_ARG_PASS_INFO(0) \
253 ZEND_ARG_PASS_INFO(0) \
254 ZEND_ARG_PASS_INFO(1) \
255 ZEND_END_ARG_INFO(); \
256 \
257 static \
258 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \
259 ZEND_ARG_PASS_INFO(0) \
260 ZEND_ARG_PASS_INFO(0) \
261 ZEND_ARG_PASS_INFO(0) \
262 ZEND_ARG_PASS_INFO(1) \
263 ZEND_END_ARG_INFO(); \
264 \
265 static \
266 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_5, 0) \
267 ZEND_ARG_PASS_INFO(0) \
268 ZEND_ARG_PASS_INFO(0) \
269 ZEND_ARG_PASS_INFO(0) \
270 ZEND_ARG_PASS_INFO(0) \
271 ZEND_ARG_PASS_INFO(1) \
272 ZEND_END_ARG_INFO(); \
273 \
274 static \
275 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_all, 1) \
276 ZEND_ARG_PASS_INFO(1) \
277 ZEND_END_ARG_INFO()
278 # else
279 # define HTTP_DECLARE_ARG_PASS_INFO() \
280 static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
281 static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
282 static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
283 static unsigned char http_arg_pass_ref_all[]={1, BYREF_FORCE_REST}
284 # endif /* ZEND_ENGINE_2 */
285 #else
286 # define HTTP_DECLARE_ARG_PASS_INFO()
287 #endif /* HTTP_HAVE_CURL */
288
289
290 #ifndef TSRMLS_FETCH_FROM_CTX
291 # ifdef ZTS
292 # define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
293 # else
294 # define TSRMLS_FETCH_FROM_CTX(ctx)
295 # endif
296 #endif
297
298 #ifndef TSRMLS_SET_CTX
299 # ifdef ZTS
300 # define TSRMLS_SET_CTX(ctx) (void ***) ctx = tsrm_ls
301 # else
302 # define TSRMLS_SET_CTX(ctx)
303 # endif
304 #endif
305
306
307
308 #endif /* PHP_HTTP_STD_DEFS_H */
309
310 /*
311 * Local variables:
312 * tab-width: 4
313 * c-basic-offset: 4
314 * End:
315 * vim600: noet sw=4 ts=4 fdm=marker
316 * vim<600: noet sw=4 ts=4
317 */
318