From: hniksic Date: Sun, 18 Nov 2001 06:49:09 +0000 (-0800) Subject: [svn] Don't list all the "known" (but unsupported) protocols. Instead, just X-Git-Tag: v1.13~2066 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=303f406997f81cb92a364152768cd35bb5ec8dd5 [svn] Don't list all the "known" (but unsupported) protocols. Instead, just skip the characters until the first ':'. Published in . --- diff --git a/src/ChangeLog b/src/ChangeLog index d84c6305..7f85c6ac 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2001-05-13 Hrvoje Niksic + + * url.c: Get rid of `protostrings'. + (skip_proto): Don't use protostrings. + (has_proto): Ditto. + 2001-11-18 Hrvoje Niksic * Makefile.in: Conditionally compile getopt.o. diff --git a/src/url.c b/src/url.c index cfa09f16..582023e8 100644 --- a/src/url.c +++ b/src/url.c @@ -49,54 +49,6 @@ extern int errno; static int urlpath_length PARAMS ((const char *)); -/* A NULL-terminated list of strings to be recognized as protocol - types (URL schemes). Note that recognized doesn't mean supported - -- only HTTP, HTTPS and FTP are currently supported. - - However, a string that does not match anything in the list will be - considered a relative URL. Thus it's important that this list has - anything anyone could think of being legal. - - #### This is probably broken. Wget should use other means to - distinguish between absolute and relative URIs in HTML links. - - Take a look at - for more. */ -static char *protostrings[] = -{ - "cid:", - "clsid:", - "file:", - "finger:", - "ftp:", - "gopher:", - "hdl:", - "http:", - "https:", - "ilu:", - "ior:", - "irc:", - "java:", - "javascript:", - "lifn:", - "mailto:", - "mid:", - "news:", - "nntp:", - "path:", - "prospero:", - "rlogin:", - "service:", - "shttp:", - "snews:", - "stanf:", - "telnet:", - "tn3270:", - "wais:", - "whois++:", - NULL -}; - struct proto { char *name; @@ -104,7 +56,7 @@ struct proto unsigned short port; }; -/* Similar to former, but for supported protocols: */ +/* Supported protocols: */ static struct proto sup_protos[] = { { "http://", URLHTTP, DEFAULT_HTTP_PORT }, @@ -307,20 +259,22 @@ urlproto (const char *url) int skip_proto (const char *url) { - char **s; - int l; + const char *p = url; - for (s = protostrings; *s; s++) - if (!strncasecmp (*s, url, strlen (*s))) - break; - if (!*s) + /* Skip protocol name. We allow `-' and `+' because of `whois++', + etc. */ + while (ISALNUM (*p) || *p == '-' || *p == '+') + ++p; + if (*p != ':') return 0; - l = strlen (*s); - /* HTTP and FTP protocols are expected to yield exact host names - (i.e. the `//' part must be skipped, too). */ - if (!strcmp (*s, "http:") || !strcmp (*s, "ftp:")) - l += 2; - return l; + /* Skip ':'. */ + ++p; + + /* Skip "//" if found. */ + if (*p == '/' && *(p + 1) == '/') + p += 2; + + return p - url; } /* Returns 1 if the URL begins with a protocol (supported or @@ -328,12 +282,10 @@ skip_proto (const char *url) int has_proto (const char *url) { - char **s; - - for (s = protostrings; *s; s++) - if (strncasecmp (url, *s, strlen (*s)) == 0) - return 1; - return 0; + const char *p = url; + while (ISALNUM (*p) || *p == '-' || *p == '+') + ++p; + return *p == ':'; } /* Skip the username and password, if present here. The function