changeset 603:efc9d88b70ab

merged.
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 09 Feb 2012 00:54:39 +0000
parents 00590d492a5b (diff) 072b05999b4b (current diff)
children 17e879822700
files
diffstat 3 files changed, 16 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mod_register_json/mod_register_json.lua	Tue Feb 07 20:01:57 2012 +0100
+++ b/mod_register_json/mod_register_json.lua	Thu Feb 09 00:54:39 2012 +0000
@@ -75,17 +75,14 @@
 			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 }
+					recent_ips[req_body["ip"]] = os_time()
 				else
-					local ip = recent_ips[req_body["ip"]]
-					ip.count = ip.count + 1
-
-					if os_time() - ip.time < throttle_time then
-						ip.time = os_time()
+					if os_time() - recent_ips[req_body["ip"]] < throttle_time then
+						recent_ips[req_body["ip"]] = os_time()
 						module:log("warn", "JSON Registration request from %s has been throttled.", req_body["ip"])
 						return http_response(503, "Woah... How many users you want to register..? Request throttled, wait a bit and try again.")
 					end
-					ip.time = os_time()
+					recent_ips[req_body["ip"]] = os_time()
 				end
 			end
 
@@ -116,7 +113,7 @@
 end
 
 -- Set it up!
-function cleanup() -- it could be better if module:hook("module-unloaded", ...) actually worked.
+function regj_cleanup() -- it could be better if module:hook("module-unloaded", ...) actually worked.
 	module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.")
 	for _, options in ipairs(ports) do
 		if options.port then
@@ -125,7 +122,7 @@
 	end
 
 	-- if there are no handlers left clean and close the socket, doesn't work with server_event
-	local event = module:get_option_boolen("use_libevent", false)
+	local event = require "core.configmanager".get("*", "core", "use_libevent")
 
 	if not event then
 		for _, options in ipairs(ports) do
@@ -140,7 +137,7 @@
 		end
 	end
 
-	prosody.events.remove_handler("module-unloaded", cleanup)
+	prosody.events.remove_handler("module-unloaded", regj_cleanup)
 end
 
 function setup()
@@ -150,7 +147,7 @@
 			else ports[id].port = 9443 end
 		elseif options.port == 9280 and options.ssl then ports[id].port = 9443 end end
 	httpserver.new_from_config(ports, handle_req, { base = "register_account" })
-	prosody.events.add_handler("module-unloaded", cleanup)
+	prosody.events.add_handler("module-unloaded", regj_cleanup)
 end
 
 if prosody.start_time then -- already started
--- a/mod_server_status/mod_server_status.lua	Tue Feb 07 20:01:57 2012 +0100
+++ b/mod_server_status/mod_server_status.lua	Thu Feb 09 00:54:39 2012 +0000
@@ -130,7 +130,7 @@
 -- initialization.
 -- init http interface
 
-function cleanup() -- handy, recycled from mod_register_json
+function stats_cleanup() -- handy, recycled from mod_register_json
         module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.")
         for _, options in ipairs(ports) do
                 if options.port then
@@ -138,7 +138,7 @@
                 end
         end
 
-	local event = module:get_option_boolen("use_libevent", false)
+	local event = require "core.configmanager".get("*", "core", "use_libevent")
 
 	-- if there're no handlers left clean the socket, not sure if it works with server_select
 	if not event then
@@ -154,12 +154,12 @@
 	        end
 	end
 
-        prosody.events.remove_handler("module-unloaded", cleanup)
+        prosody.events.remove_handler("module-unloaded", stats_cleanup)
 end
 
 local function setup()
 	httpserver.new_from_config(ports, request, { base = "server-status" })
-	prosody.events.add_handler("module-unloaded", cleanup)
+	prosody.events.add_handler("module-unloaded", stats_cleanup)
 end
 
 if prosody.start_time then
--- a/mod_stanza_counter/mod_stanza_counter_http.lua	Tue Feb 07 20:01:57 2012 +0100
+++ b/mod_stanza_counter/mod_stanza_counter_http.lua	Thu Feb 09 00:54:39 2012 +0000
@@ -44,7 +44,7 @@
 -- initialization.
 -- init http and cleanup interface
 
-function cleanup() -- recycled from mod_register_json, it's handy
+function sc_cleanup() -- recycled from mod_register_json, it's handy
         module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.")
         for _, options in ipairs(ports) do
                 if options.port then
@@ -53,7 +53,7 @@
         end
 
         -- if there are no handlers left clean and close the socket, doesn't work with server_event
-        local event = module:get_option_boolen("use_libevent", false)
+        local event = require "core.configmanager".get("*", "core", "use_libevent")
 
         if not event then
                 for _, options in ipairs(ports) do
@@ -68,12 +68,12 @@
                 end
         end
 
-        prosody.events.remove_handler("module-unloaded", cleanup)
+        prosody.events.remove_handler("module-unloaded", sc_cleanup)
 end
 
 local function setup()
 	httpserver.new_from_config(ports, req, { base = "stanza-counter" })
-	prosody.events.add_handler("module-unloaded", cleanup)
+	prosody.events.add_handler("module-unloaded", sc_cleanup)
 end
 
 -- set it