From 9e9341f5b9a1707dd897596e8e410b66fcdb61aa Mon Sep 17 00:00:00 2001 From: Claudio Saavedra Date: Wed, 21 Feb 2018 16:20:36 +0200 Subject: [PATCH] psl_is_public_suffix2(): allow checking for suffixes not in the list Add a PSL_TYPE_NO_STAR_RULE type to check for suffixes without the '*' rule. This allows checking for suffixes that are not in the PSL. --- docs/libpsl/libpsl-sections.txt | 1 + include/libpsl.h.in | 7 ++++--- src/psl.c | 10 ++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/libpsl/libpsl-sections.txt b/docs/libpsl/libpsl-sections.txt index 0711930..c858051 100644 --- a/docs/libpsl/libpsl-sections.txt +++ b/docs/libpsl/libpsl-sections.txt @@ -8,6 +8,7 @@ PSL_VERSION_NUMBER PSL_VERSION_PATCH PSL_TYPE_ICANN PSL_TYPE_PRIVATE +PSL_TYPE_NO_STAR_RULE PSL_TYPE_ANY psl_error_t psl_ctx_t diff --git a/include/libpsl.h.in b/include/libpsl.h.in index bd2dfc0..8ddcfe3 100644 --- a/include/libpsl.h.in +++ b/include/libpsl.h.in @@ -45,9 +45,10 @@ extern "C" { #endif /* types for psl_is_public_suffix2() */ -#define PSL_TYPE_ICANN (1<<0) -#define PSL_TYPE_PRIVATE (1<<1) -#define PSL_TYPE_ANY (PSL_TYPE_ICANN | PSL_TYPE_PRIVATE) +#define PSL_TYPE_ICANN (1<<0) +#define PSL_TYPE_PRIVATE (1<<1) +#define PSL_TYPE_NO_STAR_RULE (1<<2) +#define PSL_TYPE_ANY (PSL_TYPE_ICANN | PSL_TYPE_PRIVATE) /** * psl_error_t: diff --git a/src/psl.c b/src/psl.c index 10d472d..52df98b 100644 --- a/src/psl.c +++ b/src/psl.c @@ -839,10 +839,12 @@ static int _psl_is_public_suffix(const psl_ctx_t *psl, const char *domain, int t } if (suffix.nlabels == 1) { - /* TLD, this is the prevailing '*' match. - * We don't currently support exception TLDs (TLDs that are not a public suffix) + /* TLD, this is the prevailing '*' match. If type excludes the '*' rule, continue. */ - return 1; + if (type & PSL_TYPE_NO_STAR_RULE) + type &= ~PSL_TYPE_NO_STAR_RULE; + else + return 1; } if (psl->utf8 || psl == &_builtin_psl) @@ -1002,7 +1004,7 @@ int psl_is_public_suffix(const psl_ctx_t *psl, const char *domain) * [Mozilla Public Suffix List](https://publicsuffix.org). * * @type specifies the PSL section where to perform the lookup. Valid values are - * %PSL_TYPE_PRIVATE, %PSL_TYPE_ICANN and %PSL_TYPE_ANY. + * %PSL_TYPE_PRIVATE, %PSL_TYPE_ICANN, %PSL_TYPE_NO_STAR_RULE, and %PSL_TYPE_ANY. * * International @domain names have to be either in UTF-8 (lowercase + NFKC) or in ASCII/ACE format (punycode). * Other encodings likely result in incorrect return values.