cvs: php4 /ext/standard url.c

From: Date: Fri, 17 Aug 2001 07:41:21 +0000
Subject: cvs: php4 /ext/standard url.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6910@lists.php.net to get a copy of this message
sterling Fri Aug 17 03:41:21 2001 EDT Modified files: /php4/ext/standard url.c Log: pval -> zval Z_*_P{0,2} macros easier way of doing urldecode(), from rawurldecode() (a tad faster too). Index: php4/ext/standard/url.c diff -u php4/ext/standard/url.c:1.43 php4/ext/standard/url.c:1.44 --- php4/ext/standard/url.c:1.43 Sat Aug 11 13:03:37 2001 +++ php4/ext/standard/url.c Fri Aug 17 03:41:20 2001 @@ -15,7 +15,7 @@ | Author: Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ -/* $Id: url.c,v 1.43 2001/08/11 17:03:37 zeev Exp $ */ +/* $Id: url.c,v 1.44 2001/08/17 07:41:20 sterling Exp $ */ #include <stdlib.h> #include <string.h> @@ -67,13 +67,7 @@ int err; int length = strlen(str); char *result; - - php_url *ret = (php_url *) emalloc(sizeof(php_url)); - if (!ret) { - /*php_error(E_WARNING, "Unable to allocate memory\n");*/ - return NULL; - } - memset(ret, 0, sizeof(php_url)); + php_url *ret = ecalloc(1, sizeof(php_url)); /* from Appendix B of draft-fielding-url-syntax-09, http://www.ics.uci.edu/~fielding/url/url.txt */ @@ -167,7 +161,7 @@ Parse a URL and return its components */ PHP_FUNCTION(parse_url) { - pval **str; + zval **str; php_url *resource; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { @@ -175,18 +169,16 @@ } convert_to_string_ex(str); - resource = php_url_parse((*str)->value.str.val); - + resource = php_url_parse(Z_STRVAL_PP(str)); if (resource == NULL) { - php_error(E_WARNING, "unable to parse url (%s)", (*str)->value.str.val); + php_error(E_WARNING, "unable to parse url (%s)", Z_STRVAL_PP(str)); RETURN_FALSE; } + /* allocate an array for return */ - if (array_init(return_value) == FAILURE) { - php_url_free(resource); - RETURN_FALSE; - } - /* add the various elements to the array */ + array_init(return_value); + + /* add the various elements to the array */ if (resource->scheme != NULL) add_assoc_string(return_value, "scheme", resource->scheme, 1); if (resource->host != NULL) @@ -203,7 +195,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); + + php_url_free(resource); } /* }}} */ @@ -285,7 +278,7 @@ URL-encodes string */ PHP_FUNCTION(urlencode) { - pval **arg; + zval **arg; char *str; int str_len; @@ -294,12 +287,8 @@ } convert_to_string_ex(arg); - if (!(*arg)->value.str.len) { - ZVAL_FALSE(return_value); - return; - } - str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &str_len); - RETVAL_STRINGL(str, str_len, 0); + str = php_url_encode(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &str_len); + RETURN_STRINGL(str, str_len, 0); } /* }}} */ @@ -307,7 +296,8 @@ Decodes URL-encoded string */ PHP_FUNCTION(urldecode) { - pval **arg; + zval **arg; + char *str; int len; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { @@ -315,16 +305,10 @@ } convert_to_string_ex(arg); - if (!(*arg)->value.str.len) { - ZVAL_FALSE(return_value); - return; - } + str = estrndup(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)); + len = php_url_decode(str, Z_STRLEN_PP(arg)); - *return_value = **arg; - zval_copy_ctor(return_value); - - len = php_url_decode(return_value->value.str.val, return_value->value.str.len); - return_value->value.str.len = len; + RETURN_STRINGL(str, len, 0); } /* }}} */ @@ -394,7 +378,7 @@ URL-encodes string */ PHP_FUNCTION(rawurlencode) { - pval **arg; + zval **arg; char *str; int new_len; @@ -403,11 +387,8 @@ } convert_to_string_ex(arg); - if (!(*arg)->value.str.len) { - RETURN_FALSE; - } - str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &new_len); - RETVAL_STRINGL(str, new_len, 0); + str = php_raw_url_encode(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &new_len); + RETURN_STRINGL(str, new_len, 0); } /* }}} */ @@ -415,7 +396,7 @@ Decodes URL-encodes string */ PHP_FUNCTION(rawurldecode) { - pval **arg; + zval **arg; int len; char *str; @@ -424,13 +405,10 @@ } convert_to_string_ex(arg); - if (!(*arg)->value.str.len) { - RETURN_FALSE; - } str = estrndup(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)); len = php_raw_url_decode(str, Z_STRLEN_PP(arg)); - RETVAL_STRINGL(str, len, 0); + RETURN_STRINGL(str, len, 0); } /* }}} */

« previous php.cvs (#6910) next »