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

« back to all changes in this revision

Viewing changes to src/plugins/imap-quota/imap-quota-plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-08-02 14:00:15 UTC
  • mto: (1.11.1 upstream) (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20080802140015-zbmjsgoodeyc9z4s
Tags: upstream-1.1.2
ImportĀ upstreamĀ versionĀ 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005 Timo Sirainen */
 
1
/* Copyright (c) 2005-2008 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "common.h"
4
4
#include "str.h"
21
21
        uint64_t value, limit;
22
22
        int ret;
23
23
 
24
 
        t_push();
25
 
 
26
24
        str = t_str_new(128);
27
25
        str_append(str, "* QUOTA ");
28
26
        imap_quote_append_string(str, quota_root_get_name(root), FALSE);
30
28
        str_append(str, " (");
31
29
        list = quota_root_get_resources(root);
32
30
        for (i = 0; *list != NULL; list++) {
33
 
                ret = quota_get_resource(root, *list, &value, &limit);
 
31
                ret = quota_get_resource(root, "", *list, &value, &limit);
34
32
                if (ret > 0) {
35
33
                        if (i > 0)
36
34
                                str_append_c(str, ' ');
39
37
                                    (unsigned long long)limit);
40
38
                        i++;
41
39
                } else if (ret < 0) {
42
 
                        client_send_line(cmd->client, t_strconcat(
43
 
                                "* BAD ", quota_last_error(quota_set), NULL));
 
40
                        client_send_line(cmd->client, 
 
41
                                "* BAD Internal quota calculation error");
44
42
                }
45
43
        }
46
44
        str_append_c(str, ')');
47
45
        client_send_line(cmd->client, str_c(str));
48
 
 
49
 
        t_pop();
50
46
}
51
47
 
52
48
static bool cmd_getquotaroot(struct client_command_context *cmd)
86
82
        str_append(str, "* QUOTAROOT ");
87
83
        imap_quote_append_string(str, orig_mailbox, FALSE);
88
84
 
89
 
        iter = quota_root_iter_init(box);
 
85
        iter = quota_root_iter_init(quota_set, box);
90
86
        while ((root = quota_root_iter_next(iter)) != NULL) {
91
87
                str_append_c(str, ' ');
92
88
                imap_quote_append_string(str, quota_root_get_name(root), FALSE);
93
89
        }
94
 
        quota_root_iter_deinit(iter);
 
90
        quota_root_iter_deinit(&iter);
95
91
        client_send_line(cmd->client, str_c(str));
96
92
 
97
93
        /* send QUOTA reply for each quotaroot */
98
 
        iter = quota_root_iter_init(box);
 
94
        iter = quota_root_iter_init(quota_set, box);
99
95
        while ((root = quota_root_iter_next(iter)) != NULL)
100
96
                quota_send(cmd, root);
101
 
        quota_root_iter_deinit(iter);
102
 
 
 
97
        quota_root_iter_deinit(&iter);
103
98
        mailbox_close(&box);
104
99
 
105
100
        client_send_tagline(cmd, "OK Getquotaroot completed.");
134
129
static bool cmd_setquota(struct client_command_context *cmd)
135
130
{
136
131
        struct quota_root *root;
137
 
        struct imap_arg *args, *arg;
138
 
        const char *root_name, *name;
 
132
        const struct imap_arg *args, *arg;
 
133
        const char *root_name, *name, *error;
139
134
        uint64_t value;
140
135
 
141
136
        /* <quota root> <resource limits> */
159
154
                return TRUE;
160
155
        }
161
156
 
162
 
        arg = IMAP_ARG_LIST(&args[1])->args;
 
157
        arg = IMAP_ARG_LIST_ARGS(&args[1]);
163
158
        for (; arg->type != IMAP_ARG_EOL; arg += 2) {
164
159
                name = imap_arg_string(arg);
165
160
                if (name == NULL || arg[1].type != IMAP_ARG_ATOM ||
169
164
                }
170
165
 
171
166
                value = strtoull(IMAP_ARG_STR_NONULL(&arg[1]), NULL, 10);
172
 
                if (quota_set_resource(root, name, value) < 0) {
173
 
                        client_send_command_error(cmd,
174
 
                                                  quota_last_error(quota_set));
 
167
                if (quota_set_resource(root, name, value, &error) < 0) {
 
168
                        client_send_command_error(cmd, error);
175
169
                        return TRUE;
176
170
                }
177
171
        }
182
176
 
183
177
void imap_quota_plugin_init(void)
184
178
{
185
 
        command_register("GETQUOTAROOT", cmd_getquotaroot);
186
 
        command_register("GETQUOTA", cmd_getquota);
187
 
        command_register("SETQUOTA", cmd_setquota);
 
179
        command_register("GETQUOTAROOT", cmd_getquotaroot, 0);
 
180
        command_register("GETQUOTA", cmd_getquota, 0);
 
181
        command_register("SETQUOTA", cmd_setquota, 0);
188
182
        str_append(capability_string, " QUOTA");
189
183
}
190
184