[glib/gdbus-merge] GDBus: Make message serialization routines take capabilities param



commit 33952347ff9bc2875e7e1a2709566b38fc391bda
Author: David Zeuthen <davidz redhat com>
Date:   Thu May 13 14:01:41 2010 -0400

    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).

 gio/gdbusconnection.c           |    1 +
 gio/gdbusmessage.c              |   26 +++++++++++++++++---------
 gio/gdbusmessage.h              |    2 ++
 gio/gdbusprivate.c              |    1 +
 gio/tests/gdbus-serialization.c |    6 +++++-
 5 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index 6967ac0..80ae8b6 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -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;
diff --git a/gio/gdbusmessage.c b/gio/gdbusmessage.c
index d2f0245..9f871de 100644
--- a/gio/gdbusmessage.c
+++ b/gio/gdbusmessage.c
@@ -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);
diff --git a/gio/gdbusmessage.h b/gio/gdbusmessage.h
index c30abcf..a01fb8b 100644
--- a/gio/gdbusmessage.h
+++ b/gio/gdbusmessage.h
@@ -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,
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index 4cdc480..da06fe5 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -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)
             {
diff --git a/gio/tests/gdbus-serialization.c b/gio/tests/gdbus-serialization.c
index 9a96f50..90e380f 100644
--- a/gio/tests/gdbus-serialization.c
+++ b/gio/tests/gdbus-serialization.c
@@ -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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]