[Pkg-javascript-commits] [ltx] 123/469: connection & client fixes
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:01:12 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 1d0902035c61ccb770b79b0e4bc6757a0050404e
Author: Astro <astro at spaceboyz.net>
Date: Thu Sep 9 05:10:29 2010 +0200
connection & client fixes
---
lib/xmpp/client.js | 1 +
lib/xmpp/connection.js | 16 +++++++++-------
lib/xmpp/stream_parser.js | 5 +++--
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/lib/xmpp/client.js b/lib/xmpp/client.js
index 9b695a3..b46de89 100644
--- a/lib/xmpp/client.js
+++ b/lib/xmpp/client.js
@@ -99,6 +99,7 @@ Client.prototype.onRawStanza = function(stanza) {
} else if (stanza.is('success', NS_XMPP_SASL)) {
this.mech = null;
this.state = STATE_AUTHED;
+ this.stopParser();
this.startStream();
} else {
this.emit('error', 'XMPP authentication failure');
diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index f47d123..73afdf4 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -6,6 +6,7 @@ var StreamParser = require('./stream_parser');
var NS_XMPP_TLS = exports.NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls';
var NS_STREAM = exports.NS_STREAM = 'http://etherx.jabber.org/streams';
+var NS_XMPP_STREAMS = 'urn:ietf:params:xml:ns:xmpp-streams';
/** A note on events: this base class will emit 'rawStanza' and leaves
'stanza' to Client & Component. Therefore we won't confuse the
@@ -26,7 +27,7 @@ function Connection(socket) {
});
var proxyEvent = function(event) {
self.socket.addListener(event, function() {
- self.emit.apply(self, Array.prototype.slice.call(arguments, 0, 0, event));
+ self.emit.apply(self, Array.prototype.splice.call(arguments, 0, 0, event));
});
};
proxyEvent('data'); // let them sniff
@@ -53,7 +54,6 @@ Connection.prototype.send = function(stanza) {
if (stanza.root) {
var el = this.rmStreamNs(stanza.root());
-console.log({send:el.toString()});
var socket = this.socket;
el.write(function(s) { socket.write(s); });
return el;
@@ -65,8 +65,11 @@ console.log({send:el.toString()});
};
Connection.prototype.startParser = function() {
+ if (this.parser)
+ return;
+
var self = this;
- this.parser = new StreamParser.StreamParser(this.charset);
+ this.parser = new StreamParser.StreamParser(this.charset, this.maxStanzaSize);
this.parser.addListener('start', function(attrs) {
self.streamAttrs = attrs;
@@ -106,11 +109,11 @@ Connection.prototype.onData = function(data) {
this.parser.write(data);
};
-Connection.prototype.setSecure = function() {
+Connection.prototype.setSecure = function(credentials) {
var self = this;
this.stopParser();
- this.socket.setSecure(this.credentials);
- this.addListener('secure', function() {
+ this.socket.setSecure(credentials || this.credentials);
+ this.socket.addListener('secure', function() {
self.startParser();
});
};
@@ -120,7 +123,6 @@ Connection.prototype.setSecure = function() {
* before 'rawStanza' events are emitted to the derived classes.
*/
Connection.prototype.onStanza = function(stanza) {
-console.log({onStanza:stanza.toString(),allowTLS:this.allowTLS,is:stanza.is('proceed', NS_XMPP_TLS)});
if (stanza.is('error', NS_STREAM)) {
/* TODO: extract error text */
this.emit('error', stanza);
diff --git a/lib/xmpp/stream_parser.js b/lib/xmpp/stream_parser.js
index d53de14..e1dc8dc 100644
--- a/lib/xmpp/stream_parser.js
+++ b/lib/xmpp/stream_parser.js
@@ -3,11 +3,12 @@ var EventEmitter = require('events').EventEmitter;
var expat = require('node-expat');
var xml = require('./xml');
-function StreamParser(charset) {
+function StreamParser(charset, maxStanzaSize) {
EventEmitter.call(this);
var self = this;
this.parser = new expat.Parser(charset);
+ this.maxStanzaSize = maxStanzaSize;
this.bytesParsedOnStanzaBegin = 0;
this.parser.addListener('startElement', function(name, attrs) {
@@ -77,7 +78,7 @@ StreamParser.prototype.end = function(data) {
};
StreamParser.prototype.error = function(condition, message) {
- var e = new Error(reason);
+ var e = new Error(message);
e.condition = condition;
this.emit('error', e);
};
--
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