summaryrefslogtreecommitdiffstats
path: root/sqdb-build.lua
diff options
context:
space:
mode:
Diffstat (limited to 'sqdb-build.lua')
-rwxr-xr-xsqdb-build.lua20
1 files changed, 16 insertions, 4 deletions
diff --git a/sqdb-build.lua b/sqdb-build.lua
index 6cde349..fce1e7b 100755
--- a/sqdb-build.lua
+++ b/sqdb-build.lua
@@ -7,6 +7,7 @@ local all_domains = {}
local all_ips = {}
local all_categories = {}
+local all_categories_by_id = {}
local num_categories = 0
local strfind = string.find
@@ -42,9 +43,13 @@ local function get_category(category_text)
cat = all_categories[category_text]
if cat ~= nil then return cat end
- num_categories = num_categories + 1
+ -- start category ID's from zero
cat = { desc=category_text, id=num_categories }
all_categories[category_text] = cat
+ num_categories = num_categories + 1
+
+ -- but index them from one
+ all_categories_by_id[num_categories] = cat
account_string(category_text)
@@ -169,11 +174,10 @@ local function enum_paths(cb, category, path, data)
end
local function enum_tree(cb, category, dns, data)
- local cdns, cdata, fdns
- local cat = data.category or category
+ local cdns, cdata, fdns, cat
if data.paths ~= nil then
- enum_paths(cb, cat, dns, data.paths)
+ enum_paths(cb, category, dns, data.paths)
end
if data.children ~= nil then
for cdns, cdata in pairs(data.children) do
@@ -182,6 +186,7 @@ local function enum_tree(cb, category, dns, data)
else
fdns = cdns
end
+ cat = cdata.category or category
cb(fdns, dns, cdns, cat, data.children, data.paths)
enum_tree(cb, cat, fdns, cdata)
end
@@ -276,6 +281,7 @@ local function load_lists(conffile, part)
end
-- start by reading in all classification data
+get_category("unknown")
load_lists("lists.conf", "domains")
prune_tree(all_domains, nil)
load_lists("lists.conf", "urls")
@@ -288,6 +294,12 @@ num_entries = db:generate_hash(function() enum_all(coroutine.yield) end)
-- write string literals
db:map_strings(all_strings)
+-- map category names and write the category section out
+for id, cdata in ipairs(all_categories_by_id) do
+ all_categories_by_id[id] = all_strings[cdata.desc]
+end
+db:write_section("categories", all_categories_by_id)
+
-- create master index
db:create_index(num_entries)
enum_all(