/* allow user and admin to access this resource */
permissions = gst_rtsp_permissions_new ();
gst_rtsp_permissions_add_role (permissions, "user",
- gst_structure_new ("user",
- "media.factory.access", G_TYPE_BOOLEAN, TRUE,
- "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
+ "media.factory.access", G_TYPE_BOOLEAN, TRUE,
+ "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
gst_rtsp_permissions_add_role (permissions, "admin",
- gst_structure_new ("admin",
- "media.factory.access", G_TYPE_BOOLEAN, TRUE,
- "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
+ "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_structure_new ("admin2",
- "media.factory.access", G_TYPE_BOOLEAN, TRUE,
- "media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL));
+ "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);
/* 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_structure_new ("admin2",
- "media.factory.access", G_TYPE_BOOLEAN, TRUE,
- "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
+ "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);
/* allow user and admin to access this resource */
permissions = gst_rtsp_permissions_new ();
gst_rtsp_permissions_add_role (permissions, "user",
- gst_structure_new ("user",
- "media.factory.access", G_TYPE_BOOLEAN, TRUE,
- "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
+ "media.factory.access", G_TYPE_BOOLEAN, TRUE,
+ "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
gst_rtsp_permissions_add_role (permissions, "admin",
- gst_structure_new ("admin",
- "media.factory.access", G_TYPE_BOOLEAN, TRUE,
- "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
+ "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);
{
GstRTSPPermissions permissions;
- /* Roles, array of RoleEntry */
- GArray *roles;
+ /* Roles, array of GstStructure */
+ GPtrArray *roles;
} GstRTSPPermissionsImpl;
-typedef struct
-{
- gchar *role;
- GstStructure *structure;
-} RoleEntry;
-
static void
-clear_role_entry (RoleEntry * role)
+free_structure (GstStructure * structure)
{
- g_free (role->role);
- gst_structure_set_parent_refcount (role->structure, NULL);
- gst_structure_free (role->structure);
+ gst_structure_set_parent_refcount (structure, NULL);
+ gst_structure_free (structure);
}
//GST_DEBUG_CATEGORY_STATIC (rtsp_permissions_debug);
{
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
- g_array_free (impl->roles, TRUE);
+ g_ptr_array_free (impl->roles, TRUE);
g_slice_free1 (sizeof (GstRTSPPermissionsImpl), 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);
+ permissions->roles =
+ g_ptr_array_new_with_free_func ((GDestroyNotify) free_structure);
}
/**
* gst_rtsp_permissions_add_role:
* @permissions: a #GstRTSPPermissions
* @role: a role
- * @structure: the permissions structure
+ * @fielname: the first field name
+ * @...: additional arguments
*
- * Add the configuration in @structure to @permissions for @role.
+ * Add a new @role to @permissions with the given variables. The fields
+ * are the same layout as gst_structure_new().
*/
void
gst_rtsp_permissions_add_role (GstRTSPPermissions * permissions,
- const gchar * role, GstStructure * structure)
+ const gchar * role, const gchar * fieldname, ...)
+{
+ va_list var_args;
+
+ va_start (var_args, fieldname);
+ gst_rtsp_permissions_add_role_valist (permissions, role, fieldname, var_args);
+ va_end (var_args);
+}
+
+/**
+ * gst_rtsp_permissions_add_role_valist:
+ * @permissions: a #GstRTSPPermissions
+ * @role: a role
+ * @fielname: the first field name
+ * @var_args: additional fields to add
+ *
+ * Add a new @role to @permissions with the given variables. Structure fields
+ * are set according to the varargs in a manner similar to gst_structure_new().
+ */
+void
+gst_rtsp_permissions_add_role_valist (GstRTSPPermissions * permissions,
+ const gchar * role, const gchar * fieldname, va_list var_args)
{
GstRTSPPermissionsImpl *impl = (GstRTSPPermissionsImpl *) permissions;
+ GstStructure *structure;
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 (fieldname != NULL);
+
+ structure = gst_structure_new_valist (role, fieldname, var_args);
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);
+ GstStructure *entry = g_ptr_array_index (impl->roles, i);
- if (g_str_equal (entry->role, role)) {
- gst_structure_free (entry->structure);
- entry->structure = structure;
+ if (gst_structure_has_name (entry, role)) {
+ gst_structure_free (entry);
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_structure_set_parent_refcount (structure,
+ &impl->permissions.mini_object.refcount);
+ if (!found)
+ g_ptr_array_add (impl->roles, structure);
+ else
+ g_ptr_array_index (impl->roles, i) = structure;
}
/**
len = impl->roles->len;
for (i = 0; i < len; i++) {
- RoleEntry *entry = &g_array_index (impl->roles, RoleEntry, i);
+ GstStructure *entry = g_ptr_array_index (impl->roles, i);
- if (g_str_equal (entry->role, role))
- return entry->structure;
+ if (gst_structure_has_name (entry, role))
+ return entry;
}
return NULL;
}
}
-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);
+GstRTSPPermissions * gst_rtsp_permissions_new (void);
+
+void gst_rtsp_permissions_add_role (GstRTSPPermissions *permissions,
+ const gchar *role,
+ const gchar *field_name, ...);
+void gst_rtsp_permissions_add_role_valist (GstRTSPPermissions *permissions,
+ const gchar *role,
+ const gchar *field_name,
+ va_list var_args);
+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