From 03a29a33d6b25dde33275498e761a1c37ed0b00b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Dec 2012 09:48:48 -0800 Subject: [PATCH] core: Return VendorSource as string and only allow supported values --- src/device.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/device.c b/src/device.c index 7aa752c94..e7e70d363 100644 --- a/src/device.c +++ b/src/device.c @@ -640,6 +640,9 @@ static gboolean dev_property_exists_vendor(const GDBusPropertyTable *property, { struct btd_device *device = data; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + return !!device->vendor; } @@ -648,6 +651,9 @@ static gboolean dev_property_get_vendor(const GDBusPropertyTable *property, { struct btd_device *device = data; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + if (!device->vendor) return FALSE; @@ -661,19 +667,31 @@ static gboolean dev_property_exists_vendor_src( { struct btd_device *device = data; - return !!device->vendor_src; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + + return TRUE; } static gboolean dev_property_get_vendor_src(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { struct btd_device *device = data; + const char *str; - if (!device->vendor_src) + switch (device->vendor_src) { + case 1: + str = "bluetooth"; + break; + case 2: + str = "usb"; + break; + default: return FALSE; + } + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str); - dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, - &device->vendor_src); return TRUE; } @@ -682,6 +700,9 @@ static gboolean dev_property_exists_product(const GDBusPropertyTable *property, { struct btd_device *device = data; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + return !!device->product; } @@ -690,6 +711,9 @@ static gboolean dev_property_get_product(const GDBusPropertyTable *property, { struct btd_device *device = data; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + if (!device->product) return FALSE; @@ -704,6 +728,9 @@ static gboolean dev_property_exists_version(const GDBusPropertyTable *property, { struct btd_device *device = data; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + return !!device->version; } @@ -712,6 +739,9 @@ static gboolean dev_property_get_version(const GDBusPropertyTable *property, { struct btd_device *device = data; + if (device->vendor_src < 1 || device->vendor_src > 2) + return FALSE; + if (!device->version) return FALSE; @@ -1601,7 +1631,7 @@ static const GDBusPropertyTable device_properties[] = { dev_property_exists_icon }, { "Vendor", "q", dev_property_get_vendor, NULL, dev_property_exists_vendor }, - { "VendorSource", "q", dev_property_get_vendor_src, NULL, + { "VendorSource", "s", dev_property_get_vendor_src, NULL, dev_property_exists_vendor_src }, { "Product", "q", dev_property_get_product, NULL, dev_property_exists_product }, -- 2.47.3