Software /
code /
prosody-modules
File
mod_firewall/definitions.lib.lua @ 2070:2356114ff505
mod_firewall: Optimize string match operations, string.find is faster than .match since no string is returned
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 11 Mar 2016 18:13:53 +0100 |
parent | 1863:92602cfac751 |
child | 2079:edec9de0220a |
line wrap: on
line source
local definition_handlers = {}; local set = require"util.set"; local new_throttle = require "util.throttle".create; function definition_handlers.ZONE(zone_name, zone_members) local zone_member_list = {}; for member in zone_members:gmatch("[^, ]+") do zone_member_list[#zone_member_list+1] = member; end return set.new(zone_member_list)._items; end function definition_handlers.RATE(name, line) local rate = assert(tonumber(line:match("([%d.]+)")), "Unable to parse rate"); local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1; return new_throttle(rate*burst, burst); end return definition_handlers;