Mercurial > eldonilo > blog
comparison jid.js @ 0:f62b5c395a48
Initial commit.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 04 Jun 2011 05:02:47 +0200 |
parents | |
children | eb5b6d3ab09b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f62b5c395a48 |
---|---|
1 var JID = function(jid) { | |
2 this.node = null; | |
3 this.domain = null; | |
4 this.resource = null; | |
5 this.action = null; | |
6 this.query = {}; | |
7 | |
8 this.toString = function() { | |
9 return this.full; | |
10 } | |
11 | |
12 this.__defineGetter__('bare', function() { | |
13 if (!this.domain) | |
14 return null; | |
15 | |
16 if (this.node) | |
17 return this.node + '@' + this.domain; | |
18 | |
19 return this.domain; | |
20 }); | |
21 | |
22 this.__defineSetter__('bare', function(jid) { | |
23 var s = jid.indexOf('/'); | |
24 if (s != -1) | |
25 jid = jid.substring(0, s); | |
26 | |
27 s = jid.indexOf('@'); | |
28 if (s == -1) { | |
29 this.node = null; | |
30 this.domain = jid; | |
31 } else { | |
32 this.node = jid.substring(0, s); | |
33 this.domain = jid.substring(s+1); | |
34 } | |
35 }); | |
36 | |
37 this.__defineGetter__('full', function() { | |
38 if (!this.domain) | |
39 return null; | |
40 | |
41 var full = this.domain; | |
42 | |
43 if (this.node) | |
44 full = this.node + '@' + full; | |
45 | |
46 if (this.resource) | |
47 full = full + '/' + this.resource; | |
48 | |
49 return full; | |
50 }); | |
51 | |
52 this.__defineSetter__('full', function(jid) { | |
53 var s = jid.indexOf('/'); | |
54 if (s == -1) | |
55 this.resource = null; | |
56 else { | |
57 this.resource = jid.substring(s+1); | |
58 jid = jid.substring(0, s); | |
59 } | |
60 | |
61 s = jid.indexOf('@'); | |
62 if (s == -1) { | |
63 this.node = null; | |
64 this.domain = jid; | |
65 } else { | |
66 this.node = jid.substring(0, s); | |
67 this.domain = jid.substring(s+1); | |
68 } | |
69 }); | |
70 | |
71 this.__defineSetter__('uri', function(uri) { | |
72 if (uri.indexOf('xmpp:') != 0) | |
73 return; | |
74 uri = uri.substring(5); | |
75 | |
76 var s = uri.indexOf('?'); | |
77 if (s == -1) { | |
78 this.full = uri; | |
79 return; | |
80 } | |
81 | |
82 this.full = uri.substring(0, s); | |
83 | |
84 uri = uri.substring(s+1).split(';'); | |
85 this.action = null; | |
86 this.query = {}; | |
87 | |
88 for (var i in uri) { | |
89 if (i == 0) { | |
90 this.action = uri[i]; | |
91 continue; | |
92 } | |
93 s = uri[i].indexOf('='); | |
94 var key = uri[i].substring(0, s); | |
95 var value = uri[i].substring(s+1); | |
96 this.query[key] = value; | |
97 } | |
98 }); | |
99 | |
100 if (jid) | |
101 this.full = jid; | |
102 }; | |
103 | |
104 if (typeof exports === 'object') | |
105 exports.JID = JID; |