Software /
code /
prosody
Comparison
core/stanza_router.lua @ 1164:251954b07cae
stanza_router: Refactored core_handle_stanza, and added handling for unsupported top-level stanzas
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 16 May 2009 00:03:24 +0500 |
parent | 1163:8b4a57765b04 |
child | 1165:ec69bcc7ceb5 |
comparison
equal
deleted
inserted
replaced
1163:8b4a57765b04 | 1164:251954b07cae |
---|---|
41 | 41 |
42 local jid_split = require "util.jid".split; | 42 local jid_split = require "util.jid".split; |
43 local jid_prepped_split = require "util.jid".prepped_split; | 43 local jid_prepped_split = require "util.jid".prepped_split; |
44 local print = print; | 44 local print = print; |
45 local fire_event = require "core.eventmanager2".fire_event; | 45 local fire_event = require "core.eventmanager2".fire_event; |
46 local function checked_error_reply(origin, stanza) | |
47 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then | |
48 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? | |
49 end | |
50 end | |
51 | 46 |
52 function core_process_stanza(origin, stanza) | 47 function core_process_stanza(origin, stanza) |
53 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag()) | 48 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag()) |
54 | 49 |
55 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. | 50 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. |
140 end | 135 end |
141 | 136 |
142 -- This function handles stanzas which are not routed any further, | 137 -- This function handles stanzas which are not routed any further, |
143 -- that is, they are handled by this server | 138 -- that is, they are handled by this server |
144 function core_handle_stanza(origin, stanza) | 139 function core_handle_stanza(origin, stanza) |
145 -- Handlers | 140 if not modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then |
146 if modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then return; end | |
147 if origin.type == "c2s" or origin.type == "s2sin" then | |
148 if origin.type == "c2s" then | |
149 if stanza.name == "presence" and origin.roster then | |
150 if stanza.attr.type == nil or stanza.attr.type == "unavailable" and stanza.attr.type ~= "error" then | |
151 handle_normal_presence(origin, stanza, core_route_stanza); | |
152 else | |
153 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); | |
154 checked_error_reply(origin, stanza); | |
155 end | |
156 else | |
157 log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); | |
158 checked_error_reply(origin, stanza); | |
159 end | |
160 else -- s2s stanzas | |
161 log("warn", "Unhandled s2s stanza: %s", tostring(stanza)); | |
162 checked_error_reply(origin, stanza); | |
163 end | |
164 else | |
165 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza)); | 141 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza)); |
166 checked_error_reply(origin, stanza); | 142 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") then |
143 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then | |
144 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
145 end | |
146 else | |
147 origin:close("unsupported-stanza-type"); | |
148 end | |
167 end | 149 end |
168 end | 150 end |
169 | 151 |
170 function core_route_stanza(origin, stanza) | 152 function core_route_stanza(origin, stanza) |
171 -- Hooks | 153 -- Hooks |