make login more robust, specially work around first-login oddities with services.m.c
make login more robust, specially work around first-login oddities with services.m.c
--- a/services/sync/modules/dav.js
+++ b/services/sync/modules/dav.js
@@ -259,25 +259,26 @@ DAVCollection.prototype = {
headers.__proto__ = this._defaultHeaders;
this._makeRequest.async(this, self.cb, "PROPFIND", path, headers,
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<D:propfind xmlns:D='DAV:'><D:prop/></D:propfind>");
let resp = yield;
Utils.ensureStatus(resp.status, "propfind failed");
- // FIXME: shouldn't depend on the first one being the root
- let tokens = Utils.xpath(resp.responseXML, '//D:href');
- let ret = [],
- token,
- root = tokens.iterateNext();
- root = root.textContent;
-
- while (token = tokens.iterateNext())
- ret.push(token.textContent.replace(root, ''));
+ let ret = [];
+ try {
+ let tokens = Utils.xpath(resp.responseXML, '//D:href');
+ // FIXME: shouldn't depend on the first one being the root
+ let root = tokens.iterateNext();
+ root = root.textContent;
+ let token;
+ while (token = tokens.iterateNext())
+ ret.push(token.textContent.replace(root, ''));
+ } catch (e) {}
self.done(ret);
},
// Login / Logout
login: function DC_login(username, password) {
let self = yield;
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -122,25 +122,24 @@ WeaveSvc.prototype = {
get _histEngine() {
if (!this.__histEngine)
this.__histEngine = new HistoryEngine(DAV, this._cryptoId);
return this.__histEngine;
},
__cookieEngine: null,
get _cookieEngine() {
- // This gets an error that "CookieEngine" is undefined. Why?
- // BookmarksEngine and HistoryEngine are both defined in engines.js
- // and so is CookieEngine, but...
+ // This gets an error that "CookieEngine" is undefined. Why?
+ // BookmarksEngine and HistoryEngine are both defined in engines.js
+ // and so is CookieEngine, but...
if (!this.__cookieEngine)
this.__cookieEngine = new CookieEngine(DAV, this._cryptoId);
return this.__cookieEngine;
},
-
// Timer object for automagically syncing
_scheduleTimer: null,
__mozId: null,
get _mozId() {
if (this.__mozId === null)
this.__mozId = new Identity('Mozilla Services Password', this.username);
return this.__mozId;
@@ -320,23 +319,30 @@ WeaveSvc.prototype = {
let self = yield;
this._log.trace("Checking user directory exists");
let serverURL = Utils.prefs.getCharPref("serverURL");
if (serverURL[serverURL.length-1] != '/')
serverURL = serverURL + '/';
- DAV.baseURL = serverURL;
- DAV.MKCOL("user/" + this.userPath, self.cb);
- let ret = yield;
- if (!ret)
- throw "Could not create user directory";
+ try {
+ DAV.baseURL = serverURL;
+ DAV.MKCOL("user/" + this.userPath, self.cb);
+ let ret = yield;
+ if (!ret)
+ throw "Could not create user directory";
- DAV.baseURL = serverURL + "user/" + this.userPath + "/";
+ } catch (e) {
+ throw e;
+
+ } finally {
+ DAV.baseURL = serverURL + "user/" + this.userPath + "/";
+ }
+
this._log.info("Using server URL: " + DAV.baseURL);
},
_keyCheck: function WeaveSvc__keyCheck() {
let self = yield;
DAV.GET("private/privkey", self.cb);
let keyResp = yield;
@@ -415,27 +421,36 @@ WeaveSvc.prototype = {
this._log.debug("Logging in");
if (!this.username)
throw "No username set, login failed";
if (!this.password)
throw "No password given or found in password manager";
- this._checkUserDir.async(this, self.cb);
- yield;
+ let serverURL = Utils.prefs.getCharPref("serverURL");
+ if (serverURL[serverURL.length-1] != '/')
+ serverURL = serverURL + '/';
+ DAV.baseURL = serverURL + "user/" + this.userPath + "/";
DAV.login.async(DAV, self.cb, this.username, this.password);
let success = yield;
- if (!success)
- throw "Login failed";
+ if (!success) {
+ try {
+ this._checkUserDir.async(this, self.cb);
+ yield;
+ } catch (e) { /* FIXME: tmp workaround for services.m.c */ }
+ DAV.login.async(DAV, self.cb, this.username, this.password);
+ let success = yield;
+ if (!success)
+ throw "Login failed";
+ }
this._versionCheck.async(this, self.cb);
yield;
-
this._keyCheck.async(this, self.cb);
yield;
self.done(true);
},
logout: function WeaveSync_logout() {
this._log.info("Logging out");
@@ -502,18 +517,18 @@ WeaveSvc.prototype = {
yield;
}
if (Utils.prefs.getBoolPref("history")) {
this._notify(this._histEngine.name + ":sync",
this._syncEngine, this._histEngine).async(this, self.cb);
yield;
}
if (Utils.prefs.getBoolPref("cookies")) {
- this._notify(this._cookieEngine.name + ":sync",
- this._syncEngine, this._cookieEngine).async(this, self.cb);
+ this._notify(this._cookieEngine.name + ":sync",
+ this._syncEngine, this._cookieEngine).async(this, self.cb);
yield;
}
},
_syncEngine: function WeaveSvc__syncEngine(engine) {
let self = yield;
engine.sync(self.cb);
yield;
},