# HG changeset patch # User Matthew Wild # Date 1458250147 0 # Node ID edf5cf3c474b5a32cdaa9abf54f14479d459956b # Parent 89363766202cede9076722b87a3d9dfedaab0d17 mod_firewall: Move meta() function to main module, and make it a global so libs can use it diff -r 89363766202c -r edf5cf3c474b mod_firewall/actions.lib.lua --- a/mod_firewall/actions.lib.lua Thu Mar 17 21:27:24 2016 +0000 +++ b/mod_firewall/actions.lib.lua Thu Mar 17 21:29:07 2016 +0000 @@ -1,13 +1,7 @@ +--luacheck: globals meta idsafe local action_handlers = {}; --- Run code through this to allow strings to contain code. e.g.: LOG=Received: $(stanza:top_tag()) -local function meta(s, extra) - return (s:gsub("$(%b())", [["..tostring(%1).."]]) - :gsub("$(%b<>)", [["..stanza:find("%1").."]]) - :gsub("$$(%a+)", extra or {})); -end - -- Takes an XML string and returns a code string that builds that stanza -- using st.stanza() local function compile_xml(data) diff -r 89363766202c -r edf5cf3c474b mod_firewall/conditions.lib.lua --- a/mod_firewall/conditions.lib.lua Thu Mar 17 21:27:24 2016 +0000 +++ b/mod_firewall/conditions.lib.lua Thu Mar 17 21:29:07 2016 +0000 @@ -1,3 +1,4 @@ +--luacheck: globals meta idsafe local condition_handlers = {}; local jid = require "util.jid"; diff -r 89363766202c -r edf5cf3c474b mod_firewall/mod_firewall.lua --- a/mod_firewall/mod_firewall.lua Thu Mar 17 21:27:24 2016 +0000 +++ b/mod_firewall/mod_firewall.lua Thu Mar 17 21:29:07 2016 +0000 @@ -42,6 +42,22 @@ return name:match("^%a[%w_]*$") end +-- Run quoted (%q) strings through this to allow them to contain code. e.g.: LOG=Received: $(stanza:top_tag()) +function meta(s, extra) + return (s:gsub("$(%b())", [["..tostring(%1).."]]) + :gsub("$(%b<>)", function (expr) + expr = expr:sub(2,-2); + if expr:match("^@") then + return "\"..stanza.attr["..(%q):format(expr:sub(2)).."]..\""; + end + return "\"..stanza:find("..("%q"):format(expr:sub(2, -2))..")..\""; + end) + :gsub("$$(%a+)", extra or {}) + :gsub([[^""%.%.]], "") + :gsub([[%.%.""$]], "")); +end + + -- Dependency locations: -- --