From 76acb638b08c61f4414d1e8e18c0e36b4178eeeb Mon Sep 17 00:00:00 2001 From: Bartosz Szatkowski Date: Mon, 12 Dec 2011 16:31:04 +0100 Subject: [PATCH] obexd: Add support for SetFolder in MAP client --- obexd/client/map.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/obexd/client/map.c b/obexd/client/map.c index bee49c5a2..51a771173 100644 --- a/obexd/client/map.c +++ b/obexd/client/map.c @@ -49,7 +49,63 @@ struct map_data { static DBusConnection *conn = NULL; +static void simple_cb(GObex *obex, GError *err, GObexPacket *rsp, + gpointer user_data) +{ + DBusMessage *reply; + struct map_data *map = user_data; + guint8 err_code = g_obex_packet_get_operation(rsp, NULL); + + if (err != NULL) + reply = g_dbus_create_error(map->msg, + "org.openobex.Error.Failed", + "%s", err->message); + else if (err_code != G_OBEX_RSP_SUCCESS) + reply = g_dbus_create_error(map->msg, + "org.openobex.Error.Failed", + "%s (0x%02x)", + g_obex_strerror(err_code), + err_code); + else + reply = dbus_message_new_method_return(map->msg); + + g_dbus_send_message(conn, reply); + dbus_message_unref(map->msg); +} + +static DBusMessage *map_setpath(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + struct map_data *map = user_data; + const char *folder; + GObex *obex; + GError *err = NULL; + + if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &folder, + DBUS_TYPE_INVALID) == FALSE) + return g_dbus_create_error(message, + "org.openobex.Error.InvalidArguments", + NULL); + + obex = obc_session_get_obex(map->session); + + g_obex_setpath(obex, folder, simple_cb, map, &err); + if (err != NULL) { + DBusMessage *reply; + reply = g_dbus_create_error(message, + "org.openobex.Error.Failed", + "%s", err->message); + g_error_free(err); + return reply; + } + + map->msg = dbus_message_ref(message); + + return NULL; +} + static GDBusMethodTable map_methods[] = { + { "SetFolder", "s", "", map_setpath, G_DBUS_METHOD_FLAG_ASYNC }, { } }; -- 2.47.3