Bug 1281782 - Convert gtalk auth mechanisms to generators. r=clokep
authorAbdelrhman Ahmed <ab@abahmed.com>
Thu, 23 Jun 2016 07:50:00 -0400
changeset 25307 feaa4f244243e9751507ef901cdcfc99e2f6705d
parent 25306 a0fd317f89e270a489353b862ccca75b6721dfb1
child 25308 e98bbf436ca834a774f6ce88e8aaeb11d35c3a18
push id1725
push userclokep@gmail.com
push dateMon, 19 Sep 2016 17:35:08 +0000
treeherdercomm-beta@6ead1abf3817 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1281782
Bug 1281782 - Convert gtalk auth mechanisms to generators. r=clokep
chat/protocols/gtalk/gtalk.js
--- a/chat/protocols/gtalk/gtalk.js
+++ b/chat/protocols/gtalk/gtalk.js
@@ -14,33 +14,31 @@ XPCOMUtils.defineLazyGetter(this, "_", (
   l10nHelper("chrome://chat/locale/xmpp.properties")
 );
 
 // PlainFullBindAuth is an authentication mechanism that works like
 // the standard PLAIN mechanism but adds a client-uses-full-bind-result
 // attribute to the auth stanza to tell the Google Talk servers that we
 // support their JID Domain Discovery extension.
 // See https://developers.google.com/talk/jep_extensions/jid_domain_change
-function PlainFullBindAuth(username, password, domain) {
-  this._key = btoa("\0"+ username + "\0" + password);
+function* PlainFullBindAuth(aUsername, aPassword, aDomain) {
+  let key = btoa("\0"+ aUsername + "\0" + aPassword);
+  let attrs = {
+    mechanism: "PLAIN",
+    "xmlns:ga": "http://www.google.com/talk/protocol/auth",
+    "ga:client-uses-full-bind-result": "true"
+  };
+  let stanza = yield {
+    send: Stanza.node("auth", Stanza.NS.sasl, attrs, key),
+    log: '<auth.../> (PlainFullBindAuth base64 encoded username and password not logged)'
+  };
+
+  if (stanza.localName != "success")
+    throw "Didn't receive the expected auth success stanza.";
 }
-PlainFullBindAuth.prototype = {
-  next: function(aStanza) {
-    let attrs = {
-      mechanism: "PLAIN",
-      "xmlns:ga": "http://www.google.com/talk/protocol/auth",
-      "ga:client-uses-full-bind-result": "true"
-    };
-    return {
-      done: true,
-      send: Stanza.node("auth", Stanza.NS.sasl, attrs, this._key),
-      log: '<auth.../> (PlainFullBindAuth base64 encoded username and password not logged)'
-    };
-  }
-};
 
 function GTalkAccount(aProtoInstance, aImAccount) {
   this._init(aProtoInstance, aImAccount);
 }
 GTalkAccount.prototype = {
   __proto__: XMPPAccountPrototype,
   connect: function() {
     this._jid = this._parseJID(this.name);