2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
ignore.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "levels.h"
|
|
|
|
#include "lib-config/iconfig.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2000-10-09 19:40:18 -04:00
|
|
|
#include "masks.h"
|
|
|
|
#include "servers.h"
|
|
|
|
#include "channels.h"
|
|
|
|
#include "nicklist.h"
|
2001-01-28 02:22:22 -05:00
|
|
|
#include "nickmatch-cache.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#include "ignore.h"
|
|
|
|
|
|
|
|
GSList *ignores;
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
static NICKMATCH_REC *nickmatch;
|
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
static int unignore_timeout(IGNORE_REC *rec);
|
|
|
|
|
2000-06-04 08:38:28 -04:00
|
|
|
/* check if `text' contains ignored nick at the start of the line. */
|
2001-01-28 02:22:22 -05:00
|
|
|
static int ignore_check_replies_rec(IGNORE_REC *rec, CHANNEL_REC *channel,
|
|
|
|
const char *text)
|
2000-06-04 08:38:28 -04:00
|
|
|
{
|
|
|
|
GSList *nicks, *tmp;
|
|
|
|
|
2000-11-06 20:42:21 -05:00
|
|
|
nicks = nicklist_find_multiple(channel, rec->mask);
|
2000-06-04 08:38:28 -04:00
|
|
|
if (nicks == NULL) return FALSE;
|
|
|
|
|
|
|
|
for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
|
|
|
|
NICK_REC *nick = tmp->data;
|
|
|
|
|
2000-12-16 20:20:21 -05:00
|
|
|
if (nick_match_msg(channel, text, nick->nick))
|
2000-06-04 08:38:28 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
g_slist_free(nicks);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
static int ignore_check_replies(CHANNEL_REC *chanrec, const char *text)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (text == NULL || chanrec == NULL)
|
|
|
|
return FALSE;
|
2000-11-06 20:42:21 -05:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
/* check reply ignores */
|
2000-04-26 04:03:38 -04:00
|
|
|
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
|
|
|
IGNORE_REC *rec = tmp->data;
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (rec->mask != NULL && rec->replies &&
|
|
|
|
ignore_check_replies_rec(rec, chanrec, text))
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
|
|
|
|
{
|
|
|
|
if (rec->pattern == NULL)
|
|
|
|
return TRUE;
|
2000-06-04 08:38:28 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (text == NULL)
|
|
|
|
return FALSE;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (rec->regexp) {
|
|
|
|
#ifdef HAVE_REGEX_H
|
|
|
|
return rec->regexp_compiled &&
|
|
|
|
regexec(&rec->preg, text, 0, NULL, 0) == 0;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
return rec->fullword ?
|
|
|
|
stristr_full(text, rec->pattern) != NULL :
|
|
|
|
stristr(text, rec->pattern) != NULL;
|
|
|
|
}
|
2000-10-09 19:40:18 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
#define ignore_match_level(rec, level) \
|
|
|
|
((level & (rec)->level) != 0)
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 11:43:13 -05:00
|
|
|
#define ignore_match_nickmask(rec, nick, nickmask) \
|
|
|
|
((rec)->mask == NULL || \
|
|
|
|
(strchr((rec)->mask, '!') != NULL ? \
|
|
|
|
match_wildcards((rec)->mask, nickmask) : \
|
|
|
|
match_wildcards((rec)->mask, nick)))
|
2001-01-28 02:22:22 -05:00
|
|
|
|
|
|
|
#define ignore_match_server(rec, server) \
|
|
|
|
((rec)->servertag == NULL || \
|
|
|
|
g_strcasecmp((server)->tag, (rec)->servertag) == 0)
|
|
|
|
|
|
|
|
#define ignore_match_channel(rec, channel) \
|
|
|
|
((rec)->channels == NULL || ((channel) != NULL && \
|
|
|
|
strarray_find((rec)->channels, (channel)) != -1))
|
|
|
|
|
|
|
|
static int ignore_check_without_mask(GSList *list, CHANNEL_REC *channel,
|
|
|
|
int level, const char *text)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
int len, best_mask, best_match, best_patt;
|
|
|
|
|
2001-01-28 11:54:25 -05:00
|
|
|
best_mask = best_patt = -1; best_match = FALSE;
|
2001-01-28 02:22:22 -05:00
|
|
|
for (tmp = list; tmp != NULL; tmp = tmp->next) {
|
|
|
|
IGNORE_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (ignore_match_level(rec, level) &&
|
|
|
|
ignore_match_pattern(rec, text)) {
|
|
|
|
len = rec->mask == NULL ? 0 : strlen(rec->mask);
|
|
|
|
if (len > best_mask) {
|
|
|
|
best_mask = len;
|
|
|
|
best_match = !rec->exception;
|
|
|
|
} else if (len == best_mask && rec->pattern != NULL) {
|
|
|
|
len = strlen(rec->pattern);
|
|
|
|
if (len > best_patt) {
|
|
|
|
best_patt = len;
|
|
|
|
best_match = !rec->exception;
|
|
|
|
}
|
2000-11-06 19:06:35 -05:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-01-28 02:22:22 -05:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (best_match || (level & MSGLEVEL_PUBLIC) == 0)
|
|
|
|
return best_match;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
return ignore_check_replies(channel, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ignore_check(SERVER_REC *server, const char *nick, const char *host,
|
|
|
|
const char *channel, const char *text, int level)
|
|
|
|
{
|
|
|
|
CHANNEL_REC *chanrec;
|
|
|
|
NICK_REC *nickrec;
|
|
|
|
IGNORE_REC *rec;
|
|
|
|
GSList *tmp, *list;
|
|
|
|
char *nickmask;
|
|
|
|
int len, best_mask, best_match, best_patt;
|
|
|
|
|
|
|
|
g_return_val_if_fail(server != NULL, 0);
|
|
|
|
|
|
|
|
chanrec = (channel != NULL && server != NULL &&
|
|
|
|
server->ischannel(channel)) ?
|
|
|
|
channel_find(server, channel) : NULL;
|
|
|
|
if (chanrec != NULL && nick != NULL &&
|
|
|
|
(nickrec = nicklist_find(chanrec, nick)) != NULL) {
|
|
|
|
/* nick found - check only ignores in nickmatch cache */
|
|
|
|
if (nickrec->host == NULL)
|
|
|
|
nicklist_set_host(chanrec, nickrec, host);
|
|
|
|
|
|
|
|
list = nickmatch_find(nickmatch, nickrec);
|
|
|
|
return ignore_check_without_mask(list, chanrec, level, text);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmask = g_strconcat(nick, "!", host, NULL);
|
|
|
|
|
2001-02-06 16:49:57 -05:00
|
|
|
best_mask = best_patt = -1; best_match = FALSE;
|
2001-01-28 02:22:22 -05:00
|
|
|
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
|
|
|
rec = tmp->data;
|
|
|
|
|
|
|
|
if (ignore_match_level(rec, level) &&
|
|
|
|
ignore_match_server(rec, server) &&
|
|
|
|
ignore_match_channel(rec, channel) &&
|
2001-01-28 11:43:13 -05:00
|
|
|
ignore_match_nickmask(rec, nick, nickmask) &&
|
2001-01-28 02:22:22 -05:00
|
|
|
ignore_match_pattern(rec, text)) {
|
|
|
|
len = rec->mask == NULL ? 0 : strlen(rec->mask);
|
|
|
|
if (len > best_mask) {
|
|
|
|
best_mask = len;
|
|
|
|
best_match = !rec->exception;
|
|
|
|
} else if (len == best_mask && rec->pattern != NULL) {
|
|
|
|
len = strlen(rec->pattern);
|
|
|
|
if (len > best_patt) {
|
|
|
|
best_patt = len;
|
|
|
|
best_match = !rec->exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(nickmask);
|
|
|
|
|
|
|
|
if (best_match || (level & MSGLEVEL_PUBLIC) == 0)
|
|
|
|
return best_match;
|
|
|
|
|
|
|
|
return ignore_check_replies(chanrec, text);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
IGNORE_REC *ignore_find(const char *servertag, const char *mask,
|
|
|
|
char **channels)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
char **chan;
|
|
|
|
int ignore_servertag;
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (mask != NULL && (*mask == '\0' || strcmp(mask, "*") == 0))
|
|
|
|
mask = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
ignore_servertag = servertag != NULL && strcmp(servertag, "*") == 0;
|
|
|
|
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
|
|
|
IGNORE_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (!ignore_servertag) {
|
|
|
|
if ((servertag == NULL && rec->servertag != NULL) ||
|
|
|
|
(servertag != NULL && rec->servertag == NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (servertag != NULL && g_strcasecmp(servertag, rec->servertag) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rec->mask == NULL && mask != NULL) ||
|
|
|
|
(rec->mask != NULL && mask == NULL)) continue;
|
|
|
|
|
|
|
|
if (rec->mask != NULL && g_strcasecmp(rec->mask, mask) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((channels == NULL && rec->channels == NULL))
|
|
|
|
return rec; /* no channels - ok */
|
|
|
|
|
|
|
|
if (channels != NULL && strcmp(*channels, "*") == 0)
|
|
|
|
return rec; /* ignore channels */
|
|
|
|
|
|
|
|
if (channels == NULL || rec->channels == NULL)
|
|
|
|
continue; /* other doesn't have channels */
|
|
|
|
|
|
|
|
if (strarray_length(channels) != strarray_length(rec->channels))
|
|
|
|
continue; /* different amount of channels */
|
|
|
|
|
|
|
|
/* check that channels match */
|
|
|
|
for (chan = channels; *chan != NULL; chan++) {
|
|
|
|
if (strarray_find(rec->channels, *chan) == -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*chan == NULL)
|
|
|
|
return rec; /* channels ok */
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
char *ignore_get_key(IGNORE_REC *rec)
|
|
|
|
{
|
|
|
|
char *chans, *ret;
|
|
|
|
|
|
|
|
if (rec->channels == NULL)
|
|
|
|
return rec->mask != NULL ? g_strdup(rec->mask) : NULL;
|
|
|
|
|
|
|
|
chans = g_strjoinv(",", rec->channels);
|
|
|
|
if (rec->mask == NULL) return chans;
|
|
|
|
|
|
|
|
ret = g_strdup_printf("%s %s", rec->mask, chans);
|
|
|
|
g_free(chans);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static void ignore_set_config(IGNORE_REC *rec)
|
|
|
|
{
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
char *levelstr;
|
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
if (rec->level == 0 || rec->time > 0)
|
2000-07-23 10:41:42 -04:00
|
|
|
return;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
node = iconfig_node_traverse("(ignores", TRUE);
|
|
|
|
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
|
|
|
|
2000-05-10 09:57:42 -04:00
|
|
|
if (rec->mask != NULL) iconfig_node_set_str(node, "mask", rec->mask);
|
2000-04-26 04:03:38 -04:00
|
|
|
if (rec->level) {
|
|
|
|
levelstr = bits2level(rec->level);
|
2000-05-10 09:57:42 -04:00
|
|
|
iconfig_node_set_str(node, "level", levelstr);
|
2000-04-26 04:03:38 -04:00
|
|
|
g_free(levelstr);
|
|
|
|
}
|
2000-05-10 09:57:42 -04:00
|
|
|
iconfig_node_set_str(node, "pattern", rec->pattern);
|
2001-01-28 02:22:22 -05:00
|
|
|
if (rec->exception) iconfig_node_set_bool(node, "exception", TRUE);
|
2000-11-26 05:24:30 -05:00
|
|
|
if (rec->regexp) iconfig_node_set_bool(node, "regexp", TRUE);
|
|
|
|
if (rec->fullword) iconfig_node_set_bool(node, "fullword", TRUE);
|
|
|
|
if (rec->replies) iconfig_node_set_bool(node, "replies", TRUE);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (rec->channels != NULL && *rec->channels != NULL) {
|
|
|
|
node = config_node_section(node, "channels", NODE_TYPE_LIST);
|
2000-11-26 05:24:30 -05:00
|
|
|
iconfig_node_add_list(node, rec->channels);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ignore_index(IGNORE_REC *find)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
|
|
|
IGNORE_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (rec->servertag != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (rec == find)
|
|
|
|
return index;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ignore_remove_config(IGNORE_REC *rec)
|
|
|
|
{
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
|
|
|
|
node = iconfig_node_traverse("ignores", FALSE);
|
2000-05-10 09:57:42 -04:00
|
|
|
if (node != NULL) iconfig_node_list_remove(node, ignore_index(rec));
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ignore_add_rec(IGNORE_REC *rec)
|
|
|
|
{
|
2000-11-18 10:32:59 -05:00
|
|
|
#ifdef HAVE_REGEX_H
|
2000-11-06 19:06:35 -05:00
|
|
|
rec->regexp_compiled = !rec->regexp || rec->pattern == NULL ? FALSE :
|
|
|
|
regcomp(&rec->preg, rec->pattern,
|
|
|
|
REG_EXTENDED|REG_ICASE|REG_NOSUB) == 0;
|
2000-11-18 10:32:59 -05:00
|
|
|
#endif
|
2001-02-22 01:09:48 -05:00
|
|
|
if (rec->time > 0)
|
|
|
|
rec->time_tag = g_timeout_add(rec->time*1000, (GSourceFunc) unignore_timeout, rec);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
ignores = g_slist_append(ignores, rec);
|
|
|
|
ignore_set_config(rec);
|
2000-06-14 13:52:03 -04:00
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
if (!rec->autoignore)
|
|
|
|
signal_emit("ignore created", 1, rec);
|
|
|
|
else
|
|
|
|
signal_emit("autoignore new", 1, rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ignore_destroy(IGNORE_REC *rec)
|
|
|
|
{
|
|
|
|
ignores = g_slist_remove(ignores, rec);
|
2001-02-22 01:09:48 -05:00
|
|
|
if (!rec->autoignore)
|
|
|
|
signal_emit("ignore destroyed", 1, rec);
|
|
|
|
else
|
|
|
|
signal_emit("autoignore destroyed", 1, rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-11-18 10:32:59 -05:00
|
|
|
#ifdef HAVE_REGEX_H
|
2000-11-06 19:06:35 -05:00
|
|
|
if (rec->regexp_compiled) regfree(&rec->preg);
|
2000-11-18 10:32:59 -05:00
|
|
|
#endif
|
2000-07-23 10:41:42 -04:00
|
|
|
if (rec->time_tag > 0) g_source_remove(rec->time_tag);
|
2000-04-26 04:03:38 -04:00
|
|
|
if (rec->channels != NULL) g_strfreev(rec->channels);
|
|
|
|
g_free_not_null(rec->mask);
|
|
|
|
g_free_not_null(rec->servertag);
|
|
|
|
g_free_not_null(rec->pattern);
|
|
|
|
g_free(rec);
|
2001-01-28 02:22:22 -05:00
|
|
|
|
|
|
|
nickmatch_rebuild(nickmatch);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ignore_update_rec(IGNORE_REC *rec)
|
|
|
|
{
|
2001-01-28 02:22:22 -05:00
|
|
|
if (rec->level == 0) {
|
2000-04-26 04:03:38 -04:00
|
|
|
/* unignored everything */
|
|
|
|
ignore_remove_config(rec);
|
|
|
|
ignore_destroy(rec);
|
|
|
|
} else {
|
|
|
|
/* unignore just some levels.. */
|
|
|
|
ignore_remove_config(rec);
|
|
|
|
ignores = g_slist_remove(ignores, rec);
|
|
|
|
|
|
|
|
ignores = g_slist_append(ignores, rec);
|
|
|
|
ignore_set_config(rec);
|
2000-06-14 13:52:03 -04:00
|
|
|
|
|
|
|
signal_emit("ignore changed", 1, rec);
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmatch_rebuild(nickmatch);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-22 01:09:48 -05:00
|
|
|
static int unignore_timeout(IGNORE_REC *rec)
|
|
|
|
{
|
|
|
|
rec->level = 0;
|
|
|
|
ignore_update_rec(rec);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
static void read_ignores(void)
|
|
|
|
{
|
|
|
|
IGNORE_REC *rec;
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
while (ignores != NULL)
|
|
|
|
ignore_destroy(ignores->data);
|
|
|
|
|
|
|
|
node = iconfig_node_traverse("ignores", FALSE);
|
2001-01-28 02:22:22 -05:00
|
|
|
if (node == NULL) {
|
|
|
|
nickmatch_rebuild(nickmatch);
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
|
|
|
node = tmp->data;
|
|
|
|
|
|
|
|
if (node->type != NODE_TYPE_BLOCK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rec = g_new0(IGNORE_REC, 1);
|
|
|
|
ignores = g_slist_append(ignores, rec);
|
|
|
|
|
|
|
|
rec->mask = g_strdup(config_node_get_str(node, "mask", NULL));
|
2001-01-28 11:17:53 -05:00
|
|
|
if (rec->mask != NULL && strcmp(rec->mask, "*") == 0) {
|
2001-01-28 02:22:22 -05:00
|
|
|
/* FIXME: remove after .98 */
|
|
|
|
g_free(rec->mask);
|
|
|
|
rec->mask = NULL;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
rec->pattern = g_strdup(config_node_get_str(node, "pattern", NULL));
|
2000-05-04 06:32:42 -04:00
|
|
|
rec->level = level2bits(config_node_get_str(node, "level", ""));
|
2001-01-28 02:22:22 -05:00
|
|
|
rec->exception = config_node_get_bool(node, "exception", FALSE);
|
|
|
|
if (*config_node_get_str(node, "except_level", "") != '\0') {
|
|
|
|
/* FIXME: remove after .98 */
|
|
|
|
rec->level = level2bits(config_node_get_str(node, "except_level", ""));
|
|
|
|
rec->exception = TRUE;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
rec->regexp = config_node_get_bool(node, "regexp", FALSE);
|
|
|
|
rec->fullword = config_node_get_bool(node, "fullword", FALSE);
|
2000-06-04 08:38:28 -04:00
|
|
|
rec->replies = config_node_get_bool(node, "replies", FALSE);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
node = config_node_section(node, "channels", -1);
|
|
|
|
if (node != NULL) rec->channels = config_node_get_list(node);
|
|
|
|
}
|
2001-01-28 02:22:22 -05:00
|
|
|
|
|
|
|
nickmatch_rebuild(nickmatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ignore_nick_cache(GHashTable *list, CHANNEL_REC *channel,
|
|
|
|
NICK_REC *nick)
|
|
|
|
{
|
|
|
|
GSList *tmp, *matches;
|
|
|
|
char *nickmask;
|
|
|
|
|
|
|
|
if (nick->host == NULL)
|
|
|
|
return; /* don't check until host is known */
|
|
|
|
|
|
|
|
matches = NULL;
|
|
|
|
nickmask = g_strconcat(nick->nick, "!", nick->host, NULL);
|
|
|
|
for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
|
|
|
|
IGNORE_REC *rec = tmp->data;
|
|
|
|
|
2001-01-28 11:43:13 -05:00
|
|
|
if (ignore_match_nickmask(rec, nick->nick, nickmask) &&
|
2001-01-28 02:22:22 -05:00
|
|
|
ignore_match_server(rec, channel->server) &&
|
|
|
|
ignore_match_channel(rec, channel->name))
|
|
|
|
matches = g_slist_append(matches, rec);
|
|
|
|
}
|
|
|
|
g_free_not_null(nickmask);
|
|
|
|
|
|
|
|
if (matches == NULL)
|
|
|
|
g_hash_table_remove(list, nick);
|
|
|
|
else
|
|
|
|
g_hash_table_insert(list, nick, matches);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ignore_init(void)
|
|
|
|
{
|
|
|
|
ignores = NULL;
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmatch = nickmatch_init(ignore_nick_cache);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
read_ignores();
|
|
|
|
signal_add("setup reread", (SIGNAL_FUNC) read_ignores);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ignore_deinit(void)
|
|
|
|
{
|
|
|
|
while (ignores != NULL)
|
|
|
|
ignore_destroy(ignores->data);
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmatch_deinit(nickmatch);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
signal_remove("setup reread", (SIGNAL_FUNC) read_ignores);
|
|
|
|
}
|