- solve that another way
authorMichael Wallner <mike@php.net>
Sun, 5 Feb 2006 08:32:58 +0000 (08:32 +0000)
committerMichael Wallner <mike@php.net>
Sun, 5 Feb 2006 08:32:58 +0000 (08:32 +0000)
KnownIssues.txt
http.c
http_functions.c
http_util_object.c
php_http.h
php_http_util_object.h
tests/build_str_001.phpt [new file with mode: 0644]

index 7fdda72..1406943 100644 (file)
@@ -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.
 
 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 
 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 (file)
--- 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_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)
        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)
        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)
        PHP_FE(ob_etaghandler, NULL)
 #ifdef HTTP_HAVE_ZLIB
        PHP_FE(http_deflate, NULL)
index 341cec2..f03398c 100644 (file)
@@ -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; \
 #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
 
 /* {{{ */
 #ifdef HTTP_HAVE_ZLIB
 
index 6bda86d..754c693 100644 (file)
@@ -29,11 +29,11 @@ HTTP_BEGIN_ARGS(date, 0)
        HTTP_ARG_VAL(timestamp, 0)
 HTTP_END_ARGS;
 
        HTTP_ARG_VAL(timestamp, 0)
 HTTP_END_ARGS;
 
-#ifndef PHP_WIN32
 HTTP_BEGIN_ARGS(buildQuery, 1)
        HTTP_ARG_VAL(query, 0)
 HTTP_BEGIN_ARGS(buildQuery, 1)
        HTTP_ARG_VAL(query, 0)
+       HTTP_ARG_VAL(prefix, 0)
+       HTTP_ARG_VAL(arg_sep, 0)
 HTTP_END_ARGS;
 HTTP_END_ARGS;
-#endif
 
 HTTP_BEGIN_ARGS(buildUrl, 1)
        HTTP_ARG_VAL(url, 0)
 
 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)
 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)
        HTTP_UTIL_ALIAS(negotiateLanguage, http_negotiate_language)
        HTTP_UTIL_ALIAS(negotiateCharset, http_negotiate_charset)
        HTTP_UTIL_ALIAS(negotiateContentType, http_negotiate_content_type)
index 3c98bd0..7e82c04 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef PHP_EXT_HTTP_H
 #define PHP_EXT_HTTP_H
 
 #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"
 
 #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_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);
 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);
 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);
 PHP_FUNCTION(ob_etaghandler);
 #ifdef HTTP_HAVE_ZLIB
 PHP_FUNCTION(http_deflate);
index 929ad6b..4c263a2 100644 (file)
@@ -23,9 +23,7 @@ extern PHP_MINIT_FUNCTION(http_util_object);
 
 PHP_METHOD(HttpUtil, date);
 PHP_METHOD(HttpUtil, buildUrl);
 
 PHP_METHOD(HttpUtil, date);
 PHP_METHOD(HttpUtil, buildUrl);
-#ifndef PHP_WIN32
 PHP_METHOD(HttpUtil, buildQuery);
 PHP_METHOD(HttpUtil, buildQuery);
-#endif
 PHP_METHOD(HttpUtil, negotiateLanguage);
 PHP_METHOD(HttpUtil, negotiateCharset);
 PHP_METHOD(HttpUtil, negotiateContentType);
 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 (file)
index 0000000..9bd0f40
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+http_build_str
+--SKIPIF--
+<?php
+include 'skip.inc';
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+parse_str($s = "a=b", $q);
+var_dump($s === http_build_str($q, null, "&"));
+
+parse_str($s = "a=b&c[0]=1", $q);
+var_dump($s === http_build_str($q, null, "&"));
+
+parse_str($s = "a=b&c[0]=1&d[e]=f", $q);
+var_dump($s === http_build_str($q, null, "&"));
+
+var_dump("foo[0]=1&foo[1]=2&foo[2][0]=3" === http_build_str(array(1,2,array(3)), "foo", "&"));
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done