Mercurial > eldonilo > lightstring
comparison lightstring.js @ 22:6a6bb8ded046
Add a JID object, and use it in Lightstring.Connection.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Jan 2012 22:11:51 +0100 |
parents | b7d52bf259e0 |
children | 99bf2bdcfd96 |
comparison
equal
deleted
inserted
replaced
21:b7d52bf259e0 | 22:6a6bb8ded046 |
---|---|
136 }); | 136 }); |
137 } | 137 } |
138 }); | 138 }); |
139 this.on('success', function(stanza, that) { | 139 this.on('success', function(stanza, that) { |
140 that.send( | 140 that.send( |
141 "<stream:stream to='" + that.host + "'" + | 141 "<stream:stream to='" + that.jid.domain + "'" + |
142 " xmlns='jabber:client'" + | 142 " xmlns='jabber:client'" + |
143 " xmlns:stream='http://etherx.jabber.org/streams'" + | 143 " xmlns:stream='http://etherx.jabber.org/streams'" + |
144 " version='1.0'/>" | 144 " version='1.0'/>" |
145 ); | 145 ); |
146 }); | 146 }); |
183 host = matches[2]; | 183 host = matches[2]; |
184 break; | 184 break; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 var digest_uri = 'xmpp/' + that.host; | 188 var digest_uri = 'xmpp/' + that.jid.domain; |
189 if (host !== null) | 189 if (host !== null) |
190 digest_uri = digest_uri + '/' + host; | 190 digest_uri = digest_uri + '/' + host; |
191 var A1 = MD5.hash(that.node + | 191 var A1 = MD5.hash(that.jid.node + |
192 ':' + realm + ':' + that.password) + | 192 ':' + realm + ':' + that.password) + |
193 ':' + nonce + ':' + cnonce; | 193 ':' + nonce + ':' + cnonce; |
194 var A2 = 'AUTHENTICATE:' + digest_uri; | 194 var A2 = 'AUTHENTICATE:' + digest_uri; |
195 | 195 |
196 var responseText = ''; | 196 var responseText = ''; |
197 responseText += 'username=' + _quote(that.node) + ','; | 197 responseText += 'username=' + _quote(that.jid.node) + ','; |
198 responseText += 'realm=' + _quote(realm) + ','; | 198 responseText += 'realm=' + _quote(realm) + ','; |
199 responseText += 'nonce=' + _quote(nonce) + ','; | 199 responseText += 'nonce=' + _quote(nonce) + ','; |
200 responseText += 'cnonce=' + _quote(cnonce) + ','; | 200 responseText += 'cnonce=' + _quote(cnonce) + ','; |
201 responseText += 'nc="00000001",'; | 201 responseText += 'nc="00000001",'; |
202 responseText += 'qop="auth",'; | 202 responseText += 'qop="auth",'; |
219 * @param {String} [aJid] The JID (Jabber id) to use. | 219 * @param {String} [aJid] The JID (Jabber id) to use. |
220 * @param {String} [aPassword] The associated password. | 220 * @param {String} [aPassword] The associated password. |
221 */ | 221 */ |
222 connect: function(aJid, aPassword) { | 222 connect: function(aJid, aPassword) { |
223 this.emit('connecting'); | 223 this.emit('connecting'); |
224 if (aJid) | 224 this.jid = new Lightstring.JID(aJid); |
225 this.jid = aJid; | |
226 if (this.jid) { | |
227 this.host = this.jid.split('@')[1]; | |
228 this.node = this.jid.split('@')[0]; | |
229 this.resource = this.jid.split('/')[1]; | |
230 } | |
231 if (aPassword) | 225 if (aPassword) |
232 this.password = aPassword; | 226 this.password = aPassword; |
233 | 227 |
234 if (!this.jid) | 228 if (!this.jid.bare) |
235 throw 'Lightstring: Connection.jid is undefined.'; | 229 throw 'Lightstring: Connection.jid is undefined.'; |
236 if (!this.password) | 230 if (!this.password) |
237 throw 'Lightstring: Connection.password is undefined.'; | 231 throw 'Lightstring: Connection.password is undefined.'; |
238 if (!this.service) | 232 if (!this.service) |
239 throw 'Lightstring: Connection.service is undefined.'; | 233 throw 'Lightstring: Connection.service is undefined.'; |
249 var that = this; | 243 var that = this; |
250 this.socket.addEventListener('open', function() { | 244 this.socket.addEventListener('open', function() { |
251 if (this.protocol !== 'xmpp') | 245 if (this.protocol !== 'xmpp') |
252 console.error('Lightstring: The server located at '+ that.service + ' doesn\'t seems to be XMPP aware.'); | 246 console.error('Lightstring: The server located at '+ that.service + ' doesn\'t seems to be XMPP aware.'); |
253 | 247 |
254 var stream = Lightstring.stanza.stream.open(that.host); | 248 var stream = Lightstring.stanza.stream.open(that.jid.domain); |
255 | 249 |
256 that.socket.send(stream); | 250 that.socket.send(stream); |
257 that.emit('XMLOutput', stream); | 251 that.emit('XMLOutput', stream); |
258 }); | 252 }); |
259 this.socket.addEventListener('error', function(e) { | 253 this.socket.addEventListener('error', function(e) { |
268 var elm = Lightstring.xml2dom(e.data); | 262 var elm = Lightstring.xml2dom(e.data); |
269 that.emit('DOMInput', elm); | 263 that.emit('DOMInput', elm); |
270 that.emit(elm.tagName, elm); | 264 that.emit(elm.tagName, elm); |
271 | 265 |
272 if (elm.tagName === 'iq') | 266 if (elm.tagName === 'iq') |
273 that.emit(elm.getAttribute('id'), elm); | 267 that.emit(elm.getAttribute('id'), elm); //FIXME: possible attack vector. |
274 }); | 268 }); |
275 }, | 269 }, |
276 /** | 270 /** |
277 * @function Send a message. | 271 * @function Send a message. |
278 * @param {String|Object} aStanza The message to send. | 272 * @param {String|Object} aStanza The message to send. |