mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 08:43:13 +02:00
irc: fix conversion of mask to regex in ignore
This commit is contained in:
@@ -1640,7 +1640,8 @@ irc_command_ignore (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_irc_ignore *ptr_ignore;
|
||||
char *mask, *regex, *ptr_regex, *server, *channel, *error;
|
||||
char *mask, *regex, *regex2, *ptr_regex, *server, *channel, *error;
|
||||
int length;
|
||||
long number;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -1685,19 +1686,35 @@ irc_command_ignore (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
server = (argc > 3) ? argv[3] : NULL;
|
||||
channel = (argc > 4) ? argv[4] : NULL;
|
||||
|
||||
regex = NULL;
|
||||
regex2 = NULL;
|
||||
|
||||
if (strncmp (mask, "re:", 3) == 0)
|
||||
{
|
||||
regex = NULL;
|
||||
ptr_regex = mask + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* convert mask to regex (escape regex special chars) */
|
||||
regex = weechat_string_mask_to_regex (mask);
|
||||
ptr_regex = (regex) ? regex : mask;
|
||||
}
|
||||
|
||||
/* add "^" and "$" around regex */
|
||||
length = 1 + strlen (ptr_regex) + 1 + 1;
|
||||
regex2 = malloc (length);
|
||||
if (regex2)
|
||||
{
|
||||
snprintf (regex2, length, "^%s$", ptr_regex);
|
||||
ptr_regex = regex2;
|
||||
}
|
||||
|
||||
if (irc_ignore_search (ptr_regex, server, channel))
|
||||
{
|
||||
if (regex)
|
||||
free (regex);
|
||||
if (regex2)
|
||||
free (regex2);
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: ignore already exists"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
@@ -1708,6 +1725,8 @@ irc_command_ignore (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
|
||||
if (regex)
|
||||
free (regex);
|
||||
if (regex2)
|
||||
free (regex2);
|
||||
|
||||
if (ptr_ignore)
|
||||
{
|
||||
|
||||
@@ -126,37 +126,18 @@ irc_ignore_new (const char *mask, const char *server, const char *channel)
|
||||
{
|
||||
struct t_irc_ignore *new_ignore;
|
||||
regex_t *regex;
|
||||
char *complete_mask;
|
||||
|
||||
if (!mask || !mask[0])
|
||||
return NULL;
|
||||
|
||||
complete_mask = malloc (1 + strlen (mask) + 1 + 1);
|
||||
if (!complete_mask)
|
||||
return NULL;
|
||||
|
||||
if (mask[0] == '^')
|
||||
strcpy (complete_mask, mask);
|
||||
else
|
||||
{
|
||||
strcpy (complete_mask, "^");
|
||||
strcat (complete_mask, mask);
|
||||
}
|
||||
if (complete_mask[strlen (complete_mask) - 1] != '$')
|
||||
strcat (complete_mask, "$");
|
||||
|
||||
regex = malloc (sizeof (*regex));
|
||||
if (!regex)
|
||||
{
|
||||
free (complete_mask);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (weechat_string_regcomp (regex, complete_mask,
|
||||
if (weechat_string_regcomp (regex, mask,
|
||||
REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
|
||||
{
|
||||
free (regex);
|
||||
free (complete_mask);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -164,7 +145,7 @@ irc_ignore_new (const char *mask, const char *server, const char *channel)
|
||||
if (new_ignore)
|
||||
{
|
||||
new_ignore->number = (last_irc_ignore) ? last_irc_ignore->number + 1 : 1;
|
||||
new_ignore->mask = strdup (complete_mask);
|
||||
new_ignore->mask = strdup (mask);
|
||||
new_ignore->regex_mask = regex;
|
||||
new_ignore->server = (server) ? strdup (server) : strdup ("*");
|
||||
new_ignore->channel = (channel) ? strdup (channel) : strdup ("*");
|
||||
@@ -179,8 +160,6 @@ irc_ignore_new (const char *mask, const char *server, const char *channel)
|
||||
new_ignore->next_ignore = NULL;
|
||||
}
|
||||
|
||||
free (complete_mask);
|
||||
|
||||
return new_ignore;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user