-local jid_split = require "util.jid".split;
-local jid_prepped_split = require "util.jid".prepped_split;
-local print = print;
-local function checked_error_reply(origin, stanza)
- if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
- origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
+function deprecated_warning(f)
+ _G[f] = function(...)
+ log("warn", "Using the global %s() is deprecated, use module:send() or prosody.%s(). %s", f, f, debug.traceback());
+ return prosody[f](...);
+ end
+end
+deprecated_warning"core_post_stanza";
+deprecated_warning"core_process_stanza";
+deprecated_warning"core_route_stanza";
+
+local valid_stanzas = { message = true, presence = true, iq = true };
+local function handle_unhandled_stanza(host, origin, stanza)
+ local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns or "jabber:client", origin.type;
+ if xmlns == "jabber:client" and valid_stanzas[name] then
+ -- A normal stanza
+ local st_type = stanza.attr.type;
+ if st_type == "error" or (name == "iq" and st_type == "result") then
+ log("debug", "Discarding %s from %s of type: %s", name, origin_type, st_type or '<nil>');
+ return;
+ end
+ if name == "iq" and (st_type == "get" or st_type == "set") and stanza.tags[1] then
+ xmlns = stanza.tags[1].attr.xmlns or "jabber:client";
+ end
+ log("debug", "Unhandled %s stanza: %s; xmlns=%s", origin_type, name, xmlns);
+ if origin.send then
+ origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
+ end
+ elseif not((name == "features" or name == "error") and xmlns == "http://etherx.jabber.org/streams") then -- FIXME remove check once we handle S2S features
+ log("warn", "Unhandled %s stream element or stanza: %s; xmlns=%s: %s", origin_type, name, xmlns, tostring(stanza)); -- we didn't handle it
+ origin:close("unsupported-stanza-type");