This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 gdbus/gdbus.h      |    2 +
 gdbus/mainloop.c   |   43 +++++++++++++++++++
 gdbus/object.c     |    3 +
 gwobex/gw-obex.h   |   15 +++++++
 gwobex/obex-xfer.c |   12 +++++
 plugins/ebook.c    |    5 ++-
 src/pbap.c         |  119 ++++++++++++++++++++++++++++++++++++++++++++++-----
 src/phonebook.c    |    9 +++-
 src/phonebook.h    |   10 ++++-
 9 files changed, 201 insertions(+), 17 deletions(-)

New commits:
commit 9b6aa692a63b6535bced4bcaf15306be4e89dac3
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Thu Nov 27 10:50:26 2008 +0100

    Fix apparam_hdr handling and some coding style

commit bc963bc545f5c1214ae1725640b5eabe00eec548
Merge: 45f3689bbe9d7296694e8d3258af337a74b9564a 
a59cfa624d40613d1abf1fb04141a898ce919c67
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Thu Nov 27 10:45:16 2008 +0100

    Merge branch 'pbap-dev' of git://git.moblin.org/obexd

commit a59cfa624d40613d1abf1fb04141a898ce919c67
Author: Forrest Zhao <[EMAIL PROTECTED]>
Date:   Thu Nov 27 11:35:16 2008 +0800

    parsing the application parameters header of PBAP PullPhonebook

commit 45f3689bbe9d7296694e8d3258af337a74b9564a
Author: Raymond Liu <[EMAIL PROTECTED]>
Date:   Thu Nov 27 08:50:56 2008 +0800

    Add gw_obex_get_async_with_apparam function

commit f35d43add4de315f34a743a0430bc2d4de474f76
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Nov 26 14:33:36 2008 +0100

    Don't expect reply when sending D-Bus messages

commit a91d0e742f0e91e5f8a3d531b95b4c45c40523d0
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Wed Nov 26 14:27:11 2008 +0100

    Add function for checking if a service is present


Diff in this email is a maximum of 400 lines.
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 466285c..5ee5c1a 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -37,6 +37,8 @@ typedef void (* GDBusWatchFunction) (DBusConnection 
*connection,
 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
                                                        DBusError *error);
 
+gboolean g_dbus_check_service(DBusConnection *connection, const char *name);
+
 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
                                GDBusWatchFunction function,
                                void *user_data, DBusFreeFunction destroy);
diff --git a/gdbus/mainloop.c b/gdbus/mainloop.c
index 9eacdf4..2e9948d 100644
--- a/gdbus/mainloop.c
+++ b/gdbus/mainloop.c
@@ -275,6 +275,49 @@ DBusConnection *g_dbus_setup_bus(DBusBusType type, const 
char *name,
        return conn;
 }
 
+gboolean g_dbus_check_service(DBusConnection *connection, const char *name)
+{
+       DBusMessage *message, *reply;
+       const char **names;
+       int i, count;
+       gboolean result = FALSE;
+
+       message = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
+                       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "ListNames");
+       if (message == NULL) {
+               error("Can't allocate new message");
+               return FALSE;
+       }
+
+       reply = dbus_connection_send_with_reply_and_block(connection,
+                                                       message, -1, NULL);
+
+       dbus_message_unref(message);
+
+       if (reply == NULL) {
+               error("Failed to execute method call");
+               return FALSE;
+       }
+
+       if (dbus_message_get_args(reply, NULL,
+                               DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+                               &names, &count, DBUS_TYPE_INVALID) == FALSE) {
+               error("Failed to read name list");
+               goto done;
+       }
+
+       for (i = 0; i < count; i++)
+               if (g_str_equal(names[i], name) == TRUE) {
+                       result = TRUE;
+                       break;
+               }
+
+done:
+       dbus_message_unref(reply);
+
+       return result;
+}
+
 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
                                GDBusWatchFunction function,
                                void *user_data, DBusFreeFunction destroy)
diff --git a/gdbus/object.c b/gdbus/object.c
index a417ab9..50313a2 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -576,6 +576,9 @@ gboolean g_dbus_send_message(DBusConnection *connection, 
DBusMessage *message)
 {
        dbus_bool_t result;
 
+       if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL)
+               dbus_message_set_no_reply(message, TRUE);
+
        result = dbus_connection_send(connection, message, NULL);
 
        dbus_message_unref(message);
