mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-05 00:37:59 +02:00
2005-01-27 Havoc Pennington <hp@redhat.com>
* dbus/dbus-arch-deps.h.in: add 16/32-bit types * configure.in: find the right type for 16 and 32 bit ints as well as 64 * dbus/dbus-protocol.h (DBUS_TYPE_INT16, DBUS_TYPE_UINT16): add the 16-bit types so people don't have to stuff them in 32-bit or byte arrays.
This commit is contained in:
parent
4506b6594b
commit
3ed9db546e
25 changed files with 631 additions and 61 deletions
11
ChangeLog
11
ChangeLog
|
|
@ -1,3 +1,14 @@
|
|||
2005-01-27 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* dbus/dbus-arch-deps.h.in: add 16/32-bit types
|
||||
|
||||
* configure.in: find the right type for 16 and 32 bit ints as well
|
||||
as 64
|
||||
|
||||
* dbus/dbus-protocol.h (DBUS_TYPE_INT16, DBUS_TYPE_UINT16): add
|
||||
the 16-bit types so people don't have to stuff them in 32-bit or
|
||||
byte arrays.
|
||||
|
||||
2005-01-27 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* dbus/dbus-message.c: byteswap the message if you init an
|
||||
|
|
|
|||
49
configure.in
49
configure.in
|
|
@ -369,6 +369,53 @@ AC_SUBST(DBUS_INT64_CONSTANT)
|
|||
AC_SUBST(DBUS_UINT64_CONSTANT)
|
||||
AC_SUBST(DBUS_HAVE_INT64)
|
||||
|
||||
### see what 32-bit int is called
|
||||
AC_MSG_CHECKING([32-bit integer type])
|
||||
|
||||
case 4 in
|
||||
$ac_cv_sizeof_short)
|
||||
dbusint32=int
|
||||
;;
|
||||
$ac_cv_sizeof_int)
|
||||
dbusint32=int
|
||||
;;
|
||||
$ac_cv_sizeof_long)
|
||||
dbusint32=long
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -z "$dbusint32" ; then
|
||||
DBUS_INT32_TYPE="no_int32_type_detected"
|
||||
AC_MSG_ERROR([No 32-bit integer type found])
|
||||
else
|
||||
DBUS_INT32_TYPE="$dbusint32"
|
||||
AC_MSG_RESULT($DBUS_INT32_TYPE)
|
||||
fi
|
||||
|
||||
AC_SUBST(DBUS_INT32_TYPE)
|
||||
|
||||
### see what 16-bit int is called
|
||||
AC_MSG_CHECKING([16-bit integer type])
|
||||
|
||||
case 2 in
|
||||
$ac_cv_sizeof_short)
|
||||
dbusint16=short
|
||||
;;
|
||||
$ac_cv_sizeof_int)
|
||||
dbusint16=int
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -z "$dbusint16" ; then
|
||||
DBUS_INT16_TYPE="no_int16_type_detected"
|
||||
AC_MSG_ERROR([No 16-bit integer type found])
|
||||
else
|
||||
DBUS_INT16_TYPE="$dbusint16"
|
||||
AC_MSG_RESULT($DBUS_INT16_TYPE)
|
||||
fi
|
||||
|
||||
AC_SUBST(DBUS_INT16_TYPE)
|
||||
|
||||
## byte order
|
||||
AC_C_BIGENDIAN
|
||||
|
||||
|
|
@ -1194,6 +1241,8 @@ echo "
|
|||
cppflags: ${CPPFLAGS}
|
||||
cxxflags: ${CXXFLAGS}
|
||||
64-bit int: ${DBUS_INT64_TYPE}
|
||||
32-bit int: ${DBUS_INT32_TYPE}
|
||||
16-bit int: ${DBUS_INT16_TYPE}
|
||||
Doxygen: ${DOXYGEN}
|
||||
xmlto: ${XMLTO}"
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#ifndef DBUS_ARCH_DEPS_H
|
||||
#define DBUS_ARCH_DEPS_H
|
||||
|
||||
#include <dbus/dbus-types.h>
|
||||
#include <dbus/dbus-macros.h>
|
||||
|
||||
DBUS_BEGIN_DECLS;
|
||||
|
|
@ -46,6 +45,12 @@ typedef unsigned @DBUS_INT64_TYPE@ dbus_uint64_t;
|
|||
#undef DBUS_UINT64_CONSTANT
|
||||
#endif
|
||||
|
||||
typedef @DBUS_INT32_TYPE@ dbus_int32_t;
|
||||
typedef unsigned @DBUS_INT32_TYPE@ dbus_uint32_t;
|
||||
|
||||
typedef @DBUS_INT16_TYPE@ dbus_int16_t;
|
||||
typedef unsigned @DBUS_INT16_TYPE@ dbus_uint16_t;
|
||||
|
||||
DBUS_END_DECLS;
|
||||
|
||||
#endif /* DBUS_ARCH_DEPS_H */
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "dbus-protocol.h"
|
||||
#include "dbus-internals.h"
|
||||
#include "dbus-message.h"
|
||||
#include "dbus-marshal-validate.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -97,6 +97,38 @@
|
|||
*
|
||||
* @param object the object to be zeroed.
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_INT16_MIN
|
||||
*
|
||||
* Minimum value of type "int16"
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_INT16_MAX
|
||||
*
|
||||
* Maximum value of type "int16"
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_UINT16_MAX
|
||||
*
|
||||
* Maximum value of type "uint16"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def _DBUS_INT32_MIN
|
||||
*
|
||||
* Minimum value of type "int32"
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_INT32_MAX
|
||||
*
|
||||
* Maximum value of type "int32"
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_UINT32_MAX
|
||||
*
|
||||
* Maximum value of type "uint32"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def _DBUS_INT_MIN
|
||||
*
|
||||
|
|
@ -107,6 +139,11 @@
|
|||
*
|
||||
* Maximum value of type "int"
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_UINT_MAX
|
||||
*
|
||||
* Maximum value of type "uint"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef DBusForeachFunction
|
||||
|
|
|
|||
|
|
@ -183,11 +183,18 @@ dbus_bool_t _dbus_string_array_contains (const char **array,
|
|||
const char *str);
|
||||
char** _dbus_dup_string_array (const char **array);
|
||||
|
||||
#define _DBUS_INT_MIN (-_DBUS_INT_MAX - 1)
|
||||
#define _DBUS_INT_MAX 2147483647
|
||||
#define _DBUS_UINT_MAX 0xffffffff
|
||||
#define _DBUS_INT16_MIN ((dbus_int16_t) 0x8000)
|
||||
#define _DBUS_INT16_MAX ((dbus_int16_t) 0x7fff)
|
||||
#define _DBUS_UINT16_MAX ((dbus_uint16_t)0xffff)
|
||||
#define _DBUS_INT32_MIN ((dbus_int32_t) 0x80000000)
|
||||
#define _DBUS_INT32_MAX ((dbus_int32_t) 0x7fffffff)
|
||||
#define _DBUS_UINT32_MAX ((dbus_uint32_t)0xffffffff)
|
||||
/* using 32-bit here is sort of bogus */
|
||||
#define _DBUS_INT_MIN _DBUS_INT32_MIN
|
||||
#define _DBUS_INT_MAX _DBUS_INT32_MAX
|
||||
#define _DBUS_UINT_MAX _DBUS_UINT32_MAX
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
#define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (9223372036854775807)
|
||||
#define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (0x7fffffffffffffff)
|
||||
#define _DBUS_UINT64_MAX DBUS_UINT64_CONSTANT (0xffffffffffffffff)
|
||||
#endif
|
||||
#define _DBUS_ONE_KILOBYTE 1024
|
||||
|
|
|
|||
|
|
@ -489,7 +489,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (val > _DBUS_INT_MAX || val < 0)
|
||||
if (val > _DBUS_INT32_MAX || val < 0)
|
||||
{
|
||||
_dbus_verbose ("invalid secret key ID at start of line\n");
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,19 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
static void
|
||||
pack_2_octets (dbus_uint16_t value,
|
||||
int byte_order,
|
||||
unsigned char *data)
|
||||
{
|
||||
_dbus_assert (_DBUS_ALIGN_ADDRESS (data, 2) == data);
|
||||
|
||||
if ((byte_order) == DBUS_LITTLE_ENDIAN)
|
||||
*((dbus_uint16_t*)(data)) = DBUS_UINT16_TO_LE (value);
|
||||
else
|
||||
*((dbus_uint16_t*)(data)) = DBUS_UINT16_TO_BE (value);
|
||||
}
|
||||
|
||||
static void
|
||||
pack_4_octets (dbus_uint32_t value,
|
||||
int byte_order,
|
||||
|
|
@ -147,6 +160,27 @@ unpack_8_octets (int byte_order,
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef _dbus_unpack_uint16
|
||||
/**
|
||||
* Unpacks a 16 bit unsigned integer from a data pointer
|
||||
*
|
||||
* @param byte_order The byte order to use
|
||||
* @param data the data pointer
|
||||
* @returns the integer
|
||||
*/
|
||||
dbus_uint16_t
|
||||
_dbus_unpack_uint16 (int byte_order,
|
||||
const unsigned char *data)
|
||||
{
|
||||
_dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
|
||||
|
||||
if (byte_order == DBUS_LITTLE_ENDIAN)
|
||||
return DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)data);
|
||||
else
|
||||
return DBUS_UINT16_FROM_BE (*(dbus_uint16_t*)data);
|
||||
}
|
||||
#endif /* _dbus_unpack_uint16 */
|
||||
|
||||
#ifndef _dbus_unpack_uint32
|
||||
/**
|
||||
* Unpacks a 32 bit unsigned integer from a data pointer
|
||||
|
|
@ -168,6 +202,22 @@ _dbus_unpack_uint32 (int byte_order,
|
|||
}
|
||||
#endif /* _dbus_unpack_uint32 */
|
||||
|
||||
static void
|
||||
set_2_octets (DBusString *str,
|
||||
int offset,
|
||||
dbus_uint16_t value,
|
||||
int byte_order)
|
||||
{
|
||||
char *data;
|
||||
|
||||
_dbus_assert (byte_order == DBUS_LITTLE_ENDIAN ||
|
||||
byte_order == DBUS_BIG_ENDIAN);
|
||||
|
||||
data = _dbus_string_get_data_len (str, offset, 2);
|
||||
|
||||
pack_2_octets (value, byte_order, data);
|
||||
}
|
||||
|
||||
static void
|
||||
set_4_octets (DBusString *str,
|
||||
int offset,
|
||||
|
|
@ -181,7 +231,7 @@ set_4_octets (DBusString *str,
|
|||
|
||||
data = _dbus_string_get_data_len (str, offset, 4);
|
||||
|
||||
_dbus_pack_uint32 (value, byte_order, data);
|
||||
pack_4_octets (value, byte_order, data);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -350,6 +400,16 @@ _dbus_marshal_set_basic (DBusString *str,
|
|||
*new_end_pos = pos + 1;
|
||||
return TRUE;
|
||||
break;
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
pos = _DBUS_ALIGN_VALUE (pos, 2);
|
||||
set_2_octets (str, pos, vp->u16, byte_order);
|
||||
if (old_end_pos)
|
||||
*old_end_pos = pos + 2;
|
||||
if (new_end_pos)
|
||||
*new_end_pos = pos + 2;
|
||||
return TRUE;
|
||||
break;
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
|
|
@ -460,6 +520,14 @@ _dbus_marshal_read_basic (const DBusString *str,
|
|||
vp->byt = _dbus_string_get_byte (str, pos);
|
||||
(pos)++;
|
||||
break;
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
pos = _DBUS_ALIGN_VALUE (pos, 2);
|
||||
vp->u16 = *(dbus_uint16_t *)(str_data + pos);
|
||||
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
|
||||
vp->u16 = DBUS_UINT16_SWAP_LE_BE (vp->u16);
|
||||
pos += 2;
|
||||
break;
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
|
|
@ -570,6 +638,35 @@ _dbus_marshal_read_fixed_multi (const DBusString *str,
|
|||
*new_pos = pos + array_len;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
marshal_2_octets (DBusString *str,
|
||||
int insert_at,
|
||||
dbus_uint16_t value,
|
||||
int byte_order,
|
||||
int *pos_after)
|
||||
{
|
||||
dbus_bool_t retval;
|
||||
int orig_len;
|
||||
|
||||
_dbus_assert (sizeof (value) == 2);
|
||||
|
||||
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
|
||||
value = DBUS_UINT16_SWAP_LE_BE (value);
|
||||
|
||||
orig_len = _dbus_string_get_length (str);
|
||||
|
||||
retval = _dbus_string_insert_2_aligned (str, insert_at,
|
||||
(const unsigned char *)&value);
|
||||
|
||||
if (pos_after)
|
||||
{
|
||||
*pos_after = insert_at + (_dbus_string_get_length (str) - orig_len);
|
||||
_dbus_assert (*pos_after <= _dbus_string_get_length (str));
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
marshal_4_octets (DBusString *str,
|
||||
int insert_at,
|
||||
|
|
@ -762,6 +859,11 @@ _dbus_marshal_write_basic (DBusString *str,
|
|||
*pos_after = insert_at + 1;
|
||||
return TRUE;
|
||||
break;
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
return marshal_2_octets (str, insert_at, vp->u16,
|
||||
byte_order, pos_after);
|
||||
break;
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
return marshal_4_octets (str, insert_at, vp->u32 != FALSE,
|
||||
byte_order, pos_after);
|
||||
|
|
@ -855,16 +957,24 @@ _dbus_swap_array (unsigned char *data,
|
|||
d += 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (alignment == 4)
|
||||
{
|
||||
_dbus_assert (alignment == 4);
|
||||
|
||||
while (d != end)
|
||||
{
|
||||
*((dbus_uint32_t*)d) = DBUS_UINT32_SWAP_LE_BE (*((dbus_uint32_t*)d));
|
||||
d += 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbus_assert (alignment == 2);
|
||||
|
||||
while (d != end)
|
||||
{
|
||||
*((dbus_uint16_t*)d) = DBUS_UINT16_SWAP_LE_BE (*((dbus_uint16_t*)d));
|
||||
d += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -979,6 +1089,9 @@ _dbus_marshal_write_fixed_multi (DBusString *str,
|
|||
case DBUS_TYPE_BYTE:
|
||||
return marshal_1_octets_array (str, insert_at, vp, n_elements, byte_order, pos_after);
|
||||
break;
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 2, pos_after);
|
||||
/* FIXME: we canonicalize to 0 or 1 for the single boolean case
|
||||
* should we here too ? */
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
|
|
@ -1024,6 +1137,11 @@ _dbus_marshal_skip_basic (const DBusString *str,
|
|||
case DBUS_TYPE_BYTE:
|
||||
(*pos)++;
|
||||
break;
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
*pos = _DBUS_ALIGN_VALUE (*pos, 2);
|
||||
*pos += 2;
|
||||
break;
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
|
|
@ -1109,6 +1227,9 @@ _dbus_type_get_alignment (int typecode)
|
|||
case DBUS_TYPE_VARIANT:
|
||||
case DBUS_TYPE_SIGNATURE:
|
||||
return 1;
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
return 2;
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
|
|
@ -1150,6 +1271,8 @@ _dbus_type_is_valid (int typecode)
|
|||
{
|
||||
case DBUS_TYPE_BYTE:
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
case DBUS_TYPE_INT64:
|
||||
|
|
@ -1232,6 +1355,8 @@ _dbus_type_is_fixed (int typecode)
|
|||
{
|
||||
case DBUS_TYPE_BYTE:
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
case DBUS_TYPE_INT64:
|
||||
|
|
@ -1260,6 +1385,10 @@ _dbus_type_to_string (int typecode)
|
|||
return "boolean";
|
||||
case DBUS_TYPE_BYTE:
|
||||
return "byte";
|
||||
case DBUS_TYPE_INT16:
|
||||
return "int16";
|
||||
case DBUS_TYPE_UINT16:
|
||||
return "uint16";
|
||||
case DBUS_TYPE_INT32:
|
||||
return "int32";
|
||||
case DBUS_TYPE_UINT32:
|
||||
|
|
@ -1558,6 +1687,7 @@ _dbus_marshal_test (void)
|
|||
DBusString str;
|
||||
int pos, dump_pos;
|
||||
unsigned char array1[5] = { 3, 4, 0, 1, 9 };
|
||||
dbus_int16_t array2[3] = { 124, 457, 780 };
|
||||
dbus_int32_t array4[3] = { 123, 456, 789 };
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
dbus_int64_t array8[3] = { DBUS_INT64_CONSTANT (0x123ffffffff),
|
||||
|
|
@ -1566,11 +1696,16 @@ _dbus_marshal_test (void)
|
|||
dbus_int64_t *v_ARRAY_INT64;
|
||||
#endif
|
||||
unsigned char *v_ARRAY_BYTE;
|
||||
dbus_int16_t *v_ARRAY_INT16;
|
||||
dbus_uint16_t *v_ARRAY_UINT16;
|
||||
dbus_int32_t *v_ARRAY_INT32;
|
||||
dbus_uint32_t *v_ARRAY_UINT32;
|
||||
double *v_ARRAY_DOUBLE;
|
||||
DBusString t;
|
||||
double v_DOUBLE;
|
||||
double t_DOUBLE;
|
||||
dbus_int16_t v_INT16;
|
||||
dbus_uint16_t v_UINT16;
|
||||
dbus_int32_t v_INT32;
|
||||
dbus_uint32_t v_UINT32;
|
||||
dbus_int64_t v_INT64;
|
||||
|
|
@ -1600,6 +1735,14 @@ _dbus_marshal_test (void)
|
|||
if (!_DBUS_DOUBLES_BITWISE_EQUAL (t_DOUBLE, v_DOUBLE))
|
||||
_dbus_assert_not_reached ("got wrong double value");
|
||||
|
||||
/* Marshal signed 16 integers */
|
||||
MARSHAL_TEST (INT16, DBUS_BIG_ENDIAN, -12345);
|
||||
MARSHAL_TEST (INT16, DBUS_LITTLE_ENDIAN, -12345);
|
||||
|
||||
/* Marshal unsigned 16 integers */
|
||||
MARSHAL_TEST (UINT16, DBUS_BIG_ENDIAN, 0x1234);
|
||||
MARSHAL_TEST (UINT16, DBUS_LITTLE_ENDIAN, 0x1234);
|
||||
|
||||
/* Marshal signed integers */
|
||||
MARSHAL_TEST (INT32, DBUS_BIG_ENDIAN, -12345678);
|
||||
MARSHAL_TEST (INT32, DBUS_LITTLE_ENDIAN, -12345678);
|
||||
|
|
@ -1645,8 +1788,15 @@ _dbus_marshal_test (void)
|
|||
MARSHAL_TEST_STRCMP (SIGNATURE, DBUS_LITTLE_ENDIAN, "a(ii)");
|
||||
|
||||
/* Arrays */
|
||||
MARSHAL_TEST_FIXED_ARRAY (INT16, DBUS_BIG_ENDIAN, array2);
|
||||
MARSHAL_TEST_FIXED_ARRAY (INT16, DBUS_LITTLE_ENDIAN, array2);
|
||||
MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_BIG_ENDIAN, array2);
|
||||
MARSHAL_TEST_FIXED_ARRAY (UINT16, DBUS_LITTLE_ENDIAN, array2);
|
||||
|
||||
MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_BIG_ENDIAN, array4);
|
||||
MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_LITTLE_ENDIAN, array4);
|
||||
MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_BIG_ENDIAN, array4);
|
||||
MARSHAL_TEST_FIXED_ARRAY (UINT32, DBUS_LITTLE_ENDIAN, array4);
|
||||
|
||||
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_BIG_ENDIAN, array1);
|
||||
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_LITTLE_ENDIAN, array1);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@
|
|||
#define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val) ((dbus_uint16_t) ( \
|
||||
(dbus_uint16_t) ((dbus_uint16_t) (val) >> 8) | \
|
||||
(dbus_uint16_t) ((dbus_uint16_t) (val) << 8)))
|
||||
|
||||
#define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
|
||||
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
|
||||
(((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
|
||||
|
|
@ -68,48 +72,66 @@
|
|||
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
|
||||
#define DBUS_UINT16_SWAP_LE_BE(val) (DBUS_UINT16_SWAP_LE_BE_CONSTANT (val))
|
||||
#define DBUS_INT16_SWAP_LE_BE(val) ((dbus_int16_t)DBUS_UINT16_SWAP_LE_BE_CONSTANT (val))
|
||||
|
||||
#define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
|
||||
#define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
|
||||
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
#define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
|
||||
#define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
|
||||
# define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
|
||||
# define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
|
||||
#define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
|
||||
#define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
|
||||
#define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
|
||||
|
||||
# define DBUS_INT16_TO_BE(val) ((dbus_int16_t) (val))
|
||||
# define DBUS_UINT16_TO_BE(val) ((dbus_uint16_t) (val))
|
||||
# define DBUS_INT16_TO_LE(val) (DBUS_INT16_SWAP_LE_BE (val))
|
||||
# define DBUS_UINT16_TO_LE(val) (DBUS_UINT16_SWAP_LE_BE (val))
|
||||
# define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
|
||||
# define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
|
||||
# define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
|
||||
# define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
|
||||
# ifdef DBUS_HAVE_INT64
|
||||
#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
|
||||
#define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
|
||||
#define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
|
||||
#define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
|
||||
# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
|
||||
# define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
|
||||
# define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
|
||||
# define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
|
||||
# endif /* DBUS_HAVE_INT64 */
|
||||
#else
|
||||
#define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
|
||||
#define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
|
||||
#define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
|
||||
#define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
|
||||
|
||||
#else /* WORDS_BIGENDIAN */
|
||||
|
||||
# define DBUS_INT16_TO_LE(val) ((dbus_int16_t) (val))
|
||||
# define DBUS_UINT16_TO_LE(val) ((dbus_uint16_t) (val))
|
||||
# define DBUS_INT16_TO_BE(val) ((dbus_int16_t) DBUS_UINT16_SWAP_LE_BE (val))
|
||||
# define DBUS_UINT16_TO_BE(val) (DBUS_UINT16_SWAP_LE_BE (val))
|
||||
# define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
|
||||
# define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
|
||||
# define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
|
||||
# define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
|
||||
# ifdef DBUS_HAVE_INT64
|
||||
#define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
|
||||
#define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
|
||||
#define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
|
||||
#define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
|
||||
# define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
|
||||
# define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
|
||||
# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
|
||||
# define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
|
||||
# endif /* DBUS_HAVE_INT64 */
|
||||
#endif
|
||||
|
||||
/* The transformation is symmetric, so the FROM just maps to the TO. */
|
||||
#define DBUS_INT16_FROM_LE(val) (DBUS_INT16_TO_LE (val))
|
||||
#define DBUS_UINT16_FROM_LE(val) (DBUS_UINT16_TO_LE (val))
|
||||
#define DBUS_INT16_FROM_BE(val) (DBUS_INT16_TO_BE (val))
|
||||
#define DBUS_UINT16_FROM_BE(val) (DBUS_UINT16_TO_BE (val))
|
||||
#define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
|
||||
#define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
|
||||
#define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
|
||||
#define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
#define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
|
||||
#define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
|
||||
#define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
|
||||
#define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
|
||||
# define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
|
||||
# define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
|
||||
# define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
|
||||
# define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
|
||||
#ifndef DBUS_HAVE_INT64
|
||||
|
|
@ -131,11 +153,13 @@ typedef struct
|
|||
*/
|
||||
typedef union
|
||||
{
|
||||
dbus_int16_t i16; /**< as int16 */
|
||||
dbus_uint16_t u16; /**< as int16 */
|
||||
dbus_int32_t i32; /**< as int32 */
|
||||
dbus_uint32_t u32; /**< as int32 */
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
dbus_int64_t i64; /**< as int32 */
|
||||
dbus_uint64_t u64; /**< as int32 */
|
||||
dbus_int64_t i64; /**< as int64 */
|
||||
dbus_uint64_t u64; /**< as int64 */
|
||||
#else
|
||||
DBus8ByteStruct u64; /**< as 8-byte-struct */
|
||||
#endif
|
||||
|
|
@ -145,12 +169,22 @@ typedef union
|
|||
} DBusBasicValue;
|
||||
|
||||
#ifdef DBUS_DISABLE_ASSERT
|
||||
#define _dbus_unpack_uint16(byte_order, data) \
|
||||
(((byte_order) == DBUS_LITTLE_ENDIAN) ? \
|
||||
DBUS_UINT16_FROM_LE (*(dbus_uint16_t*)(data)) : \
|
||||
DBUS_UINT16_FROM_BE (*(dbus_uint16_t*)(data)))
|
||||
|
||||
#define _dbus_unpack_uint32(byte_order, data) \
|
||||
(((byte_order) == DBUS_LITTLE_ENDIAN) ? \
|
||||
DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)(data)) : \
|
||||
DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(data)))
|
||||
#endif
|
||||
|
||||
#ifndef _dbus_unpack_uint16
|
||||
dbus_uint16_t _dbus_unpack_uint16 (int byte_order,
|
||||
const unsigned char *data);
|
||||
#endif
|
||||
|
||||
void _dbus_pack_uint32 (dbus_uint32_t value,
|
||||
int byte_order,
|
||||
unsigned char *data);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,15 @@ byteswap_body_helper (DBusTypeReader *reader,
|
|||
++p;
|
||||
break;
|
||||
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
{
|
||||
p = _DBUS_ALIGN_ADDRESS (p, 2);
|
||||
*((dbus_uint16_t*)p) = DBUS_UINT16_SWAP_LE_BE (*((dbus_uint16_t*)p));
|
||||
p += 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
|
|
|
|||
|
|
@ -672,7 +672,7 @@ _dbus_header_have_message_untrusted (int max_message_length,
|
|||
dbus_uint32_t body_len_unsigned;
|
||||
|
||||
_dbus_assert (start >= 0);
|
||||
_dbus_assert (start < _DBUS_INT_MAX / 2);
|
||||
_dbus_assert (start < _DBUS_INT32_MAX / 2);
|
||||
_dbus_assert (len >= 0);
|
||||
|
||||
_dbus_assert (start == (int) _DBUS_ALIGN_VALUE (start, 8));
|
||||
|
|
@ -711,16 +711,16 @@ _dbus_header_have_message_untrusted (int max_message_length,
|
|||
/* overflow should be impossible since the lengths aren't allowed to
|
||||
* be huge.
|
||||
*/
|
||||
_dbus_assert (max_message_length < _DBUS_INT_MAX / 2);
|
||||
_dbus_assert (max_message_length < _DBUS_INT32_MAX / 2);
|
||||
if (body_len_unsigned + header_len_unsigned > (unsigned) max_message_length)
|
||||
{
|
||||
*validity = DBUS_INVALID_MESSAGE_TOO_LONG;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
_dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT_MAX);
|
||||
_dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT_MAX);
|
||||
_dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT_MAX);
|
||||
_dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT32_MAX);
|
||||
_dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT32_MAX);
|
||||
_dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT32_MAX);
|
||||
|
||||
*body_len = body_len_unsigned;
|
||||
*fields_array_len = fields_array_len_unsigned;
|
||||
|
|
|
|||
|
|
@ -396,6 +396,26 @@ struct TestTypeNodeContainerClass
|
|||
* and by merging read_value and set_value into one function
|
||||
* taking a flag argument.
|
||||
*/
|
||||
static dbus_bool_t int16_write_value (TestTypeNode *node,
|
||||
DataBlock *block,
|
||||
DBusTypeWriter *writer,
|
||||
int seed);
|
||||
static dbus_bool_t int16_read_value (TestTypeNode *node,
|
||||
DBusTypeReader *reader,
|
||||
int seed);
|
||||
static dbus_bool_t int16_set_value (TestTypeNode *node,
|
||||
DBusTypeReader *reader,
|
||||
DBusTypeReader *realign_root,
|
||||
int seed);
|
||||
static dbus_bool_t int16_write_multi (TestTypeNode *node,
|
||||
DataBlock *block,
|
||||
DBusTypeWriter *writer,
|
||||
int seed,
|
||||
int count);
|
||||
static dbus_bool_t int16_read_multi (TestTypeNode *node,
|
||||
DBusTypeReader *reader,
|
||||
int seed,
|
||||
int count);
|
||||
static dbus_bool_t int32_write_value (TestTypeNode *node,
|
||||
DataBlock *block,
|
||||
DBusTypeWriter *writer,
|
||||
|
|
@ -533,6 +553,34 @@ static dbus_bool_t variant_set_value (TestTypeNode *node,
|
|||
static void container_destroy (TestTypeNode *node);
|
||||
|
||||
|
||||
static const TestTypeNodeClass int16_class = {
|
||||
DBUS_TYPE_INT16,
|
||||
sizeof (TestTypeNode),
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
int16_write_value,
|
||||
int16_read_value,
|
||||
int16_set_value,
|
||||
NULL,
|
||||
int16_write_multi,
|
||||
int16_read_multi
|
||||
};
|
||||
|
||||
static const TestTypeNodeClass uint16_class = {
|
||||
DBUS_TYPE_UINT16,
|
||||
sizeof (TestTypeNode),
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
int16_write_value, /* recycle from int16 */
|
||||
int16_read_value, /* recycle from int16 */
|
||||
int16_set_value, /* recycle from int16 */
|
||||
NULL,
|
||||
int16_write_multi, /* recycle from int16 */
|
||||
int16_read_multi /* recycle from int16 */
|
||||
};
|
||||
|
||||
static const TestTypeNodeClass int32_class = {
|
||||
DBUS_TYPE_INT32,
|
||||
sizeof (TestTypeNode),
|
||||
|
|
@ -819,6 +867,8 @@ static const TestTypeNodeClass variant_class = {
|
|||
|
||||
static const TestTypeNodeClass* const
|
||||
basic_nodes[] = {
|
||||
&int16_class,
|
||||
&uint16_class,
|
||||
&int32_class,
|
||||
&uint32_class,
|
||||
&int64_class,
|
||||
|
|
@ -1978,6 +2028,142 @@ _dbus_marshal_recursive_test (void)
|
|||
*/
|
||||
#define MAX_MULTI_COUNT 5
|
||||
|
||||
#define SAMPLE_INT16 1234
|
||||
#define SAMPLE_INT16_ALTERNATE 6785
|
||||
static dbus_int16_t
|
||||
int16_from_seed (int seed)
|
||||
{
|
||||
/* Generate an integer value that's predictable from seed. We could
|
||||
* just use seed itself, but that would only ever touch one byte of
|
||||
* the int so would miss some kinds of bug.
|
||||
*/
|
||||
dbus_int16_t v;
|
||||
|
||||
v = 42; /* just to quiet compiler afaik */
|
||||
switch (seed % 5)
|
||||
{
|
||||
case 0:
|
||||
v = SAMPLE_INT16;
|
||||
break;
|
||||
case 1:
|
||||
v = SAMPLE_INT16_ALTERNATE;
|
||||
break;
|
||||
case 2:
|
||||
v = -1;
|
||||
break;
|
||||
case 3:
|
||||
v = _DBUS_INT16_MAX;
|
||||
break;
|
||||
case 4:
|
||||
v = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (seed > 1)
|
||||
v *= seed; /* wraps around eventually, which is fine */
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
int16_write_value (TestTypeNode *node,
|
||||
DataBlock *block,
|
||||
DBusTypeWriter *writer,
|
||||
int seed)
|
||||
{
|
||||
/* also used for uint16 */
|
||||
dbus_int16_t v;
|
||||
|
||||
v = int16_from_seed (seed);
|
||||
|
||||
return _dbus_type_writer_write_basic (writer,
|
||||
node->klass->typecode,
|
||||
&v);
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
int16_read_value (TestTypeNode *node,
|
||||
DBusTypeReader *reader,
|
||||
int seed)
|
||||
{
|
||||
/* also used for uint16 */
|
||||
dbus_int16_t v;
|
||||
|
||||
check_expected_type (reader, node->klass->typecode);
|
||||
|
||||
_dbus_type_reader_read_basic (reader,
|
||||
(dbus_int16_t*) &v);
|
||||
|
||||
_dbus_assert (v == int16_from_seed (seed));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
int16_set_value (TestTypeNode *node,
|
||||
DBusTypeReader *reader,
|
||||
DBusTypeReader *realign_root,
|
||||
int seed)
|
||||
{
|
||||
/* also used for uint16 */
|
||||
dbus_int16_t v;
|
||||
|
||||
v = int16_from_seed (seed);
|
||||
|
||||
return _dbus_type_reader_set_basic (reader,
|
||||
&v,
|
||||
realign_root);
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
int16_write_multi (TestTypeNode *node,
|
||||
DataBlock *block,
|
||||
DBusTypeWriter *writer,
|
||||
int seed,
|
||||
int count)
|
||||
{
|
||||
/* also used for uint16 */
|
||||
dbus_int16_t values[MAX_MULTI_COUNT];
|
||||
dbus_int16_t *v_ARRAY_INT16 = values;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
values[i] = int16_from_seed (seed + i);
|
||||
|
||||
return _dbus_type_writer_write_fixed_multi (writer,
|
||||
node->klass->typecode,
|
||||
&v_ARRAY_INT16, count);
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
int16_read_multi (TestTypeNode *node,
|
||||
DBusTypeReader *reader,
|
||||
int seed,
|
||||
int count)
|
||||
{
|
||||
/* also used for uint16 */
|
||||
dbus_int16_t *values;
|
||||
int n_elements;
|
||||
int i;
|
||||
|
||||
check_expected_type (reader, node->klass->typecode);
|
||||
|
||||
_dbus_type_reader_read_fixed_multi (reader,
|
||||
&values,
|
||||
&n_elements);
|
||||
|
||||
if (n_elements != count)
|
||||
_dbus_warn ("got %d elements expected %d\n", n_elements, count);
|
||||
_dbus_assert (n_elements == count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
_dbus_assert (((int)_dbus_unpack_uint16 (reader->byte_order,
|
||||
(const unsigned char*)values + (i * 2))) ==
|
||||
int16_from_seed (seed + i));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#define SAMPLE_INT32 12345678
|
||||
#define SAMPLE_INT32_ALTERNATE 53781429
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ static const ValidityTest signature_tests[] = {
|
|||
{ "i", DBUS_VALID },
|
||||
{ "ai", DBUS_VALID },
|
||||
{ "(i)", DBUS_VALID },
|
||||
{ "q", DBUS_INVALID_UNKNOWN_TYPECODE },
|
||||
{ "w", DBUS_INVALID_UNKNOWN_TYPECODE },
|
||||
{ "a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
||||
{ "aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
||||
{ "ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|||
int array_depth;
|
||||
|
||||
_dbus_assert (type_str != NULL);
|
||||
_dbus_assert (type_pos < _DBUS_INT_MAX - len);
|
||||
_dbus_assert (type_pos < _DBUS_INT32_MAX - len);
|
||||
_dbus_assert (len >= 0);
|
||||
_dbus_assert (type_pos >= 0);
|
||||
|
||||
|
|
@ -76,6 +76,8 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|||
{
|
||||
case DBUS_TYPE_BYTE:
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
case DBUS_TYPE_INT64:
|
||||
|
|
@ -159,8 +161,10 @@ validate_body_helper (DBusTypeReader *reader,
|
|||
case DBUS_TYPE_BYTE:
|
||||
++p;
|
||||
break;
|
||||
|
||||
|
||||
case DBUS_TYPE_BOOLEAN:
|
||||
case DBUS_TYPE_INT16:
|
||||
case DBUS_TYPE_UINT16:
|
||||
case DBUS_TYPE_INT32:
|
||||
case DBUS_TYPE_UINT32:
|
||||
case DBUS_TYPE_INT64:
|
||||
|
|
|
|||
|
|
@ -591,6 +591,8 @@ message_iter_test (DBusMessage *message)
|
|||
DBusMessageIter iter, array, array2;
|
||||
const char *v_STRING;
|
||||
double v_DOUBLE;
|
||||
dbus_int16_t v_INT16;
|
||||
dbus_uint16_t v_UINT16;
|
||||
dbus_int32_t v_INT32;
|
||||
dbus_uint32_t v_UINT32;
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
|
|
@ -656,6 +658,8 @@ verify_test_message (DBusMessage *message)
|
|||
{
|
||||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
dbus_int16_t our_int16;
|
||||
dbus_uint16_t our_uint16;
|
||||
dbus_int32_t our_int;
|
||||
dbus_uint32_t our_uint;
|
||||
const char *our_str;
|
||||
|
|
@ -686,6 +690,8 @@ verify_test_message (DBusMessage *message)
|
|||
|
||||
dbus_error_init (&error);
|
||||
if (!dbus_message_iter_get_args (&iter, &error,
|
||||
DBUS_TYPE_INT16, &our_int16,
|
||||
DBUS_TYPE_UINT16, &our_uint16,
|
||||
DBUS_TYPE_INT32, &our_int,
|
||||
DBUS_TYPE_UINT32, &our_uint,
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
|
|
@ -720,6 +726,12 @@ verify_test_message (DBusMessage *message)
|
|||
_dbus_assert_not_reached ("Could not get arguments");
|
||||
}
|
||||
|
||||
if (our_int16 != -0x123)
|
||||
_dbus_assert_not_reached ("16-bit integers differ!");
|
||||
|
||||
if (our_uint16 != 0x123)
|
||||
_dbus_assert_not_reached ("16-bit uints differ!");
|
||||
|
||||
if (our_int != -0x12345678)
|
||||
_dbus_assert_not_reached ("integers differ!");
|
||||
|
||||
|
|
@ -860,6 +872,8 @@ _dbus_message_test (const char *test_data_dir)
|
|||
const char *s;
|
||||
const char *v_STRING;
|
||||
double v_DOUBLE;
|
||||
dbus_int16_t v_INT16;
|
||||
dbus_uint16_t v_UINT16;
|
||||
dbus_int32_t v_INT32;
|
||||
dbus_uint32_t v_UINT32;
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
|
|
@ -974,6 +988,8 @@ _dbus_message_test (const char *test_data_dir)
|
|||
_dbus_message_set_serial (message, 1);
|
||||
dbus_message_set_reply_serial (message, 5678);
|
||||
|
||||
v_INT16 = -0x123;
|
||||
v_UINT16 = 0x123;
|
||||
v_INT32 = -0x12345678;
|
||||
v_UINT32 = 0x12300042;
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
|
|
@ -987,6 +1003,8 @@ _dbus_message_test (const char *test_data_dir)
|
|||
v2_BYTE = 24;
|
||||
|
||||
dbus_message_append_args (message,
|
||||
DBUS_TYPE_INT16, &v_INT16,
|
||||
DBUS_TYPE_UINT16, &v_UINT16,
|
||||
DBUS_TYPE_INT32, &v_INT32,
|
||||
DBUS_TYPE_UINT32, &v_UINT32,
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
|
|
@ -1017,6 +1035,8 @@ _dbus_message_test (const char *test_data_dir)
|
|||
DBUS_TYPE_INVALID);
|
||||
|
||||
i = 0;
|
||||
sig[i++] = DBUS_TYPE_INT16;
|
||||
sig[i++] = DBUS_TYPE_UINT16;
|
||||
sig[i++] = DBUS_TYPE_INT32;
|
||||
sig[i++] = DBUS_TYPE_UINT32;
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
|
|
|
|||
|
|
@ -49,9 +49,12 @@ extern "C" {
|
|||
#define DBUS_TYPE_BYTE_AS_STRING "y"
|
||||
#define DBUS_TYPE_BOOLEAN ((int) 'b')
|
||||
#define DBUS_TYPE_BOOLEAN_AS_STRING "b"
|
||||
#define DBUS_TYPE_INT16 ((int) 'n')
|
||||
#define DBUS_TYPE_INT16_AS_STRING "n"
|
||||
#define DBUS_TYPE_UINT16 ((int) 'q')
|
||||
#define DBUS_TYPE_UINT16_AS_STRING "q"
|
||||
#define DBUS_TYPE_INT32 ((int) 'i')
|
||||
#define DBUS_TYPE_INT32_AS_STRING "i"
|
||||
|
||||
#define DBUS_TYPE_UINT32 ((int) 'u')
|
||||
#define DBUS_TYPE_UINT32_AS_STRING "u"
|
||||
#define DBUS_TYPE_INT64 ((int) 'x')
|
||||
|
|
@ -81,7 +84,7 @@ extern "C" {
|
|||
#define DBUS_TYPE_STRUCT_AS_STRING "r"
|
||||
|
||||
/* Does not count INVALID */
|
||||
#define DBUS_NUMBER_OF_TYPES (13)
|
||||
#define DBUS_NUMBER_OF_TYPES (15)
|
||||
|
||||
/* characters other than typecodes that appear in type signatures */
|
||||
#define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ typedef struct
|
|||
* This is the maximum max length (and thus also the maximum length)
|
||||
* of a DBusString
|
||||
*/
|
||||
#define _DBUS_STRING_MAX_MAX_LENGTH (_DBUS_INT_MAX - _DBUS_STRING_ALLOCATION_PADDING)
|
||||
#define _DBUS_STRING_MAX_MAX_LENGTH (_DBUS_INT32_MAX - _DBUS_STRING_ALLOCATION_PADDING)
|
||||
|
||||
/**
|
||||
* Checks a bunch of assertions about a string object
|
||||
|
|
|
|||
|
|
@ -974,6 +974,9 @@ _dbus_string_append (DBusString *str,
|
|||
return append (real, buffer, buffer_len);
|
||||
}
|
||||
|
||||
/** assign 2 bytes from one string to another */
|
||||
#define ASSIGN_2_OCTETS(p, octets) \
|
||||
*((dbus_uint16_t*)(p)) = *((dbus_uint16_t*)(octets));
|
||||
|
||||
/** assign 4 bytes from one string to another */
|
||||
#define ASSIGN_4_OCTETS(p, octets) \
|
||||
|
|
@ -1051,6 +1054,30 @@ _dbus_string_append_8_aligned (DBusString *str,
|
|||
}
|
||||
#endif /* DBUS_BUILD_TESTS */
|
||||
|
||||
/**
|
||||
* Inserts 2 bytes aligned on a 2 byte boundary
|
||||
* with any alignment padding initialized to 0.
|
||||
*
|
||||
* @param str the DBusString
|
||||
* @param insert_at where to insert
|
||||
* @param octets 2 bytes to insert
|
||||
* @returns #FALSE if not enough memory.
|
||||
*/
|
||||
dbus_bool_t
|
||||
_dbus_string_insert_2_aligned (DBusString *str,
|
||||
int insert_at,
|
||||
const unsigned char octets[4])
|
||||
{
|
||||
DBUS_STRING_PREAMBLE (str);
|
||||
|
||||
if (!align_insert_point_then_open_gap (str, &insert_at, 2, 2))
|
||||
return FALSE;
|
||||
|
||||
ASSIGN_2_OCTETS (real->str + insert_at, octets);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts 4 bytes aligned on a 4 byte boundary
|
||||
* with any alignment padding initialized to 0.
|
||||
|
|
@ -1109,7 +1136,7 @@ _dbus_string_insert_8_aligned (DBusString *str,
|
|||
*
|
||||
* @param str the DBusString
|
||||
* @param insert_at location to be aligned
|
||||
* @param alignment alignment boundary (1, 4, or 8)
|
||||
* @param alignment alignment boundary (1, 2, 4, or 8)
|
||||
* @returns #FALSE if not enough memory.
|
||||
*/
|
||||
dbus_bool_t
|
||||
|
|
|
|||
|
|
@ -156,6 +156,9 @@ dbus_bool_t _dbus_string_append_printf (DBusString *str,
|
|||
dbus_bool_t _dbus_string_append_printf_valist (DBusString *str,
|
||||
const char *format,
|
||||
va_list args);
|
||||
dbus_bool_t _dbus_string_insert_2_aligned (DBusString *str,
|
||||
int insert_at,
|
||||
const unsigned char octets[2]);
|
||||
dbus_bool_t _dbus_string_insert_4_aligned (DBusString *str,
|
||||
int insert_at,
|
||||
const unsigned char octets[4]);
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
|
|||
|
||||
check_memleaks ();
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
printf ("%s: running recursive marshalling tests\n", "dbus-test");
|
||||
if (!_dbus_marshal_recursive_test ())
|
||||
die ("recursive marshal");
|
||||
|
|
@ -140,7 +140,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
|
|||
|
||||
check_memleaks ();
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
printf ("%s: running memory pool tests\n", "dbus-test");
|
||||
if (!_dbus_mem_pool_test ())
|
||||
die ("memory pools");
|
||||
|
|
|
|||
|
|
@ -920,10 +920,10 @@ _dbus_transport_get_unix_user (DBusTransport *transport,
|
|||
{
|
||||
DBusCredentials auth_identity;
|
||||
|
||||
*uid = _DBUS_INT_MAX; /* better than some root or system user in
|
||||
* case of bugs in the caller. Caller should
|
||||
* never use this value on purpose, however.
|
||||
*/
|
||||
*uid = _DBUS_INT32_MAX; /* better than some root or system user in
|
||||
* case of bugs in the caller. Caller should
|
||||
* never use this value on purpose, however.
|
||||
*/
|
||||
|
||||
if (!transport->authenticated)
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -28,9 +28,8 @@
|
|||
#define DBUS_TYPES_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <dbus/dbus-arch-deps.h>
|
||||
|
||||
typedef unsigned int dbus_uint32_t;
|
||||
typedef int dbus_int32_t;
|
||||
typedef dbus_uint32_t dbus_unichar_t;
|
||||
/* boolean size must be fixed at 4 bytes due to wire protocol! */
|
||||
typedef dbus_uint32_t dbus_bool_t;
|
||||
|
|
|
|||
|
|
@ -437,6 +437,10 @@ basic_type_from_string (const char *str)
|
|||
{
|
||||
if (strcmp (str, "string") == 0)
|
||||
return DBUS_TYPE_STRING;
|
||||
else if (strcmp (str, "int16") == 0)
|
||||
return DBUS_TYPE_INT16;
|
||||
else if (strcmp (str, "uint16") == 0)
|
||||
return DBUS_TYPE_UINT16;
|
||||
else if (strcmp (str, "int32") == 0)
|
||||
return DBUS_TYPE_INT32;
|
||||
else if (strcmp (str, "uint32") == 0)
|
||||
|
|
|
|||
|
|
@ -88,6 +88,10 @@ _dbus_gutils_type_to_string (int type)
|
|||
return "boolean";
|
||||
case DBUS_TYPE_BYTE:
|
||||
return "byte";
|
||||
case DBUS_TYPE_INT16:
|
||||
return "int16";
|
||||
case DBUS_TYPE_UINT16:
|
||||
return "uint16";
|
||||
case DBUS_TYPE_INT32:
|
||||
return "int32";
|
||||
case DBUS_TYPE_UINT32:
|
||||
|
|
|
|||
|
|
@ -40,12 +40,29 @@ dbus_gvalue_demarshal (DBusMessageIter *iter, GValue *value)
|
|||
switch (dbus_message_iter_get_arg_type (iter))
|
||||
{
|
||||
MAP_BASIC (BOOLEAN, BOOLEAN);
|
||||
MAP_BASIC (BYTE, UCHAR);
|
||||
MAP_BASIC (INT32, INT);
|
||||
MAP_BASIC (UINT32, UINT);
|
||||
MAP_BASIC (INT64, INT64);
|
||||
MAP_BASIC (UINT64, UINT64);
|
||||
MAP_BASIC (DOUBLE, DOUBLE);
|
||||
MAP_BASIC (BYTE, UCHAR);
|
||||
MAP_BASIC (INT32, INT);
|
||||
MAP_BASIC (UINT32, UINT);
|
||||
MAP_BASIC (INT64, INT64);
|
||||
MAP_BASIC (UINT64, UINT64);
|
||||
MAP_BASIC (DOUBLE, DOUBLE);
|
||||
|
||||
case DBUS_TYPE_INT16:
|
||||
{
|
||||
dbus_int16_t v;
|
||||
g_value_init (value, G_TYPE_INT);
|
||||
dbus_message_iter_get_basic (iter, &v);
|
||||
g_value_set_int (value, v);
|
||||
}
|
||||
break;
|
||||
case DBUS_TYPE_UINT16:
|
||||
{
|
||||
dbus_uint16_t v;
|
||||
g_value_init (value, G_TYPE_UINT);
|
||||
dbus_message_iter_get_basic (iter, &v);
|
||||
g_value_set_uint (value, v);
|
||||
}
|
||||
break;
|
||||
|
||||
case DBUS_TYPE_STRING:
|
||||
case DBUS_TYPE_OBJECT_PATH:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue