Comparison

core/stanza_router.lua @ 340:a31715bf08eb

Extra checks before sending error replies to incoming stanzas
author Matthew Wild <mwild1@gmail.com>
date Wed, 19 Nov 2008 05:09:05 +0000
parent 321:31fe15ce6fac
child 358:ffb1a720f5ae
comparison
equal deleted inserted replaced
339:c6446bbfe40c 340:a31715bf08eb
33 33
34 local jid_split = require "util.jid".split; 34 local jid_split = require "util.jid".split;
35 local print = print; 35 local print = print;
36 36
37 function core_process_stanza(origin, stanza) 37 function core_process_stanza(origin, stanza)
38 log("debug", "Received[%s]: %s", origin.type, stanza:pretty_top_tag()) 38 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:pretty_print()) --top_tag())
39 39
40 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. 40 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling.
41 -- TODO verify validity of stanza (as well as JID validity) 41 -- TODO verify validity of stanza (as well as JID validity)
42 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then 42 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then
43 if stanza.attr.type == "set" or stanza.attr.type == "get" then 43 if stanza.attr.type == "set" or stanza.attr.type == "get" then
175 end 175 end
176 end 176 end
177 stanza.attr.to = nil; -- reset it 177 stanza.attr.to = nil; -- reset it
178 else 178 else
179 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); 179 log("warn", "Unhandled c2s presence: %s", tostring(stanza));
180 if stanza.attr.type ~= "error" then 180 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" then
181 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? 181 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
182 end 182 end
183 end 183 end
184 else 184 else
185 log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); 185 log("warn", "Unhandled c2s stanza: %s", tostring(stanza));
186 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then 186 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
187 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? 187 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
188 end 188 end
189 end -- TODO handle other stanzas 189 end -- TODO handle other stanzas
190 else 190 else
191 log("warn", "Unhandled origin: %s", origin.type); 191 log("warn", "Unhandled origin: %s", origin.type);
192 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then 192 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
193 -- s2s stanzas can get here 193 -- s2s stanzas can get here
194 (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? 194 (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
195 end 195 end
196 end 196 end
197 end 197 end