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