soup/auto/
hsts_enforcer.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, HSTSPolicy, SessionFeature};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "SoupHSTSEnforcer")]
17    pub struct HSTSEnforcer(Object<ffi::SoupHSTSEnforcer, ffi::SoupHSTSEnforcerClass>) @implements SessionFeature;
18
19    match fn {
20        type_ => || ffi::soup_hsts_enforcer_get_type(),
21    }
22}
23
24impl HSTSEnforcer {
25    pub const NONE: Option<&'static HSTSEnforcer> = None;
26
27    #[doc(alias = "soup_hsts_enforcer_new")]
28    pub fn new() -> HSTSEnforcer {
29        assert_initialized_main_thread!();
30        unsafe { from_glib_full(ffi::soup_hsts_enforcer_new()) }
31    }
32}
33
34impl Default for HSTSEnforcer {
35    fn default() -> Self {
36        Self::new()
37    }
38}
39
40pub trait HSTSEnforcerExt: IsA<HSTSEnforcer> + 'static {
41    #[doc(alias = "soup_hsts_enforcer_get_domains")]
42    #[doc(alias = "get_domains")]
43    fn domains(&self, session_policies: bool) -> Vec<glib::GString> {
44        unsafe {
45            FromGlibPtrContainer::from_glib_full(ffi::soup_hsts_enforcer_get_domains(
46                self.as_ref().to_glib_none().0,
47                session_policies.into_glib(),
48            ))
49        }
50    }
51
52    #[doc(alias = "soup_hsts_enforcer_get_policies")]
53    #[doc(alias = "get_policies")]
54    fn policies(&self, session_policies: bool) -> Vec<HSTSPolicy> {
55        unsafe {
56            FromGlibPtrContainer::from_glib_full(ffi::soup_hsts_enforcer_get_policies(
57                self.as_ref().to_glib_none().0,
58                session_policies.into_glib(),
59            ))
60        }
61    }
62
63    #[doc(alias = "soup_hsts_enforcer_has_valid_policy")]
64    fn has_valid_policy(&self, domain: &str) -> bool {
65        unsafe {
66            from_glib(ffi::soup_hsts_enforcer_has_valid_policy(
67                self.as_ref().to_glib_none().0,
68                domain.to_glib_none().0,
69            ))
70        }
71    }
72
73    #[doc(alias = "soup_hsts_enforcer_is_persistent")]
74    fn is_persistent(&self) -> bool {
75        unsafe {
76            from_glib(ffi::soup_hsts_enforcer_is_persistent(
77                self.as_ref().to_glib_none().0,
78            ))
79        }
80    }
81
82    #[doc(alias = "soup_hsts_enforcer_set_policy")]
83    fn set_policy(&self, policy: &mut HSTSPolicy) {
84        unsafe {
85            ffi::soup_hsts_enforcer_set_policy(
86                self.as_ref().to_glib_none().0,
87                policy.to_glib_none_mut().0,
88            );
89        }
90    }
91
92    #[doc(alias = "soup_hsts_enforcer_set_session_policy")]
93    fn set_session_policy(&self, domain: &str, include_subdomains: bool) {
94        unsafe {
95            ffi::soup_hsts_enforcer_set_session_policy(
96                self.as_ref().to_glib_none().0,
97                domain.to_glib_none().0,
98                include_subdomains.into_glib(),
99            );
100        }
101    }
102
103    #[doc(alias = "changed")]
104    fn connect_changed<F: Fn(&Self, &HSTSPolicy, &HSTSPolicy) + 'static>(
105        &self,
106        f: F,
107    ) -> SignalHandlerId {
108        unsafe extern "C" fn changed_trampoline<
109            P: IsA<HSTSEnforcer>,
110            F: Fn(&P, &HSTSPolicy, &HSTSPolicy) + 'static,
111        >(
112            this: *mut ffi::SoupHSTSEnforcer,
113            old_policy: *mut ffi::SoupHSTSPolicy,
114            new_policy: *mut ffi::SoupHSTSPolicy,
115            f: glib::ffi::gpointer,
116        ) {
117            let f: &F = &*(f as *const F);
118            f(
119                HSTSEnforcer::from_glib_borrow(this).unsafe_cast_ref(),
120                &from_glib_borrow(old_policy),
121                &from_glib_borrow(new_policy),
122            )
123        }
124        unsafe {
125            let f: Box_<F> = Box_::new(f);
126            connect_raw(
127                self.as_ptr() as *mut _,
128                c"changed".as_ptr() as *const _,
129                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
130                    changed_trampoline::<Self, F> as *const (),
131                )),
132                Box_::into_raw(f),
133            )
134        }
135    }
136}
137
138impl<O: IsA<HSTSEnforcer>> HSTSEnforcerExt for O {}