[Pkg-javascript-commits] [ltx] 21/469: proper adding of <stream:stream> xmlns to each stanza
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:00:53 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 6fb6ffe1ba0057aa1c4da6eed8b22a8ea29d1829
Author: Astro <astro at spaceboyz.net>
Date: Sun May 30 22:53:26 2010 +0200
proper adding of <stream:stream> xmlns to each stanza
---
lib/xmpp/client.js | 8 +++---
lib/xmpp/connection.js | 68 ++++++++++++++++++++++++++++++--------------------
2 files changed, 45 insertions(+), 31 deletions(-)
diff --git a/lib/xmpp/client.js b/lib/xmpp/client.js
index 5c71c0b..1427001 100644
--- a/lib/xmpp/client.js
+++ b/lib/xmpp/client.js
@@ -133,7 +133,7 @@ Client.prototype.onRawStanza = function(stanza) {
*/
Connection.prototype.useFeatures = function() {
if (this.state == STATE_PREAUTH &&
- this.streamFeatures.getChild('mechanisms', NS_XMPP_SASL)) {
+ this.streamFeatures.getChild('mechanisms', NS_XMPP_SASL)) {
this.state = STATE_AUTH;
var mech = selectAuthMechanism(this.streamFeatures.
getChild('mechanisms', NS_XMPP_SASL).
@@ -185,9 +185,9 @@ Connection.prototype.useFeatures = function() {
function selectAuthMechanism(mechs) {
/*if (mechs.indexOf("DIGEST-MD5") >= 0)
- return "DIGEST-MD5";
+ return "DIGEST-MD5";
else*/ if (mechs.indexOf("PLAIN") >= 0)
- return new sasl.Mechanism("PLAIN");
+ return new sasl.Mechanism("PLAIN");
else
- return null;
+ return null;
}
diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index 05a732b..9aedbe4 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -3,14 +3,15 @@ var sys = require('sys');
var expat = require('expat');
var xml = require('./xml');
-var NS_XMPP_TLS = 'urn:ietf:params:xml:ns:xmpp-tls';
+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';
/** A note on events: this base class will emit 'rawStanza' and leaves
'stanza' to Client & Component. Therefore we won't confuse the
user with stanzas before authentication has finished.
*/
function Connection() {
-net.Stream.call(this);
+ net.Stream.call(this);
this.charset = 'UTF-8';
this.allowTLS = true; /* can be set by user */
@@ -24,22 +25,13 @@ sys.inherits(Connection, net.Stream);
exports.Connection = Connection;
Connection.prototype.send = function(stanza) {
- var self = this;
if (stanza.root) {
- var el = stanza.root();
- /* Remove superfluous xmlns that were aleady declared in
- <stream:stream> */
- for(var k in self.streamAttrs) {
- if ((k == 'xmlns' ||
- k.substr(0, 6) == 'xmlns:') &&
- el.attrs[k] == this.streamAttrs[k])
- el.attrs[k] = self.streamAttrs[k]
- }
-
+ var el = this.rmStreamNs(stanza.root());
+ var self = this;
el.write(function(s) { self.write(s); });
}
else
- self.write(stanza);
+ this.write(stanza);
};
Connection.prototype.startParser = function() {
@@ -50,19 +42,18 @@ Connection.prototype.startParser = function() {
self.parser.addListener('startElement', function(name, attrs) {
if (!self.element && name == 'stream:stream') {
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];
+ }
} else {
var child = new xml.Element(name, attrs);
if (!self.element) {
- /* Add stream xmlns, so the user can check for
- 'jabber:client' etc. */
- for(var k in self.streamAttrs) {
- if ((k == 'xmlns' ||
- k.substr(0, 6) == 'xmlns:') &&
- !child.attrs[k])
- child.attrs[k] = self.streamAttrs[k]
- }
/* A new stanza */
- self.element = child;
+ self.element = self.addStreamNs(child);
} else {
/* A child element of a stanza */
self.element = self.element.cnode(child);
@@ -95,7 +86,7 @@ Connection.prototype.startStream = function() {
this.startParser();
var tag = "<stream:stream xmlns='" + this.xmlns +
- "' xmlns:stream='http://etherx.jabber.org/streams'" +
+ "' xmlns:stream='" + NS_STREAM + "'" +
" to='" + this.streamTo + "'";
if (this.xmppVersion)
tag += " version='" + this.xmppVersion + "'";
@@ -120,9 +111,9 @@ Connection.prototype.onStanza = function(stanza) {
if (stanza.name == 'stream:error') {
/* TODO: extract error text */
this.emit('error', stanza);
- } else if (stanza.name == 'stream:features' &&
- this.allowTLS &&
- stanza.getChild('starttls', NS_XMPP_TLS)) {
+ } else if (stanza.is('stream: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 }));
} else if (this.allowTLS &&
@@ -135,4 +126,27 @@ Connection.prototype.onStanza = function(stanza) {
}
};
+/**
+ * Add stream xmlns to a stanza, so the user can check for
+ * 'jabber:client' etc.
+ */
+Connection.prototype.addStreamNs = function(stanza) {
+ for(var k in this.streamNsAttrs) {
+ if (!stanza.attrs[k])
+ stanza.attrs[k] = this.streamNsAttrs[k];
+ }
+ return stanza;
+};
+
+/**
+ * Remove superfluous xmlns that were aleady declared in
+ * <stream:stream>
+ */
+Connection.prototype.rmStreamNs = function(stanza) {
+ for(var k in this.streamNsAttrs) {
+ if (stanza.attrs[k] == this.streamNsAttrs[k])
+ delete stanza.attrs[k];
+ }
+ return stanza;
+};
--
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