summaryrefslogtreecommitdiff
path: root/gconfig.c
diff options
context:
space:
mode:
authorvenaas <venaas>2007-11-26 12:14:30 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2007-11-26 12:14:30 +0000
commitcbd283e0022dd394799786c6504c85df7fd40b5b (patch)
treed73cf8ba9ad7f30fa5ec939c47d5d8e604cdb657 /gconfig.c
parentddddde8f5202c6ae5da26b19e2c6a84709b8ea4d (diff)
implemented config file stack; to be used for include support
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@198 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'gconfig.c')
-rw-r--r--gconfig.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/gconfig.c b/gconfig.c
index 8040190..05efcec 100644
--- a/gconfig.c
+++ b/gconfig.c
@@ -46,6 +46,51 @@ char *strtokenquote(char *s, char **token, char *del, char *quote, char *comment
return t + 1;
}
+FILE *pushgconffile(struct gconffile **cf, const char *path) {
+ int i;
+ struct gconffile *newcf;
+ FILE *f;
+
+ f = fopen(path, "r");
+ if (!f) {
+ debug(DBG_INFO, "could not read config file %s", path);
+ return NULL;
+ }
+ if (!*cf) {
+ newcf = malloc(sizeof(struct gconffile) * 2);
+ if (!newcf)
+ debugx(1, DBG_ERR, "malloc failed");
+ newcf[1].path = NULL;
+ } else {
+ for (i = 0; (*cf)[i].path; i++);
+ newcf = realloc(*cf, sizeof(struct gconffile) * (i + 2));
+ if (!newcf)
+ debugx(1, DBG_ERR, "malloc failed");
+ memmove(newcf + 1, newcf, sizeof(struct gconffile) * (i + 1));
+ }
+ newcf[0].file = f;
+ newcf[0].path = stringcopy(path, 0);
+ *cf = newcf;
+ return f;
+}
+
+FILE *popgconffile(struct gconffile **cf) {
+ int i;
+
+ if (!*cf)
+ return NULL;
+ for (i = 0; (*cf)[i].path; i++);
+ if (i && (*cf)[0].file)
+ fclose((*cf)[0].file);
+ if (i < 2) {
+ free(*cf);
+ *cf = NULL;
+ return NULL;
+ }
+ memmove(*cf, *cf + 1, sizeof(struct gconffile) * i);
+ return (*cf)[0].file;
+}
+
/* Parses config with following syntax:
* One of these:
* option-name value