GDBus: Make message serialization routines take capabilities param

This is needed to e.g. allow encoding maybe types (once we add
G_DBUS_CAPABILITY_FLAGS_MAYBE_TYPES) if, and only if, that capability
has been negotiated with the peer (via authentication).
This commit is contained in:
David Zeuthen 2010-05-13 14:01:41 -04:00
parent 107b4d4bae
commit 33952347ff
5 changed files with 26 additions and 10 deletions

View File

@ -1009,6 +1009,7 @@ g_dbus_connection_send_message_unlocked (GDBusConnection *connection,
blob = g_dbus_message_to_blob (message,
&blob_size,
connection->priv->capabilities,
error);
if (blob == NULL)
goto out;

View File

@ -1070,9 +1070,9 @@ parse_value_from_blob (GMemoryInputStream *mis,
* Since: 2.26
*/
gssize
g_dbus_message_bytes_needed (guchar *blob,
gsize blob_len,
GError **error)
g_dbus_message_bytes_needed (guchar *blob,
gsize blob_len,
GError **error)
{
gssize ret;
@ -1122,6 +1122,7 @@ g_dbus_message_bytes_needed (guchar *blob,
* g_dbus_message_new_from_blob:
* @blob: A blob represent a binary D-Bus message.
* @blob_len: The length of @blob.
* @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.
@ -1132,9 +1133,10 @@ g_dbus_message_bytes_needed (guchar *blob,
* Since: 2.26
*/
GDBusMessage *
g_dbus_message_new_from_blob (guchar *blob,
gsize blob_len,
GError **error)
g_dbus_message_new_from_blob (guchar *blob,
gsize blob_len,
GDBusCapabilityFlags capabilities,
GError **error)
{
gboolean ret;
GMemoryInputStream *mis;
@ -1149,6 +1151,8 @@ g_dbus_message_new_from_blob (guchar *blob,
GVariantIter iter;
GVariant *signature;
/* TODO: check against @capabilities */
ret = FALSE;
g_return_val_if_fail (blob != NULL, NULL);
@ -1565,6 +1569,7 @@ append_body_to_blob (GVariant *value,
* g_dbus_message_to_blob:
* @message: A #GDBusMessage.
* @out_size: Return location for size of generated blob.
* @capabilities: A #GDBusCapabilityFlags describing what protocol features are supported.
* @error: Return location for error.
*
* Serializes @message to a blob.
@ -1575,9 +1580,10 @@ append_body_to_blob (GVariant *value,
* Since: 2.26
*/
guchar *
g_dbus_message_to_blob (GDBusMessage *message,
gsize *out_size,
GError **error)
g_dbus_message_to_blob (GDBusMessage *message,
gsize *out_size,
GDBusCapabilityFlags capabilities,
GError **error)
{
GMemoryOutputStream *mos;
GDataOutputStream *dos;
@ -1597,6 +1603,8 @@ g_dbus_message_to_blob (GDBusMessage *message,
gint num_fds_in_message;
gint num_fds_according_to_header;
/* TODO: check against @capabilities */
ret = NULL;
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);

View File

@ -158,6 +158,7 @@ const gchar *g_dbus_message_get_arg0 (GDBusMessage
GDBusMessage *g_dbus_message_new_from_blob (guchar *blob,
gsize blob_len,
GDBusCapabilityFlags capabilities,
GError **error);
gssize g_dbus_message_bytes_needed (guchar *blob,
@ -166,6 +167,7 @@ gssize g_dbus_message_bytes_needed (guchar
guchar *g_dbus_message_to_blob (GDBusMessage *message,
gsize *out_size,
GDBusCapabilityFlags capabilities,
GError **error);
gboolean g_dbus_message_to_gerror (GDBusMessage *message,

View File

@ -583,6 +583,7 @@ _g_dbus_worker_do_read_cb (GInputStream *input_stream,
message = g_dbus_message_new_from_blob ((guchar *) worker->read_buffer,
worker->read_buffer_cur_size,
worker->capabilities,
&error);
if (message == NULL)
{

View File

@ -522,6 +522,7 @@ check_serialization (GVariant *value,
error = NULL;
blob = g_dbus_message_to_blob (message,
&blob_size,
G_DBUS_CAPABILITY_FLAGS_NONE,
&error);
g_assert_no_error (error);
g_assert (blob != NULL);
@ -555,7 +556,10 @@ check_serialization (GVariant *value,
/* Then serialize back and check that the body is identical */
error = NULL;
recovered_message = g_dbus_message_new_from_blob (blob, blob_size, &error);
recovered_message = g_dbus_message_new_from_blob (blob,
blob_size,
G_DBUS_CAPABILITY_FLAGS_NONE,
&error);
g_assert_no_error (error);
g_assert (recovered_message != NULL);
g_assert (g_dbus_message_get_body (recovered_message) != NULL);