dovecot: Last change broke pattern matching pretty badly.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Jul 15 06:46:05 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/88f354c17ca5
changeset: 6008:88f354c17ca5
user: Timo Sirainen <tss at iki.fi>
date: Sun Jul 15 06:22:22 2007 +0300
description:
Last change broke pattern matching pretty badly.
diffstat:
1 file changed, 39 insertions(+), 41 deletions(-)
src/lib-imap/imap-match.c | 80 +++++++++++++++++++++------------------------
diffs (146 lines):
diff -r cc1f4688a988 -r 88f354c17ca5 src/lib-imap/imap-match.c
--- a/src/lib-imap/imap-match.c Sun Jul 15 05:33:43 2007 +0300
+++ b/src/lib-imap/imap-match.c Sun Jul 15 06:22:22 2007 +0300
@@ -24,8 +24,7 @@ struct imap_match_glob {
};
struct imap_match_context {
- const char *data, *inboxcase_end;
- const char *pattern;
+ const char *inboxcase_end;
char sep;
bool inboxcase;
@@ -165,20 +164,21 @@ void imap_match_deinit(struct imap_match
*glob = NULL;
}
-#define CMP_CUR_CHR(ctx) \
- (*(ctx)->data == *(ctx)->pattern || \
- (i_toupper(*(ctx)->data) == i_toupper(*(ctx)->pattern) && \
- (ctx)->data < (ctx)->inboxcase_end))
+#define CMP_CUR_CHR(ctx, data, pattern) \
+ (*(data) == *(pattern) || \
+ (i_toupper(*(data)) == i_toupper(*(pattern)) && \
+ (data) < (ctx)->inboxcase_end))
static enum imap_match_result
-match_sub(struct imap_match_context *ctx)
-{
- enum imap_match_result ret, match;
- const char *data = ctx->data, *pattern = ctx->pattern;
+match_sub(struct imap_match_context *ctx, const char **data_p,
+ const char **pattern_p)
+{
+ enum imap_match_result ret, match;
+ const char *data = *data_p, *pattern = *pattern_p;
/* match all non-wildcards */
while (*pattern != '\0' && *pattern != '*' && *pattern != '%') {
- if (!CMP_CUR_CHR(ctx)) {
+ if (!CMP_CUR_CHR(ctx, data, pattern)) {
return *data == '\0' && *pattern == ctx->sep ?
IMAP_MATCH_CHILDREN : IMAP_MATCH_NO;
}
@@ -198,8 +198,8 @@ match_sub(struct imap_match_context *ctx
/* skip over this hierarchy */
while (*data != '\0') {
- if (CMP_CUR_CHR(ctx)) {
- ret = match_sub(ctx);
+ if (CMP_CUR_CHR(ctx, data, pattern)) {
+ ret = match_sub(ctx, &data, &pattern);
if (ret == IMAP_MATCH_YES)
break;
@@ -227,52 +227,52 @@ match_sub(struct imap_match_context *ctx
}
}
- ctx->data = data;
- ctx->pattern = pattern;
+ *data_p = data;
+ *pattern_p = pattern;
return IMAP_MATCH_YES;
}
static enum imap_match_result
-imap_match_pattern(struct imap_match_context *ctx)
-{
- enum imap_match_result ret, match;
-
- ctx->inboxcase_end = ctx->data;
- if (ctx->inboxcase &&
- strncasecmp(ctx->data, inbox, INBOXLEN) == 0 &&
- (ctx->data[INBOXLEN] == '\0' || ctx->data[INBOXLEN] == ctx->sep)) {
+imap_match_pattern(struct imap_match_context *ctx,
+ const char *data, const char *pattern)
+{
+ enum imap_match_result ret, match;
+
+ ctx->inboxcase_end = data;
+ if (ctx->inboxcase && strncasecmp(data, inbox, INBOXLEN) == 0 &&
+ (data[INBOXLEN] == '\0' || data[INBOXLEN] == ctx->sep)) {
/* data begins with INBOX/, use case-insensitive comparison
for it */
ctx->inboxcase_end += INBOXLEN;
}
- if (*ctx->pattern != '*') {
+ if (*pattern != '*') {
/* handle the pattern up to the first '*' */
- ret = match_sub(ctx);
- if (ret != IMAP_MATCH_YES || *ctx->pattern == '\0')
+ ret = match_sub(ctx, &data, &pattern);
+ if (ret != IMAP_MATCH_YES || *pattern == '\0')
return ret;
}
match = IMAP_MATCH_CHILDREN;
- while (*ctx->pattern == '*') {
- ctx->pattern++;
-
- if (*ctx->pattern == '\0')
+ while (*pattern == '*') {
+ pattern++;
+
+ if (*pattern == '\0')
return IMAP_MATCH_YES;
- while (*ctx->data != '\0') {
- if (CMP_CUR_CHR(ctx)) {
- ret = match_sub(ctx);
+ while (*data != '\0') {
+ if (CMP_CUR_CHR(ctx, data, pattern)) {
+ ret = match_sub(ctx, &data, &pattern);
if (ret == IMAP_MATCH_YES)
break;
match |= ret;
}
- ctx->data++;
- }
- }
-
- return *ctx->data == '\0' && *ctx->pattern == '\0' ?
+ data++;
+ }
+ }
+
+ return *data == '\0' && *pattern == '\0' ?
IMAP_MATCH_YES : match;
}
@@ -286,11 +286,9 @@ imap_match(struct imap_match_glob *glob,
match = IMAP_MATCH_NO;
ctx.sep = glob->sep;
for (i = 0; glob->patterns[i].pattern != NULL; i++) {
- ctx.data = data;
- ctx.pattern = glob->patterns[i].pattern;
ctx.inboxcase = glob->patterns[i].inboxcase;
- ret = imap_match_pattern(&ctx);
+ ret = imap_match_pattern(&ctx, data, glob->patterns[i].pattern);
if (ret == IMAP_MATCH_YES)
return IMAP_MATCH_YES;
More information about the dovecot-cvs
mailing list