From 73acfc570b0552c873f026682d7b050689bf2e04 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Mon, 24 Mar 2014 18:33:27 -0400 Subject: [PATCH] avoid the need for psl_global_init() and psl_global_deinit() There is no need to for an initialization function if the builtin structs if the comparison function will look at label_buf directly when label == NULL. This simplifies the API for users, who now don't have to worry about library initialization and deinitialization functions (these sort of functions can cause headaches in chained library loads, esp. in plugin architectures like PAM). --- src/psl.c | 19 +------------------ tests/test-is-public-all.c | 4 ---- tests/test-is-public-builtin.c | 4 ---- tests/test-is-public.c | 3 --- 4 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/psl.c b/src/psl.c index 01e654c..484100e 100644 --- a/src/psl.c +++ b/src/psl.c @@ -188,7 +188,7 @@ static int _suffix_compare(const _psl_entry_t *s1, const _psl_entry_t *s2) if ((n = s1->length - s2->length)) return n; // shorter rules first - return strcmp(s1->label, s2->label); + return strcmp(s1->label, s2->label ? s2->label : s2->label_buf); } static void _suffix_init(_psl_entry_t *suffix, const char *rule, size_t length) @@ -299,23 +299,6 @@ int psl_is_public(const psl_ctx_t *psl, const char *domain) return 1; } -int psl_global_init(void) -{ - size_t it; - - for (it = 0; it < countof(suffixes); it++) - suffixes[it].label = suffixes[it].label_buf; - - for (it = 0; it < countof(suffix_exceptions); it++) - suffix_exceptions[it].label = suffix_exceptions[it].label_buf; - - return 0; // 0 = OK -} - -void psl_global_deinit(void) -{ -} - psl_ctx_t *psl_load_file(const char *fname) { FILE *fp; diff --git a/tests/test-is-public-all.c b/tests/test-is-public-all.c index fb5ed6e..5c4d93a 100644 --- a/tests/test-is-public-all.c +++ b/tests/test-is-public-all.c @@ -52,7 +52,6 @@ static void test_psl(void) unsigned it, result; char buf[256], domain[64], *linep, *p; - if (psl_global_init() == 0) { 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)); @@ -113,9 +112,6 @@ static void test_psl(void) } psl_free(&psl); - psl_global_deinit(); - } else - failed++; } int main(int argc, const char * const *argv) diff --git a/tests/test-is-public-builtin.c b/tests/test-is-public-builtin.c index 4a86036..ff1dad4 100644 --- a/tests/test-is-public-builtin.c +++ b/tests/test-is-public-builtin.c @@ -72,7 +72,6 @@ static void test_psl(void) unsigned it; const psl_ctx_t *psl; - if (psl_global_init() == 0) { psl = psl_builtin(); printf("have %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl)); @@ -97,9 +96,6 @@ static void test_psl(void) printf("psl_builtin_sha1sum()=%s\n", psl_builtin_sha1sum()); *psl_builtin_sha1sum() == 0 ? failed++ : ok++; - - psl_global_deinit(); - } } int main(int argc, const char * const *argv) diff --git a/tests/test-is-public.c b/tests/test-is-public.c index 34ad543..07c3df0 100644 --- a/tests/test-is-public.c +++ b/tests/test-is-public.c @@ -70,7 +70,6 @@ static void test_psl(void) unsigned it; psl_ctx_t *psl; - if (psl_global_init() == 0) { 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)); @@ -88,8 +87,6 @@ static void test_psl(void) } psl_free(&psl); - psl_global_deinit(); - } } int main(int argc, const char * const *argv)