Mercurial > psgxs
comparison fdsq.js @ 56:99bd1d1ac071
Migration to node-xmpp, done!
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 10 Aug 2011 15:11:22 -0700 |
parents | 0d3f18bb1d36 |
children |
comparison
equal
deleted
inserted
replaced
55:fd69d35cf2e6 | 56:99bd1d1ac071 |
---|---|
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. | 17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
19 | 19 |
20 'use strict'; | 20 'use strict'; |
21 | 21 |
22 var sha1hex = require('sha1').hex; | 22 var JID = require('node-xmpp').JID; |
23 | 23 |
24 var fdsq = exports; | 24 var fdsq = exports; |
25 fdsq.makeRandomId = function() { | |
26 return sha1hex(Date()+Math.random()); | |
27 }; | |
28 | |
29 var JID = function(jid) { | |
30 this.full = jid; | |
31 | |
32 var s = jid.indexOf('/'); | |
33 if (s == -1) | |
34 this.resource = ''; | |
35 else { | |
36 this.resource = jid.substring(s+1); | |
37 jid = jid.substr(0, s); | |
38 } | |
39 | |
40 var a = jid.indexOf('@'); | |
41 if (a == -1) { | |
42 this.user = ''; | |
43 this.server = jid; | |
44 } else { | |
45 this.user = jid.substr(0, a); | |
46 this.server = jid.substr(a+1); | |
47 } | |
48 this.bare = jid; | |
49 }; | |
50 | 25 |
51 fdsq.toBare = function(jid) { | 26 fdsq.toBare = function(jid) { |
52 var j = new JID(jid); | 27 return new JID(jid).bare().toString(); |
53 return j.bare; | |
54 }; | 28 }; |
55 | 29 |
56 fdsq.toResource = function(jid) { | 30 fdsq.toResource = function(jid) { |
57 var j = new JID(jid); | 31 return new JID(jid).resource; |
58 return j.resource; | |
59 }; | 32 }; |