Software /
code /
prosody-modules
Comparison
mod_firewall/conditions.lib.lua @ 5676:62c6e17a5e9d
Merge
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 18 Sep 2023 08:24:19 -0500 |
parent | 5535:eeccec0955a1 |
child | 5727:ad5c77793750 |
comparison
equal
deleted
inserted
replaced
5675:eade7ff9f52c | 5676:62c6e17a5e9d |
---|---|
63 return compile_jid_match("to", to), { "split_to" }; | 63 return compile_jid_match("to", to), { "split_to" }; |
64 end | 64 end |
65 | 65 |
66 function condition_handlers.FROM(from) | 66 function condition_handlers.FROM(from) |
67 return compile_jid_match("from", from), { "split_from" }; | 67 return compile_jid_match("from", from), { "split_from" }; |
68 end | |
69 | |
70 function condition_handlers.FROM_FULL_JID() | |
71 return "not "..compile_jid_match_part("from_resource", nil), { "split_from" }; | |
68 end | 72 end |
69 | 73 |
70 function condition_handlers.FROM_EXACTLY(from) | 74 function condition_handlers.FROM_EXACTLY(from) |
71 local metadeps = {}; | 75 local metadeps = {}; |
72 return ("from == %s"):format(metaq(from, metadeps)), { "from", unpack(metadeps) }; | 76 return ("from == %s"):format(metaq(from, metadeps)), { "from", unpack(metadeps) }; |
308 end | 312 end |
309 if not name then | 313 if not name then |
310 error("Error parsing mark name, see documentation for usage examples"); | 314 error("Error parsing mark name, see documentation for usage examples"); |
311 end | 315 end |
312 if time then | 316 if time then |
313 return ("(current_timestamp - (session.firewall_marks and session.firewall_marks.%s or 0)) < %d"):format(idsafe(name), tonumber(time)), { "timestamp" }; | 317 return ([[( |
318 current_timestamp - (session.firewall_marks and session.firewall_marks.%s or 0) | |
319 ) < %d]]):format(idsafe(name), tonumber(time)), { "timestamp" }; | |
314 end | 320 end |
315 return ("not not (session.firewall_marks and session.firewall_marks."..idsafe(name)..")"); | 321 return ("not not (session.firewall_marks and session.firewall_marks."..idsafe(name)..")"); |
316 end | 322 end |
317 | 323 |
318 function condition_handlers.SENT_DIRECTED_PRESENCE_TO_SENDER() | 324 function condition_handlers.SENT_DIRECTED_PRESENCE_TO_SENDER() |
339 function condition_handlers.SCAN(scan_expression) | 345 function condition_handlers.SCAN(scan_expression) |
340 local search_name, pattern_name, list_name = scan_expression:match("(%S+) for (%S+) in (%S+)$"); | 346 local search_name, pattern_name, list_name = scan_expression:match("(%S+) for (%S+) in (%S+)$"); |
341 if not (search_name) then | 347 if not (search_name) then |
342 error("Error parsing SCAN expression, syntax: SEARCH for PATTERN in LIST"); | 348 error("Error parsing SCAN expression, syntax: SEARCH for PATTERN in LIST"); |
343 end | 349 end |
344 return ("scan_list(list_%s, %s)"):format(list_name, "tokens_"..search_name.."_"..pattern_name), { "scan_list", "tokens:"..search_name.."-"..pattern_name, "list:"..list_name }; | 350 return ("scan_list(list_%s, %s)"):format( |
351 list_name, | |
352 "tokens_"..search_name.."_"..pattern_name | |
353 ), { | |
354 "scan_list", | |
355 "tokens:"..search_name.."-"..pattern_name, "list:"..list_name | |
356 }; | |
345 end | 357 end |
346 | 358 |
347 -- COUNT: lines in body < 10 | 359 -- COUNT: lines in body < 10 |
348 local valid_comp_ops = { [">"] = ">", ["<"] = "<", ["="] = "==", ["=="] = "==", ["<="] = "<=", [">="] = ">=" }; | 360 local valid_comp_ops = { [">"] = ">", ["<"] = "<", ["="] = "==", ["=="] = "==", ["<="] = "<=", [">="] = ">=" }; |
349 function condition_handlers.COUNT(count_expression) | 361 function condition_handlers.COUNT(count_expression) |
359 if not value then | 371 if not value then |
360 error("Error parsing COUNT expression, expected value"); | 372 error("Error parsing COUNT expression, expected value"); |
361 end | 373 end |
362 local comp_op = comparator_expression:gsub("%s+", ""); | 374 local comp_op = comparator_expression:gsub("%s+", ""); |
363 assert(valid_comp_ops[comp_op], "Error parsing COUNT expression, unknown comparison operator: "..comp_op); | 375 assert(valid_comp_ops[comp_op], "Error parsing COUNT expression, unknown comparison operator: "..comp_op); |
364 return ("it_count(search_%s:gmatch(pattern_%s)) %s %d"):format(search_name, pattern_name, comp_op, value), { "it_count", "search:"..search_name, "pattern:"..pattern_name }; | 376 return ("it_count(search_%s:gmatch(pattern_%s)) %s %d"):format( |
377 search_name, pattern_name, comp_op, value | |
378 ), { | |
379 "it_count", | |
380 "search:"..search_name, "pattern:"..pattern_name | |
381 }; | |
365 end | 382 end |
366 | 383 |
367 return condition_handlers; | 384 return condition_handlers; |