[network-manager-openvpn/th/export-bgo764132: 8/27] properties: split do_export_create() out of do_export()
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/th/export-bgo764132: 8/27] properties: split do_export_create() out of do_export()
- Date: Fri, 25 Mar 2016 19:48:54 +0000 (UTC)
commit e2c7e91afc41227bdeae75a2164579bdd0406a22
Author: Thomas Haller <thaller redhat com>
Date: Wed Mar 23 18:46:57 2016 +0100
properties: split do_export_create() out of do_export()
properties/import-export.c | 36 +++++++++++++++++++++++++++++++-----
1 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 3c6bea8..c344819 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1612,8 +1612,8 @@ args_write_line_int64_str (GString *f, const char *key, const char *value)
/*****************************************************************************/
-gboolean
-do_export (const char *path, NMConnection *connection, GError **error)
+static GString *
+do_export_create (NMConnection *connection, const char *path, GError **error)
{
NMSettingConnection *s_con;
NMSettingIPConfig *s_ip4;
@@ -1661,10 +1661,23 @@ do_export (const char *path, NMConnection *connection, GError **error)
nm_auto(_auto_free_gstring_p) GString *f = NULL;
gs_free_error GError *local = NULL;
- s_con = nm_connection_get_setting_connection (connection);
- g_assert (s_con);
+ if (!path || !path[0]) {
+ g_set_error_literal (error,
+ OPENVPN_EDITOR_PLUGIN_ERROR,
+ OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
+ _("missing path argument"));
+ return NULL;
+ }
+ s_con = nm_connection_get_setting_connection (connection);
s_vpn = nm_connection_get_setting_vpn (connection);
+ if (!s_con || !s_vpn) {
+ g_set_error_literal (error,
+ OPENVPN_EDITOR_PLUGIN_ERROR,
+ OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
+ _("connection is not a valid OpenVPN connection"));
+ return NULL;
+ }
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE);
if (value && strlen (value))
@@ -1674,7 +1687,7 @@ do_export (const char *path, NMConnection *connection, GError **error)
OPENVPN_EDITOR_PLUGIN_ERROR,
OPENVPN_EDITOR_PLUGIN_ERROR_FILE_NOT_OPENVPN,
_("connection was incomplete (missing gateway)"));
- return FALSE;
+ return NULL;
}
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
@@ -2037,6 +2050,19 @@ do_export (const char *path, NMConnection *connection, GError **error)
args_write_line (f, "user", "openvpn");
args_write_line (f, "group", "openvpn");
+ return nm_unauto (&f);
+}
+
+gboolean
+do_export (const char *path, NMConnection *connection, GError **error)
+{
+ nm_auto(_auto_free_gstring_p) GString *f = NULL;
+ gs_free_error GError *local = NULL;
+
+ f = do_export_create (connection, path, error);
+ if (!f)
+ return FALSE;
+
if (!g_file_set_contents (path, f->str, f->len, &local)) {
g_set_error (error,
OPENVPN_EDITOR_PLUGIN_ERROR,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]