Mercurial > prosody-modules
comparison mod_firewall/conditions.lib.lua @ 2342:6848297cf40a
mod_firewall: Add conditions for testing whether a sender of a stanza is in the recipient's roster (or in a certain roster group)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 Nov 2016 12:46:11 +0000 |
parents | 21bc4d7cddae |
children | c065ab67d807 |
comparison
equal
deleted
inserted
replaced
2341:52dd2a51dac8 | 2342:6848297cf40a |
---|---|
1 --luacheck: globals meta idsafe | 1 --luacheck: globals meta idsafe |
2 local condition_handlers = {}; | 2 local condition_handlers = {}; |
3 | 3 |
4 local jid = require "util.jid"; | 4 local jid = require "util.jid"; |
5 | |
6 -- Helper to convert user-input strings (yes/true//no/false) to a bool | |
7 local function string_to_boolean(s) | |
8 s = s:lower(); | |
9 return s == "yes" or s == "true"; | |
10 end | |
5 | 11 |
6 -- Return a code string for a condition that checks whether the contents | 12 -- Return a code string for a condition that checks whether the contents |
7 -- of variable with the name 'name' matches any of the values in the | 13 -- of variable with the name 'name' matches any of the values in the |
8 -- comma/space/pipe delimited list 'values'. | 14 -- comma/space/pipe delimited list 'values'. |
9 local function compile_comparison_list(name, values) | 15 local function compile_comparison_list(name, values) |
86 return zone_check(zone, "to"); | 92 return zone_check(zone, "to"); |
87 end | 93 end |
88 | 94 |
89 function condition_handlers.LEAVING(zone) | 95 function condition_handlers.LEAVING(zone) |
90 return zone_check(zone, "from"); | 96 return zone_check(zone, "from"); |
97 end | |
98 | |
99 function condition_handlers.IN_ROSTER(yes_no) | |
100 local in_roster_requirement = string_to_boolean(yes_no); | |
101 return "not "..(in_roster_requirement and "not" or "").." roster_entry", { "roster_entry" }; | |
102 end | |
103 | |
104 function condition_handlers.IN_ROSTER_GROUP(group) | |
105 return ("not not (roster_entry and roster_entry.groups[%q])"):format(group), { "roster_entry" }; | |
91 end | 106 end |
92 | 107 |
93 function condition_handlers.PAYLOAD(payload_ns) | 108 function condition_handlers.PAYLOAD(payload_ns) |
94 return ("stanza:get_child(nil, %q)"):format(payload_ns); | 109 return ("stanza:get_child(nil, %q)"):format(payload_ns); |
95 end | 110 end |