Software /
code /
prosody
Comparison
core/stanza_router.lua @ 4130:c3508071af47
stanza_router: Return a <bad-request/> error on invalid IQ type.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 29 Jan 2011 04:42:56 +0500 |
parent | 3586:78ed7ad330ab |
child | 4553:adcfdaffbccf |
comparison
equal
deleted
inserted
replaced
4129:c86b68abe12e | 4130:c3508071af47 |
---|---|
38 log("warn", "Unhandled %s stream element: %s; xmlns=%s: %s", origin.type, stanza.name, xmlns, tostring(stanza)); -- we didn't handle it | 38 log("warn", "Unhandled %s stream element: %s; xmlns=%s: %s", origin.type, stanza.name, xmlns, tostring(stanza)); -- we didn't handle it |
39 origin:close("unsupported-stanza-type"); | 39 origin:close("unsupported-stanza-type"); |
40 end | 40 end |
41 end | 41 end |
42 | 42 |
43 local iq_types = { set=true, get=true, result=true, error=true }; | |
43 function core_process_stanza(origin, stanza) | 44 function core_process_stanza(origin, stanza) |
44 (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()) |
45 | 46 |
46 -- TODO verify validity of stanza (as well as JID validity) | 47 -- TODO verify validity of stanza (as well as JID validity) |
47 if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log | 48 if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log |
48 if stanza.name == "iq" then | 49 if stanza.name == "iq" then |
49 if not stanza.attr.id then stanza.attr.id = ""; end -- COMPAT Jabiru doesn't send the id attribute on roster requests | 50 if not stanza.attr.id then stanza.attr.id = ""; end -- COMPAT Jabiru doesn't send the id attribute on roster requests |
50 if (stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1) then | 51 if not iq_types[stanza.attr.type] or ((stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1)) then |
51 origin.send(st.error_reply(stanza, "modify", "bad-request")); | 52 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid IQ type or incorrect number of children")); |
52 return; | 53 return; |
53 end | 54 end |
54 end | 55 end |
55 | 56 |
56 if origin.type == "c2s" and not stanza.attr.xmlns then | 57 if origin.type == "c2s" and not stanza.attr.xmlns then |