* dbus/dbus-auth.c (client_try_next_mechanism): Remove logic to
[platform/upstream/dbus.git] / dbus / dbus-marshal.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal.h  Marshalling routines
3  *
4  * Copyright (C) 2002  CodeFactory AB
5  *
6  * Licensed under the Academic Free License version 2.0
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_MARSHAL_H
25 #define DBUS_MARSHAL_H
26
27 #include <config.h>
28 #include <dbus/dbus-protocol.h>
29 #include <dbus/dbus-types.h>
30 #include <dbus/dbus-arch-deps.h>
31 #include <dbus/dbus-string.h>
32
33 #ifndef PACKAGE
34 #error "config.h not included here"
35 #endif
36
37 #ifdef WORDS_BIGENDIAN
38 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
39 #else
40 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
41 #endif
42
43 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint32_t) (      \
44     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) |     \
45     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) <<  8) |     \
46     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >>  8) |     \
47     (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
48
49 #ifdef DBUS_HAVE_INT64
50
51 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val)    ((dbus_uint64_t) (              \
52       (((dbus_uint64_t) (val) &                                                 \
53         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) |    \
54       (((dbus_uint64_t) (val) &                                                 \
55         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) |    \
56       (((dbus_uint64_t) (val) &                                                 \
57         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) |    \
58       (((dbus_uint64_t) (val) &                                                 \
59         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) <<  8) |    \
60       (((dbus_uint64_t) (val) &                                                 \
61         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >>  8) |    \
62       (((dbus_uint64_t) (val) &                                                 \
63         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) |    \
64       (((dbus_uint64_t) (val) &                                                 \
65         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) |    \
66       (((dbus_uint64_t) (val) &                                                 \
67         (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
68 #endif /* DBUS_HAVE_INT64 */
69
70 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
71 #define DBUS_INT32_SWAP_LE_BE(val)  ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
72
73 #ifdef DBUS_HAVE_INT64
74 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
75 #define DBUS_INT64_SWAP_LE_BE(val)  ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
76 #endif /* DBUS_HAVE_INT64 */
77
78 #ifdef WORDS_BIGENDIAN
79 #define DBUS_INT32_TO_BE(val)   ((dbus_int32_t) (val))
80 #define DBUS_UINT32_TO_BE(val)  ((dbus_uint32_t) (val))
81 #define DBUS_INT32_TO_LE(val)   (DBUS_INT32_SWAP_LE_BE (val))
82 #define DBUS_UINT32_TO_LE(val)  (DBUS_UINT32_SWAP_LE_BE (val))
83 #  ifdef DBUS_HAVE_INT64
84 #define DBUS_INT64_TO_BE(val)   ((dbus_int64_t) (val))
85 #define DBUS_UINT64_TO_BE(val)  ((dbus_uint64_t) (val))
86 #define DBUS_INT64_TO_LE(val)   (DBUS_INT64_SWAP_LE_BE (val))
87 #define DBUS_UINT64_TO_LE(val)  (DBUS_UINT64_SWAP_LE_BE (val))
88 #  endif /* DBUS_HAVE_INT64 */
89 #else
90 #define DBUS_INT32_TO_LE(val)   ((dbus_int32_t) (val))
91 #define DBUS_UINT32_TO_LE(val)  ((dbus_uint32_t) (val))
92 #define DBUS_INT32_TO_BE(val)   ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
93 #define DBUS_UINT32_TO_BE(val)  (DBUS_UINT32_SWAP_LE_BE (val))
94 #  ifdef DBUS_HAVE_INT64
95 #define DBUS_INT64_TO_LE(val)   ((dbus_int64_t) (val))
96 #define DBUS_UINT64_TO_LE(val)  ((dbus_uint64_t) (val))
97 #define DBUS_INT64_TO_BE(val)   ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
98 #define DBUS_UINT64_TO_BE(val)  (DBUS_UINT64_SWAP_LE_BE (val))
99 #  endif /* DBUS_HAVE_INT64 */
100 #endif
101
102 /* The transformation is symmetric, so the FROM just maps to the TO. */
103 #define DBUS_INT32_FROM_LE(val)  (DBUS_INT32_TO_LE (val))
104 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
105 #define DBUS_INT32_FROM_BE(val)  (DBUS_INT32_TO_BE (val))
106 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
107 #ifdef DBUS_HAVE_INT64
108 #define DBUS_INT64_FROM_LE(val)  (DBUS_INT64_TO_LE (val))
109 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
110 #define DBUS_INT64_FROM_BE(val)  (DBUS_INT64_TO_BE (val))
111 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
112 #endif /* DBUS_HAVE_INT64 */
113
114 void          _dbus_pack_int32    (dbus_int32_t         value,
115                                    int                  byte_order,
116                                    unsigned char       *data);
117 dbus_int32_t  _dbus_unpack_int32  (int                  byte_order,
118                                    const unsigned char *data);
119 void          _dbus_pack_uint32   (dbus_uint32_t        value,
120                                    int                  byte_order,
121                                    unsigned char       *data);
122 dbus_uint32_t _dbus_unpack_uint32 (int                  byte_order,
123                                    const unsigned char *data);
124 #ifdef DBUS_HAVE_INT64
125 void          _dbus_pack_int64    (dbus_int64_t         value,
126                                    int                  byte_order,
127                                    unsigned char       *data);
128 dbus_int64_t  _dbus_unpack_int64  (int                  byte_order,
129                                    const unsigned char *data);
130 void          _dbus_pack_uint64   (dbus_uint64_t        value,
131                                    int                  byte_order,
132                                    unsigned char       *data);
133 dbus_uint64_t _dbus_unpack_uint64 (int                  byte_order,
134                                    const unsigned char *data);
135 #endif /* DBUS_HAVE_INT64 */
136
137 void        _dbus_marshal_set_int32  (DBusString       *str,
138                                       int               byte_order,
139                                       int               offset,
140                                       dbus_int32_t      value);
141 void        _dbus_marshal_set_uint32 (DBusString       *str,
142                                       int               byte_order,
143                                       int               offset,
144                                       dbus_uint32_t     value);
145 #ifdef DBUS_HAVE_INT64
146 void        _dbus_marshal_set_int64  (DBusString       *str,
147                                       int               byte_order,
148                                       int               offset,
149                                       dbus_int64_t      value);
150 void        _dbus_marshal_set_uint64 (DBusString       *str,
151                                       int               byte_order,
152                                       int               offset,
153                                       dbus_uint64_t     value);
154 #endif /* DBUS_HAVE_INT64 */
155
156 dbus_bool_t _dbus_marshal_set_string      (DBusString         *str,
157                                            int                 byte_order,
158                                            int                 offset,
159                                            const DBusString   *value,
160                                            int                 len);
161 void        _dbus_marshal_set_object_path (DBusString         *str,
162                                            int                 byte_order,
163                                            int                 offset,
164                                            const char        **path,
165                                            int                 path_len);
166
167 dbus_bool_t   _dbus_marshal_int32          (DBusString            *str,
168                                             int                    byte_order,
169                                             dbus_int32_t           value);
170 dbus_bool_t   _dbus_marshal_uint32         (DBusString            *str,
171                                             int                    byte_order,
172                                             dbus_uint32_t          value);
173 #ifdef DBUS_HAVE_INT64
174 dbus_bool_t   _dbus_marshal_int64          (DBusString            *str,
175                                             int                    byte_order,
176                                             dbus_int64_t           value);
177 dbus_bool_t   _dbus_marshal_uint64         (DBusString            *str,
178                                             int                    byte_order,
179                                             dbus_uint64_t          value);
180 #endif /* DBUS_HAVE_INT64 */
181 dbus_bool_t   _dbus_marshal_double         (DBusString            *str,
182                                             int                    byte_order,
183                                             double                 value);
184 dbus_bool_t   _dbus_marshal_string         (DBusString            *str,
185                                             int                    byte_order,
186                                             const char            *value);
187 dbus_bool_t   _dbus_marshal_byte_array     (DBusString            *str,
188                                             int                    byte_order,
189                                             const unsigned char   *value,
190                                             int                    len);
191 dbus_bool_t   _dbus_marshal_int32_array    (DBusString            *str,
192                                             int                    byte_order,
193                                             const dbus_int32_t    *value,
194                                             int                    len);
195 dbus_bool_t   _dbus_marshal_uint32_array   (DBusString            *str,
196                                             int                    byte_order,
197                                             const dbus_uint32_t   *value,
198                                             int                    len);
199 #ifdef DBUS_HAVE_INT64
200 dbus_bool_t   _dbus_marshal_int64_array    (DBusString            *str,
201                                             int                    byte_order,
202                                             const dbus_int64_t    *value,
203                                             int                    len);
204 dbus_bool_t   _dbus_marshal_uint64_array   (DBusString            *str,
205                                             int                    byte_order,
206                                             const dbus_uint64_t   *value,
207                                             int                    len);
208 #endif /* DBUS_HAVE_INT64 */
209 dbus_bool_t   _dbus_marshal_double_array   (DBusString            *str,
210                                             int                    byte_order,
211                                             const double          *value,
212                                             int                    len);
213 dbus_bool_t   _dbus_marshal_string_array   (DBusString            *str,
214                                             int                    byte_order,
215                                             const char           **value,
216                                             int                    len);
217 dbus_bool_t   _dbus_marshal_object_path    (DBusString            *str,
218                                             int                    byte_order,
219                                             const char           **path,
220                                             int                    path_len);
221
222 double        _dbus_demarshal_double       (const DBusString      *str,
223                                             int                    byte_order,
224                                             int                    pos,
225                                             int                   *new_pos);
226 dbus_int32_t  _dbus_demarshal_int32        (const DBusString      *str,
227                                             int                    byte_order,
228                                             int                    pos,
229                                             int                   *new_pos);
230 dbus_uint32_t _dbus_demarshal_uint32       (const DBusString      *str,
231                                             int                    byte_order,
232                                             int                    pos,
233                                             int                   *new_pos);
234 #ifdef DBUS_HAVE_INT64
235 dbus_int64_t  _dbus_demarshal_int64        (const DBusString      *str,
236                                             int                    byte_order,
237                                             int                    pos,
238                                             int                   *new_pos);
239 dbus_uint64_t _dbus_demarshal_uint64       (const DBusString      *str,
240                                             int                    byte_order,
241                                             int                    pos,
242                                             int                   *new_pos);
243 #endif /* DBUS_HAVE_INT64 */
244 char *        _dbus_demarshal_string       (const DBusString      *str,
245                                             int                    byte_order,
246                                             int                    pos,
247                                             int                   *new_pos);
248 dbus_bool_t   _dbus_demarshal_byte_array   (const DBusString      *str,
249                                             int                    byte_order,
250                                             int                    pos,
251                                             int                   *new_pos,
252                                             unsigned char        **array,
253                                             int                   *array_len);
254 dbus_bool_t   _dbus_demarshal_int32_array  (const DBusString      *str,
255                                             int                    byte_order,
256                                             int                    pos,
257                                             int                   *new_pos,
258                                             dbus_int32_t         **array,
259                                             int                   *array_len);
260 dbus_bool_t   _dbus_demarshal_uint32_array (const DBusString      *str,
261                                             int                    byte_order,
262                                             int                    pos,
263                                             int                   *new_pos,
264                                             dbus_uint32_t        **array,
265                                             int                   *array_len);
266 #ifdef DBUS_HAVE_INT64
267 dbus_bool_t   _dbus_demarshal_int64_array  (const DBusString      *str,
268                                             int                    byte_order,
269                                             int                    pos,
270                                             int                   *new_pos,
271                                             dbus_int64_t         **array,
272                                             int                   *array_len);
273 dbus_bool_t   _dbus_demarshal_uint64_array (const DBusString      *str,
274                                             int                    byte_order,
275                                             int                    pos,
276                                             int                   *new_pos,
277                                             dbus_uint64_t        **array,
278                                             int                   *array_len);
279 #endif /* DBUS_HAVE_INT64 */
280 dbus_bool_t   _dbus_demarshal_double_array (const DBusString      *str,
281                                             int                    byte_order,
282                                             int                    pos,
283                                             int                   *new_pos,
284                                             double               **array,
285                                             int                   *array_len);
286 dbus_bool_t   _dbus_demarshal_string_array (const DBusString      *str,
287                                             int                    byte_order,
288                                             int                    pos,
289                                             int                   *new_pos,
290                                             char                ***array,
291                                             int                   *array_len);
292 dbus_bool_t   _dbus_demarshal_object_path  (const DBusString      *str,
293                                             int                    byte_order,
294                                             int                    pos,
295                                             int                   *new_pos,
296                                             char                ***path,
297                                             int                   *path_len);
298
299 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
300                                            int               byte_order,
301                                            int               type,
302                                            int               pos,
303                                            int              *end_pos);
304 dbus_bool_t _dbus_marshal_validate_type   (const DBusString *str,
305                                            int               pos,
306                                            int              *type,
307                                            int              *end_pos);
308 dbus_bool_t _dbus_marshal_validate_arg    (const DBusString *str,
309                                            int               depth,
310                                            int               byte_order,
311                                            int               type,
312                                            int               array_type_pos,
313                                            int               pos,
314                                            int              *end_pos);
315
316 dbus_bool_t _dbus_type_is_valid           (int               typecode);
317
318 #endif /* DBUS_PROTOCOL_H */