[network-manager-pptp/lr/libnm: 6/15] fixup! all: port pptp plugin to libnm



commit 15a0fc90ecbcec99e9cb4af64dee11bc0586d989
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Jul 17 14:49:41 2015 +0200

    fixup! all: port pptp plugin to libnm
    
    Subject: properties: port pptp plugin to libnm
    
    Revert service and auth-dialog parts, let's just port the properties dialog
    first. We'll still need libnm-glib anyway for the compat properties plugin
    and the port uses the VpnPluginOld API which is deprecated now.

 auth-dialog/main.c        |    7 +-
 src/nm-pptp-pppd-plugin.c |    2 +-
 src/nm-pptp-service.c     |  141 +++++++++++++++++++++++----------------------
 src/nm-pptp-service.h     |    7 +-
 4 files changed, 81 insertions(+), 76 deletions(-)
---
diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index 3249192..ba9a547 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -34,8 +34,9 @@
 #define SECRET_API_SUBJECT_TO_CHANGE
 #include <libsecret/secret.h>
 
+#include <nm-setting-vpn.h>
+#include <nm-vpn-plugin-utils.h>
 #include <nm-vpn-password-dialog.h>
-#include <NetworkManager.h>
 
 #include "src/nm-pptp-service.h"
 
@@ -270,13 +271,13 @@ main (int argc, char *argv[])
                return 1;
        }
 
