Debian Codegraph @

src/fe-common/fe-stanzas.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Colin DIDIER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include <string.h>
19
20 #include "module.h"
21 #include "levels.h"
22 #include "module-formats.h"
23 #include "printtext.h"
24 #include "settings.h"
25 #include "signals.h"
26 #include "window-items.h"
27
28 #include "xmpp-servers.h"
29
30 static WINDOW_REC *
31 get_console(XMPP_SERVER_REC *server)
32 {
33 WINDOW_REC *window;
34 char *name;
35
36 g_return_val_if_fail(IS_XMPP_SERVER(server), NULL);
37 name = g_strconcat("(raw:", (server->connrec->chatnet == NULL ||
38 *server->connrec->chatnet == '\0') ? server->jid :
39 server->connrec->chatnet, ")", (void *)NULL);
40 if ((window = window_find_name(name)) == NULL) {
41 window = window_create(NULL, TRUE);
42 window_set_name(window, name);
43 window_change_server(window, server);
44 }
45 g_free(name);
46 return window;
47 }
48
49 static void
50 sig_xml_in(XMPP_SERVER_REC *server, const char *msg)
51 {
52 WINDOW_REC *window;
53 char *len;
54
55 if (!settings_get_bool("xmpp_xml_console"))
56 return;
57 g_return_if_fail(IS_XMPP_SERVER(server));
58 g_return_if_fail(msg != NULL);
59 if ((window = get_console(server)) != NULL) {
60 len = g_strdup_printf("%lu", (unsigned long)strlen(msg));
61 printformat_module_window(MODULE_NAME, window, MSGLEVEL_CRAP,
62 XMPPTXT_RAW_IN_HEADER, len);
63 g_free(len);
64 printformat_module_window(MODULE_NAME, window, MSGLEVEL_CRAP,
65 XMPPTXT_RAW_MESSAGE, msg);
66 }
67 }
68
69 static void
70 sig_xml_out(XMPP_SERVER_REC *server, const char *msg)
71 {
72 WINDOW_REC *window;
73 char *len;
74
75 if (!settings_get_bool("xmpp_xml_console"))
76 return;
77 g_return_if_fail(IS_XMPP_SERVER(server));
78 g_return_if_fail(msg != NULL);
79 if ((window = get_console(server)) != NULL) {
80 len = g_strdup_printf("%lu", (unsigned long)strlen(msg));
81 printformat_module_window(MODULE_NAME, window, MSGLEVEL_CRAP,
82 XMPPTXT_RAW_OUT_HEADER, len);
83 g_free(len);
84 printformat_module_window(MODULE_NAME, window, MSGLEVEL_CRAP,
85 XMPPTXT_RAW_MESSAGE, msg);
86 }
87 }
88
89 void
90 fe_stanzas_init(void)
91 {
92 signal_add("xmpp xml in", (SIGNAL_FUNC)sig_xml_in);
93 signal_add("xmpp xml out", (SIGNAL_FUNC)sig_xml_out);
94
95 settings_add_bool("xmpp_lookandfeel", "xmpp_xml_console", FALSE);
96 }
97
98 void
99 fe_stanzas_deinit(void)
100 {
101 signal_remove("xmpp xml in", (SIGNAL_FUNC)sig_xml_in);
102 signal_remove("xmpp xml out", (SIGNAL_FUNC)sig_xml_out);
103 }