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(+) 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(-) 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(+) 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 7d63169215f0c4c0384c717980ef54ab458c5cf3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 22 Nov 2009 21:45:31 +0500 Subject: mod_presence: Acknowledge subscription requests by responding with an unavailable presence. --- plugins/mod_presence.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index f83e017b..468049cc 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -233,6 +233,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) end else + core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- acknowledging receipt if not rostermanager.is_contact_pending_in(node, host, from_bare) then if rostermanager.set_contact_pending_in(node, host, from_bare) then sessionmanager.send_to_available_resources(node, host, stanza); -- cgit v1.2.3 From 889562f945cc57d19db944d6085fdfe5683dea5d Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 22 Nov 2009 21:47:54 +0500 Subject: mod_presence: Route incoming presence subscription stanzas (types unsubscribe, subscribed and unsubscribed) to the user before roster pushes. --- plugins/mod_presence.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 468049cc..cda8dab0 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -242,14 +242,17 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b end elseif stanza.attr.type == "unsubscribe" then if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then + sessionmanager.send_to_interested_resources(node, host, stanza); rostermanager.roster_push(node, host, from_bare); end elseif stanza.attr.type == "subscribed" then if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then + sessionmanager.send_to_interested_resources(node, host, stanza); rostermanager.roster_push(node, host, from_bare); end elseif stanza.attr.type == "unsubscribed" then if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then + sessionmanager.send_to_interested_resources(node, host, stanza); rostermanager.roster_push(node, host, from_bare); end end -- discard any other type -- cgit v1.2.3 From 3f95c8572ce3c94b1ac4f2040ed803efbe974308 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 23 Nov 2009 08:55:27 +0500 Subject: Mainfile: Fixed some comments. --- prosody | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prosody b/prosody index ae9cd2fc..8dd37f30 100755 --- a/prosody +++ b/prosody @@ -14,7 +14,7 @@ CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); CFG_PLUGINDIR=os.getenv("PROSODY_PLUGINDIR"); CFG_DATADIR=os.getenv("PROSODY_DATADIR"); --- -- -- -- -- -- -- ---- -- -- -- -- -- -- -- -- +-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- if CFG_SOURCEDIR then package.path = CFG_SOURCEDIR.."/?.lua;"..package.path; @@ -82,13 +82,13 @@ function read_config() end function load_libraries() - --- Initialize logging + -- Initialize logging require "core.loggingmanager" - --- Check runtime dependencies + -- Check runtime dependencies require "util.dependencies" - --- Load socket framework + -- Load socket framework server = require "net.server" end -- cgit v1.2.3 From 8d13f90bed046737e1c005ed837ec09c95192d57 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 23 Nov 2009 19:35:24 +0500 Subject: util.serialization: Concise output for empty tables. --- util/serialization.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/util/serialization.lua b/util/serialization.lua index c2bbbb8d..2a1fad02 100644 --- a/util/serialization.lua +++ b/util/serialization.lua @@ -13,6 +13,7 @@ local t_insert = table.insert; local t_concat = table.concat; local error = error; local pairs = pairs; +local next = next; local debug_traceback = debug.traceback; local log = require "util.logger".init("serialization"); @@ -34,21 +35,25 @@ local function _simplesave(o, ind, t, func) elseif type(o) == "string" then func(t, (("%q"):format(o):gsub("\\\n", "\\n"))); elseif type(o) == "table" then - func(t, "{\n"); - for k,v in pairs(o) do - func(t, indent(ind)); - func(t, "["); - func(t, basicSerialize(k)); - func(t, "] = "); - if ind == 0 then - _simplesave(v, 0, t, func); - else - _simplesave(v, ind+1, t, func); + if next(o) then + func(t, "{\n"); + for k,v in pairs(o) do + func(t, indent(ind)); + func(t, "["); + func(t, basicSerialize(k)); + func(t, "] = "); + if ind == 0 then + _simplesave(v, 0, t, func); + else + _simplesave(v, ind+1, t, func); + end + func(t, ",\n"); end - func(t, ",\n"); + func(t, indent(ind-1)); + func(t, "}"); + else + func(t, "{}"); end - func(t, indent(ind-1)); - func(t, "}"); elseif type(o) == "boolean" then func(t, (o and "true" or "false")); else -- cgit v1.2.3 From 5b41760cecdfd2db66b84ce92454dd61e7f1341b Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 23 Nov 2009 19:50:04 +0500 Subject: util.serialization: Replaced commas with semi-colons between table fields. --- util/serialization.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/serialization.lua b/util/serialization.lua index 2a1fad02..07a099c9 100644 --- a/util/serialization.lua +++ b/util/serialization.lua @@ -47,7 +47,7 @@ local function _simplesave(o, ind, t, func) else _simplesave(v, ind+1, t, func); end - func(t, ",\n"); + func(t, ";\n"); end func(t, indent(ind-1)); func(t, "}"); -- cgit v1.2.3 From 7b44078ada9106c282c5ba41a75728b45ac6a65e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 23 Nov 2009 21:46:37 +0500 Subject: prosody: Added support for command line argument '--config'. --- prosody | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/prosody b/prosody index 8dd37f30..7f69e085 100755 --- a/prosody +++ b/prosody @@ -58,7 +58,27 @@ config = require "core.configmanager" function read_config() -- TODO: Check for other formats when we add support for them -- Use lfs? Make a new conf/ dir? - local ok, level, err = config.load((CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); + local filenames = {}; + + local filename; + if arg[1] == "--config" and arg[2] then + table.insert(filenames, arg[2]); + if CFG_CONFIGDIR then + table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]); + end + else + table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); + end + for _,_filename in ipairs(filenames) do + filename = _filename; + local file = io.open(filename); + if file then + file:close(); + CFG_CONFIGDIR = filename:match("^(.*)[\\/][^\\/]*$"); + break; + end + end + local ok, level, err = config.load(filename); if not ok then print("\n"); print("**************************"); -- cgit v1.2.3 From 4e56a3c519bc0d46a3491ca18cb58c3e8dbb5ae9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 24 Nov 2009 22:42:08 +0500 Subject: xmppclient_listener: Escape control characters when logging invalid XML. --- net/xmppclient_listener.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 417dfd4a..01d73a36 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -61,7 +61,7 @@ local function session_reset_stream(session) function session.data(conn, data) local ok, err = parser:parse(data); if ok then return; end - log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); + log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); session:close("xml-not-well-formed"); end -- cgit v1.2.3