diff options
author | Dan Winship <danw@gnome.org> | 2014-10-28 14:50:27 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-10-28 14:50:27 -0400 |
commit | 650d09baa3964747fb512fcdac029c7019cc397b (patch) | |
tree | 5fc9fa09e7237a53d8031630a6f06e2a63b5f91a | |
parent | e01e43cd2fa80391c6be70e8bf48eb5228177f11 (diff) | |
parent | 4d9cbaf9bf7952e8915da58057ba8db6fdea3476 (diff) | |
download | NetworkManager-650d09baa3964747fb512fcdac029c7019cc397b.tar.gz |
libnm: rename NMVpnPlugin (bgo #739072)
-rw-r--r-- | docs/libnm/libnm-docs.xml | 7 | ||||
-rw-r--r-- | libnm-core/nm-errors.c | 2 | ||||
-rw-r--r-- | libnm/Makefile.am | 16 | ||||
-rw-r--r-- | libnm/libnm.ver | 22 | ||||
-rw-r--r-- | libnm/nm-vpn-plugin-old.c (renamed from libnm/nm-vpn-plugin.c) | 509 | ||||
-rw-r--r-- | libnm/nm-vpn-plugin-old.h | 136 | ||||
-rw-r--r-- | libnm/nm-vpn-plugin-utils.c | 188 | ||||
-rw-r--r-- | libnm/nm-vpn-plugin-utils.h | 43 | ||||
-rw-r--r-- | libnm/nm-vpn-plugin.h | 130 |
9 files changed, 497 insertions, 556 deletions
diff --git a/docs/libnm/libnm-docs.xml b/docs/libnm/libnm-docs.xml index 00eba8abb2..007cbe4108 100644 --- a/docs/libnm/libnm-docs.xml +++ b/docs/libnm/libnm-docs.xml @@ -138,13 +138,6 @@ <xi:include href="xml/nm-utils.xml"/> </chapter> - <chapter> - <title>VPN Plugin API Reference </title> - <xi:include href="xml/nm-vpn-plugin.xml"/> - <xi:include href="xml/nm-vpn-plugin-ui-interface.xml"/> - <xi:include href="xml/nm-vpn-plugin-utils.xml"/> - </chapter> - <chapter id="object-tree"> <title>Object Hierarchy</title> <xi:include href="xml/tree_index.sgml"/> diff --git a/libnm-core/nm-errors.c b/libnm-core/nm-errors.c index 105425504c..2fead92e77 100644 --- a/libnm-core/nm-errors.c +++ b/libnm-core/nm-errors.c @@ -34,7 +34,7 @@ G_DEFINE_QUARK (nm-device-error-quark, nm_device_error) G_DEFINE_QUARK (nm-manager-error-quark, nm_manager_error) G_DEFINE_QUARK (nm-secret-agent-error-quark, nm_secret_agent_error) G_DEFINE_QUARK (nm-settings-error-quark, nm_settings_error) -G_DEFINE_QUARK (nm-vpn-plugin-quark, nm_vpn_plugin_error) +G_DEFINE_QUARK (nm-vpn-plugin-error-quark, nm_vpn_plugin_error) static void register_error_domain (GQuark domain, diff --git a/libnm/Makefile.am b/libnm/Makefile.am index 458aee8860..e14dc83a3f 100644 --- a/libnm/Makefile.am +++ b/libnm/Makefile.am @@ -24,7 +24,7 @@ lib_LTLIBRARIES = libnm.la libnmincludedir = $(includedir)/libnm -libnminclude_HEADERS = \ +libnminclude_hfiles = \ NetworkManager.h \ nm-access-point.h \ nm-active-connection.h \ @@ -53,11 +53,16 @@ libnminclude_HEADERS = \ nm-secret-agent.h \ nm-types.h \ nm-vpn-connection.h \ - nm-vpn-plugin.h \ nm-vpn-plugin-ui-interface.h \ - nm-vpn-plugin-utils.h \ nm-wimax-nsp.h +libnminclude_nointrospect_hfiles = \ + nm-vpn-plugin-old.h + +libnminclude_HEADERS = \ + $(libnminclude_hfiles) \ + $(libnminclude_nointrospect_hfiles) + libnm_la_private_headers = \ nm-dbus-helpers.h \ nm-device-private.h \ @@ -98,9 +103,8 @@ libnm_la_csources = \ nm-remote-settings.c \ nm-secret-agent.c \ nm-vpn-connection.c \ - nm-vpn-plugin.c \ + nm-vpn-plugin-old.c \ nm-vpn-plugin-ui-interface.c \ - nm-vpn-plugin-utils.c \ nm-wimax-nsp.c libnm_la_SOURCES = \ @@ -148,7 +152,7 @@ INTROSPECTION_COMPILER_ARGS = \ if HAVE_INTROSPECTION introspection_sources = \ $(libnm_core_headers) \ - $(libnminclude_HEADERS) \ + $(libnminclude_hfiles) \ $(libnm_core_sources) \ $(libnm_la_csources) diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 54d6057327..64a3b507df 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -856,18 +856,20 @@ global: nm_vpn_connection_get_vpn_state; nm_vpn_connection_state_get_type; nm_vpn_connection_state_reason_get_type; - nm_vpn_plugin_disconnect; nm_vpn_plugin_error_get_type; nm_vpn_plugin_error_quark; - nm_vpn_plugin_failure; nm_vpn_plugin_failure_get_type; - nm_vpn_plugin_get_connection; - nm_vpn_plugin_get_state; - nm_vpn_plugin_get_type; - nm_vpn_plugin_secrets_required; - nm_vpn_plugin_set_ip4_config; - nm_vpn_plugin_set_login_banner; - nm_vpn_plugin_set_state; + nm_vpn_plugin_old_disconnect; + nm_vpn_plugin_old_failure; + nm_vpn_plugin_old_get_connection; + nm_vpn_plugin_old_get_secret_flags; + nm_vpn_plugin_old_get_state; + nm_vpn_plugin_old_get_type; + nm_vpn_plugin_old_read_vpn_details; + nm_vpn_plugin_old_secrets_required; + nm_vpn_plugin_old_set_ip4_config; + nm_vpn_plugin_old_set_login_banner; + nm_vpn_plugin_old_set_state; nm_vpn_plugin_ui_capability_get_type; nm_vpn_plugin_ui_interface_export; nm_vpn_plugin_ui_interface_get_capabilities; @@ -879,8 +881,6 @@ global: nm_vpn_plugin_ui_widget_interface_get_type; nm_vpn_plugin_ui_widget_interface_get_widget; nm_vpn_plugin_ui_widget_interface_update_connection; - nm_vpn_plugin_utils_get_secret_flags; - nm_vpn_plugin_utils_read_vpn_details; nm_vpn_service_state_get_type; nm_wep_key_type_get_type; nm_wimax_nsp_connection_valid; diff --git a/libnm/nm-vpn-plugin.c b/libnm/nm-vpn-plugin-old.c index f6e00dbb24..28e6b7a587 100644 --- a/libnm/nm-vpn-plugin.c +++ b/libnm/nm-vpn-plugin-old.c @@ -19,26 +19,33 @@ * Copyright 2007 - 2008 Red Hat, Inc. */ +/* This interface is expected to be deprecated in NM 1.2, at which point there + * will be a new "NMVpnPlugin" class to replace it. + */ + +#include <errno.h> #include <signal.h> +#include <stdlib.h> #include <glib/gi18n.h> #include <gio/gio.h> #include "nm-glib-compat.h" -#include "nm-vpn-plugin.h" +#include "nm-vpn-plugin-old.h" #include "nm-enum-types.h" #include "nm-utils.h" #include "nm-connection.h" #include "nm-dbus-helpers.h" +#include "nm-core-internal.h" #include "nmdbus-vpn-plugin.h" -#define NM_VPN_PLUGIN_QUIT_TIMER 20 +#define NM_VPN_PLUGIN_OLD_QUIT_TIMER 20 -static void nm_vpn_plugin_initable_iface_init (GInitableIface *iface); +static void nm_vpn_plugin_old_initable_iface_init (GInitableIface *iface); -G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMVpnPlugin, nm_vpn_plugin, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_vpn_plugin_initable_iface_init); +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMVpnPluginOld, nm_vpn_plugin_old, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_vpn_plugin_old_initable_iface_init); ) typedef struct { @@ -46,7 +53,7 @@ typedef struct { /* DBUS-y stuff */ GDBusConnection *connection; - NMDBusVpnPlugin *dbus_vpn_plugin; + NMDBusVpnPlugin *dbus_vpn_plugin_old; char *dbus_service_name; /* Temporary stuff */ @@ -61,9 +68,9 @@ typedef struct { /* Config stuff copied from config to ip4config */ char *banner, *tundev, *gateway, *mtu; -} NMVpnPluginPrivate; +} NMVpnPluginOldPrivate; -#define NM_VPN_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_PLUGIN, NMVpnPluginPrivate)) +#define NM_VPN_PLUGIN_OLD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_PLUGIN_OLD, NMVpnPluginOldPrivate)) enum { STATE_CHANGED, @@ -92,10 +99,10 @@ static GSList *active_plugins = NULL; static void -nm_vpn_plugin_set_connection (NMVpnPlugin *plugin, - GDBusConnection *connection) +nm_vpn_plugin_old_set_connection (NMVpnPluginOld *plugin, + GDBusConnection *connection) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); g_clear_object (&priv->connection); @@ -103,18 +110,18 @@ nm_vpn_plugin_set_connection (NMVpnPlugin *plugin, } /** - * nm_vpn_plugin_get_connection: + * nm_vpn_plugin_old_get_connection: * * Returns: (transfer full): */ GDBusConnection * -nm_vpn_plugin_get_connection (NMVpnPlugin *plugin) +nm_vpn_plugin_old_get_connection (NMVpnPluginOld *plugin) { GDBusConnection *connection; - g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), NULL); + g_return_val_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin), NULL); - connection = NM_VPN_PLUGIN_GET_PRIVATE (plugin)->connection; + connection = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin)->connection; if (connection) g_object_ref (connection); @@ -123,22 +130,22 @@ nm_vpn_plugin_get_connection (NMVpnPlugin *plugin) } NMVpnServiceState -nm_vpn_plugin_get_state (NMVpnPlugin *plugin) +nm_vpn_plugin_old_get_state (NMVpnPluginOld *plugin) { - g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_UNKNOWN); + g_return_val_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin), NM_VPN_SERVICE_STATE_UNKNOWN); - return NM_VPN_PLUGIN_GET_PRIVATE (plugin)->state; + return NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin)->state; } void -nm_vpn_plugin_set_state (NMVpnPlugin *plugin, - NMVpnServiceState state) +nm_vpn_plugin_old_set_state (NMVpnPluginOld *plugin, + NMVpnServiceState state) { - NMVpnPluginPrivate *priv; + NMVpnPluginOldPrivate *priv; - g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); + g_return_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin)); - priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); if (priv->state != state) { priv->state = state; g_signal_emit (plugin, signals[STATE_CHANGED], 0, state); @@ -146,33 +153,33 @@ nm_vpn_plugin_set_state (NMVpnPlugin *plugin, } void -nm_vpn_plugin_set_login_banner (NMVpnPlugin *plugin, - const char *banner) +nm_vpn_plugin_old_set_login_banner (NMVpnPluginOld *plugin, + const char *banner) { - g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); + g_return_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin)); g_return_if_fail (banner != NULL); g_signal_emit (plugin, signals[LOGIN_BANNER], 0, banner); } void -nm_vpn_plugin_failure (NMVpnPlugin *plugin, - NMVpnPluginFailure reason) +nm_vpn_plugin_old_failure (NMVpnPluginOld *plugin, + NMVpnPluginFailure reason) { - g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); + g_return_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin)); g_signal_emit (plugin, signals[FAILURE], 0, reason); } gboolean -nm_vpn_plugin_disconnect (NMVpnPlugin *plugin, GError **err) +nm_vpn_plugin_old_disconnect (NMVpnPluginOld *plugin, GError **err) { gboolean ret = FALSE; NMVpnServiceState state; - g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); + g_return_val_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin), FALSE); - state = nm_vpn_plugin_get_state (plugin); + state = nm_vpn_plugin_old_get_state (plugin); switch (state) { case NM_VPN_SERVICE_STATE_STOPPING: g_set_error (err, @@ -190,9 +197,9 @@ nm_vpn_plugin_disconnect (NMVpnPlugin *plugin, GError **err) break; case NM_VPN_SERVICE_STATE_STARTING: case NM_VPN_SERVICE_STATE_STARTED: - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPING); - ret = NM_VPN_PLUGIN_GET_CLASS (plugin)->disconnect (plugin, err); - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPING); + ret = NM_VPN_PLUGIN_OLD_GET_CLASS (plugin)->disconnect (plugin, err); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED); break; case NM_VPN_SERVICE_STATE_INIT: ret = TRUE; @@ -208,7 +215,7 @@ nm_vpn_plugin_disconnect (NMVpnPlugin *plugin, GError **err) } static void -nm_vpn_plugin_emit_quit (NMVpnPlugin *plugin) +nm_vpn_plugin_old_emit_quit (NMVpnPluginOld *plugin) { g_signal_emit (plugin, signals[QUIT], 0); } @@ -216,11 +223,11 @@ nm_vpn_plugin_emit_quit (NMVpnPlugin *plugin) static gboolean connect_timer_expired (gpointer data) { - NMVpnPlugin *plugin = NM_VPN_PLUGIN (data); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD (data); GError *err = NULL; g_message ("Connect timer expired, disconnecting."); - nm_vpn_plugin_disconnect (plugin, &err); + nm_vpn_plugin_old_disconnect (plugin, &err); if (err) { g_warning ("Disconnect failed: %s", err->message); g_error_free (err); @@ -232,9 +239,9 @@ connect_timer_expired (gpointer data) static gboolean quit_timer_expired (gpointer data) { - NMVpnPlugin *plugin = NM_VPN_PLUGIN (data); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD (data); - nm_vpn_plugin_emit_quit (plugin); + nm_vpn_plugin_old_emit_quit (plugin); return FALSE; } @@ -242,16 +249,16 @@ quit_timer_expired (gpointer data) static gboolean fail_stop (gpointer data) { - NMVpnPlugin *plugin = NM_VPN_PLUGIN (data); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD (data); - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED); return FALSE; } static void -schedule_fail_stop (NMVpnPlugin *plugin) +schedule_fail_stop (NMVpnPluginOld *plugin) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); if (priv->fail_stop_id) g_source_remove (priv->fail_stop_id); @@ -259,12 +266,12 @@ schedule_fail_stop (NMVpnPlugin *plugin) } void -nm_vpn_plugin_set_config (NMVpnPlugin *plugin, - GVariant *config) +nm_vpn_plugin_old_set_config (NMVpnPluginOld *plugin, + GVariant *config) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); - g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); + g_return_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin)); g_return_if_fail (config != NULL); priv->got_config = TRUE; @@ -290,22 +297,22 @@ nm_vpn_plugin_set_config (NMVpnPlugin *plugin, } void -nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GVariant *ip4_config) +nm_vpn_plugin_old_set_ip4_config (NMVpnPluginOld *plugin, + GVariant *ip4_config) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); GVariant *combined_config; GVariantBuilder builder; GVariantIter iter; const char *key, *value; - g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); + g_return_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin)); g_return_if_fail (ip4_config != NULL); priv->got_ip4 = TRUE; /* Old plugins won't send the "config" signal and thus can't send - * NM_VPN_PLUGIN_CONFIG_HAS_IP4 either. But since they don't support IPv6, + * NM_VPN_PLUGIN_OLD_CONFIG_HAS_IP4 either. But since they don't support IPv6, * we can safely assume that, if we don't receive a "config" signal but do * receive an "ip4-config" signal, the old plugin supports IPv4. */ @@ -338,16 +345,16 @@ nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, if ( priv->has_ip4 == priv->got_ip4 && priv->has_ip6 == priv->got_ip6) - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTED); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_STARTED); } void -nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GVariant *ip6_config) +nm_vpn_plugin_old_set_ip6_config (NMVpnPluginOld *plugin, + GVariant *ip6_config) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); - g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); + g_return_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin)); g_return_if_fail (ip6_config != NULL); priv->got_ip6 = TRUE; @@ -355,19 +362,19 @@ nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, if ( priv->has_ip4 == priv->got_ip4 && priv->has_ip6 == priv->got_ip6) - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTED); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_STARTED); } static void connect_timer_removed (gpointer data) { - NM_VPN_PLUGIN_GET_PRIVATE (data)->connect_timer = 0; + NM_VPN_PLUGIN_OLD_GET_PRIVATE (data)->connect_timer = 0; } static void -connect_timer_start (NMVpnPlugin *plugin) +connect_timer_start (NMVpnPluginOld *plugin) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); priv->connect_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 60, @@ -377,13 +384,13 @@ connect_timer_start (NMVpnPlugin *plugin) } static void -_connect_generic (NMVpnPlugin *plugin, +_connect_generic (NMVpnPluginOld *plugin, GDBusMethodInvocation *context, GVariant *properties, GVariant *details) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); - NMVpnPluginClass *vpn_class = NM_VPN_PLUGIN_GET_CLASS (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); + NMVpnPluginOldClass *vpn_class = NM_VPN_PLUGIN_OLD_GET_CLASS (plugin); NMConnection *connection; gboolean success = FALSE; GError *error = NULL; @@ -417,7 +424,7 @@ _connect_generic (NMVpnPlugin *plugin, return; } - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); if (details) { priv->interactive = TRUE; @@ -443,20 +450,20 @@ _connect_generic (NMVpnPlugin *plugin, } static void -impl_vpn_plugin_connect (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *connection, - gpointer user_data) +impl_vpn_plugin_old_connect (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *connection, + gpointer user_data) { _connect_generic (plugin, context, connection, NULL); } static void -impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *connection, - GVariant *details, - gpointer user_data) +impl_vpn_plugin_old_connect_interactive (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *connection, + GVariant *details, + gpointer user_data) { _connect_generic (plugin, context, connection, details); } @@ -464,10 +471,10 @@ impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin, /***************************************************************/ static void -impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *properties, - gpointer user_data) +impl_vpn_plugin_old_need_secrets (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *properties, + gpointer user_data) { NMConnection *connection; char *setting_name; @@ -485,13 +492,13 @@ impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, return; } - if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) { + if (!NM_VPN_PLUGIN_OLD_GET_CLASS (plugin)->need_secrets) { g_dbus_method_invocation_return_value (context, g_variant_new ("(s)", "")); return; } - needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &setting_name, &error); + needed = NM_VPN_PLUGIN_OLD_GET_CLASS (plugin)->need_secrets (plugin, connection, &setting_name, &error); if (error) { g_dbus_method_invocation_take_error (context, error); return; @@ -510,12 +517,12 @@ impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, } static void -impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *properties, - gpointer user_data) +impl_vpn_plugin_old_new_secrets (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *properties, + gpointer user_data) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); NMConnection *connection; GError *error = NULL; gboolean success; @@ -540,7 +547,7 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, return; } - if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) { + if (!NM_VPN_PLUGIN_OLD_GET_CLASS (plugin)->new_secrets) { g_dbus_method_invocation_return_error (context, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, @@ -549,7 +556,7 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, return; } - success = NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets (plugin, connection, &error); + success = NM_VPN_PLUGIN_OLD_GET_CLASS (plugin)->new_secrets (plugin, connection, &error); if (success) { g_dbus_method_invocation_return_value (context, NULL); @@ -568,8 +575,8 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, } /** - * nm_vpn_plugin_secrets_required: - * @plugin: the #NMVpnPlugin + * nm_vpn_plugin_old_secrets_required: + * @plugin: the #NMVpnPluginOld * @message: an information message about why secrets are required, if any * @hints: VPN specific secret names for required new secrets * @@ -580,14 +587,14 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, * information to complete the request. */ void -nm_vpn_plugin_secrets_required (NMVpnPlugin *plugin, - const char *message, - const char **hints) +nm_vpn_plugin_old_secrets_required (NMVpnPluginOld *plugin, + const char *message, + const char **hints) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); /* Plugin must be able to accept the new secrets if it calls this method */ - g_return_if_fail (NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets); + g_return_if_fail (NM_VPN_PLUGIN_OLD_GET_CLASS (plugin)->new_secrets); /* Plugin cannot call this method if NetworkManager didn't originally call * ConnectInteractive(). @@ -605,56 +612,218 @@ nm_vpn_plugin_secrets_required (NMVpnPlugin *plugin, /***************************************************************/ +#define DATA_KEY_TAG "DATA_KEY=" +#define DATA_VAL_TAG "DATA_VAL=" +#define SECRET_KEY_TAG "SECRET_KEY=" +#define SECRET_VAL_TAG "SECRET_VAL=" + +static void +free_secret (gpointer data) +{ + char *secret = data; + + memset (secret, 0, strlen (secret)); + g_free (secret); +} + +/** + * nm_vpn_plugin_old_read_vpn_details: + * @fd: file descriptor to read from, usually stdin (0) + * @out_data: (out) (transfer full): on successful return, a hash table + * (mapping char*:char*) containing the key/value pairs of VPN data items + * @out_secrets: (out) (transfer full): on successful return, a hash table + * (mapping char*:char*) containing the key/value pairsof VPN secrets + * + * Parses key/value pairs from a file descriptor (normally stdin) passed by + * an applet when the applet calls the authentication dialog of the VPN plugin. + * + * Returns: %TRUE if reading values was successful, %FALSE if not + **/ +gboolean +nm_vpn_plugin_old_read_vpn_details (int fd, + GHashTable **out_data, + GHashTable **out_secrets) +{ + GHashTable *data, *secrets; + gboolean success = FALSE; + char *key = NULL, *val = NULL; + GString *line; + gchar c; + + if (out_data) + g_return_val_if_fail (*out_data == NULL, FALSE); + if (out_secrets) + g_return_val_if_fail (*out_secrets == NULL, FALSE); + + data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret); + + line = g_string_new (NULL); + + /* Read stdin for data and secret items until we get a DONE */ + while (1) { + ssize_t nr; + GHashTable *hash = NULL; + + errno = 0; + nr = read (fd, &c, 1); + if (nr == -1) { + if (errno == EAGAIN) { + g_usleep (100); + continue; + } + break; + } + + if (c != '\n') { + g_string_append_c (line, c); + continue; + } + + /* Check for the finish marker */ + if (strcmp (line->str, "DONE") == 0) + break; + + /* Otherwise it's a data/secret item */ + if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) { + hash = data; + key = g_strdup (line->str + strlen (DATA_KEY_TAG)); + } else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) { + hash = data; + val = g_strdup (line->str + strlen (DATA_VAL_TAG)); + } else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) { + hash = secrets; + key = g_strdup (line->str + strlen (SECRET_KEY_TAG)); + } else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) { + hash = secrets; + val = g_strdup (line->str + strlen (SECRET_VAL_TAG)); + } + g_string_truncate (line, 0); + + if (key && val && hash) { + g_hash_table_insert (hash, key, val); + key = NULL; + val = NULL; + success = TRUE; /* Got at least one value */ + } + } + + if (success) { + if (out_data) + *out_data = data; + else + g_hash_table_destroy (data); + + if (out_secrets) + *out_secrets = secrets; + else + g_hash_table_destroy (secrets); + } else { + g_hash_table_destroy (data); + g_hash_table_destroy (secrets); + } + + g_string_free (line, TRUE); + return success; +} + +/** + * nm_vpn_plugin_old_get_secret_flags: + * @data: hash table containing VPN key/value pair data items + * @secret_name: VPN secret key name for which to retrieve flags for + * @out_flags: (out): on success, the flags associated with @secret_name + * + * Given a VPN secret key name, attempts to find the corresponding flags data + * item in @data. If found, converts the flags data item to + * #NMSettingSecretFlags and returns it. + * + * Returns: %TRUE if the flag data item was found and successfully converted + * to flags, %FALSE if not + **/ +gboolean +nm_vpn_plugin_old_get_secret_flags (GHashTable *data, + const char *secret_name, + NMSettingSecretFlags *out_flags) +{ + char *flag_name; + const char *val; + unsigned long tmp; + gboolean success = FALSE; + + g_return_val_if_fail (data != NULL, FALSE); + g_return_val_if_fail (secret_name != NULL, FALSE); + g_return_val_if_fail (out_flags != NULL, FALSE); + g_return_val_if_fail (*out_flags == NM_SETTING_SECRET_FLAG_NONE, FALSE); + + flag_name = g_strdup_printf ("%s-flags", secret_name); + + /* Try new flags value first */ + val = g_hash_table_lookup (data, flag_name); + if (val) { + errno = 0; + tmp = strtoul (val, NULL, 10); + if (errno == 0 && tmp <= NM_SETTING_SECRET_FLAGS_ALL) { + *out_flags = (NMSettingSecretFlags) tmp; + success = TRUE; + } + } + + g_free (flag_name); + return success; +} + +/***************************************************************/ + static void -impl_vpn_plugin_disconnect (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - gpointer user_data) +impl_vpn_plugin_old_disconnect (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + gpointer user_data) { GError *error = NULL; - if (nm_vpn_plugin_disconnect (plugin, &error)) + if (nm_vpn_plugin_old_disconnect (plugin, &error)) g_dbus_method_invocation_return_value (context, NULL); else g_dbus_method_invocation_take_error (context, error); } static void -impl_vpn_plugin_set_config (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *config, - gpointer user_data) +impl_vpn_plugin_old_set_config (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *config, + gpointer user_data) { - nm_vpn_plugin_set_config (plugin, config); + nm_vpn_plugin_old_set_config (plugin, config); g_dbus_method_invocation_return_value (context, NULL); } static void -impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *config, - gpointer user_data) +impl_vpn_plugin_old_set_ip4_config (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *config, + gpointer user_data) { - nm_vpn_plugin_set_ip4_config (plugin, config); + nm_vpn_plugin_old_set_ip4_config (plugin, config); g_dbus_method_invocation_return_value (context, NULL); } static void -impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - GVariant *config, - gpointer user_data) +impl_vpn_plugin_old_set_ip6_config (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + GVariant *config, + gpointer user_data) { - nm_vpn_plugin_set_ip6_config (plugin, config); + nm_vpn_plugin_old_set_ip6_config (plugin, config); g_dbus_method_invocation_return_value (context, NULL); } static void -impl_vpn_plugin_set_failure (NMVpnPlugin *plugin, - GDBusMethodInvocation *context, - char *reason, - gpointer user_data) +impl_vpn_plugin_old_set_failure (NMVpnPluginOld *plugin, + GDBusMethodInvocation *context, + char *reason, + gpointer user_data) { - nm_vpn_plugin_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); + nm_vpn_plugin_old_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); g_dbus_method_invocation_return_value (context, NULL); } @@ -663,7 +832,7 @@ impl_vpn_plugin_set_failure (NMVpnPlugin *plugin, static void sigterm_handler (int signum) { - g_slist_foreach (active_plugins, (GFunc) nm_vpn_plugin_emit_quit, NULL); + g_slist_foreach (active_plugins, (GFunc) nm_vpn_plugin_old_emit_quit, NULL); } static void @@ -690,7 +859,7 @@ one_plugin_destroyed (gpointer data, } static void -nm_vpn_plugin_init (NMVpnPlugin *plugin) +nm_vpn_plugin_old_init (NMVpnPluginOld *plugin) { active_plugins = g_slist_append (active_plugins, plugin); g_object_weak_ref (G_OBJECT (plugin), @@ -701,8 +870,8 @@ nm_vpn_plugin_init (NMVpnPlugin *plugin) static gboolean init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { - NMVpnPlugin *plugin = NM_VPN_PLUGIN (initable); - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD (initable); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); GDBusConnection *connection = NULL; GDBusProxy *proxy; GVariant *ret; @@ -742,28 +911,28 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) } g_variant_unref (ret); - priv->dbus_vpn_plugin = nmdbus_vpn_plugin_skeleton_new (); - if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_vpn_plugin), + priv->dbus_vpn_plugin_old = nmdbus_vpn_plugin_skeleton_new (); + if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_vpn_plugin_old), connection, NM_VPN_DBUS_PLUGIN_PATH, error)) goto out; - _nm_dbus_bind_properties (plugin, priv->dbus_vpn_plugin); - _nm_dbus_bind_methods (plugin, priv->dbus_vpn_plugin, - "Connect", impl_vpn_plugin_connect, - "ConnectInteractive", impl_vpn_plugin_connect_interactive, - "NeedSecrets", impl_vpn_plugin_need_secrets, - "NewSecrets", impl_vpn_plugin_new_secrets, - "Disconnect", impl_vpn_plugin_disconnect, - "SetConfig", impl_vpn_plugin_set_config, - "SetIp4Config", impl_vpn_plugin_set_ip4_config, - "SetIp6Config", impl_vpn_plugin_set_ip6_config, - "SetFailure", impl_vpn_plugin_set_failure, + _nm_dbus_bind_properties (plugin, priv->dbus_vpn_plugin_old); + _nm_dbus_bind_methods (plugin, priv->dbus_vpn_plugin_old, + "Connect", impl_vpn_plugin_old_connect, + "ConnectInteractive", impl_vpn_plugin_old_connect_interactive, + "NeedSecrets", impl_vpn_plugin_old_need_secrets, + "NewSecrets", impl_vpn_plugin_old_new_secrets, + "Disconnect", impl_vpn_plugin_old_disconnect, + "SetConfig", impl_vpn_plugin_old_set_config, + "SetIp4Config", impl_vpn_plugin_old_set_ip4_config, + "SetIp6Config", impl_vpn_plugin_old_set_ip6_config, + "SetFailure", impl_vpn_plugin_old_set_failure, NULL); - nm_vpn_plugin_set_connection (plugin, connection); - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_INIT); + nm_vpn_plugin_old_set_connection (plugin, connection); + nm_vpn_plugin_old_set_state (plugin, NM_VPN_SERVICE_STATE_INIT); success = TRUE; @@ -777,7 +946,7 @@ static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (object); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (object); switch (prop_id) { case PROP_DBUS_SERVICE_NAME: @@ -785,8 +954,8 @@ set_property (GObject *object, guint prop_id, priv->dbus_service_name = g_value_dup_string (value); break; case PROP_STATE: - nm_vpn_plugin_set_state (NM_VPN_PLUGIN (object), - (NMVpnServiceState) g_value_get_enum (value)); + nm_vpn_plugin_old_set_state (NM_VPN_PLUGIN_OLD (object), + (NMVpnServiceState) g_value_get_enum (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -798,14 +967,14 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (object); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (object); switch (prop_id) { case PROP_DBUS_SERVICE_NAME: g_value_set_string (value, priv->dbus_service_name); break; case PROP_STATE: - g_value_set_enum (value, nm_vpn_plugin_get_state (NM_VPN_PLUGIN (object))); + g_value_set_enum (value, nm_vpn_plugin_old_get_state (NM_VPN_PLUGIN_OLD (object))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -816,8 +985,8 @@ get_property (GObject *object, guint prop_id, static void dispose (GObject *object) { - NMVpnPlugin *plugin = NM_VPN_PLUGIN (object); - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD (object); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); NMVpnServiceState state; GError *err = NULL; @@ -826,27 +995,27 @@ dispose (GObject *object) priv->fail_stop_id = 0; } - state = nm_vpn_plugin_get_state (plugin); + state = nm_vpn_plugin_old_get_state (plugin); if (state == NM_VPN_SERVICE_STATE_STARTED || state == NM_VPN_SERVICE_STATE_STARTING) - nm_vpn_plugin_disconnect (plugin, &err); + nm_vpn_plugin_old_disconnect (plugin, &err); if (err) { g_warning ("Error disconnecting VPN connection: %s", err->message); g_error_free (err); } - G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->dispose (object); + G_OBJECT_CLASS (nm_vpn_plugin_old_parent_class)->dispose (object); } static void finalize (GObject *object) { - NMVpnPlugin *plugin = NM_VPN_PLUGIN (object); - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOld *plugin = NM_VPN_PLUGIN_OLD (object); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); - nm_vpn_plugin_set_connection (plugin, NULL); + nm_vpn_plugin_old_set_connection (plugin, NULL); g_free (priv->dbus_service_name); g_clear_pointer (&priv->banner, g_free); @@ -854,19 +1023,19 @@ finalize (GObject *object) g_clear_pointer (&priv->gateway, g_free); g_clear_pointer (&priv->mtu, g_free); - G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (nm_vpn_plugin_old_parent_class)->finalize (object); } static void quit_timer_removed (gpointer data) { - NM_VPN_PLUGIN_GET_PRIVATE (data)->quit_timer = 0; + NM_VPN_PLUGIN_OLD_GET_PRIVATE (data)->quit_timer = 0; } static void -state_changed (NMVpnPlugin *plugin, NMVpnServiceState state) +state_changed (NMVpnPluginOld *plugin, NMVpnServiceState state) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + NMVpnPluginOldPrivate *priv = NM_VPN_PLUGIN_OLD_GET_PRIVATE (plugin); switch (state) { case NM_VPN_SERVICE_STATE_STARTING: @@ -881,7 +1050,7 @@ state_changed (NMVpnPlugin *plugin, NMVpnServiceState state) break; case NM_VPN_SERVICE_STATE_STOPPED: priv->quit_timer = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, - NM_VPN_PLUGIN_QUIT_TIMER, + NM_VPN_PLUGIN_OLD_QUIT_TIMER, quit_timer_expired, plugin, quit_timer_removed); @@ -903,11 +1072,11 @@ state_changed (NMVpnPlugin *plugin, NMVpnServiceState state) } static void -nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) +nm_vpn_plugin_old_class_init (NMVpnPluginOldClass *plugin_class) { GObjectClass *object_class = G_OBJECT_CLASS (plugin_class); - g_type_class_add_private (object_class, sizeof (NMVpnPluginPrivate)); + g_type_class_add_private (object_class, sizeof (NMVpnPluginOldPrivate)); /* virtual methods */ object_class->set_property = set_property; @@ -920,26 +1089,26 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) /* properties */ /** - * NMVpnPlugin:service-name: + * NMVpnPluginOld:service-name: * * The D-Bus service name of this plugin. */ g_object_class_install_property (object_class, PROP_DBUS_SERVICE_NAME, - g_param_spec_string (NM_VPN_PLUGIN_DBUS_SERVICE_NAME, "", "", + g_param_spec_string (NM_VPN_PLUGIN_OLD_DBUS_SERVICE_NAME, "", "", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /** - * NMVpnPlugin:state: + * NMVpnPluginOld:state: * * The state of the plugin. */ g_object_class_install_property (object_class, PROP_STATE, - g_param_spec_enum (NM_VPN_PLUGIN_STATE, "", "", + g_param_spec_enum (NM_VPN_PLUGIN_OLD_STATE, "", "", NM_TYPE_VPN_SERVICE_STATE, NM_VPN_SERVICE_STATE_INIT, G_PARAM_READWRITE | @@ -950,7 +1119,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("state-changed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, state_changed), + G_STRUCT_OFFSET (NMVpnPluginOldClass, state_changed), NULL, NULL, NULL, G_TYPE_NONE, 1, @@ -968,7 +1137,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("config", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, config), + G_STRUCT_OFFSET (NMVpnPluginOldClass, config), NULL, NULL, NULL, G_TYPE_NONE, 1, @@ -978,7 +1147,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("ip4-config", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, ip4_config), + G_STRUCT_OFFSET (NMVpnPluginOldClass, ip4_config), NULL, NULL, NULL, G_TYPE_NONE, 1, @@ -988,7 +1157,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("ip6-config", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, ip6_config), + G_STRUCT_OFFSET (NMVpnPluginOldClass, ip6_config), NULL, NULL, NULL, G_TYPE_NONE, 1, @@ -998,7 +1167,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("login-banner", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, login_banner), + G_STRUCT_OFFSET (NMVpnPluginOldClass, login_banner), NULL, NULL, NULL, G_TYPE_NONE, 1, @@ -1008,7 +1177,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("failure", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, failure), + G_STRUCT_OFFSET (NMVpnPluginOldClass, failure), NULL, NULL, NULL, G_TYPE_NONE, 1, @@ -1018,7 +1187,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_signal_new ("quit", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVpnPluginClass, quit), + G_STRUCT_OFFSET (NMVpnPluginOldClass, quit), NULL, NULL, NULL, G_TYPE_NONE, 0, @@ -1028,7 +1197,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) } static void -nm_vpn_plugin_initable_iface_init (GInitableIface *iface) +nm_vpn_plugin_old_initable_iface_init (GInitableIface *iface) { iface->init = init_sync; } diff --git a/libnm/nm-vpn-plugin-old.h b/libnm/nm-vpn-plugin-old.h new file mode 100644 index 0000000000..7fcc1c1c0a --- /dev/null +++ b/libnm/nm-vpn-plugin-old.h @@ -0,0 +1,136 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2007 - 2008 Novell, Inc. + * Copyright 2007 - 2013 Red Hat, Inc. + */ + +#ifndef __NM_VPN_PLUGIN_OLD_H__ +#define __NM_VPN_PLUGIN_OLD_H__ + +#include <gio/gio.h> +#include <nm-vpn-dbus-interface.h> +#include <nm-connection.h> + +G_BEGIN_DECLS + +#define NM_TYPE_VPN_PLUGIN_OLD (nm_vpn_plugin_old_get_type ()) +#define NM_VPN_PLUGIN_OLD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_PLUGIN_OLD, NMVpnPluginOld)) +#define NM_VPN_PLUGIN_OLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_VPN_PLUGIN_OLD, NMVpnPluginOldClass)) +#define NM_IS_VPN_PLUGIN_OLD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_PLUGIN_OLD)) +#define NM_IS_VPN_PLUGIN_OLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_VPN_PLUGIN_OLD)) +#define NM_VPN_PLUGIN_OLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_VPN_PLUGIN_OLD, NMVpnPluginOldClass)) + +#define NM_VPN_PLUGIN_OLD_DBUS_SERVICE_NAME "service-name" +#define NM_VPN_PLUGIN_OLD_STATE "state" + +typedef struct { + GObject parent; +} NMVpnPluginOld; + +typedef struct { + GObjectClass parent; + + /* Signals */ + void (*state_changed) (NMVpnPluginOld *plugin, + NMVpnServiceState state); + + void (*ip4_config) (NMVpnPluginOld *plugin, + GVariant *ip4_config); + + void (*login_banner) (NMVpnPluginOld *plugin, + const char *banner); + + void (*failure) (NMVpnPluginOld *plugin, + NMVpnPluginFailure reason); + + void (*quit) (NMVpnPluginOld *plugin); + + void (*config) (NMVpnPluginOld *plugin, + GVariant *config); + + void (*ip6_config) (NMVpnPluginOld *plugin, + GVariant *config); + + /* virtual methods */ + gboolean (*connect) (NMVpnPluginOld *plugin, + NMConnection *connection, + GError **err); + + gboolean (*need_secrets) (NMVpnPluginOld *plugin, + NMConnection *connection, + char **setting_name, + GError **error); + + gboolean (*disconnect) (NMVpnPluginOld *plugin, + GError **err); + + gboolean (*new_secrets) (NMVpnPluginOld *plugin, + NMConnection *connection, + GError **error); + + gboolean (*connect_interactive) (NMVpnPluginOld *plugin, + NMConnection *connection, + GVariant *details, + GError **error); + + /*< private >*/ + gpointer padding[8]; +} NMVpnPluginOldClass; + +GType nm_vpn_plugin_old_get_type (void); + +GDBusConnection *nm_vpn_plugin_old_get_connection (NMVpnPluginOld *plugin); +NMVpnServiceState nm_vpn_plugin_old_get_state (NMVpnPluginOld *plugin); +void nm_vpn_plugin_old_set_state (NMVpnPluginOld *plugin, + NMVpnServiceState state); + +void nm_vpn_plugin_old_secrets_required (NMVpnPluginOld *plugin, + const char *message, + const char **hints); + +void nm_vpn_plugin_old_set_login_banner (NMVpnPluginOld *plugin, + const char *banner); + +void nm_vpn_plugin_old_failure (NMVpnPluginOld *plugin, + NMVpnPluginFailure reason); + +void nm_vpn_plugin_old_set_config (NMVpnPluginOld *plugin, + GVariant *config); + +void nm_vpn_plugin_old_set_ip4_config (NMVpnPluginOld *plugin, + GVariant *ip4_config); + +void nm_vpn_plugin_old_set_ip6_config (NMVpnPluginOld *plugin, + GVariant *ip6_config); + +gboolean nm_vpn_plugin_old_disconnect (NMVpnPluginOld *plugin, + GError **err); + +/* Utility functions */ + +gboolean nm_vpn_plugin_old_read_vpn_details (int fd, + GHashTable **out_data, + GHashTable **out_secrets); + +gboolean nm_vpn_plugin_old_get_secret_flags (GHashTable *data, + const char *secret_name, + NMSettingSecretFlags *out_flags); + +G_END_DECLS + +#endif /* __NM_VPN_PLUGIN_OLD_H__ */ diff --git a/libnm/nm-vpn-plugin-utils.c b/libnm/nm-vpn-plugin-utils.c deleted file mode 100644 index 6ff2f57cac..0000000000 --- a/libnm/nm-vpn-plugin-utils.c +++ /dev/null @@ -1,188 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 Red Hat, Inc. - */ - -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> - -#include "nm-vpn-plugin-utils.h" -#include "nm-vpn-plugin.h" -#include "nm-core-internal.h" - -#define DATA_KEY_TAG "DATA_KEY=" -#define DATA_VAL_TAG "DATA_VAL=" -#define SECRET_KEY_TAG "SECRET_KEY=" -#define SECRET_VAL_TAG "SECRET_VAL=" - -static void -free_secret (gpointer data) -{ - char *secret = data; - - memset (secret, 0, strlen (secret)); - g_free (secret); -} - -/** - * nm_vpn_plugin_utils_read_vpn_details: - * @fd: file descriptor to read from, usually stdin (0) - * @out_data: (out) (transfer full): on successful return, a hash table - * (mapping char*:char*) containing the key/value pairs of VPN data items - * @out_secrets: (out) (transfer full): on successful return, a hash table - * (mapping char*:char*) containing the key/value pairsof VPN secrets - * - * Parses key/value pairs from a file descriptor (normally stdin) passed by - * an applet when the applet calls the authentication dialog of the VPN plugin. - * - * Returns: %TRUE if reading values was successful, %FALSE if not - **/ -gboolean -nm_vpn_plugin_utils_read_vpn_details (int fd, - GHashTable **out_data, - GHashTable **out_secrets) -{ - GHashTable *data, *secrets; - gboolean success = FALSE; - char *key = NULL, *val = NULL; - GString *line; - gchar c; - - if (out_data) - g_return_val_if_fail (*out_data == NULL, FALSE); - if (out_secrets) - g_return_val_if_fail (*out_secrets == NULL, FALSE); - - data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_secret); - - line = g_string_new (NULL); - - /* Read stdin for data and secret items until we get a DONE */ - while (1) { - ssize_t nr; - GHashTable *hash = NULL; - - errno = 0; - nr = read (fd, &c, 1); - if (nr == -1) { - if (errno == EAGAIN) { - g_usleep (100); - continue; - } - break; - } - - if (c != '\n') { - g_string_append_c (line, c); - continue; - } - - /* Check for the finish marker */ - if (strcmp (line->str, "DONE") == 0) - break; - - /* Otherwise it's a data/secret item */ - if (strncmp (line->str, DATA_KEY_TAG, strlen (DATA_KEY_TAG)) == 0) { - hash = data; - key = g_strdup (line->str + strlen (DATA_KEY_TAG)); - } else if (strncmp (line->str, DATA_VAL_TAG, strlen (DATA_VAL_TAG)) == 0) { - hash = data; - val = g_strdup (line->str + strlen (DATA_VAL_TAG)); - } else if (strncmp (line->str, SECRET_KEY_TAG, strlen (SECRET_KEY_TAG)) == 0) { - hash = secrets; - key = g_strdup (line->str + strlen (SECRET_KEY_TAG)); - } else if (strncmp (line->str, SECRET_VAL_TAG, strlen (SECRET_VAL_TAG)) == 0) { - hash = secrets; - val = g_strdup (line->str + strlen (SECRET_VAL_TAG)); - } - g_string_truncate (line, 0); - - if (key && val && hash) { - g_hash_table_insert (hash, key, val); - key = NULL; - val = NULL; - success = TRUE; /* Got at least one value */ - } - } - - if (success) { - if (out_data) - *out_data = data; - else - g_hash_table_destroy (data); - - if (out_secrets) - *out_secrets = secrets; - else - g_hash_table_destroy (secrets); - } else { - g_hash_table_destroy (data); - g_hash_table_destroy (secrets); - } - - g_string_free (line, TRUE); - return success; -} - -/** - * nm_vpn_plugin_utils_get_secret_flags: - * @data: hash table containing VPN key/value pair data items - * @secret_name: VPN secret key name for which to retrieve flags for - * @out_flags: (out): on success, the flags associated with @secret_name - * - * Given a VPN secret key name, attempts to find the corresponding flags data - * item in @data. If found, converts the flags data item to - * #NMSettingSecretFlags and returns it. - * - * Returns: %TRUE if the flag data item was found and successfully converted - * to flags, %FALSE if not - **/ -gboolean -nm_vpn_plugin_utils_get_secret_flags (GHashTable *data, - const char *secret_name, - NMSettingSecretFlags *out_flags) -{ - char *flag_name; - const char *val; - unsigned long tmp; - gboolean success = FALSE; - - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (secret_name != NULL, FALSE); - g_return_val_if_fail (out_flags != NULL, FALSE); - g_return_val_if_fail (*out_flags == NM_SETTING_SECRET_FLAG_NONE, FALSE); - - flag_name = g_strdup_printf ("%s-flags", secret_name); - - /* Try new flags value first */ - val = g_hash_table_lookup (data, flag_name); - if (val) { - errno = 0; - tmp = strtoul (val, NULL, 10); - if (errno == 0 && tmp <= NM_SETTING_SECRET_FLAGS_ALL) { - *out_flags = (NMSettingSecretFlags) tmp; - success = TRUE; - } - } - - g_free (flag_name); - return success; -} diff --git a/libnm/nm-vpn-plugin-utils.h b/libnm/nm-vpn-plugin-utils.h deleted file mode 100644 index 5073d1ee0b..0000000000 --- a/libnm/nm-vpn-plugin-utils.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2011 Red Hat, Inc. - */ - -#ifndef __NM_VPN_PLUGIN_UTILS_H__ -#define __NM_VPN_PLUGIN_UTILS_H__ - -#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) -#error "Only <NetworkManager.h> can be included directly." -#endif - -#include <glib.h> -#include <nm-setting.h> - -G_BEGIN_DECLS - -gboolean nm_vpn_plugin_utils_read_vpn_details (int fd, - GHashTable **out_data, - GHashTable **out_secrets); - -gboolean nm_vpn_plugin_utils_get_secret_flags (GHashTable *data, - const char *secret_name, - NMSettingSecretFlags *out_flags); - -G_END_DECLS - -#endif /* __NM_VPN_PLUGIN_UTILS_H__ */ diff --git a/libnm/nm-vpn-plugin.h b/libnm/nm-vpn-plugin.h deleted file mode 100644 index 02245d9a44..0000000000 --- a/libnm/nm-vpn-plugin.h +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Novell, Inc. - * Copyright 2007 - 2013 Red Hat, Inc. - */ - -#ifndef __NM_VPN_PLUGIN_H__ -#define __NM_VPN_PLUGIN_H__ - -#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) -#error "Only <NetworkManager.h> can be included directly." -#endif - -#include <gio/gio.h> -#include <nm-vpn-dbus-interface.h> -#include <nm-connection.h> - -G_BEGIN_DECLS - -#define NM_TYPE_VPN_PLUGIN (nm_vpn_plugin_get_type ()) -#define NM_VPN_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_PLUGIN, NMVpnPlugin)) -#define NM_VPN_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_VPN_PLUGIN, NMVpnPluginClass)) -#define NM_IS_VPN_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_PLUGIN)) -#define NM_IS_VPN_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_VPN_PLUGIN)) -#define NM_VPN_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_VPN_PLUGIN, NMVpnPluginClass)) - -#define NM_VPN_PLUGIN_DBUS_SERVICE_NAME "service-name" -#define NM_VPN_PLUGIN_STATE "state" - -typedef struct { - GObject parent; -} NMVpnPlugin; - -typedef struct { - GObjectClass parent; - - /* Signals */ - void (*state_changed) (NMVpnPlugin *plugin, - NMVpnServiceState state); - - void (*ip4_config) (NMVpnPlugin *plugin, - GVariant *ip4_config); - - void (*login_banner) (NMVpnPlugin *plugin, - const char *banner); - - void (*failure) (NMVpnPlugin *plugin, - NMVpnPluginFailure reason); - - void (*quit) (NMVpnPlugin *plugin); - - void (*config) (NMVpnPlugin *plugin, - GVariant *config); - - void (*ip6_config) (NMVpnPlugin *plugin, - GVariant *config); - - /* virtual methods */ - gboolean (*connect) (NMVpnPlugin *plugin, - NMConnection *connection, - GError **err); - - gboolean (*need_secrets) (NMVpnPlugin *plugin, - NMConnection *connection, - char **setting_name, - GError **error); - - gboolean (*disconnect) (NMVpnPlugin *plugin, - GError **err); - - gboolean (*new_secrets) (NMVpnPlugin *plugin, - NMConnection *connection, - GError **error); - - gboolean (*connect_interactive) (NMVpnPlugin *plugin, - NMConnection *connection, - GVariant *details, - GError **error); - - /*< private >*/ - gpointer padding[8]; -} NMVpnPluginClass; - -GType nm_vpn_plugin_get_type (void); - -GDBusConnection *nm_vpn_plugin_get_connection (NMVpnPlugin *plugin); -NMVpnServiceState nm_vpn_plugin_get_state (NMVpnPlugin *plugin); -void nm_vpn_plugin_set_state (NMVpnPlugin *plugin, - NMVpnServiceState state); - -void nm_vpn_plugin_secrets_required (NMVpnPlugin *plugin, - const char *message, - const char **hints); - -void nm_vpn_plugin_set_login_banner (NMVpnPlugin *plugin, - const char *banner); - -void nm_vpn_plugin_failure (NMVpnPlugin *plugin, - NMVpnPluginFailure reason); - -void nm_vpn_plugin_set_config (NMVpnPlugin *plugin, - GVariant *config); - -void nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GVariant *ip4_config); - -void nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GVariant *ip6_config); - -gboolean nm_vpn_plugin_disconnect (NMVpnPlugin *plugin, - GError **err); - -G_END_DECLS - -#endif /* __NM_VPN_PLUGIN_H__ */ |