[network-manager-libreswan/th/vpn-plugin-debug-bgo766872: 4/21] properties: move nm_libreswan_config_read() to import_from_file()



commit 5a02aef780729ee4372e8acb6fc8e96040492c01
Author: Thomas Haller <thaller redhat com>
Date:   Thu May 26 10:48:21 2016 +0200

    properties: move nm_libreswan_config_read() to import_from_file()
    
    nm_libreswan_config_read() had only one caller import_from_file() and is pretty simple.
    It is not clear that it would ever be used outside of properties (because service only
    writes the configuration, it doesn't read it).
    
    Also, it had a a logging statement 'g_print ("Ignored line: '%s'", str)'
    which however was never reached because the properties plugin never
    sets @debug.

 properties/nm-libreswan-editor-plugin.c |   36 +++++++++++++++++++++++++-
 shared/utils.c                          |   42 -------------------------------
 shared/utils.h                          |    3 --
 3 files changed, 35 insertions(+), 46 deletions(-)
---
diff --git a/properties/nm-libreswan-editor-plugin.c b/properties/nm-libreswan-editor-plugin.c
index ff8cabe..a62e7e6 100644
--- a/properties/nm-libreswan-editor-plugin.c
+++ b/properties/nm-libreswan-editor-plugin.c
@@ -66,6 +66,10 @@ import_from_file (NMVpnEditorPlugin *self,
                   GError **error)
 {
        NMConnection *connection;
+       NMSettingConnection *s_con;
+       NMSettingVpn *s_vpn;
+       GIOChannel *chan;
+       gchar *str;
        int fd;
 
        fd = g_open (path, O_RDONLY, 0777);
@@ -75,7 +79,37 @@ import_from_file (NMVpnEditorPlugin *self,
                return NULL;
        }
 
-       connection = nm_libreswan_config_read (fd);
+       connection = nm_simple_connection_new ();
+       s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+       s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
+       nm_connection_add_setting (connection, NM_SETTING (s_con));
+       nm_connection_add_setting (connection, NM_SETTING (s_vpn));
+       g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_LIBRESWAN, NULL);
+
+       chan = g_io_channel_unix_new (fd);
+       while (g_io_channel_read_line (chan, &str, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) {
+               g_strstrip (str);
+               if (g_str_has_prefix (str, "conn "))
+                       g_object_set (s_con, NM_SETTING_CONNECTION_ID, &str[5], NULL);
+               else if (g_str_has_prefix (str, "leftid=@"))
+                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_LEFTID, &str[8]);
+               else if (g_str_has_prefix (str, "leftxauthusername="))
+                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_LEFTXAUTHUSER, &str[18]);
+               else if (g_str_has_prefix (str, "right="))
+                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_RIGHT, &str[6]);
+               else if (g_str_has_prefix (str, "ike=") && strcmp (str, "ike=aes-sha1"))
+                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_IKE, &str[4]);
+               else if (g_str_has_prefix (str, "esp=") && strcmp (str, "esp=aes-sha1;modp1024"))
+                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_ESP, &str[4]);
+               else if (g_str_has_prefix (str, "cisco-unity=yes"))
+                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_VENDOR, "Cisco");
+               else {
+                       /* unknown tokens are silently ignored. */
+               }
+               g_free (str);
+       }
+       g_io_channel_unref (chan);
+
        g_close (fd, NULL);
 
        return connection;
diff --git a/shared/utils.c b/shared/utils.c
index 28dff83..d040e9d 100644
--- a/shared/utils.c
+++ b/shared/utils.c
@@ -30,48 +30,6 @@
 
 gboolean debug = FALSE;
 
-NMConnection *
-nm_libreswan_config_read (gint fd)
-{
-       NMConnection *connection;
-       NMSettingConnection *s_con;
-       NMSettingVpn *s_vpn;
-       GIOChannel *chan;
-       gchar *str;
-
-       connection = nm_simple_connection_new ();
-       s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
-       s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
-       nm_connection_add_setting (connection, NM_SETTING (s_con));
-       nm_connection_add_setting (connection, NM_SETTING (s_vpn));
-       g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_LIBRESWAN, NULL);
-
-       chan = g_io_channel_unix_new (fd);
-       while (g_io_channel_read_line (chan, &str, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) {
-               g_strstrip (str);
-               if (g_str_has_prefix (str, "conn "))
-                       g_object_set (s_con, NM_SETTING_CONNECTION_ID, &str[5], NULL);
-               else if (g_str_has_prefix (str, "leftid=@"))
-                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_LEFTID, &str[8]);
-               else if (g_str_has_prefix (str, "leftxauthusername="))
-                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_LEFTXAUTHUSER, &str[18]);
-               else if (g_str_has_prefix (str, "right="))
-                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_RIGHT, &str[6]);
-               else if (g_str_has_prefix (str, "ike=") && strcmp (str, "ike=aes-sha1"))
-                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_IKE, &str[4]);
-               else if (g_str_has_prefix (str, "esp=") && strcmp (str, "esp=aes-sha1;modp1024"))
-                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_ESP, &str[4]);
-               else if (g_str_has_prefix (str, "cisco-unity=yes"))
-                       nm_setting_vpn_add_data_item (s_vpn, NM_LIBRESWAN_VENDOR, "Cisco");
-               else if (debug)
-                       g_print ("Ignored line: '%s'", str);
-               g_free (str);
-       }
-       g_io_channel_unref (chan);
-
-       return connection;
-}
-
 void
 nm_libreswan_config_write (gint fd,
                            NMConnection *connection,
diff --git a/shared/utils.h b/shared/utils.h
index ea3c140..f488a08 100644
--- a/shared/utils.h
+++ b/shared/utils.h
@@ -45,9 +45,6 @@ write_config_option (int fd, const char *format, ...)
        va_end (args);
 }
 
-NMConnection *
-nm_libreswan_config_read (gint fd);
-
 void
 nm_libreswan_config_write (gint fd,
                            NMConnection *connection,


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