Software /
code /
prosody-modules
Comparison
mod_firewall/conditions.lib.lua @ 5535:eeccec0955a1
mod_firewall: Split some long lines [luacheck]
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 08 Jun 2023 16:17:25 +0100 |
parent | 5534:7b4e0c3642bf |
child | 5727:ad5c77793750 |
comparison
equal
deleted
inserted
replaced
5534:7b4e0c3642bf | 5535:eeccec0955a1 |
---|---|
312 end | 312 end |
313 if not name then | 313 if not name then |
314 error("Error parsing mark name, see documentation for usage examples"); | 314 error("Error parsing mark name, see documentation for usage examples"); |
315 end | 315 end |
316 if time then | 316 if time then |
317 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" }; | |
318 end | 320 end |
319 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)..")"); |
320 end | 322 end |
321 | 323 |
322 function condition_handlers.SENT_DIRECTED_PRESENCE_TO_SENDER() | 324 function condition_handlers.SENT_DIRECTED_PRESENCE_TO_SENDER() |
343 function condition_handlers.SCAN(scan_expression) | 345 function condition_handlers.SCAN(scan_expression) |
344 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+)$"); |
345 if not (search_name) then | 347 if not (search_name) then |
346 error("Error parsing SCAN expression, syntax: SEARCH for PATTERN in LIST"); | 348 error("Error parsing SCAN expression, syntax: SEARCH for PATTERN in LIST"); |
347 end | 349 end |
348 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 }; | |
349 end | 357 end |
350 | 358 |
351 -- COUNT: lines in body < 10 | 359 -- COUNT: lines in body < 10 |
352 local valid_comp_ops = { [">"] = ">", ["<"] = "<", ["="] = "==", ["=="] = "==", ["<="] = "<=", [">="] = ">=" }; | 360 local valid_comp_ops = { [">"] = ">", ["<"] = "<", ["="] = "==", ["=="] = "==", ["<="] = "<=", [">="] = ">=" }; |
353 function condition_handlers.COUNT(count_expression) | 361 function condition_handlers.COUNT(count_expression) |
363 if not value then | 371 if not value then |
364 error("Error parsing COUNT expression, expected value"); | 372 error("Error parsing COUNT expression, expected value"); |
365 end | 373 end |
366 local comp_op = comparator_expression:gsub("%s+", ""); | 374 local comp_op = comparator_expression:gsub("%s+", ""); |
367 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); |
368 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 }; | |
369 end | 382 end |
370 | 383 |
371 return condition_handlers; | 384 return condition_handlers; |