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
101/// Trait containing all [`struct@RTSPAuth`] methods.
102///
103/// # Implementors
104///
105/// [`RTSPAuth`][struct@crate::RTSPAuth]
106pub trait RTSPAuthExt: IsA<RTSPAuth> + 'static {
107 /// Add a basic token for the default authentication algorithm that
108 /// enables the client with privileges listed in `token`.
109 /// ## `basic`
110 /// the basic token
111 /// ## `token`
112 /// authorisation token
113 #[doc(alias = "gst_rtsp_auth_add_basic")]
114 fn add_basic(&self, basic: &str, token: &RTSPToken) {
115 unsafe {
116 ffi::gst_rtsp_auth_add_basic(
117 self.as_ref().to_glib_none().0,
118 basic.to_glib_none().0,
119 token.to_glib_none().0,
120 );
121 }
122 }
123
124 /// Add a digest `user` and `pass` for the default authentication algorithm that
125 /// enables the client with privileges listed in `token`.
126 /// ## `user`
127 /// the digest user name
128 /// ## `pass`
129 /// the digest password
130 /// ## `token`
131 /// authorisation token
132 #[doc(alias = "gst_rtsp_auth_add_digest")]
133 fn add_digest(&self, user: &str, pass: &str, token: &RTSPToken) {
134 unsafe {
135 ffi::gst_rtsp_auth_add_digest(
136 self.as_ref().to_glib_none().0,
137 user.to_glib_none().0,
138 pass.to_glib_none().0,
139 token.to_glib_none().0,
140 );
141 }
142 }
143
144 /// Get the default token for `self`. This token will be used for unauthenticated
145 /// users.
146 ///
147 /// # Returns
148 ///
149 /// the [`RTSPToken`][crate::RTSPToken] of `self`. `gst_rtsp_token_unref()` after
150 /// usage.
151 #[doc(alias = "gst_rtsp_auth_get_default_token")]
152 #[doc(alias = "get_default_token")]
153 fn default_token(&self) -> Option<RTSPToken> {
154 unsafe {
155 from_glib_full(ffi::gst_rtsp_auth_get_default_token(
156 self.as_ref().to_glib_none().0,
157 ))
158 }
159 }
160
161 ///
162 /// # Returns
163 ///
164 /// the `realm` of `self`
165 #[cfg(feature = "v1_16")]
166 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
167 #[doc(alias = "gst_rtsp_auth_get_realm")]
168 #[doc(alias = "get_realm")]
169 fn realm(&self) -> Option<glib::GString> {
170 unsafe { from_glib_full(ffi::gst_rtsp_auth_get_realm(self.as_ref().to_glib_none().0)) }
171 }
172
173 /// Gets the supported authentication methods of `self`.
174 ///
175 /// # Returns
176 ///
177 /// The supported authentication methods
178 #[doc(alias = "gst_rtsp_auth_get_supported_methods")]
179 #[doc(alias = "get_supported_methods")]
180 fn supported_methods(&self) -> gst_rtsp::RTSPAuthMethod {
181 unsafe {
182 from_glib(ffi::gst_rtsp_auth_get_supported_methods(
183 self.as_ref().to_glib_none().0,
184 ))
185 }
186 }
187
188 /// Get the [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode].
189 ///
190 /// # Returns
191 ///
192 /// the [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode].
193 #[doc(alias = "gst_rtsp_auth_get_tls_authentication_mode")]
194 #[doc(alias = "get_tls_authentication_mode")]
195 fn tls_authentication_mode(&self) -> gio::TlsAuthenticationMode {
196 unsafe {
197 from_glib(ffi::gst_rtsp_auth_get_tls_authentication_mode(
198 self.as_ref().to_glib_none().0,
199 ))
200 }
201 }
202
203 /// Get the [`gio::TlsCertificate`][crate::gio::TlsCertificate] used for negotiating TLS `self`.
204 ///
205 /// # Returns
206 ///
207 /// the [`gio::TlsCertificate`][crate::gio::TlsCertificate] of `self`. `g_object_unref()` after
208 /// usage.
209 #[doc(alias = "gst_rtsp_auth_get_tls_certificate")]
210 #[doc(alias = "get_tls_certificate")]
211 fn tls_certificate(&self) -> Option<gio::TlsCertificate> {
212 unsafe {
213 from_glib_full(ffi::gst_rtsp_auth_get_tls_certificate(
214 self.as_ref().to_glib_none().0,
215 ))
216 }
217 }
218
219 /// Get the [`gio::TlsDatabase`][crate::gio::TlsDatabase] used for verifying client certificate.
220 ///
221 /// # Returns
222 ///
223 /// the [`gio::TlsDatabase`][crate::gio::TlsDatabase] of `self`. `g_object_unref()` after
224 /// usage.
225 #[doc(alias = "gst_rtsp_auth_get_tls_database")]
226 #[doc(alias = "get_tls_database")]
227 fn tls_database(&self) -> Option<gio::TlsDatabase> {
228 unsafe {
229 from_glib_full(ffi::gst_rtsp_auth_get_tls_database(
230 self.as_ref().to_glib_none().0,
231 ))
232 }
233 }
234
235 /// Parse the contents of the file at `path` and enable the privileges
236 /// listed in `token` for the users it describes.
237 ///
238 /// The format of the file is expected to match the format described by
239 /// <https://en.wikipedia.org/wiki/Digest_access_authentication`The_.htdigest_file`>,
240 /// as output by the `htdigest` command.
241 /// ## `path`
242 /// Path to the htdigest file
243 /// ## `token`
244 /// authorisation token
245 ///
246 /// # Returns
247 ///
248 /// [`true`] if the file was successfully parsed, [`false`] otherwise.
249 #[cfg(feature = "v1_16")]
250 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
251 #[doc(alias = "gst_rtsp_auth_parse_htdigest")]
252 fn parse_htdigest(&self, path: impl AsRef<std::path::Path>, token: &RTSPToken) -> bool {
253 unsafe {
254 from_glib(ffi::gst_rtsp_auth_parse_htdigest(
255 self.as_ref().to_glib_none().0,
256 path.as_ref().to_glib_none().0,
257 token.to_glib_none().0,
258 ))
259 }
260 }
261
262 /// Removes `basic` authentication token.
263 /// ## `basic`
264 /// the basic token
265 #[doc(alias = "gst_rtsp_auth_remove_basic")]
266 fn remove_basic(&self, basic: &str) {
267 unsafe {
268 ffi::gst_rtsp_auth_remove_basic(self.as_ref().to_glib_none().0, basic.to_glib_none().0);
269 }
270 }
271
272 /// Removes a digest user.
273 /// ## `user`
274 /// the digest user name
275 #[doc(alias = "gst_rtsp_auth_remove_digest")]
276 fn remove_digest(&self, user: &str) {
277 unsafe {
278 ffi::gst_rtsp_auth_remove_digest(self.as_ref().to_glib_none().0, user.to_glib_none().0);
279 }
280 }
281
282 /// Set the `realm` of `self`
283 /// ## `realm`
284 /// The realm to set
285 #[cfg(feature = "v1_16")]
286 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
287 #[doc(alias = "gst_rtsp_auth_set_realm")]
288 fn set_realm(&self, realm: Option<&str>) {
289 unsafe {
290 ffi::gst_rtsp_auth_set_realm(self.as_ref().to_glib_none().0, realm.to_glib_none().0);
291 }
292 }
293
294 /// Sets the supported authentication `methods` for `self`.
295 /// ## `methods`
296 /// supported methods
297 #[doc(alias = "gst_rtsp_auth_set_supported_methods")]
298 fn set_supported_methods(&self, methods: gst_rtsp::RTSPAuthMethod) {
299 unsafe {
300 ffi::gst_rtsp_auth_set_supported_methods(
301 self.as_ref().to_glib_none().0,
302 methods.into_glib(),
303 );
304 }
305 }
306
307 /// The [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode] to set on the underlying GTlsServerConnection.
308 /// When set to another value than [`gio::TlsAuthenticationMode::None`][crate::gio::TlsAuthenticationMode::None],
309 /// [`accept-certificate`][struct@crate::RTSPAuth#accept-certificate] signal will be emitted and must be handled.
310 /// ## `mode`
311 /// a [`gio::TlsAuthenticationMode`][crate::gio::TlsAuthenticationMode]
312 #[doc(alias = "gst_rtsp_auth_set_tls_authentication_mode")]
313 fn set_tls_authentication_mode(&self, mode: gio::TlsAuthenticationMode) {
314 unsafe {
315 ffi::gst_rtsp_auth_set_tls_authentication_mode(
316 self.as_ref().to_glib_none().0,
317 mode.into_glib(),
318 );
319 }
320 }
321
322 /// Set the TLS certificate for the auth. Client connections will only
323 /// be accepted when TLS is negotiated.
324 /// ## `cert`
325 /// a [`gio::TlsCertificate`][crate::gio::TlsCertificate]
326 #[doc(alias = "gst_rtsp_auth_set_tls_certificate")]
327 fn set_tls_certificate(&self, cert: Option<&impl IsA<gio::TlsCertificate>>) {
328 unsafe {
329 ffi::gst_rtsp_auth_set_tls_certificate(
330 self.as_ref().to_glib_none().0,
331 cert.map(|p| p.as_ref()).to_glib_none().0,
332 );
333 }
334 }
335
336 /// Sets the certificate database that is used to verify peer certificates.
337 /// If set to [`None`] (the default), then peer certificate validation will always
338 /// set the [`gio::TlsCertificateFlags::UNKNOWN_CA`][crate::gio::TlsCertificateFlags::UNKNOWN_CA] error.
339 /// ## `database`
340 /// a [`gio::TlsDatabase`][crate::gio::TlsDatabase]
341 #[doc(alias = "gst_rtsp_auth_set_tls_database")]
342 fn set_tls_database(&self, database: Option<&impl IsA<gio::TlsDatabase>>) {
343 unsafe {
344 ffi::gst_rtsp_auth_set_tls_database(
345 self.as_ref().to_glib_none().0,
346 database.map(|p| p.as_ref()).to_glib_none().0,
347 );
348 }
349 }
350
351 /// Emitted during the TLS handshake after the client certificate has
352 /// been received. See also [`set_tls_authentication_mode()`][Self::set_tls_authentication_mode()].
353 /// ## `connection`
354 /// a [`gio::TlsConnection`][crate::gio::TlsConnection]
355 /// ## `peer_cert`
356 /// the peer's [`gio::TlsCertificate`][crate::gio::TlsCertificate]
357 /// ## `errors`
358 /// the problems with `peer_cert`.
359 ///
360 /// # Returns
361 ///
362 /// [`true`] to accept `peer_cert` (which will also
363 /// immediately end the signal emission). [`false`] to allow the signal
364 /// emission to continue, which will cause the handshake to fail if
365 /// no one else overrides it.
366 #[doc(alias = "accept-certificate")]
367 fn connect_accept_certificate<
368 F: Fn(&Self, &gio::TlsConnection, &gio::TlsCertificate, gio::TlsCertificateFlags) -> bool
369 + Send
370 + Sync
371 + 'static,
372 >(
373 &self,
374 f: F,
375 ) -> SignalHandlerId {
376 unsafe extern "C" fn accept_certificate_trampoline<
377 P: IsA<RTSPAuth>,
378 F: Fn(&P, &gio::TlsConnection, &gio::TlsCertificate, gio::TlsCertificateFlags) -> bool
379 + Send
380 + Sync
381 + 'static,
382 >(
383 this: *mut ffi::GstRTSPAuth,
384 connection: *mut gio::ffi::GTlsConnection,
385 peer_cert: *mut gio::ffi::GTlsCertificate,
386 errors: gio::ffi::GTlsCertificateFlags,
387 f: glib::ffi::gpointer,
388 ) -> glib::ffi::gboolean {
389 let f: &F = &*(f as *const F);
390 f(
391 RTSPAuth::from_glib_borrow(this).unsafe_cast_ref(),
392 &from_glib_borrow(connection),
393 &from_glib_borrow(peer_cert),
394 from_glib(errors),
395 )
396 .into_glib()
397 }
398 unsafe {
399 let f: Box_<F> = Box_::new(f);
400 connect_raw(
401 self.as_ptr() as *mut _,
402 c"accept-certificate".as_ptr() as *const _,
403 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
404 accept_certificate_trampoline::<Self, F> as *const (),
405 )),
406 Box_::into_raw(f),
407 )
408 }
409 }
410}
411
412impl<O: IsA<RTSPAuth>> RTSPAuthExt for O {}