[network-manager-openconnect/lr/libnm: 8/9] all: port to GDBus
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openconnect/lr/libnm: 8/9] all: port to GDBus
- Date: Fri, 21 Aug 2015 10:56:50 +0000 (UTC)
commit 3f3d6b19d950d174398db40794ee35d2b76d216c
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Sun Aug 16 16:10:05 2015 +0200
all: port to GDBus
configure.ac | 2 -
src/Makefile.am | 3 -
src/nm-openconnect-service-openconnect-helper.c | 466 ++++++++---------------
3 files changed, 168 insertions(+), 303 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1760ff4..dd69553 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,8 +60,6 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
PKG_CHECK_MODULES(LIBXML, libxml-2.0)
-PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.74)
-
if test x"$with_gnome" != xno; then
PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.4)
GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4"
diff --git a/src/Makefile.am b/src/Makefile.am
index 2fbd52f..9f8ac57 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,4 @@
AM_CPPFLAGS = \
- $(DBUS_CFLAGS) \
$(GLIB_CFLAGS) \
$(LIBNM_CFLAGS) \
-DG_DISABLE_DEPRECATED \
@@ -23,7 +22,6 @@ nm_openconnect_service_SOURCES = \
nm-openconnect-service-defines.h
nm_openconnect_service_LDADD = \
- $(DBUS_LIBS) \
$(GLIB_LIBS) \
$(LIBNM_LIBS)
@@ -32,7 +30,6 @@ nm_openconnect_service_openconnect_helper_SOURCES = \
nm-openconnect-service-openconnect-helper.c
nm_openconnect_service_openconnect_helper_LDADD = \
- $(DBUS_LIBS) \
$(GTHREAD_LIBS) \
$(LIBNM_LIBS)
diff --git a/src/nm-openconnect-service-openconnect-helper.c b/src/nm-openconnect-service-openconnect-helper.c
index 7102401..30e0ead 100644
--- a/src/nm-openconnect-service-openconnect-helper.c
+++ b/src/nm-openconnect-service-openconnect-helper.c
@@ -30,99 +30,71 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib.h>
#include <NetworkManager.h>
#include "nm-openconnect-service.h"
#include "nm-utils.h"
-/* These are here because nm-dbus-glib-types.h isn't exported */
-#define DBUS_TYPE_G_ARRAY_OF_UINT (dbus_g_type_get_collection ("GArray", G_TYPE_UINT))
-#define DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT (dbus_g_type_get_collection ("GPtrArray",
DBUS_TYPE_G_ARRAY_OF_UINT))
-#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
-#define DBUS_TYPE_G_IP6_ROUTE (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
-#define DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_IP6_ROUTE))
-
static void
-helper_failed (DBusGConnection *connection, const char *reason)
+helper_failed (GDBusProxy *proxy, const char *reason)
{
- DBusGProxy *proxy;
GError *err = NULL;
g_warning ("nm-nopenconnect-service-openconnect-helper did not receive a valid %s from openconnect",
reason);
- proxy = dbus_g_proxy_new_for_name (connection,
- NM_DBUS_SERVICE_OPENCONNECT,
- NM_VPN_DBUS_PLUGIN_PATH,
- NM_VPN_DBUS_PLUGIN_INTERFACE);
-
- dbus_g_proxy_call (proxy, "SetFailure", &err,
- G_TYPE_STRING, reason,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
-
- if (err) {
+ if (!g_dbus_proxy_call_sync (proxy, "SetFailure",
+ g_variant_new ("(s)", reason),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ &err)) {
g_warning ("Could not send failure information: %s", err->message);
g_error_free (err);
}
- g_object_unref (proxy);
-
exit (1);
}
static void
-send_config (DBusGConnection *connection, GHashTable *config,
- GHashTable *ip4config, GHashTable *ip6config)
+send_config (GDBusProxy *proxy, GVariant *config,
+ GVariant *ip4config, GVariant *ip6config)
{
- DBusGProxy *proxy;
GError *err = NULL;
- proxy = dbus_g_proxy_new_for_name (connection,
- NM_DBUS_SERVICE_OPENCONNECT,
- NM_VPN_DBUS_PLUGIN_PATH,
- NM_VPN_DBUS_PLUGIN_INTERFACE);
-
- if (!dbus_g_proxy_call (proxy, "SetConfig", &err,
- DBUS_TYPE_G_MAP_OF_VARIANT,
- config,
- G_TYPE_INVALID,
- G_TYPE_INVALID))
- goto done;
+ if (!g_dbus_proxy_call_sync (proxy, "SetConfig",
+ g_variant_new ("(*)", config),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ &err))
+ goto error;
if (ip4config) {
- if (!dbus_g_proxy_call (proxy, "SetIp4Config", &err,
- DBUS_TYPE_G_MAP_OF_VARIANT,
- ip4config,
- G_TYPE_INVALID,
- G_TYPE_INVALID))
- goto done;
+ if (!g_dbus_proxy_call_sync (proxy, "SetIp4Config",
+ g_variant_new ("(*)", ip4config),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ &err))
+ goto error;
}
if (ip6config) {
- if (!dbus_g_proxy_call (proxy, "SetIp6Config", &err,
- DBUS_TYPE_G_MAP_OF_VARIANT,
- ip6config,
- G_TYPE_INVALID,
- G_TYPE_INVALID))
- goto done;
+ if (!g_dbus_proxy_call_sync (proxy, "SetIp6Config",
+ g_variant_new ("(*)", ip6config),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL,
+ &err))
+ goto error;
}
- done:
- if (err) {
- g_warning ("Could not send configuration information: %s", err->message);
- g_error_free (err);
- }
-
- g_object_unref (proxy);
+ return;
+error:
+ g_warning ("Could not send configuration information: %s", err->message);
+ g_error_free (err);
}
-static GValue *
-str_to_gvalue (const char *str, gboolean try_convert)
+
+static GVariant *
+str_to_gvariant (const char *str, gboolean try_convert)
{
- GValue *val;
/* Empty */
if (!str || strlen (str) < 1)
@@ -137,41 +109,11 @@ str_to_gvalue (const char *str, gboolean try_convert)
return NULL;
}
- 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 num)
-{
- GValue *val;
-
- if (num == 0)
- return NULL;
-
- val = g_slice_new0 (GValue);
- g_value_init (val, G_TYPE_UINT);
- g_value_set_uint (val, num);
-
- return val;
-}
-
-static GValue *
-bool_to_gvalue (gboolean b)
-{
- GValue *val;
-
- val = g_slice_new0 (GValue);
- g_value_init (val, G_TYPE_BOOLEAN);
- g_value_set_boolean (val, b);
- return val;
+ return g_variant_new_string (str);
}
-static GValue *
-addr4_to_gvalue (const char *str)
+static GVariant *
+addr4_to_gvariant (const char *str)
{
struct in_addr temp_addr;
@@ -182,16 +124,15 @@ addr4_to_gvalue (const char *str)
if (inet_pton (AF_INET, str, &temp_addr) <= 0)
return NULL;
- return uint_to_gvalue (temp_addr.s_addr);
+ return g_variant_new_uint32 (temp_addr.s_addr);
}
-static GValue *
-addr4_list_to_gvalue (const char *str)
+static GVariant *
+addr4_list_to_gvariant (const char *str)
{
- GValue *val;
+ GVariantBuilder builder;
char **split;
int i;
- GArray *array;
/* Empty */
if (!str || strlen (str) < 1)
@@ -201,34 +142,31 @@ addr4_list_to_gvalue (const char *str)
if (g_strv_length (split) == 0)
return NULL;
- array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), g_strv_length (split));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+
for (i = 0; split[i]; i++) {
struct in_addr addr;
if (inet_pton (AF_INET, split[i], &addr) > 0) {
- g_array_append_val (array, addr.s_addr);
+ g_variant_builder_add_value (&builder, g_variant_new_uint32 (addr.s_addr));
} else {
g_strfreev (split);
- g_array_free (array, TRUE);
+ g_variant_unref (g_variant_builder_end (&builder));
return NULL;
}
}
g_strfreev (split);
- val = g_slice_new0 (GValue);
- g_value_init (val, DBUS_TYPE_G_UINT_ARRAY);
- g_value_set_boxed (val, array);
-
- return val;
+ return g_variant_builder_end (&builder);
}
-static GValue *
-addr6_to_gvalue (const char *str)
+static GVariant *
+addr6_to_gvariant (const char *str)
{
struct in6_addr temp_addr;
- GValue *val;
- GByteArray *ba;
+ GVariantBuilder builder;
+ int i;
/* Empty */
if (!str || strlen (str) < 1)
@@ -237,22 +175,18 @@ addr6_to_gvalue (const char *str)
if (inet_pton (AF_INET6, str, &temp_addr) <= 0)
return NULL;
- val = g_slice_new0 (GValue);
- g_value_init (val, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guint8 *) &temp_addr, sizeof (temp_addr));
- g_value_take_boxed (val, ba);
- return val;
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("ay"));
+ for (i = 0; i < sizeof (temp_addr); i++)
+ g_variant_builder_add (&builder, "y", ((guint8 *) &temp_addr)[i]);
+ return g_variant_builder_end (&builder);
}
-static GValue *
-addr6_list_to_gvalue (const char *str)
+static GVariant *
+addr6_list_to_gvariant (const char *str)
{
- GValue *val;
+ GVariantBuilder builder;
char **split;
int i;
- GPtrArray *array;
- GByteArray *ba;
/* Empty */
if (!str || strlen (str) < 1)
@@ -262,38 +196,29 @@ addr6_list_to_gvalue (const char *str)
if (g_strv_length (split) == 0)
return NULL;
- array = g_ptr_array_new_full (g_strv_length (split),
- (GDestroyNotify) g_byte_array_unref);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
+
for (i = 0; split[i]; i++) {
- struct in6_addr addr;
+ GVariant *val = addr6_to_gvariant (split[i]);
- if (inet_pton (AF_INET6, split[i], &addr) > 0) {
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guint8 *) &addr, sizeof (addr));
- g_ptr_array_add (array, ba);
+ if (val) {
+ g_variant_builder_add_value (&builder, val);
} else {
g_strfreev (split);
- g_ptr_array_free (array, TRUE);
+ g_variant_unref (g_variant_builder_end (&builder));
return NULL;
}
}
g_strfreev (split);
- val = g_slice_new0 (GValue);
- g_value_init (val, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT);
- g_value_set_boxed (val, array);
-
- return val;
+ return g_variant_builder_end (&builder);
}
-#define BUFLEN 256
-
-static GValue *
-split_dns_list_to_gvalue (const char *str)
+static GVariant *
+split_dns_list_to_gvariant (const char *str)
{
- GValue *val;
- char **split;
+ gchar **split;
if (!str || strlen (str) < 1)
return NULL;
@@ -302,22 +227,20 @@ split_dns_list_to_gvalue (const char *str)
if (g_strv_length (split) == 0)
return NULL;
- val = g_slice_new0 (GValue);
- g_value_init (val, G_TYPE_STRV);
- g_value_take_boxed (val, split);
-
- return val;
+ return g_variant_new_strv ((const gchar **) split, -1);
}
-static GValue *
+static GVariant *
get_ip4_routes (void)
{
- GValue *value = NULL;
- GPtrArray *routes;
+ GVariantBuilder builder;
+ GVariant *value;
char *tmp;
int num;
int i;
+#define BUFLEN 256
+
tmp = getenv ("CISCO_SPLIT_INC");
if (!tmp || strlen (tmp) < 1)
return NULL;
@@ -326,10 +249,10 @@ get_ip4_routes (void)
if (!num)
return NULL;
- routes = g_ptr_array_new ();
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aau"));
for (i = 0; i < num; i++) {
- GArray *array;
+ GVariantBuilder array;
char buf[BUFLEN];
struct in_addr network;
guint32 next_hop = 0; /* no next hop */
@@ -366,86 +289,27 @@ get_ip4_routes (void)
prefix = nm_utils_ip4_netmask_to_prefix (netmask.s_addr);
}
- array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 4);
- g_array_append_val (array, network.s_addr);
- g_array_append_val (array, prefix);
- g_array_append_val (array, next_hop);
- g_array_append_val (array, metric);
- g_ptr_array_add (routes, array);
+ g_variant_builder_init (&array, G_VARIANT_TYPE ("au"));
+ g_variant_builder_add_value (&array, g_variant_new_uint32 (network.s_addr));
+ g_variant_builder_add_value (&array, g_variant_new_uint32 (prefix));
+ g_variant_builder_add_value (&array, g_variant_new_uint32 (next_hop));
+ g_variant_builder_add_value (&array, g_variant_new_uint32 (metric));
+ g_variant_builder_add_value (&builder, g_variant_builder_end (&array));
}
- if (routes->len > 0) {
- value = g_new0 (GValue, 1);
- g_value_init (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT);
- g_value_take_boxed (value, routes);
- } else
- g_ptr_array_free (routes, TRUE);
-
- return value;
-}
-
-/* Taken from libnm-util; will be gone and replaced with a call to
- * nm_utils_ip_routes_to_variant with port to GDBus. */
-static void
-nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value)
-{
- GPtrArray *routes;
- GSList *iter;
-
- routes = g_ptr_array_new ();
-
- for (iter = list; iter; iter = iter->next) {
- NMIPRoute *route = (NMIPRoute *) iter->data;
- GValueArray *array;
- const struct in6_addr *addr;
- GByteArray *ba;
- GValue element = G_VALUE_INIT;
-
- array = g_value_array_new (4);
+ value = g_variant_builder_end (&builder);
+ if (i > 1)
+ return value;
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- if (inet_pton (AF_INET6, nm_ip_route_get_dest (route), &addr) <= 0) {
- g_warning ("Bad route destination: '%s", nm_ip_route_get_dest (route));
- continue;
- }
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_value_init (&element, G_TYPE_UINT);
- g_value_set_uint (&element, nm_ip_route_get_prefix (route));
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- if (inet_pton (AF_INET6, nm_ip_route_get_next_hop (route), &addr) <= 0) {
- g_warning ("Bad gateway: '%s", nm_ip_route_get_next_hop (route));
- continue;
- }
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_value_init (&element, G_TYPE_UINT);
- g_value_set_uint (&element, nm_ip_route_get_metric (route));
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_ptr_array_add (routes, array);
- }
-
- g_value_take_boxed (value, routes);
+ g_variant_unref (value);
+ return NULL;
}
-static GValue *
+static GVariant *
get_ip6_routes (void)
{
- GValue *value = NULL;
- GSList *routes;
+ GVariant *value = NULL;
+ GPtrArray *routes;
char *tmp;
int num;
int i;
@@ -458,7 +322,7 @@ get_ip6_routes (void)
if (!num)
return NULL;
- routes = NULL;
+ routes = g_ptr_array_new_full (num, (GDestroyNotify) nm_ip_route_unref);
for (i = 0; i < num; i++) {
NMIPRoute *route;
@@ -498,20 +362,12 @@ get_ip6_routes (void)
continue;
}
- routes = g_slist_append (routes, route);
+ g_ptr_array_add (routes, route);
}
- if (routes) {
- GSList *iter;
-
- value = g_slice_new0 (GValue);
- g_value_init (value, DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE);
- nm_utils_ip6_routes_to_gvalue (routes, value);
-
- for (iter = routes; iter; iter = iter->next)
- nm_ip_route_unref (iter->data);
- g_slist_free (routes);
- }
+ if (routes->len)
+ value = nm_utils_ip6_routes_to_variant (routes);
+ g_ptr_array_unref (routes);
return value;
}
@@ -532,10 +388,11 @@ get_ip6_routes (void)
int
main (int argc, char *argv[])
{
- DBusGConnection *connection;
+ GDBusProxy *proxy;
char *tmp;
- GHashTable *config, *ip4config, *ip6config;
- GValue *val;
+ GVariantBuilder builder, ip4builder, ip6builder;
+ GVariant *ip4config, *ip6config;
+ GVariant *val;
GError *err = NULL;
struct in_addr temp_addr;
@@ -550,41 +407,48 @@ main (int argc, char *argv[])
if (tmp && strcmp (tmp, "connect") != 0)
exit (0);
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
- if (!connection) {
- g_warning ("Could not get the system bus: %s", err->message);
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ NM_DBUS_SERVICE_OPENCONNECT,
+ NM_VPN_DBUS_PLUGIN_PATH,
+ NM_VPN_DBUS_PLUGIN_INTERFACE,
+ NULL, &err);
+ if (!proxy) {
+ g_warning ("Could not create a D-Bus proxy: %s", err->message);
+ g_error_free (err);
exit (1);
}
- config = g_hash_table_new (g_str_hash, g_str_equal);
- ip4config = g_hash_table_new (g_str_hash, g_str_equal);
- ip6config = g_hash_table_new (g_str_hash, g_str_equal);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+ g_variant_builder_init (&ip4builder, G_VARIANT_TYPE_VARDICT);
+ g_variant_builder_init (&ip6builder, G_VARIANT_TYPE_VARDICT);
/* Gateway */
- val = addr4_to_gvalue (getenv ("VPNGATEWAY"));
+ val = addr4_to_gvariant (getenv ("VPNGATEWAY"));
if (!val)
- val = addr6_to_gvalue (getenv ("VPNGATEWAY"));
+ val = addr6_to_gvariant (getenv ("VPNGATEWAY"));
if (val)
- g_hash_table_insert (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, val);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, val);
else
- helper_failed (connection, "VPN Gateway");
+ helper_failed (proxy, "VPN Gateway");
/* Tunnel device */
- val = str_to_gvalue (getenv ("TUNDEV"), FALSE);
+ val = str_to_gvariant (getenv ("TUNDEV"), FALSE);
if (val)
- g_hash_table_insert (config, NM_VPN_PLUGIN_CONFIG_TUNDEV, val);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_TUNDEV, val);
else
- helper_failed (connection, "Tunnel Device");
+ helper_failed (proxy, "Tunnel Device");
/* Banner */
- val = str_to_gvalue (getenv ("CISCO_BANNER"), TRUE);
+ val = str_to_gvariant (getenv ("CISCO_BANNER"), TRUE);
if (val)
- g_hash_table_insert (config, NM_VPN_PLUGIN_CONFIG_BANNER, val);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_BANNER, val);
/* Default domain */
- val = str_to_gvalue (getenv ("CISCO_DEF_DOMAIN"), TRUE);
+ val = str_to_gvariant (getenv ("CISCO_DEF_DOMAIN"), TRUE);
if (val)
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, val);
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, val);
/* MTU */
tmp = getenv ("INTERNAL_IP4_MTU");
@@ -596,74 +460,74 @@ main (int argc, char *argv[])
if (errno || mtu < 0 || mtu > 20000) {
g_warning ("Ignoring invalid tunnel MTU '%s'", tmp);
} else {
- val = uint_to_gvalue ((guint32) mtu);
- g_hash_table_insert (config, NM_VPN_PLUGIN_CONFIG_MTU, val);
+ val = g_variant_new_uint32 ((guint32) mtu);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_MTU, val);
}
}
/* IPv4 address */
- val = addr4_to_gvalue (getenv ("INTERNAL_IP4_ADDRESS"));
+ val = addr4_to_gvariant (getenv ("INTERNAL_IP4_ADDRESS"));
if (val)
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, val);
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, val);
else
- helper_failed (connection, "IP4 Address");
+ helper_failed (proxy, "IP4 Address");
/* IPv4 PTP address; for openconnect PTP address == internal IPv4 address */
- val = addr4_to_gvalue (getenv ("INTERNAL_IP4_ADDRESS"));
+ val = addr4_to_gvariant (getenv ("INTERNAL_IP4_ADDRESS"));
if (val)
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_PTP, val);
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_PTP, val);
else
- helper_failed (connection, "IP4 PTP Address");
+ helper_failed (proxy, "IP4 PTP Address");
/* IPv4 Netmask */
tmp = getenv ("INTERNAL_IP4_NETMASK");
if (tmp && inet_pton (AF_INET, tmp, &temp_addr) > 0) {
- val = uint_to_gvalue (nm_utils_ip4_netmask_to_prefix (temp_addr.s_addr));
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, val);
+ val = g_variant_new_uint32 (nm_utils_ip4_netmask_to_prefix (temp_addr.s_addr));
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, val);
}
/* DNS */
- val = addr4_list_to_gvalue (getenv ("INTERNAL_IP4_DNS"));
+ val = addr4_list_to_gvariant (getenv ("INTERNAL_IP4_DNS"));
if (val)
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_DNS, val);
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_DNS, val);
/* WINS servers */
- val = addr4_list_to_gvalue (getenv ("INTERNAL_IP4_NBNS"));
+ val = addr4_list_to_gvariant (getenv ("INTERNAL_IP4_NBNS"));
if (val)
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_NBNS, val);
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_NBNS, val);
/* Split DNS domains */
- val = split_dns_list_to_gvalue (getenv ("CISCO_SPLIT_DNS"));
+ val = split_dns_list_to_gvariant (getenv ("CISCO_SPLIT_DNS"));
if (val)
- g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS, val);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS, val);
/* Routes */
val = get_ip4_routes ();
if (val) {
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, val);
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, val);
/* If routes-to-include were provided, that means no default route */
- g_hash_table_insert (ip4config, NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT,
- bool_to_gvalue (TRUE));
+ g_variant_builder_add (&ip4builder, "{sv}", NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT,
+ g_variant_new_boolean (TRUE));
}
/* IPv6 address */
tmp = getenv ("INTERNAL_IP6_ADDRESS");
if (tmp && strlen (tmp)) {
- val = addr6_to_gvalue (tmp);
+ val = addr6_to_gvariant (tmp);
if (val)
- g_hash_table_insert (ip6config, NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS, val);
+ g_variant_builder_add (&ip6builder, "{sv}", NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS, val);
else
- helper_failed (connection, "IP6 Address");
+ helper_failed (proxy, "IP6 Address");
}
/* IPv6 PTP address; for openconnect PTP address == internal IPv6 address */
tmp = getenv ("INTERNAL_IP6_ADDRESS");
if (tmp && strlen (tmp)) {
- val = addr6_to_gvalue (tmp);
+ val = addr6_to_gvariant (tmp);
if (val)
- g_hash_table_insert (ip6config, NM_VPN_PLUGIN_IP6_CONFIG_PTP, val);
+ g_variant_builder_add (&ip6builder, "{sv}", NM_VPN_PLUGIN_IP6_CONFIG_PTP, val);
else
- helper_failed (connection, "IP6 PTP Address");
+ helper_failed (proxy, "IP6 PTP Address");
}
/* IPv6 Netmask */
@@ -671,42 +535,48 @@ main (int argc, char *argv[])
if (tmp)
tmp = strchr (tmp, '/');
if (tmp) {
- val = uint_to_gvalue (strtol (tmp + 1, NULL, 10));
- g_hash_table_insert (ip6config, NM_VPN_PLUGIN_IP6_CONFIG_PREFIX, val);
+ val = g_variant_new_uint32 (strtol (tmp + 1, NULL, 10));
+ g_variant_builder_add (&ip6builder, "{sv}", NM_VPN_PLUGIN_IP6_CONFIG_PREFIX, val);
}
/* DNS */
- val = addr6_list_to_gvalue (getenv ("INTERNAL_IP6_DNS"));
+ val = addr6_list_to_gvariant (getenv ("INTERNAL_IP6_DNS"));
if (val)
- g_hash_table_insert (ip6config, NM_VPN_PLUGIN_IP6_CONFIG_DNS, val);
+ g_variant_builder_add (&ip6builder, "{sv}", NM_VPN_PLUGIN_IP6_CONFIG_DNS, val);
/* Routes */
val = get_ip6_routes ();
if (val) {
- g_hash_table_insert (ip6config, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, val);
+ g_variant_builder_add (&ip6builder, "{sv}", NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, val);
/* If routes-to-include were provided, that means no default route */
- g_hash_table_insert (ip6config, NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT,
- bool_to_gvalue (TRUE));
+ g_variant_builder_add (&ip6builder, "{sv}", NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT,
+ g_variant_new_boolean (TRUE));
}
- if (g_hash_table_size (ip4config)) {
- g_hash_table_insert (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4,
- bool_to_gvalue (TRUE));
+ ip4config = g_variant_builder_end (&ip4builder);
+
+ if (g_variant_n_children (ip4config)) {
+ val = g_variant_new_boolean (TRUE);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_HAS_IP4, val);
} else {
- g_hash_table_destroy (ip4config);
+ g_variant_unref (ip4config);
ip4config = NULL;
}
- if (g_hash_table_size (ip6config)) {
- g_hash_table_insert (config, NM_VPN_PLUGIN_CONFIG_HAS_IP6,
- bool_to_gvalue (TRUE));
+ ip6config = g_variant_builder_end (&ip6builder);
+
+ if (g_variant_n_children (ip6config)) {
+ val = g_variant_new_boolean (TRUE);
+ g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_HAS_IP6, val);
} else {
- g_hash_table_destroy (ip6config);
+ g_variant_unref (ip6config);
ip6config = NULL;
}
/* Send the config info to nm-openconnect-service */
- send_config (connection, config, ip4config, ip6config);
+ send_config (proxy, g_variant_builder_end (&builder), ip4config, ip6config);
+
+ g_object_unref (proxy);
exit (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]