dovecot-1.2: Maildir keywords handling code cleanup.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Jan 15 22:12:12 EET 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/1efdf705203c
changeset: 8629:1efdf705203c
user: Timo Sirainen <tss at iki.fi>
date: Thu Jan 15 15:05:58 2009 -0500
description:
Maildir keywords handling code cleanup.
diffstat:
1 file changed, 19 insertions(+), 20 deletions(-)
src/lib-storage/index/maildir/maildir-keywords.c | 39 ++++++++++------------
diffs (98 lines):
diff -r e85c7cb22ad7 -r 1efdf705203c src/lib-storage/index/maildir/maildir-keywords.c
--- a/src/lib-storage/index/maildir/maildir-keywords.c Wed Jan 14 15:14:11 2009 -0500
+++ b/src/lib-storage/index/maildir/maildir-keywords.c Thu Jan 15 15:05:58 2009 -0500
@@ -190,24 +190,27 @@ static int maildir_keywords_sync(struct
}
static int
-maildir_keywords_lookup(struct maildir_keywords *mk, const char *name)
+maildir_keywords_lookup(struct maildir_keywords *mk, const char *name,
+ unsigned int *chridx_r)
{
void *p;
p = hash_table_lookup(mk->hash, name);
if (p == NULL) {
if (mk->synced)
- return -1;
+ return 0;
if (maildir_keywords_sync(mk) < 0)
return -1;
+ i_assert(mk->synced);
p = hash_table_lookup(mk->hash, name);
if (p == NULL)
- return -1;
- }
-
- return POINTER_CAST_TO(p, int)-1;
+ return 0;
+ }
+
+ *chridx_r = POINTER_CAST_TO(p, int)-1;
+ return 1;
}
static void
@@ -229,19 +232,15 @@ maildir_keywords_create(struct maildir_k
}
static int
-maildir_keywords_lookup_or_create(struct maildir_keywords *mk, const char *name)
+maildir_keywords_lookup_or_create(struct maildir_keywords *mk, const char *name,
+ unsigned int *chridx_r)
{
const char *const *keywords;
unsigned int i, count;
- int idx;
-
- idx = maildir_keywords_lookup(mk, name);
- if (idx >= 0)
- return idx;
- if (!mk->synced) {
- /* we couldn't open the dovecot-keywords file. */
- return -1;
- }
+ int ret;
+
+ if ((ret = maildir_keywords_lookup(mk, name, chridx_r)) != 0)
+ return ret;
/* see if we are full */
keywords = array_get(&mk->list, &count);
@@ -273,6 +272,7 @@ maildir_keywords_idx(struct maildir_keyw
if (maildir_keywords_sync(mk) < 0)
return NULL;
+ i_assert(mk->synced);
keywords = array_get(&mk->list, &count);
}
@@ -435,7 +435,7 @@ unsigned int maildir_keywords_char_idx(s
if (name == NULL) {
/* name is lost. just generate one ourself. */
name = t_strdup_printf("unknown-%u", chridx);
- while (maildir_keywords_lookup(ctx->mk, name) >= 0) {
+ while (maildir_keywords_lookup(ctx->mk, name, &idx) > 0) {
/* don't create a duplicate name.
keep changing the name until it doesn't exist */
name = t_strconcat(name, "?", NULL);
@@ -453,15 +453,14 @@ char maildir_keywords_idx_char(struct ma
{
const char *const *name_p;
char *chr_p;
- int chridx;
+ unsigned int chridx;
chr_p = array_idx_modifiable(&ctx->idx_to_chr, idx);
if (*chr_p != '\0')
return *chr_p;
name_p = array_idx(ctx->keywords, idx);
- chridx = maildir_keywords_lookup_or_create(ctx->mk, *name_p);
- if (chridx < 0)
+ if (maildir_keywords_lookup_or_create(ctx->mk, *name_p, &chridx) <= 0)
return '\0';
*chr_p = chridx + MAILDIR_KEYWORD_FIRST;
More information about the dovecot-cvs
mailing list