From a5f4fd43cc088380291ab275aae0e7f67ee2d12b Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 13 May 2002 18:16:17 +0000 Subject: don't add same ban more than once to banlist. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2790 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/core/mode-lists.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/irc/core/mode-lists.c b/src/irc/core/mode-lists.c index 8d0a9eab..d7fef183 100644 --- a/src/irc/core/mode-lists.c +++ b/src/irc/core/mode-lists.c @@ -44,6 +44,22 @@ void banlist_free(GSList *banlist) ban_free(&banlist, banlist->data); } +static BAN_REC *banlist_find(GSList *list, const char *ban) +{ + GSList *tmp; + + g_return_val_if_fail(ban != NULL, NULL); + + for (tmp = list; tmp != NULL; tmp = tmp->next) { + BAN_REC *rec = tmp->data; + + if (g_strcasecmp(rec->ban, ban) == 0) + return rec; + } + + return NULL; +} + BAN_REC *banlist_add(IRC_CHANNEL_REC *channel, const char *ban, const char *nick, time_t time) { @@ -52,6 +68,14 @@ BAN_REC *banlist_add(IRC_CHANNEL_REC *channel, const char *ban, g_return_val_if_fail(channel != NULL, NULL); g_return_val_if_fail(ban != NULL, NULL); + rec = banlist_find(channel->banlist, ban); + if (rec != NULL) { + /* duplicate - ignore. some servers send duplicates + for non-ops because they just replace the hostname with + eg. "localhost"... */ + return NULL; + } + rec = g_new(BAN_REC, 1); rec->ban = g_strdup(ban); rec->setby = nick == NULL || *nick == '\0' ? NULL : @@ -64,22 +88,6 @@ BAN_REC *banlist_add(IRC_CHANNEL_REC *channel, const char *ban, return rec; } -static BAN_REC *banlist_find(GSList *list, const char *ban) -{ - GSList *tmp; - - g_return_val_if_fail(ban != NULL, NULL); - - for (tmp = list; tmp != NULL; tmp = tmp->next) { - BAN_REC *rec = tmp->data; - - if (g_strcasecmp(rec->ban, ban) == 0) - return rec; - } - - return NULL; -} - void banlist_remove(IRC_CHANNEL_REC *channel, const char *ban) { BAN_REC *rec; -- cgit v1.2.3