1 #ifndef SETTINGS_H 2 #define SETTINGS_H 3 4 /* 5 * Note: 6 * 7 * The definitions in this file are used for parsing of external config 8 * files and *not* for parsing of dovecot.conf. Unfortunately, the types 9 * here (e.g., enum settings_type) collide with those in settings-parser.h. 10 * 11 * We should remove the need for this file in v3.0. 12 */ 13 14 enum setting_type { 15 SET_STR, 16 SET_INT, 17 SET_BOOL 18 }; 19 20 struct setting_def { 21 enum setting_type type; 22 const char *name; 23 size_t offset; 24 }; 25 26 #define DEF_STRUCT_STR(name, struct_name) \ 27 { SET_STR + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \ 28 ((struct struct_name *)0)->name, const char *), \ 29 #name, offsetof(struct struct_name, name) } 30 #define DEF_STRUCT_INT(name, struct_name) \ 31 { SET_INT + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \ 32 ((struct struct_name *)0)->name, unsigned int), \ 33 #name, offsetof(struct struct_name, name) } 34 #define DEF_STRUCT_BOOL(name, struct_name) \ 35 { SET_BOOL + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \ 36 ((struct struct_name *)0)->name, bool), \ 37 #name, offsetof(struct struct_name, name) } 38 39 /* Return error message. When closing section, key = NULL, value = NULL. */ 40 typedef const char *settings_callback_t(const char *key, const char *value, 41 void *context); 42 43 /* Return TRUE if we want to go inside the section */ 44 typedef bool settings_section_callback_t(const char *type, const char *name, 45 void *context, const char **errormsg); 46 47 extern settings_section_callback_t *null_settings_section_callback; 48 49 const char * 50 parse_setting_from_defs(pool_t pool, const struct setting_def *defs, void *base, 51 const char *key, const char *value); 52 53 bool settings_read_i(const char *path, const char *section, 54 settings_callback_t *callback, 55 settings_section_callback_t *sect_callback, void *context, 56 const char **error_r) 57 ATTR_NULL(2, 4, 5); 58 #define settings_read(path, section, callback, sect_callback, context, error_r) \ 59 settings_read_i(path - \ 60 CALLBACK_TYPECHECK(callback, const char *(*)( \ 61 const char *, const char *, typeof(context))) - \ 62 CALLBACK_TYPECHECK(sect_callback, bool (*)( \ 63 const char *, const char *, typeof(context), \ 64 const char **)), \ 65 section, (settings_callback_t *)callback, \ 66 (settings_section_callback_t *)sect_callback, context, error_r) 67 #define settings_read_nosection(path, callback, context, error_r) \ 68 settings_read_i(path - \ 69 CALLBACK_TYPECHECK(callback, const char *(*)( \ 70 const char *, const char *, typeof(context))), \ 71 NULL, (settings_callback_t *)callback, NULL, context, error_r) 72 73 #endif 74