summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-11-10 17:19:40 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-11-10 17:19:40 +0000
commit430fa04b85e6659995328792bd0ad5cffbd75921 (patch)
tree0241d107e32fbafe354788297e87084ad71f3c06
parentca0904086725bcf98343f8b2b56b148635b15812 (diff)
Implement ListRemoteDevices and ListRecentRemoteDevices methods
-rw-r--r--hcid/dbus-adapter.c129
-rw-r--r--hcid/dbus-api.txt14
2 files changed, 143 insertions, 0 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index ab1f95c8..1aeccbc6 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -25,10 +25,12 @@
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <time.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -2644,6 +2646,130 @@ static DBusHandlerResult adapter_cancel_discovery(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
+struct remote_device_list_t {
+ struct slist *list;
+ time_t time;
+};
+
+static void list_remote_devices_do_append(char *key, char *value, void *data)
+{
+ struct remote_device_list_t *param = data;
+ char *address;
+ struct tm date;
+
+ if (slist_find(param->list, key, (cmp_func_t) strcasecmp))
+ return;
+
+ if (param->time){
+ strptime(value, "%Y-%m-%d %H:%M:%S %Z", &date);
+ if (difftime(mktime(&date), param->time) < 0)
+ return;
+ }
+
+ address = strdup(key);
+ if (!address)
+ return;
+
+ param->list = slist_append(param->list, address);
+}
+
+static void remote_devices_do_append(void *data, void *user_data)
+{
+ DBusMessageIter *iter = user_data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data);
+}
+
+static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
+{
+ struct adapter *adapter = data;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessage *reply;
+ char filename[PATH_MAX + 1];
+ struct remote_device_list_t param = { NULL, 0 };
+
+ if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
+ return error_invalid_arguments(conn, msg);
+
+ /* Add Bonded devices to the list */
+ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+ textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+ /* Add Last Used devices to the list */
+ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+ textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+ /* Add Last Seen devices to the list */
+ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen");
+ textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+ reply = dbus_message_new_method_return(msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+ slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+ slist_foreach(param.list, (slist_func_t) free, NULL);
+ slist_free(param.list);
+
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+ return send_message_and_unref(conn, reply);
+}
+
+static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
+{
+ struct adapter *adapter = data;
+ const char *string;
+ struct tm date;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessage *reply;
+ char filename[PATH_MAX + 1];
+ struct remote_device_list_t param = { NULL, 0 };
+
+ if (!dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_STRING, &string,
+ DBUS_TYPE_INVALID))
+ return error_invalid_arguments(conn, msg);
+
+ if (strptime(string, "%Y-%m-%d %H:%M:%S", &date) == NULL)
+ return error_invalid_arguments(conn, msg);
+ param.time = mktime(&date);
+
+ /* Add Bonded devices to the list */
+ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+ textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+ /* Add Last Used devices to the list */
+ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+ textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+ reply = dbus_message_new_method_return(msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+ slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+ slist_foreach(param.list, (slist_func_t) free, NULL);
+ slist_free(param.list);
+
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+ return send_message_and_unref(conn, reply);
+}
+
const char *major_class_str(uint32_t class)
{
uint8_t index = (class >> 8) & 0x1F;
@@ -2776,6 +2902,9 @@ static struct service_data dev_services[] = {
{ "DiscoverDevicesWithoutNameResolving", adapter_discover_devices },
{ "CancelDiscovery", adapter_cancel_discovery },
+ { "ListRemoteDevices", adapter_list_remote_devices },
+ { "ListRecentRemoteDevices", adapter_list_recent_remote_devices },
+
{ NULL, NULL }
};
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt
index 9464ed05..b59d3770 100644
--- a/hcid/dbus-api.txt
+++ b/hcid/dbus-api.txt
@@ -947,6 +947,20 @@ Signals void ModeChanged(string mode)
Signals that a bonding was removed.
+ array{string} ListRemoteDevices()
+
+ List addresses of all known remote devices (seen, used or bonded).
+
+ Possible errors: none
+
+ array{string} ListRecentRemoteDevices(string date)
+
+ List addresses of all used or bonded remote devices since date.
+
+ date format is "YYYY-MM-DD HH:MM:SS GMT"
+
+ Possible errors: none
+
Security hierarchy
==================