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