diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libbugzilla.js | 575 | ||||
-rw-r--r-- | lib/logger.js | 170 | ||||
-rw-r--r-- | lib/main.js | 228 | ||||
-rw-r--r-- | lib/prompts.js | 130 | ||||
-rw-r--r-- | lib/util.js | 60 | ||||
-rw-r--r-- | lib/xmlrpc.js | 231 |
6 files changed, 705 insertions, 689 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js index aeccead..45a1fc4 100644 --- a/lib/libbugzilla.js +++ b/lib/libbugzilla.js @@ -16,7 +16,7 @@ var xrpc = require("xmlrpc"); var panelMod = require("panel"); var JSONURLDefault = "https://fedorahosted.org/released"+ - "/bugzilla-triage-scripts/Config_data.json"; + "/bugzilla-triage-scripts/Config_data.json"; var BTSPrefNS = "bugzilla-triage.setting."; var BTSPassRealm = "BTSXMLRPCPass"; @@ -24,7 +24,7 @@ var passwords = {}; // hash of passwords indexed by a hostname var config = exports.config = {}; function Message(cmd, data) { - console.log("Message: cmd = " + cmd + ", data = " + data); + console.log("Message: cmd = " + cmd + ", data = " + data); this.cmd = cmd; this.data = data; } @@ -41,10 +41,10 @@ function log(msg) { * @return XML object */ function parseXMLfromString (inStuff) { - // if (typeof inStuff !== 'string') In future we should recognize this.response - // and get just .text property out of it. TODO - var respStr = inStuff.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551 - return new XML(respStr); + // if (typeof inStuff !== 'string') In future we should recognize this.response + // and get just .text property out of it. TODO + var respStr = inStuff.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551 + return new XML(respStr); } /** @@ -54,343 +54,346 @@ function parseXMLfromString (inStuff) { * This is a slow variant for bugs other than actual window */ function getRealBugNoSlow(bugNo, location, callback) { - console.log("We have to deal with bug aliased as " + this.bugNo); - // https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom - Request({ - url: location.href+"&ctype=xml", - onComplete: function(response) { - if (response.status === 200) { - var xmlRepr = parseXMLfromString(response.text); - // TODO this probably wrong, both XPath and .text attribute - var bugID = parseInt(xmlRepr.bug.bug_id.text, 10); - if (isNaN(bugID)) { - throw new Error("Cannot get bug no. even from XML representation!"); - } - console.log("The real bug no. is " + bugID); - callback(bugID) - } + console.log("We have to deal with bug aliased as " + this.bugNo); + // https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom + Request({ + url: location.href+"&ctype=xml", + onComplete: function(response) { + if (response.status === 200) { + var xmlRepr = parseXMLfromString(response.text); + // TODO this probably wrong, both XPath and .text attribute + var bugID = parseInt(xmlRepr.bug.bug_id.text, 10); + if (isNaN(bugID)) { + throw new Error("Cannot get bug no. even from XML representation!"); } - }).get(); + console.log("The real bug no. is " + bugID); + callback(bugID) + } + } + }).get(); } function getPassword(login, domain, callback) { - var passPrompt = "Enter your Bugzilla password for fixing MIME attachment types"; - var switchPrompt = "Do you want to switch off features requiring password completely"; - var prefName = BTSPrefNS+"withoutPassowrd"; - var retObject = { - password: null, // password string or null if no password provided - withoutPass: false // whether user doesn't want to use password at all - }; - - passUtils.search({ - username: login, - url: domain, - realm: BTSPassRealm, - onComplete: function onComplete([credential]) { - if (credential) { - // We found the password, just go ahead and use it - retObject.password = credential.password; - callback(retObject); - } else { - // We don't have a stored password, ask for one - var passwordText = prompts.promptPassword(passPrompt); - if (passwordText && passwordText.length > 0) { - // Right, we've got it … store it and then use it. - retObject.password = passwordText; - passUtils.store({ - username: login, - password: passwordText, - url: domain, - realm: BTSPassRealm, - onComplete: function onComplete() { - callback(retObject); - } - }); - } else { - // We don't have password, and user haven't entered one? - // Does he want to live passwordless? - // FIXME should we call the callback at all? - var switchOff = prompts.promptYesNoCancel(switchPrompt); - if (switchOff) { - preferences.set(prefName,true); - } - retObject.withoutPass = switchOff; - callback(retObject); - } + var passPrompt = "Enter your Bugzilla password for fixing MIME attachment types"; + var switchPrompt = "Do you want to switch off features requiring password completely"; + var prefName = BTSPrefNS+"withoutPassowrd"; + var retObject = { + password: null, // password string or null if no password provided + withoutPass: false // whether user doesn't want to use password at all + }; + + passUtils.search({ + username: login, + url: domain, + realm: BTSPassRealm, + onComplete: function onComplete([credential]) { + if (credential) { + // We found the password, just go ahead and use it + retObject.password = credential.password; + callback(retObject); + } + else { + // We don't have a stored password, ask for one + var passwordText = prompts.promptPassword(passPrompt); + if (passwordText && passwordText.length > 0) { + // Right, we've got it … store it and then use it. + retObject.password = passwordText; + passUtils.store({ + username: login, + password: passwordText, + url: domain, + realm: BTSPassRealm, + onComplete: function onComplete() { + callback(retObject); } + }); } - }); + else { + // We don't have password, and user haven't entered one? + // Does he want to live passwordless? + // FIXME should we call the callback at all? + var switchOff = prompts.promptYesNoCancel(switchPrompt); + if (switchOff) { + preferences.set(prefName,true); + } + retObject.withoutPass = switchOff; + callback(retObject); + } + } + } + }); } exports.changeJSONURL = function changeJSONURL() { - var prfNm = BTSPrefNS+"JSONURL"; - var url = preferences.get(prfNm,""); - - var reply = prompts.prompt("New location of JSON configuration file", url); - if (reply && (reply != url)) { - preferences.set(prfNm, reply.trim()); - // TODO Restartless add-on needs to resolve this. - prompts.alert("For now, you should really restart Firefox!"); - } + var prfNm = BTSPrefNS+"JSONURL"; + var url = preferences.get(prfNm,""); + + var reply = prompts.prompt("New location of JSON configuration file", url); + if (reply && (reply != url)) { + preferences.set(prfNm, reply.trim()); + // TODO Restartless add-on needs to resolve this. + prompts.alert("For now, you should really restart Firefox!"); + } }; /** * libbz.getInstalledPackages(msg.data, function (pkgsMsg) { - worker.postMessage(pkgsMsg); + worker.postMessage(pkgsMsg); locationLoginObj: { - location: window.location.href, - login: getLogin() - } + location: window.location.href, + login: getLogin() + } */ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, callback) { - var installedPackages = {}; - var enabledPackages = []; - var location = locationLoginObj.location; - - if (typeof location == "string") { - location = new urlMod.URL(location); + var installedPackages = {}; + var enabledPackages = []; + var location = locationLoginObj.location; + + if (typeof location == "string") { + location = new urlMod.URL(location); + } + + // Collect enabled packages per hostname (plus default ones) + if (config.gJSONData && ("commentPackages" in config.gJSONData)) { + if ("enabledPackages" in config.gJSONData.configData) { + var epObject = config.gJSONData.configData.enabledPackages; + if (location.host in epObject) { + enabledPackages = enabledPackages.concat(epObject[location.host].split(/[,\s]+/)); + } + if ("any" in epObject) { + enabledPackages = enabledPackages.concat(epObject.any.split(/[,\s]+/)); + } } - // Collect enabled packages per hostname (plus default ones) - if (config.gJSONData && ("commentPackages" in config.gJSONData)) { - if ("enabledPackages" in config.gJSONData.configData) { - var epObject = config.gJSONData.configData.enabledPackages; - if (location.host in epObject) { - enabledPackages = enabledPackages.concat(epObject[location.host].split(/[,\s]+/)); - } - if ("any" in epObject) { - enabledPackages = enabledPackages.concat(epObject.any.split(/[,\s]+/)); - } - } - - var allIdx = null; - if ((allIdx = enabledPackages.indexOf("all")) != -1) { - enabledPackages = enabledPackages.splice(allIdx, - config.gJSONData.commentPackages.keys()); - } - - // TODO To be decided, whether we cannot just eliminate packages in - // installedPackages and having it just as a plain list of all cmdObjects. - enabledPackages.forEach(function (pkg, idx, arr) { - if (pkg in config.gJSONData.commentPackages) { - installedPackages[pkg] = config.gJSONData.commentPackages[pkg]; - } - }); - } - - // Expand commentIdx properties into full comments - var cmdObj = {}; - for (var pkgKey in installedPackages) { - for (var cmdObjKey in installedPackages[pkgKey]) { - cmdObj = installedPackages[pkgKey][cmdObjKey]; - if ("commentIdx" in cmdObj) { - cmdObj.comment = config.gJSONData.commentStrings[cmdObj.commentIdx]; - delete cmdObj.commentIdx; - } - } + var allIdx = null; + if ((allIdx = enabledPackages.indexOf("all")) != -1) { + enabledPackages = enabledPackages.splice(allIdx, + config.gJSONData.commentPackages.keys()); } - if (config.gJSONData.commentStrings && - "sentUpstreamString" in config.gJSONData.commentStrings) { - config.constantData.commentStrings = {}; - config.constantData.commentStrings.sentUpstreamString = - config.gJSONData.commentStrings["sentUpstreamString"]; + // TODO To be decided, whether we cannot just eliminate packages in + // installedPackages and having it just as a plain list of all cmdObjects. + enabledPackages.forEach(function (pkg, idx, arr) { + if (pkg in config.gJSONData.commentPackages) { + installedPackages[pkg] = config.gJSONData.commentPackages[pkg]; + } + }); + } + + // Expand commentIdx properties into full comments + var cmdObj = {}; + for (var pkgKey in installedPackages) { + for (var cmdObjKey in installedPackages[pkgKey]) { + cmdObj = installedPackages[pkgKey][cmdObjKey]; + if ("commentIdx" in cmdObj) { + cmdObj.comment = config.gJSONData.commentStrings[cmdObj.commentIdx]; + delete cmdObj.commentIdx; + } } + } + + if (config.gJSONData.commentStrings && + "sentUpstreamString" in config.gJSONData.commentStrings) { + config.constantData.commentStrings = {}; + config.constantData.commentStrings.sentUpstreamString = + config.gJSONData.commentStrings["sentUpstreamString"]; + } + + var locURL = new urlMod.URL(locationLoginObj.location); + var passDomain = locURL.scheme + "://" + locURL.host; + getPassword(locationLoginObj.login, passDomain, function (passwObj) { + // In order to avoid sending whole password to the content script, + // we are sending just these two Booleans. + config.constantData.passwordState = { + passAvailable: (passwObj.password !== null), + withoutPass: passwObj.withoutPass + }; - var locURL = new urlMod.URL(locationLoginObj.location); - var passDomain = locURL.scheme + "://" + locURL.host; - getPassword(locationLoginObj.login, passDomain, function (passwObj) { - // In order to avoid sending whole password to the content script, - // we are sending just these two Booleans. - config.constantData.passwordState = { - passAvailable: (passwObj.password !== null), - withoutPass: passwObj.withoutPass - }; - - callback(new Message("CreateButtons", { - instPkgs: installedPackages, - constData: config.constantData, - config: config.configData, - kNodes: config.gJSONData.configData.killNodes - })); - }); + callback(new Message("CreateButtons", { + instPkgs: installedPackages, + constData: config.constantData, + config: config.configData, + kNodes: config.gJSONData.configData.killNodes + })); + }); }; exports.getClipboard = function getClipboard(cb) { - cb(clipboard.get()); + cb(clipboard.get()); }; exports.setClipboard = function setClipboard(stuff) { - clipboard.set(stuff, "text"); + clipboard.set(stuff, "text"); }; exports.getURL = function getURL(url, callback) { - Request({ - url: url, - onComplete: function(response) { - if (response.status == 200) { - callback(response.text); - } - } - }).get(); + Request({ + url: url, + onComplete: function(response) { + if (response.status == 200) { + callback(response.text); + } + } + }).get(); }; exports.openStringInNewPanel = function openStringInNewPanel(inHTMLStr) { - openURLInNewPanel("data:text/html;charset=utf-8," + - inHTMLStr); + openURLInNewPanel("data:text/html;charset=utf-8," + + inHTMLStr); }; var openURLInNewPanel = exports.openURLInNewPanel = function openURLInNewPanel(url) { - var panel = panelMod.Panel({ - contentURL: url, - width: 640, - height: 640 - }); - panel.show(); + var panel = panelMod.Panel({ + contentURL: url, + width: 640, + height: 640 + }); + panel.show(); }; var openURLInNewTab = exports.openURLInNewTab = function openURLInNewTab(url) { - tabs.open({ - url: url, - inBackground: true, - onReady: function(t) { - t.activate(); - } - }); + tabs.open({ + url: url, + inBackground: true, + onReady: function(t) { + t.activate(); + } + }); }; exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment) { - tabs.open({ - url: urlStr, - inBackground: true, - onReady: function (t) { - var otherElems = t.contentDocument.forms.namedItem("Create").elements; - // Summary - otherElems.namedItem("short_desc").value = subject; - // Comment - otherElems.namedItem("comment").value = collectComments(); - t.activate(); - } - }); + tabs.open({ + url: urlStr, + inBackground: true, + onReady: function (t) { + var otherElems = t.contentDocument.forms.namedItem("Create").elements; + // Summary + otherElems.namedItem("short_desc").value = subject; + // Comment + otherElems.namedItem("comment").value = collectComments(); + t.activate(); + } + }); }; // Make a XML-RPC call ... most of the business logic should stay in the content script exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) { - var urlObj = urlMod.URL(url); - getPassword(login, - urlObj.schema + "://" + urlObj.host, - function (passwObj) { - if (!passwObj.password) { - // TODO this should happen, only when user presses Escape in password prompt - return null; - } - - var msg = new xrpc.XMLRPCMessage(method); - params.forEach(function (par) { - msg.addParameter(par); - }); - msg.addParameter(login); - msg.addParameter(passwObj.password); - - Request({ - url: url, - onComplete: function(response) { - if (response.status == 200) { - var resp = parseXMLfromString(response.text); - callback(resp.toXMLString()); - } - }, - content: msg.xml(), - contentType: "text/xml" - }).post(); - } - ); + var urlObj = urlMod.URL(url); + getPassword(login, + urlObj.schema + "://" + urlObj.host, + function (passwObj) { + if (!passwObj.password) { + // TODO this should happen, only when user presses Escape in password prompt + return null; + } + + var msg = new xrpc.XMLRPCMessage(method); + params.forEach(function (par) { + msg.addParameter(par); + }); + msg.addParameter(login); + msg.addParameter(passwObj.password); + + Request({ + url: url, + onComplete: function(response) { + if (response.status == 200) { + var resp = parseXMLfromString(response.text); + callback(resp.toXMLString()); + } + }, + content: msg.xml(), + contentType: "text/xml" + }).post(); + } + ); }; exports.initialize = function initialize(config, callback) { - var prefName = BTSPrefNS+"JSONURL"; - var urlStr = ""; - - if (preferences.isSet(prefName)) { - urlStr = preferences.get(prefName); - } else { - urlStr = JSONURLDefault; - preferences.set(prefName, JSONURLDefault); - } - - // Randomize URL to avoid caching - // TODO see https://fedorahosted.org/bugzilla-triage-scripts/ticket/21 - // for more thorough discussion and possible further improvement - urlStr += (urlStr.match(/\?/) == null ? "?" : "&") + (new Date()).getTime(); - - Request({ - url: urlStr, - onComplete: function (response) { - if (response.status == 200) { - config.gJSONData = response.json; - - // Get additional tables - if ("downloadJSON" in config.gJSONData.configData) { - var URLsList = config.gJSONData.configData.downloadJSON; - var dwnldObj = ""; - URLsList.forEach(function (arr) { - var title = arr[0]; - var url = arr[1]; - Request({ - url: url, - onComplete: function(response) { - if (response.status == 200) { - config.constantData[title] = response.json; - } - } - }).get(); - }); + var prefName = BTSPrefNS+"JSONURL"; + var urlStr = ""; + + if (preferences.isSet(prefName)) { + urlStr = preferences.get(prefName); + } + else { + urlStr = JSONURLDefault; + preferences.set(prefName, JSONURLDefault); + } + + // Randomize URL to avoid caching + // TODO see https://fedorahosted.org/bugzilla-triage-scripts/ticket/21 + // for more thorough discussion and possible further improvement + urlStr += (urlStr.match(/\?/) == null ? "?" : "&") + (new Date()).getTime(); + + Request({ + url: urlStr, + onComplete: function (response) { + if (response.status == 200) { + config.gJSONData = response.json; + + // Get additional tables + if ("downloadJSON" in config.gJSONData.configData) { + var URLsList = config.gJSONData.configData.downloadJSON; + var dwnldObj = ""; + URLsList.forEach(function (arr) { + var title = arr[0]; + var url = arr[1]; + Request({ + url: url, + onComplete: function(response) { + if (response.status == 200) { + config.constantData[title] = response.json; } + } + }).get(); + }); + } - config.configData = {}; - config.configData.matches = config.gJSONData.configData.matches; - config.configData.skipMatches = config.configData.matches.map(function(x) { - return x.replace("show_bug.cgi.*","((process|post)_bug|attachment)\.cgi$"); - }); - - config.constantData = {}; - if ("constantData" in config.gJSONData) { - config.constantData = config.gJSONData.constantData; - config.constantData.queryUpstreamBug = JSON.parse( - selfMod.data.load("queryUpstreamBug.json")); - config.constantData.XMLRPCData = JSON.parse( - selfMod.data.load("XMLRPCdata.json")); - config.constantData.bugzillaLabelNames = - JSON.parse(selfMod.data.load("bugzillalabelNames.json")); - config.constantData.newUpstreamBug = - JSON.parse(selfMod.data.load("newUpstreamBug.json")); - config.constantData.ProfessionalProducts = - JSON.parse(selfMod.data.load("professionalProducts.json")); - } + config.configData = {}; + config.configData.matches = config.gJSONData.configData.matches; + config.configData.skipMatches = config.configData.matches.map(function(x) { + return x.replace("show_bug.cgi.*","((process|post)_bug|attachment)\.cgi$"); + }); - if ("CCmaintainer" in config.constantData) { - config.configData.defBugzillaMaintainerArr = config.constantData.CCmaintainer; - } + config.constantData = {}; + if ("constantData" in config.gJSONData) { + config.constantData = config.gJSONData.constantData; + config.constantData.queryUpstreamBug = JSON.parse( + selfMod.data.load("queryUpstreamBug.json")); + config.constantData.XMLRPCData = JSON.parse( + selfMod.data.load("XMLRPCdata.json")); + config.constantData.bugzillaLabelNames = + JSON.parse(selfMod.data.load("bugzillalabelNames.json")); + config.constantData.newUpstreamBug = + JSON.parse(selfMod.data.load("newUpstreamBug.json")); + config.constantData.ProfessionalProducts = + JSON.parse(selfMod.data.load("professionalProducts.json")); + } - if ("suspiciousComponents" in config.gJSONData.configData) { - config.configData.suspiciousComponents = - config.gJSONData.configData.suspiciousComponents; - } + if ("CCmaintainer" in config.constantData) { + config.configData.defBugzillaMaintainerArr = config.constantData.CCmaintainer; + } - if ("XorgLogAnalysis" in config.gJSONData.configData) { - config.configData.xorglogAnalysis = - config.gJSONData.configData.XorgLogAnalysis; - } + if ("suspiciousComponents" in config.gJSONData.configData) { + config.configData.suspiciousComponents = + config.gJSONData.configData.suspiciousComponents; + } - if ("submitsLogging" in config.gJSONData.configData && - config.gJSONData.configData.submitsLogging) { - logger.initialize(JSON.parse(selfMod.data.load( - "bugzillalabelAbbreviations.json"))); - } - } - callback(); + if ("XorgLogAnalysis" in config.gJSONData.configData) { + config.configData.xorglogAnalysis = + config.gJSONData.configData.XorgLogAnalysis; + } + + if ("submitsLogging" in config.gJSONData.configData && + config.gJSONData.configData.submitsLogging) { + logger.initialize(JSON.parse(selfMod.data.load( + "bugzillalabelAbbreviations.json"))); } - }).get(); + } + callback(); + } + }).get(); } diff --git a/lib/logger.js b/lib/logger.js index 07f42ba..4411a72 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,4 +1,5 @@ -// Released under the MIT/X11 license +/ +Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; var urlMod = require("url"); @@ -17,113 +18,118 @@ var FullLogsColor = "rgb(0, 40, 103)"; var abbsMap = {}; exports.initialize = function initialize(aMap) { - if (!myStorage.storage.logs) { - myStorage.storage.logs = {}; - } - abbsMap = aMap; + if (!myStorage.storage.logs) { + myStorage.storage.logs = {}; + } + abbsMap = aMap; }; exports.addLogRecord = function addLogRecord(rec) { - if (myStorage.storage.logs[rec.key]) { - myStorage.storage.logs[rec.key].comment += "<br/>\n" + comment; - } else { - myStorage.storage.logs[rec.key] = rec; - } + if (myStorage.storage.logs[rec.key]) { + myStorage.storage.logs[rec.key].comment += "<br/>\n" + comment; + } + else { + myStorage.storage.logs[rec.key] = rec; + } }; function storeSize() { - var size = 0, key; - for (key in myStorage.storage.logs) { - size++; - } - return size; + var size = 0, key; + for (key in myStorage.storage.logs) { + size++; + } + return size; } function isEmpty() { - return (storeSize() === 0); + return (storeSize() === 0); } exports.clearTimeSheet = function clearTimeSheet() { - myStorage.storage.logs = {}; - var size = storeSize(); + myStorage.storage.logs = {}; + var size = storeSize(); }; exports.importTimeSheet = function importTimeSheet() { - var filename = prompts.promptFileOpenPicker(); - if (fileMod.exists(filename)) { - var otherTS = JSON.parse(fileMod.read(filename)); - if (otherTS.logs) { - for (var rec in otherTS.logs) { - myStorage.storage.logs[rec] = otherTS.logs[rec]; - } - } else { - console.error("This is not a log file!"); - } - } else { - console.error("File " + filename + " doesn't exist!"); + var filename = prompts.promptFileOpenPicker(); + if (fileMod.exists(filename)) { + var otherTS = JSON.parse(fileMod.read(filename)); + if (otherTS.logs) { + for (var rec in otherTS.logs) { + myStorage.storage.logs[rec] = otherTS.logs[rec]; + } } + else { + console.error("This is not a log file!"); + } + } + else { + console.error("File " + filename + " doesn't exist!"); + } }; function getBugzillaAbbr(url) { - // for https://bugzilla.redhat.com/show_bug.cgi?id=579123 get RH - // for https://bugzilla.mozilla.org/show_bug.cgi?id=579123 get MoFo - return abbsMap[urlMod.URL(url).host]; + // for https://bugzilla.redhat.com/show_bug.cgi?id=579123 get RH + // for https://bugzilla.mozilla.org/show_bug.cgi?id=579123 get MoFo + return abbsMap[urlMod.URL(url).host]; } exports.generateTimeSheet = function generateTimeSheet() { - var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs); - libbz.openURLInNewTab("data:text/html;charset=utf-8," + docHTML); + var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs); + libbz.openURLInNewTab("data:text/html;charset=utf-8," + docHTML); }; function timeSheetRecordsPrinter(records) { - var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g"); - // sort the records into temporary array - var tmpArr = []; - var outStr = '<!DOCTYPE html>' + - "<html><head>\n"+ - "<meta charset='utf-8'/>\n"+ - "<title>Status report</title>\n</head>\n<body>\n" + - "<h1>TimeSheet</h1>\n"; + var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g"); + // sort the records into temporary array + var tmpArr = []; + var outStr = '<!DOCTYPE html>' + + "<html><head>\n"+ + "<meta charset='utf-8'/>\n"+ + "<title>Status report</title>\n</head>\n<body>\n" + + "<h1>TimeSheet</h1>\n"; - for (var i in records) { - if (records.hasOwnProperty(i)) { - tmpArr.push( [ i, records[i] ]); - } + for (var i in records) { + if (records.hasOwnProperty(i)) { + tmpArr.push( [ i, records[i] ]); + } + } + tmpArr.sort(function(a, b) { + if (a[0] > b[0]) { + return 1; + } + else if (a[0] < b[0]) { + return -1; + } + else { + return 0; } - tmpArr.sort(function(a, b) { - if (a[0] > b[0]) { - return 1; - } else if (a[0] < b[0]) { - return -1; - } else { - return 0; - } - }); + }); - var currentDay = ""; - // now print the array - tmpArr.forEach(function(rec) { - var x = rec[1]; - var dayStr = utilMod.getISODate(x.date); - var host = urlMod.URL(x.url).host; - var BZName = getBugzillaAbbr(x.url); - var bugNo = utilMod.getBugNo(x.url); - if (dayStr != currentDay) { - currentDay = dayStr; - outStr += "<hr/><p><strong>" + currentDay - + "</strong></p>\n"; - } - // replace "bug ####" with a hyperlink to the current bugzilla - var comment = x.comment.replace(commentBugRE, - "<a href='http://"+host+"/show_bug.cgi?id=$1'>$&</a>"); - outStr += "<p><em><a href='" - + x.url - + "'>Bug " - + BZName + "/" + bugNo + ": " - + x.title - + "</a>" - + " </em>\n<br/>" + comment + "</p>\n"; - }); - outStr += "</body></html>"; - return outStr; + var currentDay = ""; + // now print the array + tmpArr.forEach(function(rec) { + var x = rec[1]; + var dayStr = utilMod.getISODate(x.date); + var host = urlMod.URL(x.url).host; + var BZName = getBugzillaAbbr(x.url); + var bugNo = utilMod.getBugNo(x.url); + if (dayStr != currentDay) { + currentDay = dayStr; + outStr += "<hr/><p><strong>" + currentDay + + "</strong></p>\n"; + } + // replace "bug ####" with a hyperlink to the current bugzilla + var comment = x.comment.replace(commentBugRE, + "<a href='http://"+host+"/show_bug.cgi?id=$1'>$&</a>"); + outStr += "<p><em><a href='" + + x.url + + "'>Bug " + + BZName + "/" + bugNo + ": " + + x.title + + "</a>" + + " </em>\n<br/>" + comment + "</p>\n"; + }); + outStr += "</body></html>"; + return outStr; } diff --git a/lib/main.js b/lib/main.js index b553f6f..2e79e3a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -6,7 +6,7 @@ // http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/tip/bugzillatweaks // http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/ecfa0f028b81/bugzillatweaks/lib/main.js // http://hg.mozilla.org/users/avarma_mozilla.com/atul-packages/file/42ac1e99a107/packages\ -// /facebook-acquaintances/lib/main.js#l11 +// /facebook-acquaintances/lib/main.js#l11 // http://ehsanakhgari.org/blog/2010-05-31/my-experience-jetpack-sdk#comment-1253 // "use strict"; @@ -19,138 +19,138 @@ var logger = require("logger"); var Message = require("util").Message; function isOurPage(window, matchingURLs) { - var url = window.location.href; + var url = window.location.href; - // like ["regexp-url1", "regexp-url2"] - return matchingURLs.some(function (element,i,a) { - return new RegExp(element).test(url); - }); + // like ["regexp-url1", "regexp-url2"] + return matchingURLs.some(function (element,i,a) { + return new RegExp(element).test(url); + }); } /** * */ function skipThisPage(doc) { - var stemURL = "https://HOSTNAME/show_bug.cgi?id="; - var titleElems = doc.getElementsByTagName("title"); - var titleStr = titleElems[0].textContent; - var REArr = new RegExp("[bB]ug\\s+([0-9]+)").exec(titleStr); - var hostname = doc.location.hostname; - if (REArr) { - var bugNo = REArr[1]; - doc.location = stemURL.replace("HOSTNAME",hostname) + bugNo; - } + var stemURL = "https://HOSTNAME/show_bug.cgi?id="; + var titleElems = doc.getElementsByTagName("title"); + var titleStr = titleElems[0].textContent; + var REArr = new RegExp("[bB]ug\\s+([0-9]+)").exec(titleStr); + var hostname = doc.location.hostname; + if (REArr) { + var bugNo = REArr[1]; + doc.location = stemURL.replace("HOSTNAME",hostname) + bugNo; + } } var messageHandler = exports.messageHandler = function messageHandler(worker, msg) { - switch (msg.cmd) { - case "LogMessage": - console.log(msg.data); - break; - case "ExecCmd": - libbz.executeCommand(msg.data); - break; - case "AddLogRecord": - logger.addLogRecord(msg.data); - break; - case "GenerateTS": - logger.generateTimeSheet(); - break; - case "ClearTS": - logger.clearTimeSheet(); - break; - case "ImportTS": - logger.importTimeSheet(); - break; - case "GetInstalledPackages": - // send message with packages back - libbz.getInstalledPackages(msg.data, function (pkgsMsg) { - worker.postMessage(pkgsMsg); - }); - break; - case "GetClipboard": - libbz.getClipboard(function (clipboard) { - worker.postMessage(new Message(msg.data, clipboard)); - }); - break; - case "SetClipboard": - libbz.setClipboard(msg.data); - break; - case "ChangeJSONURL": - libbz.changeJSONURL(); - break; - case "OpenURLinPanel": - libbz.openURLInNewPanel(msg.data); - break; - case "OpenURLinTab": - libbz.openURLInNewTab(msg.data); - break; - case "OpenStringInPanel": - libbz.openStringInNewPanel(msg.data); - break; - case "MakeXMLRPCall": - // url, login, method, params, callback - libbz.makeXMLRPCCall(msg.data.url, msg.data.login, msg.data.method, - msg.data.params, function(ret) { - worker.postMessage(new Message(msg.data.callRPC, ret)); - }); - break; - case "GetURL": - libbz.getURL(msg.data.url, function(stuff) { - worker.postMessage(new Message(msg.data.backMessage, stuff)); - }); - break; - case "OpenBugUpstream": - libbz.createUpstreamBug(msg.data.url, msg.data.subject, msg.data.comment); - break; - case "testReady": - // we ignore it here, interesting only in unit test - break; - default: - console.error(msg.toSource()); - } + switch (msg.cmd) { + case "LogMessage": + console.log(msg.data); + break; + case "ExecCmd": + libbz.executeCommand(msg.data); + break; + case "AddLogRecord": + logger.addLogRecord(msg.data); + break; + case "GenerateTS": + logger.generateTimeSheet(); + break; + case "ClearTS": + logger.clearTimeSheet(); + break; + case "ImportTS": + logger.importTimeSheet(); + break; + case "GetInstalledPackages": + // send message with packages back + libbz.getInstalledPackages(msg.data, function (pkgsMsg) { + worker.postMessage(pkgsMsg); + }); + break; + case "GetClipboard": + libbz.getClipboard(function (clipboard) { + worker.postMessage(new Message(msg.data, clipboard)); + }); + break; + case "SetClipboard": + libbz.setClipboard(msg.data); + break; + case "ChangeJSONURL": + libbz.changeJSONURL(); + break; + case "OpenURLinPanel": + libbz.openURLInNewPanel(msg.data); + break; + case "OpenURLinTab": + libbz.openURLInNewTab(msg.data); + break; + case "OpenStringInPanel": + libbz.openStringInNewPanel(msg.data); + break; + case "MakeXMLRPCall": + // url, login, method, params, callback + libbz.makeXMLRPCCall(msg.data.url, msg.data.login, msg.data.method, + msg.data.params, function(ret) { + worker.postMessage(new Message(msg.data.callRPC, ret)); + }); + break; + case "GetURL": + libbz.getURL(msg.data.url, function(stuff) { + worker.postMessage(new Message(msg.data.backMessage, stuff)); + }); + break; + case "OpenBugUpstream": + libbz.createUpstreamBug(msg.data.url, msg.data.subject, msg.data.comment); + break; + case "testReady": + // we ignore it here, interesting only in unit test + break; + default: + console.error(msg.toSource()); + } }; var contentScriptLibraries = [ - self.data.url("lib/jumpNextBug.js"), - self.data.url("lib/util.js"), - self.data.url("lib/color.js"), - self.data.url("lib/logging-front.js"), - self.data.url("lib/rhbzpage.js"), - self.data.url("lib/bzpage.js") + self.data.url("lib/jumpNextBug.js"), + self.data.url("lib/util.js"), + self.data.url("lib/color.js"), + self.data.url("lib/logging-front.js"), + self.data.url("lib/rhbzpage.js"), + self.data.url("lib/bzpage.js") ]; libbz.initialize(libbz.config, function () { - pageMod.PageMod({ - include: [ - "https://bugzilla.redhat.com/show_bug.cgi?id=*", - "https://bugzilla.mozilla.org/show_bug.cgi?id=*", - "https://bugzilla.gnome.org/show_bug.cgi?id=*" - ], - contentScriptWhen: 'ready', - contentScriptFile: contentScriptLibraries, - onAttach: function onAttach(worker, msg) { - worker.on('message', function (msg) { - messageHandler(worker, msg); - }); - } - }); -}); - -pageMod.PageMod({ + pageMod.PageMod({ include: [ - "https://bugzilla.redhat.com/process_bug.cgi", - "https://bugzilla.redhat.com/post_bug.cgi", - "https://bugzilla.redhat.com/attachment.cgi", - "https://bugzilla.mozilla.org/process_bug.cgi", - "https://bugzilla.mozilla.org/post_bug.cgi", - "https://bugzilla.mozilla.org/attachment.cgi", - "https://bugzilla.gnome.org/process_bug.cgi", - "https://bugzilla.gnome.org/post_bug.cgi", - "https://bugzilla.gnome.org/attachment.cgi" + "https://bugzilla.redhat.com/show_bug.cgi?id=*", + "https://bugzilla.mozilla.org/show_bug.cgi?id=*", + "https://bugzilla.gnome.org/show_bug.cgi?id=*" ], contentScriptWhen: 'ready', - contentScriptFile: self.data.url("lib/skip-bug.js") + contentScriptFile: contentScriptLibraries, + onAttach: function onAttach(worker, msg) { + worker.on('message', function (msg) { + messageHandler(worker, msg); + }); + } + }); +}); + +pageMod.PageMod({ + include: [ + "https://bugzilla.redhat.com/process_bug.cgi", + "https://bugzilla.redhat.com/post_bug.cgi", + "https://bugzilla.redhat.com/attachment.cgi", + "https://bugzilla.mozilla.org/process_bug.cgi", + "https://bugzilla.mozilla.org/post_bug.cgi", + "https://bugzilla.mozilla.org/attachment.cgi", + "https://bugzilla.gnome.org/process_bug.cgi", + "https://bugzilla.gnome.org/post_bug.cgi", + "https://bugzilla.gnome.org/attachment.cgi" + ], + contentScriptWhen: 'ready', + contentScriptFile: self.data.url("lib/skip-bug.js") }); // tabs.open("https://bugzilla.redhat.com/show_bug.cgi?id=679515"); diff --git a/lib/prompts.js b/lib/prompts.js index ed9b3e5..7cfd3d1 100644 --- a/lib/prompts.js +++ b/lib/prompts.js @@ -15,9 +15,9 @@ var promptTitle = "Bugzilla Triage Script"; * @return none */ exports.alert = function alert(msg) { - var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Ci.nsIPromptService); - prompts.alert(null, promptTitle, msg); + var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Ci.nsIPromptService); + prompts.alert(null, promptTitle, msg); }; /** @@ -26,19 +26,20 @@ exports.alert = function alert(msg) { * @return String with the password */ exports.prompt = function prompt(prompt, defaultValue) { - var stringValue = { - value: defaultValue ? defaultValue : "" - }; + var stringValue = { + value: defaultValue ? defaultValue : "" + }; - var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Ci.nsIPromptService); - var result = prompts.prompt(null, promptTitle, prompt, - stringValue, null, {}); - if (result) { - return stringValue.value; - } else { - return null; - } + var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Ci.nsIPromptService); + var result = prompts.prompt(null, promptTitle, prompt, + stringValue, null, {}); + if (result) { + return stringValue.value; + } + else { + return null; + } }; /** @@ -47,27 +48,28 @@ exports.prompt = function prompt(prompt, defaultValue) { * @return String with the password */ exports.promptPassword = function promptPassword(prompt) { - if (!prompt) { // either undefined or null - prompt = "Enter password:"; - } - var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Ci.nsIPromptService); - var password = { - value : "" - }; // default the password to pass - var check = { - value : true - }; // default the checkbox to true - var result = prompts.promptPassword(null, "Bugzilla Triage Script", prompt, - password, null, check); - // result is true if OK was pressed, false if cancel was pressed. - // password.value is set if OK was pressed. - // The checkbox is not displayed. - if (result) { - return password.value ? password.value : null; - } else { - return null; - } + if (!prompt) { // either undefined or null + prompt = "Enter password:"; + } + var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Ci.nsIPromptService); + var password = { + value : "" + }; // default the password to pass + var check = { + value : true + }; // default the checkbox to true + var result = prompts.promptPassword(null, "Bugzilla Triage Script", prompt, + password, null, check); + // result is true if OK was pressed, false if cancel was pressed. + // password.value is set if OK was pressed. + // The checkbox is not displayed. + if (result) { + return password.value ? password.value : null; + } + else { + return null; + } }; /** @@ -75,21 +77,23 @@ exports.promptPassword = function promptPassword(prompt) { * https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService */ exports.promptYesNoCancel = function promptOKNoCancel(prompt) { - if (!prompt) { // either undefined or null - throw new Error("Prompt is required!"); - } - var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Ci.nsIPromptService); + if (!prompt) { // either undefined or null + throw new Error("Prompt is required!"); + } + var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Ci.nsIPromptService); - var result = prompts.confirmEx(null, "Bugzilla Triage Script", prompt, - prompts.STD_YES_NO_BUTTONS, null, null, null, null, {}); - if (result === 0) { - return true; - } else if (result === 1) { - return false; - } else { - return null; - } + var result = prompts.confirmEx(null, "Bugzilla Triage Script", prompt, + prompts.STD_YES_NO_BUTTONS, null, null, null, null, {}); + if (result === 0) { + return true; + } + else if (result === 1) { + return false; + } + else { + return null; + } }; /** @@ -97,18 +101,18 @@ exports.promptYesNoCancel = function promptOKNoCancel(prompt) { * documentation is https://developer.mozilla.org/en/NsIFilePicker */ exports.promptFileOpenPicker = function promptFilePicker (win) { - var window = require("window-utils").activeWindow; - var fp = Cc["@mozilla.org/filepicker;1"] - .createInstance(Ci.nsIFilePicker); - fp.init(window, "JSON File Open", Ci.nsIFilePicker.modeOpen); - fp.appendFilter("JSON files", "*.json"); - fp.appendFilters(Ci.nsIFilePicker.filterAll); - fp.filterIndex = 0; - var res = fp.show(); + var window = require("window-utils").activeWindow; + var fp = Cc["@mozilla.org/filepicker;1"] + .createInstance(Ci.nsIFilePicker); + fp.init(window, "JSON File Open", Ci.nsIFilePicker.modeOpen); + fp.appendFilter("JSON files", "*.json"); + fp.appendFilters(Ci.nsIFilePicker.filterAll); + fp.filterIndex = 0; + var res = fp.show(); - if (res === Ci.nsIFilePicker.returnOK || - res === Ci.nsIFilePicker.returnReplace ) { - return fp.file.path; - } - return null; + if (res === Ci.nsIFilePicker.returnOK || + res === Ci.nsIFilePicker.returnReplace ) { + return fp.file.path; + } + return null; }; diff --git a/lib/util.js b/lib/util.js index 089e31c..d28f001 100644 --- a/lib/util.js +++ b/lib/util.js @@ -12,26 +12,26 @@ var urlMod = require("url"); * get parameters of URL as an object (name, value) */ function getParamsFromURL (url, base) { - if (!url || (url.toString().length === 0)) { - throw new Error("Missing URL value!"); - } + if (!url || (url.toString().length === 0)) { + throw new Error("Missing URL value!"); + } - if (!(url instanceof urlMod.URL)) { - url = new urlMod.URL(url.toString(), base); - } + if (!(url instanceof urlMod.URL)) { + url = new urlMod.URL(url.toString(), base); + } - var paramsArr = url.path.split("?"); - if (paramsArr.length === 1) { - return {}; + var paramsArr = url.path.split("?"); + if (paramsArr.length === 1) { + return {}; } - // get convert URL parameters to an Object - var params = {}, s = []; - paramsArr[1].split('&').forEach(function(par) { - s = par.split('='); - params[s[0]] = s[1]; - }); - return params; + // get convert URL parameters to an Object + var params = {}, s = []; + paramsArr[1].split('&').forEach(function(par) { + s = par.split('='); + params[s[0]] = s[1]; + }); + return params; } /** @@ -43,10 +43,10 @@ function getParamsFromURL (url, base) { * @return String with the bug ID (hopefully number, but not for aliases) */ exports.getBugNo = function getBugNo(url) { - var params = getParamsFromURL(url); - if (params && params.id) { - return params.id; - } + var params = getParamsFromURL(url); + if (params && params.id) { + return params.id; + } }; /** @@ -56,20 +56,20 @@ exports.getBugNo = function getBugNo(url) { * @return string with the formatted date */ exports.getISODate = function getISODate(dateStr) { - function pad(n) { - return n < 10 ? '0' + n : n; - } - var date = new Date(dateStr); - return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + - pad(date.getDate()); + function pad(n) { + return n < 10 ? '0' + n : n; + } + var date = new Date(dateStr); + return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + + pad(date.getDate()); }; /** * object to pack messaging. Use as in - postMessage(new Message("GetPassword", { - login: login, - hostname: location.hostname - })); + postMessage(new Message("GetPassword", { + login: login, + hostname: location.hostname + })); */ exports.Message = function Message(cmd, data) { this.cmd = cmd; diff --git a/lib/xmlrpc.js b/lib/xmlrpc.js index 0b84c07..8b71f32 100644 --- a/lib/xmlrpc.js +++ b/lib/xmlrpc.js @@ -27,159 +27,162 @@ */ var XMLRPCMessage = exports.XMLRPCMessage = function XMLRPCMessage(methodname) { - this.method = methodname || "system.listMethods"; - this.params = []; - return this; + this.method = methodname || "system.listMethods"; + this.params = []; + return this; }; XMLRPCMessage.prototype.myIsArray = function myIsArray(obj) { - return (typeof obj.sort === 'function'); + return (typeof obj.sort === 'function'); }; XMLRPCMessage.prototype.setMethod = function (methodName) { - if (methodName !== undefined) { - this.method = methodName; - } + if (methodName !== undefined) { + this.method = methodName; + } }; XMLRPCMessage.prototype.addParameter = function (data) { - if (data !== undefined) { - this.params.push(data); - } + if (data !== undefined) { + this.params.push(data); + } }; XMLRPCMessage.prototype.xml = function () { - var method = this.method; + var method = this.method; - // assemble the XML message header - var xml = ""; + // assemble the XML message header + var xml = ""; - xml += "<?xml version=\"1.0\"?>\n"; - xml += "<methodCall>\n"; - xml += "<methodName>" + method + "</methodName>\n"; - xml += "<params>\n"; + xml += "<?xml version=\"1.0\"?>\n"; + xml += "<methodCall>\n"; + xml += "<methodName>" + method + "</methodName>\n"; + xml += "<params>\n"; - // do individual parameters - this.params.forEach(function (data) { - xml += "<param>\n"; - xml += "<value>" + - this.getParamXML(this.dataTypeOf(data), - data) + "</value>\n"; - xml += "</param>\n"; - }, this); - xml += "</params>\n"; - xml += "</methodCall>"; + // do individual parameters + this.params.forEach(function (data) { + xml += "<param>\n"; + xml += "<value>" + + this.getParamXML(this.dataTypeOf(data), + data) + "</value>\n"; + xml += "</param>\n"; + }, this); + xml += "</params>\n"; + xml += "</methodCall>"; - return xml; // for now + return xml; // for now }; XMLRPCMessage.prototype.dataTypeOf = function (o) { - // identifies the data type - var type = typeof (o); - type = type.toLowerCase(); - switch (type) { - case "number": - if (Math.round(o) === o) { - type = "i4"; - } else { - type = "double"; - } - break; - case "object": - if ((o instanceof Date)) { - type = "date"; - } else if (this.myIsArray(o)) { - type = "array"; - } else { - type = "struct"; - } - break; + // identifies the data type + var type = typeof (o); + type = type.toLowerCase(); + switch (type) { + case "number": + if (Math.round(o) === o) { + type = "i4"; + } + else { + type = "double"; + } + break; + case "object": + if ((o instanceof Date)) { + type = "date"; + } + else if (this.myIsArray(o)) { + type = "array"; + } + else { + type = "struct"; } - return type; + break; + } + return type; }; XMLRPCMessage.prototype.doValueXML = function (type, data) { - var xml = "<" + type + ">" + data + "</" + type + ">"; - return xml; + var xml = "<" + type + ">" + data + "</" + type + ">"; + return xml; }; XMLRPCMessage.prototype.doBooleanXML = function (data) { - var value = (data === true) ? 1 : 0; - var xml = "<boolean>" + value + "</boolean>"; - return xml; + var value = (data === true) ? 1 : 0; + var xml = "<boolean>" + value + "</boolean>"; + return xml; }; XMLRPCMessage.prototype.doDateXML = function (data) { - function leadingZero(n) { - // pads a single number with a leading zero. Heh. - if (n.length === 1) { - n = "0" + n; - } - return n; + function leadingZero(n) { + // pads a single number with a leading zero. Heh. + if (n.length === 1) { + n = "0" + n; } - function dateToISO8601(date) { - // wow I hate working with the Date object - var year = date.getYear(); - var month = this.leadingZero(date.getMonth()); - var day = this.leadingZero(date.getDate()); - var time = this.leadingZero(date.getHours()) + - ":" + this.leadingZero(date.getMinutes()) + - ":" + this.leadingZero(date.getSeconds()); - - var converted = year + month + day + "T" + time; - return converted; - } - - var xml = "<dateTime.iso8601>"; - xml += dateToISO8601(data); - xml += "</dateTime.iso8601>"; - return xml; + return n; + } + function dateToISO8601(date) { + // wow I hate working with the Date object + var year = date.getYear(); + var month = this.leadingZero(date.getMonth()); + var day = this.leadingZero(date.getDate()); + var time = this.leadingZero(date.getHours()) + + ":" + this.leadingZero(date.getMinutes()) + + ":" + this.leadingZero(date.getSeconds()); + + var converted = year + month + day + "T" + time; + return converted; + } + + var xml = "<dateTime.iso8601>"; + xml += dateToISO8601(data); + xml += "</dateTime.iso8601>"; + return xml; }; XMLRPCMessage.prototype.doArrayXML = function (data) { - var xml = "<array><data>\n"; - for (var i = 0; i < data.length; i++) { - xml += "<value>" + - this.getParamXML(this.dataTypeOf(data[i]), - data[i]) + "</value>\n"; - } - xml += "</data></array>\n"; - return xml; + var xml = "<array><data>\n"; + for (var i = 0; i < data.length; i++) { + xml += "<value>" + + this.getParamXML(this.dataTypeOf(data[i]), + data[i]) + "</value>\n"; + } + xml += "</data></array>\n"; + return xml; }; XMLRPCMessage.prototype.doStructXML = function (data) { - var xml = "<struct>\n"; - for (var i in data) { - xml += "<member>\n"; - xml += "<name>" + i + "</name>\n"; - xml += "<value>" + this.getParamXML(this.dataTypeOf(data[i]), - data[i]) + "</value>\n"; - xml += "</member>\n"; - } - xml += "</struct>\n"; - return xml; + var xml = "<struct>\n"; + for (var i in data) { + xml += "<member>\n"; + xml += "<name>" + i + "</name>\n"; + xml += "<value>" + this.getParamXML(this.dataTypeOf(data[i]), + data[i]) + "</value>\n"; + xml += "</member>\n"; + } + xml += "</struct>\n"; + return xml; }; XMLRPCMessage.prototype.getParamXML = function (type, data) { - var xml; - switch (type) { - case "date": - xml = this.doDateXML(data); - break; - case "array": - xml = this.doArrayXML(data); - break; - case "struct": - xml = this.doStructXML(data); - break; - case "boolean": - xml = this.doBooleanXML(data); - break; - default: - xml = this.doValueXML(type, data); - break; - } - return xml; + var xml; + switch (type) { + case "date": + xml = this.doDateXML(data); + break; + case "array": + xml = this.doArrayXML(data); + break; + case "struct": + xml = this.doStructXML(data); + break; + case "boolean": + xml = this.doBooleanXML(data); + break; + default: + xml = this.doValueXML(type, data); + break; + } + return xml; }; |