From 856273754804e6959f086ac75932ffa77eb39a8a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 4 Jun 2000 12:38:28 +0000 Subject: [PATCH] completion_msgtoyou() -> irc_nick_match() Implemented -replies option to /ignore. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@287 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/irc/completion.c | 27 +------------ src/fe-common/irc/completion.h | 1 - src/fe-common/irc/fe-events.c | 2 +- src/fe-common/irc/fe-ignore.c | 6 ++- src/fe-common/irc/irc-window-activity.c | 3 +- src/irc/core/ignore.c | 50 ++++++++++++++++++++----- src/irc/core/ignore.h | 1 + src/irc/core/nicklist.c | 26 +++++++++++++ src/irc/core/nicklist.h | 5 ++- 9 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/fe-common/irc/completion.c b/src/fe-common/irc/completion.c index b710dd67..140bdd1f 100644 --- a/src/fe-common/irc/completion.c +++ b/src/fe-common/irc/completion.c @@ -177,7 +177,7 @@ static void event_privmsg(gchar *data, IRC_SERVER_REC *server, gchar *nick) return; } - list = completion_msgtoyou((SERVER_REC *) server, msg) ? + list = irc_nick_match(server->nick, msg) ? &channel->lastownmsgs : &channel->lastmsgs; nick_completion_create(list, time(NULL), nick); @@ -207,31 +207,6 @@ static void cmd_msg(gchar *data, IRC_SERVER_REC *server) g_free(params); } -int completion_msgtoyou(SERVER_REC *server, const char *msg) -{ - gchar *stripped, *nick; - gboolean ret; - gint len; - - g_return_val_if_fail(msg != NULL, FALSE); - - if (g_strncasecmp(msg, server->nick, strlen(server->nick)) == 0 && - !isalnum((gint) msg[strlen(server->nick)])) return TRUE; - - stripped = nick_strip(server->nick); - nick = nick_strip(msg); - - len = strlen(stripped); - ret = *stripped != '\0' && - g_strncasecmp(nick, stripped, len) == 0 && - !isalnum((gint) nick[len]) && - (guchar) nick[len] < 128; - - g_free(nick); - g_free(stripped); - return ret; -} - static void complete_list(GList **outlist, GSList *list, gchar *nick) { GSList *tmp; diff --git a/src/fe-common/irc/completion.h b/src/fe-common/irc/completion.h index 3ecb0339..e7dfd076 100644 --- a/src/fe-common/irc/completion.h +++ b/src/fe-common/irc/completion.h @@ -3,7 +3,6 @@ #include "window-items.h" -int completion_msgtoyou(SERVER_REC *server, const char *msg); char *completion_line(WINDOW_REC *window, const char *line, int *pos); char *auto_completion(const char *line, int *pos); diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index ecd82d59..ab893e15 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -80,7 +80,7 @@ static void event_privmsg(gchar *data, IRC_SERVER_REC *server, gchar *nick, gcha gchar *color; chanrec = channel_find(server, target); - toyou = completion_msgtoyou((SERVER_REC *) server, msg); + toyou = irc_nick_match(server->nick, msg); color = irc_hilight_find_nick(target, nick, addr); nickrec = chanrec == NULL ? NULL : nicklist_find(chanrec, nick); diff --git a/src/fe-common/irc/fe-ignore.c b/src/fe-common/irc/fe-ignore.c index 4920128b..989d91cd 100644 --- a/src/fe-common/irc/fe-ignore.c +++ b/src/fe-common/irc/fe-ignore.c @@ -112,8 +112,9 @@ static void ignore_print(int index, IGNORE_REC *rec) IRCTXT_IGNORE_LINE, index, key != NULL ? key : "", levels != NULL ? levels : "", + rec->regexp ? " -regexp" : "", rec->fullword ? " -word" : "", - rec->regexp ? " -regexp" : ""); + rec->replies ? " -replies" : ""); g_free(key); g_free(levels); } @@ -183,8 +184,9 @@ static void cmd_ignore(const char *data) } rec->pattern = *patternarg == '\0' ? NULL : g_strdup(patternarg); - rec->fullword = stristr(args, "-word") != NULL; rec->regexp = stristr(args, "-regexp") != NULL; + rec->fullword = stristr(args, "-word") != NULL; + rec->replies = stristr(args, "-replies") != NULL; if (rec->level == 0 && rec->except_level == 0) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED, diff --git a/src/fe-common/irc/irc-window-activity.c b/src/fe-common/irc/irc-window-activity.c index 5a9aa86f..13417f02 100644 --- a/src/fe-common/irc/irc-window-activity.c +++ b/src/fe-common/irc/irc-window-activity.c @@ -25,6 +25,7 @@ #include "irc.h" #include "ignore.h" #include "irc-server.h" +#include "nicklist.h" #include "completion.h" #include "windows.h" @@ -59,7 +60,7 @@ static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char * if (window != active_win && !ignore_check(server, nick, addr, target, msg, level)) { /* hilight */ level = !ischannel(*target) || - completion_msgtoyou((SERVER_REC *) server, msg) ? + irc_nick_match(server->nick, msg) ? NEWDATA_MSG_FORYOU : NEWDATA_MSG; if (item != NULL && item->new_data < level) { item->new_data = level; diff --git a/src/irc/core/ignore.c b/src/irc/core/ignore.c index ac4f67ca..b1b9aa1a 100644 --- a/src/irc/core/ignore.c +++ b/src/irc/core/ignore.c @@ -28,11 +28,37 @@ #include "irc.h" #include "masks.h" #include "irc-server.h" +#include "channels.h" +#include "nicklist.h" #include "ignore.h" GSList *ignores; +/* check if `text' contains ignored nick at the start of the line. */ +static int ignore_check_replies(IGNORE_REC *rec, IRC_SERVER_REC *server, + const char *channel, const char *text) +{ + CHANNEL_REC *chanrec; + GSList *nicks, *tmp; + + chanrec = channel_find(server, channel); + if (chanrec == NULL) return FALSE; + + nicks = nicklist_find_multiple(chanrec, rec->mask); + if (nicks == NULL) return FALSE; + + for (tmp = nicks; tmp != NULL; tmp = tmp->next) { + NICK_REC *nick = tmp->data; + + if (irc_nick_match(nick->nick, text)) + return TRUE; + } + g_slist_free(nicks); + + return FALSE; +} + int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host, const char *channel, const char *text, int level) { @@ -53,6 +79,14 @@ int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host, if (rec->servertag != NULL && g_strcasecmp(server->tag, rec->servertag) != 0) continue; + /* channel list */ + if (rec->channels != NULL) { + if (channel == NULL || !ischannel(*channel)) + continue; + if (strarray_find(rec->channels, channel) == -1) + continue; + } + /* nick mask */ mask_len = 0; if (rec->mask != NULL) { @@ -65,15 +99,11 @@ int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host, ok = ((host == NULL || *host == '\0')) ? match_wildcards(rec->mask, nick) : irc_mask_match_address(rec->mask, nick, host); - if (!ok) continue; - } - - /* channel list */ - if (rec->channels != NULL) { - if (channel == NULL || !ischannel(*channel)) - continue; - if (strarray_find(rec->channels, channel) == -1) - continue; + if (!ok) { + /* nick didn't match, but maybe this is a reply to nick? */ + if (!rec->replies || !ignore_check_replies(rec, server, channel, text)) + continue; + } } /* pattern */ @@ -178,6 +208,7 @@ static void ignore_set_config(IGNORE_REC *rec) iconfig_node_set_str(node, "pattern", rec->pattern); if (rec->regexp) config_node_set_bool(node, "regexp", TRUE); if (rec->fullword) config_node_set_bool(node, "fullword", TRUE); + if (rec->replies) config_node_set_bool(node, "replies", TRUE); if (rec->channels != NULL && *rec->channels != NULL) { node = config_node_section(node, "channels", NODE_TYPE_LIST); @@ -273,6 +304,7 @@ static void read_ignores(void) rec->except_level = level2bits(config_node_get_str(node, "except_level", "")); rec->regexp = config_node_get_bool(node, "regexp", FALSE); rec->fullword = config_node_get_bool(node, "fullword", FALSE); + rec->replies = config_node_get_bool(node, "replies", FALSE); node = config_node_section(node, "channels", -1); if (node != NULL) rec->channels = config_node_get_list(node); diff --git a/src/irc/core/ignore.h b/src/irc/core/ignore.h index 17e591d4..699bc445 100644 --- a/src/irc/core/ignore.h +++ b/src/irc/core/ignore.h @@ -12,6 +12,7 @@ typedef struct { int regexp:1; int fullword:1; + int replies:1; /* ignore replies to nick in channel */ } IGNORE_REC; extern GSList *ignores; diff --git a/src/irc/core/nicklist.c b/src/irc/core/nicklist.c index 826ee4a9..ec9dc1ab 100644 --- a/src/irc/core/nicklist.c +++ b/src/irc/core/nicklist.c @@ -197,6 +197,7 @@ int nicklist_compare(NICK_REC *p1, NICK_REC *p2) (a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \ (a) == '|' || (a) == '\\' || (a) == '^') +/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */ char *nick_strip(const char *nick) { char *stripped, *spos; @@ -214,6 +215,31 @@ char *nick_strip(const char *nick) return stripped; } +/* Check is `msg' is meant for `nick'. */ +int irc_nick_match(const char *nick, const char *msg) +{ + char *stripnick, *stripmsg; + int ret, len; + + g_return_val_if_fail(nick != NULL, FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + if (g_strncasecmp(msg, nick, strlen(nick)) == 0 && + !isalnum((int) msg[strlen(nick)])) return TRUE; + + stripnick = nick_strip(nick); + stripmsg = nick_strip(msg); + + len = strlen(stripnick); + ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 && + !isalnum((int) stripmsg[len]) && + (unsigned char) stripmsg[len] < 128; + + g_free(stripnick); + g_free(stripmsg); + return ret; +} + static void event_names_list(const char *data, IRC_SERVER_REC *server) { CHANNEL_REC *chanrec; diff --git a/src/irc/core/nicklist.h b/src/irc/core/nicklist.h index 27fde067..b986be5d 100644 --- a/src/irc/core/nicklist.h +++ b/src/irc/core/nicklist.h @@ -33,10 +33,13 @@ GSList *nicklist_getnicks(CHANNEL_REC *channel); /* Get all the nick records of `nick'. Returns channel, nick, channel, ... */ GSList *nicklist_get_same(IRC_SERVER_REC *server, const char *nick); -/* nick record comparision for sort functions */ +/* Nick record comparision for sort functions */ int nicklist_compare(NICK_REC *p1, NICK_REC *p2); +/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */ char *nick_strip(const char *nick); +/* Check is `msg' is meant for `nick'. */ +int irc_nick_match(const char *nick, const char *msg); void nicklist_init(void); void nicklist_deinit(void);