gstreamer-sdp: update functions returning bool to Result<(), glib::BoolError>

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/182
This commit is contained in:
François Laignel 2019-02-05 19:28:10 +01:00
parent 211e476592
commit be9566fe4a
5 changed files with 263 additions and 103 deletions

View file

@ -44,6 +44,56 @@ ref_mode = "ref"
[[object]] [[object]]
name = "GstSdp.MIKEYMessage" name = "GstSdp.MIKEYMessage"
status = "generate" status = "generate"
[[object.function]]
name = "add_cs_srtp"
[object.function.return]
bool_return_is_error = "Failed to add the Crypto policy for SRTP"
[[object.function]]
name = "add_pke"
[object.function.return]
bool_return_is_error = "Failed to add the PKE payload"
[[object.function]]
name = "add_rand"
[object.function.return]
bool_return_is_error = "Failed to add the RAND payload"
[[object.function]]
name = "add_rand_len"
[object.function.return]
bool_return_is_error = "Failed to add the RAND payload with random bytes"
[[object.function]]
name = "add_t"
[object.function.return]
bool_return_is_error = "Failed to add the T payload"
[[object.function]]
name = "add_t_now_ntp_utc"
[object.function.return]
bool_return_is_error = "Failed to add the T payload with current time"
[[object.function]]
name = "remove_cs_srtp"
[object.function.return]
bool_return_is_error = "Failed to remove the SRTP policy"
[[object.function]]
name = "remove_payload"
[object.function.return]
bool_return_is_error = "Failed to remove the payload"
[[object.function]]
name = "set_info"
[object.function.return]
bool_return_is_error = "Failed to set the information"
[[object.function]]
name = "to_caps"
[object.function.return]
bool_return_is_error = "Failed to fill caps with SRTP parameters"
[[object.function]] [[object.function]]
name = "replace_payload" name = "replace_payload"
ignore = true ignore = true
@ -71,10 +121,64 @@ status = "generate"
name = "kemac_add_sub" name = "kemac_add_sub"
ignore = true ignore = true
[[object.function]]
name = "kemac_remove_sub"
[object.function.return]
bool_return_is_error = "Failed to remove the sub payload"
[[object.function]] [[object.function]]
name = "kemac_get_sub" name = "kemac_get_sub"
ignore = true ignore = true
[[object.function]]
name = "kemac_set"
[object.function.return]
bool_return_is_error = "Failed to set the KEMAC parameters"
[[object.function]] [[object.function]]
name = "key_data_set_interval" name = "key_data_set_interval"
ignore = true ignore = true
[[object.function]]
name = "key_data_set_key"
[object.function.return]
bool_return_is_error = "Failed to set the key"
[[object.function]]
name = "key_data_set_salt"
[object.function.return]
bool_return_is_error = "Failed to set the salt key data"
[[object.function]]
name = "key_data_set_spi"
[object.function.return]
bool_return_is_error = "Failed to set the SPI/MKI validity"
[[object.function]]
name = "pke_set"
[object.function.return]
bool_return_is_error = "Failed to set the PKE values"
[[object.function]]
name = "rand_set"
[object.function.return]
bool_return_is_error = "Failed to set the random values"
[[object.function]]
name = "sp_add_param"
[object.function.return]
bool_return_is_error = "Failed to add the parameter"
[[object.function]]
name = "sp_remove_param"
[object.function.return]
bool_return_is_error = "Failed to remove the parameter"
[[object.function]]
name = "sp_set"
[object.function.return]
bool_return_is_error = "Failed to set the Security Policy parameters"
[[object.function]]
name = "t_set"
ignore = true

View file

