diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-08-27 17:13:41 -0300 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2008-08-28 19:06:20 -0300 |
commit | 506c95298346d318304aa7e2211dfba5dbe6e3e0 (patch) | |
tree | 62af6becaa65369986bdc25a31572841f972bd26 /src | |
parent | 5ec5ef30ffd7e743499462bd7b3bfde0e65e2bb4 (diff) |
Storage cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/adapter.c | 8 | ||||
-rw-r--r-- | src/agent.c | 1 | ||||
-rw-r--r-- | src/dbus-common.c | 2 | ||||
-rw-r--r-- | src/dbus-hci.c | 1 | ||||
-rw-r--r-- | src/device.c | 85 | ||||
-rw-r--r-- | src/hcid.h | 46 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/manager.c | 40 | ||||
-rw-r--r-- | src/security.c | 3 | ||||
-rw-r--r-- | src/storage.c | 39 | ||||
-rw-r--r-- | src/storage.h | 61 |
11 files changed, 130 insertions, 160 deletions
diff --git a/src/adapter.c b/src/adapter.c index 91e7c454..afd909ba 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -45,21 +45,21 @@ #include <dbus/dbus.h> #include <gdbus.h> +#include "logging.h" +#include "textfile.h" + #include "hcid.h" #include "sdpd.h" - #include "manager.h" #include "adapter.h" #include "device.h" - -#include "textfile.h" #include "dbus-common.h" #include "dbus-hci.h" #include "dbus-database.h" #include "error.h" #include "glib-helper.h" -#include "logging.h" #include "agent.h" +#include "storage.h" #define NUM_ELEMENTS(table) (sizeof(table)/sizeof(const char *)) diff --git a/src/agent.c b/src/agent.c index dc95be65..9870cb10 100644 --- a/src/agent.c +++ b/src/agent.c @@ -35,6 +35,7 @@ #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> +#include <bluetooth/sdp.h> #include <glib.h> #include <dbus/dbus.h> diff --git a/src/dbus-common.c b/src/dbus-common.c index 1ef69308..c7853d29 100644 --- a/src/dbus-common.c +++ b/src/dbus-common.c @@ -36,6 +36,7 @@ #include <sys/ioctl.h> #include <bluetooth/bluetooth.h> +#include <bluetooth/hci.h> #include <bluetooth/l2cap.h> #include <glib.h> @@ -44,7 +45,6 @@ #include "logging.h" -#include "hcid.h" #include "manager.h" #include "adapter.h" #include "dbus-hci.h" diff --git a/src/dbus-hci.c b/src/dbus-hci.c index b713b16f..a7b83c0b 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -56,6 +56,7 @@ #include "glib-helper.h" #include "dbus-common.h" #include "agent.h" +#include "storage.h" static DBusConnection *connection = NULL; 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); @@ -23,10 +23,6 @@ * */ -#include <bluetooth/bluetooth.h> -#include <bluetooth/sdp.h> -#include <bluetooth/hci.h> - #define HCID_DEFAULT_DISCOVERABLE_TIMEOUT 180 /* 3 minutes */ /* When all services should trust a remote device */ @@ -108,48 +104,8 @@ void stop_security_manager(int hdev); void set_pin_length(bdaddr_t *sba, int length); -int get_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, char *alias, size_t size); -int set_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, const char *alias); - -int get_encryption_key_size(uint16_t dev_id, const bdaddr_t *baddr); - -int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout); -int read_discoverable_timeout(bdaddr_t *bdaddr, int *timeout); -int write_device_mode(bdaddr_t *bdaddr, const char *mode); -int read_device_mode(bdaddr_t *bdaddr, char *mode, int length); -int read_on_mode(const char *src, char *mode, int length); -int write_local_name(bdaddr_t *bdaddr, char *name); -int read_local_name(bdaddr_t *bdaddr, char *name); -int write_local_class(bdaddr_t *bdaddr, uint8_t *class); -int read_local_class(bdaddr_t *bdaddr, uint8_t *class); -int write_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class); -int read_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t *class); -int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name); -int read_device_name(bdaddr_t *local, bdaddr_t *peer, char *name); -int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data); -int write_l2cap_info(bdaddr_t *local, bdaddr_t *peer, - uint16_t mtu_result, uint16_t mtu, - uint16_t mask_result, uint32_t mask); -int read_l2cap_info(bdaddr_t *local, bdaddr_t *peer, - uint16_t *mtu_result, uint16_t *mtu, - uint16_t *mask_result, uint32_t *mask); -int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver); -int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *features); -int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm); -int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm); -int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length); -int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type); -int read_pin_length(bdaddr_t *local, bdaddr_t *peer); -int read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin); -gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service); -int write_trust(bdaddr_t *local, const char *addr, const char *service, gboolean trust); -GSList *list_trusts(bdaddr_t *local, const char *service); -int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles); -int delete_entry(bdaddr_t *src, const char *storage, const char *key); -int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec); -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); gboolean plugin_init(GKeyFile *config); void plugin_cleanup(void); + void __probe_servers(const char *adapter); void __remove_servers(const char *adapter); @@ -53,11 +53,11 @@ #include "hcid.h" #include "sdpd.h" #include "adapter.h" -#include "dbus-common.h" -#include "dbus-database.h" #include "dbus-hci.h" +#include "dbus-common.h" #include "agent.h" #include "manager.h" +#include "storage.h" struct hcid_opts hcid; struct device_opts default_device; diff --git a/src/manager.c b/src/manager.c index 0b6af1b5..2caaadf7 100644 --- a/src/manager.c +++ b/src/manager.c @@ -37,8 +37,6 @@ #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> -#include <bluetooth/sdp.h> -#include <bluetooth/sdp_lib.h> #include <glib.h> @@ -47,7 +45,6 @@ #include <gdbus.h> #include "logging.h" -#include "textfile.h" #include "adapter.h" #include "error.h" #include "manager.h" @@ -89,43 +86,6 @@ int manager_set_adapter_class(uint16_t dev_id, uint8_t *cls) return adapter_set_class(adapter, cls); } -int get_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, char *alias, size_t size) -{ - struct adapter *adapter = manager_find_adapter_by_id(dev_id); - char filename[PATH_MAX + 1], addr[18], *tmp; - int err; - const gchar *source = adapter_get_address(adapter); - - create_name(filename, PATH_MAX, STORAGEDIR, source, "aliases"); - - ba2str(bdaddr, addr); - - tmp = textfile_get(filename, addr); - if (!tmp) - return -ENXIO; - - err = snprintf(alias, size, "%s", tmp); - - free(tmp); - - return err; -} - -int set_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, const char *alias) -{ - struct adapter *adapter = manager_find_adapter_by_id(dev_id); - const gchar *source = adapter_get_address(adapter); - char filename[PATH_MAX + 1], addr[18]; - - create_name(filename, PATH_MAX, STORAGEDIR, source, "aliases"); - - create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - - ba2str(bdaddr, addr); - - return textfile_put(filename, addr, alias); -} - static inline DBusMessage *invalid_args(DBusMessage *msg) { return g_dbus_create_error(msg, diff --git a/src/security.c b/src/security.c index 5c295574..fd2535fd 100644 --- a/src/security.c +++ b/src/security.c @@ -40,6 +40,7 @@ #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> +#include <bluetooth/sdp.h> #include <glib.h> @@ -48,9 +49,9 @@ #include "logging.h" #include "textfile.h" -#include "hcid.h" #include "adapter.h" #include "dbus-hci.h" +#include "storage.h" typedef enum { REQ_PENDING, diff --git a/src/storage.c b/src/storage.c index 7a9c5989..3cdc9113 100644 --- a/src/storage.c +++ b/src/storage.c @@ -45,7 +45,6 @@ #include <bluetooth/sdp_lib.h> #include "textfile.h" -#include "hcid.h" static inline int create_filename(char *buf, size_t size, const bdaddr_t *bdaddr, const char *name) { @@ -56,6 +55,35 @@ static inline int create_filename(char *buf, size_t size, const bdaddr_t *bdaddr return create_name(buf, size, STORAGEDIR, addr, name); } +int read_device_alias(const char *src, const char *dst, char *alias, size_t size) +{ + char filename[PATH_MAX + 1], *tmp; + int err; + + create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases"); + + tmp = textfile_get(filename, dst); + if (!tmp) + return -ENXIO; + + err = snprintf(alias, size, "%s", tmp); + + free(tmp); + + return err; +} + +int write_device_alias(const char *src, const char *dst, const char *alias) +{ + char filename[PATH_MAX + 1]; + + 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); +} + int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout) { char filename[PATH_MAX + 1], str[32]; @@ -270,15 +298,14 @@ int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name) return textfile_put(filename, addr, str); } -int read_device_name(bdaddr_t *local, bdaddr_t *peer, char *name) +int read_device_name(const char *src, const char *dst, char *name) { - char filename[PATH_MAX + 1], addr[18], *str; + char filename[PATH_MAX + 1], *str; int len; - create_filename(filename, PATH_MAX, local, "names"); + create_name(filename, PATH_MAX, STORAGEDIR, src, "names"); - ba2str(peer, addr); - str = textfile_get(filename, addr); + str = textfile_get(filename, dst); if (!str) return -ENOENT; diff --git a/src/storage.h b/src/storage.h new file mode 100644 index 00000000..a9bda390 --- /dev/null +++ b/src/storage.h @@ -0,0 +1,61 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2002-2008 Marcel Holtmann <marcel@holtmann.org> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +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 write_discoverable_timeout(bdaddr_t *bdaddr, int timeout); +int read_discoverable_timeout(bdaddr_t *bdaddr, int *timeout); +int write_device_mode(bdaddr_t *bdaddr, const char *mode); +int read_device_mode(bdaddr_t *bdaddr, char *mode, int length); +int read_on_mode(const char *src, char *mode, int length); +int write_local_name(bdaddr_t *bdaddr, char *name); +int read_local_name(bdaddr_t *bdaddr, char *name); +int write_local_class(bdaddr_t *bdaddr, uint8_t *class); +int read_local_class(bdaddr_t *bdaddr, uint8_t *class); +int write_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class); +int read_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t *class); +int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name); +int read_device_name(const char *src, const char *dst, char *name); +int write_remote_eir(bdaddr_t *local, bdaddr_t *peer, uint8_t *data); +int write_l2cap_info(bdaddr_t *local, bdaddr_t *peer, + uint16_t mtu_result, uint16_t mtu, + uint16_t mask_result, uint32_t mask); +int read_l2cap_info(bdaddr_t *local, bdaddr_t *peer, + uint16_t *mtu_result, uint16_t *mtu, + uint16_t *mask_result, uint32_t *mask); +int write_version_info(bdaddr_t *local, bdaddr_t *peer, uint16_t manufacturer, uint8_t lmp_ver, uint16_t lmp_subver); +int write_features_info(bdaddr_t *local, bdaddr_t *peer, unsigned char *features); +int write_lastseen_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm); +int write_lastused_info(bdaddr_t *local, bdaddr_t *peer, struct tm *tm); +int write_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t type, int length); +int read_link_key(bdaddr_t *local, bdaddr_t *peer, unsigned char *key, uint8_t *type); +int read_pin_length(bdaddr_t *local, bdaddr_t *peer); +int read_pin_code(bdaddr_t *local, bdaddr_t *peer, char *pin); +gboolean read_trust(const bdaddr_t *local, const char *addr, const char *service); +int write_trust(bdaddr_t *local, const char *addr, const char *service, gboolean trust); +GSList *list_trusts(bdaddr_t *local, const char *service); +int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles); +int delete_entry(bdaddr_t *src, const char *storage, const char *key); +int store_record(const gchar *src, const gchar *dst, sdp_record_t *rec); +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); |