diff mcabber/mcabber/xmpp_s10n.c @ 1685:1342df44c814

Improved events interface * User can pass additional arguments to event handler * MUC invitation reject now can be supplied a reason
author Myhailo Danylenko <isbear@ukrpost.net>
date Tue, 02 Feb 2010 22:44:18 +0100
parents 41c26b7d2890
children e6d355e50d7a
line wrap: on
line diff
--- a/mcabber/mcabber/xmpp_s10n.c	Tue Jan 19 19:16:38 2010 +0200
+++ b/mcabber/mcabber/xmpp_s10n.c	Tue Feb 02 22:44:18 2010 +0100
@@ -37,36 +37,32 @@
   lm_message_unref(x);
 }
 
-int evscallback_subscription(eviqs *evp, guint evcontext)
+gboolean evscallback_subscription(guint evcontext, const char *arg, gpointer userdata)
 {
-  char *barejid;
+  char *barejid = userdata;
   char *buf;
 
+  // Sanity check
+  if (G_UNLIKELY(!barejid)) {
+    // Shouldn't happen, data should be set to the barejid.
+    scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
+    return FALSE;
+  }
+
   if (evcontext == EVS_CONTEXT_TIMEOUT) {
-    scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.",
-                 evp->id);
-    return 0;
+    scr_LogPrint(LPRINT_LOGNORM, "Subscription event for %s timed out, cancelled.",
+                 barejid);
+    return FALSE;
   }
   if (evcontext == EVS_CONTEXT_CANCEL) {
-    scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id);
-    return 0;
+    scr_LogPrint(LPRINT_LOGNORM, "Subscription event for %s cancelled.", barejid);
+    return FALSE;
   }
-  if (!(evcontext & EVS_CONTEXT_USER))
-    return 0;
-
-  // Sanity check
-  if (!evp->data) {
-    // Shouldn't happen, data should be set to the barejid.
-    scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
-    return 0;
-  }
+  if (!(evcontext == EVS_CONTEXT_REJECT || evcontext == EVS_CONTEXT_ACCEPT))
+    return FALSE;
 
   // Ok, let's work now.
-  // evcontext: 0, 1 == reject, accept
-
-  barejid = evp->data;
-
-  if (evcontext & ~EVS_CONTEXT_USER) {
+  if (evcontext == EVS_CONTEXT_ACCEPT) {
     // Accept subscription request
     xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_SUBSCRIBED);
     buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
@@ -84,7 +80,7 @@
   scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0);
   scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
   g_free(buf);
-  return 0;
+  return FALSE;
 }
 
 /* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */