summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-02-26 21:15:14 +0100
committerSebastien Helleu <flashcode@flashtux.org>2013-02-26 21:15:14 +0100
commit0e641e0c45607dffd7bd4c7a9961646ea8f92392 (patch)
tree805c150e6bd912bba07de6033650959f665da514 /src
parentb84f6b5a1ba937e4cd312d0d62c8007958613678 (diff)
downloadweechat-0e641e0c45607dffd7bd4c7a9961646ea8f92392.zip
irc: fix conversion of mask to regex in ignore
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-command.c23
-rw-r--r--src/plugins/irc/irc-ignore.c25
2 files changed, 23 insertions, 25 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 9c27fa4a7..5b9b9c736 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -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)
{
diff --git a/src/plugins/irc/irc-ignore.c b/src/plugins/irc/irc-ignore.c
index f4345cc7f..d37fdc345 100644
--- a/src/plugins/irc/irc-ignore.c
+++ b/src/plugins/irc/irc-ignore.c
@@ -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;
}