All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH obexd 1/3] client: Fix opening file in obc_transfer_get
@ 2011-12-16 13:23 Bartosz Szatkowski
  2011-12-16 13:23 ` [PATCH obexd 2/3] client: Add file flexibility for GET Bartosz Szatkowski
  2011-12-16 13:23 ` [PATCH obexd 3/3] map: Add basic GetMessage support Bartosz Szatkowski
  0 siblings, 2 replies; 4+ messages in thread
From: Bartosz Szatkowski @ 2011-12-16 13:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bartosz Szatkowski

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(-)

diff --git a/client/transfer.c b/client/transfer.c
index c481378..472a04d 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -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);
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH obexd 2/3] client: Add file flexibility for GET
  2011-12-16 13:23 [PATCH obexd 1/3] client: Fix opening file in obc_transfer_get Bartosz Szatkowski
@ 2011-12-16 13:23 ` Bartosz Szatkowski
  2011-12-16 13:23 ` [PATCH obexd 3/3] map: Add basic GetMessage support Bartosz Szatkowski
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Szatkowski @ 2011-12-16 13:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bartosz Szatkowski

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(-)

diff --git a/client/transfer.c b/client/transfer.c
index 472a04d..03e2825 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -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;
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH obexd 3/3] map: Add basic GetMessage support
  2011-12-16 13:23 [PATCH obexd 1/3] client: Fix opening file in obc_transfer_get Bartosz Szatkowski
  2011-12-16 13:23 ` [PATCH obexd 2/3] client: Add file flexibility for GET Bartosz Szatkowski
@ 2011-12-16 13:23 ` Bartosz Szatkowski
  2011-12-16 14:23   ` Johan Hedberg
  1 sibling, 1 reply; 4+ messages in thread
From: Bartosz Szatkowski @ 2011-12-16 13:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bartosz Szatkowski

---
 client/map.c    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 test/map-client |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/client/map.c b/client/map.c
index cdd2725..1ee8b04 100644
--- a/client/map.c
+++ b/client/map.c
@@ -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 },
 	{ }
 };
 
diff --git a/test/map-client b/test/map-client
index 5c7c447..027d3e8 100755
--- a/test/map-client
+++ b/test/map-client
@@ -3,9 +3,45 @@
 import gobject
 
 import dbus
+import dbus.service
 import dbus.mainloop.glib
 from optparse import OptionParser
 
+class Agent(dbus.service.Object):
+    def __init__(self, conn=None, obj_path=None, verbose=False):
+        dbus.service.Object.__init__(self, conn, obj_path)
+        self.verbose = verbose
+
+    @dbus.service.method("org.openobex.Agent",
+                    in_signature="o", out_signature="s")
+    def Request(self, path):
+        return ""
+
+    @dbus.service.method("org.openobex.Agent",
+                    in_signature="ot", out_signature="")
+    def Progress(self, path, transferred):
+        if self.verbose:
+            print "Transfer progress (%d bytes)" % (transferred)
+        return
+
+    @dbus.service.method("org.openobex.Agent",
+                    in_signature="o", out_signature="")
+    def Complete(self, path):
+        if self.verbose:
+            print "Transfer finished"
+        mainloop.quit()
+
+    @dbus.service.method("org.openobex.Agent",
+                    in_signature="os", out_signature="")
+    def Error(self, path, error):
+        print "Transfer finished with an error: %s" % (error)
+        mainloop.quit()
+
+    @dbus.service.method("org.openobex.Agent",
+                    in_signature="", out_signature="")
+    def Release(self):
+        mainloop.quit()
+
 def parse_options():
     parser.add_option("-d", "--device", dest="device",
                       help="Device to connect", metavar="DEVICE")
@@ -16,6 +52,11 @@ def parse_options():
     parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
     parser.add_option("-L", "--lsmsg", action="store", dest="ls_msg",
                       help="List messages in supplied CWD subdir")
+    parser.add_option("-g", "--getmsg", action="store", dest="get_msg",
+		      metavar="HANDLE", help="Pull message with given handle")
+    parser.add_option("-f", "--dest-file", action="store", dest="dest_file",
+                      metavar="FILE", default="msg.bmsg",
+                      help="Local file to store message")
 
     return parser.parse_args()
 
@@ -38,6 +79,9 @@ if  __name__ == '__main__':
     bus = dbus.SessionBus()
     mainloop = gobject.MainLoop()
 
+    path = "/test/agent"
+    agent = Agent(bus, path, options.verbose)
+
     client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
                             "org.openobex.Client")
 
@@ -47,6 +91,8 @@ if  __name__ == '__main__':
     session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
                  "org.openobex.Session")
 
+    session.AssignAgent(path)
+
     map = dbus.Interface(bus.get_object("org.openobex.client", session_path),
                  "org.openobex.MessageAccess")
 
@@ -59,4 +105,9 @@ if  __name__ == '__main__':
     if options.ls_msg is not None:
 	print map.GetMessageListing(options.ls_msg, dict())
 
+    if options.get_msg:
+        xfer = map.GetMessage(options.get_msg, dict(), options.dest_file)
+        if options.verbose:
+            print xfer
+
     mainloop.run()
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH obexd 3/3] map: Add basic GetMessage support
  2011-12-16 13:23 ` [PATCH obexd 3/3] map: Add basic GetMessage support Bartosz Szatkowski
@ 2011-12-16 14:23   ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2011-12-16 14:23 UTC (permalink / raw)
  To: Bartosz Szatkowski; +Cc: linux-bluetooth

Hi Bartosz,

On Fri, Dec 16, 2011, Bartosz Szatkowski wrote:
>  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 },

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-12-16 14:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-16 13:23 [PATCH obexd 1/3] client: Fix opening file in obc_transfer_get Bartosz Szatkowski
2011-12-16 13:23 ` [PATCH obexd 2/3] client: Add file flexibility for GET Bartosz Szatkowski
2011-12-16 13:23 ` [PATCH obexd 3/3] map: Add basic GetMessage support Bartosz Szatkowski
2011-12-16 14:23   ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.