comparison fdsq.js @ 36:26eb015a7c40

Really should learn that “hg addremove” is good.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 10 Nov 2010 01:43:25 +0100
parents
children 023f767662d3
comparison
equal deleted inserted replaced
35:6697f394301f 36:26eb015a7c40
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 fdsq = exports;
23 fdsq.makeRandomId = function() {
24 return sha1hex(Date()+Math.random());
25 };
26
27 var JID = function(jid) {
28 this.full = jid;
29
30 var s = jid.indexOf('/');
31 if (s == -1)
32 this.resource = '';
33 else {
34 this.resource = jid.substring(s+1);
35 jid = jid.substr(0, s);
36 }
37
38 var a = jid.indexOf('@');
39 if (a == -1) {
40 this.user = '';
41 this.server = jid;
42 } else {
43 this.user = jid.substr(0, a);
44 this.server = jid.substr(a+1);
45 }
46 this.bare = jid;
47 };
48
49 fdsq.toBareJID = function(jid) {
50 var j = new JID(jid);
51 return j.bare;
52 };
53
54 fdsq.toResource = function(jid) {
55 var j = new JID(jid);
56 return j.resource;
57 };