summaryrefslogtreecommitdiffstats
path: root/sqdb-build.lua
diff options
context:
space:
mode:
Diffstat (limited to 'sqdb-build.lua')
-rwxr-xr-xsqdb-build.lua34
1 files changed, 26 insertions, 8 deletions
diff --git a/sqdb-build.lua b/sqdb-build.lua
index 2b301fc..cd039e2 100755
--- a/sqdb-build.lua
+++ b/sqdb-build.lua
@@ -193,6 +193,14 @@ local function enum_tree(cb, category, dns, data)
end
end
+function iptonumber(str)
+ local num = 0
+ for elem in str:gmatch("%d+") do
+ num = num * 256 + assert(tonumber(elem))
+ end
+ return num
+end
+
local function enum_all(cb)
local ipaddr, data, category
@@ -204,8 +212,7 @@ local function enum_all(cb)
if data.paths ~= nil then
enum_paths(cb, data.category, ipaddr, data.paths)
end
- -- fixme, calculate ip as 32-bit value
- cb(ipaddr, nil, 0, data.category, nil, data.paths)
+ cb(ipaddr, nil, iptonumber(ipaddr), data.category, nil, data.paths)
end
end
@@ -307,11 +314,22 @@ db:write_section("categories", all_categories_by_id)
db:create_index(num_entries)
enum_all(
function(uri, parent_uri, component, category, childs, paths)
- db:assign_index(db:hash(uri),
- category and category.id or 0,
- childs and true or false,
- paths and true or false,
- all_strings[component] or 0,
- parent_uri and db:hash(parent_uri) or 0)
+ if parent_uri == nil and type(component) == "number" then
+ -- Embedded IPv4 address
+ db:assign_index(db:hash(uri),
+ category and category.id or 0,
+ childs and true or false,
+ paths and true or false,
+ component,
+ -2)
+ else
+ -- Regular entry
+ db:assign_index(db:hash(uri),
+ category and category.id or 0,
+ childs and true or false,
+ paths and true or false,
+ all_strings[component] or 0,
+ parent_uri and db:hash(parent_uri) or -1)
+ end
end
)