[telepathy-mission-control/master] test-plugin.c: add more special usernames whose channels are terminated with new API, old API, or new API with a reason

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Jun 30 10:36:36 PDT 2009


---
 test/twisted/test-plugin.c |   71 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/test/twisted/test-plugin.c b/test/twisted/test-plugin.c
index 5088647..ce64043 100644
--- a/test/twisted/test-plugin.c
+++ b/test/twisted/test-plugin.c
@@ -54,6 +54,73 @@ reject_rickrolling (McdDispatcherContext *ctx,
             channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT))
     {
         DEBUG ("rickrolling detected, closing channel %s", object_path);
+        mcd_dispatcher_context_destroy_all (ctx);
+        return;
+    }
+
+    mcd_dispatcher_context_proceed (ctx);
+}
+
+static void
+reject_with_reason (McdDispatcherContext *ctx,
+                    gpointer user_data)
+{
+    McdChannel *channel = mcd_dispatcher_context_get_channel (ctx);
+    const gchar *inviter = mcd_channel_get_inviter (channel);
+    GQuark channel_type = mcd_channel_get_channel_type_quark (channel);
+    const gchar *object_path = mcd_channel_get_object_path (channel);
+
+    DEBUG ("called");
+
+    /* we don't actually use the user_data here, so just assert that it's
+     * passed to the callback correctly */
+    g_assert (!tp_strdiff (user_data, "Can't touch this"));
+
+    /* the McdChannel had better have a TpChannel, otherwise something is badly
+     * wrong */
+    g_assert (channel_type != 0);
+    g_assert (object_path != NULL);
+
+    if (!tp_strdiff (inviter, "hammertime at example.com")
+        && (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA ||
+            channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT))
+    {
+        DEBUG ("MC Hammer detected, closing channel %s", object_path);
+        mcd_dispatcher_context_close_all (ctx,
+            TP_CHANNEL_GROUP_CHANGE_REASON_PERMISSION_DENIED,
+            "Can't touch this");
+        return;
+    }
+
+    mcd_dispatcher_context_proceed (ctx);
+}
+
+/* An older API for terminating unwanted channels */
+static void
+reject_mc_hammer (McdDispatcherContext *ctx,
+                  gpointer user_data)
+{
+    McdChannel *channel = mcd_dispatcher_context_get_channel (ctx);
+    const gchar *inviter = mcd_channel_get_inviter (channel);
+    GQuark channel_type = mcd_channel_get_channel_type_quark (channel);
+    const gchar *object_path = mcd_channel_get_object_path (channel);
+
+    DEBUG ("called");
+
+    /* we don't actually use the user_data here, so just assert that it's
+     * passed to the callback correctly */
+    g_assert (!tp_strdiff (user_data, "Stop! Hammer time"));
+
+    /* the McdChannel had better have a TpChannel, otherwise something is badly
+     * wrong */
+    g_assert (channel_type != 0);
+    g_assert (object_path != NULL);
+
+    if (!tp_strdiff (inviter, "mc.hammer at example.com")
+        && (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA ||
+            channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT))
+    {
+        DEBUG ("MC Hammer detected, closing channel %s", object_path);
         mcd_dispatcher_context_process (ctx, FALSE);
         return;
     }
@@ -64,6 +131,10 @@ reject_rickrolling (McdDispatcherContext *ctx,
 static const McdFilter my_filters[] = {
       { reject_rickrolling, MCD_FILTER_PRIORITY_CRITICAL,
       "Never gonna give you up" },
+      { reject_with_reason, MCD_FILTER_PRIORITY_CRITICAL,
+      "Can't touch this" },
+      { reject_mc_hammer, MCD_FILTER_PRIORITY_CRITICAL,
+      "Stop! Hammer time" },
       { NULL }
 };
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list