Diff between f493c77f9ac37cf17b2206a02cb9192bfa1394b5 and 365a597557e3d368b69f84aaeb4b020f299fea20

Changed Files

File Additions Deletions Status
src/profile.c +31 -14 modified
src/profile.h +1 -1 modified

Full Patch

diff --git a/src/profile.c b/src/profile.c
index 9c8cfa0..c838c1d 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 27ccdd3..d858925 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,