annotate src/plugins/imap-quota/imap-quota-plugin.c @ 5253:535ff7687388 HEAD

When returning mailbox name with GETQUOTAROOT, return the original name instead of the converted storage name.
author Timo Sirainen <tss@iki.fi>
date Fri, 09 Mar 2007 21:37:23 +0200
parents 24f4a959a24c
children 88307a648e0e
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
5185
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 4796
diff changeset
13 const char *imap_quota_plugin_version = PACKAGE_VERSION;
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 4796
diff changeset
14
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 static void
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 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
17 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 const char *const *list;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 string_t *str;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 unsigned int i;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 uint64_t value, limit;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 int ret;
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 t_push();
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 str = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 str_append(str, "* QUOTA ");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 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
29
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 str_append(str, " (");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 list = quota_root_get_resources(root);
4241
4fa5cda580db Don't add extra spaces to reply if some of the resources aren't really found.
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
32 for (i = 0; *list != NULL; list++) {
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
33 ret = quota_get_resource(root, "", *list, &value, &limit);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 if (ret > 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 if (i > 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 str_append_c(str, ' ');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 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
38 (unsigned long long)value,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 (unsigned long long)limit);
4241
4fa5cda580db Don't add extra spaces to reply if some of the resources aren't really found.
Timo Sirainen <tss@iki.fi>
parents: 4084
diff changeset
40 i++;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 } else if (ret < 0) {
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
42 client_send_line(cmd->client,
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
43 "* BAD Internal quota calculation error");
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 }
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 str_append_c(str, ')');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 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
48
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 t_pop();
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
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
52 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
53 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 struct mail_storage *storage;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 struct mailbox *box;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 struct quota_root_iter *iter;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 struct quota_root *root;
5253
535ff7687388 When returning mailbox name with GETQUOTAROOT, return the original name
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
58 const char *orig_mailbox, *mailbox;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 string_t *str;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 /* <mailbox> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 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
63 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
5253
535ff7687388 When returning mailbox name with GETQUOTAROOT, return the original name
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
65 orig_mailbox = mailbox;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 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
67 if (storage == NULL)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 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
71 MAILBOX_OPEN_FAST |
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 MAILBOX_OPEN_KEEP_RECENT));
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 if (box == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 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
75 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
78 if (quota_set == NULL) {
4473
5811b2c183fd If there is no quota for the user, GETQUOTAROOT leaked memory
Timo Sirainen <tss@iki.fi>
parents: 4241
diff changeset
79 mailbox_close(&box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 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
81 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 /* send QUOTAROOT reply */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 str = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 str_append(str, "* QUOTAROOT ");
5253
535ff7687388 When returning mailbox name with GETQUOTAROOT, return the original name
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
87 imap_quote_append_string(str, orig_mailbox, FALSE);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
89 iter = quota_root_iter_init(quota_set, box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 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
91 str_append_c(str, ' ');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 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
93 }
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
94 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
95 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
96
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 /* send QUOTA reply for each quotaroot */
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
98 iter = quota_root_iter_init(quota_set, box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 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
100 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
101 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
102
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
103 mailbox_close(&box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 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
106 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108
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
109 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
110 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 const char *root_name;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 struct quota_root *root;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 /* <quota root> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 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
116 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
118 if (quota_set == NULL) {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 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
120 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
123 root = quota_root_lookup(quota_set, root_name);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 if (root == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 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
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
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 quota_send(cmd, root);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 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
131 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133
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
134 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
135 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 struct quota_root *root;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 struct imap_arg *args, *arg;
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
138 const char *root_name, *name, *error;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 uint64_t value;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 /* <quota root> <resource limits> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 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
143 return FALSE;
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 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
146 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
147 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
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
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
151 if (quota_set == NULL) {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 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
153 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155
4796
49c9e7588de4 s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents: 4513
diff changeset
156 root = quota_root_lookup(quota_set, root_name);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 if (root == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 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
159 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 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
163 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
164 name = imap_arg_string(arg);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 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
166 !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
167 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
168 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 value = strtoull(IMAP_ARG_STR_NONULL(&arg[1]), NULL, 10);
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
172 if (quota_set_resource(root, name, value, &error) < 0) {
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
173 client_send_command_error(cmd, error);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 }
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
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 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
179 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181
3750
b752272e6355 Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents: 3738
diff changeset
182 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
183 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 command_register("GETQUOTAROOT", cmd_getquotaroot);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 command_register("GETQUOTA", cmd_getquota);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 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
187 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
188 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189
3750
b752272e6355 Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents: 3738
diff changeset
190 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
191 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 command_unregister("GETQUOTAROOT");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 command_unregister("GETQUOTA");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 command_unregister("SETQUOTA");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 }