From 68303ed788d3f92acc1bdf6798ab727228e0a190 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 5 Aug 2014 23:08:29 +0200
Subject: kike: fix wildcard matching
It wasn't IRC case-insensitive.
---
src/kike.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/src/kike.c b/src/kike.c
index 738e828..0def999 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -507,6 +507,17 @@ irc_get_text (struct server_context *ctx, int id, const char *def)
return catgets (ctx->catalog, 1, id, def);
}
+static int
+irc_fnmatch (const char *pattern, const char *string)
+{
+ size_t pattern_size = strlen (pattern) + 1;
+ size_t string_size = strlen (string) + 1;
+ char x_pattern[pattern_size], x_string[string_size];
+ irc_strxfrm (x_pattern, pattern, pattern_size);
+ irc_strxfrm (x_string, string, string_size);
+ return fnmatch (x_pattern, x_string, 0);
+}
+
// --- Channels ----------------------------------------------------------------
static struct channel_user *
@@ -709,20 +720,16 @@ irc_close_link (struct client *c, const char *reason)
static bool
client_in_mask_list (const struct client *c, const struct str_vector *mask)
{
- struct str client;
- str_init (&client);
- str_append_printf (&client, "%s!%s@%s",
+ char *client = xstrdup_printf ("%s!%s@%s",
c->nickname, c->username, c->hostname);
- irc_strxfrm (client.str, client.str, client.len);
bool result = false;
for (size_t i = 0; i < mask->len; i++)
- // FIXME: irc_strxfrm() for the mask (save in canonical format?)
- if (!fnmatch (client.str, mask->vector[i], 0))
+ if (!irc_fnmatch (client, mask->vector[i]))
{
result = true;
break;
}
- str_free (&client);
+ free (client);
return result;
}
@@ -1507,10 +1514,10 @@ irc_match_send_rpl_whoreply (struct client *c, struct client *target,
if ((target->mode & IRC_USER_MODE_INVISIBLE) && !is_roommate)
return;
- if (fnmatch (mask, target->hostname, 0)
- && fnmatch (mask, target->nickname, 0)
- && fnmatch (mask, target->realname, 0)
- && fnmatch (mask, c->ctx->server_name, 0))
+ if (irc_fnmatch (mask, target->hostname)
+ && irc_fnmatch (mask, target->nickname)
+ && irc_fnmatch (mask, target->realname)
+ && irc_fnmatch (mask, c->ctx->server_name))
return;
// Try to find a channel they're on that's visible to us
--
cgit v1.2.3-70-g09d2