Debian Codegraph @

src/fe-common/fe-xmpp-queries.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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 "module.h"
19 #include "levels.h"
20 #include "module-formats.h"
21 #include "printtext.h"
22 #include "signals.h"
23 #include "window-items.h"
•24 #include "settings.h"
25
26 #include "xmpp-queries.h"
27 #include "rosters-tools.h"
28 #include "fe-xmpp-status.h"
•29 #include "tools.h"
30
31 int query_type;
32 int chatnet_type;
33
34 static void
35 sig_presence_changed(XMPP_SERVER_REC *server, const char *full_jid,
36 int show, const char *status)
37 {
38 XMPP_QUERY_REC *rec;
39 XMPP_ROSTER_USER_REC *user;
•40 const char *msg, *stripped_jid;
41 char *name;
42
•43 stripped_jid = (settings_get_bool("xmpp_strip_resource")) ?
44 xmpp_strip_resource(full_jid) : g_strdup(full_jid);
45
46 g_return_if_fail(server != NULL);
•47 g_return_if_fail(stripped_jid != NULL);
48 g_return_if_fail(0 <= show && show < XMPP_PRESENCE_SHOW_LEN);
•49 if ((rec = xmpp_query_find(server, stripped_jid)) == NULL)
50 return;
51 msg = fe_xmpp_presence_show[show];
•52 user = rosters_find_user(server->roster, stripped_jid, NULL, NULL);
53 name = user != NULL && user->name != NULL ?
54 format_get_text(MODULE_NAME, NULL, server, NULL,
•55 XMPPTXT_FORMAT_NAME, user->name, stripped_jid) :
56 format_get_text(MODULE_NAME, NULL, server, NULL,
•57 XMPPTXT_FORMAT_JID, stripped_jid);
58 if (status != NULL)
•59 printformat_module(MODULE_NAME, server, stripped_jid, MSGLEVEL_CRAP | MSGLEVEL_MODES,
60 XMPPTXT_PRESENCE_CHANGE_REASON, name, msg, status);
61 else
•62 printformat_module(MODULE_NAME, server, stripped_jid, MSGLEVEL_CRAP | MSGLEVEL_MODES,
63 XMPPTXT_PRESENCE_CHANGE, name, msg);
64 }
65
66 static void
67 sig_query_raise(XMPP_SERVER_REC *server, QUERY_REC *query)
68 {
69 WINDOW_REC *window;
70
71 g_return_if_fail(query != NULL);
72 window = window_item_window(query);
73 if (window != active_win)
74 window_set_active(window);
75 window_item_set_active(active_win, (WI_ITEM_REC *)query);
76 }
77
78 static void
79 sig_query_created(XMPP_QUERY_REC *query, int automatic)
80 {
81 XMPP_ROSTER_USER_REC *user;
82
83 if (!IS_XMPP_QUERY(query))
84 return;
85 user = rosters_find_user(query->server->roster, query->name, NULL,
86 NULL);
87 if (user == NULL || user->name == NULL)
88 return;
89 printformat_module(MODULE_NAME, query->server, query->name,
90 MSGLEVEL_CRAP, XMPPTXT_QUERY_AKA, user->jid, user->name);
91 }
92
93 static void
94 sig_window_bound_query(SERVER_REC *gserver)
95 {
96 XMPP_SERVER_REC *server;
97 g_return_if_fail(gserver != NULL);
98
99 if ((server = XMPP_SERVER(gserver)) == NULL)
100 return;
101
102 #if defined(IRSSI_ABI_VERSION) && IRSSI_ABI_VERSION >= 20
103 GSList *tmp, *tmp2, *bounds;
104 for (tmp = windows; tmp != NULL; tmp = tmp->next) {
105 WINDOW_REC *win = tmp->data;
106 bounds = g_slist_copy(win->bound_items);
107
108 for (tmp2 = bounds; tmp2 != NULL; tmp2 = tmp2->next) {
109 WINDOW_BIND_REC *bound = tmp2->data;
110
111 if (bound->type == query_type) {
112 if (server->chat_type == chatnet_type &&
113 g_strcmp0(server->tag, bound->servertag) == 0) {
114 xmpp_query_create(bound->servertag, bound->name, TRUE);
115 }
116 }
117 }
118
119 g_slist_free(bounds);
120 }
121 #endif
122 }
123
124 void
125 fe_xmpp_queries_init(void)
126 {
127 query_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
128 chatnet_type = XMPP_PROTOCOL;
129
130 signal_add("xmpp query raise", sig_query_raise);
131 signal_add("xmpp presence changed", sig_presence_changed);
132 signal_add("server connected", sig_window_bound_query);
133 signal_add_last("query created", sig_query_created);
134 }
135
136 void
137 fe_xmpp_queries_deinit(void)
138 {
139 signal_remove("xmpp query raise", sig_query_raise);
140 signal_remove("xmpp presence changed", sig_presence_changed);
141 signal_remove("server connected", sig_window_bound_query);
142 signal_remove("query created", sig_query_created);
143 }