debug(DBG_INFO, "could not read config file %s", path);
return NULL;
}
+ debug(DBG_DBG, "opened config file %s", path);
if (!*cf) {
newcf = malloc(sizeof(struct gconffile) * 2);
if (!newcf)
debugx(1, DBG_ERR, "malloc failed");
+ newcf[1].file = NULL;
newcf[1].path = NULL;
} else {
for (i = 0; (*cf)[i].path; i++);
if (!*cf)
return NULL;
for (i = 0; (*cf)[i].path; i++);
- if (i && (*cf)[0].file)
+ if (i && (*cf)[0].file) {
fclose((*cf)[0].file);
+ debug(DBG_DBG, "closing config file %s", (*cf)[0].path);
+ }
if (i < 2) {
free(*cf);
*cf = NULL;
* ...
* }
*/
-void getgenericconfig(FILE *f, char *block, ...) {
+void getgenericconfig(struct gconffile **cf, char *block, ...) {
va_list ap;
char line[1024];
/* initialise lots of stuff to avoid stupid compiler warnings */
char *tokens[3], *s, *opt = NULL, *val = NULL, *word, *optval, **str = NULL, ***mstr = NULL;
int type = 0, tcount, conftype = 0, n;
- void (*cbk)(FILE *, char *, char *, char *) = NULL;
-
- while (fgets(line, 1024, f)) {
+
+ void (*cbk)(struct gconffile **, char *, char *, char *) = NULL;
+
+ if (!cf || !*cf || !(*cf)->file)
+ return;
+ for (;;) {
+ if (!fgets(line, 1024, (*cf)->file)) {
+ if (popgconffile(cf))
+ continue;
+ return;
+ }
s = line;
for (tcount = 0; tcount < 3; tcount++) {
s = strtokenquote(s, &tokens[tcount], " \t\r\n", "\"'", tcount ? NULL : "#");
if (!*val)
debugx(1, DBG_ERR, "configuration error, option %s needs a non-empty value", opt);
-
+
+ if (conftype == CONF_STR && !strcasecmp(opt, "include")) {
+ pushgconffile(cf, val);
+ continue;
+ }
+
va_start(ap, block);
while ((word = va_arg(ap, char *))) {
type = va_arg(ap, int);
debugx(1, DBG_ERR, "getgeneralconfig: internal parameter error");
break;
case CONF_CBK:
- cbk = va_arg(ap, void (*)(FILE *, char *, char *, char *));
+ cbk = va_arg(ap, void (*)(struct gconffile **, char *, char *, char *));
break;
default:
debugx(1, DBG_ERR, "getgeneralconfig: internal parameter error");
if (!optval)
debugx(1, DBG_ERR, "malloc failed");
sprintf(optval, "%s %s", opt, val);
- cbk(f, optval, opt, val);
+ cbk(cf, optval, opt, val);
free(optval);
break;
default:
return 1;
}
-void confclient_cb(FILE *f, char *block, char *opt, char *val) {
+void confclient_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char *type = NULL, *tls = NULL, *matchcertattr = NULL, *rewriteattr = NULL;
struct clsrvconf *conf;
debugx(1, DBG_ERR, "malloc failed");
memset(conf, 0, sizeof(struct clsrvconf));
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"type", CONF_STR, &type,
"host", CONF_STR, &conf->host,
"secret", CONF_STR, &conf->secret,
}
}
-void confserver_cb(FILE *f, char *block, char *opt, char *val) {
+void confserver_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char *type = NULL, *tls = NULL, *matchcertattr = NULL, *statusserver = NULL;
struct clsrvconf *conf;
debugx(1, DBG_ERR, "malloc failed");
memset(conf, 0, sizeof(struct clsrvconf));
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"type", CONF_STR, &type,
"host", CONF_STR, &conf->host,
"port", CONF_STR, &conf->port,
}
}
-void confrealm_cb(FILE *f, char *block, char *opt, char *val) {
+void confrealm_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char **servers = NULL, *msg = NULL;
debug(DBG_DBG, "confrealm_cb called for %s", block);
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"server", CONF_MSTR, &servers,
"ReplyMessage", CONF_STR, &msg,
NULL
free(servers);
}
-void conftls_cb(FILE *f, char *block, char *opt, char *val) {
+void conftls_cb(struct gconffile **cf, char *block, char *opt, char *val) {
char *cacertfile = NULL, *cacertpath = NULL, *certfile = NULL, *certkeyfile = NULL, *certkeypwd = NULL;
debug(DBG_DBG, "conftls_cb called for %s", block);
- getgenericconfig(f, block,
+ getgenericconfig(cf, block,
"CACertificateFile", CONF_STR, &cacertfile,
"CACertificatePath", CONF_STR, &cacertpath,
"CertificateFile", CONF_STR, &certfile,
}
void getmainconfig(const char *configfile) {
- FILE *f;
char *loglevel = NULL;
struct gconffile *cfs;
cfs = openconfigfile(configfile);
- f = cfs->file;
memset(&options, 0, sizeof(options));
clconfs = list_create();
if (!tlsconfs)
debugx(1, DBG_ERR, "malloc failed");
- getgenericconfig(f, NULL,
+ getgenericconfig(&cfs, NULL,
"ListenUDP", CONF_STR, &options.listenudp,
"ListenTCP", CONF_STR, &options.listentcp,
"ListenAccountingUDP", CONF_STR, &options.listenaccudp,