From 05f37d61e3f5a97c4b6229b5d221a6b638ba0345 Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Thu, 3 Jul 2008 16:27:59 -0300 Subject: [PATCH] obexd: Adds transfer cancel. --- obexd/src/dbus.h | 4 +++- obexd/src/manager.c | 25 +++++++++++++++++++------ obexd/src/obex.c | 6 ++++++ obexd/src/obex.h | 1 + obexd/src/opp.c | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/obexd/src/dbus.h b/obexd/src/dbus.h index 3c85aaeab..8042b27b6 100644 --- a/obexd/src/dbus.h +++ b/obexd/src/dbus.h @@ -35,6 +35,8 @@ int request_authorization(gint32 cid, int fd, const gchar *filename, const gchar *type, gint32 length, gint32 time, gchar **new_folder, gchar **new_name); -void register_transfer(guint32 id); +void register_transfer(guint32 id, struct obex_session *os); void unregister_transfer(guint32 id); + +void register_session(guint32 id); diff --git a/obexd/src/manager.c b/obexd/src/manager.c index fac69c6c1..282fa82bd 100644 --- a/obexd/src/manager.c +++ b/obexd/src/manager.c @@ -265,6 +265,19 @@ static DBusMessage *get_properties(DBusConnection *conn, return reply; } +static DBusMessage *transfer_cancel(DBusConnection *connection, + DBusMessage *msg, void *user_data) +{ + struct obex_session *os = user_data; + + if (!os) + return invalid_args(msg); + + os->cancelled = TRUE; + + return dbus_message_new_method_return(msg); +} + static GDBusMethodTable manager_methods[] = { { "RegisterAgent", "o", "", register_agent }, { "UnregisterAgent", "o", "", unregister_agent }, @@ -272,15 +285,15 @@ static GDBusMethodTable manager_methods[] = { }; static GDBusSignalTable manager_signals[] = { - { "TransferStarted", "o" }, - { "TransferCompleted", "ob" }, - { "SessionCreated", "o" }, + { "TransferStarted", "o" }, + { "TransferCompleted", "ob" }, + { "SessionCreated", "o" }, { "SessionRemoved", "o" }, { } }; static GDBusMethodTable transfer_methods[] = { - { "Cancel", "" }, + { "Cancel", "", "", transfer_cancel }, { } }; @@ -387,14 +400,14 @@ void emit_transfer_progress(guint32 id, guint32 total, guint32 transfered) g_free(path); } -void register_transfer(guint32 id) +void register_transfer(guint32 id, struct obex_session *os) { gchar *path = g_strdup_printf("/transfer%u", id); if (!g_dbus_register_interface(connection, path, TRANSFER_INTERFACE, transfer_methods, transfer_signals, - NULL, NULL, NULL)) { + NULL, os, NULL)) { error("Cannot register Transfer interface."); g_free(path); return; diff --git a/obexd/src/obex.c b/obexd/src/obex.c index d4dc3bf62..86cfc674f 100644 --- a/obexd/src/obex.c +++ b/obexd/src/obex.c @@ -417,6 +417,9 @@ static gint obex_write(struct obex_session *os, debug("obex_write name: %s type: %s tx_mtu: %d fd: %d", os->name, os->type, os->tx_mtu, os->fd); + if (os->cancelled) + return -EPERM; + if (os->fd < 0) { if (os->buf == NULL) return -EIO; @@ -500,6 +503,9 @@ static gint obex_read(struct obex_session *os, gint32 len = 0; const guint8 *buffer; + if (os->cancelled) + return -EPERM; + size = OBEX_ObjectReadStream(obex, obj, &buffer); if (size < 0) { error("Error on OBEX stream"); diff --git a/obexd/src/obex.h b/obexd/src/obex.h index 1e74168f1..7cb307b48 100644 --- a/obexd/src/obex.h +++ b/obexd/src/obex.h @@ -57,6 +57,7 @@ struct obex_session { gint32 offset; gint32 size; gint fd; + gboolean cancelled; const guint8 *target; struct obex_commands *cmds; struct server *server; diff --git a/obexd/src/opp.c b/obexd/src/opp.c index 6c674b346..851e432dd 100644 --- a/obexd/src/opp.c +++ b/obexd/src/opp.c @@ -42,8 +42,8 @@ #include #include "logging.h" -#include "dbus.h" #include "obex.h" +#include "dbus.h" #define VCARD_TYPE "text/x-vcard" #define VCARD_FILE CONFIGDIR "/vcard.vcf" -- 2.47.3