From 5695fceb8dd3b72d5abd5da79b7a0551111d7400 Mon Sep 17 00:00:00 2001 From: Ulisses Furquim Date: Mon, 30 Oct 2006 14:06:31 +0000 Subject: [PATCH] Add code to release authorization agents --- hcid/dbus-security.c | 37 ++++++++++++++++++++++++++++++++++++- hcid/dbus.c | 1 + hcid/dbus.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 474037169..6d5f0b151 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -46,6 +46,7 @@ static struct passkey_agent *default_agent = NULL; static struct authorization_agent *default_auth_agent = NULL; static void release_agent(struct passkey_agent *agent); +static void release_auth_agent(struct authorization_agent *agent); static void send_cancel_request(struct pending_agent_request *req); static void passkey_agent_free(struct passkey_agent *agent) @@ -209,7 +210,10 @@ static int agent_cmp(const struct passkey_agent *a, const struct passkey_agent * static void auth_agent_free(struct authorization_agent *agent) { - /* FIXME: release the agent if necessary */ + /* FIXME: cancel all requests */ + + if (!agent->exited) + release_auth_agent(agent); if (agent->name) free(agent->name); @@ -267,6 +271,28 @@ static void default_auth_agent_exited(const char *name, void *data) default_auth_agent = NULL; } +static void release_auth_agent(struct authorization_agent *agent) +{ + DBusMessage *message; + + debug("Releasing authorization agent %s, %s", + agent->name, agent->path); + + message = dbus_message_new_method_call(agent->name, agent->path, + "org.bluez.AuthorizationAgent", "Release"); + if (!message) { + error("Couldn't allocate D-Bus message"); + return; + } + + dbus_message_set_no_reply(message, TRUE); + send_message_and_unref(agent->conn, message); + + if (agent == default_auth_agent) + name_listener_remove(agent->conn, agent->name, + (name_cb_t) default_auth_agent_exited, NULL); +} + static DBusHandlerResult register_passkey_agent(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -1063,6 +1089,15 @@ void release_default_agent(void) default_agent = NULL; } +void release_default_auth_agent(void) +{ + if (!default_auth_agent) + return; + + auth_agent_free(default_auth_agent); + default_auth_agent = NULL; +} + void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda) { struct slist *l, *next; diff --git a/hcid/dbus.c b/hcid/dbus.c index e38d82b29..ce470ab51 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -1980,6 +1980,7 @@ void hcid_dbus_exit(void) return; release_default_agent(); + release_default_auth_agent(); release_service_agents(connection); /* Unregister all paths in Adapter path hierarchy */ diff --git a/hcid/dbus.h b/hcid/dbus.h index ac72a5ee8..478949a19 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -268,6 +268,7 @@ int handle_passkey_request(DBusConnection *conn, int dev, const char *path, int handle_confirm_request(DBusConnection *conn, int dev, const char *path, bdaddr_t *sba, bdaddr_t *dba, const char *pin); void release_default_agent(void); +void release_default_auth_agent(void); void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda); void cancel_passkey_agent_requests(struct slist *agents, const char *path, bdaddr_t *dba);