#include "conffile.h"
#include "xlog.h"
-static void conf_load_defaults (int);
+#pragma GCC visibility push(hidden)
+
+static void conf_load_defaults(void);
static int conf_set(int , char *, char *, char *,
char *, int , int );
conf_parse_line(int trans, char *line, size_t sz)
{
char *val, *ptr;
- size_t i;
- int j;
+ size_t i, valsize;
+ size_t j;
static char *section = 0;
static char *arg = 0;
static int ln = 0;
/* Lines starting with '#' or ';' are comments. */
ln++;
- if (*line == '#' || *line == ';')
- return;
-
/* Ignore blank lines */
if (*line == '\0')
return;
while (isblank(*line))
line++;
+ if (*line == '#' || *line == ';')
+ return;
+
/* '[section]' parsing... */
if (*line == '[') {
line++;
if (section)
free(section);
if (i == sz) {
- xlog_warn("conf_parse_line: %d:"
+ xlog_warn("config file error: line %d: "
"non-matched ']', ignoring until next section", ln);
section = 0;
return;
}
/* Strip off any blanks before ']' */
val = line;
+ j=0;
while (*val && !isblank(*val))
val++, j++;
if (*val)
i = j;
- section = malloc(i);
+ section = malloc(i+1);
if (!section) {
xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln,
(unsigned long)i);
return;
}
strncpy(section, line, i);
+ section[i] = '\0';
if (arg)
free(arg);
if (ptr == NULL)
return;
line = ++ptr;
- while (*ptr && *ptr != '"')
+ while (*ptr && *ptr != '"' && *ptr != ']')
ptr++;
- if (*ptr == '\0') {
- xlog_warn("conf_parse_line: line %d:"
+ if (*ptr == '\0' || *ptr == ']') {
+ xlog_warn("config file error: line %d: "
"non-matched '\"', ignoring until next section", ln);
} else {
*ptr = '\0';
if (line[i] == '=') {
/* If no section, we are ignoring the lines. */
if (!section) {
- xlog_warn("conf_parse_line: %d: ignoring line due to no section",
- ln);
+ xlog_warn("config file error: line %d: "
+ "ignoring line due to no section", ln);
return;
}
line[strcspn (line, " \t=")] = '\0';
val = line + i + 1 + strspn (line + i + 1, " \t");
- /* Skip trailing whitespace, if any */
- for (j = sz - (val - line) - 1; j > 0 && isspace(val[j]); j--)
- val[j] = '\0';
+ valsize = 0;
+ while (val[valsize++]);
+
+ /* Skip trailing spaces and comments */
+ for (j = 0; j < valsize; j++) {
+ if (val[j] == '#' || val[j] == ';' || isspace(val[j])) {
+ val[j] = '\0';
+ break;
+ }
+ }
/* XXX Perhaps should we not ignore errors? */
conf_set(trans, section, arg, line, val, 0, 0);
return;
/* Other non-empty lines are weird. */
i = strspn(line, " \t");
if (line[i])
- xlog_warn("conf_parse_line: %d: syntax error", ln);
+ xlog_warn("config file error: line %d:", ln);
return;
}
}
static void
-conf_load_defaults(int tr)
+conf_load_defaults(void)
{
/* No defaults */
return;
trans = conf_begin();
/* Load default configuration values. */
- conf_load_defaults(trans);
+ conf_load_defaults();
/* Free potential existing configuration. */
if (conf_addr) {