2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 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;
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;
29 local node, host = split(jid);
31 return node.."@"..host;
36 function prepped_split(jid)
37 local node, host, resource = split(jid);
39 host = nameprep(host);
40 if not host then return; end
42 node = nodeprep(node);
43 if not node then return; end
46 resource = resourceprep(resource);
47 if not resource then return; end
49 return node, host, resource;
54 local node, host, resource = prepped_split(jid);
57 host = node .. "@" .. host;
60 host = host .. "/" .. resource;