[network-manager-pptp/lr/libnm: 5/8] all: port pptp plugin to libnm



commit c4496852fb17449aa77c207e364688e3d538432e
Author: Jiří Klimeš <jklimes redhat com>
Date:   Fri Mar 6 13:35:37 2015 +0100

    all: port pptp plugin to libnm
    
    [lkundrak v3 sk: libnm and libnm-gtk can't mix; use libnma instead.]
    
    [lkundrak v3 sk: retain also the libnm-glib version of the properties plugin
    
    [lkundrak v3 sk: avoid NMVpnPluginOld use.]

 auth-dialog/Makefile.am      |    8 +-
 auth-dialog/main.c           |    9 +--
 configure.ac                 |   17 +++--
 properties/Makefile.am       |   14 +++--
 properties/advanced-dialog.c |   10 +++-
 properties/import-export.c   |    6 +-
 properties/nm-pptp.c         |  109 +++++++++++++++++++--------------
 src/Makefile.am              |    8 +-
 src/nm-pptp-pppd-plugin.c    |    2 +-
 src/nm-pptp-service.c        |  141 ++++++++++++++++++++----------------------
 src/nm-pptp-service.h        |    7 +-
 11 files changed, 176 insertions(+), 155 deletions(-)
---
diff --git a/auth-dialog/Makefile.am b/auth-dialog/Makefile.am
index b1202a9..cc6b817 100644
--- a/auth-dialog/Makefile.am
+++ b/auth-dialog/Makefile.am
@@ -1,10 +1,10 @@
 libexec_PROGRAMS = nm-pptp-auth-dialog
 
 nm_pptp_auth_dialog_CPPFLAGS =                 \
-       $(NM_CFLAGS)            \
+       $(LIBNM_CFLAGS)                         \
        $(GLIB_CFLAGS)                          \
        $(GTK_CFLAGS)                           \
-       $(NMGTK_CFLAGS)                         \
+       $(LIBNMA_CFLAGS)                        \
        $(LIBSECRET_CFLAGS)                     \
        -I${top_srcdir}                         \
        -DICONDIR=\""$(datadir)/pixmaps"\"      \
@@ -17,9 +17,9 @@ nm_pptp_auth_dialog_SOURCES = \
        main.c
 
 nm_pptp_auth_dialog_LDADD = \
-       $(NM_LIBS) \
+       $(LIBNM_LIBS) \
        $(GTK_LIBS) \
-       $(NMGTK_LIBS) \
+       $(LIBNMA_LIBS) \
        $(LIBSECRET_LIBS)
 
 CLEANFILES = *~
diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index ba9a547..a1a4e1a 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -34,9 +34,8 @@
 #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 <nma-vpn-password-dialog.h>
 
 #include "src/nm-pptp-service.h"
 
@@ -271,13 +270,13 @@ main (int argc, char *argv[])
                return 1;
        }
 
-       if (!nm_vpn_plugin_utils_read_vpn_details (0, &data, &secrets)) {
+       if (!nm_vpn_service_plugin_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_utils_get_secret_flags (secrets, NM_PPTP_KEY_PASSWORD, &pw_flags);
+       nm_vpn_service_plugin_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/configure.ac b/configure.ac
index 02ea530..b0f24b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -66,21 +66,24 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
 
 PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= 0.74)
 
-PKG_CHECK_MODULES(NM,
-                  NetworkManager >= 0.9.10
-                  libnm-util >= 0.9.10
-                  libnm-glib >= 0.9.10
-                  libnm-glib-vpn >= 0.9.10)
+PKG_CHECK_MODULES(LIBNM_GLIB,
+                  NetworkManager >= 1.1.0
+                  libnm-glib >= 1.1.0
+                  libnm-glib-vpn >= 1.1.0)
 
 if test x"$with_gnome" != xno; then
        PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.4)
        GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4"
 
-       PKG_CHECK_MODULES(NMGTK, libnm-gtk >= 0.9.10)
-
+       PKG_CHECK_MODULES(LIBNM_GTK, libnm-gtk >= 0.9.10)
+       PKG_CHECK_MODULES(LIBNMA, libnma >= 1.1.0)
        PKG_CHECK_MODULES(LIBSECRET, libsecret-unstable)
 fi
 
+PKG_CHECK_MODULES(LIBNM, libnm >= 1.1.0)
+LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MIN_REQUIRED=NM_VERSION_1_2"
+LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MAX_ALLOWED=NM_VERSION_1_2"
+
 NM_COMPILER_WARNINGS
 
 dnl
diff --git a/properties/Makefile.am b/properties/Makefile.am
index 33f050d..fe6398e 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -20,8 +20,6 @@ ui_DATA = nm-pptp-dialog.ui
 common_CFLAGS =                                         \
         $(GLIB_CFLAGS)                                  \
         $(GTK_CFLAGS)                                   \
-        $(NM_CFLAGS)                                    \
-        $(NMGTK_CFLAGS)                                 \
         -I$(top_srcdir)/src                             \
         -DICONDIR=\""$(datadir)/pixmaps"\"              \
         -DUIDIR=\""$(uidir)"\"                          \
@@ -30,16 +28,20 @@ common_CFLAGS =                                         \
         -DVERSION=\"$(VERSION)\"
 
 libnm_vpn_plugin_pptp_la_CFLAGS =                       \
-        $(common_CFLAGS)
+        $(common_CFLAGS)                                \
+        $(LIBNMA_CFLAGS)                                \
+        $(LIBNM_CFLAGS)
 
 libnm_pptp_properties_la_CFLAGS =                       \
         -DNM_PPTP_OLD                                   \
-        $(common_CFLAGS)
+        $(common_CFLAGS)                                \
+        $(LIBNM_GLIB_CFLAGS)                            \
+        $(LIBNM_GTK_CFLAGS)
 
 libnm_vpn_plugin_pptp_la_LIBADD =                       \
         $(GTK_LIBS)                                     \
-        $(NM_LIBS)                                      \
-        $(NMGTK_LIBS)
+        $(LIBNMA_LIBS)                                  \
+        $(LIBNM_LIBS)
 
 libnm_pptp_properties_la_LIBADD =                       \
         $(GTK_LIBS)                                     \
diff --git a/properties/advanced-dialog.c b/properties/advanced-dialog.c
index 54c4325..f0a4ddb 100644
--- a/properties/advanced-dialog.c
+++ b/properties/advanced-dialog.c
@@ -35,12 +35,18 @@
 #include <glib.h>
 #include <glib/gi18n-lib.h>
 
+#ifdef NM_PPTP_OLD
+#define NM_VPN_LIBNM_COMPAT
 #include <nm-connection.h>
 #include <nm-setting-vpn.h>
 
+#else /* !NM_PPTP_OLD */
+#include <NetworkManager.h>
+#endif
+
 #include "advanced-dialog.h"
 #include "nm-pptp.h"
-#include "../src/nm-pptp-service.h"
+#include "../src/nm-pptp-service-defines.h"
 
 #define COL_NAME  0
 #define COL_VALUE 1
@@ -90,7 +96,7 @@ advanced_dialog_new_hash_from_connection (NMConnection *connection,
                                           GError **error)
 {
        GHashTable *hash;
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
 
        hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
diff --git a/properties/import-export.c b/properties/import-export.c
index 356a6de..5ef040c 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -34,13 +34,11 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <nm-setting-vpn.h>
-#include <nm-setting-connection.h>
-#include <nm-setting-ip4-config.h>
+#include <NetworkManager.h>
 
 #include "import-export.h"
 #include "nm-pptp.h"
-#include "../src/nm-pptp-service.h"
+#include "../src/nm-pptp-service-defines.h"
 
 NMConnection *
 do_import (const char *path, char **lines, GError **error)
diff --git a/properties/nm-pptp.c b/properties/nm-pptp.c
index 43f958b..c687c4f 100644
--- a/properties/nm-pptp.c
+++ b/properties/nm-pptp.c
@@ -34,37 +34,47 @@
 #include <string.h>
 #include <gtk/gtk.h>
 
+#ifdef NM_PPTP_OLD
+#define NM_VPN_LIBNM_COMPAT
 #include <nm-vpn-plugin-ui-interface.h>
 #include <nm-setting-vpn.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-ip4-config.h>
 #include <nm-ui-utils.h>
 
+#define PPTP_PLUGIN_NAME    _("Point-to-Point Tunneling Protocol (PPTP)")
+#define PPTP_PLUGIN_DESC    _("Compatible with Microsoft and other PPTP VPN servers.")
+
+#else /* !NM_PPTP_OLD */
+
+#include <NetworkManager.h>
+#include <nma-ui-utils.h>
+
+#define PPTP_PLUGIN_NAME    _("pptp")
+#define PPTP_PLUGIN_DESC    _("Point-to-Point Tunneling Protocol (PPTP)")
+#endif
+
 #include "nm-pptp-service-defines.h"
 #include "nm-pptp.h"
 #include "import-export.h"
 #include "advanced-dialog.h"
 
-#define PPTP_PLUGIN_NAME    _("Point-to-Point Tunneling Protocol (PPTP)")
-#define PPTP_PLUGIN_DESC    _("Compatible with Microsoft and other PPTP VPN servers.")
-#define PPTP_PLUGIN_SERVICE NM_DBUS_SERVICE_PPTP
-
 typedef void (*ChangedCallback) (GtkWidget *widget, gpointer user_data);
 
 /************** plugin class **************/
 
-static void pptp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class);
+static void pptp_plugin_ui_interface_init (NMVpnEditorPluginInterface *iface_class);
 
 G_DEFINE_TYPE_EXTENDED (PptpPluginUi, pptp_plugin_ui, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_INTERFACE,
+                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
                                                pptp_plugin_ui_interface_init))
 
 /************** UI widget class **************/
 
