[network-manager-applet] core: clean up utility functions and remove useless includes



commit 3cbacec2fe9aa3002b47066fb1b22ad11600f513
Author: Dan Williams <dcbw redhat com>
Date:   Fri Mar 4 11:59:12 2011 -0600

    core: clean up utility functions and remove useless includes
    
    Move around single-location-used functions from utils.c and remove
    useless includes so that we can start better isolating GConf code.

 src/ap-menu-item.c                         |    1 -
 src/applet-dialogs.c                       |    1 -
 src/connection-editor/ce-page.c            |   81 ++++++++++++++++++++++++++--
 src/connection-editor/ce-page.h            |    4 +-
 src/connection-editor/nm-connection-list.c |    3 +-
 src/connection-editor/page-wireless.c      |    1 -
 src/mb-menu-item.c                         |    1 -
 src/utils/utils.c                          |   82 ----------------------------
 src/utils/utils.h                          |    6 --
 src/wireless-security/eap-method-tls.c     |    1 -
 10 files changed, 80 insertions(+), 101 deletions(-)
---
diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c
index 1820c6f..e3b830c 100644
--- a/src/ap-menu-item.c
+++ b/src/ap-menu-item.c
@@ -32,7 +32,6 @@
 #include <nm-utils.h>
 #include "ap-menu-item.h"
 #include "nm-access-point.h"
-#include "utils.h"
 
 
 G_DEFINE_TYPE (NMNetworkMenuItem, nm_network_menu_item, GTK_TYPE_IMAGE_MENU_ITEM);
diff --git a/src/applet-dialogs.c b/src/applet-dialogs.c
index 3059007..a0371ea 100644
--- a/src/applet-dialogs.c
+++ b/src/applet-dialogs.c
@@ -43,7 +43,6 @@
 #include <glib/gi18n.h>
 
 #include "applet-dialogs.h"
-#include "utils.h"
 
 
 static void
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index 5288458..8eb76e5 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #include <config.h>
@@ -34,7 +34,6 @@
 
 #include "ce-page.h"
 #include "nma-marshal.h"
-#include "utils.h"
 
 G_DEFINE_ABSTRACT_TYPE (CEPage, ce_page, G_TYPE_OBJECT)
 
@@ -133,11 +132,46 @@ ce_page_mac_to_entry (const GByteArray *mac, GtkEntry *entry)
 		return;
 
 	memcpy (addr.ether_addr_octet, mac->data, ETH_ALEN);
-	str_addr = utils_ether_ntop (&addr);
+	/* we like leading zeros and all-caps, instead
+	 * of what glibc's ether_ntop() gives us
+	 */
+	str_addr = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
+	                            addr.ether_addr_octet[0], addr.ether_addr_octet[1],
+	                            addr.ether_addr_octet[2], addr.ether_addr_octet[3],
+	                            addr.ether_addr_octet[4], addr.ether_addr_octet[5]);
 	gtk_entry_set_text (entry, str_addr);
 	g_free (str_addr);
 }
 
