Software /
code /
prosody
Annotate
util/jid.lua @ 389:c747d6963d95
Added mod_disco
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 23 Nov 2008 03:32:57 +0500 |
parent | 384:4542bcdb7f55 |
child | 519:cccd610a0ef9 |
rev | line source |
---|---|
0 | 1 |
2 local match = string.match; | |
367
cc26368294a3
Remove some declarations I added while debugging
Matthew Wild <mwild1@gmail.com>
parents:
366
diff
changeset
|
3 |
0 | 4 module "jid" |
5 | |
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 |
369 | 8 local node, nodepos = match(jid, "^([^@]+)@()"); |
9 local host, hostpos = match(jid, "^([^@/]+)()", nodepos) | |
366
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
365
diff
changeset
|
10 if node and not host then return nil, nil, nil; end |
369 | 11 local resource = match(jid, "^/(.+)$", hostpos); |
12 if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end | |
366
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
365
diff
changeset
|
13 return node, host, resource; |
0 | 14 end |
104
cfbd3b849f9e
Fixed: util/jid.lua now returns module object
Waqas Hussain <waqas20@gmail.com>
parents:
29
diff
changeset
|
15 |
365
a59300fc22ec
Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
16 function bare(jid) |
a59300fc22ec
Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
17 local node, host = split(jid); |
366
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
365
diff
changeset
|
18 if node and host then |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
365
diff
changeset
|
19 return node.."@"..host; |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
365
diff
changeset
|
20 end |
384 | 21 return host; |
365
a59300fc22ec
Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
22 end |
a59300fc22ec
Add jid.bare() helper function
Matthew Wild <mwild1@gmail.com>
parents:
109
diff
changeset
|
23 |
366
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
365
diff
changeset
|
24 return _M; |