Software /
code /
prosody
Comparison
core/stanza_router.lua @ 186:bfa8a30ea488
sends2s -> s2s_session.send(), s2s_session.send() -> s2s_session.sends2s()
Should fix outward routing problems.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 30 Oct 2008 21:11:22 +0000 |
parent | 178:8315cf03f304 |
child | 187:2e16e5077d8f |
comparison
equal
deleted
inserted
replaced
185:a67c88ce1c6a | 186:bfa8a30ea488 |
---|---|
6 require "core.servermanager" | 6 require "core.servermanager" |
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 |
12 local send_s2s = require "core.s2smanager".send_to_host; | |
13 function send(session, stanza) | |
14 if session.type == "c2s" then | |
15 _send(session, stanza); | |
16 else | |
17 local xmlns = stanza.attr.xmlns; | |
18 --stanza.attr.xmlns = "jabber:server"; | |
19 stanza.attr.xmlns = nil; | |
20 log("debug", "sending s2s stanza: %s", tostring(stanza)); | |
21 send_s2s(session.host, host, stanza); -- TODO handle remote routing errors | |
22 stanza.attr.xmlns = xmlns; -- reset | |
23 end | |
24 end | |
25 local user_exists = require "core.usermanager".user_exists; | 12 local user_exists = require "core.usermanager".user_exists; |
26 | 13 |
27 local rostermanager = require "core.rostermanager"; | 14 local rostermanager = require "core.rostermanager"; |
28 local sessionmanager = require "core.sessionmanager"; | 15 local sessionmanager = require "core.sessionmanager"; |
29 | 16 |
140 type = "valid" | 127 type = "valid" |
141 else | 128 else |
142 type = "invalid" | 129 type = "invalid" |
143 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); | 130 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
144 end | 131 end |
145 origin.send(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); | 132 origin.sends2s(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); |
146 elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then | 133 elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then |
147 -- he wants to be identified through dialback | 134 -- he wants to be identified through dialback |
148 -- We need to check the key with the Authoritative server | 135 -- We need to check the key with the Authoritative server |
149 local attr = stanza.attr; | 136 local attr = stanza.attr; |
150 origin.from_host = attr.from; | 137 origin.from_host = attr.from; |
173 else | 160 else |
174 -- Warn the original connection that is was not verified successfully | 161 -- Warn the original connection that is was not verified successfully |
175 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); | 162 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); |
176 valid = "invalid"; | 163 valid = "invalid"; |
177 end | 164 end |
178 origin.dialback_verifying.send(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); | 165 origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); |
179 end | 166 end |
180 end | 167 end |
181 else | 168 else |
182 log("warn", "Unhandled origin: %s", origin.type); | 169 log("warn", "Unhandled origin: %s", origin.type); |
183 end | 170 end |
192 for k, session in pairs(u.sessions) do | 179 for k, session in pairs(u.sessions) do |
193 local pres = session.presence; | 180 local pres = session.presence; |
194 if pres then | 181 if pres then |
195 pres.attr.to = jid; | 182 pres.attr.to = jid; |
196 pres.attr.from = session.full_jid; | 183 pres.attr.from = session.full_jid; |
197 send(recipient_session, pres); | 184 recipient_session.send(pres); |
198 pres.attr.to = nil; | 185 pres.attr.to = nil; |
199 pres.attr.from = nil; | 186 pres.attr.from = nil; |
200 count = count + 1; | 187 count = count + 1; |
201 end | 188 end |
202 end | 189 end |
316 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); | 303 handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); |
317 else -- sender is available or unavailable | 304 else -- sender is available or unavailable |
318 for k in pairs(user.sessions) do -- presence broadcast to all user resources. FIXME should this be just for available resources? Do we need to check subscription? | 305 for k in pairs(user.sessions) do -- presence broadcast to all user resources. FIXME should this be just for available resources? Do we need to check subscription? |
319 if user.sessions[k].full_jid then | 306 if user.sessions[k].full_jid then |
320 stanza.attr.to = user.sessions[k].full_jid; -- reset at the end of function | 307 stanza.attr.to = user.sessions[k].full_jid; -- reset at the end of function |
321 send(user.sessions[k], stanza); | 308 user.sessions[k].send(stanza); |
322 end | 309 end |
323 end | 310 end |
324 end | 311 end |
325 elseif stanza.name == "message" then -- select a resource to recieve message | 312 elseif stanza.name == "message" then -- select a resource to recieve message |
326 for k in pairs(user.sessions) do | 313 for k in pairs(user.sessions) do |
328 res = user.sessions[k]; | 315 res = user.sessions[k]; |
329 break; | 316 break; |
330 end | 317 end |
331 end | 318 end |
332 -- TODO find resource with greatest priority | 319 -- TODO find resource with greatest priority |
333 send(res, stanza); | 320 res.send(stanza); |
334 else | 321 else |
335 -- TODO send IQ error | 322 -- TODO send IQ error |
336 end | 323 end |
337 else | 324 else |
338 -- User + resource is online... | 325 -- User + resource is online... |
339 stanza.attr.to = res.full_jid; -- reset at the end of function | 326 stanza.attr.to = res.full_jid; -- reset at the end of function |
340 send(res, stanza); -- Yay \o/ | 327 res.send(stanza); -- Yay \o/ |
341 end | 328 end |
342 else | 329 else |
343 -- user not online | 330 -- user not online |
344 if user_exists(node, host) then | 331 if user_exists(node, host) then |
345 if stanza.name == "presence" then | 332 if stanza.name == "presence" then |
355 end | 342 end |
356 else -- user does not exist | 343 else -- user does not exist |
357 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses? | 344 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses? |
358 if stanza.name == "presence" then | 345 if stanza.name == "presence" then |
359 if stanza.attr.type == "probe" then | 346 if stanza.attr.type == "probe" then |
360 send(origin, st.presence({from = to_bare, to = from_bare, type = "unsubscribed"})); | 347 origin.send(st.presence({from = to_bare, to = from_bare, type = "unsubscribed"})); |
361 end | 348 end |
362 -- else ignore | 349 -- else ignore |
363 else | 350 else |
364 send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); | 351 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
365 end | 352 end |
366 end | 353 end |
367 end | 354 end |
368 elseif origin.type == "c2s" then | 355 elseif origin.type == "c2s" then |
369 -- Remote host | 356 -- Remote host |