- fix overload guards leaks
[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 freeObject(o);
202 }
203
204 /* {{{ querystring helpers */
205 #define http_querystring_instantiate(g) _http_querystring_instantiate((g) TSRMLS_CC)
206 static inline zval *_http_querystring_instantiate(zend_bool global TSRMLS_DC)
207 {
208 zval *zobj, *zglobal;
209
210 MAKE_STD_ZVAL(zglobal);
211 ZVAL_BOOL(zglobal, global);
212
213 MAKE_STD_ZVAL(zobj);
214 Z_TYPE_P(zobj) = IS_OBJECT;
215 zobj->value.obj = http_querystring_object_new(http_querystring_object_ce);
216 zend_call_method_with_1_params(&zobj, Z_OBJCE_P(zobj), NULL, "__construct", NULL, zglobal);
217
218 zval_ptr_dtor(&zglobal);
219
220 return zobj;
221 }
222
223 #define http_querystring_get(o, t, n, l, def, del, r) _http_querystring_get((o), (t), (n), (l), (def), (del), (r) TSRMLS_CC)
224 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)
225 {
226 zval **arrval, *qarray = GET_PROP(queryArray);
227
228 if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_hash_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) {
229 RETVAL_ZVAL(*arrval, 1, 0);
230
231 if (type) {
232 convert_to_type(type, return_value);
233 }
234
235 if (del && (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarray), name, name_len + 1))) {
236 http_querystring_update(qarray, GET_PROP(queryString));
237 }
238 } else if(defval) {
239 RETURN_ZVAL(defval, 1, 0);
240 }
241 }
242 /* }}} */
243
244 /* {{{ proto final void HttpQueryString::__construct([bool global = true[, mixed add])
245 *
246 * Creates a new HttpQueryString object instance.
247 * Operates on and modifies $_GET and $_SERVER['QUERY_STRING'] if global is TRUE.
248 */
249 PHP_METHOD(HttpQueryString, __construct)
250 {
251 zend_bool global = 1;
252 zval *params = NULL, *qarray = NULL, *qstring = NULL, **_GET, **_SERVER, **QUERY_STRING;
253
254 SET_EH_THROW_HTTP();
255 if (!sapi_module.treat_data) {
256 http_error(HE_ERROR, HTTP_E_QUERYSTRING, "The SAPI does not have a treat_data function registered");
257 } else if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bz", &global, &params)) {
258 if (global) {
259 #ifdef ZEND_ENGINE_2
260 zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
261 #endif
262 if ( (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &_SERVER)) &&
263 (Z_TYPE_PP(_SERVER) == IS_ARRAY) &&
264 (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "QUERY_STRING", sizeof("QUERY_STRING"), (void *) &QUERY_STRING))) {
265
266 qstring = *QUERY_STRING;
267 #ifdef ZEND_ENGINE_2
268 zend_is_auto_global("_GET", lenof("_GET") TSRMLS_CC);
269 #endif
270 if ((SUCCESS == zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void *) &_GET)) && (Z_TYPE_PP(_GET) == IS_ARRAY)) {
271 qarray = *_GET;
272 } else {
273 http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Could not acquire reference to superglobal GET array");
274 }
275 } else {
276 http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Could not acquire reference to QUERY_STRING");
277 }
278
279 if (qarray && qstring) {
280 if (Z_TYPE_P(qstring) != IS_STRING) {
281 convert_to_string(qstring);
282 }
283
284 SET_PROP(queryArray, qarray);
285 SET_PROP(queryString, qstring);
286 GET_PROP(queryArray)->is_ref = 1;
287 GET_PROP(queryString)->is_ref = 1;
288
289 if (params) {
290 http_querystring_modify(GET_PROP(queryArray), params);
291 }
292 http_querystring_update(GET_PROP(queryArray), GET_PROP(queryString));
293 }
294 } else {
295 qarray = ecalloc(1, sizeof(zval));
296 array_init(qarray);
297
298 SET_PROP(queryArray, qarray);
299 UPD_STRL(queryString, "", 0);
300
301 if (params && http_querystring_modify(qarray, params)) {
302 http_querystring_update(qarray, GET_PROP(queryString));
303 }
304 }
305 }
306 SET_EH_NORMAL();
307 }
308 /* }}} */
309
310 /* {{{ proto string HttpQueryString::toString()
311 *
312 * Returns the string representation.
313 */
314 PHP_METHOD(HttpQueryString, toString)
315 {
316 NO_ARGS;
317 RETURN_PROP(queryString);
318 }
319 /* }}} */
320
321 /* {{{ proto array HttpQueryString::toArray()
322 *
323 * Returns the array representation.
324 */
325 PHP_METHOD(HttpQueryString, toArray)
326 {
327 NO_ARGS;
328 RETURN_PROP(queryArray);
329 }
330 /* }}} */
331
332 /* {{{ proto mixed HttpQueryString::get([string key[, mixed type = 0[, mixed defval = NULL[, bool delete = false]]]])
333 *
334 * Get (part of) the query string.
335 *
336 * The type parameter is either one of the HttpQueryString::TYPE_* constants or a type abbreviation like
337 * "b" for bool, "i" for int, "f" for float, "s" for string, "a" for array and "o" for a stdClass object.
338 */
339 PHP_METHOD(HttpQueryString, get)
340 {
341 char *name = NULL;
342 int name_len = 0;
343 long type = 0;
344 zend_bool del = 0;
345 zval *ztype = NULL, *defval = NULL;
346
347 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|szzb", &name, &name_len, &ztype, &defval, &del)) {
348 if (name && name_len) {
349 if (ztype) {
350 if (Z_TYPE_P(ztype) == IS_LONG) {
351 type = Z_LVAL_P(ztype);
352 } else if(Z_TYPE_P(ztype) == IS_STRING) {
353 switch (Z_STRVAL_P(ztype)[0]) {
354 case 'B':
355 case 'b': type = HTTP_QUERYSTRING_TYPE_BOOL; break;
356 case 'I':
357 case 'i': type = HTTP_QUERYSTRING_TYPE_INT; break;
358 case 'F':
359 case 'f': type = HTTP_QUERYSTRING_TYPE_FLOAT; break;
360 case 'S':
361 case 's': type = HTTP_QUERYSTRING_TYPE_STRING; break;
362 case 'A':
363 case 'a': type = HTTP_QUERYSTRING_TYPE_ARRAY; break;
364 case 'O':
365 case 'o': type = HTTP_QUERYSTRING_TYPE_OBJECT; break;
366 }
367 }
368 }
369 http_querystring_get(getThis(), type, name, name_len, defval, del, return_value);
370 } else {
371 RETURN_PROP(queryString);
372 }
373 }
374 }
375 /* }}} */
376
377 /* {{{ proto string HttpQueryString::set(mixed params)
378 *
379 * Set query string entry/entries. NULL values will unset the variable.
380 */
381 PHP_METHOD(HttpQueryString, set)
382 {
383 zval *params;
384
385 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &params)) {
386 zval *qarray = GET_PROP(queryArray);
387 if (http_querystring_modify(qarray, params)) {
388 http_querystring_update(qarray, GET_PROP(queryString));
389 }
390 }
391
392 if (return_value_used) {
393 RETURN_PROP(queryString);
394 }
395 }
396 /* }}} */
397
398 /* {{{ proto HttpQueryString HttpQueryString::mod(mixed params)
399 *
400 * Copies the query string object and sets provided params at the clone.
401 * This is basically shorthand for:
402 * <pre>
403 * <?php
404 * $newQS = new HttpQueryString(false, $oldQS);
405 * $newQS->set($other_params);
406 * ?>
407 * </pre>
408 */
409 PHP_METHOD(HttpQueryString, mod)
410 {
411 zval *orig, *zobj, *qarr, *qstr, *params;
412
413 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &params)) {
414 zobj = http_querystring_instantiate(0);
415 orig = GET_PROP(queryArray);
416 qarr = GET_PROP_EX(zobj, queryArray);
417 qstr = GET_PROP_EX(zobj, queryString);
418
419 http_querystring_modify(qarr, orig);
420 http_querystring_modify(qarr, params);
421 http_querystring_update(qarr, qstr);
422
423 RETURN_ZVAL(zobj, 1, 1);
424 }
425 }
426 /* }}} */
427
428 #ifndef WONKY
429 /* {{{ proto static HttpQueryString HttpQueryString::singleton([bool global = true])
430 *
431 * Get a single instance (differentiates between the global setting).
432 */
433 PHP_METHOD(HttpQueryString, singleton)
434 {
435 zend_bool global = 1;
436 zval *instance = GET_STATIC_PROP(instance);
437
438 SET_EH_THROW_HTTP();
439 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &global)) {
440 zval **zobj_ptr = NULL, *zobj = NULL;
441
442 if (Z_TYPE_P(instance) == IS_ARRAY) {
443 if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(instance), global, (void *) &zobj_ptr)) {
444 RETVAL_ZVAL(*zobj_ptr, 1, 0);
445 } else {
446 zobj = http_querystring_instantiate(global);
447 add_index_zval(instance, global, zobj);
448 RETVAL_OBJECT(zobj, 1);
449 }
450 } else {
451 MAKE_STD_ZVAL(instance);
452 array_init(instance);
453
454 zobj = http_querystring_instantiate(global);
455 add_index_zval(instance, global, zobj);
456 RETVAL_OBJECT(zobj, 1);
457
458 SET_STATIC_PROP(instance, instance);
459 zval_ptr_dtor(&instance);
460 }
461 }
462 SET_EH_NORMAL();
463 }
464 /* }}} */
465 #endif
466
467 /* {{{ Getters by type */
468 #define HTTP_QUERYSTRING_GETTER(method, TYPE) \
469 PHP_METHOD(HttpQueryString, method) \
470 { \
471 char *name; \
472 int name_len; \
473 zval *defval = NULL; \
474 zend_bool del = 0; \
475 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zb", &name, &name_len, &defval, &del)) { \
476 http_querystring_get(getThis(), TYPE, name, name_len, defval, del, return_value); \
477 } \
478 }
479 HTTP_QUERYSTRING_GETTER(getBool, IS_BOOL);
480 HTTP_QUERYSTRING_GETTER(getInt, IS_LONG);
481 HTTP_QUERYSTRING_GETTER(getFloat, IS_DOUBLE);
482 HTTP_QUERYSTRING_GETTER(getString, IS_STRING);
483 HTTP_QUERYSTRING_GETTER(getArray, IS_ARRAY);
484 HTTP_QUERYSTRING_GETTER(getObject, IS_OBJECT);
485 /* }}} */
486
487 #ifdef HTTP_HAVE_ICONV
488 /* {{{ proto bool HttpQueryString::xlate(string ie, string oe)
489 *
490 * Converts the query string from the source encoding ie to the target encoding oe.
491 * WARNING: Don't use any character set that can contain NUL bytes like UTF-16.
492 *
493 * Returns TRUE on success or FALSE on failure.
494 */
495 PHP_METHOD(HttpQueryString, xlate)
496 {
497 char *ie, *oe;
498 int ie_len, oe_len;
499 zval xa, *qa, *qs;
500 STATUS rs;
501
502 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ie, &ie_len, &oe, &oe_len)) {
503 RETURN_FALSE;
504 }
505
506 qa = GET_PROP(queryArray);
507 qs = GET_PROP(queryString);
508 INIT_PZVAL(&xa);
509 array_init(&xa);
510
511 if (SUCCESS == (rs = http_querystring_xlate(&xa, qa, ie, oe))) {
512 zend_hash_clean(Z_ARRVAL_P(qa));
513 zend_hash_copy(Z_ARRVAL_P(qa), Z_ARRVAL(xa), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
514 http_querystring_update(qa, qs);
515 }
516 zval_dtor(&xa);
517
518 RETURN_SUCCESS(rs);
519 }
520 /* }}} */
521 #endif /* HAVE_ICONV */
522
523 /* {{{ proto string HttpQueryString::serialize()
524 *
525 * Implements Serializable.
526 */
527 PHP_METHOD(HttpQueryString, serialize)
528 {
529 NO_ARGS;
530 RETURN_PROP(queryString);
531 }
532 /* }}} */
533
534 /* {{{ proto void HttpQueryString::unserialize(string serialized)
535 *
536 * Implements Serializable.
537 */
538 PHP_METHOD(HttpQueryString, unserialize)
539 {
540 zval *serialized;
541
542 SET_EH_THROW_HTTP();
543 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &serialized)) {
544 if (Z_TYPE_P(serialized) == IS_STRING) {
545 zval *qa = GET_PROP(queryArray);
546
547 zend_hash_clean(Z_ARRVAL_P(qa));
548 http_querystring_modify(qa, serialized);
549 http_querystring_update(qa, GET_PROP(queryString));
550 } else {
551 http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Expected a string as parameter");
552 }
553 }
554 SET_EH_NORMAL();
555 }
556 /* }}} */
557
558 /* {{{ proto mixed HttpQueryString::offsetGet(string offset)
559 *
560 * Implements ArrayAccess.
561 */
562 PHP_METHOD(HttpQueryString, offsetGet)
563 {
564 char *offset_str;
565 int offset_len;
566 zval **value;
567
568 if ( (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) &&
569 (SUCCESS == zend_hash_find(Z_ARRVAL_P(GET_PROP(queryArray)), offset_str, offset_len + 1, (void *) &value))) {
570 RETVAL_ZVAL(*value, 1, 0);
571 }
572 }
573 /* }}} */
574
575 /* {{{ proto void HttpQueryString::offsetSet(string offset, mixed value)
576 *
577 * Implements ArrayAccess.
578 */
579 PHP_METHOD(HttpQueryString, offsetSet)
580 {
581 char *offset_str;
582 int offset_len;
583 zval *value;
584
585 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) {
586 zval *qarr = GET_PROP(queryArray), *qstr = GET_PROP(queryString);
587
588 ZVAL_ADDREF(value);
589 add_assoc_zval_ex(qarr, offset_str, offset_len + 1, value);
590 http_querystring_update(qarr, qstr);
591 }
592 }
593 /* }}} */
594
595 /* {{{ proto bool HttpQueryString::offsetExists(string offset)
596 *
597 * Implements ArrayAccess.
598 */
599 PHP_METHOD(HttpQueryString, offsetExists)
600 {
601 char *offset_str;
602 int offset_len;
603 zval **value;
604
605 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
606 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));
607 }
608 }
609 /* }}} */
610
611 /* {{{ proto void HttpQueryString::offsetUnset(string offset)
612 *
613 * Implements ArrayAccess.
614 */
615 PHP_METHOD(HttpQueryString, offsetUnset)
616 {
617 char *offset_str;
618 int offset_len;
619
620 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
621 zval *qarr = GET_PROP(queryArray);
622
623 if (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarr), offset_str, offset_len + 1)) {
624 http_querystring_update(qarr, GET_PROP(queryString));
625 }
626 }
627 }
628 /* }}} */
629
630 #endif /* ZEND_ENGINE_2 */
631
632 /*
633 * Local variables:
634 * tab-width: 4
635 * c-basic-offset: 4
636 * End:
637 * vim600: noet sw=4 ts=4 fdm=marker
638 * vim<600: noet sw=4 ts=4
639 */
640