diff --git a/include/libpsl.h b/include/libpsl.h index fd2a404..9a7c934 100644 --- a/include/libpsl.h +++ b/include/libpsl.h @@ -55,6 +55,14 @@ psl_ctx_t * int psl_is_tld(const psl_ctx_t *psl, const char *domain); +/* does not include exceptions */ +int + psl_suffix_count(const psl_ctx_t *psl); +/* just counts exceptions */ +int + psl_suffix_exception_count(const psl_ctx_t *psl); + + PSL_END_DECLS #endif /* _LIBPSL_LIBPSL_H */ diff --git a/src/psl.c b/src/psl.c index 5a2f819..cd3e5fa 100644 --- a/src/psl.c +++ b/src/psl.c @@ -312,14 +312,25 @@ psl_ctx_t *psl_load_file(const char *fname) _vector_sort(psl->suffix_exceptions); _vector_sort(psl->suffixes); - printf("loaded %d (%d/%d) suffixes\n", nsuffixes, psl->suffixes->cur, psl->suffix_exceptions->cur); - } else fprintf(stderr, _("Failed to open PSL file '%s'\n"), fname); return psl; } + +/* does not include exceptions */ +int psl_suffix_count(const psl_ctx_t *psl) +{ + return psl->suffixes->cur; +} +/* just counts exceptions */ +int psl_suffix_exception_count(const psl_ctx_t *psl) +{ + return psl->suffix_exceptions->cur; +} + + void psl_free(psl_ctx_t **psl) { if (psl && *psl) { diff --git a/tests/test-is-tld.c b/tests/test-is-tld.c index 0f63b9b..1868af0 100644 --- a/tests/test-is-tld.c +++ b/tests/test-is-tld.c @@ -64,6 +64,9 @@ static void test_psl(void) psl = psl_load_file(DATADIR "/effective_tld_names.dat"); + printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl)); + + for (it = 0; it < countof(test_data); it++) { const struct test_data *t = &test_data[it]; int result = psl_is_tld(psl, t->domain);