annotate src/plugins/imap-quota/imap-quota-plugin.c @ 4084:51306837698b HEAD

Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
author Timo Sirainen <timo.sirainen@movial.fi>
date Wed, 01 Mar 2006 11:14:59 +0200
parents 12ff7067ce62
children 4fa5cda580db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2005 Timo Sirainen */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "str.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "imap-quote.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "commands.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "quota.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "quota-plugin.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "imap-quota-plugin.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include <stdlib.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 static void
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 quota_send(struct client_command_context *cmd, struct quota_root *root)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 const char *const *list;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 string_t *str;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 unsigned int i;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 uint64_t value, limit;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 int ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 t_push();
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 str = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 str_append(str, "* QUOTA ");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 imap_quote_append_string(str, quota_root_get_name(root), FALSE);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 str_append(str, " (");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 list = quota_root_get_resources(root);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 for (i = 0; *list != NULL; list++, i++) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 ret = quota_get_resource(root, *list, &value, &limit);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 if (ret > 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 if (i > 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 str_append_c(str, ' ');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 str_printfa(str, "%s %llu %llu", *list,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 (unsigned long long)value,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 (unsigned long long)limit);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 } else if (ret < 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 client_send_line(cmd->client, t_strconcat(
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 "* BAD ", quota_last_error(quota), NULL));
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 str_append_c(str, ')');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 client_send_line(cmd->client, str_c(str));
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 t_pop();
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3750
diff changeset
49 static bool cmd_getquotaroot(struct client_command_context *cmd)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 struct mail_storage *storage;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 struct mailbox *box;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 struct quota_root_iter *iter;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 struct quota_root *root;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 const char *mailbox;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 string_t *str;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 /* <mailbox> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 if (!client_read_string_args(cmd, 1, &mailbox))
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 storage = client_find_storage(cmd, &mailbox);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 if (storage == NULL)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 box = mailbox_open(storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 MAILBOX_OPEN_FAST |
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 MAILBOX_OPEN_KEEP_RECENT));
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 if (box == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 client_send_storage_error(cmd, storage);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 if (quota == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 client_send_tagline(cmd, "OK No quota.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 /* send QUOTAROOT reply */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 str = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 str_append(str, "* QUOTAROOT ");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 imap_quote_append_string(str, mailbox, FALSE);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3993
diff changeset
84 iter = quota_root_iter_init(box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 while ((root = quota_root_iter_next(iter)) != NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 str_append_c(str, ' ');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 imap_quote_append_string(str, quota_root_get_name(root), FALSE);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 }
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3993
diff changeset
89 quota_root_iter_deinit(iter);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 client_send_line(cmd->client, str_c(str));
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 /* send QUOTA reply for each quotaroot */
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3993
diff changeset
93 iter = quota_root_iter_init(box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 while ((root = quota_root_iter_next(iter)) != NULL)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 quota_send(cmd, root);
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3993
diff changeset
96 quota_root_iter_deinit(iter);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
98 mailbox_close(&box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 client_send_tagline(cmd, "OK Getquotaroot completed.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3750
diff changeset
104 static bool cmd_getquota(struct client_command_context *cmd)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 const char *root_name;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 struct quota_root *root;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 /* <quota root> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 if (!client_read_string_args(cmd, 1, &root_name))
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 if (quota == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 client_send_tagline(cmd, "OK No quota.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 root = quota_root_lookup(quota, root_name);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 if (root == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 client_send_tagline(cmd, "NO Quota root doesn't exist.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 quota_send(cmd, root);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 client_send_tagline(cmd, "OK Getquota completed.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3750
diff changeset
129 static bool cmd_setquota(struct client_command_context *cmd)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 struct quota_root *root;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 struct imap_arg *args, *arg;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 const char *root_name, *name;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 uint64_t value;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 /* <quota root> <resource limits> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 if (!client_read_args(cmd, 2, 0, &args))
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 root_name = imap_arg_string(&args[0]);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 if (args[1].type != IMAP_ARG_LIST || root_name == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 client_send_command_error(cmd, "Invalid arguments.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 if (quota == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 client_send_tagline(cmd, "OK No quota.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 root = quota_root_lookup(quota, root_name);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 if (root == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 client_send_tagline(cmd, "NO Quota root doesn't exist.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 arg = IMAP_ARG_LIST(&args[1])->args;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 for (; arg->type != IMAP_ARG_EOL; arg += 2) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 name = imap_arg_string(arg);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 if (name == NULL || arg[1].type != IMAP_ARG_ATOM ||
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 !is_numeric(IMAP_ARG_STR(&arg[1]), '\0')) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 client_send_command_error(cmd, "Invalid arguments.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 value = strtoull(IMAP_ARG_STR_NONULL(&arg[1]), NULL, 10);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 if (quota_set_resource(root, name, value) < 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 client_send_command_error(cmd,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 quota_last_error(quota));
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 client_send_tagline(cmd, "OK Setquota completed.");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177
3750
b752272e6355 Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents: 3738
diff changeset
178 void imap_quota_plugin_init(void)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 command_register("GETQUOTAROOT", cmd_getquotaroot);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 command_register("GETQUOTA", cmd_getquota);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 command_register("SETQUOTA", cmd_setquota);
3993
12ff7067ce62 Advertise the QUOTA capability if the plugin is loaded.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
183 str_append(capability_string, " QUOTA");
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185
3750
b752272e6355 Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents: 3738
diff changeset
186 void imap_quota_plugin_deinit(void)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 command_unregister("GETQUOTAROOT");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 command_unregister("GETQUOTA");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 command_unregister("SETQUOTA");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 }