X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_functions.c;h=f03398c4100ebfd242bbe48f34ec0d97c3455dba;hp=d9acab978d3e21568fac7179f2fe5a48282436c2;hb=98e0618077ab00672dd0e6e134d4722e033d827e;hpb=4fcbd8e8ae31611c5197ff2369673b5939fc2b80 diff --git a/http_functions.c b/http_functions.c index d9acab9..f03398c 100644 --- a/http_functions.c +++ b/http_functions.c @@ -41,8 +41,8 @@ * Compose a valid HTTP date regarding RFC 822/1123 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT" * - * Takes an optional unix timestamp as parameter. - * + * Accepts an optional unix timestamp as parameter. + * * Returns the HTTP date as string. */ PHP_FUNCTION(http_date) @@ -61,7 +61,7 @@ PHP_FUNCTION(http_date) } /* }}} */ -/* {{{ proto string http_build_url(mixed url[, mixed parts[, array &new_url]]) +/* {{{ proto string http_build_url(mixed url[, mixed parts[, int flags = HTTP_URL_REPLACE[, array &new_url]]]) * * Returns the new URL as string on success or FALSE on failure. */ @@ -69,10 +69,11 @@ PHP_FUNCTION(http_build_url) { char *url_str = NULL; size_t url_len = 0; + long flags = HTTP_URL_REPLACE; zval *z_old_url = NULL, *z_new_url = NULL, *z_composed_url = NULL; php_url *old_url = NULL, *new_url = NULL, *composed_url = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/|z/z", &z_old_url, &z_new_url, &z_composed_url) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/|z/lz", &z_old_url, &z_new_url, &flags, &z_composed_url) != SUCCESS) { RETURN_FALSE; } @@ -102,7 +103,7 @@ PHP_FUNCTION(http_build_url) } if (z_composed_url) { - http_build_url(old_url, new_url, &composed_url, &url_str, &url_len); + http_build_url(flags, old_url, new_url, &composed_url, &url_str, &url_len); zval_dtor(z_composed_url); array_init(z_composed_url); @@ -132,7 +133,7 @@ PHP_FUNCTION(http_build_url) } php_url_free(composed_url); } else { - http_build_url(old_url, new_url, NULL, &url_str, &url_len); + http_build_url(flags, old_url, new_url, NULL, &url_str, &url_len); } if (new_url) { @@ -144,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; \ @@ -1562,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