soup/auto/
server.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5#![allow(deprecated)]
6
7use crate::{ffi, AuthDomain, ServerListenOptions, ServerMessage};
8use glib::{
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "SoupServer")]
17    pub struct Server(Object<ffi::SoupServer, ffi::SoupServerClass>);
18
19    match fn {
20        type_ => || ffi::soup_server_get_type(),
21    }
22}
23
24impl Server {
25    pub const NONE: Option<&'static Server> = None;
26
27    //#[doc(alias = "soup_server_new")]
28    //pub fn new(optname1: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Option<Server> {
29    //    unsafe { TODO: call ffi:soup_server_new() }
30    //}
31
32    // rustdoc-stripper-ignore-next
33    /// Creates a new builder-pattern struct instance to construct [`Server`] objects.
34    ///
35    /// This method returns an instance of [`ServerBuilder`](crate::builders::ServerBuilder) which can be used to create [`Server`] objects.
36    pub fn builder() -> ServerBuilder {
37        ServerBuilder::new()
38    }
39}
40
41// rustdoc-stripper-ignore-next
42/// A [builder-pattern] type to construct [`Server`] objects.
43///
44/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
45#[must_use = "The builder must be built to be used"]
46pub struct ServerBuilder {
47    builder: glib::object::ObjectBuilder<'static, Server>,
48}
49
50impl ServerBuilder {
51    fn new() -> Self {
52        Self {
53            builder: glib::object::Object::builder(),
54        }
55    }
56
57    pub fn raw_paths(self, raw_paths: bool) -> Self {
58        Self {
59            builder: self.builder.property("raw-paths", raw_paths),
60        }
61    }
62
63    pub fn server_header(self, server_header: impl Into<glib::GString>) -> Self {
64        Self {
65            builder: self.builder.property("server-header", server_header.into()),
66        }
67    }
68
69    pub fn tls_auth_mode(self, tls_auth_mode: gio::TlsAuthenticationMode) -> Self {
70        Self {
71            builder: self.builder.property("tls-auth-mode", tls_auth_mode),
72        }
73    }
74
75    pub fn tls_certificate(self, tls_certificate: &impl IsA<gio::TlsCertificate>) -> Self {
76        Self {
77            builder: self
78                .builder
79                .property("tls-certificate", tls_certificate.clone().upcast()),
80        }
81    }
82
83    pub fn tls_database(self, tls_database: &impl IsA<gio::TlsDatabase>) -> Self {
84        Self {
85            builder: self
86                .builder
87                .property("tls-database", tls_database.clone().upcast()),
88        }
89    }
90
91    // rustdoc-stripper-ignore-next
92    /// Build the [`Server`].
93    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
94    pub fn build(self) -> Server {
95        self.builder.build()
96    }
97}
98
99mod sealed {
100    pub trait Sealed {}
101    impl<T: super::IsA<super::Server>> Sealed for T {}
102}
103
104pub trait ServerExt: IsA<Server> + sealed::Sealed + 'static {
105    #[doc(alias = "soup_server_accept_iostream")]
106    fn accept_iostream(
107        &self,
108        stream: &impl IsA<gio::IOStream>,
109        local_addr: Option<&impl IsA<gio::SocketAddress>>,
110        remote_addr: Option<&impl IsA<gio::SocketAddress>>,
111    ) -> Result<(), glib::Error> {
112        unsafe {
113            let mut error = std::ptr::null_mut();
114            let is_ok = ffi::soup_server_accept_iostream(
115                self.as_ref().to_glib_none().0,
116                stream.as_ref().to_glib_none().0,
117                local_addr.map(|p| p.as_ref()).to_glib_none().0,
118                remote_addr.map(|p| p.as_ref()).to_glib_none().0,
119                &mut error,
120            );
121            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
122            if error.is_null() {
123                Ok(())
124            } else {
125                Err(from_glib_full(error))
126            }
127        }
128    }
129
130    #[doc(alias = "soup_server_add_auth_domain")]
131    fn add_auth_domain(&self, auth_domain: &impl IsA<AuthDomain>) {
132        unsafe {
133            ffi::soup_server_add_auth_domain(
134                self.as_ref().to_glib_none().0,
135                auth_domain.as_ref().to_glib_none().0,
136            );
137        }
138    }
139
140    #[doc(alias = "soup_server_add_websocket_extension")]
141    fn add_websocket_extension(&self, extension_type: glib::types::Type) {
142        unsafe {
143            ffi::soup_server_add_websocket_extension(
144                self.as_ref().to_glib_none().0,
145                extension_type.into_glib(),
146            );
147        }
148    }
149
150    #[doc(alias = "soup_server_disconnect")]
151    fn disconnect(&self) {
152        unsafe {
153            ffi::soup_server_disconnect(self.as_ref().to_glib_none().0);
154        }
155    }
156
157    #[doc(alias = "soup_server_get_listeners")]
158    #[doc(alias = "get_listeners")]
159    fn listeners(&self) -> Vec<gio::Socket> {
160        unsafe {
161            FromGlibPtrContainer::from_glib_container(ffi::soup_server_get_listeners(
162                self.as_ref().to_glib_none().0,
163            ))
164        }
165    }
166
167    #[doc(alias = "soup_server_get_tls_auth_mode")]
168    #[doc(alias = "get_tls_auth_mode")]
169    #[doc(alias = "tls-auth-mode")]
170    fn tls_auth_mode(&self) -> gio::TlsAuthenticationMode {
171        unsafe {
172            from_glib(ffi::soup_server_get_tls_auth_mode(
173                self.as_ref().to_glib_none().0,
174            ))
175        }
176    }
177
178    #[doc(alias = "soup_server_get_tls_certificate")]
179    #[doc(alias = "get_tls_certificate")]
180    #[doc(alias = "tls-certificate")]
181    fn tls_certificate(&self) -> Option<gio::TlsCertificate> {
182        unsafe {
183            from_glib_none(ffi::soup_server_get_tls_certificate(
184                self.as_ref().to_glib_none().0,
185            ))
186        }
187    }
188
189    #[doc(alias = "soup_server_get_tls_database")]
190    #[doc(alias = "get_tls_database")]
191    #[doc(alias = "tls-database")]
192    fn tls_database(&self) -> Option<gio::TlsDatabase> {
193        unsafe {
194            from_glib_none(ffi::soup_server_get_tls_database(
195                self.as_ref().to_glib_none().0,
196            ))
197        }
198    }
199
200    #[doc(alias = "soup_server_get_uris")]
201    #[doc(alias = "get_uris")]
202    fn uris(&self) -> Vec<glib::Uri> {
203        unsafe {
204            FromGlibPtrContainer::from_glib_full(ffi::soup_server_get_uris(
205                self.as_ref().to_glib_none().0,
206            ))
207        }
208    }
209
210    #[doc(alias = "soup_server_is_https")]
211    fn is_https(&self) -> bool {
212        unsafe { from_glib(ffi::soup_server_is_https(self.as_ref().to_glib_none().0)) }
213    }
214
215    #[doc(alias = "soup_server_listen")]
216    fn listen(
217        &self,
218        address: &impl IsA<gio::SocketAddress>,
219        options: ServerListenOptions,
220    ) -> Result<(), glib::Error> {
221        unsafe {
222            let mut error = std::ptr::null_mut();
223            let is_ok = ffi::soup_server_listen(
224                self.as_ref().to_glib_none().0,
225                address.as_ref().to_glib_none().0,
226                options.into_glib(),
227                &mut error,
228            );
229            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
230            if error.is_null() {
231                Ok(())
232            } else {
233                Err(from_glib_full(error))
234            }
235        }
236    }
237
238    #[doc(alias = "soup_server_listen_all")]
239    fn listen_all(&self, port: u32, options: ServerListenOptions) -> Result<(), glib::Error> {
240        unsafe {
241            let mut error = std::ptr::null_mut();
242            let is_ok = ffi::soup_server_listen_all(
243                self.as_ref().to_glib_none().0,
244                port,
245                options.into_glib(),
246                &mut error,
247            );
248            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
249            if error.is_null() {
250                Ok(())
251            } else {
252                Err(from_glib_full(error))
253            }
254        }
255    }
256
257    #[doc(alias = "soup_server_listen_local")]
258    fn listen_local(&self, port: u32, options: ServerListenOptions) -> Result<(), glib::Error> {
259        unsafe {
260            let mut error = std::ptr::null_mut();
261            let is_ok = ffi::soup_server_listen_local(
262                self.as_ref().to_glib_none().0,
263                port,
264                options.into_glib(),
265                &mut error,
266            );
267            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
268            if error.is_null() {
269                Ok(())
270            } else {
271                Err(from_glib_full(error))
272            }
273        }
274    }
275
276    #[doc(alias = "soup_server_listen_socket")]
277    fn listen_socket(
278        &self,
279        socket: &impl IsA<gio::Socket>,
280        options: ServerListenOptions,
281    ) -> Result<(), glib::Error> {
282        unsafe {
283            let mut error = std::ptr::null_mut();
284            let is_ok = ffi::soup_server_listen_socket(
285                self.as_ref().to_glib_none().0,
286                socket.as_ref().to_glib_none().0,
287                options.into_glib(),
288                &mut error,
289            );
290            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
291            if error.is_null() {
292                Ok(())
293            } else {
294                Err(from_glib_full(error))
295            }
296        }
297    }
298
299    #[cfg_attr(feature = "v3_2", deprecated = "Since 3.2")]
300    #[allow(deprecated)]
301    #[doc(alias = "soup_server_pause_message")]
302    fn pause_message(&self, msg: &ServerMessage) {
303        unsafe {
304            ffi::soup_server_pause_message(self.as_ref().to_glib_none().0, msg.to_glib_none().0);
305        }
306    }
307
308    #[doc(alias = "soup_server_remove_auth_domain")]
309    fn remove_auth_domain(&self, auth_domain: &impl IsA<AuthDomain>) {
310        unsafe {
311            ffi::soup_server_remove_auth_domain(
312                self.as_ref().to_glib_none().0,
313                auth_domain.as_ref().to_glib_none().0,
314            );
315        }
316    }
317
318    #[doc(alias = "soup_server_remove_handler")]
319    fn remove_handler(&self, path: &str) {
320        unsafe {
321            ffi::soup_server_remove_handler(self.as_ref().to_glib_none().0, path.to_glib_none().0);
322        }
323    }
324
325    #[doc(alias = "soup_server_remove_websocket_extension")]
326    fn remove_websocket_extension(&self, extension_type: glib::types::Type) {
327        unsafe {
328            ffi::soup_server_remove_websocket_extension(
329                self.as_ref().to_glib_none().0,
330                extension_type.into_glib(),
331            );
332        }
333    }
334
335    #[doc(alias = "soup_server_set_tls_auth_mode")]
336    #[doc(alias = "tls-auth-mode")]
337    fn set_tls_auth_mode(&self, mode: gio::TlsAuthenticationMode) {
338        unsafe {
339            ffi::soup_server_set_tls_auth_mode(self.as_ref().to_glib_none().0, mode.into_glib());
340        }
341    }
342
343    #[doc(alias = "soup_server_set_tls_certificate")]
344    #[doc(alias = "tls-certificate")]
345    fn set_tls_certificate(&self, certificate: &impl IsA<gio::TlsCertificate>) {
346        unsafe {
347            ffi::soup_server_set_tls_certificate(
348                self.as_ref().to_glib_none().0,
349                certificate.as_ref().to_glib_none().0,
350            );
351        }
352    }
353
354    #[doc(alias = "soup_server_set_tls_database")]
355    #[doc(alias = "tls-database")]
356    fn set_tls_database(&self, tls_database: &impl IsA<gio::TlsDatabase>) {
357        unsafe {
358            ffi::soup_server_set_tls_database(
359                self.as_ref().to_glib_none().0,
360                tls_database.as_ref().to_glib_none().0,
361            );
362        }
363    }
364
365    #[cfg_attr(feature = "v3_2", deprecated = "Since 3.2")]
366    #[allow(deprecated)]
367    #[doc(alias = "soup_server_unpause_message")]
368    fn unpause_message(&self, msg: &ServerMessage) {
369        unsafe {
370            ffi::soup_server_unpause_message(self.as_ref().to_glib_none().0, msg.to_glib_none().0);
371        }
372    }
373
374    #[doc(alias = "raw-paths")]
375    fn is_raw_paths(&self) -> bool {
376        ObjectExt::property(self.as_ref(), "raw-paths")
377    }
378
379    #[doc(alias = "server-header")]
380    fn server_header(&self) -> Option<glib::GString> {
381        ObjectExt::property(self.as_ref(), "server-header")
382    }
383
384    #[doc(alias = "server-header")]
385    fn set_server_header(&self, server_header: Option<&str>) {
386        ObjectExt::set_property(self.as_ref(), "server-header", server_header)
387    }
388
389    #[doc(alias = "request-aborted")]
390    fn connect_request_aborted<F: Fn(&Self, &ServerMessage) + 'static>(
391        &self,
392        f: F,
393    ) -> SignalHandlerId {
394        unsafe extern "C" fn request_aborted_trampoline<
395            P: IsA<Server>,
396            F: Fn(&P, &ServerMessage) + 'static,
397        >(
398            this: *mut ffi::SoupServer,
399            message: *mut ffi::SoupServerMessage,
400            f: glib::ffi::gpointer,
401        ) {
402            let f: &F = &*(f as *const F);
403            f(
404                Server::from_glib_borrow(this).unsafe_cast_ref(),
405                &from_glib_borrow(message),
406            )
407        }
408        unsafe {
409            let f: Box_<F> = Box_::new(f);
410            connect_raw(
411                self.as_ptr() as *mut _,
412                b"request-aborted\0".as_ptr() as *const _,
413                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
414                    request_aborted_trampoline::<Self, F> as *const (),
415                )),
416                Box_::into_raw(f),
417            )
418        }
419    }
420
421    #[doc(alias = "request-finished")]
422    fn connect_request_finished<F: Fn(&Self, &ServerMessage) + 'static>(
423        &self,
424        f: F,
425    ) -> SignalHandlerId {
426        unsafe extern "C" fn request_finished_trampoline<
427            P: IsA<Server>,
428            F: Fn(&P, &ServerMessage) + 'static,
429        >(
430            this: *mut ffi::SoupServer,
431            message: *mut ffi::SoupServerMessage,
432            f: glib::ffi::gpointer,
433        ) {
434            let f: &F = &*(f as *const F);
435            f(
436                Server::from_glib_borrow(this).unsafe_cast_ref(),
437                &from_glib_borrow(message),
438            )
439        }
440        unsafe {
441            let f: Box_<F> = Box_::new(f);
442            connect_raw(
443                self.as_ptr() as *mut _,
444                b"request-finished\0".as_ptr() as *const _,
445                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
446                    request_finished_trampoline::<Self, F> as *const (),
447                )),
448                Box_::into_raw(f),
449            )
450        }
451    }
452
453    #[doc(alias = "request-read")]
454    fn connect_request_read<F: Fn(&Self, &ServerMessage) + 'static>(
455        &self,
456        f: F,
457    ) -> SignalHandlerId {
458        unsafe extern "C" fn request_read_trampoline<
459            P: IsA<Server>,
460            F: Fn(&P, &ServerMessage) + 'static,
461        >(
462            this: *mut ffi::SoupServer,
463            message: *mut ffi::SoupServerMessage,
464            f: glib::ffi::gpointer,
465        ) {
466            let f: &F = &*(f as *const F);
467            f(
468                Server::from_glib_borrow(this).unsafe_cast_ref(),
469                &from_glib_borrow(message),
470            )
471        }
472        unsafe {
473            let f: Box_<F> = Box_::new(f);
474            connect_raw(
475                self.as_ptr() as *mut _,
476                b"request-read\0".as_ptr() as *const _,
477                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
478                    request_read_trampoline::<Self, F> as *const (),
479                )),
480                Box_::into_raw(f),
481            )
482        }
483    }
484
485    #[doc(alias = "request-started")]
486    fn connect_request_started<F: Fn(&Self, &ServerMessage) + 'static>(
487        &self,
488        f: F,
489    ) -> SignalHandlerId {
490        unsafe extern "C" fn request_started_trampoline<
491            P: IsA<Server>,
492            F: Fn(&P, &ServerMessage) + 'static,
493        >(
494            this: *mut ffi::SoupServer,
495            message: *mut ffi::SoupServerMessage,
496            f: glib::ffi::gpointer,
497        ) {
498            let f: &F = &*(f as *const F);
499            f(
500                Server::from_glib_borrow(this).unsafe_cast_ref(),
501                &from_glib_borrow(message),
502            )
503        }
504        unsafe {
505            let f: Box_<F> = Box_::new(f);
506            connect_raw(
507                self.as_ptr() as *mut _,
508                b"request-started\0".as_ptr() as *const _,
509                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
510                    request_started_trampoline::<Self, F> as *const (),
511                )),
512                Box_::into_raw(f),
513            )
514        }
515    }
516
517    #[doc(alias = "server-header")]
518    fn connect_server_header_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
519        unsafe extern "C" fn notify_server_header_trampoline<
520            P: IsA<Server>,
521            F: Fn(&P) + 'static,
522        >(
523            this: *mut ffi::SoupServer,
524            _param_spec: glib::ffi::gpointer,
525            f: glib::ffi::gpointer,
526        ) {
527            let f: &F = &*(f as *const F);
528            f(Server::from_glib_borrow(this).unsafe_cast_ref())
529        }
530        unsafe {
531            let f: Box_<F> = Box_::new(f);
532            connect_raw(
533                self.as_ptr() as *mut _,
534                b"notify::server-header\0".as_ptr() as *const _,
535                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
536                    notify_server_header_trampoline::<Self, F> as *const (),
537                )),
538                Box_::into_raw(f),
539            )
540        }
541    }
542
543    #[doc(alias = "tls-auth-mode")]
544    fn connect_tls_auth_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
545        unsafe extern "C" fn notify_tls_auth_mode_trampoline<
546            P: IsA<Server>,
547            F: Fn(&P) + 'static,
548        >(
549            this: *mut ffi::SoupServer,
550            _param_spec: glib::ffi::gpointer,
551            f: glib::ffi::gpointer,
552        ) {
553            let f: &F = &*(f as *const F);
554            f(Server::from_glib_borrow(this).unsafe_cast_ref())
555        }
556        unsafe {
557            let f: Box_<F> = Box_::new(f);
558            connect_raw(
559                self.as_ptr() as *mut _,
560                b"notify::tls-auth-mode\0".as_ptr() as *const _,
561                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
562                    notify_tls_auth_mode_trampoline::<Self, F> as *const (),
563                )),
564                Box_::into_raw(f),
565            )
566        }
567    }
568
569    #[doc(alias = "tls-certificate")]
570    fn connect_tls_certificate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
571        unsafe extern "C" fn notify_tls_certificate_trampoline<
572            P: IsA<Server>,
573            F: Fn(&P) + 'static,
574        >(
575            this: *mut ffi::SoupServer,
576            _param_spec: glib::ffi::gpointer,
577            f: glib::ffi::gpointer,
578        ) {
579            let f: &F = &*(f as *const F);
580            f(Server::from_glib_borrow(this).unsafe_cast_ref())
581        }
582        unsafe {
583            let f: Box_<F> = Box_::new(f);
584            connect_raw(
585                self.as_ptr() as *mut _,
586                b"notify::tls-certificate\0".as_ptr() as *const _,
587                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
588                    notify_tls_certificate_trampoline::<Self, F> as *const (),
589                )),
590                Box_::into_raw(f),
591            )
592        }
593    }
594
595    #[doc(alias = "tls-database")]
596    fn connect_tls_database_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
597        unsafe extern "C" fn notify_tls_database_trampoline<P: IsA<Server>, F: Fn(&P) + 'static>(
598            this: *mut ffi::SoupServer,
599            _param_spec: glib::ffi::gpointer,
600            f: glib::ffi::gpointer,
601        ) {
602            let f: &F = &*(f as *const F);
603            f(Server::from_glib_borrow(this).unsafe_cast_ref())
604        }
605        unsafe {
606            let f: Box_<F> = Box_::new(f);
607            connect_raw(
608                self.as_ptr() as *mut _,
609                b"notify::tls-database\0".as_ptr() as *const _,
610                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
611                    notify_tls_database_trampoline::<Self, F> as *const (),
612                )),
613                Box_::into_raw(f),
614            )
615        }
616    }
617}
618
619impl<O: IsA<Server>> ServerExt for O {}