Skip to content

Commit 71043cc

Browse files
committed
config_format: cf_yaml: Support list format for parsers
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 5880717 commit 71043cc

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

src/config_format/flb_cf_yaml.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ enum state {
120120
STATE_SECTION, /* top level */
121121
STATE_SECTION_KEY,
122122
STATE_SECTION_VAL,
123+
STATE_SECTION_VAL_LIST,
123124

124125
STATE_SERVICE, /* 'service' section */
125126
STATE_INCLUDE, /* 'includes' section */
@@ -268,6 +269,8 @@ static char *state_str(enum state val)
268269
return "section-key";
269270
case STATE_SECTION_VAL:
270271
return "section-value";
272+
case STATE_SECTION_VAL_LIST:
273+
return "section-value-list";
271274
case STATE_SERVICE:
272275
return "service";
273276
case STATE_INCLUDE:
@@ -1961,6 +1964,67 @@ static int consume_event(struct flb_cf *conf, struct local_ctx *ctx,
19611964
return YAML_FAILURE;
19621965
}
19631966

1967+
if (state->state != STATE_SECTION_KEY) {
1968+
yaml_error_event(ctx, state, event);
1969+
return YAML_FAILURE;
1970+
}
1971+
break;
1972+
case YAML_SEQUENCE_START_EVENT:
1973+
if (state->section != SECTION_SERVICE ||
1974+
strcasecmp(state->key, "parsers_file") != 0) {
1975+
yaml_error_event(ctx, state, event);
1976+
return YAML_FAILURE;
1977+
}
1978+
1979+
state = state_push_key(ctx, STATE_SECTION_VAL_LIST, state->key);
1980+
if (state == NULL) {
1981+
flb_error("unable to allocate state");
1982+
return YAML_FAILURE;
1983+
}
1984+
break;
1985+
default:
1986+
yaml_error_event(ctx, state, event);
1987+
return YAML_FAILURE;
1988+
}
1989+
break;
1990+
1991+
case STATE_SECTION_VAL_LIST:
1992+
switch(event->type) {
1993+
case YAML_SCALAR_EVENT:
1994+
value = (char *) event->data.scalar.value;
1995+
1996+
if (state->cf_section == NULL) {
1997+
flb_error("no section to register key value to");
1998+
return YAML_FAILURE;
1999+
}
2000+
2001+
if (flb_cf_section_property_add(conf, state->cf_section->properties,
2002+
state->key, flb_sds_len(state->key),
2003+
value, strlen(value)) < 0) {
2004+
flb_error("unable to add property");
2005+
return YAML_FAILURE;
2006+
}
2007+
break;
2008+
case YAML_SEQUENCE_END_EVENT:
2009+
state = state_pop(ctx);
2010+
2011+
if (state == NULL) {
2012+
flb_error("no state left");
2013+
return YAML_FAILURE;
2014+
}
2015+
2016+
if (state->state != STATE_SECTION_VAL) {
2017+
yaml_error_event(ctx, state, event);
2018+
return YAML_FAILURE;
2019+
}
2020+
2021+
state = state_pop(ctx);
2022+
2023+
if (state == NULL) {
2024+
flb_error("no state left");
2025+
return YAML_FAILURE;
2026+
}
2027+
19642028
if (state->state != STATE_SECTION_KEY) {
19652029
yaml_error_event(ctx, state, event);
19662030
return YAML_FAILURE;

0 commit comments

Comments
 (0)