[network-manager-openconnect/lr/libnm: 5/9] service: port to libnm



commit 30fd47b9f4910cccd79c3cd24953f70eafa124de
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Jul 24 17:52:33 2015 +0200

    service: port to libnm

 src/Makefile.am                                 |    6 +-
 src/nm-openconnect-service-openconnect-helper.c |   80 ++++++++++++++++++++---
 src/nm-openconnect-service.c                    |   48 ++++++++------
 src/nm-openconnect-service.h                    |    7 +-
 4 files changed, 105 insertions(+), 36 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 532970d..2fbd52f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
 AM_CPPFLAGS = \
        $(DBUS_CFLAGS) \
        $(GLIB_CFLAGS) \
-       $(LIBNM_GLIB_CFLAGS) \
+       $(LIBNM_CFLAGS) \
        -DG_DISABLE_DEPRECATED \
        -DBINDIR=\"$(bindir)\" \
        -DPREFIX=\""$(prefix)"\" \
@@ -25,7 +25,7 @@ nm_openconnect_service_SOURCES = \
 nm_openconnect_service_LDADD = \
        $(DBUS_LIBS) \
        $(GLIB_LIBS) \
-       $(LIBNM_GLIB_LIBS)
+       $(LIBNM_LIBS)
 
 
 nm_openconnect_service_openconnect_helper_SOURCES = \
@@ -34,6 +34,6 @@ nm_openconnect_service_openconnect_helper_SOURCES = \
 nm_openconnect_service_openconnect_helper_LDADD = \
        $(DBUS_LIBS) \
        $(GTHREAD_LIBS) \
-       $(LIBNM_GLIB_LIBS)
+       $(LIBNM_LIBS)
 
 CLEANFILES = *~
diff --git a/src/nm-openconnect-service-openconnect-helper.c b/src/nm-openconnect-service-openconnect-helper.c
index 18a37a9..7102401 100644
--- a/src/nm-openconnect-service-openconnect-helper.c
+++ b/src/nm-openconnect-service-openconnect-helper.c
@@ -34,7 +34,6 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib.h>
 #include <NetworkManager.h>
-#include <nm-vpn-plugin-utils.h>
 
 #include "nm-openconnect-service.h"
 #include "nm-utils.h"
@@ -385,6 +384,63 @@ get_ip4_routes (void)
        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);
+
+               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 *
 get_ip6_routes (void)
 {
@@ -405,15 +461,16 @@ get_ip6_routes (void)
        routes = NULL;
 
        for (i = 0; i < num; i++) {
-               NMIP6Route *route;
+               NMIPRoute *route;
                char buf[BUFLEN];
-               struct in6_addr network;
+               char *network;
                guint32 prefix;
+               GError *error = NULL;
 
                snprintf (buf, BUFLEN, "CISCO_IPV6_SPLIT_INC_%d_ADDR", i);
-               tmp = getenv (buf);
-               if (!tmp || inet_pton (AF_INET6, tmp, &network) <= 0) {
-                       g_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL");
+               network = getenv (buf);
+               if (!network) {
+                       g_warning ("Ignoring invalid static route address '%s'", network ? network : "NULL");
                        continue;
                }
 
@@ -434,9 +491,12 @@ get_ip6_routes (void)
                        continue;
                }
 
-               route = nm_ip6_route_new ();
-               nm_ip6_route_set_dest (route, &network);
-               nm_ip6_route_set_prefix (route, prefix);
+               route = nm_ip_route_new (AF_INET6, network, prefix, NULL, -1, &error);
+               if (!route) {
+                       g_warning ("Ignoring a route: %s", error->message);
+                       g_error_free (error);
+                       continue;
+               }
 
                routes = g_slist_append (routes, route);
        }
@@ -449,7 +509,7 @@ get_ip6_routes (void)
                nm_utils_ip6_routes_to_gvalue (routes, value);
 
                for (iter = routes; iter; iter = iter->next)
-                       nm_ip6_route_unref (iter->data);
+                       nm_ip_route_unref (iter->data);
                g_slist_free (routes);
        }
 
diff --git a/src/nm-openconnect-service.c b/src/nm-openconnect-service.c
index 34ece9b..80c6131 100644
--- a/src/nm-openconnect-service.c
+++ b/src/nm-openconnect-service.c
@@ -43,7 +43,6 @@
 #include <locale.h>
 #include <glib/gi18n.h>
 
-#include <nm-setting-vpn.h>
 #include "nm-openconnect-service.h"
 #include "nm-utils.h"
 
@@ -51,7 +50,7 @@
 # define DIST_VERSION VERSION
 #endif
 
-G_DEFINE_TYPE (NMOpenconnectPlugin, nm_openconnect_plugin, NM_TYPE_VPN_PLUGIN)
+G_DEFINE_TYPE (NMOpenconnectPlugin, nm_openconnect_plugin, NM_TYPE_VPN_SERVICE_PLUGIN)
 
 typedef struct {
        GPid pid;
@@ -184,7 +183,7 @@ validate_one_property (const char *key, const char *value, gpointer user_data)
 }
 
 static gboolean
-nm_openconnect_properties_validate (NMSettingVPN *s_vpn, GError **error)
+nm_openconnect_properties_validate (NMSettingVpn *s_vpn, GError **error)
 {
        ValidateInfo info = { &valid_properties[0], error, FALSE };
 
@@ -202,7 +201,7 @@ nm_openconnect_properties_validate (NMSettingVPN *s_vpn, GError **error)
 }
 
 static gboolean
