summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-08-03 13:09:40 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-08-03 13:09:40 +0000
commitba268bfe5652e348450b10dbc9981e9bcd6a55d5 (patch)
treed4e978d80dc0a508fdeeb117e463c6caab710b71
parent0ffdac3e37977d4db9fb42832b95a6fd1f3a4100 (diff)
Implement Adapter.ListTrusts method
-rw-r--r--hcid/dbus-adapter.c38
-rw-r--r--hcid/dbus-api.txt4
-rw-r--r--hcid/hcid.h1
-rw-r--r--hcid/storage.c29
4 files changed, 72 insertions, 0 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 4a504067..e57309d3 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -3023,6 +3023,42 @@ static DBusHandlerResult adapter_remove_trust(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+static DBusHandlerResult adapter_list_trusts(DBusConnection *conn,
+ DBusMessage *msg,
+ void *data)
+{
+ struct adapter *adapter = data;
+ DBusMessage *reply;
+ GSList *trusts, *l;
+ char **addrs;
+ bdaddr_t local;
+ int len;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ str2ba(adapter->address, &local);
+
+ trusts = list_trusts(&local, GLOBAL_TRUST);
+
+ addrs = g_new(char *, g_slist_length(trusts));
+
+ for (l = trusts, len = 0; l; l = l->next, len++)
+ addrs[len] = l->data;
+
+ dbus_message_append_args(reply,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &addrs, len,
+ DBUS_TYPE_INVALID);
+
+ g_free(addrs);
+ g_slist_foreach(trusts, (GFunc) g_free, NULL);
+ g_slist_free(trusts);
+
+ return send_message_and_unref(conn, reply);
+}
+
const char *major_class_str(uint32_t class)
{
uint8_t index = (class >> 8) & 0x1F;
@@ -3251,6 +3287,8 @@ static DBusMethodVTable adapter_methods[] = {
"s", "b" },
{ "RemoveTrust", adapter_remove_trust,
"s", "" },
+ { "ListTrusts", adapter_list_trusts,
+ "", "as" },
{ NULL, NULL, NULL, NULL }
};
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt
index e387cd29..ed0f258e 100644
--- a/hcid/dbus-api.txt
+++ b/hcid/dbus-api.txt
@@ -851,6 +851,10 @@ Methods dict GetInfo()
Possible errors: org.bluez.Error.InvalidArguments
org.bluez.Error.DoesNotExist
+ array{string} ListTrusted()
+
+ Returns a list of remote devices that are trusted.
+
void DiscoverDevices()
This method starts the device discovery procedure. This
diff --git a/hcid/hcid.h b/hcid/hcid.h
index a16ecd58..4d49b957 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -203,3 +203,4 @@ 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(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);
diff --git a/hcid/storage.c b/hcid/storage.c
index 19b13777..68f3470c 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -608,3 +608,32 @@ gboolean read_trust(bdaddr_t *local, const char *addr, const char *service)
return ret;
}
+
+struct trust_list {
+ GSList *trusts;
+ const char *service;
+};
+
+static void append_trust(char *key, char *value, void *data)
+{
+ struct trust_list *list = data;
+
+ if (strstr(value, list->service))
+ list->trusts = g_slist_append(list->trusts, g_strdup(key));
+}
+
+GSList *list_trusts(bdaddr_t *local, const char *service)
+{
+ char filename[PATH_MAX + 1];
+ struct trust_list list;
+
+ create_filename(filename, PATH_MAX, local, "trusts");
+
+ list.trusts = NULL;
+ list.service = service;
+
+ if (textfile_foreach(filename, append_trust, &list) < 0)
+ return NULL;
+
+ return list.trusts;
+}