From 98e0618077ab00672dd0e6e134d4722e033d827e Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sun, 5 Feb 2006 08:32:58 +0000 Subject: [PATCH] - solve that another way --- KnownIssues.txt | 3 -- http.c | 7 ++-- http_functions.c | 72 +++++++++++++++++++--------------------- http_util_object.c | 8 ++--- php_http.h | 6 ++-- php_http_util_object.h | 2 -- tests/build_str_001.phpt | 30 +++++++++++++++++ 7 files changed, 73 insertions(+), 55 deletions(-) create mode 100644 tests/build_str_001.phpt diff --git a/KnownIssues.txt b/KnownIssues.txt index 7fdda72..1406943 100644 --- a/KnownIssues.txt +++ b/KnownIssues.txt @@ -18,9 +18,6 @@ generate any compressed data (gzip, deflate AKA zlib and raw deflate); just use the flag for the data format you want to generate: HTTP_DEFLATE_TYPE_GZIP, HTTP_DEFLATE_TYPE_ZLIB or HTTP_DEFLATE_TYPE_RAW. -Windows: - There's no HttpUtil alias for http_build_query() due to missing export. - Internals: - there's a memleak with sizeof(zval) for each thrown exception, which ends up in HttpRequestPoolExcepiont::$exceptionStack, in diff --git a/http.c b/http.c index 41456dc..bbbb03a 100644 --- a/http.c +++ b/http.c @@ -67,6 +67,10 @@ zend_function_entry http_functions[] = { PHP_FE(http_test, NULL) PHP_FE(http_date, NULL) PHP_FE(http_build_url, http_arg_pass_ref_4) + PHP_FE(http_build_str, NULL) +#ifndef ZEND_ENGINE_2 + PHP_FALIAS(http_build_query, http_build_str) +#endif PHP_FE(http_negotiate_language, http_arg_pass_ref_2) PHP_FE(http_negotiate_charset, http_arg_pass_ref_2) PHP_FE(http_negotiate_content_type, http_arg_pass_ref_2) @@ -103,9 +107,6 @@ zend_function_entry http_functions[] = { PHP_FE(http_request_method_unregister, NULL) PHP_FE(http_request_method_exists, NULL) PHP_FE(http_request_method_name, NULL) -#ifndef ZEND_ENGINE_2 - PHP_FE(http_build_query, NULL) -#endif PHP_FE(ob_etaghandler, NULL) #ifdef HTTP_HAVE_ZLIB PHP_FE(http_deflate, NULL) diff --git a/http_functions.c b/http_functions.c index 341cec2..f03398c 100644 --- a/http_functions.c +++ b/http_functions.c @@ -145,6 +145,40 @@ PHP_FUNCTION(http_build_url) } /* }}} */ +/* {{{ proto string http_build_str(array query [, string prefix[, string arg_separator]]) + * + * Opponent to parse_str(). + */ +PHP_FUNCTION(http_build_str) +{ + zval *formdata; + char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output"); + int prefix_len = 0, arg_sep_len = strlen(arg_sep); + phpstr formstr; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) { + RETURN_FALSE; + } + + if (!arg_sep_len) { + arg_sep = HTTP_URL_ARGSEP; + arg_sep_len = lenof(HTTP_URL_ARGSEP); + } + + phpstr_init(&formstr); + if (SUCCESS != http_urlencode_hash_recursive(HASH_OF(formdata), &formstr, arg_sep, arg_sep_len, prefix, prefix_len)) { + RETURN_FALSE; + } + + if (!formstr.used) { + phpstr_dtor(&formstr); + RETURN_NULL(); + } + + RETURN_PHPSTR_VAL(&formstr); +} +/* }}} */ + #define HTTP_DO_NEGOTIATE(type, supported, rs_array) \ { \ HashTable *result; \ @@ -1563,44 +1597,6 @@ PHP_FUNCTION(http_request_method_name) } /* }}} */ -/* {{{ Sara Golemons http_build_query() */ -#ifndef ZEND_ENGINE_2 - -/* {{{ proto string http_build_query(mixed formdata [, string prefix[, string arg_separator]]) - Generates a form-encoded query string from an associative array or object. */ -PHP_FUNCTION(http_build_query) -{ - zval *formdata; - char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output"); - int prefix_len = 0, arg_sep_len = strlen(arg_sep); - phpstr *formstr; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) { - RETURN_FALSE; - } - - if (!arg_sep_len) { - arg_sep = HTTP_URL_ARGSEP; - arg_sep_len = lenof(HTTP_URL_ARGSEP); - } - - formstr = phpstr_new(); - if (SUCCESS != http_urlencode_hash_recursive(HASH_OF(formdata), formstr, arg_sep, arg_sep_len, prefix, prefix_len)) { - phpstr_free(&formstr); - RETURN_FALSE; - } - - if (!formstr->used) { - phpstr_free(&formstr); - RETURN_NULL(); - } - - RETURN_PHPSTR_PTR(formstr); -} -/* }}} */ -#endif /* !ZEND_ENGINE_2 */ -/* }}} */ - /* {{{ */ #ifdef HTTP_HAVE_ZLIB diff --git a/http_util_object.c b/http_util_object.c index 6bda86d..754c693 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -29,11 +29,11 @@ HTTP_BEGIN_ARGS(date, 0) HTTP_ARG_VAL(timestamp, 0) HTTP_END_ARGS; -#ifndef PHP_WIN32 HTTP_BEGIN_ARGS(buildQuery, 1) HTTP_ARG_VAL(query, 0) + HTTP_ARG_VAL(prefix, 0) + HTTP_ARG_VAL(arg_sep, 0) HTTP_END_ARGS; -#endif HTTP_BEGIN_ARGS(buildUrl, 1) HTTP_ARG_VAL(url, 0) @@ -106,9 +106,7 @@ zend_class_entry *http_util_object_ce; zend_function_entry http_util_object_fe[] = { HTTP_UTIL_ALIAS(date, http_date) HTTP_UTIL_ALIAS(buildUrl, http_build_url) -#ifndef PHP_WIN32 - HTTP_UTIL_ALIAS(buildQuery, http_build_query) -#endif + HTTP_UTIL_ALIAS(buildQuery, http_build_str) HTTP_UTIL_ALIAS(negotiateLanguage, http_negotiate_language) HTTP_UTIL_ALIAS(negotiateCharset, http_negotiate_charset) HTTP_UTIL_ALIAS(negotiateContentType, http_negotiate_content_type) diff --git a/php_http.h b/php_http.h index 3c98bd0..7e82c04 100644 --- a/php_http.h +++ b/php_http.h @@ -15,7 +15,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_EXT_HTTP_VERSION "0.22.0" +#define PHP_EXT_HTTP_VERSION "0.23.0dev" #ifdef HAVE_CONFIG_H # include "config.h" @@ -147,6 +147,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http); PHP_FUNCTION(http_test); PHP_FUNCTION(http_date); PHP_FUNCTION(http_build_url); +PHP_FUNCTION(http_build_str); PHP_FUNCTION(http_negotiate_language); PHP_FUNCTION(http_negotiate_charset); PHP_FUNCTION(http_negotiate_content_type); @@ -183,9 +184,6 @@ PHP_FUNCTION(http_request_method_register); PHP_FUNCTION(http_request_method_unregister); PHP_FUNCTION(http_request_method_exists); PHP_FUNCTION(http_request_method_name); -#ifndef ZEND_ENGINE_2 -PHP_FUNCTION(http_build_query); -#endif /* ZEND_ENGINE_2 */ PHP_FUNCTION(ob_etaghandler); #ifdef HTTP_HAVE_ZLIB PHP_FUNCTION(http_deflate); diff --git a/php_http_util_object.h b/php_http_util_object.h index 929ad6b..4c263a2 100644 --- a/php_http_util_object.h +++ b/php_http_util_object.h @@ -23,9 +23,7 @@ extern PHP_MINIT_FUNCTION(http_util_object); PHP_METHOD(HttpUtil, date); PHP_METHOD(HttpUtil, buildUrl); -#ifndef PHP_WIN32 PHP_METHOD(HttpUtil, buildQuery); -#endif PHP_METHOD(HttpUtil, negotiateLanguage); PHP_METHOD(HttpUtil, negotiateCharset); PHP_METHOD(HttpUtil, negotiateContentType); diff --git a/tests/build_str_001.phpt b/tests/build_str_001.phpt new file mode 100644 index 0000000..9bd0f40 --- /dev/null +++ b/tests/build_str_001.phpt @@ -0,0 +1,30 @@ +--TEST-- +http_build_str +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +%sTEST +bool(true) +bool(true) +bool(true) +bool(true) +Done -- 2.30.2