Mercurial > psgxs
annotate fdsq.js @ 38:5395a501c991
Use internal toISOString method of Data.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 16 Nov 2010 19:00:15 +0100 |
parents | 26eb015a7c40 |
children | 023f767662d3 |
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 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 var sha1hex = require('sha1').hex; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 var fdsq = exports; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 fdsq.makeRandomId = function() { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 return sha1hex(Date()+Math.random()); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 }; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 var JID = function(jid) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 this.full = jid; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 var s = jid.indexOf('/'); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 if (s == -1) |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 this.resource = ''; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 else { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 this.resource = jid.substring(s+1); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 jid = jid.substr(0, s); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 } |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 var a = jid.indexOf('@'); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 if (a == -1) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 this.user = ''; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 this.server = jid; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 } else { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 this.user = jid.substr(0, a); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 this.server = jid.substr(a+1); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 } |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 this.bare = jid; |
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 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 fdsq.toBareJID = function(jid) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 var j = new JID(jid); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 return j.bare; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 }; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 fdsq.toResource = function(jid) { |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 var j = new JID(jid); |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 return j.resource; |
26eb015a7c40
Really should learn that “hg addremove” is good.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 }; |