Skip to content

Commit

Permalink
Add version=3 for nested objects support
Browse files Browse the repository at this point in the history
  • Loading branch information
KGuillemot committed Sep 25, 2023
1 parent c43b0b3 commit 889259f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/pdag.c
Original file line number Diff line number Diff line change
Expand Up @@ -1409,8 +1409,11 @@ fixJSON(struct ln_pdag *dag,
json_object_put(*value);
json_object_object_add_ex(json, prs->name, valDotDot,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
} else {
} else if(dag->ctx->version == 3) {
add_json_nested_key_value_pair(json, (char *)prs->name, *value);
} else {
json_object_object_add_ex(json, prs->name, *value,
JSON_C_OBJECT_ADD_KEY_IS_NEW|JSON_C_OBJECT_KEY_IS_CONSTANT);
}
}
r = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/samp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ checkVersion(FILE *const fp)
return -1;
if(!strcmp(buf, "version=2\n")) {
return 2;
} else if(!strcmp(buf, "version=3\n")) {
return 3;
} else {
return 1;
}
Expand Down Expand Up @@ -1154,7 +1156,7 @@ ln_sampLoad(ln_ctx ctx, const char *file)
}

/* now we are in our native code */
++ctx->conf_ln_nbr; /* "version=2" is line 1! */
++ctx->conf_ln_nbr; /* "version=2" or "version=3" is line 1! */
while(!isEof) {
CHKR(ln_sampRead(ctx, repo, NULL, &isEof));
}
Expand All @@ -1178,7 +1180,7 @@ ln_sampLoadFromString(ln_ctx ctx, const char *string)
goto done;

ln_dbgprintf(ctx, "loading v2 rulebase from string '%s'", string);
ctx->version = 2;
ctx->version = 3;
while(!isEof) {
CHKR(ln_sampRead(ctx, NULL, &string, &isEof));
}
Expand Down
16 changes: 16 additions & 0 deletions tests/field_v3_nested.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# added 2023-09-25 by KGuillemot
# This file is part of the liblognorm project, released under ASL 2.0
. $srcdir/exec.sh
no_solaris10

test_def $0 "v3 name-value-list parser"

add_rule 'version=3'
add_rule 'rule=:<%syslog!priority:number%>%received!time:date-rfc3164% %host!name:word% %log!data:name-value-list%'

execute '<15>Feb 10 08:30:07 hostname a=b c=d y=z'
assert_output_json_eq '{ "log": { "data": { "a": "b", "c": "d", "y": "z" } }, "host": { "name": "hostname" }, "received": { "time": "Feb 10 08:30:07" }, "syslog": { "priority": "15" } }'

cleanup_tmp_files

0 comments on commit 889259f

Please sign in to comment.