Mercurial > psgxs
annotate fdsq.js @ 52:296de54c1c4b
Rollback last commit error and fix typo error.
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Mon, 21 Mar 2011 16:30:14 +0100 |
parents | 0d3f18bb1d36 |
children | 99bd1d1ac071 |
rev | line source |
---|---|
36
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 /* |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 * |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 * This file is part of PSĜS, a PubSub server written in JavaScript. |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 * |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 * PSĜS is free software: you can redistribute it and/or modify |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 * it under the terms of the GNU Affero General Public License as |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 * License. |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 * |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 * PSĜS is distributed in the hope that it will be useful, |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 * GNU Affero General Public License for more details. |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 * |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Affero General Public License |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 */ |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 |
43
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
36
diff
changeset
|
20 'use strict'; |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
36
diff
changeset
|
21 |
36
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 var sha1hex = require('sha1').hex; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 var fdsq = exports; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 fdsq.makeRandomId = function() { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 return sha1hex(Date()+Math.random()); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 }; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 var JID = function(jid) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 this.full = jid; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 var s = jid.indexOf('/'); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 if (s == -1) |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 this.resource = ''; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 else { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 this.resource = jid.substring(s+1); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 jid = jid.substr(0, s); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 } |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 var a = jid.indexOf('@'); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 if (a == -1) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 this.user = ''; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 this.server = jid; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 } else { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 this.user = jid.substr(0, a); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 this.server = jid.substr(a+1); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 } |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 this.bare = jid; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 }; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 |
47
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
51 fdsq.toBare = function(jid) { |
36
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 var j = new JID(jid); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 return j.bare; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 }; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 fdsq.toResource = function(jid) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 var j = new JID(jid); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 return j.resource; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 }; |