65
|
1 'use strict';
|
|
2
|
|
3 /**
|
|
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net>
|
|
5
|
|
6 Permission to use, copy, modify, and/or distribute this software for any
|
|
7 purpose with or without fee is hereby granted, provided that the above
|
|
8 copyright notice and this permission notice appear in all copies.
|
|
9
|
|
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
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
|
|
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
17 */
|
|
18
|
|
19 Lightstring.plugins['ANONYMOUS'] = {
|
|
20 handlers: {
|
|
21 'mechanisms': function (stanza) {
|
|
22 if(stanza.mechanisms.indexOf('ANONYMOUS') === -1)
|
|
23 return;
|
|
24
|
|
25 this.send(
|
|
26 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" +
|
|
27 " mechanism='ANONYMOUS'/>"
|
|
28 );
|
|
29 },
|
|
30 'success': function (stanza) {
|
|
31 this.send(
|
|
32 "<stream:stream to='" + this.jid.domain + "'" +
|
|
33 " xmlns='jabber:client'" +
|
|
34 " xmlns:stream='http://etherx.jabber.org/streams'" +
|
|
35 " version='1.0'/>"
|
|
36 );
|
|
37 },
|
|
38 'features': function (stanza) {
|
|
39 var that = this;
|
|
40 //TODO check if bind supported
|
|
41 var bind =
|
|
42 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
|
|
43 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>" +
|
|
44 "</iq>";
|
|
45
|
|
46 this.send(
|
|
47 bind,
|
|
48 //Success
|
|
49 function(stanza) {
|
|
50 //Session http://xmpp.org/rfcs/rfc3921.html#session
|
|
51 that.jid = new Lightstring.JID(stanza.DOM.textContent);
|
|
52
|
|
53 that.send(
|
|
54 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
|
|
55 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" +
|
|
56 "</iq>",
|
|
57 function() {
|
|
58 that.emit('connected');
|
|
59 }
|
|
60 );
|
|
61 },
|
|
62 //Error
|
|
63 function(stanza) {
|
|
64 //TODO: Error?
|
|
65 }
|
|
66 );
|
|
67 }
|
|
68 }
|
|
69 };
|