init.c
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* This file is part of GNU Mailutils
Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
Inc.
GNU Mailutils is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 3, or (at
your option) any later version.
GNU Mailutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
#include "mailutils/libcfg.h"
#include <string.h>
#include <stdlib.h>
struct mu_cfg_capa *cfg_capa_table[] = {
#define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa)
S (auth),
S (mailbox),
S (locking),
S (address),
S (mailer),
S (logging),
S (gsasl),
S (pam),
S (radius),
S (sql),
S (tls),
S (virtdomain),
S (sieve),
S (ldap),
S (debug),
NULL
};
struct mu_cfg_capa *
find_cfg_capa (const char *name)
{
int i;
for (i = 0; cfg_capa_table[i]; i++)
if (strcmp (cfg_capa_table[i]->name, name) == 0)
return cfg_capa_table[i];
return NULL;
}
static int
reserved_name (const char *name)
{
static char *reserved[] = { "common", NULL };
char **p;
for (p = reserved; *p; p++)
if (strcmp (name, *p) == 0)
return 1;
return 0;
}
void
mu_libcfg_init (char **cnames)
{
int i;
for (i = 0; cnames[i]; i++)
{
if (!reserved_name (cnames[i]))
{
struct mu_cfg_capa *cp = find_cfg_capa (cnames[i]);
if (!cp)
mu_error (_("unknown configuration group requested `%s'"),
cnames[i]);
else
mu_config_register_section (NULL, cp->name, NULL,
cp->parser, cp->cfgparam);
}
}
}
int
mu_libcfg_parse_config (mu_cfg_tree_t **ptree)
{
struct mu_cfg_parse_hints hints;
memset (&hints, 0, sizeof (hints));
if (mu_cfg_parser_verbose)
hints.flags |= MU_PARSE_CONFIG_VERBOSE;
if (mu_cfg_parser_verbose > 1)
hints.flags |= MU_PARSE_CONFIG_DUMP;
if (mu_load_site_rcfile)
{
hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
hints.site_rcfile = MU_CONFIG_FILE;
}
if (mu_load_user_rcfile && mu_program_name)
{
hints.flags |= MU_CFG_PARSE_PROGRAM;
hints.program = (char*) mu_program_name;
}
if (mu_load_rcfile)
{
hints.flags |= MU_CFG_PARSE_CUSTOM_RCFILE;
hints.custom_rcfile = mu_load_rcfile;
}
return mu_cfg_parse_config (ptree, &hints);
}
/* FIXME: Deprecated */
int
mu_parse_config_files (struct mu_cfg_param *param, void *target)
{
int flags = 0;
int rc;
if (mu_cfg_parser_verbose)
flags |= MU_PARSE_CONFIG_VERBOSE;
if (mu_cfg_parser_verbose > 1)
flags |= MU_PARSE_CONFIG_DUMP;
if (mu_load_site_rcfile)
{
rc = mu_parse_config (MU_CONFIG_FILE, mu_program_name, param,
flags | MU_PARSE_CONFIG_GLOBAL, target);
if (rc == ENOMEM)
{
mu_error ("%s", mu_strerror (rc));
return rc;
}
}
if (mu_load_user_rcfile && mu_program_name)
{
size_t size = 3 + strlen (mu_program_name) + 1;
char *file_name = malloc (size);
if (file_name)
{
strcpy (file_name, "~/.");
strcat (file_name, mu_program_name);
rc = mu_parse_config (file_name, mu_program_name, param, flags,
target);
if (rc == ENOMEM)
{
mu_error ("%s", mu_strerror (rc));
return rc;
}
free (file_name);
}
}
if (mu_load_rcfile)
{
rc = mu_parse_config (mu_load_rcfile, mu_program_name, param,
flags, target);
if (rc)
{
mu_error (_("errors parsing file %s: %s"), mu_load_rcfile,
mu_strerror (rc));
return rc;
}
}
return 0;
}