This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 client/Makefile.am |    2 +-
 client/main.c      |    4 +-
 client/pbap.c      |   86 ++++++++++++++++++++++++++++++++++++++++++++
 client/pbap.h      |   31 ++++++++++++++++
 client/session.c   |  100 ++++++++++++++++++++++++++++++++-------------------
 gwobex/gw-obex.c   |   37 +++++++++++++++++++
 gwobex/gw-obex.h   |   42 ++++++++++++++++++++++
 test/main.c        |   70 +++++++++++++++++++++++++++++++++---
 8 files changed, 327 insertions(+), 45 deletions(-)

New commits:
commit c257d0bc46ba0c5aff880f90243378ca9d9d7aa4
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Thu Nov 27 14:48:21 2008 +0100

    Add support setting phonebook and pulling vcard listing

commit 7dd3097196d5cdeddab6016af4c76c457250a1b3
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Thu Nov 27 14:46:26 2008 +0100

    Add more functions for dealing with application parameters

commit 4bbb746f51f087cc7f316b390be8c64661da4f2a
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Thu Nov 27 14:38:39 2008 +0100

    Fix PBAP interface registration

commit 59fcd13bb9621a83dd777c353fd2668c9e8b1962
Author: Raymond Liu <[EMAIL PROTECTED]>
Date:   Thu Nov 27 12:44:21 2008 +0800

    Add framework code for pbap client


Diff in this email is a maximum of 400 lines.
diff --git a/client/Makefile.am b/client/Makefile.am
index 4a9bfa5..3660eaf 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -8,7 +8,7 @@ service_DATA = $(service_in_files:.service.in=.service)
 
 libexec_PROGRAMS = obex-client
 
-obex_client_SOURCES = main.c session.h session.c
+obex_client_SOURCES = main.c session.h session.c pbap.h pbap.c
 
 obex_client_LDADD = @GWOBEX_LIBS@ @GDBUS_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ \
                                                @OPENOBEX_LIBS@ @BLUEZ_LIBS@