@ -9,6 +9,7 @@ use MIKEYPayload;
use MIKEYPayloadType; use MIKEYPayloadType;
use MIKEYType; use MIKEYType;
use ffi; use ffi;
use glib;
use glib::translate::*; use glib::translate::*;
use gobject_ffi; use gobject_ffi;
use gst; use gst;
@ -47,39 +48,39 @@ impl MIKEYMessage {
// unsafe { TODO: call ffi::gst_mikey_message_new_from_data() } // unsafe { TODO: call ffi::gst_mikey_message_new_from_data() }
//} //}
pub fn add_cs_srtp(&mut self, policy: u8, ssrc: u32, roc: u32) -> bool { pub fn add_cs_srtp(&mut self, policy: u8, ssrc: u32, roc: u32) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_add_cs_srtp(self.to_glib_none_mut().0, policy, ssrc, roc)) glib_result_from_gboolean!(ffi::gst_mikey_message_add_cs_srtp(self.to_glib_none_mut().0, policy, ssrc, roc), "Failed to add the Crypto policy for SRTP")
} }
} }
pub fn add_pke(&mut self, C: MIKEYCacheType, data: &[u8]) -> bool { pub fn add_pke(&mut self, C: MIKEYCacheType, data: &[u8]) -> Result<(), glib::error::BoolError> {
let data_len = data.len() as u16; let data_len = data.len() as u16;
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_add_pke(self.to_glib_none_mut().0, C.to_glib(), data_len, data.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_message_add_pke(self.to_glib_none_mut().0, C.to_glib(), data_len, data.to_glib_none().0), "Failed to add the PKE payload")
} }
} }
pub fn add_rand(&mut self, rand: &[u8]) -> bool { pub fn add_rand(&mut self, rand: &[u8]) -> Result<(), glib::error::BoolError> {
let len = rand.len() as u8; let len = rand.len() as u8;
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_add_rand(self.to_glib_none_mut().0, len, rand.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_message_add_rand(self.to_glib_none_mut().0, len, rand.to_glib_none().0), "Failed to add the RAND payload")
} }
} }
pub fn add_rand_len(&mut self, len: u8) -> bool { pub fn add_rand_len(&mut self, len: u8) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_add_rand_len(self.to_glib_none_mut().0, len)) glib_result_from_gboolean!(ffi::gst_mikey_message_add_rand_len(self.to_glib_none_mut().0, len), "Failed to add the RAND payload with random bytes")
} }
} }
//pub fn add_t(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool { //pub fn add_t(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> Result<(), glib::error::BoolError> {
// unsafe { TODO: call ffi::gst_mikey_message_add_t() } // unsafe { TODO: call ffi::gst_mikey_message_add_t() }
//} //}
pub fn add_t_now_ntp_utc(&mut self) -> bool { pub fn add_t_now_ntp_utc(&mut self) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_add_t_now_ntp_utc(self.to_glib_none_mut().0)) glib_result_from_gboolean!(ffi::gst_mikey_message_add_t_now_ntp_utc(self.to_glib_none_mut().0), "Failed to add the T payload with current time")
} }
} }
@ -109,15 +110,15 @@ impl MIKEYMessage {
// unsafe { TODO: call ffi::gst_mikey_message_insert_cs_srtp() } // unsafe { TODO: call ffi::gst_mikey_message_insert_cs_srtp() }
//} //}
pub fn remove_cs_srtp(&mut self, idx: i32) -> bool { pub fn remove_cs_srtp(&mut self, idx: i32) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_remove_cs_srtp(self.to_glib_none_mut().0, idx)) glib_result_from_gboolean!(ffi::gst_mikey_message_remove_cs_srtp(self.to_glib_none_mut().0, idx), "Failed to remove the SRTP policy")
} }
} }
pub fn remove_payload(&mut self, idx: u32) -> bool { pub fn remove_payload(&mut self, idx: u32) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_remove_payload(self.to_glib_none_mut().0, idx)) glib_result_from_gboolean!(ffi::gst_mikey_message_remove_payload(self.to_glib_none_mut().0, idx), "Failed to remove the payload")
} }
} }
@ -125,9 +126,9 @@ impl MIKEYMessage {
// unsafe { TODO: call ffi::gst_mikey_message_replace_cs_srtp() } // unsafe { TODO: call ffi::gst_mikey_message_replace_cs_srtp() }
//} //}
pub fn set_info(&mut self, version: u8, type_: MIKEYType, V: bool, prf_func: MIKEYPRFFunc, CSB_id: u32, map_type: MIKEYMapType) -> bool { pub fn set_info(&mut self, version: u8, type_: MIKEYType, V: bool, prf_func: MIKEYPRFFunc, CSB_id: u32, map_type: MIKEYMapType) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_set_info(self.to_glib_none_mut().0, version, type_.to_glib(), V.to_glib(), prf_func.to_glib(), CSB_id, map_type.to_glib())) glib_result_from_gboolean!(ffi::gst_mikey_message_set_info(self.to_glib_none_mut().0, version, type_.to_glib(), V.to_glib(), prf_func.to_glib(), CSB_id, map_type.to_glib()), "Failed to set the information")
} }
} }
@ -136,9 +137,9 @@ impl MIKEYMessage {
//} //}
#[cfg(any(feature = "v1_8_1", feature = "dox"))] #[cfg(any(feature = "v1_8_1", feature = "dox"))]
pub fn to_caps(&self, caps: &gst::Caps) -> bool { pub fn to_caps(&self, caps: &gst::Caps) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_to_caps(self.to_glib_none().0, caps.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_message_to_caps(self.to_glib_none().0, caps.to_glib_none().0), "Failed to fill caps with SRTP parameters")
} }
} }
} }

