[network-manager-pptp/lr/libnm: 9/9] all: port to GDBus



commit aa0fa8d96a35ff2eae935422cbafe8cb6ae7e0d8
Author: Jiří Klimeš <jklimes redhat com>
Date:   Wed May 20 17:15:58 2015 +0200

    all: port to GDBus

 configure.ac              |    3 +-
 src/Makefile.am           |   26 +++++-
 src/nm-pptp-pppd-plugin.c |  181 ++++++++++++++++++---------------------
 src/nm-pptp-service.c     |  207 +++++++++++++++++++++++++++------------------
 src/nm-pptp-service.h     |    3 -
 5 files changed, 233 insertions(+), 187 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 81cea45..11beb0b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,8 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
 IT_PROG_INTLTOOL([0.35])
 AM_GLIB_GNU_GETTEXT
 
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.32)
+# gio-unix will require glib and gio
+PKG_CHECK_MODULES(GLIB, gio-unix-2.0 >= 2.32)
 GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
 
 PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= 0.74)
diff --git a/src/Makefile.am b/src/Makefile.am
index d62259a..886c1e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,13 +22,31 @@ nm_pptp_service_SOURCES = \
        nm-pptp-service.c \
        nm-pptp-service.h
 
-nm-pptp-pppd-service-glue.h: $(top_srcdir)/src/nm-pptp-pppd-service.xml
-       dbus-binding-tool --prefix=nm_pptp_pppd_service --mode=glib-server --output=$@ $<
+
+# D-Bus stuff
+noinst_LTLIBRARIES = libnm-pptp-pppd-service-dbus.la
+
+nodist_libnm_pptp_pppd_service_dbus_la_SOURCES = \
+       nm-pptp-pppd-service-dbus.c \
+       nm-pptp-pppd-service-dbus.h
+
+libnm_pptp_pppd_service_dbus_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(AM_CPPFLAGS))
+
+nm-pptp-pppd-service-dbus.h: $(top_srcdir)/src/nm-pptp-pppd-service.xml
+       $(AM_V_GEN) gdbus-codegen \
+               --generate-c-code $(basename $@) \
+               --c-namespace NMDBus \
+               --interface-prefix org.freedesktop \
+               $<
+
+nm-pptp-pppd-service-dbus.c:
+       @true
 
 nm_pptp_service_LDADD = \
        $(DBUS_GLIB_LIBS) \
        $(GLIB_LIBS) \
-       $(LIBNM_LIBS)
+       $(LIBNM_LIBS) \
+       libnm-pptp-pppd-service-dbus.la
 
 pppd_plugindir = $(PPPD_PLUGIN_DIR)
 pppd_plugin_LTLIBRARIES = nm-pptp-pppd-plugin.la
@@ -49,7 +67,7 @@ nm_pptp_pppd_plugin_la_LIBADD = \
        $(GLIB_LIBS) \
        $(LIBNM_LIBS)
 
-BUILT_SOURCES = nm-pptp-pppd-service-glue.h
+BUILT_SOURCES = nm-pptp-pppd-service-dbus.h nm-pptp-pppd-service-dbus.c
 
 CLEANFILES = $(BUILT_SOURCES)
 
diff --git a/src/nm-pptp-pppd-plugin.c b/src/nm-pptp-pppd-plugin.c
index ebf2b0b..e7a9afd 100644
--- a/src/nm-pptp-pppd-plugin.c
+++ b/src/nm-pptp-pppd-plugin.c
@@ -27,9 +27,9 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <dlfcn.h>
 #include <glib.h>
-#include <glib-object.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 
 #include "nm-pptp-service.h"
 #include "nm-ppp-status.h"
@@ -40,7 +40,7 @@ int plugin_init (void);
 
 char pppd_version[] = VERSION;
 
-static DBusGProxy *proxy = NULL;
+static GDBusProxy *proxy = NULL;
 
 static void
 nm_phasechange (void *data, int arg)
@@ -48,7 +48,7 @@ nm_phasechange (void *data, int arg)
        NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN;
        char *ppp_phase;
 
