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>
|
2005-07-07 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
* gnutls.c (ssl_check_certificate): Check for the validity of the
|
* 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
|
/* 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]/dir/file -> http://www.foo.com[:port]/dir/file
|
||||||
www.foo.com[:port] -> http://www.foo.com[:port]
|
www.foo.com[:port] -> http://www.foo.com[:port]
|
||||||
@ -524,52 +525,42 @@ char *
|
|||||||
rewrite_shorthand_url (const char *url)
|
rewrite_shorthand_url (const char *url)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
char *ret;
|
||||||
|
|
||||||
if (url_scheme (url) != SCHEME_INVALID)
|
if (url_scheme (url) != SCHEME_INVALID)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Look for a ':' or '/'. The former signifies NcFTP syntax, the
|
/* Look for a ':' or '/'. The former signifies NcFTP syntax, the
|
||||||
latter Netscape. */
|
latter Netscape. */
|
||||||
for (p = url; *p && *p != ':' && *p != '/'; p++)
|
p = strpbrk (url, ":/");
|
||||||
;
|
|
||||||
|
|
||||||
if (p == url)
|
if (p == url)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* If we're looking at "://", it means the URL uses a scheme we
|
/* If we're looking at "://", it means the URL uses a scheme we
|
||||||
don't support, which may include "https" when compiled without
|
don't support, which may include "https" when compiled without
|
||||||
SSL support. Don't bogusly rewrite such URLs. */
|
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;
|
return NULL;
|
||||||
|
|
||||||
if (*p == ':')
|
if (p && *p == ':')
|
||||||
{
|
{
|
||||||
const char *pp;
|
/* Colon indicates ftp, as in foo.bar.com:path. Check for
|
||||||
char *res;
|
special case of http port number ("localhost:10000"). */
|
||||||
/* If the characters after the colon and before the next slash
|
int digits = strspn (p + 1, "0123456789");
|
||||||
or end of string are all digits, it's HTTP. */
|
if (digits && (p[1 + digits] == '/' || p[1 + digits] == '\0'))
|
||||||
int digits = 0;
|
|
||||||
for (pp = p + 1; ISDIGIT (*pp); pp++)
|
|
||||||
++digits;
|
|
||||||
if (digits > 0 && (*pp == '/' || *pp == '\0'))
|
|
||||||
goto http;
|
goto http;
|
||||||
|
|
||||||
/* Prepend "ftp://" to the entire URL... */
|
/* Turn "foo.bar.com:path" to "ftp://foo.bar.com/path". */
|
||||||
res = xmalloc (6 + strlen (url) + 1);
|
ret = aprintf ("ftp://%s", url);
|
||||||
sprintf (res, "ftp://%s", url);
|
ret[6 + (p - url)] = '/';
|
||||||
/* ...and replace ':' with '/'. */
|
|
||||||
res[6 + (p - url)] = '/';
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *res;
|
|
||||||
http:
|
http:
|
||||||
/* Just prepend "http://" to what we have. */
|
/* Just prepend "http://" to URL. */
|
||||||
res = xmalloc (7 + strlen (url) + 1);
|
ret = aprintf ("http://%s", url);
|
||||||
sprintf (res, "http://%s", url);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void split_path (const char *, char **, char **);
|
static void split_path (const char *, char **, char **);
|
||||||
|
Loading…
Reference in New Issue
Block a user