diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2012-12-21 17:23:22 +0200 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2012-12-21 17:23:22 +0200 |
commit | 365a597557e3d368b69f84aaeb4b020f299fea20 (patch) | |
tree | 96b33a68e58102ce00f2cecbc8be58cf146d8de8 /src | |
parent | f493c77f9ac37cf17b2206a02cb9192bfa1394b5 (diff) | |
download | bluez-365a597557e3d368b69f84aaeb4b020f299fea20.tar.gz |
core: Fix being able to register the same custom property multiple times
btd_profile_add_custom_prop should check if the a property with the same
name already exists, in addition to that btd_profile_add_custom_prop now
returns a boolean indicating the success or failure of the operation.
Diffstat (limited to 'src')
-rw-r--r-- | src/profile.c | 45 | ||||
-rw-r--r-- | src/profile.h | 2 |
2 files changed, 32 insertions, 15 deletions
diff --git a/src/profile.c b/src/profile.c index 9c8cfa095..c838c1dc1 100644 --- a/src/profile.c +++ b/src/profile.c @@ -2204,7 +2204,25 @@ static const GDBusMethodTable methods[] = { { } }; -void btd_profile_add_custom_prop(const char *uuid, const char *type, +static struct btd_profile_custom_property *find_custom_prop(const char *uuid, + const char *name) +{ + GSList *l; + + for (l = custom_props; l; l = l->next) { + struct btd_profile_custom_property *prop = l->data; + + if (strcasecmp(prop->uuid, uuid) != 0) + continue; + + if (g_strcmp0(prop->name, name) == 0) + return prop; + } + + return NULL; +} + +bool btd_profile_add_custom_prop(const char *uuid, const char *type, const char *name, btd_profile_prop_exists exists, btd_profile_prop_get get, @@ -2212,6 +2230,10 @@ void btd_profile_add_custom_prop(const char *uuid, const char *type, { struct btd_profile_custom_property *prop; + prop = find_custom_prop(uuid, name); + if (prop != NULL) + return false; + prop = g_new0(struct btd_profile_custom_property, 1); prop->uuid = g_strdup(uuid); @@ -2222,6 +2244,8 @@ void btd_profile_add_custom_prop(const char *uuid, const char *type, prop->user_data = user_data; custom_props = g_slist_append(custom_props, prop); + + return true; } static void free_property(gpointer data) @@ -2237,21 +2261,14 @@ static void free_property(gpointer data) bool btd_profile_remove_custom_prop(const char *uuid, const char *name) { - GSList *l; - - for (l = custom_props; l; l = l->next) { - struct btd_profile_custom_property *prop = l->data; - - if (strcasecmp(prop->uuid, uuid) != 0) - continue; + struct btd_profile_custom_property *prop; - if (g_strcmp0(prop->name, name) != 0) - continue; + prop = find_custom_prop(uuid, name); + if (prop == NULL) + return false; - custom_props = g_slist_delete_link(custom_props, l); - free_property(prop); - return true; - } + custom_props = g_slist_remove(custom_props, prop); + free_property(prop); return false; } diff --git a/src/profile.h b/src/profile.h index 27ccdd3a4..d858925d8 100644 --- a/src/profile.h +++ b/src/profile.h @@ -67,7 +67,7 @@ typedef bool (*btd_profile_prop_get)(const char *uuid, DBusMessageIter *iter, void *user_data); -void btd_profile_add_custom_prop(const char *uuid, const char *type, +bool btd_profile_add_custom_prop(const char *uuid, const char *type, const char *name, btd_profile_prop_exists exists, btd_profile_prop_get get, |