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:
Tim-Philipp Müller 2018-01-18 23:53:20 +00:00
parent 8708262ebe
commit b1f515178a
4 changed files with 90 additions and 1 deletions

View file

@ -356,6 +356,8 @@ gst_rtsp_permissions_ref
gst_rtsp_permissions_unref gst_rtsp_permissions_unref
gst_rtsp_permissions_add_role gst_rtsp_permissions_add_role
gst_rtsp_permissions_add_role_valist 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_remove_role
gst_rtsp_permissions_get_role gst_rtsp_permissions_get_role
gst_rtsp_permissions_is_allowed gst_rtsp_permissions_is_allowed

View file

@ -123,6 +123,60 @@ gst_rtsp_permissions_new (void)
return GST_RTSP_PERMISSIONS (permissions); 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: * gst_rtsp_permissions_add_role:
* @permissions: a #GstRTSPPermissions * @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_IS_RTSP_PERMISSIONS (permissions));
g_return_if_fail (gst_mini_object_is_writable (&permissions->mini_object)); g_return_if_fail (gst_mini_object_is_writable (&permissions->mini_object));
g_return_if_fail (role != NULL); g_return_if_fail (role != NULL);
g_return_if_fail (fieldname != NULL);
structure = gst_structure_new_valist (role, fieldname, var_args); structure = gst_structure_new_valist (role, fieldname, var_args);
g_return_if_fail (structure != NULL); g_return_if_fail (structure != NULL);

View file

@ -86,6 +86,16 @@ void gst_rtsp_permissions_add_role_valist (GstRTSPPermissions *
const gchar *fieldname, const gchar *fieldname,
va_list var_args); 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 GST_EXPORT
void gst_rtsp_permissions_remove_role (GstRTSPPermissions *permissions, void gst_rtsp_permissions_remove_role (GstRTSPPermissions *permissions,
const gchar *role); const gchar *role);

View file

@ -86,6 +86,30 @@ GST_START_TEST (test_permissions)
fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin", "permission2")); 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", "permission1"));
fail_if (gst_rtsp_permissions_is_allowed (perms, "user", "permission2")); 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); gst_rtsp_permissions_unref (perms);
} }