aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2012-05-11 17:05:18 -0300
committerPaulo Alcantara <paulo.alcantara@openbossa.org>2012-05-22 00:53:35 -0300
commitbb0534e1da02812665174ab0a345bf4fd128c253 (patch)
tree5a7d96bbc9876e29b6ad8c2d577430be5ef23f36
parent00c9d1cd4ca1e3e8eaf0c1226c0c8fc48fa0dabe (diff)
downloadbluez-bb0534e1da02812665174ab0a345bf4fd128c253.tar.gz
bluez-bb0534e1da02812665174ab0a345bf4fd128c253.tar.xz
bluez-bb0534e1da02812665174ab0a345bf4fd128c253.zip
storage: Store address type in alias file
-rw-r--r--src/device.c7
-rw-r--r--src/storage.c22
-rw-r--r--src/storage.h6
3 files changed, 27 insertions, 8 deletions
diff --git a/src/device.c b/src/device.c
index 768ff31c..aeedf90a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -458,8 +458,8 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
ba2str(&device->bdaddr, dstaddr);
/* Remove alias if empty string */
- err = write_device_alias(srcaddr, dstaddr,
- g_str_equal(alias, "") ? NULL : alias);
+ err = write_device_alias(srcaddr, dstaddr, device->bdaddr_type,
+ g_str_equal(alias, "") ? NULL : alias);
if (err < 0)
return btd_error_failed(msg, strerror(-err));
@@ -1077,7 +1077,8 @@ struct btd_device *device_create(DBusConnection *conn,
ba2str(&src, srcaddr);
read_device_name(srcaddr, address, bdaddr_type, device->name);
- if (read_device_alias(srcaddr, address, alias, sizeof(alias)) == 0)
+ if (read_device_alias(srcaddr, address, bdaddr_type, alias,
+ sizeof(alias)) == 0)
device->alias = g_strdup(alias);
device->trusted = read_trust(&src, address, GLOBAL_TRUST);
diff --git a/src/storage.c b/src/storage.c
index 793d8b6c..8762d589 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -61,17 +61,28 @@ static inline int create_filename(char *buf, size_t size,
return create_name(buf, size, STORAGEDIR, addr, name);
}
-int read_device_alias(const char *src, const char *dst, char *alias, size_t size)
+int read_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ char *alias, size_t size)
{
char filename[PATH_MAX + 1], *tmp;
+ char key[20];
int err;
create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
+ /* New format: address#type */
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ tmp = textfile_get(filename, key);
+ if (tmp)
+ goto done;
+
+ /* Old format: address only */
tmp = textfile_get(filename, dst);
if (!tmp)
return -ENXIO;
+done:
err = snprintf(alias, size, "%s", tmp);
free(tmp);
@@ -79,15 +90,20 @@ int read_device_alias(const char *src, const char *dst, char *alias, size_t size
return err < 0 ? -EIO : 0;
}
-int write_device_alias(const char *src, const char *dst, const char *alias)
+int write_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ const char *alias)
{
char filename[PATH_MAX + 1];
+ char key[20];
create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- return textfile_put(filename, dst, alias);
+ /* New format: address#type */
+ snprintf(key, sizeof(key), "%17s#%hhu", dst, bdaddr_type);
+
+ return textfile_put(filename, key, alias);
}
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)
diff --git a/src/storage.h b/src/storage.h
index 52b44dc7..666fad00 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -23,8 +23,10 @@
#include "textfile.h"
-int read_device_alias(const char *src, const char *dst, char *alias, size_t size);
-int write_device_alias(const char *src, const char *dst, const char *alias);
+int read_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ char *alias, size_t size);
+int write_device_alias(const char *src, const char *dst, uint8_t bdaddr_type,
+ const char *alias);
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout);
int read_discoverable_timeout(const char *src, int *timeout);
int write_pairable_timeout(bdaddr_t *bdaddr, int timeout);