aboutsummaryrefslogtreecommitdiffstats
path: root/util/jid.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/jid.lua')
-rw-r--r--util/jid.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/jid.lua b/util/jid.lua
index 537735be..52fd0f44 100644
--- a/util/jid.lua
+++ b/util/jid.lua
@@ -20,6 +20,9 @@
local match = string.match;
+local nodeprep = require "util.encodings".stringprep.nodeprep;
+local nameprep = require "util.encodings".stringprep.nameprep;
+local resourceprep = require "util.encodings".stringprep.resourceprep;
module "jid"
@@ -41,4 +44,34 @@ function bare(jid)
return host;
end
+function prepped_split(jid)
+ local node, host, resource = split(jid);
+ if host then
+ host = nameprep(host);
+ if not host then return; end
+ if node then
+ node = nodeprep(node);
+ if not node then return; end
+ end
+ if resource then
+ resource = resourceprep(resource);
+ if not resource then return; end
+ end
+ return node, host, resource;
+ end
+end
+
+function prep(jid)
+ local node, host, resource = prepped_split(jid);
+ if host then
+ if node then
+ host = node .. "@" .. host;
+ end
+ if resource then
+ host = host .. "/" .. resource;
+ end
+ end
+ return host;
+end
+
return _M;