View file

@ -9,6 +9,7 @@ use MIKEYMacAlg;
use MIKEYPayloadType; use MIKEYPayloadType;
use MIKEYSecProto; use MIKEYSecProto;
use ffi; use ffi;
use glib;
use glib::translate::*; use glib::translate::*;
use gobject_ffi; use gobject_ffi;
@ -37,57 +38,57 @@ impl MIKEYPayload {
} }
} }
pub fn kemac_remove_sub(&mut self, idx: u32) -> bool { pub fn kemac_remove_sub(&mut self, idx: u32) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_kemac_remove_sub(self.to_glib_none_mut().0, idx)) glib_result_from_gboolean!(ffi::gst_mikey_payload_kemac_remove_sub(self.to_glib_none_mut().0, idx), "Failed to remove the sub payload")
} }
} }
pub fn kemac_set(&mut self, enc_alg: MIKEYEncAlg, mac_alg: MIKEYMacAlg) -> bool { pub fn kemac_set(&mut self, enc_alg: MIKEYEncAlg, mac_alg: MIKEYMacAlg) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_kemac_set(self.to_glib_none_mut().0, enc_alg.to_glib(), mac_alg.to_glib())) glib_result_from_gboolean!(ffi::gst_mikey_payload_kemac_set(self.to_glib_none_mut().0, enc_alg.to_glib(), mac_alg.to_glib()), "Failed to set the KEMAC parameters")
} }
} }
pub fn key_data_set_key(&mut self, key_type: MIKEYKeyDataType, key_data: &[u8]) -> bool { pub fn key_data_set_key(&mut self, key_type: MIKEYKeyDataType, key_data: &[u8]) -> Result<(), glib::error::BoolError> {
let key_len = key_data.len() as u16; let key_len = key_data.len() as u16;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_key_data_set_key(self.to_glib_none_mut().0, key_type.to_glib(), key_len, key_data.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_payload_key_data_set_key(self.to_glib_none_mut().0, key_type.to_glib(), key_len, key_data.to_glib_none().0), "Failed to set the key")
} }
} }
pub fn key_data_set_salt(&mut self, salt_data: &[u8]) -> bool { pub fn key_data_set_salt(&mut self, salt_data: &[u8]) -> Result<(), glib::error::BoolError> {
let salt_len = salt_data.len() as u16; let salt_len = salt_data.len() as u16;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_key_data_set_salt(self.to_glib_none_mut().0, salt_len, salt_data.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_payload_key_data_set_salt(self.to_glib_none_mut().0, salt_len, salt_data.to_glib_none().0), "Failed to set the salt key data")
} }
} }
pub fn key_data_set_spi(&mut self, spi_data: &[u8]) -> bool { pub fn key_data_set_spi(&mut self, spi_data: &[u8]) -> Result<(), glib::error::BoolError> {
let spi_len = spi_data.len() as u8; let spi_len = spi_data.len() as u8;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_key_data_set_spi(self.to_glib_none_mut().0, spi_len, spi_data.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_payload_key_data_set_spi(self.to_glib_none_mut().0, spi_len, spi_data.to_glib_none().0), "Failed to set the SPI/MKI validity")
} }
} }
pub fn pke_set(&mut self, C: MIKEYCacheType, data: &[u8]) -> bool { pub fn pke_set(&mut self, C: MIKEYCacheType, data: &[u8]) -> Result<(), glib::error::BoolError> {
let data_len = data.len() as u16; let data_len = data.len() as u16;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_pke_set(self.to_glib_none_mut().0, C.to_glib(), data_len, data.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_payload_pke_set(self.to_glib_none_mut().0, C.to_glib(), data_len, data.to_glib_none().0), "Failed to set the PKE values")
} }
} }
pub fn rand_set(&mut self, rand: &[u8]) -> bool { pub fn rand_set(&mut self, rand: &[u8]) -> Result<(), glib::error::BoolError> {
let len = rand.len() as u8; let len = rand.len() as u8;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_rand_set(self.to_glib_none_mut().0, len, rand.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_payload_rand_set(self.to_glib_none_mut().0, len, rand.to_glib_none().0), "Failed to set the random values")
} }
} }
pub fn sp_add_param(&mut self, type_: u8, val: &[u8]) -> bool { pub fn sp_add_param(&mut self, type_: u8, val: &[u8]) -> Result<(), glib::error::BoolError> {
let len = val.len() as u8; let len = val.len() as u8;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_sp_add_param(self.to_glib_none_mut().0, type_, len, val.to_glib_none().0)) glib_result_from_gboolean!(ffi::gst_mikey_payload_sp_add_param(self.to_glib_none_mut().0, type_, len, val.to_glib_none().0), "Failed to add the parameter")
} }
} }
@ -101,21 +102,17 @@ impl MIKEYPayload {
// unsafe { TODO: call ffi::gst_mikey_payload_sp_get_param() } // unsafe { TODO: call ffi::gst_mikey_payload_sp_get_param() }
//} //}
pub fn sp_remove_param(&mut self, idx: u32) -> bool { pub fn sp_remove_param(&mut self, idx: u32) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_sp_remove_param(self.to_glib_none_mut().0, idx)) glib_result_from_gboolean!(ffi::gst_mikey_payload_sp_remove_param(self.to_glib_none_mut().0, idx), "Failed to remove the parameter")
} }
} }
pub fn sp_set(&mut self, policy: u32, proto: MIKEYSecProto) -> bool { pub fn sp_set(&mut self, policy: u32, proto: MIKEYSecProto) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_sp_set(self.to_glib_none_mut().0, policy, proto.to_glib())) glib_result_from_gboolean!(ffi::gst_mikey_payload_sp_set(self.to_glib_none_mut().0, policy, proto.to_glib()), "Failed to set the Security Policy parameters")
} }
} }
//pub fn t_set(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool {
// unsafe { TODO: call ffi::gst_mikey_payload_t_set() }
//}
} }
unsafe impl Send for MIKEYPayload {} unsafe impl Send for MIKEYPayload {}