-       g_return_if_fail (DBUS_IS_G_PROXY (proxy));
+       g_return_if_fail (G_IS_DBUS_PROXY (proxy));
 
        switch (arg) {
        case PHASE_DEAD:
@@ -115,126 +115,104 @@ nm_phasechange (void *data, int arg)
                   ppp_phase);
 
        if (ppp_status != NM_PPP_STATUS_UNKNOWN) {
-               dbus_g_proxy_call_no_reply (proxy, "SetState",
-                                           G_TYPE_UINT, ppp_status,
-                                           G_TYPE_INVALID,
-                                           G_TYPE_INVALID);
+               g_dbus_proxy_call (proxy,
+                                  "SetState",
+                                  g_variant_new ("(u)", ppp_status),
+                                  G_DBUS_CALL_FLAGS_NONE, -1,
+                                  NULL,
+                                  NULL, NULL);
        }
 }
 
-static GValue *
-str_to_gvalue (const char *str)
-{
-       GValue *val;
-
-       val = g_slice_new0 (GValue);
-       g_value_init (val, G_TYPE_STRING);
-       g_value_set_string (val, str);
-
-       return val;
-}
-
-static GValue *
-uint_to_gvalue (guint32 i)
-{
-       GValue *val;
-
-       val = g_slice_new0 (GValue);
-       g_value_init (val, G_TYPE_UINT);
-       g_value_set_uint (val, i);
-
-       return val;
-}
-
-static void
-value_destroy (gpointer data)
-{
-       GValue *val = (GValue *) data;
-
-       g_value_unset (val);
-       g_slice_free (GValue, val);
-}
-
 static void
 nm_ip_up (void *data, int arg)
 {
        guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit);
        ipcp_options opts = ipcp_gotoptions[0];
        ipcp_options peer_opts = ipcp_hisoptions[0];
-       GHashTable *hash;
-       GArray *array;
-       GValue *val;
+       GVariantBuilder builder;
 
-       g_return_if_fail (DBUS_IS_G_PROXY (proxy));
+       g_return_if_fail (G_IS_DBUS_PROXY (proxy));
 
        g_message ("nm-pptp-ppp-plugin: (%s): ip-up event", __func__);
 
        if (!opts.ouraddr) {
                g_warning ("nm-pptp-ppp-plugin: (%s): didn't receive an internal IP from pppd!", __func__);
+               nm_phasechange (NULL, PHASE_DEAD);
                return;
        }
 
-       hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
+       g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+
+       g_variant_builder_add (&builder, "{sv}",
+                              NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV,
+                              g_variant_new_string (ifname));
 
-       g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV,
-                            str_to_gvalue (ifname));
+       g_variant_builder_add (&builder, "{sv}",
+                              NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS,
+                              g_variant_new_uint32 (opts.ouraddr));
 
        /* Prefer the peer options remote address first, _unless_ pppd made the
         * address up, at which point prefer the local options remote address,
         * and if that's not right, use the made-up address as a last resort.
         */
        if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) {
-               g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP,
-                                    uint_to_gvalue (peer_opts.hisaddr));
+               g_variant_builder_add (&builder, "{sv}",
+                                      NM_VPN_PLUGIN_IP4_CONFIG_PTP,
+                                      g_variant_new_uint32 (peer_opts.hisaddr));
        } else if (opts.hisaddr) {
-               g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP,
-                                    uint_to_gvalue (opts.hisaddr));
+               g_variant_builder_add (&builder, "{sv}",
+                                      NM_VPN_PLUGIN_IP4_CONFIG_PTP,
+                                      g_variant_new_uint32 (opts.hisaddr));
        } else if (peer_opts.hisaddr == pppd_made_up_address) {
                /* As a last resort, use the made-up address */
-               g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP,
-                                    uint_to_gvalue (peer_opts.hisaddr));
+               g_variant_builder_add (&builder, "{sv}",
+                                      NM_VPN_PLUGIN_IP4_CONFIG_PTP,
+                                      g_variant_new_uint32 (peer_opts.ouraddr));
        }
 
-       g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS,
-                            uint_to_gvalue (opts.ouraddr));
-
-       g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, uint_to_gvalue (32));
+       g_variant_builder_add (&builder, "{sv}",
+                              NM_VPN_PLUGIN_IP4_CONFIG_PREFIX,
+                              g_variant_new_uint32 (32));
 
        if (opts.dnsaddr[0] || opts.dnsaddr[1]) {
-               array = g_array_new (FALSE, FALSE, sizeof (guint32));
+               guint32 dns[2];
+               int len = 0;
 
                if (opts.dnsaddr[0])
-                       g_array_append_val (array, opts.dnsaddr[0]);
+                       dns[len++] = opts.dnsaddr[0];
                if (opts.dnsaddr[1])
-                       g_array_append_val (array, opts.dnsaddr[1]);
-
-               val = g_slice_new0 (GValue);
-               g_value_init (val, DBUS_TYPE_G_UINT_ARRAY);
-               g_value_set_boxed (val, array);
+                       dns[len++] = opts.dnsaddr[1];
 
-               g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val);
+               g_variant_builder_add (&builder, "{sv}",
+                                      NM_VPN_PLUGIN_IP4_CONFIG_DNS,
+                                      g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
+                                                                 dns, len, sizeof (guint32)));
        }
 
        /* Default MTU to 1400, which is also what Windows XP/Vista use */
-       g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_MTU, uint_to_gvalue (1400));
+       g_variant_builder_add (&builder, "{sv}",
+                              NM_VPN_PLUGIN_IP4_CONFIG_MTU,
+                              g_variant_new_uint32 (1400));
 
        g_message ("nm-pptp-ppp-plugin: (%s): sending Ip4Config to NetworkManager-pptp...", __func__);
 
-       dbus_g_proxy_call_no_reply (proxy, "SetIp4Config",
-                                   DBUS_TYPE_G_MAP_OF_VARIANT, hash, G_TYPE_INVALID,
-                                   G_TYPE_INVALID);
-
-       g_hash_table_destroy (hash);
+       g_dbus_proxy_call (proxy,
+                          "SetIp4Config",
+                          g_variant_new ("(a{sv})", &builder),
+                          G_DBUS_CALL_FLAGS_NONE, -1,
+                          NULL,
+                          NULL, NULL);
 }
 
 static int
-get_chap_check(void)
+get_chap_check (void)
 {
        return 1;
 }
 
 static int
-get_pap_check(void)
+get_pap_check (void)
 {
        return 1;
 }
@@ -242,27 +220,29 @@ get_pap_check(void)
 static int
 get_credentials (char *username, char *password)
 {
-       char *my_username = NULL;
-       char *my_password = NULL;
+       const char *my_username = NULL;
+       const char *my_password = NULL;
        size_t len;
+       GVariant *ret;
        GError *err = NULL;
 
-       if (username && !password) {
+       if (!password) {
                /* pppd is checking pap support; return 1 for supported */
+               g_return_val_if_fail (username, -1);
                return 1;
        }
 
-       g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), -1);
+       g_return_val_if_fail (username, -1);
+       g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
 
        g_message ("nm-pptp-ppp-plugin: (%s): passwd-hook, requesting credentials...", __func__);
 
-       dbus_g_proxy_call (proxy, "NeedSecrets", &err,
-                          G_TYPE_INVALID,
-                          G_TYPE_STRING, &my_username,
-                          G_TYPE_STRING, &my_password,
-                          G_TYPE_INVALID);
-
-       if (err) {
+       ret = g_dbus_proxy_call_sync (proxy,
+                                     "NeedSecrets",
+                                     NULL,
+                                     G_DBUS_CALL_FLAGS_NONE, -1,
+                                     NULL, &err);
+       if (!ret) {
                g_warning ("nm-pptp-ppp-plugin: (%s): could not get secrets: (%d) %s",
                           __func__,
                           err ? err->code : -1,
@@ -273,14 +253,14 @@ get_credentials (char *username, char *password)
 
        g_message ("nm-pptp-ppp-plugin: (%s): got credentials from NetworkManager-pptp", __func__);
 
+       g_variant_get (ret, "(&s&s)", &my_username, &my_password);
+
        if (my_username) {
                len = strlen (my_username) + 1;
                len = len < MAXNAMELEN ? len : MAXNAMELEN;
 
                strncpy (username, my_username, len);
                username[len - 1] = '\0';
-
-               g_free (my_username);
        }
 
        if (my_password) {
@@ -289,17 +269,17 @@ get_credentials (char *username, char *password)
 
                strncpy (password, my_password, len);
                password[len - 1] = '\0';
-
-               g_free (my_password);
        }
 
+       g_variant_unref (ret);
+
        return 1;
 }
 
 static void
 nm_exit_notify (void *data, int arg)
 {
-       g_return_if_fail (DBUS_IS_G_PROXY (proxy));
+       g_return_if_fail (G_IS_DBUS_PROXY (proxy));
 
        g_message ("nm-pptp-ppp-plugin: (%s): cleaning up", __func__);
 
@@ -310,7 +290,7 @@ nm_exit_notify (void *data, int arg)
 int
 plugin_init (void)
 {
-       DBusGConnection *bus;
+       GDBusConnection *bus;
        GError *err = NULL;
 
 #if !GLIB_CHECK_VERSION (2, 35, 0)
@@ -319,7 +299,7 @@ plugin_init (void)
 
        g_message ("nm-pptp-ppp-plugin: (%s): initializing", __func__);
 
-       bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
+       bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!bus) {
                g_warning ("nm-pptp-pppd-plugin: (%s): couldn't connect to system bus: (%d) %s",
                           __func__,
@@ -329,12 +309,19 @@ plugin_init (void)
                return -1;
        }
 
-       proxy = dbus_g_proxy_new_for_name (bus,
-                                          NM_DBUS_SERVICE_PPTP_PPP,
-                                          NM_DBUS_PATH_PPTP_PPP,
-                                          NM_DBUS_INTERFACE_PPTP_PPP);
+       proxy = g_dbus_proxy_new_sync (bus, G_DBUS_CALL_FLAGS_NONE, NULL,
+                                      NM_DBUS_SERVICE_PPTP_PPP,
+                                      NM_DBUS_PATH_PPTP_PPP,
+                                      NM_DBUS_INTERFACE_PPTP_PPP,
+                                      NULL, &err);
+       g_object_unref (bus);
 
-       dbus_g_connection_unref (bus);
+       if (!proxy) {
+               g_warning ("nm-pptp-pppd-plugin: (%s): couldn't create D-Bus proxy: %s",
+                          __func__, err->message);
+               g_error_free (err);
+               return -1;
+       }
 
        chap_passwd_hook = get_credentials;
        chap_check_hook = get_chap_check;
diff --git a/src/nm-pptp-service.c b/src/nm-pptp-service.c
index a31c5f5..1a23b4f 100644
--- a/src/nm-pptp-service.c
+++ b/src/nm-pptp-service.c
@@ -45,12 +45,12 @@
 
 #include <glib/gi18n.h>
 #include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
 
 #include <NetworkManager.h>
 
 #include "nm-pptp-service.h"
 #include "nm-ppp-status.h"
+#include "nm-pptp-pppd-service-dbus.h"
 
 #if !defined(DIST_VERSION)
 # define DIST_VERSION VERSION
@@ -62,8 +62,9 @@ static gboolean debug = FALSE;
 /* ppp plugin <-> pptp-service object                   */
 /********************************************************/
 
-/* Have to have a separate objec to handle ppp plugin requests since
- * dbus-glib doesn't allow multiple interfaces registed on one GObject.
+/* We have a separate object to handle ppp plugin requests from
+ * historical reason, because dbus-glib didn't allow multiple
+ * interfaces registed on one GObject.
  */
 
 #define NM_TYPE_PPTP_PPP_SERVICE            (nm_pptp_ppp_service_get_type ())
@@ -83,28 +84,31 @@ typedef struct {
        /* Signals */
        void (*plugin_alive) (NMPptpPppService *self);
        void (*ppp_state) (NMPptpPppService *self, guint32 state);
-       void (*ip4_config) (NMPptpPppService *self, GHashTable *config_hash);
+       void (*ip4_config) (NMPptpPppService *self, GVariant *config);
 } NMPptpPppServiceClass;
 
 GType nm_pptp_ppp_service_get_type (void);
 
 G_DEFINE_TYPE (NMPptpPppService, nm_pptp_ppp_service, G_TYPE_OBJECT)
 
-static gboolean impl_pptp_service_need_secrets (NMPptpPppService *self,
-                                                char **out_username,
-                                                char **out_password,
-                                                GError **err);
-
-static gboolean impl_pptp_service_set_state (NMPptpPppService *self,
-                                             guint32 state,
-                                             GError **err);
+static gboolean
+handle_need_secrets (NMDBusNetworkManagerPptpPpp *object,
+                     GDBusMethodInvocation *invocation,
+                     gpointer user_data);
 
-static gboolean impl_pptp_service_set_ip4_config (NMPptpPppService *self,
-                                                  GHashTable *config,
-                                                  GError **err);
+static gboolean
+handle_set_state (NMDBusNetworkManagerPptpPpp *object,
+                  GDBusMethodInvocation *invocation,
+                  guint arg_state,
+                  gpointer user_data);
 
-#include "nm-pptp-pppd-service-glue.h"
+static gboolean
+handle_set_ip4_config (NMDBusNetworkManagerPptpPpp *object,
+                       GDBusMethodInvocation *invocation,
+                       GVariant *arg_config,
+                       gpointer user_data);
 
+#include "nm-pptp-pppd-service-dbus.h"
 
 #define NM_PPTP_PPP_SERVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPTP_PPP_SERVICE, 
NMPptpPppServicePrivate))
 
@@ -113,6 +117,9 @@ typedef struct {
        char *domain;
        char *password;
 
+       /* D-Bus stuff */
+       NMDBusNetworkManagerPptpPpp *dbus_skeleton;
+
        /* IP of PPtP gateway in numeric and string format */
        guint32 naddr;
        char *saddr;
@@ -278,33 +285,41 @@ nm_pptp_ppp_service_new (const char *gwaddr,
                          GError **error)
 {
        NMPptpPppService *self = NULL;
-       DBusGConnection *bus;
-       DBusGProxy *proxy;
-       gboolean success = FALSE;
-       guint result;
+       NMPptpPppServicePrivate *priv;
+       GDBusConnection *bus;
+       GDBusProxy *proxy;
+       GVariant *ret;
 
-       bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
+       bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
        if (!bus)
                return NULL;
        dbus_connection_set_change_sigpipe (TRUE);
 
-       proxy = dbus_g_proxy_new_for_name (bus,
-                                          "org.freedesktop.DBus",
-                                          "/org/freedesktop/DBus",
-                                          "org.freedesktop.DBus");
+       proxy = g_dbus_proxy_new_sync (bus,
+                                      G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+                                      G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+                                      NULL,
+                                      DBUS_SERVICE_DBUS,
+                                      DBUS_PATH_DBUS,
+                                      DBUS_INTERFACE_DBUS,
+                                      NULL, error);
        g_assert (proxy);
-       success = dbus_g_proxy_call (proxy, "RequestName", error,
-                                    G_TYPE_STRING, NM_DBUS_SERVICE_PPTP_PPP,
-                                    G_TYPE_UINT, 0,
-                                    G_TYPE_INVALID,
-                                    G_TYPE_UINT, &result,
-                                    G_TYPE_INVALID);
+       ret = g_dbus_proxy_call_sync (proxy,
+                                     "RequestName",
+                                     g_variant_new ("(su)", NM_DBUS_SERVICE_PPTP_PPP, 0),
+                                     G_DBUS_CALL_FLAGS_NONE, -1,
+                                     NULL, error);
        g_object_unref (proxy);
-       if (success == FALSE)
+       if (!ret) {
+               if (error && *error)
+                       g_dbus_error_strip_remote_error (*error);
                goto out;
+       }
+       g_variant_unref (ret);
 
        self = (NMPptpPppService *) g_object_new (NM_TYPE_PPTP_PPP_SERVICE, NULL);
        g_assert (self);
+       priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (self);
 
        /* Look up the IP address of the PPtP server; if the server has multiple
         * addresses, because we can't get the actual IP used back from pptp itself,
@@ -327,10 +342,23 @@ nm_pptp_ppp_service_new (const char *gwaddr,
                goto out;
        }
 
-       dbus_g_connection_register_g_object (bus, NM_DBUS_PATH_PPTP_PPP, G_OBJECT (self));
+       priv->dbus_skeleton = nmdbus_network_manager_pptp_ppp_skeleton_new ();
+       if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_skeleton),
+                                              bus,
+                                              NM_DBUS_PATH_PPTP_PPP,
+                                              error))
+               goto out;
+
+       g_dbus_connection_register_object (bus, NM_DBUS_PATH_PPTP_PPP, 
+                                          nmdbus_network_manager_pptp_ppp_interface_info (),
+                                          NULL, NULL, NULL, NULL);
+
+       g_signal_connect (priv->dbus_skeleton, "handle-need-secrets", G_CALLBACK (handle_need_secrets), self);
+       g_signal_connect (priv->dbus_skeleton, "handle-set-state", G_CALLBACK (handle_set_state), self);
+       g_signal_connect (priv->dbus_skeleton, "handle-set-ip4-config", G_CALLBACK (handle_set_ip4_config), 
self);
 
 out:
-       dbus_g_connection_unref (bus);
+       g_clear_object (&bus);
        return self;
 }
 
@@ -346,6 +374,18 @@ nm_pptp_ppp_service_init (NMPptpPppService *self)
 }
 
 static void
+nm_pptp_ppp_service_dispose (GObject *object)
+{
+       NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (object);
+
+       g_signal_handlers_disconnect_by_func (priv->dbus_skeleton, handle_need_secrets, object);
+       g_signal_handlers_disconnect_by_func (priv->dbus_skeleton, handle_set_state, object);
+       g_signal_handlers_disconnect_by_func (priv->dbus_skeleton, handle_set_ip4_config, object);
+
+       G_OBJECT_CLASS (nm_pptp_ppp_service_parent_class)->dispose (object);
+}
+
+static void
 finalize (GObject *object)
 {
        NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (object);
@@ -358,6 +398,8 @@ finalize (GObject *object)
        }
        g_free (priv->domain);
        g_free (priv->saddr);
+
+       G_OBJECT_CLASS (nm_pptp_ppp_service_parent_class)->finalize (object);
 }
 
 static void
@@ -368,6 +410,7 @@ nm_pptp_ppp_service_class_init (NMPptpPppServiceClass *service_class)
        g_type_class_add_private (service_class, sizeof (NMPptpPppServicePrivate));
 
        /* virtual methods */
+       object_class->dispose = nm_pptp_ppp_service_dispose;
        object_class->finalize = finalize;
 
        /* Signals */
@@ -395,64 +438,72 @@ nm_pptp_ppp_service_class_init (NMPptpPppServiceClass *service_class)
                              G_SIGNAL_RUN_FIRST,
                              G_STRUCT_OFFSET (NMPptpPppServiceClass, ip4_config),
                              NULL, NULL,
-                             g_cclosure_marshal_VOID__POINTER,
-                             G_TYPE_NONE, 1, G_TYPE_POINTER);
-
-       dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (service_class),
-                                                                        
&dbus_glib_nm_pptp_pppd_service_object_info);
+                             NULL,
+                             G_TYPE_NONE, 1, G_TYPE_VARIANT);
 }
 
 static gboolean
