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

Method load

plugins/experimental/txn_box/plugin/src/text_block.cc:186–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186Rv<Directive::Handle>
187Do_text_block_define::load(Config &cfg, CfgStaticData const *, YAML::Node drtv_node, swoc::TextView const &, swoc::TextView const &,
188 YAML::Node key_value)
189{
190 auto self = new self_type();
191 Handle handle(self);
192 auto &fg = self->_fg;
193 self->_line_no = drtv_node.Mark().line;
194
195 auto errata = self->_fg.load(cfg, key_value,
196 {
197 {NAME_TAG, FeatureGroup::REQUIRED},
198 {PATH_TAG},
199 {TEXT_TAG},
200 {DURATION_TAG},
201 {NOTIFY_TAG}
202 });
203
204 if (!errata.is_ok()) {
205 errata.note(R"(While parsing value at {} in "{}" directive at {}.)", key_value.Mark(), KEY, drtv_node.Mark());
206 return errata;
207 }
208 auto idx = fg.index_of(NAME_TAG);
209
210 // Must have a NAME, and either TEXT or PATH. DURATION is optional, but must be a duration if present.
211 auto &name_expr{fg[idx]._expr};
212 if (!name_expr.is_literal() || !name_expr.result_type().can_satisfy(STRING)) {
213 return Errata(S_ERROR, "{} value for {} directive at {} must be a literal string.", NAME_TAG, KEY, drtv_node.Mark());
214 }
215 self->_name = std::get<IndexFor(STRING)>(std::get<Expr::LITERAL>(name_expr._raw));
216
217 if (auto path_idx = fg.index_of(PATH_TAG); path_idx != INVALID_IDX) {
218 auto &path_expr = fg[path_idx]._expr;
219 if (!path_expr.is_literal() || !path_expr.result_type().can_satisfy(STRING)) {
220 return Errata(S_ERROR, "{} value for {} directive at {} must be a literal string.", PATH_TAG, KEY, drtv_node.Mark());
221 }
222 self->_path = cfg.localize(ts::make_absolute(std::get<IndexFor(STRING)>(std::get<Expr::LITERAL>(path_expr._raw))).view().data(),
223 Config::LOCAL_CSTR);
224 }
225
226 if (auto text_idx = fg.index_of(TEXT_TAG); text_idx != INVALID_IDX) {
227 auto &text_expr = fg[text_idx]._expr;
228 if (!text_expr.is_literal() || !text_expr.result_type().can_satisfy(STRING)) {
229 return Errata(S_ERROR, "{} value for {} directive at {} must be a literal string.", TEXT_TAG, KEY, drtv_node.Mark());
230 }
231 self->_text = std::get<IndexFor(STRING)>(std::get<Expr::LITERAL>(text_expr._raw));
232 }
233
234 if (!self->_text.has_value() && self->_path.empty()) {
235 return Errata(S_ERROR, "{} directive at {} must have a {} or a {} key.", KEY, drtv_node.Mark(), PATH_TAG, TEXT_TAG);
236 }
237
238 if (auto dur_idx = fg.index_of(DURATION_TAG); dur_idx != INVALID_IDX) {
239 auto &dur_expr = fg[dur_idx]._expr;
240 if (!dur_expr.is_literal()) {
241 return Errata(S_ERROR, "{} value for {} directive at {} must be a literal duration.", DURATION_TAG, KEY, drtv_node.Mark());
242 }
243 auto &&[dur_value, dur_value_errata]{std::get<Expr::LITERAL>(dur_expr._raw).as_duration()};

Callers

nothing calls this directly

Calls 15

mapMethod · 0.95
ErrataClass · 0.85
make_absoluteFunction · 0.85
statusFunction · 0.85
ExprClass · 0.85
MaskForFunction · 0.85
can_satisfyMethod · 0.80
as_durationMethod · 0.80
parse_exprMethod · 0.80
is_nullMethod · 0.80
loadFunction · 0.50
MarkMethod · 0.45

Tested by

no test coverage detected