2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2005, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
15 #ifndef PHP_HTTP_STD_DEFS_H
16 #define PHP_HTTP_STD_DEFS_H
18 #if defined(PHP_WIN32)
19 # if defined(HTTP_EXPORTS)
20 # define PHP_HTTP_API __declspec(dllexport)
21 # elif defined(COMPILE_DL_HTTP)
22 # define PHP_HTTP_API __declspec(dllimport)
30 /* make functions that return SUCCESS|FAILURE more obvious */
34 #define lenof(S) (sizeof(S) - 1)
37 # define MIN(a,b) (a<b?a:b)
40 # define MAX(a,b) (a>b?a:b)
45 # define STR_SET(STR, SET) \
52 #define INIT_ZARR(zv, ht) \
55 Z_TYPE(zv) = IS_ARRAY; \
56 Z_ARRVAL(zv) = (ht); \
59 /* return bool (v == SUCCESS) */
60 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
61 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
62 /* return object(values) */
63 #define RETVAL_OBJECT(o) \
64 RETVAL_OBJVAL((o)->value.obj)
65 #define RETURN_OBJECT(o) \
68 #define RETVAL_OBJVAL(ov) \
69 ZVAL_OBJVAL(return_value, ov) \
70 if (Z_OBJ_HT_P(return_value)->add_ref) { \
71 Z_OBJ_HT_P(return_value)->add_ref(return_value TSRMLS_CC); \
73 #define RETURN_OBJVAL(ov) \
76 #define ZVAL_OBJVAL(zv, ov) \
77 (zv)->type = IS_OBJECT; \
78 (zv)->value.obj = (ov);
80 /* function accepts no args */
82 if (ZEND_NUM_ARGS()) { \
83 zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \
86 /* check if return value is used */
87 #define IF_RETVAL_USED \
88 if (!return_value_used) { \
93 #define HTTP_CRLF "\r\n"
95 /* default cache control */
96 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
99 #define HTTP_URL_MAXLEN 2048
100 #define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
102 /* def URL arg separator */
103 #define HTTP_URL_ARGSEP "&"
104 #define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
106 /* send buffer size */
107 #define HTTP_SENDBUF_SIZE 40960
109 /* CURL buffer size */
110 #define HTTP_CURLBUF_SIZE 16384
113 #define HTTP_KNOWN_METHODS \
115 "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \
116 /* WebDAV - RFC 2518 */ \
117 "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \
118 /* WebDAV Versioning - RFC 3253 */ \
119 "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \
120 "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \
121 /* WebDAV Access Control - RFC 3744 */ \
126 #define HTTP_PHP_INI_ENTRY(entry, default, scope, updater, global) \
127 STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_http_globals, http_globals)
128 #define HTTP_PHP_INI_ENTRY_EX(entry, default, scope, updater, displayer, global) \
129 STD_PHP_INI_ENTRY_EX(entry, default, scope, updater, global, zend_http_globals, http_globals, displayer)
132 #define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, Z_ARRVAL_P(array), val)
133 #define FOREACH_HASH_VAL(pos, hash, val) \
134 for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
135 zend_hash_get_current_data_ex(hash, (void **) &val, &pos) == SUCCESS; \
136 zend_hash_move_forward_ex(hash, &pos))
138 #define FOREACH_KEY(pos, array, strkey, numkey) FOREACH_HASH_KEY(pos, Z_ARRVAL_P(array), strkey, numkey)
139 #define FOREACH_HASH_KEY(pos, hash, strkey, numkey) \
140 for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
141 zend_hash_get_current_key_ex(hash, &strkey, NULL, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \
142 zend_hash_move_forward_ex(hash, &pos)) \
144 #define FOREACH_KEYLEN(pos, array, strkey, keylen, numkey) FOREACH_HASH_KEYLEN(pos, Z_ARRVAL_P(array), strkey, keylen, numkey)
145 #define FOREACH_HASH_KEYLEN(pos, hash, strkey, keylen, numkey) \
146 for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
147 zend_hash_get_current_key_ex(hash, &strkey, &keylen, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \
148 zend_hash_move_forward_ex(hash, &pos)) \
150 #define FOREACH_KEYVAL(pos, array, strkey, numkey, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), strkey, numkey, val)
151 #define FOREACH_HASH_KEYVAL(pos, hash, strkey, numkey, val) \
152 for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
153 zend_hash_get_current_key_ex(hash, &strkey, NULL, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT && \
154 zend_hash_get_current_data_ex(hash, (void **) &val, &pos) == SUCCESS; \
155 zend_hash_move_forward_ex(hash, &pos))
157 #define FOREACH_KEYLENVAL(pos, array, strkey, keylen, numkey, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), strkey, keylen, numkey, val)
158 #define FOREACH_HASH_KEYLENVAL(pos, hash, strkey, keylen, numkey, val) \
159 for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
160 zend_hash_get_current_key_ex(hash, &strkey, &keylen, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT && \
161 zend_hash_get_current_data_ex(hash, (void **) &val, &pos) == SUCCESS; \
162 zend_hash_move_forward_ex(hash, &pos))
164 #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 *))
165 #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)
166 #define array_append(src, dst) \
174 for ( zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(src), &pos); \
175 zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, &pos) != HASH_KEY_NON_EXISTANT && \
176 zend_hash_get_current_data_ex(Z_ARRVAL_P(src), (void **) &data, &pos) == SUCCESS; \
177 zend_hash_move_forward_ex(Z_ARRVAL_P(src), &pos)) \
182 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \
183 if (Z_TYPE_PP(tmp) != IS_ARRAY) { \
184 convert_to_array_ex(tmp); \
186 add_next_index_zval(*tmp, *data); \
188 add_assoc_zval(dst, key, *data); \
190 ZVAL_ADDREF(*data); \
197 #define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT)
199 /* {{{ objects & properties */
202 # define HTTP_STATIC_ME_ALIAS(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
204 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
206 zend_class_entry ce; \
207 memset(&ce, 0, sizeof(zend_class_entry)); \
208 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
209 ce.create_object = _ ##name## _new; \
210 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
211 name## _ce->ce_flags |= flags; \
212 memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
213 zend_hash_init(& name## _ce->constants_table, 0, NULL, ZVAL_INTERNAL_PTR_DTOR, 1); \
214 name## _declare_default_properties(); \
217 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
219 zend_class_entry ce; \
220 memset(&ce, 0, sizeof(zend_class_entry)); \
221 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
222 ce.create_object = NULL; \
223 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
224 name## _ce->ce_flags |= flags; \
227 # define HTTP_REGISTER_EXCEPTION(classname, cename, parent) \
229 zend_class_entry ce; \
230 memset(&ce, 0, sizeof(zend_class_entry)); \
231 INIT_CLASS_ENTRY(ce, #classname, NULL); \
232 ce.create_object = NULL; \
233 cename = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
236 # define getObject(t, o) getObjectEx(t, o, getThis())
237 # define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
238 # 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);
239 # define OBJ_PROP(o) (o)->zo.properties
241 # 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)
242 # 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)
243 # define DCL_STATIC_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC)
244 # define GET_STATIC_PROP_EX(ce, n) zend_std_get_static_property(ce, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
245 # define UPD_STATIC_PROP_EX(ce, t, n, v) zend_update_static_property_ ##t(ce, #n, sizeof(#n)-1, (v) TSRMLS_CC)
246 # define UPD_STATIC_STRL_EX(ce, n, v, l) zend_update_static_property_stringl(ce, #n, sizeof(#n)-1, (v), (l) TSRMLS_CC)
247 # define SET_STATIC_PROP_EX(ce, n, v) zend_update_static_property(ce, #n, sizeof(#n)-1, v TSRMLS_CC)
249 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
250 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
251 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC)
252 # define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v)
253 # define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC)
254 # define UPD_STRL(o, n, v, l) zend_update_property_stringl(o->zo.ce, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC)
255 # define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z)
256 # define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC)
257 # define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n)
258 # define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
260 # define DCL_CONST(t, n, v) zend_declare_class_constant_ ##t(ce, (n), sizeof(n)-1, (v) TSRMLS_CC)
262 # define ACC_PROP_PRIVATE(ce, flags) ((flags & ZEND_ACC_PRIVATE) && (EG(scope) && ce == EG(scope))
263 # define ACC_PROP_PROTECTED(ce, flags) ((flags & ZEND_ACC_PROTECTED) && (zend_check_protected(ce, EG(scope))))
264 # define ACC_PROP_PUBLIC(flags) (flags & ZEND_ACC_PUBLIC)
265 # define ACC_PROP(ce, flags) (ACC_PROP_PUBLIC(flags) || ACC_PROP_PRIVATE(ce, flags) || ACC_PROP_PROTECTED(ce, flags))
267 # define INIT_PARR(o, n) \
270 MAKE_STD_ZVAL(__tmp); \
272 SET_PROP(o, n, __tmp); \
275 # define FREE_PARR(o, p) \
277 zval *__tmp = GET_PROP(o, p); \
279 zval_ptr_dtor(&__tmp); \
284 * the property *MUST* be updated after SEP_PROP()
286 # define SEP_PROP(zpp) \
289 SEPARATE_ZVAL_IF_NOT_REF(zpp); \
295 # define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
296 # define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
297 # define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
298 # define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
300 #endif /* ZEND_ENGINE_2 */
307 # define HE_THROW E_THROW TSRMLS_CC
308 # define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE) TSRMLS_CC
309 # define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING) TSRMLS_CC
310 # define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR) TSRMLS_CC
312 # define HE_THROW E_WARNING TSRMLS_CC
313 # define HE_NOTICE E_NOTICE TSRMLS_CC
314 # define HE_WARNING E_WARNING TSRMLS_CC
315 # define HE_ERROR E_ERROR TSRMLS_CC
318 #define HTTP_E_RUNTIME 1L
319 #define HTTP_E_INVALID_PARAM 2L
320 #define HTTP_E_HEADER 3L
321 #define HTTP_E_MALFORMED_HEADERS 4L
322 #define HTTP_E_REQUEST_METHOD 5L
323 #define HTTP_E_MESSAGE_TYPE 6L
324 #define HTTP_E_ENCODING 7L
325 #define HTTP_E_REQUEST 8L
326 #define HTTP_E_REQUEST_POOL 9L
327 #define HTTP_E_SOCKET 10L
328 #define HTTP_E_RESPONSE 11L
329 #define HTTP_E_URL 12L
332 # 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)
333 # 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)
334 # define HTTP_END_ARGS }
335 # define HTTP_EMPTY_ARGS_EX(class, method, ret_ref) HTTP_BEGIN_ARGS_EX(class, method, ret_ref, 0) HTTP_END_ARGS
336 # define HTTP_ARGS(class, method) args_for_ ##class## _ ##method
337 # define HTTP_ARG_VAL(name, pass_ref) ZEND_ARG_INFO(pass_ref, name)
338 # define HTTP_ARG_OBJ(class, name, allow_null) ZEND_ARG_OBJ_INFO(0, name, class, allow_null)
342 # define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0}
344 # define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL}
347 #ifdef HTTP_HAVE_CURL
348 # ifdef ZEND_ENGINE_2
349 # define HTTP_DECLARE_ARG_PASS_INFO() \
351 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_2, 0) \
352 ZEND_ARG_PASS_INFO(0) \
353 ZEND_ARG_PASS_INFO(1) \
354 ZEND_END_ARG_INFO(); \
357 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \
358 ZEND_ARG_PASS_INFO(0) \
359 ZEND_ARG_PASS_INFO(0) \
360 ZEND_ARG_PASS_INFO(1) \
361 ZEND_END_ARG_INFO(); \
364 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \
365 ZEND_ARG_PASS_INFO(0) \
366 ZEND_ARG_PASS_INFO(0) \
367 ZEND_ARG_PASS_INFO(0) \
368 ZEND_ARG_PASS_INFO(1) \
369 ZEND_END_ARG_INFO(); \
372 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_5, 0) \
373 ZEND_ARG_PASS_INFO(0) \
374 ZEND_ARG_PASS_INFO(0) \
375 ZEND_ARG_PASS_INFO(0) \
376 ZEND_ARG_PASS_INFO(0) \
377 ZEND_ARG_PASS_INFO(1) \
381 # define HTTP_DECLARE_ARG_PASS_INFO() \
382 static unsigned char http_arg_pass_ref_2[] = {2, BYREF_NONE, BYREF_FORCE}; \
383 static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
384 static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
385 static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE};
386 # endif /* ZEND_ENGINE_2 */
388 # ifdef ZEND_ENGINE_2
389 # define HTTP_DECLARE_ARG_PASS_INFO() \
391 ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_2, 0) \
392 ZEND_ARG_PASS_INFO(0) \
393 ZEND_ARG_PASS_INFO(1) \
396 # define HTTP_DECLARE_ARG_PASS_INFO() \
397 static unsigned char http_arg_pass_ref_2[] = {2, BYREF_NONE, BYREF_FORCE};
398 # endif /* ZEND_ENGINE_2 */
399 #endif /* HTTP_HAVE_CURL */
402 #ifndef TSRMLS_FETCH_FROM_CTX
404 # define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
406 # define TSRMLS_FETCH_FROM_CTX(ctx)
410 #ifndef TSRMLS_SET_CTX
412 # define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls
414 # define TSRMLS_SET_CTX(ctx)
419 #define ZVAL_ZVAL(z, zv, copy, dtor) { \
420 int is_ref, refcount; \
421 is_ref = (z)->is_ref; \
422 refcount = (z)->refcount; \
431 zval_ptr_dtor(&zv); \
433 (z)->is_ref = is_ref; \
434 (z)->refcount = refcount; \
438 #define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
441 #define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; }
444 #define PHP_MINIT_CALL(func) PHP_MINIT(func)(INIT_FUNC_ARGS_PASSTHRU)
445 #define PHP_RINIT_CALL(func) PHP_RINIT(func)(INIT_FUNC_ARGS_PASSTHRU)
446 #define PHP_MSHUTDOWN_CALL(func) PHP_MSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU)
447 #define PHP_RSHUTDOWN_CALL(func) PHP_RSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU)
449 #define Z_OBJ_DELREF(z) \
450 if (Z_OBJ_HT(z)->del_ref) { \
451 Z_OBJ_HT(z)->del_ref(&(z) TSRMLS_CC); \
453 #define Z_OBJ_ADDREF(z) \
454 if (Z_OBJ_HT(z)->add_ref) { \
455 Z_OBJ_HT(z)->add_ref(&(z) TSRMLS_CC); \
457 #define Z_OBJ_DELREF_P(z) \
458 if (Z_OBJ_HT_P(z)->del_ref) { \
459 Z_OBJ_HT_P(z)->del_ref((z) TSRMLS_CC); \
461 #define Z_OBJ_ADDREF_P(z) \
462 if (Z_OBJ_HT_P(z)->add_ref) { \
463 Z_OBJ_HT_P(z)->add_ref((z) TSRMLS_CC); \
465 #define Z_OBJ_DELREF_PP(z) \
466 if (Z_OBJ_HT_PP(z)->del_ref) { \
467 Z_OBJ_HT_PP(z)->del_ref(*(z) TSRMLS_CC); \
469 #define Z_OBJ_ADDREF_PP(z) \
470 if (Z_OBJ_HT_PP(z)->add_ref) { \
471 Z_OBJ_HT_PP(z)->add_ref(*(z) TSRMLS_CC); \
474 #endif /* PHP_HTTP_STD_DEFS_H */
481 * vim600: noet sw=4 ts=4 fdm=marker
482 * vim<600: noet sw=4 ts=4