@@ -12,9 +12,11 @@ pub mod firewall {
1212 pub static GLOBAL_TRACKING_WEBSITES : OnceLock < & phf:: Set < & ' static str > > = OnceLock :: new ( ) ;
1313 /// Gambling websites list.
1414 pub static GLOBAL_GAMBLING_WEBSITES : OnceLock < & phf:: Set < & ' static str > > = OnceLock :: new ( ) ;
15+ /// Networking XHR|Fetch general list.
16+ pub static GLOBAL_NETWORKING_WEBSITES : OnceLock < & phf:: Set < & ' static str > > = OnceLock :: new ( ) ;
1517
1618 /// Defines a set of websites under a specified category. Available categories
17- /// include "ads", "tracking", "gambling", and a default category for any other strings.
19+ /// include "ads", "tracking", "gambling", "networking", and a default category for any other strings.
1820 ///
1921 /// # Examples
2022 ///
@@ -28,6 +30,9 @@ pub mod firewall {
2830 /// define_firewall!("gambling", "example-gambling.com");
2931 /// assert!(is_gambling_website_url("example-gambling.com"));
3032 ///
33+ /// define_firewall!("networking", "a.ping.com");
34+ /// assert!(is_bad_networking_url("a.ping.com"));
35+ ///
3136 /// define_firewall!("unknown", "example-unknown.com");
3237 /// assert!(is_bad_website_url("example-unknown.com"));
3338 /// ```
@@ -59,6 +64,14 @@ pub mod firewall {
5964 . expect( "Initialization already set." ) ;
6065 }
6166 } ,
67+ "networking" => {
68+ if $crate:: firewall:: GLOBAL_NETWORKING_WEBSITES . get( ) . is_none( ) {
69+ static WEBSITES : phf:: Set <& str > = phf:: phf_set! { $( $site) ,* } ;
70+ $crate:: firewall:: GLOBAL_NETWORKING_WEBSITES
71+ . set( & WEBSITES )
72+ . expect( "Initialization already set." ) ;
73+ }
74+ } ,
6275 _ => {
6376 if $crate:: firewall:: GLOBAL_BAD_WEBSITES . get( ) . is_none( ) {
6477 static WEBSITES : phf:: Set <& str > = phf:: phf_set! { $( $site) ,* } ;
@@ -104,6 +117,13 @@ pub fn is_gambling_website_url(host: &str) -> bool {
104117 || is_website_in_custom_set ( & host, & firewall:: GLOBAL_GAMBLING_WEBSITES )
105118}
106119
120+ // General networking blocking. At the moment you have to build this list yourself with the macro define_firewall!("networking", "a.ping.com").
121+ pub fn is_networking_url ( host : & str ) -> bool {
122+ BAD_WEBSITES . contains ( & host)
123+ || is_website_in_custom_set ( & host, & firewall:: GLOBAL_BAD_WEBSITES )
124+ || is_website_in_custom_set ( & host, & firewall:: GLOBAL_NETWORKING_WEBSITES )
125+ }
126+
107127/// Is the website in one of the custom sets.
108128fn is_website_in_custom_set (
109129 host : & str ,
@@ -119,8 +139,7 @@ fn is_website_in_custom_set(
119139/// The URL is in the bad list removing the URL http(s):// and paths.
120140pub fn is_bad_website_url_clean ( host : & str ) -> bool {
121141 if let Some ( host) = get_host_from_url ( host) {
122- BAD_WEBSITES . contains ( & host)
123- || is_website_in_custom_set ( host, & firewall:: GLOBAL_BAD_WEBSITES )
142+ is_bad_website_url ( & host)
124143 } else {
125144 false
126145 }
@@ -129,8 +148,7 @@ pub fn is_bad_website_url_clean(host: &str) -> bool {
129148/// The URL is in the ads list.
130149pub fn is_ad_website_url_clean ( host : & str ) -> bool {
131150 if let Some ( host) = get_host_from_url ( host) {
132- ADS_WEBSITES . contains ( & host)
133- || is_website_in_custom_set ( host, & firewall:: GLOBAL_ADS_WEBSITES )
151+ is_ads_website_url ( & host)
134152 } else {
135153 false
136154 }
@@ -139,8 +157,16 @@ pub fn is_ad_website_url_clean(host: &str) -> bool {
139157/// The URL is in the tracking list.
140158pub fn is_tracking_website_url_clean ( host : & str ) -> bool {
141159 if let Some ( host) = get_host_from_url ( host) {
142- TRACKING_WEBSITES . contains ( & host)
143- || is_website_in_custom_set ( & host, & firewall:: GLOBAL_TRACKING_WEBSITES )
160+ is_tracking_website_url ( & host)
161+ } else {
162+ false
163+ }
164+ }
165+
166+ /// The URL is in the networking list.
167+ pub fn is_networking_website_url_clean ( host : & str ) -> bool {
168+ if let Some ( host) = get_host_from_url ( host) {
169+ is_networking_url ( & host)
144170 } else {
145171 false
146172 }
@@ -149,8 +175,7 @@ pub fn is_tracking_website_url_clean(host: &str) -> bool {
149175/// The URL is in the gambling list.
150176pub fn is_gambling_website_url_clean ( host : & str ) -> bool {
151177 if let Some ( host) = get_host_from_url ( host) {
152- GAMBLING_WEBSITES . contains ( & host)
153- || is_website_in_custom_set ( & host, & firewall:: GLOBAL_GAMBLING_WEBSITES )
178+ is_gambling_website_url ( & host)
154179 } else {
155180 false
156181 }
0 commit comments