[Pkg-javascript-commits] [ltx] 71/469: router: send errors

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:03 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 fe69046c8faedf3166160db2bfc84b4a5d6442e5
Author: Astro <astro at spaceboyz.net>
Date:   Sun Sep 5 18:55:09 2010 +0200

    router: send errors
---
 lib/xmpp/router.js | 95 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 53 insertions(+), 42 deletions(-)

diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 86b5be6..bad9aab 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -125,6 +125,10 @@ DomainContext.prototype.addInStream = function(domain, stream) {
     if (this.s2sIn.hasOwnProperty(domain)) {
 	// Replace old
 	var oldStream = this.s2sIn[domain];
+	if (oldStream.writable) {
+	    oldStream.send(Server.error('conflict', 'Connection replaced'));
+	    oldStream.send('</stream:stream>');
+	}
 	oldStream.end();
     }
 
@@ -146,24 +150,28 @@ DomainContext.prototype.setupStream = function(domain, stream) {
 	if (!stream.isVerified)
 	    return;
 
-	var allowed = typeof stanza.attrs.from === 'string' &&
-	    typeof stanza.attrs.to === 'string';
-	if (allowed) {
-	    var fromDomain = (new JID.JID(stanza.attrs.from)).domain;
-	    allowed = fromDomain === domain;
+	if (!(typeof stanza.attrs.from === 'string' &&
+	      typeof stanza.attrs.to === 'string')) {
+	    stream.send(Server.error('improper-addressing'));
+	    stream.emit('error', new Error('improper-addressing'));
+	    return;
 	}
-	if (allowed) {
-	    var toDomain = (new JID.JID(stanza.attrs.to)).domain;
-	    allowed = toDomain === self.domain;
+
+	var fromDomain = (new JID.JID(stanza.attrs.from)).domain;
+	if (fromDomain !== domain) {
+	    stream.send(Server.error('invalid-from'));
+	    stream.emit('error', new Error('invalid-from'));
+	    return;
 	}
 
-	if (allowed) {
-	    self.receive(stanza);
-	} else {
-	    console.log({'improper-addressing':stanza.toString()});
+	var toDomain = (new JID.JID(stanza.attrs.to)).domain;
+	if (toDomain !== self.domain) {
 	    stream.send(Server.error('improper-addressing'));
 	    stream.emit('error', new Error('improper-addressing'));
+	    return;
 	}
+
+	self.receive(stanza);
     });
     stream.addListener('error', function() {
 	if (stream.writable)
@@ -193,10 +201,8 @@ DomainContext.prototype.receive = function(stanza) {
 /**
  * TODO:
  * * recv stanzas
- * * jid check (<improper-addressing/>)
  * * karma
  * * nameprep
- * * no forwarding/allow only to hosted domains
  * * timeouts
  * * parser errors
  * * keepAlive
@@ -226,35 +232,40 @@ Router.prototype.acceptConnection = function(inStream) {
     });
     // incoming connection wants to get verified
     inStream.addListener('dialbackKey', function(from, to, key) {
-	// TODO: what if no context?
-	var ctx = self.getContext(to);
-	var outStream = ctx.sendRaw(Server.dialbackVerify(to, from, inStream.streamId, key),
-				    from);
-
-	// TODO: hook inStream close
-	var onVerified, onClose;
-	onVerified = function(from, to, id, isValid) {
-	    inStream.send(Server.dialbackResult(to, from, isValid));
-
-	    if (isValid && self.hasContext(to)) {
-		self.getContext(to).addInStream(from, inStream);
-	    } else {
-		// the connection isn't used for another domain, so
-		// closing is safe
-		inStream.send('</stream:stream>');
-		inStream.end();
-	    }
+	if (self.hasContext(to)) {
+	    var ctx = self.getContext(to);
+	    var outStream = ctx.sendRaw(Server.dialbackVerify(to, from, inStream.streamId, key),
+					from);
+
+	    // TODO: hook inStream close
+	    var onVerified, onClose;
+	    onVerified = function(from, to, id, isValid) {
+		inStream.send(Server.dialbackResult(to, from, isValid));
+
+		if (isValid && self.hasContext(to)) {
+		    self.getContext(to).addInStream(from, inStream);
+		} else {
+		    // the connection isn't used for another domain, so
+		    // closing is safe
+		    inStream.send('</stream:stream>');
+		    inStream.end();
+		}
 
-	    outStream.removeListener('dialbackVerified', onVerified);
-	    outStream.removeListener('close', onClose);
-	};
-	onClose = function() {
-	    // outgoing connection didn't work out, tell the incoming
-	    // connection
-	    inStream.send(Server.dialbackResult(to, from, false));
-	};
-	outStream.addListener('dialbackVerified', onVerified);
-	outStream.addListener('close', onClose);
+		outStream.removeListener('dialbackVerified', onVerified);
+		outStream.removeListener('close', onClose);
+	    };
+	    onClose = function() {
+		// outgoing connection didn't work out, tell the incoming
+		// connection
+		inStream.send(Server.dialbackResult(to, from, false));
+	    };
+	    outStream.addListener('dialbackVerified', onVerified);
+	    outStream.addListener('close', onClose);
+	} else {
+	    inStream.send(Server.error('host-unknown', to + ' is not served here'));
+	    inStream.send('</stream:stream>');
+	    inStream.end();
+	}
     });
 };
 

-- 
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