summaryrefslogtreecommitdiff
path: root/gconfig.c
diff options
context:
space:
mode:
authorvenaas <venaas>2007-11-28 14:11:47 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2007-11-28 14:11:47 +0000
commit18592cef57c5a05d97dbdc56df5a1191bce494b0 (patch)
tree4ee4854dfced9db4c40c3d0902d8068c0cd6ef39 /gconfig.c
parentcbd283e0022dd394799786c6504c85df7fd40b5b (diff)
working include support for individual files
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@199 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'gconfig.c')
-rw-r--r--gconfig.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/gconfig.c b/gconfig.c
index 05efcec..b286426 100644
--- a/gconfig.c
+++ b/gconfig.c
@@ -56,10 +56,12 @@ FILE *pushgconffile(struct gconffile **cf, const char *path) {
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++);
@@ -80,8 +82,10 @@ FILE *popgconffile(struct gconffile **cf) {
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;
@@ -101,15 +105,23 @@ FILE *popgconffile(struct gconffile **cf) {
* ...
* }
*/
-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 : "#");
@@ -155,7 +167,12 @@ void getgenericconfig(FILE *f, char *block, ...) {
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);
@@ -171,7 +188,7 @@ void getgenericconfig(FILE *f, char *block, ...) {
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");
@@ -226,7 +243,7 @@ void getgenericconfig(FILE *f, char *block, ...) {
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: