~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/lib-storage/mail-storage-hooks.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2009-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
12
12
struct mail_storage_module_hooks {
13
13
        struct module *module;
14
14
        const struct mail_storage_hooks *hooks;
 
15
        bool forced;
15
16
};
16
17
 
17
18
struct hook_stack {
36
37
        struct hook_stack *head, *tail;
37
38
};
38
39
 
39
 
static ARRAY_DEFINE(module_hooks,
40
 
                    struct mail_storage_module_hooks) = ARRAY_INIT;
41
 
static ARRAY_DEFINE(internal_hooks,
42
 
                    const struct mail_storage_hooks *) = ARRAY_INIT;
 
40
static ARRAY(struct mail_storage_module_hooks) module_hooks = ARRAY_INIT;
 
41
static ARRAY(const struct mail_storage_hooks *) internal_hooks = ARRAY_INIT;
43
42
 
44
43
void mail_storage_hooks_init(void)
45
44
{
46
 
        i_array_init(&module_hooks, 32);
 
45
        if (!array_is_created(&module_hooks))
 
46
                i_array_init(&module_hooks, 32);
47
47
        i_array_init(&internal_hooks, 8);
48
48
}
49
49
 
62
62
        new_hook.module = module;
63
63
        new_hook.hooks = hooks;
64
64
 
 
65
        /* allow adding hooks before mail_storage_hooks_init() */
 
66
        if (!array_is_created(&module_hooks))
 
67
                i_array_init(&module_hooks, 32);
65
68
        array_append(&module_hooks, &new_hook, 1);
66
69
}
67
70
 
 
71
void mail_storage_hooks_add_forced(struct module *module,
 
72
                                   const struct mail_storage_hooks *hooks)
 
73
{
 
74
        struct mail_storage_module_hooks *hook;
 
75
 
 
76
        mail_storage_hooks_add(module, hooks);
 
77
        hook = array_idx_modifiable(&module_hooks,
 
78
                                    array_count(&module_hooks)-1);
 
79
        hook->forced = TRUE;
 
80
}
 
81
 
68
82
void mail_storage_hooks_remove(const struct mail_storage_hooks *hooks)
69
83
{
70
84
        const struct mail_storage_module_hooks *module_hook;
71
 
        unsigned int idx = -1U;
 
85
        unsigned int idx = UINT_MAX;
72
86
 
73
87
        array_foreach(&module_hooks, module_hook) {
74
88
                if (module_hook->hooks == hooks) {
76
90
                        break;
77
91
                }
78
92
        }
79
 
        i_assert(idx != -1U);
 
93
        i_assert(idx != UINT_MAX);
80
94
 
81
95
        array_delete(&module_hooks, idx, 1);
82
96
}
89
103
void mail_storage_hooks_remove_internal(const struct mail_storage_hooks *hooks)
90
104
{
91
105
        const struct mail_storage_hooks *const *old_hooks;
92
 
        unsigned int idx = -1U;
 
106
        unsigned int idx = UINT_MAX;
93
107
 
94
108
        array_foreach(&internal_hooks, old_hooks) {
95
109
                if (*old_hooks == hooks) {
97
111
                        break;
98
112
                }
99
113
        }
100
 
        i_assert(idx != -1U);
 
114
        i_assert(idx != UINT_MAX);
101
115
 
102
116
        array_delete(&internal_hooks, idx, 1);
103
117
}
119
133
static void mail_user_add_plugin_hooks(struct mail_user *user)
120
134
{
121
135
        const struct mail_storage_module_hooks *module_hook;
122
 
        ARRAY_DEFINE(tmp_hooks, struct mail_storage_module_hooks);
 
136
        ARRAY(struct mail_storage_module_hooks) tmp_hooks;
123
137
        const char *const *plugins, *name;
124
138
 
125
139
        /* first get all hooks wanted by the user */
127
141
        plugins = t_strsplit_spaces(user->set->mail_plugins, ", ");
128
142
        array_foreach(&module_hooks, module_hook) {
129
143
                name = module_get_plugin_name(module_hook->module);
130
 
                if (str_array_find(plugins, name))
 
144
                if (str_array_find(plugins, name) || module_hook->forced)
131
145
                        array_append(&tmp_hooks, module_hook, 1);
132
146
        }
133
147
 
267
281
        }
268
282
}
269
283
 
 
284
void hook_mail_namespaces_added(struct mail_namespace *namespaces)
 
285
{
 
286
        const struct mail_storage_hooks *const *hooks;
 
287
 
 
288
        array_foreach(&namespaces->user->hooks, hooks) {
 
289
                if ((*hooks)->mail_namespaces_added != NULL)
 
290
                        (*hooks)->mail_namespaces_added(namespaces);
 
291
        }
 
292
}
 
293
 
270
294
void hook_mail_storage_created(struct mail_storage *storage)
271
295
{
272
296
        const struct mail_storage_hooks *const *hooks;