Software /
code /
prosody
Comparison
core/stanza_router.lua @ 3539:8bbd965267b2
modulemanager, stanza_router: Moved modulemanager.handle_stanza to stanza_router, as a local function handle_unhandled_stanza. modulemanager is no longer a dependency of stanza_router.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 16 Oct 2010 08:34:32 +0500 |
parent | 2951:294c359a05f5 |
child | 3586:78ed7ad330ab |
comparison
equal
deleted
inserted
replaced
3538:3ea38f44420c | 3539:8bbd965267b2 |
---|---|
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; | 14 local send_s2s = require "core.s2smanager".send_to_host; |
15 local modules_handle_stanza = require "core.modulemanager".handle_stanza; | |
16 local component_handle_stanza = require "core.componentmanager".handle_stanza; | 15 local component_handle_stanza = require "core.componentmanager".handle_stanza; |
17 local jid_split = require "util.jid".split; | 16 local jid_split = require "util.jid".split; |
18 local jid_prepped_split = require "util.jid".prepped_split; | 17 local jid_prepped_split = require "util.jid".prepped_split; |
19 | 18 |
20 local full_sessions = _G.prosody.full_sessions; | 19 local full_sessions = _G.prosody.full_sessions; |
21 local bare_sessions = _G.prosody.bare_sessions; | 20 local bare_sessions = _G.prosody.bare_sessions; |
21 | |
22 local function handle_unhandled_stanza(host, origin, stanza) | |
23 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns or "jabber:client", origin.type; | |
24 if name == "iq" and xmlns == "jabber:client" then | |
25 if stanza.attr.type == "get" or stanza.attr.type == "set" then | |
26 xmlns = stanza.tags[1].attr.xmlns or "jabber:client"; | |
27 log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns); | |
28 else | |
29 log("debug", "Discarding %s from %s of type: %s", name, origin_type, stanza.attr.type); | |
30 return true; | |
31 end | |
32 end | |
33 if stanza.attr.xmlns == nil then | |
34 log("debug", "Unhandled %s stanza: %s; xmlns=%s", origin.type, stanza.name, xmlns); -- we didn't handle it | |
35 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then | |
36 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
37 end | |
38 elseif not((name == "features" or name == "error") and xmlns == "http://etherx.jabber.org/streams") then -- FIXME remove check once we handle S2S features | |
39 log("warn", "Unhandled %s stream element: %s; xmlns=%s: %s", origin.type, stanza.name, xmlns, tostring(stanza)); -- we didn't handle it | |
40 origin:close("unsupported-stanza-type"); | |
41 end | |
42 end | |
22 | 43 |
23 function core_process_stanza(origin, stanza) | 44 function core_process_stanza(origin, stanza) |
24 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag()) | 45 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag()) |
25 | 46 |
26 -- TODO verify validity of stanza (as well as JID validity) | 47 -- TODO verify validity of stanza (as well as JID validity) |
112 event = "stanza/"..xmlns..":"..stanza.name; | 133 event = "stanza/"..xmlns..":"..stanza.name; |
113 end | 134 end |
114 if h.events.fire_event(event, {origin = origin, stanza = stanza}) then return; end | 135 if h.events.fire_event(event, {origin = origin, stanza = stanza}) then return; end |
115 end | 136 end |
116 if host and not hosts[host] then host = nil; end -- COMPAT: workaround for a Pidgin bug which sets 'to' to the SRV result | 137 if host and not hosts[host] then host = nil; end -- COMPAT: workaround for a Pidgin bug which sets 'to' to the SRV result |
117 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); | 138 handle_unhandled_stanza(host or origin.host or origin.to_host, origin, stanza); |
118 end | 139 end |
119 end | 140 end |
120 | 141 |
121 function core_post_stanza(origin, stanza, preevents) | 142 function core_post_stanza(origin, stanza, preevents) |
122 local to = stanza.attr.to; | 143 local to = stanza.attr.to; |
154 | 175 |
155 if h.type == "component" then | 176 if h.type == "component" then |
156 component_handle_stanza(origin, stanza); | 177 component_handle_stanza(origin, stanza); |
157 return; | 178 return; |
158 end | 179 end |
159 modules_handle_stanza(h.host, origin, stanza); | 180 handle_unhandled_stanza(h.host, origin, stanza); |
160 else | 181 else |
161 core_route_stanza(origin, stanza); | 182 core_route_stanza(origin, stanza); |
162 end | 183 end |
163 end | 184 end |
164 | 185 |