Permalink
Browse files

client: use new Buffer base64 functionality in Node v0.1.102

  • Loading branch information...
astro committed Jul 27, 2010
1 parent 092076d commit 7b0c711a85c88fa05bd5b7e9c0e019fd8702184d
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/xmpp/client.js
View
@@ -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';
@@ -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
@@ -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
@@ -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.