-nm_openconnect_secrets_validate (NMSettingVPN *s_vpn, GError **error)
+nm_openconnect_secrets_validate (NMSettingVpn *s_vpn, GError **error)
 {
        ValidateInfo info = { &valid_secrets[0], error, FALSE };
 
@@ -341,22 +340,22 @@ openconnect_watch_cb (GPid pid, gint status, gpointer user_data)
        switch (error) {
        case 2:
                /* Couldn't log in due to bad user/pass */
-               nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED);
+               nm_vpn_service_plugin_failure (NM_VPN_SERVICE_PLUGIN (plugin), 
NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED);
                break;
        case 1:
                /* Other error (couldn't bind to address, etc) */
-               nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+               nm_vpn_service_plugin_failure (NM_VPN_SERVICE_PLUGIN (plugin), 
NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
                break;
        default:
                break;
        }
 
-       nm_vpn_plugin_set_state (NM_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED);
+       nm_vpn_service_plugin_set_state (NM_VPN_SERVICE_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED);
 }
 
 static gint
 nm_openconnect_start_openconnect_binary (NMOpenconnectPlugin *plugin,
-                                         NMSettingVPN *s_vpn,
+                                         NMSettingVpn *s_vpn,
                                          GError **error)
 {
        NMOpenconnectPluginPrivate *priv = NM_OPENCONNECT_PLUGIN_GET_PRIVATE (plugin);
@@ -481,11 +480,11 @@ nm_openconnect_start_openconnect_binary (NMOpenconnectPlugin *plugin,
        return 0;
 }
 static gboolean
-real_connect (NMVPNPlugin   *plugin,
+real_connect (NMVpnServicePlugin   *plugin,
               NMConnection  *connection,
               GError       **error)
 {
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        gint openconnect_fd = -1;
 
        s_vpn = nm_connection_get_setting_vpn (connection);
@@ -507,21 +506,21 @@ real_connect (NMVPNPlugin   *plugin,
 }
 
 static gboolean
-real_need_secrets (NMVPNPlugin *plugin,
+real_need_secrets (NMVpnServicePlugin *plugin,
                    NMConnection *connection,
-                   char **setting_name,
+                   const char **setting_name,
                    GError **error)
 {
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
 
-       g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE);
+       g_return_val_if_fail (NM_IS_VPN_SERVICE_PLUGIN (plugin), FALSE);
        g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
 
        s_vpn = nm_connection_get_setting_vpn (connection);
        if (!s_vpn) {
                g_set_error (error,
                             NM_VPN_PLUGIN_ERROR,
-                            NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
                             "%s",
                             "Could not process the request because the VPN connection settings were 
invalid.");
                return FALSE;
@@ -557,7 +556,7 @@ ensure_killed (gpointer data)
 }
 
 static gboolean
-real_disconnect (NMVPNPlugin   *plugin,
+real_disconnect (NMVpnServicePlugin   *plugin,
                  GError       **err)
 {
        NMOpenconnectPluginPrivate *priv = NM_OPENCONNECT_PLUGIN_GET_PRIVATE (plugin);
@@ -584,7 +583,7 @@ static void
 nm_openconnect_plugin_class_init (NMOpenconnectPluginClass *openconnect_class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (openconnect_class);
-       NMVPNPluginClass *parent_class = NM_VPN_PLUGIN_CLASS (openconnect_class);
+       NMVpnServicePluginClass *parent_class = NM_VPN_SERVICE_PLUGIN_CLASS (openconnect_class);
 
        g_type_class_add_private (object_class, sizeof (NMOpenconnectPluginPrivate));
 
@@ -597,9 +596,18 @@ nm_openconnect_plugin_class_init (NMOpenconnectPluginClass *openconnect_class)
 NMOpenconnectPlugin *
 nm_openconnect_plugin_new (void)
 {
-       return (NMOpenconnectPlugin *) g_object_new (NM_TYPE_OPENCONNECT_PLUGIN,
-                                                    NM_VPN_PLUGIN_DBUS_SERVICE_NAME, 
NM_DBUS_SERVICE_OPENCONNECT,
-                                                    NULL);
+       NMOpenconnectPlugin *plugin;
+       GError *error = NULL;
+
+       plugin = (NMOpenconnectPlugin *) g_initable_new (NM_TYPE_OPENCONNECT_PLUGIN, NULL, &error,
+                                                        NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME, 
NM_DBUS_SERVICE_OPENCONNECT,
+                                                        NULL);
+       if (!plugin) {
+               g_warning ("Failed to initialize a plugin instance: %s", error->message);
+               g_error_free (error);
+       }
+
+       return plugin;
 }
 
 static void
diff --git a/src/nm-openconnect-service.h b/src/nm-openconnect-service.h
index 13b3019..5305af7 100644
--- a/src/nm-openconnect-service.h
+++ b/src/nm-openconnect-service.h
@@ -26,7 +26,8 @@
 #define NM_OPENCONNECT_PLUGIN_H
 
 #include <glib.h>
-#include <nm-vpn-plugin.h>
+#include <NetworkManager.h>
+#include <nm-vpn-service-plugin.h>
 
 #include "nm-openconnect-service-defines.h"
 
@@ -38,11 +39,11 @@
 #define NM_OPENCONNECT_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OPENCONNECT_PLUGIN, 
NMOpenconnectPluginClass))
 
 typedef struct {
-       NMVPNPlugin parent;
+       NMVpnServicePlugin parent;
 } NMOpenconnectPlugin;
 
 typedef struct {
-       NMVPNPluginClass parent;
+       NMVpnServicePluginClass parent;
 } NMOpenconnectPluginClass;
 
 GType nm_openconnect_plugin_get_type (void);


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