changeset 550:d8143f627f9f

mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
author Marco Cirillo <maranda@lightwitch.org>
date Sat, 14 Jan 2012 19:56:24 +0000
parents fc5df35a3fe4
children 859bf77b9fbf
files mod_register_json/mod_register_json.lua
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_register_json/mod_register_json.lua	Sat Jan 14 20:50:24 2012 +0100
+++ b/mod_register_json/mod_register_json.lua	Sat Jan 14 19:56:24 2012 +0000
@@ -19,8 +19,8 @@
 
 local set_realm_name = module:get_option("reg_servlet_realm") or "Restricted"
 local throttle_time = module:get_option("reg_servlet_ttime") or false
-local whitelist = module:get_option("reg_servlet_wl") or {}
-local blacklist = module:get_option("reg_servlet_bl") or {}
+local whitelist = module:get_option_set("reg_servlet_wl", {})
+local blacklist = module:get_option_set("reg_servlet_bl", {})
 local recent_ips = {}
 
 -- Begin
@@ -71,8 +71,8 @@
 			return http_response(401, "I obey only to my masters... Have a nice day.")
 		else	
 			-- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code)
-			if blacklist[req_body["ip"]] then module:log("warn", "Attempt of reg. submission to the JSON servlet from blacklisted address: %s", req_body["ip"]) ; return http_response(403, "The specified address is blacklisted, sorry sorry.") end
-			if throttle_time and not whitelist[req_body["ip"]] then
+			if blacklist:contains(req_body["ip"]) then module:log("warn", "Attempt of reg. submission to the JSON servlet from blacklisted address: %s", req_body["ip"]) ; return http_response(403, "The specified address is blacklisted, sorry sorry.") end
+			if throttle_time and not whitelist:contains(req_body["ip"]) then
 				if not recent_ips[req_body["ip"]] then
 					recent_ips[req_body["ip"]] = { time = os_time(), count = 1 }
 				else