rtsp-token: add some API to set fields from bindings
authorTim-Philipp Müller <tim@centricular.com>
Thu, 18 Jan 2018 11:07:45 +0000 (11:07 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 18 Jan 2018 22:37:57 +0000 (22:37 +0000)
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
gst/rtsp-server/rtsp-token.c
gst/rtsp-server/rtsp-token.h
tests/check/gst/token.c

index 3299fd7..669abb9 100644 (file)
@@ -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
 <SUBSECTION Standard>
 GST_RTSP_TOKEN_CAST
index 69250f9..c002e8a 100644 (file)
@@ -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:
index 34b4d50..3122ed4 100644 (file)
@@ -90,12 +90,20 @@ 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
index df5bbd5..3b21c97 100644 (file)
@@ -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);
 }