summaryrefslogtreecommitdiff
path: root/src/irc/core
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-09-26 22:24:53 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-09-26 22:24:53 +0000
commitbae879de223ea2f6e3f2ad69b70ad19ba905354d (patch)
tree89fe06c3682edaf966d15b265b6fc980c8d3c78c /src/irc/core
parent3d627ca527c40f82911058a81df3811ee2cac6a3 (diff)
downloadirssi-bae879de223ea2f6e3f2ad69b70ad19ba905354d.zip
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
Diffstat (limited to 'src/irc/core')
-rw-r--r--src/irc/core/irc-nicklist.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/irc/core/irc-nicklist.c b/src/irc/core/irc-nicklist.c
index e8eb14f2..3b3dcd8a 100644
--- a/src/irc/core/irc-nicklist.c
+++ b/src/irc/core/irc-nicklist.c
@@ -30,9 +30,12 @@
#include "servers.h"
#define isnickchar(a) \
- (isalnum((int) (a)) || (a) == '`' || (a) == '-' || (a) == '_' || \
- (a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \
- (a) == '|' || (a) == '\\' || (a) == '^')
+ (isalnum((int) (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 */
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'. */
int irc_nick_match(const char *nick, const char *msg)
{
- char *stripnick, *stripmsg;
- int ret, len;
+ int len;
g_return_val_if_fail(nick != NULL, FALSE);
g_return_val_if_fail(msg != NULL, FALSE);
+ /* first check for identical match */
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;
- stripnick = irc_nick_strip(nick);
- stripmsg = irc_nick_strip(msg);
+ /* check if it matches for alphanumeric parts of nick */
+ 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;
+
+ nick++;
+ }
+
+ if (isalnumhigh(*msg)) {
+ /* message continues with another alphanumeric character,
+ it isn't for us. */
+ return FALSE;
+ }
- len = strlen(stripnick);
- ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 &&
- !isalnum((int) stripmsg[len]) &&
- (unsigned char) stripmsg[len] < 128;
+ /* 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++;
- g_free(stripnick);
- g_free(stripmsg);
- return ret;
+ return *nick == '\0';
}
static void event_names_list(const char *data, SERVER_REC *server)