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
1 Subproject commit 42f4712085b40173eaea58e14b1a579291a6fe3a 1 Subproject commit fd86bf7d44b0c970771830692ae7491447ebe8b1
......
1 # List of gnulib modules needed for GNU mailutils. 1 # List of gnulib modules needed for GNU mailutils.
2 # A module name per line. Empty lines and comments are ignored. 2 # A module name per line. Empty lines and comments are ignored.
3 3
4 # FIXME: fnmatch, regex and glob are used by libmailutils... 4 # FIXME: regex and glob are used by libmailutils...
5 5
6 autobuild 6 autobuild
7 crypto/des 7 crypto/des
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
25 #include <unistd.h> 25 #include <unistd.h>
26 #include <string.h> 26 #include <string.h>
27 #include <sieve-priv.h> 27 #include <sieve-priv.h>
28 #include <fnmatch.h>
29 #include <regex.h> 28 #include <regex.h>
30 #include <mailutils/cctype.h> 29 #include <mailutils/cctype.h>
31 #include <mailutils/cstr.h> 30 #include <mailutils/cstr.h>
...@@ -102,6 +101,25 @@ compile_pattern (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, int flags) ...@@ -102,6 +101,25 @@ compile_pattern (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, int flags)
102 pattern->rx = preg; 101 pattern->rx = preg;
103 } 102 }
104 103
104 static void
105 compile_wildcard (mu_sieve_machine_t mach, mu_sieve_string_t *pattern,
106 int flags)
107 {
108 int rc;
109 regex_t *preg;
110
111 if (pattern->rx)
112 return;
113 preg = mu_sieve_malloc (mach, sizeof (*preg));
114 rc = mu_glob_compile (preg, pattern->orig, flags);
115 if (rc)
116 {
117 mu_sieve_error (mach, _("can't compile pattern"));
118 mu_sieve_abort (mach);
119 }
120 pattern->rx = preg;
121 }
122
105 static int 123 static int
106 comp_false (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, 124 comp_false (mu_sieve_machine_t mach, mu_sieve_string_t *pattern,
107 const char *text) 125 const char *text)
...@@ -263,7 +281,8 @@ static int ...@@ -263,7 +281,8 @@ static int
263 i_octet_matches (mu_sieve_machine_t mach, mu_sieve_string_t *pattern, 281 i_octet_matches (mu_sieve_machine_t mach, mu_sieve_string_t *pattern,
264 const char *text) 282 const char *text)
265 { 283 {
266 return fnmatch (pattern->orig, text, 0) == 0; 284 compile_wildcard (mach, pattern, 0);
285 return regexec ((regex_t *)pattern->rx, text, 0, NULL, 0) == 0;
267 } 286 }
268 287
269 static int 288 static int
...@@ -300,7 +319,8 @@ static int ...@@ -300,7 +319,8 @@ static int
300 i_ascii_casemap_matches (mu_sieve_machine_t mach, 319 i_ascii_casemap_matches (mu_sieve_machine_t mach,
301 mu_sieve_string_t *pattern, const char *text) 320 mu_sieve_string_t *pattern, const char *text)
302 { 321 {
303 return fnmatch (pattern->orig, text, FNM_CASEFOLD) == 0; 322 compile_wildcard (mach, pattern, MU_GLOBF_ICASE);
323 return regexec ((regex_t *)pattern->rx, text, 0, NULL, 0) == 0;
304 } 324 }
305 325
306 static int 326 static int
......