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