Commit bdd24508 bdd245085a05b9a6c67eea9e491c53bd96bf3287 by Sergey Poznyakoff

Get quota value from mu_auth_data, if available.

1 parent 89375988
...@@ -23,13 +23,13 @@ ...@@ -23,13 +23,13 @@
23 23
24 #define DEFRETVAL MQUOTA_UNLIMITED 24 #define DEFRETVAL MQUOTA_UNLIMITED
25 25
26 size_t groupquota = 5*1024*1024UL; 26 mu_off_t groupquota = 5*1024*1024UL;
27 static int get_size (char *, size_t *, char **); 27 static int get_size (char *, mu_off_t *, char **);
28 28
29 int 29 int
30 get_size (char *str, size_t *size, char **endp) 30 get_size (char *str, mu_off_t *size, char **endp)
31 { 31 {
32 size_t s; 32 mu_off_t s;
33 33
34 s = strtol (str, &str, 0); 34 s = strtol (str, &str, 0);
35 switch (*str) 35 switch (*str)
...@@ -60,7 +60,7 @@ get_size (char *str, size_t *size, char **endp) ...@@ -60,7 +60,7 @@ get_size (char *str, size_t *size, char **endp)
60 #define RETR_FAILURE 1 60 #define RETR_FAILURE 1
61 61
62 int 62 int
63 fail_retrieve_quota (char *name, size_t *quota) 63 fail_retrieve_quota (char *name, mu_off_t *quota)
64 { 64 {
65 mu_error (_("No quota retrieving mechanism")); 65 mu_error (_("No quota retrieving mechanism"));
66 return RETR_FAILURE; 66 return RETR_FAILURE;
...@@ -68,7 +68,7 @@ fail_retrieve_quota (char *name, size_t *quota) ...@@ -68,7 +68,7 @@ fail_retrieve_quota (char *name, size_t *quota)
68 68
69 #ifdef USE_DBM 69 #ifdef USE_DBM
70 int 70 int
71 dbm_retrieve_quota (char *name, size_t *quota) 71 dbm_retrieve_quota (char *name, mu_off_t *quota)
72 { 72 {
73 DBM_FILE db; 73 DBM_FILE db;
74 DBM_DATUM named, contentd; 74 DBM_DATUM named, contentd;
...@@ -149,13 +149,13 @@ dbm_retrieve_quota (char *name, size_t *quota) ...@@ -149,13 +149,13 @@ dbm_retrieve_quota (char *name, size_t *quota)
149 #include <auth/sql.h> 149 #include <auth/sql.h>
150 150
151 int 151 int
152 sql_retrieve_quota (char *name, size_t *quota) 152 sql_retrieve_quota (char *name, mu_off_t *quota)
153 { 153 {
154 mu_sql_connection_t conn; 154 mu_sql_connection_t conn;
155 char *query_str; 155 char *query_str;
156 int rc, status; 156 int rc, status;
157 char *tmp; 157 char *tmp;
158 size_t n; 158 mu_off_t n;
159 159
160 query_str = mu_sql_expand_query (quota_query, name); 160 query_str = mu_sql_expand_query (quota_query, name);
161 if (!query_str) 161 if (!query_str)
...@@ -253,21 +253,29 @@ sql_retrieve_quota (char *name, size_t *quota) ...@@ -253,21 +253,29 @@ sql_retrieve_quota (char *name, size_t *quota)
253 253
254 254
255 static int 255 static int
256 retrieve_quota (char *name, size_t *quota) 256 retrieve_quota (struct mu_auth_data *auth, mu_off_t *quota)
257 { 257 {
258 if (MU_HAS_QUOTA (auth))
259 {
260 if (auth->quota == 0)
261 return RETR_UNLIMITED;
262 *quota = auth->quota;
263 return RETR_OK;
264 }
265
258 #ifdef USE_SQL 266 #ifdef USE_SQL
259 if (quota_query) 267 if (quota_query)
260 return sql_retrieve_quota (name, quota); 268 return sql_retrieve_quota (auth->name, quota);
261 #endif 269 #endif
262 return default_retrieve_quota (name, quota); 270 return default_retrieve_quota (auth->name, quota);
263 } 271 }
264 272
265 int 273 int
266 check_quota (char *name, size_t size, size_t *rest) 274 check_quota (struct mu_auth_data *auth, mu_off_t size, mu_off_t *rest)
267 { 275 {
268 size_t quota; 276 mu_off_t quota;
269 277
270 switch (retrieve_quota (name, &quota)) 278 switch (retrieve_quota (auth, &quota))
271 { 279 {
272 case RETR_FAILURE: 280 case RETR_FAILURE:
273 return DEFRETVAL; 281 return DEFRETVAL;
......