Update Makefile to set correct paths on install with Debian package
[prosody.git] / util / jid.lua
index 784d2b645739eb2bd62aaa55a18ef353d5dfc049..065f176f524e4a0c72ce6e48d72cacce16e687ee 100644 (file)
@@ -4,11 +4,21 @@ local match = string.match;
 module "jid"
 
 function split(jid)
-       if not jid then return nil; end
-       local node = match(jid, "^([^@]+)@");
-       local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)");
-       local resource = match(jid, "/(.+)$");
-       return node, server, resource;
+       if not jid then return; end
+       local node, nodepos = match(jid, "^([^@]+)@()");
+       local host, hostpos = match(jid, "^([^@/]+)()", nodepos)
+       if node and not host then return nil, nil, nil; end
+       local resource = match(jid, "^/(.+)$", hostpos);
+       if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end
+       return node, host, resource;
 end
 
-return _M;
\ No newline at end of file
+function bare(jid)
+       local node, host = split(jid);
+       if node and host then
+               return node.."@"..host;
+       end
+       return host;
+end
+
+return _M;