-static void pptp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class);
+static void pptp_plugin_ui_widget_interface_init (NMVpnEditorInterface *iface_class);
 
 G_DEFINE_TYPE_EXTENDED (PptpPluginUiWidget, pptp_plugin_ui_widget, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE,
+                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR,
                                                pptp_plugin_ui_widget_interface_init))
 
 #define PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PPTP_TYPE_PLUGIN_UI_WIDGET, 
PptpPluginUiWidgetPrivate))
@@ -79,6 +89,14 @@ typedef struct {
        gboolean new_connection;
 } PptpPluginUiWidgetPrivate;
 
+enum {
+       PROP_0,
+       PROP_NAME,
+       PROP_DESC,
+       PROP_SERVICE,
+
+       LAST_PROP
+};
 
 GQuark
 pptp_plugin_ui_error_quark (void)
@@ -210,7 +228,7 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
 static void
 setup_password_widget (PptpPluginUiWidget *self,
                        const char *entry_name,
-                       NMSettingVPN *s_vpn,
+                       NMSettingVpn *s_vpn,
                        const char *secret_name,
                        gboolean new_connection)
 {
@@ -256,7 +274,7 @@ password_storage_changed_cb (GObject *entry,
 
 static void
 init_password_icon (PptpPluginUiWidget *self,
-                    NMSettingVPN *s_vpn,
+                    NMSettingVpn *s_vpn,
                     const char *secret_key,
                     const char *entry_name)
 {
@@ -292,7 +310,7 @@ static gboolean
 init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **error)
 {
        PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        GtkWidget *widget;
        const char *value;
 
@@ -360,7 +378,7 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
 }
 
 static GObject *
-get_widget (NMVpnPluginUiWidgetInterface *iface)
+get_widget (NMVpnEditor *iface)
 {
        PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (iface);
        PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
@@ -371,13 +389,13 @@ get_widget (NMVpnPluginUiWidgetInterface *iface)
 static void
 hash_copy_advanced (gpointer key, gpointer data, gpointer user_data)
 {
-       NMSettingVPN *s_vpn = NM_SETTING_VPN (user_data);
+       NMSettingVpn *s_vpn = NM_SETTING_VPN (user_data);
 
        nm_setting_vpn_add_data_item (s_vpn, (const char *) key, (const char *) data);
 }
 
 static void
-save_password_and_flags (NMSettingVPN *s_vpn,
+save_password_and_flags (NMSettingVpn *s_vpn,
                          GtkBuilder *builder,
                          const char *entry_name,
                          const char *secret_key)
@@ -407,13 +425,13 @@ save_password_and_flags (NMSettingVPN *s_vpn,
 }
 
 static gboolean
-update_connection (NMVpnPluginUiWidgetInterface *iface,
+update_connection (NMVpnEditor *iface,
                    NMConnection *connection,
                    GError **error)
 {
        PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (iface);
        PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        GtkWidget *widget;
        const char *str;
        gboolean valid = FALSE;
@@ -466,19 +484,19 @@ is_new_func (const char *key, const char *value, gpointer user_data)
        *is_new = FALSE;
 }
 
-static NMVpnPluginUiWidgetInterface *
+static NMVpnEditor *
 nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error)
 {
-       NMVpnPluginUiWidgetInterface *object;
+       NMVpnEditor *object;
        PptpPluginUiWidgetPrivate *priv;
        char *ui_file;
        gboolean new = TRUE;
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
 
        if (error)
                g_return_val_if_fail (*error == NULL, NULL);
 
-       object = NM_VPN_PLUGIN_UI_WIDGET_INTERFACE (g_object_new (PPTP_TYPE_PLUGIN_UI_WIDGET, NULL));
+       object = NM_VPN_EDITOR (g_object_new (PPTP_TYPE_PLUGIN_UI_WIDGET, NULL));
        if (!object) {
                g_set_error (error, PPTP_PLUGIN_UI_ERROR, 0, "could not create pptp object");
                return NULL;
@@ -578,7 +596,7 @@ pptp_plugin_ui_widget_init (PptpPluginUiWidget *plugin)
 }
 
 static void
-pptp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class)
+pptp_plugin_ui_widget_interface_init (NMVpnEditorInterface *iface_class)
 {
        /* interface implementation */
        iface_class->get_widget = get_widget;
@@ -586,7 +604,7 @@ pptp_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class)
 }
 
 static NMConnection *
-import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
+import (NMVpnEditorPlugin *iface, const char *path, GError **error)
 {
        NMConnection *connection = NULL;
        char *contents = NULL;
@@ -632,7 +650,7 @@ out:
 }
 
 static gboolean
-export (NMVpnPluginUiInterface *iface,
+export (NMVpnEditorPlugin *iface,
         const char *path,
         NMConnection *connection,
         GError **error)
@@ -641,7 +659,7 @@ export (NMVpnPluginUiInterface *iface,
 }
 
 static char *
-get_suggested_name (NMVpnPluginUiInterface *iface, NMConnection *connection)
+get_suggested_filename (NMVpnEditorPlugin *iface, NMConnection *connection)
 {
        NMSettingConnection *s_con;
        const char *id;
@@ -657,14 +675,14 @@ get_suggested_name (NMVpnPluginUiInterface *iface, NMConnection *connection)
        return g_strdup_printf ("%s (pptp).conf", id);
 }
 
-static guint32
-get_capabilities (NMVpnPluginUiInterface *iface)
+static NMVpnEditorPluginCapability
+get_capabilities (NMVpnEditorPlugin *iface)
 {
-       return (NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT | NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT);
+       return (NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT | NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT);
 }
 
-static NMVpnPluginUiWidgetInterface *
-ui_factory (NMVpnPluginUiInterface *iface, NMConnection *connection, GError **error)
+static NMVpnEditor *
+get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
 {
        return nm_vpn_plugin_ui_widget_interface_new (connection, error);
 }
@@ -674,14 +692,14 @@ get_property (GObject *object, guint prop_id,
                          GValue *value, GParamSpec *pspec)
 {
        switch (prop_id) {
-       case NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME:
+       case PROP_NAME:
                g_value_set_string (value, PPTP_PLUGIN_NAME);
                break;
-       case NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC:
+       case PROP_DESC:
                g_value_set_string (value, PPTP_PLUGIN_DESC);
                break;
-       case NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE:
-               g_value_set_string (value, PPTP_PLUGIN_SERVICE);
+       case PROP_SERVICE:
+               g_value_set_string (value, NM_DBUS_SERVICE_PPTP);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -697,16 +715,16 @@ pptp_plugin_ui_class_init (PptpPluginUiClass *req_class)
        object_class->get_property = get_property;
 
        g_object_class_override_property (object_class,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_NAME);
+                                         PROP_NAME,
+                                         NM_VPN_EDITOR_PLUGIN_NAME);
 
        g_object_class_override_property (object_class,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_DESC);
+                                         PROP_DESC,
+                                         NM_VPN_EDITOR_PLUGIN_DESCRIPTION);
 
        g_object_class_override_property (object_class,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_SERVICE);
+                                         PROP_SERVICE,
+                                         NM_VPN_EDITOR_PLUGIN_SERVICE);
 }
 
 static void
@@ -715,19 +733,18 @@ pptp_plugin_ui_init (PptpPluginUi *plugin)
 }
 
 static void
-pptp_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class)
+pptp_plugin_ui_interface_init (NMVpnEditorPluginInterface *iface_class)
 {
        /* interface implementation */
-       iface_class->ui_factory = ui_factory;
+       iface_class->get_editor = get_editor;
        iface_class->get_capabilities = get_capabilities;
        iface_class->import_from_file = import;
        iface_class->export_to_file = export;
-       iface_class->get_suggested_name = get_suggested_name;
+       iface_class->get_suggested_filename = get_suggested_filename;
 }
 
