diff options
author | corvid <corvid@lavabit.com> | 2011-09-16 02:01:45 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2011-09-16 02:01:45 +0000 |
commit | a681f3f2bb769a752093517d920d57f9df8748c7 (patch) | |
tree | 415ff2e01592909d1b2f049bf659274254467c19 | |
parent | 7c6c617b0d71d06294842686ea4b3ef7abe7414f (diff) |
put public suffix comparison directly in url.c
-rw-r--r-- | src/capi.c | 9 | ||||
-rw-r--r-- | src/cookies.c | 14 | ||||
-rw-r--r-- | src/url.c | 11 | ||||
-rw-r--r-- | src/url.h | 2 |
4 files changed, 17 insertions, 19 deletions
@@ -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); @@ -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; +} @@ -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 */ |