1 | /***************************************************************************\ |
---|
2 | * * |
---|
3 | * BitlBee - An IRC to IM gateway * |
---|
4 | * Jabber module - Handling of blocking * |
---|
5 | * * |
---|
6 | * Copyright 2021 / <> * |
---|
7 | * * |
---|
8 | * This program is free software; you can redistribute it and/or modify * |
---|
9 | * it under the terms of the GNU General Public License as published by * |
---|
10 | * the Free Software Foundation; either version 2 of the License, or * |
---|
11 | * (at your option) any later version. * |
---|
12 | * * |
---|
13 | * This program is distributed in the hope that it will be useful, * |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
---|
16 | * GNU General Public License for more details. * |
---|
17 | * * |
---|
18 | * You should have received a copy of the GNU General Public License along * |
---|
19 | * with this program; if not, write to the Free Software Foundation, Inc., * |
---|
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * |
---|
21 | * * |
---|
22 | \***************************************************************************/ |
---|
23 | |
---|
24 | #include "jabber.h" |
---|
25 | |
---|
26 | int jabber_block_feature(struct im_connection *ic) |
---|
27 | { |
---|
28 | struct jabber_data *jd = ic->proto_data; |
---|
29 | GSList *features = jd->features; |
---|
30 | int foundbk = FALSE; |
---|
31 | struct prpl *prpl = ic->acc->prpl; |
---|
32 | |
---|
33 | while (features) { |
---|
34 | if (!strcmp(features->data, XMLNS_BLOCK)) { |
---|
35 | foundbk = TRUE; |
---|
36 | } |
---|
37 | features = g_slist_next(features); |
---|
38 | } |
---|
39 | |
---|
40 | if (foundbk) { |
---|
41 | prpl->add_deny = jabber_buddy_block; |
---|
42 | prpl->rem_deny = jabber_buddy_unblock; |
---|
43 | prpl->add_permit = jabber_buddy_permit; |
---|
44 | prpl->rem_permit = jabber_buddy_unpermit; |
---|
45 | } else { |
---|
46 | prpl->add_deny = NULL; |
---|
47 | prpl->rem_deny = NULL; |
---|
48 | prpl->add_permit = NULL; |
---|
49 | prpl->rem_permit = NULL; |
---|
50 | } |
---|
51 | |
---|
52 | return foundbk; |
---|
53 | } |
---|
54 | |
---|
55 | void jabber_buddy_blockunblock(struct im_connection *ic, char *who, int block) |
---|
56 | { |
---|
57 | struct xt_node *node, *query; |
---|
58 | struct jabber_buddy *bud; |
---|
59 | char *s; |
---|
60 | |
---|
61 | if ((s = strchr(who, '=')) && jabber_chat_by_jid(ic, s + 1)) { |
---|
62 | bud = jabber_buddy_by_ext_jid(ic, who, 0); |
---|
63 | } else { |
---|
64 | bud = jabber_buddy_by_jid(ic, who, GET_BUDDY_BARE_OK); |
---|
65 | } |
---|
66 | |
---|
67 | node = xt_new_node("item", NULL, NULL); |
---|
68 | xt_add_attr(node, "jid", bud ? bud->full_jid : who); |
---|
69 | |
---|
70 | node = xt_new_node(block ? "block" : "unblock", NULL, node); |
---|
71 | xt_add_attr(node, "xmlns", XMLNS_BLOCK); |
---|
72 | |
---|
73 | query = jabber_make_packet("iq", "set", NULL, node); |
---|
74 | |
---|
75 | jabber_write_packet(ic, query); |
---|
76 | xt_free_node(query); |
---|
77 | } |
---|
78 | |
---|
79 | void jabber_buddy_block(struct im_connection *ic, char *who) |
---|
80 | { |
---|
81 | jabber_buddy_blockunblock(ic, who, TRUE); |
---|
82 | } |
---|
83 | |
---|
84 | void jabber_buddy_unblock(struct im_connection *ic, char *who) |
---|
85 | { |
---|
86 | jabber_buddy_blockunblock(ic, who, FALSE); |
---|
87 | } |
---|
88 | |
---|
89 | void jabber_buddy_permit(struct im_connection *ic, char *who) |
---|
90 | { |
---|
91 | } |
---|
92 | void jabber_buddy_unpermit(struct im_connection *ic, char *who) |
---|
93 | { |
---|
94 | } |
---|