dovecot-2.0: lib-imap: Added imap_match_globs_equal().
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 28 22:09:22 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/9d411eeb7998
changeset: 11195:9d411eeb7998
user: Timo Sirainen <tss at iki.fi>
date: Wed Apr 28 17:49:16 2010 +0300
description:
lib-imap: Added imap_match_globs_equal().
diffstat:
src/lib-imap/imap-match.c | 18 ++++++++++++++++++
src/lib-imap/imap-match.h | 4 ++++
src/lib-imap/test-imap-match.c | 33 ++++++++++++++++++++++++++++++++-
3 files changed, 54 insertions(+), 1 deletions(-)
diffs (110 lines):
diff -r bb8ccf1ae2ac -r 9d411eeb7998 src/lib-imap/imap-match.c
--- a/src/lib-imap/imap-match.c Wed Apr 28 17:36:25 2010 +0300
+++ b/src/lib-imap/imap-match.c Wed Apr 28 17:49:16 2010 +0300
@@ -209,6 +209,24 @@
}
};
+bool imap_match_globs_equal(const struct imap_match_glob *glob1,
+ const struct imap_match_glob *glob2)
+{
+ const struct imap_match_pattern *p1 = glob1->patterns;
+ const struct imap_match_pattern *p2 = glob2->patterns;
+
+ if (glob1->sep != glob2->sep)
+ return FALSE;
+
+ for (; p1->pattern != NULL && p2->pattern != NULL; p1++, p2++) {
+ if (strcmp(p1->pattern, p2->pattern) != 0)
+ return FALSE;
+ if (p1->inboxcase != p2->inboxcase)
+ return FALSE;
+ }
+ return p1->pattern == p2->pattern;
+}
+
#define CMP_CUR_CHR(ctx, data, pattern) \
(*(data) == *(pattern) || \
(i_toupper(*(data)) == i_toupper(*(pattern)) && \
diff -r bb8ccf1ae2ac -r 9d411eeb7998 src/lib-imap/imap-match.h
--- a/src/lib-imap/imap-match.h Wed Apr 28 17:36:25 2010 +0300
+++ b/src/lib-imap/imap-match.h Wed Apr 28 17:49:16 2010 +0300
@@ -31,6 +31,10 @@
struct imap_match_glob *
imap_match_dup(pool_t pool, const struct imap_match_glob *glob);
+/* Returns TRUE if two globs were created with same init() parameters
+ (but inboxcase is ignored if no patterns can match INBOX) */
+bool imap_match_globs_equal(const struct imap_match_glob *glob1,
+ const struct imap_match_glob *glob2);
enum imap_match_result
imap_match(struct imap_match_glob *glob, const char *data);
diff -r bb8ccf1ae2ac -r 9d411eeb7998 src/lib-imap/test-imap-match.c
--- a/src/lib-imap/test-imap-match.c Wed Apr 28 17:36:25 2010 +0300
+++ b/src/lib-imap/test-imap-match.c Wed Apr 28 17:49:16 2010 +0300
@@ -52,7 +52,7 @@
unsigned int i;
pool_t pool;
- pool = pool_alloconly_create_clean("test", 1024);
+ pool = pool_alloconly_create_clean("imap match", 1024);
/* first try tests without inboxcasing */
test_begin("imap match");
@@ -62,6 +62,7 @@
test_assert(imap_match(glob, test[i].input) == test[i].result);
glob2 = imap_match_dup(default_pool, glob);
+ test_assert(imap_match_globs_equal(glob, glob2));
p_clear(pool);
/* test the dup after clearing first one's memory */
@@ -76,6 +77,7 @@
test_assert(imap_match(glob, inbox_test[i].input) == inbox_test[i].result);
glob2 = imap_match_dup(default_pool, glob);
+ test_assert(imap_match_globs_equal(glob, glob2));
p_clear(pool);
/* test the dup after clearing first one's memory */
@@ -86,10 +88,39 @@
test_end();
}
+static void test_imap_match_globs_equal(void)
+{
+ struct imap_match_glob *glob;
+ pool_t pool;
+
+ pool = pool_alloconly_create_clean("imap match globs equal", 1024);
+ test_begin("imap match globs equal");
+
+ glob = imap_match_init(pool, "1", FALSE, '/');
+ test_assert(imap_match_globs_equal(glob,
+ imap_match_init(pool, "1", FALSE, '/')));
+ test_assert(imap_match_globs_equal(glob,
+ imap_match_init(pool, "1", TRUE, '/')));
+ test_assert(!imap_match_globs_equal(glob,
+ imap_match_init(pool, "1", FALSE, '.')));
+ test_assert(!imap_match_globs_equal(glob,
+ imap_match_init(pool, "11", FALSE, '/')));
+
+ glob = imap_match_init(pool, "in%", TRUE, '/');
+ test_assert(!imap_match_globs_equal(glob,
+ imap_match_init(pool, "in%", FALSE, '/')));
+ test_assert(!imap_match_globs_equal(glob,
+ imap_match_init(pool, "In%", TRUE, '/')));
+
+ pool_unref(&pool);
+ test_end();
+}
+
int main(void)
{
static void (*test_functions[])(void) = {
test_imap_match,
+ test_imap_match_globs_equal,
NULL
};
return test_run(test_functions);
More information about the dovecot-cvs
mailing list