diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-01-15 04:34:55 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-01-15 04:34:55 +0500 |
commit | 7a3cc5323272cfd22a092de5f5217379a8887050 (patch) | |
tree | 6123ed04ef1d6e2d8d4ec9ae87c8a92d32927da4 /util/jid.lua | |
parent | dbab107f8ef2bbfa435496dac0d3a1a48a87afcb (diff) | |
download | prosody-7a3cc5323272cfd22a092de5f5217379a8887050.tar.gz prosody-7a3cc5323272cfd22a092de5f5217379a8887050.zip |
util/jid: string prepping functions added: prepped_split and prep
Diffstat (limited to 'util/jid.lua')
-rw-r--r-- | util/jid.lua | 33 |
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; |