Commit cab2fd5c cab2fd5c0479d16a3dcd746c98de8be771a8963d by Sergey Poznyakoff

Use glob API in sieve

* libmu_sieve/comparator.c: Use mu_glob_compile instead of fnmatch.
1 parent df608ed0
gint @ fd86bf7d
Subproject commit 42f4712085b40173eaea58e14b1a579291a6fe3a
Subproject commit fd86bf7d44b0c970771830692ae7491447ebe8b1
......
# List of gnulib modules needed for GNU mailutils.
# A module name per line. Empty lines and comments are ignored.
# FIXME: fnmatch, regex and glob are used by libmailutils...
# FIXME: regex and glob are used by libmailutils...
autobuild
crypto/des
......
......@@ -25,7 +25,6 @@
#include <unistd.h>
#include <string.h>
#include <sieve-priv.h>
#include <fnmatch.h>
#include <regex.h>
#include <mailutils/cctype.h>
#include <mailutils/cstr.h>
......@@ -102,6 +101,25 @@ compile_pattern (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, int flags)
pattern->rx = preg;
}
static void
compile_wildcard (mu_sieve_machine_t mach, mu_sieve_string_t *pattern,
int flags)
{
int rc;
regex_t *preg;
if (pattern->rx)
return;
preg = mu_sieve_malloc (mach, sizeof (*preg));
rc = mu_glob_compile (preg, pattern->orig, flags);
if (rc)
{
mu_sieve_error (mach, _("can't compile pattern"));
mu_sieve_abort (mach);
}
pattern->rx = preg;
}
static int
comp_false (mu_sieve_machine_t mach, mu_sieve_string_t *pattern,
const char *text)
......@@ -263,7 +281,8 @@ static int
i_octet_matches (mu_sieve_machine_t mach, mu_sieve_string_t *pattern,
const char *text)
{
return fnmatch (pattern->orig, text, 0) == 0;
compile_wildcard (mach, pattern, 0);
return regexec ((regex_t *)pattern->rx, text, 0, NULL, 0) == 0;
}
static int
......@@ -300,7 +319,8 @@ static int
i_ascii_casemap_matches (mu_sieve_machine_t mach,
mu_sieve_string_t *pattern, const char *text)
{
return fnmatch (pattern->orig, text, FNM_CASEFOLD) == 0;
compile_wildcard (mach, pattern, MU_GLOBF_ICASE);
return regexec ((regex_t *)pattern->rx, text, 0, NULL, 0) == 0;
}
static int
......