[network-manager-openvpn/th/vpn-editor-split-bgo765732: 9/12] properties: split NMVpnEditorPlugin out of "nm-openvpn.c"



commit 1938902455aedffff29137329f22377ebd0ebde6
Author: Thomas Haller <thaller redhat com>
Date:   Thu Apr 28 20:34:52 2016 +0200

    properties: split NMVpnEditorPlugin out of "nm-openvpn.c"

 po/POTFILES.in                        |    1 +
 properties/Makefile.am                |    2 +
 properties/import-export.c            |    1 -
 properties/nm-openvpn-editor-plugin.c |  201 +++++++++++++++++++++++++++++++++
 properties/nm-openvpn-editor-plugin.h |   48 ++++++++
 properties/nm-openvpn.c               |  164 +--------------------------
 properties/nm-openvpn.h               |   23 +----
 properties/tests/test-import-export.c |    1 +
 8 files changed, 258 insertions(+), 183 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5113f1b..738950f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ appdata/network-manager-openvpn.metainfo.xml.in
 auth-dialog/main.c
 properties/auth-helpers.c
 properties/import-export.c
+properties/nm-openvpn-editor-plugin.c
 properties/nm-openvpn.c
 shared/nm-shared-utils.c
 src/nm-openvpn-service.c
diff --git a/properties/Makefile.am b/properties/Makefile.am
index 2ba5284..3a8292c 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -7,6 +7,8 @@ plugin_LTLIBRARIES += libnm-openvpn-properties.la
 endif
 
 plugin_sources = \
+        nm-openvpn-editor-plugin.c \
+        nm-openvpn-editor-plugin.h \
         nm-openvpn.c \
         nm-openvpn.h \
         auth-helpers.c \
diff --git a/properties/import-export.c b/properties/import-export.c
index 4b97b58..d6b18a4 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -34,7 +34,6 @@
 #include <ctype.h>
 #include <stdio.h>
 
-#include "nm-openvpn.h"
 #include "utils.h"
 #include "nm-shared-utils.h"
 
