|
Packit Service |
b23acc |
// SPDX-License-Identifier: LGPL-2.1+
|
|
Packit Service |
b23acc |
/*
|
|
Packit Service |
b23acc |
* Copyright (C) 2019 Red Hat, Inc.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-default.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-dbus-aux.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
_nm_dbus_connection_call_get_name_owner_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *res,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
gs_unref_variant GVariant *ret = NULL;
|
|
Packit Service |
b23acc |
gs_free_error GError *error = NULL;
|
|
Packit Service |
b23acc |
const char *owner = NULL;
|
|
Packit Service |
b23acc |
gpointer orig_user_data;
|
|
Packit Service |
b23acc |
NMDBusConnectionCallGetNameOwnerCb callback;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nm_utils_user_data_unpack (user_data, &orig_user_data, &callback);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
|
|
Packit Service |
b23acc |
if (ret)
|
|
Packit Service |
b23acc |
g_variant_get (ret, "(&s)", &owner);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
callback (owner, error, orig_user_data);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_get_name_owner (GDBusConnection *dbus_connection,
|
|
Packit Service |
b23acc |
const char *service_name,
|
|
Packit Service |
b23acc |
int timeout_msec,
|
|
Packit Service |
b23acc |
GCancellable *cancellable,
|
|
Packit Service |
b23acc |
NMDBusConnectionCallGetNameOwnerCb callback,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
nm_assert (callback);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
g_dbus_connection_call (dbus_connection,
|
|
Packit Service |
b23acc |
DBUS_SERVICE_DBUS,
|
|
Packit Service |
b23acc |
DBUS_PATH_DBUS,
|
|
Packit Service |
b23acc |
DBUS_INTERFACE_DBUS,
|
|
Packit Service |
b23acc |
"GetNameOwner",
|
|
Packit Service |
b23acc |
g_variant_new ("(s)", service_name),
|
|
Packit Service |
b23acc |
G_VARIANT_TYPE ("(s)"),
|
|
Packit Service |
b23acc |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit Service |
b23acc |
timeout_msec,
|
|
Packit Service |
b23acc |
cancellable,
|
|
Packit Service |
b23acc |
_nm_dbus_connection_call_get_name_owner_cb,
|
|
Packit Service |
b23acc |
nm_utils_user_data_pack (user_data, callback));
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
_nm_dbus_connection_call_default_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *res,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
gs_unref_variant GVariant *ret = NULL;
|
|
Packit Service |
b23acc |
gs_free_error GError *error = NULL;
|
|
Packit Service |
b23acc |
gpointer orig_user_data;
|
|
Packit Service |
b23acc |
NMDBusConnectionCallDefaultCb callback;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nm_utils_user_data_unpack (user_data, &orig_user_data, &callback);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nm_assert ((!!ret) != (!!error));
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
callback (ret, error, orig_user_data);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_get_all (GDBusConnection *dbus_connection,
|
|
Packit Service |
b23acc |
const char *bus_name,
|
|
Packit Service |
b23acc |
const char *object_path,
|
|
Packit Service |
b23acc |
const char *interface_name,
|
|
Packit Service |
b23acc |
int timeout_msec,
|
|
Packit Service |
b23acc |
GCancellable *cancellable,
|
|
Packit Service |
b23acc |
NMDBusConnectionCallDefaultCb callback,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
nm_assert (callback);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
g_dbus_connection_call (dbus_connection,
|
|
Packit Service |
b23acc |
bus_name,
|
|
Packit Service |
b23acc |
object_path,
|
|
Packit Service |
b23acc |
DBUS_INTERFACE_PROPERTIES,
|
|
Packit Service |
b23acc |
"GetAll",
|
|
Packit Service |
b23acc |
g_variant_new ("(s)", interface_name),
|
|
Packit Service |
b23acc |
G_VARIANT_TYPE ("(a{sv})"),
|
|
Packit Service |
b23acc |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit Service |
b23acc |
timeout_msec,
|
|
Packit Service |
b23acc |
cancellable,
|
|
Packit Service |
b23acc |
_nm_dbus_connection_call_default_cb,
|
|
Packit Service |
b23acc |
nm_utils_user_data_pack (user_data, callback));
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
void nm_dbus_connection_call_set (GDBusConnection *dbus_connection,
|
|
Packit Service |
b23acc |
const char *bus_name,
|
|
Packit Service |
b23acc |
const char *object_path,
|
|
Packit Service |
b23acc |
const char *interface_name,
|
|
Packit Service |
b23acc |
const char *property_name,
|
|
Packit Service |
b23acc |
GVariant *value,
|
|
Packit Service |
b23acc |
int timeout_msec,
|
|
Packit Service |
b23acc |
GCancellable *cancellable,
|
|
Packit Service |
b23acc |
NMDBusConnectionCallDefaultCb callback,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
g_dbus_connection_call (dbus_connection,
|
|
Packit Service |
b23acc |
bus_name,
|
|
Packit Service |
b23acc |
object_path,
|
|
Packit Service |
b23acc |
DBUS_INTERFACE_PROPERTIES,
|
|
Packit Service |
b23acc |
"Set",
|
|
Packit Service |
b23acc |
g_variant_new ("(ssv)",
|
|
Packit Service |
b23acc |
interface_name,
|
|
Packit Service |
b23acc |
property_name,
|
|
Packit Service |
b23acc |
value),
|
|
Packit Service |
b23acc |
G_VARIANT_TYPE ("()"),
|
|
Packit Service |
b23acc |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit Service |
b23acc |
timeout_msec,
|
|
Packit Service |
b23acc |
cancellable,
|
|
Packit Service |
b23acc |
callback ? _nm_dbus_connection_call_default_cb : NULL,
|
|
Packit Service |
b23acc |
callback ? nm_utils_user_data_pack (user_data, callback) : NULL);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
_nm_dbus_connection_call_get_managed_objects_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *res,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
gs_unref_variant GVariant *ret = NULL;
|
|
Packit Service |
b23acc |
gs_unref_variant GVariant *arg = NULL;
|
|
Packit Service |
b23acc |
gs_free_error GError *error = NULL;
|
|
Packit Service |
b23acc |
gpointer orig_user_data;
|
|
Packit Service |
b23acc |
NMDBusConnectionCallDefaultCb callback;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nm_utils_user_data_unpack (user_data, &orig_user_data, &callback);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nm_assert ((!!ret) != (!!error));
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
if (ret) {
|
|
Packit Service |
b23acc |
nm_assert (g_variant_is_of_type (ret, G_VARIANT_TYPE ("(a{oa{sa{sv}}})")));
|
|
Packit Service |
b23acc |
arg = g_variant_get_child_value (ret, 0);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
callback (arg, error, orig_user_data);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_get_managed_objects (GDBusConnection *dbus_connection,
|
|
Packit Service |
b23acc |
const char *bus_name,
|
|
Packit Service |
b23acc |
const char *object_path,
|
|
Packit Service |
b23acc |
GDBusCallFlags flags,
|
|
Packit Service |
b23acc |
int timeout_msec,
|
|
Packit Service |
b23acc |
GCancellable *cancellable,
|
|
Packit Service |
b23acc |
NMDBusConnectionCallDefaultCb callback,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
nm_assert (callback);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
g_dbus_connection_call (dbus_connection,
|
|
Packit Service |
b23acc |
bus_name,
|
|
Packit Service |
b23acc |
object_path,
|
|
Packit Service |
b23acc |
DBUS_INTERFACE_OBJECT_MANAGER,
|
|
Packit Service |
b23acc |
"GetManagedObjects",
|
|
Packit Service |
b23acc |
NULL,
|
|
Packit Service |
b23acc |
G_VARIANT_TYPE ("(a{oa{sa{sv}}})"),
|
|
Packit Service |
b23acc |
flags,
|
|
Packit Service |
b23acc |
timeout_msec,
|
|
Packit Service |
b23acc |
cancellable,
|
|
Packit Service |
b23acc |
_nm_dbus_connection_call_get_managed_objects_cb,
|
|
Packit Service |
b23acc |
nm_utils_user_data_pack (user_data, callback));
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
_call_finish_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *result,
|
|
Packit Service |
b23acc |
gpointer user_data,
|
|
Packit Service |
b23acc |
gboolean return_void,
|
|
Packit Service |
b23acc |
gboolean strip_dbus_error)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
gs_unref_object GTask *task = user_data;
|
|
Packit Service |
b23acc |
gs_unref_variant GVariant *ret = NULL;
|
|
Packit Service |
b23acc |
GError *error = NULL;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nm_assert (G_IS_DBUS_CONNECTION (source));
|
|
Packit Service |
b23acc |
nm_assert (G_IS_TASK (user_data));
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
|
|
Packit Service |
b23acc |
if (!ret) {
|
|
Packit Service |
b23acc |
if (strip_dbus_error)
|
|
Packit Service |
b23acc |
g_dbus_error_strip_remote_error (error);
|
|
Packit Service |
b23acc |
g_task_return_error (task, error);
|
|
Packit Service |
b23acc |
return;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
if (!return_void)
|
|
Packit Service |
b23acc |
g_task_return_pointer (task, g_steal_pointer (&ret), (GDestroyNotify) g_variant_unref);
|
|
Packit Service |
b23acc |
else {
|
|
Packit Service |
b23acc |
nm_assert (g_variant_is_of_type (ret, G_VARIANT_TYPE ("()")));
|
|
Packit Service |
b23acc |
g_task_return_boolean (task, TRUE);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_dbus_connection_call_finish_void_cb:
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* A default callback to pass as callback to g_dbus_connection_call().
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* - user_data must be a GTask, whose reference will be consumed by the
|
|
Packit Service |
b23acc |
* callback.
|
|
Packit Service |
b23acc |
* - the return GVariant must be a empty tuple "()".
|
|
Packit Service |
b23acc |
* - the GTask is returned either with error or TRUE boolean.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_finish_void_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *result,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
_call_finish_cb (source, result, user_data, TRUE, FALSE);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_dbus_connection_call_finish_void_strip_dbus_error_cb:
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Like nm_dbus_connection_call_finish_void_cb(). The difference
|
|
Packit Service |
b23acc |
* is that on error this will first call g_dbus_error_strip_remote_error() on the error.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_finish_void_strip_dbus_error_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *result,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
_call_finish_cb (source, result, user_data, TRUE, TRUE);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_dbus_connection_call_finish_variant_cb:
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* A default callback to pass as callback to g_dbus_connection_call().
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* - user_data must be a GTask, whose reference will be consumed by the
|
|
Packit Service |
b23acc |
* callback.
|
|
Packit Service |
b23acc |
* - the GTask is returned either with error or with a pointer containing the GVariant.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_finish_variant_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *result,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
_call_finish_cb (source, result, user_data, FALSE, FALSE);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_dbus_connection_call_finish_variant_strip_dbus_error_cb:
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Like nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(). The difference
|
|
Packit Service |
b23acc |
* is that on error this will first call g_dbus_error_strip_remote_error() on the error.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
void
|
|
Packit Service |
b23acc |
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb (GObject *source,
|
|
Packit Service |
b23acc |
GAsyncResult *result,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
_call_finish_cb (source, result, user_data, FALSE, TRUE);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
gboolean
|
|
Packit Service |
b23acc |
_nm_dbus_error_is (GError *error, ...)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
gs_free char *dbus_error = NULL;
|
|
Packit Service |
b23acc |
const char *name;
|
|
Packit Service |
b23acc |
va_list ap;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
dbus_error = g_dbus_error_get_remote_error (error);
|
|
Packit Service |
b23acc |
if (!dbus_error)
|
|
Packit Service |
b23acc |
return FALSE;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
va_start (ap, error);
|
|
Packit Service |
b23acc |
while ((name = va_arg (ap, const char *))) {
|
|
Packit Service |
b23acc |
if (nm_streq (dbus_error, name)) {
|
|
Packit Service |
b23acc |
va_end (ap);
|
|
Packit Service |
b23acc |
return TRUE;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
va_end (ap);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
return FALSE;
|
|
Packit Service |
b23acc |
}
|