Added resource priority handling, etc
authorWaqas Hussain <waqas20@gmail.com>
Sun, 2 Nov 2008 01:36:42 +0000 (06:36 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Sun, 2 Nov 2008 01:36:42 +0000 (06:36 +0500)
core/s2smanager.lua
core/stanza_router.lua
doc/session.txt

index b2e498bd9f3f894b16a6470834deed1ee8526fbc..7855181e7abfd6652d70ec41d2e60bf53d6b1203 100644 (file)
@@ -57,7 +57,7 @@ end
 local open_sessions = 0;
 
 function new_incoming(conn)
-       local session = { conn = conn,  priority = 0, type = "s2sin_unauthed", direction = "incoming" };
+       local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming" };
        if true then
                session.trace = newproxy(true);
                getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("s2s session got collected, now "..open_sessions.." s2s sessions are allocated") end;
index 01a4696185c038117e86a39c8dd63295a28d2e27..41e89f31995b1862d506bbe840f6d0666a77f3ae 100644 (file)
@@ -21,6 +21,9 @@ local modules_handle_stanza = require "core.modulemanager".handle_stanza;
 
 local format = string.format;
 local tostring = tostring;
+local t_concat = table.concat;
+local tonumber = tonumber;
+local s_find = string.find;
 
 local jid_split = require "util.jid".split;
 local print = print;
@@ -91,7 +94,7 @@ function core_handle_stanza(origin, stanza)
                                                core_route_stanza(origin, stanza);
                                        end
                                end
-                               if not origin.presence then -- presence probes on initial presence -- FIXME does unavailable qualify as initial presence?
+                               if stanza.attr.type == nil and not origin.presence then -- initial presence
                                        local probe = st.presence({from = origin.full_jid, type = "probe"});
                                        for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to
                                                local subscription = origin.roster[jid].subscription;
@@ -100,16 +103,42 @@ function core_handle_stanza(origin, stanza)
                                                        core_route_stanza(origin, probe);
                                                end
                                        end
-                                       for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all resources
-                                               if res ~= origin and stanza.attr.type ~= "unavailable" and res.presence then -- FIXME does unavailable qualify as initial presence?
+                                       for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all available resources
+                                               if res ~= origin and res.presence then
                                                        res.presence.attr.to = origin.full_jid;
                                                        core_route_stanza(res, res.presence);
                                                        res.presence.attr.to = nil;
                                                end
                                        end
-                                       -- TODO resend subscription requests
+                                       if origin.roster.pending then -- resend incoming subscription requests
+                                               for jid in pairs(origin.roster.pending) do
+                                                       origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original?
+                                               end
+                                       end
+                                       local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host});
+                                       for jid, item in pairs(origin.roster) do -- resend outgoing subscription requests
+                                               if item.ask then
+                                                       request.attr.to = jid;
+                                                       core_route_stanza(origin, request);
+                                               end
+                                       end
+                               end
+                               origin.priority = 0;
+                               if stanza.attr.type == "unavailable" then
+                                       origin.presence = nil;
+                               else
+                                       origin.presence = stanza;
+                                       local priority = stanza:child_with_name("priority");
+                                       if priority and #priority > 0 then
+                                               priority = t_concat(priority);
+                                               if s_find(priority, "^[+-]?[0-9]+$") then
+                                                       priority = tonumber(priority);
+                                                       if priority < -128 then priority = -128 end
+                                                       if priority > 127 then priority = 127 end
+                                                       origin.priority = priority;
+                                               end
+                                       end
                                end
-                               origin.presence = stanza;
                                stanza.attr.to = nil; -- reset it
                        else
                                -- TODO error, bad type
index e475e45b53f3bb4a129169e0ded1698d206893b1..fc6eec17199af7b5b8cd52181d7086b4f0d15612 100644 (file)
@@ -13,8 +13,8 @@ session {
        host -- the host part of the client's jid (not defined before stream initiation)\r
        resource -- the resource part of the client's full jid (not defined before resource binding)\r
        full_jid -- convenience for the above 3 as string in username@host/resource form (not defined before resource binding)\r
-       priority -- the resource priority, default: 0 (not defined before initial presence)\r
-       presence -- the last non-directed presence. initially nil.\r
+       priority -- the resource priority, default: 0\r
+       presence -- the last non-directed presence with no type attribute. initially nil. reset to nil on unavailable presence.\r
        interested -- true if the resource requested the roster. Interested resources recieve roster updates. Initially nil.\r
        roster -- the user's roster. Loaded as soon as the resource is bound (session becomes a connected resource).\r
        \r
@@ -24,5 +24,5 @@ session {
 }\r
 \r
 if session.full_jid (also session.roster and session.resource) then this is a "connected resource"\r
-if session.presence then this is an "available resource"\r
-if session.interested then this is an "interested resource"\r
+if session.presence then this is an "available resource" (all available resources are connected resources)\r
+if session.interested then this is an "interested resource" (all interested resources are connected resources)\r