Comparison

core/stanza_router.lua @ 147:ccebb2720741 s2s

working incoming s2s \o/
author Matthew Wild <mwild1@gmail.com>
date Fri, 24 Oct 2008 06:13:38 +0100
parent 146:3826ca244eb6
child 148:4c0dcd245d34
comparison
equal deleted inserted replaced
146:3826ca244eb6 147:ccebb2720741
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" 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);
54 end 56 end
55 end 57 end
56 58
57 -- This function handles stanzas which are not routed any further, 59 -- This function handles stanzas which are not routed any further,
58 -- that is, they are handled by this server 60 -- that is, they are handled by this server
95 else 97 else
96 log("debug", "Routing stanza to local"); 98 log("debug", "Routing stanza to local");
97 handle_stanza(session, stanza); 99 handle_stanza(session, stanza);
98 end 100 end
99 elseif origin.type == "s2sin_unauthed" then 101 elseif origin.type == "s2sin_unauthed" then
100 if stanza.name == "verify" and stanza.attr.xmlns == "jabber:server:dialback" then 102 if stanza.attr.xmlns == "jabber:server:dialback" then
101 log("debug", "verifying dialback key..."); 103 if stanza.name == "verify" then
102 local attr = stanza.attr; 104 -- We are being asked to verify the key, to ensure it was generated by us
103 print(tostring(attr.to), tostring(attr.from)) 105 log("debug", "verifying dialback key...");
104 print(tostring(origin.to_host), tostring(origin.from_host)) 106 local attr = stanza.attr;
105 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 107 print(tostring(attr.to), tostring(attr.from))
106 --if attr.from ~= origin.to_host then error("invalid-from"); end 108 print(tostring(origin.to_host), tostring(origin.from_host))
107 local type = "invalid"; 109 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34
108 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then 110 --if attr.from ~= origin.to_host then error("invalid-from"); end
109 type = "valid" 111 local type = "invalid";
110 end 112 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then
111 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 type = "valid"
112 end 114 end
113 elseif origin.type == "s2sout_unauthed" then 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]));
114 if stanza.name == "result" and stanza.attr.xmlns == "jabber:server:dialback" then 116 elseif stanza.name == "result" then
115 if stanza.attr.type == "valid" then 117 -- We need to check the key with the Authoritative server
116 s2s_make_authenticated(origin); 118 local attr = stanza.attr;
117 else 119 origin.from_host = attr.from;
118 -- FIXME 120 origin.to_host = attr.to;
119 error("dialback failed!"); 121 origin.dialback_key = stanza[1];
122 log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]);
123 send_s2s(attr.to, attr.from, format("<db:verify from='%s' to='%s' id='%s'>%s</db:verify>", attr.to, attr.from, origin.streamid, stanza[1]));
124 hosts[attr.from].dialback_verifying = origin;
125 end
126 end
127 elseif origin.type == "s2sout_unauthed" or origin.type == "s2sout" then
128 if stanza.attr.xmlns == "jabber:server:dialback" then
129 if stanza.name == "result" then
130 if stanza.attr.type == "valid" then
131 s2s_make_authenticated(origin);
132 else
133 -- FIXME
134 error("dialback failed!");
135 end
136 elseif stanza.name == "verify" and origin.dialback_verifying then
137 local valid;
138 local attr = stanza.attr;
139 if attr.type == "valid" then
140 s2s_make_authenticated(origin.dialback_verifying);
141 valid = "valid";
142 else
143 -- Warn the original connection that is was not verified successfully
144 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed");
145 valid = "invalid";
146 end
147 origin.dialback_verifying.send(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key));
120 end 148 end
121 end 149 end
122 else 150 else
123 log("warn", "Unhandled origin: %s", origin.type); 151 log("warn", "Unhandled origin: %s", origin.type);
124 end 152 end
223 send_s2s(origin.host, host, stanza); 251 send_s2s(origin.host, host, stanza);
224 end 252 end
225 stanza.attr.to = to; -- reset 253 stanza.attr.to = to; -- reset
226 end 254 end
227 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
262
228 function handle_stanza_toremote(stanza) 263 function handle_stanza_toremote(stanza)
229 log("error", "Stanza bound for remote host, but s2s is not implemented"); 264 log("error", "Stanza bound for remote host, but s2s is not implemented");
230 end 265 end