diff --git a/properties/nm-openvpn-editor-plugin.c b/properties/nm-openvpn-editor-plugin.c
new file mode 100644
index 0000000..c4fbfab
--- /dev/null
+++ b/properties/nm-openvpn-editor-plugin.c
@@ -0,0 +1,201 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/***************************************************************************
+ * nm-openvpn-editor-plugin.c : GNOME UI dialogs for configuring openvpn VPN connections
+ *
+ * Copyright (C) 2005 Tim Niemueller <tim niemueller de>
+ * Copyright (C) 2008 - 2010 Dan Williams, <dcbw redhat com>
+ * Copyright (C) 2008 - 2011 Red Hat, Inc.
+ * Based on work by David Zeuthen, <davidz redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ **************************************************************************/
+
+#include "nm-default.h"
+
+#include "nm-openvpn-editor-plugin.h"
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "auth-helpers.h"
+#include "nm-openvpn.h"
+#include "import-export.h"
+
+#define OPENVPN_PLUGIN_NAME    _("OpenVPN")
+#define OPENVPN_PLUGIN_DESC    _("Compatible with the OpenVPN server.")
+
+/*****************************************************************************/
+
+enum {
+       PROP_0,
+       PROP_NAME,
+       PROP_DESC,
+       PROP_SERVICE
+};
+
+static void openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class);
+
+G_DEFINE_TYPE_EXTENDED (OpenvpnEditorPlugin, openvpn_editor_plugin, G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
+                                               openvpn_editor_plugin_interface_init))
+
+/*****************************************************************************/
+
+static NMConnection *
+import (NMVpnEditorPlugin *iface, const char *path, GError **error)
+{
+       NMConnection *connection = NULL;
+       char *contents = NULL;
+       char *ext;
+       gsize contents_len;
+
+       ext = strrchr (path, '.');
+
+       if (!ext || (   !g_str_has_suffix (ext, ".ovpn")
+                    && !g_str_has_suffix (ext, ".conf")
+                    && !g_str_has_suffix (ext, ".cnf")
+                    && !g_str_has_suffix (ext, ".ovpntest"))) {   /* Special extension for testcases */
+               g_set_error_literal (error,
+                                    OPENVPN_EDITOR_PLUGIN_ERROR,
+                                    OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
+                                    _("unknown OpenVPN file extension"));
+               goto out;
+       }
+
+       if (!g_file_get_contents (path, &contents, &contents_len, error))
+               return NULL;
+
+       connection = do_import (path, contents, contents_len, error);
+
+out:
+       g_free (contents);
+       return connection;
+}
+
+static gboolean
+export (NMVpnEditorPlugin *iface,
+        const char *path,
+        NMConnection *connection,
+        GError **error)
+{
+       return do_export (path, connection, error);
+}
+
+static char *
+get_suggested_filename (NMVpnEditorPlugin *iface, NMConnection *connection)
+{
+       NMSettingConnection *s_con;
+       const char *id;
+
+       g_return_val_if_fail (connection != NULL, NULL);
+
+       s_con = nm_connection_get_setting_connection (connection);
+       g_return_val_if_fail (s_con != NULL, NULL);
+
+       id = nm_setting_connection_get_id (s_con);
+       g_return_val_if_fail (id != NULL, NULL);
+
+       return g_strdup_printf ("%s (openvpn).conf", id);
+}
+
+static guint32
+get_capabilities (NMVpnEditorPlugin *iface)
+{
+       return (NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT |
+               NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT |
+               NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
+}
+
+static NMVpnEditor *
+get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
+{
+       return openvpn_editor_new (connection, error);
+}
+
+/*****************************************************************************/
+
+static void
+get_property (GObject *object, guint prop_id,
+              GValue *value, GParamSpec *pspec)
+{
+       switch (prop_id) {
+       case PROP_NAME:
+               g_value_set_string (value, OPENVPN_PLUGIN_NAME);
+               break;
+       case PROP_DESC:
+               g_value_set_string (value, OPENVPN_PLUGIN_DESC);
+               break;
+       case PROP_SERVICE:
+               g_value_set_string (value, NM_VPN_SERVICE_TYPE_OPENVPN);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+openvpn_editor_plugin_init (OpenvpnEditorPlugin *plugin)
+{
+}
+
+static void
+openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class)
+{
+       /* interface implementation */
+       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_filename = get_suggested_filename;
+}
+
+static void
+openvpn_editor_plugin_class_init (OpenvpnEditorPluginClass *req_class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (req_class);
+
+       object_class->get_property = get_property;
+
+       g_object_class_override_property (object_class,
+                                         PROP_NAME,
+                                         NM_VPN_EDITOR_PLUGIN_NAME);
+
+       g_object_class_override_property (object_class,
+                                         PROP_DESC,
+                                         NM_VPN_EDITOR_PLUGIN_DESCRIPTION);
+
+       g_object_class_override_property (object_class,
+                                         PROP_SERVICE,
+                                         NM_VPN_EDITOR_PLUGIN_SERVICE);
+}
+
+/*****************************************************************************/
+
+G_MODULE_EXPORT NMVpnEditorPlugin *
+nm_vpn_editor_plugin_factory (GError **error)
+{
+       g_return_val_if_fail (!error || !*error, NULL);
+
+       bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
+       return g_object_new (OPENVPN_TYPE_EDITOR_PLUGIN, NULL);
+}
+
diff --git a/properties/nm-openvpn-editor-plugin.h b/properties/nm-openvpn-editor-plugin.h
new file mode 100644
index 0000000..2ccdd65
--- /dev/null
+++ b/properties/nm-openvpn-editor-plugin.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/***************************************************************************
+ * nm-openvpn-editor.h : GNOME UI dialogs for configuring openvpn VPN connections
+ *
+ * Copyright (C) 2008 Dan Williams, <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ **************************************************************************/
+
+#ifndef __NM_OPENVPN_EDITOR_PLUGIN_H__
+#define __NM_OPENVPN_EDITOR_PLUGIN_H__
+
+#define OPENVPN_TYPE_EDITOR_PLUGIN                (openvpn_editor_plugin_get_type ())
+#define OPENVPN_EDITOR_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
OPENVPN_TYPE_EDITOR_PLUGIN, OpenvpnEditorPlugin))
+#define OPENVPN_EDITOR_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), OPENVPN_TYPE_EDITOR_PLUGIN, 
OpenvpnEditorPluginClass))
+#define OPENVPN_IS_EDITOR_PLUGIN(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
OPENVPN_TYPE_EDITOR_PLUGIN))
+#define OPENVPN_IS_EDITOR_PLUGIN_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), 
OPENVPN_TYPE_EDITOR_PLUGIN))
+#define OPENVPN_EDITOR_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), OPENVPN_TYPE_EDITOR_PLUGIN, 
OpenvpnEditorPluginClass))
+
+typedef struct _OpenvpnEditorPlugin OpenvpnEditorPlugin;
+typedef struct _OpenvpnEditorPluginClass OpenvpnEditorPluginClass;
+
+struct _OpenvpnEditorPlugin {
+       GObject parent;
+};
+
+struct _OpenvpnEditorPluginClass {
+       GObjectClass parent;
+};
+
+GType openvpn_editor_plugin_get_type (void);
+
+
+#endif /* __NM_OPENVPN_EDITOR_PLUGIN_H__ */
+
diff --git a/properties/nm-openvpn.c b/properties/nm-openvpn.c
index bde45c9..67fff26 100644
--- a/properties/nm-openvpn.c
+++ b/properties/nm-openvpn.c
@@ -39,25 +39,7 @@
 #include "auth-helpers.h"
 #include "import-export.h"
 
