[libhttpseverywhere] context: enable ignoring rulesets
- From: Daniel Brendle <elbren src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhttpseverywhere] context: enable ignoring rulesets
- Date: Thu, 26 Jan 2017 21:24:42 +0000 (UTC)
commit 9efa7e967e3942f8ae36260f48dc20beb48dc26c
Author: grindhold <grindhold gmx net>
Date: Thu Jan 26 22:22:24 2017 +0100
context: enable ignoring rulesets
this commit introduces two new methods of Context that enable the
user to specify rulesets that are to be ignored. One method adds
a ruleset to the ignorelist (Context.ignore_ruleset) another method
removes it from the ignorelist again (Context.unignore_ruleset).
closes 776579
src/context.vala | 28 ++++++++++++++++++++++++++++
test/main.vala | 22 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/context.vala b/src/context.vala
index f1d1990..5274b7b 100644
--- a/src/context.vala
+++ b/src/context.vala
@@ -43,6 +43,9 @@ namespace HTTPSEverywhere {
private Gee.ArrayList<Target> cache;
private const int CACHE_SIZE = 100;
+ // List of RulesetIds that are to be ignored
+ private Gee.ArrayList<uint> ignore_list;
+
/**
* Indicates whether the library has been successfully
* initialized. Be careful: this property will become //false//
@@ -87,6 +90,8 @@ namespace HTTPSEverywhere {
rulesets = new Gee.HashMap<int, Ruleset>();
cache = new Gee.ArrayList<Target>();
+ ignore_list = new Gee.ArrayList<uint>();
+
var datapaths = new Gee.ArrayList<string>();
// Specify the paths to search for rules in
@@ -158,8 +163,12 @@ namespace HTTPSEverywhere {
foreach (Target target in this.cache) {
if (target.matches(url_copy)) {
foreach (uint ruleset_id in targets.get(target)) {
+ if (ruleset_id in this.ignore_list)
+ continue;
+
if (!rulesets.has_key(ruleset_id))
load_ruleset(ruleset_id);
+
rs = rulesets.get(ruleset_id);
}
break;
@@ -170,8 +179,12 @@ namespace HTTPSEverywhere {
foreach (Target target in targets.keys) {
if (target.matches(url_copy)) {
foreach (uint ruleset_id in targets.get(target)) {
+ if (ruleset_id in this.ignore_list)
+ continue;
+
if (!rulesets.has_key(ruleset_id))
load_ruleset(ruleset_id);
+
rs = rulesets.get(ruleset_id);
}
if (cache.size >= Context.CACHE_SIZE)
@@ -207,6 +220,21 @@ namespace HTTPSEverywhere {
}
/**
+ * Tells this context to ignore the ruleset with the given id
+ */
+ public void ignore_ruleset(uint id) {
+ this.ignore_list.add(id);
+ }
+
+ /**
+ * Tells this context to check for a previously ignored ruleset again
+ */
+ public void unignore_ruleset(uint id) {
+ if (id in this.ignore_list)
+ this.ignore_list.remove(id);
+ }
+
+ /**
* Loads all possible targets into memory
*/
private void load_targets() {
diff --git a/test/main.vala b/test/main.vala
index a06bb6e..74374a4 100644
--- a/test/main.vala
+++ b/test/main.vala
@@ -143,6 +143,28 @@ namespace HTTPSEverywhereTest {
url = "http://www.dl.ed.gov/";
assert (ruleset.rewrite(url) == "https://www.dl.ed.gov/");
});
+
+ Test.add_func("/httpseverywhere/context/ignore", () => {
+ var context = new Context();
+ var m = new MainLoop();
+ context.init.begin(null, (obj, res) => {
+ try {
+ context.init.end(res);
+ var result = context.rewrite("http://amnesty.org.pl");
+ assert(result.has_prefix("https://"));
+ context.ignore_ruleset(1009);
+ result = context.rewrite("http://amnesty.org.pl");
+ assert(result.has_prefix("http://"));
+ context.unignore_ruleset(1009);
+ result = context.rewrite("http://amnesty.org.pl");
+ assert(result.has_prefix("https://"));
+ m.quit();
+ } catch (Error e) {
+ GLib.assert_not_reached();
+ }
+ });
+ m.run();
+ });
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]