diff options
author | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
commit | 7a7a89844a038b071f02fd1af309ba9ebbcda7de (patch) | |
tree | 73946c977be10a965d59de85b3ce6ba3743bc771 /core | |
parent | 3d1e7adbbc0afb8395f02ecd42fe3c38ce6a8d36 (diff) | |
parent | b6b9906c3c653935b55ad79ad4a2c41118f0a0e3 (diff) | |
download | prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.tar.gz prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.zip |
Merged with main tip.
Diffstat (limited to 'core')
-rw-r--r-- | core/componentmanager.lua | 76 | ||||
-rw-r--r-- | core/presencemanager.lua | 17 | ||||
-rw-r--r-- | core/s2smanager.lua | 7 | ||||
-rw-r--r-- | core/stanza_router.lua | 11 | ||||
-rw-r--r-- | core/xmlhandlers.lua | 24 |
5 files changed, 75 insertions, 60 deletions
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; 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;
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 <stream:stream>"); send("<?xml version='1.0'?>"); - 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 }); diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 1ebc158d..23b7a37d 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,10 +266,14 @@ 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 - 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 @@ -277,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 diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 020e08db..ea136c8d 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 #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; |