Browse Source

* config.[ch]: f2b_config_section_append() : add 'replace' flag

master
Alex 'AdUser' Z 9 years ago
parent
commit
a55ab0a382
  1. 6
      src/config.c
  2. 2
      src/config.h

6
src/config.c

@ -134,7 +134,7 @@ f2b_config_section_find(f2b_config_section_t *section, const char *name) {
} }
f2b_config_section_t * f2b_config_section_t *
f2b_config_section_append(f2b_config_section_t *section, f2b_config_param_t *param) { f2b_config_section_append(f2b_config_section_t *section, f2b_config_param_t *param, bool replace) {
f2b_config_param_t *prev = NULL; f2b_config_param_t *prev = NULL;
assert(section != NULL); assert(section != NULL);
@ -147,7 +147,7 @@ f2b_config_section_append(f2b_config_section_t *section, f2b_config_param_t *par
return section; return section;
} }
if ((prev = f2b_config_param_find(section->param, param->name)) != NULL) { if (replace && (prev = f2b_config_param_find(section->param, param->name)) != NULL) {
/* found param with same name */ /* found param with same name */
strncpy(prev->value, param->value, sizeof(prev->value)); strncpy(prev->value, param->value, sizeof(prev->value));
free(param); free(param);
@ -222,7 +222,7 @@ f2b_config_load(const char *path) {
f2b_log_msg(log_error, "can't parse key/value at line %d: %s", linenum, p); f2b_log_msg(log_error, "can't parse key/value at line %d: %s", linenum, p);
continue; continue;
} }
f2b_config_section_append(section, param); f2b_config_section_append(section, param, false);
break; break;
} /* switch */ } /* switch */
} /* while */ } /* while */

2
src/config.h

@ -40,7 +40,7 @@ f2b_config_param_t * f2b_config_param_find (f2b_config_param_t *param, const ch
f2b_config_section_t * f2b_config_section_create(const char *line); f2b_config_section_t * f2b_config_section_create(const char *line);
f2b_config_section_t * f2b_config_section_find (f2b_config_section_t *s, const char *name); f2b_config_section_t * f2b_config_section_find (f2b_config_section_t *s, const char *name);
f2b_config_section_t * f2b_config_section_append(f2b_config_section_t *s, f2b_config_param_t *p); f2b_config_section_t * f2b_config_section_append(f2b_config_section_t *s, f2b_config_param_t *p, bool replace);
f2b_config_t * f2b_config_load (const char *path); f2b_config_t * f2b_config_load (const char *path);
void f2b_config_free (f2b_config_t *c); void f2b_config_free (f2b_config_t *c);

Loading…
Cancel
Save