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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
// 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::ServerMessage;
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// Server-side authentication.
///
/// A #SoupAuthDomain manages authentication for all or part of a
/// [`Server`][crate::Server]. To make a server require authentication, first create
/// an appropriate subclass of #SoupAuthDomain, and then add it to the
/// server with [`ServerExt::add_auth_domain()`][crate::prelude::ServerExt::add_auth_domain()].
///
/// In order for an auth domain to have any effect, you must add one or more
/// paths to it (via [`AuthDomainExt::add_path()`][crate::prelude::AuthDomainExt::add_path()]). To require authentication for
/// all ordinary requests, add the path `"/"`. (Note that this does not include
/// the special `"*"` URI (eg, "OPTIONS *"), which must be added as a separate
/// path if you want to cover it.)
///
/// If you need greater control over which requests should and shouldn't be
/// authenticated, add paths covering everything you *might* want authenticated,
/// and then use a filter ([`AuthDomainExt::set_filter()`][crate::prelude::AuthDomainExt::set_filter()] to bypass
/// authentication for those requests that don't need it.
///
/// This is an Abstract Base Class, you cannot instantiate it.
///
/// ## Properties
///
///
/// #### `filter`
/// The `callback::AuthDomainFilter for the domain.
///
/// Readable | Writeable
///
///
/// #### `filter-data`
/// Data to pass to the `callback::AuthDomainFilter.
///
/// Readable | Writeable
///
///
/// #### `generic-auth-callback`
/// The `callback::AuthDomainGenericAuthCallback.
///
/// Readable | Writeable
///
///
/// #### `generic-auth-data`
/// The data to pass to the `callback::AuthDomainGenericAuthCallback.
///
/// Readable | Writeable
///
///
/// #### `proxy`
/// Whether or not this is a proxy auth domain.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `realm`
/// The realm of this auth domain.
///
/// Readable | Writeable | Construct Only
///
/// # Implements
///
/// [`AuthDomainExt`][trait@crate::prelude::AuthDomainExt], [`trait@glib::ObjectExt`]
#[doc(alias = "SoupAuthDomain")]
pub struct AuthDomain(Object<ffi::SoupAuthDomain, ffi::SoupAuthDomainClass>);
match fn {
type_ => || ffi::soup_auth_domain_get_type(),
}
}
impl AuthDomain {
pub const NONE: Option<&'static AuthDomain> = None;
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::AuthDomain>> Sealed for T {}
}
/// Trait containing all [`struct@AuthDomain`] methods.
///
/// # Implementors
///
/// [`AuthDomainBasic`][struct@crate::AuthDomainBasic], [`AuthDomainDigest`][struct@crate::AuthDomainDigest], [`AuthDomain`][struct@crate::AuthDomain]
pub trait AuthDomainExt: IsA<AuthDomain> + sealed::Sealed + 'static {
/// Checks if @msg contains appropriate authorization for @self to
/// accept it.
///
/// Mirroring [`covers()`][Self::covers()], this does not check whether or not
/// @self *cares* if @msg is authorized.
///
/// This is used by [`Server`][crate::Server] internally and is probably of no use to
/// anyone else.
/// ## `msg`
/// a #SoupServerMessage
///
/// # Returns
///
/// the username that @msg has authenticated
/// as, if in fact it has authenticated. [`None`] otherwise.
#[doc(alias = "soup_auth_domain_accepts")]
fn accepts(&self, msg: &ServerMessage) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::soup_auth_domain_accepts(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
))
}
}
/// Adds @path to @self.
///
/// Requests under @path on @self's server will require authentication (unless
/// overridden by [`remove_path()`][Self::remove_path()] or
/// [`set_filter()`][Self::set_filter()]).
/// ## `path`
/// the path to add to @self
#[doc(alias = "soup_auth_domain_add_path")]
fn add_path(&self, path: &str) {
unsafe {
ffi::soup_auth_domain_add_path(self.as_ref().to_glib_none().0, path.to_glib_none().0);
}
}
/// Adds a "WWW-Authenticate" or "Proxy-Authenticate" header to @msg.
///
/// It requests that the client authenticate, and sets @msg's status accordingly.
///
/// This is used by [`Server`][crate::Server] internally and is probably of no use to
/// anyone else.
/// ## `msg`
/// a #SoupServerMessage
#[doc(alias = "soup_auth_domain_challenge")]
fn challenge(&self, msg: &ServerMessage) {
unsafe {
ffi::soup_auth_domain_challenge(self.as_ref().to_glib_none().0, msg.to_glib_none().0);
}
}
/// Checks if @msg authenticates to @self via @username and
/// @password.
///
/// This would normally be called from a
/// `callback::AuthDomainGenericAuthCallback.
/// ## `msg`
/// a #SoupServerMessage
/// ## `username`
/// a username
/// ## `password`
/// a password
///
/// # Returns
///
/// whether or not the message is authenticated
#[doc(alias = "soup_auth_domain_check_password")]
fn check_password(&self, msg: &ServerMessage, username: &str, password: &str) -> bool {
unsafe {
from_glib(ffi::soup_auth_domain_check_password(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
username.to_glib_none().0,
password.to_glib_none().0,
))
}
}
/// Checks if @self requires @msg to be authenticated (according to
/// its paths and filter function).
///
/// This does not actually look at whether @msg *is* authenticated, merely
/// whether or not it needs to be.
///
/// This is used by [`Server`][crate::Server] internally and is probably of no use to
/// anyone else.
/// ## `msg`
/// a #SoupServerMessage
///
/// # Returns
///
/// [`true`] if @self requires @msg to be authenticated
#[doc(alias = "soup_auth_domain_covers")]
fn covers(&self, msg: &ServerMessage) -> bool {
unsafe {
from_glib(ffi::soup_auth_domain_covers(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
))
}
}
/// Gets the realm name associated with @self.
///
/// # Returns
///
/// @self's realm
#[doc(alias = "soup_auth_domain_get_realm")]
#[doc(alias = "get_realm")]
fn realm(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::soup_auth_domain_get_realm(
self.as_ref().to_glib_none().0,
))
}
}
/// Removes @path from @self.
///
/// Requests under @path on @self's server will NOT require
/// authentication.
///
/// This is not simply an undo-er for [`add_path()`][Self::add_path()]; it
/// can be used to "carve out" a subtree that does not require
/// authentication inside a hierarchy that does. Note also that unlike
/// with [`add_path()`][Self::add_path()], this cannot be overridden by
/// adding a filter, as filters can only bypass authentication that
/// would otherwise be required, not require it where it would
/// otherwise be unnecessary.
/// ## `path`
/// the path to remove from @self
#[doc(alias = "soup_auth_domain_remove_path")]
fn remove_path(&self, path: &str) {
unsafe {
ffi::soup_auth_domain_remove_path(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
);
}
}
/// Adds @filter as an authentication filter to @self.
///
/// The filter gets a chance to bypass authentication for certain requests that
/// would otherwise require it. Eg, it might check the message's path in some way
/// that is too complicated to do via the other methods, or it might check the
/// message's method, and allow GETs but not PUTs.
///
/// The filter function returns [`true`] if the request should still
/// require authentication, or [`false`] if authentication is unnecessary
/// for this request.
///
/// To help prevent security holes, your filter should return [`true`] by
/// default, and only return [`false`] under specifically-tested
/// circumstances, rather than the other way around. Eg, in the example
/// above, where you want to authenticate PUTs but not GETs, you should
/// check if the method is GET and return [`false`] in that case, and then
/// return [`true`] for all other methods (rather than returning [`true`] for
/// PUT and [`false`] for all other methods). This way if it turned out
/// (now or later) that some paths supported additional methods besides
/// GET and PUT, those methods would default to being NOT allowed for
/// unauthenticated users.
///
/// You can also set the filter by setting the SoupAuthDomain:filter
/// and [`filter-data`][struct@crate::AuthDomain#filter-data] properties], which can also be
/// used to set the filter at construct time.
/// ## `filter`
/// the auth filter for @self
/// ## `filter_data`
/// data to pass to @filter
#[doc(alias = "soup_auth_domain_set_filter")]
fn set_filter<P: Fn(&AuthDomain, &ServerMessage) -> bool + 'static>(&self, filter: P) {
let filter_data: Box_<P> = Box_::new(filter);
unsafe extern "C" fn filter_func<P: Fn(&AuthDomain, &ServerMessage) -> bool + 'static>(
domain: *mut ffi::SoupAuthDomain,
msg: *mut ffi::SoupServerMessage,
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let domain = from_glib_borrow(domain);
let msg = from_glib_borrow(msg);
let callback = &*(user_data as *mut P);
(*callback)(&domain, &msg).into_glib()
}
let filter = Some(filter_func::<P> as _);
unsafe extern "C" fn dnotify_func<P: Fn(&AuthDomain, &ServerMessage) -> bool + 'static>(
data: glib::ffi::gpointer,
) {
let _callback = Box_::from_raw(data as *mut P);
}
let destroy_call3 = Some(dnotify_func::<P> as _);
let super_callback0: Box_<P> = filter_data;
unsafe {
ffi::soup_auth_domain_set_filter(
self.as_ref().to_glib_none().0,
filter,
Box_::into_raw(super_callback0) as *mut _,
destroy_call3,
);
}
}
/// Sets @auth_callback as an authentication-handling callback for @self.
///
/// Whenever a request comes in to @self which cannot be authenticated via a
/// domain-specific auth callback (eg, `callback::AuthDomainDigestAuthCallback),
/// the generic auth callback will be invoked. See
/// `callback::AuthDomainGenericAuthCallback for information on what the callback
/// should do.
/// ## `auth_callback`
/// the auth callback
/// ## `auth_data`
/// data to pass to @auth_callback
#[doc(alias = "soup_auth_domain_set_generic_auth_callback")]
fn set_generic_auth_callback<P: Fn(&AuthDomain, &ServerMessage, &str) -> bool + 'static>(
&self,
auth_callback: P,
) {
let auth_callback_data: Box_<P> = Box_::new(auth_callback);
unsafe extern "C" fn auth_callback_func<
P: Fn(&AuthDomain, &ServerMessage, &str) -> bool + 'static,
>(
domain: *mut ffi::SoupAuthDomain,
msg: *mut ffi::SoupServerMessage,
username: *const libc::c_char,
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let domain = from_glib_borrow(domain);
let msg = from_glib_borrow(msg);
let username: Borrowed<glib::GString> = from_glib_borrow(username);
let callback = &*(user_data as *mut P);
(*callback)(&domain, &msg, username.as_str()).into_glib()
}
let auth_callback = Some(auth_callback_func::<P> as _);
unsafe extern "C" fn dnotify_func<
P: Fn(&AuthDomain, &ServerMessage, &str) -> bool + 'static,
>(
data: glib::ffi::gpointer,
) {
let _callback = Box_::from_raw(data as *mut P);
}
let destroy_call3 = Some(dnotify_func::<P> as _);
let super_callback0: Box_<P> = auth_callback_data;
unsafe {
ffi::soup_auth_domain_set_generic_auth_callback(
self.as_ref().to_glib_none().0,
auth_callback,
Box_::into_raw(super_callback0) as *mut _,
destroy_call3,
);
}
}
//#[doc(alias = "filter-data")]
//fn filter_data(&self) -> /*Unimplemented*/Basic: Pointer {
// ObjectExt::property(self.as_ref(), "filter-data")
//}
//#[doc(alias = "filter-data")]
//fn set_filter_data(&self, filter_data: /*Unimplemented*/Basic: Pointer) {
// ObjectExt::set_property(self.as_ref(),"filter-data", filter_data)
//}
//#[doc(alias = "generic-auth-data")]
//fn generic_auth_data(&self) -> /*Unimplemented*/Basic: Pointer {
// ObjectExt::property(self.as_ref(), "generic-auth-data")
//}
//#[doc(alias = "generic-auth-data")]
//fn set_generic_auth_data(&self, generic_auth_data: /*Unimplemented*/Basic: Pointer) {
// ObjectExt::set_property(self.as_ref(),"generic-auth-data", generic_auth_data)
//}
/// Whether or not this is a proxy auth domain.
fn is_proxy(&self) -> bool {
ObjectExt::property(self.as_ref(), "proxy")
}
#[doc(alias = "filter-data")]
fn connect_filter_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_filter_data_trampoline<
P: IsA<AuthDomain>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupAuthDomain,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(AuthDomain::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::filter-data\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_filter_data_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "generic-auth-data")]
fn connect_generic_auth_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_generic_auth_data_trampoline<
P: IsA<AuthDomain>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupAuthDomain,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(AuthDomain::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::generic-auth-data\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_generic_auth_data_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<AuthDomain>> AuthDomainExt for O {}