Mercurial > eldonilo > lightstring
comparison jid.js @ 108:5cb4733c5189
many api changes
author | Sonny Piers <sonny@fastmail.net> |
---|---|
date | Fri, 13 Jul 2012 15:26:18 +0200 |
parents | c06ec02217ee |
children |
comparison
equal
deleted
inserted
replaced
107:704ce44c1a22 | 108:5cb4733c5189 |
---|---|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 */ | 17 */ |
18 | 18 |
19 //https://tools.ietf.org/html/rfc6122 | |
20 | |
21 (function() { | |
22 | |
23 | |
24 if (typeof define !== 'undefined') { | |
25 define(function() { | |
26 //return an object to define the "my/shirt" module. | |
27 return JID; | |
28 }); | |
29 } | |
30 else { | |
31 Lightstring.JID = JID; | |
32 } | |
19 | 33 |
20 /** | 34 /** |
21 * @constructor Creates a new JID object. | 35 * @constructor Creates a new JID object. |
22 * @param {String} [aJID] The host, bare or full JID. | 36 * @param {String} [aJID] The host, bare or full JID. |
23 * @memberOf Lightstring | 37 * @memberOf Lightstring |
24 */ | 38 */ |
25 Lightstring.JID = function(aJID) { | 39 var JID = function(aJID) { |
26 this.node = null; | 40 this.local = null; |
27 this.domain = null; | 41 this.domain = null; |
28 this.resource = null; | 42 this.resource = null; |
29 | 43 |
30 if (aJID) | 44 if (aJID) |
31 this.full = aJID.toString(); | 45 this.full = aJID.toString(); |
32 | 46 |
33 //TODO: use a stringprep library to validate the input. | 47 //TODO: use a stringprep library to validate the input. |
34 }; | 48 }; |
35 | 49 |
36 Lightstring.JID.prototype = { | 50 JID.prototype = { |
37 toString: function() { | 51 toString: function() { |
38 return this.full; | 52 return this.full; |
39 }, | 53 }, |
40 | 54 |
41 equals: function(aJID) { | 55 equals: function(aJID) { |
42 if (!(aJID instanceof Lightstring.JID)) | 56 if (!(aJID instanceof Lightstring.JID)) |
43 aJID = new Lightstring.JID(aJID); | 57 aJID = new Lightstring.JID(aJID); |
44 | 58 |
45 return (this.node === aJID.node && | 59 return (this.local === aJID.local && |
46 this.domain === aJID.domain && | 60 this.domain === aJID.domain && |
47 this.resource === aJID.resource) | 61 this.resource === aJID.resource) |
48 }, | 62 }, |
49 | 63 |
50 get bare() { | 64 get bare() { |
51 if (!this.domain) | 65 if (!this.domain) |
52 return null; | 66 return null; |
53 | 67 |
54 if (this.node) | 68 if (this.local) |
55 return this.node + '@' + this.domain; | 69 return this.local + '@' + this.domain; |
56 | 70 |
57 return this.domain; | 71 return this.domain; |
58 }, | 72 }, |
59 | 73 |
60 set bare(aJID) { | 74 set bare(aJID) { |
65 if (s != -1) | 79 if (s != -1) |
66 aJID = aJID.substring(0, s); | 80 aJID = aJID.substring(0, s); |
67 | 81 |
68 s = aJID.indexOf('@'); | 82 s = aJID.indexOf('@'); |
69 if (s == -1) { | 83 if (s == -1) { |
70 this.node = null; | 84 this.local = null; |
71 this.domain = aJID; | 85 this.domain = aJID; |
72 } else { | 86 } else { |
73 this.node = aJID.substring(0, s); | 87 this.local = aJID.substring(0, s); |
74 this.domain = aJID.substring(s+1); | 88 this.domain = aJID.substring(s+1); |
75 } | 89 } |
76 }, | 90 }, |
77 | 91 |
78 get full() { | 92 get full() { |
79 if (!this.domain) | 93 if (!this.domain) |
80 return null; | 94 return null; |
81 | 95 |
82 var full = this.domain; | 96 var full = this.domain; |
83 | 97 |
84 if (this.node) | 98 if (this.local) |
85 full = this.node + '@' + full; | 99 full = this.local + '@' + full; |
86 | 100 |
87 if (this.resource) | 101 if (this.resource) |
88 full = full + '/' + this.resource; | 102 full = full + '/' + this.resource; |
89 | 103 |
90 return full; | 104 return full; |
103 aJID = aJID.substring(0, s); | 117 aJID = aJID.substring(0, s); |
104 } | 118 } |
105 | 119 |
106 s = aJID.indexOf('@'); | 120 s = aJID.indexOf('@'); |
107 if (s == -1) { | 121 if (s == -1) { |
108 this.node = null; | 122 this.local = null; |
109 this.domain = aJID; | 123 this.domain = aJID; |
110 } else { | 124 } else { |
111 this.node = aJID.substring(0, s); | 125 this.local = aJID.substring(0, s); |
112 this.domain = aJID.substring(s+1); | 126 this.domain = aJID.substring(s+1); |
113 } | 127 } |
114 } | 128 } |
115 }; | 129 }; |
130 })(); | |
131 |