From 1c2f8cc575dfd808e69487cb586c27d5b46a532c Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Mon, 3 Mar 2008 17:02:17 +0000 Subject: Saving work for today. Filtering is starting to take shape. git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@797 ab2d0c66-481e-0410-8bed-d214d4d58bed --- tinydns-model.lua | 63 +++++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 41 deletions(-) (limited to 'tinydns-model.lua') diff --git a/tinydns-model.lua b/tinydns-model.lua index a68cda8..c45fb98 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -305,9 +305,24 @@ local function rebuild_table(t,domains_rebuilt) end end +-- This function removes all records that doesn't have the filter-value +local function filter_table(t1,domains_filtered,filter) + if not (type(t1) == "string") then + for k1,v1 in pairs(t1) do + for k2,v2 in pairs(v1) do + if (v2.label) then + if ( string.find(filter,v2.label) ) then + table.insert(domains_filtered, v2) + end + end + end + end + end +end + -- If you enter 'filter_type' (this should be one of the options found in local function check_signs() ) then -- the output will be filtered to only contain this type of data. -function getconfigobjects(self,filter_type) +function getconfigobjects(self,filter_type, filter_levels) local domains = {} --Loop through all available configfiles @@ -319,7 +334,7 @@ function getconfigobjects(self,filter_type) local filecontent_table = split_config_items(vv) -- Create domain information tables - local domain, level1, level2, level3, level4, level5, level6, levels + local domain -- * START * COMMONT SETTINGS *************************************************************************************** local descr=check_signs("prefix") @@ -526,13 +541,6 @@ function getconfigobjects(self,filter_type) option=domainoptions, }) ---[[ - table.insert(domainoptions, cfe ({ - name="debug", - label="Debug", - value=filter_type, - })) ---]] end -- * END * COMMONT SETTINGS *************************************************************************************** -- Inject the previous data into the right table @@ -560,39 +568,12 @@ function getconfigobjects(self,filter_type) local domains_rebuilt = {} rebuild_table(domains,domains_rebuilt) ---[==[ - for k1,v1 in pairsByKeys(domains) do - table.insert(domains_sorted, { name=k1 }) - for k2,v2 in pairsByKeys(v1) do - table.insert(domains_sorted[#domains_sorted], { name=k2 }) ----[=[ - if (v2) and (type(v2) == "table") then --- if not (v2.type) then - for k3,v3 in pairsByKeys(v2) do - if (v2[k3]["value"]) then - if not (domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"]) then - domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"] = {} - end --- table.insert(domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"], domains[k1][k2] ) - else - table.insert(domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]], { name=k3 }) - end - end --- else --- if not (domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"]) then --- domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"] = {} --- end --- table.insert(domains_sorted[#domains_sorted][#domains_sorted[#domains_sorted]]["value"], { name=v2, name=k3 } ) --- end - end ---]=] - end - end --- table.sort(domains_sorted) - ---]==] + -- Filter away not wanted records + local domains_filtered = {} + local filter_level2 = "cat.org" -- < This is DEBUG!!! REMOVE WHEN DONE! + filter_table(domains_rebuilt,domains_filtered,filter_level2) - return domains_rebuilt + return domains_filtered end -- cgit v1.2.3