Changeset

6647:0c363fddcdd9

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sun, 03 May 2015 18:39:27 +0200
parents 6636:441f8cb0deec (current diff) 6646:9795b8cf14f1 (diff)
children 6650:cf15b18e9810
files core/moduleapi.lua
diffstat 7 files changed, 108 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/core/moduleapi.lua	Mon Apr 27 00:03:14 2015 +0200
+++ b/core/moduleapi.lua	Sun May 03 18:39:27 2015 +0200
@@ -122,6 +122,18 @@
 	return self:unhook_object_event((hosts[self.host] or prosody).events, event, handler);
 end
 
+function api:wrap_object_event(events_object, event, handler)
+	return self:hook_object_event(assert(events_object.wrappers, "no wrappers"), event, handler);
+end
+
+function api:wrap_event(event, handler)
+	return self:wrap_object_event((hosts[self.host] or prosody).events, event, handler);
+end
+
+function api:wrap_global(event, handler)
+	return self:hook_object_event(prosody.events, event, handler, priority);
+end
+
 function api:require(lib)
 	local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment);
 	if not f then
@@ -395,6 +407,25 @@
 	return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name);
 end
 
+function api:measure_object_event(events_object, event_name, stat_name)
+	local m = self:measure(stat_name or event_name, "duration");
+	local function handler(handlers, event_name, event_data)
+		local finished = m();
+		local ret = handlers(event_name, event_data);
+		finished();
+		return ret;
+	end
+	return self:hook_object_event(events_object, event_name, handler);
+end
+
+function api:measure_event(event_name, stat_name)
+	return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler);
+end
+
+function api:measure_global_event(event_name, stat_name)
+	return self:hook_object_event(prosody.events.wrappers, event_name, handler);
+end
+
 function api.init(mm)
 	modulemanager = mm;
 	return api;
--- a/net/dns.lua	Mon Apr 27 00:03:14 2015 +0200
+++ b/net/dns.lua	Sun May 03 18:39:27 2015 +0200
@@ -226,7 +226,7 @@
 
 
 function dns.random(...)    -- - - - - - - - - - - - - - - - - - -  dns.random
-	math.randomseed(math.floor(10000*socket.gettime()) % 0x100000000);
+	math.randomseed(math.floor(10000*socket.gettime()) % 0x80000000);
 	dns.random = math.random;
 	return dns.random(...);
 end
--- a/prosodyctl	Mon Apr 27 00:03:14 2015 +0200
+++ b/prosodyctl	Sun May 03 18:39:27 2015 +0200
@@ -1146,7 +1146,7 @@
 						end
 						if (not (config.get(host, "anonymous_login")
 							or config.get(host, "authentication") == "anonymous"))
-							and not x509_verify_identity(host, "_xmpp-client", cert) then
+							and not x509_verify_identity(host, "_xmpp-server", cert) then
 							print("    Not vaild for server-to-server connections to "..host..".")
 							cert_ok = false
 						end
--- a/util-src/encodings.c	Mon Apr 27 00:03:14 2015 +0200
+++ b/util-src/encodings.c	Sun May 03 18:39:27 2015 +0200
@@ -476,14 +476,15 @@
 static int Lidna_to_ascii(lua_State* L) {	/** idna.to_ascii(s) */
 	size_t len;
 	const char* s = check_utf8(L, 1, &len);
+	char* output = NULL;
+	int ret;
 
 	if(s == NULL || len != strlen(s)) {
 		lua_pushnil(L);
 		return 1; /* TODO return error message */
 	}
 
-	char* output = NULL;
-	int ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
+	ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES);
 
 	if(ret == IDNA_SUCCESS) {
 		lua_pushstring(L, output);
--- a/util-src/pposix.c	Mon Apr 27 00:03:14 2015 +0200
+++ b/util-src/pposix.c	Sun May 03 18:39:27 2015 +0200
@@ -750,7 +750,10 @@
 		lua_pushstring(L, strerror(ret));
 		/* posix_fallocate() can leave a bunch of NULs at the end, so we cut that
 		 * this assumes that offset == length of the file */
-		ftruncate(fileno(f), offset);
+		if(ftruncate(fileno(f), offset) != 0) {
+			lua_pushstring(L, strerror(errno));
+			return 3;
+		}
 		return 2;
 	}
 }
--- a/util/datamanager.lua	Mon Apr 27 00:03:14 2015 +0200
+++ b/util/datamanager.lua	Sun May 03 18:39:27 2015 +0200
@@ -293,7 +293,7 @@
 
 	local mode, err = lfs.attributes(store_dir, "mode");
 	if not mode then
-		return function() log("debug", err or (store_dir .. " does not exist")) end
+		return function() log("debug", "%s", err or (store_dir .. " does not exist")) end
 	end
 	local next, state = lfs.dir(store_dir);
 	return function(state)
--- a/util/events.lua	Mon Apr 27 00:03:14 2015 +0200
+++ b/util/events.lua	Sun May 03 18:39:27 2015 +0200
@@ -17,6 +17,8 @@
 
 function new()
 	local handlers = {};
+	local global_wrappers;
+	local wrappers = {};
 	local event_map = {};
 	local function _rebuild_index(handlers, event)
 		local _handlers = event_map[event];
@@ -60,7 +62,7 @@
 			remove_handler(event, handler);
 		end
 	end;
-	local function fire_event(event_name, event_data)
+	local function _fire_event(event_name, event_data)
 		local h = handlers[event_name];
 		if h then
 			for i=1,#h do
@@ -69,11 +71,75 @@
 			end
 		end
 	end;
+	local function fire_event(event_name, event_data)
+		local w = wrappers[event_name] or global_wrappers;
+		if w then
+			local curr_wrapper = #w;
+			local function c(event_name, event_data)
+				curr_wrapper = curr_wrapper - 1;
+				if curr_wrapper == 0 then
+					if global_wrappers == nil or w == global_wrappers then
+						return _fire_event(event_name, event_data);
+					end
+					w, curr_wrapper = global_wrappers, #global_wrappers;
+					return w[curr_wrapper](c, event_name, event_data);
+				else
+					return w[curr_wrapper](c, event_name, event_data);
+				end
+			end
+			return w[curr_wrapper](c, event_name, event_data);
+		end
+		return _fire_event(event_name, event_data);
+	end
+	local function add_wrapper(event_name, wrapper)
+		local w;
+		if event_name == false then
+			w = global_wrappers;
+			if not w then
+				w = {};
+				global_wrappers = w;
+			end
+		else
+			w = wrappers[event_name];
+			if not w then
+				w = {};
+				wrappers[event_name] = w;
+			end
+		end
+		w[#w+1] = wrapper;
+	end
+	local function remove_wrapper(event_name, wrapper)
+		local w;
+		if event_name == false then
+			w = global_wrappers;
+		else
+			w = wrappers[event_name];
+		end
+		if not w then return; end
+		for i = #w, 1 do
+			if w[i] == wrapper then
+				table.remove(w, i);
+			end
+		end
+		if #w == 0 then
+			if event_name == nil then
+				global_wrappers = nil;
+			else
+				wrappers[event_name] = nil;
+			end
+		end
+	end
 	return {
 		add_handler = add_handler;
 		remove_handler = remove_handler;
 		add_handlers = add_handlers;
 		remove_handlers = remove_handlers;
+		wrappers = {
+			add_handler = add_wrapper;
+			remove_handler = remove_wrapper;
+		};
+		add_wrapper = add_wrapper;
+		remove_wrapper = remove_wrapper;
 		fire_event = fire_event;
 		_handlers = handlers;
 		_event_map = event_map;