Skip to content

Instantly share code, notes, and snippets.

@niedbalski
Created November 13, 2024 11:47
Show Gist options
  • Save niedbalski/d0225e3fdd89a063c146fa0fe6a3d6e2 to your computer and use it in GitHub Desktop.
Save niedbalski/d0225e3fdd89a063c146fa0fe6a3d6e2 to your computer and use it in GitHub Desktop.
patch.patch
diff --git a/src/config_format/flb_cf_yaml.c b/src/config_format/flb_cf_yaml.c
index 6581692a4..dfed60197 100644
--- a/src/config_format/flb_cf_yaml.c
+++ b/src/config_format/flb_cf_yaml.c
@@ -106,7 +106,7 @@ enum state {
STATE_SECTION, /* top level */
STATE_SECTION_KEY,
STATE_SECTION_VAL,
-
+ STATE_SECTION_VAL_LIST, /* List of section values */
STATE_SERVICE, /* 'service' section */
STATE_INCLUDE, /* 'includes' section */
STATE_OTHER, /* any other unknown section */
@@ -1135,7 +1135,50 @@ static int consume_event(struct flb_cf *conf, struct local_ctx *ctx,
return YAML_FAILURE;
}
break;
+ case STATE_SECTION_VAL_LIST:
+ switch(event->type) {
+ case YAML_SCALAR_EVENT:
+ value = (char *) event->data.scalar.value;
+ if (!state->values) {
+ flb_error("no values array for sequence");
+ return YAML_FAILURE;
+ }
+ if (cfl_array_append_string(state->values, value) < 0) {
+ flb_error("failed to append to sequence");
+ return YAML_FAILURE;
+ }
+ break;
+
+ case YAML_SEQUENCE_END_EVENT:
+ if (!state->values) {
+ flb_error("no values array at sequence end");
+ return YAML_FAILURE;
+ }
+ state = state_pop(ctx);
+ if (state == NULL) {
+ flb_error("no state left");
+ return YAML_FAILURE;
+ }
+ if (state->state != STATE_SECTION_KEY) {
+ yaml_error_event(ctx, state, event);
+ return YAML_FAILURE;
+ }
+ state->values = NULL;
+ break;
+
+ case YAML_MAPPING_START_EVENT:
+ yaml_error_event(ctx, state, event);
+ return YAML_FAILURE;
+
+ case YAML_MAPPING_END_EVENT:
+ yaml_error_event(ctx, state, event);
+ return YAML_FAILURE;
+ default:
+ yaml_error_event(ctx, state, event);
+ return YAML_FAILURE;
+ }
+ break;
case STATE_SECTION_VAL:
switch(event->type) {
case YAML_SCALAR_EVENT:
@@ -1153,7 +1196,6 @@ static int consume_event(struct flb_cf *conf, struct local_ctx *ctx,
}
}
else {
-
/* register key/value pair as a property */
if (state->cf_section == NULL) {
flb_error("no section to register key value to");
@@ -1180,6 +1222,26 @@ static int consume_event(struct flb_cf *conf, struct local_ctx *ctx,
return YAML_FAILURE;
}
break;
+
+ case YAML_SEQUENCE_START_EVENT:
+ if (state->section == SECTION_SERVICE) {
+ state->values = flb_cf_section_property_add_list(conf,
+ state->cf_section->properties,
+ state->key,
+ flb_sds_len(state->key));
+ if (!state->values) {
+ flb_error("unable to create list property");
+ if (state->key) {
+ flb_sds_destroy(state->key);
+ }
+ return YAML_FAILURE;
+ }
+ state->state = STATE_SECTION_VAL_LIST;
+ break;
+ }
+ yaml_error_event(ctx, state, event);
+ return YAML_FAILURE;
+
default:
yaml_error_event(ctx, state, event);
return YAML_FAILURE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment