mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
permissions: add some new API to make this usable from bindings
https://bugzilla.gnome.org/show_bug.cgi?id=787073
This commit is contained in:
parent
8708262ebe
commit
b1f515178a
4 changed files with 90 additions and 1 deletions
|
@ -356,6 +356,8 @@ gst_rtsp_permissions_ref
|
|||
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_permission_for_role
|
||||
gst_rtsp_permissions_remove_role
|
||||
gst_rtsp_permissions_get_role
|
||||
gst_rtsp_permissions_is_allowed
|
||||
|
|
|
@ -123,6 +123,60 @@ gst_rtsp_permissions_new (void)
|
|||
return GST_RTSP_PERMISSIONS (permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_add_permission_for_role:
|
||||
* @permissions: a #GstRTSPPermissions
|
||||
* @role: a role
|
||||
* @permission: the permission
|
||||
* @allowed: whether the role has this permission or not
|
||||
*
|
||||
* Add a new @permission for @role to @permissions with the access in @allowed.
|
||||
*
|
||||
* Since: 1.14
|
||||
*/
|
||||
void
|
||||
gst_rtsp_permissions_add_permission_for_role (GstRTSPPermissions * permissions,
|
||||
const gchar * role, const gchar * permission, gboolean allowed)
|
||||
{
|
||||
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
|
||||
guint i, len;
|
||||
|
||||
g_return_if_fail (GST_IS_RTSP_PERMISSIONS (permissions));
|
||||
g_return_if_fail (gst_mini_object_is_writable (&permissions->mini_object));
|
||||
g_return_if_fail (role != NULL);
|
||||
g_return_if_fail (permission != NULL);
|
||||
|
||||
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)) {
|
||||
gst_structure_set (entry, permission, G_TYPE_BOOLEAN, allowed, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gst_rtsp_permissions_add_role (permissions, role,
|
||||
permission, G_TYPE_BOOLEAN, allowed, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_add_role_empty: (rename-to gst_rtsp_permissions_add_role)
|
||||
* @permissions: a #GstRTSPPermissions
|
||||
* @role: a role
|
||||
*
|
||||
* Add a new @role to @permissions without any permissions. You can add
|
||||
* permissions for the role with gst_rtsp_permissions_add_permission_for_role().
|
||||
*
|
||||
* Since: 1.14
|
||||
*/
|
||||
void
|
||||
gst_rtsp_permissions_add_role_empty (GstRTSPPermissions * permissions,
|
||||
const gchar * role)
|
||||
{
|
||||
gst_rtsp_permissions_add_role (permissions, role, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_add_role:
|
||||
* @permissions: a #GstRTSPPermissions
|
||||
|
@ -165,7 +219,6 @@ gst_rtsp_permissions_add_role_valist (GstRTSPPermissions * permissions,
|
|||
g_return_if_fail (GST_IS_RTSP_PERMISSIONS (permissions));
|
||||
g_return_if_fail (gst_mini_object_is_writable (&permissions->mini_object));
|
||||
g_return_if_fail (role != NULL);
|
||||
g_return_if_fail (fieldname != NULL);
|
||||
|
||||
structure = gst_structure_new_valist (role, fieldname, var_args);
|
||||
g_return_if_fail (structure != NULL);
|
||||
|
|
|
@ -86,6 +86,16 @@ void gst_rtsp_permissions_add_role_valist (GstRTSPPermissions *
|
|||
const gchar *fieldname,
|
||||
va_list var_args);
|
||||
|
||||
GST_EXPORT
|
||||
void gst_rtsp_permissions_add_role_empty (GstRTSPPermissions * permissions,
|
||||
const gchar * role);
|
||||
|
||||
GST_EXPORT
|
||||
void gst_rtsp_permissions_add_permission_for_role (GstRTSPPermissions * permissions,
|
||||
const gchar * role,
|
||||
const gchar * permission,
|
||||
gboolean allowed);
|
||||
|
||||
GST_EXPORT
|
||||
void gst_rtsp_permissions_remove_role (GstRTSPPermissions *permissions,
|
||||
const gchar *role);
|
||||
|
|
|
@ -86,6 +86,30 @@ GST_START_TEST (test_permissions)
|
|||
fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2"));
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission1"));
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2"));
|
||||
|
||||
/* _add_permission_for_role() should overwrite existing or create new role */
|
||||
fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1"));
|
||||
gst_rtsp_permissions_add_permission_for_role (perms, "admin", "permission1",
|
||||
FALSE);
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "admin", "permission1"));
|
||||
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission1"));
|
||||
gst_rtsp_permissions_add_permission_for_role (perms, "tester", "permission1",
|
||||
TRUE);
|
||||
fail_unless (gst_rtsp_permissions_is_allowed (perms, "tester",
|
||||
"permission1"));
|
||||
gst_rtsp_permissions_add_permission_for_role (perms, "tester", "permission1",
|
||||
FALSE);
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission1"));
|
||||
gst_rtsp_permissions_add_permission_for_role (perms, "tester", "permission2",
|
||||
TRUE);
|
||||
fail_unless (gst_rtsp_permissions_is_allowed (perms, "tester",
|
||||
"permission2"));
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "tester", "permission3"));
|
||||
|
||||
gst_rtsp_permissions_add_role_empty (perms, "noone");
|
||||
fail_if (gst_rtsp_permissions_is_allowed (perms, "noone", "permission1"));
|
||||
|
||||
gst_rtsp_permissions_unref (perms);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue