util/jid.lua

Thu, 20 Nov 2008 23:28:16 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 20 Nov 2008 23:28:16 +0000
changeset 365
a59300fc22ec
parent 109
7efedc96352a
child 366
5691edc7dd63
permissions
-rw-r--r--

Add jid.bare() helper function

0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
1
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
2 local match = string.match;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
3
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
4 module "jid"
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
5
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
6 function split(jid)
109
7efedc96352a Minor edit, and added a TODO
Waqas Hussain <waqas20@gmail.com>
parents: 104
diff changeset
7 if not jid then return; end
7efedc96352a Minor edit, and added a TODO
Waqas Hussain <waqas20@gmail.com>
parents: 104
diff changeset
8 -- TODO verify JID, and return; if invalid
27
859b316e2fb0 Fixing jid.split() for all JIDs
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
9 local node = match(jid, "^([^@]+)@");
859b316e2fb0 Fixing jid.split() for all JIDs
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
10 local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)");
859b316e2fb0 Fixing jid.split() for all JIDs
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
11 local resource = match(jid, "/(.+)$");
859b316e2fb0 Fixing jid.split() for all JIDs
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
12 return node, server, resource;
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
13 end
104
cfbd3b849f9e Fixed: util/jid.lua now returns module object
Waqas Hussain <waqas20@gmail.com>
parents: 29
diff changeset
14
365
a59300fc22ec Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents: 109
diff changeset
15 function bare(jid)
a59300fc22ec Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents: 109
diff changeset
16 local node, host = split(jid);
a59300fc22ec Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents: 109
diff changeset
17 return node.."@"..host;
a59300fc22ec Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents: 109
diff changeset
18 end
a59300fc22ec Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents: 109
diff changeset
19
104
cfbd3b849f9e Fixed: util/jid.lua now returns module object
Waqas Hussain <waqas20@gmail.com>
parents: 29
diff changeset
20 return _M;

mercurial