util/jid.lua

Sat, 29 Nov 2008 22:28:11 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 29 Nov 2008 22:28:11 +0000
changeset 492
279f64370885
parent 384
4542bcdb7f55
child 519
cccd610a0ef9
permissions
-rw-r--r--

Don't write to prosody.cfg.lua from Makefile. Much apologies to poor albert :(


local match = string.match;

module "jid"

function split(jid)
	if not jid then return; end
	local node, nodepos = match(jid, "^([^@]+)@()");
	local host, hostpos = match(jid, "^([^@/]+)()", nodepos)
	if node and not host then return nil, nil, nil; end
	local resource = match(jid, "^/(.+)$", hostpos);
	if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end
	return node, host, resource;
end

function bare(jid)
	local node, host = split(jid);
	if node and host then
		return node.."@"..host;
	end
	return host;
end

return _M;

mercurial