diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-17 08:00:34 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-17 08:00:34 +0200 |
commit | 71f602c4e97a67097ede995642a5cb09c0ceca07 (patch) | |
tree | f37529e532f060b531ce1706d8be1c130a0189f2 /runtime/msg.c | |
parent | 8fe7507de1d9f800fedb82a2cf2e1f443db940f7 (diff) | |
download | rsyslog-71f602c4e97a67097ede995642a5cb09c0ceca07.tar.gz rsyslog-71f602c4e97a67097ede995642a5cb09c0ceca07.tar.bz2 rsyslog-71f602c4e97a67097ede995642a5cb09c0ceca07.zip |
new ruleengine: Implent "unset" statement
Diffstat (limited to 'runtime/msg.c')
-rw-r--r-- | runtime/msg.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index 15eb7abb..0cb60436 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -3779,6 +3779,48 @@ finalize_it: } rsRetVal +msgDelJSON(msg_t *pM, uchar *name) +{ + struct json_object *parent, *leafnode; + uchar *leaf; + DEFiRet; + +dbgprintf("AAAA: unset variable '%s'\n", name); + MsgLock(pM); + if(name[0] == '!' && name[1] == '\0') { + /* strange, but I think we should permit this. After all, + * we trust rsyslog.conf to be written by the admin. + */ + DBGPRINTF("unsetting JSON root object\n"); + json_object_put(pM->json); + pM->json = NULL; + } else { + if(pM->json == NULL) { + /* now we need a root obj */ + pM->json = json_object_new_object(); + } + leaf = jsonPathGetLeaf(name, ustrlen(name)); + CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 1)); + leafnode = json_object_object_get(parent, (char*)leaf); +DBGPRINTF("AAAA: unset found JSON value path '%s', " "leaf '%s', leafnode %p\n", name, leaf, leafnode); + if(leafnode == NULL) { + DBGPRINTF("unset JSON: could not find '%s'\n", name); + ABORT_FINALIZE(RS_RET_JNAME_NOTFOUND); + } else { + DBGPRINTF("deleting JSON value path '%s', " + "leaf '%s', type %d\n", + name, leaf, json_object_get_type(leafnode)); + json_object_put(leafnode); + json_object_object_del(parent, (char*)leaf); + } + } + +finalize_it: + MsgUnlock(pM); + RETiRet; +} + +rsRetVal msgSetJSONFromVar(msg_t *pMsg, uchar *varname, struct var *var) { struct json_object *json = NULL; |