- new negotiator + test
[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 #ifndef MIN
40 # define MIN(a,b) (a<b?a:b)
41 #endif
42 #ifndef MAX
43 # define MAX(a,b) (a>b?a:b)
44 #endif
45
46 /* STR_SET() */
47 #ifndef STR_SET
48 # define STR_SET(STR, SET) \
49 { \
50 STR_FREE(STR); \
51 STR = SET; \
52 }
53 #endif
54
55 /* return bool (v == SUCCESS) */
56 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
57 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
58 /* return object(values) */
59 #define RETVAL_OBJECT(o) \
60 RETVAL_OBJVAL((o)->value.obj)
61 #define RETURN_OBJECT(o) \
62 RETVAL_OBJECT(o); \
63 return
64 #define RETVAL_OBJVAL(ov) \
65 ZVAL_OBJVAL(return_value, ov)
66 #define RETURN_OBJVAL(ov) \
67 RETVAL_OBJVAL(ov); \
68 return
69 #define ZVAL_OBJVAL(zv, ov) \
70 (zv)->is_ref = 1; \
71 (zv)->type = IS_OBJECT; \
72 (zv)->value.obj = (ov); \
73 if (Z_OBJ_HT_P(zv)->add_ref) { \
74 Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \
75 }
76
77 /* function accepts no args */
78 #define NO_ARGS \
79 if (ZEND_NUM_ARGS()) { \
80 zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \
81 }
82
83 /* check if return value is used */
84 #define IF_RETVAL_USED \
85 if (!return_value_used) { \
86 return; \
87 } else
88
89 /* CR LF */
90 #define HTTP_CRLF "\r\n"
91
92 /* default cache control */
93 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
94
95 /* max URL length */
96 #define HTTP_URL_MAXLEN 2048
97 #define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
98
99 /* def URL arg separator */
100 #define HTTP_URL_ARGSEP "&"
101 #define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
102
103 /* send buffer size */
104 #define HTTP_SENDBUF_SIZE 2097152
105
106 /* CURL buffer size */
107 #define HTTP_CURLBUF_SIZE 16384
108
109 /* known methods */
110 #define HTTP_KNOWN_METHODS \
111 /* HTTP 1.1 */ \
112 "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \
113 /* WebDAV - RFC 2518 */ \
114 "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \
115 /* WebDAV Versioning - RFC 3253 */ \
116 "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \
117 "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \
118 /* WebDAV Access Control - RFC 3744 */ \
119 "ACL, " \
120 /* END */
121
122
123 #define HTTP_PHP_INI_ENTRY(entry, default, scope, updater, global) \
124 STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_http_globals, http_globals)
125 #define HTTP_PHP_INI_ENTRY_EX(entry, default, scope, updater, displayer, global) \
126 STD_PHP_INI_ENTRY_EX(entry, default, scope, updater, global, zend_http_globals, http_globals, displayer)
127
128 /* {{{ arrays */
129 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
130 #define FOREACH_HASH_VAL(hash, val) \
131 for ( zend_hash_internal_pointer_reset(hash); \
132 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
133 zend_hash_move_forward(hash))
134
135 #define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey)
136 #define FOREACH_HASH_KEY(hash, strkey, numkey) \
137 for ( zend_hash_internal_pointer_reset(hash); \
138 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \
139 zend_hash_move_forward(hash)) \
140
141 #define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val)
142 #define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \
143 for ( zend_hash_internal_pointer_reset(hash); \
144 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \
145 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
146 zend_hash_move_forward(hash)) \
147
148 #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 *))
149 #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)
150 #define array_append(src, dst) \
151 { \
152 ulong idx; \
153 uint klen; \
154 char *key = NULL; \
155 zval **data; \
156 \
157 for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \
158 zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \
159 zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \
160 zend_hash_move_forward(Z_ARRVAL_P(src))) \
161 { \
162 if (key) { \
163 zval **tmp; \
164 \
165 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \
166 if (Z_TYPE_PP(tmp) != IS_ARRAY) { \
167 convert_to_array_ex(tmp); \
168 } \
169 add_next_index_zval(*tmp, *data); \
170 } else { \
171 add_assoc_zval(dst, key, *data); \
172 } \
173 zval_add_ref(data); \
174 key = NULL; \
175 } \
176 } \
177 }
178 /* }}} */
179
180 #define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT)
181
182 /* {{{ objects & properties */
183 #ifdef ZEND_ENGINE_2
184
185 # define HTTP_STATIC_ME_ALIAS(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
186
187 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
188 { \
189 zend_class_entry ce; \
190 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
191 ce.create_object = name## _new; \
192 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
193 name## _ce->ce_flags |= flags; \
194 memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
195 zend_hash_init(& name## _ce->constants_table, 0, NULL, ZVAL_INTERNAL_PTR_DTOR, 1); \
196 name## _declare_default_properties(); \
197 }
198
199 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
200 { \
201 zend_class_entry ce; \
202 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
203 ce.create_object = NULL; \
204 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
205 name## _ce->ce_flags |= flags; \
206 }
207
208 # define HTTP_REGISTER_EXCEPTION(classname, cename, parent) \
209 { \
210 zend_class_entry ce; \
211 INIT_CLASS_ENTRY(ce, #classname, NULL); \
212 ce.create_object = NULL; \
213 cename = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
214 }
215
216 # define getObject(t, o) getObjectEx(t, o, getThis())
217 # define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
218 # define putObject(t, o) zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) t## _free, NULL TSRMLS_CC);
219 # define OBJ_PROP(o) (o)->zo.properties
220
221 # define DCL_STATIC_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
222 # define DCL_STATIC_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
223 # define DCL_STATIC_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
224 # define GET_STATIC_PROP_EX(ce, n) zend_std_get_static_property(ce, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
225 # define UPD_STATIC_PROP_EX(ce, t, n, v) zend_update_static_property_ ##t(ce, #n, sizeof(#n)-1, (v) TSRMLS_CC)
226 # define UPD_STATIC_STRL_EX(ce, n, v, l) zend_update_static_property_stringl(ce, #n, sizeof(#n)-1, (v), (l) TSRMLS_CC)
227 # define SET_STATIC_PROP_EX(ce, n, v) zend_update_static_property(ce, #n, sizeof(#n)-1, v TSRMLS_CC)
228
229 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
230 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
231 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC)
232 # define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v)
233 # define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC)
234 # define UPD_STRL(o, n, v, l) zend_update_property_stringl(o->zo.ce, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC)
235 # define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z)
236 # define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC)
237 # define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n)
238 # define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
239
240 # define DCL_CONST(t, n, v) zend_declare_class_constant_ ##t(ce, (n), sizeof(n)-1, (v) TSRMLS_CC)
241
242 # define ACC_PROP_PRIVATE(ce, flags) ((flags & ZEND_ACC_PRIVATE) && (EG(scope) && ce == EG(scope))
243 # define ACC_PROP_PROTECTED(ce, flags) ((flags & ZEND_ACC_PROTECTED) && (zend_check_protected(ce, EG(scope))))
244 # define ACC_PROP_PUBLIC(flags) (flags & ZEND_ACC_PUBLIC)
245 # define ACC_PROP(ce, flags) (ACC_PROP_PUBLIC(flags) || ACC_PROP_PRIVATE(ce, flags) || ACC_PROP_PROTECTED(ce, flags))
246
247 # define INIT_PARR(o, n) \
248 { \
249 zval *__tmp; \
250 MAKE_STD_ZVAL(__tmp); \
251 array_init(__tmp); \
252 SET_PROP(o, n, __tmp); \
253 }
254
255 # define FREE_PARR(o, p) \
256 { \
257 zval *__tmp = GET_PROP(o, p); \
258 if (__tmp) { \
259 zval_dtor(__tmp); \
260 FREE_ZVAL(__tmp); \
261 __tmp = NULL; \
262 } \
263 }
264
265 # define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
266 # define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
267 # define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
268 # define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
269
270 #endif /* ZEND_ENGINE_2 */
271 /* }}} */
272
273 #ifndef E_THROW
274 # define E_THROW 0
275 #endif
276 #ifdef ZEND_ENGINE_2
277 # define HE_THROW E_THROW TSRMLS_CC
278 # define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE) TSRMLS_CC
279 # define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING) TSRMLS_CC
280 # define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR) TSRMLS_CC
281 #else
282 # define HE_THROW E_WARNING TSRMLS_CC
283 # define HE_NOTICE E_NOTICE TSRMLS_CC
284 # define HE_WARNING E_WARNING TSRMLS_CC
285 # define HE_ERROR E_ERROR TSRMLS_CC
286 #endif
287
288 #define HTTP_E_RUNTIME 1L
289 #define HTTP_E_INVALID_PARAM 2L
290 #define HTTP_E_HEADER 3L
291 #define HTTP_E_MALFORMED_HEADERS 4L
292 #define HTTP_E_REQUEST_METHOD 5L
293 #define HTTP_E_MESSAGE_TYPE 6L
294 #define HTTP_E_ENCODING 7L
295 #define HTTP_E_REQUEST 8L
296 #define HTTP_E_REQUEST_POOL 9L
297 #define HTTP_E_SOCKET 10L
298 #define HTTP_E_RESPONSE 11L
299 #define HTTP_E_URL 12L
300
301 #ifdef ZEND_ENGINE_2
302 # define HTTP_BEGIN_ARGS_EX(class, method, ret_ref, req_args) static ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 0, ret_ref, req_args)
303 # define HTTP_BEGIN_ARGS_AR(class, method, ret_ref, req_args) static ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 1, ret_ref, req_args)
304 # define HTTP_END_ARGS }
305 # define HTTP_EMPTY_ARGS_EX(class, method, ret_ref) HTTP_BEGIN_ARGS_EX(class, method, ret_ref, 0) HTTP_END_ARGS
306 # define HTTP_ARGS(class, method) args_for_ ##class## _ ##method
307 # define HTTP_ARG_VAL(name, pass_ref) ZEND_ARG_INFO(pass_ref, name)
308 # define HTTP_ARG_OBJ(class, name, allow_null) ZEND_ARG_OBJ_INFO(0, name, class, allow_null)
309 #endif
310
311 #ifdef ZEND_ENGINE_2
312 # define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0}
313 #else
314 # define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL}
315 #endif
316
317 #ifdef HTTP_HAVE_CURL
318 # ifdef ZEND_ENGINE_2
319 # define HTTP_DECLARE_ARG_PASS_INFO() \
320 static \
321 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \
322 ZEND_ARG_PASS_INFO(0) \
323 ZEND_ARG_PASS_INFO(0) \
324 ZEND_ARG_PASS_INFO(1) \
325 ZEND_END_ARG_INFO(); \
326 \
327 static \
328 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \
329 ZEND_ARG_PASS_INFO(0) \
330 ZEND_ARG_PASS_INFO(0) \
331 ZEND_ARG_PASS_INFO(0) \
332 ZEND_ARG_PASS_INFO(1) \
333 ZEND_END_ARG_INFO(); \
334 \
335 static \
336 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_5, 0) \
337 ZEND_ARG_PASS_INFO(0) \
338 ZEND_ARG_PASS_INFO(0) \
339 ZEND_ARG_PASS_INFO(0) \
340 ZEND_ARG_PASS_INFO(0) \
341 ZEND_ARG_PASS_INFO(1) \
342 ZEND_END_ARG_INFO(); \
343 \
344 static \
345 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_all, 1) \
346 ZEND_ARG_PASS_INFO(1) \
347 ZEND_END_ARG_INFO()
348 # else
349 # define HTTP_DECLARE_ARG_PASS_INFO() \
350 static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
351 static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
352 static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
353 static unsigned char http_arg_pass_ref_all[]={1, BYREF_FORCE_REST}
354 # endif /* ZEND_ENGINE_2 */
355 #else
356 # define HTTP_DECLARE_ARG_PASS_INFO()
357 #endif /* HTTP_HAVE_CURL */
358
359
360 #ifndef TSRMLS_FETCH_FROM_CTX
361 # ifdef ZTS
362 # define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
363 # else
364 # define TSRMLS_FETCH_FROM_CTX(ctx)
365 # endif
366 #endif
367
368 #ifndef TSRMLS_SET_CTX
369 # ifdef ZTS
370 # define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls
371 # else
372 # define TSRMLS_SET_CTX(ctx)
373 # endif
374 #endif
375
376
377
378 #endif /* PHP_HTTP_STD_DEFS_H */
379
380 /*
381 * Local variables:
382 * tab-width: 4
383 * c-basic-offset: 4
384 * End:
385 * vim600: noet sw=4 ts=4 fdm=marker
386 * vim<600: noet sw=4 ts=4
387 */
388