aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib
diff options
context:
space:
mode:
Diffstat (limited to 'data/lib')
-rw-r--r--data/lib/bzpage.js6
-rw-r--r--data/lib/collectingMetadata.js4
-rw-r--r--data/lib/rpcutils.js63
3 files changed, 68 insertions, 5 deletions
diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js
index 4401792..d4c393f 100644
--- a/data/lib/bzpage.js
+++ b/data/lib/bzpage.js
@@ -36,7 +36,7 @@ self.on('message', function onMessage(msg) {
equivalentComponents = ("equivalentComponents" in constantData) ?
constantData.equivalentComponents : null;
generateButtons(msg.data.instPkgs, msg.data.kNodes);
- completeInit();
+ JSONRPCLogin(completeInit);
break;
case "Error":
alert("Error " + msg.data);
@@ -44,8 +44,8 @@ self.on('message', function onMessage(msg) {
case "Unhandled":
break;
default:
- if (TweakOnMessageHandler) {
- TweakOnMessageHandler(msg, [RHOnMessageHandler, MozOnMessageHandler]);
+ if (RHOnMessageHandler) {
+ RHOnMessageHandler(msg, [MozOnMessageHandler]);
}
else {
console.error("Error: unknown RPC call " + msg.toSource());
diff --git a/data/lib/collectingMetadata.js b/data/lib/collectingMetadata.js
index 743c812..00b973d 100644
--- a/data/lib/collectingMetadata.js
+++ b/data/lib/collectingMetadata.js
@@ -170,11 +170,11 @@ AttachList.prototype.markBadAttachments = function markBadAttachments() {
createDeadLink("fixAllButton", "Fix all", titleElement, function () {
Array.forEach(badAttachments, function (x) {
- fixAttachById(x.id, constantData.XMLRPCData[window.location.hostname].url);
+ fixAttachById(x.id);
});
}, [], false, null, "f");
badAttachments.forEach(function (x, i, a) {
- addTextLink(x, constantData.XMLRPCData[window.location.hostname].url);
+ addTextLink(x);
});
}
};
diff --git a/data/lib/rpcutils.js b/data/lib/rpcutils.js
new file mode 100644
index 0000000..d29fd68
--- /dev/null
+++ b/data/lib/rpcutils.js
@@ -0,0 +1,63 @@
+//Released under the MIT/X11 license
+//http://www.opensource.org/licenses/mit-license.php
+"use strict";
+
+/*
+We should first login and then we shouldn't bother with it.
+It could be interesting to know how many logins per second are bad.
+ */
+
+function JSONRPCLogin(callback) {
+ if (!constantData.passwordState.password) {
+ return;
+ }
+
+ console.myDebug("JSONRPCLogin: passObj = " +
+ constantData.passwordState.toSource());
+ makeJSONRPCCall("User.login", {
+ login: getLogin(),
+ password: constantData.passwordState.password,
+ remember: false
+ }, function(logResult) {
+ callback();
+ });
+};
+
+
+// Make a JSONL-RPC call ... most of the business logic should stay in the
+// content script
+// http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
+function makeJSONRPCCall(method, params, callback) {
+
+ var msg = {
+ "version": "1.1",
+ "method": method,
+ "params": params
+ };
+
+ console.myDebug("makeJSONRPCCall(" + method +
+ "): out = " + JSON.stringify(msg));
+
+ var req = new XMLHttpRequest();
+ req.open('POST', "/jsonrpc.cgi", true);
+ req.onreadystatechange = function (aEvt) {
+ if (req.readyState == 4) {
+ if(req.status == 200) {
+ console.myDebug("makeJSONRPCCall (" + method +
+ "): in = " + req.responseText);
+ var JSONresponse = JSON.parse(req.responseText);
+ if ("error" in JSONresponse) {
+ throw new Error("Error in JSON-RPC call:\n" +
+ JSONresponse.error);
+ }
+ callback(JSONresponse);
+ }
+ else {
+ console.error('Error', req.statusText);
+ }
+ }
+ };
+ req.setRequestHeader('Content-Type', "application/json");
+ req.send(JSON.stringify(msg));
+};
+