Merge pull request #1 from dkg/master

minor source and edge case cleanup
This commit is contained in:
rockdaboot 2014-03-21 20:21:18 +01:00
commit 6569b1c948
5 changed files with 100 additions and 10 deletions

9
.dir-locals.el Normal file
View File

@ -0,0 +1,9 @@
;; emacs local configuration settings for libpsl source
;; surmised by dkg on 2014-03-21 14:35:49-0400
((c-mode
(indent-tabs-mode . t)
(tab-width . 4)
(c-basic-offset . 4)
(c-file-style . "linux"))
)

57
.gitignore vendored Normal file
View File

@ -0,0 +1,57 @@
*~
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
compile
config.guess
config.h
config.h.in
config.log
config.rpath
config.status
config.sub
configure
data/Makefile
data/Makefile.in
depcomp
include/Makefile
include/Makefile.in
install-sh
libpsl-*.pc
libtool
ltmain.sh
m4/
missing
po/Makefile
po/Makefile.in
po/Makefile.in.in
po/Makevars.template
po/POTFILES
po/Rules-quot
po/boldquot.sed
po/en@boldquot.header
po/en@quot.header
po/insert-header.sin
po/psl.pot
po/quot.sed
po/remove-potcdate.sin
po/remove-potcdate.sed
po/stamp-po
src/.deps/
src/.libs/
src/Makefile
src/Makefile.in
src/libpsl-*.la
src/libpsl_*_la-psl.lo
stamp-h1
test-driver
tests/.deps/
tests/Makefile
tests/Makefile.in
tests/test-is-tld
tests/test-is-tld.log
tests/test-is-tld.o
tests/test-is-tld.trs
tests/test-suite.log
psl-*.tar.gz

View File

@ -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 */

View File

@ -275,13 +275,13 @@ psl_ctx_t *psl_load_file(const char *fname)
if (!(psl = calloc(1, sizeof(psl_ctx_t))))
return NULL;
// as of 02.11.2012, the list at http://publicsuffix.org/list/ contains ~6000 rules and 40 exceptions.
// as of 19.02.2014, the list at http://publicsuffix.org/list/ contains ~6500 rules and 19 exceptions.
psl->suffixes = _vector_alloc(8*1024, _suffix_compare);
psl->suffix_exceptions = _vector_alloc(64, _suffix_compare);
if ((fp = fopen(fname, "r"))) {
while ((linep = fgets(&buf, sizeof(buf), fp))) {
// as of 02.11.2012, the list at http://publicsuffix.org/list/ contains ~6000 rules and 40 exceptions.
// as of 19.02.2014, the list at http://publicsuffix.org/list/ contains ~6500 rules and 19 exceptions.
psl->suffixes = _vector_alloc(8*1024, _suffix_compare);
psl->suffix_exceptions = _vector_alloc(64, _suffix_compare);
while ((linep = fgets(buf, sizeof(buf), fp))) {
while (isspace(*linep)) linep++; // ignore leading whitespace
if (!*linep) continue; // skip empty lines
@ -312,14 +312,27 @@ 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);
} else {
free(psl);
return NULL;
}
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) {

View File

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