Merge with private git 1.0_post
authorDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 1 Jun 2012 03:53:24 +0000 (12:53 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 1 Jun 2012 04:06:18 +0000 (13:06 +0900)
Change-Id: I26b27dbcce0d5150bb68742c650548360b36bf5c

12 files changed:
client/transfer.c
debian/obexd-doc.debhelper.log
gobex/gobex-transfer.c
gobex/gobex.c
gobex/gobex.h
packaging/create-symlinks [new file with mode: 0644]
packaging/obex-root-setup [new file with mode: 0644]
packaging/obexd.spec
plugins/ftp.c
plugins/opp.c
plugins/phonebook-tizen.c
src/obexd.service.in

index bd9870d..b2e2ce0 100644 (file)
@@ -55,6 +55,9 @@ struct obc_transfer {
        struct obc_transfer_params *params;
        struct transfer_callback *callback;
        DBusConnection *conn;
+#ifdef TIZEN_PATCH
+       DBusMessage *msg;
+#endif
        char *path;             /* Transfer path */
        gchar *filename;        /* Transfer file location */
        char *name;             /* Transfer object name */
@@ -130,6 +133,114 @@ static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
        return reply;
 }
 
+#ifdef TIZEN_PATCH
+static void abort_complete(GObex *obex, GError *err, gpointer user_data)
+{
+       struct obc_transfer *transfer = user_data;
+       struct transfer_callback *callback = transfer->callback;
+       DBusMessage *reply;
+
+       transfer->xfer = 0;
+
+       reply = dbus_message_new_method_return(transfer->msg);
+       if (reply)
+               g_dbus_send_message(transfer->conn, reply);
+
+       dbus_message_unref(transfer->msg);
+       transfer->msg = NULL;
+
+       if (callback) {
+               if (err) {
+                       callback->func(transfer, transfer->transferred, err,
+                                                       callback->data);
+               } else {
+                       GError *abort_err;
+
+                       abort_err = g_error_new(OBEX_IO_ERROR, -ECANCELED, "%s",
+                                               "Transfer cancelled by user");
+                       callback->func(transfer, transfer->transferred, abort_err,
+                                                               callback->data);
+                       g_error_free(abort_err);
+               }
+       }
+}
+
+static gboolean obc_transfer_abort(struct obc_transfer *transfer)
+{
+       if (transfer->xfer == 0)
+               return FALSE;
+
+       return g_obex_cancel_transfer(transfer->xfer, abort_complete,
+                                                               transfer);
+}
+
+static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
+                                       DBusMessage *message, void *user_data)
+{
+       struct obc_transfer *transfer = user_data;
+       struct obc_session *session = transfer->session;
+       const gchar *sender, *agent;
+
+       sender = dbus_message_get_sender(message);
+       agent = obc_session_get_agent(session);
+       if (g_str_equal(sender, agent) == FALSE)
+               return g_dbus_create_error(message,
+                               "org.openobex.Error.NotAuthorized",
+                               "Not Authorized");
+
+       if (!obc_transfer_abort(transfer))
+               return g_dbus_create_error(message,
+                               "org.openobex.Error.Failed",
+                               "Failed");
+
+       transfer->msg = dbus_message_ref(message);
+
+       return NULL;
+}
+
+static GDBusMethodTable obc_transfer_methods[] = {
+       { "GetProperties", "", "a{sv}", obc_transfer_get_properties },
+       { "Cancel", "", "", obc_transfer_cancel, G_DBUS_METHOD_FLAG_ASYNC },
+       { }
+};
+
+static void obc_transfer_free(struct obc_transfer *transfer)
+{
+       struct obc_session *session = transfer->session;
+
+       DBG("%p", transfer);
+
+       if (transfer->xfer)
+               g_obex_cancel_transfer(transfer->xfer, NULL, NULL);
+
+       if (transfer->fd > 0)
+               close(transfer->fd);
+
+       obc_session_remove_transfer(session, transfer);
+
+       obc_session_unref(session);
+
+       if (transfer->params != NULL) {
+               g_free(transfer->params->data);
+               g_free(transfer->params);
+       }
+
+       if (transfer->conn)
+               dbus_connection_unref(transfer->conn);
+
+       if (transfer->msg)
+               dbus_message_unref(transfer->msg);
+
+       g_free(transfer->callback);
+       g_free(transfer->filename);
+       g_free(transfer->name);
+       g_free(transfer->type);
+       g_free(transfer->path);
+       g_free(transfer->buffer);
+       g_free(transfer);
+}
+#else
+
 static void obc_transfer_abort(struct obc_transfer *transfer)
 {
        struct transfer_callback *callback = transfer->callback;
@@ -213,6 +324,7 @@ static void obc_transfer_free(struct obc_transfer *transfer)
        g_free(transfer->buffer);
        g_free(transfer);
 }
