From 38dc47caaef527891f068fb666af55f41ee3cb5b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 21 Nov 2009 13:47:45 +0000 Subject: s2smanager: Don't tostring() the data before sending, sends2s already does this. --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 4c61eaa3..aa6de317 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -391,7 +391,7 @@ function streamopened(session, attr) if send_buffer and #send_buffer > 0 then log("debug", "Sending s2s send_buffer now..."); for i, data in ipairs(send_buffer) do - session.sends2s(tostring(data)); + session.sends2s(data); send_buffer[i] = nil; end end -- cgit v1.2.3 From c3ed7fbfced3ef8d3cb76185106bed6270104783 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 21 Nov 2009 13:49:48 +0000 Subject: s2smanager: Don't log full stanza when sending outwards --- core/s2smanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index aa6de317..d8edaed0 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -128,7 +128,7 @@ function new_incoming(conn) open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); session.log = log; - session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end + session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^([^>]*>?)")); w(tostring(t)); end incoming_s2s[session] = true; add_task(connect_timeout, function () if session.conn ~= conn or @@ -317,7 +317,7 @@ function make_connect(host_session, connect_host, connect_port) cl.register_outgoing(conn, host_session); local w, log = conn.write, host_session.log; - host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end + host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(tostring(t)); end conn.write(format([[]], from_host, to_host)); log("debug", "Connection attempt in progress..."); -- cgit v1.2.3 From ecb81f3ad2145fc28cbc81c87769cc1cf6ad61d1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 21 Nov 2009 17:07:22 +0000 Subject: sessionmanager: Use : syntax for calling connection methods --- core/sessionmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 08e70d44..7e609f22 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -50,8 +50,8 @@ function new_session(conn) open_sessions = open_sessions + 1; log("debug", "open sessions now: ".. open_sessions); local w = conn.write; - session.send = function (t) w(tostring(t)); end - session.ip = conn.ip(); + session.send = function (t) w(conn, tostring(t)); end + session.ip = conn:ip(); local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); session.log = logger.init(conn_name); -- cgit v1.2.3 From 2b75fe3807dcaa4aeafbe8adb864c8540933e8e3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 21 Nov 2009 23:04:26 +0000 Subject: objectmanager: Convert to unix line-endings --- core/objectmanager.lua | 120 ++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'core') diff --git a/core/objectmanager.lua b/core/objectmanager.lua index e96cbd90..293622c9 100644 --- a/core/objectmanager.lua +++ b/core/objectmanager.lua @@ -6,63 +6,63 @@ -- COPYING file in the source package for more information. -- - -local new_multitable = require "util.multitable".new; -local t_insert = table.insert; -local t_concat = table.concat; -local tostring = tostring; -local unpack = unpack; -local pairs = pairs; -local error = error; -local type = type; -local _G = _G; - -local data = new_multitable(); - -module "objectmanager" - -function set(...) - return data:set(...); -end -function remove(...) - return data:remove(...); -end -function get(...) - return data:get(...); -end - -local function get_path(path) - if type(path) == "table" then return path; end - local s = {}; - for part in tostring(path):gmatch("[%w_]+") do - t_insert(s, part); - end - return s; -end - -function get_object(path) - path = get_path(path) - return data:get(unpack(path)), path; -end -function set_object(path, object) - path = get_path(path); - data:set(unpack(path), object); -end - -data:set("ls", function(_dir) - local obj, dir = get_object(_dir); - if not obj then error("object not found: " .. t_concat(dir, '/')); end - local r = {}; - if type(obj) == "table" then - for key, val in pairs(obj) do - r[key] = type(val); - end - end - return r; -end); -data:set("get", get_object); -data:set("set", set_object); -data:set("echo", function(...) return {...}; end); -data:set("_G", _G); - -return _M; + +local new_multitable = require "util.multitable".new; +local t_insert = table.insert; +local t_concat = table.concat; +local tostring = tostring; +local unpack = unpack; +local pairs = pairs; +local error = error; +local type = type; +local _G = _G; + +local data = new_multitable(); + +module "objectmanager" + +function set(...) + return data:set(...); +end +function remove(...) + return data:remove(...); +end +function get(...) + return data:get(...); +end + +local function get_path(path) + if type(path) == "table" then return path; end + local s = {}; + for part in tostring(path):gmatch("[%w_]+") do + t_insert(s, part); + end + return s; +end + +function get_object(path) + path = get_path(path) + return data:get(unpack(path)), path; +end +function set_object(path, object) + path = get_path(path); + data:set(unpack(path), object); +end + +data:set("ls", function(_dir) + local obj, dir = get_object(_dir); + if not obj then error("object not found: " .. t_concat(dir, '/')); end + local r = {}; + if type(obj) == "table" then + for key, val in pairs(obj) do + r[key] = type(val); + end + end + return r; +end); +data:set("get", get_object); +data:set("set", set_object); +data:set("echo", function(...) return {...}; end); +data:set("_G", _G); + +return _M; -- cgit v1.2.3 From 8da42f8d71b94aacf7b914bd9c1d1147cb33e041 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Nov 2009 04:42:03 +0000 Subject: s2smanager: Update for new net.server API (s2s still doesn't work with libevent for other reasons) --- core/s2smanager.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 4c61eaa3..5dae58c9 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -128,7 +128,7 @@ function new_incoming(conn) open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); session.log = log; - session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end + session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(conn, tostring(t)); end incoming_s2s[session] = true; add_task(connect_timeout, function () if session.conn ~= conn or @@ -317,9 +317,9 @@ function make_connect(host_session, connect_host, connect_port) cl.register_outgoing(conn, host_session); local w, log = conn.write, host_session.log; - host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end + host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(conn, tostring(t)); end - conn.write(format([[]], from_host, to_host)); + conn:write(format([[]], from_host, to_host)); log("debug", "Connection attempt in progress..."); add_task(connect_timeout, function () if host_session.conn ~= conn or -- cgit v1.2.3 From 87edc64c11a5f38229c915f32165bccd2de65a84 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Nov 2009 04:46:48 +0000 Subject: stanza_router: Don't log full stanzas destined for s2s --- 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..ad312b85 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -180,7 +180,7 @@ function core_route_stanza(origin, stanza) local xmlns = stanza.attr.xmlns; --stanza.attr.xmlns = "jabber:server"; stanza.attr.xmlns = nil; - log("debug", "sending s2s stanza: %s", tostring(stanza)); + log("debug", "sending s2s stanza: %s", tostring(stanza.top_tag and stanza:top_tag()) or stanza); send_s2s(origin.host, host, stanza); -- TODO handle remote routing errors stanza.attr.xmlns = xmlns; -- reset else -- cgit v1.2.3 From a1efb7e1423a9ee1e529979b098481fedce9a3a1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Nov 2009 04:53:02 +0000 Subject: s2smanager: Fix syntax error introduced in merge --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index fb532a73..e1f70693 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -128,7 +128,7 @@ function new_incoming(conn) open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); session.log = log; - session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^([^>]*>?)"); w(conn, tostring(t)); end + session.sends2s = function (t) log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); w(conn, tostring(t)); end incoming_s2s[session] = true; add_task(connect_timeout, function () if session.conn ~= conn or -- cgit v1.2.3 From b50d8bac6f81907e48aaa650311861a60abcd2ed Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 22 Nov 2009 21:33:41 +0500 Subject: loggingmanager: Explicitly flush log messages if the __FLUSH_LOG environment variable is defined (workaround for MSVCRT buffering piped output). --- core/loggingmanager.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'core') diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index c26fdc71..4154e1a7 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -17,6 +17,12 @@ local math_max, rep = math.max, string.rep; local os_date, os_getenv = os.date, os.getenv; local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; +if os.getenv("__FLUSH_LOG") then + local io_flush = io.flush; + local _io_write = io_write; + io_write = function(...) _io_write(...); io_flush(); end +end + local config = require "core.configmanager"; local eventmanager = require "core.eventmanager"; local logger = require "util.logger"; -- cgit v1.2.3 From 10d98b6eef93eff3a0c5b305aea051017e282785 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 22 Nov 2009 21:40:01 +0500 Subject: sessionmanager: Fixed and cleaned function send_to_available_resources(). The 'to' attribute for presence subscription stanzas is now preserved. --- core/sessionmanager.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 08e70d44..8de70e97 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -201,22 +201,17 @@ function streamclosed(session) end function send_to_available_resources(user, host, stanza) + local jid = user.."@"..host; local count = 0; - local to = stanza.attr.to; - stanza.attr.to = nil; - local h = hosts[host]; - if h and h.type == "local" then - local u = h.sessions[user]; - if u then - for k, session in pairs(u.sessions) do - if session.presence then - session.send(stanza); - count = count + 1; - end + local user = bare_sessions[jid]; + if user then + for k, session in pairs(user.sessions) do + if session.presence then + session.send(stanza); + count = count + 1; end end end - stanza.attr.to = to; return count; end -- cgit v1.2.3 From bb00a63d236fffcfcbea919c12e8585b1c20cadb Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 22 Nov 2009 21:41:09 +0500 Subject: sessionmanager: Added function send_to_interested_resources(). --- core/sessionmanager.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 8de70e97..5e7fe06d 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -215,4 +215,19 @@ function send_to_available_resources(user, host, stanza) return count; end +function send_to_interested_resources(user, host, stanza) + local jid = user.."@"..host; + local count = 0; + local user = bare_sessions[jid]; + if user then + for k, session in pairs(user.sessions) do + if session.interested then + session.send(stanza); + count = count + 1; + end + end + end + return count; +end + return _M; -- cgit v1.2.3 From 0ccdad92eff7fd98d9d4a6d3c0edbd8db21279c0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Nov 2009 16:07:33 +0000 Subject: modulemanager: New module API methods for getting config options with type conversion, get_option_string, get_option_number, get_option_boolean, get_option_array, get_option_set --- core/modulemanager.lua | 83 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 9cd56187..d1f7d413 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -28,7 +28,9 @@ local type = type; local next = next; local rawget = rawget; local error = error; -local tostring = tostring; +local tostring, tonumber = tostring, tonumber; + +local array, set = require "util.array", require "util.set"; local autoload_modules = {"presence", "message", "iq"}; @@ -400,6 +402,85 @@ function api:get_option(name, default_value) return value; end +function api:get_option_string(...) + local value = self:get_option(...); + if type(value) == "table" then + if #value > 1 then + self:log("error", "Config option '%s' does not take a list, using just the first item", name); + end + value = value[1]; + end + if value == nil then + return nil; + end + return tostring(value); +end + +function api:get_option_number(name, ...) + local value = self:get_option(name, ...); + if type(value) == "table" then + if #value > 1 then + self:log("error", "Config option '%s' does not take a list, using just the first item", name); + end + value = value[1]; + end + local ret = tonumber(value); + if value ~= nil and ret == nil then + self:log("error", "Config option '%s' not understood, expecting a number", name); + end + return ret; +end + +function api:get_option_boolean(name, ...) + local value = self:get_option(name, ...); + if type(value) == "table" then + if #value > 1 then + self:log("error", "Config option '%s' does not take a list, using just the first item", name); + end + value = value[1]; + end + if value == nil then + return nil; + end + local ret = value == true or value == "true" or value == 1 or nil; + if ret == nil then + ret = (value == false or value == "false" or value == 0); + if ret then + ret = false; + else + ret = nil; + end + end + if ret == nil then + self:log("error", "Config option '%s' not understood, expecting true/false", name); + end + return ret; +end + +function api:get_option_array(name, ...) + local value = self:get_option(name, ...); + + if value == nil then + return nil; + end + + if type(value) ~= "table" then + return array{ value }; -- Assume any non-list is a single-item list + end + + return array():append(value); -- Clone +end + +function api:get_option_set(name, ...) + local value = self:get_option_array(name, ...); + + if value == nil then + return nil; + end + + return set.new(value); +end + local t_remove = _G.table.remove; local module_items = multitable_new(); function api:add_item(key, value) -- cgit v1.2.3 From f5afdcb5642fb5260717613cc7909e20805a957c 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 380d8129..69160af7 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 c4742ed7810b3e10bfc6bdb55a11c31b3faf5426 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 25 Nov 2009 03:30:00 +0000 Subject: s2smanager: Log warning when trying to send a stanza from a host we don't serve, instead of a traceback (thanks stpeter) --- core/s2smanager.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 4c61eaa3..20d932e8 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -79,6 +79,10 @@ local function bounce_sendq(session) end function send_to_host(from_host, to_host, data) + if not hosts[from_host] then + log("warn", "Attempt to send stanza from %s - a host we don't serve", from_host); + return false; + end local host = hosts[from_host].s2sout[to_host]; if host then -- We have a connection to this host already -- cgit v1.2.3 From fb4bbe19bf54b792b2321d2a4e95bca9c28360d9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 26 Nov 2009 17:17:54 +0000 Subject: s2smanager: Allow configuration of the dialback_secret in the config --- core/s2smanager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 666022d1..f4d46802 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -36,13 +36,12 @@ local log = logger_init("s2smanager"); local sha256_hash = require "util.hashes".sha256; -local dialback_secret = uuid_gen(); - local adns, dns = require "net.adns", require "net.dns"; local config = require "core.configmanager"; local connect_timeout = config.get("*", "core", "s2s_timeout") or 60; local dns_timeout = config.get("*", "core", "dns_timeout") or 60; local max_dns_depth = config.get("*", "core", "dns_max_depth") or 3; +local dialback_secret = config.get("*", "core", "dialback_secret") or uuid_gen(); incoming_s2s = {}; _G.prosody.incoming_s2s = incoming_s2s; -- cgit v1.2.3 From beb6fa2f210bbf8ea8d976f11728d20c5b41ad42 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 28 Nov 2009 12:00:31 +0500 Subject: core.xmlhandlers: Fixed processing of empty namespaces (which caused an issue with jwchat). --- core/xmlhandlers.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index d679af97..82c2d0b8 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -50,7 +50,7 @@ function init_xmlhandlers(session, stream_callbacks) chardata = {}; end local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$"); - if not name then + if name == "" then curr_ns, name = "", curr_ns; end @@ -63,7 +63,7 @@ function init_xmlhandlers(session, stream_callbacks) local k = attr[i]; attr[i] = nil; local ns, nm = k:match("^([^\1]*)\1?(.*)$"); - if ns and nm then + if nm ~= "" then ns = ns_prefixes[ns]; if ns then attr[ns..":"..nm] = attr[k]; @@ -105,7 +105,7 @@ function init_xmlhandlers(session, stream_callbacks) end function xml_handlers:EndElement(tagname) local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$"); - if not name then + if name == "" then curr_ns, name = "", curr_ns; end if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then -- cgit v1.2.3