+static gboolean
+is_mac_valid (const struct ether_addr *addr)
+{
+	guint8 invalid1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+	guint8 invalid2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+	guint8 invalid3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
+	guint8 invalid4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
+
+	g_return_val_if_fail (addr != NULL, FALSE);
+
+	/* Compare the AP address the card has with invalid ethernet MAC addresses. */
+	if (!memcmp (addr->ether_addr_octet, &invalid1, ETH_ALEN))
+		return FALSE;
+
+	if (!memcmp (addr->ether_addr_octet, &invalid2, ETH_ALEN))
+		return FALSE;
+
+	if (!memcmp (addr->ether_addr_octet, &invalid3, ETH_ALEN))
+		return FALSE;
+
+	if (!memcmp (addr->ether_addr_octet, &invalid4, ETH_ALEN))
+		return FALSE;
+
+	if (addr->ether_addr_octet[0] & 1) /* Multicast addresses */
+		return FALSE;
+
+	return TRUE;
+}
+
 GByteArray *
 ce_page_entry_to_mac (GtkEntry *entry, gboolean *invalid)
 {
@@ -156,7 +190,7 @@ ce_page_entry_to_mac (GtkEntry *entry, gboolean *invalid)
 		return NULL;
 
 	ether = ether_aton (temp);
-	if (!ether || !utils_mac_valid (ether)) {
+	if (!ether || !is_mac_valid (ether)) {
 		if (invalid)
 			*invalid = TRUE;
 		return NULL;
@@ -167,6 +201,43 @@ ce_page_entry_to_mac (GtkEntry *entry, gboolean *invalid)
 	return mac;
 }
 
+char *
+ce_page_get_next_available_name (GSList *connections, const char *format)
+{
+	GSList *names = NULL, *iter;
+	char *cname = NULL;
+	int i = 0;
+
+	for (iter = connections; iter; iter = g_slist_next (iter)) {
+		const char *id;
+
+		id = nm_connection_get_id (NM_CONNECTION (iter->data));
+		g_assert (id);
+		names = g_slist_append (names, (gpointer) id);
+	}
+
+	/* Find the next available unique connection name */
+	while (!cname && (i++ < 10000)) {
+		char *temp;
+		gboolean found = FALSE;
+
+		temp = g_strdup_printf (format, i);
+		for (iter = names; iter; iter = g_slist_next (iter)) {
+			if (!strcmp (iter->data, temp)) {
+				found = TRUE;
+				break;
+			}
+		}
+		if (!found)
+			cname = temp;
+		else
+			g_free (temp);
+	}
+
+	g_slist_free (names);
+	return cname;
+}
+
 static void
 emit_initialized (CEPage *self, GError *error)
 {
@@ -416,7 +487,7 @@ ce_page_new_connection (const char *format,
 	uuid = nm_utils_uuid_generate ();
 
 	connections = (*get_connections_func) (user_data);
-	id = utils_next_available_name (connections, format);
+	id = ce_page_get_next_available_name (connections, format);
 	g_slist_free (connections);
 
 	g_object_set (s_con,
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index aa14e57..5ce79c9 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __CE_PAGE_H__
@@ -114,6 +114,8 @@ void ce_page_complete_init (CEPage *self,
 
 gboolean ce_page_get_initialized (CEPage *self);
 
+char *ce_page_get_next_available_name (GSList *connections, const char *format);
+
 /* Only for subclasses */
 NMConnection *ce_page_new_connection (const char *format,
                                       const char *ctype,
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index d39f523..95b35b4 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -53,7 +53,6 @@
 #include "page-vpn.h"
 #include "nm-connection-editor.h"
 #include "nm-connection-list.h"
-#include "utils.h"
 #include "vpn-helpers.h"
 #include "ce-polkit-button.h"
 
@@ -865,7 +864,7 @@ import_success_cb (NMConnection *connection, gpointer user_data)
 		GSList *connections;
 
 		connections = nm_remote_settings_list_connections (info->list->settings);
-		s = utils_next_available_name (connections, _("VPN connection %d"));
+		s = ce_page_get_next_available_name (connections, _("VPN connection %d"));
 		g_object_set (s_con, NM_SETTING_CONNECTION_ID, s, NULL);
 		g_free (s);
 
diff --git a/src/connection-editor/page-wireless.c b/src/connection-editor/page-wireless.c
index d96398c..fe22b04 100644
--- a/src/connection-editor/page-wireless.c
+++ b/src/connection-editor/page-wireless.c
@@ -31,7 +31,6 @@
 #include <nm-utils.h>
 
 #include "page-wireless.h"
-#include "utils.h"
 
 G_DEFINE_TYPE (CEPageWireless, ce_page_wireless, CE_TYPE_PAGE)
 
diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c
index 2447576..a470d2b 100644
--- a/src/mb-menu-item.c
+++ b/src/mb-menu-item.c
@@ -30,7 +30,6 @@
 #include <string.h>
 
 #include "mb-menu-item.h"
-#include "utils.h"
 
 G_DEFINE_TYPE (NMMbMenuItem, nm_mb_menu_item, GTK_TYPE_IMAGE_MENU_ITEM);
 
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 301aa00..0eb5e2d 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -632,88 +632,6 @@ utils_filter_connections_for_device (NMDevice *device, GSList *connections)
 	return filtered;
 }
 
-gboolean
-utils_mac_valid (const struct ether_addr *addr)
-{
-	guint8 invalid1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-	guint8 invalid2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-	guint8 invalid3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
-	guint8 invalid4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
-
-	g_return_val_if_fail (addr != NULL, FALSE);
-
-	/* Compare the AP address the card has with invalid ethernet MAC addresses. */
-	if (!memcmp (addr->ether_addr_octet, &invalid1, ETH_ALEN))
-		return FALSE;
-
-	if (!memcmp (addr->ether_addr_octet, &invalid2, ETH_ALEN))
-		return FALSE;
-
-	if (!memcmp (addr->ether_addr_octet, &invalid3, ETH_ALEN))
-		return FALSE;
-
-	if (!memcmp (addr->ether_addr_octet, &invalid4, ETH_ALEN))
-		return FALSE;
-
-	if (addr->ether_addr_octet[0] & 1) /* Multicast addresses */
-		return FALSE;
-	
-	return TRUE;
-}
-
-char *
-utils_ether_ntop (const struct ether_addr *mac)
-{
-	/* we like leading zeros and all-caps, instead
-	 * of what glibc's ether_ntop() gives us
-	 */
-	return g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
-	                        mac->ether_addr_octet[0], mac->ether_addr_octet[1],
-	                        mac->ether_addr_octet[2], mac->ether_addr_octet[3],
-	                        mac->ether_addr_octet[4], mac->ether_addr_octet[5]);
-}
-
-
-char *
-utils_next_available_name (GSList *connections, const char *format)
-{
-	GSList *names = NULL, *iter;
-	char *cname = NULL;
-	int i = 0;
-
-	for (iter = connections; iter; iter = g_slist_next (iter)) {
-		NMConnection *candidate = NM_CONNECTION (iter->data);
-		NMSettingConnection *s_con;
-		const char *id;
-
-		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
-		id = nm_setting_connection_get_id (s_con);
-		g_assert (id);
-		names = g_slist_append (names, (gpointer) id);
-	}	
-
-	/* Find the next available unique connection name */
-	while (!cname && (i++ < 10000)) {
-		char *temp;
-		gboolean found = FALSE;
-
-		temp = g_strdup_printf (format, i);
-		for (iter = names; iter; iter = g_slist_next (iter)) {
-			if (!strcmp (iter->data, temp)) {
-				found = TRUE;
-				break;
-			}
-		}
-		if (!found)
-			cname = temp;
-		else
-			g_free (temp);
-	}
-
-	g_slist_free (names);
-	return cname;
-}
-
 char *
 utils_hash_ap (const GByteArray *ssid,
                NM80211Mode mode,
diff --git a/src/utils/utils.h b/src/utils/utils.h
index 052bb3f..fe6095c 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -44,12 +44,6 @@ gboolean utils_connection_valid_for_device (NMConnection *connection,
 
 GSList *utils_filter_connections_for_device (NMDevice *device, GSList *connections);
 
-char *utils_ether_ntop (const struct ether_addr *mac);
-
-gboolean utils_mac_valid (const struct ether_addr *addr);
-
-char *utils_next_available_name (GSList *connections, const char *format);
-
 char *utils_hash_ap (const GByteArray *ssid,
                      NM80211Mode mode,
                      guint32 flags,
diff --git a/src/wireless-security/eap-method-tls.c b/src/wireless-security/eap-method-tls.c
index 89f672d..065efbb 100644
--- a/src/wireless-security/eap-method-tls.c
+++ b/src/wireless-security/eap-method-tls.c
@@ -30,7 +30,6 @@
 #include "gconf-helpers.h"
 #include "eap-method.h"
 #include "wireless-security.h"
-#include "utils.h"
 #include "helpers.h"
 
 struct _EAPMethodTLS {



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