X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_params.c;h=b91314df617e8766d0d772f62d45939955ec8f6a;hp=523424423d3b21ce15704d4804cae4dd73fc1daa;hb=16bf75db1f89db511833657630cff588576088e2;hpb=2b065af121eb367bd3fe7e5ad3c673d342438d34 diff --git a/php_http_params.c b/php_http_params.c index 5234244..b91314d 100644 --- a/php_http_params.c +++ b/php_http_params.c @@ -291,6 +291,12 @@ static inline void sanitize_rfc5987(zval *zv, char **language, zend_bool *latin1 } } +static inline void sanitize_rfc5988(char *str, size_t len, zval *zv TSRMLS_DC) +{ + zval_dtor(zv); + php_trim(str, len, " ><", 3, zv, 3 TSRMLS_CC); +} + static void utf8encode(zval *zv) { size_t pos, len = 0; @@ -347,7 +353,7 @@ static inline void sanitize_value(unsigned flags, char *str, size_t len, zval *z ZVAL_COPY_VALUE(tmp, zv); array_init(zv); add_assoc_zval(zv, language, tmp); - STR_FREE(language); + PTR_FREE(language); } } @@ -541,8 +547,12 @@ static void push_param(HashTable *params, php_http_params_state_t *state, const MAKE_STD_ZVAL(key); ZVAL_NULL(key); - sanitize_key(opts->flags, state->param.str, state->param.len, key, &rfc5987 TSRMLS_CC); - state->rfc5987 = rfc5987; + if (opts->flags & PHP_HTTP_PARAMS_RFC5988) { + sanitize_rfc5988(state->param.str, state->param.len, key TSRMLS_CC); + } else { + sanitize_key(opts->flags, state->param.str, state->param.len, key, &rfc5987 TSRMLS_CC); + state->rfc5987 = rfc5987; + } if (Z_TYPE_P(key) != IS_STRING) { merge_param(params, key, &state->current.val, &state->current.args TSRMLS_CC); } else if (Z_STRLEN_P(key)) { @@ -623,7 +633,13 @@ HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t } while (state.input.len) { - if (*state.input.str == '"' && !state.escape) { + if ((opts->flags & PHP_HTTP_PARAMS_RFC5988) && !state.arg.str) { + if (*state.input.str == '<') { + state.quotes = 1; + } else if (*state.input.str == '>') { + state.quotes = 0; + } + } else if (*state.input.str == '"' && !state.escape) { state.quotes = !state.quotes; } else { state.escape = (*state.input.str == '\\'); @@ -730,6 +746,22 @@ static inline void shift_rfc5987(php_http_buffer_t *buf, zval *zvalue, const cha } } +static inline void shift_rfc5988(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags TSRMLS_DC) +{ + char *str; + size_t len; + + if (buf->used) { + php_http_buffer_append(buf, ass, asl); + } + + prepare_key(flags, key_str, key_len, &str, &len TSRMLS_CC); + php_http_buffer_appends(buf, "<"); + php_http_buffer_append(buf, str, len); + php_http_buffer_appends(buf, ">"); + efree(str); +} + static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags TSRMLS_DC) { if (Z_TYPE_P(zvalue) != IS_BOOL) { @@ -789,7 +821,11 @@ static void shift_param(php_http_buffer_t *buf, char *key_str, size_t key_len, z shift_arg(buf, key_str, key_len, zvalue, ass, asl, vss, vsl, flags TSRMLS_CC); } } else { - shift_key(buf, key_str, key_len, pss, psl, flags TSRMLS_CC); + if (flags & PHP_HTTP_PARAMS_RFC5988) { + shift_rfc5988(buf, key_str, key_len, pss, psl, flags TSRMLS_CC); + } else { + shift_key(buf, key_str, key_len, pss, psl, flags TSRMLS_CC); + } shift_val(buf, zvalue, vss, vsl, flags TSRMLS_CC); } } @@ -885,7 +921,7 @@ void php_http_params_separator_free(php_http_params_token_t **separator) php_http_params_token_t **sep = separator; if (sep) { while (*sep) { - STR_FREE((*sep)->str); + PTR_FREE((*sep)->str); efree(*sep); ++sep; } @@ -1180,6 +1216,7 @@ PHP_MINIT_FUNCTION(http_params) 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_RFC5987"), PHP_HTTP_PARAMS_RFC5987 TSRMLS_CC); + zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RFC5988"), PHP_HTTP_PARAMS_RFC5988 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_QUERY"), PHP_HTTP_PARAMS_QUERY TSRMLS_CC);