- improve http_chunked_decode
[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 #ifdef PHP_WIN32
22 # define PHP_HTTP_API __declspec(dllexport)
23 #else
24 # define PHP_HTTP_API
25 #endif
26
27 /* make functions that return SUCCESS|FAILURE more obvious */
28 typedef int STATUS;
29
30 /* lenof() */
31 #define lenof(S) (sizeof(S) - 1)
32
33 /* return bool (v == SUCCESS) */
34 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
35 #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
36 /* return object(values) */
37 #define RETVAL_OBJECT(o) \
38 return_value->is_ref = 1; \
39 return_value->type = IS_OBJECT; \
40 return_value->value.obj = (o)->value.obj; \
41 zval_add_ref(&return_value)
42 #define RETURN_OBJECT(o) \
43 RETVAL_OBJECT(o); \
44 return
45 #define RETVAL_OBJVAL(ov) \
46 return_value->is_ref = 1; \
47 return_value->type = IS_OBJECT; \
48 return_value->value.obj = (ov); \
49 zend_objects_store_add_ref(return_value TSRMLS_CC)
50 #define RETURN_OBJVAL(ov) \
51 RETVAL_OBJVAL(ov); \
52 return
53
54 /* function accepts no args */
55 #define NO_ARGS \
56 if (ZEND_NUM_ARGS()) { \
57 zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \
58 }
59
60 /* CR LF */
61 #define HTTP_CRLF "\r\n"
62
63 /* default cache control */
64 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
65
66 /* max URL length */
67 #define HTTP_URL_MAXLEN 2048
68 #define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
69
70 /* def URL arg separator */
71 #define HTTP_URL_ARGSEP "&"
72 #define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
73
74 /* send buffer size */
75 #define HTTP_SENDBUF_SIZE 2097152
76
77 /* CURL buffer size */
78 #define HTTP_CURLBUF_SIZE 16384
79
80 /* known methods */
81 #define HTTP_KNOWN_METHODS \
82 /* HTTP 1.1 */ \
83 "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \
84 /* WebDAV - RFC 2518 */ \
85 "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \
86 /* WebDAV Versioning - RFC 3253 */ \
87 "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \
88 "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \
89 /* WebDAV Access Control - RFC 3744 */ \
90 "ACL, " \
91 /* END */
92
93
94 /* server vars shorthand */
95 #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
96
97 #define HTTP_INI_ENTRY(entry, default, scope, global) \
98 STD_PHP_INI_ENTRY(entry, default, scope, http_update_##global, global, zend_http_globals, http_globals)
99
100 /* {{{ arrays */
101 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
102 #define FOREACH_HASH_VAL(hash, val) \
103 for ( zend_hash_internal_pointer_reset(hash); \
104 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
105 zend_hash_move_forward(hash))
106
107 #define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey)
108 #define FOREACH_HASH_KEY(hash, strkey, numkey) \
109 for ( zend_hash_internal_pointer_reset(hash); \
110 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \
111 zend_hash_move_forward(hash)) \
112
113 #define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val)
114 #define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \
115 for ( zend_hash_internal_pointer_reset(hash); \
116 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \
117 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
118 zend_hash_move_forward(hash)) \
119
120 #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 *))
121 #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)
122 #define array_append(src, dst) \
123 { \
124 ulong idx; \
125 uint klen; \
126 char *key = NULL; \
127 zval **data; \
128 \
129 for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \
130 zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \
131 zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \
132 zend_hash_move_forward(Z_ARRVAL_P(src))) \
133 { \
134 if (key) { \
135 zval **tmp; \
136 \
137 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \
138 if (Z_TYPE_PP(tmp) != IS_ARRAY) { \
139 convert_to_array_ex(tmp); \
140 } \
141 add_next_index_zval(*tmp, *data); \
142 } else { \
143 add_assoc_zval(dst, key, *data); \
144 } \
145 zval_add_ref(data); \
146 key = NULL; \
147 } \
148 } \
149 }
150 /* }}} */
151
152 #define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT);
153
154 /* {{{ objects & properties */
155 #ifdef ZEND_ENGINE_2
156
157
158 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
159 { \
160 zend_class_entry ce; \
161 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
162 ce.create_object = name## _new; \
163 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
164 name## _ce->ce_flags |= flags; \
165 memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
166 name## _declare_default_properties(); \
167 }
168
169 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
170 { \
171 zend_class_entry ce; \
172 INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
173 ce.create_object = NULL; \
174 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
175 name## _ce->ce_flags |= flags; \
176 }
177
178 # define getObject(t, o) getObjectEx(t, o, getThis())
179 # define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
180 # define OBJ_PROP(o) o->zo.properties
181 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
182 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
183 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
184 # define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
185 # define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
186 # define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
187
188 # define INIT_PARR(o, n) \
189 { \
190 zval *__tmp; \
191 MAKE_STD_ZVAL(__tmp); \
192 array_init(__tmp); \
193 SET_PROP(o, n, __tmp); \
194 }
195
196 # define FREE_PARR(o, p) \
197 { \
198 zval *__tmp = NULL; \
199 if (__tmp = GET_PROP(o, p)) { \
200 zval_dtor(__tmp); \
201 FREE_ZVAL(__tmp); \
202 __tmp = NULL; \
203 } \
204 }
205
206 # define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
207 # define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
208 # define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
209 # define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
210
211 #endif /* ZEND_ENGINE_2 */
212 /* }}} */
213
214 #ifndef E_THROW
215 # define E_THROW 0
216 #endif
217
218 #define HTTP_E_UNKOWN 0L
219 #define HTTP_E_PARSE 1L
220 #define HTTP_E_HEADER 2L
221 #define HTTP_E_OBUFFER 3L
222 #define HTTP_E_CURL 4L
223 #define HTTP_E_ENCODE 5L
224 #define HTTP_E_PARAM 6L
225 #define HTTP_E_URL 7L
226 #define HTTP_E_MSG 8L
227
228 #endif /* PHP_HTTP_STD_DEFS_H */
229
230 /*
231 * Local variables:
232 * tab-width: 4
233 * c-basic-offset: 4
234 * End:
235 * vim600: noet sw=4 ts=4 fdm=marker
236 * vim<600: noet sw=4 ts=4
237 */
238