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.
This commit is contained in:
Claudio Saavedra 2018-02-21 16:20:36 +02:00
parent 819486edd1
commit 9e9341f5b9
3 changed files with 11 additions and 7 deletions

View File

@ -8,6 +8,7 @@ PSL_VERSION_NUMBER
PSL_VERSION_PATCH PSL_VERSION_PATCH
PSL_TYPE_ICANN PSL_TYPE_ICANN
PSL_TYPE_PRIVATE PSL_TYPE_PRIVATE
PSL_TYPE_NO_STAR_RULE
PSL_TYPE_ANY PSL_TYPE_ANY
psl_error_t psl_error_t
psl_ctx_t psl_ctx_t

View File

@ -47,6 +47,7 @@ extern "C" {
/* types for psl_is_public_suffix2() */ /* types for psl_is_public_suffix2() */
#define PSL_TYPE_ICANN (1<<0) #define PSL_TYPE_ICANN (1<<0)
#define PSL_TYPE_PRIVATE (1<<1) #define PSL_TYPE_PRIVATE (1<<1)
#define PSL_TYPE_NO_STAR_RULE (1<<2)
#define PSL_TYPE_ANY (PSL_TYPE_ICANN | PSL_TYPE_PRIVATE) #define PSL_TYPE_ANY (PSL_TYPE_ICANN | PSL_TYPE_PRIVATE)
/** /**

View File

@ -839,9 +839,11 @@ static int _psl_is_public_suffix(const psl_ctx_t *psl, const char *domain, int t
} }
if (suffix.nlabels == 1) { if (suffix.nlabels == 1) {
/* TLD, this is the prevailing '*' match. /* TLD, this is the prevailing '*' match. If type excludes the '*' rule, continue.
* We don't currently support exception TLDs (TLDs that are not a public suffix)
*/ */
if (type & PSL_TYPE_NO_STAR_RULE)
type &= ~PSL_TYPE_NO_STAR_RULE;
else
return 1; return 1;
} }
@ -1002,7 +1004,7 @@ int psl_is_public_suffix(const psl_ctx_t *psl, const char *domain)
* [Mozilla Public Suffix List](https://publicsuffix.org). * [Mozilla Public Suffix List](https://publicsuffix.org).
* *
* @type specifies the PSL section where to perform the lookup. Valid values are * @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). * 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. * Other encodings likely result in incorrect return values.