token: simplify token constructor
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 12 Jul 2013 14:36:05 +0000 (16:36 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 12 Jul 2013 14:36:05 +0000 (16:36 +0200)
Use variable arguments to make easier API.

examples/test-auth.c
examples/test-cgroups.c
gst/rtsp-server/rtsp-token.c
gst/rtsp-server/rtsp-token.h

index d491029..27eca57 100644 (file)
@@ -64,7 +64,6 @@ main (int argc, char *argv[])
   GstRTSPAuth *auth;
   GstRTSPToken *token;
   gchar *basic;
-  GstStructure *s;
 
   gst_init (&argc, &argv);
 
@@ -126,30 +125,24 @@ main (int argc, char *argv[])
   auth = gst_rtsp_auth_new ();
 
   /* make user token */
-  token = gst_rtsp_token_new ();
-  s = gst_rtsp_token_writable_structure (token);
-  gst_structure_set (s, "resources.class", G_TYPE_STRING, "user", NULL);
-  gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "user", NULL);
+  token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "user",
+      "media.factory.role", G_TYPE_STRING, "user", NULL);
   basic = gst_rtsp_auth_make_basic ("user", "password");
   gst_rtsp_auth_add_basic (auth, basic, token);
   g_free (basic);
   gst_rtsp_token_unref (token);
 
   /* make admin token */
-  token = gst_rtsp_token_new ();
-  s = gst_rtsp_token_writable_structure (token);
-  gst_structure_set (s, "resources.class", G_TYPE_STRING, "admin", NULL);
-  gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "admin", NULL);
+  token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "admin",
+      "media.factory.role", G_TYPE_STRING, "admin", NULL);
   basic = gst_rtsp_auth_make_basic ("admin", "power");
   gst_rtsp_auth_add_basic (auth, basic, token);
   g_free (basic);
   gst_rtsp_token_unref (token);
 
   /* make admin2 token */
-  token = gst_rtsp_token_new ();
-  s = gst_rtsp_token_writable_structure (token);
-  gst_structure_set (s, "resources.class", G_TYPE_STRING, "admin", NULL);
-  gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "admin2", NULL);
+  token = gst_rtsp_token_new ("resources.class", G_TYPE_STRING, "admin",
+      "media.factory.role", G_TYPE_STRING, "admin2", NULL);
   basic = gst_rtsp_auth_make_basic ("admin2", "power2");
   gst_rtsp_auth_add_basic (auth, basic, token);
   g_free (basic);
index 4c7504d..8188588 100644 (file)
@@ -163,7 +163,6 @@ main (int argc, char *argv[])
   GstRTSPAuth *auth;
   GstRTSPToken *token;
   gchar *basic;
-  GstStructure *s;
   GstRTSPThreadPool *thread_pool;
 
   gst_init (&argc, &argv);
@@ -205,21 +204,16 @@ main (int argc, char *argv[])
   auth = gst_rtsp_auth_new ();
 
   /* make user token */
-  token = gst_rtsp_token_new ();
-  s = gst_rtsp_token_writable_structure (token);
-  gst_structure_set (s, "cgroup.pool.media.class", G_TYPE_STRING, "user", NULL);
-  gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "user", NULL);
+  token = gst_rtsp_token_new ("cgroup.pool.media.class", G_TYPE_STRING, "user",
+      "media.factory.role", G_TYPE_STRING, "user", NULL);
   basic = gst_rtsp_auth_make_basic ("user", "password");
   gst_rtsp_auth_add_basic (auth, basic, token);
   g_free (basic);
   gst_rtsp_token_unref (token);
 
   /* make admin token */
-  token = gst_rtsp_token_new ();
-  s = gst_rtsp_token_writable_structure (token);
-  gst_structure_set (s, "cgroup.pool.media.class", G_TYPE_STRING, "admin",
-      NULL);
-  gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "admin", NULL);
+  token = gst_rtsp_token_new ("cgroup.pool.media.class", G_TYPE_STRING, "admin",
+      "media.factory.role", G_TYPE_STRING, "admin", NULL);
   basic = gst_rtsp_auth_make_basic ("admin", "power");
   gst_rtsp_auth_add_basic (auth, basic, token);
   g_free (basic);
index f82e58d..2c228f7 100644 (file)
@@ -84,20 +84,64 @@ gst_rtsp_token_init (GstRTSPTokenImpl * token, GstStructure * structure)
 }
 
 /**
- * gst_rtsp_token_new:
+ * gst_rtsp_token_new_empty:
  *
  * Create a new empty Authorization token.
  *
  * Returns: (transfer full): a new empty authorization token.
  */
 GstRTSPToken *
-gst_rtsp_token_new (void)
+gst_rtsp_token_new_empty (void)
+{
+  return gst_rtsp_token_new (NULL, NULL);
+}
+
+/**
+ * gst_rtsp_token_new:
+ * @firstfield: the first fieldname
+ * @...: additional arguments
+ *
+ * Create a new Authorization token with the given fieldnames and values.
+ * Arguments are given similar to gst_structure_new().
+ *
+ * Returns: (transfer full): a new authorization token.
+ */
+GstRTSPToken *
+gst_rtsp_token_new (const gchar * firstfield, ...)
+{
+  GstRTSPToken *result;
+  va_list var_args;
+
+  va_start (var_args, firstfield);
+  result = gst_rtsp_token_new_valist (firstfield, var_args);
+  va_end (var_args);
+
+  return result;
+}
+
+/**
+ * gst_rtsp_token_new:
+ * @firstfield: the first fieldname
+ * @var_args additional arguments
+ *
+ * Create a new Authorization token with the given fieldnames and values.
+ * Arguments are given similar to gst_structure_new_valist().
+ *
+ * Returns: (transfer full): a new authorization token.
+ */
+GstRTSPToken *
+gst_rtsp_token_new_valist (const gchar * firstfield, va_list var_args)
 {
   GstRTSPTokenImpl *token;
+  GstStructure *s;
 
-  token = g_slice_new0 (GstRTSPTokenImpl);
+  g_return_val_if_fail (firstfield != NULL, NULL);
+
+  s = gst_structure_new_valist ("GstRTSPToken", firstfield, var_args);
+  g_return_val_if_fail (s != NULL, NULL);
 
-  gst_rtsp_token_init (token, gst_structure_new_empty ("GstRTSPToken"));
+  token = g_slice_new0 (GstRTSPTokenImpl);
+  gst_rtsp_token_init (token, s);
 
   return (GstRTSPToken *) token;
 }
index 732a683..fa6a888 100644 (file)
@@ -81,7 +81,9 @@ gst_rtsp_token_unref (GstRTSPToken * token)
 }
 
 
-GstRTSPToken *       gst_rtsp_token_new                (void);
+GstRTSPToken *       gst_rtsp_token_new_empty          (void);
+GstRTSPToken *       gst_rtsp_token_new                (const gchar * firstfield, ...);
+GstRTSPToken *       gst_rtsp_token_new_valist         (const gchar * firstfield, va_list var_args);
 
 const GstStructure * gst_rtsp_token_get_structure      (GstRTSPToken *token);
 GstStructure *       gst_rtsp_token_writable_structure (GstRTSPToken *token);