diff --git a/gwobex/gw-obex.h b/gwobex/gw-obex.h
index 94a6a64..fcbb40a 100644
--- a/gwobex/gw-obex.h
+++ b/gwobex/gw-obex.h
@@ -474,6 +474,21 @@ GwObexXfer *gw_obex_put_async(GwObex *ctx, const char 
*name, const char *type,
  */
 GwObexXfer *gw_obex_get_async(GwObex *ctx, const char *name, const char *type, 
gint *error);
 
+/** Start a GET operation asynchronously with application parameters
+ *
+ * @param ctx   Pointer returned by gw_obex_setup()
+ * @param name  Name of the object (null terminated UTF-8)
+ * @param type  Type of the object (null terminated UTF-8), or NULL
+ * @param apparam      Application parameters of the object
+ * @param apparam_size Application paramters' size
+ * @param error Place to store error code on failure (NULL if not interested)
+ *
+ * @returns a new GwObexXfer object on success, NULL on failure
+ */
+
+GwObexXfer *gw_obex_get_async_with_apparam(GwObex *ctx, const char *name, 
const char *type,
+               const guint8  *apparam, gint apparam_size, gint *error);
+
 
 /** Set a callback function for a GwObexXfer object
  * The callback function will be called in the following situations:
diff --git a/gwobex/obex-xfer.c b/gwobex/obex-xfer.c
index c7ebbd5..fcbee35 100644
--- a/gwobex/obex-xfer.c
+++ b/gwobex/obex-xfer.c
@@ -135,6 +135,18 @@ GwObexXfer *gw_obex_get_async(GwObex *ctx, const char 
*name, const char *type, g
     return ret ? ctx->xfer : NULL;
 }
 
+GwObexXfer *gw_obex_get_async_with_apparam(GwObex *ctx, const char *name, 
const char *type,
+               const guint8  *apparam, gint apparam_size, gint *error) {
+    gboolean ret;
+    GW_OBEX_LOCK(ctx);
+    CHECK_DISCONNECT(NULL, error, ctx);
+    ret = gw_obex_get(ctx, NULL, name, type, apparam, apparam_size, NULL, 
NULL, -1, TRUE);
+    if (ret == FALSE)
+        gw_obex_get_error(ctx, error);
+    GW_OBEX_UNLOCK(ctx);
+    return ret ? ctx->xfer : NULL;
+}
+
 static gboolean gw_obex_put_idle(GwObexXfer *xfer) {
     struct gw_obex *ctx = xfer->ctx;
 
diff --git a/plugins/ebook.c b/plugins/ebook.c
index abb16cb..5316bd8 100644
--- a/plugins/ebook.c
+++ b/plugins/ebook.c
@@ -78,7 +78,10 @@ static void ebooklist_cb(EBook *book, EBookStatus status, 
GList *list,
        g_object_unref(book);
 }
 
-static int ebook_pullphonebook(struct phonebook_context *context)
+static int ebook_pullphonebook(struct phonebook_context *context,
+               gchar *objname, guint64 filter, guint8 format,
+               guint16 maxlistcount, guint16 liststartoffset,
+               guint16 *phonebooksize, guint8 *newmissedcalls)
 {
        EBook *book;
        EBookQuery *query;
diff --git a/src/pbap.c b/src/pbap.c
index 6da8a32..05c48ec 100644
--- a/src/pbap.c
+++ b/src/pbap.c
@@ -25,43 +25,138 @@
 #include <config.h>
 #endif
 
+#include <glib.h>
+#include <bluetooth/bluetooth.h>
+
 #include <openobex/obex.h>
 #include <openobex/obex_const.h>
 
-#include <glib.h>
-
 #include "logging.h"
 #include "obex.h"
 
 #define PHONEBOOK_TYPE "x-bt/phonebook"
 
+#define ORDER_TAG              0x01
+#define SEARCHVALUE_TAG                0x02
+#define SEARCHATTRIB_TAG       0x03
+#define MAXLISTCOUNT_TAG       0x04
+#define LISTSTARTOFFSET_TAG    0x05
+#define FILTER_TAG             0x06
+#define FORMAT_TAG             0X07
+#define PHONEBOOKSIZE_TAG      0X08
+#define NEWMISSEDCALLS_TAG     0X09
+
+/* The following length is in the unit of byte */
+#define ORDER_LEN              1
+#define SEARCHATTRIB_LEN       1
+#define MAXLISTCOUNT_LEN       2
+#define LISTSTARTOFFSET_LEN    2
+#define FILTER_LEN             8
+#define FORMAT_LEN             1
+#define PHONEBOOKSIZE_LEN      2
+#define NEWMISSEDCALLS_LEN     1
+
+struct apparam_hdr {
+       uint8_t         tag;
+       uint8_t         len;
+       uint8_t         val[0];
+} __attribute__ ((packed));
+
+#define get_be64(val)  GUINT64_FROM_BE(bt_get_unaligned((guint64 *) val))
+#define get_be16(val)  GUINT16_FROM_BE(bt_get_unaligned((guint16 *) val))
+
 static GSList *session_list = NULL;
 
+static int pbap_pullphonebook(obex_t *obex, obex_object_t *obj)
+{
+       struct obex_session *session;
+       obex_headerdata_t hd;
+       guint8 hi, *p, newmissedcalls, format;
+       guint16 maxlistcount, liststartoffset, phonebooksize;
+       guint32 hlen, offset;
+       guint64 filter;
+       struct apparam_hdr *hdr;
+
+       session = OBEX_GetUserData(obex);
+
+       while (OBEX_ObjectGetNextHeader(obex, obj, &hi, &hd, &hlen)) {
+               if (hi != OBEX_HDR_APPARAM)
+                       continue;
+
+               if (hlen <= sizeof(struct apparam_hdr)) {
+                       error("PBAP pullphonebook app parameters header"
+                                               " is too short: %d", hlen);
+                       return -1;
+               }
+
+               p = (guint8 *) hd.bs;
+               hdr = (struct apparam_hdr *) hd.bs;
+               offset = 0;
+               while (offset < hlen) {
+                       switch (hdr->tag) {
+                       case FILTER_TAG:
+                               if (hdr->len == FILTER_LEN)
+                                       filter = get_be64(hdr->val);
+                               break;
+                       case FORMAT_TAG:
+                               if (hdr->len == FORMAT_LEN)
+                                       format = hdr->val[0];
+                               break;
+                       case MAXLISTCOUNT_TAG:
+                               if (hdr->len == MAXLISTCOUNT_LEN)
+                                       maxlistcount = get_be16(hdr->val);
+                               break;
+                       case LISTSTARTOFFSET_TAG:
+                               if (hdr->len == LISTSTARTOFFSET_LEN)
+                                       liststartoffset = get_be16(hdr->val);
+                               break;
+                       default:
+                               error("Unexpected PBAP pullphonebook app"
+                                               " parameter, tag %d, len %d",
+                                                       hdr->tag, hdr->len);
+                               return -1;
+                       }
+
+                       p += sizeof(struct apparam_hdr) + hdr->len;
+                       offset += sizeof(struct apparam_hdr) + hdr->len;
+                       hdr = (struct apparam_hdr *) p;
+               }
+
+               /* Ignore multiple app param headers */
+               break;
+       }
+
+       return phonebook_pullphonebook(session->pbctx, session->name, filter,
+                               format, maxlistcount, liststartoffset,
+                               &phonebooksize, &newmissedcalls);
+}
+
 void pbap_get(obex_t *obex, obex_object_t *obj)
 {
        struct obex_session *session;
        obex_headerdata_t hv;
-       int ret;
+       int err;
 
        session = OBEX_GetUserData(obex);
        if (session == NULL)
                return;
 
-       if (session->type == NULL)
-               goto fail;
-
-       if (g_str_equal(session->type, PHONEBOOK_TYPE) == FALSE)
+       if (session->type == NULL || session->name == NULL)
                goto fail;
 
-       ret = phonebook_pullphonebook(session->pbctx);
+       OBEX_ObjectReParseHeaders(obex, obj);
 
-       if (!ret) {
-               OBEX_SuspendRequest(obex, obj);
-               session->size = 0;
-       }
+       if (g_str_equal(session->type, PHONEBOOK_TYPE) == TRUE)
+               err = pbap_pullphonebook(obex, obj);
        else
                goto fail;
 
+       if (err < 0)
+               goto fail;
+
+       OBEX_SuspendRequest(obex, obj);
+       session->size = 0;
+
        /* Add body header */
        hv.bs = NULL;
        OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY,
diff --git a/src/phonebook.c b/src/phonebook.c
index 1b7d723..874da7d 100644
--- a/src/phonebook.c
+++ b/src/phonebook.c
@@ -101,12 +101,17 @@ void phonebook_unref(struct phonebook_context *context)
        }
 }
 
