summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2006-12-01 21:09:49 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2006-12-01 21:09:49 +0000
commitef65cb38bdb135423561726a9e19be076292318a (patch)
tree713f83e319cf276e421c5812547ee031909b9e75 /utils
parentc9d76ba242f908f7d85ee4112335d9822e410e9d (diff)
downloadnetsurf-ef65cb38bdb135423561726a9e19be076292318a.tar.gz
netsurf-ef65cb38bdb135423561726a9e19be076292318a.tar.bz2
Fix 1535120, 1528673
svn path=/trunk/netsurf/; revision=3087
Diffstat (limited to 'utils')
-rw-r--r--utils/url.c36
-rw-r--r--utils/url.h1
2 files changed, 37 insertions, 0 deletions
diff --git a/utils/url.c b/utils/url.c
index 1c8005a5d..f6f7fdc9d 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -64,6 +64,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.
*
* \param url an absolute 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);