From 2e58fc0a7a69ecbe4a48b296bcf6313825fcfa7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Wed, 18 Aug 2010 23:03:58 +0300 Subject: db, filter: fix db generation of ipv4 style addresses Properly embed the ipv4 address in database now. Teach filter to understand the two new reserved component id's. --- squark-filter.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'squark-filter.c') 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; -- cgit v1.2.3