[network-manager-openvpn/lr/libnm: 6/9] service: port to libnm
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/lr/libnm: 6/9] service: port to libnm
- Date: Fri, 24 Jul 2015 15:48:39 +0000 (UTC)
commit c1c0e7af623d592664c4a4d80b9d4cb114f0a952
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Thu Jul 23 16:25:19 2015 +0200
service: port to libnm
src/Makefile.am | 6 +-
src/nm-openvpn-service-openvpn-helper.c | 84 ++++++++++++++++++++++------
src/nm-openvpn-service.c | 92 +++++++++++++++---------------
src/nm-openvpn-service.h | 6 +-
4 files changed, 117 insertions(+), 71 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d7b8e86..6ef53b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
AM_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
- $(LIBNM_GLIB_CFLAGS) \
+ $(LIBNM_CFLAGS) \
-DBINDIR=\"$(bindir)\" \
-DPREFIX=\""$(prefix)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
@@ -21,7 +21,7 @@ nm_openvpn_service_SOURCES = \
nm-openvpn-service-defines.h
nm_openvpn_service_LDADD = \
- $(LIBNM_GLIB_LIBS) \
+ $(LIBNM_LIBS) \
$(top_builddir)/common/libnm-openvpn-common.la
nm_openvpn_service_openvpn_helper_SOURCES = \
@@ -29,6 +29,6 @@ nm_openvpn_service_openvpn_helper_SOURCES = \
nm_openvpn_service_openvpn_helper_LDADD = \
$(DBUS_LIBS) \
- $(LIBNM_GLIB_LIBS)
+ $(LIBNM_LIBS)
CLEANFILES = *~
diff --git a/src/nm-openvpn-service-openvpn-helper.c b/src/nm-openvpn-service-openvpn-helper.c
index 2c07cff..fe6268c 100644
--- a/src/nm-openvpn-service-openvpn-helper.c
+++ b/src/nm-openvpn-service-openvpn-helper.c
@@ -350,6 +350,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)
{
@@ -361,11 +418,11 @@ get_ip6_routes (void)
routes = NULL;
for (i = 1; i < 256; i++) {
- NMIP6Route *route;
+ NMIPRoute *route;
char buf[BUFLEN];
- struct in6_addr network, gateway;
guint32 prefix;
gchar **dest_prefix;
+ GError *error = NULL;
snprintf (buf, BUFLEN, "route_ipv6_network_%d", i);
tmp = getenv (buf);
@@ -375,13 +432,6 @@ get_ip6_routes (void)
/* Split network string in "dest/prefix" format */
dest_prefix = g_strsplit (tmp, "/", 2);
- tmp = dest_prefix[0];
- if (inet_pton (AF_INET6, tmp, &network) <= 0) {
- g_warning ("Ignoring invalid static route address '%s'", tmp ? tmp : "NULL");
- g_strfreev (dest_prefix);
- continue;
- }
-
tmp = dest_prefix[1];
if (tmp) {
long int tmp_prefix;
@@ -403,17 +453,13 @@ get_ip6_routes (void)
snprintf (buf, BUFLEN, "route_ipv6_gateway_%d", i);
tmp = getenv (buf);
- /* gateway can be missing */
- if (tmp && (inet_pton (AF_INET6, tmp, &gateway) <= 0)) {
- g_warning ("Ignoring invalid static route gateway '%s'", tmp ? tmp : "NULL");
+
+ route = nm_ip_route_new (AF_INET6, dest_prefix[0], prefix, tmp, -1, &error);
+ if (!route) {
+ g_warning ("Ignoring a route: %s", error->message);
+ g_error_free (error);
continue;
}
-
- route = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route, &network);
- nm_ip6_route_set_prefix (route, prefix);
- nm_ip6_route_set_next_hop (route, &gateway);
-
routes = g_slist_append (routes, route);
}
@@ -425,7 +471,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-openvpn-service.c b/src/nm-openvpn-service.c
index 5c3229f..17a2412 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -49,7 +49,7 @@
#include <locale.h>
#include <NetworkManager.h>
-#include <NetworkManagerVPN.h>
+#include <nm-vpn-service-plugin.h>
#include <nm-setting-vpn.h>
#include "nm-openvpn-service.h"
@@ -66,7 +66,7 @@ static GMainLoop *loop = NULL;
#define NM_OPENVPN_HELPER_PATH LIBEXECDIR"/nm-openvpn-service-openvpn-helper"
-G_DEFINE_TYPE (NMOpenvpnPlugin, nm_openvpn_plugin, NM_TYPE_VPN_PLUGIN)
+G_DEFINE_TYPE (NMOpenvpnPlugin, nm_openvpn_plugin, NM_TYPE_VPN_SERVICE_PLUGIN)
#define NM_OPENVPN_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OPENVPN_PLUGIN,
NMOpenvpnPluginPrivate))
@@ -249,7 +249,7 @@ validate_one_property (const char *key, const char *value, gpointer user_data)
}
static gboolean
-nm_openvpn_properties_validate (NMSettingVPN *s_vpn, GError **error)
+nm_openvpn_properties_validate (NMSettingVpn *s_vpn, GError **error)
{
GError *validate_error = NULL;
ValidateInfo info = { &valid_properties[0], &validate_error, FALSE };
@@ -271,7 +271,7 @@ nm_openvpn_properties_validate (NMSettingVPN *s_vpn, GError **error)
}
static gboolean
-nm_openvpn_secrets_validate (NMSettingVPN *s_vpn, GError **error)
+nm_openvpn_secrets_validate (NMSettingVpn *s_vpn, GError **error)
{
GError *validate_error = NULL;
ValidateInfo info = { &valid_secrets[0], &validate_error, FALSE };
@@ -485,10 +485,10 @@ handle_auth (NMOpenvpnPluginIOData *io_data,
}
static gboolean
-handle_management_socket (NMVPNPlugin *plugin,
+handle_management_socket (NMVpnServicePlugin *plugin,
GIOChannel *source,
GIOCondition condition,
- NMVPNPluginFailure *out_failure)
+ NMVpnPluginFailure *out_failure)
{
NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
gboolean again = TRUE;
@@ -527,7 +527,7 @@ handle_management_socket (NMVPNPlugin *plugin,
g_message ("Requesting new secrets: '%s' (%s)", message,
joined);
g_free (joined);
}
- nm_vpn_plugin_secrets_required (plugin, message, (const char **)
hints);
+ nm_vpn_service_plugin_secrets_required (plugin, message, (const char
**) hints);
} else {
/* Interactive not allowed, can't ask for more secrets */
g_warning ("More secrets required but cannot ask interactively");
@@ -581,12 +581,12 @@ out:
static gboolean
nm_openvpn_socket_data_cb (GIOChannel *source, GIOCondition condition, gpointer user_data)
{
- NMVPNPlugin *plugin = NM_VPN_PLUGIN (user_data);
- NMVPNPluginFailure failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED;
+ NMVpnServicePlugin *plugin = NM_VPN_SERVICE_PLUGIN (user_data);
+ NMVpnPluginFailure failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED;
if (!handle_management_socket (plugin, source, condition, &failure)) {
- nm_vpn_plugin_failure (plugin, failure);
- nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED);
+ nm_vpn_service_plugin_failure (plugin, failure);
+ nm_vpn_service_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED);
return FALSE;
}
@@ -608,8 +608,8 @@ nm_openvpn_connect_timer_cb (gpointer data)
fd = socket (AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
g_warning ("Could not create management socket");
- nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
- nm_vpn_plugin_set_state (NM_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED);
+ nm_vpn_service_plugin_failure (NM_VPN_SERVICE_PLUGIN (plugin),
NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+ nm_vpn_service_plugin_set_state (NM_VPN_SERVICE_PLUGIN (plugin),
NM_VPN_SERVICE_STATE_STOPPED);
goto out;
}
@@ -623,8 +623,8 @@ nm_openvpn_connect_timer_cb (gpointer data)
priv->connect_timer = 0;
g_warning ("Could not open management socket");
- nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
- nm_vpn_plugin_set_state (NM_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED);
+ nm_vpn_service_plugin_failure (NM_VPN_SERVICE_PLUGIN (plugin),
NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+ nm_vpn_service_plugin_set_state (NM_VPN_SERVICE_PLUGIN (plugin),
NM_VPN_SERVICE_STATE_STOPPED);
} else {
io_data->socket_channel = g_io_channel_unix_new (fd);
g_io_channel_set_encoding (io_data->socket_channel, NULL, NULL);
@@ -651,9 +651,9 @@ nm_openvpn_schedule_connect_timer (NMOpenvpnPlugin *plugin)
static void
openvpn_watch_cb (GPid pid, gint status, gpointer user_data)
{
- NMVPNPlugin *plugin = NM_VPN_PLUGIN (user_data);
+ NMVpnServicePlugin *plugin = NM_VPN_SERVICE_PLUGIN (user_data);
NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
- NMVPNPluginFailure failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED;
+ NMVpnPluginFailure failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED;
guint error = 0;
gboolean good_exit = FALSE;
@@ -697,9 +697,9 @@ openvpn_watch_cb (GPid pid, gint status, gpointer user_data)
}
if (!good_exit)
- nm_vpn_plugin_failure (plugin, failure);
+ nm_vpn_service_plugin_failure (plugin, failure);
- nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED);
+ nm_vpn_service_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED);
}
static gboolean
@@ -797,7 +797,7 @@ add_openvpn_arg_int (GPtrArray *args, const char *arg)
}
static void
-add_cert_args (GPtrArray *args, NMSettingVPN *s_vpn)
+add_cert_args (GPtrArray *args, NMSettingVpn *s_vpn)
{
const char *ca, *cert, *key;
@@ -835,7 +835,7 @@ add_cert_args (GPtrArray *args, NMSettingVPN *s_vpn)
static void
update_io_data_from_vpn_setting (NMOpenvpnPluginIOData *io_data,
- NMSettingVPN *s_vpn,
+ NMSettingVpn *s_vpn,
const char *default_username)
{
const char *tmp;
@@ -877,7 +877,7 @@ update_io_data_from_vpn_setting (NMOpenvpnPluginIOData *io_data,
static gboolean
nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
- NMSettingVPN *s_vpn,
+ NMSettingVpn *s_vpn,
const char *default_username,
const char *uuid,
GError **error)
@@ -1334,7 +1334,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
}
static const char *
-check_need_secrets (NMSettingVPN *s_vpn, gboolean *need_secrets)
+check_need_secrets (NMSettingVpn *s_vpn, gboolean *need_secrets)
{
const char *tmp, *key, *ctype;
NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
@@ -1389,12 +1389,12 @@ check_need_secrets (NMSettingVPN *s_vpn, gboolean *need_secrets)
}
static gboolean
-_connect_common (NMVPNPlugin *plugin,
+_connect_common (NMVpnServicePlugin *plugin,
NMConnection *connection,
- GHashTable *details,
+ GVariant *details,
GError **error)
{
- NMSettingVPN *s_vpn;
+ NMSettingVpn *s_vpn;
const char *connection_type;
const char *user_name;
@@ -1402,7 +1402,7 @@ _connect_common (NMVPNPlugin *plugin,
if (!s_vpn) {
g_set_error_literal (error,
NM_VPN_PLUGIN_ERROR,
- NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+ NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
_("Could not process the request because the VPN connection settings
were invalid."));
return FALSE;
}
@@ -1411,7 +1411,7 @@ _connect_common (NMVPNPlugin *plugin,
if (!validate_connection_type (connection_type)) {
g_set_error_literal (error,
NM_VPN_PLUGIN_ERROR,
- NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+ NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
_("Could not process the request because the openvpn connection type was
invalid."));
return FALSE;
}
@@ -1437,7 +1437,7 @@ _connect_common (NMVPNPlugin *plugin,
}
static gboolean
-real_connect (NMVPNPlugin *plugin,
+real_connect (NMVpnServicePlugin *plugin,
NMConnection *connection,
GError **error)
{
@@ -1445,9 +1445,9 @@ real_connect (NMVPNPlugin *plugin,
}
static gboolean
-real_connect_interactive (NMVPNPlugin *plugin,
+real_connect_interactive (NMVpnServicePlugin *plugin,
NMConnection *connection,
- GHashTable *details,
+ GVariant *details,
GError **error)
{
if (!_connect_common (plugin, connection, details, error))
@@ -1458,16 +1458,16 @@ real_connect_interactive (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;
const char *connection_type;
gboolean need_secrets = FALSE;
- 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);
if (debug) {
@@ -1479,7 +1479,7 @@ real_need_secrets (NMVPNPlugin *plugin,
if (!s_vpn) {
g_set_error_literal (error,
NM_VPN_PLUGIN_ERROR,
- NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+ NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
_("Could not process the request because the VPN connection settings
were invalid."));
return FALSE;
}
@@ -1500,12 +1500,12 @@ real_need_secrets (NMVPNPlugin *plugin,
}
static gboolean
-real_new_secrets (NMVPNPlugin *plugin,
+real_new_secrets (NMVpnServicePlugin *plugin,
NMConnection *connection,
GError **error)
{
NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
- NMSettingVPN *s_vpn;
+ NMSettingVpn *s_vpn;
const char *message = NULL;
char **hints = NULL;
@@ -1513,7 +1513,7 @@ real_new_secrets (NMVPNPlugin *plugin,
if (!s_vpn) {
g_set_error_literal (error,
NM_VPN_PLUGIN_ERROR,
- NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+ NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
_("Could not process the request because the VPN connection settings
were invalid."));
return FALSE;
}
@@ -1527,7 +1527,7 @@ real_new_secrets (NMVPNPlugin *plugin,
if (!handle_auth (priv->io_data, priv->io_data->pending_auth, &message, &hints)) {
g_set_error_literal (error,
NM_VPN_PLUGIN_ERROR,
- NM_VPN_PLUGIN_ERROR_GENERAL,
+ NM_VPN_PLUGIN_ERROR_FAILED,
_("Unhandled pending authentication."));
return FALSE;
}
@@ -1536,7 +1536,7 @@ real_new_secrets (NMVPNPlugin *plugin,
if (message) {
if (debug)
g_message ("Requesting new secrets: '%s'", message);
- nm_vpn_plugin_secrets_required (plugin, message, (const char **) hints);
+ nm_vpn_service_plugin_secrets_required (plugin, message, (const char **) hints);
}
if (hints)
g_free (hints); /* elements are 'const' */
@@ -1555,7 +1555,7 @@ ensure_killed (gpointer data)
}
static gboolean
-real_disconnect (NMVPNPlugin *plugin,
+real_disconnect (NMVpnServicePlugin *plugin,
GError **err)
{
NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
@@ -1585,7 +1585,7 @@ static void
nm_openvpn_plugin_class_init (NMOpenvpnPluginClass *plugin_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (plugin_class);
- NMVPNPluginClass *parent_class = NM_VPN_PLUGIN_CLASS (plugin_class);
+ NMVpnServicePluginClass *parent_class = NM_VPN_SERVICE_PLUGIN_CLASS (plugin_class);
g_type_class_add_private (object_class, sizeof (NMOpenvpnPluginPrivate));
@@ -1599,7 +1599,7 @@ nm_openvpn_plugin_class_init (NMOpenvpnPluginClass *plugin_class)
static void
plugin_state_changed (NMOpenvpnPlugin *plugin,
- NMVPNServiceState state,
+ NMVpnServiceState state,
gpointer user_data)
{
NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
@@ -1628,7 +1628,7 @@ nm_openvpn_plugin_new (void)
NMOpenvpnPlugin *plugin;
plugin = (NMOpenvpnPlugin *) g_object_new (NM_TYPE_OPENVPN_PLUGIN,
- NM_VPN_PLUGIN_DBUS_SERVICE_NAME,
+ NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME,
NM_DBUS_SERVICE_OPENVPN,
NULL);
if (plugin)
@@ -1659,7 +1659,7 @@ setup_signals (void)
}
static void
-quit_mainloop (NMVPNPlugin *plugin, gpointer user_data)
+quit_mainloop (NMVpnServicePlugin *plugin, gpointer user_data)
{
g_main_loop_quit ((GMainLoop *) user_data);
}
diff --git a/src/nm-openvpn-service.h b/src/nm-openvpn-service.h
index d4b5710..5c3b0a4 100644
--- a/src/nm-openvpn-service.h
+++ b/src/nm-openvpn-service.h
@@ -25,7 +25,7 @@
#include <glib.h>
#include <glib-object.h>
-#include <nm-vpn-plugin.h>
+#include <nm-vpn-service-plugin.h>
#include "nm-openvpn-service-defines.h"
@@ -37,11 +37,11 @@
#define NM_OPENVPN_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OPENVPN_PLUGIN,
NMOpenvpnPluginClass))
typedef struct {
- NMVPNPlugin parent;
+ NMVpnServicePlugin parent;
} NMOpenvpnPlugin;
typedef struct {
- NMVPNPluginClass parent;
+ NMVpnServicePluginClass parent;
} NMOpenvpnPluginClass;
GType nm_openvpn_plugin_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]