GDBusMessageType type;
GDBusMessageFlags flags;
+ gboolean locked;
+ GDBusMessageByteOrder byte_order;
guchar major_protocol_version;
guint32 serial;
GHashTable *headers;
#endif
};
+enum
+{
+ PROP_0,
+ PROP_LOCKED
+};
+
G_DEFINE_TYPE (GDBusMessage, g_dbus_message, G_TYPE_OBJECT);
static void
}
static void
+g_dbus_message_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GDBusMessage *message = G_DBUS_MESSAGE (object);
+
+ switch (prop_id)
+ {
+ case PROP_LOCKED:
+ g_value_set_boolean (value, g_dbus_message_get_locked (message));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
g_dbus_message_class_init (GDBusMessageClass *klass)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
-
gobject_class->finalize = g_dbus_message_finalize;
+ gobject_class->get_property = g_dbus_message_get_property;
+
+ /**
+ * GDBusConnection:locked:
+ *
+ * A boolean specifying whether the message is locked.
+ *
+ * Since: 2.26
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_LOCKED,
+ g_param_spec_boolean ("locked",
+ P_("Locked"),
+ P_("Whether the message is locked"),
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NICK));
}
static void
g_dbus_message_init (GDBusMessage *message)
{
+ /* Any D-Bus implementation is supposed to handle both Big and
+ * Little Endian encodings and the Endianness is part of the D-Bus
+ * message - we prefer to use Big Endian (since it's Network Byte
+ * Order and just easier to read for humans) but if the machine is
+ * Little Endian we use that for performance reasons.
+ */
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN;
+#else
+ /* this could also be G_PDP_ENDIAN */
+ message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN;
+#endif
message->headers = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
/**
* g_dbus_message_new_signal:
* @path: A valid object path.
- * @interface_: A valid D-Bus interface name or %NULL.
+ * @interface_: A valid D-Bus interface name.
* @signal: A valid signal name.
*
* Creates a new #GDBusMessage for a signal emission.
g_return_val_if_fail (g_variant_is_object_path (path), NULL);
g_return_val_if_fail (g_dbus_is_member_name (signal), NULL);
- g_return_val_if_fail (interface_ == NULL || g_dbus_is_interface_name (interface_), NULL);
+ g_return_val_if_fail (g_dbus_is_interface_name (interface_), NULL);
message = g_dbus_message_new ();
message->type = G_DBUS_MESSAGE_TYPE_SIGNAL;
g_dbus_message_set_path (message, path);
g_dbus_message_set_member (message, signal);
-
- if (interface_ != NULL)
- g_dbus_message_set_interface (message, interface_);
+ g_dbus_message_set_interface (message, interface_);
return message;
}
*
* Creates a new #GDBusMessage that is a reply to @method_call_message.
*
- * Returns: A #GDBusMessage. Free with g_object_unref().
+ * Returns: (transfer full): #GDBusMessage. Free with g_object_unref().
*
* Since: 2.26
*/
message = g_dbus_message_new ();
message->type = G_DBUS_MESSAGE_TYPE_METHOD_RETURN;
message->flags = G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED;
+ /* reply with same endianness */
+ message->byte_order = method_call_message->byte_order;
g_dbus_message_set_reply_serial (message, g_dbus_message_get_serial (method_call_message));
sender = g_dbus_message_get_sender (method_call_message);
*
* Creates a new #GDBusMessage that is an error reply to @method_call_message.
*
- * Returns: A #GDBusMessage. Free with g_object_unref().
+ * Returns: (transfer full): A #GDBusMessage. Free with g_object_unref().
*
* Since: 2.26
*/
*
* Creates a new #GDBusMessage that is an error reply to @method_call_message.
*
- * Returns: A #GDBusMessage. Free with g_object_unref().
+ * Returns: (transfer full): A #GDBusMessage. Free with g_object_unref().
*
* Since: 2.26
*/
message = g_dbus_message_new ();
message->type = G_DBUS_MESSAGE_TYPE_ERROR;
message->flags = G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED;
+ /* reply with same endianness */
+ message->byte_order = method_call_message->byte_order;
g_dbus_message_set_reply_serial (message, g_dbus_message_get_serial (method_call_message));
g_dbus_message_set_error_name (message, error_name);
*
* Like g_dbus_message_new_method_error() but intended for language bindings.
*
- * Returns: A #GDBusMessage. Free with g_object_unref().
+ * Returns: (transfer full): A #GDBusMessage. Free with g_object_unref().
*
* Since: 2.26
*/
/* ---------------------------------------------------------------------------------------------------- */
+/**
+ * g_dbus_message_get_byte_order:
+ * @message: A #GDBusMessage.
+ *
+ * Gets the byte order of @message.
+ *
+ * Returns: The byte order.
+ */
+GDBusMessageByteOrder
+g_dbus_message_get_byte_order (GDBusMessage *message)
+{
+ g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), (GDBusMessageByteOrder) 0);
+ return message->byte_order;
+}
+
+/**
+ * g_dbus_message_set_byte_order:
+ * @message: A #GDBusMessage.
+ * @byte_order: The byte order.
+ *
+ * Sets the byte order of @message.
+ */
+void
+g_dbus_message_set_byte_order (GDBusMessage *message,
+ GDBusMessageByteOrder byte_order)
+{
+ g_return_if_fail (G_IS_DBUS_MESSAGE (message));
+
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
+ message->byte_order = byte_order;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
/* TODO: need GI annotations to specify that any guchar value goes for the type */
/**
{
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
g_return_if_fail (type >=0 && type < 256);
+
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
message->type = type;
}
{
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
g_return_if_fail (flags >=0 && flags < 256);
+
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
message->flags = flags;
}
guint32 serial)
{
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
+
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
message->serial = serial;
}
{
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
g_return_if_fail (header_field >=0 && header_field < 256);
+
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
if (value == NULL)
{
g_hash_table_remove (message->headers, GUINT_TO_POINTER (header_field));
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
g_return_if_fail ((body == NULL) || g_variant_is_of_type (body, G_VARIANT_TYPE_TUPLE));
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
if (message->body != NULL)
g_variant_unref (message->body);
if (body == NULL)
*
* This method is only available on UNIX.
*
- * Returns: A #GUnixFDList or %NULL if no file descriptors are
+ * Returns: (transfer none):A #GUnixFDList or %NULL if no file descriptors are
* associated. Do not free, this object is owned by @message.
*
* Since: 2.26
/**
* g_dbus_message_set_unix_fd_list:
* @message: A #GDBusMessage.
- * @fd_list: A #GUnixFDList or %NULL.
+ * @fd_list: (allow-none): A #GUnixFDList or %NULL.
*
* Sets the UNIX file descriptors associated with @message. As a
* side-effect the %G_DBUS_MESSAGE_HEADER_FIELD_NUM_UNIX_FDS header
{
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
g_return_if_fail (fd_list == NULL || G_IS_UNIX_FD_LIST (fd_list));
+
+ if (message->locked)
+ {
+ g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
+ return;
+ }
+
if (message->fd_list != NULL)
g_object_unref (message->fd_list);
if (fd_list != NULL)
/* ---------------------------------------------------------------------------------------------------- */
static gboolean
+validate_headers (GDBusMessage *message,
+ GError **error)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = FALSE;
+
+ switch (message->type)
+ {
+ case G_DBUS_MESSAGE_TYPE_INVALID:
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("type is INVALID"));
+ goto out;
+ break;
+
+ case G_DBUS_MESSAGE_TYPE_METHOD_CALL:
+ if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_PATH) == NULL ||
+ g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_MEMBER) == NULL)
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("METHOD_CALL message: PATH or MEMBER header field is missing"));
+ goto out;
+ }
+ break;
+
+ case G_DBUS_MESSAGE_TYPE_METHOD_RETURN:
+ if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL) == NULL)
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("METHOD_RETURN message: REPLY_SERIAL header field is missing"));
+ goto out;
+ }
+ break;
+
+ case G_DBUS_MESSAGE_TYPE_ERROR:
+ if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME) == NULL ||
+ g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL) == NULL)
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing"));
+ goto out;
+ }
+ break;
+
+ case G_DBUS_MESSAGE_TYPE_SIGNAL:
+ if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_PATH) == NULL ||
+ g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_INTERFACE) == NULL ||
+ g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_MEMBER) == NULL)
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("SIGNAL message: PATH, INTERFACE or MEMBER header field is missing"));
+ goto out;
+ }
+ if (g_strcmp0 (g_dbus_message_get_path (message), "/org/freedesktop/DBus/Local") == 0)
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("SIGNAL message: The PATH header field is using the reserved value /org/freedesktop/DBus/Local"));
+ goto out;
+ }
+ if (g_strcmp0 (g_dbus_message_get_interface (message), "org.freedesktop.DBus.Local") == 0)
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("SIGNAL message: The INTERFACE header field is using the reserved value org.freedesktop.DBus.Local"));
+ goto out;
+ }
+ break;
+
+ default:
+ /* hitherto unknown type - nothing to check */
+ break;
+ }
+
+ ret = TRUE;
+
+ out:
+ g_assert (ret || (error == NULL || *error != NULL));
+ return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
ensure_input_padding (GMemoryInputStream *mis,
gsize padding_size,
GError **error)
gsize remaining;
guchar nul;
GError *local_error;
+ const gchar *end_valid;
s = g_string_new (NULL);
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Wanted to read %lu bytes but got EOF"),
- to_read);
+ (gulong)to_read);
goto fail;
}
g_propagate_error (error, local_error);
goto fail;
}
+ if (!g_utf8_validate (s->str, -1, &end_valid))
+ {
+ gint offset;
+ gchar *valid_str;
+ offset = (gint) (end_valid - s->str);
+ valid_str = g_strndup (s->str, offset);
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ _("Expected valid UTF-8 string but found invalid bytes at byte offset %d (length of string is %d). "
+ "The valid UTF-8 string up until that point was `%s'"),
+ offset,
+ (gint) s->len,
+ valid_str);
+ g_free (valid_str);
+ goto fail;
+ }
if (nul != '\0')
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
- _("Expected NUL byte after the string `%s' but found `%c' (%d)"),
- s->str, nul, nul);
+ _("Expected NUL byte after the string `%s' but found byte %d"),
+ s->str, nul);
goto fail;
}
v = g_data_input_stream_read_uint64 (dis, NULL, &local_error);
if (local_error != NULL)
goto fail;
- /* TODO: hmm */
+ G_STATIC_ASSERT (sizeof (gdouble) == sizeof (guint64));
encoded = (gdouble *) &v;
ret = g_variant_new_double (*encoded);
}
g_free (v);
}
}
+ else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
+ {
+ if (!ensure_input_padding (mis, 4, &local_error))
+ goto fail;
+ if (!just_align)
+ {
+ gint32 v;
+ v = g_data_input_stream_read_int32 (dis, NULL, &local_error);
+ if (local_error != NULL)
+ goto fail;
+ ret = g_variant_new_handle (v);
+ }
+ }
else if (g_variant_type_is_array (type))
{
guint32 array_len;
g_set_error (&local_error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
- _("Encountered array of length %u bytes. Maximum length is 2<<26 bytes."),
+ _("Encountered array of length %u bytes. Maximum length is 2<<26 bytes (64 MiB)."),
array_len);
goto fail;
}
g_set_error (&local_error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
- _("Error deserializing GVariant with type-string `%s' from the D-Bus wire format"),
+ _("Error deserializing GVariant with type string `%s' from the D-Bus wire format"),
s);
g_free (s);
goto fail;
* @capabilities: A #GDBusCapabilityFlags describing what protocol features are supported.
* @error: Return location for error or %NULL.
*
- * Creates a new #GDBusMessage from the data stored at @blob.
+ * Creates a new #GDBusMessage from the data stored at @blob. The byte
+ * order that the message was in can be retrieved using
+ * g_dbus_message_get_byte_order().
*
* Returns: A new #GDBusMessage or %NULL if @error is set. Free with
* g_object_unref().
{
case 'l':
byte_order = G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
+ message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN;
break;
case 'B':
byte_order = G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN;
+ message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN;
break;
default:
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
- _("Invalid endianness value. Expected 'l' or 'B' but found '%c' (%d)"),
- endianness, endianness);
+ _("Invalid endianness value. Expected 0x6c ('l') or 0x42 ('B') but found value 0x%02x"),
+ endianness);
goto out;
}
g_data_input_stream_set_byte_order (dis, byte_order);
}
}
+ if (!validate_headers (message, error))
+ {
+ g_prefix_error (error, _("Cannot deserialize message: "));
+ goto out;
+ }
ret = TRUE;
{
guint64 *encoded;
gdouble v = g_variant_get_double (value);
- /* TODO: hmm */
+ G_STATIC_ASSERT (sizeof (gdouble) == sizeof (guint64));
encoded = (guint64 *) &v;
g_data_output_stream_put_uint64 (dos, *encoded, NULL, NULL);
}
if (value != NULL)
{
gsize len;
- const gchar *v = g_variant_get_string (value, &len);
+ const gchar *v;
+ const gchar *end;
+ v = g_variant_get_string (value, &len);
+ g_assert (g_utf8_validate (v, -1, &end) && (end == v + len));
g_data_output_stream_put_uint32 (dos, len, NULL, NULL);
g_data_output_stream_put_string (dos, v, NULL, NULL);
g_data_output_stream_put_byte (dos, '\0', NULL, NULL);
padding_added = ensure_output_padding (mos, dos, 4);
if (value != NULL)
{
- /* TODO: validate object path */
gsize len;
const gchar *v = g_variant_get_string (value, &len);
+ g_assert (g_variant_is_object_path (v));
g_data_output_stream_put_uint32 (dos, len, NULL, NULL);
g_data_output_stream_put_string (dos, v, NULL, NULL);
g_data_output_stream_put_byte (dos, '\0', NULL, NULL);
{
if (value != NULL)
{
- /* TODO: validate signature (including max len being 255) */
gsize len;
const gchar *v = g_variant_get_string (value, &len);
+ g_assert (g_variant_is_signature (v));
g_data_output_stream_put_byte (dos, len, NULL, NULL);
g_data_output_stream_put_string (dos, v, NULL, NULL);
g_data_output_stream_put_byte (dos, '\0', NULL, NULL);
}
}
+ else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
+ {
+ padding_added = ensure_output_padding (mos, dos, 4);
+ if (value != NULL)
+ {
+ gint32 v = g_variant_get_handle (value);
+ g_data_output_stream_put_int32 (dos, v, NULL, NULL);
+ }
+ }
else if (g_variant_type_is_array (type))
{
GVariant *item;
const gchar *signature;
child = g_variant_get_child_value (value, 0);
signature = g_variant_get_type_string (child);
- /* TODO: validate signature (including max len being 255) */
g_data_output_stream_put_byte (dos, strlen (signature), NULL, NULL);
g_data_output_stream_put_string (dos, signature, NULL, NULL);
g_data_output_stream_put_byte (dos, '\0', NULL, NULL);
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
- _("Error serializing GVariant with type-string `%s' to the D-Bus wire format"),
+ _("Error serializing GVariant with type string `%s' to the D-Bus wire format"),
g_variant_get_type_string (value));
goto fail;
}
* @capabilities: A #GDBusCapabilityFlags describing what protocol features are supported.
* @error: Return location for error.
*
- * Serializes @message to a blob.
+ * Serializes @message to a blob. The byte order returned by
+ * g_dbus_message_get_byte_order() will be used.
*
* Returns: A pointer to a valid binary D-Bus message of @out_size bytes
* generated by @message or %NULL if @error is set. Free with g_free().
mos = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (NULL, 0, g_realloc, g_free));
dos = g_data_output_stream_new (G_OUTPUT_STREAM (mos));
- /* Any D-Bus implementation is supposed to handle both Big and
- * Little Endian encodings and the Endianness is part of the D-Bus
- * message - we prefer to use Big Endian (since it's Network Byte
- * Order and just easier to read for humans) but if the machine is
- * Little Endian we use that for performance reasons.
- */
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- byte_order = G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
-#else
- /* this could also be G_PDP_ENDIAN */
- byte_order = G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN;
-#endif
+ byte_order = G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN;
+ switch (message->byte_order)
+ {
+ case G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN:
+ byte_order = G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN;
+ break;
+ case G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN:
+ byte_order = G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
+ break;
+ }
g_data_output_stream_set_byte_order (dos, byte_order);
/* Core header */
- g_data_output_stream_put_byte (dos, byte_order == G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN ? 'l' : 'B', NULL, NULL);
+ g_data_output_stream_put_byte (dos, (guchar) message->byte_order, NULL, NULL);
g_data_output_stream_put_byte (dos, message->type, NULL, NULL);
g_data_output_stream_put_byte (dos, message->flags, NULL, NULL);
g_data_output_stream_put_byte (dos, 1, NULL, NULL); /* major protocol version */
num_fds_in_message = g_unix_fd_list_get_length (message->fd_list);
#endif
num_fds_according_to_header = g_dbus_message_get_num_unix_fds (message);
- /* TODO: check we have all the right header fields and that they are the correct value etc etc */
if (num_fds_in_message != num_fds_according_to_header)
{
g_set_error (error,
goto out;
}
+ if (!validate_headers (message, error))
+ {
+ g_prefix_error (error, _("Cannot serialize message: "));
+ goto out;
+ }
+
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{yv}"));
g_hash_table_iter_init (&hash_iter, message->headers);
while (g_hash_table_iter_next (&hash_iter, &key, (gpointer) &header_value))
g_data_output_stream_put_uint32 (dos, body_size, NULL, NULL);
+ if (!g_output_stream_close (G_OUTPUT_STREAM (dos), NULL, error))
+ goto out;
+
*out_size = size;
- ret = g_memdup (g_memory_output_stream_get_data (mos), size);
+ ret = g_memory_output_stream_steal_data (mos);
out:
g_object_unref (dos);
return g_string_free (str, FALSE);
}
+
+/**
+ * g_dbus_message_get_locked:
+ * @message: A #GDBusMessage.
+ *
+ * Checks whether @message is locked. To monitor changes to this
+ * value, conncet to the #GObject::notify signal to listen for changes
+ * on the #GDBusMessage:locked property.
+ *
+ * Returns: %TRUE if @message is locked, %FALSE otherwise.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_dbus_message_get_locked (GDBusMessage *message)
+{
+ g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), FALSE);
+ return message->locked;
+}
+
+/**
+ * g_dbus_message_lock:
+ * @message: A #GDBusMessage.
+ *
+ * If @message is locked, does nothing. Otherwise locks the message.
+ *
+ * Since: 2.26
+ */
+void
+g_dbus_message_lock (GDBusMessage *message)
+{
+ g_return_if_fail (G_IS_DBUS_MESSAGE (message));
+
+ if (message->locked)
+ goto out;
+
+ message->locked = TRUE;
+ g_object_notify (G_OBJECT (message), "locked");
+
+ out:
+ ;
+}
+
+/**
+ * g_dbus_message_copy:
+ * @message: A #GDBusMessage.
+ * @error: Return location for error or %NULL.
+ *
+ * Copies @message. The copy is a deep copy and the returned
+ * #GDBusMessage is completely identical except that it is guaranteed
+ * to not be locked.
+ *
+ * This operation can fail if e.g. @message contains file descriptors
+ * and the per-process or system-wide open files limit is reached.
+ *
+ * Returns: (transfer full): A new #GDBusMessage or %NULL if @error is set. Free with
+ * g_object_unref().
+ *
+ * Since: 2.26
+ */
+GDBusMessage *
+g_dbus_message_copy (GDBusMessage *message,
+ GError **error)
+{
+ GDBusMessage *ret;
+ GHashTableIter iter;
+ gpointer header_key;
+ GVariant *header_value;
+
+ g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = g_dbus_message_new ();
+ ret->type = message->type;
+ ret->flags = message->flags;
+ ret->byte_order = message->byte_order;
+ ret->major_protocol_version = message->major_protocol_version;
+ ret->serial = message->serial;
+
+#ifdef G_OS_UNIX
+ if (message->fd_list != NULL)
+ {
+ gint n;
+ gint num_fds;
+ const gint *fds;
+
+ ret->fd_list = g_unix_fd_list_new ();
+ fds = g_unix_fd_list_peek_fds (message->fd_list, &num_fds);
+ for (n = 0; n < num_fds; n++)
+ {
+ if (g_unix_fd_list_append (ret->fd_list,
+ fds[n],
+ error) == -1)
+ {
+ g_object_unref (ret);
+ ret = NULL;
+ goto out;
+ }
+ }
+ }
+#endif
+
+ /* see https://bugzilla.gnome.org/show_bug.cgi?id=624546#c8 for why it's fine
+ * to just ref (as opposed to deep-copying) the GVariant instances
+ */
+ ret->body = message->body != NULL ? g_variant_ref (message->body) : NULL;
+ g_hash_table_iter_init (&iter, message->headers);
+ while (g_hash_table_iter_next (&iter, &header_key, (gpointer) &header_value))
+ g_hash_table_insert (ret->headers, header_key, g_variant_ref (header_value));
+
+ out:
+ return ret;
+}
+