soup/auto/
auth_domain_basic.rs1use crate::{AuthDomain, ServerMessage, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "SoupAuthDomainBasic")]
16 pub struct AuthDomainBasic(Object<ffi::SoupAuthDomainBasic, ffi::SoupAuthDomainBasicClass>) @extends AuthDomain;
17
18 match fn {
19 type_ => || ffi::soup_auth_domain_basic_get_type(),
20 }
21}
22
23impl AuthDomainBasic {
24 pub fn builder() -> AuthDomainBasicBuilder {
34 AuthDomainBasicBuilder::new()
35 }
36
37 #[doc(alias = "soup_auth_domain_basic_set_auth_callback")]
38 #[doc(alias = "auth-callback")]
39 pub fn set_auth_callback<
40 P: Fn(&AuthDomainBasic, &ServerMessage, &str, &str) -> bool + 'static,
41 >(
42 &self,
43 callback: P,
44 ) {
45 let callback_data: Box_<P> = Box_::new(callback);
46 unsafe extern "C" fn callback_func<
47 P: Fn(&AuthDomainBasic, &ServerMessage, &str, &str) -> bool + 'static,
48 >(
49 domain: *mut ffi::SoupAuthDomainBasic,
50 msg: *mut ffi::SoupServerMessage,
51 username: *const std::ffi::c_char,
52 password: *const std::ffi::c_char,
53 user_data: glib::ffi::gpointer,
54 ) -> glib::ffi::gboolean {
55 unsafe {
56 let domain = from_glib_borrow(domain);
57 let msg = from_glib_borrow(msg);
58 let username: Borrowed<glib::GString> = from_glib_borrow(username);
59 let password: Borrowed<glib::GString> = from_glib_borrow(password);
60 let callback = &*(user_data as *mut P);
61 (*callback)(&domain, &msg, username.as_str(), password.as_str()).into_glib()
62 }
63 }
64 let callback = Some(callback_func::<P> as _);
65 unsafe extern "C" fn dnotify_func<
66 P: Fn(&AuthDomainBasic, &ServerMessage, &str, &str) -> bool + 'static,
67 >(
68 data: glib::ffi::gpointer,
69 ) {
70 unsafe {
71 let _callback = Box_::from_raw(data as *mut P);
72 }
73 }
74 let destroy_call3 = Some(dnotify_func::<P> as _);
75 let super_callback0: Box_<P> = callback_data;
76 unsafe {
77 ffi::soup_auth_domain_basic_set_auth_callback(
78 self.to_glib_none().0,
79 callback,
80 Box_::into_raw(super_callback0) as *mut _,
81 destroy_call3,
82 );
83 }
84 }
85
86 #[doc(alias = "auth-data")]
97 pub fn connect_auth_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
98 unsafe extern "C" fn notify_auth_data_trampoline<F: Fn(&AuthDomainBasic) + 'static>(
99 this: *mut ffi::SoupAuthDomainBasic,
100 _param_spec: glib::ffi::gpointer,
101 f: glib::ffi::gpointer,
102 ) {
103 unsafe {
104 let f: &F = &*(f as *const F);
105 f(&from_glib_borrow(this))
106 }
107 }
108 unsafe {
109 let f: Box_<F> = Box_::new(f);
110 connect_raw(
111 self.as_ptr() as *mut _,
112 c"notify::auth-data".as_ptr(),
113 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
114 notify_auth_data_trampoline::<F> as *const (),
115 )),
116 Box_::into_raw(f),
117 )
118 }
119 }
120}
121
122impl Default for AuthDomainBasic {
123 fn default() -> Self {
124 glib::object::Object::new::<Self>()
125 }
126}
127
128#[must_use = "The builder must be built to be used"]
133pub struct AuthDomainBasicBuilder {
134 builder: glib::object::ObjectBuilder<'static, AuthDomainBasic>,
135}
136
137impl AuthDomainBasicBuilder {
138 fn new() -> Self {
139 Self {
140 builder: glib::object::Object::builder(),
141 }
142 }
143
144 pub fn proxy(self, proxy: bool) -> Self {
157 Self {
158 builder: self.builder.property("proxy", proxy),
159 }
160 }
161
162 pub fn realm(self, realm: impl Into<glib::GString>) -> Self {
163 Self {
164 builder: self.builder.property("realm", realm.into()),
165 }
166 }
167
168 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
171 pub fn build(self) -> AuthDomainBasic {
172 assert_initialized_main_thread!();
173 self.builder.build()
174 }
175}