tests: Add basic test for net.http.parser
[prosody.git] / util / jid.lua
index 696f51d83ff5e2093f4f7b275ab1c1d70bb63e71..522fb126747439aea5add0853db74f35643fc014 100644 (file)
@@ -8,6 +8,7 @@
 
 
 
+local select = select;
 local match, sub = string.match, string.sub;
 local nodeprep = require "util.encodings".stringprep.nodeprep;
 local nameprep = require "util.encodings".stringprep.nameprep;
@@ -36,7 +37,11 @@ local function split(jid)
 end
 
 local function bare(jid)
-       return jid and match(jid, "^[^/]+");
+       local node, host = split(jid);
+       if node and host then
+               return node.."@"..host;
+       end
+       return host;
 end
 
 local function prepped_split(jid)
@@ -89,6 +94,18 @@ local function compare(jid, acl)
        return false
 end
 
+local function node(jid)
+       return (select(1, split(jid)));
+end
+
+local function host(jid)
+       return (select(2, split(jid)));
+end
+
+local function resource(jid)
+       return (select(3, split(jid)));
+end
+
 local function escape(s) return s and (s:gsub(".", escapes)); end
 local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end
 
@@ -99,6 +116,9 @@ return {
        join = join;
        prep = prep;
        compare = compare;
+       node = node;
+       host = host;
+       resource = resource;
        escape = escape;
        unescape = unescape;
 };