From 99d057d51404aa6c18bdf12b69d3b60ffcce5132 Mon Sep 17 00:00:00 2001 From: Tim Ruehsen Date: Sat, 22 Mar 2014 22:19:20 +0100 Subject: [PATCH] revert logic for psl_is_public() --- src/psl.c | 12 ++++++------ src/psl2c.c | 12 ++++++++++++ tests/test-is-public-inline.c | 24 ++++++++++++------------ tests/test-is-public.c | 20 ++++++++++---------- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/psl.c b/src/psl.c index aba1594..fed72b7 100644 --- a/src/psl.c +++ b/src/psl.c @@ -231,15 +231,15 @@ int psl_is_public(const psl_ctx_t *psl, const char *domain) if (*p == '.') 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); if (!rule || rule->nlabels < suffix.nlabels - 1) - return 0; + return 1; rule = _vector_get(psl->suffixes, _vector_find(psl->suffixes, &suffix)); if (rule) { // definitely a match, no matter if the found rule is a wildcard or not - return 1; + return 0; } label_bak = suffix.label; @@ -259,14 +259,14 @@ int psl_is_public(const psl_ctx_t *psl, const char *domain) suffix.nlabels++; 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) diff --git a/src/psl2c.c b/src/psl2c.c index ffe1487..511e19b 100644 --- a/src/psl2c.c +++ b/src/psl2c.c @@ -28,6 +28,7 @@ # include #endif +// # include #include "psl.c" 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", 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"); diff --git a/tests/test-is-public-inline.c b/tests/test-is-public-inline.c index e3430da..1777317 100644 --- a/tests/test-is-public-inline.c +++ b/tests/test-is-public-inline.c @@ -50,18 +50,18 @@ static void test_psl(void) int result; } test_data[] = { - { "www.example.com", 0 }, - { "com.ar", 1 }, - { "www.com.ar", 0 }, - { "cc.ar.us", 1 }, - { ".cc.ar.us", 1 }, - { "www.cc.ar.us", 0 }, - { "www.ck", 0 }, // exception from *.ck - { "abc.www.ck", 0 }, - { "xxx.ck", 1 }, - { "www.xxx.ck", 0 }, - { "\345\225\206\346\240\207", 1 }, // xn--czr694b oder 商标 - { "www.\345\225\206\346\240\207", 0 }, + { "www.example.com", 1 }, + { "com.ar", 0 }, + { "www.com.ar", 1 }, + { "cc.ar.us", 0 }, + { ".cc.ar.us", 0 }, + { "www.cc.ar.us", 1 }, + { "www.ck", 1 }, // exception from *.ck + { "abc.www.ck", 1 }, + { "xxx.ck", 0 }, + { "www.xxx.ck", 1 }, + { "\345\225\206\346\240\207", 0 }, // xn--czr694b oder 商标 + { "www.\345\225\206\346\240\207", 1 }, // { "xn--czr694b", 1 }, // { "www.xn--czr694b", 1 }, }; diff --git a/tests/test-is-public.c b/tests/test-is-public.c index 09fb057..00db2d0 100644 --- a/tests/test-is-public.c +++ b/tests/test-is-public.c @@ -48,16 +48,16 @@ static void test_psl(void) int result; } test_data[] = { - { "www.example.com", 0 }, - { "com.ar", 1 }, - { "www.com.ar", 0 }, - { "cc.ar.us", 1 }, - { ".cc.ar.us", 1 }, - { "www.cc.ar.us", 0 }, - { "www.ck", 0 }, // exception from *.ck - { "abc.www.ck", 0 }, - { "xxx.ck", 1 }, - { "www.xxx.ck", 0 }, + { "www.example.com", 1 }, + { "com.ar", 0 }, + { "www.com.ar", 1 }, + { "cc.ar.us", 0 }, + { ".cc.ar.us", 0 }, + { "www.cc.ar.us", 1 }, + { "www.ck", 1 }, // exception from *.ck + { "abc.www.ck", 1 }, + { "xxx.ck", 0 }, + { "www.xxx.ck", 1 }, }; unsigned it; psl_ctx_t *psl;