doxygen-ize publich functions; make config_read_file() not ignore errors frm underlying parser

This commit is contained in:
marschap
2006-09-18 10:37:51 +00:00
parent 9344df67ef
commit 086b56a60d
+64 -22
View File
@@ -53,7 +53,7 @@ static int process_config(section **current_section, char(*get_next_char)(), con
#ifdef WITH_LDAP_SUPPORT #ifdef WITH_LDAP_SUPPORT
int connect_to_ldap(void); static int connect_to_ldap(void);
static LDAP *ld = NULL; static LDAP *ld = NULL;
int use_ldap = 0; int use_ldap = 0;
@@ -68,12 +68,18 @@ int ldap_port;
#endif /* WITH_LDAP_SUPPORT */ #endif /* WITH_LDAP_SUPPORT */
/**** EXTERNAL FUNCTIONS ****/ /**** PUBLIC FUNCTIONS ****/
/** Parse configuration from INI-file style config file into memory.
* \param filename Name of the config file.
* \returns 0 : config successfully parsed
* \returns <0 : error occurred
*/
int config_read_file(const char *filename) int config_read_file(const char *filename)
{ {
FILE *f; FILE *f;
section *curr_section = NULL; section *curr_section = NULL;
int result = 0;
#ifdef WITH_LDAP_SUPPORT #ifdef WITH_LDAP_SUPPORT
LDAPURLDesc *url = NULL; LDAPURLDesc *url = NULL;
@@ -115,11 +121,11 @@ int config_read_file(const char *filename)
return -1; return -1;
} }
process_config(&curr_section, get_next_char_f, filename, f); result = process_config(&curr_section, get_next_char_f, filename, f);
fclose(f); fclose(f);
return 0; return result;
} }
@@ -137,12 +143,17 @@ int config_read_string(const char *sectionname, const char *str)
if ((s = find_section(sectionname)) == NULL) if ((s = find_section(sectionname)) == NULL)
s = add_section(sectionname); s = add_section(sectionname);
process_config(&s, get_next_char, 0, "command line", NULL); return process_config(&s, get_next_char, "command line", NULL);
return 0;
} }
/** Get string from configuration in memory.
* \param sectionname Name of the section where the key is sought.
* \param keyname Name of the key to look for.
* \param skip Number of values to skip/ignore before returning the value.
* \param default_value Default value if section/key is not found.
* \return Value found / default value
*/
const char *config_get_string(const char *sectionname, const char *keyname, const char *config_get_string(const char *sectionname, const char *keyname,
int skip, const char *default_value) int skip, const char *default_value)
{ {
@@ -165,6 +176,13 @@ const char *config_get_string(const char *sectionname, const char *keyname,
} }
/** Get boolean value from configuration in memory.
* \param sectionname Name of the section where the key is sought.
* \param keyname Name of the key to look for.
* \param skip Number of values to skip/ignore before returning the value.
* \param default_value Default value if section/key is not found or value is no legal boolean.
* \return Value found / default value
*/
short config_get_bool(const char *sectionname, const char *keyname, short config_get_bool(const char *sectionname, const char *keyname,
int skip, short default_value) int skip, short default_value)
{ {
@@ -187,6 +205,13 @@ short config_get_bool(const char *sectionname, const char *keyname,
} }
/** Get integer from configuration in memory.
* \param sectionname Name of the section where the key is sought.
* \param keyname Name of the key to look for.
* \param skip Number of values to skip/ignore before returning the value.
* \param default_value Default value if section/key is not found or value is no integer.
* \return Value found / default value
*/
long int config_get_int(const char *sectionname, const char *keyname, long int config_get_int(const char *sectionname, const char *keyname,
int skip, long int default_value) int skip, long int default_value)
{ {
@@ -204,6 +229,13 @@ long int config_get_int(const char *sectionname, const char *keyname,
} }
/** Get floating point number from configuration in memory.
* \param sectionname Name of the section where the key is sought.
* \param keyname Name of the key to look for.
* \param skip Number of values to skip/ignore before returning the value.
* \param default_value Default value if section/key is not found or value is no floating point number.
* \return Value found / default value
*/
double config_get_float(const char *sectionname, const char *keyname, double config_get_float(const char *sectionname, const char *keyname,
int skip, double default_value) int skip, double default_value)
{ {
@@ -221,12 +253,21 @@ double config_get_float(const char *sectionname, const char *keyname,
} }
/** Test whether the configuration containis a specific section.
* \param sectionname Name of the section to look for.
* \return 0 = section not in config; 1 = section in config
*/
int config_has_section(const char *sectionname) int config_has_section(const char *sectionname)
{ {
return (find_section(sectionname) != NULL) ? 1 : 0; return (find_section(sectionname) != NULL) ? 1 : 0;
} }
/** Test whether the configuration contains a specific key in a specfic section.
* \param sectionname Name of the section where the key is sought.
* \param keyname Name of the key to look for.
* \return 0 = key or section not found; n = key found with n values
*/
int config_has_key(const char *sectionname, const char *keyname) int config_has_key(const char *sectionname, const char *keyname)
{ {
section *s = find_section(sectionname); section *s = find_section(sectionname);
@@ -245,6 +286,7 @@ int config_has_key(const char *sectionname, const char *keyname)
} }
/** Clear configuration. */
void config_clear() void config_clear()
{ {
section *s; section *s;
@@ -277,7 +319,7 @@ void config_clear()
/**** INTERNAL FUNCTIONS ****/ /**** INTERNAL FUNCTIONS ****/
#ifdef WITH_LDAP_SUPPORT #ifdef WITH_LDAP_SUPPORT
int static int
connect_to_ldap(void) connect_to_ldap(void)
{ {
int retval; int retval;
@@ -552,17 +594,17 @@ static char get_next_char_f(FILE *f)
/* Parser states */ /* Parser states */
#define ST_INITIAL 0 #define ST_INITIAL 0
#define ST_IGNORE 1 #define ST_IGNORE 257
#define ST_SECTIONNAME 2 #define ST_SECTIONNAME 258
#define ST_KEYNAME 3 #define ST_KEYNAME 259
#define ST_VALUE 10 #define ST_VALUE 260
#define ST_QUOTEDVALUE 11 #define ST_QUOTEDVALUE 261
#define ST_QUOTEDVALUE_ESCCHAR 12 #define ST_QUOTEDVALUE_ESCCHAR 262
#define ST_INVALID_SECTIONNAME 23 #define ST_INVALID_SECTIONNAME 263
#define ST_INVALID_KEYNAME 24 #define ST_INVALID_KEYNAME 264
#define ST_INVALID_VALUE 30 #define ST_INVALID_VALUE 265
#define ST_INVALID_QUOTEDVALUE 31 #define ST_INVALID_QUOTEDVALUE 266
#define ST_END 99 #define ST_END 999
/* Limits */ /* Limits */
#define MAXSECTIONNAMELENGTH 40 #define MAXSECTIONNAMELENGTH 40
@@ -572,7 +614,7 @@ static char get_next_char_f(FILE *f)
static int process_config(section **current_section, char(*get_next_char)(), const char *source_descr, FILE *f) static int process_config(section **current_section, char(*get_next_char)(), const char *source_descr, FILE *f)
{ {
char state = ST_INITIAL; int state = ST_INITIAL;
char ch; char ch;
char sectionname[MAXSECTIONNAMELENGTH+1]; char sectionname[MAXSECTIONNAMELENGTH+1];
int sectionname_pos = 0; int sectionname_pos = 0;
@@ -712,7 +754,6 @@ static int process_config(section **current_section, char(*get_next_char)(), con
switch (ch) { switch (ch) {
case '\n': case '\n':
state = ST_INITIAL; state = ST_INITIAL;
/*case ' ':*/
} }
break; break;
case ST_VALUE: case ST_VALUE:
@@ -829,12 +870,13 @@ section *s;
fprintf(stderr, "[%s]\n", s->name); fprintf(stderr, "[%s]\n", s->name);
for (k = s->first_key; k != NULL; k = k->next_key) for (k = s->first_key; k != NULL; k = k->next_key)
fprintf(stderr, "%s = '%s'\n", k->name, k->value); fprintf(stderr, "%s = \"%s\"\n", k->name, k->value);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc > 0) if (argc > 0)