mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Simplify rewrite_shorthand_url.
This commit is contained in:
parent
87bcfdb7de
commit
1fa77ff5b1
@ -1,3 +1,8 @@
|
||||
2005-07-08 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* url.c (rewrite_shorthand_url): Simplify code using aprintf and
|
||||
strspn.
|
||||
|
||||
2005-07-07 Hrvoje Niksic <hniksic@xemacs.org>
|
||||
|
||||
* gnutls.c (ssl_check_certificate): Check for the validity of the
|
||||
|
41
src/url.c
41
src/url.c
@ -508,7 +508,8 @@ parse_credentials (const char *beg, const char *end, char **user, char **passwd)
|
||||
}
|
||||
|
||||
/* Used by main.c: detect URLs written using the "shorthand" URL forms
|
||||
popularized by Netscape and NcFTP. HTTP shorthands look like this:
|
||||
originally popularized by Netscape and NcFTP. HTTP shorthands look
|
||||
like this:
|
||||
|
||||
www.foo.com[:port]/dir/file -> http://www.foo.com[:port]/dir/file
|
||||
www.foo.com[:port] -> http://www.foo.com[:port]
|
||||
@ -524,52 +525,42 @@ char *
|
||||
rewrite_shorthand_url (const char *url)
|
||||
{
|
||||
const char *p;
|
||||
char *ret;
|
||||
|
||||
if (url_scheme (url) != SCHEME_INVALID)
|
||||
return NULL;
|
||||
|
||||
/* Look for a ':' or '/'. The former signifies NcFTP syntax, the
|
||||
latter Netscape. */
|
||||
for (p = url; *p && *p != ':' && *p != '/'; p++)
|
||||
;
|
||||
|
||||
p = strpbrk (url, ":/");
|
||||
if (p == url)
|
||||
return NULL;
|
||||
|
||||
/* If we're looking at "://", it means the URL uses a scheme we
|
||||
don't support, which may include "https" when compiled without
|
||||
SSL support. Don't bogusly rewrite such URLs. */
|
||||
if (p[0] == ':' && p[1] == '/' && p[2] == '/')
|
||||
if (p && p[0] == ':' && p[1] == '/' && p[2] == '/')
|
||||
return NULL;
|
||||
|
||||
if (*p == ':')
|
||||
if (p && *p == ':')
|
||||
{
|
||||
const char *pp;
|
||||
char *res;
|
||||
/* If the characters after the colon and before the next slash
|
||||
or end of string are all digits, it's HTTP. */
|
||||
int digits = 0;
|
||||
for (pp = p + 1; ISDIGIT (*pp); pp++)
|
||||
++digits;
|
||||
if (digits > 0 && (*pp == '/' || *pp == '\0'))
|
||||
/* Colon indicates ftp, as in foo.bar.com:path. Check for
|
||||
special case of http port number ("localhost:10000"). */
|
||||
int digits = strspn (p + 1, "0123456789");
|
||||
if (digits && (p[1 + digits] == '/' || p[1 + digits] == '\0'))
|
||||
goto http;
|
||||
|
||||
/* Prepend "ftp://" to the entire URL... */
|
||||
res = xmalloc (6 + strlen (url) + 1);
|
||||
sprintf (res, "ftp://%s", url);
|
||||
/* ...and replace ':' with '/'. */
|
||||
res[6 + (p - url)] = '/';
|
||||
return res;
|
||||
/* Turn "foo.bar.com:path" to "ftp://foo.bar.com/path". */
|
||||
ret = aprintf ("ftp://%s", url);
|
||||
ret[6 + (p - url)] = '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
char *res;
|
||||
http:
|
||||
/* Just prepend "http://" to what we have. */
|
||||
res = xmalloc (7 + strlen (url) + 1);
|
||||
sprintf (res, "http://%s", url);
|
||||
return res;
|
||||
/* Just prepend "http://" to URL. */
|
||||
ret = aprintf ("http://%s", url);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void split_path (const char *, char **, char **);
|
||||
|
Loading…
Reference in New Issue
Block a user