comparison 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
comparison
equal deleted inserted replaced
1684:95df4ea512c8 1685:1342df44c814
35 type); 35 type);
36 lm_connection_send(lconnection, x, NULL); 36 lm_connection_send(lconnection, x, NULL);
37 lm_message_unref(x); 37 lm_message_unref(x);
38 } 38 }
39 39
40 int evscallback_subscription(eviqs *evp, guint evcontext) 40 gboolean evscallback_subscription(guint evcontext, const char *arg, gpointer userdata)
41 { 41 {
42 char *barejid; 42 char *barejid = userdata;
43 char *buf; 43 char *buf;
44 44
45 // Sanity check
46 if (G_UNLIKELY(!barejid)) {
47 // Shouldn't happen, data should be set to the barejid.
48 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
49 return FALSE;
50 }
51
45 if (evcontext == EVS_CONTEXT_TIMEOUT) { 52 if (evcontext == EVS_CONTEXT_TIMEOUT) {
46 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", 53 scr_LogPrint(LPRINT_LOGNORM, "Subscription event for %s timed out, cancelled.",
47 evp->id); 54 barejid);
48 return 0; 55 return FALSE;
49 } 56 }
50 if (evcontext == EVS_CONTEXT_CANCEL) { 57 if (evcontext == EVS_CONTEXT_CANCEL) {
51 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id); 58 scr_LogPrint(LPRINT_LOGNORM, "Subscription event for %s cancelled.", barejid);
52 return 0; 59 return FALSE;
53 } 60 }
54 if (!(evcontext & EVS_CONTEXT_USER)) 61 if (!(evcontext == EVS_CONTEXT_REJECT || evcontext == EVS_CONTEXT_ACCEPT))
55 return 0; 62 return FALSE;
56
57 // Sanity check
58 if (!evp->data) {
59 // Shouldn't happen, data should be set to the barejid.
60 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
61 return 0;
62 }
63 63
64 // Ok, let's work now. 64 // Ok, let's work now.
65 // evcontext: 0, 1 == reject, accept 65 if (evcontext == EVS_CONTEXT_ACCEPT) {
66
67 barejid = evp->data;
68
69 if (evcontext & ~EVS_CONTEXT_USER) {
70 // Accept subscription request 66 // Accept subscription request
71 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_SUBSCRIBED); 67 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_SUBSCRIBED);
72 buf = g_strdup_printf("<%s> is allowed to receive your presence updates", 68 buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
73 barejid); 69 barejid);
74 } else { 70 } else {
82 } 78 }
83 } 79 }
84 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0); 80 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0);
85 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); 81 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
86 g_free(buf); 82 g_free(buf);
87 return 0; 83 return FALSE;
88 } 84 }
89 85
90 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 86 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */