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
This commit is contained in:
Timo Sirainen 2000-06-04 12:38:28 +00:00 committed by cras
commit 8562737548
9 changed files with 80 additions and 41 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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);