Changeset

1263:7797354dc9b5

Merge backout with following commits
author Matthew Wild <mwild1@gmail.com>
date Mon, 01 Jun 2009 02:06:02 +0100
parents 1261:497178e0ddbe (diff) 1262:0d94c57555d9 (current diff)
children 1264:498293bce4bf
files core/stanza_router.lua
diffstat 4 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/core/componentmanager.lua	Mon Jun 01 02:05:27 2009 +0100
+++ b/core/componentmanager.lua	Mon Jun 01 02:06:02 2009 +0100
@@ -89,6 +89,12 @@
 	if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
 		components[host] = component;
 		hosts[host] = session or create_component(host, component);
+		
+		-- Add events object if not already one
+		if not hosts[host].events then
+			hosts[host].events = events_new();
+		end
+		
 		-- add to disco_items
 		if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
 			disco_items:set(host:sub(host:find(".", 1, true)+1), host, true);
--- a/core/modulemanager.lua	Mon Jun 01 02:05:27 2009 +0100
+++ b/core/modulemanager.lua	Mon Jun 01 02:06:02 2009 +0100
@@ -49,6 +49,7 @@
 local features_table = multitable_new();
 local handler_table = multitable_new();
 local hooked = multitable_new();
+local hooks = multitable_new();
 local event_hooks = multitable_new();
 
 local NULL = {};
@@ -165,6 +166,13 @@
 		end
 	end
 	event_hooks:remove(host, name);
+	-- unhook event handlers hooked by module:hook
+	for event, handlers in pairs(hooks:get(host, name) or NULL) do
+		for handler in pairs(handlers or NULL) do
+			(hosts[host] or prosody).events.remove_handler(event, handler);
+		end
+	end
+	hooks:remove(host, name);
 	return true;
 end
 
@@ -356,6 +364,7 @@
 end
 
 function api:hook(event, handler)
+	hooks:set(self.host, self.name, event, handler, true);
 	(hosts[self.host] or prosody).events.add_handler(event, handler);
 end
 
--- a/core/stanza_router.lua	Mon Jun 01 02:05:27 2009 +0100
+++ b/core/stanza_router.lua	Mon Jun 01 02:06:02 2009 +0100
@@ -165,9 +165,6 @@
 		else
 			if h.events.fire_event(stanza.name..to_type, event_data) then return; end -- do processing
 		end
-	else -- non-local recipient
-		core_route_stanza(origin, stanza);
-		return;
 	end
 
 	if host and fire_event(host.."/"..stanza.name, event_data) then
--- a/plugins/mod_iq.lua	Mon Jun 01 02:05:27 2009 +0100
+++ b/plugins/mod_iq.lua	Mon Jun 01 02:06:02 2009 +0100
@@ -22,12 +22,20 @@
 
 	-- TODO if not user exists, return an error
 	-- TODO fire post processing events
-	-- TODO fire event with the xmlns:tag of the child, or with the id of errors and results
+	if #stanza.tags == 1 then
+		return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name);
+	else
+		return true; -- TODO do something with results and errors
+	end
 end);
 
 module:hook("iq/host", function(data)
 	-- IQ to a local host recieved
 	local origin, stanza = data.origin, data.stanza;
 
-	-- TODO fire event with the xmlns:tag of the child, or with the id of errors and results
+	if #stanza.tags == 1 then
+		return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name);
+	else
+		return true; -- TODO do something with results and errors
+	end
 end);