mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
permissions: more bindings-friendly API
https://bugzilla.gnome.org/show_bug.cgi?id=793975
This commit is contained in:
parent
030992d03a
commit
e356cf33f2
6 changed files with 83 additions and 12 deletions
|
@ -248,6 +248,7 @@ gst_rtsp_media_factory_set_launch
|
|||
gst_rtsp_media_factory_get_permissions
|
||||
gst_rtsp_media_factory_set_permissions
|
||||
gst_rtsp_media_factory_add_role
|
||||
gst_rtsp_media_factory_add_role_from_structure
|
||||
|
||||
gst_rtsp_media_factory_set_shared
|
||||
gst_rtsp_media_factory_is_shared
|
||||
|
@ -361,6 +362,7 @@ gst_rtsp_permissions_unref
|
|||
gst_rtsp_permissions_add_role
|
||||
gst_rtsp_permissions_add_role_valist
|
||||
gst_rtsp_permissions_add_role_empty
|
||||
gst_rtsp_permissions_add_role_from_structure
|
||||
gst_rtsp_permissions_add_permission_for_role
|
||||
gst_rtsp_permissions_remove_role
|
||||
gst_rtsp_permissions_get_role
|
||||
|
|
|
@ -494,6 +494,31 @@ gst_rtsp_media_factory_add_role (GstRTSPMediaFactory * factory,
|
|||
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_media_factory_add_role_from_structure:
|
||||
*
|
||||
* A convenience wrapper around gst_rtsp_permissions_add_role_from_structure().
|
||||
* 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_from_structure (GstRTSPMediaFactory * factory,
|
||||
GstStructure * structure)
|
||||
{
|
||||
GstRTSPMediaFactoryPrivate *priv;
|
||||
g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory));
|
||||
g_return_if_fail (GST_IS_STRUCTURE (structure));
|
||||
|
||||
priv = factory->priv;
|
||||
|
||||
GST_RTSP_MEDIA_FACTORY_LOCK (factory);
|
||||
if (priv->permissions == NULL)
|
||||
priv->permissions = gst_rtsp_permissions_new ();
|
||||
|
||||
gst_rtsp_permissions_add_role_from_structure (priv->permissions, structure);
|
||||
GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_media_factory_set_launch:
|
||||
* @factory: a #GstRTSPMediaFactory
|
||||
|
|
|
@ -127,6 +127,9 @@ void gst_rtsp_media_factory_add_role (GstRTSPMediaFacto
|
|||
const gchar *fieldname, ...);
|
||||
|
||||
GST_EXPORT
|
||||
void gst_rtsp_media_factory_add_role_from_structure (GstRTSPMediaFactory * factory,
|
||||
GstStructure *structure);
|
||||
GST_EXPORT
|
||||
void gst_rtsp_media_factory_set_shared (GstRTSPMediaFactory *factory,
|
||||
gboolean shared);
|
||||
|
||||
|
|
|
@ -105,6 +105,28 @@ gst_rtsp_permissions_init (GstRTSPPermissionsImpl * permissions)
|
|||
g_ptr_array_new_with_free_func ((GDestroyNotify) free_structure);
|
||||
}
|
||||
|
||||
static void
|
||||
add_role_from_structure (GstRTSPPermissionsImpl * impl,
|
||||
GstStructure * structure)
|
||||
{
|
||||
guint i, len;
|
||||
const gchar *role = gst_structure_get_name (structure);
|
||||
|
||||
len = impl->roles->len;
|
||||
for (i = 0; i < len; i++) {
|
||||
GstStructure *entry = g_ptr_array_index (impl->roles, i);
|
||||
|
||||
if (gst_structure_has_name (entry, role)) {
|
||||
g_ptr_array_remove_index_fast (impl->roles, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gst_structure_set_parent_refcount (structure,
|
||||
&impl->permissions.mini_object.refcount);
|
||||
g_ptr_array_add (impl->roles, structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_new:
|
||||
*
|
||||
|
@ -214,7 +236,6 @@ gst_rtsp_permissions_add_role_valist (GstRTSPPermissions * permissions,
|
|||
{
|
||||
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
|
||||
GstStructure *structure;
|
||||
guint i, len;
|
||||
|
||||
g_return_if_fail (GST_IS_RTSP_PERMISSIONS (permissions));
|
||||
g_return_if_fail (gst_mini_object_is_writable (&permissions->mini_object));
|
||||
|
@ -223,19 +244,27 @@ gst_rtsp_permissions_add_role_valist (GstRTSPPermissions * permissions,
|
|||
structure = gst_structure_new_valist (role, fieldname, var_args);
|
||||
g_return_if_fail (structure != NULL);
|
||||
|
||||
len = impl->roles->len;
|
||||
for (i = 0; i < len; i++) {
|
||||
GstStructure *entry = g_ptr_array_index (impl->roles, i);
|
||||
add_role_from_structure (impl, structure);
|
||||
}
|
||||
|
||||
if (gst_structure_has_name (entry, role)) {
|
||||
g_ptr_array_remove_index_fast (impl->roles, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* gst_rtsp_permissions_add_role_from_structure:
|
||||
*
|
||||
* Add a new role to @permissions based on @structure
|
||||
*/
|
||||
void
|
||||
gst_rtsp_permissions_add_role_from_structure (GstRTSPPermissions * permissions,
|
||||
GstStructure * structure)
|
||||
{
|
||||
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
|
||||
GstStructure *copy;
|
||||
|
||||
gst_structure_set_parent_refcount (structure,
|
||||
&impl->permissions.mini_object.refcount);
|
||||
g_ptr_array_add (impl->roles, structure);
|
||||
g_return_if_fail (GST_IS_RTSP_PERMISSIONS (permissions));
|
||||
g_return_if_fail (GST_IS_STRUCTURE (structure));
|
||||
|
||||
copy = gst_structure_copy (structure);
|
||||
|
||||
add_role_from_structure (impl, copy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,6 +91,9 @@ void gst_rtsp_permissions_add_role_empty (GstRTSPPermissions *
|
|||
const gchar * role);
|
||||
|
||||
GST_EXPORT
|
||||
void gst_rtsp_permissions_add_role_from_structure (GstRTSPPermissions * permissions,
|
||||
GstStructure *structure);
|
||||
GST_EXPORT
|
||||
void gst_rtsp_permissions_add_permission_for_role (GstRTSPPermissions * permissions,
|
||||
const gchar * role,
|
||||
const gchar * permission,
|
||||
|
|
|
@ -25,6 +25,7 @@ GST_START_TEST (test_permissions)
|
|||
{
|
||||
GstRTSPPermissions *perms;
|
||||
GstRTSPPermissions *copy;
|
||||
GstStructure *role_structure;
|
||||
|
||||
perms = gst_rtsp_permissions_new ();
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "missing", "permission1"));
|
||||
|
@ -110,6 +111,14 @@ GST_START_TEST (test_permissions)
|
|||
gst_rtsp_permissions_add_role_empty (perms, "noone");
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "noone", "permission1"));
|
||||
|
||||
role_structure = gst_structure_new ("tester", "permission1", G_TYPE_BOOLEAN,
|
||||
TRUE, NULL);
|
||||
gst_rtsp_permissions_add_role_from_structure (perms, role_structure);
|
||||
gst_structure_free (role_structure);
|
||||
fail_unless (gst_rtsp_permissions_is_allowed (perms, "tester",
|
||||
"permission1"));
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission2"));
|
||||
|
||||
gst_rtsp_permissions_unref (perms);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue