[network-manager-pptp/lr/libnm: 11/12] Revert "all: port to GDBus"
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-pptp/lr/libnm: 11/12] Revert "all: port to GDBus"
- Date: Fri, 17 Jul 2015 15:48:03 +0000 (UTC)
commit 63accb14df43106fa520af74db82530c482870fc
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Fri Jul 17 17:38:03 2015 +0200
Revert "all: port to GDBus"
This reverts commit aa0fa8d96a35ff2eae935422cbafe8cb6ae7e0d8.
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, 187 insertions(+), 233 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 784fe3e..09185ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,8 +61,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
IT_PROG_INTLTOOL([0.35])
AM_GLIB_GNU_GETTEXT
-# gio-unix will require glib and gio
-PKG_CHECK_MODULES(GLIB, gio-unix-2.0 >= 2.32)
+PKG_CHECK_MODULES(GLIB, glib-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 886c1e3..d62259a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,31 +22,13 @@ nm_pptp_service_SOURCES = \
nm-pptp-service.c \
nm-pptp-service.h
-
-# 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-pppd-service-glue.h: $(top_srcdir)/src/nm-pptp-pppd-service.xml
+ dbus-binding-tool --prefix=nm_pptp_pppd_service --mode=glib-server --output=$@ $<
nm_pptp_service_LDADD = \
$(DBUS_GLIB_LIBS) \
$(GLIB_LIBS) \
- $(LIBNM_LIBS) \
- libnm-pptp-pppd-service-dbus.la
+ $(LIBNM_LIBS)
pppd_plugindir = $(PPPD_PLUGIN_DIR)
pppd_plugin_LTLIBRARIES = nm-pptp-pppd-plugin.la
@@ -67,7 +49,7 @@ nm_pptp_pppd_plugin_la_LIBADD = \
$(GLIB_LIBS) \
$(LIBNM_LIBS)
-BUILT_SOURCES = nm-pptp-pppd-service-dbus.h nm-pptp-pppd-service-dbus.c
+BUILT_SOURCES = nm-pptp-pppd-service-glue.h
CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/nm-pptp-pppd-plugin.c b/src/nm-pptp-pppd-plugin.c
index e7a9afd..ebf2b0b 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 <gio/gio.h>
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
#include "nm-pptp-service.h"
#include "nm-ppp-status.h"
@@ -40,7 +40,7 @@ int plugin_init (void);
char pppd_version[] = VERSION;
-static GDBusProxy *proxy = NULL;
+static DBusGProxy *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 (G_IS_DBUS_PROXY (proxy));
+ g_return_if_fail (DBUS_IS_G_PROXY (proxy));
switch (arg) {
case PHASE_DEAD:
@@ -115,104 +115,126 @@ nm_phasechange (void *data, int arg)
ppp_phase);
if (ppp_status != NM_PPP_STATUS_UNKNOWN) {
- g_dbus_proxy_call (proxy,
- "SetState",
- g_variant_new ("(u)", ppp_status),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL,
- NULL, NULL);
+ dbus_g_proxy_call_no_reply (proxy, "SetState",
+ G_TYPE_UINT, ppp_status,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
}
}
+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];
- GVariantBuilder builder;
+ GHashTable *hash;
+ GArray *array;
+ GValue *val;
- g_return_if_fail (G_IS_DBUS_PROXY (proxy));
+ g_return_if_fail (DBUS_IS_G_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;
}
- 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));
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
- g_variant_builder_add (&builder, "{sv}",
- NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS,
- g_variant_new_uint32 (opts.ouraddr));
+ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV,
+ str_to_gvalue (ifname));
/* 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_variant_builder_add (&builder, "{sv}",
- NM_VPN_PLUGIN_IP4_CONFIG_PTP,
- g_variant_new_uint32 (peer_opts.hisaddr));
+ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP,
+ uint_to_gvalue (peer_opts.hisaddr));
} else if (opts.hisaddr) {
- g_variant_builder_add (&builder, "{sv}",
- NM_VPN_PLUGIN_IP4_CONFIG_PTP,
- g_variant_new_uint32 (opts.hisaddr));
+ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP,
+ uint_to_gvalue (opts.hisaddr));
} else if (peer_opts.hisaddr == pppd_made_up_address) {
/* As a last resort, use the made-up address */
- 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_PTP,
+ uint_to_gvalue (peer_opts.hisaddr));
}
- g_variant_builder_add (&builder, "{sv}",
- NM_VPN_PLUGIN_IP4_CONFIG_PREFIX,
- g_variant_new_uint32 (32));
+ 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));
if (opts.dnsaddr[0] || opts.dnsaddr[1]) {
- guint32 dns[2];
- int len = 0;
+ array = g_array_new (FALSE, FALSE, sizeof (guint32));
if (opts.dnsaddr[0])
- dns[len++] = opts.dnsaddr[0];
+ g_array_append_val (array, opts.dnsaddr[0]);
if (opts.dnsaddr[1])
- dns[len++] = 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);
- 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)));
+ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val);
}
/* Default MTU to 1400, which is also what Windows XP/Vista use */
- g_variant_builder_add (&builder, "{sv}",
- NM_VPN_PLUGIN_IP4_CONFIG_MTU,
- g_variant_new_uint32 (1400));
+ g_hash_table_insert (hash, NM_VPN_PLUGIN_IP4_CONFIG_MTU, uint_to_gvalue (1400));
g_message ("nm-pptp-ppp-plugin: (%s): sending Ip4Config to NetworkManager-pptp...", __func__);
- g_dbus_proxy_call (proxy,
- "SetIp4Config",
- g_variant_new ("(a{sv})", &builder),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL,
- NULL, NULL);
+ 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);
}
static int
-get_chap_check (void)
+get_chap_check(void)
{
return 1;
}
static int
-get_pap_check (void)
+get_pap_check(void)
{
return 1;
}
@@ -220,29 +242,27 @@ get_pap_check (void)
static int
get_credentials (char *username, char *password)
{
- const char *my_username = NULL;
- const char *my_password = NULL;
+ char *my_username = NULL;
+ char *my_password = NULL;
size_t len;
- GVariant *ret;
GError *err = NULL;
- if (!password) {
+ if (username && !password) {
/* pppd is checking pap support; return 1 for supported */
- g_return_val_if_fail (username, -1);
return 1;
}
- g_return_val_if_fail (username, -1);
- g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);
+ g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), -1);
g_message ("nm-pptp-ppp-plugin: (%s): passwd-hook, requesting credentials...", __func__);
- ret = g_dbus_proxy_call_sync (proxy,
- "NeedSecrets",
- NULL,
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &err);
- if (!ret) {
+ 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) {
g_warning ("nm-pptp-ppp-plugin: (%s): could not get secrets: (%d) %s",
__func__,
err ? err->code : -1,
@@ -253,14 +273,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) {
@@ -269,9 +289,9 @@ get_credentials (char *username, char *password)
strncpy (password, my_password, len);
password[len - 1] = '\0';
- }
- g_variant_unref (ret);
+ g_free (my_password);
+ }
return 1;
}
@@ -279,7 +299,7 @@ get_credentials (char *username, char *password)
static void
nm_exit_notify (void *data, int arg)
{
- g_return_if_fail (G_IS_DBUS_PROXY (proxy));
+ g_return_if_fail (DBUS_IS_G_PROXY (proxy));
g_message ("nm-pptp-ppp-plugin: (%s): cleaning up", __func__);
@@ -290,7 +310,7 @@ nm_exit_notify (void *data, int arg)
int
plugin_init (void)
{
- GDBusConnection *bus;
+ DBusGConnection *bus;
GError *err = NULL;
#if !GLIB_CHECK_VERSION (2, 35, 0)
@@ -299,7 +319,7 @@ plugin_init (void)
g_message ("nm-pptp-ppp-plugin: (%s): initializing", __func__);
- bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &err);
+ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
if (!bus) {
g_warning ("nm-pptp-pppd-plugin: (%s): couldn't connect to system bus: (%d) %s",
__func__,
@@ -309,19 +329,12 @@ plugin_init (void)
return -1;
}
- 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);
+ proxy = dbus_g_proxy_new_for_name (bus,
+ NM_DBUS_SERVICE_PPTP_PPP,
+ NM_DBUS_PATH_PPTP_PPP,
+ NM_DBUS_INTERFACE_PPTP_PPP);
- 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;
- }
+ dbus_g_connection_unref (bus);
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 1a23b4f..a31c5f5 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,9 +62,8 @@ static gboolean debug = FALSE;
/* ppp plugin <-> pptp-service object */
/********************************************************/
-/* 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.
+/* Have to have a separate objec to handle ppp plugin requests since
+ * dbus-glib doesn't allow multiple interfaces registed on one GObject.
*/
#define NM_TYPE_PPTP_PPP_SERVICE (nm_pptp_ppp_service_get_type ())
@@ -84,31 +83,28 @@ typedef struct {
/* Signals */
void (*plugin_alive) (NMPptpPppService *self);
void (*ppp_state) (NMPptpPppService *self, guint32 state);
- void (*ip4_config) (NMPptpPppService *self, GVariant *config);
+ void (*ip4_config) (NMPptpPppService *self, GHashTable *config_hash);
} NMPptpPppServiceClass;
GType nm_pptp_ppp_service_get_type (void);
G_DEFINE_TYPE (NMPptpPppService, nm_pptp_ppp_service, G_TYPE_OBJECT)
-static gboolean
-handle_need_secrets (NMDBusNetworkManagerPptpPpp *object,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+static gboolean impl_pptp_service_need_secrets (NMPptpPppService *self,
+ char **out_username,
+ char **out_password,
+ GError **err);
-static gboolean
-handle_set_state (NMDBusNetworkManagerPptpPpp *object,
- GDBusMethodInvocation *invocation,
- guint arg_state,
- gpointer user_data);
+static gboolean impl_pptp_service_set_state (NMPptpPppService *self,
+ guint32 state,
+ GError **err);
-static gboolean
-handle_set_ip4_config (NMDBusNetworkManagerPptpPpp *object,
- GDBusMethodInvocation *invocation,
- GVariant *arg_config,
- gpointer user_data);
+static gboolean impl_pptp_service_set_ip4_config (NMPptpPppService *self,
+ GHashTable *config,
+ GError **err);
+
+#include "nm-pptp-pppd-service-glue.h"
-#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))
@@ -117,9 +113,6 @@ 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;
@@ -285,41 +278,33 @@ nm_pptp_ppp_service_new (const char *gwaddr,
GError **error)
{
NMPptpPppService *self = NULL;
- NMPptpPppServicePrivate *priv;
- GDBusConnection *bus;
- GDBusProxy *proxy;
- GVariant *ret;
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+ gboolean success = FALSE;
+ guint result;
- bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
+ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
if (!bus)
return NULL;
dbus_connection_set_change_sigpipe (TRUE);
- 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);
+ proxy = dbus_g_proxy_new_for_name (bus,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus");
g_assert (proxy);
- 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);
+ 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);
g_object_unref (proxy);
- if (!ret) {
- if (error && *error)
- g_dbus_error_strip_remote_error (*error);
+ if (success == FALSE)
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,
@@ -342,23 +327,10 @@ nm_pptp_ppp_service_new (const char *gwaddr,
goto out;
}
- 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);
+ dbus_g_connection_register_g_object (bus, NM_DBUS_PATH_PPTP_PPP, G_OBJECT (self));
out:
- g_clear_object (&bus);
+ dbus_g_connection_unref (bus);
return self;
}
@@ -374,18 +346,6 @@ 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);
@@ -398,8 +358,6 @@ finalize (GObject *object)
}
g_free (priv->domain);
g_free (priv->saddr);
-
- G_OBJECT_CLASS (nm_pptp_ppp_service_parent_class)->finalize (object);
}
static void
@@ -410,7 +368,6 @@ 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 */
@@ -438,72 +395,64 @@ nm_pptp_ppp_service_class_init (NMPptpPppServiceClass *service_class)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMPptpPppServiceClass, ip4_config),
NULL, NULL,
- NULL,
- G_TYPE_NONE, 1, G_TYPE_VARIANT);
+ 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);
}
static gboolean
-handle_need_secrets (NMDBusNetworkManagerPptpPpp *object,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+impl_pptp_service_need_secrets (NMPptpPppService *self,
+ char **out_username,
+ char **out_password,
+ GError **error)
{
- 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 (!*priv->username || !*priv->password) {
- g_set_error (&error,
+ if (!strlen (priv->username) || !strlen (priv->password)) {
+ g_set_error (error,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
"%s",
_("No cached credentials."));
- g_dbus_method_invocation_take_error (invocation, error);
- return FALSE;
+ goto error;
}
+
/* Success */
- if (priv->domain && *priv->domain)
- username = g_strdup_printf ("%s\\%s", priv->domain, priv->username);
+ if (priv->domain && strlen (priv->domain))
+ *out_username = g_strdup_printf ("%s\\%s", priv->domain, priv->username);
else
- username = g_strdup (priv->username);
- password = g_strdup (priv->password);
-
- g_dbus_method_invocation_return_value (invocation,
- g_variant_new ("(ss)", username, password));
- g_free (username);
- g_free (password);
+ *out_username = g_strdup (priv->username);
+ *out_password = g_strdup (priv->password);
return TRUE;
+
+error:
+ return FALSE;
}
static gboolean
-handle_set_state (NMDBusNetworkManagerPptpPpp *object,
- GDBusMethodInvocation *invocation,
- guint arg_state,
- gpointer user_data)
+impl_pptp_service_set_state (NMPptpPppService *self,
+ guint32 pppd_state,
+ GError **err)
{
- 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, arg_state);
- g_dbus_method_invocation_return_value (invocation, NULL);
+ g_signal_emit (G_OBJECT (self), signals[PPP_STATE], 0, pppd_state);
return TRUE;
}
static gboolean
-handle_set_ip4_config (NMDBusNetworkManagerPptpPpp *object,
- GDBusMethodInvocation *invocation,
- GVariant *arg_config,
- gpointer user_data)
+impl_pptp_service_set_ip4_config (NMPptpPppService *self,
+ GHashTable *config_hash,
+ GError **err)
{
- 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, arg_config);
+ g_signal_emit (G_OBJECT (self), signals[IP4_CONFIG], 0, config_hash);
return TRUE;
}
@@ -1112,24 +1061,32 @@ service_ppp_state_cb (NMPptpPppService *service,
static void
service_ip4_config_cb (NMPptpPppService *service,
- GVariant *config,
+ GHashTable *config_hash,
NMVpnPluginOld *plugin)
{
NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (service);
- GVariantIter iter;
- const char *key;
- GVariant *value;
+ GHashTableIter iter;
+ char *key;
+ GValue *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 (!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);
+ if (tmp)
+ g_variant_builder_add (&builder, "{sv}", key, tmp);
}
/* 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 6300e87..7872527 100644
--- a/src/nm-pptp-service.h
+++ b/src/nm-pptp-service.h
@@ -37,6 +37,9 @@
#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]