MCPcopy Create free account
hub / github.com/apache/trafficserver / readConfig

Method readConfig

plugins/background_fetch/configs.cc:84–186  ·  view source on GitHub ↗

Read a config file, populate the linked list (chain the BgFetchRule's)

Source from the content-addressed store, hash-verified

82
83// Read a config file, populate the linked list (chain the BgFetchRule's)
84bool
85BgFetchConfig::readConfig(const char *config_file)
86{
87 if (nullptr == config_file) {
88 TSError("[%s] invalid config file", PLUGIN_NAME);
89 return false;
90 }
91
92 swoc::file::path path(config_file);
93
94 Dbg(Bg_dbg_ctl, "trying to open config file in this path: %s", config_file);
95
96 if (!path.is_absolute()) {
97 path = swoc::file::path(TSConfigDirGet()) / path;
98 }
99 Dbg(Bg_dbg_ctl, "chosen config file is at: %s", path.c_str());
100
101 std::error_code ec;
102 auto content = swoc::file::load(path, ec);
103 if (ec) {
104 swoc::bwprint(ts::bw_dbg, "[{}] invalid config file: {} {}", PLUGIN_NAME, path, ec);
105 TSError("%s", ts::bw_dbg.c_str());
106 Dbg(Bg_dbg_ctl, "%s", ts::bw_dbg.c_str());
107 return false;
108 }
109
110 swoc::TextView text{content};
111 while (text) {
112 auto line = text.take_prefix_at('\n').ltrim_if(&isspace);
113
114 if (line.empty() || line.front() == '#') {
115 continue;
116 }
117
118 auto cfg_type = line.take_prefix_if(&isspace);
119 if (cfg_type.empty()) {
120 continue;
121 }
122
123 Dbg(Bg_dbg_ctl, "setting background_fetch exclusion criterion based on string: %.*s", int(cfg_type.size()), cfg_type.data());
124
125 bool exclude = false;
126 if (0 == strcasecmp(cfg_type, "exclude")) {
127 exclude = true;
128 } else if (0 != strcasecmp(cfg_type, "include")) {
129 swoc::bwprint(ts::bw_dbg, "[{}] invalid specifier {}, skipping config line", PLUGIN_NAME, cfg_type);
130 TSError("%s", ts::bw_dbg.c_str());
131 continue;
132 }
133
134 if (auto cfg_name = line.take_prefix_if(&isspace); !cfg_name.empty()) {
135 if (auto cfg_value = line.take_prefix_if(&isspace); !cfg_value.empty()) {
136 if ("Client-IP"_tv == cfg_name) {
137 swoc::IPRange r;
138 // '*' is special - match any address. Signalled by empty range.
139 if (cfg_value.size() != 1 || cfg_value.front() == '*') {
140 if (!r.load(cfg_value)) { // assume if it loads, it's not empty.
141 TSError("[%s] invalid IP address range %.*s, skipping config value", PLUGIN_NAME, int(cfg_value.size()),

Callers 1

TSRemapNewInstanceFunction · 0.45

Calls 15

pathClass · 0.85
TSConfigDirGetFunction · 0.85
strcasecmpFunction · 0.85
svtouFunction · 0.85
is_absoluteMethod · 0.80
take_prefix_atMethod · 0.80
take_prefix_ifMethod · 0.80
emplace_backMethod · 0.80
TSErrorFunction · 0.50
loadFunction · 0.50
c_strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected