From 1c3c5302ba25e5474f5319f2f766a0a9dc31802c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Mar 2016 23:15:08 +0000 Subject: util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID --- tests/test_util_jid.lua | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ util/jid.lua | 15 +++++++++++ 2 files changed, 85 insertions(+) diff --git a/tests/test_util_jid.lua b/tests/test_util_jid.lua index 02a90c3b..c697e63f 100644 --- a/tests/test_util_jid.lua +++ b/tests/test_util_jid.lua @@ -71,3 +71,73 @@ function compare(compare) assert_equal(compare("user@other-host", "host"), false, "host should not match"); assert_equal(compare("user@other-host", "user@host"), false, "host should not match"); end + +function node(node) + local function test(jid, expected_node) + assert_equal(node(jid), expected_node, "Unexpected node for "..tostring(jid)); + end + + test("example.com", nil); + test("foo.example.com", nil); + test("foo.example.com/resource", nil); + test("foo.example.com/some resource", nil); + test("foo.example.com/some@resource", nil); + + test("foo@foo.example.com/some@resource", "foo"); + test("foo@example/some@resource", "foo"); + + test("foo@example/@resource", "foo"); + test("foo@example@resource", nil); + test("foo@example", "foo"); + test("foo", nil); + + test(nil, nil); +end + +function host(host) + local function test(jid, expected_host) + assert_equal(host(jid), expected_host, "Unexpected host for "..tostring(jid)); + end + + test("example.com", "example.com"); + test("foo.example.com", "foo.example.com"); + test("foo.example.com/resource", "foo.example.com"); + test("foo.example.com/some resource", "foo.example.com"); + test("foo.example.com/some@resource", "foo.example.com"); + + test("foo@foo.example.com/some@resource", "foo.example.com"); + test("foo@example/some@resource", "example"); + + test("foo@example/@resource", "example"); + test("foo@example@resource", nil); + test("foo@example", "example"); + test("foo", "foo"); + + test(nil, nil); +end + +function resource(resource) + local function test(jid, expected_resource) + assert_equal(resource(jid), expected_resource, "Unexpected resource for "..tostring(jid)); + end + + test("example.com", nil); + test("foo.example.com", nil); + test("foo.example.com/resource", "resource"); + test("foo.example.com/some resource", "some resource"); + test("foo.example.com/some@resource", "some@resource"); + + test("foo@foo.example.com/some@resource", "some@resource"); + test("foo@example/some@resource", "some@resource"); + + test("foo@example/@resource", "@resource"); + test("foo@example@resource", nil); + test("foo@example", nil); + test("foo", nil); + test("/foo", nil); + test("@x/foo", nil); + test("@/foo", nil); + + test(nil, nil); +end + diff --git a/util/jid.lua b/util/jid.lua index 76155ac7..60bb0829 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -93,6 +93,18 @@ local function compare(jid, acl) return false end +local function node(jid) + return (select(1, split(jid))); +end + +local function host(jid) + return (select(2, split(jid))); +end + +local function resource(jid) + return (select(3, split(jid))); +end + local function escape(s) return s and (s:gsub(".", escapes)); end local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end @@ -103,6 +115,9 @@ return { join = join; prep = prep; compare = compare; + node = node; + host = host; + resource = resource; escape = escape; unescape = unescape; }; -- cgit v1.2.3 From 42f15c4eb2f1b52b886f70eefe9c89697e825529 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 18 Mar 2016 10:24:46 +0000 Subject: prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308. --- prosody | 8 ++++---- prosodyctl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/prosody b/prosody index 6a3b50db..9cc32cee 100755 --- a/prosody +++ b/prosody @@ -11,10 +11,10 @@ -- Will be modified by configure script if run -- -CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); -CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); -CFG_PLUGINDIR=os.getenv("PROSODY_PLUGINDIR"); -CFG_DATADIR=os.getenv("PROSODY_DATADIR"); +CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); +CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); +CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); +CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR"); -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- diff --git a/prosodyctl b/prosodyctl index a7483456..7c8659fb 100755 --- a/prosodyctl +++ b/prosodyctl @@ -11,10 +11,10 @@ -- Will be modified by configure script if run -- -CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); -CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); -CFG_PLUGINDIR=os.getenv("PROSODY_PLUGINDIR"); -CFG_DATADIR=os.getenv("PROSODY_DATADIR"); +CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); +CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); +CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); +CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR"); -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- cgit v1.2.3 From 94c745e8e83bcabc945e93ebffb5f5eead5544bf Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 18 Mar 2016 11:51:58 +0100 Subject: mod_saslauth: Disable DIGEST-MD5 by default (closes #515) --- plugins/mod_saslauth.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 7e9b0720..bb36600b 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -19,7 +19,7 @@ local tostring = tostring; local secure_auth_only = module:get_option_boolean("c2s_require_encryption", module:get_option_boolean("require_encryption", false)); local allow_unencrypted_plain_auth = module:get_option_boolean("allow_unencrypted_plain_auth", false) local insecure_mechanisms = module:get_option_set("insecure_sasl_mechanisms", allow_unencrypted_plain_auth and {} or {"PLAIN", "LOGIN"}); -local disabled_mechanisms = module:get_option_set("disable_sasl_mechanisms", {}); +local disabled_mechanisms = module:get_option_set("disable_sasl_mechanisms", { "DIGEST-MD5" }); local log = module._log; -- cgit v1.2.3 From 4b907ce3ffd17d7f2a1464156fd186506e6904c8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 18 Mar 2016 13:58:55 +0000 Subject: mod_component: Fire event when component disconnects --- plugins/mod_component.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua index a5136f6c..7709d185 100644 --- a/plugins/mod_component.lua +++ b/plugins/mod_component.lua @@ -314,6 +314,7 @@ function listener.ondisconnect(conn, err) local session = sessions[conn]; if session then (session.log or log)("info", "component disconnected: %s (%s)", tostring(session.host), tostring(err)); + module:fire_event("component-disconnected", { session = session, reason = err }); if session.on_destroy then session:on_destroy(err); end sessions[conn] = nil; for k in pairs(session) do -- cgit v1.2.3 From f739ed2c46827cca1b0b7af08320584886e76283 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 18 Mar 2016 14:03:14 +0000 Subject: mod_component: Some cleanup [luacheck] --- plugins/mod_component.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua index 7709d185..eebaaf3e 100644 --- a/plugins/mod_component.lua +++ b/plugins/mod_component.lua @@ -40,7 +40,7 @@ function module.add_host(module) local send; - local function on_destroy(session, err) + local function on_destroy(session, err) --luacheck: ignore 212/err env.connected = false; env.session = false; send = nil; @@ -149,7 +149,7 @@ local stream_callbacks = { default_ns = xmlns_component }; local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; -function stream_callbacks.error(session, error, data, data2) +function stream_callbacks.error(session, error, data) if session.destroyed then return; end module:log("warn", "Error processing component stream: %s", tostring(error)); if error == "no-stream" then @@ -295,7 +295,7 @@ function listener.onconnect(conn) session.stream:reset(); end - function session.data(conn, data) + function session.data(_, data) local ok, err = stream:feed(data); if ok then return; end module:log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); @@ -323,7 +323,6 @@ function listener.ondisconnect(conn, err) end end session.destroyed = true; - session = nil; end end -- cgit v1.2.3