diff --git a/client/main.c b/client/main.c
index 9595af9..0ce274a 100644
--- a/client/main.c
+++ b/client/main.c
@@ -180,7 +180,7 @@ static DBusMessage *send_files(DBusConnection *connection,
        data->agent = g_strdup(agent);
        data->files = files;
 
-       if (session_create(NULL, dest, NULL, create_callback, data) == 0)
+       if (session_create(NULL, dest, "OPP", create_callback, data) == 0)
                return NULL;
 
        g_ptr_array_free(data->files, TRUE);
@@ -256,7 +256,7 @@ static DBusMessage *pull_business_card(DBusConnection 
*connection,
        data->message = dbus_message_ref(message);
        data->sender = g_strdup(dbus_message_get_sender(message));
 
-       if (session_create(source, dest, NULL,
+       if (session_create(source, dest, "OPP",
                                        pull_session_callback, data) == 0)
                return NULL;
 
diff --git a/client/pbap.c b/client/pbap.c
new file mode 100644
index 0000000..e29d3c9
--- /dev/null
+++ b/client/pbap.c
@@ -0,0 +1,86 @@
+/*
+ *
+ *  OBEX Client
+ *
+ *  Copyright (C) 2007-2008  Intel Corporation
+ *  Copyright (C) 2007-2008  Marcel Holtmann <[EMAIL PROTECTED]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <gdbus.h>
+
+#include "session.h"
+#include "pbap.h"
+
+static DBusMessage *pbap_pull_phonebook(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       return NULL;
+}
+
+static DBusMessage *pbap_set_phonebook(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       return NULL;
+}
+
+static DBusMessage *pbap_pull_vcard_listing(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       return NULL;
+}
+
+static DBusMessage *pbap_pull_vcard_entry(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       return NULL;
+}
+
+static GDBusMethodTable pbap_methods[] = {
+       /* PullPhoneBook input parameters : Name, Filter, Format,
+                                       MaxListCount, ListStartOffset */
+       { "PullPhoneBook",      "styqq", "s",   pbap_pull_phonebook,
+                                               G_DBUS_METHOD_FLAG_ASYNC },
+       /* SetPhoneBook input parameters : Name */
+       { "SetPhoneBook",       "s", "",        pbap_set_phonebook },
+       /* PullvCardListing input parameters : Name, Order, SearchValue,
+                       SearchAttribute, MaxListCount, ListStartOffset */
+       { "PullvCardListing",   "sysyqq", "s",  pbap_pull_vcard_listing,
+                                               G_DBUS_METHOD_FLAG_ASYNC },
+       /* PullPhoneBook input parameters : Name, Filter, Format */
+       { "PullvCardEntry",     "sty", "s",     pbap_pull_vcard_entry,
+                                               G_DBUS_METHOD_FLAG_ASYNC },
+       { }
+};
+
+gboolean pbap_register_interface(DBusConnection *connection, const char *path,
+                               void *user_data, GDBusDestroyFunction destroy)
+{
+       return g_dbus_register_interface(connection, path, PBAP_INTERFACE,
+                               pbap_methods, NULL, NULL, user_data, destroy);
+}
+
+void pbap_unregister_interface(DBusConnection *connection, const char *path)
+{
+       g_dbus_unregister_interface(connection, path, PBAP_INTERFACE);
+}
diff --git a/client/pbap.h b/client/pbap.h
new file mode 100644
index 0000000..76d7819
--- /dev/null
+++ b/client/pbap.h
@@ -0,0 +1,31 @@
+/*
+ *
+ *  OBEX Client
+ *
+ *  Copyright (C) 2007-2008  Intel Corporation
+ *  Copyright (C) 2007-2008  Marcel Holtmann <[EMAIL PROTECTED]>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <gdbus.h>
+
+#define PBAP_INTERFACE  "org.openobex.PhonebookAccess"
+
+gboolean pbap_register_interface(DBusConnection *connection, const char *path,
+                               void *user_data, GDBusDestroyFunction destroy);
+void pbap_unregister_interface(DBusConnection *connection, const char *path);
diff --git a/client/session.c b/client/session.c
index 03ddffd..30231fd 100644
--- a/client/session.c
+++ b/client/session.c
@@ -39,6 +39,7 @@
 #include <bluetooth/sdp.h>
 #include <bluetooth/sdp_lib.h>
 
+#include "pbap.h"
 #include "session.h"
 
 #define AGENT_INTERFACE  "org.openobex.Agent"
@@ -104,9 +105,19 @@ static void session_unref(struct session_data *session)
                close(session->sock);
 
        if (session->conn) {
-               if (session->transfer_path)
-                       g_dbus_unregister_interface(session->conn,
-                                       session->transfer_path, 
TRANSFER_INTERFACE);
+               if (session->transfer_path) {
+                       switch (session->uuid) {
+                       case OBEX_FILETRANS_SVCLASS_ID:
+                               g_dbus_unregister_interface(session->conn,
+                                               session->transfer_path,
+                                                       TRANSFER_INTERFACE);
+                               break;
+                       case PBAP_PSE_SVCLASS_ID:
+                               pbap_unregister_interface(session->conn,
+                                               session->transfer_path);
+                               break;
+                       }
+               }
 
                dbus_connection_unref(session->conn);
        }
@@ -388,12 +399,19 @@ int session_create(const char *source,
 
        str2ba(destination, &session->dst);
 
-       if (target != NULL) {
+       if (!g_ascii_strncasecmp(target, "OPP", 3)) {
+               session->uuid = OBEX_OBJPUSH_SVCLASS_ID;
+       } else if (!g_ascii_strncasecmp(target, "FTP", 3)) {
                session->uuid = OBEX_FILETRANS_SVCLASS_ID;
                session->target = OBEX_FTP_UUID;
                session->target_len = OBEX_FTP_UUID_LEN;
-       } else
-               session->uuid = OBEX_OBJPUSH_SVCLASS_ID;
+       } else if (!g_ascii_strncasecmp(target, "PBAP", 4)) {
+               session->uuid = PBAP_PSE_SVCLASS_ID;
+               session->target = OBEX_PBAP_UUID;
+               session->target_len = OBEX_PBAP_UUID_LEN;
+       } else {
+               return -EINVAL;
+       }
 
        callback = g_try_malloc0(sizeof(*callback));
        if (callback == NULL) {
@@ -1156,6 +1174,7 @@ complete:
 
 int session_get(struct session_data *session, const char *type,
                const char *filename, const char *targetname,
+               const guint8  *apparam, gint apparam_size,
                session_callback_t func)
 {
        struct callback_data *callback;
@@ -1175,7 +1194,17 @@ int session_get(struct session_data *session, const char 
*type,
                        fprintf(stderr, "open(): %s(%d)\n", strerror(err), err);
                        return -err;
                }
+       }
 
+       session->transfer_path = register_transfer(session->conn, session);
+       if (session->transfer_path == NULL) {
+               if (fd)
+                       close(fd);
+
+               return -EIO;
+       }
+
+       if (!g_str_equal(type, "x-obex/folder-listing")) {
                session->transfer_path = register_transfer(session->conn, 
session);
                if (session->transfer_path == NULL) {
                        if (fd)
@@ -1193,8 +1222,8 @@ int session_get(struct session_data *session, const char 
*type,
 
        session_ref(session);
 
-       xfer = gw_obex_get_async(session->obex,
-                               filename, type, NULL);
+       xfer = gw_obex_get_async_with_apparam(session->obex,
+                               filename, type, apparam, apparam_size, NULL);
        if (xfer == NULL) {
                close(session->fd);
                session_unref(session);
@@ -1212,11 +1241,11 @@ int session_get(struct session_data *session, const 
char *type,
        callback->session = session;
        callback->func = func;
 
-       if (type && g_str_equal(type, "x-obex/folder-listing"))
-               gw_obex_xfer_set_callback(xfer, get_xfer_listing_progress,
-                                               callback);
-       else
+       if (type == NULL)
                gw_obex_xfer_set_callback(xfer, get_xfer_progress, callback);
+       else
+               gw_obex_xfer_set_callback(xfer, get_xfer_listing_progress,
+                                       callback);
 
        session->xfer = xfer;
 
@@ -1283,7 +1312,7 @@ static DBusMessage *list_folder(DBusConnection 
*connection,
                                "Transfer in progress");
 
        if (session_get(session, "x-obex/folder-listing",
-                               NULL, NULL, list_folder_callback) < 0)
+                               NULL, NULL, NULL, 0, list_folder_callback) < 0)
                return g_dbus_create_error(message,
                                "org.openobex.Error.Failed",
                                "Failed");
@@ -1313,7 +1342,7 @@ static DBusMessage *get_file(DBusConnection *connection,
                                "org.openobex.Error.InvalidArguments", NULL);
 
        if (session_get(session, NULL, source_file,
-                               target_file, get_file_callback) < 0)
+                               target_file, NULL, 0, get_file_callback) < 0)
                return g_dbus_create_error(message,
                                "org.openobex.Error.Failed",
                                "Failed");
@@ -1429,7 +1458,6 @@ static void put_xfer_progress(GwObexXfer *xfer, gpointer 
user_data)
        return;
 
 complete:
-
        if (len == 0)
                agent_notify_complete(session->conn, session->agent_name,
                                session->agent_path, session->transfer_path);
@@ -1545,39 +1573,37 @@ int session_pull(struct session_data *session,
 
 int session_register(struct session_data *session)
 {
-       GDBusMethodTable *methods;
-       const char *iface;
-
-       switch (session->uuid) {
-       case OBEX_FILETRANS_SVCLASS_ID:
-               iface = FTP_INTERFACE;
-               methods = ftp_methods;
-               break;
-       default:
-               return -EINVAL;
-       }
+       gboolean result = FALSE;
 
        session->path = g_strdup_printf("%s/session%ju",
-                                       SESSION_BASEPATH, counter++);
+                                               SESSION_BASEPATH, counter++);
 
        if (g_dbus_register_interface(session->conn, session->path,
-                               SESSION_INTERFACE,
-                               session_methods, NULL, NULL,
-                               session, NULL) == FALSE)
+                                       SESSION_INTERFACE, session_methods,
+                                       NULL, NULL, session, NULL) == FALSE)
                return -EIO;
 
-       if (g_dbus_register_interface(session->conn, session->path,
-                               iface,
-                               methods, NULL, NULL,
-                               session, NULL) == FALSE) {
+       switch (session->uuid) {
+       case OBEX_FILETRANS_SVCLASS_ID:
+               result = g_dbus_register_interface(session->conn,
+                                       session->path, FTP_INTERFACE,
+                                       ftp_methods, NULL, NULL, session, NULL);
+               break;
+       case PBAP_PSE_SVCLASS_ID:
+               result = pbap_register_interface(session->conn,
+                                               session->path, session, NULL);
+               break;
+       }
+
+       if (result == FALSE) {
                g_dbus_unregister_interface(session->conn,
-                               session->path, SESSION_INTERFACE);
+                                       session->path, SESSION_INTERFACE);
                return -EIO;
        }
 
        session->owner_watch = g_dbus_add_disconnect_watch(session->conn,
-                               session->owner, owner_disconnected, session,
-                               NULL);
+                                       session->owner, owner_disconnected,
+                                                               session, NULL);
 
        session_ref(session);
 
diff --git a/gwobex/gw-obex.c b/gwobex/gw-obex.c
index ef32ff8..e656692 100644
--- a/gwobex/gw-obex.c
+++ b/gwobex/gw-obex.c
@@ -129,6 +129,43 @@ gboolean gw_obex_put_buf(GwObex      *ctx,
     return ret;
 }
 
+gboolean gw_obex_get_buf_with_apparam(GwObex        *ctx,
+                                      const gchar   *remote,
+                                      const gchar   *type,
+                                      const guint8  *apparam,
+                                      gint           apparam_size,
+                                      gchar        **buf,
+                                      gint          *buf_size,
+                                      gint          *error) {
+    gboolean ret;
+    GW_OBEX_LOCK(ctx);
+    CHECK_DISCONNECT(FALSE, error, ctx);
+    ret = gw_obex_get(ctx, NULL, remote, type, apparam, apparam_size, buf, 
buf_size, -1, FALSE);
+    if (ret == FALSE)
+        gw_obex_get_error(ctx, error);
+    GW_OBEX_UNLOCK(ctx);
+    return ret;
+}
+
+gboolean gw_obex_put_buf_with_apparam(GwObex       *ctx,
+                                      const gchar  *remote,
+                                      const gchar  *type,
+                                      const guint8 *apparam,
+                                      gint          apparam_size,
+                                      const gchar  *buf,
+                                      gint          buf_size,
+                                      gint          time,
+                                      gint         *error) {
+    gboolean ret;
+    GW_OBEX_LOCK(ctx);
+    CHECK_DISCONNECT(FALSE, error, ctx);
+    ret = gw_obex_put(ctx, NULL, remote, type, apparam, apparam_size, buf, 
buf_size, time, -1, FALSE);
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to