dovecot-2.2: lib-storage: Added MAIL_ATTRIBUTE_INTERNAL_FLAG_CHI...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 7 13:40:50 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/31f8e377b632
changeset: 19102:31f8e377b632
user: Timo Sirainen <tss at iki.fi>
date: Mon Sep 07 16:38:24 2015 +0300
description:
lib-storage: Added MAIL_ATTRIBUTE_INTERNAL_FLAG_CHILDREN
This also adds the key to get() and set() functions, so they can know
exactly what key is wanted to be accessed.
diffstat:
src/lib-storage/mailbox-attribute.c | 35 +++++++++++++++++++++++++----------
src/lib-storage/mailbox-attribute.h | 10 ++++++++--
2 files changed, 33 insertions(+), 12 deletions(-)
diffs (116 lines):
diff -r a2e28ee1a673 -r 31f8e377b632 src/lib-storage/mailbox-attribute.c
--- a/src/lib-storage/mailbox-attribute.c Sat Apr 25 11:42:06 2015 +0200
+++ b/src/lib-storage/mailbox-attribute.c Mon Sep 07 16:38:24 2015 +0300
@@ -55,6 +55,7 @@
mailbox_internal_attribute_get(enum mail_attribute_type type,
const char *key)
{
+ const struct mailbox_attribute_internal *iattr;
struct mailbox_attribute_internal dreg;
unsigned int insert_idx;
@@ -62,12 +63,26 @@
dreg.type = type;
dreg.key = key;
- if (!array_bsearch_insert_pos(&mailbox_internal_attributes,
- &dreg, mailbox_attribute_internal_cmp,
- &insert_idx))
+ if (array_bsearch_insert_pos(&mailbox_internal_attributes,
+ &dreg, mailbox_attribute_internal_cmp,
+ &insert_idx)) {
+ /* exact match */
+ return array_idx(&mailbox_internal_attributes, insert_idx);
+ }
+ if (insert_idx == 0) {
+ /* not found at all */
return NULL;
-
- return array_idx(&mailbox_internal_attributes, insert_idx);
+ }
+ iattr = array_idx(&mailbox_internal_attributes, insert_idx-1);
+ if (strncmp(iattr->key, key, strlen(iattr->key)) != 0) {
+ /* iattr isn't a prefix of key */
+ return NULL;
+ } else if ((iattr->flags & MAIL_ATTRIBUTE_INTERNAL_FLAG_CHILDREN) != 0) {
+ /* iattr is a prefix of key and it wants to handle the key */
+ return iattr;
+ } else {
+ return NULL;
+ }
}
static void
@@ -138,7 +153,7 @@
case MAIL_ATTRIBUTE_INTERNAL_RANK_DEFAULT:
case MAIL_ATTRIBUTE_INTERNAL_RANK_OVERRIDE:
/* notify about assignment */
- if (iattr->set != NULL && iattr->set(t, value) < 0)
+ if (iattr->set != NULL && iattr->set(t, key, value) < 0)
return -1;
break;
case MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY:
@@ -149,7 +164,7 @@
return -1;
}
/* assign internal attribute */
- return iattr->set(t, value);
+ return iattr->set(t, key, value);
default:
i_unreached();
}
@@ -228,7 +243,7 @@
if (iattr != NULL) {
switch (iattr->rank) {
case MAIL_ATTRIBUTE_INTERNAL_RANK_OVERRIDE:
- if ((ret = iattr->get(t, value_r)) != 0) {
+ if ((ret = iattr->get(t, key, value_r)) != 0) {
if (ret < 0)
return -1;
value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_READONLY;
@@ -237,7 +252,7 @@
case MAIL_ATTRIBUTE_INTERNAL_RANK_DEFAULT:
break;
case MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY:
- if ((ret = iattr->get(t, value_r)) <= 0)
+ if ((ret = iattr->get(t, key, value_r)) <= 0)
return ret;
value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_READONLY;
return 1;
@@ -254,7 +269,7 @@
if (iattr != NULL) {
switch (iattr->rank) {
case MAIL_ATTRIBUTE_INTERNAL_RANK_DEFAULT:
- if ((ret = iattr->get(t, value_r)) < 0)
+ if ((ret = iattr->get(t, key, value_r)) < 0)
return ret;
if (ret > 0) {
value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_READONLY;
diff -r a2e28ee1a673 -r 31f8e377b632 src/lib-storage/mailbox-attribute.h
--- a/src/lib-storage/mailbox-attribute.h Sat Apr 25 11:42:06 2015 +0200
+++ b/src/lib-storage/mailbox-attribute.h Mon Sep 07 16:38:24 2015 +0300
@@ -82,16 +82,22 @@
MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY
};
+enum mail_attribute_internal_flags {
+ /* Apply this attribute to the given key and its children. */
+ MAIL_ATTRIBUTE_INTERNAL_FLAG_CHILDREN = 0x01
+};
+
struct mailbox_attribute_internal {
enum mail_attribute_type type;
const char *key;
enum mail_attribute_internal_rank rank;
+ enum mail_attribute_internal_flags flags;
/* Get the value of this internal attribute */
- int (*get)(struct mailbox_transaction_context *t,
+ int (*get)(struct mailbox_transaction_context *t, const char *key,
struct mail_attribute_value *value_r);
/* Set the value of this internal attribute */
- int (*set)(struct mailbox_transaction_context *t,
+ int (*set)(struct mailbox_transaction_context *t, const char *key,
const struct mail_attribute_value *value);
};
More information about the dovecot-cvs
mailing list