+#endif
 
 struct obc_transfer *obc_transfer_register(DBusConnection *conn,
                                                const char *filename,
index 77de4ac..4dc7b9a 100644 (file)
@@ -11,3 +11,4 @@ dh_installdocs
 dh_installdocs
 dh_installdocs
 dh_installdocs
+dh_installdocs
index a779e4f..d644ae6 100644 (file)
@@ -622,6 +622,35 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
                                                        user_data, err);
 }
 
+#ifdef TIZEN_PATCH
+gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
+                       gpointer user_data)
+{
+       struct transfer *transfer = NULL;
+       gboolean ret = TRUE;
+
+       g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);
+
+       transfer = find_transfer(id);
+
+       if (transfer == NULL)
+               return FALSE;
+
+       if (complete_func == NULL)
+               goto done;
+
+       transfer->complete_func = complete_func;
+       transfer->user_data = user_data;
+
+       ret = g_obex_pending_req_abort(transfer->obex, NULL);
+       if (ret)
+               return TRUE;
+
+done:
+       transfer_free(transfer);
+       return ret;
+}
+#else
 gboolean g_obex_cancel_transfer(guint id)
 {
        struct transfer *transfer = NULL;
@@ -636,3 +665,4 @@ gboolean g_obex_cancel_transfer(guint id)
        transfer_free(transfer);
        return TRUE;
 }
+#endif
index 4afc21b..4005312 100644 (file)
@@ -679,7 +679,11 @@ static gint pending_pkt_cmp(gconstpointer a, gconstpointer b)
        return (p->id - id);
 }
 
+#ifdef TIZEN_PATCH
+gboolean g_obex_pending_req_abort(GObex *obex, GError **err)
+#else
 static gboolean pending_req_abort(GObex *obex, GError **err)