View file

@ -64,13 +64,20 @@ impl MIKEYMessage {
} }
} }
pub fn add_t(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool { pub fn add_t(
&mut self,
type_: MIKEYTSType,
ts_value: &[u8],
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_message_add_t( glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_message_add_t(
type_.to_glib(), self.to_glib_none_mut().0,
ts_value.to_glib_none().0, type_.to_glib(),
)) ts_value.to_glib_none().0,
),
"Failed to add the T payload"
)
} }
} }
@ -83,15 +90,22 @@ impl MIKEYMessage {
} }
} }
pub fn insert_cs_srtp(&mut self, idx: i32, map: MIKEYMapSRTP) -> bool { pub fn insert_cs_srtp(
&mut self,
idx: i32,
map: MIKEYMapSRTP,
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_message_insert_cs_srtp( let res = glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_message_insert_cs_srtp(
idx, self.to_glib_none_mut().0,
map.to_glib_full(), idx,
)); map.to_glib_full(),
),
"Failed to insert the Crypto Session map for SRTP"
);
mem::forget(map); mem::forget(map);
ret res
} }
} }
@ -104,50 +118,77 @@ impl MIKEYMessage {
} }
} }
pub fn add_payload(&mut self, payload: MIKEYPayload) -> bool { pub fn add_payload(
&mut self,
payload: MIKEYPayload,
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_message_add_payload( let res = glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_message_add_payload(
payload.to_glib_full(), self.to_glib_none_mut().0,
)); payload.to_glib_full(),
),
"Failed to add the payload"
);
mem::forget(payload); mem::forget(payload);
ret res
} }
} }
pub fn insert_payload(&mut self, idx: u32, payload: MIKEYPayload) -> bool { pub fn insert_payload(
&mut self,
idx: u32,
payload: MIKEYPayload,
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_message_insert_payload( let res = glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_message_insert_payload(
idx, self.to_glib_none_mut().0,
payload.to_glib_full(), idx,
)); payload.to_glib_full(),
),
"Failed to insert the payload"
);
mem::forget(payload); mem::forget(payload);
ret res
} }
} }
pub fn replace_cs_srtp(&mut self, idx: i32, map: MIKEYMapSRTP) -> bool { pub fn replace_cs_srtp(
&mut self,
idx: i32,
map: MIKEYMapSRTP,
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_message_replace_cs_srtp( let res = glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_message_replace_cs_srtp(
idx, self.to_glib_none_mut().0,
map.to_glib_full(), idx,
)); map.to_glib_full(),
),
"Failed to replace the Crypto Session map for SRTP"
);
mem::forget(map); mem::forget(map);
ret res
} }
} }
pub fn replace_payload(&mut self, idx: u32, payload: MIKEYPayload) -> bool { pub fn replace_payload(
&mut self,
idx: u32,
payload: MIKEYPayload,
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_message_replace_payload( let res = glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_message_replace_payload(
idx, self.to_glib_none_mut().0,
payload.to_glib_full(), idx,
)); payload.to_glib_full(),
),
"Failed to replace the payload"
);
mem::forget(payload); mem::forget(payload);
ret res
} }
} }

