[Pkg-javascript-commits] [ltx] 58/469: rm 'authFail' event in favour of 'error'; cleanup

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:00 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 4e863cc1025322ed652caf5c73a2f8a4e4d8f2c2
Author: Astro <astro at spaceboyz.net>
Date:   Sat Aug 14 01:19:21 2010 +0200

    rm 'authFail' event in favour of 'error'; cleanup
---
 README.markdown                    | 10 +++++-----
 examples/echo_bot.js               | 10 ----------
 examples/send_message.js           | 11 ++---------
 examples/send_message_component.js | 11 ++---------
 lib/xmpp/client.js                 |  7 +------
 lib/xmpp/connection.js             | 11 +++++++++--
 6 files changed, 19 insertions(+), 41 deletions(-)

diff --git a/README.markdown b/README.markdown
index b26db74..2f35b0c 100644
--- a/README.markdown
+++ b/README.markdown
@@ -30,7 +30,7 @@ Objectives of *node-xmpp:*
 
 * Client authentication with SASL DIGEST-MD5, PLAIN, ANONYMOUS
 * `_xmpp-client._tcp` SRV record support
-* Simple JID parsing
+* Simple JID parsing with Stringprep normalization
 * XML builder & serialization, xmlns-aware
 * [Component](http://xmpp.org/extensions/xep-0114.html) connections
 
@@ -38,6 +38,7 @@ Objectives of *node-xmpp:*
 ## Dependencies
 
 * [node-expat](http://github.com/astro/node-expat)
+* [node-stringprep](http://github.com/astro/node-stringprep)
 
 
 ## Design
@@ -59,7 +60,6 @@ Objectives of *node-xmpp:*
 That means you can use the TCP events of `net.Stream` with Client and
 Component objects. Other than that, hook callbacks to these events:
 
-* `authFail`, distinguished from `error`
 * `online`, when authentication is done and you can send XMPP stanzas
   (ie. `<presence/>`)
 * `stanza` for each incoming XMPP stanza, with the XML Element as
@@ -89,6 +89,6 @@ stanza, before sending it out the wire.
 
 ## TODO
 
-* Documentation
-* Tests ([what framework?](http://wiki.github.com/ry/node/modules#testing))
-* Avoid namespace pollution?
+* More documentation
+* More tests (Using [Vows](http://vowsjs.org/))
+
diff --git a/examples/echo_bot.js b/examples/echo_bot.js
index 1952e39..5970c5d 100644
--- a/examples/echo_bot.js
+++ b/examples/echo_bot.js
@@ -34,17 +34,7 @@ cl.on('stanza',
 	      cl.send(stanza);
 	  }
       });
-cl.on('authFail',
-      function() {
-	  sys.puts("Authentication failure");
-	  process.exit(1);
-      });
 cl.on('error',
       function(e) {
 	  sys.puts(e);
-	  process.exit(1);
-      });
-cl.on('end',
-      function() {
-	  /* node.js will exit by itself */
       });
diff --git a/examples/send_message.js b/examples/send_message.js
index 87330ed..79ca2ea 100644
--- a/examples/send_message.js
+++ b/examples/send_message.js
@@ -20,19 +20,12 @@ cl.addListener('online',
 				   c('body').
 				   t(argv[4]));
 		       });
+
+		   // nodejs has nothing left to do and will exit
 		   cl.end();
 	       });
-cl.addListener('authFail',
-	       function() {
-		   sys.puts("Authentication failure");
-		   process.exit(1);
-	       });
 cl.addListener('error',
 	       function(e) {
 		   sys.puts(e);
 		   process.exit(1);
 	       });
-cl.addListener('end',
-	       function() {
-		   /* node.js will exit by itself */
-	       });
diff --git a/examples/send_message_component.js b/examples/send_message_component.js
index b143784..a2d82f9 100644
--- a/examples/send_message_component.js
+++ b/examples/send_message_component.js
@@ -24,19 +24,12 @@ c.addListener('online',
 				  c('body').
 				  t(argv[4]));
 		       });
+
+		   // nodejs has nothing left to do and will exit
 		   c.end();
 	       });
-c.addListener('authFail',
-	       function() {
-		   sys.puts("Authentication failure");
-		   process.exit(1);
-	       });
 c.addListener('error',
 	       function(e) {
 		   sys.puts(e);
 		   process.exit(1);
 	       });
-c.addListener('end',
-	       function() {
-		   /* node.js will exit by itself */
-	       });
diff --git a/lib/xmpp/client.js b/lib/xmpp/client.js
index 2764358..bf2cf69 100644
--- a/lib/xmpp/client.js
+++ b/lib/xmpp/client.js
@@ -95,8 +95,7 @@ Client.prototype.onRawStanza = function(stanza) {
 	    this.state = STATE_AUTHED;
 	    this.startStream();
 	} else {
-	    this.emit('authFail');
-	    this.end();
+	    this.emit('error', 'XMPP authentication failure');
 	}
     } else if (this.state == STATE_BIND &&
 	       stanza.is('iq', NS_CLIENT) &&
@@ -114,7 +113,6 @@ Client.prototype.onRawStanza = function(stanza) {
 	    this.useFeatures();
 	} else {
 	    this.emit('error', 'Cannot bind resource');
-	    this.end();
 	}
     } else if (this.state == STATE_SESSION &&
 	       stanza.is('iq', NS_CLIENT) &&
@@ -128,11 +126,9 @@ Client.prototype.onRawStanza = function(stanza) {
 	    this.useFeatures();
 	} else {
 	    this.emit('error', 'Cannot bind resource');
-	    this.end();
 	}
     } else if (stanza.name == 'stream:error') {
 	this.emit('error', stanza);
-	this.end();
     } else if (this.state == STATE_ONLINE) {
 	this.emit('stanza', stanza);
     }
@@ -164,7 +160,6 @@ Client.prototype.useFeatures = function() {
 				      }).t(authMsg));
 	} else {
 	    this.emit('error', 'No usable SASL mechanism');
-	    this.end();
 	}
     } else if (this.state == STATE_AUTHED &&
 	       !this.did_bind &&
diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index 2766438..74ca92b 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -18,7 +18,7 @@ function Connection() {
     this.addListener('connect', this.startStream);
     this.addListener('data', this.onData);
 //    this.addListener('end', this.onEnd);
-//    this.addListener('error', this.onError);
+    this.addListener('error', this.onError);
 }
 
 sys.inherits(Connection, net.Stream);
@@ -109,7 +109,7 @@ Connection.prototype.startStream = function() {
 Connection.prototype.onData = function(data) {
     if (this.parser) {
 	if (!this.parser.parse(data, false)) {
-	    this.emit('parseError');
+	    this.emit('error', 'XMPP parse error');
 	    this.end();
 	}
     }
@@ -162,3 +162,10 @@ Connection.prototype.rmStreamNs = function(stanza) {
     return stanza;
 };
 
+
+/**
+ * All errors are terminal for the connection.
+ */
+Connection.prototype.onError = function(error) {
+    this.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