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