Software /
code /
prosody
Diff
util/jid.lua @ 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 |
parent | 615:4ae3e81513f3 |
child | 758:b1885732e979 |
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;