mirror of
https://github.com/rsyslog/rsyslog.git
synced 2026-06-20 11:02:56 +02:00
enhanced rainerscript to allow chained dereference of json-arrays + fixed a bug json-array dereference handling + added a test for rainerscript using chained json-array dereference
Conflicts: tests/Makefile.am
This commit is contained in:
parent
a0cac770c4
commit
2e3266b097
@ -199,7 +199,6 @@ expr: expr AND expr { $$ = cnfexprNew(AND, $1, $3); }
|
|||||||
| NUMBER { $$ = (struct cnfexpr*) cnfnumvalNew($1); }
|
| NUMBER { $$ = (struct cnfexpr*) cnfnumvalNew($1); }
|
||||||
| STRING { $$ = (struct cnfexpr*) cnfstringvalNew($1); }
|
| STRING { $$ = (struct cnfexpr*) cnfstringvalNew($1); }
|
||||||
| VAR { $$ = (struct cnfexpr*) cnfvarNew($1); }
|
| VAR { $$ = (struct cnfexpr*) cnfvarNew($1); }
|
||||||
| VAR '[' NUMBER ']' { $$ = (struct cnfexpr*) cnfvarNewIndexed($1, $3); }
|
|
||||||
| array { $$ = (struct cnfexpr*) $1; }
|
| array { $$ = (struct cnfexpr*) $1; }
|
||||||
fparams: expr { $$ = cnffparamlstNew($1, NULL); }
|
fparams: expr { $$ = cnffparamlstNew($1, NULL); }
|
||||||
| expr ',' fparams { $$ = cnffparamlstNew($1, $3); }
|
| expr ',' fparams { $$ = cnffparamlstNew($1, $3); }
|
||||||
|
|||||||
@ -138,7 +138,7 @@ int fileno(FILE *stream);
|
|||||||
<EXPR>0[0-7]+ | /* octal number */
|
<EXPR>0[0-7]+ | /* octal number */
|
||||||
<EXPR>0x[0-7a-f] | /* hex number, following rule is dec; strtoll handles all! */
|
<EXPR>0x[0-7a-f] | /* hex number, following rule is dec; strtoll handles all! */
|
||||||
<EXPR>([1-9][0-9]*|0) { yylval.n = strtoll(yytext, NULL, 0); return NUMBER; }
|
<EXPR>([1-9][0-9]*|0) { yylval.n = strtoll(yytext, NULL, 0); return NUMBER; }
|
||||||
<EXPR>\$[$!./]{0,1}[@a-z][!@a-z0-9\-_\.]* { yylval.s = strdup(yytext+1); return VAR; }
|
<EXPR>\$[$!./]{0,1}[@a-z][!@a-z0-9\-_\.\[\]]* { yylval.s = strdup(yytext+1); return VAR; }
|
||||||
<EXPR>\'([^'\\]|\\['"\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\' {
|
<EXPR>\'([^'\\]|\\['"\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\' {
|
||||||
yytext[yyleng-1] = '\0';
|
yytext[yyleng-1] = '\0';
|
||||||
unescapeStr((uchar*)yytext+1, yyleng-2);
|
unescapeStr((uchar*)yytext+1, yyleng-2);
|
||||||
|
|||||||
@ -2823,22 +2823,6 @@ cnfvarNew(char *name)
|
|||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cnfvar*
|
|
||||||
cnfvarNewIndexed(char *name, int subscript)
|
|
||||||
{
|
|
||||||
char name_buff[MAX_VARIABLE_NAME_LEN];
|
|
||||||
int len = strlen(name);
|
|
||||||
memcpy(name_buff, name, len);
|
|
||||||
free(name);
|
|
||||||
name_buff[len++] = '[';
|
|
||||||
len += snprintf(name_buff + len, MAX_VARIABLE_NAME_LEN - len - 2, "%d", subscript); //2 is for ]\0
|
|
||||||
name_buff[len++] = ']';
|
|
||||||
name_buff[len] = '\0';
|
|
||||||
char *indexed_name = strdup(name_buff);
|
|
||||||
return indexed_name == NULL ? NULL : cnfvarNew(indexed_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct cnfstmt *
|
struct cnfstmt *
|
||||||
cnfstmtNew(unsigned s_type)
|
cnfstmtNew(unsigned s_type)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -340,7 +340,6 @@ void cnfexprDestruct(struct cnfexpr *expr);
|
|||||||
struct cnfnumval* cnfnumvalNew(long long val);
|
struct cnfnumval* cnfnumvalNew(long long val);
|
||||||
struct cnfstringval* cnfstringvalNew(es_str_t *estr);
|
struct cnfstringval* cnfstringvalNew(es_str_t *estr);
|
||||||
struct cnfvar* cnfvarNew(char *name);
|
struct cnfvar* cnfvarNew(char *name);
|
||||||
struct cnfvar* cnfvarNewIndexed(char *name, int subscript);
|
|
||||||
struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst);
|
struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst);
|
||||||
struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next);
|
struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next);
|
||||||
int cnfDoInclude(char *name);
|
int cnfDoInclude(char *name);
|
||||||
|
|||||||
@ -4194,7 +4194,7 @@ static json_bool jsonVarExtract(struct json_object* root, const char *key, struc
|
|||||||
char *array_idx_start = strstr(key, "[");
|
char *array_idx_start = strstr(key, "[");
|
||||||
char *array_idx_end = NULL;
|
char *array_idx_end = NULL;
|
||||||
char *array_idx_num_end_discovered = NULL;
|
char *array_idx_num_end_discovered = NULL;
|
||||||
struct json_object **arr = NULL;
|
struct json_object *arr = NULL;
|
||||||
if (array_idx_start != NULL) {
|
if (array_idx_start != NULL) {
|
||||||
array_idx_end = strstr(array_idx_start, "]");
|
array_idx_end = strstr(array_idx_start, "]");
|
||||||
}
|
}
|
||||||
@ -4204,11 +4204,11 @@ static json_bool jsonVarExtract(struct json_object* root, const char *key, struc
|
|||||||
if (errno == 0 && array_idx_num_end_discovered == array_idx_end) {
|
if (errno == 0 && array_idx_num_end_discovered == array_idx_end) {
|
||||||
memcpy(namebuf, key, array_idx_start - key);
|
memcpy(namebuf, key, array_idx_start - key);
|
||||||
namebuf[array_idx_start - key] = '\0';
|
namebuf[array_idx_start - key] = '\0';
|
||||||
json_bool found_obj = RS_json_object_object_get_ex(root, namebuf, arr);
|
json_bool found_obj = RS_json_object_object_get_ex(root, namebuf, &arr);
|
||||||
if (found_obj && json_object_is_type(*arr, json_type_array)) {
|
if (found_obj && json_object_is_type(arr, json_type_array)) {
|
||||||
int len = json_object_array_length(*arr);
|
int len = json_object_array_length(arr);
|
||||||
if (len > idx) {
|
if (len > idx) {
|
||||||
*value = json_object_array_get_idx(*arr, idx);
|
*value = json_object_array_get_idx(arr, idx);
|
||||||
if (*value != NULL) return TRUE;
|
if (*value != NULL) return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|||||||
@ -186,7 +186,8 @@ endif
|
|||||||
if ENABLE_MMJSONPARSE
|
if ENABLE_MMJSONPARSE
|
||||||
TESTS += \
|
TESTS += \
|
||||||
mmjsonparse_simple.sh \
|
mmjsonparse_simple.sh \
|
||||||
mmjsonparse_cim.sh
|
mmjsonparse_cim.sh \
|
||||||
|
json_array_subscripting.sh
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_GNUTLS
|
if ENABLE_GNUTLS
|
||||||
@ -705,6 +706,9 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
|
|||||||
testsuites/rscript_wrap3.conf \
|
testsuites/rscript_wrap3.conf \
|
||||||
testsuites/wrap3_input\
|
testsuites/wrap3_input\
|
||||||
testsuites/gethostname.conf \
|
testsuites/gethostname.conf \
|
||||||
|
json_array_subscripting.sh \
|
||||||
|
testsuites/json_array_subscripting.conf \
|
||||||
|
testsuites/json_array_input \
|
||||||
cfg.sh
|
cfg.sh
|
||||||
|
|
||||||
# TODO: re-enable
|
# TODO: re-enable
|
||||||
|
|||||||
@ -9,5 +9,5 @@ echo doing shutdown
|
|||||||
source $srcdir/diag.sh shutdown-when-empty
|
source $srcdir/diag.sh shutdown-when-empty
|
||||||
echo wait on shutdown
|
echo wait on shutdown
|
||||||
source $srcdir/diag.sh wait-shutdown
|
source $srcdir/diag.sh wait-shutdown
|
||||||
source $srcdir/diag.sh content-check "msg: def1 | important_msg | other_msg"
|
source $srcdir/diag.sh content-check 'msg: def1 | ghi2 | important_msg | { "baz": "other_msg" } | other_msg'
|
||||||
source $srcdir/diag.sh exit
|
source $srcdir/diag.sh exit
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
$IncludeConfig diag-common.conf
|
$IncludeConfig diag-common.conf
|
||||||
template(name="outfmt" type="string" string="msg: %$!foo[1]% | %$!foo[3]!bar[0]!baz% | %$!foo[3]!bar[1]!baz%\n")
|
template(name="outfmt" type="string" string="msg: %$!foo[1]% | %$.quux% | %$.corge% | %$.grault% | %$!foo[3]!bar[1]!baz%\n")
|
||||||
|
|
||||||
module(load="../plugins/mmjsonparse/.libs/mmjsonparse")
|
module(load="../plugins/mmjsonparse/.libs/mmjsonparse")
|
||||||
module(load="../plugins/imptcp/.libs/imptcp")
|
module(load="../plugins/imptcp/.libs/imptcp")
|
||||||
input(type="imptcp" port="13514")
|
input(type="imptcp" port="13514")
|
||||||
|
|
||||||
action(type="mmjsonparse")
|
action(type="mmjsonparse")
|
||||||
|
set $.quux = $!foo[2];
|
||||||
|
set $.corge = $!foo[3]!bar[0]!baz;
|
||||||
|
set $.grault = $!foo[3]!bar[1];
|
||||||
action(type="omfile" file="./rsyslog.out.log" template="outfmt")
|
action(type="omfile" file="./rsyslog.out.log" template="outfmt")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user