[network-manager-openconnect/lr/libnm] fixup! service: port to libnm



commit af74a0a68841bf46067164eb2df9c78819ede0e1
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Sun Aug 16 16:10:05 2015 +0200

    fixup! service: port to libnm
    
    port to gvariant.
    
    UNTESTED!

 src/nm-openconnect-service-openconnect-helper.c |  353 ++++++++---------------
 1 files changed, 121 insertions(+), 232 deletions(-)
---
diff --git a/src/nm-openconnect-service-openconnect-helper.c b/src/nm-openconnect-service-openconnect-helper.c
index 7102401..c46d950 100644
--- a/src/nm-openconnect-service-openconnect-helper.c
+++ b/src/nm-openconnect-service-openconnect-helper.c
@@ -74,8 +74,8 @@ helper_failed (DBusGConnection *connection, const char *reason)
 }
 
 static void
-send_config (DBusGConnection *connection, GHashTable *config,
-             GHashTable *ip4config, GHashTable *ip6config)
+send_config (DBusGConnection *connection, GVariant *config,
+             GVariant *ip4config, GVariant *ip6config)
 {
        DBusGProxy *proxy;
        GError *err = NULL;
@@ -119,10 +119,10 @@ send_config (DBusGConnection *connection, GHashTable *config,
        g_object_unref (proxy);
 }
 
-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 +137,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 +152,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 +170,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 +203,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 +224,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 +255,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 +277,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 +317,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);
+       value = g_variant_builder_end (&builder);
+       if (i > 1)
+               return value;
 
-       return value;
+       g_variant_unref (value);
+       return NULL;
 }
 
-/* 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);
-
-               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);
-}
-
-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 +350,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 +390,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;
 }
@@ -534,8 +418,9 @@ main (int argc, char *argv[])
 {
        DBusGConnection *connection;
        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;
 
@@ -556,35 +441,35 @@ main (int argc, char *argv[])
                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");
 
        /* 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");
 
        /* 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,62 +481,62 @@ 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");
 
        /* 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");
 
        /* 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");
        }
@@ -659,9 +544,9 @@ main (int argc, char *argv[])
        /* 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");
        }
@@ -671,42 +556,46 @@ 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 (connection, g_variant_builder_end (&builder), ip4config, ip6config);
 
        exit (0);
 }


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