util/jid.lua

Fri, 21 Nov 2008 05:59:03 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 21 Nov 2008 05:59:03 +0000
changeset 372
e7c1e30d06d5
parent 369
42de92add67b
child 384
4542bcdb7f55
permissions
-rw-r--r--

Now possible to specify nil origin to core_route_stanza. Origin will be chosen as the host of the 'from' attribute on the stanza. Returns false on no such host.


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;
	elseif host then
		return host;
	end
	return nil;
end

return _M;

mercurial