Merge branch 'master' into phpng
[m6w6/ext-http] / php_http_params.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-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 static php_http_params_token_t def_param_sep = {",", 1}, *def_param_sep_ptr[] = {&def_param_sep, NULL};
16 static php_http_params_token_t def_arg_sep = {";", 1}, *def_arg_sep_ptr[] = {&def_arg_sep, NULL};
17 static php_http_params_token_t def_val_sep = {"=", 1}, *def_val_sep_ptr[] = {&def_val_sep, NULL};
18 static php_http_params_opts_t def_opts = {
19 {NULL, 0},
20 def_param_sep_ptr,
21 def_arg_sep_ptr,
22 def_val_sep_ptr,
23 {{0}},
24 PHP_HTTP_PARAMS_DEFAULT
25 };
26
27 php_http_params_opts_t *php_http_params_opts_default_get(php_http_params_opts_t *opts)
28 {
29 if (!opts) {
30 opts = emalloc(sizeof(*opts));
31 }
32
33 memcpy(opts, &def_opts, sizeof(def_opts));
34
35 return opts;
36 }
37
38 typedef struct php_http_params_state {
39 php_http_params_token_t input;
40 php_http_params_token_t param;
41 php_http_params_token_t arg;
42 php_http_params_token_t val;
43 struct {
44 zval *param;
45 zval *args;
46 zval *val;
47 } current;
48 unsigned quotes:1;
49 unsigned escape:1;
50 unsigned rfc5987:1;
51 } php_http_params_state_t;
52
53 static inline void sanitize_escaped(zval *zv)
54 {
55 if (Z_STRVAL_P(zv)[0] == '"' && Z_STRVAL_P(zv)[Z_STRLEN_P(zv) - 1] == '"') {
56 size_t deq_len = Z_STRLEN_P(zv) - 2;
57 char *deq = estrndup(Z_STRVAL_P(zv) + 1, deq_len);
58
59 zval_dtor(zv);
60 ZVAL_STR(zv, php_http_cs2zs(deq, deq_len));
61 }
62
63 php_stripcslashes(Z_STR_P(zv));
64 }
65
66 static inline void prepare_escaped(zval *zv)
67 {
68 if (Z_TYPE_P(zv) == IS_STRING) {
69 size_t len = Z_STRLEN_P(zv);
70 zend_string *stripped = php_addcslashes(Z_STR_P(zv), 0,
71 ZEND_STRL("\0..\37\173\\\""));
72
73 if (len != stripped->len || strpbrk(stripped->val, "()<>@,;:\"[]?={} ")) {
74 size_t len = stripped->len + 2;
75 char *str = emalloc(len + 1);
76
77 str[0] = '"';
78 memcpy(&str[1], stripped->val, stripped->len);
79 str[len-1] = '"';
80 str[len] = '\0';
81
82 zval_dtor(zv);
83 zend_string_release(stripped);
84 ZVAL_STR(zv, php_http_cs2zs(str, len));
85 } else {
86 zval_dtor(zv);
87 ZVAL_STR(zv, stripped);
88 }
89 } else {
90 zval_dtor(zv);
91 ZVAL_EMPTY_STRING(zv);
92 }
93 }
94
95 static inline void sanitize_urlencoded(zval *zv)
96 {
97 Z_STRLEN_P(zv) = php_raw_url_decode(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
98 }
99
100 static inline void prepare_urlencoded(zval *zv)
101 {
102 zend_string *str = php_raw_url_encode(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
103
104 zval_dtor(zv);
105 ZVAL_STR(zv, str);
106 }
107
108 static void sanitize_dimension(zval *zv)
109 {
110 zval arr, tmp, *cur = NULL;
111 char *var = NULL, *ptr = Z_STRVAL_P(zv), *end = Z_STRVAL_P(zv) + Z_STRLEN_P(zv);
112 long level = 0;
113
114 array_init(&arr);
115 cur = &arr;
116
117 while (ptr < end) {
118 if (!var) {
119 var = ptr;
120 }
121
122 switch (*ptr) {
123 case '[':
124 if (++level > PG(max_input_nesting_level)) {
125 zval_ptr_dtor(&arr);
126 php_error_docref(NULL, E_WARNING, "Max input nesting level of %ld exceeded", (long) PG(max_input_nesting_level));
127 return;
128 }
129 if (ptr - var == 0) {
130 ++var;
131 break;
132 }
133 /* no break */
134
135 case ']':
136
137 ZVAL_NULL(&tmp);
138 convert_to_array(cur);
139
140 if (ptr - var) {
141 char chr = *ptr;
142 *ptr = '\0';
143 cur = zend_symtable_str_update(Z_ARRVAL_P(cur), var, ptr - var, &tmp);
144 *ptr = chr;
145 } else {
146 cur = zend_hash_next_index_insert(Z_ARRVAL_P(cur), &tmp);
147 }
148
149 var = NULL;
150 break;
151 }
152
153 ++ptr;
154 }
155
156 if (zend_hash_num_elements(Z_ARRVAL(arr))) {
157 zval_dtor(zv);
158 ZVAL_COPY_VALUE(zv, &arr);
159 } else {
160 zval_ptr_dtor(&arr);
161 }
162 }
163
164 static inline void shift_key(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags);
165 static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags);
166
167 static void prepare_dimension(php_http_buffer_t *buf, php_http_buffer_t *keybuf, zval *zvalue, const char *pss, size_t psl, const char *vss, size_t vsl, unsigned flags)
168 {
169 HashTable *ht = HASH_OF(zvalue);
170 php_http_arrkey_t key;
171 zval *val;
172 php_http_buffer_t prefix;
173
174 if (!ZEND_HASH_GET_APPLY_COUNT(ht)) {
175 ZEND_HASH_INC_APPLY_COUNT(ht);
176 php_http_buffer_init(&prefix);
177 php_http_buffer_append(&prefix, keybuf->data, keybuf->used);
178
179 ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key.h, key.key, val)
180 {
181 if (key.key && !*key.key->val) {
182 /* only public properties */
183 continue;
184 }
185
186 php_http_buffer_appends(&prefix, "[");
187 if (key.key) {
188 php_http_buffer_append(&prefix, key.key->val, key.key->len);
189 } else {
190 php_http_buffer_appendf(&prefix, "%lu", key.h);
191 }
192 php_http_buffer_appends(&prefix, "]");
193
194 if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) {
195 prepare_dimension(buf, &prefix, val, pss, psl, vss, vsl, flags);
196 } else {
197 zend_string *cpy = zval_get_string(val);
198 zval tmp;
199
200 ZVAL_STR(&tmp, cpy);
201 shift_key(buf, prefix.data, prefix.used, pss, psl, flags);
202 shift_val(buf, &tmp, vss, vsl, flags);
203 zend_string_release(cpy);
204 }
205
206 php_http_buffer_cut(&prefix, keybuf->used, prefix.used - keybuf->used);
207 }
208 ZEND_HASH_FOREACH_END();
209 ZEND_HASH_DEC_APPLY_COUNT(ht);
210
211 php_http_buffer_dtor(&prefix);
212 }
213 }
214
215 static inline void sanitize_key(unsigned flags, const char *str, size_t len, zval *zv, zend_bool *rfc5987)
216 {
217 char *eos;
218 zend_string *zs = zend_string_init(str, len, 0);
219
220 zval_dtor(zv);
221 ZVAL_STR(zv, php_trim(zs, NULL, 0, 3));
222 zend_string_release(zs);
223
224 if (flags & PHP_HTTP_PARAMS_ESCAPED) {
225 sanitize_escaped(zv);
226 }
227
228 if (!Z_STRLEN_P(zv)) {
229 return;
230 }
231
232 eos = &Z_STRVAL_P(zv)[Z_STRLEN_P(zv)-1];
233 if (*eos == '*') {
234 *eos = '\0';
235 *rfc5987 = 1;
236 Z_STRLEN_P(zv) -= 1;
237 }
238
239 if (flags & PHP_HTTP_PARAMS_URLENCODED) {
240 sanitize_urlencoded(zv);
241 }
242
243 if (flags & PHP_HTTP_PARAMS_DIMENSION) {
244 sanitize_dimension(zv);
245 }
246 }
247
248 static inline void sanitize_rfc5987(zval *zv, char **language, zend_bool *latin1)
249 {
250 char *ptr;
251
252 /* examples:
253 * iso-8850-1'de'bl%f6der%20schei%df%21
254 * utf-8'de-DE'bl%c3%b6der%20schei%c3%9f%21
255 */
256
257 switch (Z_STRVAL_P(zv)[0]) {
258 case 'I':
259 case 'i':
260 if (!strncasecmp(Z_STRVAL_P(zv), "iso-8859-1", lenof("iso-8859-1"))) {
261 *latin1 = 1;
262 ptr = Z_STRVAL_P(zv) + lenof("iso-8859-1");
263 break;
264 }
265 /* no break */
266 case 'U':
267 case 'u':
268 if (!strncasecmp(Z_STRVAL_P(zv), "utf-8", lenof("utf-8"))) {
269 *latin1 = 0;
270 ptr = Z_STRVAL_P(zv) + lenof("utf-8");
271 break;
272 }
273 /* no break */
274 default:
275 return;
276 }
277
278 /* extract language */
279 if (*ptr == '\'') {
280 for (*language = ++ptr; *ptr && *ptr != '\''; ++ptr);
281 if (!*ptr) {
282 *language = NULL;
283 return;
284 }
285 *language = estrndup(*language, ptr - *language);
286
287 /* remainder */
288 ptr = estrdup(++ptr);
289 zval_dtor(zv);
290 ZVAL_STR(zv, php_http_cs2zs(ptr, strlen(ptr)));
291 }
292 }
293
294 static void utf8encode(zval *zv)
295 {
296 size_t pos, len = 0;
297 unsigned char *ptr = (unsigned char *) Z_STRVAL_P(zv);
298
299 while (*ptr) {
300 if (*ptr++ >= 0x80) {
301 ++len;
302 }
303 ++len;
304 }
305
306 ptr = safe_emalloc(1, len, 1);
307 for (len = 0, pos = 0; len <= Z_STRLEN_P(zv); ++len, ++pos) {
308 ptr[pos] = Z_STRVAL_P(zv)[len];
309 if ((ptr[pos]) >= 0x80) {
310 ptr[pos + 1] = 0x80 | (ptr[pos] & 0x3f);
311 ptr[pos] = 0xc0 | ((ptr[pos] >> 6) & 0x1f);
312 ++pos;
313 }
314 }
315 zval_dtor(zv);
316 ZVAL_STR(zv, php_http_cs2zs((char *) ptr, pos-1));
317 }
318
319 static inline void sanitize_value(unsigned flags, const char *str, size_t len, zval *zv, zend_bool rfc5987)
320 {
321 char *language = NULL;
322 zend_bool latin1 = 0;
323 zend_string *zs = zend_string_init(str, len, 0);
324
325 zval_dtor(zv);
326 ZVAL_STR(zv, php_trim(zs, NULL, 0, 3));
327 zend_string_release(zs);
328
329 if (rfc5987) {
330 sanitize_rfc5987(zv, &language, &latin1);
331 }
332
333 if (flags & PHP_HTTP_PARAMS_ESCAPED) {
334 sanitize_escaped(zv);
335 }
336
337 if ((flags & PHP_HTTP_PARAMS_URLENCODED) || (rfc5987 && language)) {
338 sanitize_urlencoded(zv);
339 }
340
341 if (rfc5987 && language) {
342 zval tmp;
343
344 if (latin1) {
345 utf8encode(zv);
346 }
347
348 ZVAL_COPY_VALUE(&tmp, zv);
349 array_init(zv);
350 add_assoc_zval(zv, language, &tmp);
351 efree(language);
352 }
353 }
354
355 static inline void prepare_key(unsigned flags, char *old_key, size_t old_len, char **new_key, size_t *new_len)
356 {
357 zval zv;
358
359 ZVAL_STRINGL(&zv, old_key, old_len);
360
361 if (flags & PHP_HTTP_PARAMS_URLENCODED) {
362 prepare_urlencoded(&zv);
363 }
364
365 if (flags & PHP_HTTP_PARAMS_ESCAPED) {
366 prepare_escaped(&zv);
367 }
368
369 *new_key = estrndup(Z_STRVAL(zv), Z_STRLEN(zv));
370 *new_len = Z_STRLEN(zv);
371 zval_ptr_dtor(&zv);
372 }
373
374 static inline void prepare_value(unsigned flags, zval *zv)
375 {
376 if (flags & PHP_HTTP_PARAMS_URLENCODED) {
377 prepare_urlencoded(zv);
378 }
379
380 if (flags & PHP_HTTP_PARAMS_ESCAPED) {
381 prepare_escaped(zv);
382 }
383 }
384
385 static void merge_param(HashTable *params, zval *zdata, zval **current_param, zval **current_args)
386 {
387 zval *ptr, *zdata_ptr;
388 php_http_arrkey_t hkey = {0};
389
390 #if 0
391 {
392 zval tmp;
393 INIT_PZVAL_ARRAY(&tmp, params);
394 fprintf(stderr, "params = ");
395 zend_print_zval_r(&tmp, 1 TSRMLS_CC);
396 fprintf(stderr, "\n");
397 }
398 #endif
399
400 zend_hash_get_current_key(Z_ARRVAL_P(zdata), &hkey.key, &hkey.h);
401
402 if ((hkey.key && !zend_hash_exists(params, hkey.key))
403 || (!hkey.key && !zend_hash_index_exists(params, hkey.h))
404 ) {
405 zval tmp, arg, *args;
406
407 /* create the entry if it doesn't exist */
408 ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata));
409 Z_TRY_ADDREF_P(ptr);
410 array_init(&tmp);
411 add_assoc_zval_ex(&tmp, ZEND_STRL("value"), ptr);
412
413 array_init(&arg);
414 args = zend_hash_str_update(Z_ARRVAL(tmp), "arguments", lenof("arguments"), &arg);
415 *current_args = args;
416
417 if (hkey.key) {
418 ptr = zend_hash_update(params, hkey.key, &tmp);
419 } else {
420 ptr = zend_hash_index_update(params, hkey.h, &tmp);
421 }
422 } else {
423 /* merge */
424 if (hkey.key) {
425 ptr = zend_hash_find(params, hkey.key);
426 } else {
427 ptr = zend_hash_index_find(params, hkey.h);
428 }
429
430 zdata_ptr = zdata;
431
432 if (Z_TYPE_P(ptr) == IS_ARRAY
433 && (ptr = zend_hash_str_find(Z_ARRVAL_P(ptr), "value", lenof("value")))
434 && (zdata_ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata_ptr)))
435 ) {
436 /*
437 * params = [arr => [value => [0 => 1]]]
438 * ^- ptr
439 * zdata = [arr => [0 => NULL]]
440 * ^- zdata_ptr
441 */
442 zval *test_ptr;
443
444 while (Z_TYPE_P(zdata_ptr) == IS_ARRAY && (test_ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata_ptr)))) {
445 if (Z_TYPE_P(test_ptr) == IS_ARRAY) {
446 /* now find key in ptr */
447 if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h)) {
448 zval *tmp_ptr = ptr;
449
450 if ((ptr = zend_hash_find(Z_ARRVAL_P(ptr), hkey.key))) {
451 zdata_ptr = test_ptr;
452 } else {
453 ptr = tmp_ptr;
454 Z_TRY_ADDREF_P(test_ptr);
455 ptr = zend_hash_update(Z_ARRVAL_P(ptr), hkey.key, test_ptr);
456 break;
457 }
458 } else {
459 if ((ptr = zend_hash_index_find(Z_ARRVAL_P(ptr), hkey.h))) {
460 zdata_ptr = test_ptr;
461 } else if (hkey.h) {
462 Z_TRY_ADDREF_P(test_ptr);
463 ptr = zend_hash_index_update(Z_ARRVAL_P(ptr), hkey.h, test_ptr);
464 break;
465 } else {
466 Z_TRY_ADDREF_P(test_ptr);
467 ptr = zend_hash_next_index_insert(Z_ARRVAL_P(ptr), test_ptr);
468 break;
469 }
470 }
471 } else {
472 /* this is the leaf */
473 Z_TRY_ADDREF_P(test_ptr);
474 if (Z_TYPE_P(ptr) != IS_ARRAY) {
475 zval_dtor(ptr);
476 array_init(ptr);
477 }
478 if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h)) {
479 ptr = zend_hash_update(Z_ARRVAL_P(ptr), hkey.key, test_ptr);
480 } else if (hkey.h) {
481 ptr = zend_hash_index_update(Z_ARRVAL_P(ptr), hkey.h, test_ptr);
482 } else {
483 ptr = zend_hash_next_index_insert(Z_ARRVAL_P(ptr), test_ptr);
484 }
485 break;
486 }
487 }
488
489 }
490 }
491
492 /* bubble up */
493 while (Z_TYPE_P(ptr) == IS_ARRAY) {
494 zval *tmp = zend_hash_get_current_data(Z_ARRVAL_P(ptr));
495
496 if (tmp) {
497 ptr = tmp;
498 } else {
499 break;
500 }
501 }
502 *current_param = ptr;
503 }
504
505 static void push_param(HashTable *params, php_http_params_state_t *state, const php_http_params_opts_t *opts)
506 {
507 if (state->val.str) {
508 if (0 < (state->val.len = state->input.str - state->val.str)) {
509 sanitize_value(opts->flags, state->val.str, state->val.len, state->current.val, state->rfc5987);
510 }
511 state->rfc5987 = 0;
512 } else if (state->arg.str) {
513 if (0 < (state->arg.len = state->input.str - state->arg.str)) {
514 zval val, key;
515 zend_bool rfc5987 = 0;
516
517 ZVAL_NULL(&key);
518 sanitize_key(opts->flags, state->arg.str, state->arg.len, &key, &rfc5987);
519 state->rfc5987 = rfc5987;
520 if (Z_TYPE(key) == IS_STRING && Z_STRLEN(key)) {
521 ZVAL_TRUE(&val);
522
523 if (rfc5987) {
524 zval *rfc;
525
526 if ((rfc = zend_hash_str_find(Z_ARRVAL_P(state->current.args), ZEND_STRL("*rfc5987*")))) {
527 state->current.val = zend_symtable_str_update(Z_ARRVAL_P(rfc), Z_STRVAL(key), Z_STRLEN(key), &val);
528 } else {
529 zval tmp;
530
531 array_init_size(&tmp, 1);
532 state->current.val = zend_symtable_str_update(Z_ARRVAL(tmp), Z_STRVAL(key), Z_STRLEN(key), &val);
533 zend_symtable_str_update(Z_ARRVAL_P(state->current.args), ZEND_STRL("*rfc5987*"), &tmp);
534 }
535 } else {
536 state->current.val = zend_symtable_str_update(Z_ARRVAL_P(state->current.args), Z_STRVAL(key), Z_STRLEN(key), &val);
537 }
538 }
539 zval_dtor(&key);
540 }
541 } else if (state->param.str) {
542 if (0 < (state->param.len = state->input.str - state->param.str)) {
543 zval prm, arg, val, key;
544 zend_bool rfc5987 = 0;
545
546 ZVAL_NULL(&key);
547 sanitize_key(opts->flags, state->param.str, state->param.len, &key, &rfc5987);
548 state->rfc5987 = rfc5987;
549 if (Z_TYPE(key) == IS_ARRAY) {
550 merge_param(params, &key, &state->current.val, &state->current.args);
551 } else if (Z_TYPE(key) == IS_STRING && Z_STRLEN(key)) {
552 //array_init_size(&prm, 2);
553 array_init(&prm);
554
555 if (!Z_ISUNDEF(opts->defval)) {
556 ZVAL_COPY_VALUE(&val, &opts->defval);
557 zval_copy_ctor(&val);
558 } else {
559 ZVAL_TRUE(&val);
560 }
561 if (rfc5987 && (opts->flags & PHP_HTTP_PARAMS_RFC5987)) {
562 state->current.val = zend_hash_str_update(Z_ARRVAL(prm), "*rfc5987*", lenof("*rfc5987*"), &val);
563 } else {
564 state->current.val = zend_hash_str_update(Z_ARRVAL(prm), "value", lenof("value"), &val);
565 }
566 //array_init_size(&arg, 3);
567 array_init(&arg);
568 state->current.args = zend_hash_str_update(Z_ARRVAL(prm), "arguments", lenof("arguments"), &arg);
569 state->current.param = zend_symtable_str_update(params, Z_STRVAL(key), Z_STRLEN(key), &prm);
570 }
571 zval_ptr_dtor(&key);
572 }
573 }
574 }
575
576 static inline zend_bool check_str(const char *chk_str, size_t chk_len, const char *sep_str, size_t sep_len) {
577 return 0 < sep_len && chk_len >= sep_len && *chk_str == *sep_str && !memcmp(chk_str + 1, sep_str + 1, sep_len - 1);
578 }
579
580 static size_t check_sep(php_http_params_state_t *state, php_http_params_token_t **separators)
581 {
582 php_http_params_token_t **sep = separators;
583
584 if (state->quotes || state->escape) {
585 return 0;
586 }
587
588 if (sep) while (*sep) {
589 if (check_str(state->input.str, state->input.len, (*sep)->str, (*sep)->len)) {
590 return (*sep)->len;
591 }
592 ++sep;
593 }
594 return 0;
595 }
596
597 static void skip_sep(size_t skip, php_http_params_state_t *state, php_http_params_token_t **param, php_http_params_token_t **arg, php_http_params_token_t **val)
598 {
599 size_t sep_len;
600
601 state->input.str += skip;
602 state->input.len -= skip;
603
604 while ( (param && (sep_len = check_sep(state, param)))
605 || (arg && (sep_len = check_sep(state, arg)))
606 || (val && (sep_len = check_sep(state, val)))
607 ) {
608 state->input.str += sep_len;
609 state->input.len -= sep_len;
610 }
611 }
612
613 HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts)
614 {
615 php_http_params_state_t state = {{NULL,0}, {NULL,0}, {NULL,0}, {NULL,0}, {NULL,NULL,NULL}, 0, 0};
616
617 state.input.str = opts->input.str;
618 state.input.len = opts->input.len;
619
620 if (!params) {
621 ALLOC_HASHTABLE(params);
622 ZEND_INIT_SYMTABLE(params);
623 }
624
625 while (state.input.len) {
626 if (*state.input.str == '"' && !state.escape) {
627 state.quotes = !state.quotes;
628 } else {
629 state.escape = (*state.input.str == '\\');
630 }
631
632 if (!state.param.str) {
633 /* initialize */
634 skip_sep(0, &state, opts->param, opts->arg, opts->val);
635 state.param.str = state.input.str;
636 } else {
637 size_t sep_len;
638 /* are we at a param separator? */
639 if (0 < (sep_len = check_sep(&state, opts->param))) {
640 push_param(params, &state, opts);
641
642 skip_sep(sep_len, &state, opts->param, opts->arg, opts->val);
643
644 /* start off with a new param */
645 state.param.str = state.input.str;
646 state.param.len = 0;
647 state.arg.str = NULL;
648 state.arg.len = 0;
649 state.val.str = NULL;
650 state.val.len = 0;
651
652 continue;
653
654 } else
655 /* are we at an arg separator? */
656 if (0 < (sep_len = check_sep(&state, opts->arg))) {
657 push_param(params, &state, opts);
658
659 skip_sep(sep_len, &state, NULL, opts->arg, opts->val);
660
661 /* continue with a new arg */
662 state.arg.str = state.input.str;
663 state.arg.len = 0;
664 state.val.str = NULL;
665 state.val.len = 0;
666
667 continue;
668
669 } else
670 /* are we at a val separator? */
671 if (0 < (sep_len = check_sep(&state, opts->val))) {
672 /* only handle separator if we're not already reading in a val */
673 if (!state.val.str) {
674 push_param(params, &state, opts);
675
676 skip_sep(sep_len, &state, NULL, NULL, opts->val);
677
678 state.val.str = state.input.str;
679 state.val.len = 0;
680
681 continue;
682 }
683 }
684 }
685
686 if (state.input.len) {
687 ++state.input.str;
688 --state.input.len;
689 }
690 }
691 /* finalize */
692 push_param(params, &state, opts);
693
694 return params;
695 }
696
697 static inline void shift_key(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags)
698 {
699 char *str;
700 size_t len;
701
702 if (buf->used) {
703 php_http_buffer_append(buf, ass, asl);
704 }
705
706 prepare_key(flags, key_str, key_len, &str, &len);
707 php_http_buffer_append(buf, str, len);
708 efree(str);
709 }
710
711 static inline void shift_rfc5987(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags)
712 {
713 HashTable *ht = HASH_OF(zvalue);
714 zval *zdata, tmp;
715 zend_string *zs;
716 php_http_arrkey_t key = {0};
717
718 if ((zdata = zend_hash_get_current_data(ht))
719 && HASH_KEY_NON_EXISTENT != zend_hash_get_current_key(ht, &key.key, &key.h)
720 ) {
721 php_http_arrkey_stringify(&key, NULL);
722 php_http_buffer_appendf(buf, "*%.*sutf-8'%.*s'",
723 (int) (vsl > INT_MAX ? INT_MAX : vsl), vss,
724 (int) (key.key->len > INT_MAX ? INT_MAX : key.key->len), key.key->val);
725 php_http_arrkey_dtor(&key);
726
727 if (Z_TYPE_P(zdata) == IS_INDIRECT) {
728 zdata = Z_INDIRECT_P(zdata);
729 }
730 zs = zval_get_string(zdata);
731 ZVAL_STR(&tmp, zs);
732 prepare_value(flags | PHP_HTTP_PARAMS_URLENCODED, &tmp);
733 php_http_buffer_append(buf, Z_STRVAL(tmp), Z_STRLEN(tmp));
734 zval_ptr_dtor(&tmp);
735 }
736 }
737
738 static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags)
739 {
740 zval tmp;
741 zend_string *zs;
742
743 switch (Z_TYPE_P(zvalue)) {
744 case IS_TRUE:
745 break;
746
747 case IS_FALSE:
748 php_http_buffer_append(buf, vss, vsl);
749 php_http_buffer_appends(buf, "0");
750 break;
751
752 default:
753 zs = zval_get_string(zvalue);
754
755 ZVAL_STR(&tmp, zs);
756 prepare_value(flags, &tmp);
757 php_http_buffer_append(buf, vss, vsl);
758 php_http_buffer_append(buf, Z_STRVAL(tmp), Z_STRLEN(tmp));
759
760 zval_ptr_dtor(&tmp);
761 break;
762 }
763 }
764
765 static void shift_arg(php_http_buffer_t *buf, char *key_str, size_t key_len, zval *zvalue, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags)
766 {
767 if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
768 php_http_arrkey_t key;
769 HashTable *ht = HASH_OF(zvalue);
770 zval *val;
771 zend_bool rfc5987 = !strcmp(key_str, "*rfc5987*");
772
773 if (!rfc5987) {
774 shift_key(buf, key_str, key_len, ass, asl, flags);
775 }
776 ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key.h, key.key, val)
777 {
778 /* did you mean recursion? */
779 php_http_arrkey_stringify(&key, NULL);
780 if (rfc5987 && (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT)) {
781 shift_key(buf, key.key->val, key.key->len, ass, asl, flags);
782 shift_rfc5987(buf, val, vss, vsl, flags);
783 } else {
784 shift_arg(buf, key.key->val, key.key->len, val, ass, asl, vss, vsl, flags);
785 }
786 php_http_arrkey_dtor(&key);
787 }
788 ZEND_HASH_FOREACH_END();
789 } else {
790 shift_key(buf, key_str, key_len, ass, asl, flags);
791 shift_val(buf, zvalue, vss, vsl, flags);
792 }
793 }
794
795 static void shift_param(php_http_buffer_t *buf, char *key_str, size_t key_len, zval *zvalue, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags, zend_bool rfc5987)
796 {
797 if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
798 /* treat as arguments, unless we care for dimensions or rfc5987 */
799 if (flags & PHP_HTTP_PARAMS_DIMENSION) {
800 php_http_buffer_t *keybuf = php_http_buffer_from_string(key_str, key_len);
801 prepare_dimension(buf, keybuf, zvalue, pss, psl, vss, vsl, flags);
802 php_http_buffer_free(&keybuf);
803 } else if (rfc5987) {
804 shift_key(buf, key_str, key_len, pss, psl, flags);
805 shift_rfc5987(buf, zvalue, vss, vsl, flags);
806 } else {
807 shift_arg(buf, key_str, key_len, zvalue, ass, asl, vss, vsl, flags);
808 }
809 } else {
810 shift_key(buf, key_str, key_len, pss, psl, flags);
811 shift_val(buf, zvalue, vss, vsl, flags);
812 }
813 }
814
815 php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags)
816 {
817 zval *zparam;
818 php_http_arrkey_t key;
819 zend_bool rfc5987 = 0;
820
821 if (!buf) {
822 buf = php_http_buffer_init(NULL);
823 }
824
825 ZEND_HASH_FOREACH_KEY_VAL(params, key.h, key.key, zparam)
826 {
827 zval *zvalue, *zargs;
828
829 if (Z_TYPE_P(zparam) != IS_ARRAY) {
830 zvalue = zparam;
831 } else {
832 if (!(zvalue = zend_hash_str_find(Z_ARRVAL_P(zparam), ZEND_STRL("value")))) {
833 if (!(zvalue = zend_hash_str_find(Z_ARRVAL_P(zparam), ZEND_STRL("*rfc5987*")))) {
834 zvalue = zparam;
835 } else {
836 rfc5987 = 1;
837 }
838 }
839 }
840
841 php_http_arrkey_stringify(&key, NULL);
842 shift_param(buf, key.key->val, key.key->len, zvalue, pss, psl, ass, asl, vss, vsl, flags, rfc5987);
843 php_http_arrkey_dtor(&key);
844
845 if (Z_TYPE_P(zparam) == IS_ARRAY) {
846 zval *tmp = zend_hash_str_find(Z_ARRVAL_P(zparam), ZEND_STRL("arguments"));
847
848 if (tmp) {
849 zvalue = tmp;
850 } else if (zvalue == zparam) {
851 continue;
852 } else {
853 zvalue = zparam;
854 }
855 }
856
857 if (Z_TYPE_P(zvalue) == IS_ARRAY) {
858 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(zvalue), key.h, key.key, zargs)
859 {
860 if (zvalue == zparam && key.key && zend_string_equals_literal(key.key, "value")) {
861 continue;
862 }
863
864 php_http_arrkey_stringify(&key, NULL);
865 shift_arg(buf, key.key->val, key.key->len, zargs, ass, asl, vss, vsl, flags);
866 php_http_arrkey_dtor(&key);
867 }
868 ZEND_HASH_FOREACH_END();
869 }
870 }
871 ZEND_HASH_FOREACH_END();
872
873 php_http_buffer_shrink(buf);
874 php_http_buffer_fix(buf);
875
876 return buf;
877 }
878
879 php_http_params_token_t **php_http_params_separator_init(zval *zv)
880 {
881 zval *sep, ztmp;
882 php_http_params_token_t **ret, **tmp;
883
884 if (!zv) {
885 return NULL;
886 }
887
888 ZVAL_DUP(&ztmp, zv);
889 zv = &ztmp;
890 convert_to_array(zv);
891
892 ret = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(zv)) + 1, sizeof(*ret));
893
894 tmp = ret;
895 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zv), sep)
896 {
897 zend_string *zs = zval_get_string(sep);
898
899 if (zs->len) {
900 *tmp = emalloc(sizeof(**tmp));
901 (*tmp)->str = estrndup(zs->val, (*tmp)->len = zs->len);
902 ++tmp;
903 }
904 zend_string_release(zs);
905 }
906 ZEND_HASH_FOREACH_END();
907
908 zval_ptr_dtor(&ztmp);
909
910 *tmp = NULL;
911 return ret;
912 }
913
914 void php_http_params_separator_free(php_http_params_token_t **separator)
915 {
916 php_http_params_token_t **sep = separator;
917 if (sep) {
918 while (*sep) {
919 PTR_FREE((*sep)->str);
920 efree(*sep);
921 ++sep;
922 }
923 efree(separator);
924 }
925 }
926
927 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams___construct, 0, 0, 0)
928 ZEND_ARG_INFO(0, params)
929 ZEND_ARG_INFO(0, param_sep)
930 ZEND_ARG_INFO(0, arg_sep)
931 ZEND_ARG_INFO(0, val_sep)
932 ZEND_ARG_INFO(0, flags)
933 ZEND_END_ARG_INFO();
934 PHP_METHOD(HttpParams, __construct)
935 {
936 zval *zparams = NULL, *param_sep = NULL, *arg_sep = NULL, *val_sep = NULL;
937 zend_long flags = PHP_HTTP_PARAMS_DEFAULT;
938 zend_error_handling zeh;
939 zend_string *zs;
940
941 php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!/z/z/z/l", &zparams, &param_sep, &arg_sep, &val_sep, &flags), invalid_arg, return);
942
943 zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh);
944 {
945 switch (ZEND_NUM_ARGS()) {
946 case 5:
947 zend_update_property_long(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), flags);
948 /* no break */
949 case 4:
950 zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep);
951 /* no break */
952 case 3:
953 zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), arg_sep);
954 /* no break */
955 case 2:
956 zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep);
957 /* no break */
958 }
959
960 if (zparams) {
961 switch (Z_TYPE_P(zparams)) {
962 case IS_OBJECT:
963 case IS_ARRAY:
964 convert_to_array(zparams);
965 zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams);
966 break;
967 default:
968 zs = zval_get_string(zparams);
969 if (zs->len) {
970 zval tmp;
971
972 php_http_params_opts_t opts = {
973 {zs->val, zs->len},
974 php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0, &tmp)),
975 php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0, &tmp)),
976 php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0, &tmp)),
977 {{0}}, flags
978 };
979
980 array_init(&tmp);
981 php_http_params_parse(Z_ARRVAL(tmp), &opts);
982 zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp);
983 zval_ptr_dtor(&tmp);
984
985 php_http_params_separator_free(opts.param);
986 php_http_params_separator_free(opts.arg);
987 php_http_params_separator_free(opts.val);
988 }
989 zend_string_release(zs);
990 break;
991 }
992 } else {
993 zval tmp;
994
995 array_init(&tmp);
996 zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp);
997 zval_ptr_dtor(&tmp);
998 }
999 }
1000 zend_restore_error_handling(&zeh);
1001 }
1002
1003 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toArray, 0, 0, 0)
1004 ZEND_END_ARG_INFO();
1005 PHP_METHOD(HttpParams, toArray)
1006 {
1007 zval zparams_tmp, *zparams;
1008
1009 if (SUCCESS != zend_parse_parameters_none()) {
1010 return;
1011 }
1012 zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
1013 RETURN_ZVAL_FAST(zparams);
1014 }
1015
1016 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toString, 0, 0, 0)
1017 ZEND_END_ARG_INFO();
1018 PHP_METHOD(HttpParams, toString)
1019 {
1020 zval *tmp, *zparams, *zpsep, *zasep, *zvsep;
1021 zval zparams_tmp, flags_tmp, psep_tmp, asep_tmp, vsep_tmp;
1022 zend_string *psep, *asep, *vsep;
1023 long flags;
1024 php_http_buffer_t buf;
1025
1026 zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
1027 convert_to_array_ex(zparams);
1028 flags = zval_get_long(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), 0, &flags_tmp));
1029
1030 zpsep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0, &psep_tmp);
1031 if (Z_TYPE_P(zpsep) == IS_ARRAY && (tmp = zend_hash_get_current_data(Z_ARRVAL_P(zpsep)))) {
1032 psep = zval_get_string(tmp);
1033 } else {
1034 psep = zval_get_string(zpsep);
1035 }
1036 zasep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0, &asep_tmp);
1037 if (Z_TYPE_P(zasep) == IS_ARRAY && (tmp = zend_hash_get_current_data(Z_ARRVAL_P(zasep)))) {
1038 asep = zval_get_string(tmp);
1039 } else {
1040 asep = zval_get_string(zasep);
1041 }
1042 zvsep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0, &vsep_tmp);
1043 if (Z_TYPE_P(zvsep) == IS_ARRAY && (tmp = zend_hash_get_current_data(Z_ARRVAL_P(zvsep)))) {
1044 vsep = zval_get_string(tmp);
1045 } else {
1046 vsep = zval_get_string(zvsep);
1047 }
1048
1049 php_http_buffer_init(&buf);
1050 php_http_params_to_string(&buf, Z_ARRVAL_P(zparams), psep->val, psep->len, asep->val, asep->len, vsep->val, vsep->len, flags);
1051
1052 zend_string_release(psep);
1053 zend_string_release(asep);
1054 zend_string_release(vsep);
1055
1056 RETVAL_STR(php_http_cs2zs(buf.data, buf.used));
1057 }
1058
1059 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetExists, 0, 0, 1)
1060 ZEND_ARG_INFO(0, name)
1061 ZEND_END_ARG_INFO();
1062 PHP_METHOD(HttpParams, offsetExists)
1063 {
1064 zend_string *name;
1065 zval zparams_tmp, *zparam, *zparams;
1066
1067 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name)) {
1068 return;
1069 }
1070
1071 zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
1072
1073 if (Z_TYPE_P(zparams) == IS_ARRAY && (zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
1074 RETVAL_BOOL(Z_TYPE_P(zparam) != IS_NULL);
1075 } else {
1076 RETVAL_FALSE;
1077 }
1078 }
1079
1080 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetGet, 0, 0, 1)
1081 ZEND_ARG_INFO(0, name)
1082 ZEND_END_ARG_INFO();
1083 PHP_METHOD(HttpParams, offsetGet)
1084 {
1085 zend_string *name;
1086 zval zparams_tmp, *zparam, *zparams;
1087
1088 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name)) {
1089 return;
1090 }
1091
1092 zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
1093
1094 if (Z_TYPE_P(zparams) == IS_ARRAY && (zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
1095 RETVAL_ZVAL_FAST(zparam);
1096 }
1097 }
1098
1099 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetUnset, 0, 0, 1)
1100 ZEND_ARG_INFO(0, name)
1101 ZEND_END_ARG_INFO();
1102 PHP_METHOD(HttpParams, offsetUnset)
1103 {
1104 zend_string *name;
1105 zval zparams_tmp, *zparams;
1106
1107 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name)) {
1108 return;
1109 }
1110
1111 zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
1112
1113 if (Z_TYPE_P(zparams) == IS_ARRAY) {
1114 zend_symtable_del(Z_ARRVAL_P(zparams), name);
1115 }
1116 }
1117
1118 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetSet, 0, 0, 2)
1119 ZEND_ARG_INFO(0, name)
1120 ZEND_ARG_INFO(0, value)
1121 ZEND_END_ARG_INFO();
1122 PHP_METHOD(HttpParams, offsetSet)
1123 {
1124 zend_string *name;
1125 zval zparams_tmp, *zparam, *zparams, *nvalue;
1126
1127 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz", &name, &nvalue)) {
1128 return;
1129 }
1130
1131 zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
1132 convert_to_array(zparams);
1133
1134 if (name->len) {
1135 if (Z_TYPE_P(nvalue) == IS_ARRAY) {
1136 if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
1137 convert_to_array(zparam);
1138 array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(zparam), 0, 0);
1139 } else {
1140 Z_TRY_ADDREF_P(nvalue);
1141 add_assoc_zval_ex(zparams, name->val, name->len, nvalue);
1142 }
1143 } else {
1144 zval tmp;
1145
1146 if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
1147 ZVAL_DUP(&tmp, zparam);
1148 convert_to_array(&tmp);
1149 } else {
1150 array_init(&tmp);
1151 }
1152
1153 Z_TRY_ADDREF_P(nvalue);
1154 add_assoc_zval_ex(&tmp, ZEND_STRL("value"), nvalue);
1155 add_assoc_zval_ex(zparams, name->val, name->len, &tmp);
1156 }
1157 } else {
1158 zval arr;
1159 zend_string *zs = zval_get_string(nvalue);
1160
1161 array_init(&arr);
1162 add_assoc_bool_ex(&arr, ZEND_STRL("value"), 1);
1163 add_assoc_zval_ex(zparams, zs->val, zs->len, &arr);
1164 zend_string_release(zs);
1165 }
1166 }
1167
1168 static zend_function_entry php_http_params_methods[] = {
1169 PHP_ME(HttpParams, __construct, ai_HttpParams___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL)
1170
1171 PHP_ME(HttpParams, toArray, ai_HttpParams_toArray, ZEND_ACC_PUBLIC)
1172 PHP_ME(HttpParams, toString, ai_HttpParams_toString, ZEND_ACC_PUBLIC)
1173 ZEND_MALIAS(HttpParams, __toString, toString, ai_HttpParams_toString, ZEND_ACC_PUBLIC)
1174
1175 PHP_ME(HttpParams, offsetExists, ai_HttpParams_offsetExists, ZEND_ACC_PUBLIC)
1176 PHP_ME(HttpParams, offsetUnset, ai_HttpParams_offsetUnset, ZEND_ACC_PUBLIC)
1177 PHP_ME(HttpParams, offsetSet, ai_HttpParams_offsetSet, ZEND_ACC_PUBLIC)
1178 PHP_ME(HttpParams, offsetGet, ai_HttpParams_offsetGet, ZEND_ACC_PUBLIC)
1179
1180 EMPTY_FUNCTION_ENTRY
1181 };
1182
1183 zend_class_entry *php_http_params_class_entry;
1184
1185 PHP_MINIT_FUNCTION(http_params)
1186 {
1187 zend_class_entry ce = {0};
1188
1189 INIT_NS_CLASS_ENTRY(ce, "http", "Params", php_http_params_methods);
1190 php_http_params_class_entry = zend_register_internal_class(&ce);
1191 php_http_params_class_entry->create_object = php_http_params_object_new;
1192 zend_class_implements(php_http_params_class_entry, 1, zend_ce_arrayaccess);
1193
1194 zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_PARAM_SEP"), ZEND_STRL(","));
1195 zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_ARG_SEP"), ZEND_STRL(";"));
1196 zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_VAL_SEP"), ZEND_STRL("="));
1197 zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("COOKIE_PARAM_SEP"), ZEND_STRL(""));
1198
1199 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_PARAMS_RAW);
1200 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_ESCAPED"), PHP_HTTP_PARAMS_ESCAPED);
1201 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_URLENCODED"), PHP_HTTP_PARAMS_URLENCODED);
1202 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DIMENSION"), PHP_HTTP_PARAMS_DIMENSION);
1203 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RFC5987"), PHP_HTTP_PARAMS_RFC5987);
1204 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT);
1205 zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_QUERY"), PHP_HTTP_PARAMS_QUERY);
1206
1207 zend_declare_property_null(php_http_params_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC);
1208 zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("param_sep"), ZEND_STRL(","), ZEND_ACC_PUBLIC);
1209 zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("arg_sep"), ZEND_STRL(";"), ZEND_ACC_PUBLIC);
1210 zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("val_sep"), ZEND_STRL("="), ZEND_ACC_PUBLIC);
1211 zend_declare_property_long(php_http_params_class_entry, ZEND_STRL("flags"), PHP_HTTP_PARAMS_DEFAULT, ZEND_ACC_PUBLIC);
1212
1213 return SUCCESS;
1214 }
1215
1216 /*
1217 * Local variables:
1218 * tab-width: 4
1219 * c-basic-offset: 4
1220 * End:
1221 * vim600: noet sw=4 ts=4 fdm=marker
1222 * vim<600: noet sw=4 ts=4
1223 */
1224