view util/jid.lua @ 416:7cc2d8a8ae97

Added util-src/hashes.c - support for sha1, sha256 and md5 hashes
author Waqas Hussain <waqas20@gmail.com>
date Wed, 26 Nov 2008 01:46:16 +0500
parents 4542bcdb7f55
children cccd610a0ef9
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;
	end
	return host;
end

return _M;