]> granicus.if.org Git - php/commitdiff
MFH:
authorIlia Alshanetsky <iliaa@php.net>
Sun, 4 Dec 2005 17:44:27 +0000 (17:44 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 4 Dec 2005 17:44:27 +0000 (17:44 +0000)
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.

ext/standard/basic_functions.c
ext/standard/http.c
ext/standard/php_http.h
ext/standard/url.c
ext/standard/url.h

index be910cf789c29e65af1ec67870d12feec574d4dd..976d577805c5619fd4ccac6755fa3781a12e0bed 100644 (file)
@@ -107,8 +107,6 @@ php_basic_globals basic_globals;
 #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 @@ static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC)
        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 @@ PHP_MINIT_FUNCTION(basic)
 #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 @@ PHP_MINIT_FUNCTION(basic)
        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);
index afa07f13d7c253e7ef43191929a9ef6802fc6915..ae84293f857bcfb11bffbb04219d7a8892970580 100644 (file)
@@ -29,9 +29,9 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                                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 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                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 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                                *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 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
 }
 /* }}} */
 
-/* {{{ 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 @@ PHP_FUNCTION(http_build_query)
                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);
                }
index d2211916623440335366b44ff38281639002f042..a2de9dc59f1d848f2cd81124243b3f1da4e0c23e 100644 (file)
@@ -28,7 +28,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                                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);
index 6e499afe95350a7308998f6c689962316ba0c746..1e5dece138cd1809acaf6df934f50e2ed01b60d8 100644 (file)
@@ -328,15 +328,16 @@ end:
 }
 /* }}} */
 
-/* {{{ 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 @@ PHP_FUNCTION(parse_url)
                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 @@ PHP_FUNCTION(parse_url)
                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);
 }
 /* }}} */
 
index e09ecae6fd7fc06d47c235363dddd61b035c682d..ece95e0e39bf37b0d75902d480c37171f8e6648e 100644 (file)
@@ -46,6 +46,15 @@ PHP_FUNCTION(rawurlencode);
 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 */
 
 /*