-
-G_MODULE_EXPORT NMVpnPluginUiInterface *
-nm_vpn_plugin_ui_factory (GError **error)
+G_MODULE_EXPORT NMVpnEditorPlugin *
+nm_vpn_editor_plugin_factory (GError **error)
 {
        if (error)
                g_return_val_if_fail (*error == NULL, NULL);
@@ -735,6 +752,6 @@ nm_vpn_plugin_ui_factory (GError **error)
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-       return NM_VPN_PLUGIN_UI_INTERFACE (g_object_new (PPTP_TYPE_PLUGIN_UI, NULL));
+       return NM_VPN_EDITOR_PLUGIN (g_object_new (PPTP_TYPE_PLUGIN_UI, NULL));
 }
 
diff --git a/src/Makefile.am b/src/Makefile.am
index d3a210a..d62259a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
 AM_CPPFLAGS =                                                  \
        $(DBUS_GLIB_CFLAGS)                                     \
        $(GLIB_CFLAGS)                                          \
-       $(NM_CFLAGS)                                            \
+       $(LIBNM_CFLAGS)                                         \
        -I${top_srcdir}                                         \
        -DG_DISABLE_DEPRECATED                                  \
        -DBINDIR=\"$(bindir)\"                                  \
@@ -28,7 +28,7 @@ nm-pptp-pppd-service-glue.h: $(top_srcdir)/src/nm-pptp-pppd-service.xml
 nm_pptp_service_LDADD = \
        $(DBUS_GLIB_LIBS) \
        $(GLIB_LIBS) \
