Merge with trunk.

Fri, 29 Jan 2010 21:15:33 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Fri, 29 Jan 2010 21:15:33 +0500
changeset 2533
d6ca46b834d9
parent 2532
b1b1b4a7db26 (diff)
parent 2529
7968e8b3ecf9 (current diff)
child 2534
1f46a9d9b16a

Merge with trunk.

--- a/core/stanza_router.lua	Fri Jan 29 15:13:06 2010 +0000
+++ b/core/stanza_router.lua	Fri Jan 29 21:15:33 2010 +0500
@@ -98,7 +98,7 @@
 				return; -- FIXME what should we do here? does this work with subdomains?
 			end
 		end
-		core_post_stanza(origin, stanza);
+		core_post_stanza(origin, stanza, origin.full_jid);
 	else
 		local h = hosts[stanza.attr.to or origin.host or origin.to_host];
 		if h then
@@ -119,7 +119,7 @@
 	end
 end
 
-function core_post_stanza(origin, stanza)
+function core_post_stanza(origin, stanza, preevents)
 	local to = stanza.attr.to;
 	local node, host, resource = jid_split(to);
 	local to_bare = node and (node.."@"..host) or host; -- bare JID
@@ -143,7 +143,7 @@
 	end
 
 	local event_data = {origin=origin, stanza=stanza};
-	if origin.full_jid == stanza.attr.from then -- c2s connection
+	if preevents then -- c2s connection
 		if hosts[origin.host].events.fire_event('pre-'..stanza.name..to_type, event_data) then return; end -- do preprocessing
 	end
 	local h = hosts[to_bare] or hosts[host or origin.host];
--- a/plugins/mod_presence.lua	Fri Jan 29 15:13:06 2010 +0000
+++ b/plugins/mod_presence.lua	Fri Jan 29 21:15:33 2010 +0500
@@ -76,6 +76,7 @@
 		end
 	end
 	if stanza.attr.type == nil and not origin.presence then -- initial presence
+		origin.presence = stanza; -- FIXME repeated later
 		local probe = st.presence({from = origin.full_jid, type = "probe"});
 		for jid, item in pairs(roster) do -- probe all contacts we are subscribed to
 			if item.subscription == "both" or item.subscription == "to" then
@@ -309,13 +310,6 @@
 	end
 	return true;
 end);
-module:hook("presence/host", function (data)
-	local stanza = data.stanza;
-	local reply = st.reply(stanza);
-	reply.attr.type = "unsubscribed";
-	handle_inbound_presence_subscriptions_and_probes(data.origin, reply, jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), core_route_stanza);
-	return true;
-end);
 module:hook("presence/full", function(data)
 	-- inbound presence to full JID recieved
 	local origin, stanza = data.origin, data.stanza;
@@ -333,6 +327,20 @@
 	end -- resource not online, discard
 	return true;
 end);
+module:hook("presence/host", function(data)
+	-- inbound presence to the host
+	local origin, stanza = data.origin, data.stanza;
+	
+	local from_bare = jid_bare(stanza.attr.from);
+	local t = stanza.attr.type;
+	if t == "probe" then
+		core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id }));
+	elseif t == "subscribe" then
+		core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id, type = "subscribed" }));
+		core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id }));
+	end
+	return true;
+end);
 
 module:hook("resource-unbind", function(event)
 	local session, err = event.session, event.error;

mercurial