mirror of https://github.com/bjc/prosody
parent
c36a8743fe
commit
48e7f5ea64
@ -1,20 +1,28 @@ |
||||
|
||||
local match = string.match; |
||||
|
||||
local tostring = tostring; |
||||
local print = print |
||||
module "jid" |
||||
|
||||
function split(jid) |
||||
if not jid then return; end |
||||
-- TODO verify JID, and return; if invalid |
||||
local node = match(jid, "^([^@]+)@"); |
||||
local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)"); |
||||
local resource = match(jid, "/(.+)$"); |
||||
return node, server, resource; |
||||
local node, nodelen = match(jid, "^([^@]+)@()"); |
||||
local host, hostlen = match(jid, "^([^@/]+)()", nodelen) |
||||
if node and not host then return nil, nil, nil; end |
||||
local resource = match(jid, "^/(.+)$", hostlen); |
||||
if (not host) or ((not resource) and #jid >= hostlen) then return nil, nil, nil; end |
||||
return node, host, resource; |
||||
end |
||||
|
||||
function bare(jid) |
||||
local node, host = split(jid); |
||||
return node.."@"..host; |
||||
if node and host then |
||||
return node.."@"..host; |
||||
elseif host then |
||||
return host; |
||||
end |
||||
return nil; |
||||
end |
||||
|
||||
return _M; |
||||
return _M; |
||||
|
||||
Loading…
Reference in new issue