diff options
author | Andrew Lewis <nerf@judo.za.org> | 2015-08-28 18:32:19 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2015-09-02 14:10:00 +0200 |
commit | eca44757e9de09063f0c90240c12db84f0c8a219 (patch) | |
tree | ccec632ccf7226ea1d0066e858e353c96a3e69fb /src | |
parent | ffdf614e84e2548f9e21aa62b0300b0e91e4807d (diff) | |
download | rspamd-eca44757e9de09063f0c90240c12db84f0c8a219.tar.gz rspamd-eca44757e9de09063f0c90240c12db84f0c8a219.zip |
Minor refactoring
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/rbl.lua | 69 |
1 files changed, 29 insertions, 40 deletions
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index 6f6c17c7b..0203e969c 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -79,51 +79,40 @@ end local function rbl_cb (task) local function rbl_dns_cb(resolver, to_resolve, results, err, key) - if results then - local thisrbl = nil - for k,r in pairs(rbls) do - if k == key then - thisrbl = r - break - end - end - if thisrbl ~= nil then - if thisrbl['returncodes'] == nil then - if thisrbl['symbol'] ~= nil then - task:insert_result(thisrbl['symbol'], 1) + if not results then return end + if not rbls[key] then return end + if rbls[key]['returncodes'] == nil and rbls[key]['symbol'] ~= nil then + task:insert_result(rbls[key]['symbol'], 1) + return + end + for _,result in pairs(results) do + local ipstr = result:to_string() + local foundrc = false + for s,i in pairs(rbls[key]['returncodes']) do + if type(i) == 'string' then + if string.find(ipstr, '^' .. i .. '$') then + foundrc = true + task:insert_result(s, 1) + break end - else - for _,result in pairs(results) do - local ipstr = result:to_string() - local foundrc = false - for s,i in pairs(thisrbl['returncodes']) do - if type(i) == 'string' then - if string.find(ipstr, '^' .. i .. '$') then - foundrc = true - task:insert_result(s, 1) - break - end - elseif type(i) == 'table' then - for _,v in pairs(i) do - if string.find(ipstr, '^' .. v .. '$') then - foundrc = true - task:insert_result(s, 1) - break - end - end - end - end - if not foundrc then - if thisrbl['unknown'] and thisrbl['symbol'] then - task:insert_result(thisrbl['symbol'], 1) - else - rspamd_logger.errx(task, 'RBL %1 returned unknown result: %2', - thisrbl['rbl'], ipstr) - end + elseif type(i) == 'table' then + for _,v in pairs(i) do + if string.find(ipstr, '^' .. v .. '$') then + foundrc = true + task:insert_result(s, 1) + break end end end end + if not foundrc then + if rbls[key]['unknown'] and rbls[key]['symbol'] then + task:insert_result(rbls[key]['symbol'], 1) + else + rspamd_logger.errx(task, 'RBL %1 returned unknown result: %2', + rbls[key]['rbl'], ipstr) + end + end end task:inc_dns_req() end |