1#![allow(deprecated)]
6
7use crate::{ffi, AuthDomain, ServerListenOptions, ServerMessage};
8use glib::{
9 object::ObjectType as _,
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
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 let f: &F = &*(f as *const F);
400 f(
401 Server::from_glib_borrow(this).unsafe_cast_ref(),
402 &from_glib_borrow(message),
403 )
404 }
405 unsafe {
406 let f: Box_<F> = Box_::new(f);
407 connect_raw(
408 self.as_ptr() as *mut _,
409 c"request-aborted".as_ptr() as *const _,
410 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
411 request_aborted_trampoline::<Self, F> as *const (),
412 )),
413 Box_::into_raw(f),
414 )
415 }
416 }
417
418 #[doc(alias = "request-finished")]
419 fn connect_request_finished<F: Fn(&Self, &ServerMessage) + 'static>(
420 &self,
421 f: F,
422 ) -> SignalHandlerId {
423 unsafe extern "C" fn request_finished_trampoline<
424 P: IsA<Server>,
425 F: Fn(&P, &ServerMessage) + 'static,
426 >(
427 this: *mut ffi::SoupServer,
428 message: *mut ffi::SoupServerMessage,
429 f: glib::ffi::gpointer,
430 ) {
431 let f: &F = &*(f as *const F);
432 f(
433 Server::from_glib_borrow(this).unsafe_cast_ref(),
434 &from_glib_borrow(message),
435 )
436 }
437 unsafe {
438 let f: Box_<F> = Box_::new(f);
439 connect_raw(
440 self.as_ptr() as *mut _,
441 c"request-finished".as_ptr() as *const _,
442 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
443 request_finished_trampoline::<Self, F> as *const (),
444 )),
445 Box_::into_raw(f),
446 )
447 }
448 }
449
450 #[doc(alias = "request-read")]
451 fn connect_request_read<F: Fn(&Self, &ServerMessage) + 'static>(
452 &self,
453 f: F,
454 ) -> SignalHandlerId {
455 unsafe extern "C" fn request_read_trampoline<
456 P: IsA<Server>,
457 F: Fn(&P, &ServerMessage) + 'static,
458 >(
459 this: *mut ffi::SoupServer,
460 message: *mut ffi::SoupServerMessage,
461 f: glib::ffi::gpointer,
462 ) {
463 let f: &F = &*(f as *const F);
464 f(
465 Server::from_glib_borrow(this).unsafe_cast_ref(),
466 &from_glib_borrow(message),
467 )
468 }
469 unsafe {
470 let f: Box_<F> = Box_::new(f);
471 connect_raw(
472 self.as_ptr() as *mut _,
473 c"request-read".as_ptr() as *const _,
474 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
475 request_read_trampoline::<Self, F> as *const (),
476 )),
477 Box_::into_raw(f),
478 )
479 }
480 }
481
482 #[doc(alias = "request-started")]
483 fn connect_request_started<F: Fn(&Self, &ServerMessage) + 'static>(
484 &self,
485 f: F,
486 ) -> SignalHandlerId {
487 unsafe extern "C" fn request_started_trampoline<
488 P: IsA<Server>,
489 F: Fn(&P, &ServerMessage) + 'static,
490 >(
491 this: *mut ffi::SoupServer,
492 message: *mut ffi::SoupServerMessage,
493 f: glib::ffi::gpointer,
494 ) {
495 let f: &F = &*(f as *const F);
496 f(
497 Server::from_glib_borrow(this).unsafe_cast_ref(),
498 &from_glib_borrow(message),
499 )
500 }
501 unsafe {
502 let f: Box_<F> = Box_::new(f);
503 connect_raw(
504 self.as_ptr() as *mut _,
505 c"request-started".as_ptr() as *const _,
506 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
507 request_started_trampoline::<Self, F> as *const (),
508 )),
509 Box_::into_raw(f),
510 )
511 }
512 }
513
514 #[doc(alias = "server-header")]
515 fn connect_server_header_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
516 unsafe extern "C" fn notify_server_header_trampoline<
517 P: IsA<Server>,
518 F: Fn(&P) + 'static,
519 >(
520 this: *mut ffi::SoupServer,
521 _param_spec: glib::ffi::gpointer,
522 f: glib::ffi::gpointer,
523 ) {
524 let f: &F = &*(f as *const F);
525 f(Server::from_glib_borrow(this).unsafe_cast_ref())
526 }
527 unsafe {
528 let f: Box_<F> = Box_::new(f);
529 connect_raw(
530 self.as_ptr() as *mut _,
531 c"notify::server-header".as_ptr() as *const _,
532 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
533 notify_server_header_trampoline::<Self, F> as *const (),
534 )),
535 Box_::into_raw(f),
536 )
537 }
538 }
539
540 #[doc(alias = "tls-auth-mode")]
541 fn connect_tls_auth_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
542 unsafe extern "C" fn notify_tls_auth_mode_trampoline<
543 P: IsA<Server>,
544 F: Fn(&P) + 'static,
545 >(
546 this: *mut ffi::SoupServer,
547 _param_spec: glib::ffi::gpointer,
548 f: glib::ffi::gpointer,
549 ) {
550 let f: &F = &*(f as *const F);
551 f(Server::from_glib_borrow(this).unsafe_cast_ref())
552 }
553 unsafe {
554 let f: Box_<F> = Box_::new(f);
555 connect_raw(
556 self.as_ptr() as *mut _,
557 c"notify::tls-auth-mode".as_ptr() as *const _,
558 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
559 notify_tls_auth_mode_trampoline::<Self, F> as *const (),
560 )),
561 Box_::into_raw(f),
562 )
563 }
564 }
565
566 #[doc(alias = "tls-certificate")]
567 fn connect_tls_certificate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
568 unsafe extern "C" fn notify_tls_certificate_trampoline<
569 P: IsA<Server>,
570 F: Fn(&P) + 'static,
571 >(
572 this: *mut ffi::SoupServer,
573 _param_spec: glib::ffi::gpointer,
574 f: glib::ffi::gpointer,
575 ) {
576 let f: &F = &*(f as *const F);
577 f(Server::from_glib_borrow(this).unsafe_cast_ref())
578 }
579 unsafe {
580 let f: Box_<F> = Box_::new(f);
581 connect_raw(
582 self.as_ptr() as *mut _,
583 c"notify::tls-certificate".as_ptr() as *const _,
584 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
585 notify_tls_certificate_trampoline::<Self, F> as *const (),
586 )),
587 Box_::into_raw(f),
588 )
589 }
590 }
591
592 #[doc(alias = "tls-database")]
593 fn connect_tls_database_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
594 unsafe extern "C" fn notify_tls_database_trampoline<P: IsA<Server>, F: Fn(&P) + 'static>(
595 this: *mut ffi::SoupServer,
596 _param_spec: glib::ffi::gpointer,
597 f: glib::ffi::gpointer,
598 ) {
599 let f: &F = &*(f as *const F);
600 f(Server::from_glib_borrow(this).unsafe_cast_ref())
601 }
602 unsafe {
603 let f: Box_<F> = Box_::new(f);
604 connect_raw(
605 self.as_ptr() as *mut _,
606 c"notify::tls-database".as_ptr() as *const _,
607 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
608 notify_tls_database_trampoline::<Self, F> as *const (),
609 )),
610 Box_::into_raw(f),
611 )
612 }
613 }
614}
615
616impl<O: IsA<Server>> ServerExt for O {}