annotate mcabber/mcabber/xmpp_s10n.c @ 2210:ea90906cb691

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