aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/componentmanager.lua21
-rw-r--r--core/modulemanager.lua2
-rw-r--r--core/rostermanager.lua4
-rw-r--r--core/s2smanager.lua5
-rw-r--r--core/sessionmanager.lua2
-rw-r--r--core/stanza_router.lua8
6 files changed, 35 insertions, 7 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua
index da079e83..e7b5e4dc 100644
--- a/core/componentmanager.lua
+++ b/core/componentmanager.lua
@@ -20,6 +20,18 @@ local pairs, type, tostring = pairs, type, tostring;
local components = {};
+local disco_items = require "util.multitable".new();
+local NULL = {};
+require "core.discomanager".addDiscoItemsHandler("*host", function(reply, to, from, node)
+ if #node == 0 and hosts[to] then
+ for jid in pairs(disco_items:get(to) or NULL) do
+ reply:tag("item", {jid = jid}):up();
+ end
+ return true;
+ end
+end);
+
+
module "componentmanager"
function load_enabled_components(config)
@@ -64,7 +76,10 @@ 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);
-
+ -- add to disco_items
+ if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
+ disco_items:set(host:sub(host:find(".", 1, true)+1), host, true);
+ end
-- 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);
@@ -79,6 +94,10 @@ function deregister_component(host)
modulemanager.unload(host, "dialback");
components[host] = nil;
hosts[host] = nil;
+ -- remove from disco_items
+ if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
+ disco_items:remove(host:sub(host:find(".", 1, true)+1), host);
+ end
log("debug", "component removed: "..host);
return true;
else
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 4391fc7f..a1d3bef3 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -204,7 +204,7 @@ function handle_stanza(host, origin, stanza)
local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;
if name == "iq" and xmlns == "jabber:client" then
if stanza.attr.type == "get" or stanza.attr.type == "set" then
- xmlns = stanza.tags[1].attr.xmlns;
+ xmlns = stanza.tags[1].attr.xmlns or "jabber:client";
log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns);
else
log("debug", "Discarding %s from %s of type: %s", name, origin_type, stanza.attr.type);
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index fdaf64a7..867add2c 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -224,6 +224,10 @@ function subscribed(username, host, jid)
if is_contact_pending_in(username, host, jid) then
local roster = load_roster(username, host);
local item = roster[jid];
+ if not item then -- FIXME should roster item be auto-created?
+ item = {subscription = "none", groups = {}};
+ roster[jid] = item;
+ end
if item.subscription == "none" then
item.subscription = "from";
else -- subscription == to
diff --git a/core/s2smanager.lua b/core/s2smanager.lua
index 19b7f047..f4f7ad36 100644
--- a/core/s2smanager.lua
+++ b/core/s2smanager.lua
@@ -24,6 +24,7 @@ local wrapclient = require "net.server".wrapclient;
local modulemanager = require "core.modulemanager";
local st = require "stanza";
local stanza = st.stanza;
+local nameprep = require "util.encodings".stringprep.nameprep;
local uuid_gen = require "util.uuid".generate;
@@ -211,8 +212,8 @@ function streamopened(session, attr)
if session.direction == "incoming" then
-- Send a reply stream header
- session.to_host = attr.to;
- session.from_host = attr.from;
+ session.to_host = attr.to and nameprep(attr.to);
+ session.from_host = attr.from and nameprep(attr.from);
session.streamid = uuid_gen();
(session.log or log)("debug", "incoming s2s received <stream:stream>");
diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua
index 762982c1..efc99366 100644
--- a/core/sessionmanager.lua
+++ b/core/sessionmanager.lua
@@ -23,6 +23,7 @@ local error = error;
local uuid_generate = require "util.uuid".generate;
local rm_load_roster = require "core.rostermanager".load_roster;
local config_get = require "core.configmanager".get;
+local nameprep = require "util.encodings".stringprep.nameprep;
local fire_event = require "core.eventmanager".fire_event;
@@ -156,6 +157,7 @@ end
function streamopened(session, attr)
local send = session.send;
session.host = attr.to or error("Client failed to specify destination hostname");
+ session.host = nameprep(session.host);
session.version = tonumber(attr.version) or 0;
session.streamid = m_random(1000000, 99999999);
(session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host);
diff --git a/core/stanza_router.lua b/core/stanza_router.lua
index ef973ba2..bbbb6385 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -51,9 +51,11 @@ function core_process_stanza(origin, stanza)
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)
- if stanza.name == "iq" and #stanza.tags > 1 then
- if stanza.attr.type == "set" or stanza.attr.type == "get" then
- error("Invalid IQ");
+ if stanza.attr.xmlns == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log
+ if stanza.name == "iq" then
+ if (stanza.attr.type == "set" or stanza.attr.type == "get") and #stanza.tags ~= 1 then
+ origin.send(st.error_reply(stanza, "modify", "bad-request"));
+ return;
end
end