This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 src/pbap.c |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 75 insertions(+), 12 deletions(-)

New commits:
commit 84a42d911525142111c101b39b5fe5071f01f8ce
Author: Marcel Holtmann <[EMAIL PROTECTED]>
Date:   Fri Nov 28 09:24:01 2008 +0100

    Simplify apparam result generation

commit d7400efc743f5232e7ea82e0c91a3a0efe0cd3a8
Author: Forrest Zhao <[EMAIL PROTECTED]>
Date:   Fri Nov 28 10:54:13 2008 +0800

    add response app parameters header of PBAP PullPhonebook


Diff in this email is a maximum of 400 lines.
diff --git a/src/pbap.c b/src/pbap.c
index cfdaf6e..2c523ee 100644
--- a/src/pbap.c
+++ b/src/pbap.c
@@ -56,6 +56,9 @@
 #define PHONEBOOKSIZE_LEN      2
 #define NEWMISSEDCALLS_LEN     1
 
+#define MCH            "telecom/mch.vcf"
+#define SIM1_MCH       "SIM1/telecom/mch.vcf"
+
 struct apparam_hdr {
        uint8_t         tag;
        uint8_t         len;
@@ -66,16 +69,21 @@ struct apparam_hdr {
 #define get_be64(val)  GUINT64_FROM_BE(bt_get_unaligned((guint64 *) val))
 #define get_be16(val)  GUINT16_FROM_BE(bt_get_unaligned((guint16 *) val))
 
+#define put_be16(val, ptr) bt_put_unaligned(GUINT16_TO_BE(val), (guint16 *) 
ptr)
+
 static GSList *session_list = NULL;
 
-static int pbap_pullphonebook(obex_t *obex, obex_object_t *obj)
+static int pbap_pullphonebook(obex_t *obex, obex_object_t *obj,
+                                                       gboolean *addbody)
 {
        struct obex_session *session;
        obex_headerdata_t hd;
-       guint8 hi, newmissedcalls, format;
-       guint16 maxlistcount, liststartoffset, phonebooksize;
+       guint8 hi, format, newmissedcalls = 0, rspsize = 0;
+       guint16 maxlistcount, liststartoffset, phonebooksize = 0;
        guint32 hlen;
        guint64 filter;
+       gboolean addmissedcalls = FALSE;
+       int err;
 
        session = OBEX_GetUserData(obex);
 
@@ -134,15 +142,68 @@ static int pbap_pullphonebook(obex_t *obex, obex_object_t 
*obj)
                break;
        }
 
-       return phonebook_pullphonebook(session->pbctx, session->name, filter,
+       err = phonebook_pullphonebook(session->pbctx, session->name, filter,
                                format, maxlistcount, liststartoffset,
                                &phonebooksize, &newmissedcalls);
+       if (err < 0)
+               return err;
+
+       /* Add app parameter header, that is sent back to PBAP client */
+       if (maxlistcount == 0) {
+               rspsize += APPARAM_HDR_SIZE + PHONEBOOKSIZE_LEN;
+               *addbody = FALSE;
+       }
+
+       if (g_str_equal(session->name, SIM1_MCH) == TRUE ||
+                               g_str_equal(session->name, MCH) == TRUE) {
+               rspsize += APPARAM_HDR_SIZE + NEWMISSEDCALLS_LEN;
+               addmissedcalls = TRUE;
+       }
+
+       if (rspsize > 0) {
+               void *buf, *ptr;
+
+               buf = g_try_malloc0(rspsize);
+               if (buf == NULL)
+                       return -1;
+
+               ptr = buf;
+
+               if (maxlistcount == 0) {
+                       struct apparam_hdr *hdr = ptr;
+
+                       hdr->tag = PHONEBOOKSIZE_TAG;
+                       hdr->len = PHONEBOOKSIZE_LEN;
+                       put_be16(phonebooksize, hdr->val);
+
+                       ptr += APPARAM_HDR_SIZE + PHONEBOOKSIZE_LEN;
+               }
+
+               if (addmissedcalls == TRUE) {
+                       struct apparam_hdr *hdr = ptr;
+
+                       hdr->tag = NEWMISSEDCALLS_TAG;
+                       hdr->len = NEWMISSEDCALLS_LEN;
+                       hdr->val[0] = newmissedcalls;
+
+                       ptr += APPARAM_HDR_SIZE + NEWMISSEDCALLS_LEN;
+               }
+
+               hd.bs = buf;
+               OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_APPARAM,
+                                                       hd, rspsize, 0);
+
+               g_free(buf);
+       }
+
+       return 0;
 }
 
 void pbap_get(obex_t *obex, obex_object_t *obj)
 {
        struct obex_session *session;
-       obex_headerdata_t hv;
+       obex_headerdata_t hd;
+       gboolean addbody = TRUE;
        int err;
 
        session = OBEX_GetUserData(obex);
@@ -155,20 +216,22 @@ void pbap_get(obex_t *obex, obex_object_t *obj)
        OBEX_ObjectReParseHeaders(obex, obj);
 
        if (g_str_equal(session->type, PHONEBOOK_TYPE) == TRUE)
-               err = pbap_pullphonebook(obex, obj);
+               err = pbap_pullphonebook(obex, obj, &addbody);
        else
                goto fail;
 
        if (err < 0)
                goto fail;
 
-       OBEX_SuspendRequest(obex, obj);
-       session->size = 0;
+       if (addbody == TRUE) {
+               OBEX_SuspendRequest(obex, obj);
+               session->size = 0;
 
-       /* Add body header */
-       hv.bs = NULL;
-       OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY,
-                                       hv, 0, OBEX_FL_STREAM_START);
+               /* Add body header */
+               hd.bs = NULL;
+               OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY,
+                                               hd, 0, OBEX_FL_STREAM_START);
+       }
 
        OBEX_ObjectSetRsp(obj, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
 
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to