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_TYPE_ICANN
PSL_TYPE_PRIVATE
PSL_TYPE_NO_STAR_RULE
PSL_TYPE_ANY
psl_error_t
psl_ctx_t

View File

@ -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:

View File

@ -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.