mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-06 22:10:33 +01:00
dns: refactor domain_is_valid() to combine #if blocks
This commit is contained in:
parent
4ddbf32f1b
commit
db3da65c6c
1 changed files with 32 additions and 30 deletions
|
|
@ -177,40 +177,42 @@ domain_is_valid(const char *domain,
|
|||
gboolean reject_public_suffix,
|
||||
gboolean assume_any_tld_is_public)
|
||||
{
|
||||
#if WITH_LIBPSL
|
||||
/* ifdef to fall back to old API function on platforms with older LIBPSL */
|
||||
#ifdef PSL_TYPE_NO_STAR_RULE
|
||||
int type = PSL_TYPE_ANY;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (*domain == '\0')
|
||||
return FALSE;
|
||||
#if WITH_LIBPSL
|
||||
/* ifdef to fall back to old API function on platforms with older LIBPSL */
|
||||
#ifdef PSL_TYPE_NO_STAR_RULE
|
||||
/*
|
||||
* If we use PSL_TYPE_ANY, any TLD (top-level domain, i.e., domain
|
||||
* with no dots) is considered *public* by the PSL library even if
|
||||
* it is *not* on the official suffix list. This is the implicit
|
||||
* behavior of the older API function psl_is_public_suffix().
|
||||
* To inhibit that and only deem TLDs explicitly listed in the PSL
|
||||
* as public, we need to turn off the "prevailing star rule" with
|
||||
* PSL_TYPE_NO_STAR_RULE.
|
||||
* For documentation on psl_is_public_suffix2(), see:
|
||||
* https://rockdaboot.github.io/libpsl/libpsl-Public-Suffix-List-functions.html#psl-is-public-suffix2
|
||||
* For more on the public suffix format, including wildcards:
|
||||
* https://github.com/publicsuffix/list/wiki/Format#format
|
||||
*/
|
||||
if (!assume_any_tld_is_public)
|
||||
type = PSL_TYPE_NO_STAR_RULE;
|
||||
if (reject_public_suffix && psl_is_public_suffix2(psl_builtin(), domain, type))
|
||||
return FALSE;
|
||||
|
||||
if (reject_public_suffix) {
|
||||
int is_pub;
|
||||
|
||||
#if !WITH_LIBPSL
|
||||
/* Without libpsl, we cannot detect that the domain is a public suffix, we assume
|
||||
* the domain is not and valid. */
|
||||
is_pub = FALSE;
|
||||
#elif defined(PSL_TYPE_NO_STAR_RULE)
|
||||
/*
|
||||
* If we use PSL_TYPE_ANY, any TLD (top-level domain, i.e., domain
|
||||
* with no dots) is considered *public* by the PSL library even if
|
||||
* it is *not* on the official suffix list. This is the implicit
|
||||
* behavior of the older API function psl_is_public_suffix().
|
||||
* To inhibit that and only deem TLDs explicitly listed in the PSL
|
||||
* as public, we need to turn off the "prevailing star rule" with
|
||||
* PSL_TYPE_NO_STAR_RULE.
|
||||
* For documentation on psl_is_public_suffix2(), see:
|
||||
* https://rockdaboot.github.io/libpsl/libpsl-Public-Suffix-List-functions.html#psl-is-public-suffix2
|
||||
* For more on the public suffix format, including wildcards:
|
||||
* https://github.com/publicsuffix/list/wiki/Format#format
|
||||
*/
|
||||
is_pub =
|
||||
psl_is_public_suffix2(psl_builtin(),
|
||||
domain,
|
||||
assume_any_tld_is_public ? PSL_TYPE_ANY : PSL_TYPE_NO_STAR_RULE);
|
||||
#else
|
||||
if (reject_public_suffix && psl_is_public_suffix(psl_builtin(), domain))
|
||||
return FALSE;
|
||||
#endif
|
||||
is_pub = psl_is_public_suffix(psl_builtin(), domain);
|
||||
#endif
|
||||
|
||||
if (is_pub)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue