@cryptotaxi247 / netdata-1 / commits / 56ac19d8a

cove355076: Config per section (#8588)

This commit brings the possibility to search an option directly when we already have a section

thiagoftsm committed Apr 3, 2020 at 10:26 UTC 56ac19d8afd49f200fb2bd954d2f5bcd56c920cf
3 files changed +32 -10
libnetdata/config/appconfig.c
+29 -9
@@ -285,16 +285,10 @@ cleanup:
285 return ret;
286 }
287
288 -
289 -char *appconfig_get(struct config *root, const char *section, const char *name, const char *default_value)
288 +char *appconfig_get_by_section(struct section *co, const char *name, const char *default_value)
289 {
290 struct config_option *cv;
291
293 - debug(D_CONFIG, "request to get config in section '%s', name '%s', default_value '%s'", section, name, default_value);
294 -
295 - struct section *co = appconfig_section_find(root, section);
296 - if(!co) co = appconfig_section_create(root, section);
297 -
292 cv = appconfig_option_index_find(co, name, 0);
293 if(!cv) {
294 cv = appconfig_value_create(co, name, default_value);
@@ -314,6 +308,16 @@ char *appconfig_get(struct config *root, const char *section, const char *name,
308 return(cv->value);
309 }
310
311 +char *appconfig_get(struct config *root, const char *section, const char *name, const char *default_value)
312 +{
313 + debug(D_CONFIG, "request to get config in section '%s', name '%s', default_value '%s'", section, name, default_value);
314 +
315 + struct section *co = appconfig_section_find(root, section);
316 + if(!co) co = appconfig_section_create(root, section);
317 +
318 + return appconfig_get_by_section(co, name, default_value);
319 +}
320 +
321 long long appconfig_get_number(struct config *root, const char *section, const char *name, long long value)
322 {
323 char buffer[100], *s;
@@ -336,6 +340,23 @@ LONG_DOUBLE appconfig_get_float(struct config *root, const char *section, const
340 return str2ld(s, NULL);
341 }
342
343 +static inline int appconfig_test_boolean_value(char *s) {
344 + if(!strcasecmp(s, "yes") || !strcasecmp(s, "true") || !strcasecmp(s, "on")
345 + || !strcasecmp(s, "auto") || !strcasecmp(s, "on demand"))
346 + return 1;
347 +
348 + return 0;
349 +}
350 +
351 +int appconfig_get_boolean_by_section(struct section *co, const char *name, int value) {
352 + char *s;
353 +
354 + s = appconfig_get_by_section(co, name, (!value)?"no":"yes");
355 + if(!s) return value;
356 +
357 + return appconfig_test_boolean_value(s);
358 +}
359 +
360 int appconfig_get_boolean(struct config *root, const char *section, const char *name, int value)
361 {
362 char *s;
@@ -345,8 +366,7 @@ int appconfig_get_boolean(struct config *root, const char *section, const char *
366 s = appconfig_get(root, section, name, s);
367 if(!s) return value;
368
348 - if(!strcasecmp(s, "yes") || !strcasecmp(s, "true") || !strcasecmp(s, "on") || !strcasecmp(s, "auto") || !strcasecmp(s, "on demand")) return 1;
349 - return 0;
369 + return appconfig_test_boolean_value(s);
370 }
371
372 int appconfig_get_boolean_ondemand(struct config *root, const char *section, const char *name, int value)
libnetdata/config/appconfig.h
+2
@@ -159,9 +159,11 @@ extern int appconfig_load(struct config *root, char *filename, int overwrite_use
159 extern void config_section_wrlock(struct section *co);
160 extern void config_section_unlock(struct section *co);
161
162 +extern char *appconfig_get_by_section(struct section *co, const char *name, const char *default_value);
163 extern char *appconfig_get(struct config *root, const char *section, const char *name, const char *default_value);
164 extern long long appconfig_get_number(struct config *root, const char *section, const char *name, long long value);
165 extern LONG_DOUBLE appconfig_get_float(struct config *root, const char *section, const char *name, LONG_DOUBLE value);
166 +extern int appconfig_get_boolean_by_section(struct section *co, const char *name, int value);
167 extern int appconfig_get_boolean(struct config *root, const char *section, const char *name, int value);
168 extern int appconfig_get_boolean_ondemand(struct config *root, const char *section, const char *name, int value);
169 extern int appconfig_get_duration(struct config *root, const char *section, const char *name, const char *value);
streaming/rrdpush.c
+1 -1
@@ -174,7 +174,7 @@ int configured_as_master() {
174 uuid_t uuid;
175
176 if (uuid_parse(section->name, uuid) != -1 &&
177 - appconfig_get_boolean(&stream_config, section->name, "enabled", 0)) {
177 + appconfig_get_boolean_by_section(section, "enabled", 0)) {
178 is_master = 1;
179 break;
180 }