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

Commit 4183a20

Browse files
authored
Adding 'get_simple_rules_ending_with' message and functionality for Tor (#18994)
* Adding 'get_simple_rules_ending_with' message and functionality for Tor * Strict equality for checking whether the ruleset is active * Update lib-wasm
1 parent 08da693 commit 4183a20

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

chromium/background-scripts/background.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
884884
});
885885
return true;
886886
},
887+
get_simple_rules_ending_with: () => {
888+
return sendResponse(all_rules.getSimpleRulesEndingWith(message.object));
889+
},
887890
get_last_checked: () => {
888891
store.local.get({'last-checked': false}, item => {
889892
sendResponse(item['last-checked']);

chromium/background-scripts/rules.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,36 @@ RuleSets.prototype = {
722722
return false;
723723
},
724724

725+
/**
726+
* Get a list of simple rules (active, with no exclusions) for all hosts that
727+
* are in a single ruleset, and end in the specified ending.
728+
* @param ending Target ending to search for
729+
* @returns A list of { host, from_regex, to, scope_regex }
730+
*/
731+
getSimpleRulesEndingWith: function(ending) {
732+
let results;
733+
734+
if (this.wasm_rs) {
735+
results = this.wasm_rs.get_simple_rules_ending_with(ending);
736+
} else {
737+
results = [];
738+
for(let [host, rulesets] of this.targets) {
739+
if (host.endsWith(ending) &&
740+
rulesets.length == 1 &&
741+
rulesets[0].active === true &&
742+
rulesets[0].exclusions == null
743+
) {
744+
for (let rule of rulesets[0].rules) {
745+
if (rule.from_c.test("http://" + host + "/")) {
746+
results.push({ host, from_regex: rule.from_c.toString(), to: rule.to, scope_regex: rulesets[0].scope.toString() });
747+
}
748+
}
749+
}
750+
}
751+
}
752+
return results;
753+
},
754+
725755
/**
726756
* Rewrite an URI
727757
* @param urispec The uri to rewrite

0 commit comments

Comments
 (0)