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 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
// 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::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// The abstract base class for handling authentication.
///
/// Specific HTTP Authentication mechanisms are implemented by its subclasses,
/// but applications never need to be aware of the specific subclasses being
/// used.
///
/// #SoupAuth objects store the authentication data associated with a given bit
/// of web space. They are created automatically by [`Session`][crate::Session].
///
/// This is an Abstract Base Class, you cannot instantiate it.
///
/// ## Properties
///
///
/// #### `authority`
/// The authority (host:port) being authenticated to.
///
/// Readable | Writeable
///
///
/// #### `is-authenticated`
/// Whether or not the auth has been authenticated.
///
/// Readable
///
///
/// #### `is-cancelled`
/// Whether or not the auth has been cancelled.
///
/// Readable
///
///
/// #### `is-for-proxy`
/// Whether or not the auth is for a proxy server.
///
/// Readable | Writeable
///
///
/// #### `realm`
/// The authentication realm.
///
/// Readable | Writeable
///
///
/// #### `scheme-name`
/// The authentication scheme name.
///
/// Readable
///
/// # Implements
///
/// [`AuthExt`][trait@crate::prelude::AuthExt], [`trait@glib::ObjectExt`]
#[doc(alias = "SoupAuth")]
pub struct Auth(Object<ffi::SoupAuth, ffi::SoupAuthClass>);
match fn {
type_ => || ffi::soup_auth_get_type(),
}
}
impl Auth {
pub const NONE: Option<&'static Auth> = None;
/// Creates a new #SoupAuth of type @type_ with the information from
/// @msg and @auth_header.
///
/// This is called by [`Session`][crate::Session]; you will normally not create auths
/// yourself.
/// ## `type_`
/// the type of auth to create (a subtype of #SoupAuth)
/// ## `msg`
/// the #SoupMessage the auth is being created for
/// ## `auth_header`
/// the WWW-Authenticate/Proxy-Authenticate header
///
/// # Returns
///
/// the new #SoupAuth, or [`None`] if it could
/// not be created
#[doc(alias = "soup_auth_new")]
pub fn new(type_: glib::types::Type, msg: &Message, auth_header: &str) -> Option<Auth> {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::soup_auth_new(
type_.into_glib(),
msg.to_glib_none().0,
auth_header.to_glib_none().0,
))
}
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Auth>> Sealed for T {}
}
/// Trait containing all [`struct@Auth`] methods.
///
/// # Implementors
///
/// [`AuthBasic`][struct@crate::AuthBasic], [`AuthDigest`][struct@crate::AuthDigest], [`AuthNTLM`][struct@crate::AuthNTLM], [`AuthNegotiate`][struct@crate::AuthNegotiate], [`Auth`][struct@crate::Auth]
pub trait AuthExt: IsA<Auth> + sealed::Sealed + 'static {
/// Call this on an auth to authenticate it.
///
/// Normally this will cause the auth's message to be requeued with the new
/// authentication info.
/// ## `username`
/// the username provided by the user or client
/// ## `password`
/// the password provided by the user or client
#[doc(alias = "soup_auth_authenticate")]
fn authenticate(&self, username: &str, password: &str) {
unsafe {
ffi::soup_auth_authenticate(
self.as_ref().to_glib_none().0,
username.to_glib_none().0,
password.to_glib_none().0,
);
}
}
/// Tests if @self is able to authenticate by providing credentials to the
/// [`authenticate()`][Self::authenticate()].
///
/// # Returns
///
/// [`true`] if @self is able to accept credentials.
#[doc(alias = "soup_auth_can_authenticate")]
fn can_authenticate(&self) -> bool {
unsafe {
from_glib(ffi::soup_auth_can_authenticate(
self.as_ref().to_glib_none().0,
))
}
}
/// Call this on an auth to cancel it.
///
/// You need to cancel an auth to complete an asynchronous authenticate operation
/// when no credentials are provided ([`authenticate()`][Self::authenticate()] is not called).
/// The #SoupAuth will be cancelled on dispose if it hans't been authenticated.
#[doc(alias = "soup_auth_cancel")]
fn cancel(&self) {
unsafe {
ffi::soup_auth_cancel(self.as_ref().to_glib_none().0);
}
}
//#[doc(alias = "soup_auth_free_protection_space")]
//fn free_protection_space(&self, space: /*Unimplemented*/&[&Basic: Pointer]) {
// unsafe { TODO: call ffi:soup_auth_free_protection_space() }
//}
/// Returns the authority (host:port) that @self is associated with.
///
/// # Returns
///
/// the authority
#[doc(alias = "soup_auth_get_authority")]
#[doc(alias = "get_authority")]
fn authority(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::soup_auth_get_authority(self.as_ref().to_glib_none().0)) }
}
/// Generates an appropriate "Authorization" header for @msg.
///
/// (The session will only call this if [`is_authenticated()`][Self::is_authenticated()] returned
/// [`true`].)
/// ## `msg`
/// the #SoupMessage to be authorized
///
/// # Returns
///
/// the "Authorization" header, which must be freed.
#[doc(alias = "soup_auth_get_authorization")]
#[doc(alias = "get_authorization")]
fn authorization(&self, msg: &Message) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::soup_auth_get_authorization(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
))
}
}
/// Gets an opaque identifier for @self.
///
/// The identifier can be used as a hash key or the like. #SoupAuth objects from
/// the same server with the same identifier refer to the same authentication
/// domain (eg, the URLs associated with them take the same usernames and
/// passwords).
///
/// # Returns
///
/// the identifier
#[doc(alias = "soup_auth_get_info")]
#[doc(alias = "get_info")]
fn info(&self) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::soup_auth_get_info(self.as_ref().to_glib_none().0)) }
}
/// Returns a list of paths on the server which @self extends over.
///
/// (All subdirectories of these paths are also assumed to be part
/// of @self's protection space, unless otherwise discovered not to
/// be.)
/// ## `source_uri`
/// the URI of the request that @self was generated in
/// response to.
///
/// # Returns
///
/// the list of
/// paths, which can be freed with `Auth::free_protection_space()`.
#[doc(alias = "soup_auth_get_protection_space")]
#[doc(alias = "get_protection_space")]
fn protection_space(&self, source_uri: &glib::Uri) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::soup_auth_get_protection_space(
self.as_ref().to_glib_none().0,
source_uri.to_glib_none().0,
))
}
}
/// Returns @self's realm.
///
/// This is an identifier that distinguishes separate authentication spaces on a
/// given server, and may be some string that is meaningful to the user.
/// (Although it is probably not localized.)
///
/// # Returns
///
/// the realm name
#[doc(alias = "soup_auth_get_realm")]
#[doc(alias = "get_realm")]
fn realm(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::soup_auth_get_realm(self.as_ref().to_glib_none().0)) }
}
/// soup_auth_get_scheme_name: (attributes org.gtk.Method.get_property=scheme-name)
/// Returns @self's scheme name. (Eg, "Basic", "Digest", or "NTLM")
///
/// # Returns
///
/// the scheme name
#[doc(alias = "soup_auth_get_scheme_name")]
#[doc(alias = "get_scheme_name")]
fn scheme_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::soup_auth_get_scheme_name(
self.as_ref().to_glib_none().0,
))
}
}
/// Tests if @self has been given a username and password.
///
/// # Returns
///
/// [`true`] if @self has been given a username and password
#[doc(alias = "soup_auth_is_authenticated")]
fn is_authenticated(&self) -> bool {
unsafe {
from_glib(ffi::soup_auth_is_authenticated(
self.as_ref().to_glib_none().0,
))
}
}
/// Tests if @self has been cancelled
///
/// # Returns
///
/// [`true`] if @self has been cancelled
#[doc(alias = "soup_auth_is_cancelled")]
fn is_cancelled(&self) -> bool {
unsafe { from_glib(ffi::soup_auth_is_cancelled(self.as_ref().to_glib_none().0)) }
}
/// Tests whether or not @self is associated with a proxy server rather
/// than an "origin" server.
///
/// # Returns
///
/// [`true`] or [`false`]
#[doc(alias = "soup_auth_is_for_proxy")]
fn is_for_proxy(&self) -> bool {
unsafe { from_glib(ffi::soup_auth_is_for_proxy(self.as_ref().to_glib_none().0)) }
}
/// Tests if @self is ready to make a request for @msg with.
///
/// For most auths, this is equivalent to [`is_authenticated()`][Self::is_authenticated()], but for
/// some auth types (eg, NTLM), the auth may be sendable (eg, as an
/// authentication request) even before it is authenticated.
/// ## `msg`
/// a #SoupMessage
///
/// # Returns
///
/// [`true`] if @self is ready to make a request with.
#[doc(alias = "soup_auth_is_ready")]
fn is_ready(&self, msg: &Message) -> bool {
unsafe {
from_glib(ffi::soup_auth_is_ready(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
))
}
}
/// Updates @self with the information from @msg and @auth_header,
/// possibly un-authenticating it.
///
/// As with [`Auth::new()`][crate::Auth::new()], this is normally only used by [`Session`][crate::Session].
/// ## `msg`
/// the #SoupMessage @self is being updated for
/// ## `auth_header`
/// the WWW-Authenticate/Proxy-Authenticate header
///
/// # Returns
///
/// [`true`] if @self is still a valid (but potentially
/// unauthenticated) #SoupAuth. [`false`] if something about @auth_params
/// could not be parsed or incorporated into @self at all.
#[doc(alias = "soup_auth_update")]
fn update(&self, msg: &Message, auth_header: &str) -> bool {
unsafe {
from_glib(ffi::soup_auth_update(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
auth_header.to_glib_none().0,
))
}
}
/// The authority (host:port) being authenticated to.
fn set_authority(&self, authority: Option<&str>) {
ObjectExt::set_property(self.as_ref(), "authority", authority)
}
/// Whether or not the auth is for a proxy server.
#[doc(alias = "is-for-proxy")]
fn set_is_for_proxy(&self, is_for_proxy: bool) {
ObjectExt::set_property(self.as_ref(), "is-for-proxy", is_for_proxy)
}
/// The authentication realm.
fn set_realm(&self, realm: Option<&str>) {
ObjectExt::set_property(self.as_ref(), "realm", realm)
}
#[doc(alias = "authority")]
fn connect_authority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_authority_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupAuth,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Auth::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::authority\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_authority_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "is-authenticated")]
fn connect_is_authenticated_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_is_authenticated_trampoline<
P: IsA<Auth>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupAuth,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Auth::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::is-authenticated\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_is_authenticated_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "is-cancelled")]
fn connect_is_cancelled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_is_cancelled_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupAuth,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Auth::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::is-cancelled\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_is_cancelled_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "is-for-proxy")]
fn connect_is_for_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_is_for_proxy_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupAuth,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Auth::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::is-for-proxy\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_is_for_proxy_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "realm")]
fn connect_realm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_realm_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupAuth,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Auth::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::realm\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_realm_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "scheme-name")]
fn connect_scheme_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_scheme_name_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupAuth,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Auth::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::scheme-name\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_scheme_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Auth>> AuthExt for O {}