Diff

core/stanza_router.lua @ 128:77a1778b16e8

Set things up for presence subscriptions. Remove reference to core.s2smanager.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 23 Oct 2008 18:36:10 +0500
parent 121:74e5919e4737
child 130:907cff6b5359
line wrap: on
line diff
--- a/core/stanza_router.lua	Thu Oct 23 04:06:51 2008 +0100
+++ b/core/stanza_router.lua	Thu Oct 23 18:36:10 2008 +0500
@@ -9,7 +9,6 @@
 
 local st = require "util.stanza";
 local send = require "core.sessionmanager".send_to_session;
-local send_s2s = require "core.s2smanager".send_to_host;
 local user_exists = require "core.usermanager".user_exists;
 
 local jid_split = require "util.jid".split;
@@ -118,22 +117,32 @@
 			if not res then
 				-- if we get here, resource was not specified or was unavailable
 				if stanza.name == "presence" then
-					if stanza.attr.type == "probe" then
-						if is_authorized_to_see_presence(origin, node, host) then
-							for k in pairs(user.sessions) do -- return presence for all resources
-								if user.sessions[k].presence then
-									local pres = user.sessions[k].presence;
-									pres.attr.to = origin.full_jid;
-									pres.attr.from = user.sessions[k].full_jid;
-									send(origin, pres);
-									pres.attr.to = nil;
-									pres.attr.from = nil;
+					if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then
+						if stanza.attr.type == "probe" then
+							if is_authorized_to_see_presence(origin, node, host) then
+								for k in pairs(user.sessions) do -- return presence for all resources
+									if user.sessions[k].presence then
+										local pres = user.sessions[k].presence;
+										pres.attr.to = origin.full_jid;
+										pres.attr.from = user.sessions[k].full_jid;
+										send(origin, pres);
+										pres.attr.to = nil;
+										pres.attr.from = nil;
+									end
 								end
+							else
+								send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"}));
 							end
-						else
-							send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"}));
-						end
-					else
+						elseif stanza.attr.type == "subscribe" then
+							-- TODO
+						elseif stanza.attr.type == "unsubscribe" then
+							-- TODO
+						elseif stanza.attr.type == "subscribed" then
+							-- TODO
+						elseif stanza.attr.type == "unsubscribed" then
+							-- TODO
+						end -- discard any other type
+					else -- sender is available or unavailable
 						for k in pairs(user.sessions) do -- presence broadcast to all user resources
 							if user.sessions[k].full_jid then
 								stanza.attr.to = user.sessions[k].full_jid;