util/jid.lua

changeset 717
ab428c579cbc
parent 615
4ae3e81513f3
child 758
b1885732e979
equal deleted inserted replaced
716:d61eabc678a6 717:ab428c579cbc
18 -- 18 --
19 19
20 20
21 21
22 local match = string.match; 22 local match = string.match;
23 local nodeprep = require "util.encodings".stringprep.nodeprep;
24 local nameprep = require "util.encodings".stringprep.nameprep;
25 local resourceprep = require "util.encodings".stringprep.resourceprep;
23 26
24 module "jid" 27 module "jid"
25 28
26 function split(jid) 29 function split(jid)
27 if not jid then return; end 30 if not jid then return; end
39 return node.."@"..host; 42 return node.."@"..host;
40 end 43 end
41 return host; 44 return host;
42 end 45 end
43 46
47 function prepped_split(jid)
48 local node, host, resource = split(jid);
49 if host then
50 host = nameprep(host);
51 if not host then return; end
52 if node then
53 node = nodeprep(node);
54 if not node then return; end
55 end
56 if resource then
57 resource = resourceprep(resource);
58 if not resource then return; end
59 end
60 return node, host, resource;
61 end
62 end
63
64 function prep(jid)
65 local node, host, resource = prepped_split(jid);
66 if host then
67 if node then
68 host = node .. "@" .. host;
69 end
70 if resource then
71 host = host .. "/" .. resource;
72 end
73 end
74 return host;
75 end
76
44 return _M; 77 return _M;

mercurial