Bug Summary

File:irc/notifylist/notifylist.c
Location:line 244, column 20
Description:Value stored to 'data' is never read

Annotated Source Code

1/*
2 notifylist.c : irssi
3
4 Copyright (C) 1999-2000 Timo Sirainen
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#include "module.h"
22#include "modules.h"
23#include "signals.h"
24#include "settings.h"
25
26#include "irc.h"
27#include "irc-channels.h"
28#include "servers-redirect.h"
29#include "masks.h"
30#include "nicklist.h"
31
32#include "notifylist.h"
33#include "notify-setup.h"
34
35GSList *notifies;
36
37NOTIFYLIST_REC *notifylist_add(const char *mask, const char *ircnets,
38 int away_check)
39{
40 NOTIFYLIST_REC *rec;
41
42 g_return_val_if_fail(mask != NULL, NULL)do{ if (mask != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "mask != NULL"); return (
((void *)0)); }; }while (0)
;
43
44 rec = g_new0(NOTIFYLIST_REC, 1)((NOTIFYLIST_REC *) g_malloc0 (((gsize) sizeof (NOTIFYLIST_REC
)) * ((gsize) (1))))
;
45 rec->mask = g_strdup(mask);
46 rec->ircnets = ircnets == NULL((void *)0) || *ircnets == '\0' ? NULL((void *)0) :
47 g_strsplit(ircnets, " ", -1);
48 rec->away_check = away_check;
49
50 notifylist_add_config(rec);
51
52 notifies = g_slist_append(notifies, rec);
53 signal_emit("notifylist new", 1, rec);
54 return rec;
55}
56
57static void notify_destroy(NOTIFYLIST_REC *rec)
58{
59 if (rec->ircnets != NULL((void *)0)) g_strfreev(rec->ircnets);
60 g_free(rec->mask);
61 g_free(rec);
62}
63
64void notifylist_destroy_all(void)
65{
66 g_slist_foreach(notifies, (GFunc) notify_destroy, NULL((void *)0));
67 g_slist_free(notifies);
68
69 notifies = NULL((void *)0);
70}
71
72void notifylist_remove(const char *mask)
73{
74 NOTIFYLIST_REC *rec;
75
76 g_return_if_fail(mask != NULL)do{ if (mask != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "mask != NULL"); return;
}; }while (0)
;
77
78 rec = notifylist_find(mask, "*");
79 if (rec == NULL((void *)0)) return;
80
81 notifylist_remove_config(rec);
82 notifies = g_slist_remove(notifies, rec);
83 signal_emit("notifylist remove", 1, rec);
84
85 notify_destroy(rec);
86}
87
88int notifylist_ircnets_match(NOTIFYLIST_REC *rec, const char *ircnet)
89{
90 char **tmp;
91
92 if (rec->ircnets == NULL((void *)0)) return TRUE(!(0));
93 if (ircnet == NULL((void *)0)) return FALSE(0);
94 if (strcmp(ircnet, "*") == 0) return TRUE(!(0));
95
96 for (tmp = rec->ircnets; *tmp != NULL((void *)0); tmp++) {
97 if (g_strcasecmp(*tmp, ircnet) == 0)
98 return TRUE(!(0));
99 }
100
101 return FALSE(0);
102}
103
104NOTIFYLIST_REC *notifylist_find(const char *mask, const char *ircnet)
105{
106 NOTIFYLIST_REC *best;
107 GSList *tmp;
108 int len;
109
110 best = NULL((void *)0);
111 len = strlen(mask);
112 for (tmp = notifies; tmp != NULL((void *)0); tmp = tmp->next) {
113 NOTIFYLIST_REC *rec = tmp->data;
114
115 /* check mask */
116 if (g_strncasecmp(rec->mask, mask, len) != 0 ||
117 (rec->mask[len] != '\0' && rec->mask[len] != '!')) continue;
118
119 /* check ircnet */
120 if (rec->ircnets == NULL((void *)0)) {
121 best = rec;
122 continue;
123 }
124
125 if (notifylist_ircnets_match(rec, ircnet))
126 return rec;
127 }
128
129 return best;
130}
131
132int notifylist_ison_server(IRC_SERVER_REC *server, const char *nick)
133{
134 NOTIFY_NICK_REC *rec;
135
136 g_return_val_if_fail(nick != NULL, FALSE)do{ if (nick != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "nick != NULL"); return (
(0)); }; }while (0)
;
137 g_return_val_if_fail(IS_IRC_SERVER(server), FALSE)do{ if ((((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC
*) module_check_cast(server, __builtin_offsetof(SERVER_REC, type
), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type),
"IRC")) ? (!(0)) : (0))) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "IS_IRC_SERVER(server)")
; return ((0)); }; }while (0)
;
138
139 rec = notify_nick_find(server, nick);
140 return rec != NULL((void *)0) && rec->host_ok && rec->away_ok;
141}
142
143static IRC_SERVER_REC *notifylist_ison_serverlist(const char *nick, const char *taglist)
144{
145 IRC_SERVER_REC *server;
146 char **list, **tmp;
147
148 g_return_val_if_fail(nick != NULL, NULL)do{ if (nick != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "nick != NULL"); return (
((void *)0)); }; }while (0)
;
149 g_return_val_if_fail(taglist != NULL, NULL)do{ if (taglist != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "taglist != NULL"); return
(((void *)0)); }; }while (0)
;
150
151 list = g_strsplit(taglist, " ", -1);
152
153 server = NULL((void *)0);
154 for (tmp = list; *tmp != NULL((void *)0); tmp++) {
155 server = (IRC_SERVER_REC *) server_find_chatnet(*tmp);
156
157 if (IS_IRC_SERVER(server)(((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *)
module_check_cast(server, __builtin_offsetof(SERVER_REC, type
), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type),
"IRC")) ? (!(0)) : (0))
&&
158 notifylist_ison_server(server, nick))
159 break;
160 }
161 g_strfreev(list);
162
163 return tmp == NULL((void *)0) ? NULL((void *)0) : server;
164}
165
166IRC_SERVER_REC *notifylist_ison(const char *nick, const char *serverlist)
167{
168 GSList *tmp;
169
170 g_return_val_if_fail(nick != NULL, FALSE)do{ if (nick != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "nick != NULL"); return (
(0)); }; }while (0)
;
171 g_return_val_if_fail(serverlist != NULL, FALSE)do{ if (serverlist != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "serverlist != NULL"); return
((0)); }; }while (0)
;
172
173 if (*serverlist != '\0')
174 return notifylist_ison_serverlist(nick, serverlist);
175
176 /* any server.. */
177 for (tmp = servers; tmp != NULL((void *)0); tmp = tmp->next) {
178 IRC_SERVER_REC *server = tmp->data;
179
180 if (IS_IRC_SERVER(server)(((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *)
module_check_cast(server, __builtin_offsetof(SERVER_REC, type
), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type),
"IRC")) ? (!(0)) : (0))
&&
181 notifylist_ison_server(server, nick))
182 return tmp->data;
183 }
184
185 return NULL((void *)0);
186}
187
188static void notifylist_init_server(IRC_SERVER_REC *server)
189{
190 MODULE_SERVER_REC *rec;
191
192 g_return_if_fail(server != NULL)do{ if (server != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "server != NULL"); return
; }; }while (0)
;
193
194 if (!IS_IRC_SERVER(server)(((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *)
module_check_cast(server, __builtin_offsetof(SERVER_REC, type
), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type),
"IRC")) ? (!(0)) : (0))
)
195 return;
196
197 rec = g_new0(MODULE_SERVER_REC,1 )((MODULE_SERVER_REC *) g_malloc0 (((gsize) sizeof (MODULE_SERVER_REC
)) * ((gsize) (1))))
;
198 MODULE_DATA_SET(server, rec)g_hash_table_insert((server)->module_data, "irc/notifylist"
, rec)
;
199}
200
201static void notifylist_deinit_server(IRC_SERVER_REC *server)
202{
203 MODULE_SERVER_REC *mserver;
204 NOTIFY_NICK_REC *rec;
205
206 g_return_if_fail(server != NULL)do{ if (server != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "server != NULL"); return
; }; }while (0)
;
207
208 if (!IS_IRC_SERVER(server)(((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *)
module_check_cast(server, __builtin_offsetof(SERVER_REC, type
), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type),
"IRC")) ? (!(0)) : (0))
)
209 return;
210
211 mserver = MODULE_DATA(server)g_hash_table_lookup((server)->module_data, "irc/notifylist"
)
;
212 while (mserver->notify_users != NULL((void *)0)) {
213 rec = mserver->notify_users->data;
214
215 mserver->notify_users = g_slist_remove(mserver->notify_users, rec);
216 notify_nick_destroy(rec);
217 }
218 g_free(mserver);
219 MODULE_DATA_UNSET(server)g_hash_table_remove((server)->module_data, "irc/notifylist"
)
;
220}
221
222void notifylist_left(IRC_SERVER_REC *server, NOTIFY_NICK_REC *rec)
223{
224 MODULE_SERVER_REC *mserver;
225
226 mserver = MODULE_DATA(server)g_hash_table_lookup((server)->module_data, "irc/notifylist"
)
;
227 mserver->notify_users = g_slist_remove(mserver->notify_users, rec);
228
229 if (rec->host_ok && rec->away_ok) {
230 signal_emit("notifylist left", 6,
231 server, rec->nick,
232 rec->user, rec->host,
233 rec->realname, rec->awaymsg);
234 }
235
236 notify_nick_destroy(rec);
237}
238
239static void event_quit(IRC_SERVER_REC *server, const char *data,
240 const char *nick)
241{
242 NOTIFY_NICK_REC *rec;
243
244 if (*data == ':') data++; /* quit message */
Value stored to 'data' is never read
245
246 rec = notify_nick_find(server, nick);
247 if (rec != NULL((void *)0)) notifylist_left(server, rec);
248}
249
250static void notifylist_check_join(IRC_SERVER_REC *server, const char *nick,
251 const char *userhost, const char *realname, int away)
252{
253 NOTIFYLIST_REC *notify;
254 NOTIFY_NICK_REC *rec;
255 char *user, *host;
256
257 if (nick == NULL((void *)0))
258 return;
259
260 notify = notifylist_find(nick, server->connrec->chatnet);
261 if (notify == NULL((void *)0)) return;
262
263 rec = notify_nick_find(server, nick);
264 if (rec != NULL((void *)0) && rec->join_announced) return;
265 if (rec == NULL((void *)0)) rec = notify_nick_create(server, nick);
266
267 user = g_strdup(userhost == NULL((void *)0) ? "" : userhost);
268 host = strchr(user, '@');
269 if (host != NULL((void *)0)) *host++ = '\0'; else host = "";
270
271 if (!mask_match(SERVER(server)((SERVER_REC *) module_check_cast(server, __builtin_offsetof(
SERVER_REC, type), "SERVER"))
, notify->mask, nick, user, host)) {
272 g_free(user);
273 return;
274 }
275
276 if (notify->away_check && away == -1) {
277 /* we need to know if the nick is away */
278 g_free(user);
279 return;
280 }
281
282 g_free_not_null(rec->user)g_free(rec->user);
283 g_free_not_null(rec->host)g_free(rec->host);
284 g_free_not_null(rec->realname)g_free(rec->realname);
285 rec->user = g_strdup(user);
286 rec->host = g_strdup(host);
287 rec->realname = realname == NULL((void *)0) || *realname == '\0' ? NULL((void *)0) : g_strdup(realname);
288
289 if (away != -1) rec->away = away;
290 rec->host_ok = TRUE(!(0));
291 rec->join_announced = TRUE(!(0));
292
293 signal_emit("notifylist joined", 6,
294 server, rec->nick, rec->user, rec->host, realname, NULL((void *)0));
295 g_free(user);
296}
297
298static void event_privmsg(IRC_SERVER_REC *server, const char *data,
299 const char *nick, const char *address)
300{
301 if (nick != NULL((void *)0)) {
302 notifylist_check_join(server, nick, address, "", -1);
303 }
304}
305
306static void event_join(IRC_SERVER_REC *server, const char *data,
307 const char *nick, const char *address)
308{
309 notifylist_check_join(server, nick, address, "", -1);
310}
311
312static void sig_channel_wholist(IRC_CHANNEL_REC *channel)
313{
314 GSList *nicks, *tmp;
315
316 nicks = nicklist_getnicks(CHANNEL(channel)((CHANNEL_REC *) module_check_cast_module(channel, __builtin_offsetof
(CHANNEL_REC, type), "WINDOW ITEM TYPE", "CHANNEL"))
);
317 for (tmp = nicks; tmp != NULL((void *)0); tmp = tmp->next) {
318 NICK_REC *rec = tmp->data;
319
320 notifylist_check_join(channel->server, rec->nick, rec->host, rec->realname, rec->gone);
321 }
322 g_slist_free(nicks);
323}
324
325void irc_notifylist_init(void)
326{
327 notifylist_read_config();
328
329 notifylist_commands_init();
330 notifylist_ison_init();
331 notifylist_whois_init();
332 signal_add("server connected", (SIGNAL_FUNC) notifylist_init_server)signal_add_full("irc/notifylist", 0, ("server connected"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) notifylist_init_server), ((void *)0))
;
333 signal_add("server disconnected", (SIGNAL_FUNC) notifylist_deinit_server)signal_add_full("irc/notifylist", 0, ("server disconnected"),
(SIGNAL_FUNC) ((SIGNAL_FUNC) notifylist_deinit_server), ((void
*)0))
;
334 signal_add("event quit", (SIGNAL_FUNC) event_quit)signal_add_full("irc/notifylist", 0, ("event quit"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) event_quit), ((void *)0))
;
335 signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg)signal_add_full("irc/notifylist", 0, ("event privmsg"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) event_privmsg), ((void *)0))
;
336 signal_add("event join", (SIGNAL_FUNC) event_join)signal_add_full("irc/notifylist", 0, ("event join"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) event_join), ((void *)0))
;
337 signal_add("channel wholist", (SIGNAL_FUNC) sig_channel_wholist)signal_add_full("irc/notifylist", 0, ("channel wholist"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) sig_channel_wholist), ((void *)0))
;
338 signal_add("setup reread", (SIGNAL_FUNC) notifylist_read_config)signal_add_full("irc/notifylist", 0, ("setup reread"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) notifylist_read_config), ((void *)0))
;
339
340 settings_check()settings_check_module("irc/notifylist");
341 module_register("notifylist", "irc")module_register_full("notifylist", "irc", "irc/notifylist");
342}
343
344void irc_notifylist_deinit(void)
345{
346 notifylist_commands_deinit();
347 notifylist_ison_deinit();
348 notifylist_whois_deinit();
349
350 signal_remove("server connected", (SIGNAL_FUNC) notifylist_init_server)signal_remove_full(("server connected"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) notifylist_init_server), ((void *)0))
;
351 signal_remove("server disconnected", (SIGNAL_FUNC) notifylist_deinit_server)signal_remove_full(("server disconnected"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) notifylist_deinit_server), ((void *)0))
;
352 signal_remove("event quit", (SIGNAL_FUNC) event_quit)signal_remove_full(("event quit"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) event_quit), ((void *)0))
;
353 signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg)signal_remove_full(("event privmsg"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) event_privmsg), ((void *)0))
;
354 signal_remove("event join", (SIGNAL_FUNC) event_join)signal_remove_full(("event join"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) event_join), ((void *)0))
;
355 signal_remove("channel wholist", (SIGNAL_FUNC) sig_channel_wholist)signal_remove_full(("channel wholist"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) sig_channel_wholist), ((void *)0))
;
356 signal_remove("setup reread", (SIGNAL_FUNC) notifylist_read_config)signal_remove_full(("setup reread"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) notifylist_read_config), ((void *)0))
;
357
358 notifylist_destroy_all();
359}