Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Adding 'get_simple_rules_ending_with' message and functionality for Tor #18994

Merged
merged 3 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions chromium/background-scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
});
return true;
},
get_simple_rules_ending_with: () => {
return sendResponse(all_rules.getSimpleRulesEndingWith(message.object));
},
get_last_checked: () => {
store.local.get({'last-checked': false}, item => {
sendResponse(item['last-checked']);
Expand Down
30 changes: 30 additions & 0 deletions chromium/background-scripts/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,36 @@ RuleSets.prototype = {
return false;
},

/**
* Get a list of simple rules (active, with no exclusions) for all hosts that
* are in a single ruleset, and end in the specified ending.
* @param ending Target ending to search for
* @returns A list of { host, from_regex, to, scope_regex }
*/
getSimpleRulesEndingWith: function(ending) {
let results;

if (this.wasm_rs) {
results = this.wasm_rs.get_simple_rules_ending_with(ending);
} else {
results = [];
for(let [host, rulesets] of this.targets) {
if (host.endsWith(ending) &&
rulesets.length == 1 &&
rulesets[0].active === true &&
rulesets[0].exclusions == null
) {
for (let rule of rulesets[0].rules) {
if (rule.from_c.test("http://" + host + "/")) {
results.push({ host, from_regex: rule.from_c.toString(), to: rule.to, scope_regex: rulesets[0].scope.toString() });
Hainish marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
return results;
},

/**
* Rewrite an URI
* @param urispec The uri to rewrite
Expand Down