MAP: Implementation of MAP AP core functions
PATCH v3 1/4 MAP: Implementation of MAP AP core functions
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(-)
src/map_ap.c +106 -1
@@ -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 u32; +uint16_t u16; +uint8_t u8; +char *str; + } val; +}; + +static int find_ap_def_offset (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 offset; + + offset =find_ap_def_offset (entry->tag); + +if (offset >=0 && ap_defs[offset].type ==APT_STR ) +g_free (entry->val.str); + +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)
Signature · 1 line
1.7.4.1
PATCH v3 2/4 map_ap.c: Add implementation for map_ap_set_*
--- src/map_ap.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 52 insertions(+), 4 deletions(-)
src/map_ap.c +52 -4
@@ -175,20 +175,68 @@ const char *map_ap_get_string(map_ap_t *ap, enum map_ap_tag tag)gboolean map_ap_set_u8 (map_ap_t *ap,enum map_ap_tag tag,uint8_t val) { -return FALSE; +struct ap_entry *entry; +int offset =find_ap_def_offset (tag); + +if (offset <0 || ap_defs[offset].type !=APT_UINT8 ) +return FALSE; + + entry = g_new0(struct ap_entry, 1); + entry->tag = tag; + entry->val.u8 = val; + +g_hash_table_insert (ap,GINT_TO_POINTER (tag), entry); + +return TRUE; }gboolean map_ap_set_u16 (map_ap_t *ap,enum map_ap_tag tag,uint16_t val) { -return FALSE; +struct ap_entry *entry; +int offset =find_ap_def_offset (tag); + +if (offset <0 || ap_defs[offset].type !=APT_UINT16 ) +return FALSE; + + entry = g_new0(struct ap_entry, 1); + entry->tag = tag; + entry->val.u16 = val; + +g_hash_table_insert (ap,GINT_TO_POINTER (tag), entry); + +return TRUE; }gboolean map_ap_set_u32 (map_ap_t *ap,enum map_ap_tag tag,uint32_t val) { -return FALSE; +struct ap_entry *entry; +int offset =find_ap_def_offset (tag); + +if (offset <0 || ap_defs[offset].type !=APT_UINT32 ) +return FALSE; + + entry = g_new0(struct ap_entry, 1); + entry->tag = tag; + entry->val.u32 = val; + +g_hash_table_insert (ap,GINT_TO_POINTER (tag), entry); + +return TRUE; }gboolean map_ap_set_string (map_ap_t *ap,enum map_ap_tag tag,const char *val) { -return FALSE; +struct ap_entry *entry; +int offset =find_ap_def_offset (tag); + +if (offset <0 || ap_defs[offset].type !=APT_STR ) +return FALSE; + + entry = g_new0(struct ap_entry, 1); + entry->tag = tag; + entry->val.str =g_strdup (val); + +g_hash_table_insert (ap,GINT_TO_POINTER (tag), entry); + +return TRUE; }
Signature · 1 line
1.7.4.1
PATCH v3 3/4 map_ap.c: Add implementation for map_ap_decode()
In reply to Slawomir Bochenski--- src/map_ap.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 100 insertions(+), 1 deletions(-)
src/map_ap.c +100 -1
@@ -25,6 +25,10 @@#include <config.h> #endif +#include <string.h> + +#include "log.h" +#include "map_ap.h" enum ap_type {
@@ -103,6 +107,13 @@ struct ap_entry { } val; }; +/* This comes from OBEX specs */ +struct obex_ap_header { +uint8_t tag; +uint8_t len; +uint8_t val[0 ]; +} __attribute__ ((packed)); +static int find_ap_def_offset (uint8_t tag) {int i;
@@ -141,9 +152,97 @@ void map_ap_free(map_ap_t *ap)g_hash_table_destroy (ap); } +static void ap_decode_u8 (map_ap_t *ap,const struct obex_ap_header *hdr) +{ +if (hdr->len !=1 ) { +DBG ("Value of tag %d is %d bytes long instead of expected " +"1 byte - skipped!" , hdr->tag, hdr->len); +return ; + } + +map_ap_set_u8 (ap, hdr->tag, hdr->val[0 ]); +} + +static void ap_decode_u16 (map_ap_t *ap,const struct obex_ap_header *hdr) +{ +uint16_t val; + +if (hdr->len !=2 ) { +DBG ("Value of tag %d is %d bytes long instead of expected " +"2 bytes - skipped!" , hdr->tag, hdr->len); +return ; + } + +memcpy (&val, hdr->val,sizeof (val)); +map_ap_set_u16 (ap, hdr->tag,GUINT16_FROM_BE (val)); +} + +static void ap_decode_u32 (map_ap_t *ap,const struct obex_ap_header *hdr) +{ +uint32_t val; + +if (hdr->len !=4 ) { +DBG ("Value of tag %d is %d bytes long instead of expected " +"4 bytes - skipped!" , hdr->tag, hdr->len); +return ; + } + +memcpy (&val, hdr->val,sizeof (val)); +map_ap_set_u32 (ap, hdr->tag,GUINT32_FROM_BE (val)); +} + +static void ap_decode_str (map_ap_t *ap,const struct obex_ap_header *hdr) +{ +char *val =g_malloc0 (hdr->len +1 ); + +memcpy (val, hdr->val, hdr->len); +map_ap_set_string (ap, hdr->tag, val); + +g_free (val); +} +map_ap_t *map_ap_decode (const uint8_t *buffer,size_t length) { -return NULL ; +map_ap_t *ap; +struct obex_ap_header *hdr; +uint32_t done =0 ; +int offset; + + ap =map_ap_new (); +if (!ap) +return NULL ; + +while (done < length) { + hdr = (void *) buffer + done; + + offset =find_ap_def_offset (hdr->tag); + +if (offset <0 ) { +DBG ("Unknown tag %d (length %d) - skipped." , + hdr->tag, hdr->len); + goto skip; + } + +switch (ap_defs[offset].type) { +case APT_UINT8 : +ap_decode_u8 (ap, hdr); +break ; +case APT_UINT16 : +ap_decode_u16 (ap, hdr); +break ; +case APT_UINT32 : +ap_decode_u32 (ap, hdr); +break ; +case APT_STR : +ap_decode_str (ap, hdr); +break ; + } + +skip: + done += hdr->len +sizeof (struct obex_ap_header ); + } + +return ap; }uint8_t *map_ap_encode (map_ap_t *ap,size_t *length)
Signature · 1 line
1.7.4.1
PATCH v3 4/4 map_ap.c: Add dumping of map_ap_t after decoding
In reply to Slawomir Bochenski--- src/map_ap.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-)
src/map_ap.c +25 -0
@@ -125,6 +125,29 @@ static int find_ap_def_offset(uint8_t tag)return -1 ; } +static void ap_entry_dump (gpointer tag,gpointer val,gpointer user_data) +{ +struct ap_entry *entry = val; +int offset; + + offset =find_ap_def_offset (GPOINTER_TO_INT (tag)); + +switch (ap_defs[offset].type) { +case APT_UINT8 : +DBG ("%-30s %08x" , ap_defs[offset].name, entry->val.u8); +break ; +case APT_UINT16 : +DBG ("%-30s %08x" , ap_defs[offset].name, entry->val.u16); +break ; +case APT_UINT32 : +DBG ("%-30s %08x" , ap_defs[offset].name, entry->val.u32); +break ; +case APT_STR : +DBG ("%-30s %s" , ap_defs[offset].name, entry->val.str); +break ; + } +} +static void ap_entry_free (gpointer val) {struct ap_entry *entry = val;
@@ -242,6 +265,8 @@ skip: done += hdr->len +sizeof (struct obex_ap_header ); } +g_hash_table_foreach (ap, ap_entry_dump,NULL ); +return ap; }
Signature · 1 line
1.7.4.1