1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::Message;
use glib::translate::*;
glib::wrapper! {
/// #SoupHSTSPolicy implements HTTP policies, as described by
/// [RFC 6797](http://tools.ietf.org/html/rfc6797).
///
/// @domain represents the host that this policy applies to. The domain
/// must be IDNA-canonicalized. `HSTSPolicy::new()` and related methods
/// will do this for you.
///
/// @max_age contains the 'max-age' value from the Strict Transport
/// Security header and indicates the time to live of this policy,
/// in seconds.
///
/// @expires will be non-[`None`] if the policy has been set by the host and
/// hence has an expiry time. If @expires is [`None`], it indicates that the
/// policy is a permanent session policy set by the user agent.
///
/// If @include_subdomains is [`true`], the Strict Transport Security policy
/// must also be enforced on subdomains of @domain.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HSTSPolicy(Boxed<ffi::SoupHSTSPolicy>);
match fn {
copy => |ptr| ffi::soup_hsts_policy_copy(mut_override(ptr)),
free => |ptr| ffi::soup_hsts_policy_free(ptr),
type_ => || ffi::soup_hsts_policy_get_type(),
}
}
impl HSTSPolicy {
/// Creates a new #SoupHSTSPolicy with the given attributes.
///
/// @domain is a domain on which the strict transport security policy
/// represented by this object must be enforced.
///
/// @max_age is used to set the "expires" attribute on the policy; pass
/// `SOUP_HSTS_POLICY_MAX_AGE_PAST` for an already-expired policy, or a
/// lifetime in seconds.
///
/// If @include_subdomains is [`true`], the strict transport security policy
/// must also be enforced on all subdomains of @domain.
/// ## `domain`
/// policy domain or hostname
/// ## `max_age`
/// max age of the policy
/// ## `include_subdomains`
/// [`true`] if the policy applies on subdomains
///
/// # Returns
///
/// a new #SoupHSTSPolicy.
#[doc(alias = "soup_hsts_policy_new")]
pub fn new(domain: &str, max_age: libc::c_ulong, include_subdomains: bool) -> HSTSPolicy {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_hsts_policy_new(
domain.to_glib_none().0,
max_age,
include_subdomains.into_glib(),
))
}
}
/// Parses @msg's first "Strict-Transport-Security" response header and
/// returns a #SoupHSTSPolicy.
/// ## `msg`
/// a #SoupMessage
///
/// # Returns
///
/// a new #SoupHSTSPolicy, or [`None`] if no valid
/// "Strict-Transport-Security" response header was found.
#[doc(alias = "soup_hsts_policy_new_from_response")]
#[doc(alias = "new_from_response")]
pub fn from_response(msg: &Message) -> Option<HSTSPolicy> {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::soup_hsts_policy_new_from_response(
msg.to_glib_none().0,
))
}
}
/// Full version of `HSTSPolicy::new()`, to use with an existing
/// expiration date.
///
/// See `HSTSPolicy::new()` for details.
/// ## `domain`
/// policy domain or hostname
/// ## `max_age`
/// max age of the policy
/// ## `expires`
/// the date of expiration of the policy or [`None`] for a permanent policy
/// ## `include_subdomains`
/// [`true`] if the policy applies on subdomains
///
/// # Returns
///
/// a new #SoupHSTSPolicy.
#[doc(alias = "soup_hsts_policy_new_full")]
pub fn new_full(
domain: &str,
max_age: libc::c_ulong,
expires: &glib::DateTime,
include_subdomains: bool,
) -> HSTSPolicy {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_hsts_policy_new_full(
domain.to_glib_none().0,
max_age,
expires.to_glib_none().0,
include_subdomains.into_glib(),
))
}
}
/// Creates a new session #SoupHSTSPolicy with the given attributes.
///
/// A session policy is a policy that is valid during the lifetime of
/// the [`HSTSEnforcer`][crate::HSTSEnforcer] it is added to. Contrary to regular policies,
/// it has no expiration date and is not stored in persistent
/// enforcers. These policies are useful for user-agent to load their
/// own or user-defined rules.
///
/// @domain is a domain on which the strict transport security policy
/// represented by this object must be enforced.
///
/// If @include_subdomains is [`true`], the strict transport security policy
/// must also be enforced on all subdomains of @domain.
/// ## `domain`
/// policy domain or hostname
/// ## `include_subdomains`
/// [`true`] if the policy applies on sub domains
///
/// # Returns
///
/// a new #SoupHSTSPolicy.
#[doc(alias = "soup_hsts_policy_new_session_policy")]
pub fn new_session_policy(domain: &str, include_subdomains: bool) -> HSTSPolicy {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::soup_hsts_policy_new_session_policy(
domain.to_glib_none().0,
include_subdomains.into_glib(),
))
}
}
/// Gets @self's domain.
///
/// # Returns
///
/// @self's domain.
#[doc(alias = "soup_hsts_policy_get_domain")]
#[doc(alias = "get_domain")]
pub fn domain(&mut self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::soup_hsts_policy_get_domain(self.to_glib_none_mut().0)) }
}
/// Returns the expiration date for @self.
///
/// # Returns
///
/// A #GDateTime or [`None`] if unset
#[doc(alias = "soup_hsts_policy_get_expires")]
#[doc(alias = "get_expires")]
pub fn expires(&mut self) -> Option<glib::DateTime> {
unsafe { from_glib_full(ffi::soup_hsts_policy_get_expires(self.to_glib_none_mut().0)) }
}
/// Returns the max age for @self.
///
/// # Returns
///
/// Max age in seconds
#[doc(alias = "soup_hsts_policy_get_max_age")]
#[doc(alias = "get_max_age")]
pub fn max_age(&mut self) -> libc::c_ulong {
unsafe { ffi::soup_hsts_policy_get_max_age(self.to_glib_none_mut().0) }
}
/// Gets whether @self include its subdomains.
///
/// # Returns
///
/// [`true`] if @self includes subdomains, [`false`] otherwise.
#[doc(alias = "soup_hsts_policy_includes_subdomains")]
pub fn includes_subdomains(&mut self) -> bool {
unsafe {
from_glib(ffi::soup_hsts_policy_includes_subdomains(
self.to_glib_none_mut().0,
))
}
}
/// Gets whether @self is expired.
///
/// Permanent policies never expire.
///
/// # Returns
///
/// [`true`] if @self is expired, [`false`] otherwise.
#[doc(alias = "soup_hsts_policy_is_expired")]
pub fn is_expired(&mut self) -> bool {
unsafe { from_glib(ffi::soup_hsts_policy_is_expired(self.to_glib_none_mut().0)) }
}
/// Gets whether @self is a non-permanent, non-expirable session policy.
///
/// See `HSTSPolicy::new_session_policy()` for details.
///
/// # Returns
///
/// [`true`] if @self is permanent, [`false`] otherwise
#[doc(alias = "soup_hsts_policy_is_session_policy")]
pub fn is_session_policy(&mut self) -> bool {
unsafe {
from_glib(ffi::soup_hsts_policy_is_session_policy(
self.to_glib_none_mut().0,
))
}
}
}