gstreamer_rtsp_server/
rtsp_auth.rs
1use std::{boxed::Box as Box_, mem::transmute};
4
5use glib::{
6 prelude::*,
7 signal::{connect_raw, SignalHandlerId},
8 translate::*,
9};
10
11use crate::{ffi, RTSPAuth, RTSPToken};
12
13pub trait RTSPAuthExtManual: IsA<RTSPAuth> + 'static {
14 #[doc(alias = "gst_rtsp_auth_set_default_token")]
19 fn set_default_token(&self, mut token: Option<&mut RTSPToken>) {
20 unsafe {
21 ffi::gst_rtsp_auth_set_default_token(
22 self.as_ref().to_glib_none().0,
23 token.to_glib_none_mut().0,
24 );
25 }
26 }
27
28 fn connect_accept_certificate<
29 F: Fn(
30 &Self,
31 &gio::TlsConnection,
32 &gio::TlsCertificate,
33 gio::TlsCertificateFlags,
34 ) -> Result<(), gst::LoggableError>
35 + Send
36 + Sync
37 + 'static,
38 >(
39 &self,
40 f: F,
41 ) -> SignalHandlerId {
42 unsafe {
43 let f: Box_<F> = Box_::new(f);
44 connect_raw(
45 self.as_ptr() as *mut _,
46 b"accept-certificate\0".as_ptr() as *const _,
47 Some(transmute::<*const (), unsafe extern "C" fn()>(
48 accept_certificate_trampoline::<Self, F> as *const (),
49 )),
50 Box_::into_raw(f),
51 )
52 }
53 }
54}
55
56impl<O: IsA<RTSPAuth>> RTSPAuthExtManual for O {}
57
58unsafe extern "C" fn accept_certificate_trampoline<
59 P,
60 F: Fn(
61 &P,
62 &gio::TlsConnection,
63 &gio::TlsCertificate,
64 gio::TlsCertificateFlags,
65 ) -> Result<(), gst::LoggableError>
66 + Send
67 + Sync
68 + 'static,
69>(
70 this: *mut ffi::GstRTSPAuth,
71 connection: *mut gio::ffi::GTlsConnection,
72 peer_cert: *mut gio::ffi::GTlsCertificate,
73 errors: gio::ffi::GTlsCertificateFlags,
74 f: glib::ffi::gpointer,
75) -> glib::ffi::gboolean
76where
77 P: IsA<RTSPAuth>,
78{
79 let f: &F = &*(f as *const F);
80 match f(
81 RTSPAuth::from_glib_borrow(this).unsafe_cast_ref(),
82 &from_glib_borrow(connection),
83 &from_glib_borrow(peer_cert),
84 from_glib(errors),
85 ) {
86 Ok(()) => true,
87 Err(err) => {
88 err.log();
89 false
90 }
91 }
92 .into_glib()
93}