From 8ec710fae20d8915e8794c86651bf58bab984473 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 27 Nov 2008 10:50:26 +0100 Subject: [PATCH] obexd: Fix apparam_hdr handling and some coding style --- obexd/src/pbap.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/obexd/src/pbap.c b/obexd/src/pbap.c index 676d38ffe..05c48ec0a 100644 --- a/obexd/src/pbap.c +++ b/obexd/src/pbap.c @@ -25,12 +25,12 @@ #include #endif -#include -#include - #include #include +#include +#include + #include "logging.h" #include "obex.h" @@ -56,11 +56,11 @@ #define PHONEBOOKSIZE_LEN 2 #define NEWMISSEDCALLS_LEN 1 -typedef struct { +struct apparam_hdr { uint8_t tag; uint8_t len; uint8_t val[0]; -} __attribute__ ((packed)) apparam_hdr; +} __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)) @@ -75,7 +75,7 @@ static int pbap_pullphonebook(obex_t *obex, obex_object_t *obj) guint16 maxlistcount, liststartoffset, phonebooksize; guint32 hlen, offset; guint64 filter; - apparam_hdr *hdr; + struct apparam_hdr *hdr; session = OBEX_GetUserData(obex); @@ -83,51 +83,43 @@ static int pbap_pullphonebook(obex_t *obex, obex_object_t *obj) if (hi != OBEX_HDR_APPARAM) continue; - if (hlen <= sizeof(apparam_hdr)) { + if (hlen <= sizeof(struct apparam_hdr)) { error("PBAP pullphonebook app parameters header" - " is too short: %d", hlen); + " is too short: %d", hlen); return -1; } p = (guint8 *) hd.bs; - hdr = (apparam_hdr *) 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); - else - goto fail; break; case FORMAT_TAG: if (hdr->len == FORMAT_LEN) format = hdr->val[0]; - else - goto fail; break; case MAXLISTCOUNT_TAG: if (hdr->len == MAXLISTCOUNT_LEN) maxlistcount = get_be16(hdr->val); - else - goto fail; break; case LISTSTARTOFFSET_TAG: if (hdr->len == LISTSTARTOFFSET_LEN) liststartoffset = get_be16(hdr->val); - else - goto fail; break; default: -fail: error("Unexpected PBAP pullphonebook app" - " parameter, tag %d, len %d", - hdr->tag, hdr->len); + error("Unexpected PBAP pullphonebook app" + " parameter, tag %d, len %d", + hdr->tag, hdr->len); return -1; } - p += sizeof(apparam_hdr) + hdr->len; - offset += sizeof(apparam_hdr) + hdr->len; - hdr = (apparam_hdr *) p; + p += sizeof(struct apparam_hdr) + hdr->len; + offset += sizeof(struct apparam_hdr) + hdr->len; + hdr = (struct apparam_hdr *) p; } /* Ignore multiple app param headers */ -- 2.47.3