File

util/jid.lua @ 374:ff502dada372

All the people who don't use TLS, this one's for you.
author Matthew Wild <mwild1@gmail.com>
date Sat, 22 Nov 2008 20:12:27 +0000 (2008-11-22)
parent 369:42de92add67b
child 384:4542bcdb7f55
line wrap: on
line source

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;