]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Prepare attribute API for having flags in the type
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 23 Jul 2019 11:42:45 +0000 (12:42 +0100)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 30 Jul 2019 08:19:58 +0000 (08:19 +0000)
src/lib-storage/index/index-attribute.c
src/lib-storage/index/index-storage.h
src/lib-storage/mail-storage-private.h
src/lib-storage/mailbox-attribute.c
src/lib-storage/mailbox-attribute.h

index a6c7bb1b88fdfe40e43d3d844830d28fd3fafe26..aed651f04ee6583f011a5d5474d61205fd083a29 100644 (file)
@@ -78,9 +78,10 @@ index_storage_get_user_dict(struct mail_storage *err_storage,
 }
 
 static int
-index_storage_get_dict(struct mailbox *box, enum mail_attribute_type type,
+index_storage_get_dict(struct mailbox *box, enum mail_attribute_type type_flags,
                       struct dict **dict_r, const char **mailbox_prefix_r)
 {
+       enum mail_attribute_type type = type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
        struct mail_storage *storage = box->storage;
        struct mail_namespace *ns;
        struct mailbox_metadata metadata;
@@ -139,9 +140,11 @@ index_storage_get_dict(struct mailbox *box, enum mail_attribute_type type,
 }
 
 static const char *
-key_get_prefixed(enum mail_attribute_type type, const char *mailbox_prefix,
+key_get_prefixed(enum mail_attribute_type type_flags, const char *mailbox_prefix,
                 const char *key)
 {
+       enum mail_attribute_type type = type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
+
        switch (type) {
        case MAIL_ATTRIBUTE_TYPE_PRIVATE:
                return t_strconcat(DICT_PATH_PRIVATE, mailbox_prefix, "/",
@@ -155,10 +158,11 @@ key_get_prefixed(enum mail_attribute_type type, const char *mailbox_prefix,
 
 static int
 index_storage_attribute_get_dict_trans(struct mailbox_transaction_context *t,
-                                      enum mail_attribute_type type,
+                                      enum mail_attribute_type type_flags,
                                       struct dict_transaction_context **dtrans_r,
                                       const char **mailbox_prefix_r)
 {
+       enum mail_attribute_type type = type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
        struct dict_transaction_context **dtransp = NULL;
        struct dict *dict;
        struct mailbox_metadata metadata;
@@ -183,29 +187,31 @@ index_storage_attribute_get_dict_trans(struct mailbox_transaction_context *t,
                return 0;
        }
 
-       if (index_storage_get_dict(t->box, type, &dict, mailbox_prefix_r) < 0)
+       if (index_storage_get_dict(t->box, type_flags, &dict, mailbox_prefix_r) < 0)
                return -1;
        *dtransp = *dtrans_r = dict_transaction_begin(dict);
        return 0;
 }
 
 int index_storage_attribute_set(struct mailbox_transaction_context *t,
-                               enum mail_attribute_type type, const char *key,
+                               enum mail_attribute_type type_flags,
+                               const char *key,
                                const struct mail_attribute_value *value)
 {
+       enum mail_attribute_type type = type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
        struct dict_transaction_context *dtrans;
        const char *mailbox_prefix;
        bool pvt = type == MAIL_ATTRIBUTE_TYPE_PRIVATE;
        time_t ts = value->last_change != 0 ? value->last_change : ioloop_time;
        int ret = 0;
 
-       if (index_storage_attribute_get_dict_trans(t, type, &dtrans,
+       if (index_storage_attribute_get_dict_trans(t, type_flags, &dtrans,
                                                   &mailbox_prefix) < 0)
                return -1;
 
        T_BEGIN {
                const char *prefixed_key =
-                       key_get_prefixed(type, mailbox_prefix, key);
+                       key_get_prefixed(type_flags, mailbox_prefix, key);
                const char *value_str;
 
                if (mailbox_attribute_value_to_string(t->box->storage, value,
@@ -224,7 +230,8 @@ int index_storage_attribute_set(struct mailbox_transaction_context *t,
 }
 
 int index_storage_attribute_get(struct mailbox *box,
-                               enum mail_attribute_type type, const char *key,
+                               enum mail_attribute_type type_flags,
+                               const char *key,
                                struct mail_attribute_value *value_r)
 {
        struct dict *dict;
@@ -233,11 +240,11 @@ int index_storage_attribute_get(struct mailbox *box,
 
        i_zero(value_r);
 
-       if (index_storage_get_dict(box, type, &dict, &mailbox_prefix) < 0)
+       if (index_storage_get_dict(box, type_flags, &dict, &mailbox_prefix) < 0)
                return -1;
 
        ret = dict_lookup(dict, pool_datastack_create(),
-                         key_get_prefixed(type, mailbox_prefix, key),
+                         key_get_prefixed(type_flags, mailbox_prefix, key),
                          &value_r->value, &error);
        if (ret < 0) {
                mailbox_set_critical(box,
@@ -249,7 +256,7 @@ int index_storage_attribute_get(struct mailbox *box,
 
 struct mailbox_attribute_iter *
 index_storage_attribute_iter_init(struct mailbox *box,
-                                 enum mail_attribute_type type,
+                                 enum mail_attribute_type type_flags,
                                  const char *prefix)
 {
        struct index_storage_attribute_iter *iter;
@@ -258,11 +265,11 @@ index_storage_attribute_iter_init(struct mailbox *box,
 
        iter = i_new(struct index_storage_attribute_iter, 1);
        iter->iter.box = box;
-       if (index_storage_get_dict(box, type, &dict, &mailbox_prefix) < 0) {
+       if (index_storage_get_dict(box, type_flags, &dict, &mailbox_prefix) < 0) {
                if (mailbox_get_last_mail_error(box) == MAIL_ERROR_NOTPOSSIBLE)
                        iter->dict_disabled = TRUE;
        } else {
-               iter->prefix = i_strdup(key_get_prefixed(type, mailbox_prefix,
+               iter->prefix = i_strdup(key_get_prefixed(type_flags, mailbox_prefix,
                                                         prefix));
                iter->prefix_len = strlen(iter->prefix);
                iter->diter = dict_iterate_init(dict, iter->prefix,
index 74de187ba047a73569668cd7dc814f6abf580b1c..dd26b3d3723bc8219694e2240667918acf9846d2 100644 (file)
@@ -117,14 +117,16 @@ int index_mailbox_get_physical_size(struct mailbox *box,
                                    struct mailbox_metadata *metadata_r);
 
 int index_storage_attribute_set(struct mailbox_transaction_context *t,
-                               enum mail_attribute_type type, const char *key,
+                               enum mail_attribute_type type_flags,
+                               const char *key,
                                const struct mail_attribute_value *value);
 int index_storage_attribute_get(struct mailbox *box,
-                               enum mail_attribute_type type, const char *key,
+                               enum mail_attribute_type type_flags,
+                               const char *key,
                                struct mail_attribute_value *value_r);
 struct mailbox_attribute_iter *
 index_storage_attribute_iter_init(struct mailbox *box,
-                                 enum mail_attribute_type type,
+                                 enum mail_attribute_type type_flags,
                                  const char *prefix);
 const char *
 index_storage_attribute_iter_next(struct mailbox_attribute_iter *iter);
index 3140e98d61faf3950c701b74172b552071f9221d..d5b450f2180274677269132b1dbfdc5e39c81ff0 100644 (file)
@@ -234,14 +234,16 @@ struct mailbox_vfuncs {
        int (*set_subscribed)(struct mailbox *box, bool set);
 
        int (*attribute_set)(struct mailbox_transaction_context *t,
-                            enum mail_attribute_type type, const char *key,
+                            enum mail_attribute_type type_flags,
+                            const char *key,
                             const struct mail_attribute_value *value);
        int (*attribute_get)(struct mailbox *box,
-                            enum mail_attribute_type type, const char *key,
+                            enum mail_attribute_type type_flags,
+                            const char *key,
                             struct mail_attribute_value *value_r);
        struct mailbox_attribute_iter *
                (*attribute_iter_init)(struct mailbox *box,
-                                      enum mail_attribute_type type,
+                                      enum mail_attribute_type type_flags,
                                       const char *prefix);
        const char *(*attribute_iter_next)(struct mailbox_attribute_iter *iter);
        int (*attribute_iter_deinit)(struct mailbox_attribute_iter *iter);
index b3bd5831347b54d737bf3aab8fdeb2d36ca9a435..51455b885184e8699e7ad20a3b7a64b995d8f2f4 100644 (file)
@@ -88,7 +88,7 @@ void mailbox_attribute_unregister_internals(
 }
 
 static const struct mailbox_attribute_internal *
-mailbox_internal_attribute_get(enum mail_attribute_type type,
+mailbox_internal_attribute_get(enum mail_attribute_type type_flags,
                               const char *key)
 {
        const struct mailbox_attribute_internal *iattr;
@@ -96,7 +96,7 @@ mailbox_internal_attribute_get(enum mail_attribute_type type,
        unsigned int insert_idx;
 
        i_zero(&dreg);
-       dreg.type = type;       
+       dreg.type = type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
        dreg.key = key;
 
        if (array_bsearch_insert_pos(&mailbox_internal_attributes,
@@ -122,7 +122,7 @@ mailbox_internal_attribute_get(enum mail_attribute_type type,
 }
 
 static void
-mailbox_internal_attributes_get(enum mail_attribute_type type,
+mailbox_internal_attributes_get(enum mail_attribute_type type_flags,
        const char *prefix, bool have_dict, ARRAY_TYPE(const_string) *attrs)
 {
        const struct mailbox_attribute_internal *regs;
@@ -139,7 +139,7 @@ mailbox_internal_attributes_get(enum mail_attribute_type type,
        }
 
        i_zero(&dreg);
-       dreg.type = type;       
+       dreg.type = type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
        dreg.key = bare_prefix;
 
        (void)array_bsearch_insert_pos(&mailbox_internal_attributes,
@@ -149,7 +149,7 @@ mailbox_internal_attributes_get(enum mail_attribute_type type,
        for (; i < count; i++) {
                const char *key = regs[i].key;
 
-               if (regs[i].type != type)
+               if (regs[i].type != dreg.type)
                        return;
                if (plen > 0) {
                        if (strncmp(key, bare_prefix, plen) != 0)
@@ -177,13 +177,16 @@ mailbox_internal_attributes_get(enum mail_attribute_type type,
 
 static int
 mailbox_attribute_set_common(struct mailbox_transaction_context *t,
-                            enum mail_attribute_type type, const char *key,
+                            enum mail_attribute_type type_flags,
+                            const char *key,
                             const struct mail_attribute_value *value)
 {
+       enum mail_attribute_type type =
+               type_flags & MAIL_ATTRIBUTE_TYPE_MASK;
        const struct mailbox_attribute_internal *iattr;
        int ret;
 
-       iattr = mailbox_internal_attribute_get(type, key);
+       iattr = mailbox_internal_attribute_get(type_flags, key);
 
        /* allow internal server attribute only for inbox */
        if (iattr != NULL && !t->box->inbox_any &&
@@ -213,24 +216,24 @@ mailbox_attribute_set_common(struct mailbox_transaction_context *t,
                }
        }
 
-       ret = t->box->v.attribute_set(t, type, key, value);
+       ret = t->box->v.attribute_set(t, type_flags, key, value);
        return ret;
 }
 
 int mailbox_attribute_set(struct mailbox_transaction_context *t,
-                         enum mail_attribute_type type, const char *key,
+                         enum mail_attribute_type type_flags, const char *key,
                          const struct mail_attribute_value *value)
 {
-       return mailbox_attribute_set_common(t, type, key, value);
+       return mailbox_attribute_set_common(t, type_flags, key, value);
 }
 
 int mailbox_attribute_unset(struct mailbox_transaction_context *t,
-                           enum mail_attribute_type type, const char *key)
+                           enum mail_attribute_type type_flags, const char *key)
 {
        struct mail_attribute_value value;
 
        i_zero(&value);
-       return mailbox_attribute_set_common(t, type, key, &value);
+       return mailbox_attribute_set_common(t, type_flags, key, &value);
 }
 
 int mailbox_attribute_value_to_string(struct mail_storage *storage,
@@ -269,13 +272,14 @@ int mailbox_attribute_value_to_string(struct mail_storage *storage,
 
 static int
 mailbox_attribute_get_common(struct mailbox *box,
-                            enum mail_attribute_type type, const char *key,
+                            enum mail_attribute_type type_flags,
+                            const char *key,
                             struct mail_attribute_value *value_r)
 {
        const struct mailbox_attribute_internal *iattr;
        int ret;
 
-       iattr = mailbox_internal_attribute_get(type, key);
+       iattr = mailbox_internal_attribute_get(type_flags, key);
 
        /* allow internal server attributes only for the inbox */
        if (iattr != NULL && !box->inbox_user &&
@@ -305,7 +309,7 @@ mailbox_attribute_get_common(struct mailbox *box,
                }
        }
 
-       ret = box->v.attribute_get(box, type, key, value_r);
+       ret = box->v.attribute_get(box, type_flags, key, value_r);
        if (ret != 0)
                return ret;
 
@@ -334,12 +338,12 @@ mailbox_attribute_get_common(struct mailbox *box,
 }
 
 int mailbox_attribute_get(struct mailbox *box,
-                         enum mail_attribute_type type, const char *key,
+                         enum mail_attribute_type type_flags, const char *key,
                          struct mail_attribute_value *value_r)
 {
        int ret;
        i_zero(value_r);
-       if ((ret = mailbox_attribute_get_common(box, type, key,
+       if ((ret = mailbox_attribute_get_common(box, type_flags, key,
                                value_r)) <= 0)
                return ret;
        i_assert(value_r->value != NULL);
@@ -347,14 +351,15 @@ int mailbox_attribute_get(struct mailbox *box,
 }
 
 int mailbox_attribute_get_stream(struct mailbox *box,
-                                enum mail_attribute_type type, const char *key,
+                                enum mail_attribute_type type_flags,
+                                const char *key,
                                 struct mail_attribute_value *value_r)
 {
        int ret;
 
        i_zero(value_r);
        value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_INT_STREAMS;
-       if ((ret = mailbox_attribute_get_common(box, type, key,
+       if ((ret = mailbox_attribute_get_common(box, type_flags, key,
                                value_r)) <= 0)
                return ret;
        i_assert(value_r->value != NULL || value_r->value_stream != NULL);
@@ -372,7 +377,8 @@ struct mailbox_attribute_internal_iter {
 
 struct mailbox_attribute_iter *
 mailbox_attribute_iter_init(struct mailbox *box,
-                           enum mail_attribute_type type, const char *prefix)
+                           enum mail_attribute_type type_flags,
+                           const char *prefix)
 {
        struct mailbox_attribute_internal_iter *intiter;
        struct mailbox_attribute_iter *iter;
@@ -380,14 +386,15 @@ mailbox_attribute_iter_init(struct mailbox *box,
        const char *const *attr;
        bool have_dict;
 
-       iter = box->v.attribute_iter_init(box, type, prefix);
+       iter = box->v.attribute_iter_init(box, type_flags, prefix);
        i_assert(iter->box != NULL);
        box->attribute_iter_count++;
 
        /* check which internal attributes may apply */
        t_array_init(&extra_attrs, 4);
        have_dict = box->storage->set->mail_attribute_dict[0] != '\0';
-       mailbox_internal_attributes_get(type, prefix, have_dict, &extra_attrs);
+       mailbox_internal_attributes_get(type_flags, prefix,
+                                       have_dict, &extra_attrs);
 
        /* any extra internal attributes to add? */
        if (array_count(&extra_attrs) == 0) {
index 8c7bc96c06f87f65986b34183429f04f5131a9ef..76428dd185884dde6074f87aee66fb3165a367de 100644 (file)
@@ -182,6 +182,8 @@ enum mail_attribute_type {
        MAIL_ATTRIBUTE_TYPE_PRIVATE,
        MAIL_ATTRIBUTE_TYPE_SHARED
 };
+#define MAIL_ATTRIBUTE_TYPE_MASK               0x0f
+
 enum mail_attribute_value_flags {
        MAIL_ATTRIBUTE_VALUE_FLAG_READONLY      = 0x01,
        MAIL_ATTRIBUTE_VALUE_FLAG_INT_STREAMS   = 0x02
@@ -267,27 +269,29 @@ void mailbox_attribute_unregister_internals(
    IMAP METADATA, so for Dovecot-specific keys use
    MAILBOX_ATTRIBUTE_PREFIX_DOVECOT. */
 int mailbox_attribute_set(struct mailbox_transaction_context *t,
-                         enum mail_attribute_type type, const char *key,
+                         enum mail_attribute_type type_flags, const char *key,
                          const struct mail_attribute_value *value);
 /* Delete mailbox attribute key. This is just a wrapper to
    mailbox_attribute_set() with value->value=NULL. */
 int mailbox_attribute_unset(struct mailbox_transaction_context *t,
-                           enum mail_attribute_type type, const char *key);
+                           enum mail_attribute_type type_flags, const char *key);
 /* Returns value for mailbox attribute key. Returns 1 if value was returned,
    0 if value wasn't found (set to NULL), -1 if error */
 int mailbox_attribute_get(struct mailbox *box,
-                         enum mail_attribute_type type, const char *key,
+                         enum mail_attribute_type type_flags, const char *key,
                          struct mail_attribute_value *value_r);
 /* Same as mailbox_attribute_get(), but the returned value may be either an
    input stream or a string. */
 int mailbox_attribute_get_stream(struct mailbox *box,
-                                enum mail_attribute_type type, const char *key,
+                                enum mail_attribute_type type_flags,
+                                const char *key,
                                 struct mail_attribute_value *value_r);
 
 /* Iterate through mailbox attributes of the given type. The prefix can be used
    to restrict what attributes are returned. */
 struct mailbox_attribute_iter *
-mailbox_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type,
+mailbox_attribute_iter_init(struct mailbox *box,
+                           enum mail_attribute_type type_flags,
                            const char *prefix);
 /* Returns the attribute key or NULL if there are no more attributes. */
 const char *mailbox_attribute_iter_next(struct mailbox_attribute_iter *iter);