1use crate::{ffi, ServerMessage};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "SoupAuthDomain")]
16 pub struct AuthDomain(Object<ffi::SoupAuthDomain, ffi::SoupAuthDomainClass>);
17
18 match fn {
19 type_ => || ffi::soup_auth_domain_get_type(),
20 }
21}
22
23impl AuthDomain {
24 pub const NONE: Option<&'static AuthDomain> = None;
25}
26
27mod sealed {
28 pub trait Sealed {}
29 impl<T: super::IsA<super::AuthDomain>> Sealed for T {}
30}
31
32pub trait AuthDomainExt: IsA<AuthDomain> + sealed::Sealed + 'static {
33 #[doc(alias = "soup_auth_domain_accepts")]
34 fn accepts(&self, msg: &ServerMessage) -> Option<glib::GString> {
35 unsafe {
36 from_glib_full(ffi::soup_auth_domain_accepts(
37 self.as_ref().to_glib_none().0,
38 msg.to_glib_none().0,
39 ))
40 }
41 }
42
43 #[doc(alias = "soup_auth_domain_add_path")]
44 fn add_path(&self, path: &str) {
45 unsafe {
46 ffi::soup_auth_domain_add_path(self.as_ref().to_glib_none().0, path.to_glib_none().0);
47 }
48 }
49
50 #[doc(alias = "soup_auth_domain_challenge")]
51 fn challenge(&self, msg: &ServerMessage) {
52 unsafe {
53 ffi::soup_auth_domain_challenge(self.as_ref().to_glib_none().0, msg.to_glib_none().0);
54 }
55 }
56
57 #[doc(alias = "soup_auth_domain_check_password")]
58 fn check_password(&self, msg: &ServerMessage, username: &str, password: &str) -> bool {
59 unsafe {
60 from_glib(ffi::soup_auth_domain_check_password(
61 self.as_ref().to_glib_none().0,
62 msg.to_glib_none().0,
63 username.to_glib_none().0,
64 password.to_glib_none().0,
65 ))
66 }
67 }
68
69 #[doc(alias = "soup_auth_domain_covers")]
70 fn covers(&self, msg: &ServerMessage) -> bool {
71 unsafe {
72 from_glib(ffi::soup_auth_domain_covers(
73 self.as_ref().to_glib_none().0,
74 msg.to_glib_none().0,
75 ))
76 }
77 }
78
79 #[doc(alias = "soup_auth_domain_get_realm")]
80 #[doc(alias = "get_realm")]
81 fn realm(&self) -> Option<glib::GString> {
82 unsafe {
83 from_glib_none(ffi::soup_auth_domain_get_realm(
84 self.as_ref().to_glib_none().0,
85 ))
86 }
87 }
88
89 #[doc(alias = "soup_auth_domain_remove_path")]
90 fn remove_path(&self, path: &str) {
91 unsafe {
92 ffi::soup_auth_domain_remove_path(
93 self.as_ref().to_glib_none().0,
94 path.to_glib_none().0,
95 );
96 }
97 }
98
99 #[doc(alias = "soup_auth_domain_set_filter")]
100 #[doc(alias = "filter")]
101 fn set_filter<P: Fn(&AuthDomain, &ServerMessage) -> bool + 'static>(&self, filter: P) {
102 let filter_data: Box_<P> = Box_::new(filter);
103 unsafe extern "C" fn filter_func<P: Fn(&AuthDomain, &ServerMessage) -> bool + 'static>(
104 domain: *mut ffi::SoupAuthDomain,
105 msg: *mut ffi::SoupServerMessage,
106 user_data: glib::ffi::gpointer,
107 ) -> glib::ffi::gboolean {
108 let domain = from_glib_borrow(domain);
109 let msg = from_glib_borrow(msg);
110 let callback = &*(user_data as *mut P);
111 (*callback)(&domain, &msg).into_glib()
112 }
113 let filter = Some(filter_func::<P> as _);
114 unsafe extern "C" fn dnotify_func<P: Fn(&AuthDomain, &ServerMessage) -> bool + 'static>(
115 data: glib::ffi::gpointer,
116 ) {
117 let _callback = Box_::from_raw(data as *mut P);
118 }
119 let destroy_call3 = Some(dnotify_func::<P> as _);
120 let super_callback0: Box_<P> = filter_data;
121 unsafe {
122 ffi::soup_auth_domain_set_filter(
123 self.as_ref().to_glib_none().0,
124 filter,
125 Box_::into_raw(super_callback0) as *mut _,
126 destroy_call3,
127 );
128 }
129 }
130
131 #[doc(alias = "soup_auth_domain_set_generic_auth_callback")]
132 #[doc(alias = "generic-auth-callback")]
133 fn set_generic_auth_callback<P: Fn(&AuthDomain, &ServerMessage, &str) -> bool + 'static>(
134 &self,
135 auth_callback: P,
136 ) {
137 let auth_callback_data: Box_<P> = Box_::new(auth_callback);
138 unsafe extern "C" fn auth_callback_func<
139 P: Fn(&AuthDomain, &ServerMessage, &str) -> bool + 'static,
140 >(
141 domain: *mut ffi::SoupAuthDomain,
142 msg: *mut ffi::SoupServerMessage,
143 username: *const libc::c_char,
144 user_data: glib::ffi::gpointer,
145 ) -> glib::ffi::gboolean {
146 let domain = from_glib_borrow(domain);
147 let msg = from_glib_borrow(msg);
148 let username: Borrowed<glib::GString> = from_glib_borrow(username);
149 let callback = &*(user_data as *mut P);
150 (*callback)(&domain, &msg, username.as_str()).into_glib()
151 }
152 let auth_callback = Some(auth_callback_func::<P> as _);
153 unsafe extern "C" fn dnotify_func<
154 P: Fn(&AuthDomain, &ServerMessage, &str) -> bool + 'static,
155 >(
156 data: glib::ffi::gpointer,
157 ) {
158 let _callback = Box_::from_raw(data as *mut P);
159 }
160 let destroy_call3 = Some(dnotify_func::<P> as _);
161 let super_callback0: Box_<P> = auth_callback_data;
162 unsafe {
163 ffi::soup_auth_domain_set_generic_auth_callback(
164 self.as_ref().to_glib_none().0,
165 auth_callback,
166 Box_::into_raw(super_callback0) as *mut _,
167 destroy_call3,
168 );
169 }
170 }
171
172 fn is_proxy(&self) -> bool {
193 ObjectExt::property(self.as_ref(), "proxy")
194 }
195
196 #[doc(alias = "filter-data")]
197 fn connect_filter_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
198 unsafe extern "C" fn notify_filter_data_trampoline<
199 P: IsA<AuthDomain>,
200 F: Fn(&P) + 'static,
201 >(
202 this: *mut ffi::SoupAuthDomain,
203 _param_spec: glib::ffi::gpointer,
204 f: glib::ffi::gpointer,
205 ) {
206 let f: &F = &*(f as *const F);
207 f(AuthDomain::from_glib_borrow(this).unsafe_cast_ref())
208 }
209 unsafe {
210 let f: Box_<F> = Box_::new(f);
211 connect_raw(
212 self.as_ptr() as *mut _,
213 b"notify::filter-data\0".as_ptr() as *const _,
214 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215 notify_filter_data_trampoline::<Self, F> as *const (),
216 )),
217 Box_::into_raw(f),
218 )
219 }
220 }
221
222 #[doc(alias = "generic-auth-data")]
223 fn connect_generic_auth_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
224 unsafe extern "C" fn notify_generic_auth_data_trampoline<
225 P: IsA<AuthDomain>,
226 F: Fn(&P) + 'static,
227 >(
228 this: *mut ffi::SoupAuthDomain,
229 _param_spec: glib::ffi::gpointer,
230 f: glib::ffi::gpointer,
231 ) {
232 let f: &F = &*(f as *const F);
233 f(AuthDomain::from_glib_borrow(this).unsafe_cast_ref())
234 }
235 unsafe {
236 let f: Box_<F> = Box_::new(f);
237 connect_raw(
238 self.as_ptr() as *mut _,
239 b"notify::generic-auth-data\0".as_ptr() as *const _,
240 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
241 notify_generic_auth_data_trampoline::<Self, F> as *const (),
242 )),
243 Box_::into_raw(f),
244 )
245 }
246 }
247}
248
249impl<O: IsA<AuthDomain>> AuthDomainExt for O {}