revert logic for psl_is_public()

This commit is contained in:
Tim Ruehsen 2014-03-22 22:19:20 +01:00
parent 1c90fac381
commit 99d057d514
4 changed files with 40 additions and 28 deletions

View File

@ -231,15 +231,15 @@ int psl_is_public(const psl_ctx_t *psl, const char *domain)
if (*p == '.') if (*p == '.')
suffix.nlabels++; suffix.nlabels++;
// if domain has enough labels, it won't match // if domain has enough labels, it is public
rule = _vector_get(psl->suffixes, 0); rule = _vector_get(psl->suffixes, 0);
if (!rule || rule->nlabels < suffix.nlabels - 1) if (!rule || rule->nlabels < suffix.nlabels - 1)
return 0; return 1;
rule = _vector_get(psl->suffixes, _vector_find(psl->suffixes, &suffix)); rule = _vector_get(psl->suffixes, _vector_find(psl->suffixes, &suffix));
if (rule) { if (rule) {
// definitely a match, no matter if the found rule is a wildcard or not // definitely a match, no matter if the found rule is a wildcard or not
return 1; return 0;
} }
label_bak = suffix.label; label_bak = suffix.label;
@ -259,14 +259,14 @@ int psl_is_public(const psl_ctx_t *psl, const char *domain)
suffix.nlabels++; suffix.nlabels++;
if (_vector_get(psl->suffix_exceptions, _vector_find(psl->suffix_exceptions, &suffix)) != 0) if (_vector_get(psl->suffix_exceptions, _vector_find(psl->suffix_exceptions, &suffix)) != 0)
return 0; return 1; // found an exception, so 'domain' is public
return 1; return 0;
} }
} }
} }
return 0; return 1;
} }
psl_ctx_t *psl_load_file(const char *fname) psl_ctx_t *psl_load_file(const char *fname)

View File

@ -28,6 +28,7 @@
# include <config.h> # include <config.h>
#endif #endif
// # include <idn2.h>
#include "psl.c" #include "psl.c"
static void _print_psl_entries(_psl_vector_t *v, const char *varname) static void _print_psl_entries(_psl_vector_t *v, const char *varname)
@ -42,6 +43,17 @@ static void _print_psl_entries(_psl_vector_t *v, const char *varname)
printf("\t{ \"%s\", NULL, %hd, %hhd, %hhd },\n", printf("\t{ \"%s\", NULL, %hd, %hhd, %hhd },\n",
e->label_buf, e->length, e->nlabels, e->wildcard); e->label_buf, e->length, e->nlabels, e->wildcard);
/*
if (str_needs_encoding(e->label_buf)) {
char *asc = NULL;
int rc;
if ((rc = idn2_lookup_u8((uint8_t *)e->label_buf, (uint8_t **)&asc, 0)) == IDN2_OK) {
fprintf(stderr, "idn2 '%s' -> '%s'\n", e->label_buf, asc);
} else
fprintf(stderr, "toASCII(%s) failed (%d): %s\n", e->label_buf, rc, idn2_strerror(rc));
}
*/
} }
printf("};\n"); printf("};\n");

View File

@ -50,18 +50,18 @@ static void test_psl(void)
int int
result; result;
} test_data[] = { } test_data[] = {
{ "www.example.com", 0 }, { "www.example.com", 1 },
{ "com.ar", 1 }, { "com.ar", 0 },
{ "www.com.ar", 0 }, { "www.com.ar", 1 },
{ "cc.ar.us", 1 }, { "cc.ar.us", 0 },
{ ".cc.ar.us", 1 }, { ".cc.ar.us", 0 },
{ "www.cc.ar.us", 0 }, { "www.cc.ar.us", 1 },
{ "www.ck", 0 }, // exception from *.ck { "www.ck", 1 }, // exception from *.ck
{ "abc.www.ck", 0 }, { "abc.www.ck", 1 },
{ "xxx.ck", 1 }, { "xxx.ck", 0 },
{ "www.xxx.ck", 0 }, { "www.xxx.ck", 1 },
{ "\345\225\206\346\240\207", 1 }, // xn--czr694b oder 商标 { "\345\225\206\346\240\207", 0 }, // xn--czr694b oder 商标
{ "www.\345\225\206\346\240\207", 0 }, { "www.\345\225\206\346\240\207", 1 },
// { "xn--czr694b", 1 }, // { "xn--czr694b", 1 },
// { "www.xn--czr694b", 1 }, // { "www.xn--czr694b", 1 },
}; };

View File

@ -48,16 +48,16 @@ static void test_psl(void)
int int
result; result;
} test_data[] = { } test_data[] = {
{ "www.example.com", 0 }, { "www.example.com", 1 },
{ "com.ar", 1 }, { "com.ar", 0 },
{ "www.com.ar", 0 }, { "www.com.ar", 1 },
{ "cc.ar.us", 1 }, { "cc.ar.us", 0 },
{ ".cc.ar.us", 1 }, { ".cc.ar.us", 0 },
{ "www.cc.ar.us", 0 }, { "www.cc.ar.us", 1 },
{ "www.ck", 0 }, // exception from *.ck { "www.ck", 1 }, // exception from *.ck
{ "abc.www.ck", 0 }, { "abc.www.ck", 1 },
{ "xxx.ck", 1 }, { "xxx.ck", 0 },
{ "www.xxx.ck", 0 }, { "www.xxx.ck", 1 },
}; };
unsigned it; unsigned it;
psl_ctx_t *psl; psl_ctx_t *psl;