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