-       $(NM_LIBS)
+       $(LIBNM_LIBS)
 
 pppd_plugindir = $(PPPD_PLUGIN_DIR)
 pppd_plugin_LTLIBRARIES = nm-pptp-pppd-plugin.la
@@ -40,14 +40,14 @@ nm_pptp_pppd_plugin_la_SOURCES = \
 nm_pptp_pppd_plugin_la_CPPFLAGS = \
        $(DBUS_GLIB_CFLAGS) \
        $(GLIB_CFLAGS) \
-       $(NM_CFLAGS)
+       $(LIBNM_CFLAGS)
 
 nm_pptp_pppd_plugin_la_LDFLAGS = -module -avoid-version
 
 nm_pptp_pppd_plugin_la_LIBADD = \
        $(DBUS_GLIB_LIBS) \
        $(GLIB_LIBS) \
-       $(NM_LIBS)
+       $(LIBNM_LIBS)
 
 BUILT_SOURCES = nm-pptp-pppd-service-glue.h
 
diff --git a/src/nm-pptp-pppd-plugin.c b/src/nm-pptp-pppd-plugin.c
index 302274a..ebf2b0b 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 <nm-utils.h>
+#include <NetworkManager.h>
 
 int plugin_init (void);
 
diff --git a/src/nm-pptp-service.c b/src/nm-pptp-service.c
index 9a1da0e..638f9be 100644
--- a/src/nm-pptp-service.c
+++ b/src/nm-pptp-service.c
@@ -47,8 +47,7 @@
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 
-#include <nm-setting-vpn.h>
-#include <nm-utils.h>
+#include <NetworkManager.h>
 
 #include "nm-pptp-service.h"
 #include "nm-ppp-status.h"
