mdbox-settings.c revision 9ff39148453aa6db8887ec1cde46bd7489109c09
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2006-2010 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "lib.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "settings-parser.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mail-storage-settings.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mdbox-settings.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include <stddef.h>
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#undef DEF
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DEF(type, name) \
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen { type, #name, offsetof(struct mdbox_settings, name), NULL }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic bool mdbox_settings_verify(void *_set, pool_t pool ATTR_UNUSED,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char **error_r);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_define mdbox_setting_defines[] = {
61618d4c58080570f689614fec204ae14e90cef2Timo Sirainen DEF(SET_SIZE, mdbox_rotate_size),
61618d4c58080570f689614fec204ae14e90cef2Timo Sirainen DEF(SET_SIZE, mdbox_rotate_min_size),
9ff39148453aa6db8887ec1cde46bd7489109c09Timo Sirainen DEF(SET_TIME, mdbox_rotate_interval),
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen DEF(SET_UINT, mdbox_max_open_files),
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen DEF(SET_UINT, mdbox_purge_min_percentage),
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen SETTING_DEFINE_LIST_END
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct mdbox_settings mdbox_default_settings = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .mdbox_rotate_size = 2*1024*1024,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .mdbox_rotate_min_size = 16*1024,
9ff39148453aa6db8887ec1cde46bd7489109c09Timo Sirainen .mdbox_rotate_interval = 0,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .mdbox_max_open_files = 64,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .mdbox_purge_min_percentage = 0
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic const struct setting_parser_info mdbox_setting_parser_info = {
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .module_name = "mdbox",
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defines = mdbox_setting_defines,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .defaults = &mdbox_default_settings,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .type_offset = (size_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .struct_size = sizeof(struct mdbox_settings),
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .parent_offset = (size_t)-1,
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .parent = &mail_user_setting_parser_info,
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen .check_func = mdbox_settings_verify
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* <settings checks> */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic bool mdbox_settings_verify(void *_set, pool_t pool ATTR_UNUSED,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char **error_r)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mdbox_settings *set = _set;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (set->mdbox_max_open_files < 2) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen *error_r = "mdbox_max_open_files must be at least 2";
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return FALSE;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return TRUE;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* </settings checks> */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenconst struct setting_parser_info *mdbox_get_setting_parser_info(void)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return &mdbox_setting_parser_info;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}