Software /
code /
prosody
Comparison
util/jid.lua @ 403:da92afa267cf
Merging with main branch.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 23 Nov 2008 20:44:48 +0100 |
parent | 384:4542bcdb7f55 |
child | 519:cccd610a0ef9 |
comparison
equal
deleted
inserted
replaced
402:50f1c09541cd | 403:da92afa267cf |
---|---|
3 | 3 |
4 module "jid" | 4 module "jid" |
5 | 5 |
6 function split(jid) | 6 function split(jid) |
7 if not jid then return; end | 7 if not jid then return; end |
8 -- TODO verify JID, and return; if invalid | 8 local node, nodepos = match(jid, "^([^@]+)@()"); |
9 local node = match(jid, "^([^@]+)@"); | 9 local host, hostpos = match(jid, "^([^@/]+)()", nodepos) |
10 local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)"); | 10 if node and not host then return nil, nil, nil; end |
11 local resource = match(jid, "/(.+)$"); | 11 local resource = match(jid, "^/(.+)$", hostpos); |
12 return node, server, resource; | 12 if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end |
13 return node, host, resource; | |
14 end | |
15 | |
16 function bare(jid) | |
17 local node, host = split(jid); | |
18 if node and host then | |
19 return node.."@"..host; | |
20 end | |
21 return host; | |
13 end | 22 end |
14 | 23 |
15 return _M; | 24 return _M; |