a0f7ddf7b4d40104e1135436e6c02d0bb1961d43
[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 if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT
38
39 /* CR LF */
40 #define HTTP_CRLF "\r\n"
41
42 /* default cache control */
43 #define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
44
45 /* max URL length */
46 #define HTTP_URL_MAXLEN 2048
47 #define HTTP_URI_MAXLEN HTTP_URL_MAXLEN
48
49 /* def URL arg separator */
50 #define HTTP_URL_ARGSEP "&"
51 #define HTTP_URI_ARGSEP HTTP_URL_ARGSEP
52
53 /* send buffer size */
54 #define HTTP_SENDBUF_SIZE 2097152
55
56 /* CURL buffer size */
57 #define HTTP_CURLBUF_SIZE 16384
58
59 /* server vars shorthand */
60 #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])
61
62 /* {{{ arrays */
63 #define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val)
64 #define FOREACH_HASH_VAL(hash, val) \
65 for ( zend_hash_internal_pointer_reset(hash); \
66 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
67 zend_hash_move_forward(hash))
68
69 #define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey)
70 #define FOREACH_HASH_KEY(hash, strkey, numkey) \
71 for ( zend_hash_internal_pointer_reset(hash); \
72 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \
73 zend_hash_move_forward(hash)) \
74
75 #define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val)
76 #define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \
77 for ( zend_hash_internal_pointer_reset(hash); \
78 zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \
79 zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \
80 zend_hash_move_forward(hash)) \
81
82 #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 *))
83 #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)
84 /* }}} */
85
86 /* {{{ objects & properties */
87 #ifdef ZEND_ENGINE_2
88
89 # define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
90 { \
91 zend_class_entry ce; \
92 INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
93 ce.create_object = name## _new_object; \
94 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
95 name## _ce->ce_flags |= flags; \
96 memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
97 name## _object_handlers.clone_obj = NULL; \
98 name## _declare_default_properties(name## _ce); \
99 }
100
101 # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
102 { \
103 zend_class_entry ce; \
104 INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \
105 ce.create_object = NULL; \
106 name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
107 name## _ce->ce_flags |= flags; \
108 }
109
110 # define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC))
111 # define OBJ_PROP(o) o->zo.properties
112 # define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
113 # define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC)
114 # define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC)
115 # define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC)
116 # define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC)
117 # define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC)
118
119 # define INIT_PARR(o, n) \
120 { \
121 zval *__tmp; \
122 MAKE_STD_ZVAL(__tmp); \
123 array_init(__tmp); \
124 SET_PROP(o, n, __tmp); \
125 }
126
127 # define FREE_PARR(o, p) \
128 { \
129 zval *__tmp = NULL; \
130 if (__tmp = GET_PROP(o, p)) { \
131 zval_dtor(__tmp); \
132 FREE_ZVAL(__tmp); \
133 __tmp = NULL; \
134 } \
135 }
136
137 #endif /* ZEND_ENGINE_2 */
138 /* }}} */
139
140
141 #endif /* PHP_HTTP_STD_DEFS_H */
142
143 /*
144 * Local variables:
145 * tab-width: 4
146 * c-basic-offset: 4
147 * End:
148 * vim600: noet sw=4 ts=4 fdm=marker
149 * vim<600: noet sw=4 ts=4
150 */
151