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