Return-Path: From: Slawomir Bochenski To: linux-bluetooth@vger.kernel.org Cc: Slawomir Bochenski Subject: [PATCH obexd v2 1/4] MAP: Implementation of MAP AP core functions Date: Fri, 13 Jan 2012 14:33:35 +0100 Message-Id: <1326461618-26864-1-git-send-email-lkslawek@gmail.com> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: This adds implementation for creation and destruction of map_ap_t and the definitions of MAP supported application parameters. --- src/map_ap.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 106 insertions(+), 1 deletions(-) diff --git a/src/map_ap.c b/src/map_ap.c index 9d13adf..8040b6d 100644 --- a/src/map_ap.c +++ b/src/map_ap.c @@ -27,13 +27,118 @@ #include "map_ap.h" +enum ap_type { + APT_UINT8, + APT_UINT16, + APT_UINT32, + APT_STR +}; + +static const struct ap_def { + enum map_ap_tag tag; + const char *name; + enum ap_type type; +} ap_defs[] = { + { MAP_AP_MAXLISTCOUNT, "MAXLISTCOUNT", + APT_UINT16 }, + { MAP_AP_STARTOFFSET, "STARTOFFSET", + APT_UINT16 }, + { MAP_AP_FILTERMESSAGETYPE, "FILTERMESSAGETYPE", + APT_UINT8 }, + { MAP_AP_FILTERPERIODBEGIN, "FILTERPERIODBEGIN", + APT_STR }, + { MAP_AP_FILTERPERIODEND, "FILTERPERIODEND", + APT_STR }, + { MAP_AP_FILTERREADSTATUS, "FILTERREADSTATUS", + APT_UINT8 }, + { MAP_AP_FILTERRECIPIENT, "FILTERRECIPIENT", + APT_STR }, + { MAP_AP_FILTERORIGINATOR, "FILTERORIGINATOR", + APT_STR }, + { MAP_AP_FILTERPRIORITY, "FILTERPRIORITY", + APT_UINT8 }, + { MAP_AP_ATTACHMENT, "ATTACHMENT", + APT_UINT8 }, + { MAP_AP_TRANSPARENT, "TRANSPARENT", + APT_UINT8 }, + { MAP_AP_RETRY, "RETRY", + APT_UINT8 }, + { MAP_AP_NEWMESSAGE, "NEWMESSAGE", + APT_UINT8 }, + { MAP_AP_NOTIFICATIONSTATUS, "NOTIFICATIONSTATUS", + APT_UINT8 }, + { MAP_AP_MASINSTANCEID, "MASINSTANCEID", + APT_UINT8 }, + { MAP_AP_PARAMETERMASK, "PARAMETERMASK", + APT_UINT32 }, + { MAP_AP_FOLDERLISTINGSIZE, "FOLDERLISTINGSIZE", + APT_UINT16 }, + { MAP_AP_MESSAGESLISTINGSIZE, "MESSAGESLISTINGSIZE", + APT_UINT16 }, + { MAP_AP_SUBJECTLENGTH, "SUBJECTLENGTH", + APT_UINT8 }, + { MAP_AP_CHARSET, "CHARSET", + APT_UINT8 }, + { MAP_AP_FRACTIONREQUEST, "FRACTIONREQUEST", + APT_UINT8 }, + { MAP_AP_FRACTIONDELIVER, "FRACTIONDELIVER", + APT_UINT8 }, + { MAP_AP_STATUSINDICATOR, "STATUSINDICATOR", + APT_UINT8 }, + { MAP_AP_STATUSVALUE, "STATUSVALUE", + APT_UINT8 }, + { MAP_AP_MSETIME, "MSETIME", + APT_STR }, + { MAP_AP_INVALID, NULL, + 0 }, +}; + +struct ap_entry { + enum map_ap_tag tag; + union { + uint32_t val32u; + uint16_t val16u; + uint8_t val8u; + char *valstr; + }; +}; + +static int find_ap_def(uint8_t tag) +{ + int i; + + for (i = 0; ap_defs[i].tag != MAP_AP_INVALID; ++i) + if (ap_defs[i].tag == tag) + return i; + + return -1; +} + +static void ap_entry_free(gpointer val) +{ + struct ap_entry *entry = val; + int tago; + + tago = find_ap_def(entry->tag); + + if (tago >= 0 && ap_defs[tago].type == APT_STR) + g_free(entry->valstr); + + g_free(entry); +} + map_ap_t *map_ap_new(void) { - return NULL; + return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, + ap_entry_free); } void map_ap_free(map_ap_t *ap) { + if (!ap) + return; + + g_hash_table_destroy(ap); } map_ap_t *map_ap_decode(const uint8_t *buffer, size_t length) -- 1.7.4.1