OSDN Git Service

Fix handling of SDP records.
authorJaikumar Ganesh <jaikumar@google.com>
Fri, 30 Oct 2009 16:29:02 +0000 (09:29 -0700)
committerJaikumar Ganesh <jaikumar@google.com>
Fri, 30 Oct 2009 16:31:39 +0000 (09:31 -0700)
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
src/storage.c
src/storage.h

index 7c6ce4e..2aaf5b8 100644 (file)
@@ -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);
index 47c401b..e2d7632 100644 (file)
@@ -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];
index 6288da2..de0e837 100644 (file)
@@ -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,