summaryrefslogtreecommitdiff
path: root/libnm/nm-dbus-helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm/nm-dbus-helpers.c')
-rw-r--r--libnm/nm-dbus-helpers.c105
1 files changed, 56 insertions, 49 deletions
diff --git a/libnm/nm-dbus-helpers.c b/libnm/nm-dbus-helpers.c
index f80cb375a3..5d6cd9f74d 100644
--- a/libnm/nm-dbus-helpers.c
+++ b/libnm/nm-dbus-helpers.c
@@ -21,79 +21,86 @@
#include <string.h>
#include <config.h>
#include <gio/gio.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include "nm-dbus-helpers-private.h"
#include "nm-dbus-interface.h"
-static dbus_int32_t priv_slot = -1;
+#define NM_DBUS_PRIVATE_CONNECTION_TAG "libnm-private-connection"
-static gboolean
-_ensure_dbus_data_slot (void)
-{
- static gsize init_value = 0;
- gboolean success = TRUE;
-
- if (g_once_init_enter (&init_value)) {
- success = dbus_connection_allocate_data_slot (&priv_slot);
- g_once_init_leave (&init_value, 1);
- }
- return success;
-}
-
-DBusGConnection *
+GDBusConnection *
_nm_dbus_new_connection (GError **error)
{
- DBusGConnection *connection = NULL;
+ GDBusConnection *connection = NULL;
- if (!_ensure_dbus_data_slot ()) {
- g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED, "failed to allocated data slot");
- return NULL;
- }
-
-#if HAVE_DBUS_GLIB_100
/* If running as root try the private bus first */
if (0 == geteuid ()) {
- connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error);
+ connection = g_dbus_connection_new_for_address_sync ("unix:path=" NMRUNDIR "/private",
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
+ NULL, NULL, NULL);
if (connection) {
- DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection);
-
/* Mark this connection as private */
- dbus_connection_set_data (dbus_connection, priv_slot, GUINT_TO_POINTER (TRUE), NULL);
- dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
+ g_object_set_data (G_OBJECT (connection),
+ NM_DBUS_PRIVATE_CONNECTION_TAG,
+ GUINT_TO_POINTER (TRUE));
return connection;
}
- /* Fall back to a bus if for some reason private socket isn't available */
- g_clear_error (error);
}
-#endif
-
- if (connection == NULL)
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
- return connection;
+ return g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
}
gboolean
-_nm_dbus_is_connection_private (DBusGConnection *connection)
+_nm_dbus_is_connection_private (GDBusConnection *connection)
{
- if (!_ensure_dbus_data_slot ())
- return FALSE;
- return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot);
+ return !!g_object_get_data (G_OBJECT (connection), NM_DBUS_PRIVATE_CONNECTION_TAG);
}
-DBusGProxy *
-_nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
+GDBusProxy *
+_nm_dbus_new_proxy_for_connection (GDBusConnection *connection,
const char *path,
const char *interface)
{
- /* Private connections can't use dbus_g_proxy_new_for_name() or
- * dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't
- * have either a bus daemon or name owners, both of which those functions
- * require.
- */
+ GDBusProxy *proxy;
+ const char *name;
+ GError *error = NULL;
+
if (_nm_dbus_is_connection_private (connection))
- return dbus_g_proxy_new_for_peer (connection, path, interface);
+ name = NULL;
+ else
+ name = NM_DBUS_SERVICE;
+
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ name, path, interface,
+ NULL,
+ &error);
+ if (error) {
+ /* FIXME */
+ g_warning ("Could not create proxy for %s on %s: %s",
+ path, interface, error->message);
+ g_clear_error (&error);
+ }
+
+ return proxy;
+}
+
+void
+_nm_dbus_register_error_domain (GQuark domain,
+ const char *interface,
+ GType enum_type)
+{
+ GEnumClass *enum_class;
+ GEnumValue *e;
+ char *error_name;
+ int i;
+
+ enum_class = g_type_class_ref (enum_type);
+ for (i = 0; i < enum_class->n_values; i++) {
+ e = &enum_class->values[i];
+ error_name = g_strdup_printf ("%s.%s", interface, e->value_nick);
+ g_dbus_error_register_error (domain, e->value, error_name);
+ g_free (error_name);
+ }
- return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface);
+ g_type_class_unref (enum_class);
}