From: Wim Taymans Date: Fri, 12 Jul 2013 14:17:57 +0000 (+0200) Subject: media-factory: add convenience API for factory X-Git-Tag: 1.19.3~495^2~1034 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67d0fbc0485cdfe5c3b55773605eaff3bb1d8d37;p=platform%2Fupstream%2Fgstreamer.git media-factory: add convenience API for factory --- diff --git a/examples/test-auth.c b/examples/test-auth.c index b72161e..d491029 100644 --- a/examples/test-auth.c +++ b/examples/test-auth.c @@ -65,7 +65,6 @@ main (int argc, char *argv[]) GstRTSPToken *token; gchar *basic; GstStructure *s; - GstRTSPPermissions *permissions; gst_init (&argc, &argv); @@ -93,20 +92,17 @@ main (int argc, char *argv[]) gst_rtsp_mount_points_add_factory (mounts, "/test", factory); /* allow user and admin to access this resource */ - permissions = gst_rtsp_permissions_new (); - gst_rtsp_permissions_add_role (permissions, "user", + gst_rtsp_media_factory_add_role (factory, "user", "media.factory.access", G_TYPE_BOOLEAN, TRUE, "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); - gst_rtsp_permissions_add_role (permissions, "admin", + gst_rtsp_media_factory_add_role (factory, "admin", "media.factory.access", G_TYPE_BOOLEAN, TRUE, "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); /* admin2 can look at the media but not construct so he gets a * 401 Unauthorized */ - gst_rtsp_permissions_add_role (permissions, "admin2", + gst_rtsp_media_factory_add_role (factory, "admin2", "media.factory.access", G_TYPE_BOOLEAN, TRUE, "media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL); - gst_rtsp_media_factory_set_permissions (factory, permissions); - gst_rtsp_permissions_unref (permissions); /* make another factory */ factory = gst_rtsp_media_factory_new (); @@ -117,14 +113,11 @@ main (int argc, char *argv[]) gst_rtsp_mount_points_add_factory (mounts, "/test2", factory); /* allow admin2 to access this resource */ - permissions = gst_rtsp_permissions_new (); /* user and admin have no permissions so they can't even see the * media and get a 404 Not Found */ - gst_rtsp_permissions_add_role (permissions, "admin2", + gst_rtsp_media_factory_add_role (factory, "admin2", "media.factory.access", G_TYPE_BOOLEAN, TRUE, "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); - gst_rtsp_media_factory_set_permissions (factory, permissions); - gst_rtsp_permissions_unref (permissions); /* don't need the ref to the mapper anymore */ g_object_unref (mounts); diff --git a/examples/test-cgroups.c b/examples/test-cgroups.c index 7669c3d..4c7504d 100644 --- a/examples/test-cgroups.c +++ b/examples/test-cgroups.c @@ -164,7 +164,6 @@ main (int argc, char *argv[]) GstRTSPToken *token; gchar *basic; GstStructure *s; - GstRTSPPermissions *permissions; GstRTSPThreadPool *thread_pool; gst_init (&argc, &argv); @@ -192,15 +191,12 @@ main (int argc, char *argv[]) gst_rtsp_mount_points_add_factory (mounts, "/test", factory); /* allow user and admin to access this resource */ - permissions = gst_rtsp_permissions_new (); - gst_rtsp_permissions_add_role (permissions, "user", + gst_rtsp_media_factory_add_role (factory, "user", "media.factory.access", G_TYPE_BOOLEAN, TRUE, "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); - gst_rtsp_permissions_add_role (permissions, "admin", + gst_rtsp_media_factory_add_role (factory, "admin", "media.factory.access", G_TYPE_BOOLEAN, TRUE, "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL); - gst_rtsp_media_factory_set_permissions (factory, permissions); - gst_rtsp_permissions_unref (permissions); /* don't need the ref to the mapper anymore */ g_object_unref (mounts); diff --git a/gst/rtsp-server/rtsp-media-factory.c b/gst/rtsp-server/rtsp-media-factory.c index 391ea83..89678dc 100644 --- a/gst/rtsp-server/rtsp-media-factory.c +++ b/gst/rtsp-server/rtsp-media-factory.c @@ -346,6 +346,41 @@ gst_rtsp_media_factory_get_permissions (GstRTSPMediaFactory * factory) } /** + * gst_rtsp_media_factory_add_role: + * @factory: a #GstRTSPMediaFactory + * @role: a role + * @fieldname: the first field name + * @...: additional arguments + * + * A convenience method to add @role with @fieldname and additional arguments to + * the permissions of @factory. If @factory had no permissions, new permissions + * will be created and the role will be added to it. + */ +void +gst_rtsp_media_factory_add_role (GstRTSPMediaFactory * factory, + const gchar * role, const gchar * fieldname, ...) +{ + GstRTSPMediaFactoryPrivate *priv; + va_list var_args; + + g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory)); + g_return_if_fail (role != NULL); + g_return_if_fail (fieldname != NULL); + + priv = factory->priv; + + GST_RTSP_MEDIA_FACTORY_LOCK (factory); + if (priv->permissions == NULL) + priv->permissions = gst_rtsp_permissions_new (); + + va_start (var_args, fieldname); + gst_rtsp_permissions_add_role_valist (priv->permissions, role, fieldname, + var_args); + va_end (var_args); + GST_RTSP_MEDIA_FACTORY_UNLOCK (factory); +} + +/** * gst_rtsp_media_factory_set_launch: * @factory: a #GstRTSPMediaFactory * @launch: the launch description diff --git a/gst/rtsp-server/rtsp-media-factory.h b/gst/rtsp-server/rtsp-media-factory.h index 2815d95..33ec540 100644 --- a/gst/rtsp-server/rtsp-media-factory.h +++ b/gst/rtsp-server/rtsp-media-factory.h @@ -106,6 +106,9 @@ gchar * gst_rtsp_media_factory_get_launch (GstRTSPMediaFacto void gst_rtsp_media_factory_set_permissions (GstRTSPMediaFactory *factory, GstRTSPPermissions *permissions); GstRTSPPermissions * gst_rtsp_media_factory_get_permissions (GstRTSPMediaFactory *factory); +void gst_rtsp_media_factory_add_role (GstRTSPMediaFactory *factory, + const gchar *role, + const gchar *fieldname, ...); void gst_rtsp_media_factory_set_shared (GstRTSPMediaFactory *factory, gboolean shared);