http\Env::parseParams()
authorMichael Wallner <mike@php.net>
Tue, 14 Jun 2011 08:12:10 +0000 (08:12 +0000)
committerMichael Wallner <mike@php.net>
Tue, 14 Jun 2011 08:12:10 +0000 (08:12 +0000)
updated php_http_url_encode_hash*()

php_http.c
php_http_curl.c
php_http_env.c
php_http_env.h
php_http_neon.c
php_http_querystring.c
php_http_request.c
php_http_url.c
php_http_url.h

index ebe73ccae447cfc6f90a52676f36c2eddbc4f007..0b47165a3c1c319cbde7e8d42f998d1ed5a350e8 100644 (file)
@@ -119,12 +119,6 @@ zend_php_http_globals *php_http_globals(void)
 }
 #endif
 #endif
-PHP_INI_MH(http_update_persistent_handle_ident)
-{
-       PHP_HTTP_G->persistent_handle.ident.h = zend_hash_func(new_value, PHP_HTTP_G->persistent_handle.ident.l = new_value_length+1);
-       return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
-}
-
 PHP_INI_BEGIN()
        PHP_HTTP_INI_ENTRY("http.etag.mode", "md5", PHP_INI_ALL, OnUpdateString, env.etag_mode)
        PHP_HTTP_INI_ENTRY("http.request_datashare.cookie", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.cookie)
@@ -132,7 +126,6 @@ PHP_INI_BEGIN()
        PHP_HTTP_INI_ENTRY("http.request_datashare.ssl", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.ssl)
        PHP_HTTP_INI_ENTRY("http.request_datashare.connect", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.connect)
        PHP_HTTP_INI_ENTRY("http.persistent_handle.limit", "-1", PHP_INI_SYSTEM, OnUpdateLong, persistent_handle.limit)
-       PHP_HTTP_INI_ENTRY("http.persistent_handle.ident", "GLOBAL", PHP_INI_ALL, http_update_persistent_handle_ident, persistent_handle.ident.s)
 PHP_INI_END()
 
 PHP_MINIT_FUNCTION(http)
