comparison mcabber/src/xmpp_s10n.c @ 1598:a087125d8fc8

Replace libjabber with loudmouth
author franky
date Sun, 11 Oct 2009 15:38:32 +0200
parents mcabber/src/jabglue.c@1802b926e3fa
children dcd5d4c75199
comparison
equal deleted inserted replaced
1597:4f59a414217e 1598:a087125d8fc8
1 /* See xmpp.c file for copyright and license details. */
2
3 // xmpp_send_s10n(jid, subtype)
4 // Send a s10n message with the passed subtype
5 void xmpp_send_s10n(const char *bjid, LmMessageSubType type)
6 {
7 LmMessage *x = lm_message_new_with_sub_type(bjid,
8 LM_MESSAGE_TYPE_PRESENCE,
9 type);
10 lm_connection_send(lconnection, x, NULL);
11 lm_message_unref(x);
12 }
13
14 static int evscallback_subscription(eviqs *evp, guint evcontext)
15 {
16 char *barejid;
17 char *buf;
18
19 if (evcontext == EVS_CONTEXT_TIMEOUT) {
20 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.",
21 evp->id);
22 return 0;
23 }
24 if (evcontext == EVS_CONTEXT_CANCEL) {
25 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id);
26 return 0;
27 }
28 if (!(evcontext & EVS_CONTEXT_USER))
29 return 0;
30
31 // Sanity check
32 if (!evp->data) {
33 // Shouldn't happen, data should be set to the barejid.
34 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
35 return 0;
36 }
37
38 // Ok, let's work now.
39 // evcontext: 0, 1 == reject, accept
40
41 barejid = evp->data;
42
43 if (evcontext & ~EVS_CONTEXT_USER) {
44 // Accept subscription request
45 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_SUBSCRIBED);
46 buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
47 barejid);
48 } else {
49 // Reject subscription request
50 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED);
51 buf = g_strdup_printf("<%s> won't receive your presence updates", barejid);
52 if (settings_opt_get_int("delete_on_reject")) {
53 // Remove the buddy from the roster if there is no current subscription
54 if (roster_getsubscription(barejid) == sub_none)
55 xmpp_delbuddy(barejid);
56 }
57 }
58 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0);
59 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
60 g_free(buf);
61 return 0;
62 }
63