summaryrefslogtreecommitdiffstats
path: root/hcid/storage.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-04-09 00:12:36 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-04-09 00:12:36 +0000
commite0d05942e436393256b61f111d5924add57840c7 (patch)
tree3657026fe793e6e051022d90728369578a7bec9b /hcid/storage.c
parent8fa8629fa44075dfa41b1bff96a7951dd40cfb0a (diff)
* Add D-Bus methods for getting remote device class information
* Fix a couple of memory leaks where result of textfile_get wasn't free'd
Diffstat (limited to 'hcid/storage.c')
-rw-r--r--hcid/storage.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/hcid/storage.c b/hcid/storage.c
index 17f0744a..e3781278 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -122,6 +122,44 @@ int read_local_class(bdaddr_t *bdaddr, uint8_t *class)
return 0;
}
+int write_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class)
+{
+ char filename[PATH_MAX + 1], addr[18], str[9];
+
+ ba2str(local, addr);
+ snprintf(filename, PATH_MAX, "%s/%s/classes", STORAGEDIR, addr);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ ba2str(peer, addr);
+ sprintf(str, "0x%6.6x", class);
+
+ return textfile_put(filename, addr, str);
+}
+
+int read_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t *class)
+{
+ char filename[PATH_MAX + 1], addr[18], *str;
+
+ ba2str(local, addr);
+ snprintf(filename, PATH_MAX, "%s/%s/classes", STORAGEDIR, addr);
+
+ ba2str(peer, addr);
+
+ str = textfile_get(filename, addr);
+ if (!str)
+ return -ENOENT;
+
+ if (sscanf(str, "%x", class) != 1) {
+ free(str);
+ return -ENOENT;
+ }
+
+ free(str);
+
+ return 0;
+}
+
int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name)
{
char filename[PATH_MAX + 1], addr[18], str[249];
@@ -251,8 +289,11 @@ int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, int type
if (length < 0) {
char *tmp = textfile_get(filename, addr);
- if (tmp && strlen(tmp) > 34)
- memcpy(str + 34, tmp + 34, 3);
+ if (tmp) {
+ if (strlen(tmp) > 34)
+ memcpy(str + 34, tmp + 34, 3);
+ free(tmp);
+ }
}
return textfile_put(filename, addr, str);
@@ -295,8 +336,10 @@ int read_pin_length(bdaddr_t *local, bdaddr_t *peer)
if (!str)
return -ENOENT;
- if (strlen(str) < 36)
+ if (strlen(str) < 36) {
+ free(str);
return -ENOENT;
+ }
len = atoi(str + 35);