mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 04:22:27 +00:00
permissions: add permissions object
Add a mini object to store permissions based on a role.
This commit is contained in:
parent
a63f4a2a4c
commit
8f008807ad
3 changed files with 306 additions and 0 deletions
|
@ -7,6 +7,7 @@ public_headers = \
|
|||
rtsp-media-factory.h \
|
||||
rtsp-media-factory-uri.h \
|
||||
rtsp-mount-points.h \
|
||||
rtsp-permissions.h \
|
||||
rtsp-stream.h \
|
||||
rtsp-stream-transport.h \
|
||||
rtsp-session.h \
|
||||
|
@ -25,6 +26,7 @@ c_sources = \
|
|||
rtsp-media-factory.c \
|
||||
rtsp-media-factory-uri.c \
|
||||
rtsp-mount-points.c \
|
||||
rtsp-permissions.c \
|
||||
rtsp-stream.c \
|
||||
rtsp-stream-transport.c \
|
||||
rtsp-session.c \
|
||||
|
|
209
gst/rtsp-server/rtsp-permissions.c
Normal file
209
gst/rtsp-server/rtsp-permissions.c
Normal file
|
@ -0,0 +1,209 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2013 Wim Taymans <wim.taymans at gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "rtsp-permissions.h"
|
||||
|
||||
typedef struct _GstRTSPPermissionsImpl
|
||||
{
|
||||
GstRTSPPermissions permissions;
|
||||
|
||||
/* Roles, array of RoleEntry */
|
||||
GArray *roles;
|
||||
} GstRTSPPermissionsImpl;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar *role;
|
||||
GstStructure *structure;
|
||||
} RoleEntry;
|
||||
|
||||
static void
|
||||
clear_role_entry (RoleEntry * role)
|
||||
{
|
||||
g_free (role->role);
|
||||
gst_structure_set_parent_refcount (role->structure, NULL);
|
||||
gst_structure_free (role->structure);
|
||||
}
|
||||
|
||||
//GST_DEBUG_CATEGORY_STATIC (rtsp_permissions_debug);
|
||||
//#define GST_CAT_DEFAULT rtsp_permissions_debug
|
||||
|
||||
GST_DEFINE_MINI_OBJECT_TYPE (GstRTSPPermissions, gst_rtsp_permissions);
|
||||
|
||||
static void gst_rtsp_permissions_init (GstRTSPPermissionsImpl * permissions,
|
||||
GstStructure * structure);
|
||||
|
||||
static void
|
||||
_gst_rtsp_permissions_free (GstRTSPPermissions * permissions)
|
||||
{
|
||||
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
|
||||
|
||||
g_array_free (impl->roles, TRUE);
|
||||
|
||||
g_slice_free1 (sizeof (GstRTSPPermissionsImpl), permissions);
|
||||
}
|
||||
|
||||
static GstRTSPPermissions *
|
||||
_gst_rtsp_permissions_copy (GstRTSPPermissionsImpl * permissions)
|
||||
{
|
||||
GstRTSPPermissionsImpl *copy;
|
||||
GstStructure *structure;
|
||||
|
||||
copy = g_slice_new0 (GstRTSPPermissionsImpl);
|
||||
gst_rtsp_permissions_init (copy, structure);
|
||||
|
||||
return GST_RTSP_PERMISSIONS (copy);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_rtsp_permissions_init (GstRTSPPermissionsImpl * permissions,
|
||||
GstStructure * structure)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (permissions), 0,
|
||||
GST_TYPE_RTSP_PERMISSIONS,
|
||||
(GstMiniObjectCopyFunction) _gst_rtsp_permissions_copy, NULL,
|
||||
(GstMiniObjectFreeFunction) _gst_rtsp_permissions_free);
|
||||
|
||||
permissions->roles = g_array_new (FALSE, TRUE, sizeof (RoleEntry));
|
||||
g_array_set_clear_func (permissions->roles,
|
||||
(GDestroyNotify) clear_role_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_new:
|
||||
*
|
||||
* Create a new empty Authorization permissions.
|
||||
*
|
||||
* Returns: (transfer full): a new empty authorization permissions.
|
||||
*/
|
||||
GstRTSPPermissions *
|
||||
gst_rtsp_permissions_new (void)
|
||||
{
|
||||
GstRTSPPermissionsImpl *permissions;
|
||||
|
||||
permissions = g_slice_new0 (GstRTSPPermissionsImpl);
|
||||
|
||||
gst_rtsp_permissions_init (permissions,
|
||||
gst_structure_new_empty ("GstRTSPPermissions"));
|
||||
|
||||
return GST_RTSP_PERMISSIONS (permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_add_role:
|
||||
* @permissions: a #GstRTSPPermissions
|
||||
*
|
||||
* Add the configuration in @structure to @permissions for @role.
|
||||
*/
|
||||
void
|
||||
gst_rtsp_permissions_add_role (GstRTSPPermissions * permissions,
|
||||
const gchar * role, GstStructure * structure)
|
||||
{
|
||||
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
|
||||
gint i, len;
|
||||
RoleEntry item;
|
||||
gboolean found;
|
||||
|
||||
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 (structure != NULL);
|
||||
|
||||
len = impl->roles->len;
|
||||
found = FALSE;
|
||||
for (i = 0; i < len; i++) {
|
||||
RoleEntry *entry = &g_array_index (impl->roles, RoleEntry, i);
|
||||
|
||||
if (g_str_equal (entry->role, role)) {
|
||||
gst_structure_free (entry->structure);
|
||||
entry->structure = structure;
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
item.role = g_strdup (role);
|
||||
item.structure = structure;
|
||||
gst_structure_set_parent_refcount (structure,
|
||||
&impl->permissions.mini_object.refcount);
|
||||
g_array_append_val (impl->roles, item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_remove_role:
|
||||
* @permissions: a #GstRTSPPermissions
|
||||
*
|
||||
*/
|
||||
void
|
||||
gst_rtsp_permissions_remove_role (GstRTSPPermissions * permissions,
|
||||
const gchar * role)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_get_role:
|
||||
* @permissions: a #GstRTSPPermissions
|
||||
*
|
||||
*/
|
||||
const GstStructure *
|
||||
gst_rtsp_permissions_get_role (GstRTSPPermissions * permissions,
|
||||
const gchar * role)
|
||||
{
|
||||
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
|
||||
gint i, len;
|
||||
|
||||
g_return_val_if_fail (GST_IS_RTSP_PERMISSIONS (permissions), NULL);
|
||||
g_return_val_if_fail (role != NULL, NULL);
|
||||
|
||||
len = impl->roles->len;
|
||||
for (i = 0; i < len; i++) {
|
||||
RoleEntry *entry = &g_array_index (impl->roles, RoleEntry, i);
|
||||
|
||||
if (g_str_equal (entry->role, role))
|
||||
return entry->structure;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_rtsp_permissions_is_allowed (GstRTSPPermissions * permissions,
|
||||
const gchar * role, const gchar * permission)
|
||||
{
|
||||
const GstStructure *str;
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (GST_IS_RTSP_PERMISSIONS (permissions), FALSE);
|
||||
g_return_val_if_fail (role != NULL, FALSE);
|
||||
g_return_val_if_fail (permission != NULL, FALSE);
|
||||
|
||||
str = gst_rtsp_permissions_get_role (permissions, role);
|
||||
if (str == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (!gst_structure_get_boolean (str, permission, &result))
|
||||
result = FALSE;
|
||||
|
||||
return result;
|
||||
}
|
95
gst/rtsp-server/rtsp-permissions.h
Normal file
95
gst/rtsp-server/rtsp-permissions.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2010 Wim Taymans <wim.taymans at gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#ifndef __GST_RTSP_PERMISSIONS_H__
|
||||
#define __GST_RTSP_PERMISSIONS_H__
|
||||
|
||||
typedef struct _GstRTSPPermissions GstRTSPPermissions;
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GType gst_rtsp_permissions_get_type (void);
|
||||
|
||||
#define GST_TYPE_RTSP_PERMISSIONS (gst_rtsp_permissions_get_type ())
|
||||
#define GST_IS_RTSP_PERMISSIONS(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_RTSP_PERMISSIONS))
|
||||
#define GST_RTSP_PERMISSIONS_CAST(obj) ((GstRTSPPermissions*)(obj))
|
||||
#define GST_RTSP_PERMISSIONS(obj) (GST_RTSP_PERMISSIONS_CAST(obj))
|
||||
|
||||
|
||||
/**
|
||||
* GstRTSPPermissions:
|
||||
*
|
||||
* The opaque permissions structure. It is used to define the permissions
|
||||
* of objects in different roles.
|
||||
*/
|
||||
struct _GstRTSPPermissions {
|
||||
GstMiniObject mini_object;
|
||||
};
|
||||
|
||||
/* refcounting */
|
||||
/**
|
||||
* gst_rtsp_permissions_ref:
|
||||
* @permissions: The permissions to refcount
|
||||
*
|
||||
* Increase the refcount of this permissions.
|
||||
*
|
||||
* Returns: (transfer full): @permissions (for convenience when doing assignments)
|
||||
*/
|
||||
#ifdef _FOOL_GTK_DOC_
|
||||
G_INLINE_FUNC GstRTSPPermissions * gst_rtsp_permissions_ref (GstRTSPPermissions * permissions);
|
||||
#endif
|
||||
|
||||
static inline GstRTSPPermissions *
|
||||
gst_rtsp_permissions_ref (GstRTSPPermissions * permissions)
|
||||
{
|
||||
return (GstRTSPPermissions *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (permissions));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_permissions_unref:
|
||||
* @permissions: (transfer full): the permissions to refcount
|
||||
*
|
||||
* Decrease the refcount of an permissions, freeing it if the refcount reaches 0.
|
||||
*/
|
||||
#ifdef _FOOL_GTK_DOC_
|
||||
G_INLINE_FUNC void gst_rtsp_permissions_unref (GstRTSPPermissions * permissions);
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
gst_rtsp_permissions_unref (GstRTSPPermissions * permissions)
|
||||
{
|
||||
gst_mini_object_unref (GST_MINI_OBJECT_CAST (permissions));
|
||||
}
|
||||
|
||||
|
||||
GstRTSPPermissions * gst_rtsp_permissions_new (void);
|
||||
|
||||
void gst_rtsp_permissions_add_role (GstRTSPPermissions *permissions, const gchar *role,
|
||||
GstStructure *structure);
|
||||
void gst_rtsp_permissions_remove_role (GstRTSPPermissions *permissions, const gchar *role);
|
||||
const GstStructure * gst_rtsp_permissions_get_role (GstRTSPPermissions *permissions, const gchar *role);
|
||||
|
||||
gboolean gst_rtsp_permissions_is_allowed (GstRTSPPermissions *permissions,
|
||||
const gchar *role, const gchar *permission);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_RTSP_PERMISSIONS_H__ */
|
Loading…
Reference in a new issue