# HG changeset patch # User Sonny Piers # Date 1328127808 -3600 # Node ID 2e8fbf3bce7f2913df39550a2faf4f0e0ec948a4 # Parent d9f5ae0b6d98401dfabdd0aa782d79d4d8524f9c ANONYMOUS auth plugin. diff --git a/lightstring.js b/lightstring.js --- a/lightstring.js +++ b/lightstring.js @@ -141,8 +141,6 @@ Lightstring.Connection.prototype = { if (!this.jid.bare) throw 'Lightstring: Connection.jid is undefined.'; - if (!this.password) - throw 'Lightstring: Connection.password is undefined.'; if (!this.service) throw 'Lightstring: Connection.service is undefined.'; @@ -186,6 +184,7 @@ Lightstring.Connection.prototype = { var name = stanza.DOM.localName; + //FIXME SASL mechanisms and XMPP features can be both in a stream:features if (name === 'features') { //SASL mechanisms if (stanza.DOM.firstChild.localName === 'mechanisms') { @@ -196,7 +195,7 @@ Lightstring.Connection.prototype = { that.emit('mechanisms', stanza); } //XMPP features - else if (stanza.DOM.firstChild.localName === 'c') { + else { //TODO: stanza.features that.emit('features', stanza); } diff --git a/plugins/ANONYMOUS.js b/plugins/ANONYMOUS.js new file mode 100644 --- /dev/null +++ b/plugins/ANONYMOUS.js @@ -0,0 +1,69 @@ +'use strict'; + +/** + Copyright (c) 2012, Sonny Piers + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +Lightstring.plugins['ANONYMOUS'] = { + handlers: { + 'mechanisms': function (stanza) { + if(stanza.mechanisms.indexOf('ANONYMOUS') === -1) + return; + + this.send( + "" + ); + }, + 'success': function (stanza) { + this.send( + "" + ); + }, + 'features': function (stanza) { + var that = this; + //TODO check if bind supported + var bind = + "" + + "" + + ""; + + this.send( + bind, + //Success + function(stanza) { + //Session http://xmpp.org/rfcs/rfc3921.html#session + that.jid = new Lightstring.JID(stanza.DOM.textContent); + + that.send( + "" + + "" + + "", + function() { + that.emit('connected'); + } + ); + }, + //Error + function(stanza) { + //TODO: Error? + } + ); + } + } +}; diff --git a/plugins/DIGEST-MD5.js b/plugins/DIGEST-MD5.js --- a/plugins/DIGEST-MD5.js +++ b/plugins/DIGEST-MD5.js @@ -39,7 +39,7 @@ Lightstring.plugins['DIGEST-MD5'] = { var that = this; //TODO check if bind supported var bind = - "" + + "" + "" + (this.jid.resource? "" + this.jid.resource + "": "") + "" + @@ -51,7 +51,7 @@ Lightstring.plugins['DIGEST-MD5'] = { //Session http://xmpp.org/rfcs/rfc3921.html#session that.jid = new Lightstring.JID(stanza.DOM.textContent); that.send( - "" + + "" + "" + "", function() { diff --git a/plugins/PLAIN.js b/plugins/PLAIN.js --- a/plugins/PLAIN.js +++ b/plugins/PLAIN.js @@ -46,7 +46,7 @@ Lightstring.plugins['PLAIN'] = { var that = this; //TODO check if bind supported var bind = - "" + + "" + "" + (this.jid.resource? "" + this.jid.resource + "": "") + "" + @@ -58,7 +58,7 @@ Lightstring.plugins['PLAIN'] = { //Session http://xmpp.org/rfcs/rfc3921.html#session that.jid = new Lightstring.JID(stanza.DOM.textContent); that.send( - "" + + "" + "" + "", function() {