upgrade obexd to 0.47
[profile/ivi/obexd.git] / client / sync.c
index 7675b23..65c9210 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include <errno.h>
+#include <string.h>
 
 #include <glib.h>
 #include <gdbus.h>
@@ -41,7 +42,7 @@
 #define OBEX_SYNC_UUID "IRMC-SYNC"
 #define OBEX_SYNC_UUID_LEN 9
 
-#define SYNC_INTERFACE "org.openobex.Synchronization"
+#define SYNC_INTERFACE "org.bluez.obex.Synchronization"
 #define ERROR_INF SYNC_INTERFACE ".Error"
 #define SYNC_UUID "00001104-0000-1000-8000-00805f9b34fb"
 
@@ -83,34 +84,21 @@ static DBusMessage *sync_setlocation(DBusConnection *connection,
        return dbus_message_new_method_return(message);
 }
 
-static void sync_getphonebook_callback(struct obc_session *session,
-                                       GError *err, void *user_data)
-{
-       struct obc_transfer *transfer = obc_session_get_transfer(session);
-       struct sync_data *sync = user_data;
-       DBusMessage *reply;
-       const char *buf;
-       int size;
-
-       reply = dbus_message_new_method_return(sync->msg);
-
-       buf = obc_transfer_get_buffer(transfer, &size);
-       if (size == 0)
-               buf = "";
-
-       dbus_message_append_args(reply,
-               DBUS_TYPE_STRING, &buf,
-               DBUS_TYPE_INVALID);
-
-       g_dbus_send_message(conn, reply);
-       dbus_message_unref(sync->msg);
-       sync->msg = NULL;
-}
-
 static DBusMessage *sync_getphonebook(DBusConnection *connection,
                        DBusMessage *message, void *user_data)
 {
        struct sync_data *sync = user_data;
+       struct obc_transfer *transfer;
+       const char *target_file;
+       GError *err = NULL;
+       DBusMessage *reply;
+
+       if (dbus_message_get_args(message, NULL,
+                                       DBUS_TYPE_STRING, &target_file,
+                                       DBUS_TYPE_INVALID) == FALSE)
+               return g_dbus_create_error(message,
+                               ERROR_INF ".InvalidArguments",
+                               "Invalid arguments in method call");
 
        if (sync->msg)
                return g_dbus_create_error(message,
@@ -120,49 +108,75 @@ static DBusMessage *sync_getphonebook(DBusConnection *connection,
        if (!sync->phonebook_path)
                sync->phonebook_path = g_strdup("telecom/pb.vcf");
 
-       if (obc_session_get(sync->session, "phonebook", sync->phonebook_path, NULL,
-                               NULL, 0, sync_getphonebook_callback, sync) < 0)
-               return g_dbus_create_error(message,
-                       ERROR_INF ".Failed", "Failed");
+       transfer = obc_transfer_get("phonebook", sync->phonebook_path,
+                                                       target_file, &err);
+       if (transfer == NULL)
+               goto fail;
 
-       sync->msg = dbus_message_ref(message);
+       if (!obc_session_queue(sync->session, transfer, NULL, NULL, &err))
+               goto fail;
 
-       return NULL;
+       return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+       reply = g_dbus_create_error(message, ERROR_INF ".Failed", "%s",
+                                                               err->message);
+       g_error_free(err);
+       return reply;
 }
 
 static DBusMessage *sync_putphonebook(DBusConnection *connection,
                        DBusMessage *message, void *user_data)
 {
        struct sync_data *sync = user_data;
-       const char *buf;
-       char *buffer;
+       struct obc_transfer *transfer;
+       const char *source_file;
+       GError *err = NULL;
+       DBusMessage *reply;
 
        if (dbus_message_get_args(message, NULL,
-                       DBUS_TYPE_STRING, &buf,
-                       DBUS_TYPE_INVALID) == FALSE)
+                                       DBUS_TYPE_STRING, &source_file,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return g_dbus_create_error(message,
-                       ERROR_INF ".InvalidArguments", NULL);
+                               ERROR_INF ".InvalidArguments",
+                               "Invalid arguments in method call");
 
        /* set default phonebook_path to memory internal phonebook */
        if (!sync->phonebook_path)
                sync->phonebook_path = g_strdup("telecom/pb.vcf");
 
-       buffer = g_strdup(buf);
+       transfer = obc_transfer_put(NULL, sync->phonebook_path, source_file,
+                                                       NULL, 0, &err);
+       if (transfer == NULL)
+               goto fail;
 
-       if (obc_session_put(sync->session, buffer, sync->phonebook_path) < 0)
-               return g_dbus_create_error(message,
-                               ERROR_INF ".Failed", "Failed");
+       if (!obc_session_queue(sync->session, transfer, NULL, NULL, &err))
+               goto fail;
 
-       return dbus_message_new_method_return(message);
+       return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+       reply = g_dbus_create_error(message, ERROR_INF ".Failed", "%s",
+                                                               err->message);
+       g_error_free(err);
+       return reply;
 }
 
-static GDBusMethodTable sync_methods[] = {
-       { "SetLocation", "s", "", sync_setlocation },
-       { "GetPhonebook", "", "s", sync_getphonebook,
-                       G_DBUS_METHOD_FLAG_ASYNC },
-       { "PutPhonebook", "s", "", sync_putphonebook,
-                       G_DBUS_METHOD_FLAG_ASYNC },
-       {}
+static const GDBusMethodTable sync_methods[] = {
+       { GDBUS_METHOD("SetLocation",
+                       GDBUS_ARGS({ "location", "s" }), NULL,
+                       sync_setlocation) },
+       { GDBUS_METHOD("GetPhonebook",
+                       GDBUS_ARGS({ "targetfile", "s" }),
+                       GDBUS_ARGS({ "transfer", "o" },
+                                       { "properties", "a{sv}" }),
+                       sync_getphonebook) },
+       { GDBUS_METHOD("PutPhonebook",
+                       GDBUS_ARGS({ "sourcefile", "s" }),
+                       GDBUS_ARGS({ "transfer", "o" },
+                                       { "properties", "a{sv}" }),
+                       sync_putphonebook) },
+       { }
 };
 
 static void sync_free(void *data)