- fix HttpQueryString failures with objects as argument
[m6w6/ext-http] / http_querystring_object.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #define HTTP_WANT_SAPI
16 #include "php_http.h"
17
18 #ifdef ZEND_ENGINE_2
19
20 #include "php_variables.h"
21 #include "zend_interfaces.h"
22
23 #include "php_http_api.h"
24 #include "php_http_querystring_api.h"
25 #include "php_http_querystring_object.h"
26 #include "php_http_exception_object.h"
27
28 #define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpQueryString, method, 0, req_args)
29 #define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpQueryString, method, 0)
30 #define HTTP_QUERYSTRING_ME(method, visibility) PHP_ME(HttpQueryString, method, HTTP_ARGS(HttpQueryString, method), visibility)
31 #define HTTP_QUERYSTRING_GME(method, visibility) PHP_ME(HttpQueryString, method, HTTP_ARGS(HttpQueryString, __getter), visibility)
32
33 HTTP_BEGIN_ARGS(__construct, 0)
34 HTTP_ARG_VAL(global, 0)
35 HTTP_ARG_VAL(params, 0)
36 HTTP_END_ARGS;
37
38 #ifndef WONKY
39 HTTP_BEGIN_ARGS(singleton, 0)
40 HTTP_ARG_VAL(global, 0)
41 HTTP_END_ARGS;
42 #endif
43
44 HTTP_EMPTY_ARGS(toArray);
45 HTTP_EMPTY_ARGS(toString);
46
47 HTTP_BEGIN_ARGS(get, 0)
48 HTTP_ARG_VAL(name, 0)
49 HTTP_ARG_VAL(type, 0)
50 HTTP_ARG_VAL(defval, 0)
51 HTTP_ARG_VAL(delete, 0)
52 HTTP_END_ARGS;
53
54 HTTP_BEGIN_ARGS(set, 1)
55 HTTP_ARG_VAL(params, 0)
56 HTTP_END_ARGS;
57
58 HTTP_BEGIN_ARGS(mod, 0)
59 HTTP_ARG_VAL(params, 0)
60 HTTP_END_ARGS;
61
62 HTTP_BEGIN_ARGS(__getter, 1)
63 HTTP_ARG_VAL(name, 0)
64 HTTP_ARG_VAL(defval, 0)
65 HTTP_ARG_VAL(delete, 0)
66 HTTP_END_ARGS;
67
68 #ifdef HTTP_HAVE_ICONV
69 HTTP_BEGIN_ARGS(xlate, 2)
70 HTTP_ARG_VAL(from_encoding, 0)
71 HTTP_ARG_VAL(to_encoding, 0)
72 HTTP_END_ARGS;
73 #endif
74
75 HTTP_EMPTY_ARGS(serialize);
76 HTTP_BEGIN_ARGS(unserialize, 1)
77 HTTP_ARG_VAL(serialized, 0)
78 HTTP_END_ARGS;
79
80 HTTP_BEGIN_ARGS(offsetGet, 1)
81 HTTP_ARG_VAL(offset, 0)
82 HTTP_END_ARGS;
83
84 HTTP_BEGIN_ARGS(offsetSet, 2)
85 HTTP_ARG_VAL(offset, 0)
86 HTTP_ARG_VAL(value, 0)
87 HTTP_END_ARGS;
88
89 HTTP_BEGIN_ARGS(offsetExists, 1)
90 HTTP_ARG_VAL(offset, 0)
91 HTTP_END_ARGS;
92
93 HTTP_BEGIN_ARGS(offsetUnset, 1)
94 HTTP_ARG_VAL(offset, 0)
95 HTTP_END_ARGS;
96
97
98 #define OBJ_PROP_CE http_querystring_object_ce
99 zend_class_entry *http_querystring_object_ce;
100 zend_function_entry http_querystring_object_fe[] = {
101 HTTP_QUERYSTRING_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL)
102
103 HTTP_QUERYSTRING_ME(toArray, ZEND_ACC_PUBLIC)
104 HTTP_QUERYSTRING_ME(toString, ZEND_ACC_PUBLIC)
105 ZEND_MALIAS(HttpQueryString, __toString, toString, HTTP_ARGS(HttpQueryString, toString), ZEND_ACC_PUBLIC)
106
107 HTTP_QUERYSTRING_ME(get, ZEND_ACC_PUBLIC)
108 HTTP_QUERYSTRING_ME(set, ZEND_ACC_PUBLIC)
109 HTTP_QUERYSTRING_ME(mod, ZEND_ACC_PUBLIC)
110
111 HTTP_QUERYSTRING_GME(getBool, ZEND_ACC_PUBLIC)
112 HTTP_QUERYSTRING_GME(getInt, ZEND_ACC_PUBLIC)
113 HTTP_QUERYSTRING_GME(getFloat, ZEND_ACC_PUBLIC)
114 HTTP_QUERYSTRING_GME(getString, ZEND_ACC_PUBLIC)
115 HTTP_QUERYSTRING_GME(getArray, ZEND_ACC_PUBLIC)
116 HTTP_QUERYSTRING_GME(getObject, ZEND_ACC_PUBLIC)
117
118 #ifndef WONKY
119 HTTP_QUERYSTRING_ME(singleton, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
120 #endif
121 #ifdef HTTP_HAVE_ICONV
122 HTTP_QUERYSTRING_ME(xlate, ZEND_ACC_PUBLIC)
123 #endif
124
125 /* Implements Serializable */
126 HTTP_QUERYSTRING_ME(serialize, ZEND_ACC_PUBLIC)
127 HTTP_QUERYSTRING_ME(unserialize, ZEND_ACC_PUBLIC)
128
129 /* Implements ArrayAccess */
130 HTTP_QUERYSTRING_ME(offsetGet, ZEND_ACC_PUBLIC)
131 HTTP_QUERYSTRING_ME(offsetSet, ZEND_ACC_PUBLIC)
132 HTTP_QUERYSTRING_ME(offsetExists, ZEND_ACC_PUBLIC)
133 HTTP_QUERYSTRING_ME(offsetUnset, ZEND_ACC_PUBLIC)
134
135 EMPTY_FUNCTION_ENTRY
136 };
137 static zend_object_handlers http_querystring_object_handlers;
138
139 PHP_MINIT_FUNCTION(http_querystring_object)
140 {
141 HTTP_REGISTER_CLASS_EX(HttpQueryString, http_querystring_object, NULL, 0);
142
143 #ifndef WONKY
144 zend_class_implements(http_querystring_object_ce TSRMLS_CC, 2, zend_ce_serializable, zend_ce_arrayaccess);
145 #endif
146
147 DCL_STATIC_PROP_N(PRIVATE, instance);
148 DCL_PROP_N(PRIVATE, queryArray);
149 DCL_PROP(PRIVATE, string, queryString, "");
150
151 #ifndef WONKY
152 DCL_CONST(long, "TYPE_BOOL", HTTP_QUERYSTRING_TYPE_BOOL);
153 DCL_CONST(long, "TYPE_INT", HTTP_QUERYSTRING_TYPE_INT);
154 DCL_CONST(long, "TYPE_FLOAT", HTTP_QUERYSTRING_TYPE_FLOAT);
155 DCL_CONST(long, "TYPE_STRING", HTTP_QUERYSTRING_TYPE_STRING);
156 DCL_CONST(long, "TYPE_ARRAY", HTTP_QUERYSTRING_TYPE_ARRAY);
157 DCL_CONST(long, "TYPE_OBJECT", HTTP_QUERYSTRING_TYPE_OBJECT);
158 #endif
159
160 HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_BOOL", HTTP_QUERYSTRING_TYPE_BOOL);
161 HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_INT", HTTP_QUERYSTRING_TYPE_INT);
162 HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_FLOAT", HTTP_QUERYSTRING_TYPE_FLOAT);
163 HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_STRING", HTTP_QUERYSTRING_TYPE_STRING);
164 HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_ARRAY", HTTP_QUERYSTRING_TYPE_ARRAY);
165 HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_OBJECT", HTTP_QUERYSTRING_TYPE_OBJECT);
166
167 return SUCCESS;
168 }
169
170 zend_object_value _http_querystring_object_new(zend_class_entry *ce TSRMLS_DC)
171 {
172 return http_querystring_object_new_ex(ce, NULL);
173 }
174
175 zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, http_querystring_object **ptr TSRMLS_DC)
176 {
177 zend_object_value ov;
178 http_querystring_object *o;
179
180 o = ecalloc(1, sizeof(http_querystring_object));
181 o->zo.ce = ce;
182
183 if (ptr) {
184 *ptr = o;
185 }
186
187 ALLOC_HASHTABLE(OBJ_PROP(o));
188 zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
189 zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
190
191 ov.handle = putObject(http_querystring_object, o);
192 ov.handlers = &http_querystring_object_handlers;
193
194 return ov;
195 }
196
197 void _http_querystring_object_free(zend_object *object TSRMLS_DC)
198 {
199 http_querystring_object *o = (http_querystring_object *) object;
200
201 if (OBJ_PROP(o)) {
202 zend_hash_destroy(OBJ_PROP(o));
203 FREE_HASHTABLE(OBJ_PROP(o));
204 }
205 efree(o);
206 }
207
208 /* {{{ querystring helpers */
209 #define http_querystring_instantiate(g) _http_querystring_instantiate((g) TSRMLS_CC)
210 static inline zval *_http_querystring_instantiate(zend_bool global TSRMLS_DC)
211 {
212 zval *zobj, *zglobal;
213
214 MAKE_STD_ZVAL(zglobal);
215 ZVAL_BOOL(zglobal, global);
216
217 MAKE_STD_ZVAL(zobj);
218 Z_TYPE_P(zobj) = IS_OBJECT;
219 Z_OBJVAL_P(zobj) = http_querystring_object_new(http_querystring_object_ce);
220 zend_call_method_with_1_params(&zobj, Z_OBJCE_P(zobj), NULL, "__construct", NULL, zglobal);
221
222 zval_ptr_dtor(&zglobal);
223
224 return zobj;
225 }
226
227 #define http_querystring_get(o, t, n, l, def, del, r) _http_querystring_get((o), (t), (n), (l), (def), (del), (r) TSRMLS_CC)
228 static inline void _http_querystring_get(zval *this_ptr, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC)
229 {
230 zval **arrval, *qarray = GET_PROP(queryArray);
231
232 if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_hash_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) {
233 RETVAL_ZVAL(*arrval, 1, 0);
234
235 if (type) {
236 convert_to_type(type, return_value);
237 }
238
239 if (del && (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarray), name, name_len + 1))) {
240 http_querystring_update(qarray, GET_PROP(queryString));
241 }
242 } else if(defval) {
243 RETURN_ZVAL(defval, 1, 0);
244 }
245 }
246 /* }}} */
247
248 /* {{{ proto final void HttpQueryString::__construct([bool global = true[, mixed add])
249 *
250 * Creates a new HttpQueryString object instance.
251 * Operates on and modifies $_GET and $_SERVER['QUERY_STRING'] if global is TRUE.
252 */
253 PHP_METHOD(HttpQueryString, __construct)
254 {
255 zend_bool global = 1;
256 zval *params = NULL, *qarray = NULL, *qstring = NULL, **_GET, **_SERVER, **QUERY_STRING;
257
258 SET_EH_THROW_HTTP();
259 if (!sapi_module.treat_data) {
260 http_error(HE_ERROR, HTTP_E_QUERYSTRING, "The SAPI does not have a treat_data function registered");
261 } else if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bz", &global, &params)) {
262 if (global) {
263 #ifdef ZEND_ENGINE_2
264 zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
265 #endif
266 if ( (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &_SERVER)) &&
267 (Z_TYPE_PP(_SERVER) == IS_ARRAY) &&
268 (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "QUERY_STRING", sizeof("QUERY_STRING"), (void *) &QUERY_STRING))) {
269
270 qstring = *QUERY_STRING;
271 #ifdef ZEND_ENGINE_2
272 zend_is_auto_global("_GET", lenof("_GET") TSRMLS_CC);
273 #endif
274 if ((SUCCESS == zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void *) &_GET)) && (Z_TYPE_PP(_GET) == IS_ARRAY)) {
275 qarray = *_GET;
276 } else {
277 http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Could not acquire reference to superglobal GET array");
278 }
279 } else {
280 http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Could not acquire reference to QUERY_STRING");
281 }
282
283 if (qarray && qstring) {
284 if (Z_TYPE_P(qstring) != IS_STRING) {
285 convert_to_string(qstring);
286 }
287
288 SET_PROP(queryArray, qarray);
289 SET_PROP(queryString, qstring);
290 GET_PROP(queryArray)->is_ref = 1;
291 GET_PROP(queryString)->is_ref = 1;
292
293 if (params) {
294 http_querystring_modify(GET_PROP(queryArray), params);
295 }
296 http_querystring_update(GET_PROP(queryArray), GET_PROP(queryString));
297 }
298 } else {
299 qarray = ecalloc(1, sizeof(zval));
300 array_init(qarray);
301
302 SET_PROP(queryArray, qarray);
303 UPD_STRL(queryString, "", 0);
304
305 if (params && http_querystring_modify(qarray, params)) {
306 http_querystring_update(qarray, GET_PROP(queryString));
307 }
308 }
309 }
310 SET_EH_NORMAL();
311 }
312 /* }}} */
313
314 /* {{{ proto string HttpQueryString::toString()
315 *
316 * Returns the string representation.
317 */
318 PHP_METHOD(HttpQueryString, toString)
319 {
320 NO_ARGS;
321 RETURN_PROP(queryString);
322 }
323 /* }}} */
324
325 /* {{{ proto array HttpQueryString::toArray()
326 *
327 * Returns the array representation.
328 */
329 PHP_METHOD(HttpQueryString, toArray)
330 {
331 NO_ARGS;
332 RETURN_PROP(queryArray);
333 }
334 /* }}} */
335
336 /* {{{ proto mixed HttpQueryString::get([string key[, mixed type = 0[, mixed defval = NULL[, bool delete = false]]]])
337 *
338 * Get (part of) the query string.
339 *
340 * The type parameter is either one of the HttpQueryString::TYPE_* constants or a type abbreviation like
341 * "b" for bool, "i" for int, "f" for float, "s" for string, "a" for array and "o" for a stdClass object.
342 */
343 PHP_METHOD(HttpQueryString, get)
344 {
345 char *name = NULL;
346 int name_len = 0;
347 long type = 0;
348 zend_bool del = 0;
349 zval *ztype = NULL, *defval = NULL;
350
351 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|szzb", &name, &name_len, &ztype, &defval, &del)) {
352 if (name && name_len) {
353 if (ztype) {
354 if (Z_TYPE_P(ztype) == IS_LONG) {
355 type = Z_LVAL_P(ztype);
356 } else if(Z_TYPE_P(ztype) == IS_STRING) {
357 switch (Z_STRVAL_P(ztype)[0]) {
358 case 'B':
359 case 'b': type = HTTP_QUERYSTRING_TYPE_BOOL; break;
360 case 'I':
361 case 'i': type = HTTP_QUERYSTRING_TYPE_INT; break;
362 case 'F':
363 case 'f': type = HTTP_QUERYSTRING_TYPE_FLOAT; break;
364 case 'S':
365 case 's': type = HTTP_QUERYSTRING_TYPE_STRING; break;
366 case 'A':
367 case 'a': type = HTTP_QUERYSTRING_TYPE_ARRAY; break;
368 case 'O':
369 case 'o': type = HTTP_QUERYSTRING_TYPE_OBJECT; break;
370 }
371 }
372 }
373 http_querystring_get(getThis(), type, name, name_len, defval, del, return_value);
374 } else {
375 RETURN_PROP(queryString);
376 }
377 }
378 }
379 /* }}} */
380
381 /* {{{ proto string HttpQueryString::set(mixed params)
382 *
383 * Set query string entry/entries. NULL values will unset the variable.
384 */
385 PHP_METHOD(HttpQueryString, set)
386 {
387 zval *params;
388
389 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &params)) {
390 zval *qarray = GET_PROP(queryArray);
391 if (http_querystring_modify(qarray, params)) {
392 http_querystring_update(qarray, GET_PROP(queryString));
393 }
394 }
395
396 if (return_value_used) {
397 RETURN_PROP(queryString);
398 }
399 }
400 /* }}} */
401
402 /* {{{ proto HttpQueryString HttpQueryString::mod(mixed params)
403 *
404 * Copies the query string object and sets provided params at the clone.
405 * This is basically shorthand for:
406 * <pre>
407 * <?php
408 * $newQS = new HttpQueryString(false, $oldQS);
409 * $newQS->set($other_params);
410 * ?>
411 * </pre>
412 */
413 PHP_METHOD(HttpQueryString, mod)
414 {
415 zval *orig, *zobj, *qarr, *qstr, *params;
416
417 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &params)) {
418 zobj = http_querystring_instantiate(0);
419 orig = GET_PROP(queryArray);
420 qarr = GET_PROP_EX(zobj, queryArray);
421 qstr = GET_PROP_EX(zobj, queryString);
422
423 http_querystring_modify(qarr, orig);
424 http_querystring_modify(qarr, params);
425 http_querystring_update(qarr, qstr);
426
427 RETURN_ZVAL(zobj, 1, 1);
428 }
429 }
430 /* }}} */
431
432 #ifndef WONKY
433 /* {{{ proto static HttpQueryString HttpQueryString::singleton([bool global = true])
434 *
435 * Get a single instance (differentiates between the global setting).
436 */
437 PHP_METHOD(HttpQueryString, singleton)
438 {
439 zend_bool global = 1;
440 zval *instance = GET_STATIC_PROP(instance);
441
442 SET_EH_THROW_HTTP();
443 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &global)) {
444 zval **zobj_ptr = NULL, *zobj = NULL;
445
446 if (Z_TYPE_P(instance) == IS_ARRAY) {
447 if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(instance), global, (void *) &zobj_ptr)) {
448 RETVAL_ZVAL(*zobj_ptr, 1, 0);
449 } else {
450 zobj = http_querystring_instantiate(global);
451 add_index_zval(instance, global, zobj);
452 RETVAL_OBJECT(zobj, 1);
453 }
454 } else {
455 MAKE_STD_ZVAL(instance);
456 array_init(instance);
457
458 zobj = http_querystring_instantiate(global);
459 add_index_zval(instance, global, zobj);
460 RETVAL_OBJECT(zobj, 1);
461
462 SET_STATIC_PROP(instance, instance);
463 zval_ptr_dtor(&instance);
464 }
465 }
466 SET_EH_NORMAL();
467 }
468 /* }}} */
469 #endif
470
471 /* {{{ Getters by type */
472 #define HTTP_QUERYSTRING_GETTER(method, TYPE) \
473 PHP_METHOD(HttpQueryString, method) \
474 { \
475 char *name; \
476 int name_len; \
477 zval *defval = NULL; \
478 zend_bool del = 0; \
479 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zb", &name, &name_len, &defval, &del)) { \
480 http_querystring_get(getThis(), TYPE, name, name_len, defval, del, return_value); \
481 } \
482 }
483 HTTP_QUERYSTRING_GETTER(getBool, IS_BOOL);
484 HTTP_QUERYSTRING_GETTER(getInt, IS_LONG);
485 HTTP_QUERYSTRING_GETTER(getFloat, IS_DOUBLE);
486 HTTP_QUERYSTRING_GETTER(getString, IS_STRING);
487 HTTP_QUERYSTRING_GETTER(getArray, IS_ARRAY);
488 HTTP_QUERYSTRING_GETTER(getObject, IS_OBJECT);
489 /* }}} */
490
491 #ifdef HTTP_HAVE_ICONV
492 /* {{{ proto bool HttpQueryString::xlate(string ie, string oe)
493 *
494 * Converts the query string from the source encoding ie to the target encoding oe.
495 * WARNING: Don't use any character set that can contain NUL bytes like UTF-16.
496 *
497 * Returns TRUE on success or FALSE on failure.
498 */
499 PHP_METHOD(HttpQueryString, xlate)
500 {
501 char *ie, *oe;
502 int ie_len, oe_len;
503 zval xa, *qa, *qs;
504 STATUS rs;
505
506 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ie, &ie_len, &oe, &oe_len)) {
507 RETURN_FALSE;
508 }
509
510 qa = GET_PROP(queryArray);
511 qs = GET_PROP(queryString);
512 INIT_PZVAL(&xa);
513 array_init(&xa);
514
515 if (SUCCESS == (rs = http_querystring_xlate(&xa, qa, ie, oe))) {
516 zend_hash_clean(Z_ARRVAL_P(qa));
517 zend_hash_copy(Z_ARRVAL_P(qa), Z_ARRVAL(xa), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
518 http_querystring_update(qa, qs);
519 }
520 zval_dtor(&xa);
521
522 RETURN_SUCCESS(rs);
523 }
524 /* }}} */
525 #endif /* HAVE_ICONV */
526
527 /* {{{ proto string HttpQueryString::serialize()
528 *
529 * Implements Serializable.
530 */
531 PHP_METHOD(HttpQueryString, serialize)
532 {
533 NO_ARGS;
534 RETURN_PROP(queryString);
535 }
536 /* }}} */
537
538 /* {{{ proto void HttpQueryString::unserialize(string serialized)
539 *
540 * Implements Serializable.
541 */
542 PHP_METHOD(HttpQueryString, unserialize)
543 {
544 zval *serialized;
545
546 SET_EH_THROW_HTTP();
547 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &serialized)) {
548 if (Z_TYPE_P(serialized) == IS_STRING) {
549 zval *qa = GET_PROP(queryArray);
550
551 zend_hash_clean(Z_ARRVAL_P(qa));
552 http_querystring_modify(qa, serialized);
553 http_querystring_update(qa, GET_PROP(queryString));
554 } else {
555 http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Expected a string as parameter");
556 }
557 }
558 SET_EH_NORMAL();
559 }
560 /* }}} */
561
562 /* {{{ proto mixed HttpQueryString::offsetGet(string offset)
563 *
564 * Implements ArrayAccess.
565 */
566 PHP_METHOD(HttpQueryString, offsetGet)
567 {
568 char *offset_str;
569 int offset_len;
570 zval **value;
571
572 if ( (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) &&
573 (SUCCESS == zend_hash_find(Z_ARRVAL_P(GET_PROP(queryArray)), offset_str, offset_len + 1, (void *) &value))) {
574 RETVAL_ZVAL(*value, 1, 0);
575 }
576 }
577 /* }}} */
578
579 /* {{{ proto void HttpQueryString::offsetSet(string offset, mixed value)
580 *
581 * Implements ArrayAccess.
582 */
583 PHP_METHOD(HttpQueryString, offsetSet)
584 {
585 char *offset_str;
586 int offset_len;
587 zval *value;
588
589 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) {
590 zval *qarr = GET_PROP(queryArray), *qstr = GET_PROP(queryString);
591
592 ZVAL_ADDREF(value);
593 add_assoc_zval_ex(qarr, offset_str, offset_len + 1, value);
594 http_querystring_update(qarr, qstr);
595 }
596 }
597 /* }}} */
598
599 /* {{{ proto bool HttpQueryString::offsetExists(string offset)
600 *
601 * Implements ArrayAccess.
602 */
603 PHP_METHOD(HttpQueryString, offsetExists)
604 {
605 char *offset_str;
606 int offset_len;
607 zval **value;
608
609 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
610 RETURN_BOOL((SUCCESS == zend_hash_find(Z_ARRVAL_P(GET_PROP(queryArray)), offset_str, offset_len + 1, (void *) &value)) && (Z_TYPE_PP(value) != IS_NULL));
611 }
612 }
613 /* }}} */
614
615 /* {{{ proto void HttpQueryString::offsetUnset(string offset)
616 *
617 * Implements ArrayAccess.
618 */
619 PHP_METHOD(HttpQueryString, offsetUnset)
620 {
621 char *offset_str;
622 int offset_len;
623
624 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
625 zval *qarr = GET_PROP(queryArray);
626
627 if (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarr), offset_str, offset_len + 1)) {
628 http_querystring_update(qarr, GET_PROP(queryString));
629 }
630 }
631 }
632 /* }}} */
633
634 #endif /* ZEND_ENGINE_2 */
635
636 /*
637 * Local variables:
638 * tab-width: 4
639 * c-basic-offset: 4
640 * End:
641 * vim600: noet sw=4 ts=4 fdm=marker
642 * vim<600: noet sw=4 ts=4
643 */
644