Mercurial > psgxs
comparison util.js @ 0:9ee956af41e3
Initial commit
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 27 Jun 2010 22:05:12 +0200 |
parents | |
children | 60c80751cfa5 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9ee956af41e3 |
---|---|
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 var a = jid.indexOf('@'); | |
29 var b = jid.indexOf('/', a); | |
30 this.full = jid; | |
31 if (b == -1) { | |
32 this.resource = ''; | |
33 } else { | |
34 this.resource = jid.substring(b+1); | |
35 jid = jid.substring(0, b); | |
36 } | |
37 if (a == -1) { | |
38 this.user = ''; | |
39 this.server = jid; | |
40 } else { | |
41 this.user = jid.substring(0, a); | |
42 this.server = jid.substring(a+1); | |
43 } | |
44 this.bare = jid; | |
45 }; | |
46 | |
47 util.toBareJID = function(jid) { | |
48 var j = new JID(jid); | |
49 return j.bare; | |
50 }; |