--- embedaddon/php/ext/standard/http.c 2012/02/21 23:48:02 1.1.1.1 +++ embedaddon/php/ext/standard/http.c 2014/06/15 20:03:57 1.1.1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.1.1.1 2012/02/21 23:48:02 misho Exp $ */ +/* $Id: http.c,v 1.1.1.4 2014/06/15 20:03:57 misho Exp $ */ #include "php_http.h" #include "php_ini.h" @@ -29,10 +29,12 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart const char *num_prefix, int num_prefix_len, const char *key_prefix, int key_prefix_len, const char *key_suffix, int key_suffix_len, - zval *type, char *arg_sep TSRMLS_DC) + zval *type, char *arg_sep, int enc_type TSRMLS_DC) { - char *key = NULL, *ekey, *newprefix, *p; - int arg_sep_len, key_len, ekey_len, key_type, newprefix_len; + char *key = NULL; + char *ekey, *newprefix, *p; + int arg_sep_len, ekey_len, key_type, newprefix_len; + uint key_len; ulong idx; zval **zdata = NULL, *copyzval; @@ -64,14 +66,14 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart /* handling for private & protected object properties */ if (key && *key == '\0' && type != NULL) { - char *tmp; + const char *tmp; zend_object *zobj = zend_objects_get_address(type TSRMLS_CC); if (zend_check_property_access(zobj, key, key_len-1 TSRMLS_CC) != SUCCESS) { /* private or protected property access outside of the class */ continue; } - zend_unmangle_property_name(key, key_len-1, &tmp, &key); + zend_unmangle_property_name(key, key_len-1, &tmp, (const char**)&key); key_len = strlen(key); } @@ -81,7 +83,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart } if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) { if (key_type == HASH_KEY_IS_STRING) { - ekey = php_url_encode(key, key_len, &ekey_len); + if (enc_type == PHP_QUERY_RFC3986) { + ekey = php_raw_url_encode(key, key_len, &ekey_len); + } else { + ekey = php_url_encode(key, key_len, &ekey_len); + } newprefix_len = key_suffix_len + ekey_len + key_prefix_len + 3 /* %5B */; newprefix = emalloc(newprefix_len + 1); p = newprefix; @@ -132,7 +138,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart *p = '\0'; } ht->nApplyCount++; - php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "%5D", 3, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL), arg_sep TSRMLS_CC); + php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "%5D", 3, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL), arg_sep, enc_type TSRMLS_CC); ht->nApplyCount--; efree(newprefix); } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) { @@ -145,7 +151,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart /* Simple key=value */ smart_str_appendl(formstr, key_prefix, key_prefix_len); if (key_type == HASH_KEY_IS_STRING) { - ekey = php_url_encode(key, key_len, &ekey_len); + if (enc_type == PHP_QUERY_RFC3986) { + ekey = php_raw_url_encode(key, key_len, &ekey_len); + } else { + ekey = php_url_encode(key, key_len, &ekey_len); + } smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } else { @@ -161,7 +171,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart smart_str_appendl(formstr, "=", 1); switch (Z_TYPE_PP(zdata)) { case IS_STRING: - ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); + if (enc_type == PHP_QUERY_RFC3986) { + ekey = php_raw_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); + } else { + ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); + } break; case IS_LONG: case IS_BOOL: @@ -176,7 +190,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart *copyzval = **zdata; zval_copy_ctor(copyzval); convert_to_string_ex(©zval); - ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); + if (enc_type == PHP_QUERY_RFC3986) { + ekey = php_raw_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); + } else { + ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); + } zval_ptr_dtor(©zval); } smart_str_appendl(formstr, ekey, ekey_len); @@ -188,7 +206,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart } /* }}} */ -/* {{{ proto string http_build_query(mixed formdata [, string prefix [, string arg_separator]]) +/* {{{ proto string http_build_query(mixed formdata [, string prefix [, string arg_separator [, int enc_type]]]) Generates a form-encoded query string from an associative array or object. */ PHP_FUNCTION(http_build_query) { @@ -196,9 +214,9 @@ PHP_FUNCTION(http_build_query) char *prefix = NULL, *arg_sep=NULL; int arg_sep_len = 0, prefix_len = 0; smart_str formstr = {0}; - + long enc_type = PHP_QUERY_RFC1738; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ssl", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len, &enc_type) != SUCCESS) { RETURN_FALSE; } @@ -207,7 +225,7 @@ PHP_FUNCTION(http_build_query) RETURN_FALSE; } - if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep TSRMLS_CC) == FAILURE) { + if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, enc_type TSRMLS_CC) == FAILURE) { if (formstr.c) { efree(formstr.c); }