]> granicus.if.org Git - php/commitdiff
Parsing of URLs with literal IPv6 addresses, see RFC 2732
authorStig Venaas <venaas@php.net>
Fri, 22 Sep 2000 00:12:00 +0000 (00:12 +0000)
committerStig Venaas <venaas@php.net>
Fri, 22 Sep 2000 00:12:00 +0000 (00:12 +0000)
@- IPv6 support in fopen (one can access IPv6 ftp/web servers) (Stig Venaas)

ext/standard/url.c

index ab12801d30c2d30211357d5284547a48a4dab0a6..004956081c3a328bd2283649278ec9d709511037 100644 (file)
@@ -116,8 +116,8 @@ php_url *url_parse(char *str)
 
                regfree(&re);                   /* free the old regex */
                
-               if ((cerr=regcomp(&re, "^(([^@:]+)(:([^@:]+))?@)?([^:@]+)(:([^:@]+))?", REG_EXTENDED))
-                       || (err=regexec(&re, result, 10, subs, 0))) {
+               if ((cerr=regcomp(&re, "^(([^@:]+)(:([^@:]+))?@)?((\\[(.*)\\])|([^:@]+))(:([^:@]+))?", REG_EXTENDED))
+                       || (err=regexec(&re, result, 11, subs, 0))) {
                        STR_FREE(ret->scheme);
                        STR_FREE(ret->path);
                        STR_FREE(ret->query);
@@ -135,11 +135,13 @@ php_url *url_parse(char *str)
                if (subs[4].rm_so != -1 && subs[4].rm_so < length) {
                        ret->pass = estrndup(result + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
                }
-               if (subs[5].rm_so != -1 && subs[5].rm_so < length) {
-                       ret->host = estrndup(result + subs[5].rm_so, subs[5].rm_eo - subs[5].rm_so);
-               }
                if (subs[7].rm_so != -1 && subs[7].rm_so < length) {
-                       ret->port = (unsigned short) strtol(result + subs[7].rm_so, NULL, 10);
+                       ret->host = estrndup(result + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so);
+               } else if (subs[8].rm_so != -1 && subs[8].rm_so < length) {
+                       ret->host = estrndup(result + subs[8].rm_so, subs[8].rm_eo - subs[8].rm_so);
+               }
+               if (subs[10].rm_so != -1 && subs[10].rm_so < length) {
+                       ret->port = (unsigned short) strtol(result + subs[10].rm_so, NULL, 10);
                }
                efree(result);
        }