commit
912d9a296a
|
@ -64,7 +64,7 @@ psl_ctx_t *
|
||||||
psl_load_file(const char *fname);
|
psl_load_file(const char *fname);
|
||||||
psl_ctx_t *
|
psl_ctx_t *
|
||||||
psl_load_fp(FILE *fp);
|
psl_load_fp(FILE *fp);
|
||||||
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(const psl_ctx_t *psl, const char *domain);
|
||||||
|
|
25
src/psl.c
25
src/psl.c
|
@ -81,8 +81,8 @@ struct _psl_ctx_st {
|
||||||
#include "suffixes.c"
|
#include "suffixes.c"
|
||||||
|
|
||||||
// references to this PSL will result in lookups to built-in data
|
// references to this PSL will result in lookups to built-in data
|
||||||
static psl_ctx_t
|
static const psl_ctx_t
|
||||||
_builtin_psl;
|
_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 *))
|
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))
|
if ((n = s1->length - s2->length))
|
||||||
return n; // shorter rules first
|
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)
|
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;
|
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)
|
psl_ctx_t *psl_load_file(const char *fname)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -380,7 +363,7 @@ psl_ctx_t *psl_load_fp(FILE *fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return built-in PSL structure
|
// return built-in PSL structure
|
||||||
psl_ctx_t *psl_builtin(void)
|
const psl_ctx_t *psl_builtin(void)
|
||||||
{
|
{
|
||||||
return &_builtin_psl;
|
return &_builtin_psl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ static void test_psl(void)
|
||||||
unsigned it, result;
|
unsigned it, result;
|
||||||
char buf[256], domain[64], *linep, *p;
|
char buf[256], domain[64], *linep, *p;
|
||||||
|
|
||||||
if (psl_global_init() == 0) {
|
|
||||||
psl = psl_load_file(DATADIR "/effective_tld_names.dat");
|
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));
|
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_free(&psl);
|
||||||
psl_global_deinit();
|
|
||||||
} else
|
|
||||||
failed++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * const *argv)
|
int main(int argc, const char * const *argv)
|
||||||
|
|
|
@ -70,9 +70,8 @@ static void test_psl(void)
|
||||||
{ "www.xn--czr694b", 1 },
|
{ "www.xn--czr694b", 1 },
|
||||||
};
|
};
|
||||||
unsigned it;
|
unsigned it;
|
||||||
psl_ctx_t *psl;
|
const psl_ctx_t *psl;
|
||||||
|
|
||||||
if (psl_global_init() == 0) {
|
|
||||||
psl = psl_builtin();
|
psl = psl_builtin();
|
||||||
|
|
||||||
printf("have %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
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());
|
printf("psl_builtin_sha1sum()=%s\n", psl_builtin_sha1sum());
|
||||||
*psl_builtin_sha1sum() == 0 ? failed++ : ok++;
|
*psl_builtin_sha1sum() == 0 ? failed++ : ok++;
|
||||||
|
|
||||||
psl_global_deinit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * const *argv)
|
int main(int argc, const char * const *argv)
|
||||||
|
|
|
@ -70,7 +70,6 @@ static void test_psl(void)
|
||||||
unsigned it;
|
unsigned it;
|
||||||
psl_ctx_t *psl;
|
psl_ctx_t *psl;
|
||||||
|
|
||||||
if (psl_global_init() == 0) {
|
|
||||||
psl = psl_load_file(DATADIR "/effective_tld_names.dat");
|
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));
|
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_free(&psl);
|
||||||
psl_global_deinit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * const *argv)
|
int main(int argc, const char * const *argv)
|
||||||
|
|
Loading…
Reference in New Issue