Software /
code /
prosody
Comparison
core/stanza_router.lua @ 715:beec1eb7d9c6
stanza_router: Fixed error replies for unhandled stanzas
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 14 Jan 2009 22:35:01 +0500 |
parent | 667:4f4d94253547 |
child | 718:aa78dfb26593 |
comparison
equal
deleted
inserted
replaced
714:ab3c47f4fe1d | 715:beec1eb7d9c6 |
---|---|
46 local tonumber = tonumber; | 46 local tonumber = tonumber; |
47 local s_find = string.find; | 47 local s_find = string.find; |
48 | 48 |
49 local jid_split = require "util.jid".split; | 49 local jid_split = require "util.jid".split; |
50 local print = print; | 50 local print = print; |
51 local function checked_error_reply(origin, stanza) | |
52 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server" or not stanza.attr.xmlns) and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then | |
53 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? | |
54 end | |
55 end | |
51 | 56 |
52 function core_process_stanza(origin, stanza) | 57 function core_process_stanza(origin, stanza) |
53 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:pretty_print()) --top_tag()) | 58 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:pretty_print()) --top_tag()) |
54 | 59 |
55 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. | 60 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. |
131 if stanza.name == "presence" and origin.roster then | 136 if stanza.name == "presence" and origin.roster then |
132 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then | 137 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then |
133 handle_normal_presence(origin, stanza, core_route_stanza); | 138 handle_normal_presence(origin, stanza, core_route_stanza); |
134 else | 139 else |
135 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); | 140 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); |
136 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" then | 141 checked_error_reply(origin, stanza); |
137 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? | |
138 end | |
139 end | 142 end |
140 else | 143 else |
141 log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); | 144 log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); |
142 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then | 145 checked_error_reply(origin, stanza); |
143 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? | |
144 end | |
145 end | 146 end |
146 else -- s2s stanzas | 147 else -- s2s stanzas |
147 log("warn", "Unhandled s2s stanza: %s", tostring(stanza)); | 148 log("warn", "Unhandled s2s stanza: %s", tostring(stanza)); |
148 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then | 149 checked_error_reply(origin, stanza); |
149 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? | |
150 end | |
151 end | 150 end |
152 else | 151 else |
153 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza)); | 152 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza)); |
153 checked_error_reply(origin, stanza); | |
154 end | 154 end |
155 end | 155 end |
156 | 156 |
157 function core_route_stanza(origin, stanza) | 157 function core_route_stanza(origin, stanza) |
158 -- Hooks | 158 -- Hooks |