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).
This commit is contained in:
Daniel Kahn Gillmor 2014-03-24 18:33:27 -04:00
parent 6e7e58aa38
commit 73acfc570b
4 changed files with 1 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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