static php_http_params_opts_t def_opts = {
.param = def_param_sep_ptr,
.arg = def_arg_sep_ptr,
- .val = def_val_sep_ptr
+ .val = def_val_sep_ptr,
+ .defval = NULL,
+ .flags = PHP_HTTP_PARAMS_DEFAULT
};
PHP_HTTP_API php_http_params_opts_t *php_http_params_opts_default_get(php_http_params_opts_t *opts)
} current;
} php_http_params_state_t;
-static inline void sanitize_string(char *str, size_t len, zval *zv TSRMLS_DC)
+static void sanitize_default(zval *zv TSRMLS_DC)
{
- /* trim whitespace */
- php_trim(str, len, NULL, 0, zv, 3 TSRMLS_CC);
-
- /* dequote */
if (Z_STRVAL_P(zv)[0] == '"' && Z_STRVAL_P(zv)[Z_STRLEN_P(zv) - 1] == '"') {
size_t deq_len = Z_STRLEN_P(zv) - 2;
char *deq = estrndup(Z_STRVAL_P(zv) + 1, deq_len);
ZVAL_STRINGL(zv, deq, deq_len, 0);
}
- /* strip slashes */
php_stripslashes(Z_STRVAL_P(zv), &Z_STRLEN_P(zv) TSRMLS_CC);
}
+static void prepare_default(zval *zv TSRMLS_DC)
+{
+ int len = Z_STRLEN_P(zv);
+
+ Z_STRVAL_P(zv) = php_addslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), &Z_STRLEN_P(zv), 1 TSRMLS_CC);
+
+ if (len != Z_STRLEN_P(zv)) {
+ zval tmp = *zv;
+ int len = Z_STRLEN_P(zv) + 2;
+ char *str = emalloc(len + 1);
+
+ str[0] = '"';
+ memcpy(&str[1], Z_STRVAL_P(zv), Z_STRLEN_P(zv));
+ str[len-1] = '"';
+ str[len] = '\0';
+
+ zval_dtor(&tmp);
+ ZVAL_STRINGL(zv, str, len, 0);
+ }
+}
+
+static void sanitize_urlencoded(zval *zv TSRMLS_DC)
+{
+ Z_STRLEN_P(zv) = php_raw_url_decode(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
+}
+
+static void prepare_urlencoded(zval *zv TSRMLS_DC)
+{
+ int len;
+ char *str = php_raw_url_encode(Z_STRVAL_P(zv), Z_STRLEN_P(zv), &len);
+
+ zval_dtor(zv);
+ ZVAL_STRINGL(zv, str, len, 0);
+}
+
+static void sanitize_dimension(zval *zv TSRMLS_DC)
+{
+ zval *arr = NULL, *tmp = NULL, **cur = NULL;
+ char *var = NULL, *ptr = Z_STRVAL_P(zv), *end = Z_STRVAL_P(zv) + Z_STRLEN_P(zv);
+ long level = 0;
+
+ MAKE_STD_ZVAL(arr);
+ array_init(arr);
+ cur = &arr;
+
+ while (ptr < end) {
+ if (!var) {
+ var = ptr;
+ }
+
+ switch (*ptr) {
+ case '[':
+ if (++level > PG(max_input_nesting_level)) {
+ zval_ptr_dtor(&arr);
+ php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Max input nesting level of %ld exceeded", PG(max_input_nesting_level));
+ return;
+ }
+ if (ptr - var == 0) {
+ ++var;
+ break;
+ }
+ /* no break */
+
+ case ']':
+
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_NULL(tmp);
+ convert_to_array(*cur);
+
+ if (ptr - var) {
+ char chr = *ptr;
+ *ptr = '\0';
+ zend_symtable_update(Z_ARRVAL_PP(cur), var, ptr - var + 1, (void *) &tmp, sizeof(zval *), (void *) &cur);
+ *ptr = chr;
+ } else {
+ zend_hash_next_index_insert(Z_ARRVAL_PP(cur), (void *) &tmp, sizeof(zval *), (void *) &cur);
+ }
+
+ var = NULL;
+ break;
+ }
+
+ ++ptr;
+ }
+
+ if (zend_hash_num_elements(Z_ARRVAL_P(arr))) {
+ zval_dtor(zv);
+ ZVAL_COPY_VALUE(zv, arr);
+ FREE_ZVAL(arr);
+ } else {
+ zval_ptr_dtor(&arr);
+ }
+}
+
+static void prepare_dimension(zval *zv TSRMLS_DC)
+{
+ if (Z_TYPE_P(zv) == IS_ARRAY) {
+ zval **zdata = &zv;
+ php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ php_http_buffer_t buf;
+
+ php_http_buffer_init(&buf);
+
+ do {
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(zdata), &key.str, &key.len, &key.num, key.dup, NULL)) {
+ php_http_buffer_appendf(&buf, "[%s]", key.str);
+ } else {
+ php_http_buffer_appendf(&buf, "[%lu]", key.num);
+ }
+ } while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zdata), (void *) &zdata) && Z_TYPE_PP(zdata) == IS_ARRAY);
+
+ php_http_buffer_fix(&buf);
+ zval_dtor(zv);
+ ZVAL_STRINGL(zv, buf.data, buf.used, 0);
+ }
+}
+
+static void sanitize_key(unsigned flags, char *str, size_t len, zval *zv TSRMLS_DC)
+{
+ php_trim(str, len, NULL, 0, zv, 3 TSRMLS_CC);
+
+ if (flags & PHP_HTTP_PARAMS_DEFAULT) {
+ sanitize_default(zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_URLENCODED) {
+ sanitize_urlencoded(zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_DIMENSION) {
+ sanitize_dimension(zv TSRMLS_CC);
+ }
+}
+
+static void sanitize_value(unsigned flags, char *str, size_t len, zval *zv TSRMLS_DC)
+{
+ php_trim(str, len, NULL, 0, zv, 3 TSRMLS_CC);
+
+ if (flags & PHP_HTTP_PARAMS_DEFAULT) {
+ sanitize_default(zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_URLENCODED) {
+ sanitize_urlencoded(zv TSRMLS_CC);
+ }
+}
+
+static void prepare_key(unsigned flags, char *old_key, size_t old_len, char **new_key, size_t *new_len TSRMLS_DC)
+{
+ zval zv;
+
+ INIT_PZVAL(&zv);
+ ZVAL_STRINGL(&zv, old_key, old_len, 1);
+
+ if (flags & PHP_HTTP_PARAMS_DIMENSION) {
+ prepare_dimension(&zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_URLENCODED) {
+ prepare_urlencoded(&zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_DEFAULT) {
+ prepare_default(&zv TSRMLS_CC);
+ }
+
+ *new_key = Z_STRVAL(zv);
+ *new_len = Z_STRLEN(zv);
+}
+
+static void prepare_value(unsigned flags, zval *zv TSRMLS_DC)
+{
+ if (flags & PHP_HTTP_PARAMS_DIMENSION) {
+ prepare_dimension(zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_URLENCODED) {
+ prepare_urlencoded(zv TSRMLS_CC);
+ }
+
+ if (flags & PHP_HTTP_PARAMS_DEFAULT) {
+ prepare_default(zv TSRMLS_CC);
+ }
+}
+
+static void merge_param(HashTable *params, zval *zdata, zval ***cur TSRMLS_DC)
+{
+ zval **ptr, **zdata_ptr;
+ php_http_array_hashkey_t hkey = php_http_array_hashkey_init(0);
+
+#if 0
+ {
+ zval tmp;
+ INIT_PZVAL_ARRAY(&tmp, params);
+ fprintf(stderr, "params = ");
+ zend_print_zval_r(&tmp, 1 TSRMLS_CC);
+ fprintf(stderr, "\n");
+ }
+#endif
+
+ hkey.type = zend_hash_get_current_key_ex(Z_ARRVAL_P(zdata), &hkey.str, &hkey.len, &hkey.num, hkey.dup, NULL);
+
+ if ((hkey.type == HASH_KEY_IS_STRING && !zend_hash_exists(params, hkey.str, hkey.len))
+ || (hkey.type == HASH_KEY_IS_LONG && !zend_hash_index_exists(params, hkey.num))
+ ) {
+ zval *tmp;
+
+ /* create the entry if it doesn't exist */
+ zend_hash_get_current_data(Z_ARRVAL_P(zdata), (void *) &ptr);
+ Z_ADDREF_PP(ptr);
+ MAKE_STD_ZVAL(tmp);
+ array_init(tmp);
+ add_assoc_zval_ex(tmp, ZEND_STRS("value"), *ptr);
+
+ if (hkey.type == HASH_KEY_IS_STRING) {
+ zend_hash_update(params, hkey.str, hkey.len, (void *) &tmp, sizeof(zval *), (void *) &ptr);
+ } else {
+ zend_hash_index_update(params, hkey.num, (void *) &tmp, sizeof(zval *), (void *) &ptr);
+ }
+ } else {
+ /* merge */
+ if (hkey.type == HASH_KEY_IS_STRING) {
+ zend_hash_find(params, hkey.str, hkey.len, (void *) &ptr);
+ } else {
+ zend_hash_index_find(params, hkey.num, (void *) &ptr);
+ }
+
+ zdata_ptr = &zdata;
+
+ if (Z_TYPE_PP(ptr) == IS_ARRAY
+ && SUCCESS == zend_hash_find(Z_ARRVAL_PP(ptr), "value", sizeof("value"), (void *) &ptr)
+ && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zdata_ptr), (void *) &zdata_ptr)
+ ) {
+ /*
+ * params = [arr => [value => [0 => 1]]]
+ * ^- ptr
+ * zdata = [arr => [0 => NULL]]
+ * ^- zdata_ptr
+ */
+ zval **test_ptr;
+
+ while (Z_TYPE_PP(zdata_ptr) == IS_ARRAY
+ && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zdata_ptr), (void *) &test_ptr)
+ ) {
+ if (Z_TYPE_PP(test_ptr) == IS_ARRAY) {
+
+ /* now find key in ptr */
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(zdata_ptr), &hkey.str, &hkey.len, &hkey.num, hkey.dup, NULL)) {
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) &ptr)) {
+ zdata_ptr = test_ptr;
+ } else {
+ Z_ADDREF_PP(test_ptr);
+ zend_hash_update(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ break;
+ }
+ } else {
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) &ptr)) {
+ zdata_ptr = test_ptr;
+ } else if (hkey.num) {
+ Z_ADDREF_PP(test_ptr);
+ zend_hash_index_update(Z_ARRVAL_PP(ptr), hkey.num, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ break;
+ } else {
+ Z_ADDREF_PP(test_ptr);
+ zend_hash_next_index_insert(Z_ARRVAL_PP(ptr), (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ break;
+ }
+ }
+ } else {
+ /* this is the leaf */
+ Z_ADDREF_PP(test_ptr);
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(zdata_ptr), &hkey.str, &hkey.len, &hkey.num, hkey.dup, NULL)) {
+ zend_hash_update(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ } else if (hkey.num) {
+ zend_hash_index_update(Z_ARRVAL_PP(ptr), hkey.num, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ } else {
+ zend_hash_next_index_insert(Z_ARRVAL_PP(ptr), (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ }
+ break;
+ }
+ }
+
+ }
+ }
+
+ /* bubble up */
+ while (Z_TYPE_PP(ptr) == IS_ARRAY && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(ptr), (void *) &ptr));
+ *cur = ptr;
+}
+
static void push_param(HashTable *params, php_http_params_state_t *state, const php_http_params_opts_t *opts TSRMLS_DC)
{
if (state->val.str) {
if (0 < (state->val.len = state->input.str - state->val.str)) {
- sanitize_string(state->val.str, state->val.len, *(state->current.val) TSRMLS_CC);
+ sanitize_value(opts->flags, state->val.str, state->val.len, *(state->current.val) TSRMLS_CC);
}
} else if (state->arg.str) {
if (0 < (state->arg.len = state->input.str - state->arg.str)) {
zval *val, key;
INIT_PZVAL(&key);
- sanitize_string(state->arg.str, state->arg.len, &key TSRMLS_CC);
+ sanitize_key(opts->flags, state->arg.str, state->arg.len, &key TSRMLS_CC);
if (Z_STRLEN(key)) {
MAKE_STD_ZVAL(val);
ZVAL_TRUE(val);
}
} else if (state->param.str) {
if (0 < (state->param.len = state->input.str - state->param.str)) {
- zval *prm, *arg, *val, key;
-
- INIT_PZVAL(&key);
- sanitize_string(state->param.str, state->param.len, &key TSRMLS_CC);
- if (Z_STRLEN(key)) {
+ zval *prm, *arg, *val, *key;
+
+ MAKE_STD_ZVAL(key);
+ ZVAL_NULL(key);
+ sanitize_key(opts->flags, state->param.str, state->param.len, key TSRMLS_CC);
+ if (Z_TYPE_P(key) != IS_STRING) {
+ merge_param(params, key, &state->current.val TSRMLS_CC);
+ } else if (Z_STRLEN_P(key)) {
MAKE_STD_ZVAL(prm);
array_init(prm);
+
MAKE_STD_ZVAL(val);
- ZVAL_TRUE(val);
+ if (opts->defval) {
+ ZVAL_COPY_VALUE(val, opts->defval);
+ zval_copy_ctor(val);
+ } else {
+ ZVAL_TRUE(val);
+ }
zend_hash_update(Z_ARRVAL_P(prm), "value", sizeof("value"), (void *) &val, sizeof(zval *), (void *) &state->current.val);
MAKE_STD_ZVAL(arg);
array_init(arg);
zend_hash_update(Z_ARRVAL_P(prm), "arguments", sizeof("arguments"), (void *) &arg, sizeof(zval *), (void *) &state->current.args);
- zend_symtable_update(params, Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &prm, sizeof(zval *), (void *) &state->current.param);
+ zend_symtable_update(params, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void *) &prm, sizeof(zval *), (void *) &state->current.param);
}
- zval_dtor(&key);
+ zval_ptr_dtor(&key);
}
}
}
}
while (state.input.len) {
- if (!state.param.str) {
+ if (*state.input.str == '\\') {
+ ++state.input.str;
+ --state.input.len;
+ } else if (!state.param.str) {
/* initialize */
state.param.str = state.input.str;
} else {
}
}
- ++state.input.str;
- --state.input.len;
+ if (state.input.len) {
+ ++state.input.str;
+ --state.input.len;
+ }
}
/* finalize */
push_param(params, &state, opts TSRMLS_CC);
return params;
}
-PHP_HTTP_API 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 TSRMLS_DC)
+PHP_HTTP_API 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 TSRMLS_DC)
{
zval **zparam;
HashPosition pos1, pos2;
- php_http_array_hashkey_t key1 = php_http_array_hashkey_init(0), key2 = php_http_array_hashkey_init(0);
+ php_http_array_hashkey_t key1 = php_http_array_hashkey_init(0), key2 = php_http_array_hashkey_init(0), key3 = php_http_array_hashkey_init(0);
if (!buf) {
buf = php_http_buffer_init(NULL);
/* add name */
if (key1.type == HASH_KEY_IS_STRING) {
- php_http_buffer_append(buf, key1.str, key1.len - 1);
+ char *key;
+ size_t len;
+
+ prepare_key(flags, key1.str, key1.len - 1, &key, &len TSRMLS_CC);
+ php_http_buffer_append(buf, key, len);
+ efree(key);
} else {
php_http_buffer_appendf(buf, "%lu", key1.num);
}
if (Z_TYPE_PP(zparam) != IS_ARRAY) {
zval *tmp = php_http_ztyp(IS_STRING, *zparam);
+ prepare_value(flags, tmp TSRMLS_CC);
+
php_http_buffer_append(buf, vss, vsl);
php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
zval_ptr_dtor(&tmp);
/* got a value? */
if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(zparam), ZEND_STRS("value"), (void *) &zvalue)) {
if (Z_TYPE_PP(zvalue) != IS_BOOL) {
- zval *tmp = php_http_ztyp(IS_STRING, *zvalue);
+ zval *tmp;
+ if (Z_TYPE_PP(zvalue) == IS_ARRAY) {
+ tmp = php_http_zsep(1, IS_ARRAY, *zvalue);
+ prepare_value(flags, tmp TSRMLS_CC);
+ php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+ zval_ptr_dtor(&tmp);
+
+ /* go to leaf */
+ while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zvalue), (void *) &zvalue) && Z_TYPE_PP(zvalue) == IS_ARRAY);
+ }
+
+ tmp = php_http_ztyp(IS_STRING, *zvalue);
+ prepare_value(flags, tmp TSRMLS_CC);
php_http_buffer_append(buf, vss, vsl);
php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
zval_ptr_dtor(&tmp);
/* add name */
if (key2.type == HASH_KEY_IS_STRING) {
- php_http_buffer_append(buf, key2.str, key2.len - 1);
+ char *key;
+ size_t len;
+
+ prepare_key(flags, key2.str, key2.len - 1, &key, &len TSRMLS_CC);
+ php_http_buffer_append(buf, key, len);
+ efree(key);
} else {
php_http_buffer_appendf(buf, "%lu", key2.num);
}
/* add value */
if (Z_TYPE_PP(zarg) != IS_BOOL) {
- zval *tmp = php_http_ztyp(IS_STRING, *zarg);
- int escaped_len;
+ zval *tmp;
- Z_STRVAL_P(tmp) = php_addslashes(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &escaped_len, 1 TSRMLS_CC);
- php_http_buffer_append(buf, vss, vsl);
- if (escaped_len != Z_STRLEN_P(tmp)) {
- php_http_buffer_appends(buf, "\"");
- php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) = escaped_len);
- php_http_buffer_appends(buf, "\"");
- } else {
+ if (Z_TYPE_PP(zarg) == IS_ARRAY) {
+ tmp = php_http_zsep(1, IS_ARRAY, *zarg);
+ prepare_value(flags, tmp TSRMLS_CC);
php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+ zval_ptr_dtor(&tmp);
+
+ /* go to leaf */
+ while (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zarg), (void *) &zarg) && Z_TYPE_PP(zarg) == IS_ARRAY);
}
+
+ tmp = php_http_ztyp(IS_STRING, *zarg);
+ prepare_value(flags, tmp TSRMLS_CC);
+ php_http_buffer_append(buf, vss, vsl);
+ php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
zval_ptr_dtor(&tmp);
} else if (!Z_BVAL_PP(zarg)) {
php_http_buffer_append(buf, vss, vsl);
PHP_HTTP_ARG_VAL(param_sep, 0)
PHP_HTTP_ARG_VAL(arg_sep, 0)
PHP_HTTP_ARG_VAL(val_sep, 0)
+ PHP_HTTP_ARG_VAL(flags, 0)
PHP_HTTP_END_ARGS;
PHP_HTTP_EMPTY_ARGS(toArray);
zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_VAL_SEP"), ZEND_STRL("=") TSRMLS_CC);
zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("COOKIE_PARAM_SEP"), ZEND_STRL("") TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_PARAMS_RAW TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_URLENCODED"), PHP_HTTP_PARAMS_URLENCODED TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DIMENSION"), PHP_HTTP_PARAMS_DIMENSION TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_QUERY"), PHP_HTTP_PARAMS_QUERY TSRMLS_CC);
+
zend_declare_property_null(php_http_params_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("param_sep"), ZEND_STRL(","), ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("arg_sep"), ZEND_STRL(";"), ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("val_sep"), ZEND_STRL("="), ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_long(php_http_params_class_entry, ZEND_STRL("flags"), PHP_HTTP_PARAMS_DEFAULT, ZEND_ACC_PUBLIC TSRMLS_CC);
return SUCCESS;
}
-static php_http_params_token_t **parse_sep(zval *zv TSRMLS_DC)
+PHP_HTTP_API php_http_params_token_t **php_http_params_separator_init(zval *zv TSRMLS_DC)
{
zval **sep;
HashPosition pos;
return ret;
}
-static void free_sep(php_http_params_token_t **separator) {
+PHP_HTTP_API void php_http_params_separator_free(php_http_params_token_t **separator)
+{
php_http_params_token_t **sep = separator;
if (sep) {
while (*sep) {
{
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
zval *zcopy, *zparams = NULL, *param_sep = NULL, *arg_sep = NULL, *val_sep = NULL;
+ long flags = PHP_HTTP_PARAMS_DEFAULT;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z/z/z/", &zparams, ¶m_sep, &arg_sep, &val_sep)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z/z/z/l", &zparams, ¶m_sep, &arg_sep, &val_sep, &flags)) {
switch (ZEND_NUM_ARGS()) {
+ case 5:
+ zend_update_property_long(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), flags TSRMLS_CC);
+ /* no break */
case 4:
zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep TSRMLS_CC);
/* no break */
.str = Z_STRVAL_P(zcopy),
.len = Z_STRLEN_P(zcopy)
},
- .param = parse_sep(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- .arg = parse_sep(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- .val = parse_sep(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC) TSRMLS_CC)
+ .param = php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC) TSRMLS_CC),
+ .arg = php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC) TSRMLS_CC),
+ .val = php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC) TSRMLS_CC),
+ .flags = flags
};
MAKE_STD_ZVAL(zparams);
zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
zval_ptr_dtor(&zparams);
- free_sep(opts.param);
- free_sep(opts.arg);
- free_sep(opts.val);
+ php_http_params_separator_free(opts.param);
+ php_http_params_separator_free(opts.arg);
+ php_http_params_separator_free(opts.val);
}
zval_ptr_dtor(&zcopy);
break;
PHP_METHOD(HttpParams, toString)
{
- zval *zparams, *zpsep, *zasep, *zvsep;
+ zval *zparams, *zpsep, *zasep, *zvsep, *zflags;
php_http_buffer_t buf;
zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
zpsep = php_http_ztyp(IS_STRING, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC));
zasep = php_http_ztyp(IS_STRING, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC));
zvsep = php_http_ztyp(IS_STRING, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC));
+ zflags = php_http_ztyp(IS_LONG, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), 0 TSRMLS_CC));
php_http_buffer_init(&buf);
- php_http_params_to_string(&buf, Z_ARRVAL_P(zparams), Z_STRVAL_P(zpsep), Z_STRLEN_P(zpsep), Z_STRVAL_P(zasep), Z_STRLEN_P(zasep), Z_STRVAL_P(zvsep), Z_STRLEN_P(zvsep) TSRMLS_CC);
+ php_http_params_to_string(&buf, Z_ARRVAL_P(zparams), Z_STRVAL_P(zpsep), Z_STRLEN_P(zpsep), Z_STRVAL_P(zasep), Z_STRLEN_P(zasep), Z_STRVAL_P(zvsep), Z_STRLEN_P(zvsep), Z_LVAL_P(zflags) TSRMLS_CC);
zval_ptr_dtor(&zparams);
zval_ptr_dtor(&zpsep);
zval_ptr_dtor(&zasep);
zval_ptr_dtor(&zvsep);
+ zval_ptr_dtor(&zflags);
RETVAL_PHP_HTTP_BUFFER_VAL(&buf);
}