mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 09:31:06 +00:00
rtsp-server: Add builder API for RTSPToken
for consistency with Structure
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1421>
This commit is contained in:
parent
da1f53f4c7
commit
43c82da25a
3 changed files with 48 additions and 15 deletions
|
@ -138,7 +138,11 @@ mod auth {
|
||||||
if let Some(authorization) = auth_credentials.authorization() {
|
if let Some(authorization) = auth_credentials.authorization() {
|
||||||
if let Some(user) = self.external_auth(authorization) {
|
if let Some(user) = self.external_auth(authorization) {
|
||||||
// Update context token with authenticated username
|
// Update context token with authenticated username
|
||||||
ctx.set_token(gst_rtsp_server::RTSPToken::new(&[("user", &user)]));
|
ctx.set_token(
|
||||||
|
gst_rtsp_server::RTSPToken::builder()
|
||||||
|
.field("user", user)
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,9 @@ fn main_loop() -> Result<(), Error> {
|
||||||
// Here we configure a method of authentication that we want the
|
// Here we configure a method of authentication that we want the
|
||||||
// server to require from clients.
|
// server to require from clients.
|
||||||
let auth = gst_rtsp_server::RTSPAuth::new();
|
let auth = gst_rtsp_server::RTSPAuth::new();
|
||||||
let token = gst_rtsp_server::RTSPToken::new(&[(
|
let token = gst_rtsp_server::RTSPToken::builder()
|
||||||
gst_rtsp_server::RTSP_TOKEN_MEDIA_FACTORY_ROLE,
|
.field(gst_rtsp_server::RTSP_TOKEN_MEDIA_FACTORY_ROLE, "user")
|
||||||
&"user",
|
.build();
|
||||||
)]);
|
|
||||||
let basic = gst_rtsp_server::RTSPAuth::make_basic("user", "password");
|
let basic = gst_rtsp_server::RTSPAuth::make_basic("user", "password");
|
||||||
// For proper authentication, we want to use encryption. And there's no
|
// For proper authentication, we want to use encryption. And there's no
|
||||||
// encryption without a certificate!
|
// encryption without a certificate!
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use glib::{translate::*, value::ToSendValue};
|
use glib::{translate::*, SendValue};
|
||||||
|
|
||||||
gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
|
gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
|
||||||
ffi::gst_rtsp_token_get_type()
|
ffi::gst_rtsp_token_get_type()
|
||||||
|
@ -15,18 +15,19 @@ impl RTSPToken {
|
||||||
unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
|
unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(values: &[(&str, &(dyn ToSendValue + Sync))]) -> Self {
|
#[doc(alias = "gst_rtsp_token_new")]
|
||||||
|
pub fn builder() -> Builder {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
Builder::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::should_implement_trait)]
|
||||||
|
pub fn from_iter(iter: impl IntoIterator<Item = (impl IntoGStr, SendValue)>) -> RTSPToken {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
let mut token = RTSPToken::new_empty();
|
let mut token = RTSPToken::new_empty();
|
||||||
|
|
||||||
{
|
let s = token.get_mut().unwrap().structure_mut();
|
||||||
let token = token.get_mut().unwrap();
|
iter.into_iter().for_each(|(f, v)| s.set_value(f, v));
|
||||||
let structure = token.structure_mut();
|
|
||||||
|
|
||||||
for &(f, v) in values {
|
|
||||||
structure.set_value(f, v.to_send_value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
@ -82,3 +83,32 @@ impl fmt::Debug for RTSPTokenRef {
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[must_use = "The builder must be built to be used"]
|
||||||
|
pub struct Builder {
|
||||||
|
token: RTSPToken,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Builder {
|
||||||
|
fn new() -> Self {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
Builder {
|
||||||
|
token: RTSPToken::new_empty(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn field(mut self, name: impl IntoGStr, value: impl Into<glib::Value> + Send) -> Self {
|
||||||
|
self.token
|
||||||
|
.get_mut()
|
||||||
|
.unwrap()
|
||||||
|
.structure_mut()
|
||||||
|
.set(name, value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use = "Building the structure without using it has no effect"]
|
||||||
|
pub fn build(self) -> RTSPToken {
|
||||||
|
self.token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue