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