dbus-marshal-basic.h revision 305a8d4d988a1011982e284e358165d3368067cc
1/* -*- mode: C; c-file-style: "gnu" -*- */ 2/* dbus-marshal-basic.h Marshalling routines for basic (primitive) types 3 * 4 * Copyright (C) 2002 CodeFactory AB 5 * Copyright (C) 2004 Red Hat, Inc. 6 * 7 * Licensed under the Academic Free License version 2.1 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * 23 */ 24 25#ifndef DBUS_MARSHAL_H 26#define DBUS_MARSHAL_H 27 28#include <config.h> 29#include <dbus/dbus-protocol.h> 30#include <dbus/dbus-types.h> 31#include <dbus/dbus-arch-deps.h> 32#include <dbus/dbus-string.h> 33 34#ifndef PACKAGE 35#error "config.h not included here" 36#endif 37 38/****************************************************** Remove later */ 39#undef DBUS_TYPE_INVALID 40#undef DBUS_TYPE_BYTE 41#undef DBUS_TYPE_INT32 42#undef DBUS_TYPE_UINT32 43#undef DBUS_TYPE_INT64 44#undef DBUS_TYPE_UINT64 45#undef DBUS_TYPE_DOUBLE 46#undef DBUS_TYPE_STRING 47#undef DBUS_TYPE_OBJECT_PATH 48#undef DBUS_TYPE_ARRAY 49#undef DBUS_TYPE_DICT 50#undef DBUS_TYPE_VARIANT 51#undef DBUS_TYPE_STRUCT 52#undef DBUS_NUMBER_OF_TYPES 53 54/* Never a legitimate type */ 55#define DBUS_TYPE_INVALID ((int) '\0') 56 57/* Primitive types */ 58#define DBUS_TYPE_BYTE ((int) 'y') 59#define DBUS_TYPE_BOOLEAN ((int) 'b') 60#define DBUS_TYPE_INT32 ((int) 'i') 61 62#define DBUS_TYPE_UINT32 ((int) 'u') 63#define DBUS_TYPE_INT64 ((int) 'x') 64#define DBUS_TYPE_UINT64 ((int) 't') 65 66#define DBUS_TYPE_DOUBLE ((int) 'd') 67#define DBUS_TYPE_STRING ((int) 's') 68#define DBUS_TYPE_OBJECT_PATH ((int) 'o') 69 70/* Compound types */ 71#define DBUS_TYPE_ARRAY ((int) 'a') 72#define DBUS_TYPE_DICT ((int) 'm') 73#define DBUS_TYPE_VARIANT ((int) 'v') 74 75/* STRUCT is sort of special since its code can't appear in a type string, 76 * instead DBUS_STRUCT_BEGIN_CHAR has to appear 77 */ 78#define DBUS_TYPE_STRUCT ((int) 'r') 79 80/* Does not count INVALID */ 81#define DBUS_NUMBER_OF_TYPES (13) 82 83/* characters other than typecodes that appear in type signatures */ 84#define DBUS_STRUCT_BEGIN_CHAR ((int) '(') 85#define DBUS_STRUCT_END_CHAR ((int) ')') 86#define DBUS_NAME_DELIMITER_CHAR ((int) '\'') 87/****************************************************** Remove later */ 88 89#ifdef WORDS_BIGENDIAN 90#define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN 91#else 92#define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN 93#endif 94 95#define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \ 96 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \ 97 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \ 98 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \ 99 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24))) 100 101#ifdef DBUS_HAVE_INT64 102 103#define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \ 104 (((dbus_uint64_t) (val) & \ 105 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \ 106 (((dbus_uint64_t) (val) & \ 107 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \ 108 (((dbus_uint64_t) (val) & \ 109 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \ 110 (((dbus_uint64_t) (val) & \ 111 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \ 112 (((dbus_uint64_t) (val) & \ 113 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \ 114 (((dbus_uint64_t) (val) & \ 115 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \ 116 (((dbus_uint64_t) (val) & \ 117 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \ 118 (((dbus_uint64_t) (val) & \ 119 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56))) 120#endif /* DBUS_HAVE_INT64 */ 121 122#define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val)) 123#define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val)) 124 125#ifdef DBUS_HAVE_INT64 126#define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val)) 127#define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val)) 128#endif /* DBUS_HAVE_INT64 */ 129 130#ifdef WORDS_BIGENDIAN 131#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val)) 132#define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val)) 133#define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val)) 134#define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val)) 135# ifdef DBUS_HAVE_INT64 136#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val)) 137#define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val)) 138#define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val)) 139#define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val)) 140# endif /* DBUS_HAVE_INT64 */ 141#else 142#define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val)) 143#define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val)) 144#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val)) 145#define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val)) 146# ifdef DBUS_HAVE_INT64 147#define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val)) 148#define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val)) 149#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val)) 150#define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val)) 151# endif /* DBUS_HAVE_INT64 */ 152#endif 153 154/* The transformation is symmetric, so the FROM just maps to the TO. */ 155#define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val)) 156#define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val)) 157#define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val)) 158#define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val)) 159#ifdef DBUS_HAVE_INT64 160#define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val)) 161#define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val)) 162#define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val)) 163#define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val)) 164#endif /* DBUS_HAVE_INT64 */ 165 166void _dbus_pack_int32 (dbus_int32_t value, 167 int byte_order, 168 unsigned char *data); 169dbus_int32_t _dbus_unpack_int32 (int byte_order, 170 const unsigned char *data); 171void _dbus_pack_uint32 (dbus_uint32_t value, 172 int byte_order, 173 unsigned char *data); 174dbus_uint32_t _dbus_unpack_uint32 (int byte_order, 175 const unsigned char *data); 176#ifdef DBUS_HAVE_INT64 177void _dbus_pack_int64 (dbus_int64_t value, 178 int byte_order, 179 unsigned char *data); 180dbus_int64_t _dbus_unpack_int64 (int byte_order, 181 const unsigned char *data); 182void _dbus_pack_uint64 (dbus_uint64_t value, 183 int byte_order, 184 unsigned char *data); 185dbus_uint64_t _dbus_unpack_uint64 (int byte_order, 186 const unsigned char *data); 187#endif /* DBUS_HAVE_INT64 */ 188 189void _dbus_marshal_set_int32 (DBusString *str, 190 int byte_order, 191 int offset, 192 dbus_int32_t value); 193void _dbus_marshal_set_uint32 (DBusString *str, 194 int byte_order, 195 int offset, 196 dbus_uint32_t value); 197#ifdef DBUS_HAVE_INT64 198void _dbus_marshal_set_int64 (DBusString *str, 199 int byte_order, 200 int offset, 201 dbus_int64_t value); 202void _dbus_marshal_set_uint64 (DBusString *str, 203 int byte_order, 204 int offset, 205 dbus_uint64_t value); 206#endif /* DBUS_HAVE_INT64 */ 207 208dbus_bool_t _dbus_marshal_set_string (DBusString *str, 209 int byte_order, 210 int offset, 211 const DBusString *value, 212 int len); 213void _dbus_marshal_set_object_path (DBusString *str, 214 int byte_order, 215 int offset, 216 const char **path, 217 int path_len); 218 219dbus_bool_t _dbus_marshal_int32 (DBusString *str, 220 int byte_order, 221 dbus_int32_t value); 222dbus_bool_t _dbus_marshal_uint32 (DBusString *str, 223 int byte_order, 224 dbus_uint32_t value); 225#ifdef DBUS_HAVE_INT64 226dbus_bool_t _dbus_marshal_int64 (DBusString *str, 227 int byte_order, 228 dbus_int64_t value); 229dbus_bool_t _dbus_marshal_uint64 (DBusString *str, 230 int byte_order, 231 dbus_uint64_t value); 232#endif /* DBUS_HAVE_INT64 */ 233dbus_bool_t _dbus_marshal_double (DBusString *str, 234 int byte_order, 235 double value); 236dbus_bool_t _dbus_marshal_string (DBusString *str, 237 int byte_order, 238 const char *value); 239dbus_bool_t _dbus_marshal_string_len (DBusString *str, 240 int byte_order, 241 const char *value, 242 int len); 243dbus_bool_t _dbus_marshal_basic_type (DBusString *str, 244 char type, 245 void *value, 246 int byte_order); 247dbus_bool_t _dbus_marshal_byte_array (DBusString *str, 248 int byte_order, 249 const unsigned char *value, 250 int len); 251dbus_bool_t _dbus_marshal_int32_array (DBusString *str, 252 int byte_order, 253 const dbus_int32_t *value, 254 int len); 255dbus_bool_t _dbus_marshal_uint32_array (DBusString *str, 256 int byte_order, 257 const dbus_uint32_t *value, 258 int len); 259#ifdef DBUS_HAVE_INT64 260dbus_bool_t _dbus_marshal_int64_array (DBusString *str, 261 int byte_order, 262 const dbus_int64_t *value, 263 int len); 264dbus_bool_t _dbus_marshal_uint64_array (DBusString *str, 265 int byte_order, 266 const dbus_uint64_t *value, 267 int len); 268#endif /* DBUS_HAVE_INT64 */ 269dbus_bool_t _dbus_marshal_double_array (DBusString *str, 270 int byte_order, 271 const double *value, 272 int len); 273dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str, 274 char element_type, 275 const void *value, 276 int len, 277 int byte_order); 278 279dbus_bool_t _dbus_marshal_string_array (DBusString *str, 280 int byte_order, 281 const char **value, 282 int len); 283dbus_bool_t _dbus_marshal_object_path (DBusString *str, 284 int byte_order, 285 const char **path, 286 int path_len); 287 288double _dbus_demarshal_double (const DBusString *str, 289 int byte_order, 290 int pos, 291 int *new_pos); 292dbus_int32_t _dbus_demarshal_int32 (const DBusString *str, 293 int byte_order, 294 int pos, 295 int *new_pos); 296dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str, 297 int byte_order, 298 int pos, 299 int *new_pos); 300#ifdef DBUS_HAVE_INT64 301dbus_int64_t _dbus_demarshal_int64 (const DBusString *str, 302 int byte_order, 303 int pos, 304 int *new_pos); 305dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str, 306 int byte_order, 307 int pos, 308 int *new_pos); 309#endif /* DBUS_HAVE_INT64 */ 310void _dbus_demarshal_basic_type (const DBusString *str, 311 int type, 312 void *value, 313 int byte_order, 314 int *pos); 315char * _dbus_demarshal_string (const DBusString *str, 316 int byte_order, 317 int pos, 318 int *new_pos); 319dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str, 320 int byte_order, 321 int pos, 322 int *new_pos, 323 unsigned char **array, 324 int *array_len); 325dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str, 326 int byte_order, 327 int pos, 328 int *new_pos, 329 dbus_int32_t **array, 330 int *array_len); 331dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str, 332 int byte_order, 333 int pos, 334 int *new_pos, 335 dbus_uint32_t **array, 336 int *array_len); 337#ifdef DBUS_HAVE_INT64 338dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str, 339 int byte_order, 340 int pos, 341 int *new_pos, 342 dbus_int64_t **array, 343 int *array_len); 344dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str, 345 int byte_order, 346 int pos, 347 int *new_pos, 348 dbus_uint64_t **array, 349 int *array_len); 350#endif /* DBUS_HAVE_INT64 */ 351dbus_bool_t _dbus_demarshal_double_array (const DBusString *str, 352 int byte_order, 353 int pos, 354 int *new_pos, 355 double **array, 356 int *array_len); 357dbus_bool_t _dbus_demarshal_basic_type_array (const DBusString *str, 358 int type, 359 void **array, 360 int *array_len, 361 int byte_order, 362 int *pos); 363 364dbus_bool_t _dbus_demarshal_string_array (const DBusString *str, 365 int byte_order, 366 int pos, 367 int *new_pos, 368 char ***array, 369 int *array_len); 370dbus_bool_t _dbus_decompose_path (const char* data, 371 int len, 372 char ***path, 373 int *path_len); 374dbus_bool_t _dbus_demarshal_object_path (const DBusString *str, 375 int byte_order, 376 int pos, 377 int *new_pos, 378 char ***path, 379 int *path_len); 380 381dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str, 382 int byte_order, 383 int type, 384 int pos, 385 int *end_pos); 386dbus_bool_t _dbus_marshal_validate_type (const DBusString *str, 387 int pos, 388 int *type, 389 int *end_pos); 390dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str, 391 int depth, 392 int byte_order, 393 int type, 394 int array_type_pos, 395 int pos, 396 int *end_pos); 397 398dbus_bool_t _dbus_type_is_valid (int typecode); 399 400#endif /* DBUS_MARSHAL_H */ 401