From 54a8c6bddfb877c5eb953ffeb3892ceae4b91835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 18 Jan 2018 11:07:45 +0000 Subject: [PATCH] rtsp-token: add some API to set fields from bindings The existing functions are all vararg-based and as such not usable from bindings. https://bugzilla.gnome.org/show_bug.cgi?id=787073 --- docs/libs/gst-rtsp-server-sections.txt | 2 ++ gst/rtsp-server/rtsp-token.c | 48 ++++++++++++++++++++++++++ gst/rtsp-server/rtsp-token.h | 10 +++++- tests/check/gst/token.c | 11 ++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/docs/libs/gst-rtsp-server-sections.txt b/docs/libs/gst-rtsp-server-sections.txt index 3299fd71e9..669abb9cc5 100644 --- a/docs/libs/gst-rtsp-server-sections.txt +++ b/docs/libs/gst-rtsp-server-sections.txt @@ -725,7 +725,9 @@ gst_rtsp_token_ref gst_rtsp_token_unref gst_rtsp_token_get_structure gst_rtsp_token_writable_structure +gst_rtsp_token_set_string gst_rtsp_token_get_string +gst_rtsp_token_set_bool gst_rtsp_token_is_allowed GST_RTSP_TOKEN_CAST diff --git a/gst/rtsp-server/rtsp-token.c b/gst/rtsp-server/rtsp-token.c index 69250f9adc..c002e8af84 100644 --- a/gst/rtsp-server/rtsp-token.c +++ b/gst/rtsp-server/rtsp-token.c @@ -165,6 +165,54 @@ gst_rtsp_token_new_valist (const gchar * firstfield, va_list var_args) return token; } +/** + * gst_rtsp_token_set_string: + * @token: The #GstRTSPToken. + * @field: field to set + * @string_value: string value to set + * + * Sets a string value on @token. + * + * Since: 1.14 + */ +void +gst_rtsp_token_set_string (GstRTSPToken * token, const gchar * field, + const gchar * string_value) +{ + GstStructure *s; + + g_return_if_fail (token != NULL); + g_return_if_fail (field != NULL); + g_return_if_fail (string_value != NULL); + + s = gst_rtsp_token_writable_structure (token); + if (s != NULL) + gst_structure_set (s, field, G_TYPE_STRING, string_value, NULL); +} + +/** + * gst_rtsp_token_set_bool: + * @token: The #GstRTSPToken. + * @field: field to set + * @bool_value: boolean value to set + * + * Sets a boolean value on @token. + * + * Since: 1.14 + */ +void +gst_rtsp_token_set_bool (GstRTSPToken * token, const gchar * field, + gboolean bool_value) +{ + GstStructure *s; + + g_return_if_fail (token != NULL); + g_return_if_fail (field != NULL); + + s = gst_rtsp_token_writable_structure (token); + if (s != NULL) + gst_structure_set (s, field, G_TYPE_BOOLEAN, bool_value, NULL); +} /** * gst_rtsp_token_get_structure: diff --git a/gst/rtsp-server/rtsp-token.h b/gst/rtsp-server/rtsp-token.h index 34b4d50cdd..3122ed4873 100644 --- a/gst/rtsp-server/rtsp-token.h +++ b/gst/rtsp-server/rtsp-token.h @@ -89,13 +89,21 @@ const GstStructure * gst_rtsp_token_get_structure (GstRTSPToken *token); GST_EXPORT GstStructure * gst_rtsp_token_writable_structure (GstRTSPToken *token); +GST_EXPORT +void gst_rtsp_token_set_string (GstRTSPToken * token, + const gchar * field, + const gchar * string_value); GST_EXPORT const gchar * gst_rtsp_token_get_string (GstRTSPToken *token, const gchar *field); - +GST_EXPORT +void gst_rtsp_token_set_bool (GstRTSPToken * token, + const gchar * field, + gboolean bool_value); GST_EXPORT gboolean gst_rtsp_token_is_allowed (GstRTSPToken *token, const gchar *field); + #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstRTSPToken, gst_rtsp_token_unref) #endif diff --git a/tests/check/gst/token.c b/tests/check/gst/token.c index df5bbd5162..3b21c9794e 100644 --- a/tests/check/gst/token.c +++ b/tests/check/gst/token.c @@ -78,6 +78,17 @@ GST_START_TEST (test_token) fail_unless (gst_rtsp_token_is_allowed (token, "permission1")); fail_unless (gst_rtsp_token_is_allowed (token, "permission2")); fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); + + gst_rtsp_token_set_bool (token, "permission3", FALSE); + fail_unless (!gst_rtsp_token_is_allowed (token, "permission3")); + gst_rtsp_token_set_bool (token, "permission4", TRUE); + fail_unless (gst_rtsp_token_is_allowed (token, "permission4")); + + fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user"); + gst_rtsp_token_set_string (token, "role", "admin"); + fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), + "admin"); + gst_rtsp_token_unref (token); }