aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-08-05 23:08:29 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-08-05 23:08:29 +0200
commit68303ed788d3f92acc1bdf6798ab727228e0a190 (patch)
tree7f1466835de15edff6f6241613b165055669578b
parent9b2b3844e2e8f8ff1f22fc0fcb804615214f9a7a (diff)
downloadxK-68303ed788d3f92acc1bdf6798ab727228e0a190.tar.gz
xK-68303ed788d3f92acc1bdf6798ab727228e0a190.tar.xz
xK-68303ed788d3f92acc1bdf6798ab727228e0a190.zip
kike: fix wildcard matching
It wasn't IRC case-insensitive.
-rw-r--r--src/kike.c29
1 files 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