[network-manager-openvpn/th/export-bgo764132: 6/23] properties: split do_export_create() out of do_export()



commit 9206b2f2aa7de27f0d15d2a089a62049a757cf17
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 0c47006..42f8a00 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1610,8 +1610,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;
@@ -1659,10 +1659,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))
@@ -1672,7 +1685,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);
@@ -2038,6 +2051,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]