working incoming s2s \o/
authorMatthew Wild <mwild1@gmail.com>
Fri, 24 Oct 2008 05:13:38 +0000 (06:13 +0100)
committerMatthew Wild <mwild1@gmail.com>
Fri, 24 Oct 2008 05:13:38 +0000 (06:13 +0100)
core/stanza_router.lua
util/logger.lua

index 215b01a0d0f390d84167394e8b4e018ab4b1dde9..2399c25f2705814206eafc49ef99a4d0c8111864 100644 (file)
@@ -51,6 +51,8 @@ function core_process_stanza(origin, stanza)
                core_handle_stanza(origin, stanza);
        elseif origin.type == "c2s" then
                core_route_stanza(origin, stanza);
+       elseif origin.type == "s2sin" then
+               core_deliver_stanza(origin, stanza);
        end
 end
 
@@ -97,26 +99,52 @@ function core_handle_stanza(origin, stanza)
                        handle_stanza(session, stanza);
                end
        elseif origin.type == "s2sin_unauthed" then
-               if stanza.name == "verify" and stanza.attr.xmlns == "jabber:server:dialback" then
-                       log("debug", "verifying dialback key...");
-                       local attr = stanza.attr;
-                       print(tostring(attr.to), tostring(attr.from))
-                       print(tostring(origin.to_host), tostring(origin.from_host))
-                       -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34
-                       --if attr.from ~= origin.to_host then error("invalid-from"); end
-                       local type = "invalid";
-                       if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then
-                               type = "valid"
+               if stanza.attr.xmlns == "jabber:server:dialback" then
+                       if stanza.name == "verify" then
+                               -- We are being asked to verify the key, to ensure it was generated by us
+                               log("debug", "verifying dialback key...");
+                               local attr = stanza.attr;
+                               print(tostring(attr.to), tostring(attr.from))
+                               print(tostring(origin.to_host), tostring(origin.from_host))
+                               -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34
+                               --if attr.from ~= origin.to_host then error("invalid-from"); end
+                               local type = "invalid";
+                               if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then
+                                       type = "valid"
+                               end
+                               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]));
+                       elseif stanza.name == "result" then
+                               -- We need to check the key with the Authoritative server
+                               local attr = stanza.attr;
+                               origin.from_host = attr.from;
+                               origin.to_host = attr.to;
+                               origin.dialback_key = stanza[1];
+                               log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]);
+                               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]));
+                               hosts[attr.from].dialback_verifying = origin;
                        end
-                       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]));
                end
-       elseif origin.type == "s2sout_unauthed" then
-               if stanza.name == "result" and stanza.attr.xmlns == "jabber:server:dialback" then
-                       if stanza.attr.type == "valid" then
-                               s2s_make_authenticated(origin);
-                       else
-                               -- FIXME
-                               error("dialback failed!");
+       elseif origin.type == "s2sout_unauthed" or origin.type == "s2sout" then
+               if stanza.attr.xmlns == "jabber:server:dialback" then
+                       if stanza.name == "result" then
+                               if stanza.attr.type == "valid" then
+                                       s2s_make_authenticated(origin);
+                               else
+                                       -- FIXME
+                                       error("dialback failed!");
+                               end
+                       elseif stanza.name == "verify" and origin.dialback_verifying then
+                               local valid;
+                               local attr = stanza.attr;
+                               if attr.type == "valid" then
+                                       s2s_make_authenticated(origin.dialback_verifying);
+                                       valid = "valid";
+                               else
+                                       -- Warn the original connection that is was not verified successfully
+                                       log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed");
+                                       valid = "invalid";
+                               end
+                               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));
                        end
                end
        else
@@ -225,6 +253,13 @@ function core_route_stanza(origin, stanza)
        stanza.attr.to = to; -- reset
 end
 
+function core_deliver_stanza(origin, stanza)
+       local name, attr = stanza.name, stanza.attr;
+       if name == "message" then
+               
+       end
+end
+
 function handle_stanza_toremote(stanza)
        log("error", "Stanza bound for remote host, but s2s is not implemented");
 end
index 623ceb674abf8d054de14d0e850f880a426e04a5..8d98360536fdab26c73d4b27e1e42a76e0cf44a5 100644 (file)
@@ -6,7 +6,7 @@ local tostring = tostring;
 module "logger"
 
 function init(name)
-       name = nil; -- While this line is not commented, will automatically fill in file/line number info
+       --name = nil; -- While this line is not commented, will automatically fill in file/line number info
        return  function (level, message, ...)
                                if not name then
                                        local inf = debug.getinfo(3, 'Snl');