2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
18 #ifndef PHP_HTTP_STD_DEFS_H
19 #define PHP_HTTP_STD_DEFS_H
22 # define PHP_HTTP_API __declspec(dllexport)
27 /* make functions that return SUCCESS|FAILURE more obvious */
31 #define lenof(S) (sizeof(S) - 1)
33 /* return bool (v == SUCCESS) */
34 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
36 /* function accepts no args */
38 if (ZEND_NUM_ARGS()) { \
39 zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \
43 #define HTTP_CRLF "\r\n"
45 /* default cache control */
46 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
49 #define HTTP_URL_MAXLEN 2048
50 #define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
52 /* def URL arg separator */
53 #define HTTP_URL_ARGSEP "&"
54 #define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
56 /* send buffer size */
57 #define HTTP_SENDBUF_SIZE 2097152
59 /* CURL buffer size */
60 #define HTTP_CURLBUF_SIZE 16384
62 /* server vars shorthand */
63 #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
66 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
67 #define FOREACH_HASH_VAL(hash, val) \
68 for ( zend_hash_internal_pointer_reset(hash); \
69 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
70 zend_hash_move_forward(hash))
72 #define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey)
73 #define FOREACH_HASH_KEY(hash, strkey, numkey) \
74 for ( zend_hash_internal_pointer_reset(hash); \
75 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \
76 zend_hash_move_forward(hash)) \
78 #define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val)
79 #define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \
80 for ( zend_hash_internal_pointer_reset(hash); \
81 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \
82 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
83 zend_hash_move_forward(hash)) \
85 #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 *))
86 #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)
87 #define array_append(src, dst) \
94 for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \
95 zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \
96 zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \
97 zend_hash_move_forward(Z_ARRVAL_P(src))) \
102 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \
103 if (Z_TYPE_PP(tmp) != IS_ARRAY) { \
104 convert_to_array_ex(tmp); \
106 add_next_index_zval(*tmp, *data); \
108 add_assoc_zval(dst, key, *data); \
110 zval_add_ref(data); \
117 #define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT);
119 /* {{{ objects & properties */
123 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
125 zend_class_entry ce; \
126 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
127 ce.create_object = name## _new; \
128 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
129 name## _ce->ce_flags |= flags; \
130 memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
131 name## _declare_default_properties(); \
134 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
136 zend_class_entry ce; \
137 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
138 ce.create_object = NULL; \
139 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
140 name## _ce->ce_flags |= flags; \
143 # define getObject(t, o) getObjectEx(t, o, getThis())
144 # define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
145 # define OBJ_PROP(o) o->zo.properties
146 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
147 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
148 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
149 # define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
150 # define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
151 # define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
153 # define INIT_PARR(o, n) \
156 MAKE_STD_ZVAL(__tmp); \
158 SET_PROP(o, n, __tmp); \
161 # define FREE_PARR(o, p) \
163 zval *__tmp = NULL; \
164 if (__tmp = GET_PROP(o, p)) { \
171 # define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
172 # define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
173 # define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
174 # define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
176 #endif /* ZEND_ENGINE_2 */
183 #define HTTP_E_UNKOWN 0L
184 #define HTTP_E_PARSE 1L
185 #define HTTP_E_HEADER 2L
186 #define HTTP_E_OBUFFER 3L
187 #define HTTP_E_CURL 4L
188 #define HTTP_E_ENCODE 5L
189 #define HTTP_E_PARAM 6L
190 #define HTTP_E_URL 7L
191 #define HTTP_E_MSG 8L
193 #endif /* PHP_HTTP_STD_DEFS_H */
200 * vim600: noet sw=4 ts=4 fdm=marker
201 * vim<600: noet sw=4 ts=4