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



commit 58e56002db28d5f3f401e90c8a8b5b47deb9ee95
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Sun Aug 16 16:19:53 2015 +0200

    fixup! service: port to libnm
    
    port to gdbus
    
    UNTESTED!

 configure.ac                                    |    2 -
 src/Makefile.am                                 |    3 -
 src/nm-openconnect-service-openconnect-helper.c |  117 ++++++++++-------------
 3 files changed, 49 insertions(+), 73 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 c46d950..01b1ce4 100644
--- a/src/nm-openconnect-service-openconnect-helper.c
+++ b/src/nm-openconnect-service-openconnect-helper.c
@@ -30,93 +30,65 @@
 #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_string (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, GVariant *config,
+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",
+                                    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",
+                                            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",
+                                            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);
 }
 
 
@@ -416,7 +388,7 @@ get_ip6_routes (void)
 int 
 main (int argc, char *argv[])
 {
-       DBusGConnection *connection;
+       GDBusProxy *proxy;
        char *tmp;
        GVariantBuilder builder, ip4builder, ip6builder;
        GVariant *ip4config, *ip6config;
@@ -435,9 +407,16 @@ 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);
        }
 
@@ -452,14 +431,14 @@ main (int argc, char *argv[])
        if (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_gvariant (getenv ("TUNDEV"), FALSE);
        if (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_gvariant (getenv ("CISCO_BANNER"), TRUE);
@@ -491,14 +470,14 @@ main (int argc, char *argv[])
        if (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_gvariant (getenv ("INTERNAL_IP4_ADDRESS"));
        if (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");
@@ -538,7 +517,7 @@ main (int argc, char *argv[])
                if (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 */
@@ -548,7 +527,7 @@ main (int argc, char *argv[])
                if (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 */
@@ -595,7 +574,9 @@ main (int argc, char *argv[])
        }
 
        /* Send the config info to nm-openconnect-service */
-       send_config (connection, g_variant_builder_end (&builder), 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]