summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-internals.c4
-rw-r--r--dbus/dbus-marshal.c10
-rw-r--r--dbus/dbus-message-builder.c107
-rw-r--r--dbus/dbus-message.c156
-rw-r--r--dbus/dbus-message.h118
-rw-r--r--dbus/dbus-protocol.h20
6 files changed, 347 insertions, 68 deletions
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c
index f85ad18b..8dedb56a 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -355,6 +355,8 @@ _dbus_type_to_string (int type)
return "invalid";
case DBUS_TYPE_NIL:
return "nil";
+ case DBUS_TYPE_BOOLEAN:
+ return "boolean";
case DBUS_TYPE_INT32:
return "int32";
case DBUS_TYPE_UINT32:
@@ -363,6 +365,8 @@ _dbus_type_to_string (int type)
return "double";
case DBUS_TYPE_STRING:
return "string";
+ case DBUS_TYPE_BOOLEAN_ARRAY:
+ return "boolean array";
case DBUS_TYPE_INT32_ARRAY:
return "int32 array";
case DBUS_TYPE_UINT32_ARRAY:
diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c
index f32daef0..37a97515 100644
--- a/dbus/dbus-marshal.c
+++ b/dbus/dbus-marshal.c
@@ -878,6 +878,10 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str,
case DBUS_TYPE_NIL:
*end_pos = pos + 1;
break;
+
+ case DBUS_TYPE_BOOLEAN:
+ *end_pos = pos + 2;
+ break;
case DBUS_TYPE_INT32:
*end_pos = _DBUS_ALIGN_VALUE (pos + 1, sizeof (dbus_int32_t)) + sizeof (dbus_int32_t);
@@ -905,6 +909,7 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str,
}
break;
+ case DBUS_TYPE_BOOLEAN_ARRAY:
case DBUS_TYPE_BYTE_ARRAY:
{
int len;
@@ -1102,6 +1107,10 @@ _dbus_marshal_validate_arg (const DBusString *str,
case DBUS_TYPE_NIL:
*end_pos = pos + 1;
break;
+
+ case DBUS_TYPE_BOOLEAN:
+ *end_pos = pos + 2;
+ break;
case DBUS_TYPE_INT32:
case DBUS_TYPE_UINT32:
@@ -1152,6 +1161,7 @@ _dbus_marshal_validate_arg (const DBusString *str,
}
break;
+ case DBUS_TYPE_BOOLEAN_ARRAY:
case DBUS_TYPE_BYTE_ARRAY:
{
int len;
diff --git a/dbus/dbus-message-builder.c b/dbus/dbus-message-builder.c
index 03022ba5..9526a2e1 100644
--- a/dbus/dbus-message-builder.c
+++ b/dbus/dbus-message-builder.c
@@ -597,6 +597,8 @@ _dbus_message_data_load (DBusString *dest,
code = DBUS_TYPE_INVALID;
else if (_dbus_string_starts_with_c_str (&line, "NIL"))
code = DBUS_TYPE_NIL;
+ else if (_dbus_string_starts_with_c_str (&line, "BOOLEAN_ARRAY"))
+ code = DBUS_TYPE_BOOLEAN_ARRAY;
else if (_dbus_string_starts_with_c_str (&line, "INT32_ARRAY"))
code = DBUS_TYPE_INT32_ARRAY;
else if (_dbus_string_starts_with_c_str (&line, "UINT32_ARRAY"))
@@ -607,6 +609,8 @@ _dbus_message_data_load (DBusString *dest,
code = DBUS_TYPE_BYTE_ARRAY;
else if (_dbus_string_starts_with_c_str (&line, "STRING_ARRAY"))
code = DBUS_TYPE_STRING_ARRAY;
+ else if (_dbus_string_starts_with_c_str (&line, "BOOLEAN"))
+ code = DBUS_TYPE_BOOLEAN;
else if (_dbus_string_starts_with_c_str (&line, "INT32"))
code = DBUS_TYPE_INT32;
else if (_dbus_string_starts_with_c_str (&line, "UINT32"))
@@ -630,6 +634,86 @@ _dbus_message_data_load (DBusString *dest,
}
}
else if (_dbus_string_starts_with_c_str (&line,
+ "BOOLEAN_ARRAY"))
+ {
+ SAVE_FOR_UNALIGN (dest, 4);
+ int i, len, allocated;
+ unsigned char *values;
+ unsigned char b, val;
+
+ allocated = 4;
+ values = dbus_new (unsigned char, allocated);
+ if (!values)
+ {
+ _dbus_warn ("could not allocate memory for BOOLEAN_ARRAY\n");
+ goto parse_failed;
+ }
+
+ len = 0;
+
+ _dbus_string_delete_first_word (&line);
+ _dbus_string_skip_blank (&line, 0, &i);
+ b = _dbus_string_get_byte (&line, i++);
+
+ if (b != '{')
+ goto parse_failed;
+
+ while (i < _dbus_string_get_length (&line))
+ {
+ _dbus_string_skip_blank (&line, i, &i);
+ printf ("i is: %d\n", i);
+
+ if (_dbus_string_find_to (&line, i, i + 5,
+ "false", NULL))
+ {
+ i += 5;
+ val = TRUE;
+ }
+ else if (_dbus_string_find_to (&line, i, i + 4,
+ "true", NULL))
+ {
+ i += 4;
+ val = FALSE;
+ }
+ else
+ {
+ _dbus_warn ("could not parse BOOLEAN_ARRAY\n");
+ goto parse_failed;
+ }
+
+ values[len++] = val;
+ if (len == allocated)
+ {
+ allocated *= 2;
+ values = dbus_realloc (values, allocated * sizeof (unsigned char));
+ if (!values)
+ {
+ _dbus_warn ("could not allocate memory for BOOLEAN_ARRAY\n");
+ goto parse_failed;
+ }
+ }
+
+ _dbus_string_skip_blank (&line, i, &i);
+
+ b = _dbus_string_get_byte (&line, i++);
+
+ if (b == '}')
+ break;
+ else if (b != ',')
+ goto parse_failed;
+ }
+
+ if (!_dbus_marshal_int32 (dest, endian, len) ||
+ !_dbus_string_append_len (dest, values, len))
+ {
+ _dbus_warn ("failed to append BOOLEAN_ARRAY\n");
+ goto parse_failed;
+ }
+ dbus_free (values);
+
+ PERFORM_UNALIGN (dest);
+ }
+ else if (_dbus_string_starts_with_c_str (&line,
"INT32_ARRAY"))
{
SAVE_FOR_UNALIGN (dest, 4);
@@ -913,6 +997,29 @@ _dbus_message_data_load (DBusString *dest,
PERFORM_UNALIGN (dest);
}
else if (_dbus_string_starts_with_c_str (&line,
+ "BOOLEAN"))
+ {
+ unsigned char val;
+
+ _dbus_string_delete_first_word (&line);
+
+ if (_dbus_string_starts_with_c_str (&line, "true"))
+ val = TRUE;
+ else if (_dbus_string_starts_with_c_str (&line, "false"))
+ val = FALSE;
+ else
+ {
+ _dbus_warn ("could not parse BOOLEAN\n");
+ goto parse_failed;
+ }
+ if (!_dbus_string_append_byte (dest, val))
+ {
+ _dbus_warn ("failed to append BOOLEAN\n");
+ goto parse_failed;
+ }
+ }
+
+ else if (_dbus_string_starts_with_c_str (&line,
"INT32"))
{
SAVE_FOR_UNALIGN (dest, 4);
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 7feee745..0d664916 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -1049,6 +1049,9 @@ dbus_message_append_args_valist (DBusMessage *message,
case DBUS_TYPE_NIL:
if (!dbus_message_append_nil (message))
goto enomem;
+ case DBUS_TYPE_BOOLEAN:
+ if (!dbus_message_append_boolean (message, va_arg (var_args, dbus_bool_t)))
+ goto enomem;
case DBUS_TYPE_INT32:
if (!dbus_message_append_int32 (message, va_arg (var_args, dbus_int32_t)))
goto enomem;
@@ -1065,6 +1068,18 @@ dbus_message_append_args_valist (DBusMessage *message,
if (!dbus_message_append_string (message, va_arg (var_args, const char *)))
goto enomem;
break;
+ case DBUS_TYPE_BOOLEAN_ARRAY:
+ {
+ int len;
+ unsigned char *data;
+
+ data = va_arg (var_args, unsigned char *);
+ len = va_arg (var_args, int);
+
+ if (!dbus_message_append_boolean_array (message, data, len))
+ goto enomem;
+ }
+ break;
case DBUS_TYPE_INT32_ARRAY:
{
int len;
@@ -1157,6 +1172,31 @@ dbus_message_append_nil (DBusMessage *message)
}
/**
+ * Appends a boolean value to the message
+ *
+ * @param message the message
+ * @param value the boolean value
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_boolean (DBusMessage *message,
+ unsigned char value)
+{
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_BOOLEAN))
+ return FALSE;
+
+ if (!_dbus_string_append_byte (&message->body, (value != FALSE)))
+ {
+ _dbus_string_shorten (&message->body, 1);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* Appends a 32 bit signed integer to the message.
*
* @param message the message
@@ -1257,6 +1297,33 @@ dbus_message_append_string (DBusMessage *message,
}
/**
+ * Appends a boolean array to the message.
+ *
+ * @param message the message
+ * @param value the array
+ * @param len the length of the array
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_boolean_array (DBusMessage *message,
+ unsigned char *value,
+ int len)
+{
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_BOOLEAN_ARRAY))
+ return FALSE;
+
+ if (!_dbus_marshal_byte_array (&message->body, message->byte_order, value, len))
+ {
+ _dbus_string_shorten (&message->body, 1);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* Appends a 32 bit signed integer array to the message.
*
* @param message the message
@@ -1472,6 +1539,17 @@ dbus_message_get_args_valist (DBusMessage *message,
switch (spec_type)
{
+ case DBUS_TYPE_NIL:
+ break;
+ case DBUS_TYPE_BOOLEAN:
+ {
+ unsigned char *ptr;
+
+ ptr = va_arg (var_args, unsigned char *);
+
+ *ptr = dbus_message_iter_get_boolean (iter);
+ break;
+ }
case DBUS_TYPE_INT32:
{
dbus_int32_t *ptr;
@@ -1515,6 +1593,20 @@ dbus_message_get_args_valist (DBusMessage *message,
break;
}
+ case DBUS_TYPE_BOOLEAN_ARRAY:
+ {
+ unsigned char **ptr;
+ int *len;
+
+ ptr = va_arg (var_args, unsigned char **);
+ len = va_arg (var_args, int *);
+
+ if (!dbus_message_iter_get_boolean_array (iter, ptr, len))
+ return DBUS_RESULT_NO_MEMORY;
+
+ break;
+ }
+
case DBUS_TYPE_INT32_ARRAY:
{
dbus_int32_t **ptr;
@@ -1740,7 +1832,7 @@ dbus_message_iter_get_arg_type (DBusMessageIter *iter)
* Note that you need to check that the iterator points to
* a string value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the string
*/
@@ -1754,17 +1846,41 @@ dbus_message_iter_get_string (DBusMessageIter *iter)
}
/**
+ * Returns the boolean value that an iterator may point to.
+ * Note that you need to check that the iterator points to
+ * a boolean value before using this function.
+ *
+ * @see dbus_message_iter_get_arg_type
+ * @param iter the message iter
+ * @returns the string
+ */
+unsigned char
+dbus_message_iter_get_boolean (DBusMessageIter *iter)
+{
+ unsigned char value;
+
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BOOLEAN);
+
+ value = _dbus_string_get_byte (&iter->message->body, iter->pos + 1);
+ iter->pos += 2;
+
+ return value;
+}
+
+/**
* Returns the 32 bit signed integer value that an iterator may point to.
* Note that you need to check that the iterator points to
* an integer value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the integer
*/
int
dbus_message_iter_get_int32 (DBusMessageIter *iter)
{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_INT32);
+
return _dbus_demarshal_int32 (&iter->message->body, iter->message->byte_order,
iter->pos + 1, NULL);
}
@@ -1774,13 +1890,15 @@ dbus_message_iter_get_int32 (DBusMessageIter *iter)
* Note that you need to check that the iterator points to
* an unsigned integer value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the integer
*/
int
dbus_message_iter_get_uint32 (DBusMessageIter *iter)
{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_UINT32);
+
return _dbus_demarshal_uint32 (&iter->message->body, iter->message->byte_order,
iter->pos + 1, NULL);
}
@@ -1790,18 +1908,46 @@ dbus_message_iter_get_uint32 (DBusMessageIter *iter)
* Note that you need to check that the iterator points to
* a string value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the double
*/
double
dbus_message_iter_get_double (DBusMessageIter *iter)
{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_DOUBLE);
+
return _dbus_demarshal_double (&iter->message->body, iter->message->byte_order,
iter->pos + 1, NULL);
}
/**
+ * Returns the boolean array that the iterator may point to. Note that
+ * you need to check that the iterator points to an array of the
+ * correct type prior to using this function.
+ *
+ * @param iter the iterator
+ * @param value return location for the array
+ * @param len return location for the array length
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_iter_get_boolean_array (DBusMessageIter *iter,
+ unsigned char **value,
+ int *len)
+{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BOOLEAN_ARRAY);
+
+ *value = _dbus_demarshal_byte_array (&iter->message->body, iter->message->byte_order,
+ iter->pos + 1, NULL, len);
+
+ if (!*value)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+/**
* Returns the 32 bit signed integer array that the iterator may point
* to. Note that you need to check that the iterator points to an
* array of the correct type prior to using this function.
@@ -2668,7 +2814,7 @@ message_iter_test (DBusMessage *message)
if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT32)
_dbus_assert_not_reached ("Argument type isn't int32");
- if (dbus_message_iter_get_int32 (iter) != 0xedd1e)
+ if (dbus_message_iter_get_uint32 (iter) != 0xedd1e)
_dbus_assert_not_reached ("Unsigned integers differ");
if (!dbus_message_iter_next (iter))
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index 50ca6d7e..ecb7407e 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -59,36 +59,42 @@ dbus_bool_t dbus_message_get_is_error (DBusMessage *message);
dbus_bool_t dbus_message_name_is (DBusMessage *message,
const char *name);
-dbus_bool_t dbus_message_append_args (DBusMessage *message,
- int first_arg_type,
- ...);
-dbus_bool_t dbus_message_append_args_valist (DBusMessage *message,
- int first_arg_type,
- va_list var_args);
-dbus_bool_t dbus_message_append_nil (DBusMessage *message);
-dbus_bool_t dbus_message_append_int32 (DBusMessage *message,
- dbus_int32_t value);
-dbus_bool_t dbus_message_append_uint32 (DBusMessage *message,
- dbus_uint32_t value);
-dbus_bool_t dbus_message_append_double (DBusMessage *message,
- double value);
-dbus_bool_t dbus_message_append_string (DBusMessage *message,
- const char *value);
-dbus_bool_t dbus_message_append_int32_array (DBusMessage *message,
- const dbus_int32_t *value,
- int len);
-dbus_bool_t dbus_message_append_uint32_array (DBusMessage *message,
- const dbus_uint32_t *value,
- int len);
-dbus_bool_t dbus_message_append_double_array (DBusMessage *message,
- const double *value,
- int len);
-dbus_bool_t dbus_message_append_byte_array (DBusMessage *message,
- unsigned const char *value,
- int len);
-dbus_bool_t dbus_message_append_string_array (DBusMessage *message,
- const char **value,
- int len);
+dbus_bool_t dbus_message_append_args (DBusMessage *message,
+ int first_arg_type,
+ ...);
+dbus_bool_t dbus_message_append_args_valist (DBusMessage *message,
+ int first_arg_type,
+ va_list var_args);
+dbus_bool_t dbus_message_append_nil (DBusMessage *message);
+dbus_bool_t dbus_message_append_boolean (DBusMessage *message,
+ unsigned char value);
+dbus_bool_t dbus_message_append_int32 (DBusMessage *message,
+ dbus_int32_t value);
+dbus_bool_t dbus_message_append_uint32 (DBusMessage *message,
+ dbus_uint32_t value);
+dbus_bool_t dbus_message_append_double (DBusMessage *message,
+ double value);
+dbus_bool_t dbus_message_append_string (DBusMessage *message,
+ const char *value);
+dbus_bool_t dbus_message_append_boolean_array (DBusMessage *message,
+ unsigned char *value,
+ int len);
+dbus_bool_t dbus_message_append_int32_array (DBusMessage *message,
+ const dbus_int32_t *value,
+ int len);
+dbus_bool_t dbus_message_append_uint32_array (DBusMessage *message,
+ const dbus_uint32_t *value,
+ int len);
+dbus_bool_t dbus_message_append_double_array (DBusMessage *message,
+ const double *value,
+ int len);
+dbus_bool_t dbus_message_append_byte_array (DBusMessage *message,
+ unsigned const char *value,
+ int len);
+dbus_bool_t dbus_message_append_string_array (DBusMessage *message,
+ const char **value,
+ int len);
+
DBusMessageIter *dbus_message_get_args_iter (DBusMessage *message);
DBusResultCode dbus_message_get_args (DBusMessage *message,
@@ -100,30 +106,34 @@ DBusResultCode dbus_message_get_args_valist (DBusMessage *message,
-void dbus_message_iter_ref (DBusMessageIter *iter);
-void dbus_message_iter_unref (DBusMessageIter *iter);
-dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter);
-dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
-int dbus_message_iter_get_arg_type (DBusMessageIter *iter);
-int dbus_message_iter_get_int32 (DBusMessageIter *iter);
-int dbus_message_iter_get_uint32 (DBusMessageIter *iter);
-double dbus_message_iter_get_double (DBusMessageIter *iter);
-char * dbus_message_iter_get_string (DBusMessageIter *iter);
-dbus_bool_t dbus_message_iter_get_int32_array (DBusMessageIter *iter,
- dbus_int32_t **value,
- int *len);
-dbus_bool_t dbus_message_iter_get_uint32_array (DBusMessageIter *iter,
- dbus_uint32_t **value,
- int *len);
-dbus_bool_t dbus_message_iter_get_double_array (DBusMessageIter *iter,
- double **value,
- int *len);
-dbus_bool_t dbus_message_iter_get_byte_array (DBusMessageIter *iter,
- unsigned char **value,
- int *len);
-dbus_bool_t dbus_message_iter_get_string_array (DBusMessageIter *iter,
- char ***value,
- int *len);
+void dbus_message_iter_ref (DBusMessageIter *iter);
+void dbus_message_iter_unref (DBusMessageIter *iter);
+dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter);
+dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
+int dbus_message_iter_get_arg_type (DBusMessageIter *iter);
+unsigned char dbus_message_iter_get_boolean (DBusMessageIter *iter);
+int dbus_message_iter_get_int32 (DBusMessageIter *iter);
+int dbus_message_iter_get_uint32 (DBusMessageIter *iter);
+double dbus_message_iter_get_double (DBusMessageIter *iter);
+char * dbus_message_iter_get_string (DBusMessageIter *iter);
+dbus_bool_t dbus_message_iter_get_boolean_array (DBusMessageIter *iter,
+ unsigned char **value,
+ int *len);
+dbus_bool_t dbus_message_iter_get_int32_array (DBusMessageIter *iter,
+ dbus_int32_t **value,
+ int *len);
+dbus_bool_t dbus_message_iter_get_uint32_array (DBusMessageIter *iter,
+ dbus_uint32_t **value,
+ int *len);
+dbus_bool_t dbus_message_iter_get_double_array (DBusMessageIter *iter,
+ double **value,
+ int *len);
+dbus_bool_t dbus_message_iter_get_byte_array (DBusMessageIter *iter,
+ unsigned char **value,
+ int *len);
+dbus_bool_t dbus_message_iter_get_string_array (DBusMessageIter *iter,
+ char ***value,
+ int *len);
DBUS_END_DECLS;
diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h
index dd9b3122..1a6fcb80 100644
--- a/dbus/dbus-protocol.h
+++ b/dbus/dbus-protocol.h
@@ -42,15 +42,17 @@ extern "C" {
/* Data types */
#define DBUS_TYPE_INVALID 0
#define DBUS_TYPE_NIL 1
-#define DBUS_TYPE_INT32 2
-#define DBUS_TYPE_UINT32 3
-#define DBUS_TYPE_DOUBLE 4
-#define DBUS_TYPE_STRING 5
-#define DBUS_TYPE_INT32_ARRAY 6
-#define DBUS_TYPE_UINT32_ARRAY 7
-#define DBUS_TYPE_DOUBLE_ARRAY 8
-#define DBUS_TYPE_BYTE_ARRAY 9
-#define DBUS_TYPE_STRING_ARRAY 10
+#define DBUS_TYPE_BOOLEAN 2
+#define DBUS_TYPE_INT32 3
+#define DBUS_TYPE_UINT32 4
+#define DBUS_TYPE_DOUBLE 5
+#define DBUS_TYPE_STRING 6
+#define DBUS_TYPE_BOOLEAN_ARRAY 7
+#define DBUS_TYPE_INT32_ARRAY 8
+#define DBUS_TYPE_UINT32_ARRAY 9
+#define DBUS_TYPE_DOUBLE_ARRAY 10
+#define DBUS_TYPE_BYTE_ARRAY 11
+#define DBUS_TYPE_STRING_ARRAY 12
/* Header flags */
#define DBUS_HEADER_FLAG_ERROR 0x1