Mercurial > prosody-hg
comparison core/stanza_router.lua @ 4797:e239668aa6d2
Merge 0.9->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 29 Apr 2012 02:10:55 +0100 |
| parents | 6ceabde7af91 |
| children | 897ec7dcdaa6 |
comparison
equal
deleted
inserted
replaced
| 4796:04a34287dc12 | 4797:e239668aa6d2 |
|---|---|
| 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; |
| 102 end | 101 end |
| 103 from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID | 102 from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID |
| 104 if from_resource then from = from_bare.."/"..from_resource; else from = from_bare; end | 103 if from_resource then from = from_bare.."/"..from_resource; else from = from_bare; end |
| 105 stanza.attr.from = from; | 104 stanza.attr.from = from; |
| 106 end | 105 end |
| 107 | |
| 108 --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us? | |
| 109 log("warn", "stanza recieved for a non-local server"); | |
| 110 return; -- FIXME what should we do here? | |
| 111 end]] -- FIXME | |
| 112 | 106 |
| 113 if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and xmlns == nil then | 107 if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and xmlns == nil then |
| 114 if origin.type == "s2sin" and not origin.dummy then | 108 if origin.type == "s2sin" and not origin.dummy then |
| 115 local host_status = origin.hosts[from_host]; | 109 local host_status = origin.hosts[from_host]; |
| 116 if not host_status or not host_status.authed then -- remote server trying to impersonate some other server? | 110 if not host_status or not host_status.authed then -- remote server trying to impersonate some other server? |
| 187 if not origin then return false; end | 181 if not origin then return false; end |
| 188 | 182 |
| 189 if hosts[host] then | 183 if hosts[host] then |
| 190 -- old stanza routing code removed | 184 -- old stanza routing code removed |
| 191 core_post_stanza(origin, stanza); | 185 core_post_stanza(origin, stanza); |
| 192 elseif origin.type == "c2s" then | 186 else |
| 193 -- Remote host | 187 log("debug", "Routing to remote..."); |
| 194 if not hosts[from_host] then | 188 if not hosts[from_host] then |
| 195 log("error", "No hosts[from_host] (please report): %s", tostring(stanza)); | 189 log("error", "No hosts[from_host] (please report): %s", tostring(stanza)); |
| 196 end | 190 else |
| 197 if (not hosts[from_host]) or (not hosts[from_host].disallow_s2s) then | |
| 198 local xmlns = stanza.attr.xmlns; | 191 local xmlns = stanza.attr.xmlns; |
| 199 --stanza.attr.xmlns = "jabber:server"; | |
| 200 stanza.attr.xmlns = nil; | 192 stanza.attr.xmlns = nil; |
| 201 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!) |
| 202 send_s2s(origin.host, host, stanza); -- TODO handle remote routing errors | |
| 203 stanza.attr.xmlns = xmlns; -- reset | 194 stanza.attr.xmlns = xmlns; -- reset |
| 204 else | 195 if routed == nil then |
| 205 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")); |
| 206 end | 197 end |
| 207 elseif origin.type == "component" or origin.type == "local" then | 198 end |
| 208 -- Route via s2s for components and modules | 199 end |
| 209 log("debug", "Routing outgoing stanza for %s to %s", from_host, host); | 200 end |
| 210 send_s2s(from_host, host, stanza); | |
| 211 else | |
| 212 log("warn", "received %s stanza from unhandled connection type: %s", tostring(stanza.name), tostring(origin.type)); | |
| 213 end | |
| 214 end |
