summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--dbus/dbus-message.c72
-rw-r--r--test/data/valid-messages/opposite-endian.message33
3 files changed, 109 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9eea1d58..7afd0e28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2003-01-28 Havoc Pennington <hp@pobox.com>
+ * dbus/dbus-message.c (check_message_handling): function to check
+ on the loaded message, iterates over it etc.
+
+2003-01-28 Havoc Pennington <hp@pobox.com>
+
* test/Makefile.am (dist-hook): fix make distdir
* dbus/Makefile.am (TESTS_ENVIRONMENT): fix make check
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index e0b85663..08dc45e5 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -422,6 +422,12 @@ set_string_field (DBusMessage *message,
* Sets the client serial of a message.
* This can only be done once on a message.
*
+ * @todo client_serial should be called simply
+ * "serial"; it's in outgoing messages for both
+ * the client and the server, it's only client-specific
+ * in the message bus case. It's more like origin_serial
+ * or something.
+ *
* @param message the message
* @param client_serial the client serial
*/
@@ -458,6 +464,11 @@ _dbus_message_set_reply_serial (DBusMessage *message,
* Returns the client serial of a message or
* -1 if none has been specified.
*
+ * @todo see note in _dbus_message_set_client_serial()
+ * about how client_serial is a misnomer
+ *
+ * @todo this function should be public, after renaming it.
+ *
* @param message the message
* @returns the client serial
*/
@@ -1277,7 +1288,8 @@ dbus_message_iter_has_next (DBusMessageIter *iter)
{
int end_pos;
- if (!_dbus_marshal_get_field_end_pos (&iter->message->body, iter->message->byte_order,
+ if (!_dbus_marshal_get_field_end_pos (&iter->message->body,
+ iter->message->byte_order,
iter->pos, &end_pos))
return FALSE;
@@ -2020,6 +2032,57 @@ message_iter_test (DBusMessage *message)
}
static dbus_bool_t
+check_message_handling (DBusMessage *message)
+{
+ DBusMessageIter *iter;
+ int type;
+ dbus_bool_t retval;
+ dbus_int32_t client_serial;
+
+ retval = FALSE;
+ iter = NULL;
+
+ client_serial = _dbus_message_get_client_serial (message);
+ _dbus_message_set_client_serial (message);
+
+ if (client_serial != _dbus_message_get_client_serial (message))
+ {
+ _dbus_warn ("get/set cycle for client_serial did not succeed\n");
+ goto failed;
+ }
+
+ /* If we implement message_set_field (message, n, value)
+ * then we would want to test it here
+ */
+
+ iter = dbus_message_get_fields_iter (message);
+ while ((type = dbus_message_iter_get_field_type (iter)) != DBUS_TYPE_INVALID)
+ {
+ switch (type)
+ {
+ case DBUS_TYPE_STRING:
+ {
+ char *str;
+ str = dbus_message_iter_get_string (iter);
+ dbus_free (str);
+ }
+ break;
+ }
+
+ if (!dbus_message_iter_next (iter))
+ break;
+ }
+
+ retval = TRUE;
+
+ failed:
+ if (iter)
+ dbus_message_iter_unref (iter);
+
+ return retval;
+}
+
+static dbus_bool_t
check_have_valid_message (DBusMessageLoader *loader)
{
DBusMessage *message;
@@ -2047,6 +2110,13 @@ check_have_valid_message (DBusMessageLoader *loader)
goto failed;
}
+ /* Verify that we're able to properly deal with the message.
+ * For example, this would detect improper handling of messages
+ * in nonstandard byte order.
+ */
+ if (!check_message_handling (message))
+ goto failed;
+
retval = TRUE;
failed:
diff --git a/test/data/valid-messages/opposite-endian.message b/test/data/valid-messages/opposite-endian.message
new file mode 100644
index 00000000..864795bd
--- /dev/null
+++ b/test/data/valid-messages/opposite-endian.message
@@ -0,0 +1,33 @@
+## Message of opposite endianness, with lots of random fields in it
+
+OPPOSITE_ENDIAN
+
+## VALID_HEADER includes a LENGTH Header and LENGTH Body
+VALID_HEADER
+
+FIELD_NAME repl
+TYPE INT32
+INT32 10000
+
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
+
+FIELD_NAME unkn
+TYPE INT32
+INT32 0xfeeb
+
+END_LENGTH Header
+
+START_LENGTH Body
+
+TYPE INT32
+INT32 89765432
+TYPE UINT32
+UINT32 0xfffffff
+TYPE STRING
+STRING 'Hello this is a string'
+TYPE DOUBLE
+DOUBLE 3.14159
+
+END_LENGTH Body