Merge
authorKim Alvefur <zash@zash.se>
Fri, 18 Mar 2016 11:55:40 +0100
changeset 7302 b7dea8fd09c7
parent 7301 7056bbaf81ee (current diff)
parent 7300 b34a42a10c9f (diff)
child 7303 66e7517bd8f3
Merge
--- a/prosody	Fri Mar 18 11:51:58 2016 +0100
+++ b/prosody	Fri Mar 18 11:55:40 2016 +0100
@@ -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");
 
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
--- a/prosodyctl	Fri Mar 18 11:51:58 2016 +0100
+++ b/prosodyctl	Fri Mar 18 11:55:40 2016 +0100
@@ -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");
 
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
--- a/tests/test_util_jid.lua	Fri Mar 18 11:51:58 2016 +0100
+++ b/tests/test_util_jid.lua	Fri Mar 18 11:55:40 2016 +0100
@@ -71,3 +71,73 @@
 	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
+
--- a/util/jid.lua	Fri Mar 18 11:51:58 2016 +0100
+++ b/util/jid.lua	Fri Mar 18 11:55:40 2016 +0100
@@ -93,6 +93,18 @@
 	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 @@
 	join = join;
 	prep = prep;
 	compare = compare;
+	node = node;
+	host = host;
+	resource = resource;
 	escape = escape;
 	unescape = unescape;
 };