-int phonebook_pullphonebook(struct phonebook_context *context)
+int phonebook_pullphonebook(struct phonebook_context *context, gchar *objname,
+                       guint64 filter, guint8 format, guint16 maxlistcount,
+                       guint16 liststartoffset, guint16 *phonebooksize,
+                       guint8 *newmissedcalls)
 {
        if (!context->driver->pullphonebook)
                return -1;
 
-       return context->driver->pullphonebook(context);
+       return context->driver->pullphonebook(context, objname, filter, format,
+                               maxlistcount, liststartoffset, phonebooksize,
+                               newmissedcalls);
 }
 
 /* if buf is NULL or size is 0, this indicate that no more result will
diff --git a/src/phonebook.h b/src/phonebook.h
index 440d857..c334c05 100644
--- a/src/phonebook.h
+++ b/src/phonebook.h
@@ -49,7 +49,10 @@ static inline void phonebook_set_data(struct 
phonebook_context *context,
        context->driver_data = data;
 }
 
-extern int phonebook_pullphonebook(struct phonebook_context *context);
+extern int phonebook_pullphonebook(struct phonebook_context *context,
+                       gchar *objname, guint64 filter, guint8 format,
+                       guint16 maxlistcount, guint16 liststartoffset,
+                       guint16 *phonebooksize, guint8 *newmissedcalls);
 extern void phonebook_return(struct phonebook_context *context,
                                                char *buf, int size);
 
@@ -57,7 +60,10 @@ struct phonebook_driver {
        const char *name;
        int (*create) (struct phonebook_context *context);
        void (*destroy) (struct phonebook_context *context);
-       int (*pullphonebook) (struct phonebook_context *context);
+       int (*pullphonebook) (struct phonebook_context *context,
+                       gchar *objname, guint64 filter, guint8 format,
+                       guint16 maxlistcount, guint16 liststartoffset,
+                       guint16 *phonebooksize, guint8 *newmissedcalls);
        int (*pullvcardlisting) (struct phonebook_context *context);
        int (*pullvcardentry) (struct phonebook_context *context);
 };
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to