Commit 4bcd5c9d 4bcd5c9de0cb6ca85bcc3a35b1518739b939b009 by Sergey Poznyakoff

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.
1 parent ad938c5a
......@@ -70,6 +70,7 @@ struct mu_gocs_virtual
};
/* Auxiliary variables for use by libargp/libcfg */
extern char *mu_site_rcfile;
extern int mu_load_user_rcfile;
extern int mu_load_site_rcfile;
extern char *mu_load_rcfile;
......
......@@ -25,10 +25,6 @@
#include <mailutils/error.h>
#include <mailutils/errno.h>
#ifndef MU_CONFIG_FILE
# define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
#endif
#ifndef MU_USER_CONFIG_FILE
# define MU_USER_CONFIG_FILE "~/.mailutils"
#endif
......@@ -44,10 +40,7 @@ struct mu_cfg_capa
mu_cfg_section_fp parser;
};
extern int mu_register_cfg_capa (const char *name,
struct mu_cfg_param *cfgparam,
mu_cfg_section_fp *parser);
extern int mu_libcfg_register_capa (struct mu_cfg_capa *capa);
extern void mu_libcfg_init (char **cnames);
extern int mu_parse_config_files (struct mu_cfg_param *param,
void *target_ptr) MU_CFG_DEPRECATED;
......
......@@ -38,6 +38,11 @@
#include <mailutils/log.h>
#include <syslog.h>
#ifndef MU_CONFIG_FILE
# define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
#endif
char *mu_site_rcfile = MU_CONFIG_FILE;
int mu_load_user_rcfile = 1;
int mu_load_site_rcfile = 1;
char *mu_load_rcfile = NULL;
......
......@@ -158,7 +158,7 @@ mu_app_init (struct argp *myargp, const char **capa,
mu_asprintf (&comment,
"For use in global configuration file (%s), enclose it "
"in `program %s { ... };",
MU_CONFIG_FILE,
mu_site_rcfile,
mu_program_name);
mu_cfg_format_docstring (stream, comment, 0);
free (comment);
......@@ -207,6 +207,7 @@ mu_app_init (struct argp *myargp, const char **capa,
mu_gocs_flush ();
mu_cfg_destroy_tree (&mu_argp_tree);
mu_cfg_destroy_tree (&parse_tree);
return !!(rc || mu_cfg_error_count);
}
......
......@@ -24,7 +24,8 @@
#include <string.h>
#include <stdlib.h>
struct mu_cfg_capa *cfg_capa_table[] = {
#define CFG_CAPA_MAX 512
static struct mu_cfg_capa *cfg_capa_table[CFG_CAPA_MAX] = {
#define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa)
S (auth),
S (mailbox),
......@@ -44,7 +45,9 @@ struct mu_cfg_capa *cfg_capa_table[] = {
NULL
};
struct mu_cfg_capa *
static int cfg_capa_index = MU_ARRAY_SIZE(cfg_capa_table) - 1;
static struct mu_cfg_capa *
find_cfg_capa (const char *name)
{
int i;
......@@ -60,12 +63,25 @@ reserved_name (const char *name)
{
static char *reserved[] = { "common", NULL };
char **p;
if (name[0] == '.')
return 1;
for (p = reserved; *p; p++)
if (strcmp (name, *p) == 0)
return 1;
return 0;
}
int
mu_libcfg_register_capa (struct mu_cfg_capa *capa)
{
if (cfg_capa_index == CFG_CAPA_MAX)
return MU_ERR_NOENT;
cfg_capa_table[cfg_capa_index++] = capa;
return 0;
}
void
mu_libcfg_init (char **cnames)
{
......@@ -100,7 +116,7 @@ mu_libcfg_parse_config (mu_cfg_tree_t **ptree)
if (mu_load_site_rcfile)
{
hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
hints.site_rcfile = MU_CONFIG_FILE;
hints.site_rcfile = mu_site_rcfile;
}
if (mu_load_user_rcfile && mu_program_name)
......@@ -134,7 +150,7 @@ mu_parse_config_files (struct mu_cfg_param *param, void *target)
if (mu_load_site_rcfile)
{
rc = mu_parse_config (MU_CONFIG_FILE, mu_program_name, param,
rc = mu_parse_config (mu_site_rcfile, mu_program_name, param,
flags | MU_PARSE_CONFIG_GLOBAL, target);
if (rc == ENOMEM)
{
......
......@@ -114,7 +114,7 @@ mutool_query (int argc, char **argv)
}
hints.flags |= MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL;
hints.site_rcfile = file_name ? file_name : MU_CONFIG_FILE;
hints.site_rcfile = file_name ? file_name : mu_site_rcfile;
if (mu_cfg_parse_config (&tree, &hints))
return 1;
......