new function psl_load_fp()
This commit is contained in:
parent
de7d394223
commit
a707b267c9
|
@ -27,6 +27,8 @@
|
|||
#ifndef _LIBPSL_LIBPSL_H
|
||||
#define _LIBPSL_LIBPSL_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Let C++ include C headers
|
||||
#ifdef __cplusplus
|
||||
# define PSL_BEGIN_DECLS extern "C" {
|
||||
|
@ -52,6 +54,8 @@ void
|
|||
psl_free(psl_ctx_t **psl);
|
||||
psl_ctx_t *
|
||||
psl_load_file(const char *fname);
|
||||
psl_ctx_t *
|
||||
psl_load_fp(FILE *fp);
|
||||
int
|
||||
psl_is_public(const psl_ctx_t *psl, const char *domain);
|
||||
|
||||
|
|
25
src/psl.c
25
src/psl.c
|
@ -265,17 +265,31 @@ int psl_is_public(const psl_ctx_t *psl, const char *domain)
|
|||
}
|
||||
|
||||
psl_ctx_t *psl_load_file(const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
psl_ctx_t *psl = NULL;
|
||||
|
||||
if ((fp = fopen(fname, "r"))) {
|
||||
psl = psl_load_fp(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return psl;
|
||||
}
|
||||
|
||||
psl_ctx_t *psl_load_fp(FILE *fp)
|
||||
{
|
||||
psl_ctx_t *psl;
|
||||
_psl_entry_t suffix, *suffixp;
|
||||
FILE *fp;
|
||||
int nsuffixes = 0;
|
||||
char buf[256], *linep, *p;
|
||||
|
||||
if (!fp)
|
||||
return NULL;
|
||||
|
||||
if (!(psl = calloc(1, sizeof(psl_ctx_t))))
|
||||
return NULL;
|
||||
|
||||
if ((fp = fopen(fname, "r"))) {
|
||||
// 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);
|
||||
|
@ -307,16 +321,9 @@ psl_ctx_t *psl_load_file(const char *fname)
|
|||
nsuffixes++;;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
_vector_sort(psl->suffix_exceptions);
|
||||
_vector_sort(psl->suffixes);
|
||||
|
||||
} else {
|
||||
free(psl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return psl;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue