telepathy-glib: TpCapabilities: Verify fixed properties does not contain extra fields we don't understand

Xavier Claessens xclaesse at kemper.freedesktop.org
Tue Apr 17 03:57:57 PDT 2012


Module: telepathy-glib
Branch: master
Commit: bb1105761f7a42179a670485d3d910ba033e2ca9
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=bb1105761f7a42179a670485d3d910ba033e2ca9

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Mon Apr 16 16:15:12 2012 +0200

TpCapabilities: Verify fixed properties does not contain extra fields we don't understand

---

 telepathy-glib/capabilities.c |   83 ++++++++++++++++++++++++++---------------
 1 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c
index 2aafdd1..c071bdf 100644
--- a/telepathy-glib/capabilities.c
+++ b/telepathy-glib/capabilities.c
@@ -456,6 +456,7 @@ supports_call_full (TpCapabilities *self,
       const gchar *chan_type;
       TpHandleType handle_type;
       gboolean valid;
+      guint nb_fixed_props = 2;
 
       tp_value_array_unpack (arr, 2,
           &fixed_prop,
@@ -470,22 +471,39 @@ supports_call_full (TpCapabilities *self,
       if (!valid || handle_type != expected_handle_type)
         continue;
 
-      if (expected_initial_audio &&
-          !tp_asv_get_boolean (fixed_prop,
-              TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, NULL) &&
-          !tp_strv_contains (allowed_prop,
-              TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO))
-        continue;
+      if (expected_initial_audio)
+        {
+          /* We want audio, INITIAL_AUDIO must be in either fixed or allowed */
+          if (tp_asv_get_boolean (fixed_prop,
+                  TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, NULL))
+            {
+              nb_fixed_props++;
+            }
+          else if (!tp_strv_contains (allowed_prop,
+                  TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO))
+            {
+              continue;
+            }
+        }
 
-      if (expected_initial_video &&
-          !tp_asv_get_boolean (fixed_prop,
-              TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, NULL) &&
-          !tp_strv_contains (allowed_prop,
-              TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO))
-        continue;
+      if (expected_initial_video)
+        {
+          /* We want video, INITIAL_VIDEO must be in either fixed or allowed */
+          if (tp_asv_get_boolean (fixed_prop,
+                  TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, NULL))
+            {
+              nb_fixed_props++;
+            }
+          else if (!tp_strv_contains (allowed_prop,
+                  TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO))
+            {
+              continue;
+            }
+        }
 
       /* We found the right class */
-      return TRUE;
+      if (g_hash_table_size (fixed_prop) == nb_fixed_props)
+        return TRUE;
     }
 
   return FALSE;
@@ -577,35 +595,31 @@ tp_capabilities_supports_tubes_common (TpCapabilities *self,
       const gchar *chan_type;
       TpHandleType handle_type;
       gboolean valid;
-      const gchar *service;
+      guint nb_fixed_props = 2;
 
       fixed =  g_value_get_boxed (g_value_array_get_nth (arr, 0));
 
       chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
-
       if (tp_strdiff (chan_type, expected_channel_type))
         continue;
 
       handle_type = tp_asv_get_uint32 (fixed,
           TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, &valid);
-
-      if (!valid)
-        continue;
-
-      if (handle_type != expected_handle_type)
+      if (!valid || handle_type != expected_handle_type)
         continue;
 
-      if (expected_service == NULL || !self->priv->contact_specific)
-        /* No need to check the service */
-        return TRUE;
-
-      service = tp_asv_get_string (fixed, service_prop);
+      if (expected_service != NULL && self->priv->contact_specific)
+        {
+          const gchar *service;
 
-      if (tp_strdiff (service, expected_service))
-        continue;
+          nb_fixed_props++;
+          service = tp_asv_get_string (fixed, service_prop);
+          if (tp_strdiff (service, expected_service))
+            continue;
+        }
 
-      /* We found the right service */
-      return TRUE;
+      if (g_hash_table_size (fixed) == nb_fixed_props)
+        return TRUE;
     }
 
   return FALSE;
@@ -814,14 +828,23 @@ tp_capabilities_supports_room_list (TpCapabilities *self,
       GHashTable *fixed;
       const gchar *chan_type;
       const gchar **allowed_properties;
+      TpHandleType handle_type;
+      gboolean valid;
 
       tp_value_array_unpack (arr, 2, &fixed, &allowed_properties);
 
-      chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
+      if (g_hash_table_size (fixed) != 2)
+        continue;
 
+      chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
       if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_ROOM_LIST))
         continue;
 
+      handle_type = tp_asv_get_uint32 (fixed,
+          TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, &valid);
+      if (!valid || handle_type != TP_HANDLE_TYPE_NONE)
+        continue;
+
       result = TRUE;
 
       server = tp_strv_contains (allowed_properties,



More information about the telepathy-commits mailing list