# HG changeset patch # User Florian Zeitz # Date 1392567443 -3600 # Node ID 8a3f3f485675e7e33c4a745d103b07b18a1fbe99 # Parent e556219cb43d7af6f2a0564e8abf8a614e661be0 mod_firewall: Produce code with nicer indentation diff -r e556219cb43d -r 8a3f3f485675 mod_firewall/actions.lib.lua --- a/mod_firewall/actions.lib.lua Fri Feb 14 15:08:11 2014 +0100 +++ b/mod_firewall/actions.lib.lua Sun Feb 16 17:17:23 2014 +0100 @@ -123,8 +123,8 @@ reroute = ("newstanza.attr.to = %q; core_post_stanza(session, newstanza)"):format(to); deps[#deps+1] = "core_post_stanza"; end - return ([[local newstanza = st.%s; %s; %s ]]) - :format(make_new, reroute, drop and "return true;" or ""), deps; + return ([[local newstanza = st.%s; %s;%s]]) + :format(make_new, reroute, drop and " return true;" or ""), deps; end function action_handlers.BOUNCE(with) diff -r e556219cb43d -r 8a3f3f485675 mod_firewall/mod_firewall.lua --- a/mod_firewall/mod_firewall.lua Fri Feb 14 15:08:11 2014 +0100 +++ b/mod_firewall/mod_firewall.lua Sun Feb 16 17:17:23 2014 +0100 @@ -44,7 +44,7 @@ -- end local available_deps = { - st = { global_code = [[local st = require "util.stanza"]]}; + st = { global_code = [[local st = require "util.stanza";]]}; jid_split = { global_code = [[local jid_split = require "util.jid".split;]]; }; @@ -117,9 +117,9 @@ end if dep_info.local_code then if dep_param ~= "" then - table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code(dep_param).."\n\n\t"); + table.insert(code, "\n\t\t-- "..dep.."\n\t\t"..dep_info.local_code(dep_param).."\n"); else - table.insert(code, "\n\t-- "..dep.."\n\t"..dep_info.local_code.."\n\n\t"); + table.insert(code, "\n\t\t-- "..dep.."\n\t\t"..dep_info.local_code.."\n"); end end code.included_deps[dep] = true; @@ -283,7 +283,8 @@ for _, dep in ipairs(rule.deps) do include_dep(dep, code); end - local rule_code = table.concat(rule.actions, "\n\t"); + table.insert(code, "\n\t\t"); + local rule_code; if #rule.conditions > 0 then for i, condition in ipairs(rule.conditions) do local negated = condition:match("^not%(.+%)$"); @@ -296,13 +297,15 @@ n_conditions = n_conditions + 1; local name = "condition"..n_conditions; condition_cache[condition] = name; - table.insert(code, "local "..name.." = "..condition..";\n\t"); + table.insert(code, "local "..name.." = "..condition..";\n\t\t"); rule.conditions[i] = (negated and "not(" or "")..name..(negated and ")" or ""); end end - rule_code = "if "..table.concat(rule.conditions, " and ").." then\n\t" - ..rule_code - .."\n end\n"; + rule_code = "if "..table.concat(rule.conditions, " and ").." then\n\t\t\t" + ..table.concat(rule.actions, "\n\t\t\t") + .."\n\t\tend\n"; + else + rule_code = table.concat(rule.actions, "\n\t\t"); end table.insert(code, rule_code); end @@ -311,15 +314,13 @@ table.insert(code.global_header, 1, "local "..name:lower().."s = definitions."..name..";"); end - local code_string = [[return function (definitions, fire_event, log) - ]]..table.concat(code.global_header, "\n")..[[ - local db = require 'util.debug' - return function (event) - local stanza, session = event.stanza, event.origin; - - ]]..table.concat(code, " ")..[[ - end; - end]]; + local code_string = "return function (definitions, fire_event, log)\n\t" + ..table.concat(code.global_header, "\n\t") + .."\n\tlocal db = require 'util.debug';\n\n\t" + .."return function (event)\n\t\t" + .."local stanza, session = event.stanza, event.origin;\n" + ..table.concat(code, "") + .."\n\tend;\nend"; chain_handlers[chain_name] = code_string; end