Comparison

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
comparison
equal deleted inserted replaced
121:74e5919e4737 128:77a1778b16e8
7 7
8 local log = require "util.logger".init("stanzarouter") 8 local log = require "util.logger".init("stanzarouter")
9 9
10 local st = require "util.stanza"; 10 local st = require "util.stanza";
11 local send = require "core.sessionmanager".send_to_session; 11 local send = require "core.sessionmanager".send_to_session;
12 local send_s2s = require "core.s2smanager".send_to_host;
13 local user_exists = require "core.usermanager".user_exists; 12 local user_exists = require "core.usermanager".user_exists;
14 13
15 local jid_split = require "util.jid".split; 14 local jid_split = require "util.jid".split;
16 local print = print; 15 local print = print;
17 16
116 if user then 115 if user then
117 local res = user.sessions[resource]; 116 local res = user.sessions[resource];
118 if not res then 117 if not res then
119 -- if we get here, resource was not specified or was unavailable 118 -- if we get here, resource was not specified or was unavailable
120 if stanza.name == "presence" then 119 if stanza.name == "presence" then
121 if stanza.attr.type == "probe" then 120 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then
122 if is_authorized_to_see_presence(origin, node, host) then 121 if stanza.attr.type == "probe" then
123 for k in pairs(user.sessions) do -- return presence for all resources 122 if is_authorized_to_see_presence(origin, node, host) then
124 if user.sessions[k].presence then 123 for k in pairs(user.sessions) do -- return presence for all resources
125 local pres = user.sessions[k].presence; 124 if user.sessions[k].presence then
126 pres.attr.to = origin.full_jid; 125 local pres = user.sessions[k].presence;
127 pres.attr.from = user.sessions[k].full_jid; 126 pres.attr.to = origin.full_jid;
128 send(origin, pres); 127 pres.attr.from = user.sessions[k].full_jid;
129 pres.attr.to = nil; 128 send(origin, pres);
130 pres.attr.from = nil; 129 pres.attr.to = nil;
130 pres.attr.from = nil;
131 end
131 end 132 end
133 else
134 send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"}));
132 end 135 end
133 else 136 elseif stanza.attr.type == "subscribe" then
134 send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); 137 -- TODO
135 end 138 elseif stanza.attr.type == "unsubscribe" then
136 else 139 -- TODO
140 elseif stanza.attr.type == "subscribed" then
141 -- TODO
142 elseif stanza.attr.type == "unsubscribed" then
143 -- TODO
144 end -- discard any other type
145 else -- sender is available or unavailable
137 for k in pairs(user.sessions) do -- presence broadcast to all user resources 146 for k in pairs(user.sessions) do -- presence broadcast to all user resources
138 if user.sessions[k].full_jid then 147 if user.sessions[k].full_jid then
139 stanza.attr.to = user.sessions[k].full_jid; 148 stanza.attr.to = user.sessions[k].full_jid;
140 send(user.sessions[k], stanza); 149 send(user.sessions[k], stanza);
141 end 150 end