From 093cf3e0172ee565202910a324261883d6ff5a5a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Nov 2008 12:13:13 +0500 Subject: Added basic offline message support --- core/stanza_router.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 9ae98f1c..5d6358ec 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -13,6 +13,7 @@ local user_exists = require "core.usermanager".user_exists; local rostermanager = require "core.rostermanager"; local sessionmanager = require "core.sessionmanager"; +local offlinemanager = require "core.offlinemanager"; local s2s_verify_dialback = require "core.s2smanager".verify_dialback; local s2s_make_authenticated = require "core.s2smanager".make_authenticated; @@ -149,6 +150,10 @@ function core_handle_stanza(origin, stanza) core_route_stanza(origin, request); end end + for _, msg in ipairs(offlinemanager.load(node, host) or {}) do + origin.send(msg); -- FIXME do we need to modify to/from in any way? + end + offlinemanager.deleteAll(node, host); end origin.priority = 0; if stanza.attr.type == "unavailable" then @@ -328,8 +333,14 @@ function core_route_stanza(origin, stanza) t_insert(recipients, session); end end + local count = 0; for _, session in pairs(recipients) do session.send(stanza); + count = count + 1; + end + if count == 0 then + offlinemanager.store(node, host, stanza); + -- TODO deal with storage errors end else -- TODO send IQ error @@ -349,7 +360,12 @@ function core_route_stanza(origin, stanza) -- TODO send unavailable presence or unsubscribed end elseif stanza.name == "message" then - -- TODO send message error, or store offline messages + if stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type then + offlinemanager.store(node, host, stanza); + -- FIXME don't store messages with only chat state notifications + end + -- TODO allow configuration of offline storage + -- TODO send error if not storing offline elseif stanza.name == "iq" then -- TODO send IQ error end -- cgit v1.2.3 From a1740642f2a9af6bf42747fe0b4bf2148fc38449 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Nov 2008 19:14:31 +0500 Subject: Added error replies for unhandled stanzas --- core/stanza_router.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 5d6358ec..1793f547 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -173,11 +173,16 @@ function core_handle_stanza(origin, stanza) end stanza.attr.to = nil; -- reset it else - -- TODO error, bad type + log("warn", "Unhandled c2s presence: %s", tostring(stanza)); + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? end + else + log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? end -- TODO handle other stanzas else - log("warn", "Unhandled origin: %s", origin.type); -- FIXME reply with error + log("warn", "Unhandled origin: %s", origin.type); + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? end end -- cgit v1.2.3 From c374478423b1fa6df31f2e133db77f89ceb91fac Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:33:20 +0000 Subject: I knew it ;) Fix sending error replies over s2s (though we shouldn't be error'ing on stream:features anyway) --- core/stanza_router.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 1793f547..6c117c25 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -182,7 +182,8 @@ function core_handle_stanza(origin, stanza) end -- TODO handle other stanzas else log("warn", "Unhandled origin: %s", origin.type); - origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + -- s2s stanzas can get here + (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? end end -- cgit v1.2.3 From d67940a1d7700c0389341c42f845b91e8b32eea6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 16:03:33 +0000 Subject: A treat for Linux users ;) --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 6c117c25..16e6598f 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -32,7 +32,7 @@ local jid_split = require "util.jid".split; local print = print; function core_process_stanza(origin, stanza) - log("debug", "Received["..origin.type.."]: "..tostring(st.reply(st.reply(stanza)))) + log("debug", "Received[%s]: %s", origin.type, stanza:pretty_top_tag()) if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. -- TODO verify validity of stanza (as well as JID validity) -- cgit v1.2.3 From 50e328e87fb21ffca2780128ed5da9c0e011eb5f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 18:46:00 +0000 Subject: Only reply with errors if the stanza is not an error or a result (don't know how much bandwidth this just cost me :) ) --- core/stanza_router.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'core/stanza_router.lua') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 16e6598f..c1819651 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -174,16 +174,22 @@ function core_handle_stanza(origin, stanza) stanza.attr.to = nil; -- reset it else log("warn", "Unhandled c2s presence: %s", tostring(stanza)); - origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + if stanza.attr.type ~= "error" then + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + end end else log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); - origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + end end -- TODO handle other stanzas else log("warn", "Unhandled origin: %s", origin.type); - -- s2s stanzas can get here - (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then + -- s2s stanzas can get here + (origin.sends2s or origin.send)(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? + end end end -- cgit v1.2.3