network-manager-applet r471 - in trunk: . src/wireless-security



Author: dcbw
Date: Thu Jan 24 04:33:30 2008
New Revision: 471
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=471&view=rev

Log:
2008-01-23  Dan Williams  <dcbw redhat com>

	* src/wireless-security/ws-wep-key.c
		- (wep_entry_filter_cb, ws_wep_key_new): filter key entry input and
			allow only those characters that the key algorithm allows.  Fixes
			gnome.org #332951



Modified:
   trunk/ChangeLog
   trunk/src/wireless-security/ws-wep-key.c

Modified: trunk/src/wireless-security/ws-wep-key.c
==============================================================================
--- trunk/src/wireless-security/ws-wep-key.c	(original)
+++ trunk/src/wireless-security/ws-wep-key.c	Thu Jan 24 04:33:30 2008
@@ -119,6 +119,46 @@
 	}
 }
 
+static void
+wep_entry_filter_cb (GtkEntry *   entry,
+                     const gchar *text,
+                     gint         length,
+                     gint *       position,
+                     gpointer     data)
+{
+	WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) data;
+	GtkEditable *editable = GTK_EDITABLE (entry);
+	int i, count = 0;
+	gchar *result = g_new (gchar, length);
+
+	if (sec->type == WEP_KEY_TYPE_HEX) {
+		for (i = 0; i < length; i++) {
+			if (isxdigit(text[i]))
+				result[count++] = text[i];
+		}
+	} else if (sec->type == WEP_KEY_TYPE_ASCII) {
+		for (i = 0; i < length; i++) {
+			if (isascii(text[i]))
+				result[count++] = text[i];
+		}
+	}
+
+	if (count == 0)
+		goto out;
+
+	g_signal_handlers_block_by_func (G_OBJECT (editable),
+	                                 G_CALLBACK (wep_entry_filter_cb),
+	                                 data);
+	gtk_editable_insert_text (editable, result, count, position);
+	g_signal_handlers_unblock_by_func (G_OBJECT (editable),
+	                                   G_CALLBACK (wep_entry_filter_cb),
+	                                   data);
+
+out:
+	g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
+	g_free (result);
+}
+
 WirelessSecurityWEPKey *
 ws_wep_key_new (const char *glade_file,
                 NMConnection *connection,
@@ -159,6 +199,9 @@
 	g_signal_connect (G_OBJECT (widget), "changed",
 	                  (GCallback) wireless_security_changed_cb,
 	                  sec);
+	g_signal_connect (G_OBJECT (widget), "insert-text",
+	                  (GCallback) wep_entry_filter_cb,
+	                  sec);
 
 	widget = glade_xml_get_widget (xml, "show_checkbutton");
 	g_assert (widget);



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