@@ -227,7 +226,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);
@@ -237,7 +236,7 @@ _service_cache_credentials (NMPptpPppService *self,
        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 find secrets (connection invalid, no vpn setting)."));
                return FALSE;
        }
@@ -249,7 +248,7 @@ _service_cache_credentials (NMPptpPppService *self,
                if (!username || !*username) {
                        g_set_error_literal (error,
                                             NM_VPN_PLUGIN_ERROR,
-                                            NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+                                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
                                             _("Missing or invalid VPN username."));
                        return FALSE;
                }
@@ -259,7 +258,7 @@ _service_cache_credentials (NMPptpPppService *self,
        if (!password || !strlen (password)) {
                g_set_error_literal (error,
                                     NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+                                    NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
                                     _("Missing or invalid VPN password."));
                return FALSE;
        }
@@ -416,7 +415,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_CONNECTION_INVALID,
+                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
                             "%s",
                             _("No cached credentials."));
                goto error;
@@ -463,7 +462,7 @@ impl_pptp_service_set_ip4_config (NMPptpPppService *self,
 /* The VPN plugin service                               */
 /********************************************************/
 
-G_DEFINE_TYPE (NMPptpPlugin, nm_pptp_plugin, NM_TYPE_VPN_PLUGIN)
+G_DEFINE_TYPE (NMPptpPlugin, nm_pptp_plugin, NM_TYPE_VPN_SERVICE_PLUGIN)
 
 typedef struct {
        GPid pid;
@@ -613,7 +612,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 };
@@ -655,7 +654,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 };
 
@@ -700,21 +699,21 @@ pppd_watch_cb (GPid pid, gint status, gpointer user_data)
        case 16:
                /* hangup */
                // FIXME: better failure reason
-               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;
        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 inline const char *
@@ -767,7 +766,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_failure (NM_VPN_PLUGIN (plugin), NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT);
+       nm_vpn_service_plugin_failure (NM_VPN_SERVICE_PLUGIN (plugin), 
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT);
 
        return FALSE;
 }