View file

@ -18,14 +18,17 @@ use auto::MIKEYPayload;
use m_i_k_e_y_map_s_r_t_p::MIKEYPayloadSPParam; use m_i_k_e_y_map_s_r_t_p::MIKEYPayloadSPParam;
impl MIKEYPayload { impl MIKEYPayload {
pub fn kemac_add_sub(&mut self, newpay: MIKEYPayload) -> bool { pub fn kemac_add_sub(&mut self, newpay: MIKEYPayload) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
let ret = from_glib(ffi::gst_mikey_payload_kemac_add_sub( let res = glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_payload_kemac_add_sub(
newpay.to_glib_full(), self.to_glib_none_mut().0,
)); newpay.to_glib_full(),
),
"Failed to add the sub payload"
);
mem::forget(newpay); mem::forget(newpay);
ret res
} }
} }
@ -47,27 +50,41 @@ impl MIKEYPayload {
} }
} }
pub fn t_set(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool { pub fn t_set(
&mut self,
type_: MIKEYTSType,
ts_value: &[u8],
) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_t_set( glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_payload_t_set(
type_.to_glib(), self.to_glib_none_mut().0,
ts_value.to_glib_none().0, type_.to_glib(),
)) ts_value.to_glib_none().0,
),
"Failed to set the timestamp"
)
} }
} }
pub fn key_data_set_interval(&mut self, vf_data: &[u8], vt_data: &[u8]) -> bool { pub fn key_data_set_interval(
&mut self,
vf_data: &[u8],
vt_data: &[u8],
) -> Result<(), glib::error::BoolError> {
let vf_len = vf_data.len() as u8; let vf_len = vf_data.len() as u8;
let vt_len = vt_data.len() as u8; let vt_len = vt_data.len() as u8;
unsafe { unsafe {
from_glib(ffi::gst_mikey_payload_key_data_set_interval( glib_result_from_gboolean!(
self.to_glib_none_mut().0, ffi::gst_mikey_payload_key_data_set_interval(
vf_len, self.to_glib_none_mut().0,
vf_data.to_glib_none().0, vf_len,
vt_len, vf_data.to_glib_none().0,
vt_data.to_glib_none().0, vt_len,
)) vt_data.to_glib_none().0,
),
"Failed to set the key validity period"
)
} }
} }
} }