[Telepathy-commits] [telepathy-gabble/master] Requestotron: copy changes back from Salut before moving to tp-glib

Will Thompson will.thompson at collabora.co.uk
Tue Sep 23 03:13:40 PDT 2008


Confirms that the test suite still passes in light of slight changes to
the API.
---
 src/channel-manager.h       |    3 +-
 src/conn-requests.c         |  124 +++++++++++++++++++++++++++++-------------
 src/im-factory.c            |   10 +---
 src/media-factory.c         |   14 ++----
 src/muc-factory.c           |   11 ++--
 src/private-tubes-factory.c |   10 +---
 src/roomlist-manager.c      |    7 +--
 src/roster.c                |   18 ++-----
 8 files changed, 106 insertions(+), 91 deletions(-)

diff --git a/src/channel-manager.h b/src/channel-manager.h
index 4dfb091..6e7e31e 100644
--- a/src/channel-manager.h
+++ b/src/channel-manager.h
@@ -60,8 +60,7 @@ void gabble_channel_manager_foreach_channel (GabbleChannelManager *manager,
 typedef void (*GabbleChannelManagerChannelClassFunc) (
     GabbleChannelManager *manager,
     GHashTable *fixed_properties,
-    const gchar * const *required_properties,
-    const gchar * const *optional_properties,
+    const gchar * const *allowed_properties,
     gpointer user_data);
 
 typedef void (*GabbleChannelManagerForeachChannelClassFunc) (
diff --git a/src/conn-requests.c b/src/conn-requests.c
index d76db6d..50cb7ab 100644
--- a/src/conn-requests.c
+++ b/src/conn-requests.c
@@ -837,29 +837,12 @@ conn_requests_get_channel_details (GabbleConnection *self)
 static void
 get_requestables_foreach (GabbleChannelManager *manager,
                           GHashTable *fixed_properties,
-                          const gchar * const *required_properties,
-                          const gchar * const *optional_properties,
+                          const gchar * const *allowed_properties,
                           gpointer user_data)
 {
   GPtrArray *details = user_data;
-  GValueArray *requestable = g_value_array_new (3);
+  GValueArray *requestable = g_value_array_new (2);
   GValue *value;
-  GPtrArray *allowed;
-  const gchar * const *iter;
-
-  allowed = g_ptr_array_new ();
-
-  for (iter = required_properties;
-       iter != NULL && *iter != NULL;
-       iter++)
-    g_ptr_array_add (allowed, g_strdup (*iter));
-
-  for (iter = optional_properties;
-       iter != NULL && *iter != NULL;
-       iter++)
-    g_ptr_array_add (allowed, g_strdup (*iter));
-
-  g_ptr_array_add (allowed, NULL);
 
   g_value_array_append (requestable, NULL);
   value = g_value_array_get_nth (requestable, 0);
@@ -869,7 +852,7 @@ get_requestables_foreach (GabbleChannelManager *manager,
   g_value_array_append (requestable, NULL);
   value = g_value_array_get_nth (requestable, 1);
   g_value_init (value, G_TYPE_STRV);
-  g_value_take_boxed (value, g_ptr_array_free (allowed, FALSE));
+  g_value_set_boxed (value, allowed_properties);
 
   g_ptr_array_add (details, requestable);
 }
@@ -928,6 +911,8 @@ conn_requests_requestotron (GabbleConnection *self,
                             ChannelRequestMethod method,
                             DBusGMethodInvocation *context)
 {
+  TpBaseConnection *base_conn = (TpBaseConnection *) self;
+  TpHandleRepoIface *handles;
   guint i;
   ChannelRequest *request = NULL;
   GHashTable *altered_properties = NULL;
@@ -936,10 +921,11 @@ conn_requests_requestotron (GabbleConnection *self,
   gboolean suppress_handler;
   TpHandleType target_handle_type;
   TpHandle target_handle;
+  GValue *target_handle_value = NULL;
+  const gchar *target_id;
   gboolean valid;
 
-  TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED ((TpBaseConnection *) self,
-      context);
+  TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base_conn, context);
 
   type = tp_asv_get_string (requested_properties,
         TP_IFACE_CHANNEL ".ChannelType");
@@ -981,6 +967,9 @@ conn_requests_requestotron (GabbleConnection *self,
       goto out;
     }
 
+  target_id = tp_asv_get_string (requested_properties,
+      TP_IFACE_CHANNEL ".TargetID");
+
   /* Handle type 0 cannot have a handle */
   if (target_handle_type == TP_HANDLE_TYPE_NONE && target_handle != 0)
     {
@@ -991,21 +980,76 @@ conn_requests_requestotron (GabbleConnection *self,
       goto out;
     }
 
-  /* FIXME: when TargetID is officially supported, if it has
-   * target_handle_type == TP_HANDLE_TYPE_NONE and has a TargetID, raise
-   * an error */
+  /* Handle type 0 cannot have a target id */
+  if (target_handle_type == TP_HANDLE_TYPE_NONE && target_id != NULL)
+    {
+      GError e = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+          "When TargetHandleType is NONE, TargetID must be omitted" };
 
-  /* FIXME: when TargetID is officially supported, if it has both a TargetID
-   * and a TargetHandle, raise an error */
+      dbus_g_method_return_error (context, &e);
+      goto out;
+    }
 
   /* FIXME: when InitiatorHandle, InitiatorID and Requested are officially
    * supported, if the request has any of them, raise an error */
 
-  /* FIXME: when TargetID is officially supported, if it has TargetID but
-   * no TargetHandle, copy requested_properties to altered_properties,
-   * remove TargetID, add TargetHandle, and set
-   * requested_properties = altered_properties (shadowing the original).
-   * If handle normalization fails, raise an error */
+  if (target_handle_type != TP_HANDLE_TYPE_NONE)
+    {
+      GError *error = NULL;
+
+      if ((target_handle == 0 && target_id == NULL) ||
+          (target_handle != 0 && target_id != NULL))
+        {
+          GError e = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+            "Exactly one of TargetHandle and TargetID must be supplied" };
+
+          dbus_g_method_return_error (context, &e);
+          goto out;
+        }
+
+      handles = tp_base_connection_get_handles (base_conn, target_handle_type);
+
+      if (target_handle == 0)
+        {
+          /* Turn TargetID into TargetHandle */
+          target_handle = tp_handle_ensure (handles, target_id, NULL, &error);
+
+          if (target_handle == 0)
+            {
+              dbus_g_method_return_error (context, error);
+              g_error_free (error);
+              goto out;
+            }
+
+          altered_properties = g_hash_table_new_full (g_str_hash, g_str_equal,
+              NULL, NULL);
+          tp_g_hash_table_update (altered_properties, requested_properties,
+              NULL, NULL);
+
+          target_handle_value = tp_g_value_slice_new (G_TYPE_UINT);
+          g_value_set_uint (target_handle_value, target_handle);
+          g_hash_table_insert (altered_properties,
+              TP_IFACE_CHANNEL ".TargetHandle", target_handle_value);
+
+          g_hash_table_remove (altered_properties,
+              TP_IFACE_CHANNEL ".TargetID");
+
+          requested_properties = altered_properties;
+        }
+      else
+        {
+          /* Check the supplied TargetHandle is valid */
+          if (!tp_handle_is_valid (handles, target_handle, &error))
+            {
+              dbus_g_method_return_error (context, error);
+              g_error_free (error);
+              goto out;
+            }
+
+          tp_handle_ref (handles, target_handle);
+        }
+    }
+
 
   switch (method)
     {
@@ -1039,18 +1083,20 @@ conn_requests_requestotron (GabbleConnection *self,
     }
 
   /* Nobody accepted the request */
-    {
-      GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
-          "Not implemented" };
+  tp_dbus_g_method_return_not_implemented (context);
+
+  request->context = NULL;
+  g_ptr_array_remove (self->channel_requests, request);
+  channel_request_free (request);
 
-      dbus_g_method_return_error (context, &e);
-      g_ptr_array_remove (self->channel_requests, request);
-      channel_request_free (request);
-    }
 
 out:
+  if (target_handle != 0)
+    tp_handle_unref (handles, target_handle);
   if (altered_properties != NULL)
     g_hash_table_destroy (altered_properties);
+  if (target_handle_value != NULL)
+    tp_g_value_slice_free (target_handle_value);
 
   return;
 }
diff --git a/src/im-factory.c b/src/im-factory.c
index e9ac1c1..1a58b00 100644
--- a/src/im-factory.c
+++ b/src/im-factory.c
@@ -482,17 +482,12 @@ gabble_im_factory_foreach_channel (GabbleChannelManager *manager,
 }
 
 
-static const gchar * const im_channel_required_properties[] = {
+static const gchar * const im_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL ".TargetHandle",
     NULL
 };
 
 
-static const gchar * const im_channel_optional_properties[] = {
-    NULL
-};
-
-
 static void
 gabble_im_factory_foreach_channel_class (GabbleChannelManager *manager,
     GabbleChannelManagerChannelClassFunc func,
@@ -512,8 +507,7 @@ gabble_im_factory_foreach_channel_class (GabbleChannelManager *manager,
   g_hash_table_insert (table, TP_IFACE_CHANNEL ".TargetHandleType",
       value);
 
-  func (manager, table, im_channel_required_properties,
-      im_channel_optional_properties, user_data);
+  func (manager, table, im_channel_allowed_properties, user_data);
 
   g_hash_table_destroy (table);
 }
diff --git a/src/media-factory.c b/src/media-factory.c
index bf5bd07..9920a84 100644
--- a/src/media-factory.c
+++ b/src/media-factory.c
@@ -836,16 +836,12 @@ gabble_media_factory_foreach_channel (GabbleChannelManager *manager,
 }
 
 
-static const gchar * const no_properties[] = {
-    NULL
-};
-
-static const gchar * const named_channel_required_properties[] = {
+static const gchar * const named_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL ".TargetHandle",
     NULL
 };
 
-static const gchar * const anon_channel_optional_properties[] = {
+static const gchar * const anon_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL ".TargetHandle",   /* must be 0 if given */
     NULL
 };
@@ -870,12 +866,10 @@ gabble_media_factory_foreach_channel_class (GabbleChannelManager *manager,
       handle_type_value);
 
   g_value_set_uint (handle_type_value, TP_HANDLE_TYPE_NONE);
-  func (manager, table, no_properties,
-      anon_channel_optional_properties, user_data);
+  func (manager, table, anon_channel_allowed_properties, user_data);
 
   g_value_set_uint (handle_type_value, TP_HANDLE_TYPE_CONTACT);
-  func (manager, table, named_channel_required_properties,
-      no_properties, user_data);
+  func (manager, table, named_channel_allowed_properties, user_data);
 
   g_hash_table_destroy (table);
 }
diff --git a/src/muc-factory.c b/src/muc-factory.c
index 63e4404..00c62af 100644
--- a/src/muc-factory.c
+++ b/src/muc-factory.c
@@ -1230,15 +1230,14 @@ gabble_muc_factory_find_text_channel (GabbleMucFactory *self,
 }
 
 
-static const gchar * const muc_channel_required_properties[] = {
+static const gchar * const muc_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL ".TargetHandle",
     NULL
 };
 
-static const gchar * const * muc_tubes_channel_required_properties =
-    muc_channel_required_properties;
+static const gchar * const * muc_tubes_channel_allowed_properties =
+    muc_channel_allowed_properties;
 
-static const gchar * const no_properties[] = { NULL };
 
 
 static void
@@ -1261,11 +1260,11 @@ gabble_muc_factory_foreach_channel_class (GabbleChannelManager *manager,
       handle_type_value);
 
   g_value_set_static_string (channel_type_value, TP_IFACE_CHANNEL_TYPE_TEXT);
-  func (manager, table, muc_channel_required_properties, no_properties,
+  func (manager, table, muc_channel_allowed_properties,
       user_data);
 
   g_value_set_static_string (channel_type_value, TP_IFACE_CHANNEL_TYPE_TUBES);
-  func (manager, table, muc_tubes_channel_required_properties, no_properties,
+  func (manager, table, muc_tubes_channel_allowed_properties,
       user_data);
 
   g_hash_table_destroy (table);
diff --git a/src/private-tubes-factory.c b/src/private-tubes-factory.c
index 041c351..3de8f02 100644
--- a/src/private-tubes-factory.c
+++ b/src/private-tubes-factory.c
@@ -554,17 +554,12 @@ gabble_private_tubes_factory_iface_init (gpointer g_iface,
 }
 
 
-static const gchar * const tubes_channel_required_properties[] = {
+static const gchar * const tubes_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL ".TargetHandle",
     NULL
 };
 
 
-static const gchar * const tubes_channel_optional_properties[] = {
-    NULL
-};
-
-
 static void
 gabble_private_tubes_factory_foreach_channel_class (
     GabbleChannelManager *manager,
@@ -585,8 +580,7 @@ gabble_private_tubes_factory_foreach_channel_class (
   g_hash_table_insert (table, TP_IFACE_CHANNEL ".TargetHandleType",
       value);
 
-  func (manager, table, tubes_channel_required_properties,
-      tubes_channel_optional_properties, user_data);
+  func (manager, table, tubes_channel_allowed_properties, user_data);
 
   g_hash_table_destroy (table);
 }
diff --git a/src/roomlist-manager.c b/src/roomlist-manager.c
index 7012e5d..dfef5a8 100644
--- a/src/roomlist-manager.c
+++ b/src/roomlist-manager.c
@@ -254,9 +254,7 @@ gabble_roomlist_manager_foreach_channel (GabbleChannelManager *manager,
 }
 
 
-static const gchar * const no_properties[] = { NULL };
-
-static const gchar * const roomlist_channel_optional_properties[] = {
+static const gchar * const roomlist_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL_TYPE_ROOM_LIST ".Server",
     NULL
 };
@@ -279,8 +277,7 @@ gabble_roomlist_manager_foreach_channel_class (GabbleChannelManager *manager,
   g_value_set_uint (value, TP_HANDLE_TYPE_NONE);
   g_hash_table_insert (table, TP_IFACE_CHANNEL ".TargetHandleType", value);
 
-  func (manager, table, no_properties, roomlist_channel_optional_properties,
-      user_data);
+  func (manager, table, roomlist_channel_allowed_properties, user_data);
 
   g_hash_table_destroy (table);
 }
diff --git a/src/roster.c b/src/roster.c
index a54d1cb..d43fca2 100644
--- a/src/roster.c
+++ b/src/roster.c
@@ -2467,20 +2467,14 @@ gabble_roster_handle_remove_from_group (GabbleRoster *roster,
 }
 
 
-static const gchar * const list_channel_required_properties[] = {
+static const gchar * const list_channel_allowed_properties[] = {
     TP_IFACE_CHANNEL ".TargetHandle",
     NULL
 };
-static const gchar * const *group_channel_required_properties =
-    list_channel_required_properties;
+static const gchar * const *group_channel_allowed_properties =
+    list_channel_allowed_properties;
 
 
-static const gchar * const list_channel_optional_properties[] = {
-    NULL
-};
-static const gchar * const *group_channel_optional_properties =
-    list_channel_optional_properties;
-
 
 static void
 gabble_roster_foreach_channel_class (GabbleChannelManager *manager,
@@ -2501,8 +2495,7 @@ gabble_roster_foreach_channel_class (GabbleChannelManager *manager,
       handle_type_value);
 
   g_value_set_uint (handle_type_value, TP_HANDLE_TYPE_GROUP);
-  func (manager, table, group_channel_required_properties,
-      group_channel_optional_properties, user_data);
+  func (manager, table, group_channel_allowed_properties, user_data);
 
   /* FIXME: should these actually be in RequestableChannelClasses? You can't
    * usefully call CreateChannel on them, although EnsureChannel would be
@@ -2510,8 +2503,7 @@ gabble_roster_foreach_channel_class (GabbleChannelManager *manager,
   /* FIXME: since we have a finite set of possible values for TargetHandle,
    * should we enumerate them all as separate channel classes? */
   g_value_set_uint (handle_type_value, TP_HANDLE_TYPE_LIST);
-  func (manager, table, list_channel_required_properties,
-      list_channel_optional_properties, user_data);
+  func (manager, table, list_channel_allowed_properties, user_data);
 
   g_hash_table_destroy (table);
 }
-- 
1.5.6.5




More information about the Telepathy-commits mailing list