Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5840:f4dac54df44e HEAD
s/mask/pattern/
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 29 Jun 2007 21:21:44 +0300 |
parents | 978722ad6184 |
children | 1983995ae243 |
files | src/lib-imap/imap-match.c src/lib-imap/imap-match.h |
diffstat | 2 files changed, 47 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-imap/imap-match.c Fri Jun 29 19:41:22 2007 +0300 +++ b/src/lib-imap/imap-match.c Fri Jun 29 21:21:44 2007 +0300 @@ -16,7 +16,7 @@ const char *inboxcase_end; char sep_char; - char mask[1]; + char pattern[1]; }; /* name of "INBOX" - must not have repeated substrings */ @@ -24,35 +24,36 @@ #define INBOXLEN (sizeof(inbox) - 1) struct imap_match_glob * -imap_match_init(pool_t pool, const char *mask, bool inboxcase, char separator) +imap_match_init(pool_t pool, const char *pattern, + bool inboxcase, char separator) { struct imap_match_glob *glob; const char *p, *inboxp; char *dst; /* +1 from struct */ - glob = p_malloc(pool, sizeof(struct imap_match_glob) + strlen(mask)); + glob = p_malloc(pool, sizeof(struct imap_match_glob) + strlen(pattern)); glob->pool = pool; glob->sep_char = separator; - /* @UNSAFE: compress the mask */ - dst = glob->mask; - while (*mask != '\0') { - if (*mask == '*' || *mask == '%') { + /* @UNSAFE: compress the pattern */ + dst = glob->pattern; + while (*pattern != '\0') { + if (*pattern == '*' || *pattern == '%') { /* remove duplicate hierarchy wildcards */ - while (*mask == '%') mask++; + while (*pattern == '%') pattern++; /* "%*" -> "*" */ - if (*mask == '*') { + if (*pattern == '*') { /* remove duplicate wildcards */ - while (*mask == '*' || *mask == '%') - mask++; + while (*pattern == '*' || *pattern == '%') + pattern++; *dst++ = '*'; } else { *dst++ = '%'; } } else { - *dst++ = *mask++; + *dst++ = *pattern++; } } *dst++ = '\0'; @@ -61,7 +62,7 @@ /* check if we could be comparing INBOX. */ inboxp = inbox; glob->inboxcase = TRUE; - p = glob->mask; + p = glob->pattern; for (; *p != '\0' && *p != '*' && *p != separator; p++) { if (*p != '%') { inboxp = strchr(inboxp, i_toupper(*p)); @@ -93,43 +94,43 @@ } static inline bool cmp_chr(const struct imap_match_glob *glob, - const char *data, char maskchr) + const char *data, char patternchr) { - return *data == maskchr || + return *data == patternchr || (glob->inboxcase_end != NULL && data < glob->inboxcase_end && - i_toupper(*data) == i_toupper(maskchr)); + i_toupper(*data) == i_toupper(patternchr)); } static enum imap_match_result match_sub(const struct imap_match_glob *glob, const char **data_p, - const char **mask_p) + const char **pattern_p) { - const char *mask, *data; + const char *pattern, *data; enum imap_match_result ret, best_ret; - data = *data_p; mask = *mask_p; + data = *data_p; pattern = *pattern_p; - while (*mask != '\0' && *mask != '*' && *mask != '%') { - if (!cmp_chr(glob, data, *mask)) { - return *data == '\0' && *mask == glob->sep_char ? + while (*pattern != '\0' && *pattern != '*' && *pattern != '%') { + if (!cmp_chr(glob, data, *pattern)) { + return *data == '\0' && *pattern == glob->sep_char ? IMAP_MATCH_CHILDREN : IMAP_MATCH_NO; } - data++; mask++; + data++; pattern++; } best_ret = IMAP_MATCH_NO; - while (*mask == '%') { - mask++; + while (*pattern == '%') { + pattern++; - if (*mask == '\0') { + if (*pattern == '\0') { while (*data != '\0' && *data != glob->sep_char) data++; break; } while (*data != '\0') { - if (cmp_chr(glob, data, *mask)) { - ret = match_sub(glob, &data, &mask); + if (cmp_chr(glob, data, *pattern)) { + ret = match_sub(glob, &data, &pattern); if (ret > 0) break; @@ -146,27 +147,27 @@ } } - if (*mask != '*') { - if (*data == '\0' && *mask != '\0') - return *mask == glob->sep_char ? + if (*pattern != '*') { + if (*data == '\0' && *pattern != '\0') + return *pattern == glob->sep_char ? IMAP_MATCH_CHILDREN : best_ret; if (*data != '\0') { return best_ret != IMAP_MATCH_NO || - *mask != '\0' || *data != glob->sep_char ? + *pattern != '\0' || *data != glob->sep_char ? best_ret : IMAP_MATCH_PARENT; } } *data_p = data; - *mask_p = mask; + *pattern_p = pattern; return IMAP_MATCH_YES; } enum imap_match_result imap_match(struct imap_match_glob *glob, const char *data) { - const char *mask; + const char *pattern; int ret; if (glob->inboxcase && @@ -176,24 +177,24 @@ else glob->inboxcase_end = NULL; - mask = glob->mask; - if (*mask != '*') { - if ((ret = match_sub(glob, &data, &mask)) <= 0) + pattern = glob->pattern; + if (*pattern != '*') { + if ((ret = match_sub(glob, &data, &pattern)) <= 0) return ret; - if (*mask == '\0') + if (*pattern == '\0') return IMAP_MATCH_YES; } - while (*mask == '*') { - mask++; + while (*pattern == '*') { + pattern++; - if (*mask == '\0') + if (*pattern == '\0') return IMAP_MATCH_YES; while (*data != '\0') { - if (cmp_chr(glob, data, *mask)) { - if (match_sub(glob, &data, &mask) > 0) + if (cmp_chr(glob, data, *pattern)) { + if (match_sub(glob, &data, &pattern) > 0) break; } @@ -201,6 +202,6 @@ } } - return *data == '\0' && *mask == '\0' ? + return *data == '\0' && *pattern == '\0' ? IMAP_MATCH_YES : IMAP_MATCH_CHILDREN; }
--- a/src/lib-imap/imap-match.h Fri Jun 29 19:41:22 2007 +0300 +++ b/src/lib-imap/imap-match.h Fri Jun 29 21:21:44 2007 +0300 @@ -19,7 +19,8 @@ /* If inboxcase is TRUE, the "INBOX" string at the beginning of line is compared case-insensitively */ struct imap_match_glob * -imap_match_init(pool_t pool, const char *mask, bool inboxcase, char separator); +imap_match_init(pool_t pool, const char *pattern, + bool inboxcase, char separator); void imap_match_deinit(struct imap_match_glob **glob);