summaryrefslogtreecommitdiff
path: root/src/irc/flood
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc/flood')
-rw-r--r--src/irc/flood/autoignore.c257
-rw-r--r--src/irc/flood/autoignore.h11
-rw-r--r--src/irc/flood/flood.c1
3 files changed, 29 insertions, 240 deletions
diff --git a/src/irc/flood/autoignore.c b/src/irc/flood/autoignore.c
index 95967686..bc7be104 100644
--- a/src/irc/flood/autoignore.c
+++ b/src/irc/flood/autoignore.c
@@ -31,265 +31,62 @@
#include "autoignore.h"
-/* How often to check if there's anyone to be unignored in autoignore list */
-#define AUTOIGNORE_TIMECHECK 10000
-
-static int ignore_tag;
-
-GSList *server_autoignores(IRC_SERVER_REC *server)
-{
- MODULE_SERVER_REC *rec;
-
- g_return_val_if_fail(IS_IRC_SERVER(server), NULL);
-
- rec = MODULE_DATA(server);
- return rec->ignorelist;
-}
-
-static void autoignore_remove_rec(IRC_SERVER_REC *server, AUTOIGNORE_REC *rec)
-{
- MODULE_SERVER_REC *mserver;
-
- g_return_if_fail(IS_IRC_SERVER(server));
- g_return_if_fail(rec != NULL);
-
- signal_emit("autoignore remove", 2, server, rec);
-
- g_free(rec->nick);
- g_free(rec);
-
- mserver = MODULE_DATA(server);
- mserver->ignorelist = g_slist_remove(mserver->ignorelist, rec);
-}
-
-static AUTOIGNORE_REC *autoignore_find(IRC_SERVER_REC *server, const char *mask)
-{
- MODULE_SERVER_REC *mserver;
- GSList *tmp;
-
- g_return_val_if_fail(IS_IRC_SERVER(server), NULL);
- g_return_val_if_fail(mask != NULL, NULL);
-
- mserver = MODULE_DATA(server);
- for (tmp = mserver->ignorelist; tmp != NULL; tmp = tmp->next) {
- AUTOIGNORE_REC *rec = tmp->data;
-
- if (g_strcasecmp(rec->nick, mask) == 0)
- return rec;
- }
-
- return NULL;
-}
-
-/* timeout function: unignore old ignores.. */
-static void autoignore_timeout_server(IRC_SERVER_REC *server)
+void autoignore_update(IGNORE_REC *rec, int level)
{
- MODULE_SERVER_REC *mserver;
- GSList *tmp, *next;
- time_t t;
-
- g_return_if_fail(server != NULL);
- if (!IS_IRC_SERVER(server))
- return;
-
- mserver = MODULE_DATA(server);
- t = time(NULL);
- t -= mserver->ignore_lastcheck;
-
- for (tmp = mserver->ignorelist; tmp != NULL; tmp = next) {
- AUTOIGNORE_REC *rec = tmp->data;
-
- next = tmp->next;
- if (rec->timeleft > t)
- rec->timeleft -= t;
- else
- autoignore_remove_rec(server, rec);
- }
-
- mserver->ignore_lastcheck = time(NULL);
-}
-
-static int autoignore_timeout(void)
-{
- g_slist_foreach(servers, (GFunc) autoignore_timeout_server, NULL);
- return 1;
-}
-
-static void autoignore_init_server(IRC_SERVER_REC *server)
-{
- MODULE_SERVER_REC *mserver;
-
- if (!IS_IRC_SERVER(server))
- return;
-
- mserver = MODULE_DATA(server);
- mserver->ignorelist = NULL;
- mserver->ignore_lastcheck = time(NULL)-AUTOIGNORE_TIMECHECK;
-}
-
-static void autoignore_deinit_server(IRC_SERVER_REC *server)
-{
- MODULE_SERVER_REC *mserver;
-
- if (!IS_IRC_SERVER(server))
- return;
+ rec->level |= level;
+ rec->time = settings_get_int("autoignore_time");
- mserver = MODULE_DATA(server);
- while (mserver->ignorelist != NULL)
- autoignore_remove_rec(server, (AUTOIGNORE_REC *) mserver->ignorelist->data);
+ ignore_update_rec(rec);
}
-IGNORE_REC *ignore_find_server(IRC_SERVER_REC *server, const char *mask)
+void autoignore_add(IRC_SERVER_REC *server, char *mask, int level)
{
- GSList *tmp;
+ IGNORE_REC *rec;
- for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
- IGNORE_REC *rec = tmp->data;
-
- if (rec->servertag != NULL &&
- g_strcasecmp(rec->mask, mask) == 0 &&
- g_strcasecmp(rec->servertag, server->tag) == 0)
- return rec;
- }
-
- return NULL;
-}
-
-void autoignore_add(IRC_SERVER_REC *server, const char *nick, int level)
-{
- MODULE_SERVER_REC *mserver;
- AUTOIGNORE_REC *rec;
- IGNORE_REC *irec;
- int igtime;
-
- g_return_if_fail(nick != NULL);
- if (level == 0 || !IRC_SERVER(server)) return;
-
- igtime = settings_get_int("autoignore_time");
- if (igtime <= 0) return;
-
- irec = ignore_find_server(server, nick);
- if (irec == NULL) {
- irec = g_new0(IGNORE_REC, 1);
- irec->servertag = g_strdup(server->tag);
- irec->mask = g_strdup(nick);
- irec->level = level;
- ignore_add_rec(irec);
- } else {
- irec->level |= level;
- ignore_update_rec(irec);
- }
-
- rec = autoignore_find(server, nick);
- if (rec != NULL) {
- /* already being ignored */
- rec->timeleft = igtime;
- return;
- }
-
- rec = g_new(AUTOIGNORE_REC, 1);
- rec->nick = g_strdup(nick);
- rec->timeleft = igtime;
+ rec = g_new0(IGNORE_REC, 1);
+
+ rec->mask = mask;
+ rec->servertag = g_strdup(server->tag);
rec->level = level;
-
- mserver = MODULE_DATA(server);
- mserver->ignorelist = g_slist_append(mserver->ignorelist, rec);
-
- signal_emit("autoignore new", 2, server, rec);
-}
-
-int autoignore_remove(IRC_SERVER_REC *server, const char *mask, int level)
-{
- AUTOIGNORE_REC *rec;
- IGNORE_REC *irec;
-
- g_return_val_if_fail(mask != NULL, FALSE);
- if (!IS_IRC_SERVER(server))
- return FALSE;
-
- irec = ignore_find_server(server, mask);
- if (irec != NULL) {
- irec->level &= ~level;
- ignore_update_rec(irec);
- }
-
- rec = autoignore_find(server, mask);
- if (rec != NULL && (level & rec->level)) {
- rec->level &= ~level;
- if (rec->level == 0) autoignore_remove_rec(server, rec);
- return TRUE;
- }
-
- return FALSE;
+ rec->time = settings_get_int("autoignore_time");
+ rec->autoignore = 1;
+
+ ignore_add_rec(rec);
}
static void sig_flood(IRC_SERVER_REC *server, const char *nick, const char *host, gpointer levelp)
{
int level, check_level;
+ GString *mask;
+ IGNORE_REC *rec;
+
g_return_if_fail(IS_IRC_SERVER(server));
level = GPOINTER_TO_INT(levelp);
check_level = level2bits(settings_get_str("autoignore_levels"));
- if (level & check_level)
- autoignore_add(server, nick, level);
-}
-
-static void autoignore_remove_level(const char *nick, int level)
-{
- AUTOIGNORE_REC *rec;
- GSList *tmp;
-
- g_return_if_fail(nick != NULL);
-
- for (tmp = servers; tmp != NULL; tmp = tmp->next) {
- IRC_SERVER_REC *server = tmp->data;
-
- if (!IS_IRC_SERVER(server))
- continue;
-
- rec = autoignore_find(server, nick);
- if (rec != NULL && (rec->level & level)) {
- rec->level &= ~level;
- if (rec->level == 0) autoignore_remove_rec(server, rec);
- }
+ mask = g_string_new(nick);
+ mask = g_string_append_c(mask, '!');
+ mask = g_string_append(mask, host);
+ if (level & check_level) {
+ rec = ignore_find(server->tag, mask->str, NULL);
+ if (rec == NULL)
+ autoignore_add(server, mask->str, level);
+ else
+ autoignore_update(rec, level);
}
}
-static void sig_ignore_destroyed(IGNORE_REC *ignore)
-{
- if (ignore->mask != NULL)
- autoignore_remove_level(ignore->mask, MSGLEVEL_ALL);
-}
-
-static void sig_ignore_changed(IGNORE_REC *ignore)
-{
- if (ignore->mask != NULL)
- autoignore_remove_level(ignore->mask, ~ignore->level);
-}
-
void autoignore_init(void)
{
settings_add_int("flood", "autoignore_time", 300);
settings_add_str("flood", "autoignore_levels", "");
- ignore_tag = g_timeout_add(AUTOIGNORE_TIMECHECK, (GSourceFunc) autoignore_timeout, NULL);
-
- signal_add("server connected", (SIGNAL_FUNC) autoignore_init_server);
- signal_add("server disconnected", (SIGNAL_FUNC) autoignore_deinit_server);
- signal_add("flood", (SIGNAL_FUNC) sig_flood);
- signal_add("ignore destroyed", (SIGNAL_FUNC) sig_ignore_destroyed);
- signal_add("ignore changed", (SIGNAL_FUNC) sig_ignore_changed);
+ signal_add("flood", (SIGNAL_FUNC) sig_flood);
}
void autoignore_deinit(void)
{
- g_source_remove(ignore_tag);
-
- signal_remove("server connected", (SIGNAL_FUNC) autoignore_init_server);
- signal_remove("server disconnected", (SIGNAL_FUNC) autoignore_deinit_server);
signal_remove("flood", (SIGNAL_FUNC) sig_flood);
- signal_remove("ignore destroyed", (SIGNAL_FUNC) sig_ignore_destroyed);
- signal_remove("ignore changed", (SIGNAL_FUNC) sig_ignore_changed);
}
diff --git a/src/irc/flood/autoignore.h b/src/irc/flood/autoignore.h
index efa01d27..b00829a1 100644
--- a/src/irc/flood/autoignore.h
+++ b/src/irc/flood/autoignore.h
@@ -1,16 +1,7 @@
#ifndef __AUTOIGNORE_H
#define __AUTOIGNORE_H
-typedef struct {
- char *nick;
- int timeleft;
- int level;
-} AUTOIGNORE_REC;
-
-GSList *server_autoignores(IRC_SERVER_REC *server);
-
-void autoignore_add(IRC_SERVER_REC *server, const char *nick, int level);
-int autoignore_remove(IRC_SERVER_REC *server, const char *mask, int level);
+void autoignore_add(IRC_SERVER_REC *server, char *nick, int level);
void autoignore_init(void);
void autoignore_deinit(void);
diff --git a/src/irc/flood/flood.c b/src/irc/flood/flood.c
index 0c4dc7ab..a1d4dd91 100644
--- a/src/irc/flood/flood.c
+++ b/src/irc/flood/flood.c
@@ -63,6 +63,7 @@ static int flood_hash_check_remove(const char *key, FLOOD_REC *flood, gpointer n
flood->items = g_slist_remove(flood->items, rec);
g_free(rec->target);
g_free(rec);
+ rec->msgcount--;
}
}