renamed psl_is_public() to psl_is_public_suffix()
This commit is contained in:
parent
af717a0d80
commit
b49e681d8f
|
@ -6,7 +6,7 @@ psl_free
|
||||||
psl_load_file
|
psl_load_file
|
||||||
psl_load_fp
|
psl_load_fp
|
||||||
psl_builtin
|
psl_builtin
|
||||||
psl_is_public
|
psl_is_public_suffix
|
||||||
psl_unregistrable_domain
|
psl_unregistrable_domain
|
||||||
psl_registrable_domain
|
psl_registrable_domain
|
||||||
psl_suffix_count
|
psl_suffix_count
|
||||||
|
|
|
@ -50,7 +50,7 @@ psl_ctx_t *
|
||||||
const psl_ctx_t *
|
const psl_ctx_t *
|
||||||
psl_builtin(void);
|
psl_builtin(void);
|
||||||
int
|
int
|
||||||
psl_is_public(const psl_ctx_t *psl, const char *domain);
|
psl_is_public_suffix(const psl_ctx_t *psl, const char *domain);
|
||||||
// returns the longest unregistrable domain within 'domain' or NULL if none found
|
// returns the longest unregistrable domain within 'domain' or NULL if none found
|
||||||
const char *
|
const char *
|
||||||
psl_unregistrable_domain(const psl_ctx_t *psl, const char *domain);
|
psl_unregistrable_domain(const psl_ctx_t *psl, const char *domain);
|
||||||
|
|
10
src/psl.c
10
src/psl.c
|
@ -248,7 +248,7 @@ static int _suffix_init(_psl_entry_t *suffix, const char *rule, size_t length)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* psl_is_public:
|
* psl_is_public_suffix:
|
||||||
* @psl: PSL context
|
* @psl: PSL context
|
||||||
* @domain: Domain string
|
* @domain: Domain string
|
||||||
*
|
*
|
||||||
|
@ -265,7 +265,7 @@ static int _suffix_init(_psl_entry_t *suffix, const char *rule, size_t length)
|
||||||
*
|
*
|
||||||
* Since: 0.1
|
* Since: 0.1
|
||||||
*/
|
*/
|
||||||
int psl_is_public(const psl_ctx_t *psl, const char *domain)
|
int psl_is_public_suffix(const psl_ctx_t *psl, const char *domain)
|
||||||
{
|
{
|
||||||
_psl_entry_t suffix, *rule;
|
_psl_entry_t suffix, *rule;
|
||||||
const char *p, *label_bak;
|
const char *p, *label_bak;
|
||||||
|
@ -369,10 +369,10 @@ const char *psl_unregistrable_domain(const psl_ctx_t *psl, const char *domain)
|
||||||
// for being a registered domain.
|
// for being a registered domain.
|
||||||
|
|
||||||
if (!(p = strrchr(domain, '.')))
|
if (!(p = strrchr(domain, '.')))
|
||||||
return psl_is_public(psl, domain) ? domain : NULL;
|
return psl_is_public_suffix(psl, domain) ? domain : NULL;
|
||||||
|
|
||||||
for (ret_domain = NULL; ;) {
|
for (ret_domain = NULL; ;) {
|
||||||
if (!psl_is_public(psl, p))
|
if (!psl_is_public_suffix(psl, p))
|
||||||
return ret_domain;
|
return ret_domain;
|
||||||
else if (p == domain)
|
else if (p == domain)
|
||||||
return domain;
|
return domain;
|
||||||
|
@ -415,7 +415,7 @@ const char *psl_registrable_domain(const psl_ctx_t *psl, const char *domain)
|
||||||
if (!(p = strrchr(domain, '.')))
|
if (!(p = strrchr(domain, '.')))
|
||||||
p = domain;
|
p = domain;
|
||||||
|
|
||||||
while ((ispublic = psl_is_public(psl, p)) && p > domain) {
|
while ((ispublic = psl_is_public_suffix(psl, p)) && p > domain) {
|
||||||
// go left to next dot
|
// go left to next dot
|
||||||
while (p > domain && *--p != '.')
|
while (p > domain && *--p != '.')
|
||||||
;
|
;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the test suite of libpsl.
|
* This file is part of the test suite of libpsl.
|
||||||
*
|
*
|
||||||
* Test psl_is_public() for all entries in effective_tld_names.dat
|
* Test psl_is_public_suffix() for all entries in effective_tld_names.dat
|
||||||
*
|
*
|
||||||
* Changelog
|
* Changelog
|
||||||
* 19.03.2014 Tim Ruehsen created
|
* 19.03.2014 Tim Ruehsen created
|
||||||
|
@ -67,38 +67,38 @@ static void test_psl(void)
|
||||||
*linep = 0;
|
*linep = 0;
|
||||||
|
|
||||||
if (*p == '!') { // an exception to a wildcard, e.g. !www.ck (wildcard is *.ck)
|
if (*p == '!') { // an exception to a wildcard, e.g. !www.ck (wildcard is *.ck)
|
||||||
if ((result = psl_is_public(psl, p + 1))) {
|
if ((result = psl_is_public_suffix(psl, p + 1))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 0)\n", p, result);
|
printf("psl_is_public_suffix(%s)=%d (expected 0)\n", p, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
|
|
||||||
if (!(result = psl_is_public(psl, strchr(p, '.') + 1))) {
|
if (!(result = psl_is_public_suffix(psl, strchr(p, '.') + 1))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 1)\n", strchr(p, '.') + 1, result);
|
printf("psl_is_public_suffix(%s)=%d (expected 1)\n", strchr(p, '.') + 1, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
}
|
}
|
||||||
else if (*p == '*') { // a wildcard, e.g. *.ck
|
else if (*p == '*') { // a wildcard, e.g. *.ck
|
||||||
if (!(result = psl_is_public(psl, p + 1))) {
|
if (!(result = psl_is_public_suffix(psl, p + 1))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 1)\n", p + 1, result);
|
printf("psl_is_public_suffix(%s)=%d (expected 1)\n", p + 1, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
|
|
||||||
*p = 'x';
|
*p = 'x';
|
||||||
if (!(result = psl_is_public(psl, p))) {
|
if (!(result = psl_is_public_suffix(psl, p))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 1)\n", p, result);
|
printf("psl_is_public_suffix(%s)=%d (expected 1)\n", p, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!(result = psl_is_public(psl, p))) {
|
if (!(result = psl_is_public_suffix(psl, p))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 1)\n", p, result);
|
printf("psl_is_public_suffix(%s)=%d (expected 1)\n", p, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
|
|
||||||
snprintf(domain, sizeof(domain), "xxxx.%s", p);
|
snprintf(domain, sizeof(domain), "xxxx.%s", p);
|
||||||
if ((result = psl_is_public(psl, domain))) {
|
if ((result = psl_is_public_suffix(psl, domain))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 0)\n", domain, result);
|
printf("psl_is_public_suffix(%s)=%d (expected 0)\n", domain, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,13 +78,13 @@ static void test_psl(void)
|
||||||
|
|
||||||
for (it = 0; it < countof(test_data); it++) {
|
for (it = 0; it < countof(test_data); it++) {
|
||||||
const struct test_data *t = &test_data[it];
|
const struct test_data *t = &test_data[it];
|
||||||
int result = psl_is_public(psl, t->domain);
|
int result = psl_is_public_suffix(psl, t->domain);
|
||||||
|
|
||||||
if (result == t->result) {
|
if (result == t->result) {
|
||||||
ok++;
|
ok++;
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
printf("psl_is_public_suffix(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the test suite of libpsl.
|
* This file is part of the test suite of libpsl.
|
||||||
*
|
*
|
||||||
* Test case for psl_load_file(), psl_is_public(), psl_free()
|
* Test case for psl_load_file(), psl_is_public_suffix(), psl_free()
|
||||||
*
|
*
|
||||||
* Changelog
|
* Changelog
|
||||||
* 19.03.2014 Tim Ruehsen created from libmget/cookie.c
|
* 19.03.2014 Tim Ruehsen created from libmget/cookie.c
|
||||||
|
@ -76,13 +76,13 @@ static void test_psl(void)
|
||||||
|
|
||||||
for (it = 0; it < countof(test_data); it++) {
|
for (it = 0; it < countof(test_data); it++) {
|
||||||
const struct test_data *t = &test_data[it];
|
const struct test_data *t = &test_data[it];
|
||||||
int result = psl_is_public(psl, t->domain);
|
int result = psl_is_public_suffix(psl, t->domain);
|
||||||
|
|
||||||
if (result == t->result) {
|
if (result == t->result) {
|
||||||
ok++;
|
ok++;
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
printf("psl_is_public_suffix(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ int main(int argc, const char *const *argv)
|
||||||
|
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
for (; arg < argv + argc; arg++)
|
for (; arg < argv + argc; arg++)
|
||||||
printf("%s: %d\n", *arg, psl_is_public(psl, *arg));
|
printf("%s: %d\n", *arg, psl_is_public_suffix(psl, *arg));
|
||||||
}
|
}
|
||||||
else if (mode == 2) {
|
else if (mode == 2) {
|
||||||
for (; arg < argv + argc; arg++)
|
for (; arg < argv + argc; arg++)
|
||||||
|
|
Loading…
Reference in New Issue