2021-02-03 15:16:22 -05:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2021 Collabora Ltd.
|
|
|
|
|
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-29 10:43:06 -04:00
|
|
|
#include <wp/wp.h>
|
2023-06-04 22:22:26 +03:00
|
|
|
#include "dbus-connection-state.h"
|
2021-02-03 15:16:22 -05:00
|
|
|
|
log: implement a log topics system, like pipewire
The intention is to make checks for enabled log topics faster.
Every topic has its own structure that is statically defined in the file
where the logs are printed from. The structure is initialized transparently
when it is first used and it contains all the log level flags for the levels
that this topic should print messages. It is then checked on the wp_log()
macro before printing the message.
Topics from SPA/PipeWire are also handled natively, so messages are printed
directly without checking if the topic is enabled, since the PipeWire and SPA
macros do the checking themselves.
Messages coming from GLib are checked inside the handler.
An internal WpLogFields object is used to manage the state of each log
message, populating all the fields appropriately from the place they
are coming from (wp_log, spa_log, glib log), formatting the message and
then printing it. For printing to the journald, we still use the glib
message handler, converting all the needed fields to GLogField on demand.
That message handler does not do any checks for the topic or the level, so
we can just call it to send the message.
2023-05-16 11:51:29 +03:00
|
|
|
WP_DEFINE_LOCAL_LOG_TOPIC ("m-portal-permissionstore")
|
|
|
|
|
|
2021-02-03 15:16:22 -05:00
|
|
|
#define DBUS_INTERFACE_NAME "org.freedesktop.impl.portal.PermissionStore"
|
|
|
|
|
#define DBUS_OBJECT_PATH "/org/freedesktop/impl/portal/PermissionStore"
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
2022-04-29 10:32:15 -04:00
|
|
|
ACTION_GET_DBUS,
|
2021-02-03 15:16:22 -05:00
|
|
|
ACTION_LOOKUP,
|
|
|
|
|
ACTION_SET,
|
|
|
|
|
SIGNAL_CHANGED,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
2022-04-29 10:43:06 -04:00
|
|
|
struct _WpPortalPermissionStorePlugin
|
|
|
|
|
{
|
|
|
|
|
WpPlugin parent;
|
|
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
WpPlugin *dbus;
|
2022-04-29 10:43:06 -04:00
|
|
|
guint signal_id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
G_DECLARE_FINAL_TYPE (WpPortalPermissionStorePlugin,
|
|
|
|
|
wp_portal_permissionstore_plugin, WP, PORTAL_PERMISSIONSTORE_PLUGIN,
|
|
|
|
|
WpPlugin)
|
|
|
|
|
G_DEFINE_TYPE (WpPortalPermissionStorePlugin, wp_portal_permissionstore_plugin,
|
|
|
|
|
WP_TYPE_PLUGIN)
|
|
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
static gpointer
|
|
|
|
|
wp_portal_permissionstore_plugin_get_dbus (WpPortalPermissionStorePlugin *self)
|
|
|
|
|
{
|
|
|
|
|
return self->dbus ? g_object_ref (self->dbus) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-03 15:16:22 -05:00
|
|
|
static GVariant *
|
|
|
|
|
wp_portal_permissionstore_plugin_lookup (WpPortalPermissionStorePlugin *self,
|
|
|
|
|
const gchar *table, const gchar *id)
|
|
|
|
|
{
|
2022-04-29 10:32:15 -04:00
|
|
|
g_autoptr (GDBusConnection) conn = NULL;
|
2021-02-03 15:16:22 -05:00
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
g_autoptr (GVariant) res = NULL;
|
|
|
|
|
GVariant *permissions = NULL, *data = NULL;
|
|
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
g_object_get (self->dbus, "connection", &conn, NULL);
|
2022-04-29 10:32:15 -04:00
|
|
|
g_return_val_if_fail (conn, NULL);
|
2021-02-03 15:16:22 -05:00
|
|
|
|
|
|
|
|
/* Lookup */
|
2022-04-29 10:32:15 -04:00
|
|
|
res = g_dbus_connection_call_sync (conn, DBUS_INTERFACE_NAME,
|
2021-02-03 15:16:22 -05:00
|
|
|
DBUS_OBJECT_PATH, DBUS_INTERFACE_NAME, "Lookup",
|
|
|
|
|
g_variant_new ("(ss)", table, id), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
|
|
|
|
|
&error);
|
|
|
|
|
if (error) {
|
|
|
|
|
wp_warning_object (self, "Failed to call Lookup: %s", error->message);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the permissions */
|
|
|
|
|
g_variant_get (res, "(@a{sas}@v)", &permissions, &data);
|
|
|
|
|
|
|
|
|
|
return permissions ? g_variant_ref (permissions) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
wp_portal_permissionstore_plugin_set (WpPortalPermissionStorePlugin *self,
|
|
|
|
|
const gchar *table, gboolean create, const gchar *id, GVariant *permissions)
|
|
|
|
|
{
|
2022-04-29 10:32:15 -04:00
|
|
|
g_autoptr (GDBusConnection) conn = NULL;
|
2021-02-03 15:16:22 -05:00
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
g_autoptr (GVariant) res = NULL;
|
|
|
|
|
GVariant *data = NULL;
|
|
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
g_object_get (self->dbus, "connection", &conn, NULL);
|
2022-04-29 10:32:15 -04:00
|
|
|
g_return_if_fail (conn);
|
2021-02-03 15:16:22 -05:00
|
|
|
|
|
|
|
|
/* Set */
|
2022-04-29 10:32:15 -04:00
|
|
|
res = g_dbus_connection_call_sync (conn, DBUS_INTERFACE_NAME,
|
2021-02-03 15:16:22 -05:00
|
|
|
DBUS_OBJECT_PATH, DBUS_INTERFACE_NAME, "Set",
|
|
|
|
|
g_variant_new ("(sbs@a{sas}@v)", table, id, permissions, data), NULL,
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
|
|
|
|
|
if (error)
|
|
|
|
|
wp_warning_object (self, "Failed to call Set: %s", error->message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
wp_portal_permissionstore_plugin_changed (GDBusConnection *connection,
|
|
|
|
|
const gchar *sender_name, const gchar *object_path,
|
|
|
|
|
const gchar *interface_name, const gchar *signal_name,
|
|
|
|
|
GVariant *parameters, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
WpPortalPermissionStorePlugin *self =
|
|
|
|
|
WP_PORTAL_PERMISSIONSTORE_PLUGIN (user_data);
|
|
|
|
|
const char *table = NULL, *id = NULL;
|
|
|
|
|
gboolean deleted = FALSE;
|
|
|
|
|
GVariant *permissions = NULL, *data = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (parameters);
|
|
|
|
|
g_variant_get (parameters, "(ssb@v@a{sas})", &table, &id, &deleted, &data,
|
|
|
|
|
&permissions);
|
|
|
|
|
|
|
|
|
|
g_signal_emit (self, signals[SIGNAL_CHANGED], 0, table, id, deleted,
|
|
|
|
|
permissions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2022-04-29 10:32:15 -04:00
|
|
|
clear_signal (WpPortalPermissionStorePlugin *self)
|
2021-02-03 15:16:22 -05:00
|
|
|
{
|
2022-04-29 10:32:15 -04:00
|
|
|
g_autoptr (GDBusConnection) conn = NULL;
|
2021-02-03 15:16:22 -05:00
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
g_object_get (self->dbus, "connection", &conn, NULL);
|
2022-04-29 10:32:15 -04:00
|
|
|
if (conn && self->signal_id > 0) {
|
|
|
|
|
g_dbus_connection_signal_unsubscribe (conn, self->signal_id);
|
|
|
|
|
self->signal_id = 0;
|
2021-02-03 15:16:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
static void
|
2023-06-04 22:22:26 +03:00
|
|
|
on_dbus_state_changed (GObject * dbus, GParamSpec * spec,
|
2022-04-29 10:32:15 -04:00
|
|
|
WpPortalPermissionStorePlugin *self)
|
2021-02-03 15:16:22 -05:00
|
|
|
{
|
2023-06-04 22:22:26 +03:00
|
|
|
WpDBusConnectionState state = -1;
|
|
|
|
|
g_object_get (dbus, "state", &state, NULL);
|
2021-09-24 09:31:29 -04:00
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
switch (state) {
|
2023-06-04 22:22:26 +03:00
|
|
|
case WP_DBUS_CONNECTION_STATE_CONNECTED: {
|
2022-04-29 10:32:15 -04:00
|
|
|
g_autoptr (GDBusConnection) conn = NULL;
|
2021-09-24 09:31:29 -04:00
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
g_object_get (dbus, "connection", &conn, NULL);
|
2022-04-29 10:32:15 -04:00
|
|
|
g_return_if_fail (conn);
|
2021-09-24 09:31:29 -04:00
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
self->signal_id = g_dbus_connection_signal_subscribe (conn,
|
|
|
|
|
DBUS_INTERFACE_NAME, DBUS_INTERFACE_NAME, "Changed", NULL, NULL,
|
|
|
|
|
G_DBUS_SIGNAL_FLAGS_NONE, wp_portal_permissionstore_plugin_changed,
|
|
|
|
|
self, NULL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-09-24 09:31:29 -04:00
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
case WP_DBUS_CONNECTION_STATE_CONNECTING:
|
|
|
|
|
case WP_DBUS_CONNECTION_STATE_CLOSED:
|
2022-04-29 10:32:15 -04:00
|
|
|
clear_signal (self);
|
|
|
|
|
break;
|
2021-02-03 15:16:22 -05:00
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
default:
|
|
|
|
|
break;
|
2021-02-03 15:16:22 -05:00
|
|
|
}
|
2021-09-24 09:31:29 -04:00
|
|
|
}
|
|
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
static void
|
|
|
|
|
wp_portal_permissionstore_plugin_init (WpPortalPermissionStorePlugin * self)
|
2021-09-24 09:31:29 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-06-04 22:22:26 +03:00
|
|
|
wp_portal_permissionstore_plugin_enable (WpPlugin * plugin,
|
|
|
|
|
WpTransition * transition)
|
2021-09-24 09:31:29 -04:00
|
|
|
{
|
2022-04-29 10:32:15 -04:00
|
|
|
WpPortalPermissionStorePlugin *self =
|
2023-06-04 22:22:26 +03:00
|
|
|
WP_PORTAL_PERMISSIONSTORE_PLUGIN (plugin);
|
2021-09-24 09:31:29 -04:00
|
|
|
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (self));
|
2021-02-03 15:16:22 -05:00
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
self->dbus = wp_plugin_find (core, "dbus-connection");
|
|
|
|
|
if (!self->dbus) {
|
|
|
|
|
wp_transition_return_error (transition, g_error_new (WP_DOMAIN_LIBRARY,
|
|
|
|
|
WP_LIBRARY_ERROR_INVARIANT,
|
|
|
|
|
"dbus-connection module must be loaded before portal-permissionstore"));
|
2021-09-24 09:31:29 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
g_signal_connect_object (self->dbus, "notify::state",
|
|
|
|
|
G_CALLBACK (on_dbus_state_changed), self, 0);
|
|
|
|
|
on_dbus_state_changed (G_OBJECT (self->dbus), NULL, self);
|
2021-02-03 15:16:22 -05:00
|
|
|
|
2023-06-04 22:22:26 +03:00
|
|
|
wp_object_update_features (WP_OBJECT (self), WP_PLUGIN_FEATURE_ENABLED, 0);
|
2021-02-03 15:16:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
wp_portal_permissionstore_plugin_disable (WpPlugin * plugin)
|
|
|
|
|
{
|
|
|
|
|
WpPortalPermissionStorePlugin *self =
|
|
|
|
|
WP_PORTAL_PERMISSIONSTORE_PLUGIN (plugin);
|
|
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
clear_signal (self);
|
2023-06-04 22:22:26 +03:00
|
|
|
g_clear_object (&self->dbus);
|
2021-09-24 09:31:29 -04:00
|
|
|
|
|
|
|
|
wp_object_update_features (WP_OBJECT (self), 0, WP_PLUGIN_FEATURE_ENABLED);
|
2021-02-03 15:16:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
wp_portal_permissionstore_plugin_class_init (
|
|
|
|
|
WpPortalPermissionStorePluginClass * klass)
|
|
|
|
|
{
|
|
|
|
|
WpPluginClass *plugin_class = (WpPluginClass *) klass;
|
|
|
|
|
|
|
|
|
|
plugin_class->enable = wp_portal_permissionstore_plugin_enable;
|
|
|
|
|
plugin_class->disable = wp_portal_permissionstore_plugin_disable;
|
|
|
|
|
|
2022-04-29 10:32:15 -04:00
|
|
|
/**
|
|
|
|
|
* WpPortalPermissionStorePlugin::get-dbus:
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the dbus object
|
|
|
|
|
*/
|
|
|
|
|
signals[ACTION_GET_DBUS] = g_signal_new_class_handler (
|
|
|
|
|
"get-dbus", G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
(GCallback) wp_portal_permissionstore_plugin_get_dbus,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
G_TYPE_OBJECT, 0);
|
2021-02-03 15:16:22 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WpPortalPermissionStorePlugin::lookup:
|
2021-05-13 17:54:58 +03:00
|
|
|
*
|
|
|
|
|
* @brief
|
|
|
|
|
* @em table: the table name
|
|
|
|
|
* @em id: the Id name
|
2021-02-03 15:16:22 -05:00
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the GVariant with permissions
|
|
|
|
|
*/
|
|
|
|
|
signals[ACTION_LOOKUP] = g_signal_new_class_handler (
|
|
|
|
|
"lookup", G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
(GCallback) wp_portal_permissionstore_plugin_lookup,
|
|
|
|
|
NULL, NULL, NULL, G_TYPE_VARIANT,
|
|
|
|
|
2, G_TYPE_STRING, G_TYPE_STRING);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WpPortalPermissionStorePlugin::set:
|
2021-05-13 17:54:58 +03:00
|
|
|
*
|
|
|
|
|
* @brief
|
|
|
|
|
* @em table: the table name
|
|
|
|
|
* @em create: whether to create the table if it does not exist
|
|
|
|
|
* @em id: the Id name
|
|
|
|
|
* @em permissions: the permissions
|
2021-02-03 15:16:22 -05:00
|
|
|
*
|
|
|
|
|
* Sets the permissions in the permission store
|
|
|
|
|
*/
|
|
|
|
|
signals[ACTION_SET] = g_signal_new_class_handler (
|
|
|
|
|
"set", G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
|
(GCallback) wp_portal_permissionstore_plugin_set,
|
|
|
|
|
NULL, NULL, NULL, G_TYPE_NONE,
|
|
|
|
|
4, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_VARIANT);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WpPortalPermissionStorePlugin::changed:
|
2021-05-13 17:54:58 +03:00
|
|
|
*
|
|
|
|
|
* @brief
|
|
|
|
|
* @em table: the table name
|
|
|
|
|
* @em id: the Id name
|
|
|
|
|
* @em deleted: whether the permission was deleted or not
|
|
|
|
|
* @em permissions: the GVariant with permissions
|
2021-02-03 15:16:22 -05:00
|
|
|
*
|
|
|
|
|
* Signaled when the permissions changed
|
|
|
|
|
*/
|
|
|
|
|
signals[SIGNAL_CHANGED] = g_signal_new (
|
|
|
|
|
"changed", G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST, 0,
|
|
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 4,
|
|
|
|
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_VARIANT);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 13:11:14 -05:00
|
|
|
WP_PLUGIN_EXPORT GObject *
|
2023-05-25 18:29:58 +03:00
|
|
|
wireplumber__module_init (WpCore * core, WpSpaJson * args, GError ** error)
|
2021-02-03 15:16:22 -05:00
|
|
|
{
|
2023-02-09 13:11:14 -05:00
|
|
|
return G_OBJECT (g_object_new (
|
|
|
|
|
wp_portal_permissionstore_plugin_get_type(),
|
2021-02-03 15:16:22 -05:00
|
|
|
"name", "portal-permissionstore",
|
|
|
|
|
"core", core,
|
|
|
|
|
NULL));
|
|
|
|
|
}
|