Software /
code /
prosody
Comparison
core/stanza_router.lua @ 4554:6ceabde7af91
stanza_router: Replace s2s send logic with firing of a 'route/remote' event
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Jan 2012 16:25:21 +0000 |
parent | 4553:adcfdaffbccf |
child | 4816:897ec7dcdaa6 |
comparison
equal
deleted
inserted
replaced
4553:adcfdaffbccf | 4554:6ceabde7af91 |
---|---|
9 local log = require "util.logger".init("stanzarouter") | 9 local log = require "util.logger".init("stanzarouter") |
10 | 10 |
11 local hosts = _G.prosody.hosts; | 11 local hosts = _G.prosody.hosts; |
12 local tostring = tostring; | 12 local tostring = tostring; |
13 local st = require "util.stanza"; | 13 local st = require "util.stanza"; |
14 local send_s2s = require "core.s2smanager".send_to_host; | |
15 local jid_split = require "util.jid".split; | 14 local jid_split = require "util.jid".split; |
16 local jid_prepped_split = require "util.jid".prepped_split; | 15 local jid_prepped_split = require "util.jid".prepped_split; |
17 | 16 |
18 local full_sessions = _G.prosody.full_sessions; | 17 local full_sessions = _G.prosody.full_sessions; |
19 local bare_sessions = _G.prosody.bare_sessions; | 18 local bare_sessions = _G.prosody.bare_sessions; |
182 if not origin then return false; end | 181 if not origin then return false; end |
183 | 182 |
184 if hosts[host] then | 183 if hosts[host] then |
185 -- old stanza routing code removed | 184 -- old stanza routing code removed |
186 core_post_stanza(origin, stanza); | 185 core_post_stanza(origin, stanza); |
187 elseif origin.type == "c2s" then | 186 else |
188 -- Remote host | 187 log("debug", "Routing to remote..."); |
189 if not hosts[from_host] then | 188 if not hosts[from_host] then |
190 log("error", "No hosts[from_host] (please report): %s", tostring(stanza)); | 189 log("error", "No hosts[from_host] (please report): %s", tostring(stanza)); |
191 end | 190 else |
192 if (not hosts[from_host]) or (not hosts[from_host].disallow_s2s) then | |
193 local xmlns = stanza.attr.xmlns; | 191 local xmlns = stanza.attr.xmlns; |
194 --stanza.attr.xmlns = "jabber:server"; | |
195 stanza.attr.xmlns = nil; | 192 stanza.attr.xmlns = nil; |
196 log("debug", "sending s2s stanza: %s", tostring(stanza.top_tag and stanza:top_tag()) or stanza); | 193 local routed = prosody.events.fire_event("route/remote", { origin = origin, stanza = stanza, from_host = from_host, to_host = host }); --FIXME: Should be per-host (shared modules!) |
197 send_s2s(origin.host, host, stanza); -- TODO handle remote routing errors | |
198 stanza.attr.xmlns = xmlns; -- reset | 194 stanza.attr.xmlns = xmlns; -- reset |
199 else | 195 if routed == nil then |
200 core_route_stanza(hosts[from_host], st.error_reply(stanza, "cancel", "not-allowed", "Communication with remote servers is not allowed")); | 196 core_route_stanza(hosts[from_host], st.error_reply(stanza, "cancel", "not-allowed", "Communication with remote domains is not enabled")); |
201 end | 197 end |
202 elseif origin.type == "component" or origin.type == "local" then | 198 end |
203 -- Route via s2s for components and modules | 199 end |
204 log("debug", "Routing outgoing stanza for %s to %s", from_host, host); | 200 end |
205 send_s2s(from_host, host, stanza); | |
206 else | |
207 log("warn", "received %s stanza from unhandled connection type: %s", tostring(stanza.name), tostring(origin.type)); | |
208 end | |
209 end |