index ae8eb556872f5dd5b71452954550ac5ab69773de..377a0ea43d8398743de8bc9d0b29b6899df3f494 100644 (file)
@@ -863,7 +863,7 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
                        zval *urlenc_cookies = NULL;
                        /* check whether cookies should not be urlencoded; default is to urlencode them */
                        if ((!(urlenc_cookies = get_option(&curl->options.cache, options, ZEND_STRS("encodecookies"), IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
-                               if (SUCCESS == php_http_url_encode_hash_recursive(HASH_OF(zoption), &curl->options.cookies, "; ", lenof("; "), NULL, 0 TSRMLS_CC)) {
+                               if (SUCCESS == php_http_url_encode_hash_ex(HASH_OF(zoption), &curl->options.cookies, ZEND_STRS(";"), ZEND_STRS("="), NULL, 0 TSRMLS_CC)) {
                                        php_http_buffer_fix(&curl->options.cookies);
                                        curl_easy_setopt(ch, CURLOPT_COOKIE, curl->options.cookies.data);
                                }
index 1bd1a14e3de6bb03149d5500305961bde7574a36..4b9ea88313c701fea0c765544dbc9c6f376ea0b6 100644 (file)
@@ -593,6 +593,11 @@ PHP_HTTP_BEGIN_ARGS(persistentHandlesIdent, 0)
        PHP_HTTP_ARG_VAL(name, 0)
 PHP_HTTP_END_ARGS;
 
+PHP_HTTP_BEGIN_ARGS(parseParams, 1)
+       PHP_HTTP_ARG_VAL(params, 0)
+       PHP_HTTP_ARG_VAL(flags, 0)
+PHP_HTTP_END_ARGS;
+
 zend_function_entry php_http_env_method_entry[] = {
        PHP_HTTP_ENV_ME(getRequestHeader)
        PHP_HTTP_ENV_ME(getRequestBody)
@@ -612,6 +617,8 @@ zend_function_entry php_http_env_method_entry[] = {
        PHP_HTTP_ENV_ME(persistentHandlesStat)
        PHP_HTTP_ENV_ME(persistentHandlesClean)
 
+       PHP_HTTP_ENV_ME(parseParams)
+
        EMPTY_FUNCTION_ENTRY
 };
 
@@ -865,6 +872,23 @@ PHP_METHOD(HttpEnv, persistentHandlesClean)
        }
 }
 
+PHP_METHOD(HttpEnv, parseParams)
+{
+       char *param_str;
+       int param_len;
+       long flags = PHP_HTTP_PARAMS_DEFAULT;
+
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &param_str, &param_len, &flags)) {
+               RETURN_FALSE;
+       }
+
+       array_init(return_value);
+       if (SUCCESS != php_http_params_parse(param_str, flags, php_http_params_parse_default_func, Z_ARRVAL_P(return_value) TSRMLS_CC)) {
+               zval_dtor(return_value);
+               RETURN_FALSE;
+       }
+}
+
 zend_class_entry *php_http_env_request_class_entry;
 
 #undef PHP_HTTP_BEGIN_ARGS
@@ -897,6 +921,13 @@ PHP_METHOD(HttpEnvRequest, __construct)
 PHP_MINIT_FUNCTION(http_env)
 {
        PHP_HTTP_REGISTER_CLASS(http, Env, http_env, NULL, 0);
+
+       zend_declare_class_constant_long(php_http_env_class_entry, ZEND_STRL("PARAMS_ALLOW_COMMA"), PHP_HTTP_PARAMS_ALLOW_COMMA TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_env_class_entry, ZEND_STRL("PARAMS_ALLOW_FAILURE"), PHP_HTTP_PARAMS_ALLOW_FAILURE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_env_class_entry, ZEND_STRL("PARAMS_RAISE_ERROR"), PHP_HTTP_PARAMS_RAISE_ERROR TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_env_class_entry, ZEND_STRL("PARAMS_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_env_class_entry, ZEND_STRL("PARAMS_COLON_SEPARATOR"), PHP_HTTP_PARAMS_COLON_SEPARATOR TSRMLS_CC);
+
        PHP_HTTP_REGISTER_CLASS(http\\env, Request, http_env_request, php_http_message_class_entry, 0);
 
        return SUCCESS;
index 94fff29c28aa2395aa6fe2b75bdc445266829d56..5fb5e5b6a02f419cf730866af387e07cf16ff26c 100644 (file)
@@ -88,6 +88,7 @@ PHP_METHOD(HttpEnv, negotiateContentType);
 PHP_METHOD(HttpEnv, negotiate);
 PHP_METHOD(HttpEnv, persistentHandlesStat);
 PHP_METHOD(HttpEnv, persistentHandlesClean);
+PHP_METHOD(HttpEnv, parseParams);
 
 extern zend_class_entry *php_http_env_request_class_entry;
 extern zend_function_entry php_http_env_request_method_entry[];
index 99f7cf5bacf3f1687523b643ed47b1713e3b3311..a153f8667521b74b26f2e6bb99e51c624d141c65 100644 (file)
@@ -425,7 +425,7 @@ static STATUS set_options(php_http_request_t *h, HashTable *options)
 
                        /* check whether cookies should not be urlencoded; default is to urlencode them */
                        if ((!(urlenc_cookies = get_option(&neon->options.cache, options, ZEND_STRS("encodecookies"), IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
-                               php_http_url_encode_hash_recursive(HASH_OF(zoption), &neon->options.headers, "; ", lenof("; "), NULL, 0 TSRMLS_CC);
+                               php_http_url_encode_hash_ex(HASH_OF(zoption), &neon->options.headers, ZEND_STRS("; "), ZEND_STRS("="), NULL, 0 TSRMLS_CC);
                        } else {
                                HashPosition pos;
                                php_http_array_hashkey_t cookie_key = php_http_array_hashkey_init(0);
index de40a23f3944473cfee1cfcb99d6f814a6e62ca1..5f6748263349951d6155ed5daee7634f173ce082 100644 (file)
@@ -181,7 +181,7 @@ PHP_HTTP_API STATUS php_http_querystring_update(zval *qarray, zval *params, zval
                char *s;
                size_t l;
 
-               if (SUCCESS == php_http_url_encode_hash(Z_ARRVAL_P(qarray), 0, NULL, 0, &s, &l TSRMLS_CC)) {
+               if (SUCCESS == php_http_url_encode_hash(Z_ARRVAL_P(qarray), NULL, 0, &s, &l TSRMLS_CC)) {
                        zval_dtor(outstring);
                        ZVAL_STRINGL(outstring, s, l, 0);
                } else {
index 08128282a2f30b98d81616fe9fa522d8fd347e3c..b0df03146b1e663eb9f19959df34f39faa51a92c 100644 (file)
@@ -978,7 +978,7 @@ PHP_METHOD(HttpRequest, setQueryData)
                        char *query_data_str = NULL;
                        size_t query_data_len;
 
-                       if (SUCCESS == php_http_url_encode_hash(HASH_OF(qdata), 0, NULL, 0, &query_data_str, &query_data_len TSRMLS_CC)) {
+                       if (SUCCESS == php_http_url_encode_hash(HASH_OF(qdata), NULL, 0, &query_data_str, &query_data_len TSRMLS_CC)) {
                                zend_update_property_stringl(php_http_request_class_entry, getThis(), ZEND_STRL("queryData"), query_data_str, query_data_len TSRMLS_CC);
                                efree(query_data_str);
                        }
@@ -1009,7 +1009,7 @@ PHP_METHOD(HttpRequest, addQueryData)
                size_t query_data_len = 0;
                zval *old_qdata = zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("queryData"), 0 TSRMLS_CC);
 
-               if (SUCCESS == php_http_url_encode_hash(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data_str, &query_data_len TSRMLS_CC)) {
+               if (SUCCESS == php_http_url_encode_hash(HASH_OF(qdata), Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data_str, &query_data_len TSRMLS_CC)) {
                        zend_update_property_stringl(php_http_request_class_entry, getThis(), ZEND_STRL("queryData"), query_data_str, query_data_len TSRMLS_CC);
                        efree(query_data_str);
                }
index 79966b601774dc81a4ffdeffa1f0684c572e9a1d..58250234751bb2c15bd481313dc5df8856c0ba0d 100644 (file)
@@ -325,33 +325,30 @@ PHP_HTTP_API void php_http_url(int flags, const php_url *old_url, const php_url
        }
 }
 
-PHP_HTTP_API STATUS php_http_url_encode_hash(HashTable *hash, zend_bool override_argsep,       char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len TSRMLS_DC)
 {
-       char *arg_sep;
+       const char *arg_sep_str;
        size_t arg_sep_len;
        php_http_buffer_t *qstr = php_http_buffer_new();
 
-       if (override_argsep || !(arg_sep_len = strlen(arg_sep = INI_STR("arg_separator.output")))) {
-               arg_sep = PHP_HTTP_URL_ARGSEP;
-               arg_sep_len = lenof(PHP_HTTP_URL_ARGSEP);
-       }
+       php_http_url_argsep(&arg_sep_str, &arg_sep_len TSRMLS_CC);
 
-       if (pre_encoded_len && pre_encoded_data) {
-               php_http_buffer_append(qstr, pre_encoded_data, pre_encoded_len);
+       if (pre_encoded_len && pre_encoded_str) {
+               php_http_buffer_append(qstr, pre_encoded_str, pre_encoded_len);
        }
 
-       if (SUCCESS != php_http_url_encode_hash_recursive(hash, qstr, arg_sep, arg_sep_len, NULL, 0 TSRMLS_CC)) {
+       if (SUCCESS != php_http_url_encode_hash_ex(hash, qstr, arg_sep_str, arg_sep_len, ZEND_STRS("="), NULL, 0 TSRMLS_CC)) {
                php_http_buffer_free(&qstr);
                return FAILURE;
        }
 
-       php_http_buffer_data(qstr, encoded_data, encoded_len);
+       php_http_buffer_data(qstr, encoded_str, encoded_len);
        php_http_buffer_free(&qstr);
 
        return SUCCESS;
 }
 
-PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_buffer_t *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC)
+PHP_HTTP_API STATUS php_http_url_encode_hash_ex(HashTable *ht, php_http_buffer_t *str, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *prefix_str, size_t prefix_len TSRMLS_DC)
 {
        php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
        zval **data = NULL;
@@ -390,15 +387,15 @@ PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_b
                
                {
                        php_http_buffer_init(&new_prefix);
-                       if (prefix && prefix_len) {
-                               php_http_buffer_append(&new_prefix, prefix, prefix_len);
+                       if (prefix_str && prefix_len) {
+                               php_http_buffer_append(&new_prefix, prefix_str, prefix_len);
                                php_http_buffer_appends(&new_prefix, "%5B");
                        }
                        
                        php_http_buffer_append(&new_prefix, encoded_key, encoded_len);
                        efree(encoded_key);
                        
-                       if (prefix && prefix_len) {
+                       if (prefix_str && prefix_len) {
                                php_http_buffer_appends(&new_prefix, "%5D");
                        }
                        php_http_buffer_fix(&new_prefix);
@@ -407,7 +404,7 @@ PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_b
                if (Z_TYPE_PP(data) == IS_ARRAY || Z_TYPE_PP(data) == IS_OBJECT) {
                        STATUS status;
                        ++ht->nApplyCount;
-                       status = php_http_url_encode_hash_recursive(HASH_OF(*data), str, arg_sep, arg_sep_len, PHP_HTTP_BUFFER_VAL(&new_prefix), PHP_HTTP_BUFFER_LEN(&new_prefix) TSRMLS_CC);
+                       status = php_http_url_encode_hash_ex(HASH_OF(*data), str, arg_sep_str, arg_sep_len, val_sep_str, val_sep_len, PHP_HTTP_BUFFER_VAL(&new_prefix), PHP_HTTP_BUFFER_LEN(&new_prefix) TSRMLS_CC);
                        --ht->nApplyCount;
                        if (SUCCESS != status) {
                                php_http_buffer_dtor(&new_prefix);
@@ -418,10 +415,10 @@ PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_b
                        zval *val = php_http_ztyp(IS_STRING, *data);
                        
                        if (PHP_HTTP_BUFFER_LEN(str)) {
-                               php_http_buffer_append(str, arg_sep, arg_sep_len);
+                               php_http_buffer_append(str, arg_sep_str, arg_sep_len);
                        }
                        php_http_buffer_append(str, PHP_HTTP_BUFFER_VAL(&new_prefix), PHP_HTTP_BUFFER_LEN(&new_prefix));
-                       php_http_buffer_appends(str, "=");
+                       php_http_buffer_append(str, val_sep_str, val_sep_len);
                        
                        if (Z_STRLEN_P(val) && Z_STRVAL_P(val)) {
                                char *encoded_val;
index 7b16c0119f17e723fd5f1cd6087d9fe0ae9e4b52..23f529dfa3ddc91caceb69d52839aee46d49bdfd 100644 (file)
 PHP_HTTP_API void php_http_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC);
 PHP_HTTP_API char *php_http_url_absolute(const char *url, int flags TSRMLS_DC);
 
-PHP_HTTP_API STATUS php_http_url_encode_hash(HashTable *hash, zend_bool override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
-PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_buffer_t *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC);
+PHP_HTTP_API STATUS php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len TSRMLS_DC);
+PHP_HTTP_API STATUS php_http_url_encode_hash_ex(HashTable *ht, php_http_buffer_t *str, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *prefix_str, size_t prefix_len TSRMLS_DC);
+
+static inline void php_http_url_argsep(const char **str, size_t *len TSRMLS_DC)
+{
+       *str = INI_STR("arg_separator.output");
+       *len = strlen(*str);
+
+       if (!*len) {
+               *str = PHP_HTTP_URL_ARGSEP;
+               *len = lenof(PHP_HTTP_URL_ARGSEP);
+       }
+}
 
 static inline php_url *php_http_url_from_struct(php_url *url, HashTable *ht TSRMLS_DC)
 {