From 9c2b1e35d6a6f06870d2ad309e406b5ad532a0c9 Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Fri, 30 Oct 2009 09:29:02 -0700 Subject: [PATCH] Fix handling of SDP records. Delete SDP records when device is deleted. Update cache whenever SDP is performed. Remove SDP records even when there is no driver associated with the UUID. Bug: 2173752 Dr No: Eastham --- src/device.c | 40 ++++++++++++++++++++++------------------ src/storage.c | 20 ++++++++++++++++++++ src/storage.h | 1 + 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/device.c b/src/device.c index 7c6ce4e40..2aaf5b888 100644 --- a/src/device.c +++ b/src/device.c @@ -1016,9 +1016,11 @@ static void device_remove_stored(struct btd_device *device, adapter_get_address(device->adapter, &src); ba2str(&device->bdaddr, addr); + device_remove_bonding(device, conn); delete_entry(&src, "profiles", addr); delete_entry(&src, "trusts", addr); + delete_all_records(&src, &device->bdaddr); } void device_remove(struct btd_device *device, DBusConnection *conn, @@ -1213,8 +1215,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; @@ -1227,24 +1227,28 @@ 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; + } + } - delete_record(srcaddr, dstaddr, rec->handle); + for (list = uuids; list; list = list->next) { + sdp_record_t *rec; - records = sdp_list_remove(records, rec); - sdp_record_free(rec); + device->uuids = g_slist_remove(device->uuids, list->data); + + rec = find_record_in_list(records, list->data); + if (!rec) + continue; + + delete_record(srcaddr, dstaddr, rec->handle); + + 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) @@ -1386,11 +1390,6 @@ static void search_cb(sdp_list_t *recs, int err, gpointer user_data) update_services(req, recs); - if (!req->profiles_added && !req->profiles_removed) { - debug("%s: No service update", device->path); - goto proceed; - } - if (device->tmp_records && req->records) { sdp_list_free(device->tmp_records, (sdp_free_func_t) sdp_record_free); @@ -1398,6 +1397,11 @@ static void search_cb(sdp_list_t *recs, int err, gpointer user_data) req->records = NULL; } + if (!req->profiles_added && !req->profiles_removed) { + debug("%s: No service update", device->path); + goto proceed; + } + /* Probe matching drivers for services added */ if (req->profiles_added) device_probe_drivers(device, req->profiles_added); diff --git a/src/storage.c b/src/storage.c index 47c401b72..e2d7632fa 100644 --- a/src/storage.c +++ b/src/storage.c @@ -908,6 +908,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 6288da218..de0e8370e 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, -- 2.11.0