From 412368f62ac29b4880f14c26372806a32b2bb4ae Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 19 Feb 2009 19:00:18 +0000 Subject: core.presencemanager: Set 'from' attribute on outgoing unavailable directed presences --- core/presencemanager.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/presencemanager.lua b/core/presencemanager.lua index 8fdf3612..f94ffd55 100644 --- a/core/presencemanager.lua +++ b/core/presencemanager.lua @@ -95,13 +95,16 @@ function handle_normal_presence(origin, stanza, core_route_stanza) end origin.priority = 0; if stanza.attr.type == "unavailable" then - origin.presence = nil; - if origin.directed then - for jid in pairs(origin.directed) do - stanza.attr.to = jid; - core_route_stanza(origin, stanza); - end - origin.directed = nil; + origin.presence = nil; + if origin.directed then + local old_from = stanza.attr.from; + stanza.attr.from = origin.full_jid; + for jid in pairs(origin.directed) do + stanza.attr.to = jid; + core_route_stanza(origin, stanza); + end + stanza.attr.from = old_from; + origin.directed = nil; end else origin.presence = stanza; -- cgit v1.2.3 From 2aa35ba40d4868d6e65f07b743b269c89d6b0e46 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 26 Feb 2009 02:26:30 +0000 Subject: core.xmlhandlers: Optimise completed stanza logic --- core/xmlhandlers.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 020e08db..56115917 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -121,17 +121,19 @@ function init_xmlhandlers(session, stream_callbacks) cb_error(session, "parse-error", "unexpected-element-close", name); end end - if stanza and #chardata > 0 then - -- We have some character data in the buffer - stanza:text(t_concat(chardata)); - chardata = {}; - end - -- Complete stanza - if #stanza.last_add == 0 then - cb_handlestanza(session, stanza); - stanza = nil; - else - stanza:up(); + if stanza then + if stanza and #chardata > 0 then + -- We have some character data in the buffer + stanza:text(t_concat(chardata)); + chardata = {}; + end + -- Complete stanza + if #stanza.last_add == 0 then + cb_handlestanza(session, stanza); + stanza = nil; + else + stanza:up(); + end end end return xml_handlers; -- cgit v1.2.3 From 219c84da4a2f42938e84ad60b53fbf1ed98954b8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 27 Feb 2009 04:42:06 +0000 Subject: core.xmlhandlers: Remove redundant check in condition --- core/xmlhandlers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 56115917..ea136c8d 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -122,7 +122,7 @@ function init_xmlhandlers(session, stream_callbacks) end end if stanza then - if stanza and #chardata > 0 then + if #chardata > 0 then -- We have some character data in the buffer stanza:text(t_concat(chardata)); chardata = {}; -- cgit v1.2.3 From 8c36520f60140741cde82860a05b39fbe1844535 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Feb 2009 02:05:37 +0000 Subject: core.componentmanager: Refactor a little to make XEP-0114 plugin a little simpler --- core/componentmanager.lua | 76 +++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 35 deletions(-) (limited to 'core') diff --git a/core/componentmanager.lua b/core/componentmanager.lua index 04909a07..15931167 100644 --- a/core/componentmanager.lua +++ b/core/componentmanager.lua @@ -7,20 +7,20 @@ -- - - + + local log = require "util.logger".init("componentmanager"); local configmanager = require "core.configmanager"; local eventmanager = require "core.eventmanager"; -local modulemanager = require "core.modulemanager"; -local jid_split = require "util.jid".split; +local modulemanager = require "core.modulemanager"; +local jid_split = require "util.jid".split; local hosts = hosts; -local pairs, type, tostring = pairs, type, tostring; - -local components = {}; - -module "componentmanager" +local pairs, type, tostring = pairs, type, tostring; + +local components = {}; + +module "componentmanager" function load_enabled_components(config) local defined_hosts = config or configmanager.getconfig(); @@ -39,34 +39,40 @@ function load_enabled_components(config) end eventmanager.add_event_hook("server-starting", load_enabled_components); - -function handle_stanza(origin, stanza) - local node, host = jid_split(stanza.attr.to); + +function handle_stanza(origin, stanza) + local node, host = jid_split(stanza.attr.to); local component = nil; if not component then component = components[stanza.attr.to]; end -- hack to allow hooking node@server/resource and server/resource - if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server + if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server if not component then component = components[host]; end - if component then - log("debug", "stanza being handled by component: "..host); - component(origin, stanza, hosts[host]); - else - log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to); - end -end - -function register_component(host, component) - if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then - -- TODO check for host well-formedness - components[host] = component; - hosts[host] = { type = "component", host = host, connected = true, s2sout = {} }; + if component then + log("debug", "stanza being handled by component: "..host); + component(origin, stanza, hosts[host]); + else + log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to); + end +end + +function create_component(host, component) + -- TODO check for host well-formedness + session = session or { type = "component", host = host, connected = true, s2sout = {}, send = component }; + return session; +end + +function register_component(host, component, session) + if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then + components[host] = component; + hosts[host] = session or create_component(host, component); + -- FIXME only load for a.b.c if b.c has dialback, and/or check in config - modulemanager.load(host, "dialback"); - log("debug", "component added: "..host); - return hosts[host]; - else - log("error", "Attempt to set component for existing host: "..host); - end -end + modulemanager.load(host, "dialback"); + log("debug", "component added: "..host); + return session or hosts[host]; + else + log("error", "Attempt to set component for existing host: "..host); + end +end function deregister_component(host) if components[host] then @@ -79,5 +85,5 @@ function deregister_component(host) log("error", "Attempt to remove component for non-existing host: "..host); end end - -return _M; + +return _M; -- cgit v1.2.3 From 4a34bb9adef891a5451fdb3648c72c37bf54d744 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Feb 2009 04:58:14 +0000 Subject: core.stanza_router: Reply with error to groupchat messages directed at unavailable resources or offline users --- core/stanza_router.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 1ebc158d..29a4797b 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -217,6 +217,9 @@ function core_route_stanza(origin, stanza) session.send(stanza); end end + elseif resource and stanza.attr.type == 'groupchat' then + -- Groupchat message sent to offline resource + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); else local priority = 0; local recipients = {}; @@ -263,6 +266,10 @@ function core_route_stanza(origin, stanza) 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 + elseif stanza.attr.type == "groupchat" then + local reply = st.error_reply(stanza, "cancel", "service-unavailable"); + reply.attr.from = to; + origin.send(reply); end -- TODO allow configuration of offline storage -- TODO send error if not storing offline -- cgit v1.2.3 From 1a7a72a9f664b78bbb093a5c59620cfdadb18c93 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 2 Mar 2009 13:52:08 +0000 Subject: core.s2smanager: Remove some old commented code, break a long line in 2 --- core/s2smanager.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 4f205418..db6d2fe5 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -206,22 +206,19 @@ function streamopened(session, attr) session.version = 0; --tonumber(attr.version) or 0; if session.version >= 1.0 and not (attr.to and attr.from) then - --print("to: "..tostring(attr.to).." from: "..tostring(attr.from)); log("warn", (session.to_host or "(unknown)").." failed to specify 'to' or 'from' hostname as per RFC"); end if session.direction == "incoming" then -- Send a reply stream header - - --for k,v in pairs(attr) do print("", tostring(k), ":::", tostring(v)); end - session.to_host = attr.to; session.from_host = attr.from; session.streamid = uuid_gen(); (session.log or log)("debug", "incoming s2s received "); send(""); - send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host }):top_tag()); + send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', + ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host }):top_tag()); if session.to_host and not hosts[session.to_host] then -- Attempting to connect to a host we don't serve session:close({ condition = "host-unknown"; text = "This host does not serve "..session.to_host }); -- cgit v1.2.3 From a6107b2b5e84db104641545bd72c7d871678261f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 2 Mar 2009 19:45:44 +0000 Subject: core.stanza_router: Don't bounce errors to iq type=result/error --- core/stanza_router.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 29a4797b..23b7a37d 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -273,7 +273,7 @@ function core_route_stanza(origin, stanza) end -- TODO allow configuration of offline storage -- TODO send error if not storing offline - elseif stanza.name == "iq" then + elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); end else -- user does not exist @@ -284,7 +284,7 @@ function core_route_stanza(origin, stanza) origin.send(st.presence({from = to_bare, to = from_bare, type = "unsubscribed"})); end -- else ignore - else + elseif stanza.attr.type ~= "error" and (stanza.name ~= "iq" or stanza.attr.type ~= "result") then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); end end -- cgit v1.2.3