summaryrefslogtreecommitdiffstats
path: root/src/device.c
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-08-27 17:13:41 -0300
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-08-28 19:06:20 -0300
commit506c95298346d318304aa7e2211dfba5dbe6e3e0 (patch)
tree62af6becaa65369986bdc25a31572841f972bd26 /src/device.c
parent5ec5ef30ffd7e743499462bd7b3bfde0e65e2bb4 (diff)
Storage cleanup
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c85
1 files changed, 24 insertions, 61 deletions
diff --git a/src/device.c b/src/device.c
index 3c75cedf..62471a15 100644
--- a/src/device.c
+++ b/src/device.c
@@ -41,11 +41,10 @@
#include <dbus/dbus.h>
#include <gdbus.h>
-#include "hcid.h"
-
#include "logging.h"
#include "textfile.h"
+#include "hcid.h"
#include "adapter.h"
#include "device.h"
#include "dbus-common.h"
@@ -54,6 +53,7 @@
#include "glib-helper.h"
#include "agent.h"
#include "sdp-xml.h"
+#include "storage.h"
#define DEFAULT_XML_BUF_SIZE 1024
#define DISCONNECT_TIMER 2
@@ -136,16 +136,6 @@ static gboolean device_is_paired(struct btd_device *device)
return ret;
}
-static char *device_get_name(struct btd_device *device)
-{
- struct adapter *adapter = device->adapter;
- char filename[PATH_MAX + 1];
- const gchar *source = adapter_get_address(adapter);
-
- create_name(filename, PATH_MAX, STORAGEDIR, source, "names");
- return textfile_caseget(filename, device->address);
-}
-
static DBusMessage *get_properties(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
@@ -155,10 +145,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
DBusMessageIter iter;
DBusMessageIter dict;
bdaddr_t src, dst;
- char path[MAX_PATH_LENGTH];
- char buf[64];
+ char path[MAX_PATH_LENGTH], name[248];
+ char *ppath, **uuids;
const char *ptr;
- char *name, *ppath, **uuids;
dbus_bool_t boolean;
uint32_t class;
int i;
@@ -182,12 +171,22 @@ static DBusMessage *get_properties(DBusConnection *conn,
&device->address);
/* Name */
- name = device_get_name(device);
- if (name) {
+ ptr = NULL;
+ memset(name, 0, sizeof(name));
+ if (read_device_name(source, device->address, name) == 0) {
+ ptr = name;
dbus_message_iter_append_dict_entry(&dict, "Name",
- DBUS_TYPE_STRING, &name);
+ DBUS_TYPE_STRING, &ptr);
}
+ if (read_device_alias(source, device->address, name, sizeof(name)) > 0)
+ ptr = name;
+
+ /* Alias: use Name if Alias doesn't exist */
+ if (ptr)
+ dbus_message_iter_append_dict_entry(&dict, "Alias",
+ DBUS_TYPE_STRING, &ptr);
+
str2ba(source, &src);
str2ba(device->address, &dst);
@@ -197,17 +196,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
DBUS_TYPE_UINT32, &class);
}
- /* Alias */
- if (get_device_alias(dev_id, &dst, buf, sizeof(buf)) > 0) {
- ptr = buf;
- dbus_message_iter_append_dict_entry(&dict, "Alias",
- DBUS_TYPE_STRING, &ptr);
- } else if (name) {
- dbus_message_iter_append_dict_entry(&dict, "Alias",
- DBUS_TYPE_STRING, &name);
- free(name);
- }
-
/* Paired */
boolean = device_is_paired(device);
dbus_message_iter_append_dict_entry(&dict, "Paired",
@@ -247,50 +235,25 @@ static DBusMessage *get_properties(DBusConnection *conn,
return reply;
}
-static int remove_device_alias(const char *source, const char *destination)
-{
- char filename[PATH_MAX + 1];
-
- create_name(filename, PATH_MAX, STORAGEDIR, source, "aliases");
- create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
- return textfile_del(filename, destination);
-}
-
static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
const char *alias, void *data)
{
struct btd_device *device = data;
struct adapter *adapter = device->adapter;
- bdaddr_t bdaddr;
- int ecode;
- char *str, filename[PATH_MAX + 1];
- uint16_t dev_id = adapter_get_dev_id(adapter);
const gchar *source = adapter_get_address(adapter);
-
- str2ba(device->address, &bdaddr);
+ int err;
/* Remove alias if empty string */
- if (g_str_equal(alias, "")) {
- create_name(filename, PATH_MAX, STORAGEDIR, source,
- "names");
- str = textfile_caseget(filename, device->address);
- ecode = remove_device_alias(source, device->address);
- } else {
- str = g_strdup(alias);
- ecode = set_device_alias(dev_id, &bdaddr, alias);
- }
-
- if (ecode < 0)
+ err = write_device_alias(source, device->address,
+ g_str_equal(alias, "") ? NULL : alias);
+ if (err < 0)
return g_dbus_create_error(msg,
ERROR_INTERFACE ".Failed",
- strerror(-ecode));
+ strerror(-err));
dbus_connection_emit_property_changed(conn, dbus_message_get_path(msg),
DEVICE_INTERFACE, "Alias",
- DBUS_TYPE_STRING, &str);
-
- g_free(str);
+ DBUS_TYPE_STRING, &alias);
return dbus_message_new_method_return(msg);
}
@@ -350,7 +313,7 @@ static DBusMessage *set_property(DBusConnection *conn,
return set_trust(conn, msg, value, data);
} else if (g_str_equal("Alias", property)) {
- char *alias;
+ const char *alias;
if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
return invalid_args(msg);