2 nickmatch-cache.c : irssi
4 Copyright (C) 2001 Timo Sirainen
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "nickmatch-cache.h"
31 NICKMATCH_REC *nickmatch_init(NICKMATCH_REBUILD_FUNC func)
35 rec = g_new0(NICKMATCH_REC, 1);
38 lists = g_slist_append(lists, rec);
42 void nickmatch_deinit(NICKMATCH_REC *rec)
44 lists = g_slist_remove(lists, rec);
46 g_hash_table_destroy(rec->nicks);
50 static void nickmatch_check_channel(CHANNEL_REC *channel, NICKMATCH_REC *rec)
54 nicks = nicklist_getnicks(channel);
55 for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
56 NICK_REC *nick = tmp->data;
58 rec->func(rec->nicks, channel, nick);
63 void nickmatch_rebuild(NICKMATCH_REC *rec)
65 if (rec->nicks != NULL)
66 g_hash_table_destroy(rec->nicks);
68 rec->nicks = g_hash_table_new((GHashFunc) g_direct_hash,
69 (GCompareFunc) g_direct_equal);
71 g_slist_foreach(channels, (GFunc) nickmatch_check_channel, rec);
74 static void sig_nick_new(CHANNEL_REC *channel, NICK_REC *nick)
78 g_return_if_fail(channel != NULL);
79 g_return_if_fail(nick != NULL);
81 for (tmp = lists; tmp != NULL; tmp = tmp->next) {
82 NICKMATCH_REC *rec = tmp->data;
84 rec->func(rec->nicks, channel, nick);
88 static void sig_nick_remove(CHANNEL_REC *channel, NICK_REC *nick)
92 g_return_if_fail(channel != NULL);
93 g_return_if_fail(nick != NULL);
95 for (tmp = lists; tmp != NULL; tmp = tmp->next) {
96 NICKMATCH_REC *rec = tmp->data;
98 g_hash_table_remove(rec->nicks, nick);
102 void nickmatch_cache_init(void)
105 signal_add("nicklist new", (SIGNAL_FUNC) sig_nick_new);
106 signal_add("nicklist changed", (SIGNAL_FUNC) sig_nick_new);
107 signal_add("nicklist host changed", (SIGNAL_FUNC) sig_nick_new);
108 signal_add("nicklist remove", (SIGNAL_FUNC) sig_nick_remove);
111 void nickmatch_cache_deinit(void)
113 g_slist_foreach(lists, (GFunc) nickmatch_deinit, NULL);
116 signal_remove("nicklist new", (SIGNAL_FUNC) sig_nick_new);
117 signal_remove("nicklist changed", (SIGNAL_FUNC) sig_nick_new);
118 signal_remove("nicklist host changed", (SIGNAL_FUNC) sig_nick_new);
119 signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nick_remove);