master
c 95 lines 2.78 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "inicfg_internals.h"
4
5 struct config netdata_config = APPCONFIG_INITIALIZER;
6
7 int inicfg_exists(struct config *root, const char *section, const char *name) {
8 struct config_section *sect = inicfg_section_find(root, section);
9 if(!sect) return 0;
10
11 struct config_option *opt = inicfg_option_find(sect, name);
12 if(!opt) return 0;
13
14 return 1;
15 }
16
17 void inicfg_set_default_raw_value(struct config *root, const char *section, const char *name, const char *value) {
18 struct config_section *sect = inicfg_section_find(root, section);
19 if(!sect) {
20 inicfg_set_raw_value(root, section, name, value, CONFIG_VALUE_TYPE_UNKNOWN);
21 return;
22 }
23
24 struct config_option *opt = inicfg_option_find(sect, name);
25 if(!opt) {
26 inicfg_set_raw_value(root, section, name, value, CONFIG_VALUE_TYPE_UNKNOWN);
27 return;
28 }
29
30 opt->flags |= CONFIG_VALUE_USED;
31
32 if(opt->flags & CONFIG_VALUE_LOADED)
33 return;
34
35 if(string_strcmp(opt->value, value) != 0) {
36 opt->flags |= CONFIG_VALUE_CHANGED;
37
38 string_freez(opt->value);
39 opt->value = string_strdupz(value);
40 }
41 }
42
43 bool stream_conf_needs_dbengine(struct config *root) {
44 struct config_section *sect;
45 bool ret = false;
46
47 APPCONFIG_LOCK(root);
48 for(sect = root->sections; sect; sect = sect->next) {
49 if(string_strcmp(sect->name, "stream") == 0)
50 continue; // the first section is not relevant
51
52 struct config_option *opt = inicfg_get_raw_value_of_option_in_section(sect, "enabled", NULL, CONFIG_VALUE_TYPE_UNKNOWN, NULL);
53 if(!opt || !inicfg_test_boolean_value(string2str(opt->value)))
54 continue;
55
56 opt = inicfg_get_raw_value_of_option_in_section(sect, "db", NULL, CONFIG_VALUE_TYPE_UNKNOWN, NULL);
57 if(opt && string_strcmp(opt->value, "dbengine") == 0) {
58 ret = true;
59 break;
60 }
61 }
62 APPCONFIG_UNLOCK(root);
63
64 return ret;
65 }
66
67 bool stream_conf_has_api_enabled(struct config *root) {
68 struct config_section *sect = NULL;
69 struct config_option *opt;
70 bool is_parent = false;
71
72 APPCONFIG_LOCK(root);
73 for (sect = root->sections; sect; sect = sect->next) {
74 nd_uuid_t uuid;
75
76 if (uuid_parse(string2str(sect->name), uuid) != 0)
77 continue;
78
79 opt = inicfg_option_find(sect, "type");
80 // when the 'type' is missing, we assume it is 'api'
81 if(opt && string_strcmp(opt->value, "api") != 0)
82 continue;
83
84 opt = inicfg_option_find(sect, "enabled");
85 // when the 'enabled' is missing, we assume it is 'false'
86 if(!opt || !inicfg_test_boolean_value(string2str(opt->value)))
87 continue;
88
89 is_parent = true;
90 break;
91 }
92 APPCONFIG_UNLOCK(root);
93
94 return is_parent;
95 }