gstreamer_rtsp_server/auto/rtsp_auth.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, RTSPToken};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// The authentication structure.
17 ///
18 /// ## Signals
19 ///
20 ///
21 /// #### `accept-certificate`
22 /// Emitted during the TLS handshake after the client certificate has
23 /// been received. See also [`RTSPAuthExt::set_tls_authentication_mode()`][crate::prelude::RTSPAuthExt::set_tls_authentication_mode()].
24 ///
25 ///
26 ///
27 /// # Implements
28 ///
29 /// [`RTSPAuthExt`][trait@crate::prelude::RTSPAuthExt], [`trait@glib::ObjectExt`], [`RTSPAuthExtManual`][trait@crate::prelude::RTSPAuthExtManual]
30 #[doc(alias = "GstRTSPAuth")]
31 pub struct RTSPAuth(Object<ffi::GstRTSPAuth, ffi::GstRTSPAuthClass>);
32
33 match fn {
34 type_ => || ffi::gst_rtsp_auth_get_type(),
35 }
36}
37
38impl RTSPAuth {
39 pub const NONE: Option<&'static RTSPAuth> = None;
40
41 /// Create a new [`RTSPAuth`][crate::RTSPAuth] instance.
42 ///
43 /// # Returns
44 ///
45 /// a new [`RTSPAuth`][crate::RTSPAuth]
46 #[doc(alias = "gst_rtsp_auth_new")]
47 pub fn new() -> RTSPAuth {
48 assert_initialized_main_thread!();
49 unsafe { from_glib_full(ffi::gst_rtsp_auth_new()) }
50 }
51
52 /// Check if `check` is allowed in the current context.
53 /// ## `check`
54 /// the item to check
55 ///
56 /// # Returns
57 ///
58 /// FALSE if check failed.
59 #[doc(alias = "gst_rtsp_auth_check")]
60 pub fn check(check: &str) -> Result<(), glib::error::BoolError> {
61 assert_initialized_main_thread!();
62 unsafe {
63 glib::result_from_gboolean!(
64 ffi::gst_rtsp_auth_check(check.to_glib_none().0),
65 "Check failed"
66 )
67 }
68 }
69
70 /// Construct a Basic authorisation token from `user` and `pass`.
71 /// ## `user`
72 /// a userid
73 /// ## `pass`
74 /// a password
75 ///
76 /// # Returns
77 ///
78 /// the base64 encoding of the string `user`:`pass`.
79 /// `g_free()` after usage.
80 #[doc(alias = "gst_rtsp_auth_make_basic")]
81 pub fn make_basic(user: &str, pass: &str) -> glib::GString {
82 assert_initialized_main_thread!();
83 unsafe {
84 from_glib_full(ffi::gst_rtsp_auth_make_basic(
85 user.to_glib_none().0,
86 pass.to_glib_none().0,
87 ))
88 }
89 }
90}
91
92impl Default for RTSPAuth {
93 fn default() -> Self {
94 Self::new()
95 }
96}
97
98unsafe impl Send for RTSPAuth {}
99unsafe impl Sync for RTSPAuth {}
100
101mod sealed {
102 pub trait Sealed {}
103 impl<T: super::IsA<super::RTSPAuth>> Sealed for T {}
104}
105
106/// Trait containing all [`struct@RTSPAuth`] methods.
107///
108/// # Implementors
109///
110/// [`RTSPAuth`][struct@crate::RTSPAuth]
111pub trait RTSPAuthExt: IsA<RTSPAuth> + sealed::Sealed + 'static {
112 /// Add a basic token for the default authentication algorithm that
113 /// enables the client with privileges listed in `token`.
114 /// ## `basic`
115 /// the basic token
116 /// ## `token`
117 /// authorisation token
118 #[doc(alias = "gst_rtsp_auth_add_basic")]
119 fn add_basic(&self, basic: &str, token: &RTSPToken) {
120 unsafe {
121 ffi::gst_rtsp_auth_add_basic(
122 self.as_ref().to_glib_none().0,
123 basic.to_glib_none().0,
124 token.to_glib_none().0,
125 );
126 }
127 }
128
129 /// Add a digest `user` and `pass` for the default authentication algorithm that
130 /// enables the client with privileges listed in `token`.
131 /// ## `user`
132 /// the digest user name
133 /// ## `pass`
134 /// the digest password
135 /// ## `token`
136 /// authorisation token
137 #[doc(alias = "gst_rtsp_auth_add_digest")]
138 fn add_digest(&self, user: &str, pass: &str, token: &RTSPToken) {
139 unsafe {
140 ffi::gst_rtsp_auth_add_digest(
141 self.as_ref().to_glib_none().0,
142 user.to_glib_none().0,
143 pass.to_glib_none().0,
144 token.to_glib_none().0,
145 );
146 }
147 }
148
149 /// Get the default token for `self`. This token will be used for unauthenticated
150 /// users.
151 ///
152 /// # Returns
153 ///
154 /// the [`RTSPToken`][crate::RTSPToken] of `self`. `gst_rtsp_token_unref()` after
155 /// usage.
156 #[doc(alias = "gst_rtsp_auth_get_default_token")]
157 #[doc(alias = "get_default_token")]
158 fn default_token(&self) -> Option<RTSPToken> {
159 unsafe {
160 from_glib_full(ffi::gst_rtsp_auth_get_default_token(
161 self.as_ref().to_glib_none().0,
162 ))
163 }
164 }
165
166 ///
167 /// # Returns
168 ///
169 /// the `realm` of `self`
170 #[cfg(feature = "v1_16")]
171 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
172 #[doc(alias = "gst_rtsp_auth_get_realm")]
173 #[doc(alias = "get_realm")]
174 fn realm(&self) -> Option<glib::GString> {
175 unsafe { from_glib_full(ffi::gst_rtsp_auth_get_realm(self.as_ref().to_glib_none().0)) }
176 }
177
178 /// Gets the supported authentication methods of `self`.
179 ///
180 /// # Returns
181 ///
182 /// The supported authentication methods
183 #[doc(alias = "gst_rtsp_auth_get_supported_methods")]
184 #[doc(alias = "get_supported_methods")]
185 fn supported_methods(&self) -> gst_rtsp::RTSPAuthMethod {
186 unsafe {
187 from_glib(ffi::gst_rtsp_auth_get_supported_methods(
188 self.as_ref().to_glib_none().0,
189 ))
190 }
191 }
192
193 /// Get the [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode].
194 ///
195 /// # Returns
196 ///
197 /// the [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode].
198 #[doc(alias = "gst_rtsp_auth_get_tls_authentication_mode")]
199 #[doc(alias = "get_tls_authentication_mode")]
200 fn tls_authentication_mode(&self) -> gio::TlsAuthenticationMode {
201 unsafe {
202 from_glib(ffi::gst_rtsp_auth_get_tls_authentication_mode(
203 self.as_ref().to_glib_none().0,
204 ))
205 }
206 }
207
208 /// Get the [`gio::TlsCertificate`][crate::gio::TlsCertificate] used for negotiating TLS `self`.
209 ///
210 /// # Returns
211 ///
212 /// the [`gio::TlsCertificate`][crate::gio::TlsCertificate] of `self`. `g_object_unref()` after
213 /// usage.
214 #[doc(alias = "gst_rtsp_auth_get_tls_certificate")]
215 #[doc(alias = "get_tls_certificate")]
216 fn tls_certificate(&self) -> Option<gio::TlsCertificate> {
217 unsafe {
218 from_glib_full(ffi::gst_rtsp_auth_get_tls_certificate(
219 self.as_ref().to_glib_none().0,
220 ))
221 }
222 }
223
224 /// Get the [`gio::TlsDatabase`][crate::gio::TlsDatabase] used for verifying client certificate.
225 ///
226 /// # Returns
227 ///
228 /// the [`gio::TlsDatabase`][crate::gio::TlsDatabase] of `self`. `g_object_unref()` after
229 /// usage.
230 #[doc(alias = "gst_rtsp_auth_get_tls_database")]
231 #[doc(alias = "get_tls_database")]
232 fn tls_database(&self) -> Option<gio::TlsDatabase> {
233 unsafe {
234 from_glib_full(ffi::gst_rtsp_auth_get_tls_database(
235 self.as_ref().to_glib_none().0,
236 ))
237 }
238 }
239
240 /// Parse the contents of the file at `path` and enable the privileges
241 /// listed in `token` for the users it describes.
242 ///
243 /// The format of the file is expected to match the format described by
244 /// <https://en.wikipedia.org/wiki/Digest_access_authentication`The_.htdigest_file`>,
245 /// as output by the `htdigest` command.
246 /// ## `path`
247 /// Path to the htdigest file
248 /// ## `token`
249 /// authorisation token
250 ///
251 /// # Returns
252 ///
253 /// [`true`] if the file was successfully parsed, [`false`] otherwise.
254 #[cfg(feature = "v1_16")]
255 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
256 #[doc(alias = "gst_rtsp_auth_parse_htdigest")]
257 fn parse_htdigest(&self, path: impl AsRef<std::path::Path>, token: &RTSPToken) -> bool {
258 unsafe {
259 from_glib(ffi::gst_rtsp_auth_parse_htdigest(
260 self.as_ref().to_glib_none().0,
261 path.as_ref().to_glib_none().0,
262 token.to_glib_none().0,
263 ))
264 }
265 }
266
267 /// Removes `basic` authentication token.
268 /// ## `basic`
269 /// the basic token
270 #[doc(alias = "gst_rtsp_auth_remove_basic")]
271 fn remove_basic(&self, basic: &str) {
272 unsafe {
273 ffi::gst_rtsp_auth_remove_basic(self.as_ref().to_glib_none().0, basic.to_glib_none().0);
274 }
275 }
276
277 /// Removes a digest user.
278 /// ## `user`
279 /// the digest user name
280 #[doc(alias = "gst_rtsp_auth_remove_digest")]
281 fn remove_digest(&self, user: &str) {
282 unsafe {
283 ffi::gst_rtsp_auth_remove_digest(self.as_ref().to_glib_none().0, user.to_glib_none().0);
284 }
285 }
286
287 /// Set the `realm` of `self`
288 /// ## `realm`
289 /// The realm to set
290 #[cfg(feature = "v1_16")]
291 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
292 #[doc(alias = "gst_rtsp_auth_set_realm")]
293 fn set_realm(&self, realm: Option<&str>) {
294 unsafe {
295 ffi::gst_rtsp_auth_set_realm(self.as_ref().to_glib_none().0, realm.to_glib_none().0);
296 }
297 }
298
299 /// Sets the supported authentication `methods` for `self`.
300 /// ## `methods`
301 /// supported methods
302 #[doc(alias = "gst_rtsp_auth_set_supported_methods")]
303 fn set_supported_methods(&self, methods: gst_rtsp::RTSPAuthMethod) {
304 unsafe {
305 ffi::gst_rtsp_auth_set_supported_methods(
306 self.as_ref().to_glib_none().0,
307 methods.into_glib(),
308 );
309 }
310 }
311
312 /// The [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode] to set on the underlying GTlsServerConnection.
313 /// When set to another value than [`gio::TlsAuthenticationMode::None`][crate::gio::TlsAuthenticationMode::None],
314 /// [`accept-certificate`][struct@crate::RTSPAuth#accept-certificate] signal will be emitted and must be handled.
315 /// ## `mode`
316 /// a [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode]
317 #[doc(alias = "gst_rtsp_auth_set_tls_authentication_mode")]
318 fn set_tls_authentication_mode(&self, mode: gio::TlsAuthenticationMode) {
319 unsafe {
320 ffi::gst_rtsp_auth_set_tls_authentication_mode(
321 self.as_ref().to_glib_none().0,
322 mode.into_glib(),
323 );
324 }
325 }
326
327 /// Set the TLS certificate for the auth. Client connections will only
328 /// be accepted when TLS is negotiated.
329 /// ## `cert`
330 /// a [`gio::TlsCertificate`][crate::gio::TlsCertificate]
331 #[doc(alias = "gst_rtsp_auth_set_tls_certificate")]
332 fn set_tls_certificate(&self, cert: Option<&impl IsA<gio::TlsCertificate>>) {
333 unsafe {
334 ffi::gst_rtsp_auth_set_tls_certificate(
335 self.as_ref().to_glib_none().0,
336 cert.map(|p| p.as_ref()).to_glib_none().0,
337 );
338 }
339 }
340
341 /// Sets the certificate database that is used to verify peer certificates.
342 /// If set to [`None`] (the default), then peer certificate validation will always
343 /// set the [`gio::TlsCertificateFlags::UNKNOWN_CA`][crate::gio::TlsCertificateFlags::UNKNOWN_CA] error.
344 /// ## `database`
345 /// a [`gio::TlsDatabase`][crate::gio::TlsDatabase]
346 #[doc(alias = "gst_rtsp_auth_set_tls_database")]
347 fn set_tls_database(&self, database: Option<&impl IsA<gio::TlsDatabase>>) {
348 unsafe {
349 ffi::gst_rtsp_auth_set_tls_database(
350 self.as_ref().to_glib_none().0,
351 database.map(|p| p.as_ref()).to_glib_none().0,
352 );
353 }
354 }
355
356 /// Emitted during the TLS handshake after the client certificate has
357 /// been received. See also [`set_tls_authentication_mode()`][Self::set_tls_authentication_mode()].
358 /// ## `connection`
359 /// a [`gio::TlsConnection`][crate::gio::TlsConnection]
360 /// ## `peer_cert`
361 /// the peer's [`gio::TlsCertificate`][crate::gio::TlsCertificate]
362 /// ## `errors`
363 /// the problems with `peer_cert`.
364 ///
365 /// # Returns
366 ///
367 /// [`true`] to accept `peer_cert` (which will also
368 /// immediately end the signal emission). [`false`] to allow the signal
369 /// emission to continue, which will cause the handshake to fail if
370 /// no one else overrides it.
371 #[doc(alias = "accept-certificate")]
372 fn connect_accept_certificate<
373 F: Fn(&Self, &gio::TlsConnection, &gio::TlsCertificate, gio::TlsCertificateFlags) -> bool
374 + Send
375 + Sync
376 + 'static,
377 >(
378 &self,
379 f: F,
380 ) -> SignalHandlerId {
381 unsafe extern "C" fn accept_certificate_trampoline<
382 P: IsA<RTSPAuth>,
383 F: Fn(&P, &gio::TlsConnection, &gio::TlsCertificate, gio::TlsCertificateFlags) -> bool
384 + Send
385 + Sync
386 + 'static,
387 >(
388 this: *mut ffi::GstRTSPAuth,
389 connection: *mut gio::ffi::GTlsConnection,
390 peer_cert: *mut gio::ffi::GTlsCertificate,
391 errors: gio::ffi::GTlsCertificateFlags,
392 f: glib::ffi::gpointer,
393 ) -> glib::ffi::gboolean {
394 let f: &F = &*(f as *const F);
395 f(
396 RTSPAuth::from_glib_borrow(this).unsafe_cast_ref(),
397 &from_glib_borrow(connection),
398 &from_glib_borrow(peer_cert),
399 from_glib(errors),
400 )
401 .into_glib()
402 }
403 unsafe {
404 let f: Box_<F> = Box_::new(f);
405 connect_raw(
406 self.as_ptr() as *mut _,
407 b"accept-certificate\0".as_ptr() as *const _,
408 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
409 accept_certificate_trampoline::<Self, F> as *const (),
410 )),
411 Box_::into_raw(f),
412 )
413 }
414 }
415}
416
417impl<O: IsA<RTSPAuth>> RTSPAuthExt for O {}