From: Andrew Lewis Date: Tue, 27 Feb 2018 11:58:09 +0000 (+0200) Subject: [Minor] DMARC: apply library functions X-Git-Tag: 1.7.0~110^2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e3c522b8e5702d6c187dd2d6b54b13c7e8f05e7e;p=rspamd.git [Minor] DMARC: apply library functions --- diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index 8ab390257..46509039d 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -134,7 +134,7 @@ local dmarc_actions = {} local E = {} -local take_report_sha +local take_report_id local take_report_script = [[ local index_key = KEYS[1] local report_key = KEYS[2] @@ -157,29 +157,6 @@ end local tz_offset = get_timezone_offset(os.time()) -local function load_scripts(cfg, ev_base) - local function redis_report_script_cb(err, data) - if err then - rspamd_logger.errx(cfg, 'DMARC report script loading failed: ' .. err) - else - take_report_sha = tostring(data) - rspamd_logger.infox(cfg, 'Loaded DMARC report script with SHA %s', take_report_sha) - end - end - local ret = rspamd_redis.redis_make_request_taskless(ev_base, - rspamd_config, - redis_params, - nil, - true, -- is write - redis_report_script_cb, --callback - 'SCRIPT', -- command - {'LOAD', take_report_script} - ) - if not ret then - rspamd_logger.errx(cfg, 'Unable to load DMARC report script') - end -end - local function gen_dmarc_grammar() local lpeg = require "lpeg" lpeg.locale(lpeg) @@ -259,9 +236,6 @@ local function dmarc_callback(task) rspamd_logger.infox(task, '<%1> dmarc report saved for %2', task:get_message_id(), hfromdom) else - if string.match(err, 'NOSCRIPT') then - load_scripts(rspamd_config, task:get_ev_base()) - end rspamd_logger.errx(task, '<%1> dmarc report is not saved for %2: %3', task:get_message_id(), hfromdom, err) end @@ -567,17 +541,8 @@ local function dmarc_callback(task) local idx_key = table.concat({redis_keys.index_prefix, period}, redis_keys.join_char) if report_data then - local ret = rspamd_redis.redis_make_request(task, - redis_params, -- connect params - hfromdom, -- hash key - true, -- is write - dmarc_report_cb, --callback - 'EVALSHA', -- command - {take_report_sha, 2, idx_key, dmarc_domain_key, hfromdom, report_data} -- arguments - ) - if not ret then - rspamd_logger.errx(task, 'Unable to schedule redis request') - end + rspamd_redis.exec_redis_script(take_report_id, {task = task, is_write = true}, dmarc_report_cb, + {2, idx_key, dmarc_domain_key, hfromdom, report_data}) end end @@ -625,9 +590,7 @@ if opts['reporting'] == true then rspamd_logger.errx(rspamd_config, 'cannot parse servers parameter') elseif not opts['send_reports'] then dmarc_reporting = true - rspamd_config:add_on_load(function(cfg, ev_base, worker) - load_scripts(cfg, ev_base) - end) + take_report_id = rspamd_redis.add_redis_script(take_report_script, redis_params) else dmarc_reporting = true if type(opts['report_settings']) == 'table' then @@ -641,8 +604,8 @@ if opts['reporting'] == true then return end end + take_report_id = rspamd_redis.add_redis_script(take_report_script, redis_params) rspamd_config:add_on_load(function(cfg, ev_base, worker) - load_scripts(cfg, ev_base) if not worker:is_primary_controller() then return end local rresolver = rspamd_resolver.init(ev_base, rspamd_config) rspamd_config:register_finish_script(function ()