diff options
author | laforge <laforge> | 2004-10-03 09:20:10 +0000 |
---|---|---|
committer | laforge <laforge> | 2004-10-03 09:20:10 +0000 |
commit | 6023b98a2980bab6d854e19cc79ee2560c4e32f1 (patch) | |
tree | a6acc9661b4dd740a7fe810691c0c507bcce1362 | |
parent | 11db6a39c00d81efaa28187e774ddee4e7bd19d0 (diff) |
- remove 'config_entry_t' typedef. use structure name.
- fix typo in debug message
- now uses arrays of 'struct config_entry' instead of linked list
- introduce 'struct config_kset' to describe array of config_entries
-rw-r--r-- | conffile/conffile.c | 33 | ||||
-rw-r--r-- | include/ulogd/conffile.h | 16 |
2 files changed, 20 insertions, 29 deletions
diff --git a/conffile/conffile.c b/conffile/conffile.c index d26c5ff..ef7112e 100644 --- a/conffile/conffile.c +++ b/conffile/conffile.c @@ -1,8 +1,8 @@ /* config file parser functions * - * (C) 2000 by Harald Welte <laforge@gnumonks.org> + * (C) 2000-2004 by Harald Welte <laforge@gnumonks.org> * - * $Id: conffile.c,v 1.4 2001/09/01 11:51:53 laforge Exp $ + * $Id$ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -30,7 +30,7 @@ #endif /* points to config entry with error */ -config_entry_t *config_errce = NULL; +struct config_entry *config_errce = NULL; /* Filename of the config file */ static char *fname = NULL; @@ -90,21 +90,6 @@ static char *get_word(char *line, char *not, char *buf) return stop; } -#if 0 -/* do we have a config directive for this name */ -static int config_iskey(char *name) -{ - config_entry_t *ce; - - for (ce = config; ce; ce = ce->next) { - if (!strcmp(name, ce->key)) - return 0; - } - - return 1; -} -#endif - /*********************************************************************** * PUBLIC INTERFACE ***********************************************************************/ @@ -126,11 +111,10 @@ int config_register_file(const char *file) } /* parse config file */ -int config_parse_file(const char *section, config_entry_t *keys) +int config_parse_file(const char *section, struct config_keyset *kset) { FILE *cfile; char *args; - config_entry_t *ce; int err = 0; int found = 0; char linebuf[LINE_LEN+1]; @@ -140,7 +124,7 @@ int config_parse_file(const char *section, config_entry_t *keys) if (!cfile) return -ERROPEN; - DEBUGC("prasing section [%s]\n", section); + DEBUGC("parsing section [%s]\n", section); /* Search for correct section */ while (fgets(line, LINE_LEN, cfile)) { @@ -167,6 +151,7 @@ int config_parse_file(const char *section, config_entry_t *keys) /* Parse this section until next section */ while (fgets(line, LINE_LEN, cfile)) { + int i; char wordbuf[LINE_LEN]; char *wordend; @@ -183,7 +168,8 @@ int config_parse_file(const char *section, config_entry_t *keys) } DEBUGC("parse_file: entering main loop\n"); - for (ce = keys; ce; ce = ce->next) { + for (i = 0; i < kset->num_ces; i++) { + struct config_entry *ce = kset->ces[i]; DEBUGC("parse main loop, key: %s\n", ce->key); if (strcmp(ce->key, (char *) &wordbuf)) { continue; @@ -222,7 +208,8 @@ int config_parse_file(const char *section, config_entry_t *keys) } - for (ce = keys; ce; ce = ce->next) { + for (i = 0; i < kset->num_ces; i++) { + struct config_entry *ce = kset->ces[i]; DEBUGC("ce post loop, ce=%s\n", ce->key); if ((ce->options & CONFIG_OPT_MANDATORY) && (ce->hit == 0)) { DEBUGC("Mandatory config directive \"%s\" not found\n", diff --git a/include/ulogd/conffile.h b/include/ulogd/conffile.h index 4a390d2..d16aed8 100644 --- a/include/ulogd/conffile.h +++ b/include/ulogd/conffile.h @@ -2,7 +2,7 @@ * * (C) 2000 by Harald Welte <laforge@gnumonks.org> * - * $Id: conffile.h,v 1.2 2001/05/26 23:19:28 laforge Exp $ + * $Id$ * * This code is distributed under the terms of GNU GPL */ @@ -41,8 +41,7 @@ enum { #define CONFIG_OPT_MANDATORY 0x0001 #define CONFIG_OPT_MULTI 0x0002 -typedef struct config_entry { - struct config_entry *next; /* the next one in linked list */ +struct config_entry { char key[CONFIG_KEY_LEN]; /* name of config directive */ u_int8_t type; /* type; see above */ u_int8_t options; /* options; see above */ @@ -52,15 +51,20 @@ typedef struct config_entry { int value; int (*parser)(char *argstr); } u; -} config_entry_t; +}; + +struct config_keyset { + unsigned int num_ces; + struct config_entry ces[]; +}; /* if an error occurs, config_errce is set to the erroneous ce */ -extern config_entry_t *config_errce; +extern struct config_entry *config_errce; /* tell us the name of the config file */ int config_register_file(const char *file); /* parse the config file */ -int config_parse_file(const char *section, config_entry_t *keys); +int config_parse_file(const char *section, struct config_keyset *kset); #endif /* ifndef _CONFFILE_H */ |