1use crate::{Message, 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 = "SoupAuth")]
16 pub struct Auth(Object<ffi::SoupAuth, ffi::SoupAuthClass>);
17
18 match fn {
19 type_ => || ffi::soup_auth_get_type(),
20 }
21}
22
23impl Auth {
24 pub const NONE: Option<&'static Auth> = None;
25
26 #[doc(alias = "soup_auth_new")]
27 pub fn new(type_: glib::types::Type, msg: &Message, auth_header: &str) -> Option<Auth> {
28 skip_assert_initialized!();
29 unsafe {
30 from_glib_full(ffi::soup_auth_new(
31 type_.into_glib(),
32 msg.to_glib_none().0,
33 auth_header.to_glib_none().0,
34 ))
35 }
36 }
37}
38
39pub trait AuthExt: IsA<Auth> + 'static {
40 #[doc(alias = "soup_auth_authenticate")]
41 fn authenticate(&self, username: &str, password: &str) {
42 unsafe {
43 ffi::soup_auth_authenticate(
44 self.as_ref().to_glib_none().0,
45 username.to_glib_none().0,
46 password.to_glib_none().0,
47 );
48 }
49 }
50
51 #[doc(alias = "soup_auth_can_authenticate")]
52 fn can_authenticate(&self) -> bool {
53 unsafe {
54 from_glib(ffi::soup_auth_can_authenticate(
55 self.as_ref().to_glib_none().0,
56 ))
57 }
58 }
59
60 #[doc(alias = "soup_auth_cancel")]
61 fn cancel(&self) {
62 unsafe {
63 ffi::soup_auth_cancel(self.as_ref().to_glib_none().0);
64 }
65 }
66
67 #[doc(alias = "soup_auth_get_authority")]
73 #[doc(alias = "get_authority")]
74 fn authority(&self) -> Option<glib::GString> {
75 unsafe { from_glib_none(ffi::soup_auth_get_authority(self.as_ref().to_glib_none().0)) }
76 }
77
78 #[doc(alias = "soup_auth_get_authorization")]
79 #[doc(alias = "get_authorization")]
80 fn authorization(&self, msg: &Message) -> Option<glib::GString> {
81 unsafe {
82 from_glib_full(ffi::soup_auth_get_authorization(
83 self.as_ref().to_glib_none().0,
84 msg.to_glib_none().0,
85 ))
86 }
87 }
88
89 #[doc(alias = "soup_auth_get_info")]
90 #[doc(alias = "get_info")]
91 fn info(&self) -> Option<glib::GString> {
92 unsafe { from_glib_full(ffi::soup_auth_get_info(self.as_ref().to_glib_none().0)) }
93 }
94
95 #[doc(alias = "soup_auth_get_protection_space")]
96 #[doc(alias = "get_protection_space")]
97 fn protection_space(&self, source_uri: &glib::Uri) -> Vec<glib::GString> {
98 unsafe {
99 FromGlibPtrContainer::from_glib_full(ffi::soup_auth_get_protection_space(
100 self.as_ref().to_glib_none().0,
101 source_uri.to_glib_none().0,
102 ))
103 }
104 }
105
106 #[doc(alias = "soup_auth_get_realm")]
107 #[doc(alias = "get_realm")]
108 fn realm(&self) -> Option<glib::GString> {
109 unsafe { from_glib_none(ffi::soup_auth_get_realm(self.as_ref().to_glib_none().0)) }
110 }
111
112 #[doc(alias = "soup_auth_get_scheme_name")]
113 #[doc(alias = "get_scheme_name")]
114 #[doc(alias = "scheme-name")]
115 fn scheme_name(&self) -> Option<glib::GString> {
116 unsafe {
117 from_glib_none(ffi::soup_auth_get_scheme_name(
118 self.as_ref().to_glib_none().0,
119 ))
120 }
121 }
122
123 #[doc(alias = "soup_auth_is_authenticated")]
124 #[doc(alias = "is-authenticated")]
125 fn is_authenticated(&self) -> bool {
126 unsafe {
127 from_glib(ffi::soup_auth_is_authenticated(
128 self.as_ref().to_glib_none().0,
129 ))
130 }
131 }
132
133 #[doc(alias = "soup_auth_is_cancelled")]
134 #[doc(alias = "is-cancelled")]
135 fn is_cancelled(&self) -> bool {
136 unsafe { from_glib(ffi::soup_auth_is_cancelled(self.as_ref().to_glib_none().0)) }
137 }
138
139 #[doc(alias = "soup_auth_is_for_proxy")]
140 #[doc(alias = "is-for-proxy")]
141 fn is_for_proxy(&self) -> bool {
142 unsafe { from_glib(ffi::soup_auth_is_for_proxy(self.as_ref().to_glib_none().0)) }
143 }
144
145 #[doc(alias = "soup_auth_is_ready")]
146 fn is_ready(&self, msg: &Message) -> bool {
147 unsafe {
148 from_glib(ffi::soup_auth_is_ready(
149 self.as_ref().to_glib_none().0,
150 msg.to_glib_none().0,
151 ))
152 }
153 }
154
155 #[doc(alias = "soup_auth_update")]
156 fn update(&self, msg: &Message, auth_header: &str) -> bool {
157 unsafe {
158 from_glib(ffi::soup_auth_update(
159 self.as_ref().to_glib_none().0,
160 msg.to_glib_none().0,
161 auth_header.to_glib_none().0,
162 ))
163 }
164 }
165
166 fn set_authority(&self, authority: Option<&str>) {
167 ObjectExt::set_property(self.as_ref(), "authority", authority)
168 }
169
170 #[doc(alias = "is-for-proxy")]
171 fn set_is_for_proxy(&self, is_for_proxy: bool) {
172 ObjectExt::set_property(self.as_ref(), "is-for-proxy", is_for_proxy)
173 }
174
175 fn set_realm(&self, realm: Option<&str>) {
176 ObjectExt::set_property(self.as_ref(), "realm", realm)
177 }
178
179 #[doc(alias = "authority")]
180 fn connect_authority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
181 unsafe extern "C" fn notify_authority_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
182 this: *mut ffi::SoupAuth,
183 _param_spec: glib::ffi::gpointer,
184 f: glib::ffi::gpointer,
185 ) {
186 unsafe {
187 let f: &F = &*(f as *const F);
188 f(Auth::from_glib_borrow(this).unsafe_cast_ref())
189 }
190 }
191 unsafe {
192 let f: Box_<F> = Box_::new(f);
193 connect_raw(
194 self.as_ptr() as *mut _,
195 c"notify::authority".as_ptr(),
196 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
197 notify_authority_trampoline::<Self, F> as *const (),
198 )),
199 Box_::into_raw(f),
200 )
201 }
202 }
203
204 #[doc(alias = "is-authenticated")]
205 fn connect_is_authenticated_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
206 unsafe extern "C" fn notify_is_authenticated_trampoline<
207 P: IsA<Auth>,
208 F: Fn(&P) + 'static,
209 >(
210 this: *mut ffi::SoupAuth,
211 _param_spec: glib::ffi::gpointer,
212 f: glib::ffi::gpointer,
213 ) {
214 unsafe {
215 let f: &F = &*(f as *const F);
216 f(Auth::from_glib_borrow(this).unsafe_cast_ref())
217 }
218 }
219 unsafe {
220 let f: Box_<F> = Box_::new(f);
221 connect_raw(
222 self.as_ptr() as *mut _,
223 c"notify::is-authenticated".as_ptr(),
224 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225 notify_is_authenticated_trampoline::<Self, F> as *const (),
226 )),
227 Box_::into_raw(f),
228 )
229 }
230 }
231
232 #[doc(alias = "is-cancelled")]
233 fn connect_is_cancelled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
234 unsafe extern "C" fn notify_is_cancelled_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
235 this: *mut ffi::SoupAuth,
236 _param_spec: glib::ffi::gpointer,
237 f: glib::ffi::gpointer,
238 ) {
239 unsafe {
240 let f: &F = &*(f as *const F);
241 f(Auth::from_glib_borrow(this).unsafe_cast_ref())
242 }
243 }
244 unsafe {
245 let f: Box_<F> = Box_::new(f);
246 connect_raw(
247 self.as_ptr() as *mut _,
248 c"notify::is-cancelled".as_ptr(),
249 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
250 notify_is_cancelled_trampoline::<Self, F> as *const (),
251 )),
252 Box_::into_raw(f),
253 )
254 }
255 }
256
257 #[doc(alias = "is-for-proxy")]
258 fn connect_is_for_proxy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
259 unsafe extern "C" fn notify_is_for_proxy_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
260 this: *mut ffi::SoupAuth,
261 _param_spec: glib::ffi::gpointer,
262 f: glib::ffi::gpointer,
263 ) {
264 unsafe {
265 let f: &F = &*(f as *const F);
266 f(Auth::from_glib_borrow(this).unsafe_cast_ref())
267 }
268 }
269 unsafe {
270 let f: Box_<F> = Box_::new(f);
271 connect_raw(
272 self.as_ptr() as *mut _,
273 c"notify::is-for-proxy".as_ptr(),
274 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
275 notify_is_for_proxy_trampoline::<Self, F> as *const (),
276 )),
277 Box_::into_raw(f),
278 )
279 }
280 }
281
282 #[doc(alias = "realm")]
283 fn connect_realm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
284 unsafe extern "C" fn notify_realm_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
285 this: *mut ffi::SoupAuth,
286 _param_spec: glib::ffi::gpointer,
287 f: glib::ffi::gpointer,
288 ) {
289 unsafe {
290 let f: &F = &*(f as *const F);
291 f(Auth::from_glib_borrow(this).unsafe_cast_ref())
292 }
293 }
294 unsafe {
295 let f: Box_<F> = Box_::new(f);
296 connect_raw(
297 self.as_ptr() as *mut _,
298 c"notify::realm".as_ptr(),
299 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
300 notify_realm_trampoline::<Self, F> as *const (),
301 )),
302 Box_::into_raw(f),
303 )
304 }
305 }
306
307 #[doc(alias = "scheme-name")]
308 fn connect_scheme_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
309 unsafe extern "C" fn notify_scheme_name_trampoline<P: IsA<Auth>, F: Fn(&P) + 'static>(
310 this: *mut ffi::SoupAuth,
311 _param_spec: glib::ffi::gpointer,
312 f: glib::ffi::gpointer,
313 ) {
314 unsafe {
315 let f: &F = &*(f as *const F);
316 f(Auth::from_glib_borrow(this).unsafe_cast_ref())
317 }
318 }
319 unsafe {
320 let f: Box_<F> = Box_::new(f);
321 connect_raw(
322 self.as_ptr() as *mut _,
323 c"notify::scheme-name".as_ptr(),
324 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
325 notify_scheme_name_trampoline::<Self, F> as *const (),
326 )),
327 Box_::into_raw(f),
328 )
329 }
330 }
331}
332
333impl<O: IsA<Auth>> AuthExt for O {}