Software /
code /
prosody
Changeset
717:ab428c579cbc
util/jid: string prepping functions added: prepped_split and prep
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 15 Jan 2009 04:34:55 +0500 |
parents | 716:d61eabc678a6 |
children | 718:aa78dfb26593 |
files | util/jid.lua |
diffstat | 1 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/jid.lua Wed Jan 14 23:04:16 2009 +0500 +++ b/util/jid.lua Thu Jan 15 04:34:55 2009 +0500 @@ -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 @@ 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;