aboutsummaryrefslogtreecommitdiffstats
path: root/src/storage.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2010-09-20 18:58:57 -0300
committerAnderson Lizardo <anderson.lizardo@openbossa.org>2010-09-22 16:00:04 -0400
commit727ae28e17be0910c9d5cdba6c8e373a704f7dbf (patch)
tree154bd22e5a486da63d1e680806a0e5a30f0c1748 /src/storage.c
parentd74b6fd61f4cf3b7d5953d3d1fc08fa2f663874c (diff)
downloadbluez-727ae28e17be0910c9d5cdba6c8e373a704f7dbf.tar.gz
bluez-727ae28e17be0910c9d5cdba6c8e373a704f7dbf.tar.xz
bluez-727ae28e17be0910c9d5cdba6c8e373a704f7dbf.zip
Delete all stored data related to GATT/ATT when the device is removed
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c
index 8bfe953a..06b36f19 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -48,6 +48,11 @@
#include "glib-helper.h"
#include "storage.h"
+struct match {
+ GSList *keys;
+ char *pattern;
+};
+
static inline int create_filename(char *buf, size_t size,
const bdaddr_t *bdaddr, const char *name)
{
@@ -1252,6 +1257,69 @@ int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
return textfile_put(filename, addr, services);
}
+static void filter_keys(char *key, char *value, void *data)
+{
+ struct match *match = data;
+ const char *address = match->pattern;
+
+ /* Each key contains: MAC#handle*/
+ if (g_strncasecmp(key, address, 17) == 0)
+ match->keys = g_slist_append(match->keys, g_strdup(key));
+}
+
+int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba)
+{
+ GSList *l;
+ struct match match;
+ char filename[PATH_MAX + 1], address[18];
+ int err;
+
+ create_filename(filename, PATH_MAX, sba, "primary");
+
+ memset(address, 0, sizeof(address));
+ ba2str(dba, address);
+
+ err = textfile_del(filename, address);
+ if (err < 0)
+ return err;
+
+ /* Deleting all characteristics of a given address */
+ memset(&match, 0, sizeof(match));
+ match.pattern = address;
+
+ create_filename(filename, PATH_MAX, sba, "characteristic");
+ err = textfile_foreach(filename, filter_keys, &match);
+ if (err < 0)
+ return err;
+
+ for (l = match.keys; l; l = l->next) {
+ const char *key = l->data;
+ textfile_del(filename, key);
+ }
+
+ g_slist_foreach(match.keys, (GFunc) g_free, NULL);
+ g_slist_free(match.keys);
+
+ /* Deleting all attributes values of a given address */
+ memset(&match, 0, sizeof(match));
+ match.pattern = address;
+
+ create_filename(filename, PATH_MAX, sba, "attributes");
+ err = textfile_foreach(filename, filter_keys, &match);
+ if (err < 0)
+ return err;
+
+ for (l = match.keys; l; l = l->next) {
+ const char *key = l->data;
+ textfile_del(filename, key);
+ }
+
+ g_slist_foreach(match.keys, (GFunc) g_free, NULL);
+ g_slist_free(match.keys);
+
+ return 0;
+}
+
char *read_device_services(const bdaddr_t *sba, const bdaddr_t *dba)
{
char filename[PATH_MAX + 1], addr[18];