annotate mcabber/mcabber/xmpp_s10n.c @ 2347:db8de1b464d3 default tip

Reordered some lines of code for clarity
author franky
date Sat, 18 May 2019 20:41:52 +0200
parents f5402d705f67
children
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
2268
f5402d705f67 Fix FSF addresses in all files
Mikael Berthe <mikael@lilotux.net>
parents: 2210
diff changeset
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
19 */
1363
32077249de77 Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
20
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
21 #include "xmpp_helper.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
22 #include "events.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
23 #include "screen.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
24 #include "hbuf.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
25 #include "settings.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
26
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
27 // xmpp_send_s10n(jid, subtype)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
28 // Send a s10n message with the passed subtype
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
29 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
30 {
2210
ea90906cb691 Add a few more checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
31 if (G_UNLIKELY(!bjid || !*bjid)) {
ea90906cb691 Add a few more checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
32 scr_LogPrint(LPRINT_LOGNORM, "Empty JID.");
ea90906cb691 Add a few more checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
33 return;
ea90906cb691 Add a few more checks
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
34 }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
35 LmMessage *x = lm_message_new_with_sub_type(bjid,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
36 LM_MESSAGE_TYPE_PRESENCE,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
37 type);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
38 lm_connection_send(lconnection, x, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
39 lm_message_unref(x);
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
40 }
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
41
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
42 gboolean evscallback_subscription(guint evcontext, const char *arg, gpointer userdata)
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
43 {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
44 char *barejid = userdata;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
45 char *buf;
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
46
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
47 // Sanity check
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
48 if (G_UNLIKELY(!barejid)) {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
49 // Shouldn't happen, data should be set to the barejid.
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
50 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
51 return FALSE;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
52 }
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
53
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
54 if (evcontext == EVS_CONTEXT_TIMEOUT) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
55 scr_LogPrint(LPRINT_LOGNORM, "Subscription event for %s timed out, cancelled.",
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
56 barejid);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
57 return FALSE;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
58 }
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
59 if (evcontext == EVS_CONTEXT_CANCEL) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
60 scr_LogPrint(LPRINT_LOGNORM, "Subscription event for %s cancelled.", barejid);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
61 return FALSE;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
62 }
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
63 if (!(evcontext == EVS_CONTEXT_REJECT || evcontext == EVS_CONTEXT_ACCEPT))
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
64 return FALSE;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
65
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
66 // Ok, let's work now.
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
67 if (evcontext == EVS_CONTEXT_ACCEPT) {
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
68 // Accept subscription request
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
69 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
70 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
71 barejid);
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
72 } else {
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
73 // Reject subscription request
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
74 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
75 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
76 if (settings_opt_get_int("delete_on_reject")) {
19c615fd071e New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
77 // 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
78 if (roster_getsubscription(barejid) == sub_none)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
79 xmpp_delbuddy(barejid);
823
19c615fd071e New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
80 }
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
81 }
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1282
diff changeset
82 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
83 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
84 g_free(buf);
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
85 return FALSE;
749
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
86 }
6c633adaae10 Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents: 745
diff changeset
87
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1685
diff changeset
88 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */