[gnome-bluetooth] settings: Add vendor attribute for PIN database



commit 720506b00ec1f89f03fd9e90ec8e24968e0a3f21
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Dec 9 23:38:14 2013 +0100

    settings: Add vendor attribute for PIN database
    
    Allows us to remove hard-coded OUIs in the database.

 lib/pin-code-database.xml |    1 +
 lib/pin.c                 |   13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/lib/pin-code-database.xml b/lib/pin-code-database.xml
index fc4cd89..2a529f1 100644
--- a/lib/pin-code-database.xml
+++ b/lib/pin-code-database.xml
@@ -45,6 +45,7 @@
        <!ELEMENT device EMPTY>
        <!ATTLIST device type (any|mouse|tablet|keyboard|headset|headphones|audio|printer|network) "any">
        <!ATTLIST device oui CDATA #IMPLIED>
+       <!ATTLIST device vendor CDATA #IMPLIED>
        <!ATTLIST device name CDATA #IMPLIED>
        <!ATTLIST device pin CDATA #REQUIRED>
 ]>
diff --git a/lib/pin.c b/lib/pin.c
index 74e6c87..df4b1c3 100644
--- a/lib/pin.c
+++ b/lib/pin.c
@@ -111,6 +111,7 @@ typedef struct {
        guint type;
        const char *address;
        const char *name;
+       char *vendor;
        gboolean confirm;
 } PinParseData;
 
@@ -139,6 +140,11 @@ pin_db_parse_start_tag (GMarkupParseContext *ctx,
                } else if (g_str_equal (*attr_names, "oui")) {
                        if (g_str_has_prefix (pdata->address, *attr_values) == FALSE)
                                return;
+               } else if (g_str_equal (*attr_names, "vendor")) {
+                       if (*attr_values == NULL || pdata->vendor == NULL)
+                               return;
+                       if (strstr (pdata->vendor, *attr_values) == NULL)
+                               return;
                } else if (g_str_equal (*attr_names, "name")) {
                        if (*attr_values == NULL || pdata->name == NULL)
                                return;
@@ -197,6 +203,7 @@ get_pincode_for_device (guint       type,
        data.type = type;
        data.address = address;
        data.name = name;
+       data.vendor = oui_to_vendor (address);
        data.confirm = TRUE;
 
        ctx = g_markup_parse_context_new (&parser, 0, &data, NULL);
@@ -214,9 +221,11 @@ get_pincode_for_device (guint       type,
        if (confirm != NULL)
                *confirm = data.confirm;
 
-       g_debug ("Got pin '%s' (max digits: %d) for device '%s' (type: %s address: %s)",
+       g_debug ("Got pin '%s' (max digits: %d) for device '%s' (type: %s address: %s, vendor: %s)",
                 data.ret_pin, data.max_digits,
-                name ? name : "", bluetooth_type_to_string (type), address);
+                name ? name : "", bluetooth_type_to_string (type), address, data.vendor);
+
+       g_free (data.vendor);
 
        return data.ret_pin;
 }


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