mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
irc_nick_match() should now work better for checking if nick at the
start of the message was really meant for you. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@677 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
3d627ca527
commit
bae879de22
@ -30,9 +30,12 @@
|
|||||||
#include "servers.h"
|
#include "servers.h"
|
||||||
|
|
||||||
#define isnickchar(a) \
|
#define isnickchar(a) \
|
||||||
(isalnum((int) (a)) || (a) == '`' || (a) == '-' || (a) == '_' || \
|
(isalnum((int) (a)) || (a) == '`' || (a) == '-' || (a) == '_' || \
|
||||||
(a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
|
(a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
|
||||||
(a) == '|' || (a) == '\\' || (a) == '^')
|
(a) == '|' || (a) == '\\' || (a) == '^')
|
||||||
|
|
||||||
|
#define isalnumhigh(a) \
|
||||||
|
(isalnum(a) || (unsigned char) (a) >= 128)
|
||||||
|
|
||||||
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
|
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
|
||||||
char *irc_nick_strip(const char *nick)
|
char *irc_nick_strip(const char *nick)
|
||||||
@ -56,27 +59,40 @@ char *irc_nick_strip(const char *nick)
|
|||||||
/* Check is `msg' is meant for `nick'. */
|
/* Check is `msg' is meant for `nick'. */
|
||||||
int irc_nick_match(const char *nick, const char *msg)
|
int irc_nick_match(const char *nick, const char *msg)
|
||||||
{
|
{
|
||||||
char *stripnick, *stripmsg;
|
int len;
|
||||||
int ret, len;
|
|
||||||
|
|
||||||
g_return_val_if_fail(nick != NULL, FALSE);
|
g_return_val_if_fail(nick != NULL, FALSE);
|
||||||
g_return_val_if_fail(msg != NULL, FALSE);
|
g_return_val_if_fail(msg != NULL, FALSE);
|
||||||
|
|
||||||
|
/* first check for identical match */
|
||||||
len = strlen(nick);
|
len = strlen(nick);
|
||||||
if (g_strncasecmp(msg, nick, len) == 0 && !isalnum((int) msg[len]))
|
if (g_strncasecmp(msg, nick, len) == 0 && !isalnumhigh((int) msg[len]))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
stripnick = irc_nick_strip(nick);
|
/* check if it matches for alphanumeric parts of nick */
|
||||||
stripmsg = irc_nick_strip(msg);
|
while (*nick != '\0' && *msg != '\0') {
|
||||||
|
if (*nick == *msg) {
|
||||||
|
/* total match */
|
||||||
|
msg++;
|
||||||
|
} else if (isalnum(*msg) && !isalnum(*nick)) {
|
||||||
|
/* some strange char in your nick, pass it */
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
|
||||||
len = strlen(stripnick);
|
nick++;
|
||||||
ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 &&
|
}
|
||||||
!isalnum((int) stripmsg[len]) &&
|
|
||||||
(unsigned char) stripmsg[len] < 128;
|
|
||||||
|
|
||||||
g_free(stripnick);
|
if (isalnumhigh(*msg)) {
|
||||||
g_free(stripmsg);
|
/* message continues with another alphanumeric character,
|
||||||
return ret;
|
it isn't for us. */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove all the non-alphanumeric characters at the end of
|
||||||
|
the nick and check if message matched that far. */
|
||||||
|
while (*nick != '\0' && !isalnum(*nick)) nick++;
|
||||||
|
|
||||||
|
return *nick == '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_names_list(const char *data, SERVER_REC *server)
|
static void event_names_list(const char *data, SERVER_REC *server)
|
||||||
|
Loading…
Reference in New Issue
Block a user