michael@0: // SJS file that receives violation reports and then responds with nothing. michael@0: michael@0: const CC = Components.Constructor; michael@0: const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", michael@0: "nsIBinaryInputStream", michael@0: "setInputStream"); michael@0: michael@0: const STATE_KEY = "bug836922_ro_violations"; michael@0: michael@0: function handleRequest(request, response) michael@0: { michael@0: var query = {}; michael@0: request.queryString.split('&').forEach(function (val) { michael@0: var [name, value] = val.split('='); michael@0: query[name] = unescape(value); michael@0: }); michael@0: michael@0: if ('results' in query) { michael@0: // if asked for the received data, send it. michael@0: response.setHeader("Content-Type", "text/javascript", false); michael@0: if (getState(STATE_KEY)) { michael@0: response.write(getState(STATE_KEY)); michael@0: } else { michael@0: // no state has been recorded. michael@0: response.write(JSON.stringify({})); michael@0: } michael@0: } else if ('reset' in query) { michael@0: //clear state michael@0: setState(STATE_KEY, JSON.stringify(null)); michael@0: } else { michael@0: // ... otherwise, just respond "ok". michael@0: response.write("null"); michael@0: michael@0: var bodystream = new BinaryInputStream(request.bodyInputStream); michael@0: var avail; michael@0: var bytes = []; michael@0: while ((avail = bodystream.available()) > 0) michael@0: Array.prototype.push.apply(bytes, bodystream.readByteArray(avail)); michael@0: michael@0: var data = String.fromCharCode.apply(null, bytes); michael@0: michael@0: // figure out which test was violating a policy michael@0: var testpat = new RegExp("testid=([a-z0-9_]+)"); michael@0: var testid = testpat.exec(data)[1]; michael@0: michael@0: // store the violation in the persistent state michael@0: var s = JSON.parse(getState(STATE_KEY) || "{}"); michael@0: s[testid] ? s[testid]++ : s[testid] = 1; michael@0: setState(STATE_KEY, JSON.stringify(s)); michael@0: } michael@0: } michael@0: michael@0: