summaryrefslogtreecommitdiffstats
path: root/squark-filter.c
diff options
context:
space:
mode:
Diffstat (limited to 'squark-filter.c')
-rw-r--r--squark-filter.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/squark-filter.c b/squark-filter.c
index 097f420..fac9241 100644
--- a/squark-filter.c
+++ b/squark-filter.c
@@ -182,7 +182,7 @@ static int url_classify(struct url_info *url, struct sqdb *db)
blob_t b, key, got, tld, mkey;
void *cmph;
struct sqdb_index_entry *indx;
- cmph_uint32 i = -1, previ;
+ cmph_uint32 i = SQDB_PARENT_ROOT, previ;
int dots_done = 1;
cmph = sqdb_section_get(db, SQDB_SECTION_INDEX_MPH, NULL);
@@ -201,26 +201,33 @@ static int url_classify(struct url_info *url, struct sqdb *db)
previ = i;
i = cmph_search_packed(cmph, key.ptr, key.len);
- if (blob_cmp(got, sqdb_get_string_literal(db, indx[i].component)) != 0) {
- /* the subdomain did no longer match, use
- * parents classification */
- i = previ;
- goto parent_dns_match;
- }
if (!blob_is_null(tld)) {
- if (blob_cmp(tld, sqdb_get_string_literal(db, indx[indx[i].parent].component)) != 0) {
+ int p = indx[i].parent;
+
+ if (p == SQDB_PARENT_ROOT ||
+ p == SQDB_PARENT_IPV4 ||
+ indx[p].parent != SQDB_PARENT_ROOT ||
+ blob_cmp(tld, sqdb_get_string_literal(db, indx[p].component)) != 0) {
/* top level domain did not match */
i = -1;
goto parent_dns_match;
}
tld = BLOB_NULL;
+ previ = p;
+ }
+ if (indx[i].parent != previ ||
+ blob_cmp(got, sqdb_get_string_literal(db, indx[i].component)) != 0) {
+ /* the subdomain did no longer match, use
+ * parents classification */
+ i = previ;
+ goto parent_dns_match;
}
mkey = key;
dots_done++;
} while (indx[i].has_subdomains);
/* No paths to match for */
- if (!indx[i].has_paths)
+ if (i == SQDB_PARENT_ROOT || !indx[i].has_paths)
goto parent_dns_match;
if (key.ptr != url->host.ptr) {
@@ -268,7 +275,7 @@ static int url_classify(struct url_info *url, struct sqdb *db)
}
parent_dns_match:
- if (i == -1)
+ if (i == SQDB_PARENT_ROOT)
return 0; /* no category */
return indx[i].category;