[network-manager-libreswan/th/vpn-editor-split-bgo766623: 15/18] properties: split "nm-libreswan-editor-plugin.c" out of "nm-libreswan.c"
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-libreswan/th/vpn-editor-split-bgo766623: 15/18] properties: split "nm-libreswan-editor-plugin.c" out of "nm-libreswan.c"
- Date: Wed, 18 May 2016 19:03:39 +0000 (UTC)
commit d31aea4495848e607ff0d2e4757885d7b2828d96
Author: Thomas Haller <thaller redhat com>
Date: Tue May 10 15:29:43 2016 +0200
properties: split "nm-libreswan-editor-plugin.c" out of "nm-libreswan.c"
po/POTFILES.in | 1 +
properties/Makefile.am | 20 ++-
properties/nm-libreswan-editor-plugin.c | 193 +++++++++++++++++++++++++++++++
properties/nm-libreswan-editor-plugin.h | 49 ++++++++
properties/nm-libreswan.c | 162 +-------------------------
properties/nm-libreswan.h | 27 +----
6 files changed, 262 insertions(+), 190 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index db91bca..caf44ab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@
# Please keep this file sorted alphabetically.
appdata/network-manager-libreswan.metainfo.xml.in
auth-dialog/main.c
+properties/nm-libreswan-editor-plugin.c
properties/nm-libreswan.c
src/nm-libreswan-service.c
shared/nm-utils/nm-shared-utils.c
diff --git a/properties/Makefile.am b/properties/Makefile.am
index 97b63e1..8dc075c 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -5,9 +5,16 @@ plugin_LTLIBRARIES += libnm-libreswan-properties.la
endif
plugin_sources = \
+ nm-libreswan-editor-plugin.c \
+ nm-libreswan-editor-plugin.h
+
+editor_sources = \
nm-libreswan.c \
nm-libreswan.h
+uidir = $(datadir)/gnome-vpn-properties/libreswan
+ui_DATA = nm-libreswan-dialog.ui
+
common_CFLAGS = \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
@@ -25,7 +32,8 @@ libnm_vpn_plugin_libreswan_la_CFLAGS = \
$(LIBNMA_CFLAGS)
libnm_vpn_plugin_libreswan_la_SOURCES = \
- $(plugin_sources)
+ $(plugin_sources) \
+ $(editor_sources)
libnm_vpn_plugin_libreswan_la_LIBADD = \
$(GTK_LIBS) \
@@ -47,7 +55,8 @@ libnm_libreswan_properties_la_CFLAGS = \
$(LIBNM_GTK_CFLAGS)
libnm_libreswan_properties_la_SOURCES = \
- $(plugin_sources)
+ $(plugin_sources) \
+ $(editor_sources)
libnm_libreswan_properties_la_LIBADD = \
$(GTK_LIBS) \
@@ -61,12 +70,9 @@ libnm_libreswan_properties_la_LDFLAGS = \
###############################################################################
-uidir = $(datadir)/gnome-vpn-properties/libreswan
-ui_DATA = nm-libreswan-dialog.ui
-
CLEANFILES = *.bak *~
EXTRA_DIST = \
- $(ui_DATA) \
libnm-libreswan-properties.ver \
- libnm-vpn-plugin-libreswan.ver
+ libnm-vpn-plugin-libreswan.ver \
+ nm-libreswan-dialog.ui
diff --git a/properties/nm-libreswan-editor-plugin.c b/properties/nm-libreswan-editor-plugin.c
new file mode 100644
index 0000000..aba85b1
--- /dev/null
+++ b/properties/nm-libreswan-editor-plugin.c
@@ -0,0 +1,193 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/***************************************************************************
+ * nm-libreswan.c : GNOME UI dialogs for configuring libreswan VPN connections
+ *
+ * Copyright (C) 2005 David Zeuthen, <davidz redhat com>
+ * Copyright (C) 2005 - 2008 Dan Williams, <dcbw redhat com>
+ * Copyright (C) 2010 Avesh Agarwal <avagarwa 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-libreswan-editor-plugin.h"
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <glib/gstdio.h>
+#include <string.h>
+
+#include "utils.h"
+
+#include "nm-libreswan.h"
+
+#define LIBRESWAN_PLUGIN_NAME _("IPsec based VPN")
+#define LIBRESWAN_PLUGIN_DESC _("IPsec based VPN using IKEv1")
+
+/*****************************************************************************/
+
+enum {
+ PROP_0,
+ PROP_NAME,
+ PROP_DESC,
+ PROP_SERVICE
+};
+
+static void libreswan_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class);
+
+G_DEFINE_TYPE_EXTENDED (LibreswanEditorPlugin, libreswan_editor_plugin, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
+ libreswan_editor_plugin_interface_init))
+
+/*****************************************************************************/
+
+static NMConnection *
+import_from_file (NMVpnEditorPlugin *self,
+ const char *path,
+ GError **error)
+{
+ NMConnection *connection;
+ int fd;
+
+ fd = g_open (path, O_RDONLY, 0777);
+ if (fd == -1) {
+ g_set_error (error, NMV_EDITOR_PLUGIN_ERROR, 0,
+ _("Can't open file '%s': %s"), path, g_strerror (errno));
+ return FALSE;
+ }
+
+ connection = nm_libreswan_config_read (fd);
+ g_close (fd, NULL);
+
+ return connection;
+}
+
+static gboolean
+export_to_file (NMVpnEditorPlugin *self,
+ const char *path,
+ NMConnection *connection,
+ GError **error)
+{
+ NMSettingVpn *s_vpn;
+ gboolean openswan = FALSE;
+ int fd;
+
+ fd = g_open (path, O_WRONLY | O_CREAT, 0777);
+ if (fd == -1) {
+ g_set_error (error, NMV_EDITOR_PLUGIN_ERROR, 0,
+ _("Can't open file '%s': %s"), path, g_strerror (errno));
+ return FALSE;
+ }
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+ if (s_vpn)
+ openswan = nm_streq (nm_setting_vpn_get_service_type (s_vpn), NM_VPN_SERVICE_TYPE_OPENSWAN);
+
+ nm_libreswan_config_write (fd, connection, NULL, openswan);
+
+ if (!g_close (fd, error))
+ return FALSE;
+
+ return TRUE;
+}
+
+static guint32
+get_capabilities (NMVpnEditorPlugin *iface)
+{
+ return NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT | NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT;
+}
+
+static NMVpnEditor *
+get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
+{
+ return nm_vpn_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, LIBRESWAN_PLUGIN_NAME);
+ break;
+ case PROP_DESC:
+ g_value_set_string (value, LIBRESWAN_PLUGIN_DESC);
+ break;
+ case PROP_SERVICE:
+ g_value_set_string (value, NM_VPN_SERVICE_TYPE_LIBRESWAN);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+libreswan_editor_plugin_class_init (LibreswanEditorPluginClass *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
+libreswan_editor_plugin_init (LibreswanEditorPlugin *plugin)
+{
+}
+
+static void
+libreswan_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_from_file;
+ iface_class->export_to_file = export_to_file;
+
+ iface_class->get_suggested_filename = NULL;
+}
+
+
+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 (LIBRESWAN_TYPE_EDITOR_PLUGIN, NULL);
+}
+
diff --git a/properties/nm-libreswan-editor-plugin.h b/properties/nm-libreswan-editor-plugin.h
new file mode 100644
index 0000000..1c5e49a
--- /dev/null
+++ b/properties/nm-libreswan-editor-plugin.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/***************************************************************************
+ * nm-libreswan.h : GNOME UI dialogs for configuring libreswan VPN connections
+ *
+ * Copyright (C) 2008 Dan Williams, <dcbw redhat com>
+ * Copyright (C) 2010 Avesh Agarwal, <avagarwa 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_LIBRESWAN_EDITOR_PLUGIN_H__
+#define __NM_LIBRESWAN_EDITOR_PLUGIN_H__
+
+#define LIBRESWAN_TYPE_EDITOR_PLUGIN (libreswan_editor_plugin_get_type ())
+#define LIBRESWAN_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN, LibreswanEditorPlugin))
+#define LIBRESWAN_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
LIBRESWAN_TYPE_EDITOR_PLUGIN, LibreswanEditorPluginClass))
+#define LIBRESWAN_IS_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN))
+#define LIBRESWAN_IS_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN))
+#define LIBRESWAN_EDITOR_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN, LibreswanEditorPluginClass))
+
+typedef struct _LibreswanEditorPlugin LibreswanEditorPlugin;
+typedef struct _LibreswanEditorPluginClass LibreswanEditorPluginClass;
+
+struct _LibreswanEditorPlugin {
+ GObject parent;
+};
+
+struct _LibreswanEditorPluginClass {
+ GObjectClass parent;
+};
+
+GType libreswan_editor_plugin_get_type (void);
+
+
+#endif /* __NM_LIBRESWAN_EDITOR_PLUGIN_H__ */
+
diff --git a/properties/nm-libreswan.c b/properties/nm-libreswan.c
index 9d867d0..4cc2fe8 100644
--- a/properties/nm-libreswan.c
+++ b/properties/nm-libreswan.c
@@ -1,7 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/***************************************************************************
- * nm-libreswan.c : GNOME UI dialogs for configuring libreswan VPN connections
- *
* Copyright (C) 2005 David Zeuthen, <davidz redhat com>
* Copyright (C) 2005 - 2008 Dan Williams, <dcbw redhat com>
* Copyright (C) 2010 Avesh Agarwal <avagarwa redhat com>
@@ -34,11 +32,6 @@
#include <glib/gstdio.h>
#include <string.h>
-#include "utils.h"
-
-#define LIBRESWAN_PLUGIN_NAME _("IPsec based VPN")
-#define LIBRESWAN_PLUGIN_DESC _("IPsec based VPN using IKEv1")
-
#define ENC_TYPE_SECURE 0
#define ENC_TYPE_WEAK 1
#define ENC_TYPE_NONE 2
@@ -47,22 +40,7 @@
#define PW_TYPE_ASK 1
#define PW_TYPE_UNUSED 2
-/************** plugin class **************/
-
-enum {
- PROP_0,
- PROP_NAME,
- PROP_DESC,
- PROP_SERVICE
-};
-
-static void libreswan_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class);
-
-G_DEFINE_TYPE_EXTENDED (LibreswanEditorPlugin, libreswan_editor_plugin, G_TYPE_OBJECT, 0,
- G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
- libreswan_editor_plugin_interface_init))
-
-/************** UI widget class **************/
+/*****************************************************************************/
static void libreswan_editor_interface_init (NMVpnEditorInterface *iface_class);
@@ -398,7 +376,7 @@ update_connection (NMVpnEditor *iface,
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str))
nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_LEFTXAUTHUSER, str);
-
+
/* Phase 1 Algorithms: ike */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "phase1_entry"));
str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
@@ -441,7 +419,7 @@ is_new_func (const char *key, const char *value, gpointer user_data)
*is_new = FALSE;
}
-static NMVpnEditor *
+NMVpnEditor *
nm_vpn_editor_new (NMConnection *connection, GError **error)
{
NMVpnEditor *object;
@@ -551,137 +529,3 @@ libreswan_editor_interface_init (NMVpnEditorInterface *iface_class)
iface_class->update_connection = update_connection;
}
-static NMConnection *
-import_from_file (NMVpnEditorPlugin *self,
- const char *path,
- GError **error)
-{
- NMConnection *connection;
- int fd;
-
- fd = g_open (path, O_RDONLY, 0777);
- if (fd == -1) {
- g_set_error (error, NMV_EDITOR_PLUGIN_ERROR, 0,
- _("Can't open file '%s': %s"), path, g_strerror (errno));
- return FALSE;
- }
-
- connection = nm_libreswan_config_read (fd);
- g_close (fd, NULL);
-
- return connection;
-}
-
-static gboolean
-export_to_file (NMVpnEditorPlugin *self,
- const char *path,
- NMConnection *connection,
- GError **error)
-{
- NMSettingVpn *s_vpn;
- gboolean openswan = FALSE;
- int fd;
-
- fd = g_open (path, O_WRONLY | O_CREAT, 0777);
- if (fd == -1) {
- g_set_error (error, NMV_EDITOR_PLUGIN_ERROR, 0,
- _("Can't open file '%s': %s"), path, g_strerror (errno));
- return FALSE;
- }
-
- s_vpn = nm_connection_get_setting_vpn (connection);
- if (s_vpn)
- openswan = nm_streq (nm_setting_vpn_get_service_type (s_vpn), NM_VPN_SERVICE_TYPE_OPENSWAN);
-
- nm_libreswan_config_write (fd, connection, NULL, openswan);
-
- if (!g_close (fd, error))
- return FALSE;
-
- return TRUE;
-
-}
-
-static guint32
-get_capabilities (NMVpnEditorPlugin *iface)
-{
- return NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT | NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT;
-}
-
-static NMVpnEditor *
-get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
-{
- return nm_vpn_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, LIBRESWAN_PLUGIN_NAME);
- break;
- case PROP_DESC:
- g_value_set_string (value, LIBRESWAN_PLUGIN_DESC);
- break;
- case PROP_SERVICE:
- g_value_set_string (value, NM_VPN_SERVICE_TYPE_LIBRESWAN);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-libreswan_editor_plugin_class_init (LibreswanEditorPluginClass *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
-libreswan_editor_plugin_init (LibreswanEditorPlugin *plugin)
-{
-}
-
-static void
-libreswan_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_from_file;
- iface_class->export_to_file = export_to_file;
-
- iface_class->get_suggested_filename = NULL;
-}
-
-
-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 (LIBRESWAN_TYPE_EDITOR_PLUGIN, NULL);
-}
-
diff --git a/properties/nm-libreswan.h b/properties/nm-libreswan.h
index 06a05bc..6b990ff 100644
--- a/properties/nm-libreswan.h
+++ b/properties/nm-libreswan.h
@@ -1,7 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/***************************************************************************
- * nm-libreswan.h : GNOME UI dialogs for configuring libreswan VPN connections
- *
* Copyright (C) 2008 Dan Williams, <dcbw redhat com>
* Copyright (C) 2010 Avesh Agarwal, <avagarwa redhat com>
*
@@ -24,27 +22,6 @@
#ifndef _NM_LIBRESWAN_H_
#define _NM_LIBRESWAN_H_
-#define LIBRESWAN_TYPE_EDITOR_PLUGIN (libreswan_editor_plugin_get_type ())
-#define LIBRESWAN_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN, LibreswanEditorPlugin))
-#define LIBRESWAN_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
LIBRESWAN_TYPE_EDITOR_PLUGIN, LibreswanEditorPluginClass))
-#define LIBRESWAN_IS_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN))
-#define LIBRESWAN_IS_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN))
-#define LIBRESWAN_EDITOR_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
LIBRESWAN_TYPE_EDITOR_PLUGIN, LibreswanEditorPluginClass))
-
-typedef struct _LibreswanEditorPlugin LibreswanEditorPlugin;
-typedef struct _LibreswanEditorPluginClass LibreswanEditorPluginClass;
-
-struct _LibreswanEditorPlugin {
- GObject parent;
-};
-
-struct _LibreswanEditorPluginClass {
- GObjectClass parent;
-};
-
-GType libreswan_editor_plugin_get_type (void);
-
-
#define LIBRESWAN_TYPE_EDITOR (libreswan_editor_get_type ())
#define LIBRESWAN_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBRESWAN_TYPE_EDITOR,
LibreswanEditor))
#define LIBRESWAN_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LIBRESWAN_TYPE_EDITOR,
LibreswanEditorClass))
@@ -65,5 +42,7 @@ struct _LibreswanEditorClass {
GType libreswan_editor_get_type (void);
-#endif /* _NM_LIBRESWAN_H_ */
+NMVpnEditor *nm_vpn_editor_new (NMConnection *connection, GError **error);
+
+#endif /* _NM_LIBRESWAN_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]