@@ -804,7 +803,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)
@@ -834,7 +833,7 @@ construct_pppd_args (NMPptpPlugin *plugin,
        if (!gwaddr || !strlen (gwaddr)) {
                g_set_error (error,
                             NM_VPN_PLUGIN_ERROR,
-                            NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
+                            NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
                             "%s",
                             _("Missing VPN gateway."));
                goto error;
@@ -982,7 +981,7 @@ error:
 
 static gboolean
 nm_pptp_start_pppd_binary (NMPptpPlugin *plugin,
-                           NMSettingVPN *s_vpn,
+                           NMSettingVpn *s_vpn,
                            const char *gwaddr,
                            GError **error)
 {
@@ -1045,15 +1044,15 @@ service_ppp_state_cb (NMPptpPppService *service,
                       guint32 ppp_state,
                       NMPptpPlugin *plugin)
 {
-       NMVPNServiceState plugin_state = nm_vpn_plugin_get_state (NM_VPN_PLUGIN (plugin));
+       NMVpnServiceState plugin_state = nm_vpn_service_plugin_get_state (NM_VPN_SERVICE_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_disconnect (NM_VPN_PLUGIN (plugin), NULL);
+                       nm_vpn_service_plugin_disconnect (NM_VPN_SERVICE_PLUGIN (plugin), NULL);
                else if (plugin_state == NM_VPN_SERVICE_STATE_STARTING)
-                       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;
@@ -1061,62 +1060,53 @@ 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,
-                       NMVPNPlugin *plugin)
+                       NMVpnServicePlugin *plugin)
 {
        NMPptpPppServicePrivate *priv = NM_PPTP_PPP_SERVICE_GET_PRIVATE (service);
-       GHashTable *hash;
+       GHashTableIter iter;
+       char *key;
        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;
 
-       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);
+               if (tmp)
+                       g_variant_builder_add (&builder, "{sv}", key, tmp);
+       }
 
        /* Insert the external VPN gateway into the table, which the pppd plugin
         * simply doesn't know about.
         */
-       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);
+       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);
 