-       if (!nm_vpn_plugin_old_read_vpn_details (0, &data, &secrets)) {
+       if (!nm_vpn_plugin_utils_read_vpn_details (0, &data, &secrets)) {
                fprintf (stderr, "Failed to read '%s' (%s) data and secrets from stdin.\n",
                         vpn_name, vpn_uuid);
                return 1;
        }
 
-       nm_vpn_plugin_old_get_secret_flags (secrets, NM_PPTP_KEY_PASSWORD, &pw_flags);
+       nm_vpn_plugin_utils_get_secret_flags (secrets, NM_PPTP_KEY_PASSWORD, &pw_flags);
 
        if (!get_secrets (vpn_uuid, vpn_name, retry, allow_interaction, external_ui_mode,
                          g_hash_table_lookup (secrets, NM_PPTP_KEY_PASSWORD),
diff --git a/src/nm-pptp-pppd-plugin.c b/src/nm-pptp-pppd-plugin.c
index ebf2b0b..302274a 100644
--- a/src/nm-pptp-pppd-plugin.c
+++ b/src/nm-pptp-pppd-plugin.c
@@ -34,7 +34,7 @@
 #include "nm-pptp-service.h"
 #include "nm-ppp-status.h"
 
-#include <NetworkManager.h>
+#include <nm-utils.h>
 
 int plugin_init (void);
 
diff --git a/src/nm-pptp-service.c b/src/nm-pptp-service.c
index a31c5f5..9a1da0e 100644
--- a/src/nm-pptp-service.c
+++ b/src/nm-pptp-service.c
@@ -47,7 +47,8 @@
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 
-#include <NetworkManager.h>
+#include <nm-setting-vpn.h>
+#include <nm-utils.h>
 
 #include "nm-pptp-service.h"
 #include "nm-ppp-status.h"
@@ -226,7 +227,7 @@ _service_cache_credentials (NMPptpPppService *self,
                             GError **error)
 {
        NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (self);
-       NMSettingVpn *s_vpn;
+       NMSettingVPN *s_vpn;
        const char *username, *password, *domain;
 
        g_return_val_if_fail (self != NULL, FALSE);
@@ -236,7 +237,7 @@ _service_cache_credentials (NMPptpPppService *self,
        if (!s_vpn) {
                g_set_error_literal (error,
                                     NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
+                                    NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
                                     _("Could not find secrets (connection invalid, no vpn setting)."));
                return FALSE;
        }
@@ -248,7 +249,7 @@ _service_cache_credentials (NMPptpPppService *self,
                if (!username || !*username) {
                        g_set_error_literal (error,
                                             NM_VPN_PLUGIN_ERROR,
-                                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
+                                            NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
                                             _("Missing or invalid VPN username."));
                        return FALSE;
                }
@@ -258,7 +259,7 @@ _service_cache_credentials (NMPptpPppService *self,
        if (!password || !strlen (password)) {
                g_set_error_literal (error,
                                     NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
+                                    NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
                                     _("Missing or invalid VPN password."));
                return FALSE;
        }
@@ -415,7 +416,7 @@ impl_pptp_service_need_secrets (NMPptpPppService *self,
        if (!strlen (priv->username) || !strlen (priv->password)) {
                g_set_error (error,
                             NM_VPN_PLUGIN_ERROR,
-                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
+                            NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
                             "%s",
                             _("No cached credentials."));
                goto error;
@@ -462,7 +463,7 @@ impl_pptp_service_set_ip4_config (NMPptpPppService *self,
 /* The VPN plugin service                               */
 /********************************************************/
 
-G_DEFINE_TYPE (NMPptpPlugin, nm_pptp_plugin, NM_TYPE_VPN_PLUGIN_OLD)
+G_DEFINE_TYPE (NMPptpPlugin, nm_pptp_plugin, NM_TYPE_VPN_PLUGIN)
 
 typedef struct {
        GPid pid;
@@ -612,7 +613,7 @@ validate_one_property (const char *key, const char *value, gpointer user_data)
 }
 
 static gboolean
-nm_pptp_properties_validate (NMSettingVpn *s_vpn,
+nm_pptp_properties_validate (NMSettingVPN *s_vpn,
                              GError **error)
 {
        ValidateInfo info = { &valid_properties[0], error, FALSE };
@@ -654,7 +655,7 @@ nm_pptp_properties_validate (NMSettingVpn *s_vpn,
 }
 
 static gboolean
-nm_pptp_secrets_validate (NMSettingVpn *s_vpn, GError **error)
+nm_pptp_secrets_validate (NMSettingVPN *s_vpn, GError **error)
 {
        ValidateInfo info = { &valid_secrets[0], error, FALSE };
 
@@ -699,21 +700,21 @@ pppd_watch_cb (GPid pid, gint status, gpointer user_data)
        case 16:
                /* hangup */
                // FIXME: better failure reason
-               nm_vpn_plugin_old_failure (NM_VPN_PLUGIN_OLD (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+               nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
                break;
        case 2:
                /* Couldn't log in due to bad user/pass */
-               nm_vpn_plugin_old_failure (NM_VPN_PLUGIN_OLD (plugin), NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED);
+               nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED);
                break;
        case 1:
                /* Other error (couldn't bind to address, etc) */
-               nm_vpn_plugin_old_failure (NM_VPN_PLUGIN_OLD (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+               nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
                break;
        default:
                break;
        }
 
-       nm_vpn_plugin_old_set_state (NM_VPN_PLUGIN_OLD (plugin), NM_VPN_SERVICE_STATE_STOPPED);
+       nm_vpn_plugin_set_state (NM_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED);
 }
 
 static inline const char *
@@ -766,7 +767,7 @@ pppd_timed_out (gpointer user_data)
        NMPptpPlugin *plugin = NM_PPTP_PLUGIN (user_data);
 
        g_warning ("Looks like pppd didn't initialize our dbus module");
-       nm_vpn_plugin_old_failure (NM_VPN_PLUGIN_OLD (plugin), 
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT);
+       nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT);
 
        return FALSE;
 }
@@ -803,7 +804,7 @@ str_to_int (const char *str, long int *out)
 
 static GPtrArray *
 construct_pppd_args (NMPptpPlugin *plugin,
-                     NMSettingVpn *s_vpn,
+                     NMSettingVPN *s_vpn,
                      const char *pppd,
                      const char *gwaddr,
                      GError **error)
@@ -833,7 +834,7 @@ construct_pppd_args (NMPptpPlugin *plugin,
        if (!gwaddr || !strlen (gwaddr)) {
                g_set_error (error,
                             NM_VPN_PLUGIN_ERROR,
-                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
+                            NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
                             "%s",
                             _("Missing VPN gateway."));
                goto error;
@@ -981,7 +982,7 @@ error:
 
 static gboolean
 nm_pptp_start_pppd_binary (NMPptpPlugin *plugin,
-                           NMSettingVpn *s_vpn,
+                           NMSettingVPN *s_vpn,
                            const char *gwaddr,
                            GError **error)
 {
@@ -1044,15 +1045,15 @@ service_ppp_state_cb (NMPptpPppService *service,
                       guint32 ppp_state,
                       NMPptpPlugin *plugin)
 {
-       NMVpnServiceState plugin_state = nm_vpn_plugin_old_get_state (NM_VPN_PLUGIN_OLD (plugin));
+       NMVPNServiceState plugin_state = nm_vpn_plugin_get_state (NM_VPN_PLUGIN (plugin));
 
        switch (ppp_state) {
        case NM_PPP_STATUS_DEAD:
        case NM_PPP_STATUS_DISCONNECT:
                if (plugin_state == NM_VPN_SERVICE_STATE_STARTED)
-                       nm_vpn_plugin_old_disconnect (NM_VPN_PLUGIN_OLD (plugin), NULL);
+                       nm_vpn_plugin_disconnect (NM_VPN_PLUGIN (plugin), NULL);
                else if (plugin_state == NM_VPN_SERVICE_STATE_STARTING)
-                       nm_vpn_plugin_old_failure (NM_VPN_PLUGIN_OLD (plugin), 
NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+                       nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
                break;
        default:
                break;
@@ -1060,53 +1061,62 @@ service_ppp_state_cb (NMPptpPppService *service,
 }
 
 static void
+nm_gvalue_destroy (gpointer data)
+{
+       g_value_unset ((GValue *) data);
+       g_slice_free (GValue, data);
+}
+
+static GValue *
+nm_gvalue_dup (const GValue *value)
+{
+       GValue *value_dup;
+
+       value_dup = g_slice_new0 (GValue);
+       g_value_init (value_dup, G_VALUE_TYPE (value));
+       g_value_copy (value, value_dup);
+
+       return value_dup;
+}
+
+static void
+copy_hash (gpointer key, gpointer value, gpointer user_data)
+{
+       g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), nm_gvalue_dup ((GValue *) value));
+}
+
+static void
 service_ip4_config_cb (NMPptpPppService *service,
                        GHashTable *config_hash,
-                       NMVpnPluginOld *plugin)
+                       NMVPNPlugin *plugin)
 {
        NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (service);
-       GHashTableIter iter;
-       char *key;
+       GHashTable *hash;
        GValue *value;
-       GVariantBuilder builder;
-       GVariant *new_config;
-       GVariant *tmp;
-
-        g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
-       g_hash_table_iter_init (&iter, config_hash);
-       while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
-               if (G_VALUE_HOLDS_STRING (value))
-                       tmp = g_variant_new_string (g_value_get_string (value));
-               else if (G_VALUE_HOLDS_UINT (value))
-                       tmp = g_variant_new_uint32 (g_value_get_uint (value));
-               else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)) {
-                       GArray *arr = g_value_get_boxed (value);
-                       tmp = g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, arr->data, arr->len, sizeof 
(guint32));
-               } else
-                       tmp = NULL;
 
-               if (tmp)
-                       g_variant_builder_add (&builder, "{sv}", key, tmp);
-       }
+       hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
+       g_hash_table_foreach (config_hash, copy_hash, hash);
 
        /* Insert the external VPN gateway into the table, which the pppd plugin
         * simply doesn't know about.
         */
-       g_variant_builder_add (&builder, "{sv}", NM_PPTP_KEY_GATEWAY, g_variant_new_uint32 (priv->naddr));
-       new_config = g_variant_builder_end (&builder);
-       g_variant_ref_sink (new_config);
+       value = g_slice_new0 (GValue);
+       g_value_init (value, G_TYPE_UINT);
+       g_value_set_uint (value, priv->naddr);
+       g_hash_table_insert (hash, g_strdup (NM_PPTP_KEY_GATEWAY), value);
 
-       nm_vpn_plugin_old_set_ip4_config (plugin, new_config);
-       g_variant_unref (new_config);
+       nm_vpn_plugin_set_ip4_config (plugin, hash);
+
+       g_hash_table_destroy (hash);
 }
 
 static gboolean
-real_connect (NMVpnPluginOld *plugin,
-              NMConnection *connection,
-              GError **error)
+real_connect (NMVPNPlugin   *plugin,
+              NMConnection  *connection,
+              GError       **error)
 {
        NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin);
-       NMSettingVpn *s_vpn;
+       NMSettingVPN *s_vpn;
        const char *gwaddr;
 
        s_vpn = nm_connection_get_setting_vpn (connection);
@@ -1152,15 +1162,15 @@ real_connect (NMVpnPluginOld *plugin,
 }
 
 static gboolean
-real_need_secrets (NMVpnPluginOld *plugin,
+real_need_secrets (NMVPNPlugin *plugin,
                    NMConnection *connection,
-                   const char **setting_name,
+                   char **setting_name,
                    GError **error)
 {
-       NMSettingVpn *s_vpn;
+       NMSettingVPN *s_vpn;
        NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
 
-       g_return_val_if_fail (NM_IS_VPN_PLUGIN_OLD (plugin), FALSE);
+       g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE);
        g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
 
        s_vpn = nm_connection_get_setting_vpn (connection);
@@ -1192,7 +1202,8 @@ ensure_killed (gpointer data)
 }
 
 static gboolean
-real_disconnect (NMVpnPluginOld *plugin, GError **err)
+real_disconnect (NMVPNPlugin   *plugin,
+                         GError       **err)
 {
        NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin);
 
@@ -1213,7 +1224,7 @@ real_disconnect (NMVpnPluginOld *plugin, GError **err)
 }
 
 static void
-state_changed_cb (GObject *object, NMVpnServiceState state, gpointer user_data)
+state_changed_cb (GObject *object, NMVPNServiceState state, gpointer user_data)
 {
        NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (object);
 
@@ -1255,7 +1266,7 @@ static void
 nm_pptp_plugin_class_init (NMPptpPluginClass *pptp_class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (pptp_class);
-       NMVpnPluginOldClass *parent_class = NM_VPN_PLUGIN_OLD_CLASS (pptp_class);
+       NMVPNPluginClass *parent_class = NM_VPN_PLUGIN_CLASS (pptp_class);
 
        g_type_class_add_private (object_class, sizeof (NMPptpPluginPrivate));
 
@@ -1270,19 +1281,13 @@ NMPptpPlugin *
 nm_pptp_plugin_new (void)
 {
        NMPptpPlugin *plugin;
-       GError *error = NULL;
 
-       plugin = g_initable_new (NM_TYPE_PPTP_PLUGIN, NULL, &error,
-                                NM_VPN_PLUGIN_OLD_DBUS_SERVICE_NAME,
-                                NM_DBUS_SERVICE_PPTP,
-                                NULL);
+       plugin = g_object_new (NM_TYPE_PPTP_PLUGIN,
+                              NM_VPN_PLUGIN_DBUS_SERVICE_NAME,
+                              NM_DBUS_SERVICE_PPTP,
+                              NULL);
        if (plugin)
                g_signal_connect (G_OBJECT (plugin), "state-changed", G_CALLBACK (state_changed_cb), NULL);
-
-       if (debug && error)
-               g_message ("Error: failed to create NMPptpPlugin: %s", error->message);
-       g_clear_error (&error);
-
        return plugin;
 }
 
diff --git a/src/nm-pptp-service.h b/src/nm-pptp-service.h
index 7872527..135cf4e 100644
--- a/src/nm-pptp-service.h
+++ b/src/nm-pptp-service.h
@@ -25,8 +25,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <NetworkManager.h>
-#include <nm-vpn-plugin-old.h>
+#include <nm-vpn-plugin.h>
 
 #include "nm-pptp-service-defines.h"
 
@@ -41,11 +40,11 @@
 #define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
 
 typedef struct {
-       NMVpnPluginOld parent;
+       NMVPNPlugin parent;
 } NMPptpPlugin;
 
 typedef struct {
-       NMVpnPluginOldClass parent;
+       NMVPNPluginClass parent;
 } NMPptpPluginClass;
 
 GType nm_pptp_plugin_get_type (void);


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