diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ignore.c | 16 | ||||
-rw-r--r-- | src/core/ignore.h | 7 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/core/ignore.c b/src/core/ignore.c index 5c37fe45..9ff6ce98 100644 --- a/src/core/ignore.c +++ b/src/core/ignore.c @@ -122,9 +122,14 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host, if (patt_len <= best_patt) continue; } - ok = rec->regexp ? regexp_match(text, rec->pattern) : - rec->fullword ? stristr_full(text, rec->pattern) != NULL : - stristr(text, rec->pattern) != NULL; + if (rec->regexp) { + ok = !rec->regexp_compiled ? FALSE : + regexec(&rec->preg, text, 0, NULL, 0) == 0; + } else { + ok = rec->fullword ? + stristr_full(text, rec->pattern) != NULL : + stristr(text, rec->pattern) != NULL; + } if (!ok) continue; } @@ -257,6 +262,10 @@ static void ignore_remove_config(IGNORE_REC *rec) void ignore_add_rec(IGNORE_REC *rec) { + rec->regexp_compiled = !rec->regexp || rec->pattern == NULL ? FALSE : + regcomp(&rec->preg, rec->pattern, + REG_EXTENDED|REG_ICASE|REG_NOSUB) == 0; + ignores = g_slist_append(ignores, rec); ignore_set_config(rec); @@ -268,6 +277,7 @@ static void ignore_destroy(IGNORE_REC *rec) ignores = g_slist_remove(ignores, rec); signal_emit("ignore destroyed", 1, rec); + if (rec->regexp_compiled) regfree(&rec->preg); if (rec->time_tag > 0) g_source_remove(rec->time_tag); if (rec->channels != NULL) g_strfreev(rec->channels); g_free_not_null(rec->mask); diff --git a/src/core/ignore.h b/src/core/ignore.h index c52e09ba..6c336c00 100644 --- a/src/core/ignore.h +++ b/src/core/ignore.h @@ -2,6 +2,9 @@ #define __IGNORE_H #include "servers.h" +#ifdef HAVE_REGEX_H +# include <regex.h> +#endif typedef struct { char *mask; /* nick mask */ @@ -18,6 +21,10 @@ typedef struct { int regexp:1; int fullword:1; int replies:1; /* ignore replies to nick in channel */ +#ifdef HAVE_REGEX_H + int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */ + regex_t preg; +#endif } IGNORE_REC; extern GSList *ignores; |