upgrade obexd to 0.47
[profile/ivi/obexd.git] / src / map_ap.h
1 /*
2  *
3  *  OBEX Server
4  *
5  *  Copyright (C) 2010-2011  Nokia Corporation
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <glib.h>
25 #include <inttypes.h>
26
27 /* List of OBEX application parameters tags as per MAP specification. */
28 enum map_ap_tag {
29         MAP_AP_MAXLISTCOUNT             = 0x01,         /* uint16_t     */
30         MAP_AP_STARTOFFSET              = 0x02,         /* uint16_t     */
31         MAP_AP_FILTERMESSAGETYPE        = 0x03,         /* uint8_t      */
32         MAP_AP_FILTERPERIODBEGIN        = 0x04,         /* char *       */
33         MAP_AP_FILTERPERIODEND          = 0x05,         /* char *       */
34         MAP_AP_FILTERREADSTATUS         = 0x06,         /* uint8_t      */
35         MAP_AP_FILTERRECIPIENT          = 0x07,         /* char *       */
36         MAP_AP_FILTERORIGINATOR         = 0x08,         /* char *       */
37         MAP_AP_FILTERPRIORITY           = 0x09,         /* uint8_t      */
38         MAP_AP_ATTACHMENT               = 0x0A,         /* uint8_t      */
39         MAP_AP_TRANSPARENT              = 0x0B,         /* uint8_t      */
40         MAP_AP_RETRY                    = 0x0C,         /* uint8_t      */
41         MAP_AP_NEWMESSAGE               = 0x0D,         /* uint8_t      */
42         MAP_AP_NOTIFICATIONSTATUS       = 0x0E,         /* uint8_t      */
43         MAP_AP_MASINSTANCEID            = 0x0F,         /* uint8_t      */
44         MAP_AP_PARAMETERMASK            = 0x10,         /* uint32_t     */
45         MAP_AP_FOLDERLISTINGSIZE        = 0x11,         /* uint16_t     */
46         MAP_AP_MESSAGESLISTINGSIZE      = 0x12,         /* uint16_t     */
47         MAP_AP_SUBJECTLENGTH            = 0x13,         /* uint8_t      */
48         MAP_AP_CHARSET                  = 0x14,         /* uint8_t      */
49         MAP_AP_FRACTIONREQUEST          = 0x15,         /* uint8_t      */
50         MAP_AP_FRACTIONDELIVER          = 0x16,         /* uint8_t      */
51         MAP_AP_STATUSINDICATOR          = 0x17,         /* uint8_t      */
52         MAP_AP_STATUSVALUE              = 0x18,         /* uint8_t      */
53         MAP_AP_MSETIME                  = 0x19,         /* char *       */
54 };
55
56 /* Data type representing MAP application parameters. Consider opaque. */
57 typedef GHashTable map_ap_t;
58
59 /* Creates a new empty MAP application parameters object. */
60 map_ap_t *map_ap_new(void);
61
62 /* Frees all the memory used by MAP application parameters object. */
63 void map_ap_free(map_ap_t *ap);
64
65 /* Parses given buffer that is a payload of OBEX application parameter header
66  * with a given length. Returned value can be used in calls to map_ap_get_*()
67  * and map_ap_set_*(). It has to be freed using map_ap_free(). It also takes
68  * care of converting all the data to host byte order, so this is the byte
69  * order used in map_ap_get_*()/map_ap_set_*().
70  *
71  * Returns NULL in case of failure.
72  */
73 map_ap_t *map_ap_decode(const uint8_t *buffer, size_t length);
74
75 /* Takes all parameters currently set and packs them into a buffer with OBEX
76  * application parameters header payload format.
77  *
78  * Returns newly allocated buffer of size 'length'. Free with g_free().
79  */
80 uint8_t *map_ap_encode(map_ap_t *ap, size_t *length);
81
82 /* Following family of functions reads value of MAP parameter with given tag.
83  * Use the one with appropriate type for a given tag, as noted above in
84  * map_ap_tag declaration comments.
85  *
86  * Returns TRUE when value is present. FALSE if it is not or the function is
87  * used get a parameter of a different type. When FALSE is returned, variable
88  * pointed by 'val' is left intact.
89  */
90 gboolean map_ap_get_u8(map_ap_t *ap, enum map_ap_tag tag, uint8_t *val);
91 gboolean map_ap_get_u16(map_ap_t *ap, enum map_ap_tag tag, uint16_t *val);
92 gboolean map_ap_get_u32(map_ap_t *ap, enum map_ap_tag tag, uint32_t *val);
93
94 /* Reads value of MAP parameter with given tag that is of a string type.
95  *
96  * Returns NULL if parameter is not present in ap or given tag is not of a
97  * string type.
98  */
99 const char *map_ap_get_string(map_ap_t *ap, enum map_ap_tag tag);
100
101 /* Following family of functions sets the value of MAP parameter with given
102  * tag. Use the one with appropriate type for a given tag, as noted above in
103  * map_ap_tag declaration comments.
104  *
105  * If there is already a parameter with given tag present, it will be
106  * replaced. map_ap_set_string() makes its own copy of given string.
107  *
108  * Returns TRUE on success (the tag is known and the function chosen matches
109  * the type of tag).
110  */
111 gboolean map_ap_set_u8(map_ap_t *ap, enum map_ap_tag tag, uint8_t val);
112 gboolean map_ap_set_u16(map_ap_t *ap, enum map_ap_tag tag, uint16_t val);
113 gboolean map_ap_set_u32(map_ap_t *ap, enum map_ap_tag tag, uint32_t val);
114 gboolean map_ap_set_string(map_ap_t *ap, enum map_ap_tag tag, const char *val);