+#endif
 {
        struct pending_pkt *p = obex->pending_req;
        GObexPacket *req;
@@ -723,7 +727,11 @@ gboolean g_obex_cancel_req(GObex *obex, guint req_id, gboolean remove_callback)
        struct pending_pkt *p;
 
        if (obex->pending_req && obex->pending_req->id == req_id) {
+#ifdef TIZEN_PATCH
+               if (!g_obex_pending_req_abort(obex, NULL)) {
+#else
                if (!pending_req_abort(obex, NULL)) {
+#endif
                        p = obex->pending_req;
                        obex->pending_req = NULL;
                        goto immediate_completion;
@@ -1316,11 +1324,7 @@ GObex *g_obex_ref(GObex *obex)
 
 void g_obex_unref(GObex *obex)
 {
-#ifdef TIZEN_PATCH
-       gboolean last_ref, ret;
-#else
        gboolean last_ref;
-#endif
 
        last_ref = g_atomic_int_dec_and_test(&obex->ref_count);
 
@@ -1331,14 +1335,6 @@ void g_obex_unref(GObex *obex)
 
        g_slist_free_full(obex->req_handlers, g_free);
 
-#ifdef TIZEN_PATCH
-       do {
-               ret = write_data(obex->io, G_IO_OUT, obex);
-               if (obex->pending_req && obex->pending_req->cancelled)
-                       break;
-       } while(ret);
-#endif
-
        g_queue_foreach(obex->tx_queue, (GFunc) pending_pkt_free, NULL);
        g_queue_free(obex->tx_queue);
 
index 1c47c68..a0eae54 100644 (file)
@@ -49,6 +49,10 @@ guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
 gboolean g_obex_cancel_req(GObex *obex, guint req_id,
                                                gboolean remove_callback);
 
+#ifdef TIZEN_PATCH
+gboolean g_obex_pending_req_abort(GObex *obex, GError **err);
+#endif
+
 gboolean g_obex_send_rsp(GObex *obex, guint8 rspcode, GError **err,
                                                guint8 first_hdr_type, ...);
 
@@ -122,7 +126,12 @@ guint g_obex_get_rsp_pkt(GObex *obex, GObexPacket *rsp,
                        GObexDataProducer data_func, GObexFunc complete_func,
                        gpointer user_data, GError **err);
 
+#ifdef TIZEN_PATCH
+gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
+                                                       gpointer user_data);
+#else
 gboolean g_obex_cancel_transfer(guint id);
+#endif
 
 const char *g_obex_strerror(guint8 err_code);
 
diff --git a/packaging/create-symlinks b/packaging/create-symlinks
new file mode 100644 (file)
index 0000000..11cdcdc
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+OBEX_ROOT="$1"
+
+cd "$OBEX_ROOT"
+
+ln -s ../MyDocs/.documents Documents
+ln -s ../MyDocs/.images Images
+ln -s ../MyDocs/.sounds "Audio clips"
+ln -s ../MyDocs/.camera Camera
+ln -s ../MyDocs/.videos "Video clips"
+ln -s ../MyDocs Data
diff --git a/packaging/obex-root-setup b/packaging/obex-root-setup
new file mode 100644 (file)
index 0000000..fc0864f
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+set -e
+
+ROOT_SETUP=/etc/obex/root-setup.d
+
+OBEX_ROOT="$1"
+
+mkdir -p "$OBEX_ROOT"
+
+if [ -d "$ROOT_SETUP" ]; then
+       run-parts -a "$OBEX_ROOT" "$ROOT_SETUP"
+fi
+
+chmod 0550 "$OBEX_ROOT"
index 0e2c5f2..dde0bf4 100644 (file)
@@ -1,49 +1,54 @@
 Name:       obexd
 Summary:    OBEX Server A basic OBEX server implementation
 Version:    0.44
-Release:    1
+Release:    6
 Group:      TO_BE/FILLED_IN
-License:    GPL-2.0
-Source0:    obexd-%{version}.tar.gz
-Source1001: packaging/obexd.manifest 
-BuildRequires:  pkgconfig(bluez) 
+License:    TO BE FILLED IN
+Source0:    %{name}-%{version}.tar.gz
+Source101:    obex-root-setup
+Source102:    create-symlinks
+Source1001: packaging/obexd.manifest
+BuildRequires:  pkgconfig(bluez)
 BuildRequires:  pkgconfig(dbus-1)
-BuildRequires:  pkgconfig(glib-2.0) 
+BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(dbus-glib-1)
 
-
 %description
 OBEX Server A basic OBEX server implementation.
 
-
 %prep
 %setup -q
 
-
 %build
 cp %{SOURCE1001} .
-export CFLAGS+=" -DDEBUG -DTIZEN_PATCH -DOPENSOURCE_PATCH"
-chmod +x bootstrap
-./bootstrap && \
-    ./configure \
+export CFLAGS+=" -DDEBUG -DTIZEN_PATCH -DOPENSOURCE_PATCH "
+chmod +x bootstrap-configure
+
+./bootstrap-configure --disable-static \
                 --enable-debug \
-                --enable-usb \
-                --prefix=/usr \
+                      --sysconfdir=/etc \
                 --libexec=/usr/lib/obex \
-                --mandir=/usr/share/man \
-                --sysconfdir=/etc \
-               --with-phonebook=tizen \
-               --with-messages=tizen
-make %{?jobs:-j%jobs}
+                     --disable-maintainer-mode \
+                      --with-phonebook=tizen \
+                      --with-messages=tizen
 
+#make %{?jobs:-j%jobs}
+make
 
 %install
+rm -rf %{buildroot}
 %make_install
 
+install -D -m 0755 %SOURCE101 %{buildroot}%{_bindir}/obex-root-setup
+install -D -m 0755 %SOURCE102 %{buildroot}%{_sysconfdir}/obex/root-setup.d/000_create-symlinks
 
 %files
 %manifest obexd.manifest
-/usr/lib/obex/obex-client
+%{_sysconfdir}/obex/root-setup.d/000_create-symlinks
+%{_datadir}/dbus-1/services/obexd.service
+%{_datadir}/dbus-1/services/obex-client.service
+%{_bindir}/obex-root-setup
 /usr/lib/obex/obexd
-/usr/share/dbus-1/services/obex-client.service
-/usr/share/dbus-1/services/obexd.service
+/usr/lib/obex/obex-client
+%dir /usr/lib/obex/plugins
+
index 2a7a725..b20209b 100644 (file)
@@ -224,12 +224,13 @@ int ftp_chkput(struct obex_session *os, void *user_data)
 
        path = g_build_filename(ftp->folder, name, NULL);
 
+       ret = obex_put_stream_start(os, path);
+
 #ifdef TIZEN_PATCH
+       if (ret == 0)
        manager_emit_transfer_started(os);
 #endif
 
-       ret = obex_put_stream_start(os, path);
-
        g_free(path);
 
        return ret;
index 9a80c15..2132b3e 100644 (file)
@@ -203,11 +203,22 @@ skip_auth:
 
        path = g_build_filename(folder, name, NULL);
 
+#ifdef TIZEN_PATCH
+       err = obex_put_stream_start(os, path);
+
+       g_free(path);
+
+       if (err < 0)
+               goto failed;
+
+       manager_emit_transfer_started(os);
+#else
        manager_emit_transfer_started(os);
 
        err = obex_put_stream_start(os, path);
 
        g_free(path);
+#endif
 
 failed:
        g_free(folder);
index f08ddf7..d9eaea2 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
+#include <stdarg.h>
 #include <glib.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include "phonebook.h"
 
 #include <dbus/dbus.h>
-#define QUERY_GET_PHONEBOOK_SIZE       "GetPhonebookSize"
 
-#define QUERY_GET_PHONEBOOK                    "GetPhonebook"
-#define QUERY_GET_CALLS                                "GetCalls"
+#define PHONEBOOK_DESTINATION          "org.bluez.pb_agent"
+#define PHONEBOOK_PATH                 "/org/bluez/pb_agent"
+#define PHONEBOOK_INTERFACE            "org.bluez.PbAgent"
 
+#define QUERY_GET_PHONEBOOK_SIZE       "GetPhonebookSize"
+#define QUERY_GET_PHONEBOOK                    "GetPhonebook"
 #define QUERY_GET_PHONEBOOK_LIST       "GetPhonebookList"
-#define QUERY_GET_CALLS_LIST           "GetCallsList"
-
 #define QUERY_GET_PHONEBOOK_ENTRY      "GetPhonebookEntry"
-#define QUERY_GET_CALLS_ENTRY          "GetCallsEntry"
-
-#define QUERY_CALL_TYPE_INCOMING       "incoming"
-#define QUERY_CALL_TYPE_OUTGOING       "outgoing"
-#define QUERY_CALL_TYPE_MISSED         "missed"
-#define QUERY_CALL_TYPE_COMBINED       "combined"
 
 struct phonebook_tizen_data {
        phonebook_cb cb;
@@ -67,18 +62,9 @@ struct phonebook_tizen_data {
        phonebook_entry_cb entry_cb;
        phonebook_cache_ready_cb ready_cb;
 
-       const char *id;
        char *req_name;
 };
 
-static void get_phonebook_reply(DBusPendingCall *call, void *user_data);
-static void get_phonebook_size_reply(DBusPendingCall *call, void *user_data);
-static void get_phonebook_list_reply(DBusPendingCall *call, void *user_data);
-static void get_phonebook_entry_reply(DBusPendingCall *call, void *user_data);
-int get_phonebook_data(const char *query, const char *call_type,
-                               struct phonebook_tizen_data *s_data);
-static gboolean get_sim_phonebook_reply(void *user_data);
-
 static gboolean folder_is_valid(const char *folder)
 {
        if (folder == NULL)
@@ -102,6 +88,250 @@ static gboolean folder_is_valid(const char *folder)
        return FALSE;
 }
 
+static gboolean phonebook_request(struct phonebook_tizen_data *data,
+                               const gchar *method,
+                               DBusPendingCallNotifyFunction function,
+                               int first_arg_type,
+                               ...)
+{
+       DBusConnection *connection;
+       DBusPendingCall *call;
+       DBusMessage *message;
+
+       va_list args;
+
+       DBG("%s\n", method);
+
+       if (!method) {
+               error("Can't get method name");
+               return FALSE;
+       }
+
+
+       connection = dbus_bus_get(DBUS_BUS_SESSION, NULL);
+       if (!connection) {
+               error("Can't get on session bus");
+               return FALSE;
+       }
+
+       message = dbus_message_new_method_call(PHONEBOOK_DESTINATION,
+                       PHONEBOOK_PATH,
+                       PHONEBOOK_INTERFACE,
+                       method);
+       if(!message) {
+               dbus_connection_unref(connection);
+               error("Can't Allocate new message");
+               return FALSE;
+       }
+
+       va_start(args, first_arg_type);
+       dbus_message_append_args_valist(message, first_arg_type, args);
+       va_end(args);
+
+       if (dbus_connection_send_with_reply(connection, message, &call, -1) == FALSE) {
+               dbus_message_unref(message);
+               dbus_connection_unref(connection);
+               return FALSE;
+       }
+       dbus_pending_call_set_notify(call, function, data, NULL);
+
+       dbus_pending_call_unref(call);
+       dbus_message_unref(message);
+       dbus_connection_unref(connection);
+
+       return TRUE;
+}
+
+static void get_phonebook_size_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply = dbus_pending_call_steal_reply(call);
+       struct phonebook_tizen_data *s_data = user_data;
+       DBusError derr;
+       uint32_t phonebook_size;
+
+       DBG("");
+
+       if (!reply) {
+               DBG("Reply Error\n");
+               return;
+       }
+
+       dbus_error_init(&derr);
+       if (dbus_set_error_from_message(&derr, reply)) {
+               error("Replied with an error: %s, %s", derr.name, derr.message);
+               dbus_error_free(&derr);
+               phonebook_size = 0;
+       } else {
+               dbus_message_get_args(reply, NULL, DBUS_TYPE_UINT32,
+                                       &phonebook_size, DBUS_TYPE_INVALID);
+               DBG("phonebooksize:%d\n", phonebook_size);
+       }
+
+       s_data->cb(NULL, 0, phonebook_size, 0, TRUE, s_data->user_data);
+
+       dbus_message_unref(reply);
+}
+
+static void get_phonebook_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply = dbus_pending_call_steal_reply(call);
+       struct phonebook_tizen_data *s_data = user_data;
+       DBusError derr;
+       GString *buffer;
+
+       guint  new_missed_call = 0;
+
+       uint32_t count = 0;
+
+       DBG("");
+
+       if (!reply) {
+               DBG("Reply Error\n");
+               return;
+       }
+
+       buffer = g_string_new("");
+
+       dbus_error_init(&derr);
+       if (dbus_set_error_from_message(&derr, reply)) {
+               error("Replied with an error: %s, %s", derr.name, derr.message);
+               dbus_error_free(&derr);
+       } else {
+               DBusMessageIter iter;
+
+               dbus_message_iter_init(reply, &iter);
+
+               if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) {
+                       DBusMessageIter recurse_iter;
+
+                       dbus_message_iter_recurse(&iter, &recurse_iter);
+                       while(dbus_message_iter_get_arg_type(&recurse_iter) == DBUS_TYPE_STRING) {
+                               gchar *str;
+
+                               dbus_message_iter_get_basic(&recurse_iter, &str);
+                               dbus_message_iter_next(&recurse_iter);
+
+                               g_string_append(buffer, str);
+
+                               DBG("str:\n%s\n", str);
+
+                               count++;
+                       }
+                       dbus_message_iter_next(&iter);
+               }
+
+               if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT16)
+                       dbus_message_iter_get_basic(&iter, &new_missed_call);
+
+               DBG("new_missed_call %d\n", new_missed_call);
+       }
+
+       s_data->cb(buffer->str, buffer->len, count, new_missed_call, 1, s_data->user_data);
+
+       g_string_free(buffer, TRUE);
+       dbus_message_unref(reply);
+}
+
+
+static void get_phonebook_list_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply = dbus_pending_call_steal_reply(call);
+       DBusMessageIter iter, iter_struct, entry;
+       struct phonebook_tizen_data *data = user_data;
+       DBusError derr;
+       uint32_t handle = 0;
+       const char *name = NULL;
+       const char *tel = NULL;
+       char id[10];
+
+       if (!reply) {
+               DBG("Reply Error\n");
+               return;
+       }
+
+       dbus_error_init(&derr);
+       if (dbus_set_error_from_message(&derr, reply)) {
+               error("Replied with an error: %s, %s", derr.name, derr.message);
+               dbus_error_free(&derr);
+       } else {
+
+               dbus_message_iter_init(reply, &iter);
+
+               dbus_message_iter_recurse(&iter, &iter_struct);
+
+               while (dbus_message_iter_get_arg_type(&iter_struct) ==
+                                                       DBUS_TYPE_STRUCT) {
+                       dbus_message_iter_recurse(&iter_struct, &entry);
+
+                       dbus_message_iter_get_basic(&entry, &name);
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_get_basic(&entry, &tel);
+                       dbus_message_iter_next(&entry);
+                       dbus_message_iter_get_basic(&entry, &handle);
+
+                       /*
+                       DBG("[handle:%d name:%s tel:%s]\n", handle, name, tel);
+                       */
+
+                       snprintf(id, sizeof(id), "%d.vcf", handle);
+
+                       data->entry_cb(id, handle, name, NULL, tel,
+                                       data->user_data);
+
+                       dbus_message_iter_next(&iter_struct);
+               }
+       }
+
+       data->ready_cb(data->user_data);
+
+       dbus_message_unref(reply);
+}
+
+static void get_phonebook_entry_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply = dbus_pending_call_steal_reply(call);
+       struct phonebook_tizen_data *s_data = user_data;
+       DBusError derr;
+       const char *phonebook_entry;
+
+       DBG("");
+
+       if (!reply) {
+               DBG("Reply Error\n");
+               return;
+       }
+
+       dbus_error_init(&derr);
+       if (dbus_set_error_from_message(&derr, reply)) {
+               error("Replied with an error: %s, %s", derr.name, derr.message);
+               dbus_error_free(&derr);
+       } else {
+               dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING,
+                                       &phonebook_entry, DBUS_TYPE_INVALID);
+               DBG("phonebook_entry:[%s]\n", phonebook_entry);
+       }
+
+       s_data->cb(phonebook_entry, strlen(phonebook_entry), 1, 0, TRUE,
+                                                       s_data->user_data);
+
+       dbus_message_unref(reply);
+}
+
+static gboolean get_sim_phonebook_reply(void *user_data)
+{
+       struct phonebook_tizen_data *s_data = user_data;
+       uint32_t phonebook_size = 0;
+       int lastpart = 1;
+
+       DBG("");
+
+       /* We don't support phonebook of SIM
+        * Send dummy data */
+       s_data->cb(NULL, 0, phonebook_size, 0, lastpart, s_data->user_data);
+
+       return FALSE;
+}
+
 int phonebook_init(void)
 {
        return 0;
@@ -229,37 +459,33 @@ void *phonebook_pull(const char *name, const struct apparam_field *params,
 
 int phonebook_pull_read(void *request)
 {
-       struct phonebook_tizen_data *s_data = request;
-       const char *query;
-       const char *call_type = NULL;
-
-       DBG("name %s", s_data->req_name);
-
-       s_data->reply_cb = get_phonebook_reply;
-
-       if (g_strcmp0(s_data->req_name, "/telecom/ich.vcf") == 0) {
-               call_type = QUERY_CALL_TYPE_INCOMING;
-               query = QUERY_GET_CALLS;
-       } else if (g_strcmp0(s_data->req_name, "/telecom/och.vcf") == 0) {
-               call_type = QUERY_CALL_TYPE_OUTGOING;
-               query = QUERY_GET_CALLS;
-       } else if (g_strcmp0(s_data->req_name, "/telecom/mch.vcf") == 0) {
-               call_type = QUERY_CALL_TYPE_MISSED;
-               query = QUERY_GET_CALLS;
-       } else if (g_strcmp0(s_data->req_name, "/telecom/cch.vcf") == 0) {
-               call_type = QUERY_CALL_TYPE_COMBINED;
-               query = QUERY_GET_CALLS;
-       } else if (g_strcmp0(s_data->req_name, "/SIM1/telecom/pb.vcf") == 0) {
-               g_idle_add(get_sim_phonebook_reply, s_data);
+       struct phonebook_tizen_data *data = request;
+
+       DBG("name %s", data->req_name);
+
+       if (data->params->maxlistcount == 0) {
+               phonebook_request(data,
+                               QUERY_GET_PHONEBOOK_SIZE,
+                               get_phonebook_size_reply,
+                               DBUS_TYPE_STRING, &data->req_name,
+                               DBUS_TYPE_INVALID);
+               return 0;
+       }
+
+       if (g_strcmp0(data->req_name, "/SIM1/telecom/pb.vcf") == 0) {
+               g_idle_add(get_sim_phonebook_reply, data);
                return 0;
-       } else if (s_data->params->maxlistcount == 0) {
-               query = QUERY_GET_PHONEBOOK_SIZE;
-               s_data->reply_cb = get_phonebook_size_reply;
-       } else {
-               query = QUERY_GET_PHONEBOOK;
        }
 
-       get_phonebook_data(query, call_type, s_data);
+       phonebook_request(data,
+                       QUERY_GET_PHONEBOOK,
+                       get_phonebook_reply,
+                       DBUS_TYPE_STRING, &data->req_name,
+                       DBUS_TYPE_UINT64, &data->params->filter,
+                       DBUS_TYPE_BYTE, &data->params->format,
+                       DBUS_TYPE_UINT16, &data->params->maxlistcount,
+                       DBUS_TYPE_UINT16, &data->params->liststartoffset,
+                       DBUS_TYPE_INVALID);
 
        return 0;
 }
@@ -268,31 +494,29 @@ void *phonebook_get_entry(const char *folder, const char *id,
                        const struct apparam_field *params, phonebook_cb cb,
                        void *user_data, int *err)
 {
-       struct phonebook_tizen_data *s_data;
-       DBusPendingCallNotifyFunction reply_cb;
-       const char *query;
-
-       DBG("folder %s id %s", folder, id);
+       struct phonebook_tizen_data *data;
 
-       if (g_strcmp0(folder, "/telecom/pb") == 0) {
-               query = QUERY_GET_PHONEBOOK_ENTRY;
-       } else {
-               query = QUERY_GET_CALLS_ENTRY;
+       if (!g_str_has_suffix(id, ".vcf")) {
+               DBG("invaild request");
+               if (err)
+                       *err = -EBADR;
+               return NULL;
        }
+       DBG("folder %s id %s", folder, id);
 
-       reply_cb = get_phonebook_entry_reply;
-
-       s_data = g_new0(struct phonebook_tizen_data, 1);
-       s_data->params = params;
-       s_data->user_data = user_data;
-       s_data->cb = cb;
-       s_data->reply_cb = reply_cb;
-       s_data->id = id;
-
-       get_phonebook_data(query, NULL, s_data);
+       data = g_new0(struct phonebook_tizen_data, 1);
+       data->params = params;
+       data->user_data = user_data;
+       data->cb = cb;
 
-       if (err)
-               *err = 0;
+       phonebook_request(data,
+                       QUERY_GET_PHONEBOOK_ENTRY,
+                       get_phonebook_entry_reply,
+                       DBUS_TYPE_STRING, &folder,
+                       DBUS_TYPE_STRING, &id,
+                       DBUS_TYPE_UINT64, &data->params->filter,
+                       DBUS_TYPE_BYTE, &data->params->format,
+                       DBUS_TYPE_INVALID);
 
        return NULL;
 }
@@ -300,286 +524,28 @@ void *phonebook_get_entry(const char *folder, const char *id,
 void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
                phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
 {
-       struct phonebook_tizen_data *s_data;
-       DBusPendingCallNotifyFunction reply_cb;
-       const char *query;
-       const char *call_type = NULL;
+       struct phonebook_tizen_data *data;
+       gboolean req = FALSE;
 
        DBG("name %s", name);
 
-       if (g_strcmp0(name, "/telecom/pb") == 0) {
-               query = QUERY_GET_PHONEBOOK_LIST;
-       } else if (g_strcmp0(name, "/telecom/ich") == 0) {
-               call_type = QUERY_CALL_TYPE_INCOMING;
-               query = QUERY_GET_CALLS_LIST;
-       } else if (g_strcmp0(name, "/telecom/och") == 0) {
-               call_type = QUERY_CALL_TYPE_OUTGOING;
-               query = QUERY_GET_CALLS_LIST;
-       } else if (g_strcmp0(name, "/telecom/mch") == 0) {
-               call_type = QUERY_CALL_TYPE_MISSED;
-               query = QUERY_GET_CALLS_LIST;
-       } else if (g_strcmp0(name, "/telecom/cch") == 0) {
-               call_type = QUERY_CALL_TYPE_COMBINED;
-               query = QUERY_GET_CALLS_LIST;
-       } else {
-               if (err)
-                       *err = -ENOENT;
-               return NULL;
-       }
-
-       reply_cb = get_phonebook_list_reply;
-
-       s_data = g_new0(struct phonebook_tizen_data, 1);
-       s_data->user_data = user_data;
-       s_data->entry_cb = entry_cb;
-       s_data->ready_cb = ready_cb;
-       s_data->reply_cb = reply_cb;
-       s_data->params = NULL;
-
-       get_phonebook_data(query, call_type, s_data);
-
-       if (err)
-               *err = 0;
-
-       return NULL;
-}
-
-static void get_phonebook_reply(DBusPendingCall *call, void *user_data)
-{
-       DBusMessage *reply = dbus_pending_call_steal_reply(call);
-       DBusMessageIter iter, element;
-       struct phonebook_tizen_data *s_data = user_data;
-       DBusError derr;
-       uint32_t phonebook_size = 0;
-       GString *buffer;
-       int lastpart = 1;
-
-       DBG("");
-
-       buffer = g_string_new("");
-
-       dbus_error_init(&derr);
-       if (dbus_set_error_from_message(&derr, reply)) {
-               error("Replied with an error: %s, %s", derr.name, derr.message);
-               dbus_error_free(&derr);
-       } else {
-               dbus_message_iter_init(reply, &iter);
-
-               if (dbus_message_iter_get_arg_type(&iter) ==
-                                                       DBUS_TYPE_INT32) {
-                       dbus_message_iter_get_basic(&iter, &lastpart);
-                       dbus_message_iter_next(&iter);
-               }
-
-               dbus_message_iter_recurse(&iter, &element);
-
-               while(dbus_message_iter_get_arg_type(&element) !=
-                                                       DBUS_TYPE_INVALID) {
-                       char *arg;
-
-                       if (dbus_message_iter_get_arg_type(&element) !=
-                                                       DBUS_TYPE_STRING) {
-                               DBG("element is not a string");
-                               dbus_message_iter_next(&element);
-                               continue;
-                       }
-
-                       dbus_message_iter_get_basic(&element, &arg);
-
-                       g_string_append(buffer, arg);
-
-                       dbus_message_iter_next(&element);
-
-                       phonebook_size++;
-               }
-
-               DBG("phonebooksize : %d\n", phonebook_size);
-       }
-
-       s_data->cb(buffer->str, buffer->len, phonebook_size, 0, lastpart,
-                                                       s_data->user_data);
-
-       g_string_free(buffer, TRUE);
-
-       dbus_message_unref(reply);
-}
-
-static void get_phonebook_size_reply(DBusPendingCall *call, void *user_data)
-{
-       DBusMessage *reply = dbus_pending_call_steal_reply(call);
-       struct phonebook_tizen_data *s_data = user_data;
-       DBusError derr;
-       uint32_t phonebook_size;
-
-       DBG("");
-
-       dbus_error_init(&derr);
-       if (dbus_set_error_from_message(&derr, reply)) {
-               error("Replied with an error: %s, %s", derr.name, derr.message);
-               dbus_error_free(&derr);
-               phonebook_size = 0;
-       } else {
-               dbus_message_get_args(reply, NULL, DBUS_TYPE_UINT32,
-                                       &phonebook_size, DBUS_TYPE_INVALID);
-               DBG("phonebooksize:%d\n", phonebook_size);
-       }
-
-       s_data->cb(NULL, 0, phonebook_size, 0, TRUE, s_data->user_data);
-
-       dbus_message_unref(reply);
-}
-
-static void get_phonebook_list_reply(DBusPendingCall *call, void *user_data)
-{
-       DBusMessage *reply = dbus_pending_call_steal_reply(call);
-       DBusMessageIter iter, iter_struct, entry;
-       struct phonebook_tizen_data *s_data = user_data;
-       DBusError derr;
-       uint32_t handle = 0;
-       const char *name = NULL;
-       const char *tel = NULL;
-       char id[10];
-
-       DBG("");
-
-       dbus_error_init(&derr);
-       if (dbus_set_error_from_message(&derr, reply)) {
-               error("Replied with an error: %s, %s", derr.name, derr.message);
-               dbus_error_free(&derr);
-       } else {
-
-               dbus_message_iter_init(reply, &iter);
-
-               dbus_message_iter_recurse(&iter, &iter_struct);
-
-               while (dbus_message_iter_get_arg_type(&iter_struct) ==
-                                                       DBUS_TYPE_STRUCT) {
-                       dbus_message_iter_recurse(&iter_struct, &entry);
-
-                       dbus_message_iter_get_basic(&entry, &name);
-                       dbus_message_iter_next(&entry);
-                       dbus_message_iter_get_basic(&entry, &tel);
-                       dbus_message_iter_next(&entry);
-                       dbus_message_iter_get_basic(&entry, &handle);
-
-                       //DBG("[handle:%d name:%s tel:%s]\n", handle, name, tel);
-
-                       snprintf(id, sizeof(id), "%d.vcf", handle);
-
-                       s_data->entry_cb(id, handle, name, NULL, tel,
-                                                       s_data->user_data);
-
-                       dbus_message_iter_next(&iter_struct);
-               }
-       }
-
-       s_data->ready_cb(s_data->user_data);
-
-       dbus_message_unref(reply);
-}
-
-static void get_phonebook_entry_reply(DBusPendingCall *call, void *user_data)
-{
-       DBusMessage *reply = dbus_pending_call_steal_reply(call);
-       struct phonebook_tizen_data *s_data = user_data;
-       DBusError derr;
-       const char *phonebook_entry;
-
-       DBG("");
-
-       dbus_error_init(&derr);
-       if (dbus_set_error_from_message(&derr, reply)) {
-               error("Replied with an error: %s, %s", derr.name, derr.message);
-               dbus_error_free(&derr);
-       } else {
-               dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING,
-                                       &phonebook_entry, DBUS_TYPE_INVALID);
-               DBG("phonebook_entry:[%s]\n", phonebook_entry);
-       }
-
-       s_data->cb(phonebook_entry, strlen(phonebook_entry), 1, 0, TRUE,
-                                                       s_data->user_data);
-
-       dbus_message_unref(reply);
-}
-
-int get_phonebook_data(const char *query, const char *call_type,
-                               struct phonebook_tizen_data *s_data)
-{
-       DBusConnection *conn;
-       DBusPendingCall *call;
-       DBusMessage *message;
-
-       DBG("call_type:%s", call_type);
-
-       conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
-       if (!conn) {
-               error("Can't get on session bus");
-               return -1;
-       }
-
-       message = dbus_message_new_method_call("org.bluez.pb_agent",
-                                                       "/org/bluez/pb_agent",
-                                                       "org.bluez.PbAgent",
-                                                       query);
-       if (!message) {
-               error("Can't allocate new message");
-               return -1;
-       }
-
-       if (s_data->id) {
-               DBG("phonebook_get_entry");
-               dbus_message_append_args(message, DBUS_TYPE_STRING, &s_data->id,
-                                                       DBUS_TYPE_INVALID);
-       } else if (s_data->params) {
-               DBG("phonebook_pull_read");
-               if (call_type)
-                       dbus_message_append_args(message, DBUS_TYPE_UINT16,
-                                               &s_data->params->maxlistcount,
-                                               DBUS_TYPE_UINT16,
-                                               &s_data->params->liststartoffset,
-                                               DBUS_TYPE_STRING, &call_type,
-                                               DBUS_TYPE_INVALID);
+       data = g_new0(struct phonebook_tizen_data, 1);
+       data->user_data = user_data;
+       data->entry_cb = entry_cb;
+       data->ready_cb = ready_cb;
+
+       req = phonebook_request(data,
+                               QUERY_GET_PHONEBOOK_LIST,
+                               get_phonebook_list_reply,
+                               DBUS_TYPE_STRING, &name,
+                               DBUS_TYPE_INVALID);
+
+       if (*err) {
+               if (req)
+                       *err = 0;
                else
-                       dbus_message_append_args(message, DBUS_TYPE_UINT16,
-                                               &s_data->params->maxlistcount,
-                                               DBUS_TYPE_UINT16,
-                                               &s_data->params->liststartoffset,
-                                               DBUS_TYPE_INVALID);
-
-       } else if (call_type) {
-               DBG("phonebook_create_cache");
-               dbus_message_append_args(message, DBUS_TYPE_STRING, &call_type,
-                                                       DBUS_TYPE_INVALID);
-       }
-
-       if (dbus_connection_send_with_reply(conn, message, &call,
-                                                       -1) == FALSE) {
-               error("Could not send dbus message");
-               dbus_message_unref(message);
-               return -1;
+                       *err = -ENOENT;
        }
 
-       dbus_pending_call_set_notify(call, s_data->reply_cb, s_data, NULL);
-       dbus_message_unref(message);
-
-       //dbus_connection_unref(conn);
-
-       return 0;
-}
-
-static gboolean get_sim_phonebook_reply(void *user_data)
-{
-       struct phonebook_tizen_data *s_data = user_data;
-       uint32_t phonebook_size = 0;
-       int lastpart = 1;
-
-       DBG("");
-
-       /* We don't support phonebook of SIM
-        * Send dummy data */
-       s_data->cb(NULL, 0, phonebook_size, 0, lastpart, s_data->user_data);
-
-       return FALSE;
+       return data;
 }
-
index 74de50f..03b8d24 100644 (file)
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.openobex
-Exec=@libexecdir@/obexd -d --symlinks -r /opt/media
+Exec=/bin/sh -c 'if [ -z `ps ax | grep -v grep | grep obexd` ] ; then exec @libexecdir@/obexd -d --noplugin=syncevolution,pcsuite --symlinks -r /opt/media; fi'