Diff between e539764caa99d648d2e9c9b78f0add432aff5caf and 05f37d61e3f5a97c4b6229b5d221a6b638ba0345

Changed Files

File Additions Deletions Status
obexd/src/dbus.h +3 -1 modified
obexd/src/manager.c +19 -6 modified
obexd/src/obex.c +6 -0 modified
obexd/src/obex.h +1 -0 modified
obexd/src/opp.c +1 -1 modified

Full Patch

diff --git a/obexd/src/dbus.h b/obexd/src/dbus.h
index 3c85aae..8042b27 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 fac69c6..282fa82 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 d4dc3bf..86cfc67 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 1e74168..7cb307b 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 6c674b3..851e432 100644
--- a/obexd/src/opp.c
+++ b/obexd/src/opp.c
@@ -42,8 +42,8 @@
 #include <glib.h>
 
 #include "logging.h"
-#include "dbus.h"
 #include "obex.h"
+#include "dbus.h"
 
 #define VCARD_TYPE "text/x-vcard"
 #define VCARD_FILE CONFIGDIR "/vcard.vcf"