token: simplify token constructor

Use variable arguments to make easier API.
This commit is contained in:
Wim Taymans 2013-07-12 16:36:05 +02:00
parent 67d0fbc048
commit b8c5aa3a6b
4 changed files with 61 additions and 28 deletions

View 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);

View 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);

View 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;
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);
token = g_slice_new0 (GstRTSPTokenImpl);
gst_rtsp_token_init (token, gst_structure_new_empty ("GstRTSPToken"));
gst_rtsp_token_init (token, s);
return (GstRTSPToken *) token;
}

View 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);