[Pkg-javascript-commits] [ltx] 129/469: s/\t/ /g

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:13 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 9c3c3f0d03be155d6b8d25c90f1ed0b19c2bd1db
Author: Astro <astro at spaceboyz.net>
Date:   Thu Sep 9 20:05:27 2010 +0200

    s/\t/        /g
---
 lib/xmpp/client.js        | 214 +++++++++----------
 lib/xmpp/component.js     |  18 +-
 lib/xmpp/connection.js    | 120 +++++------
 lib/xmpp/jid.js           |  30 +--
 lib/xmpp/router.js        | 526 +++++++++++++++++++++++-----------------------
 lib/xmpp/sasl.js          | 144 ++++++-------
 lib/xmpp/server.js        | 164 +++++++--------
 lib/xmpp/srv.js           | 170 +++++++--------
 lib/xmpp/stream_parser.js |  82 ++++----
 lib/xmpp/xml.js           | 112 +++++-----
 10 files changed, 790 insertions(+), 790 deletions(-)

diff --git a/lib/xmpp/client.js b/lib/xmpp/client.js
index e762516..437fc5b 100644
--- a/lib/xmpp/client.js
+++ b/lib/xmpp/client.js
@@ -31,9 +31,9 @@ function Client(params) {
     Connection.Connection.call(this);
 
     if (typeof params.jid == 'string')
-	this.jid = new JID(params.jid);
+        this.jid = new JID(params.jid);
     else
-	this.jid = params.jid;
+        this.jid = params.jid;
     this.password = params.password;
     this.xmlns[''] = NS_CLIENT;
     this.xmppVersion = "1.0";
@@ -42,26 +42,26 @@ function Client(params) {
     this.addListener('rawStanza', this.onRawStanza);
 
     if (params.host) {
-	this.connect(params.port || 5222, params.host);
+        this.connect(params.port || 5222, params.host);
     } else {
-	var self = this;
-	var attempt = SRV.connect(this.socket,
-				  ['_xmpp-client._tcp'], this.jid.domain, 5222);
-	attempt.addListener('connect', function() {
-	    self.startParser();
-	    self.startStream();
-	});
-	attempt.addListener('error', function(e) {
-	    self.emit('error', e);
-	});
+        var self = this;
+        var attempt = SRV.connect(this.socket,
+                                  ['_xmpp-client._tcp'], this.jid.domain, 5222);
+        attempt.addListener('connect', function() {
+            self.startParser();
+            self.startStream();
+        });
+        attempt.addListener('error', function(e) {
+            self.emit('error', e);
+        });
     }
 
     // it's us who must restart after starttls
     this.socket.addListener('secure', function() {
-	self.startStream();
+        self.startStream();
     });
     this.socket.addListener('end', function() {
-	self.state = STATE_PREAUTH;
+        self.state = STATE_PREAUTH;
     });
 }
 
@@ -73,59 +73,59 @@ Client.prototype.onRawStanza = function(stanza) {
        this.streamAttrs.version is missing, but who uses pre-XMPP-1.0
        these days anyway? */
     if (this.state != STATE_ONLINE &&
-	stanza.is('features', Connection.NS_STREAM)) {
-	this.streamFeatures = stanza;
-	this.useFeatures();
+        stanza.is('features', Connection.NS_STREAM)) {
+        this.streamFeatures = stanza;
+        this.useFeatures();
     } else if (this.state == STATE_AUTH) {
-	if (stanza.is('challenge', NS_XMPP_SASL)) {
-	    var challengeMsg = decode64(stanza.getText());
-	    var responseMsg = encode64(
-				  this.mech.challenge(challengeMsg));
-	    this.send(new xml.Element('response',
-				      { xmlns: NS_XMPP_SASL
-				      }).t(responseMsg));
-	} else if (stanza.is('success', NS_XMPP_SASL)) {
-	    this.mech = null;
-	    this.state = STATE_AUTHED;
-	    this.startParser();
-	    this.startStream();
-	} else {
-	    this.emit('error', 'XMPP authentication failure');
-	}
+        if (stanza.is('challenge', NS_XMPP_SASL)) {
+            var challengeMsg = decode64(stanza.getText());
+            var responseMsg = encode64(
+                                  this.mech.challenge(challengeMsg));
+            this.send(new xml.Element('response',
+                                      { xmlns: NS_XMPP_SASL
+                                      }).t(responseMsg));
+        } else if (stanza.is('success', NS_XMPP_SASL)) {
+            this.mech = null;
+            this.state = STATE_AUTHED;
+            this.startParser();
+            this.startStream();
+        } else {
+            this.emit('error', 'XMPP authentication failure');
+        }
     } else if (this.state == STATE_BIND &&
-	       stanza.is('iq', NS_CLIENT) &&
-	       stanza.attrs.id == IQID_BIND) {
-	if (stanza.attrs.type == 'result') {
-	    this.state = STATE_AUTHED;
-	    this.did_bind = true;
+               stanza.is('iq', NS_CLIENT) &&
+               stanza.attrs.id == IQID_BIND) {
+        if (stanza.attrs.type == 'result') {
+            this.state = STATE_AUTHED;
+            this.did_bind = true;
 
-	    var bindEl = stanza.getChild('bind', NS_XMPP_BIND);
-	    if (bindEl && bindEl.getChild('jid')) {
-		this.jid = new JID(bindEl.getChild('jid').getText());
-	    }
+            var bindEl = stanza.getChild('bind', NS_XMPP_BIND);
+            if (bindEl && bindEl.getChild('jid')) {
+                this.jid = new JID(bindEl.getChild('jid').getText());
+            }
 
-	    /* no stream restart, but next feature */
-	    this.useFeatures();
-	} else {
-	    this.emit('error', 'Cannot bind resource');
-	}
+            /* no stream restart, but next feature */
+            this.useFeatures();
+        } else {
+            this.emit('error', 'Cannot bind resource');
+        }
     } else if (this.state == STATE_SESSION &&
-	       stanza.is('iq', NS_CLIENT) &&
-	       stanza.attrs.id == IQID_SESSION) {
-	if (stanza.attrs.type == 'result') {
-	    this.state = STATE_AUTHED;
-	    this.did_session = true;
+               stanza.is('iq', NS_CLIENT) &&
+               stanza.attrs.id == IQID_SESSION) {
+        if (stanza.attrs.type == 'result') {
+            this.state = STATE_AUTHED;
+            this.did_session = true;
 
-	    /* no stream restart, but next feature (most probably
-	       we'll go online next) */
-	    this.useFeatures();
-	} else {
-	    this.emit('error', 'Cannot bind resource');
-	}
+            /* no stream restart, but next feature (most probably
+               we'll go online next) */
+            this.useFeatures();
+        } else {
+            this.emit('error', 'Cannot bind resource');
+        }
     } else if (stanza.name == 'stream:error') {
-	this.emit('error', stanza);
+        this.emit('error', stanza);
     } else if (this.state == STATE_ONLINE) {
-	this.emit('stanza', stanza);
+        this.emit('stanza', stanza);
     }
 };
 
@@ -135,56 +135,56 @@ Client.prototype.onRawStanza = function(stanza) {
  */
 Client.prototype.useFeatures = function() {
     if (this.state == STATE_PREAUTH &&
-	this.streamFeatures.getChild('mechanisms', NS_XMPP_SASL)) {
-	this.state = STATE_AUTH;
-	this.mech = sasl.selectMechanism(
-		       this.streamFeatures.
-		       getChild('mechanisms', NS_XMPP_SASL).
-		       getChildren('mechanism', NS_XMPP_SASL).
-		       map(function(el) { return el.getText(); }));
-	if (this.mech) {
-	    this.mech.authzid = this.jid.bare().toString();
-	    this.mech.authcid = this.jid.user;
-	    this.mech.password = this.password;
-	    this.mech.realm = this.jid.domain;  // anything?
-	    this.mech.digest_uri = "xmpp/" + this.jid.domain;
-	    var authMsg = encode64(this.mech.auth());
-	    this.send(new xml.Element('auth',
-				      { xmlns: NS_XMPP_SASL,
-					mechanism: this.mech.name
-				      }).t(authMsg));
-	} else {
-	    this.emit('error', 'No usable SASL mechanism');
-	}
+        this.streamFeatures.getChild('mechanisms', NS_XMPP_SASL)) {
+        this.state = STATE_AUTH;
+        this.mech = sasl.selectMechanism(
+                       this.streamFeatures.
+                       getChild('mechanisms', NS_XMPP_SASL).
+                       getChildren('mechanism', NS_XMPP_SASL).
+                       map(function(el) { return el.getText(); }));
+        if (this.mech) {
+            this.mech.authzid = this.jid.bare().toString();
+            this.mech.authcid = this.jid.user;
+            this.mech.password = this.password;
+            this.mech.realm = this.jid.domain;  // anything?
+            this.mech.digest_uri = "xmpp/" + this.jid.domain;
+            var authMsg = encode64(this.mech.auth());
+            this.send(new xml.Element('auth',
+                                      { xmlns: NS_XMPP_SASL,
+                                        mechanism: this.mech.name
+                                      }).t(authMsg));
+        } else {
+            this.emit('error', 'No usable SASL mechanism');
+        }
     } else if (this.state == STATE_AUTHED &&
-	       !this.did_bind &&
-	       this.streamFeatures.getChild('bind', NS_XMPP_BIND)) {
-	this.state = STATE_BIND;
-	var bindEl = new xml.Element('iq',
-				     { type: 'set',
-				       id: IQID_BIND
-				     }).c('bind',
-					  { xmlns: NS_XMPP_BIND
-					  });
-	if (this.jid.resource)
-	    bindEl.c('resource').t(this.jid.resource);
-	this.send(bindEl);
+               !this.did_bind &&
+               this.streamFeatures.getChild('bind', NS_XMPP_BIND)) {
+        this.state = STATE_BIND;
+        var bindEl = new xml.Element('iq',
+                                     { type: 'set',
+                                       id: IQID_BIND
+                                     }).c('bind',
+                                          { xmlns: NS_XMPP_BIND
+                                          });
+        if (this.jid.resource)
+            bindEl.c('resource').t(this.jid.resource);
+        this.send(bindEl);
     } else if (this.state == STATE_AUTHED &&
-	       !this.did_session &&
-	       this.streamFeatures.getChild('session', NS_XMPP_SESSION)) {
-	this.state = STATE_SESSION;
-	this.send(new xml.Element('iq',
-				  { type: 'set',
-				    to: this.jid.domain,
-				    id: IQID_SESSION
-				  }).c('session',
-				       { xmlns: NS_XMPP_SESSION
-				       }));
+               !this.did_session &&
+               this.streamFeatures.getChild('session', NS_XMPP_SESSION)) {
+        this.state = STATE_SESSION;
+        this.send(new xml.Element('iq',
+                                  { type: 'set',
+                                    to: this.jid.domain,
+                                    id: IQID_SESSION
+                                  }).c('session',
+                                       { xmlns: NS_XMPP_SESSION
+                                       }));
     } else if (this.state == STATE_AUTHED) {
-	/* Ok, we're authenticated and all features have been
-	   processed */
-	this.state = STATE_ONLINE;
-	this.emit('online');
+        /* Ok, we're authenticated and all features have been
+           processed */
+        this.state = STATE_ONLINE;
+        this.emit('online');
     }
 };
 
diff --git a/lib/xmpp/component.js b/lib/xmpp/component.js
index b9cc381..4541c59 100644
--- a/lib/xmpp/component.js
+++ b/lib/xmpp/component.js
@@ -19,26 +19,26 @@ function Component(params) {
     Connection.Connection.call(this);
 
     if (typeof params.jid == 'string')
-	this.jid = new JID(params.jid);
+        this.jid = new JID(params.jid);
     else
-	this.jid = params.jid;
+        this.jid = params.jid;
     this.password = params.password;
     this.xmlns[''] = NS_COMPONENT;
     this.streamTo = this.jid.domain;
 
     this.addListener('streamStart', function(streamAttrs) {
-	self.onStreamStart(streamAttrs);
+        self.onStreamStart(streamAttrs);
     });
     this.addListener('rawStanza', function(stanza) {
-	self.onRawStanza(stanza);
+        self.onRawStanza(stanza);
     });
     var attempt = SRV.connect(this.socket, [], params.host, params.port);
     attempt.addListener('connect', function() {
-	self.startParser();
-	self.startStream();
+        self.startParser();
+        self.startStream();
     });
     attempt.addListener('error', function(e) {
-	self.emit('error', e);
+        self.emit('error', e);
     });
 }
 
@@ -52,9 +52,9 @@ Component.prototype.onStreamStart = function(streamAttrs) {
 
 Component.prototype.onRawStanza = function(stanza) {
     if (stanza.is('handshake', NS_COMPONENT)) {
-	this.emit('online');
+        this.emit('online');
     } else {
-	this.emit('stanza', stanza);
+        this.emit('stanza', stanza);
     }
 };
 
diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index ebe5acb..d7c7ff4 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -21,15 +21,15 @@ function Connection(socket) {
 
     this.socket = socket || new net.Stream();
     this.socket.addListener('data', function(data) {
-	self.onData(data);
+        self.onData(data);
     });
     this.socket.addListener('end', function() {
-	self.onEnd();
+        self.onEnd();
     });
     var proxyEvent = function(event) {
-	self.socket.addListener(event, function() {
-	    self.emit.apply(self, Array.prototype.splice.call(arguments, 0, 0, event));
-	});
+        self.socket.addListener(event, function() {
+            self.emit.apply(self, Array.prototype.splice.call(arguments, 0, 0, event));
+        });
     };
     proxyEvent('data');  // let them sniff
     proxyEvent('drain');
@@ -49,19 +49,19 @@ Connection.prototype.allowTLS = true;
 */
 Connection.prototype.send = function(stanza) {
     if (!this.socket.writable) {
-	this.socket.end();
-	return;
+        this.socket.end();
+        return;
     }
 
     if (stanza.root) {
-	var el = this.rmStreamNs(stanza.root());
-	var socket = this.socket;
-	el.write(function(s) { socket.write(s); });
-	return el;
+        var el = this.rmStreamNs(stanza.root());
+        var socket = this.socket;
+        el.write(function(s) { socket.write(s); });
+        return el;
     } else {
-	console.log({write:stanza});
-	this.socket.write(stanza);
-	return stanza;
+        console.log({write:stanza});
+        this.socket.write(stanza);
+        return stanza;
     }
 };
 
@@ -70,28 +70,28 @@ Connection.prototype.startParser = function() {
     this.parser = new StreamParser.StreamParser(this.charset, this.maxStanzaSize);
 
     this.parser.addListener('start', function(attrs) {
-	self.streamAttrs = attrs;
-	/* We need those xmlns often, store them extra */
-	self.streamNsAttrs = {};
-	for(var k in attrs) {
-	if (k == 'xmlns' ||
-	    k.substr(0, 6) == 'xmlns:')
-		self.streamNsAttrs[k] = attrs[k];
-	}
-
-	/* Notify in case we don't wait for <stream:features/>
-	   (Component or non-1.0 streams)
-	 */
-	self.emit('streamStart', attrs);
+        self.streamAttrs = attrs;
+        /* We need those xmlns often, store them extra */
+        self.streamNsAttrs = {};
+        for(var k in attrs) {
+        if (k == 'xmlns' ||
+            k.substr(0, 6) == 'xmlns:')
+                self.streamNsAttrs[k] = attrs[k];
+        }
+
+        /* Notify in case we don't wait for <stream:features/>
+           (Component or non-1.0 streams)
+         */
+        self.emit('streamStart', attrs);
     });
     this.parser.addListener('stanza', function(stanza) {
-	self.onStanza(self.addStreamNs(stanza));
+        self.onStanza(self.addStreamNs(stanza));
     });
     this.parser.addListener('error', function(e) {
-	self.error(e.condition || 'internal-server-error', e.message);
+        self.error(e.condition || 'internal-server-error', e.message);
     });
     this.parser.addListener('end', function() {
-	self.end();
+        self.end();
     });
 };
 
@@ -102,19 +102,19 @@ Connection.prototype.stopParser = function() {
 Connection.prototype.startStream = function() {
     var attrs = {};
     for(var k in this.xmlns) {
-	if (this.xmlns.hasOwnProperty(k)) {
-	    if (!k)
-		attrs.xmlns = this.xmlns[k];
-	    else
-		attrs['xmlns:' + k] = this.xmlns[k];
-	}
+        if (this.xmlns.hasOwnProperty(k)) {
+            if (!k)
+                attrs.xmlns = this.xmlns[k];
+            else
+                attrs['xmlns:' + k] = this.xmlns[k];
+        }
     }
     if (this.xmppVersion)
-	attrs.version = this.xmppVersion;
+        attrs.version = this.xmppVersion;
     if (this.streamTo)
-	attrs.to = this.streamTo;
+        attrs.to = this.streamTo;
     if (this.streamId)
-	attrs.id = this.streamId;
+        attrs.id = this.streamId;
 
     var el = new xml.Element('stream:stream', attrs);
     // make it non-empty to cut the closing tag
@@ -125,7 +125,7 @@ Connection.prototype.startStream = function() {
 
 Connection.prototype.onData = function(data) {
     if (this.parser)
-	this.parser.write(data);
+        this.parser.write(data);
 };
 
 Connection.prototype.setSecure = function(credentials) {
@@ -133,7 +133,7 @@ Connection.prototype.setSecure = function(credentials) {
     this.stopParser();
     this.socket.setSecure(credentials || this.credentials);
     this.socket.addListener('secure', function() {
-	self.startParser();
+        self.startParser();
     });
 };
 
@@ -143,19 +143,19 @@ Connection.prototype.setSecure = function(credentials) {
  */
 Connection.prototype.onStanza = function(stanza) {
     if (stanza.is('error', NS_STREAM)) {
-	/* TODO: extract error text */
-	this.emit('error', stanza);
+        /* TODO: extract error text */
+        this.emit('error', stanza);
     } else if (stanza.is('features', NS_STREAM) &&
-	       this.allowTLS &&
-	       stanza.getChild('starttls', NS_XMPP_TLS)) {
-	/* Signal willingness to perform TLS handshake */
-	this.send(new xml.Element('starttls', { xmlns: NS_XMPP_TLS }));
+               this.allowTLS &&
+               stanza.getChild('starttls', NS_XMPP_TLS)) {
+        /* Signal willingness to perform TLS handshake */
+        this.send(new xml.Element('starttls', { xmlns: NS_XMPP_TLS }));
     } else if (this.allowTLS &&
-	       stanza.is('proceed', NS_XMPP_TLS)) {
-	/* Server is waiting for TLS handshake */
-	this.setSecure();
+               stanza.is('proceed', NS_XMPP_TLS)) {
+        /* Server is waiting for TLS handshake */
+        this.setSecure();
     } else {
-	this.emit('rawStanza', stanza);
+        this.emit('rawStanza', stanza);
     }
 };
 
@@ -165,8 +165,8 @@ Connection.prototype.onStanza = function(stanza) {
  */
 Connection.prototype.addStreamNs = function(stanza) {
     for(var k in this.streamNsAttrs) {
-	if (!stanza.attrs[k])
-	    stanza.attrs[k] = this.streamNsAttrs[k];
+        if (!stanza.attrs[k])
+            stanza.attrs[k] = this.streamNsAttrs[k];
     }
     return stanza;
 };
@@ -177,8 +177,8 @@ Connection.prototype.addStreamNs = function(stanza) {
  */
 Connection.prototype.rmStreamNs = function(stanza) {
     for(var k in this.streamNsAttrs) {
-	if (stanza.attrs[k] == this.streamNsAttrs[k])
-	    delete stanza.attrs[k];
+        if (stanza.attrs[k] == this.streamNsAttrs[k])
+            delete stanza.attrs[k];
     }
     return stanza;
 };
@@ -200,7 +200,7 @@ Connection.prototype.onEnd = function() {
  */
 Connection.prototype.end = function() {
     if (this.socket.writable)
-	this.socket.write('</stream:stream>');
+        this.socket.write('</stream:stream>');
     this.socket.end();
     // stopParser will called on 'end'/'error' event
 };
@@ -216,14 +216,14 @@ Connection.prototype.error = function(condition, message) {
     this.emit('error', new Error(message));
 
     if (!this.socket.writable)
-	return;
+        return;
 
     var e = new xml.Element('stream:error');
     e.c(condition, { xmlns: NS_XMPP_STREAMS });
     if (message)
-	e.c('text', { xmlns: NS_XMPP_STREAMS,
-		      'xml:lang': 'en' }).
-	t(message);
+        e.c('text', { xmlns: NS_XMPP_STREAMS,
+                      'xml:lang': 'en' }).
+        t(message);
 
     this.send(e);
     this.end();
diff --git a/lib/xmpp/jid.js b/lib/xmpp/jid.js
index 69afe34..5a241d2 100644
--- a/lib/xmpp/jid.js
+++ b/lib/xmpp/jid.js
@@ -5,23 +5,23 @@ var resourceprep = new StringPrep('resourceprep');
 
 function JID(a, b, c) {
     if (a && b == null && c == null) {
-	this.parseJID(a);
+        this.parseJID(a);
     } else if (b) {
-	this.setUser(a);
-	this.setDomain(b);
-	this.setResource(c);
+        this.setUser(a);
+        this.setDomain(b);
+        this.setResource(c);
     } else
-	throw 'Argument error';
+        throw 'Argument error';
 }
 
 JID.prototype.parseJID = function(s) {
     if (s.indexOf('@') >= 0) {
-	this.setUser(s.substr(0, s.indexOf('@')));
-	s = s.substr(s.indexOf('@') + 1);
+        this.setUser(s.substr(0, s.indexOf('@')));
+        s = s.substr(s.indexOf('@') + 1);
     }
     if (s.indexOf('/') >= 0) {
-	this.setResource(s.substr(s.indexOf('/') + 1));
-	s = s.substr(0, s.indexOf('/'));
+        this.setResource(s.substr(s.indexOf('/') + 1));
+        s = s.substr(0, s.indexOf('/'));
     }
     this.setDomain(s);
 };
@@ -29,9 +29,9 @@ JID.prototype.parseJID = function(s) {
 JID.prototype.toString = function() {
     var s = this.domain;
     if (this.user)
-	s = this.user + '@' + s;
+        s = this.user + '@' + s;
     if (this.resource)
-	s = s + '/' + this.resource;
+        s = s + '/' + this.resource;
     return s;
 };
 
@@ -40,9 +40,9 @@ JID.prototype.toString = function() {
  **/
 JID.prototype.bare = function() {
     if (this.resource)
-	return new JID(this.user, this.domain, null);
+        return new JID(this.user, this.domain, null);
     else
-	return this;
+        return this;
 };
 
 /**
@@ -50,8 +50,8 @@ JID.prototype.bare = function() {
  **/
 JID.prototype.equals = function(other) {
     return this.user == other.user &&
-	this.domain == other.domain &&
-	this.resource == other.resource;
+        this.domain == other.domain &&
+        this.resource == other.resource;
 };
 
 /**
diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 4635ff2..fb9ceff 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -13,18 +13,18 @@ var NS_XMPP_STANZAS = 'urn:ietf:params:xml:ns:xmpp-stanzas';
 
 dbgStream = function(tag, stream) {
     stream.socket.on('data', function(data) {
-	console.log(tag + ' in: ' + data);
+        console.log(tag + ' in: ' + data);
     });
     stream.on('error', function(e) {
-	console.log(tag + ' error: ' + e.stack ? e.stack : e);
+        console.log(tag + ' error: ' + e.stack ? e.stack : e);
     });
     stream.on('close', function() {
-	console.log(tag + ' close');
+        console.log(tag + ' close');
     });
     var oldSend = stream.send;
     stream.send = function(data) {
-	console.log(tag + ' out: ' + data);
-	oldSend.call(stream, data);
+        console.log(tag + ' out: ' + data);
+        oldSend.call(stream, data);
     };
 };
 
@@ -43,33 +43,33 @@ function DomainContext(router, domain) {
  */
 DomainContext.prototype.send = function(stanza) {
     if (stanza.root)
-	stanza = stanza.root();
+        stanza = stanza.root();
 
     // no destination? return to ourself
     if (!stanza.attrs.to) {
-	// do not provoke ping-pong effects
-	if (stanza.attrs.type === 'error')
-	    return;
-
-	stanza.attrs.to = stanza.attrs.from;
-	delete stanza.attrs.from;
-	stanza.attrs.type = 'error';
-	stanza.c('error', { type: 'modify' }).
-	    c('jid-malformed', { xmlns: NS_XMPP_STANZAS });
-	this.receive(stanza);
-
-	return;
+        // do not provoke ping-pong effects
+        if (stanza.attrs.type === 'error')
+            return;
+
+        stanza.attrs.to = stanza.attrs.from;
+        delete stanza.attrs.from;
+        stanza.attrs.type = 'error';
+        stanza.c('error', { type: 'modify' }).
+            c('jid-malformed', { xmlns: NS_XMPP_STANZAS });
+        this.receive(stanza);
+
+        return;
     }
 
     destDomain = new JID.JID(stanza.attrs.to).domain;
     var outStream = this.getOutStream(destDomain);
 
     if (outStream.isAuthed)
-	outStream.send(stanza);
+        outStream.send(stanza);
     else {
-	// TODO: queues per domain in domaincontext
-	outStream.queue = outStream.queue || [];
-	outStream.queue.push(stanza);
+        // TODO: queues per domain in domaincontext
+        outStream.queue = outStream.queue || [];
+        outStream.queue.push(stanza);
     }
 };
 
@@ -81,17 +81,17 @@ DomainContext.prototype.send = function(stanza) {
  */
 DomainContext.prototype.sendRaw = function(stanza, destDomain) {
     if (stanza.root)
-	stanza = stanza.root();
+        stanza = stanza.root();
 
     var outStream = this.getOutStream(destDomain);
     var send = function() {
-	outStream.send(stanza);
+        outStream.send(stanza);
     };
 
     if (outStream.isConnected)
-	send();
+        send();
     else
-	outStream.addListener('online', send);
+        outStream.addListener('online', send);
 
     return outStream;
 };
@@ -105,98 +105,98 @@ DomainContext.prototype.getOutStream = function(destDomain) {
     // unfortunately we cannot use the incoming streams
 
     if (!destDomain) {
-	throw new Error('Trying to reach empty domain');
+        throw new Error('Trying to reach empty domain');
     } else if (this.s2sOut.hasOwnProperty(destDomain)) {
-	// There's one already
-	return this.s2sOut[destDomain];
+        // There's one already
+        return this.s2sOut[destDomain];
     } else {
-	console.log("OUTGOING to " + destDomain);
-	var credentials = this.router.credentials[this.domain];
-	// Setup a new outgoing connection
-	var outStream = new Server.OutgoingServer(this.domain, destDomain, credentials);
-	this.s2sOut[destDomain] = outStream;
-	dbgStream('outgoing', outStream);
-
-	this.router.setupStream(outStream);
-	this.setupStream(destDomain, outStream);
-
-	var closeCb = function() {
-	    // purge queue
-	    if (outStream.queue) {
-		outStream.queue.forEach(function(stanza) {
-					    // do not provoke ping-pong effects
-					    if (stanza.attrs.type === 'error')
-						return;
-
-					    var dest = stanza.attrs.to;
-					    stanza.attrs.to = stanza.attrs.from;
-					    stanza.attrs.from = dest;
-					    stanza.attrs.type = 'error';
-					    stanza.c('error', { type: 'cancel' }).
-						c('remote-server-not-found', { xmlns: NS_XMPP_STANZAS });
-					    self.receive(stanza);
-					});
-	    }
-	    delete outStream.queue;
-
-	    // remove from DomainContext
-	    delete self.s2sOut[destDomain];
-	};
-	outStream.addListener('close', closeCb);
-	outStream.addListener('error', closeCb);
-
-	var onAuth =  function(method) {
-	    console.log({auth:method});
-	    outStream.isConnected = true;
-	    switch(method) {
-	    case 'dialback':
-		self.startDialback(destDomain, outStream);
-		break;
-
-	    case 'external':
-		outStream.send(new xml.Element('auth', { xmlns: NS_XMPP_SASL,
-							 mechanism: 'EXTERNAL' }).
-			       t(new Buffer(self.domain).toString('base64'))
-			      );
-		var onStanza;
-		onStanza = function(stanza) {
-		    console.log({external:{domain:destDomain,stanza:stanza.toString()}});
-		    if (stanza.is('success', NS_XMPP_SASL)) {
-			outStream.startParser();
-			outStream.startStream();
-			outStream.removeListener('stanza', onStanza);
-			var onStream;
-			onStream = function() {
-			    outStream.emit('online');
-			    outStream.removeListener('streamStart', onStream);
-			};
-			outStream.addListener('streamStart', onStream);
-		    } else if (stanza.is('failure', NS_XMPP_SASL))
-			outStream.end();
-		};
-		outStream.addListener('stanza', onStanza);
-		break;
-
-	    default:
-		outStream.error('undefined-condition',
-				'Cannot authenticate via ' + method);
-	    }
-	    outStream.removeListener('auth', onAuth);
-	};
-	outStream.addListener('auth', onAuth);
-
-	outStream.addListener('online', function() {
-	    console.log('ONLINE!');
-	    outStream.isAuthed = true;
-	    if (outStream.queue) {
-		outStream.queue.forEach(function(stanza) {
-		    outStream.send(stanza);
-		});
-		delete outStream.queue;
-	    }
-	});
-
-	return outStream;
+        console.log("OUTGOING to " + destDomain);
+        var credentials = this.router.credentials[this.domain];
+        // Setup a new outgoing connection
+        var outStream = new Server.OutgoingServer(this.domain, destDomain, credentials);
+        this.s2sOut[destDomain] = outStream;
+        dbgStream('outgoing', outStream);
+
+        this.router.setupStream(outStream);
+        this.setupStream(destDomain, outStream);
+
+        var closeCb = function() {
+            // purge queue
+            if (outStream.queue) {
+                outStream.queue.forEach(function(stanza) {
+                                            // do not provoke ping-pong effects
+                                            if (stanza.attrs.type === 'error')
+                                                return;
+
+                                            var dest = stanza.attrs.to;
+                                            stanza.attrs.to = stanza.attrs.from;
+                                            stanza.attrs.from = dest;
+                                            stanza.attrs.type = 'error';
+                                            stanza.c('error', { type: 'cancel' }).
+                                                c('remote-server-not-found', { xmlns: NS_XMPP_STANZAS });
+                                            self.receive(stanza);
+                                        });
+            }
+            delete outStream.queue;
+
+            // remove from DomainContext
+            delete self.s2sOut[destDomain];
+        };
+        outStream.addListener('close', closeCb);
+        outStream.addListener('error', closeCb);
+
+        var onAuth =  function(method) {
+            console.log({auth:method});
+            outStream.isConnected = true;
+            switch(method) {
+            case 'dialback':
+                self.startDialback(destDomain, outStream);
+                break;
+
+            case 'external':
+                outStream.send(new xml.Element('auth', { xmlns: NS_XMPP_SASL,
+                                                         mechanism: 'EXTERNAL' }).
+                               t(new Buffer(self.domain).toString('base64'))
+                              );
+                var onStanza;
+                onStanza = function(stanza) {
+                    console.log({external:{domain:destDomain,stanza:stanza.toString()}});
+                    if (stanza.is('success', NS_XMPP_SASL)) {
+                        outStream.startParser();
+                        outStream.startStream();
+                        outStream.removeListener('stanza', onStanza);
+                        var onStream;
+                        onStream = function() {
+                            outStream.emit('online');
+                            outStream.removeListener('streamStart', onStream);
+                        };
+                        outStream.addListener('streamStart', onStream);
+                    } else if (stanza.is('failure', NS_XMPP_SASL))
+                        outStream.end();
+                };
+                outStream.addListener('stanza', onStanza);
+                break;
+
+            default:
+                outStream.error('undefined-condition',
+                                'Cannot authenticate via ' + method);
+            }
+            outStream.removeListener('auth', onAuth);
+        };
+        outStream.addListener('auth', onAuth);
+
+        outStream.addListener('online', function() {
+            console.log('ONLINE!');
+            outStream.isAuthed = true;
+            if (outStream.queue) {
+                outStream.queue.forEach(function(stanza) {
+                    outStream.send(stanza);
+                });
+                delete outStream.queue;
+            }
+        });
+
+        return outStream;
     }
 };
 
@@ -207,18 +207,18 @@ DomainContext.prototype.addInStream = function(srcDomain, stream) {
     var self = this;
 
     if (this.s2sIn.hasOwnProperty(srcDomain)) {
-	// Replace old
-	var oldStream = this.s2sIn[srcDomain];
-	oldStream.error('conflict', 'Connection replaced');
-	delete self.s2sIn[srcDomain];
+        // Replace old
+        var oldStream = this.s2sIn[srcDomain];
+        oldStream.error('conflict', 'Connection replaced');
+        delete self.s2sIn[srcDomain];
     }
 
     this.setupStream(srcDomain, stream);
     stream.isConnected = true;
     stream.isAuthed = true;
     stream.addListener('close', function() {
-	if (self.s2sIn[srcDomain] == stream)
-	    delete self.s2sIn[srcDomain];
+        if (self.s2sIn[srcDomain] == stream)
+            delete self.s2sIn[srcDomain];
     });
     this.s2sIn[srcDomain] = stream;
 };
@@ -227,39 +227,39 @@ DomainContext.prototype.setupStream = function(domain, stream) {
     var self = this;
 
     stream.addListener('stanza', function(stanza) {
-	// Before verified they can send whatever they want
-	if (!stream.isAuthed)
-	    return;
-
-	if (stanza.name !== 'message' &&
-	    stanza.name !== 'presence' &&
-	    stanza.name !== 'iq')
-	    // no normal stanza
-	    return;
-
-
-	if (!(typeof stanza.attrs.from === 'string' &&
-	      typeof stanza.attrs.to === 'string')) {
-	    stream.error('improper-addressing');
-	    return;
-	}
-
-	// Only accept 'from' attribute JIDs that have the same domain
-	// that we validated the stream for
-	var fromDomain = (new JID.JID(stanza.attrs.from)).domain;
-	if (fromDomain !== domain) {
-	    stream.error('invalid-from');
-	    return;
-	}
-
-	// Only accept 'to' attribute JIDs to this DomainContext
-	var toDomain = (new JID.JID(stanza.attrs.to)).domain;
-	if (toDomain !== self.domain) {
-	    stream.error('improper-addressing');
-	    return;
-	}
-
-	self.receive(stanza);
+        // Before verified they can send whatever they want
+        if (!stream.isAuthed)
+            return;
+
+        if (stanza.name !== 'message' &&
+            stanza.name !== 'presence' &&
+            stanza.name !== 'iq')
+            // no normal stanza
+            return;
+
+
+        if (!(typeof stanza.attrs.from === 'string' &&
+              typeof stanza.attrs.to === 'string')) {
+            stream.error('improper-addressing');
+            return;
+        }
+
+        // Only accept 'from' attribute JIDs that have the same domain
+        // that we validated the stream for
+        var fromDomain = (new JID.JID(stanza.attrs.from)).domain;
+        if (fromDomain !== domain) {
+            stream.error('invalid-from');
+            return;
+        }
+
+        // Only accept 'to' attribute JIDs to this DomainContext
+        var toDomain = (new JID.JID(stanza.attrs.to)).domain;
+        if (toDomain !== self.domain) {
+            stream.error('improper-addressing');
+            return;
+        }
+
+        self.receive(stanza);
     });
 };
 
@@ -270,19 +270,19 @@ DomainContext.prototype.startDialback = function(destDomain, outStream) {
 
     var self = this;
     var onResult = function(from, to, isValid) {
-	if (from != destDomain ||
-	    to != self.domain)
-	    // not for us
-	    return;
-
-	outStream.removeListener('dialbackResult', onResult);
-	if (isValid) {
-	    outStream.emit('online');
-	} else {
-	    // we cannot do anything else with this stream that
-	    // failed dialback
-	    outStream.end();
-	}
+        if (from != destDomain ||
+            to != self.domain)
+            // not for us
+            return;
+
+        outStream.removeListener('dialbackResult', onResult);
+        if (isValid) {
+            outStream.emit('online');
+        } else {
+            // we cannot do anything else with this stream that
+            // failed dialback
+            outStream.end();
+        }
     };
     outStream.addListener('dialbackResult', onResult);
 };
@@ -293,77 +293,77 @@ DomainContext.prototype.verifyDialback = function(domain, id, key, cb) {
     var self = this;
     var outStream;
     if (this.s2sOut.hasOwnProperty(domain) &&
-	(outStream = this.s2sOut[domain])) {
-
-	if (outStream.isConnected) {
-	    var isValid = outStream.streamAttrs.id === id &&
-			      outStream.dbKey === key;
-	    cb(isValid);
-	} else {
-	    // Not online, wait for outStream.streamAttrs
-	    // (they may have our stream header & dialback key, but
-	    // our slow connection hasn't received their stream
-	    // header)
-	    outStream.addListener('online', function() {
-				      // recurse
-				      self.verifyDialback(domain, id, key, cb);
-				  });
-	    outStream.addListener('close', function() {
-				      cb(false);
-				  });
-	}
+        (outStream = this.s2sOut[domain])) {
+
+        if (outStream.isConnected) {
+            var isValid = outStream.streamAttrs.id === id &&
+                              outStream.dbKey === key;
+            cb(isValid);
+        } else {
+            // Not online, wait for outStream.streamAttrs
+            // (they may have our stream header & dialback key, but
+            // our slow connection hasn't received their stream
+            // header)
+            outStream.addListener('online', function() {
+                                      // recurse
+                                      self.verifyDialback(domain, id, key, cb);
+                                  });
+            outStream.addListener('close', function() {
+                                      cb(false);
+                                  });
+        }
     } else
-	cb(false);
+        cb(false);
 };
 
 DomainContext.prototype.verifyIncoming = function(fromDomain, inStream, dbKey) {
     var self = this;
     var outStream = this.sendRaw(Server.dialbackVerify(this.domain, fromDomain,
-						       inStream.streamId, dbKey),
-				 fromDomain);
+                                                       inStream.streamId, dbKey),
+                                 fromDomain);
 
     // these are needed before for removeListener()
     var onVerified = function(from, to, id, isValid) {
-	from = nameprep.prepare(from);
-	to = nameprep.prepare(to);
-	if (from !== fromDomain ||
-	    to !== self.domain ||
-	    id != inStream.streamId)
-	    // not for us
-	    return;
-
-	// tell them about it
-	inStream.send(Server.dialbackResult(to, from, isValid));
-
-	if (isValid) {
-	    // finally validated them!
-	    self.addInStream(from, inStream);
-	} else {
-	    // the connection isn't used for another domain, so
-	    // closing is safe
-	    inStream.send('</stream:stream>');
-	    inStream.end();
-	}
-
-	rmCbs();
+        from = nameprep.prepare(from);
+        to = nameprep.prepare(to);
+        if (from !== fromDomain ||
+            to !== self.domain ||
+            id != inStream.streamId)
+            // not for us
+            return;
+
+        // tell them about it
+        inStream.send(Server.dialbackResult(to, from, isValid));
+
+        if (isValid) {
+            // finally validated them!
+            self.addInStream(from, inStream);
+        } else {
+            // the connection isn't used for another domain, so
+            // closing is safe
+            inStream.send('</stream:stream>');
+            inStream.end();
+        }
+
+        rmCbs();
     };
     var onClose = function() {
-	// outgoing connection didn't work out, tell the incoming
-	// connection
-	inStream.send(Server.dialbackResult(to, from, false));
+        // outgoing connection didn't work out, tell the incoming
+        // connection
+        inStream.send(Server.dialbackResult(to, from, false));
 
-	rmCbs();
+        rmCbs();
     };
     var onCloseIn = function() {
-	// t'was the incoming stream that wanted to get
-	// verified, nothing to do remains
+        // t'was the incoming stream that wanted to get
+        // verified, nothing to do remains
 
-	rmCbs();
+        rmCbs();
     };
     var rmCbs = function() {
-	outStream.removeListener('dialbackVerified', onVerified);
-	outStream.removeListener('close', onClose);
-	inStream.removeListener('close', onCloseIn);
+        outStream.removeListener('dialbackVerified', onVerified);
+        outStream.removeListener('close', onClose);
+        inStream.removeListener('close', onCloseIn);
     };
     outStream.addListener('dialbackVerified', onVerified);
     outStream.addListener('close', onClose);
@@ -373,14 +373,14 @@ DomainContext.prototype.verifyIncoming = function(fromDomain, inStream, dbKey) {
 
 DomainContext.prototype.receive = function(stanza) {
     if (this.stanzaListener)
-	this.stanzaListener(stanza);
+        this.stanzaListener(stanza);
 };
 
 DomainContext.prototype.end = function() {
     var shutdown = function(conns) {
-	for(var domain in conns)
-	    if (conns.hasOwnProperty(domain))
-		conns[domain].end();
+        for(var domain in conns)
+            if (conns.hasOwnProperty(domain))
+                conns[domain].end();
     };
     shutdown(this.s2sOut);
     shutdown(this.s2sIn);
@@ -395,8 +395,8 @@ function Router(s2sPort) {
     this.ctxs = {};
 
     net.createServer(function(inStream) {
-	console.log('INCOMING from ' + inStream.remoteAddress);
-	self.acceptConnection(inStream);
+        console.log('INCOMING from ' + inStream.remoteAddress);
+        self.acceptConnection(inStream);
     }).listen(s2sPort || 5269);
 }
 exports.Router = Router;
@@ -417,7 +417,7 @@ Router.prototype.loadCredentials = function(domain, keyPath, certPath) {
     var cert = fs.readFileSync(certPath, 'ascii');
 
     this.credentials[domain] = crypto.createCredentials({ key: key,
-							  cert: cert });
+                                                          cert: cert });
 };
 
 Router.prototype.acceptConnection = function(socket) {
@@ -429,29 +429,29 @@ Router.prototype.acceptConnection = function(socket) {
 
     // incoming server wants to verify an outgoing connection of ours
     inStream.addListener('dialbackVerify', function(from, to, id, key) {
-	from = nameprep.prepare(from);
-	to = nameprep.prepare(to);
-
-	if (self.hasContext(to)) {
-	    self.getContext(to).verifyDialback(from, id, key, function(isValid) {
-		// look if this was a connection of ours
-		inStream.send(Server.dialbackVerified(to, from, id, isValid));
-	    });
-	} else
-	    // we don't host the 'to' domain
-	    inStream.send(Server.dialbackVerified(to, from, id, false));
+        from = nameprep.prepare(from);
+        to = nameprep.prepare(to);
+
+        if (self.hasContext(to)) {
+            self.getContext(to).verifyDialback(from, id, key, function(isValid) {
+                // look if this was a connection of ours
+                inStream.send(Server.dialbackVerified(to, from, id, isValid));
+            });
+        } else
+            // we don't host the 'to' domain
+            inStream.send(Server.dialbackVerified(to, from, id, false));
     });
     // incoming connection wants to get verified
     inStream.addListener('dialbackKey', function(from, to, key) {
-	from = nameprep.prepare(from);
-	to = nameprep.prepare(to);
-
-	if (self.hasContext(to)) {
-	    // trigger verification via outgoing connection
-	    self.getContext(to).verifyIncoming(from, inStream, key);
-	} else {
-	    inStream.error('host-unknown', to + ' is not served here');
-	}
+        from = nameprep.prepare(from);
+        to = nameprep.prepare(to);
+
+        if (self.hasContext(to)) {
+            // trigger verification via outgoing connection
+            self.getContext(to).verifyIncoming(from, inStream, key);
+        } else {
+            inStream.error('host-unknown', to + ' is not served here');
+        }
     });
 };
 
@@ -461,8 +461,8 @@ Router.prototype.setupStream = function(stream) {
     stream.socket.setKeepAlive(true, this.keepAlive);
     IdleTimeout.attach(stream.socket, this.streamTimeout);
     stream.socket.addListener('timeout', function() {
-			   stream.error('connection-timeout');
-		       });
+                           stream.error('connection-timeout');
+                       });
 };
 
 /**
@@ -478,28 +478,28 @@ Router.prototype.register = function(domain, listener) {
  */
 Router.prototype.unregister = function(domain) {
     if (this.hasContext(domain)) {
-	this.ctxs[domain].end();
+        this.ctxs[domain].end();
 
 console.log('deleting '+domain);
-	delete this.ctxs[domain];
+        delete this.ctxs[domain];
     }
 };
 
 Router.prototype.send = function(stanza) {
     if (stanza.root)
-	stanza = stanza.root();
+        stanza = stanza.root();
 
     var to = stanza.attrs && stanza.attrs.to;
     var toDomain = to && (new JID.JID(to)).domain;
     if (toDomain && this.hasContext(toDomain)) {
-	// inner routing
-	this.getContext(toDomain).receive(stanza);
+        // inner routing
+        this.getContext(toDomain).receive(stanza);
     } else if (stanza.attrs && stanza.attrs.from) {
-	// route to domain context for s2s
-	var domain = (new JID.JID(stanza.attrs.from)).domain;
-	this.getContext(domain).send(stanza);
+        // route to domain context for s2s
+        var domain = (new JID.JID(stanza.attrs.from)).domain;
+        this.getContext(domain).send(stanza);
     } else
-	throw 'Sending stanza from a domain we do not host';
+        throw 'Sending stanza from a domain we do not host';
 };
 
 Router.prototype.hasContext = function(domain) {
@@ -508,9 +508,9 @@ Router.prototype.hasContext = function(domain) {
 
 Router.prototype.getContext = function(domain) {
     if (this.ctxs.hasOwnProperty(domain))
-	return this.ctxs[domain];
+        return this.ctxs[domain];
     else
-	return (this.ctxs[domain] = new DomainContext(this, domain));
+        return (this.ctxs[domain] = new DomainContext(this, domain));
 };
 
 
@@ -520,7 +520,7 @@ Router.prototype.getContext = function(domain) {
 function generateKey() {
     var r = new Buffer(16);
     for(var i = 0; i < r.length; i++) {
-	r[i] = 48 + Math.floor(Math.random() * 10);  // '0'..'9'
+        r[i] = 48 + Math.floor(Math.random() * 10);  // '0'..'9'
     }
     return r.toString();
 }
diff --git a/lib/xmpp/sasl.js b/lib/xmpp/sasl.js
index ab9857a..8138ddd 100644
--- a/lib/xmpp/sasl.js
+++ b/lib/xmpp/sasl.js
@@ -2,108 +2,108 @@ var crypto = require('crypto');
 
 function selectMechanism(mechs) {
     if (mechs.indexOf("ANONYMOUS") >= 0)
-	return new Anonymous();
+        return new Anonymous();
     else if (mechs.indexOf("DIGEST-MD5") >= 0)
-	return new DigestMD5();
+        return new DigestMD5();
     else if (mechs.indexOf("PLAIN") >= 0)
-	return new Plain();
+        return new Plain();
     else
-	return null;
+        return null;
 }
 exports.selectMechanism = selectMechanism;
 
 function Plain() {
     this.name = "PLAIN";
     this.auth = function() {
-	return this.authzid + "\0" +
-	    this.authcid + "\0" +
-	    this.password;
+        return this.authzid + "\0" +
+            this.authcid + "\0" +
+            this.password;
     };
 }
 
 function Anonymous() {
     this.name = "ANONYMOUS";
     this.auth = function() {
-	return this.authzid;
+        return this.authzid;
     };
 }
 
 function DigestMD5() {
     this.name = "DIGEST-MD5";
     this.auth = function() {
-	return "";
+        return "";
     };
 
     this.nonce_count = 0;
     this.getNC = function() {
-	return rjust(this.nonce_count.toString(), 8, '0');
+        return rjust(this.nonce_count.toString(), 8, '0');
     };
     this.cnonce = generateNonce();
     this.challenge = function(s) {
-	dict = parseDict(s);
-	if (dict.realm)
-	    this.realm = dict.realm;
-	//require('sys').puts("dict: "+JSON.stringify(dict));
+        dict = parseDict(s);
+        if (dict.realm)
+            this.realm = dict.realm;
+        //require('sys').puts("dict: "+JSON.stringify(dict));
 
-	var response;
-	if (dict.nonce && dict.qop) {
-	    this.nonce_count++;
-	    var a1 = md5(this.authcid + ':' +
-			 this.realm + ':' +
-			 this.password) + ':' +
-			     dict.nonce + ':' +
-			     this.cnonce + ':' +
-			     this.authzid;
-	    var a2 = "AUTHENTICATE:" + this.digest_uri;
-	    if (dict.qop == 'auth-int' || dict.qop == 'auth-conf')
-		a2 += ":00000000000000000000000000000000";
-	    var responseValue = md5_hex(md5_hex(a1) + ':' +
-					dict.nonce + ':' +
-					this.getNC() + ':' +
-					this.cnonce + ':' +
-					dict.qop + ':' +
-					md5_hex(a2)
-				       );
-	    response = {
-		username: this.authcid,
-		realm: this.realm,
-		nonce: dict.nonce,
-		cnonce: this.cnonce,
-		nc: this.getNC(),
-		qop: dict.qop,
-		'digest-uri': this.digest_uri,
-		response: responseValue,
-		authzid: this.authzid,
-		charset: 'utf-8'
-	    };
-	} else if (dict.rspauth) {
-	    return "";
-	}
-	//require('sys').puts('response: '+JSON.stringify(response));
-	return encodeDict(response);
+        var response;
+        if (dict.nonce && dict.qop) {
+            this.nonce_count++;
+            var a1 = md5(this.authcid + ':' +
+                         this.realm + ':' +
+                         this.password) + ':' +
+                             dict.nonce + ':' +
+                             this.cnonce + ':' +
+                             this.authzid;
+            var a2 = "AUTHENTICATE:" + this.digest_uri;
+            if (dict.qop == 'auth-int' || dict.qop == 'auth-conf')
+                a2 += ":00000000000000000000000000000000";
+            var responseValue = md5_hex(md5_hex(a1) + ':' +
+                                        dict.nonce + ':' +
+                                        this.getNC() + ':' +
+                                        this.cnonce + ':' +
+                                        dict.qop + ':' +
+                                        md5_hex(a2)
+                                       );
+            response = {
+                username: this.authcid,
+                realm: this.realm,
+                nonce: dict.nonce,
+                cnonce: this.cnonce,
+                nc: this.getNC(),
+                qop: dict.qop,
+                'digest-uri': this.digest_uri,
+                response: responseValue,
+                authzid: this.authzid,
+                charset: 'utf-8'
+            };
+        } else if (dict.rspauth) {
+            return "";
+        }
+        //require('sys').puts('response: '+JSON.stringify(response));
+        return encodeDict(response);
     };
 }
 
 function parseDict(s) {
     var result = {};
     while (s) {
-	var m;
+        var m;
 
-	if ((m = /^(.+?)="(.*?[^\\])",(.*)/.exec(s))) {
-	    result[m[1]] = m[2];
-	    s = m[3];
-	} else if ((m = /^(.+?)="(.*?[^\\])"$/.exec(s))) {
-	    result[m[1]] = m[2];
-	    s = m[3];
-	} else if ((m = /^(.+?)=(.+?),(.*)/.exec(s))) {
-	    result[m[1]] = m[2];
-	    s = m[3];
-	} else if ((m = /^(.+?)=(.+?)$/.exec(s))) {
-	    result[m[1]] = m[2];
-	    s = m[3];
-	} else {
-	    s = null;
-	}
+        if ((m = /^(.+?)="(.*?[^\\])",(.*)/.exec(s))) {
+            result[m[1]] = m[2];
+            s = m[3];
+        } else if ((m = /^(.+?)="(.*?[^\\])"$/.exec(s))) {
+            result[m[1]] = m[2];
+            s = m[3];
+        } else if ((m = /^(.+?)=(.+?),(.*)/.exec(s))) {
+            result[m[1]] = m[2];
+            s = m[3];
+        } else if ((m = /^(.+?)=(.+?)$/.exec(s))) {
+            result[m[1]] = m[2];
+            s = m[3];
+        } else {
+            s = null;
+        }
     }
     return result;
 }
@@ -111,16 +111,16 @@ function parseDict(s) {
 function encodeDict(dict) {
     var s = "";
     for(k in dict) {
-	var v = dict[k];
-	if (v)
-	    s += ',' + k + '="' + v + '"';
+        var v = dict[k];
+        if (v)
+            s += ',' + k + '="' + v + '"';
     }
     return s.substr(1);  // without first ','
 }
 
 function rjust(s, targetLen, padding) {
     while(s.length < targetLen)
-	s = padding + s;
+        s = padding + s;
     return s;
 }
 
@@ -137,7 +137,7 @@ function md5_hex(s) {
 function generateNonce() {
     var result = "";
     for(var i = 0; i < 8; i++)
-	result += String.fromCharCode(48 +
-				      Math.ceil(Math.random() * 10));
+        result += String.fromCharCode(48 +
+                                      Math.ceil(Math.random() * 10));
     return result;
 }
diff --git a/lib/xmpp/server.js b/lib/xmpp/server.js
index a78c7b8..de37f11 100644
--- a/lib/xmpp/server.js
+++ b/lib/xmpp/server.js
@@ -25,65 +25,65 @@ function Server(socket) {
 
 console.log({Server:this});
     this.addListener('rawStanza', function(stanza) {
-	var key = stanza.getText();
+        var key = stanza.getText();
 
-	if (stanza.is('result', NS_DIALBACK)) {
-	    if (stanza.attrs.from && stanza.attrs.to &&
-		stanza.attrs.type) {
+        if (stanza.is('result', NS_DIALBACK)) {
+            if (stanza.attrs.from && stanza.attrs.to &&
+                stanza.attrs.type) {
 
-		self.emit('dialbackResult',
-			  stanza.attrs.from, stanza.attrs.to,
-			  stanza.attrs.type == 'valid');
+                self.emit('dialbackResult',
+                          stanza.attrs.from, stanza.attrs.to,
+                          stanza.attrs.type == 'valid');
 
-	    } else if (stanza.attrs.from && stanza.attrs.to) {
+            } else if (stanza.attrs.from && stanza.attrs.to) {
 
-		self.emit('dialbackKey',
-			  stanza.attrs.from, stanza.attrs.to,
-			  key);
+                self.emit('dialbackKey',
+                          stanza.attrs.from, stanza.attrs.to,
+                          key);
 
-	    }
-	} else if (stanza.is('verify', NS_DIALBACK)) {
-	    if (stanza.attrs.from && stanza.attrs.to &&
-		stanza.attrs.id && stanza.attrs.type) {
+            }
+        } else if (stanza.is('verify', NS_DIALBACK)) {
+            if (stanza.attrs.from && stanza.attrs.to &&
+                stanza.attrs.id && stanza.attrs.type) {
 
-		self.emit('dialbackVerified',
-			  stanza.attrs.from, stanza.attrs.to,
-			  stanza.attrs.id, stanza.attrs.type == 'valid');
+                self.emit('dialbackVerified',
+                          stanza.attrs.from, stanza.attrs.to,
+                          stanza.attrs.id, stanza.attrs.type == 'valid');
 
-	    } else if (stanza.attrs.from && stanza.attrs.to &&
-		       stanza.attrs.id) {
+            } else if (stanza.attrs.from && stanza.attrs.to &&
+                       stanza.attrs.id) {
 
-		self.emit('dialbackVerify',
-			  stanza.attrs.from, stanza.attrs.to,
-			  stanza.attrs.id, key);
-	    }
-	} else
-	    self.emit('stanza', stanza);
+                self.emit('dialbackVerify',
+                          stanza.attrs.from, stanza.attrs.to,
+                          stanza.attrs.id, key);
+            }
+        } else
+            self.emit('stanza', stanza);
     });
 }
 sys.inherits(Server, Connection.Connection);
 
 exports.dialbackKey = function(from, to, key) {
     return new xml.Element('db:result', { to: to,
-					  from: from }).
-	t(key);
+                                          from: from }).
+        t(key);
 };
 exports.dialbackVerify = function(from, to, id, key) {
     return new xml.Element('db:verify', { to: to,
-					  from: from,
-					  id: id }).
-	t(key);
+                                          from: from,
+                                          id: id }).
+        t(key);
 };
 exports.dialbackVerified = function(from, to, id, isValid) {
     return new xml.Element('db:verify', { to: to,
-					  from: from,
-					  id: id,
-					  type: isValid ? 'valid' : 'invalid' });
+                                          from: from,
+                                          id: id,
+                                          type: isValid ? 'valid' : 'invalid' });
 };
 exports.dialbackResult = function(from, to, isValid) {
     return new xml.Element('db:result', { to: to,
-					  from: from,
-					  type: isValid ? 'valid' : 'invalid' });
+                                          from: from,
+                                          type: isValid ? 'valid' : 'invalid' });
 };
 
 exports.IncomingServer = function(stream, credentials) {
@@ -95,23 +95,23 @@ exports.IncomingServer = function(stream, credentials) {
 
     this.addListener('streamStart', function(streamAttrs) {
 console.log({streamAttrs:streamAttrs,credentials:credentials});
-	if (streamAttrs.to &&
-	    credentials &&
-	    credentials.hasOwnProperty(streamAttrs.to))
-	    // TLS cert & key for this domain
-	    self.credentials = credentials[streamAttrs.to];
-	// No credentials means we cannot <starttls/> on the server
-	// side. Unfortunately this is required for XMPP 1.0.
-	if (!self.credentials)
-	    delete self.xmppVersion;
-
-	self.startStream();
+        if (streamAttrs.to &&
+            credentials &&
+            credentials.hasOwnProperty(streamAttrs.to))
+            // TLS cert & key for this domain
+            self.credentials = credentials[streamAttrs.to];
+        // No credentials means we cannot <starttls/> on the server
+        // side. Unfortunately this is required for XMPP 1.0.
+        if (!self.credentials)
+            delete self.xmppVersion;
+
+        self.startStream();
     });
     this.addListener('rawStanza', function(stanza) {
-	if (stanza.is('starttls', Connection.NS_XMPP_TLS)) {
-	    self.send(new xml.Element('proceed', { xmlns: Connection.NS_XMPP_TLS }));
-	    self.setSecure();
-	}
+        if (stanza.is('starttls', Connection.NS_XMPP_TLS)) {
+            self.send(new xml.Element('proceed', { xmlns: Connection.NS_XMPP_TLS }));
+            self.setSecure();
+        }
     });
 
     return self;
@@ -122,10 +122,10 @@ exports.IncomingServer.prototype.startStream = function() {
     Server.prototype.startStream.call(this);
 
     if (this.xmppVersion == '1.0') {
-	this.send("<stream:features>");
-	if (this.credentials && !this.socket.secureEstablished)
-	    this.send("<starttls xmlns='" + Connection.NS_XMPP_TLS + "'/>");
-	this.send("</stream:features>");
+        this.send("<stream:features>");
+        if (this.credentials && !this.socket.secureEstablished)
+            this.send("<starttls xmlns='" + Connection.NS_XMPP_TLS + "'/>");
+        this.send("</stream:features>");
     }
 };
 
@@ -140,43 +140,43 @@ exports.OutgoingServer = function(srcDomain, destDomain, credentials) {
     // side. Unfortunately this is required for XMPP 1.0.
 console.log({outCreds:self.credentials});
     if (!this.credentials)
-	delete this.xmppVersion;
+        delete this.xmppVersion;
 
     this.socket.addListener('secure', function() {
-	self.startStream();
+        self.startStream();
     });
     this.addListener('streamStart', function(attrs) {
-			 if (attrs.version !== "1.0")
-			     // Don't wait for <stream:features/>
-			     self.emit('auth', 'dialback');
-		     });
+                         if (attrs.version !== "1.0")
+                             // Don't wait for <stream:features/>
+                             self.emit('auth', 'dialback');
+                     });
     self.addListener('rawStanza', function(stanza) {
-	if (stanza.is('features', Connection.NS_STREAM)) {
-	    var mechsEl;
-	    if ((mechsEl = stanza.getChild('mechanisms', NS_XMPP_SASL))) {
-		var mechs = mechsEl.getChildren('mechanism', NS_XMPP_SASL).
-		    map(function(el) { return el.getText(); });
-		if (mechs.indexOf('EXTERNAL') >= 0)
-		    self.emit('auth', 'external');
-		else
-		    self.emit('auth', 'dialback');
-	    } else {
-		// No SASL mechanisms
-		self.emit('auth', 'dialback');
-	    }
-	}
+        if (stanza.is('features', Connection.NS_STREAM)) {
+            var mechsEl;
+            if ((mechsEl = stanza.getChild('mechanisms', NS_XMPP_SASL))) {
+                var mechs = mechsEl.getChildren('mechanism', NS_XMPP_SASL).
+                    map(function(el) { return el.getText(); });
+                if (mechs.indexOf('EXTERNAL') >= 0)
+                    self.emit('auth', 'external');
+                else
+                    self.emit('auth', 'dialback');
+            } else {
+                // No SASL mechanisms
+                self.emit('auth', 'dialback');
+            }
+        }
     });
 
     var attempt = SRV.connect(this.socket, ['_xmpp-server._tcp',
-					    '_jabber._tcp'],
-			      destDomain, 5269);
+                                            '_jabber._tcp'],
+                              destDomain, 5269);
     attempt.addListener('connect', function() {
-	self.startParser();
-	self.startStream();
+        self.startParser();
+        self.startStream();
     });
     attempt.addListener('error', function(e) {
-	console.log({attemptError:e});
-	self.emit('error', e);
+        console.log({attemptError:e});
+        self.emit('error', e);
     });
 };
 sys.inherits(exports.OutgoingServer, Server);
@@ -184,7 +184,7 @@ sys.inherits(exports.OutgoingServer, Server);
 function generateId() {
     var r = new Buffer(16);
     for(var i = 0; i < r.length; i++) {
-	r[i] = 48 + Math.floor(Math.random() * 10);  // '0'..'9'
+        r[i] = 48 + Math.floor(Math.random() * 10);  // '0'..'9'
     }
     return r.toString();
 };
diff --git a/lib/xmpp/srv.js b/lib/xmpp/srv.js
index 6c8872e..df51643 100644
--- a/lib/xmpp/srv.js
+++ b/lib/xmpp/srv.js
@@ -5,38 +5,38 @@ function compareNumbers(a, b) {
     a = parseInt(a, 10);
     b = parseInt(b, 10);
     if (a < b)
-	return -1;
+        return -1;
     if (a > b)
-	return 1;
+        return 1;
     return 0;
 }
 
 function groupSrvRecords(addrs) {
     var groups = {};  // by priority
     addrs.forEach(function(addr) {
-		      if (!groups.hasOwnProperty(addr.priority))
-			  groups[addr.priority] = [];
+                      if (!groups.hasOwnProperty(addr.priority))
+                          groups[addr.priority] = [];
 
-		      groups[addr.priority].push(addr);
-		  });
+                      groups[addr.priority].push(addr);
+                  });
 
     var result = [];
     Object.keys(groups).sort(compareNumbers).forEach(function(priority) {
-	var group = groups[priority];
-	var totalWeight = 0;
-	group.forEach(function(addr) {
-	    totalWeight += addr.weight;
-	});
-	var w = Math.floor(Math.random() * totalWeight);
-	totalWeight = 0;
-	var candidate = group[0];
-	group.forEach(function(addr) {
-	    totalWeight += addr.weight;
-	    if (w < totalWeight)
-		candidate = addr;
-	});
-	if (candidate)
-	    result.push(candidate);
+        var group = groups[priority];
+        var totalWeight = 0;
+        group.forEach(function(addr) {
+            totalWeight += addr.weight;
+        });
+        var w = Math.floor(Math.random() * totalWeight);
+        totalWeight = 0;
+        var candidate = group[0];
+        group.forEach(function(addr) {
+            totalWeight += addr.weight;
+            if (w < totalWeight)
+                candidate = addr;
+        });
+        if (candidate)
+            result.push(candidate);
     });
     return result;
 }
@@ -44,32 +44,32 @@ function groupSrvRecords(addrs) {
 function resolveSrv(name, cb) {
     dns.resolveSrv(name, function(err, addrs) {
 console.log({resolveSrv:[name,err,addrs]});
-	if (err) {
-	    /* no SRV record, try domain as A */
-	    cb(err);
-	} else {
-	    var pending = 0, error, results = [];
-	    var cb1 = function(e, addrs1) {
-		error = error || e;
-		results = results.concat(addrs1);
-		pending--;
-		console.log({results:results,error:error,pending:pending});
-		if (pending < 1) {
-		    cb(results ? null : error, results);
-		}
-	    };
-	    groupSrvRecords(addrs).forEach(function(addr) {
-		resolveHost(addr.name, function(e, a) {
-		    if (a)
-			a = a.map(function(a1) {
-				      return { name: a1,
-					       port: addr.port };
-				  });
-		    cb1(e, a);
-		});
-		pending++;
-	    });
-	}
+        if (err) {
+            /* no SRV record, try domain as A */
+            cb(err);
+        } else {
+            var pending = 0, error, results = [];
+            var cb1 = function(e, addrs1) {
+                error = error || e;
+                results = results.concat(addrs1);
+                pending--;
+                console.log({results:results,error:error,pending:pending});
+                if (pending < 1) {
+                    cb(results ? null : error, results);
+                }
+            };
+            groupSrvRecords(addrs).forEach(function(addr) {
+                resolveHost(addr.name, function(e, a) {
+                    if (a)
+                        a = a.map(function(a1) {
+                                      return { name: a1,
+                                               port: addr.port };
+                                  });
+                    cb1(e, a);
+                });
+                pending++;
+            });
+        }
     });
 }
 
@@ -78,14 +78,14 @@ function resolveHost(name, cb) {
     var error, results = [], pending = 2;
     var cb1 = function(e, addrs) {
 console.log({resolveHost:[name,e,addrs]});
-	error = error || e;
-	var addr = addrs && addrs[Math.floor(Math.random() * addrs.length)];
-	if (addr)
-	    results.push(addr);
+        error = error || e;
+        var addr = addrs && addrs[Math.floor(Math.random() * addrs.length)];
+        if (addr)
+            results.push(addr);
 
-	pending--;
-	if (pending < 1)
-	    cb((results.length > 0) ? null : error, results);
+        pending--;
+        if (pending < 1)
+            cb((results.length > 0) ? null : error, results);
     };
 
     dns.resolve4(name, cb1);
@@ -96,22 +96,22 @@ console.log({resolveHost:[name,e,addrs]});
 function tryConnect(socket, addrs, listener) {
 console.log({tryConnect:addrs});
     var onConnect = function() {
-	socket.removeListener('connect', onConnect);
-	socket.removeListener('error', onError);
-	// done!
-	listener.emit('connect');
+        socket.removeListener('connect', onConnect);
+        socket.removeListener('error', onError);
+        // done!
+        listener.emit('connect');
     };
     var error;
     var onError = function(e) {
-	error = e;
-	connectNext();
+        error = e;
+        connectNext();
     };
     var connectNext = function() {
-	var addr = addrs.shift();
-	if (addr)
-	    socket.connect(addr.port, addr.name);
-	else
-	    listener.emit('error', error);
+        var addr = addrs.shift();
+        if (addr)
+            socket.connect(addr.port, addr.name);
+        else
+            listener.emit('error', error);
     };
     socket.addListener('connect', onConnect);
     socket.addListener('error', onError);
@@ -123,26 +123,26 @@ exports.connect = function(socket, services, domain, defaultPort) {
     var listener = new EventEmitter();
 
     var tryServices = function() {
-	var service = services.shift();
-	if (service) {
-	    resolveSrv(service + '.' + domain, function(error, addrs) {
-		if (addrs)
-		    tryConnect(socket, addrs, listener);
-		else
-		    tryServices();
-	    });
-	} else {
-	    resolveHost(domain, function(error, addrs) {
-		if (addrs && addrs.length > 0) {
-		    addrs = addrs.map(function(addr) {
-			return { name: addr,
-				 port: defaultPort };
-		    });
-		    tryConnect(socket, addrs, listener);
-		} else
-		    listener.emit('error', error);
-	    });
-	}
+        var service = services.shift();
+        if (service) {
+            resolveSrv(service + '.' + domain, function(error, addrs) {
+                if (addrs)
+                    tryConnect(socket, addrs, listener);
+                else
+                    tryServices();
+            });
+        } else {
+            resolveHost(domain, function(error, addrs) {
+                if (addrs && addrs.length > 0) {
+                    addrs = addrs.map(function(addr) {
+                        return { name: addr,
+                                 port: defaultPort };
+                    });
+                    tryConnect(socket, addrs, listener);
+                } else
+                    listener.emit('error', error);
+            });
+        }
 
     };
     tryServices();
diff --git a/lib/xmpp/stream_parser.js b/lib/xmpp/stream_parser.js
index e1dc8dc..90e1f08 100644
--- a/lib/xmpp/stream_parser.js
+++ b/lib/xmpp/stream_parser.js
@@ -12,40 +12,40 @@ function StreamParser(charset, maxStanzaSize) {
     this.bytesParsedOnStanzaBegin = 0;
 
     this.parser.addListener('startElement', function(name, attrs) {
-	// TODO: refuse anything but <stream:stream>
-	if (!self.element && name == 'stream:stream') {
-	    self.emit('start', attrs);
-	} else {
-	    var child = new xml.Element(name, attrs);
-	    if (!self.element) {
-		/* A new stanza */
-		self.element = child;
-		self.bytesParsedOnStanzaBegin = self.bytesParsed;
-	    } else {
-		/* A child element of a stanza */
-		self.element = self.element.cnode(child);
-	    }
-	}
+        // TODO: refuse anything but <stream:stream>
+        if (!self.element && name == 'stream:stream') {
+            self.emit('start', attrs);
+        } else {
+            var child = new xml.Element(name, attrs);
+            if (!self.element) {
+                /* A new stanza */
+                self.element = child;
+                self.bytesParsedOnStanzaBegin = self.bytesParsed;
+            } else {
+                /* A child element of a stanza */
+                self.element = self.element.cnode(child);
+            }
+        }
     });
     this.parser.addListener('endElement', function(name, attrs) {
-	if (!self.element && name == 'stream:stream') {
-	    self.end();
-	} else if (self.element && name == self.element.name) {
-	    if (self.element.parent)
-		self.element = self.element.parent;
-	    else {
-		/* Stanza complete */
-		self.emit('stanza', self.element);
-		delete self.element;
-		delete self.bytesParsedOnStanzaBegin;
-	    }
-	} else {
-	    self.error('xml-not-well-formed', 'XML parse error');
-	}
+        if (!self.element && name == 'stream:stream') {
+            self.end();
+        } else if (self.element && name == self.element.name) {
+            if (self.element.parent)
+                self.element = self.element.parent;
+            else {
+                /* Stanza complete */
+                self.emit('stanza', self.element);
+                delete self.element;
+                delete self.bytesParsedOnStanzaBegin;
+            }
+        } else {
+            self.error('xml-not-well-formed', 'XML parse error');
+        }
     });
     this.parser.addListener('text', function(str) {
-	if (self.element)
-	    self.element.t(str);
+        if (self.element)
+            self.element.t(str);
     });
 }
 sys.inherits(StreamParser, EventEmitter);
@@ -53,24 +53,24 @@ exports.StreamParser = StreamParser;
 
 StreamParser.prototype.write = function(data) {
     if (this.parser) {
-	if (this.bytesParsedOnStanzaBegin && this.maxStanzaSize &&
-	    this.bytesParsed > this.bytesParsedOnStanzaBegin + this.maxStanzaSize) {
+        if (this.bytesParsedOnStanzaBegin && this.maxStanzaSize &&
+            this.bytesParsed > this.bytesParsedOnStanzaBegin + this.maxStanzaSize) {
 
-	    this.error('policy-violation', 'Maximum stanza size exceeded');
-	    return;
-	}
-	this.bytesParsed += data.length;
+            this.error('policy-violation', 'Maximum stanza size exceeded');
+            return;
+        }
+        this.bytesParsed += data.length;
 
-	if (!this.parser.parse(data, this.final ? true : false)) {
-	    this.error('xml-not-well-formed', 'XML parse error');
-	}
+        if (!this.parser.parse(data, this.final ? true : false)) {
+            this.error('xml-not-well-formed', 'XML parse error');
+        }
     }
 };
 
 StreamParser.prototype.end = function(data) {
     if (data) {
-	this.final = true;
-	this.write(data);
+        this.final = true;
+        this.write(data);
     }
 
     delete this.parser;
diff --git a/lib/xmpp/xml.js b/lib/xmpp/xml.js
index 2bd2576..f6bd973 100644
--- a/lib/xmpp/xml.js
+++ b/lib/xmpp/xml.js
@@ -18,15 +18,15 @@ function Element(name, attrs) {
  **/
 Element.prototype.is = function(name, xmlns) {
     return this.getName() == name &&
-	(!xmlns || this.getNS() == xmlns);
+        (!xmlns || this.getNS() == xmlns);
 };
 
 /* without prefix */
 Element.prototype.getName = function() {
     if (this.name.indexOf(":") >= 0)
-	return this.name.substr(this.name.indexOf(":") + 1);
+        return this.name.substr(this.name.indexOf(":") + 1);
     else
-	return this.name;
+        return this.name;
 };
 
 /**
@@ -34,10 +34,10 @@ Element.prototype.getName = function() {
  **/
 Element.prototype.getNS = function() {
     if (this.name.indexOf(":") >= 0) {
-	var prefix = this.name.substr(0, this.name.indexOf(":"));
-	return this.findNS(prefix);
+        var prefix = this.name.substr(0, this.name.indexOf(":"));
+        return this.findNS(prefix);
     } else {
-	return this.findNS();
+        return this.findNS();
     }
 };
 
@@ -46,18 +46,18 @@ Element.prototype.getNS = function() {
  **/
 Element.prototype.findNS = function(prefix) {
     if (!prefix) {
-	/* default namespace */
-	if (this.attrs.xmlns)
-	    return this.attrs.xmlns;
-	else
-	    return this.parent.findNS();
+        /* default namespace */
+        if (this.attrs.xmlns)
+            return this.attrs.xmlns;
+        else
+            return this.parent.findNS();
     } else {
-	/* prefixed namespace */
-	var attr = 'xmlns:' + prefix;
-	if (this.attrs[attr])
-	    return this.attrs[attr];
-	else
-	    return this.parent.findNS(prefix);
+        /* prefixed namespace */
+        var attr = 'xmlns:' + prefix;
+        if (this.attrs[attr])
+            return this.attrs[attr];
+        else
+            return this.parent.findNS(prefix);
     }
 };
 
@@ -73,10 +73,10 @@ Element.prototype.getChild = function(name, xmlns) {
 Element.prototype.getChildren = function(name, xmlns) {
     var result = [];
     this.children.forEach(function(child) {
-	if (child.getName &&
-	    child.getName() == name &&
-	    (!xmlns || child.getNS() == xmlns))
-	    result.push(child);
+        if (child.getName &&
+            child.getName() == name &&
+            (!xmlns || child.getNS() == xmlns))
+            result.push(child);
     });
     return result;
 };
@@ -84,8 +84,8 @@ Element.prototype.getChildren = function(name, xmlns) {
 Element.prototype.getText = function() {
     var text = "";
     this.children.forEach(function(child) {
-	if (typeof child == 'string')
-	    text += child;
+        if (typeof child == 'string')
+            text += child;
     });
     return text;
 };
@@ -93,10 +93,10 @@ Element.prototype.getText = function() {
 Element.prototype.getChildText = function(name) {
     var text = null;
     this.children.forEach(function(el) {
-	if (!text && el.name == name)
-	{
-	    text = el.getText();
-	}
+        if (!text && el.name == name)
+        {
+            text = el.getText();
+        }
     });
     return text;
 };
@@ -106,18 +106,18 @@ Element.prototype.getChildText = function(name) {
 /** returns uppermost parent */
 Element.prototype.root = function() {
     if (this.parent)
-	return this.parent.root();
+        return this.parent.root();
     else
-	return this;
+        return this;
 };
 Element.prototype.tree = Element.prototype.root;
 
 /** just parent or itself */
 Element.prototype.up = function() {
     if (this.parent)
-	return this.parent;
+        return this.parent;
     else
-	return this;
+        return this;
 };
 
 /** create child node and return it */
@@ -142,7 +142,7 @@ Element.prototype.t = function(text) {
 Element.prototype.toString = function() {
     var s = "";
     this.write(function(c) {
-	s += c;
+        s += c;
     });
     return s;
 };
@@ -151,38 +151,38 @@ Element.prototype.write = function(writer) {
     writer("<");
     writer(this.name);
     for(var k in this.attrs) {
-	writer(" ");
-	writer(k);
-	writer("=\"");
-	var v = this.attrs[k];
-	if (typeof v != 'string')
-	    v = v.toString();
-	writer(escapeXml(v));
-	writer("\"");
+        writer(" ");
+        writer(k);
+        writer("=\"");
+        var v = this.attrs[k];
+        if (typeof v != 'string')
+            v = v.toString();
+        writer(escapeXml(v));
+        writer("\"");
     }
     if (this.children.length == 0) {
-	writer("/>");
+        writer("/>");
     } else {
-	writer(">");
-	this.children.forEach(function(child) {
-	    if (typeof child == 'string')
-		writer(escapeXml(child));
-	    else
-		child.write(writer);
-	});
-	writer("</");
-	writer(this.name);
-	writer(">");
+        writer(">");
+        this.children.forEach(function(child) {
+            if (typeof child == 'string')
+                writer(escapeXml(child));
+            else
+                child.write(writer);
+        });
+        writer("</");
+        writer(this.name);
+        writer(">");
     }
 };
 
 function escapeXml(s) {
     return s.
-	replace(/\&/g, '&').
-	replace(/</g, '<').
-	replace(/>/g, '>').
-	replace(/"/g, '"').
-	replace(/'/g, ''');
+        replace(/\&/g, '&').
+        replace(/</g, '<').
+        replace(/>/g, '>').
+        replace(/"/g, '"').
+        replace(/'/g, ''');
 };
 
 exports.Element = Element;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list