From d414d4238725e4f0877aab94057e2d1353a75d65 Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Wed, 9 Jul 2008 18:05:04 -0300 Subject: [PATCH] obexd: Allows the Remote Device to cancel the tranfer while waiting for authorization. Now we don't need to wait for a timeout to start another transfer. --- obexd/src/manager.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/obexd/src/manager.c b/obexd/src/manager.c index 282fa82bd..da11cb6fa 100644 --- a/obexd/src/manager.c +++ b/obexd/src/manager.c @@ -439,6 +439,7 @@ static void agent_reply(DBusPendingCall *call, gpointer user_data) error("Agent replied with an error: %s, %s", derr.name, derr.message); dbus_error_free(&derr); + dbus_message_unref(reply); return; } @@ -455,6 +456,16 @@ static void agent_reply(DBusPendingCall *call, gpointer user_data) agent->new_folder = g_strndup(name, slash - name); } } + + dbus_message_unref(reply); +} + +static gboolean auth_error(GIOChannel *io, GIOCondition cond, + gpointer user_data) +{ + agent->auth_pending = FALSE; + + return FALSE; } int request_authorization(gint32 cid, int fd, const gchar *filename, @@ -463,11 +474,13 @@ int request_authorization(gint32 cid, int fd, const gchar *filename, { DBusMessage *msg; DBusPendingCall *call; + GIOChannel *io; struct sockaddr_rc addr; socklen_t addrlen; gchar address[18]; const gchar *bda = address; gchar *path; + guint watch; if (!agent) return -1; @@ -503,20 +516,33 @@ int request_authorization(gint32 cid, int fd, const gchar *filename, g_free(path); if (!dbus_connection_send_with_reply(connection, - msg, &call, TIMEOUT)) + msg, &call, TIMEOUT)) { + dbus_message_unref(msg); return -EPERM; + } dbus_message_unref(msg); agent->auth_pending = TRUE; + /* Catches errors before authorization response comes */ + io = g_io_channel_unix_new(fd); + watch = g_io_add_watch_full(io, G_PRIORITY_DEFAULT, + G_IO_HUP | G_IO_ERR | G_IO_NVAL, + auth_error, NULL, NULL); + g_io_channel_unref(io); + dbus_pending_call_set_notify(call, agent_reply, NULL, NULL); - dbus_pending_call_unref(call); /* Workaround: process events while agent doesn't reply */ while (agent->auth_pending) g_main_context_iteration(NULL, TRUE); + g_source_remove(watch); + + dbus_pending_call_cancel(call); + dbus_pending_call_unref(call); + if (!agent->new_name) { return -EPERM; } -- 2.47.3