2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{boxed::Box as Box_, mem::transmute};
|
2019-02-04 14:56:17 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use glib::{
|
|
|
|
prelude::*,
|
|
|
|
signal::{connect_raw, SignalHandlerId},
|
|
|
|
translate::*,
|
|
|
|
};
|
2019-02-04 14:56:17 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use crate::{RTSPAuth, RTSPToken};
|
2018-02-23 02:33:37 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
mod sealed {
|
|
|
|
pub trait Sealed {}
|
|
|
|
impl<T: super::IsA<super::RTSPAuth>> Sealed for T {}
|
2018-02-23 02:33:37 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
pub trait RTSPAuthExtManual: sealed::Sealed + IsA<RTSPAuth> + 'static {
|
|
|
|
#[doc(alias = "gst_rtsp_auth_set_default_token")]
|
2019-05-23 18:19:24 +00:00
|
|
|
fn set_default_token(&self, mut token: Option<&mut RTSPToken>) {
|
2018-02-23 02:33:37 +00:00
|
|
|
unsafe {
|
2020-11-22 10:45:51 +00:00
|
|
|
ffi::gst_rtsp_auth_set_default_token(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
token.to_glib_none_mut().0,
|
|
|
|
);
|
2018-02-23 02:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-04 14:56:17 +00:00
|
|
|
|
|
|
|
fn connect_accept_certificate<
|
|
|
|
F: Fn(
|
|
|
|
&Self,
|
|
|
|
&gio::TlsConnection,
|
|
|
|
&gio::TlsCertificate,
|
|
|
|
gio::TlsCertificateFlags,
|
|
|
|
) -> Result<(), gst::LoggableError>
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
>(
|
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
|
|
|
unsafe {
|
|
|
|
let f: Box_<F> = Box_::new(f);
|
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"accept-certificate\0".as_ptr() as *const _,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
|
|
accept_certificate_trampoline::<Self, F> as *const (),
|
|
|
|
)),
|
2019-02-04 14:56:17 +00:00
|
|
|
Box_::into_raw(f),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
impl<O: IsA<RTSPAuth>> RTSPAuthExtManual for O {}
|
|
|
|
|
2019-02-04 14:56:17 +00:00
|
|
|
unsafe extern "C" fn accept_certificate_trampoline<
|
|
|
|
P,
|
|
|
|
F: Fn(
|
|
|
|
&P,
|
|
|
|
&gio::TlsConnection,
|
|
|
|
&gio::TlsCertificate,
|
|
|
|
gio::TlsCertificateFlags,
|
|
|
|
) -> Result<(), gst::LoggableError>
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
>(
|
2020-11-22 10:45:51 +00:00
|
|
|
this: *mut ffi::GstRTSPAuth,
|
|
|
|
connection: *mut gio::ffi::GTlsConnection,
|
|
|
|
peer_cert: *mut gio::ffi::GTlsCertificate,
|
|
|
|
errors: gio::ffi::GTlsCertificateFlags,
|
|
|
|
f: glib::ffi::gpointer,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-02-04 14:56:17 +00:00
|
|
|
where
|
|
|
|
P: IsA<RTSPAuth>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let f: &F = &*(f as *const F);
|
2019-02-04 14:56:17 +00:00
|
|
|
match f(
|
2021-07-30 10:19:24 +00:00
|
|
|
RTSPAuth::from_glib_borrow(this).unsafe_cast_ref(),
|
2019-02-04 14:56:17 +00:00
|
|
|
&from_glib_borrow(connection),
|
|
|
|
&from_glib_borrow(peer_cert),
|
|
|
|
from_glib(errors),
|
|
|
|
) {
|
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
|
|
|
err.log();
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-02-23 02:33:37 +00:00
|
|
|
}
|