]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Cleanup - separate search arg values that are set by mail_search_init()
authorTimo Sirainen <tss@iki.fi>
Mon, 18 May 2015 10:21:50 +0000 (06:21 -0400)
committerTimo Sirainen <tss@iki.fi>
Mon, 18 May 2015 10:21:50 +0000 (06:21 -0400)
src/lib-storage/index/index-search.c
src/lib-storage/mail-search-args-imap.c
src/lib-storage/mail-search.c
src/lib-storage/mail-search.h

index dc39edd9f8f74850100f99ba27747898a9085762..e487e7bdd74e0d85f195b9c6b3ac0a85c6d98ccb 100644 (file)
@@ -127,7 +127,7 @@ static int search_arg_match_keywords(struct index_search_context *ctx,
                                     struct mail_search_arg *arg)
 {
        ARRAY_TYPE(keyword_indexes) keyword_indexes_arr;
-       const struct mail_keywords *search_kws = arg->value.keywords;
+       const struct mail_keywords *search_kws = arg->initialized.keywords;
        const unsigned int *keyword_indexes;
        unsigned int i, j, count;
 
@@ -202,9 +202,9 @@ static int search_arg_match_index(struct index_search_context *ctx,
                if (arg->value.flags != 0) {
                        modseq = mail_index_modseq_lookup_flags(ctx->view,
                                        arg->value.flags, ctx->mail_ctx.seq);
-               } else if (arg->value.keywords != NULL) {
+               } else if (arg->initialized.keywords != NULL) {
                        modseq = mail_index_modseq_lookup_keywords(ctx->view,
-                                       arg->value.keywords, ctx->mail_ctx.seq);
+                                       arg->initialized.keywords, ctx->mail_ctx.seq);
                } else {
                        modseq = mail_index_modseq_lookup(ctx->view,
                                                ctx->mail_ctx.seq);
@@ -260,12 +260,12 @@ static int search_arg_match_mailbox(struct index_search_context *ctx,
                        return strcasecmp(arg->value.str, "INBOX") == 0;
                return strcmp(str, arg->value.str) == 0;
        case SEARCH_MAILBOX_GLOB:
-               if (imap_match(arg->value.mailbox_glob, box->vname) == IMAP_MATCH_YES)
+               if (imap_match(arg->initialized.mailbox_glob, box->vname) == IMAP_MATCH_YES)
                        return 1;
                if (mail_get_special(ctx->cur_mail, MAIL_FETCH_MAILBOX_NAME,
                                     &str) < 0)
                        return -1;
-               return imap_match(arg->value.mailbox_glob, str) == IMAP_MATCH_YES;
+               return imap_match(arg->initialized.mailbox_glob, str) == IMAP_MATCH_YES;
        default:
                return -1;
        }
@@ -1073,11 +1073,11 @@ static int search_build_inthread_result(struct index_search_context *ctx,
        int ret = 0;
 
        /* mail_search_args_init() must have been called by now */
-       i_assert(arg->value.search_args != NULL);
+       i_assert(arg->initialized.search_args != NULL);
 
        p_array_init(&arg->value.seqset, ctx->mail_ctx.args->pool, 64);
        if (mailbox_search_result_build(ctx->mail_ctx.transaction,
-                                       arg->value.search_args,
+                                       arg->initialized.search_args,
                                        MAILBOX_SEARCH_RESULT_FLAG_UPDATE |
                                        MAILBOX_SEARCH_RESULT_FLAG_QUEUE_SYNC,
                                        &arg->value.search_result) < 0)
index 8dd4a8558c7bbb7cabc34c655d636d58120d270e..1775d63f4f2832b90b27427f5b1d4ad8c07c66cd 100644 (file)
@@ -98,7 +98,7 @@ bool mail_search_arg_to_imap(string_t *dest, const struct mail_search_arg *arg,
                str_append_c(dest, ')');
                break;
        case SEARCH_KEYWORDS: {
-               const struct mail_keywords *kw = arg->value.keywords;
+               const struct mail_keywords *kw = arg->initialized.keywords;
                const ARRAY_TYPE(keywords) *names_arr;
                const char *const *namep;
                unsigned int i;
index c826205008c615323e6438d04d182d222b7c7ce1..087118a05de8bdedf912266ae71ce4da4fd3a507 100644 (file)
@@ -85,8 +85,8 @@ mail_search_args_init_sub(struct mail_search_args *args,
                        keywords[0] = arg->value.str;
                        keywords[1] = NULL;
 
-                       i_assert(arg->value.keywords == NULL);
-                       arg->value.keywords =
+                       i_assert(arg->initialized.keywords == NULL);
+                       arg->initialized.keywords =
                                mailbox_keywords_create_valid(args->box,
                                                              keywords);
                        break;
@@ -95,15 +95,15 @@ mail_search_args_init_sub(struct mail_search_args *args,
                        struct mail_namespace *ns =
                                mailbox_get_namespace(args->box);
 
-                       arg->value.mailbox_glob =
+                       arg->initialized.mailbox_glob =
                                imap_match_init(default_pool, arg->value.str,
                                                TRUE, mail_namespace_get_sep(ns));
                        break;
                }
                case SEARCH_INTHREAD:
-                       thread_args = arg->value.search_args;
+                       thread_args = arg->initialized.search_args;
                        if (thread_args == NULL) {
-                               arg->value.search_args = thread_args =
+                               arg->initialized.search_args = thread_args =
                                        p_new(args->pool,
                                              struct mail_search_args, 1);
                                thread_args->pool = args->pool;
@@ -153,25 +153,25 @@ static void mail_search_args_deinit_sub(struct mail_search_args *args,
                switch (arg->type) {
                case SEARCH_MODSEQ:
                case SEARCH_KEYWORDS:
-                       if (arg->value.keywords == NULL)
+                       if (arg->initialized.keywords == NULL)
                                break;
-                       mailbox_keywords_unref(&arg->value.keywords);
+                       mailbox_keywords_unref(&arg->initialized.keywords);
                        break;
                case SEARCH_MAILBOX_GLOB:
-                       if (arg->value.mailbox_glob == NULL)
+                       if (arg->initialized.mailbox_glob == NULL)
                                break;
 
-                       imap_match_deinit(&arg->value.mailbox_glob);
+                       imap_match_deinit(&arg->initialized.mailbox_glob);
                        break;
                case SEARCH_INTHREAD:
-                       i_assert(arg->value.search_args->refcount > 0);
+                       i_assert(arg->initialized.search_args->refcount > 0);
                        if (args->refcount == 0 &&
                            arg->value.search_result != NULL) {
                                mailbox_search_result_free(
                                        &arg->value.search_result);
                        }
-                       arg->value.search_args->refcount--;
-                       arg->value.search_args->box = NULL;
+                       arg->initialized.search_args->refcount--;
+                       arg->initialized.search_args->box = NULL;
                        /* fall through */
                case SEARCH_SUB:
                case SEARCH_OR:
@@ -650,8 +650,8 @@ static bool mail_search_arg_one_equals(const struct mail_search_arg *arg1,
                        m1->type == m2->type;
        }
        case SEARCH_INTHREAD:
-               return mail_search_args_equal(arg1->value.search_args,
-                                             arg2->value.search_args);
+               return mail_search_args_equal(arg1->initialized.search_args,
+                                             arg2->initialized.search_args);
        }
        i_unreached();
        return FALSE;
index 1b4b0d54475d266526c07223dcc00f8ffdfd3c0a..f4b6deaaf57dc3e40e80c7070e916a5b5f9acd7e 100644 (file)
@@ -83,12 +83,15 @@ struct mail_search_arg {
                enum mail_search_arg_flag search_flags;
                enum mail_search_date_type date_type;
                enum mail_thread_type thread_type;
-               struct mail_keywords *keywords;
                struct mail_search_modseq *modseq;
-               struct mail_search_args *search_args;
                struct mail_search_result *search_result;
-               struct imap_match_glob *mailbox_glob;
        } value;
+       /* set by mail_search_args_init(): */
+       struct {
+               struct mail_search_args *search_args;
+               struct mail_keywords *keywords;
+               struct imap_match_glob *mailbox_glob;
+       } initialized;
 
         void *context;
        const char *hdr_field_name; /* for SEARCH_HEADER* */