Comparison

core/stanza_router.lua @ 2951:294c359a05f5

Merge 0.6->0.7
author Matthew Wild <mwild1@gmail.com>
date Tue, 30 Mar 2010 19:45:56 +0100
parent 2925:692b3c6c5bd2
parent 2949:ef19faa7d106
child 3539:8bbd965267b2
comparison
equal deleted inserted replaced
2947:ff7f6668b34f 2951:294c359a05f5
21 local bare_sessions = _G.prosody.bare_sessions; 21 local bare_sessions = _G.prosody.bare_sessions;
22 22
23 function core_process_stanza(origin, stanza) 23 function core_process_stanza(origin, stanza)
24 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag()) 24 (origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag())
25 25
26 -- Currently we guarantee every stanza to have an xmlns, should we keep this rule?
27 if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end
28
29 -- TODO verify validity of stanza (as well as JID validity) 26 -- TODO verify validity of stanza (as well as JID validity)
30 if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log 27 if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log
31 if stanza.name == "iq" then 28 if stanza.name == "iq" then
32 if not stanza.attr.id then stanza.attr.id = ""; end -- COMPAT Jabiru doesn't send the id attribute on roster requests 29 if not stanza.attr.id then stanza.attr.id = ""; end -- COMPAT Jabiru doesn't send the id attribute on roster requests
33 if (stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1) then 30 if (stanza.attr.type == "set" or stanza.attr.type == "get") and (#stanza.tags ~= 1) then
34 origin.send(st.error_reply(stanza, "modify", "bad-request")); 31 origin.send(st.error_reply(stanza, "modify", "bad-request"));
35 return; 32 return;
36 end 33 end
37 end 34 end
38 35
39 if origin.type == "c2s" and stanza.attr.xmlns == "jabber:client" then 36 if origin.type == "c2s" and not stanza.attr.xmlns then
40 if not origin.full_jid 37 if not origin.full_jid
41 and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" 38 and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind"
42 and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then 39 and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then
43 -- authenticated client isn't bound and current stanza is not a bind request 40 -- authenticated client isn't bound and current stanza is not a bind request
44 if stanza.attr.type ~= "result" and stanza.attr.type ~= "error" then 41 if stanza.attr.type ~= "result" and stanza.attr.type ~= "error" then
90 --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us? 87 --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us?
91 log("warn", "stanza recieved for a non-local server"); 88 log("warn", "stanza recieved for a non-local server");
92 return; -- FIXME what should we do here? 89 return; -- FIXME what should we do here?
93 end]] -- FIXME 90 end]] -- FIXME
94 91
95 if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and xmlns == "jabber:client" then 92 if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and xmlns == nil then
96 if origin.type == "s2sin" and not origin.dummy then 93 if origin.type == "s2sin" and not origin.dummy then
97 local host_status = origin.hosts[from_host]; 94 local host_status = origin.hosts[from_host];
98 if not host_status or not host_status.authed then -- remote server trying to impersonate some other server? 95 if not host_status or not host_status.authed then -- remote server trying to impersonate some other server?
99 log("warn", "Received a stanza claiming to be from %s, over a stream authed for %s!", from_host, origin.from_host); 96 log("warn", "Received a stanza claiming to be from %s, over a stream authed for %s!", from_host, origin.from_host);
100 return; -- FIXME what should we do here? does this work with subdomains? 97 return; -- FIXME what should we do here? does this work with subdomains?
103 core_post_stanza(origin, stanza, origin.full_jid); 100 core_post_stanza(origin, stanza, origin.full_jid);
104 else 101 else
105 local h = hosts[stanza.attr.to or origin.host or origin.to_host]; 102 local h = hosts[stanza.attr.to or origin.host or origin.to_host];
106 if h then 103 if h then
107 local event; 104 local event;
108 if stanza.attr.xmlns == "jabber:client" then 105 if xmlns == nil then
109 if stanza.name == "iq" and (stanza.attr.type == "set" or stanza.attr.type == "get") then 106 if stanza.name == "iq" and (stanza.attr.type == "set" or stanza.attr.type == "get") then
110 event = "stanza/iq/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name; 107 event = "stanza/iq/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name;
111 else 108 else
112 event = "stanza/"..stanza.name; 109 event = "stanza/"..stanza.name;
113 end 110 end
114 else 111 else
115 event = "stanza/"..stanza.attr.xmlns..":"..stanza.name; 112 event = "stanza/"..xmlns..":"..stanza.name;
116 end 113 end
117 if h.events.fire_event(event, {origin = origin, stanza = stanza}) then return; end 114 if h.events.fire_event(event, {origin = origin, stanza = stanza}) then return; end
118 end 115 end
119 if host and not hosts[host] then host = nil; end -- COMPAT: workaround for a Pidgin bug which sets 'to' to the SRV result 116 if host and not hosts[host] then host = nil; end -- COMPAT: workaround for a Pidgin bug which sets 'to' to the SRV result
120 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); 117 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);