From b8c5aa3a6bf8d7287770b3dfb5094b7fa63acdc6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 12 Jul 2013 16:36:05 +0200 Subject: [PATCH] token: simplify token constructor Use variable arguments to make easier API. --- examples/test-auth.c | 19 +++++----------- examples/test-cgroups.c | 14 ++++-------- gst/rtsp-server/rtsp-token.c | 52 ++++++++++++++++++++++++++++++++++++++++---- gst/rtsp-server/rtsp-token.h | 4 +++- 4 files changed, 61 insertions(+), 28 deletions(-) diff --git a/examples/test-auth.c b/examples/test-auth.c index d491029..27eca57 100644 --- a/examples/test-auth.c +++ b/examples/test-auth.c @@ -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); diff --git a/examples/test-cgroups.c b/examples/test-cgroups.c index 4c7504d..8188588 100644 --- a/examples/test-cgroups.c +++ b/examples/test-cgroups.c @@ -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); diff --git a/gst/rtsp-server/rtsp-token.c b/gst/rtsp-server/rtsp-token.c index f82e58d..2c228f7 100644 --- a/gst/rtsp-server/rtsp-token.c +++ b/gst/rtsp-server/rtsp-token.c @@ -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; } diff --git a/gst/rtsp-server/rtsp-token.h b/gst/rtsp-server/rtsp-token.h index 732a683..fa6a888 100644 --- a/gst/rtsp-server/rtsp-token.h +++ b/gst/rtsp-server/rtsp-token.h @@ -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); -- 2.7.4