[network-manager-applet/lr/pkcs11: 4/15] editor: drop use of deprecated NetworkManager API



commit 28e452652e962e47a25885ff5305fcbe064be346
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Feb 17 18:17:18 2017 +0000

    editor: drop use of deprecated NetworkManager API
    
    It provides a better error reporting too.

 src/connection-editor/ce-page.c     |   62 +++++++++++++++++++++--------------
 src/connection-editor/page-master.c |    2 +-
 2 files changed, 38 insertions(+), 26 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index 5ba6ca9..961482c 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -382,15 +382,15 @@ gboolean
 ce_page_interface_name_valid (const char *iface, const char *property_name, GError **error)
 {
        if (iface && *iface) {
-               if (!nm_utils_iface_valid_name (iface)) {
+               if (!nm_utils_is_valid_iface_name (iface, error)) {
                        if (property_name) {
-                               g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC,
-                                            _("invalid interface-name for %s (%s)"),
-                                            property_name, iface);
+                               g_prefix_error (error,
+                                               _("invalid interface-name for %s (%s): "),
+                                               property_name, iface);
                        } else {
-                               g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC,
-                                            _("invalid interface-name (%s)"),
-                                            iface);
+                               g_prefix_error (error,
+                                               _("invalid interface-name (%s): "),
+                                               iface);
                        }
                        return FALSE;
                }
@@ -556,9 +556,9 @@ gboolean
 ce_page_device_entry_get (GtkEntry *entry, int type, gboolean check_ifname,
                           char **ifname, char **mac, const char *device_name, GError **error)
 {
-       char *first, *second;
+       gs_free char *first = NULL;
+       gs_free char *second = NULL;
        const char *ifname_tmp = NULL, *mac_tmp = NULL;
-       gboolean valid = TRUE;
        const char *str;
 
        g_return_val_if_fail (entry != NULL, FALSE);
@@ -566,29 +566,36 @@ ce_page_device_entry_get (GtkEntry *entry, int type, gboolean check_ifname,
 
        str = gtk_entry_get_text (entry);
 
-       valid = _device_entry_parse (str, &first, &second);
+       if (!_device_entry_parse (str, &first, &second)) {
+               g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
+                                    _("can't parse device name"));
+               goto invalid;
+       }
 
        if (first) {
                if (nm_utils_hwaddr_valid (first, nm_utils_hwaddr_len (type)))
                        mac_tmp = first;
-               else if (!check_ifname || nm_utils_iface_valid_name (first))
+               else if (!check_ifname || nm_utils_is_valid_iface_name (first, error))
                        ifname_tmp = first;
                else
-                       valid = FALSE;
+                       goto invalid;
        }
        if (second) {
                if (nm_utils_hwaddr_valid (second, nm_utils_hwaddr_len (type))) {
-                       if (!mac_tmp)
+                       if (!mac_tmp) {
                                mac_tmp = second;
-                       else
-                               valid = FALSE;
-               } else if (!check_ifname || nm_utils_iface_valid_name (second)) {
+                       } else {
+                               g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
+                                                    _("invalid hardware address"));
+                               goto invalid;
+                       }
+               } else if (!check_ifname || nm_utils_is_valid_iface_name (second, error)) {
                        if (!ifname_tmp)
                                ifname_tmp = second;
                        else
-                               valid = FALSE;
+                               goto invalid;
                } else
-                       valid = FALSE;
+                       goto invalid;
        }
 
        if (ifname)
@@ -596,17 +603,22 @@ ce_page_device_entry_get (GtkEntry *entry, int type, gboolean check_ifname,
        if (mac)
                *mac = g_strdup (mac_tmp);
 
-       g_free (first);
-       g_free (second);
+       return TRUE;
 
-       if (!valid) {
+invalid:
+       if (error) {
+               g_prefix_error (error,
+                               _("invalid %s (%s): "),
+                               device_name ? device_name : _("device"),
+                               str);
+       } else {
                g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC,
-                            _("invalid %s (%s)"),
-                            device_name ? device_name : _("device"),
-                            str);
+                            _("invalid %s (%s) "),
+                           device_name ? device_name : _("device"),
+                           str);
        }
 
-       return valid;
+       return FALSE;
 }
 
 char *
diff --git a/src/connection-editor/page-master.c b/src/connection-editor/page-master.c
index 7e4ab73..deafa5b 100644
--- a/src/connection-editor/page-master.c
+++ b/src/connection-editor/page-master.c
@@ -380,7 +380,7 @@ add_connection (FUNC_TAG_NEW_CONNECTION_RESULT_IMPL,
        iface_name = gtk_entry_get_text (priv->interface_name);
        if (!*iface_name)
                iface_name = nm_connection_get_interface_name (connection);
-       if (!iface_name || !nm_utils_iface_valid_name (iface_name))
+       if (!iface_name || !nm_utils_is_valid_iface_name (iface_name, NULL))
                iface_name = nm_connection_get_id (connection);
        name = g_strdup_printf (_("%s slave %d"), iface_name,
                                gtk_tree_model_iter_n_children (priv->connections_model, NULL) + 1);


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