-impl_pptp_service_need_secrets (NMPptpPppService *self,
-                                char **out_username,
-                                char **out_password,
-                                GError **error)
+handle_need_secrets (NMDBusNetworkManagerPptpPpp *object,
+                     GDBusMethodInvocation *invocation,
+                     gpointer user_data)
 {
+       NMPptpPppService *self = NM_PPTP_PPP_SERVICE (user_data);
        NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (self);
+       char *username = NULL, *password = NULL;
+       GError *error = NULL;
 
        g_signal_emit (G_OBJECT (self), signals[PLUGIN_ALIVE], 0);
 
-       if (!strlen (priv->username) || !strlen (priv->password)) {
-               g_set_error (error,
+       if (!*priv->username || !*priv->password) {
+               g_set_error (&error,
                             NM_VPN_PLUGIN_ERROR,
                             NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
                             "%s",
                             _("No cached credentials."));
-               goto error;
+               g_dbus_method_invocation_take_error (invocation, error);
+               return FALSE;
        }
-
        /* Success */
-       if (priv->domain && strlen (priv->domain))
-               *out_username = g_strdup_printf ("%s\\%s", priv->domain, priv->username);
+       if (priv->domain && *priv->domain)
+               username = g_strdup_printf ("%s\\%s", priv->domain, priv->username);
        else
-               *out_username = g_strdup (priv->username);
-       *out_password = g_strdup (priv->password);
-       return TRUE;
+               username = g_strdup (priv->username);
+       password = g_strdup (priv->password);
 
-error:
-       return FALSE;
+       g_dbus_method_invocation_return_value (invocation,
+                                              g_variant_new ("(ss)", username, password));
+       g_free (username);
+       g_free (password);
+       return TRUE;
 }
 
 static gboolean
-impl_pptp_service_set_state (NMPptpPppService *self,
-                             guint32 pppd_state,
-                             GError **err)
+handle_set_state (NMDBusNetworkManagerPptpPpp *object,
+                  GDBusMethodInvocation *invocation,
+                  guint arg_state,
+                  gpointer user_data)
 {
+       NMPptpPppService *self = NM_PPTP_PPP_SERVICE (user_data);
+
        g_signal_emit (G_OBJECT (self), signals[PLUGIN_ALIVE], 0);
-       g_signal_emit (G_OBJECT (self), signals[PPP_STATE], 0, pppd_state);
+       g_signal_emit (G_OBJECT (self), signals[PPP_STATE], 0, arg_state);
+       g_dbus_method_invocation_return_value (invocation, NULL);
        return TRUE;
 }
 
 static gboolean
-impl_pptp_service_set_ip4_config (NMPptpPppService *self,
-                                  GHashTable *config_hash,
-                                  GError **err)
+handle_set_ip4_config (NMDBusNetworkManagerPptpPpp *object,
+                       GDBusMethodInvocation *invocation,
+                       GVariant *arg_config,
+                       gpointer user_data)
 {
+       NMPptpPppService *self = NM_PPTP_PPP_SERVICE (user_data);
+
        g_message ("PPTP service (IP Config Get) reply received.");
        g_signal_emit (G_OBJECT (self), signals[PLUGIN_ALIVE], 0);
 
        /* Just forward the pppd plugin config up to our superclass; no need to modify it */
-       g_signal_emit (G_OBJECT (self), signals[IP4_CONFIG], 0, config_hash);
+       g_signal_emit (G_OBJECT (self), signals[IP4_CONFIG], 0, arg_config);
 
        return TRUE;
 }
@@ -1061,32 +1112,24 @@ service_ppp_state_cb (NMPptpPppService *service,
 
 static void
 service_ip4_config_cb (NMPptpPppService *service,
-                       GHashTable *config_hash,
+                       GVariant *config,
                        NMVpnPluginOld *plugin)
 {
        NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (service);
-       GHashTableIter iter;
-       char *key;
-       GValue *value;
+       GVariantIter iter;
+       const char *key;
+       GVariant *value;
        GVariantBuilder builder;
        GVariant *new_config;
-       GVariant *tmp;
-
-        g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
-       g_hash_table_iter_init (&iter, config_hash);
-       while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
-               if (G_VALUE_HOLDS_STRING (value))
-                       tmp = g_variant_new_string (g_value_get_string (value));
-               else if (G_VALUE_HOLDS_UINT (value))
-                       tmp = g_variant_new_uint32 (g_value_get_uint (value));
-               else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)) {
-                       GArray *arr = g_value_get_boxed (value);
-                       tmp = g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, arr->data, arr->len, sizeof 
(guint32));
-               } else
-                       tmp = NULL;
 
-               if (tmp)
-                       g_variant_builder_add (&builder, "{sv}", key, tmp);
+       if (!config)
+               return;
+
+       g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+       g_variant_iter_init (&iter, config);
+       while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) {
+               g_variant_builder_add (&builder, "{sv}", key, value);
+               g_variant_unref (value);
        }
 
        /* Insert the external VPN gateway into the table, which the pppd plugin
diff --git a/src/nm-pptp-service.h b/src/nm-pptp-service.h
index 7872527..6300e87 100644
--- a/src/nm-pptp-service.h
+++ b/src/nm-pptp-service.h
@@ -37,9 +37,6 @@
 #define NM_IS_PPTP_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_PPTP_PLUGIN))
 #define NM_PPTP_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPTP_PLUGIN, 
NMPptpPluginClass))
 
-/* For the pppd plugin <-> VPN plugin service */
-#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
-
 typedef struct {
        NMVpnPluginOld parent;
 } NMPptpPlugin;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]