util/jid: string prepping functions added: prepped_split and prep
authorWaqas Hussain <waqas20@gmail.com>
Wed, 14 Jan 2009 23:34:55 +0000 (04:34 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Wed, 14 Jan 2009 23:34:55 +0000 (04:34 +0500)
util/jid.lua

index 537735bee40ce005c3a0b4d20ef098c9f802f392..52fd0f44cd5d24b96ccdc9a2b36f7083328fbb73 100644 (file)
@@ -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;