-#define OPENVPN_PLUGIN_NAME    _("OpenVPN")
-#define OPENVPN_PLUGIN_DESC    _("Compatible with the OpenVPN server.")
-
-/************** plugin class **************/
-
-enum {
-       PROP_0,
-       PROP_NAME,
-       PROP_DESC,
-       PROP_SERVICE
-};
-
-static void openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class);
-
-G_DEFINE_TYPE_EXTENDED (OpenvpnEditorPlugin, openvpn_editor_plugin, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
-                                               openvpn_editor_plugin_interface_init))
-
-/************** UI widget class **************/
+/*****************************************************************************/
 
 static void openvpn_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class);
 
@@ -494,8 +476,8 @@ is_new_func (const char *key, const char *value, gpointer user_data)
        *is_new = FALSE;
 }
 
-static NMVpnEditor *
-nm_vpn_editor_interface_new (NMConnection *connection, GError **error)
+NMVpnEditor *
+openvpn_editor_new (NMConnection *connection, GError **error)
 {
        NMVpnEditor *object;
        OpenvpnEditorPrivate *priv;
@@ -603,143 +585,3 @@ openvpn_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class)
        iface_class->update_connection = update_connection;
 }
 
-static NMConnection *
-import (NMVpnEditorPlugin *iface, const char *path, GError **error)
-{
-       NMConnection *connection = NULL;
-       char *contents = NULL;
-       char *ext;
-       gsize contents_len;
-
-       ext = strrchr (path, '.');
-
-       if (!ext || (   !g_str_has_suffix (ext, ".ovpn")
-                    && !g_str_has_suffix (ext, ".conf")
-                    && !g_str_has_suffix (ext, ".cnf")
-                    && !g_str_has_suffix (ext, ".ovpntest"))) {   /* Special extension for testcases */
-               g_set_error_literal (error,
-                                    OPENVPN_EDITOR_PLUGIN_ERROR,
-                                    OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
-                                    _("unknown OpenVPN file extension"));
-               goto out;
-       }
-
-       if (!g_file_get_contents (path, &contents, &contents_len, error))
-               return NULL;
-
-       connection = do_import (path, contents, contents_len, error);
-
-out:
-       g_free (contents);
-       return connection;
-}
-
-static gboolean
-export (NMVpnEditorPlugin *iface,
-        const char *path,
-        NMConnection *connection,
-        GError **error)
-{
-       return do_export (path, connection, error);
-}
-
-static char *
-get_suggested_filename (NMVpnEditorPlugin *iface, NMConnection *connection)
-{
-       NMSettingConnection *s_con;
-       const char *id;
-
-       g_return_val_if_fail (connection != NULL, NULL);
-
-       s_con = nm_connection_get_setting_connection (connection);
-       g_return_val_if_fail (s_con != NULL, NULL);
-
-       id = nm_setting_connection_get_id (s_con);
-       g_return_val_if_fail (id != NULL, NULL);
-
-       return g_strdup_printf ("%s (openvpn).conf", id);
-}
-
-static guint32
-get_capabilities (NMVpnEditorPlugin *iface)
-{
-       return (NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT |
-               NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT |
-               NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
-}
-
-static NMVpnEditor *
-get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
-{
-       return nm_vpn_editor_interface_new (connection, error);
-}
-
-static void
-get_property (GObject *object, guint prop_id,
-                         GValue *value, GParamSpec *pspec)
-{
-       switch (prop_id) {
-       case PROP_NAME:
-               g_value_set_string (value, OPENVPN_PLUGIN_NAME);
-               break;
-       case PROP_DESC:
-               g_value_set_string (value, OPENVPN_PLUGIN_DESC);
-               break;
-       case PROP_SERVICE:
-               g_value_set_string (value, NM_VPN_SERVICE_TYPE_OPENVPN);
-               break;
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-               break;
-       }
-}
-
-static void
-openvpn_editor_plugin_class_init (OpenvpnEditorPluginClass *req_class)
-{
-       GObjectClass *object_class = G_OBJECT_CLASS (req_class);
-
-       object_class->get_property = get_property;
-
-       g_object_class_override_property (object_class,
-                                         PROP_NAME,
-                                         NM_VPN_EDITOR_PLUGIN_NAME);
-
-       g_object_class_override_property (object_class,
-                                         PROP_DESC,
-                                         NM_VPN_EDITOR_PLUGIN_DESCRIPTION);
-
-       g_object_class_override_property (object_class,
-                                         PROP_SERVICE,
-                                         NM_VPN_EDITOR_PLUGIN_SERVICE);
-}
-
-static void
-openvpn_editor_plugin_init (OpenvpnEditorPlugin *plugin)
-{
-}
-
-static void
-openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class)
-{
-       /* interface implementation */
-       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_filename = get_suggested_filename;
-}
-
-
-G_MODULE_EXPORT NMVpnEditorPlugin *
-nm_vpn_editor_plugin_factory (GError **error)
-{
-       if (error)
-               g_return_val_if_fail (*error == NULL, NULL);
-
-       bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-
-       return g_object_new (OPENVPN_TYPE_EDITOR_PLUGIN, NULL);
-}
-
diff --git a/properties/nm-openvpn.h b/properties/nm-openvpn.h
index b19fe37..cc973ed 100644
--- a/properties/nm-openvpn.h
+++ b/properties/nm-openvpn.h
@@ -23,27 +23,6 @@
 #ifndef _NM_OPENVPN_H_
 #define _NM_OPENVPN_H_
 
