Merge pull request #3 from dkg/master

API pruning
This commit is contained in:
rockdaboot 2014-03-25 21:39:17 +01:00
commit 912d9a296a
5 changed files with 6 additions and 34 deletions

View File

@ -64,7 +64,7 @@ psl_ctx_t *
psl_load_file(const char *fname);
psl_ctx_t *
psl_load_fp(FILE *fp);
psl_ctx_t *
const psl_ctx_t *
psl_builtin(void);
int
psl_is_public(const psl_ctx_t *psl, const char *domain);

View File

@ -81,8 +81,8 @@ struct _psl_ctx_st {
#include "suffixes.c"
// references to this PSL will result in lookups to built-in data
static psl_ctx_t
_builtin_psl;
static const psl_ctx_t
_builtin_psl = { .suffixes = NULL, .suffix_exceptions = NULL, };
static _psl_vector_t *_vector_alloc(int max, int (*cmp)(const _psl_entry_t *, const _psl_entry_t *))
{
@ -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;
@ -380,7 +363,7 @@ psl_ctx_t *psl_load_fp(FILE *fp)
}
// return built-in PSL structure
psl_ctx_t *psl_builtin(void)
const psl_ctx_t *psl_builtin(void)
{
return &_builtin_psl;
}

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

@ -70,9 +70,8 @@ static void test_psl(void)
{ "www.xn--czr694b", 1 },
};
unsigned it;
psl_ctx_t *psl;
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)