Re: [PATCH] Update SDP storage records when a record is deleted.

Jaikumar Ganesh
2009-10-29T18:42:16Z

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Hi Johan:

On Wed, Oct 28, 2009 at 5:15 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi,
>
> On Wed, Oct 28, 2009, Jaikumar Ganesh wrote:
>> > On Wed, Oct 28, 2009, Jaikumar Ganesh wrote:
>> >> The SDP cache is  removed when the device is removed. In fact, you
>> >> fixed this a few days back.
>> >
>> > Which commit are you referring to?
>>
>> Commit number:
>>
>> 4bec43039626e853489e72149014868f8c8afedc
>>
>> http://git.kernel.org/?p=bluetooth/bluez.git;a=commit;h=4bec43039626e853489e72149014868f8c8afedc
>
> Ok, so we're talking about different things here. I was talking about
> removing the records from /var/lib/bluetooth/...
>
>> We can also fix this by removing the on disk SDP records when the
>> device is freed.
>> (I think which is what you suggested - by cache I was interpreting it
>> as in memory cache)
>> Will submit a new patch. Let me know if I read you wrong.
>
> No, you're right. I was referring to the disk cache. I'm glad we have this
> misunderstanding finally sorted out :)

New patch attached.

>
> Johan
>

[-- Attachment #2: 0001-Fix-handling-of-SDP-records.patch --]
[-- Type: text/x-diff, Size: 3889 bytes --]

From 3b973c8a8fcc32ac9fe8ef939932800d70b59e48 Mon Sep 17 00:00:00 2001
From: Jaikumar Ganesh <jaikumar@google.com>
Date: Thu, 29 Oct 2009 11:23:25 -0700
Subject: [PATCH] Fix handling of SDP records.

1. Delete all SDP records when the device is removed.
We are going to do the SDP connection again anyways next time.
This fixes the issues of stale SDP records.
2. Handle deletion of SDP records even when there is no driver
registered for that UUID
---
src/device.c | 29 ++++++++++++++++-------------
src/storage.c | 20 ++++++++++++++++++++
src/storage.h | 1 +
3 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/device.c b/src/device.c
index 6cb9641..760e661 100644
--- a/src/device.c
+++ b/src/device.c
@@ -937,10 +937,12 @@ static void device_remove_stored(struct btd_device *device)

adapter_get_address(device->adapter, &src);
ba2str(&device->bdaddr, addr);
+
if (device->paired)
device_remove_bonding(device);
delete_entry(&src, "profiles", addr);
delete_entry(&src, "trusts", addr);
+ delete_all_records(&src, &device->bdaddr);
}

void device_remove(struct btd_device *device, gboolean remove_stored)
@@ -1134,8 +1136,6 @@ static void device_remove_drivers(struct btd_device *device, GSList *uuids)
next = list->next;

for (uuid = driver->uuids; *uuid; uuid++) {
- sdp_record_t *rec;
-
if (!g_slist_find_custom(uuids, *uuid,
(GCompareFunc) strcasecmp))
continue;
@@ -1148,24 +1148,27 @@ static void device_remove_drivers(struct btd_device *device, GSList *uuids)
driver_data);
g_free(driver_data);

- rec = find_record_in_list(records, *uuid);
- if (!rec)
- break;
+ break;
+ }
+ }
+
+ for (list = uuids; list; list = list->next) {
+ device->uuids = g_slist_remove(device->uuids, list->data);
+
+ sdp_record_t *rec;
+ rec = find_record_in_list(records, list->data);
+ if (!rec)
+ continue;

- delete_record(srcaddr, dstaddr, rec->handle);
+ delete_record(srcaddr, dstaddr, rec->handle);

- records = sdp_list_remove(records, rec);
- sdp_record_free(rec);
+ records = sdp_list_remove(records, rec);
+ sdp_record_free(rec);

- break;
- }
}

if (records)
sdp_list_free(records, (sdp_free_func_t) sdp_record_free);
-
- for (list = uuids; list; list = list->next)
- device->uuids = g_slist_remove(device->uuids, list->data);
}

static void services_changed(struct btd_device *device)
diff --git a/src/storage.c b/src/storage.c
index 5760656..cd33206 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -913,6 +913,26 @@ static void create_stored_records_from_keys(char *key, char *value,
rec_list->recs = sdp_list_append(rec_list->recs, rec);
}

+void delete_all_records(bdaddr_t *src, bdaddr_t *dst)
+{
+ sdp_list_t *records, *seq;
+ sdp_record_t *rec;
+ char srcaddr[18], dstaddr[18];
+
+ ba2str(src, srcaddr);
+ ba2str(dst, dstaddr);
+
+ records = read_records(src, dst);
+
+ for (seq = records; seq; seq = seq->next) {
+ rec = seq->data;
+ delete_record(srcaddr, dstaddr, rec->handle);
+ }
+
+ if (records)
+ sdp_list_free(records, (sdp_free_func_t) sdp_record_free);
+}
+
sdp_list_t *read_records(bdaddr_t *src, bdaddr_t *dst)
{
char filename[PATH_MAX + 1];
diff --git a/src/storage.h b/src/storage.h
index 3159f2a..6e40151 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -63,6 +63,7 @@ int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec);
sdp_record_t *record_from_string(const gchar *str);
sdp_record_t *fetch_record(const gchar *src, const gchar *dst, const uint32_t handle);
int delete_record(const gchar *src, const gchar *dst, const uint32_t handle);
+void delete_all_records(bdaddr_t *src, bdaddr_t *dst);
sdp_list_t *read_records(bdaddr_t *src, bdaddr_t *dst);
sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
int store_device_id(const gchar *src, const gchar *dst,
--
1.6.2.3