Skip to contentSkip to conversation

client: Fix opening file in obc_transfer_get

PATCH In review Bartosz Szatkowski 2 participants 4 messages Dec 16, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 client: Fix opening file in obc_transfer_get

Until now file was opened, but not truncated - resulting in garbage on the end of file in situations when new content was shorter then old one.

---
 client/transfer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
client/transfer.c +1 -1
index c481378..472a04d 100644
@@ -516,7 +516,7 @@ int obc_transfer_get(struct obc_transfer *transfer, transfer_callback_t func,
 		rsp_cb = get_buf_xfer_progress;
 	} else {
 		int fd = open(transfer->name ? : transfer->filename,
-				O_WRONLY | O_CREAT, 0600);
+				O_WRONLY | O_CREAT | O_TRUNC, 0600);
 
 		if (fd < 0) {
 			error("open(): %s(%d)", strerror(errno), errno);
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 2/3 client: Add file flexibility for GET

Sometimes it would be useful to use file (and actually register transfer object) instead of memory buffer for GET, even for OBEX specific mime types (in some cases amount of data might be substantial eg. MAP GetMessage).

---
 client/transfer.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
client/transfer.c +2 -2
index 472a04d..03e2825 100644
@@ -232,7 +232,7 @@ struct obc_transfer *obc_transfer_register(DBusConnection *conn,
 	transfer->params = params;
 
 	/* for OBEX specific mime types we don't need to register a transfer */
-	if (type != NULL &&
+	if (type != NULL && name == NULL &&
 			(strncmp(type, "x-obex/", 7) == 0 ||
 			strncmp(type, "x-bt/", 5) == 0))
 		goto done;
@@ -510,7 +510,7 @@ int obc_transfer_get(struct obc_transfer *transfer, transfer_callback_t func,
 	if (transfer->xfer != 0)
 		return -EALREADY;
 
-	if (transfer->type != NULL &&
+	if (transfer->type != NULL && transfer->name == NULL &&
 			(strncmp(transfer->type, "x-obex/", 7) == 0 ||
 			strncmp(transfer->type, "x-bt/", 5) == 0)) {
 		rsp_cb = get_buf_xfer_progress;
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 3/3 map: Add basic GetMessage support

In reply to Bartosz Szatkowski
---
 client/map.c    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 test/map-client |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 0 deletions(-)
client/map.c +45 -0
index cdd2725..1ee8b04 100644
@@ -181,6 +181,50 @@ static DBusMessage *map_get_message_listing(DBusConnection *connection,
 	return NULL;
 }
 
+static DBusMessage *map_get_message(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct map_data *map = user_data;
+	int err;
+	const char *handle, *path, *transfer_path;
+	DBusMessageIter msg_iter;
+	struct obc_transfer *transfer;
+
+	dbus_message_iter_init(message, &msg_iter);
+
+	if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message,
+				"org.openobex.Error.InvalidArguments", NULL);
+
+	dbus_message_iter_get_basic(&msg_iter, &handle);
+
+	dbus_message_iter_next(&msg_iter);
+
+	if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_ARRAY)
+		return g_dbus_create_error(message,
+				"org.openobex.Error.InvalidArguments", NULL);
+
+	dbus_message_iter_next(&msg_iter);
+
+	if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_STRING)
+		return g_dbus_create_error(message,
+				"org.openobex.Error.InvalidArguments", NULL);
+
+	dbus_message_iter_get_basic(&msg_iter, &path);
+
+	err = obc_session_get(map->session, "x-bt/message", handle, path,
+							NULL, 0, NULL, NULL);
+	if (err < 0)
+		return g_dbus_create_error(message, "org.openobex.Error.Failed",
+									NULL);
+
+	transfer = obc_session_get_transfer(map->session);
+	transfer_path = obc_transfer_get_path(transfer);
+
+	return g_dbus_create_reply(message, DBUS_TYPE_OBJECT_PATH,
+					&transfer_path, DBUS_TYPE_INVALID);
+}
+
 static GDBusMethodTable map_methods[] = {
 	{ "SetFolder",		"s", "",	map_setpath,
 						G_DBUS_METHOD_FLAG_ASYNC },
@@ -188,6 +232,7 @@ static GDBusMethodTable map_methods[] = {
 						G_DBUS_METHOD_FLAG_ASYNC },
 	{ "GetMessageListing",	"sa{ss}", "s",	map_get_message_listing,
 						G_DBUS_METHOD_FLAG_ASYNC },
+	{ "GetMessage",		"sa{ss}s", "o",	map_get_message },
 	{ }
 };
 
test/map-client +51 -0

82 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#3 lore raw

Re: [PATCH obexd 3/3] map: Add basic GetMessage support

Hi Bartosz,

client/map.c static GDBusMethodTable map_methods[] = { · line 235

Quoted 8 lines · Bartosz Szatkowski

static GDBusMethodTable map_methods[] = {

client/map.c +1 -0
 	{ "SetFolder",		"s", "",	map_setpath,
 						G_DBUS_METHOD_FLAG_ASYNC },
@@ -188,6 +232,7 @@ static GDBusMethodTable map_methods[] = {
 						G_DBUS_METHOD_FLAG_ASYNC },
 	{ "GetMessageListing",	"sa{ss}", "s",	map_get_message_listing,
 						G_DBUS_METHOD_FLAG_ASYNC },
+	{ "GetMessage",		"sa{ss}s", "o",	map_get_message },

Before adding new methods could you please send a patch to add them to the Message Access section in doc/client-api.txt. It should contain all entries in this map_methods table but right now only contains SetFolder. This will also help me understand the API, and particularly parameters like "sa{ss}s" faster than by reading the code.

Johan