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

Method readConfig

plugins/experimental/cache_fill/configs.cc:94–196  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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