[telepathy-mission-control/master] McdDispatcher: rewrite logic for whether channels bypass approval

Simon McVittie simon.mcvittie at collabora.co.uk
Thu May 7 03:39:14 PDT 2009


It doesn't make sense to check whether each individual channel can bypass
approval - what we want is to see whether the whole batch bypasses
approval. Also, instead of calling get_default_handler() we can just
iterate through the saved list of possible handlers.
---
 src/mcd-dispatcher.c |   34 +++++++++++++++++++++++++---------
 1 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 01cb071..1b3b14b 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1182,18 +1182,34 @@ mcd_dispatcher_run_approvers (McdDispatcherContext *context)
 static gboolean
 handlers_can_bypass_approval (McdDispatcherContext *context)
 {
-    McdClient *handler;
-    GList *cl;
+    McdDispatcher *self = context->dispatcher;
+    gchar **iter;
+
+    g_assert (context->possible_handlers != NULL);
 
-    for (cl = context->channels; cl != NULL; cl = cl->next)
+    for (iter = context->possible_handlers; *iter != NULL; iter++)
     {
-        McdChannel *channel = MCD_CHANNEL (cl->data);
+        McdClient *handler = g_hash_table_lookup (self->priv->clients,
+                                                  *iter);
 
-        handler = get_default_handler (context->dispatcher, channel);
-        if (!handler || !handler->bypass_approver)
-            return FALSE;
+        /* If the best handler that still exists bypasses approval, then
+         * we're going to bypass approval.
+         *
+         * Also, because handlers are sorted with the best ones first, and
+         * handlers with BypassApproval are "better", we can be sure that if
+         * we've found a handler that still exists and does not bypass
+         * approval, no handler bypasses approval. */
+        if (handler != NULL)
+        {
+            DEBUG ("%s has BypassApproval=%c", *iter,
+                   handler->bypass_approver ? 'T' : 'F');
+            return handler->bypass_approver;
+        }
     }
-    return TRUE;
+
+    /* If no handler still exists, we don't bypass approval, although if that
+     * happens we're basically doomed anyway. */
+    return FALSE;
 }
 
 /* Happens at the end of successful filter chain execution (empty chain
-- 
1.5.6.5




More information about the telepathy-commits mailing list