2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
11 local match = string.match;
12 local nodeprep = require "util.encodings".stringprep.nodeprep;
13 local nameprep = require "util.encodings".stringprep.nameprep;
14 local resourceprep = require "util.encodings".stringprep.resourceprep;
18 local function _split(jid)
19 if not jid then return; end
20 local node, nodepos = match(jid, "^([^@]+)@()");
21 local host, hostpos = match(jid, "^([^@/]+)()", nodepos)
22 if node and not host then return nil, nil, nil; end
23 local resource = match(jid, "^/(.+)$", hostpos);
24 if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end
25 return node, host, resource;
30 local node, host = _split(jid);
32 return node.."@"..host;
37 local function _prepped_split(jid)
38 local node, host, resource = _split(jid);
40 host = nameprep(host);
41 if not host then return; end
43 node = nodeprep(node);
44 if not node then return; end
47 resource = resourceprep(resource);
48 if not resource then return; end
50 return node, host, resource;
53 prepped_split = _prepped_split;
56 local node, host, resource = _prepped_split(jid);
59 host = node .. "@" .. host;
62 host = host .. "/" .. resource;