]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc backend parameter parsing changed to use common function
authorSergey Kitov <sergey.kitov@open-xchange.com>
Fri, 19 May 2017 07:52:46 +0000 (10:52 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 23 May 2017 08:14:26 +0000 (11:14 +0300)
src/plugins/quota/quota-imapc.c

index a3d64941dde85b35a19f14b70a6f97df82055200..0aea5ea122a2d2d193da5eb2dacb6fccbd5ee5f2 100644 (file)
@@ -46,26 +46,30 @@ static struct quota_root *imapc_quota_alloc(void)
        return &root->root;
 }
 
+static void handle_box_param(struct quota_root *_root, const char *param_value)
+{
+       ((struct imapc_quota_root *)_root)->box_name = p_strdup(_root->pool, param_value);
+}
+
+static void handle_root_param(struct quota_root *_root, const char *param_value)
+{
+       ((struct imapc_quota_root *)_root)->root_name = p_strdup(_root->pool, param_value);
+}
+
 static int imapc_quota_init(struct quota_root *_root, const char *args,
                            const char **error_r)
 {
        struct imapc_quota_root *root = (struct imapc_quota_root *)_root;
-       const char *const *tmp;
-
-       if (args == NULL)
-               args = "";
-       for (tmp = t_strsplit(args, ":"); *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "ns=", 3) == 0)
-                       _root->ns_prefix = p_strdup(_root->pool, *tmp + 3);
-               else if (strncmp(*tmp, "box=", 4) == 0)
-                       root->box_name = p_strdup(_root->pool, *tmp + 4);
-               else if (strncmp(*tmp, "root=", 5) == 0)
-                       root->root_name = p_strdup(_root->pool, *tmp + 5);
-               else {
-                       *error_r = t_strdup_printf("Invalid parameter: %s", *tmp);
-                       return -1;
-               }
-       }
+       const struct quota_param_parser imapc_params[] = {
+               {.param_name = "box=", .param_handler = handle_box_param},
+               {.param_name = "root=", .param_handler = handle_root_param},
+               quota_param_ns,
+               {.param_name = NULL}
+       };
+
+       if (quota_parse_parameters(_root, &args, error_r, imapc_params, FALSE) < 0)
+               return -1;
+
        if (root->box_name == NULL && root->root_name == NULL)
                root->box_name = "INBOX";
        /* we'll never try to enforce the quota - it's just a lot of