annotate mcabber/src/xmpp_s10n.c @ 1602:f4a2c6f767d1

Message Receipts support (XEP-0184)
author franky
date Wed, 24 Sep 2008 11:41:29 +0200
parents dcd5d4c75199
children 351427ef0b4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
1 /*
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
2 * xmpp_s10n.c -- Jabber presence subscription handling
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
3 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
4 * Copyright (C) 2008-2009 Frank Zschockelt <mcabber@freakysoft.de>
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
5 * Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net>
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
6 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
7 * This program is free software; you can redistribute it and/or modify
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
8 * it under the terms of the GNU General Public License as published by
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or (at
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
10 * your option) any later version.
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
11 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
12 * This program is distributed in the hope that it will be useful, but
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
15 * General Public License for more details.
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
16 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
17 * You should have received a copy of the GNU General Public License
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
18 * along with this program; if not, write to the Free Software
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
20 * USA
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
21 */
1363
32077249de77 Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
22
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
23 // xmpp_send_s10n(jid, subtype)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
24 // Send a s10n message with the passed subtype
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
25 void xmpp_send_s10n(const char *bjid, LmMessageSubType type)
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
26 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
27 LmMessage *x = lm_message_new_with_sub_type(bjid,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
28 LM_MESSAGE_TYPE_PRESENCE,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
29 type);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
30 lm_connection_send(lconnection, x, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
31 lm_message_unref(x);
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
32 }
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
33
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
34 static int evscallback_subscription(eviqs *evp, guint evcontext)
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
35 {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
36 char *barejid;
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
37 char *buf;
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
38
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
39 if (evcontext == EVS_CONTEXT_TIMEOUT) {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
40 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.",
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
41 evp->id);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
42 return 0;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
43 }
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
44 if (evcontext == EVS_CONTEXT_CANCEL) {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
45 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
46 return 0;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
47 }
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
48 if (!(evcontext & EVS_CONTEXT_USER))
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
49 return 0;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
50
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
51 // Sanity check
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
52 if (!evp->data) {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
53 // Shouldn't happen, data should be set to the barejid.
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
54 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
55 return 0;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
56 }
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
57
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
58 // Ok, let's work now.
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
59 // evcontext: 0, 1 == reject, accept
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
60
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
61 barejid = evp->data;
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
62
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
63 if (evcontext & ~EVS_CONTEXT_USER) {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
64 // Accept subscription request
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
65 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_SUBSCRIBED);
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
66 buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
67 barejid);
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
68 } else {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
69 // Reject subscription request
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
70 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED);
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
71 buf = g_strdup_printf("<%s> won't receive your presence updates", barejid);
823
19c615fd071e New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
72 if (settings_opt_get_int("delete_on_reject")) {
19c615fd071e New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
73 // Remove the buddy from the roster if there is no current subscription
19c615fd071e New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
74 if (roster_getsubscription(barejid) == sub_none)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
75 xmpp_delbuddy(barejid);
823
19c615fd071e New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
76 }
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
77 }
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1282
diff changeset
78 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0);
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
79 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
80 g_free(buf);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
81 return 0;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
82 }
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
83
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
84 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */