Mercurial > eldonilo > lightstring
annotate jid.js @ 23:99bf2bdcfd96
Emit an iq/namespace:tag event for each iq containing a payload.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Jan 2012 22:16:26 +0100 |
parents | 6a6bb8ded046 |
children | 06e3a883d3a3 |
rev | line source |
---|---|
22
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 'use strict'; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 /** |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 Permission to use, copy, modify, and/or distribute this software for any |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 purpose with or without fee is hereby granted, provided that the above |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 copyright notice and this permission notice appear in all copies. |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 */ |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 /** |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 * @constructor Creates a new JID object. |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 * @param {String} [aJID] The host, bare or full JID. |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 * @memberOf Lightstring |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 */ |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 Lightstring.JID = function(aJID) { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 this.node = null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 this.domain = null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 this.resource = null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 if (aJID) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 this.full = aJID; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 //TODO: use a stringprep library to validate the input. |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 }; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 Lightstring.JID.prototype = { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 toString: function() { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 return this.full; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 }, |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 get bare() { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 if (!this.domain) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 return null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 if (this.node) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 return this.node + '@' + this.domain; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 return this.domain; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 }, |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 set bare(aJID) { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 if (!aJID) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 return; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 var s = aJID.indexOf('/'); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 if (s != -1) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 aJID = aJID.substring(0, s); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 s = aJID.indexOf('@'); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 if (s == -1) { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 this.node = null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 this.domain = aJID; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 } else { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 this.node = aJID.substring(0, s); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 this.domain = aJID.substring(s+1); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 } |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 }, |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 get full() { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 if (!this.domain) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 return null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 var full = this.domain; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 if (this.node) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 full = this.node + '@' + full; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 if (this.resource) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 full = full + '/' + this.resource; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 return full; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 }, |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 set full(aJID) { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 if (!aJID) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 return; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 var s = aJID.indexOf('/'); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 if (s == -1) |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 this.resource = null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 else { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 this.resource = aJID.substring(s+1); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 aJID = aJID.substring(0, s); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 } |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 s = aJID.indexOf('@'); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 if (s == -1) { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 this.node = null; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 this.domain = aJID; |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 } else { |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 this.node = aJID.substring(0, s); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 this.domain = aJID.substring(s+1); |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 } |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 } |
6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 }; |