From a681f3f2bb769a752093517d920d57f9df8748c7 Mon Sep 17 00:00:00 2001 From: corvid Date: Fri, 16 Sep 2011 02:01:45 +0000 Subject: put public suffix comparison directly in url.c --- src/capi.c | 9 ++------- src/cookies.c | 14 ++++---------- src/url.c | 11 ++++++++++- src/url.h | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/capi.c b/src/capi.c index a0ede65d..421a3841 100644 --- a/src/capi.c +++ b/src/capi.c @@ -385,9 +385,7 @@ static bool_t Capi_filters_test(const DilloUrl *wanted, case PREFS_FILTER_SAME_DOMAIN: { const char *req_host = URL_HOST(requester), - *want_host = URL_HOST(wanted), - *req_suffix, - *want_suffix; + *want_host = URL_HOST(wanted); if (want_host[0] == '\0') { ret = (req_host[0] == '\0' || !dStrcasecmp(URL_SCHEME(wanted), "data")) ? TRUE : FALSE; @@ -395,10 +393,7 @@ static bool_t Capi_filters_test(const DilloUrl *wanted, /* This will regard "www.dillo.org" and "www.dillo.org." as * different, but it doesn't seem worth caring about. */ - req_suffix = a_Url_host_find_public_suffix(req_host); - want_suffix = a_Url_host_find_public_suffix(want_host); - - ret = dStrcasecmp(req_suffix, want_suffix) == 0; + ret = a_Url_same_public_suffix(wanted, requester); } MSG("Capi_filters_test: %s from '%s' to '%s'\n", diff --git a/src/cookies.c b/src/cookies.c index 53ff452e..fd8e08ad 100644 --- a/src/cookies.c +++ b/src/cookies.c @@ -196,16 +196,10 @@ char *a_Cookies_get_query(const DilloUrl *query_url, const DilloUrl *requester) if (requester == NULL) { /* request made by user */ - } else { - const char *req_host = URL_HOST(requester), - *req_suffix = a_Url_host_find_public_suffix(req_host), - *query_host = URL_HOST(query_url), - *query_suffix = a_Url_host_find_public_suffix(query_host); - if (dStrcasecmp(req_suffix, query_suffix)) { - MSG("Cookies: No cookies sent for third-party request by '%s' for " - "'%s'\n", req_host, URL_STR(query_url)); - return dStrdup(""); - } + } else if (!a_Url_same_public_suffix(query_url, requester)) { + MSG("Cookies: No cookies sent for third-party request by '%s' for " + "'%s'\n", URL_HOST(requester), URL_STR(query_url)); + return dStrdup(""); } path = URL_PATH_(query_url); diff --git a/src/url.c b/src/url.c index faee044a..80be1fa6 100644 --- a/src/url.c +++ b/src/url.c @@ -718,7 +718,7 @@ static uint_t Url_host_public_internal_dots(const char *host) * domain that is in a registry outside the organization. * For 'www.dillo.org', that would be 'dillo.org'. */ -const char *a_Url_host_find_public_suffix(const char *host) +const char *Url_host_find_public_suffix(const char *host) { const char *s; uint_t dots; @@ -753,3 +753,12 @@ const char *a_Url_host_find_public_suffix(const char *host) _MSG("public suffix of %s is %s\n", host, s); return s; } + +bool_t a_Url_same_public_suffix(const DilloUrl *u1, const DilloUrl *u2) +{ + if (!u1 || !u2) + return FALSE; + + return dStrcasecmp(Url_host_find_public_suffix(URL_HOST(u1)), + Url_host_find_public_suffix(URL_HOST(u2))) ? FALSE :TRUE; +} diff --git a/src/url.h b/src/url.h index 5590c048..6d1f8816 100644 --- a/src/url.h +++ b/src/url.h @@ -122,7 +122,7 @@ void a_Url_set_ismap_coords(DilloUrl *u, char *coord_str); char *a_Url_decode_hex_str(const char *str); char *a_Url_encode_hex_str(const char *str); char *a_Url_string_strip_delimiters(const char *str); -const char *a_Url_host_find_public_suffix(const char *host); +bool_t a_Url_same_public_suffix(const DilloUrl *u1, const DilloUrl *u2); #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3