Skip to content

Commit

Permalink
client: use new Buffer base64 functionality in Node v0.1.102
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jul 27, 2010
1 parent 092076d commit 7b0c711
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/xmpp/client.js
Expand Up @@ -4,7 +4,7 @@ var xml = require('./xml');
var sasl = require('./sasl');
var sys = require('sys');
var dns = require('dns');
var b64 = require('base64');
var Buffer = require('buffer').Buffer;

var NS_CLIENT = 'jabber:client';
var NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl';
Expand Down Expand Up @@ -84,9 +84,9 @@ Client.prototype.onRawStanza = function(stanza) {
this.useFeatures();
} else if (this.state == STATE_AUTH) {
if (stanza.is('challenge', NS_XMPP_SASL)) {
var challengeMsg = b64.decode(stanza.getText());
var challengeMsg = decode64(stanza.getText());
sys.puts("challengeMsg: " + challengeMsg);
var responseMsg = b64.encode(
var responseMsg = encode64(
this.mech.challenge(challengeMsg));
this.send(new xml.Element('response',
{ xmlns: NS_XMPP_SASL
Expand Down Expand Up @@ -158,7 +158,7 @@ Client.prototype.useFeatures = function() {
this.mech.password = this.password;
this.mech.realm = this.jid.domain; // anything?
this.mech.digest_uri = "xmpp/" + this.jid.domain;
var authMsg = b64.encode(this.mech.auth());
var authMsg = encode64(this.mech.auth());
this.send(new xml.Element('auth',
{ xmlns: NS_XMPP_SASL,
mechanism: this.mech.name
Expand Down Expand Up @@ -199,3 +199,9 @@ Client.prototype.useFeatures = function() {
}
};

function decode64(encoded) {
return (new Buffer(encoded, 'base64')).toString('utf8');
}
function encode64(decoded) {
return (new Buffer(decoded, 'utf8')).toString('base64');
}

0 comments on commit 7b0c711

Please sign in to comment.