Skip to content

Commit 1a2b892

Browse files
committed
store procedural action filters in serialized format
1 parent 4dbfd7c commit 1a2b892

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/data_format/v0.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum LegacySpecificFilterType {
3030

3131
#[derive(Deserialize, Serialize, Default)]
3232
pub(crate) struct LegacyHostnameRuleDb {
33-
#[serde(serialize_with = "crate::data_format::utils::stabilize_hashmap_serialization")]
33+
#[serde(serialize_with = "stabilize_hashmap_serialization")]
3434
db: HashMap<Hash, Vec<LegacySpecificFilterType>>,
3535
}
3636

@@ -141,7 +141,7 @@ pub(crate) struct LegacyRedirectResource {
141141

142142
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
143143
pub(crate) struct LegacyRedirectResourceStorage {
144-
#[serde(serialize_with = "crate::data_format::utils::stabilize_hashmap_serialization")]
144+
#[serde(serialize_with = "stabilize_hashmap_serialization")]
145145
pub resources: HashMap<String, LegacyRedirectResource>,
146146
}
147147

@@ -152,7 +152,7 @@ pub(crate) struct LegacyScriptletResource {
152152

153153
#[derive(Default, Deserialize, Serialize)]
154154
pub(crate) struct LegacyScriptletResourceStorage {
155-
#[serde(serialize_with = "crate::data_format::utils::stabilize_hashmap_serialization")]
155+
#[serde(serialize_with = "stabilize_hashmap_serialization")]
156156
resources: HashMap<String, LegacyScriptletResource>,
157157
}
158158

@@ -216,7 +216,7 @@ where
216216
{
217217
#[derive(Serialize, Default)]
218218
struct NetworkFilterListV0SerializeFmt<'a> {
219-
#[serde(serialize_with = "crate::data_format::utils::stabilize_hashmap_serialization")]
219+
#[serde(serialize_with = "stabilize_hashmap_serialization")]
220220
filter_map: HashMap<crate::utils::Hash, Vec<NetworkFilterV0SerializeFmt<'a>>>,
221221
}
222222

@@ -283,6 +283,11 @@ pub(crate) struct SerializeFormat<'a> {
283283
misc_generic_selectors: &'a HashSet<String>,
284284

285285
scriptlets: LegacyScriptletResourceStorage,
286+
287+
#[serde(serialize_with = "stabilize_hashmap_serialization")]
288+
procedural_action: &'a HashMap<Hash, Vec<String>>,
289+
#[serde(serialize_with = "stabilize_hashmap_serialization")]
290+
procedural_action_exception: &'a HashMap<Hash, Vec<String>>,
286291
}
287292

288293
impl<'a> SerializeFormat<'a> {
@@ -382,6 +387,11 @@ pub(crate) struct DeserializeFormat {
382387
misc_generic_selectors: HashSet<String>,
383388

384389
_scriptlets: LegacyScriptletResourceStorage,
390+
391+
#[serde(default)]
392+
procedural_action: HashMap<Hash, Vec<String>>,
393+
#[serde(default)]
394+
procedural_action_exception: HashMap<Hash, Vec<String>>,
385395
}
386396

387397
impl DeserializeFormat {
@@ -422,12 +432,21 @@ impl<'a> From<(&'a Blocker, &'a CosmeticFilterCache)> for SerializeFormat<'a> {
422432
misc_generic_selectors: &cfc.misc_generic_selectors,
423433

424434
scriptlets: LegacyScriptletResourceStorage::default(),
435+
436+
procedural_action: &cfc.specific_rules.procedural_action.0,
437+
procedural_action_exception: &cfc.specific_rules.procedural_action_exception.0,
425438
}
426439
}
427440
}
428441

429442
impl From<DeserializeFormat> for (Blocker, CosmeticFilterCache) {
430443
fn from(v: DeserializeFormat) -> Self {
444+
use crate::cosmetic_filter_cache::HostnameFilterBin;
445+
446+
let mut specific_rules: HostnameRuleDb = v.specific_rules.into();
447+
specific_rules.procedural_action = HostnameFilterBin(v.procedural_action);
448+
specific_rules.procedural_action_exception = HostnameFilterBin(v.procedural_action_exception);
449+
431450
(
432451
Blocker {
433452
csp: v.csp.into(),
@@ -454,7 +473,7 @@ impl From<DeserializeFormat> for (Blocker, CosmeticFilterCache) {
454473
complex_class_rules: v.complex_class_rules,
455474
complex_id_rules: v.complex_id_rules,
456475

457-
specific_rules: v.specific_rules.into(),
476+
specific_rules,
458477

459478
misc_generic_selectors: v.misc_generic_selectors,
460479
},

0 commit comments

Comments
 (0)