-       nm_vpn_plugin_set_ip4_config (plugin, hash);
-
-       g_hash_table_destroy (hash);
+       nm_vpn_service_plugin_set_ip4_config (plugin, new_config);
+       g_variant_unref (new_config);
 }
 
 static gboolean
-real_connect (NMVPNPlugin   *plugin,
-              NMConnection  *connection,
-              GError       **error)
+real_connect (NMVpnServicePlugin *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);
@@ -1162,15 +1152,15 @@ 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;
        NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
 
-       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);
@@ -1202,8 +1192,7 @@ ensure_killed (gpointer data)
 }
 
 static gboolean
-real_disconnect (NMVPNPlugin   *plugin,
-                         GError       **err)
+real_disconnect (NMVpnServicePlugin *plugin, GError **err)
 {
        NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (plugin);
 
@@ -1224,7 +1213,7 @@ real_disconnect (NMVPNPlugin   *plugin,
 }
 
 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);
 
@@ -1266,7 +1255,7 @@ static void
 nm_pptp_plugin_class_init (NMPptpPluginClass *pptp_class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (pptp_class);
-       NMVPNPluginClass *parent_class = NM_VPN_PLUGIN_CLASS (pptp_class);
+       NMVpnServicePluginClass *parent_class = NM_VPN_SERVICE_PLUGIN_CLASS (pptp_class);
 
        g_type_class_add_private (object_class, sizeof (NMPptpPluginPrivate));
 
@@ -1281,13 +1270,19 @@ NMPptpPlugin *
 nm_pptp_plugin_new (void)
 {
        NMPptpPlugin *plugin;
+       GError *error = NULL;
 
-       plugin = g_object_new (NM_TYPE_PPTP_PLUGIN,
-                              NM_VPN_PLUGIN_DBUS_SERVICE_NAME,
-                              NM_DBUS_SERVICE_PPTP,
-                              NULL);
+       plugin = g_initable_new (NM_TYPE_PPTP_PLUGIN, NULL, &error,
+                                NM_VPN_SERVICE_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 135cf4e..e73f792 100644
--- a/src/nm-pptp-service.h
+++ b/src/nm-pptp-service.h
@@ -25,7 +25,8 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <nm-vpn-plugin.h>
+#include <NetworkManager.h>
+#include <nm-vpn-service-plugin.h>
 
 #include "nm-pptp-service-defines.h"
 
@@ -40,11 +41,11 @@
 #define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
 
 typedef struct {
-       NMVPNPlugin parent;
+       NMVpnServicePlugin parent;
 } NMPptpPlugin;
 
 typedef struct {
-       NMVPNPluginClass parent;
+       NMVpnServicePluginClass parent;
 } NMPptpPluginClass;
 
 GType nm_pptp_plugin_get_type (void);


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