-#define OPENVPN_TYPE_EDITOR_PLUGIN                (openvpn_editor_plugin_get_type ())
-#define OPENVPN_EDITOR_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
OPENVPN_TYPE_EDITOR_PLUGIN, OpenvpnEditorPlugin))
-#define OPENVPN_EDITOR_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), OPENVPN_TYPE_EDITOR_PLUGIN, 
OpenvpnEditorPluginClass))
-#define OPENVPN_IS_EDITOR_PLUGIN(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
OPENVPN_TYPE_EDITOR_PLUGIN))
-#define OPENVPN_IS_EDITOR_PLUGIN_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), 
OPENVPN_TYPE_EDITOR_PLUGIN))
-#define OPENVPN_EDITOR_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), OPENVPN_TYPE_EDITOR_PLUGIN, 
OpenvpnEditorPluginClass))
-
-typedef struct _OpenvpnEditorPlugin OpenvpnEditorPlugin;
-typedef struct _OpenvpnEditorPluginClass OpenvpnEditorPluginClass;
-
-struct _OpenvpnEditorPlugin {
-       GObject parent;
-};
-
-struct _OpenvpnEditorPluginClass {
-       GObjectClass parent;
-};
-
-GType openvpn_editor_plugin_get_type (void);
-
-
 #define OPENVPN_TYPE_EDITOR            (openvpn_editor_plugin_widget_get_type ())
 #define OPENVPN_EDITOR(obj)                      (G_TYPE_CHECK_INSTANCE_CAST ((obj), OPENVPN_TYPE_EDITOR, 
OpenvpnEditor))
 #define OPENVPN_EDITOR_CLASS(klass)              (G_TYPE_CHECK_CLASS_CAST ((klass), OPENVPN_TYPE_EDITOR, 
OpenvpnEditorClass))
@@ -64,5 +43,7 @@ struct _OpenvpnEditorClass {
 
 GType openvpn_editor_plugin_widget_get_type (void);
 
+NMVpnEditor *openvpn_editor_new (NMConnection *connection, GError **error);
+
 #endif /* _NM_OPENVPN_H_ */
 
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 8a3008f..e520d4f 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -26,6 +26,7 @@
 #include <locale.h>
 #include <sys/stat.h>
 
+#include "nm-openvpn-editor-plugin.h"
 #include "nm-openvpn.h"
 #include "import-export.h"
 #include "utils.h"


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