media-factory: add convenience API for factory

This commit is contained in:
Wim Taymans 2013-07-12 16:17:57 +02:00
parent facc91a942
commit 67d0fbc048
4 changed files with 44 additions and 17 deletions

View file

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

View file

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

View file

@ -345,6 +345,41 @@ gst_rtsp_media_factory_get_permissions (GstRTSPMediaFactory * factory)
return result;
}
/**
* 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

View file

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