gnome-bluetooth r345 - trunk/common



Author: hadess
Date: Wed Feb 25 14:41:53 2009
New Revision: 345
URL: http://svn.gnome.org/viewvc/gnome-bluetooth?rev=345&view=rev

Log:
Add function to verify whether a bdaddr is valid

Similar to what's available in libbluetooth, but LGPL.

Modified:
   trunk/common/bluetooth-client.c
   trunk/common/bluetooth-client.h

Modified: trunk/common/bluetooth-client.c
==============================================================================
--- trunk/common/bluetooth-client.c	(original)
+++ trunk/common/bluetooth-client.c	Wed Feb 25 14:41:53 2009
@@ -117,6 +117,35 @@
 	}
 }
 
+gboolean
+bluetooth_verify_address (const char *bdaddr)
+{
+	gboolean retval = TRUE;
+	char **elems;
+
+	g_return_val_if_fail (bdaddr != NULL, FALSE);
+
+	if (strlen (bdaddr) != 17)
+		return FALSE;
+
+	elems = g_strsplit (bdaddr, ":", -1);
+	if (elems == NULL)
+		return FALSE;
+	if (g_strv_length (elems) != 6) {
+		g_strfreev (elems);
+		return FALSE;
+	}
+	for (i = 0; i < 6; i++) {
+		if (g_ascii_isxdigit (elems[i][0]) == FALSE || g_ascii_isxdigit (elems[i][1]) == FALSE) {
+			retval = FALSE;
+			break;
+		}
+	}
+
+	g_strfreev (elems);
+	return retval;
+}
+
 static guint class_to_type(guint32 class)
 {
 	switch ((class & 0x1f00) >> 8) {

Modified: trunk/common/bluetooth-client.h
==============================================================================
--- trunk/common/bluetooth-client.h	(original)
+++ trunk/common/bluetooth-client.h	Wed Feb 25 14:41:53 2009
@@ -106,6 +106,7 @@
 				BluetoothClientConnectFunc, gpointer data);
 
 const gchar *bluetooth_type_to_string(guint type);
+gboolean bluetooth_verify_address (const char *bdaddr);
 
 G_END_DECLS
 



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