annotate plugins/PLAIN.js @ 105:fb50311997b5

Add EventEmitter.js lib
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 13 Jun 2012 12:48:06 +0200
parents e1ccfb580228
children c06ec02217ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
1 'use strict';
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
2
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
3 /**
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net>
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
5
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
9
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
17 */
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
18
66
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
19 /*
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
20 References:
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
21 Extensible Messaging and Presence Protocol (XMPP): Core - SASL Negotiation
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
22 http://xmpp.org/rfcs/rfc6120.html#sasl
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
23 Simple Authentication and Security Layer (SASL)
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
24 http://tools.ietf.org/html/rfc4422
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
25 The PLAIN Simple Authentication and Security Layer (SASL) Mechanism
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
26 http://tools.ietf.org/html/rfc4616
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
27 */
fa184759fc41 Adds references to ANONYMOUS/DIGEST-MD5/PLAIN plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 65
diff changeset
28
63
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
29 Lightstring.plugins['PLAIN'] = {
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
30 handlers: {
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 'mechanisms': function (stanza) {
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 if(stanza.mechanisms.indexOf('PLAIN') === -1)
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 return;
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 var token = btoa(
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36 this.jid +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
37 '\u0000' +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 this.jid.node +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
39 '\u0000' +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
40 this.password
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
41 );
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
42 this.send(
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
43 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
44 " mechanism='PLAIN'>" + token + "</auth>"
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
45 );
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
46 },
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
47 'success': function (stanza) {
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
48 this.send(
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
49 "<stream:stream to='" + this.jid.domain + "'" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
50 " xmlns='jabber:client'" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
51 " xmlns:stream='http://etherx.jabber.org/streams'" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
52 " version='1.0'/>"
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
53 );
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
54 },
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
55 'features': function (stanza) {
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
56 var Conn = this;
63
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
57 //TODO check if bind supported
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
58 var bind =
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents: 64
diff changeset
59 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
63
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
60 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
61 (this.jid.resource? "<resource>" + this.jid.resource + "</resource>": "") +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
62 "</bind>" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
63 "</iq>";
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
64 this.send(
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
65 bind,
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
66 //Success
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
67 function(stanza) {
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
68 //Session http://xmpp.org/rfcs/rfc3921.html#session
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
69 Conn.jid = new Lightstring.JID(stanza.DOM.textContent);
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
70 Conn.send(
65
2e8fbf3bce7f ANONYMOUS auth plugin.
Sonny Piers <sonny.piers@gmail.com>
parents: 64
diff changeset
71 "<iq type='set' id='"+Lightstring.newId('sendiq:')+"'>" +
63
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
72 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" +
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
73 "</iq>",
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
74 function() {
68
e1ccfb580228 Replaces that by Conn.
Sonny Piers <sonny.piers@gmail.com>
parents: 66
diff changeset
75 Conn.emit('connected');
63
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
76 }
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
77 );
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
78 },
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
79 //Error
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
80 function(stanza) {
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81 //TODO: Error?
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
82 }
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
83 );
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
84 }
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
85 }
20da4fb67977 Auth PLAIN as plugin. Several fixes.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
86 };