From ef65cb38bdb135423561726a9e19be076292318a Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Fri, 1 Dec 2006 21:09:49 +0000 Subject: Fix 1535120, 1528673 svn path=/trunk/netsurf/; revision=3087 --- utils/url.c | 36 ++++++++++++++++++++++++++++++++++++ utils/url.h | 1 + 2 files changed, 37 insertions(+) (limited to 'utils') diff --git a/utils/url.c b/utils/url.c index 1c8005a5d..f6f7fdc9d 100644 --- a/utils/url.c +++ b/utils/url.c @@ -63,6 +63,42 @@ void url_init(void) } +/** + * Check whether a host is an IP address + * + * \param host a hostname terminated by '\0' or '/' + * \return true if the hostname is an IP address, false otherwise + */ +bool url_host_is_ip_address(const char *host) { + int b; + bool n; + + assert(host); + + /* an IP address is of the format XXX.XXX.XXX.XXX, ie totally + * numeric with 3 full stops between the numbers */ + b = 0; // number of breaks + n = false; // number present + do { + if (*host == '.') { + if (!n) + return false; + b++; + n = false; + } else if ((*host == '\0') || (*host == '/')) { + if (!n) + return false; + /* todo: check the values are in 0-255 range */ + return (b == 3); + } else if (*host < '0' || *host > '9') { + return false; + } else { + n = true; + } + *host++; + } while (1); +} + /** * Normalize a URL. * diff --git a/utils/url.h b/utils/url.h index e9ad7fcb4..1467811b7 100644 --- a/utils/url.h +++ b/utils/url.h @@ -29,6 +29,7 @@ struct url_components { }; void url_init(void); +bool url_host_is_ip_address(const char *host); url_func_result url_normalize(const char *url, char **result); url_func_result url_join(const char *rel, const char *base, char **result); url_func_result url_host(const char *url, char **result); -- cgit v1.2.3