/* Make sure the message does not have any header fields that we
* don't understand (or validate), so that we can add header fields
* in future and clients can assume that we have checked them. */
- if (!_dbus_message_remove_unknown_fields (message))
+ if (!_dbus_message_remove_unknown_fields (message) ||
+ !dbus_message_set_container_instance (message, NULL))
{
BUS_SET_OOM (&error);
goto out;
{ DBUS_HEADER_FIELD_DESTINATION, DBUS_TYPE_STRING },
{ DBUS_HEADER_FIELD_SENDER, DBUS_TYPE_STRING },
{ DBUS_HEADER_FIELD_SIGNATURE, DBUS_TYPE_SIGNATURE },
- { DBUS_HEADER_FIELD_UNIX_FDS, DBUS_TYPE_UINT32 }
+ { DBUS_HEADER_FIELD_UNIX_FDS, DBUS_TYPE_UINT32 },
+ { DBUS_HEADER_FIELD_CONTAINER_INSTANCE, DBUS_TYPE_OBJECT_PATH }
};
/** Macro to look up the correct type for a field */
string_validation_func = NULL;
break;
+ case DBUS_HEADER_FIELD_CONTAINER_INSTANCE:
+ /* OBJECT_PATH was validated generically due to its type */
+ string_validation_func = NULL;
+ break;
+
default:
_dbus_assert_not_reached ("unknown field shouldn't be seen here");
break;
_dbus_assert (strcmp (dbus_message_get_path (message),
"/foo") == 0);
+ if (!dbus_message_set_container_instance (message, "/org/freedesktop/DBus/Containers1/c42"))
+ _dbus_test_fatal ("out of memory");
+ _dbus_assert (strcmp (dbus_message_get_container_instance (message),
+ "/org/freedesktop/DBus/Containers1/c42") == 0);
+
if (!dbus_message_set_interface (message, "org.Foo"))
_dbus_test_fatal ("out of memory");
_dbus_assert (strcmp (dbus_message_get_interface (message),
#endif
}
+/**
+ * Sets the container instance this message was sent from.
+ *
+ * The path must contain only valid characters for an object path
+ * as defined in the D-Bus specification.
+ *
+ * @param message the message
+ * @param object_path the path or #NULL to unset
+ * @returns #FALSE if not enough memory
+ */
+dbus_bool_t
+dbus_message_set_container_instance (DBusMessage *message,
+ const char *object_path)
+{
+ _dbus_return_val_if_fail (message != NULL, FALSE);
+ _dbus_return_val_if_fail (!message->locked, FALSE);
+ _dbus_return_val_if_fail (object_path == NULL ||
+ _dbus_check_is_valid_path (object_path),
+ FALSE);
+
+ return set_or_delete_string_field (message,
+ DBUS_HEADER_FIELD_CONTAINER_INSTANCE,
+ DBUS_TYPE_OBJECT_PATH,
+ object_path);
+}
+
+/**
+ * Gets the container instance this message was sent from, or #NULL
+ * if none.
+ *
+ * The returned string becomes invalid if the message is
+ * modified, since it points into the wire-marshaled message data.
+ *
+ * @param message the message
+ * @returns the path (should not be freed) or #NULL
+ */
+const char *
+dbus_message_get_container_instance (DBusMessage *message)
+{
+ const char *v;
+
+ _dbus_return_val_if_fail (message != NULL, NULL);
+
+ v = NULL; /* in case field doesn't exist */
+ _dbus_header_get_field_basic (&message->header,
+ DBUS_HEADER_FIELD_CONTAINER_INSTANCE,
+ DBUS_TYPE_OBJECT_PATH,
+ (void *) &v);
+ return v;
+}
+
/** @} */
/**
dbus_bool_t dbus_message_get_path_decomposed (DBusMessage *message,
char ***path);
+DBUS_EXPORT
+const char *dbus_message_get_container_instance (DBusMessage *message);
+DBUS_EXPORT
+dbus_bool_t dbus_message_set_container_instance (DBusMessage *message,
+ const char *object_path);
+
DBUS_EXPORT
dbus_bool_t dbus_message_append_args (DBusMessage *message,
int first_arg_type,
* with this message.
*/
#define DBUS_HEADER_FIELD_UNIX_FDS 9
+/**
+ * Header field code for the container instance that sent this message.
+ */
+#define DBUS_HEADER_FIELD_CONTAINER_INSTANCE 10
/**
* that unknown codes must be ignored, so check for that before
* indexing the array.
*/
-#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_UNIX_FDS
+#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_CONTAINER_INSTANCE
/** Header format is defined as a signature:
* byte byte order