Mercurial > psgxs
annotate util.js @ 34:dcf1f09f8cee
Add message to publish module and various fixes.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 05 Nov 2010 15:31:13 +0100 |
parents | 60c80751cfa5 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
3 * | |
4 * This file is part of PSĜS, a PubSub server written in JavaScript. | |
5 * | |
6 * PSĜS is free software: you can redistribute it and/or modify | |
7 * it under the terms of the GNU Affero General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License. | |
10 * | |
11 * PSĜS is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU Affero General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Affero General Public License | |
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. | |
18 */ | |
19 | |
20 var sha1hex = require('sha1').hex; | |
21 | |
22 var util = exports; | |
23 util.makeRandomId = function() { | |
24 return sha1hex(Date()+Math.random()); | |
25 }; | |
26 | |
27 var JID = function(jid) { | |
28 this.full = jid; | |
15
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
29 |
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
30 var s = jid.indexOf('/'); |
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
31 if (s == -1) |
0 | 32 this.resource = ''; |
15
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
33 else { |
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
34 this.resource = jid.substring(s+1); |
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
35 jid = jid.substr(0, s); |
0 | 36 } |
15
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
37 |
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
38 var a = jid.indexOf('@'); |
0 | 39 if (a == -1) { |
40 this.user = ''; | |
41 this.server = jid; | |
42 } else { | |
15
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
43 this.user = jid.substr(0, a); |
60c80751cfa5
JID handling conforming to the RFC.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
44 this.server = jid.substr(a+1); |
0 | 45 } |
46 this.bare = jid; | |
47 }; | |
48 | |
49 util.toBareJID = function(jid) { | |
50 var j = new JID(jid); | |
51 return j.bare; | |
52 }; | |
34
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
15
diff
changeset
|
53 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
15
diff
changeset
|
54 util.toResource = function(jid) { |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
15
diff
changeset
|
55 var j = new JID(jid); |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
15
diff
changeset
|
56 return j.resource; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
15
diff
changeset
|
57 }; |