New global variable mu_site_rcfile keeps the name of the site-wide configuration file.
* include/mailutils/gocs.h (mu_site_rcfile): New extern. * include/mailutils/libcfg.h (MU_CONFIG_FILE): Remove. (mu_register_cfg_capa): Remove proto. (mu_libcfg_register_capa): New proto. * libmailutils/cfg/gocs.c (mu_site_rcfile): New variable. * libmu_argp/muinit.c (mu_app_init): Use mu_site_rcfile instead of MU_CONFIG_FILE. Destroy parse_tree when no longer needed. * libmu_cfg/init.c (cfg_capa_table): Static. (find_cfg_capa): Likewise. (reserved_name): Treat names starting with dot as reserved. (mu_libcfg_register_capa): New function. (mu_libcfg_parse_config): Use mu_site_rcfile instead of MU_CONFIG_FILE. * mu/query.c (mutool_query): Use mu_site_rcfile instead of MU_CONFIG_FILE.
Showing
6 changed files
with
30 additions
and
14 deletions
... | @@ -70,6 +70,7 @@ struct mu_gocs_virtual | ... | @@ -70,6 +70,7 @@ struct mu_gocs_virtual |
70 | }; | 70 | }; |
71 | 71 | ||
72 | /* Auxiliary variables for use by libargp/libcfg */ | 72 | /* Auxiliary variables for use by libargp/libcfg */ |
73 | extern char *mu_site_rcfile; | ||
73 | extern int mu_load_user_rcfile; | 74 | extern int mu_load_user_rcfile; |
74 | extern int mu_load_site_rcfile; | 75 | extern int mu_load_site_rcfile; |
75 | extern char *mu_load_rcfile; | 76 | extern char *mu_load_rcfile; | ... | ... |
... | @@ -25,10 +25,6 @@ | ... | @@ -25,10 +25,6 @@ |
25 | #include <mailutils/error.h> | 25 | #include <mailutils/error.h> |
26 | #include <mailutils/errno.h> | 26 | #include <mailutils/errno.h> |
27 | 27 | ||
28 | #ifndef MU_CONFIG_FILE | ||
29 | # define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc" | ||
30 | #endif | ||
31 | |||
32 | #ifndef MU_USER_CONFIG_FILE | 28 | #ifndef MU_USER_CONFIG_FILE |
33 | # define MU_USER_CONFIG_FILE "~/.mailutils" | 29 | # define MU_USER_CONFIG_FILE "~/.mailutils" |
34 | #endif | 30 | #endif |
... | @@ -44,10 +40,7 @@ struct mu_cfg_capa | ... | @@ -44,10 +40,7 @@ struct mu_cfg_capa |
44 | mu_cfg_section_fp parser; | 40 | mu_cfg_section_fp parser; |
45 | }; | 41 | }; |
46 | 42 | ||
47 | extern int mu_register_cfg_capa (const char *name, | 43 | extern int mu_libcfg_register_capa (struct mu_cfg_capa *capa); |
48 | struct mu_cfg_param *cfgparam, | ||
49 | mu_cfg_section_fp *parser); | ||
50 | |||
51 | extern void mu_libcfg_init (char **cnames); | 44 | extern void mu_libcfg_init (char **cnames); |
52 | extern int mu_parse_config_files (struct mu_cfg_param *param, | 45 | extern int mu_parse_config_files (struct mu_cfg_param *param, |
53 | void *target_ptr) MU_CFG_DEPRECATED; | 46 | void *target_ptr) MU_CFG_DEPRECATED; | ... | ... |
... | @@ -38,6 +38,11 @@ | ... | @@ -38,6 +38,11 @@ |
38 | #include <mailutils/log.h> | 38 | #include <mailutils/log.h> |
39 | #include <syslog.h> | 39 | #include <syslog.h> |
40 | 40 | ||
41 | #ifndef MU_CONFIG_FILE | ||
42 | # define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc" | ||
43 | #endif | ||
44 | |||
45 | char *mu_site_rcfile = MU_CONFIG_FILE; | ||
41 | int mu_load_user_rcfile = 1; | 46 | int mu_load_user_rcfile = 1; |
42 | int mu_load_site_rcfile = 1; | 47 | int mu_load_site_rcfile = 1; |
43 | char *mu_load_rcfile = NULL; | 48 | char *mu_load_rcfile = NULL; | ... | ... |
... | @@ -158,7 +158,7 @@ mu_app_init (struct argp *myargp, const char **capa, | ... | @@ -158,7 +158,7 @@ mu_app_init (struct argp *myargp, const char **capa, |
158 | mu_asprintf (&comment, | 158 | mu_asprintf (&comment, |
159 | "For use in global configuration file (%s), enclose it " | 159 | "For use in global configuration file (%s), enclose it " |
160 | "in `program %s { ... };", | 160 | "in `program %s { ... };", |
161 | MU_CONFIG_FILE, | 161 | mu_site_rcfile, |
162 | mu_program_name); | 162 | mu_program_name); |
163 | mu_cfg_format_docstring (stream, comment, 0); | 163 | mu_cfg_format_docstring (stream, comment, 0); |
164 | free (comment); | 164 | free (comment); |
... | @@ -207,6 +207,7 @@ mu_app_init (struct argp *myargp, const char **capa, | ... | @@ -207,6 +207,7 @@ mu_app_init (struct argp *myargp, const char **capa, |
207 | 207 | ||
208 | mu_gocs_flush (); | 208 | mu_gocs_flush (); |
209 | mu_cfg_destroy_tree (&mu_argp_tree); | 209 | mu_cfg_destroy_tree (&mu_argp_tree); |
210 | mu_cfg_destroy_tree (&parse_tree); | ||
210 | 211 | ||
211 | return !!(rc || mu_cfg_error_count); | 212 | return !!(rc || mu_cfg_error_count); |
212 | } | 213 | } | ... | ... |
... | @@ -24,7 +24,8 @@ | ... | @@ -24,7 +24,8 @@ |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | struct mu_cfg_capa *cfg_capa_table[] = { | 27 | #define CFG_CAPA_MAX 512 |
28 | static struct mu_cfg_capa *cfg_capa_table[CFG_CAPA_MAX] = { | ||
28 | #define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa) | 29 | #define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa) |
29 | S (auth), | 30 | S (auth), |
30 | S (mailbox), | 31 | S (mailbox), |
... | @@ -44,7 +45,9 @@ struct mu_cfg_capa *cfg_capa_table[] = { | ... | @@ -44,7 +45,9 @@ struct mu_cfg_capa *cfg_capa_table[] = { |
44 | NULL | 45 | NULL |
45 | }; | 46 | }; |
46 | 47 | ||
47 | struct mu_cfg_capa * | 48 | static int cfg_capa_index = MU_ARRAY_SIZE(cfg_capa_table) - 1; |
49 | |||
50 | static struct mu_cfg_capa * | ||
48 | find_cfg_capa (const char *name) | 51 | find_cfg_capa (const char *name) |
49 | { | 52 | { |
50 | int i; | 53 | int i; |
... | @@ -60,12 +63,25 @@ reserved_name (const char *name) | ... | @@ -60,12 +63,25 @@ reserved_name (const char *name) |
60 | { | 63 | { |
61 | static char *reserved[] = { "common", NULL }; | 64 | static char *reserved[] = { "common", NULL }; |
62 | char **p; | 65 | char **p; |
66 | |||
67 | if (name[0] == '.') | ||
68 | return 1; | ||
69 | |||
63 | for (p = reserved; *p; p++) | 70 | for (p = reserved; *p; p++) |
64 | if (strcmp (name, *p) == 0) | 71 | if (strcmp (name, *p) == 0) |
65 | return 1; | 72 | return 1; |
66 | return 0; | 73 | return 0; |
67 | } | 74 | } |
68 | 75 | ||
76 | int | ||
77 | mu_libcfg_register_capa (struct mu_cfg_capa *capa) | ||
78 | { | ||
79 | if (cfg_capa_index == CFG_CAPA_MAX) | ||
80 | return MU_ERR_NOENT; | ||
81 | cfg_capa_table[cfg_capa_index++] = capa; | ||
82 | return 0; | ||
83 | } | ||
84 | |||
69 | void | 85 | void |
70 | mu_libcfg_init (char **cnames) | 86 | mu_libcfg_init (char **cnames) |
71 | { | 87 | { |
... | @@ -100,7 +116,7 @@ mu_libcfg_parse_config (mu_cfg_tree_t **ptree) | ... | @@ -100,7 +116,7 @@ mu_libcfg_parse_config (mu_cfg_tree_t **ptree) |
100 | if (mu_load_site_rcfile) | 116 | if (mu_load_site_rcfile) |
101 | { | 117 | { |
102 | hints.flags |= MU_CFG_PARSE_SITE_RCFILE; | 118 | hints.flags |= MU_CFG_PARSE_SITE_RCFILE; |
103 | hints.site_rcfile = MU_CONFIG_FILE; | 119 | hints.site_rcfile = mu_site_rcfile; |
104 | } | 120 | } |
105 | 121 | ||
106 | if (mu_load_user_rcfile && mu_program_name) | 122 | if (mu_load_user_rcfile && mu_program_name) |
... | @@ -134,7 +150,7 @@ mu_parse_config_files (struct mu_cfg_param *param, void *target) | ... | @@ -134,7 +150,7 @@ mu_parse_config_files (struct mu_cfg_param *param, void *target) |
134 | 150 | ||
135 | if (mu_load_site_rcfile) | 151 | if (mu_load_site_rcfile) |
136 | { | 152 | { |
137 | rc = mu_parse_config (MU_CONFIG_FILE, mu_program_name, param, | 153 | rc = mu_parse_config (mu_site_rcfile, mu_program_name, param, |
138 | flags | MU_PARSE_CONFIG_GLOBAL, target); | 154 | flags | MU_PARSE_CONFIG_GLOBAL, target); |
139 | if (rc == ENOMEM) | 155 | if (rc == ENOMEM) |
140 | { | 156 | { | ... | ... |
... | @@ -114,7 +114,7 @@ mutool_query (int argc, char **argv) | ... | @@ -114,7 +114,7 @@ mutool_query (int argc, char **argv) |
114 | } | 114 | } |
115 | 115 | ||
116 | hints.flags |= MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL; | 116 | hints.flags |= MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL; |
117 | hints.site_rcfile = file_name ? file_name : MU_CONFIG_FILE; | 117 | hints.site_rcfile = file_name ? file_name : mu_site_rcfile; |
118 | 118 | ||
119 | if (mu_cfg_parse_config (&tree, &hints)) | 119 | if (mu_cfg_parse_config (&tree, &hints)) |
120 | return 1; | 120 | return 1; | ... | ... |
-
Please register or sign in to post a comment