- add etag generation through mhash
[m6w6/ext-http] / missing.c
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 #include "php.h"
19 #include "missing.h"
20
21 #if PHP_MAJOR_VERSION == 5
22
23 static inline zval *new_zval(int persistent)
24 {
25 zval *z = pemalloc(sizeof(zval), persistent);
26 INIT_PZVAL(z);
27 return z;
28 }
29
30 static inline zval *tmp_zval(void)
31 {
32 zval *z;
33 ALLOC_ZVAL(z);
34 z->is_ref = 0;
35 z->refcount = 0;
36 return z;
37 }
38
39 static void dup_zval(zval **z)
40 {
41 zval *o = *z;
42 zval_add_ref(z);
43 SEPARATE_ZVAL(z);
44 }
45
46
47 # if PHP_MINOR_VERSION == 0
48
49 int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC)
50 {
51 zval *property = new_zval(ce->type & ZEND_INTERNAL_CLASS);
52 ZVAL_DOUBLE(property, value);
53 return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
54 }
55
56 void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC)
57 {
58 zval *tmp = tmp_zval();
59 ZVAL_DOUBLE(tmp, value);
60 zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
61 }
62
63 int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC)
64 {
65 zval *property = new_zval(ce->type & ZEND_INTERNAL_CLASS);
66 ZVAL_BOOL(property, value);
67 return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
68 }
69
70 void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC)
71 {
72 zval *tmp = tmp_zval();
73 ZVAL_BOOL(tmp, value);
74 zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
75 }
76
77 # endif /* PHP_MINOR_VERSION == 0 */
78
79 int zend_declare_class_constant(zend_class_entry *ce, char *name, size_t name_length, zval *value TSRMLS_DC)
80 {
81 return zend_hash_add(&ce->constants_table, name, name_length, &value, sizeof(zval *), NULL);
82 }
83
84 int zend_declare_class_constant_long(zend_class_entry *ce, char *name, size_t name_length, long value TSRMLS_DC)
85 {
86 zval *constant = new_zval(ce->type & ZEND_INTERNAL_CLASS);
87 ZVAL_LONG(constant, value);
88 return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
89 }
90
91 int zend_declare_class_constant_bool(zend_class_entry *ce, char *name, size_t name_length, zend_bool value TSRMLS_DC)
92 {
93 zval *constant = new_zval(ce->type & ZEND_INTERNAL_CLASS);
94 ZVAL_BOOL(constant, value);
95 return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
96 }
97
98 int zend_declare_class_constant_double(zend_class_entry *ce, char *name, size_t name_length, double value TSRMLS_DC)
99 {
100 zval *constant = new_zval(ce->type & ZEND_INTERNAL_CLASS);
101 ZVAL_DOUBLE(constant, value);
102 return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
103 }
104
105 int zend_declare_class_constant_string(zend_class_entry *ce, char *name, size_t name_length, char *value TSRMLS_DC)
106 {
107 return zend_declare_class_constant_stringl(ce, name, name_length, value, strlen(value) TSRMLS_CC);
108 }
109
110 int zend_declare_class_constant_stringl(zend_class_entry *ce, char *name, size_t name_length, char *value, size_t value_length TSRMLS_DC)
111 {
112 zval *constant = new_zval(ce->type & ZEND_INTERNAL_CLASS);
113 if (ce->type & ZEND_INTERNAL_CLASS) {
114 ZVAL_STRINGL(constant, zend_strndup(value, value_length), value_length, 0);
115 } else {
116 ZVAL_STRINGL(constant, value, value_length, 1);
117 }
118 return zend_declare_class_constant(ce, name, name_length, constant TSRMLS_CC);
119 }
120
121 int zend_update_static_property(zend_class_entry *scope, char *name, size_t name_len, zval *value TSRMLS_DC)
122 {
123 int retval;
124 zval **property = NULL;
125 zend_class_entry *old_scope = EG(scope);
126
127 EG(scope) = scope;
128
129 if (!(property = zend_std_get_static_property(scope, name, name_len, 0 TSRMLS_CC))) {
130 retval = FAILURE;
131 } else if (*property == value) {
132 retval = SUCCESS;
133 } else {
134 value->refcount++;
135 if (PZVAL_IS_REF(*property)) {
136 zval_dtor(*property);
137 (*property)->type = value->type;
138 (*property)->value = value->value;
139
140 if (value->refcount) {
141 zval_copy_ctor(*property);
142 }
143 } else {
144 **property = *value;
145 zval_copy_ctor(*property);
146 }
147 retval = SUCCESS;
148 }
149 zval_ptr_dtor(&value);
150 EG(scope) = old_scope;
151
152 return retval;
153 }
154
155 int zend_update_static_property_bool(zend_class_entry *scope, char *name, size_t name_len, zend_bool value TSRMLS_DC)
156 {
157 zval *tmp = tmp_zval();
158 ZVAL_BOOL(tmp, value);
159 return zend_update_static_property(scope, name, name_len, tmp TSRMLS_CC);
160 }
161
162 int zend_update_static_property_long(zend_class_entry *scope, char *name, size_t name_len, long value TSRMLS_DC)
163 {
164 zval *tmp = tmp_zval();
165 ZVAL_LONG(tmp, value);
166 return zend_update_static_property(scope, name, name_len, tmp TSRMLS_CC);
167 }
168
169 int zend_update_static_property_double(zend_class_entry *scope, char *name, size_t name_len, double value TSRMLS_DC)
170 {
171 zval *tmp = tmp_zval();
172 ZVAL_DOUBLE(tmp, value);
173 return zend_update_static_property(scope, name, name_len, tmp TSRMLS_CC);
174 }
175
176 int zend_update_static_property_string(zend_class_entry *scope, char *name, size_t name_len, char *value TSRMLS_DC)
177 {
178 zval *tmp = tmp_zval();
179 ZVAL_STRING(tmp, value, 1);
180 return zend_update_static_property(scope, name, name_len, tmp TSRMLS_CC);
181 }
182
183 int zend_update_static_property_stringl(zend_class_entry *scope, char *name, size_t name_len, char *value, size_t value_len TSRMLS_DC)
184 {
185 zval *tmp = tmp_zval();
186 ZVAL_STRINGL(tmp, value, value_len, 1);
187 return zend_update_static_property(scope, name, name_len, tmp TSRMLS_CC);
188 }
189
190 void zend_fix_static_properties(zend_class_entry *ce, HashTable *static_members TSRMLS_DC)
191 {
192 zend_hash_copy(static_members, ce->static_members, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
193 zend_hash_destroy(ce->static_members);
194 zend_hash_init_ex(ce->static_members, static_members->nNumOfElements, NULL, ZVAL_PTR_DTOR, 1, 0);
195 }
196
197 void zend_init_static_properties(zend_class_entry *ce, HashTable *static_members TSRMLS_DC)
198 {
199 zend_hash_copy(ce->static_members, static_members, (copy_ctor_func_t) dup_zval, NULL, sizeof(zval *));
200 }
201
202 void zend_clean_static_properties(zend_class_entry *ce TSRMLS_DC)
203 {
204 zend_hash_clean(ce->static_members);
205 }
206
207 #endif /* PHP_MAJOR_VERSION == 5 */
208
209 /*
210 * Local variables:
211 * tab-width: 4
212 * c-basic-offset: 4
213 * End:
214 * vim600: noet sw=4 ts=4 fdm=marker
215 * vim<600: noet sw=4 ts=4
216 */
217