From: Mikhail Galanin Date: Tue, 14 Aug 2018 15:27:43 +0000 (+0100) Subject: [Minor] Update some Lua using new API X-Git-Tag: 1.8.0~234^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a3f2d9a9831b2e44dbb9f4a6c2d2a917f08dadf;p=thirdparty%2Frspamd.git [Minor] Update some Lua using new API --- diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 2898bfe4a2..4fe69ef881 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -701,24 +701,24 @@ local function multimap_callback(task, rule) if rt == 'ip' then match_rule(rule, ip) else - local cb = function (_, to_resolve, results, err) - task:inc_dns_req() - if err and (err ~= 'requested record is not found' and err ~= 'no records with this name') then - rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, err) - end - if results then - task:insert_result(rule['symbol'], 1, rule['map']) + local to_resolve = ip_to_rbl(ip, rule['map']) + + local is_ok, results = task:get_resolver():resolve_a({ + task = task, + name = to_resolve, + }) - if pre_filter then - task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol']) - end + lua_util.debugm(N, rspamd_config, 'resolve_a() finished: results=%1, is_ok=%2, to_resolve=%3', results, is_ok, to_resolve) + + if not is_ok and (results ~= 'requested record is not found' and results ~= 'no records with this name') then + rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, results) + elseif is_ok then + task:insert_result(rule['symbol'], 1, rule['map']) + if pre_filter then + task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol']) end end - task:get_resolver():resolve_a({task = task, - name = ip_to_rbl(ip, rule['map']), - callback = cb, - }) end end end, diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua index 138899417e..f1f9ad9162 100644 --- a/src/plugins/lua/reputation.lua +++ b/src/plugins/lua/reputation.lua @@ -720,45 +720,40 @@ local function reputation_dns_get_token(task, rule, token, continuation_cb) local key = gen_token_key(token, rule) local dns_name = key .. '.' .. rule.backend.config.list - local function dns_callback(_, to_resolve, results, err) - if err and (err ~= 'requested record is not found' and err ~= 'no records with this name') then - rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, err) - end - if not results then - lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 error=%3 list=%4', - to_resolve, false, err, rule.backend.config.list) - else - lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 error=%3 list=%4', - to_resolve, true, err, rule.backend.config.list) - end - - -- Now split tokens to list of values - if not err and results then - local values = {} - -- Format: key1=num1;key2=num2...keyn=numn - fun.each(function(e) - local vals = lua_util.rspamd_str_split(e, "=") - if vals and #vals == 2 then - local nv = tonumber(vals[2]) - if nv then - values[vals[1]] = nv - end - end - end, - lua_util.rspamd_str_split(results[1], ";")) - continuation_cb(nil, to_resolve, values) - else - continuation_cb(err, to_resolve, nil) - end - - task:inc_dns_req() - end - r:resolve_a({ + local is_ok, results = r:resolve_a({ task = task, name = dns_name, - callback = dns_callback, forced = true, }) + + if not is_ok and (results ~= 'requested record is not found' and results ~= 'no records with this name') then + rspamd_logger.errx(task, 'error looking up %s: %s', dns_name, results) + end + + lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 is_ok=%3 list=%4', + dns_name, results, is_ok, rule.backend.config.list) + + -- Now split tokens to list of values + if is_ok then + local values = {} + -- Format: key1=num1;key2=num2...keyn=numn + fun.each(function(e) + local vals = lua_util.rspamd_str_split(e, "=") + if vals and #vals == 2 then + local nv = tonumber(vals[2]) + if nv then + values[vals[1]] = nv + end + end + end, + lua_util.rspamd_str_split(results[1], ";")) + + continuation_cb(nil, dns_name, values) + else + continuation_cb(results, dns_name, nil) + end + + task:inc_dns_req() end local function reputation_redis_init(rule, cfg, ev_base, worker)