Adds another pref for the "misc" api, makes base/misc url prefs default to auth.smc/{user,misc}/, fixes about:weave captcha path. r=Mardak

This commit is contained in:
Dan Mills 2009-08-26 15:01:28 -07:00
Родитель 6dce762690
Коммит 5e5d1b1243
3 изменённых файлов: 36 добавлений и 24 удалений

Просмотреть файл

@ -202,25 +202,21 @@ WeaveSvc.prototype = {
},
get baseURL() {
let url = Svc.Prefs.get("serverURL");
if (!url)
throw "No server URL set";
if (url[url.length-1] != '/')
url += '/';
return url;
return Utils.getURLPref("serverURL");
},
set baseURL(value) {
Svc.Prefs.set("serverURL", value);
},
get miscURL() {
return Utils.getURLPref("miscURL");
},
set miscURL(value) {
Svc.Prefs.set("miscURL", value);
},
get clusterURL() {
let url = Svc.Prefs.get("clusterURL");
if (!url)
return null;
if (url[url.length-1] != '/')
url += '/';
url += "0.5/";
return url;
return Utils.getURLPref("clusterURL", null, "0.5/");
},
set clusterURL(value) {
Svc.Prefs.set("clusterURL", value);
@ -461,7 +457,7 @@ WeaveSvc.prototype = {
findCluster: function WeaveSvc_findCluster(username) {
this._log.debug("Finding cluster for user " + username);
let res = new Resource(this.baseURL + "user/1/" + username + "/node/weave");
let res = new Resource(this.baseURL + "1/" + username + "/node/weave");
try {
res.get();
} catch(ex) {}
@ -470,11 +466,9 @@ WeaveSvc.prototype = {
switch (res.lastChannel.responseStatus) {
case 404:
this._log.debug("Using serverURL as data cluster (multi-cluster support disabled)");
return Svc.Prefs.get("serverURL");
return this.baseURL;
case 200:
// The server gives JSON of a string literal, but JS doesn't allow it
res.data = res.data.replace(/"/g, "");
return "https://" + res.data + "/";
return res.data;
default:
this._log.debug("Unexpected response code trying to find cluster: " + res.lastChannel.responseStatus);
break;
@ -604,8 +598,7 @@ WeaveSvc.prototype = {
changePassword: function WeaveSvc_changePassword(newpass)
this._catch(this._notify("changepwd", "", function() {
let url = Svc.Prefs.get('tmpServerURL') + 'user/1/' +
username + "/password";
let url = this.baseURL + '1/' + username + "/password";
let res = new Weave.Resource(url);
res.authenticator = new Weave.NoOpAuthenticator();
@ -770,7 +763,7 @@ WeaveSvc.prototype = {
},
checkUsername: function WeaveSvc_checkUsername(username) {
let url = Svc.Prefs.get('tmpServerURL') + "/user/1/" + username;
let url = this.baseURL + "1/" + username;
let res = new Resource(url);
res.authenticator = new NoOpAuthenticator();
@ -795,7 +788,7 @@ WeaveSvc.prototype = {
"captcha_response": captchaResponse
});
let url = Svc.Prefs.get('tmpServerURL') + 'user/1/' + username;
let url = this.baseURL + '1/' + username;
let res = new Resource(url);
res.authenticator = new Weave.NoOpAuthenticator();

Просмотреть файл

@ -488,6 +488,25 @@ let Utils = {
return url;
},
// ensures url ends with a slash, optionally adds an extra string at the end
slashify: function Weave_slashify(url, extra) {
if (url[url.length-1] != '/')
url += '/';
if (extra)
url += extra;
return url;
},
//
getURLPref: function Weave_getURLPref(pref, def, extra) {
let url = Svc.Prefs.get(pref);
if (!url && typeof(def) == "undefined")
throw pref + " not set";
else if (!url)
return def;
return Utils.slashify(url, extra);
},
xpath: function Weave_xpath(xmlDoc, xpathString) {
let root = xmlDoc.ownerDocument == null ?
xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement;

Просмотреть файл

@ -1,5 +1,5 @@
pref("extensions.weave.serverURL", "https://auth.services.mozilla.com/");
pref("extensions.weave.tmpServerURL", "https://services.mozilla.com/");
pref("extensions.weave.serverURL", "https://auth.services.mozilla.com/user/");
pref("extensions.weave.miscURL", "https://auth.services.mozilla.com/misc/");
pref("extensions.weave.encryption", "aes-256-cbc");