From 95b463a3ee6dc6d93e1c7b39d043357a4c72f6b1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Nov 2009 20:34:22 +0000 Subject: core.sessionmanager, net.*_listener: Remove the evil collectgarbage() calls --- core/sessionmanager.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 5e7fe06d..9aafe0bf 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -10,7 +10,6 @@ local tonumber, tostring = tonumber, tostring; local ipairs, pairs, print, next= ipairs, pairs, print, next; -local collectgarbage = collectgarbage; local format = import("string", "format"); local hosts = hosts; -- cgit v1.2.3 From 2f8bd04c9ca0fbbc40b1f9630816f3976e6754df Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 03:02:04 +0500 Subject: modulemanager: Fire item-removed events on module unload. --- core/modulemanager.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 9cd56187..ecb1bc6c 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -197,6 +197,15 @@ function unload(host, name, ...) end end hooks:remove(host, name); + if mod.module.items then -- remove items + for key,t in pairs(mod.module.items) do + for i = #t,1,-1 do + local value = t[i]; + t[i] = nil; + hosts[host].events.fire_event("item-removed/"..key, {source = self, item = value}); + end + end + end modulemap[host][name] = nil; return true; end -- cgit v1.2.3 From 909e439525e41721abd91b227c7f9078aeda504b Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 11 Jan 2010 18:59:06 +0500 Subject: sessionmanager: Added resource prepping, and invalid resource checking to the bind_resource function. --- core/sessionmanager.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 9aafe0bf..df144f07 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -24,6 +24,7 @@ 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 resourceprep = require "util.encodings".stringprep.resourceprep; local fire_event = require "core.eventmanager".fire_event; local add_task = require "util.timer".add_task; @@ -105,7 +106,8 @@ function bind_resource(session, resource) if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end -- We don't support binding multiple resources - resource = resource or uuid_generate(); + resource = resourceprep(resource); + resource = resource ~= "" and resource or uuid_generate(); --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing if not hosts[session.host].sessions[session.username] then -- cgit v1.2.3 From f4e886e7177eaf24ac415e3b8ebc80af256a3232 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Jan 2010 16:31:57 +0000 Subject: stanza_router: Log the name of unhandled stanzas (thanks bear) --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 00c37ed7..b60ff2b5 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -191,6 +191,6 @@ function core_route_stanza(origin, stanza) log("debug", "Routing outgoing stanza for %s to %s", from_host, host); send_s2s(from_host, host, stanza); else - log("warn", "received stanza from unhandled connection type: %s", origin.type); + log("warn", "received %s stanza from unhandled connection type: %s", tostring(stanza.name), tostring(origin.type)); end end -- cgit v1.2.3 From b7d45c17f2c325f55ef9cb27b1896d4b7ee8d324 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 21:04:36 +0500 Subject: stanza_router: Added third parameter to core_post_stanza, to control pre-events. --- core/stanza_router.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index b60ff2b5..b025511e 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -98,7 +98,7 @@ function core_process_stanza(origin, stanza) return; -- FIXME what should we do here? does this work with subdomains? end end - core_post_stanza(origin, stanza); + core_post_stanza(origin, stanza, origin.full_jid); else local h = hosts[stanza.attr.to or origin.host or origin.to_host]; if h then @@ -119,7 +119,7 @@ function core_process_stanza(origin, stanza) end end -function core_post_stanza(origin, stanza) +function core_post_stanza(origin, stanza, preevents) local to = stanza.attr.to; local node, host, resource = jid_split(to); local to_bare = node and (node.."@"..host) or host; -- bare JID @@ -143,7 +143,7 @@ function core_post_stanza(origin, stanza) end local event_data = {origin=origin, stanza=stanza}; - if origin.full_jid == stanza.attr.from then -- c2s connection + if preevents then -- c2s connection if hosts[origin.host].events.fire_event('pre-'..stanza.name..to_type, event_data) then return; end -- do preprocessing end local h = hosts[to_bare] or hosts[host or origin.host]; -- cgit v1.2.3 From f3444ceaa2a879e7823bd772791bc7c31dc61075 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 12:43:50 +0000 Subject: hostmanager: Log an error if no hosts are defined --- core/hostmanager.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'core') diff --git a/core/hostmanager.lua b/core/hostmanager.lua index f89eaeba..8010b3de 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -33,12 +33,19 @@ local hosts_loaded_once; local function load_enabled_hosts(config) local defined_hosts = config or configmanager.getconfig(); + local activated_any_host; for host, host_config in pairs(defined_hosts) do if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) and not host_config.core.component_module then + activated_any_host = true; activate(host, host_config); end end + + if not activated_any_host then + log("error", "No hosts defined in the config file. This may cause unexpected behaviour as no modules will be loaded."); + end + eventmanager.fire_event("hosts-activated", defined_hosts); hosts_loaded_once = true; end -- cgit v1.2.3 From 2739ed3948b9df3a596d6aef6d6790f1c2e1c59f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 17:14:54 +0000 Subject: sessionmanager, s2smanager: Give sessions dummy data handlers that log when data is received by a destroyed session --- core/s2smanager.lua | 3 +++ core/sessionmanager.lua | 3 +++ 2 files changed, 6 insertions(+) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index bfa3069a..7de97d0c 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -491,6 +491,8 @@ function mark_connected(session) end end +local function null_data_handler(data) log("debug", "Discarding data from destroyed s2s session: %s", data); end + function destroy_session(session) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); @@ -506,6 +508,7 @@ function destroy_session(session) session[k] = nil; end end + session.data = null_data_handler; end return _M; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index df144f07..9df7823c 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -66,6 +66,8 @@ function new_session(conn) return session; end +local function null_data_handler(data) log("debug", "Discarding data from destroyed c2s session: %s", data); end + function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); @@ -88,6 +90,7 @@ function destroy_session(session, err) session[k] = nil; end end + session.data = null_data_handler; end function make_authenticated(session, username) -- cgit v1.2.3 From 4a592b5069548aa13a6aad96a1fcb54222345290 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 17:27:53 +0000 Subject: sessionmanager, s2smanager: Fix for syntax of null_data_handler() (thanks Nolan) --- core/s2smanager.lua | 2 +- core/sessionmanager.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 7de97d0c..e8d8e723 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -491,7 +491,7 @@ function mark_connected(session) end end -local function null_data_handler(data) log("debug", "Discarding data from destroyed s2s session: %s", data); end +local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed s2s session: %s", data); end function destroy_session(session) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 9df7823c..2dd0070b 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -66,7 +66,7 @@ function new_session(conn) return session; end -local function null_data_handler(data) log("debug", "Discarding data from destroyed c2s session: %s", data); end +local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed c2s session: %s", data); end function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); -- cgit v1.2.3 From 8b0ec93370f16cb2b4da3a2dd7734d6d41175312 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Feb 2010 18:41:44 +0000 Subject: configmanager: Error when a component and host clash hostnames --- core/configmanager.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/configmanager.lua b/core/configmanager.lua index 1fbe83b8..7ae472f6 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -9,8 +9,11 @@ local _G = _G; -local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type = - setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type; +local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, format = + setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; + + +local trb = debug.traceback local eventmanager = require "core.eventmanager"; @@ -115,6 +118,10 @@ do rawset(env, "__currenthost", "*") -- Default is global function env.Host(name) + if rawget(config, name) and rawget(config[name].core, "component_module") then + error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", + name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); + end rawset(env, "__currenthost", name); -- Needs at least one setting to logically exist :) set(name or "*", "core", "defined", true); @@ -122,6 +129,10 @@ do env.host = env.Host; function env.Component(name) + if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then + error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", + name, name, name), 0); + end set(name, "core", "component_module", "component"); -- Don't load the global modules by default set(name, "core", "load_global_modules", false); -- cgit v1.2.3 From 4d3d1789cc57c1c0b9ce8d199a95a9a412f9d723 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Feb 2010 20:37:49 +0000 Subject: configmanager: Remove debugging code accidentally committed --- core/configmanager.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'core') diff --git a/core/configmanager.lua b/core/configmanager.lua index 7ae472f6..a7c7c4be 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -13,8 +13,6 @@ local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, p setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; -local trb = debug.traceback - local eventmanager = require "core.eventmanager"; module "configmanager" -- cgit v1.2.3 From 836da37747ac1d76aa76dbc38354daac8c79bb40 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 4 Mar 2010 02:20:17 +0500 Subject: stanza_router: Allow non-jabber:client elements after auth, before bind. --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index b025511e..cd7c650b 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -36,7 +36,7 @@ function core_process_stanza(origin, stanza) end end - if origin.type == "c2s" then + if origin.type == "c2s" and stanza.attr.xmlns == "jabber:client" then if not origin.full_jid and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then -- cgit v1.2.3 From 5d9b9b6b30f06a3e3aa957279357dd42ae19ddf4 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 4 Mar 2010 02:22:45 +0500 Subject: stanza_router: Don't send error replies for stanzas of type 'error' and 'result' on unbound authenticated connections. --- core/stanza_router.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/stanza_router.lua b/core/stanza_router.lua index cd7c650b..b5b1b45f 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -41,7 +41,9 @@ function core_process_stanza(origin, stanza) and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then -- authenticated client isn't bound and current stanza is not a bind request - origin.send(st.error_reply(stanza, "auth", "not-authorized")); -- FIXME maybe allow stanzas to account or server + if stanza.attr.type ~= "result" and stanza.attr.type ~= "error" then + origin.send(st.error_reply(stanza, "auth", "not-authorized")); -- FIXME maybe allow stanzas to account or server + end return; end -- cgit v1.2.3