From 7a3cc5323272cfd22a092de5f5217379a8887050 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 15 Jan 2009 04:34:55 +0500 Subject: util/jid: string prepping functions added: prepped_split and prep --- util/jid.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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; -- cgit v1.2.3