iliaa Sun Dec 4 12:44:28 2005 EDT Modified files: (Branch: PHP_5_1) /php-src/ext/standard basic_functions.c http.c php_http.h url.c url.h Log: MFH: Added 2nd optional parameter to parse_url() that allows retrieval of individual URL components. Added 3rd optional parameter to http_build_query() that allows custom param separator.
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.725.2.9&r2=1.725.2.10&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.9 php-src/ext/standard/basic_functions.c:1.725.2.10 --- php-src/ext/standard/basic_functions.c:1.725.2.9 Thu Dec 1 06:48:13 2005 +++ php-src/ext/standard/basic_functions.c Sun Dec 4 12:44:23 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.9 2005/12/01 11:48:13 dmitry Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.10 2005/12/04 17:44:23 iliaa Exp $ */ #include "php.h" #include "php_streams.h" @@ -107,8 +107,6 @@ #include "php_fopen_wrappers.h" #include "streamsfuncs.h" -static zend_class_entry *incomplete_class_entry = NULL; - static ZEND_BEGIN_ARG_INFO(first_and_second__args_force_ref, 0) ZEND_ARG_PASS_INFO(1) @@ -958,7 +956,7 @@ memset(&BG(mblen_state), 0, sizeof(BG(mblen_state))); #endif - BG(incomplete_class) = incomplete_class_entry; + BG(incomplete_class) = php_create_incomplete_class(TSRMLS_C); } @@ -1024,8 +1022,6 @@ #endif #endif - BG(incomplete_class) = incomplete_class_entry = php_create_incomplete_class(TSRMLS_C); - REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CONNECTION_NORMAL", PHP_CONNECTION_NORMAL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("CONNECTION_TIMEOUT", PHP_CONNECTION_TIMEOUT, CONST_CS | CONST_PERSISTENT); @@ -1039,6 +1035,15 @@ REGISTER_LONG_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_SCHEME", PHP_URL_SCHEME, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_HOST", PHP_URL_HOST, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_PORT", PHP_URL_PORT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_USER", PHP_URL_USER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_PASS", PHP_URL_PASS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_PATH", PHP_URL_PATH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_QUERY", PHP_URL_QUERY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_URL_FRAGMENT", PHP_URL_FRAGMENT, CONST_CS | CONST_PERSISTENT); + #define REGISTER_MATH_CONSTANT(x) REGISTER_DOUBLE_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT) REGISTER_MATH_CONSTANT(M_E); REGISTER_MATH_CONSTANT(M_LOG2E); http://cvs.php.net/diff.php/php-src/ext/standard/http.c?r1=1.14.2.1&r2=1.14.2.2&ty=u Index: php-src/ext/standard/http.c diff -u php-src/ext/standard/http.c:1.14.2.1 php-src/ext/standard/http.c:1.14.2.2 --- php-src/ext/standard/http.c:1.14.2.1 Fri Sep 16 13:10:58 2005 +++ php-src/ext/standard/http.c Sun Dec 4 12:44:27 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.14.2.1 2005/09/16 17:10:58 tony2001 Exp $ */ +/* $Id: http.c,v 1.14.2.2 2005/12/04 17:44:27 iliaa Exp $ */ #include "php_http.h" #include "php_ini.h" @@ -29,9 +29,9 @@ 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 TSRMLS_DC) + zval *type, char *arg_sep TSRMLS_DC) { - char *arg_sep = NULL, *key = NULL, *ekey, *newprefix, *p; + char *key = NULL, *ekey, *newprefix, *p; int arg_sep_len, key_len, ekey_len, key_type, newprefix_len; ulong idx; zval **zdata = NULL, *copyzval; @@ -45,9 +45,11 @@ return SUCCESS; } - arg_sep = INI_STR("arg_separator.output"); - if (!arg_sep || !strlen(arg_sep)) { - arg_sep = URL_DEFAULT_ARG_SEP; + if (!arg_sep) { + arg_sep = INI_STR("arg_separator.output"); + if (!arg_sep || !strlen(arg_sep)) { + arg_sep = URL_DEFAULT_ARG_SEP; + } } arg_sep_len = strlen(arg_sep); @@ -127,7 +129,7 @@ *p = '\0'; } ht->nApplyCount++; - php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL) TSRMLS_CC); + php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL), arg_sep TSRMLS_CC); ht->nApplyCount--; efree(newprefix); } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) { @@ -183,16 +185,17 @@ } /* }}} */ -/* {{{ proto string http_build_query(mixed formdata [, string prefix]) +/* {{{ 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; - int prefix_len = 0; + char *prefix = NULL, *arg_sep=NULL; + int arg_sep_len, prefix_len = 0; smart_str formstr = {0}; + - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &formdata, &prefix, &prefix_len) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) { RETURN_FALSE; } @@ -201,7 +204,7 @@ 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) 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 TSRMLS_CC) == FAILURE) { if (formstr.c) { efree(formstr.c); } http://cvs.php.net/diff.php/php-src/ext/standard/php_http.h?r1=1.5&r2=1.5.2.1&ty=u Index: php-src/ext/standard/php_http.h diff -u php-src/ext/standard/php_http.h:1.5 php-src/ext/standard/php_http.h:1.5.2.1 --- php-src/ext/standard/php_http.h:1.5 Wed Aug 3 10:08:10 2005 +++ php-src/ext/standard/php_http.h Sun Dec 4 12:44:27 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http.h,v 1.5 2005/08/03 14:08:10 sniper Exp $ */ +/* $Id: php_http.h,v 1.5.2.1 2005/12/04 17:44:27 iliaa Exp $ */ #ifndef PHP_HTTP_H #define PHP_HTTP_H @@ -28,7 +28,7 @@ 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 TSRMLS_DC); + zval *type, char *arg_sep TSRMLS_DC); #define php_url_encode_hash(ht, formstr) php_url_encode_hash_ex((ht), (formstr), NULL, 0, NULL, 0, NULL, 0, NULL TSRMLS_CC) PHP_FUNCTION(http_build_query); http://cvs.php.net/diff.php/php-src/ext/standard/url.c?r1=1.86.2.1&r2=1.86.2.2&ty=u Index: php-src/ext/standard/url.c diff -u php-src/ext/standard/url.c:1.86.2.1 php-src/ext/standard/url.c:1.86.2.2 --- php-src/ext/standard/url.c:1.86.2.1 Tue Aug 16 10:20:41 2005 +++ php-src/ext/standard/url.c Sun Dec 4 12:44:27 2005 @@ -15,7 +15,7 @@ | Author: Jim Winstead <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: url.c,v 1.86.2.1 2005/08/16 14:20:41 iliaa Exp $ */ +/* $Id: url.c,v 1.86.2.2 2005/12/04 17:44:27 iliaa Exp $ */ #include <stdlib.h> #include <string.h> @@ -328,15 +328,16 @@ } /* }}} */ -/* {{{ proto array parse_url(string url) +/* {{{ proto mixed parse_url(string url, [int url_component]) Parse a URL and return its components */ PHP_FUNCTION(parse_url) { char *str; int str_len; php_url *resource; + long key = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &key) == FAILURE) { return; } @@ -346,6 +347,39 @@ RETURN_FALSE; } + if (key > -1) { + switch (key) { + case PHP_URL_SCHEME: + if (resource->scheme != NULL) RETVAL_STRING(resource->scheme, 1); + break; + case PHP_URL_HOST: + if (resource->host != NULL) RETVAL_STRING(resource->host, 1); + break; + case PHP_URL_PORT: + if (resource->port != 0) RETVAL_LONG(resource->port); + break; + case PHP_URL_USER: + if (resource->user != NULL) RETVAL_STRING(resource->user, 1); + break; + case PHP_URL_PASS: + if (resource->pass != NULL) RETVAL_STRING(resource->pass, 1); + break; + case PHP_URL_PATH: + if (resource->path != NULL) RETVAL_STRING(resource->path, 1); + break; + case PHP_URL_QUERY: + if (resource->query != NULL) RETVAL_STRING(resource->query, 1); + break; + case PHP_URL_FRAGMENT: + if (resource->fragment != NULL) RETVAL_STRING(resource->fragment, 1); + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid url component identifier %ld.", key); + RETVAL_FALSE; + } + goto done; + } + /* allocate an array for return */ array_init(return_value); @@ -366,8 +400,8 @@ add_assoc_string(return_value, "query", resource->query, 1); if (resource->fragment != NULL) add_assoc_string(return_value, "fragment", resource->fragment, 1); - - php_url_free(resource); +done: + php_url_free(resource); } /* }}} */ http://cvs.php.net/diff.php/php-src/ext/standard/url.h?r1=1.20&r2=1.20.2.1&ty=u Index: php-src/ext/standard/url.h diff -u php-src/ext/standard/url.h:1.20 php-src/ext/standard/url.h:1.20.2.1 --- php-src/ext/standard/url.h:1.20 Wed Aug 3 10:08:14 2005 +++ php-src/ext/standard/url.h Sun Dec 4 12:44:27 2005 @@ -15,7 +15,7 @@ | Author: Jim Winstead <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: url.h,v 1.20 2005/08/03 14:08:14 sniper Exp $ */ +/* $Id: url.h,v 1.20.2.1 2005/12/04 17:44:27 iliaa Exp $ */ #ifndef URL_H #define URL_H @@ -46,6 +46,15 @@ PHP_FUNCTION(rawurldecode); PHP_FUNCTION(get_headers); +#define PHP_URL_SCHEME 0 +#define PHP_URL_HOST 1 +#define PHP_URL_PORT 2 +#define PHP_URL_USER 3 +#define PHP_URL_PASS 4 +#define PHP_URL_PATH 5 +#define PHP_URL_QUERY 6 +#define PHP_URL_FRAGMENT 7 + #endif /* URL_H */ /*
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php