summaryrefslogtreecommitdiff
path: root/utils/url.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2006-07-02 22:34:04 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2006-07-02 22:34:04 +0000
commitb7af14b591707b28d9d99c77a7d5579e4d176c2a (patch)
treedb2011592881356bff3493a3040fc246285b81ee /utils/url.c
parent71287140cac2bd231638bf1580bd75b5c42dfd32 (diff)
downloadnetsurf-b7af14b591707b28d9d99c77a7d5579e4d176c2a.tar.gz
netsurf-b7af14b591707b28d9d99c77a7d5579e4d176c2a.tar.bz2
Implement component-wise URL comparison
svn path=/trunk/netsurf/; revision=2697
Diffstat (limited to 'utils/url.c')
-rw-r--r--utils/url.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/utils/url.c b/utils/url.c
index 7d8b1673d..26c3295ab 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -823,6 +823,72 @@ url_func_result url_escape(const char *unescaped, char **result)
return URL_FUNC_OK;
}
+/**
+ * Compare two absolute, normalized URLs
+ *
+ * \param url1 URL 1
+ * \param url2 URL 2
+ * \param result Pointer to location to store result (true if URLs match)
+ * \return URL_FUNC_OK on success
+ */
+url_func_result url_compare(const char *url1, const char *url2, bool *result)
+{
+ url_func_result status;
+ struct url_components c1, c2;
+ bool res = true;
+
+ assert(url1 && url2 && result);
+
+ /* Decompose URLs */
+ status = url_get_components(url1, &c1, false);
+ if (status != URL_FUNC_OK) {
+ url_destroy_components(&c1);
+ return status;
+ }
+
+ status = url_get_components(url2, &c2, false);
+ if (status != URL_FUNC_OK) {
+ url_destroy_components(&c2);
+ url_destroy_components(&c1);
+ return status;
+ }
+
+ if (((c1.scheme && c2.scheme) || (!c1.scheme && !c2.scheme )) &&
+ ((c1.authority && c2.authority) ||
+ (!c1.authority && !c2.authority)) &&
+ ((c1.path && c2.path) || (!c1.path && !c2.path)) &&
+ ((c1.query && c2.query) ||
+ (!c1.query && !c2.query)) &&
+ ((c1.fragment && c2.fragment) ||
+ (!c1.fragment && !c2.fragment))) {
+
+ if (c1.scheme)
+ res &= strcasecmp(c1.scheme, c2.scheme) == 0;
+
+ /** \todo consider each part of the authority separately */
+ if (c1.authority)
+ res &= strcasecmp(c1.authority, c2.authority) == 0;
+
+ if (c1.path)
+ res &= strcmp(c1.path, c2.path) == 0;
+
+ if (c1.query)
+ res &= strcmp(c1.query, c2.query) == 0;
+
+ if (c1.fragment)
+ res &= strcmp(c1.fragment, c2.fragment) == 0;
+ } else {
+ /* Can't match */
+ res = false;
+ }
+
+ *result = res;
+
+ url_destroy_components(&c2);
+ url_destroy_components(&c1);
+
+ return URL_FUNC_OK;
+}
/**
* Split a URL into separate components