Debian Codegraph @

debian/patches/singpolyma-0203-Implement-XEP-0280-Message-Carbons.patch

raw
1 commit ce998ece64ffacec59d23013e3fa176b1d333841
2 Author: Stephen Paul Weber <[email protected]>
3 Date: Wed Nov 18 13:25:59 2015 -0500
4 Bug-Github: https://github.com/cdidier/irssi-xmpp/pull/25
5
6 Implement XEP-0280: Message Carbons
7
8 --- /dev/null
9 +++ b/src/core/xep/carbons.c
10 @@ -0,0 +1,152 @@
11 +/*
12 + * Copyright (C) 2017 Stephen Paul Weber
13 + *
14 + * This program is free software; you can redistribute it and/or modify
15 + * it under the terms of the GNU General Public License version 2 as
16 + * published by the Free Software Foundation.
17 + *
18 + * This program is distributed in the hope that it will be useful,
19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 + * GNU General Public License for more details.
22 + *
23 + * You should have received a copy of the GNU General Public License along
24 + * with this program; if not, write to the Free Software Foundation, Inc.,
25 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 + */
27 +
28 +#include "module.h"
29 +#include "misc.h"
30 +#include "settings.h"
31 +#include "signals.h"
32 +
33 +#include "rosters-tools.h"
34 +#include "xmpp-servers.h"
35 +#include "disco.h"
36 +#include "tools.h"
37 +#include "muc.h"
38 +
39 +#define XMLNS_CARBONS "urn:xmpp:carbons:2"
40 +
41 +static void
42 +sig_server_features(XMPP_SERVER_REC *server)
43 +{
44 + if (disco_have_feature(server->server_features, XMLNS_CARBONS)) {
45 + LmMessage *lmsg;
46 + LmMessageNode *node;
47 +
48 + lmsg = lm_message_new_with_sub_type(
49 + NULL,
50 + LM_MESSAGE_TYPE_IQ,
51 + LM_MESSAGE_SUB_TYPE_SET);
52 + node = lm_message_node_add_child(lmsg->node, "enable", NULL);
53 + lm_message_node_set_attribute(node, XMLNS, XMLNS_CARBONS);
54 + signal_emit("xmpp send iq", 2, server, lmsg);
55 + lm_message_unref(lmsg);
56 + }
57 +}
58 +
59 +static void
60 +sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
61 + const char *id, const char *from, const char *to)
62 +{
63 + LmMessageNode *node = NULL;
64 + LmMessageNode *forwarded = NULL;
65 + LmMessageNode *message = NULL;
66 + char *ffrom, *fto;
67 +
68 + node = lm_find_node(lmsg->node, "received", "xmlns", XMLNS_CARBONS);
69 + if (node != NULL) {
70 + forwarded = lm_find_node(node, "forwarded", "xmlns", "urn:xmpp:forward:0");
71 + if (forwarded != NULL) {
72 + message = lm_find_node(forwarded, "message", "xmlns", "jabber:client");
73 + }
74 + if (message != NULL) {
75 + ffrom = xmpp_recode_in(lm_message_node_get_attribute(message, "from"));
76 + if (ffrom == NULL) {
77 + ffrom = g_strdup("");
78 + }
79 + fto = xmpp_recode_in(lm_message_node_get_attribute(message, "to"));
80 + if (fto == NULL) {
81 + fto = g_strdup("");
82 + }
83 +
84 + node = lmsg->node;
85 + lmsg->node = message;
86 + signal_emit("xmpp recv message", 6, server, lmsg, type, id, ffrom, fto);
87 + lmsg->node = node;
88 + goto done;
89 + }
90 + }
91 +
92 + node = lm_find_node(lmsg->node, "sent", "xmlns", XMLNS_CARBONS);
93 + if (node == NULL) {
94 + return; // Not for us
95 + }
96 +
97 + forwarded = lm_find_node(node, "forwarded", "xmlns", "urn:xmpp:forward:0");
98 + if (forwarded != NULL) {
99 + message = lm_find_node(forwarded, "message", "xmlns", "jabber:client");
100 + }
101 + if (message != NULL) {
102 + MUC_REC *channel;
103 + char *nick, *str;
104 + node = lm_message_node_get_child(message, "body");
105 + if (node == NULL || node->value == NULL || *node->value == '\0') {
106 + return;
107 + }
108 + str = xmpp_recode_in(node->value);
109 +
110 + ffrom = xmpp_recode_in(lm_message_node_get_attribute(message, "from"));
111 + if (ffrom == NULL) {
112 + ffrom = g_strdup("");
113 + }
114 + fto = xmpp_recode_in(lm_message_node_get_attribute(message, "to"));
115 + if (fto == NULL) {
116 + fto = g_strdup("");
117 + }
118 +
119 + nick = rosters_resolve_name(server, fto);
120 + if (nick != NULL) {
121 + g_free(fto);
122 + fto = nick;
123 + }
124 +
125 + if (type == LM_MESSAGE_SUB_TYPE_GROUPCHAT
126 + && (channel = get_muc(server, fto)) != NULL
127 + && (nick = muc_extract_nick(ffrom)) != NULL) {
128 + signal_emit("message xmpp carbons sent", 6, server,
129 + str, nick, channel->name,
130 + GINT_TO_POINTER(SEND_TARGET_CHANNEL));
131 + g_free(nick);
132 + } else if ((type == LM_MESSAGE_SUB_TYPE_NOT_SET
133 + || type == LM_MESSAGE_SUB_TYPE_HEADLINE
134 + || type == LM_MESSAGE_SUB_TYPE_NORMAL
135 + || type == LM_MESSAGE_SUB_TYPE_CHAT)) {
136 + signal_emit("message xmpp carbons sent", 6, server,
137 + str, ffrom, fto,
138 + GINT_TO_POINTER(SEND_TARGET_NICK));
139 + }
140 +
141 + g_free(str);
142 + }
143 +
144 +done:
145 + g_free(fto);
146 + g_free(ffrom);
147 + signal_stop();
148 +}
149 +
150 +void
151 +carbons_init(void)
152 +{
153 + signal_add("xmpp server features", sig_server_features);
154 + signal_add_first("xmpp recv message", sig_recv_message);
155 +}
156 +
157 +void
158 +carbons_deinit(void)
159 +{
160 + signal_remove("xmpp server features", sig_server_features);
161 + signal_remove("xmpp recv message", sig_recv_message);
162 +}
163 --- /dev/null
164 +++ b/src/core/xep/carbons.h
165 @@ -0,0 +1,26 @@
166 +/*
167 + * Copyright (C) 2017 Stephen Paul Weber
168 + *
169 + * This program is free software; you can redistribute it and/or modify
170 + * it under the terms of the GNU General Public License version 2 as
171 + * published by the Free Software Foundation.
172 + *
173 + * This program is distributed in the hope that it will be useful,
174 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
175 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
176 + * GNU General Public License for more details.
177 + *
178 + * You should have received a copy of the GNU General Public License along
179 + * with this program; if not, write to the Free Software Foundation, Inc.,
180 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
181 + */
182 +
183 +#ifndef __CARBONS_H
184 +#define __CARBONS_H
185 +
186 +__BEGIN_DECLS
187 +void carbons_init(void);
188 +void carbons_deinit(void);
189 +__END_DECLS
190 +
191 +#endif
192 --- a/src/core/xep/xep.c
193 +++ b/src/core/xep/xep.c
194 @@ -17,6 +17,7 @@
195
196 #include "module.h"
197
198 +#include "carbons.h"
199 #include "chatstates.h"
200 #include "composing.h"
201 #include "delay.h"
202 @@ -32,6 +33,7 @@
203 xep_init(void)
204 {
205 disco_init(); /* init sevice discovery first */
206 + carbons_init();
207 chatstates_init();
208 composing_init();
209 delay_init();
210 @@ -47,6 +49,7 @@
211 xep_deinit(void)
212 {
213 disco_deinit();
214 + carbons_deinit();
215 chatstates_deinit();
216 composing_deinit();
217 delay_deinit();
218 --- a/src/fe-common/Makefile
219 +++ b/src/fe-common/Makefile
220 @@ -9,6 +9,7 @@
221 module-formats.c \
222 xmpp-completion.c \
223 xmpp-formats.c \
224 + xep/fe-carbons.c \
225 xep/fe-composing.c \
226 xep/fe-delay.c \
227 xep/fe-muc.c \
228 --- /dev/null
229 +++ b/src/fe-common/xep/fe-carbons.c
230 @@ -0,0 +1,80 @@
231 +/*
232 + * Copyright (C) 2017 Stephen Paul Weber
233 + *
234 + * This program is free software; you can redistribute it and/or modify
235 + * it under the terms of the GNU General Public License version 2 as
236 + * published by the Free Software Foundation.
237 + *
238 + * This program is distributed in the hope that it will be useful,
239 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
240 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
241 + * GNU General Public License for more details.
242 + *
243 + * You should have received a copy of the GNU General Public License along
244 + * with this program; if not, write to the Free Software Foundation, Inc.,
245 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
246 + */
247 +
248 +#include "module.h"
249 +#include "levels.h"
250 +#include "module-formats.h"
251 +#include "printtext.h"
252 +#include "settings.h"
253 +#include "signals.h"
254 +#include "window-items.h"
255 +#include "fe-messages.h"
256 +#include "fe-queries.h"
257 +#include "fe-common/core/module-formats.h"
258 +#include "fe-common/core/fe-messages.h"
259 +#include "fe-common/irc/module-formats.h"
260 +
261 +#include "xmpp-servers.h"
262 +#include "rosters-tools.h"
263 +#include "xep/muc.h"
264 +
265 +static void
266 +sig_message_carbons_sent(SERVER_REC *server, const char *msg, const char *nick,
267 + const char *target, gpointer gpointer_type)
268 +{
269 + void *item;
270 + char *freemsg = NULL;
271 + int level, type;
272 +
273 + g_return_if_fail(server != NULL);
274 + g_return_if_fail(msg != NULL);
275 + g_return_if_fail(nick != NULL);
276 + g_return_if_fail(target != NULL);
277 +
278 + type = GPOINTER_TO_INT(gpointer_type);
279 + level = MSGLEVEL_NO_ACT | MSGLEVEL_NOHILIGHT
280 + | (type == SEND_TARGET_CHANNEL ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS);
281 + item = type == SEND_TARGET_CHANNEL ?
282 + (void *)get_muc((XMPP_SERVER_REC *)server, target) :
283 + query_find(server, target);
284 +
285 + if (settings_get_bool("emphasis"))
286 + msg = freemsg = expand_emphasis(item, msg);
287 +
288 + if (type == SEND_TARGET_CHANNEL) {
289 + char *nickmode = channel_get_nickmode(item, nick);
290 + printformat_module(CORE_MODULE_NAME, server, target,
291 + level, TXT_OWN_MSG_CHANNEL, nick, target, msg, nickmode);
292 + } else if(item) { // If no query, why do we want to see carbons?
293 + printformat_module(CORE_MODULE_NAME, server, target,
294 + level, TXT_OWN_MSG_PRIVATE_QUERY, target, msg, nick);
295 + }
296 +
297 + g_free_not_null(freemsg);
298 +}
299 +
300 +void
301 +fe_carbons_init(void)
302 +{
303 + signal_add("message xmpp carbons sent", sig_message_carbons_sent);
304 +}
305 +
306 +void
307 +fe_carbons_deinit(void)
308 +{
309 + signal_remove("message xmpp carbons sent", sig_message_carbons_sent);
310 +}
311 --- /dev/null
312 +++ b/src/fe-common/xep/fe-carbons.h
313 @@ -0,0 +1,9 @@
314 +#ifndef __FE_CARBONS_H
315 +#define __FE_CARBONS_H
316 +
317 +__BEGIN_DECLS
318 +void fe_carbons_init(void);
319 +void fe_carbons_deinit(void);
320 +__END_DECLS
321 +
322 +#endif
323 --- a/src/fe-common/xep/fe-xep.c
324 +++ b/src/fe-common/xep/fe-xep.c
325 @@ -17,6 +17,7 @@
326
327 #include "module.h"
328
329 +#include "fe-carbons.h"
330 #include "fe-composing.h"
331 #include "fe-delay.h"
332 #include "fe-muc.h"
333 @@ -28,6 +29,7 @@
334 void
335 fe_xep_init(void)
336 {
337 + fe_carbons_init();
338 fe_composing_init();
339 fe_delay_init();
340 fe_muc_init();
341 @@ -40,6 +42,7 @@
342 void
343 fe_xep_deinit(void)
344 {
345 + fe_carbons_deinit();
346 fe_composing_deinit();
347 fe_delay_deinit();
348 fe_muc_deinit();
349 --- a/src/core/Makefile
350 +++ b/src/core/Makefile
351 @@ -12,6 +12,7 @@
352 stanzas.c \
353 tools.c \
354 popenRWE.c \
355 + xep/carbons.c \
356 xep/chatstates.c \
357 xep/composing.c \
358 xep/datetime.c \