24 log("debug", "Received: "..tostring(stanza)) |
24 log("debug", "Received: "..tostring(stanza)) |
25 -- TODO verify validity of stanza (as well as JID validity) |
25 -- TODO verify validity of stanza (as well as JID validity) |
26 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then |
26 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then |
27 if stanza.attr.type == "set" or stanza.attr.type == "get" then |
27 if stanza.attr.type == "set" or stanza.attr.type == "get" then |
28 error("Invalid IQ"); |
28 error("Invalid IQ"); |
29 elseif #stanza.tags > 1 or not(stanza.attr.type == "error" or stanza.attr.type == "result") then |
29 elseif #stanza.tags > 1 and not(stanza.attr.type == "error" or stanza.attr.type == "result") then |
30 error("Invalid IQ"); |
30 error("Invalid IQ"); |
31 end |
31 end |
32 end |
32 end |
33 |
33 |
34 if origin.type == "c2s" and not origin.full_jid |
34 if origin.type == "c2s" and not origin.full_jid |
47 core_handle_stanza(origin, stanza); |
47 core_handle_stanza(origin, stanza); |
48 elseif hosts[to] and hosts[to].type == "local" then |
48 elseif hosts[to] and hosts[to].type == "local" then |
49 core_handle_stanza(origin, stanza); |
49 core_handle_stanza(origin, stanza); |
50 elseif stanza.name == "iq" and not select(3, jid_split(to)) then |
50 elseif stanza.name == "iq" and not select(3, jid_split(to)) then |
51 core_handle_stanza(origin, stanza); |
51 core_handle_stanza(origin, stanza); |
52 elseif origin.type == "c2s" then |
52 elseif origin.type == "c2s" or origin.type == "s2sin" then |
53 core_route_stanza(origin, stanza); |
53 core_route_stanza(origin, stanza); |
54 elseif origin.type == "s2sin" then |
|
55 core_deliver_stanza(origin, stanza); |
|
56 end |
54 end |
57 end |
55 end |
58 |
56 |
59 -- This function handles stanzas which are not routed any further, |
57 -- This function handles stanzas which are not routed any further, |
60 -- that is, they are handled by this server |
58 -- that is, they are handled by this server |
96 end |
94 end |
97 else |
95 else |
98 log("debug", "Routing stanza to local"); |
96 log("debug", "Routing stanza to local"); |
99 handle_stanza(session, stanza); |
97 handle_stanza(session, stanza); |
100 end |
98 end |
101 elseif origin.type == "s2sin_unauthed" then |
99 elseif origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
102 if stanza.attr.xmlns == "jabber:server:dialback" then |
100 if stanza.attr.xmlns == "jabber:server:dialback" then |
103 if stanza.name == "verify" then |
101 if stanza.name == "verify" then |
104 -- We are being asked to verify the key, to ensure it was generated by us |
102 -- We are being asked to verify the key, to ensure it was generated by us |
105 log("debug", "verifying dialback key..."); |
103 log("debug", "verifying dialback key..."); |
106 local attr = stanza.attr; |
104 local attr = stanza.attr; |
111 local type = "invalid"; |
109 local type = "invalid"; |
112 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then |
110 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then |
113 type = "valid" |
111 type = "valid" |
114 end |
112 end |
115 origin.send(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); |
113 origin.send(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); |
116 elseif stanza.name == "result" then |
114 elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then |
|
115 -- he wants to be identified through dialback |
117 -- We need to check the key with the Authoritative server |
116 -- We need to check the key with the Authoritative server |
118 local attr = stanza.attr; |
117 local attr = stanza.attr; |
119 origin.from_host = attr.from; |
118 origin.from_host = attr.from; |
120 origin.to_host = attr.to; |
119 origin.to_host = attr.to; |
121 origin.dialback_key = stanza[1]; |
120 origin.dialback_key = stanza[1]; |
242 else |
241 else |
243 send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); |
242 send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); |
244 end |
243 end |
245 end |
244 end |
246 end |
245 end |
|
246 elseif origin.type == "c2s" then |
|
247 -- Remote host |
|
248 --stanza.attr.xmlns = "jabber:server"; |
|
249 stanza.attr.xmlns = nil; |
|
250 log("debug", "sending s2s stanza: %s", tostring(stanza)); |
|
251 send_s2s(origin.host, host, stanza); |
247 else |
252 else |
248 -- Remote host |
253 log("warn", "received stanza from unhandled connection type: %s", origin.type); |
249 log("debug", "sending s2s stanza: %s", tostring(stanza)); |
|
250 stanza.attr.xmlns = "jabber:server"; |
|
251 send_s2s(origin.host, host, stanza); |
|
252 end |
254 end |
253 stanza.attr.to = to; -- reset |
255 stanza.attr.to = to; -- reset |
254 end |
|
255 |
|
256 function core_deliver_stanza(origin, stanza) |
|
257 local name, attr = stanza.name, stanza.attr; |
|
258 if name == "message" then |
|
259 |
|
260 end |
|
261 end |
256 end |
262 |
257 |
263 function handle_stanza_toremote(stanza) |
258 function handle_stanza_toremote(stanza) |
264 log("error", "Stanza bound for remote host, but s2s is not implemented"); |
259 log("error", "Stanza bound for remote host, but s2s is not implemented"); |
265 end |
260 end |