diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-18 11:32:45 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-18 11:32:45 +0200 |
commit | 037eaa0d69e1a65373baba93bb69476345c34e10 (patch) | |
tree | dc8049b48ad46139be000395125993f568259b54 /runtime | |
parent | 447f0e6421f2576d57623a398f90b8dd2eb8becf (diff) | |
download | rsyslog-037eaa0d69e1a65373baba93bb69476345c34e10.tar.gz rsyslog-037eaa0d69e1a65373baba93bb69476345c34e10.tar.xz rsyslog-037eaa0d69e1a65373baba93bb69476345c34e10.zip |
new ruleengine: implement template type "subtree"
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/msg.c | 45 | ||||
-rw-r--r-- | runtime/msg.h | 4 | ||||
-rw-r--r-- | runtime/ruleset.c | 2 | ||||
-rw-r--r-- | runtime/typedefs.h | 2 |
4 files changed, 42 insertions, 11 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index 2f6606bb..f4ad7bf4 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -2408,8 +2408,8 @@ static uchar *getNOW(eNOWType eNow) /* Get a CEE-Property as string value*/ -static inline rsRetVal -getCEEPropVal(msg_t *pM, es_str_t *propName, uchar **pRes, int *buflen, unsigned short *pbMustBeFreed) +rsRetVal +getCEEPropVal(msg_t *pM, es_str_t *propName, uchar **pRes, rs_size_t *buflen, unsigned short *pbMustBeFreed) { uchar *name = NULL; uchar *leaf; @@ -2431,10 +2431,7 @@ getCEEPropVal(msg_t *pM, es_str_t *propName, uchar **pRes, int *buflen, unsigned CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 1)); field = json_object_object_get(parent, (char*)leaf); } - if(field == 0) { - *pRes = (uchar*) ""; - *pbMustBeFreed = 0; - } else { + if(field != NULL) { *pRes = (uchar*) strdup(json_object_get_string(field)); *buflen = (int) ustrlen(*pRes); *pbMustBeFreed = 1; @@ -2684,11 +2681,11 @@ finalize_it: *pPropLen = sizeof("**OUT OF MEMORY**") - 1; \ return(UCHAR_CONSTANT("**OUT OF MEMORY**"));} uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, - propid_t propid, es_str_t *propName, size_t *pPropLen, + propid_t propid, es_str_t *propName, rs_size_t *pPropLen, unsigned short *pbMustBeFreed) { uchar *pRes; /* result pointer */ - int bufLen = -1; /* length of string or -1, if not known */ + rs_size_t bufLen = -1; /* length of string or -1, if not known */ uchar *pBufStart; uchar *pBuf; int iLen; @@ -3528,7 +3525,7 @@ done: es_str_t* msgGetMsgVarNew(msg_t *pThis, uchar *name) { - size_t propLen; + rs_size_t propLen; uchar *pszProp = NULL; propid_t propid; unsigned short bMustBeFreed = 0; @@ -3730,6 +3727,36 @@ DBGPRINTF("AAAA jsonMerge adds '%s'\n", it.key); RETiRet; } +/* find a JSON structure element (field or container doesn't matter). */ +rsRetVal +jsonFind(msg_t *pM, es_str_t *propName, struct json_object **jsonres) +{ + uchar *name = NULL; + uchar *leaf; + struct json_object *parent; + struct json_object *field; + DEFiRet; + + if(pM->json == NULL) { + field = NULL; + goto finalize_it; + } + + if(!es_strbufcmp(propName, (uchar*)"!", 1)) { + field = pM->json; + } else { + name = (uchar*)es_str2cstr(propName, NULL); + leaf = jsonPathGetLeaf(name, ustrlen(name)); + CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 0)); + field = json_object_object_get(parent, (char*)leaf); + } + *jsonres = field; + +finalize_it: + free(name); + RETiRet; +} + rsRetVal msgAddJSON(msg_t *pM, uchar *name, struct json_object *json) { diff --git a/runtime/msg.h b/runtime/msg.h index 477d1f1a..396e861f 100644 --- a/runtime/msg.h +++ b/runtime/msg.h @@ -173,7 +173,7 @@ void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg, size_t lenMsg); rsRetVal MsgReplaceMSG(msg_t *pThis, uchar* pszMSG, int lenMSG); uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, propid_t propid, es_str_t *propName, - size_t *pPropLen, unsigned short *pbMustBeFreed); + rs_size_t *pPropLen, unsigned short *pbMustBeFreed); char *textpri(char *pRes, size_t pResLen, int pri); rsRetVal msgGetMsgVar(msg_t *pThis, cstr_t *pstrPropName, var_t **ppVar); es_str_t* msgGetMsgVarNew(msg_t *pThis, uchar *name); @@ -186,6 +186,7 @@ void getRawMsg(msg_t *pM, uchar **pBuf, int *piLen); rsRetVal msgGetCEEVar(msg_t *pThis, cstr_t *propName, var_t **ppVar); es_str_t* msgGetCEEVarNew(msg_t *pMsg, char *name); rsRetVal msgAddJSON(msg_t *pM, uchar *name, struct json_object *json); +rsRetVal getCEEPropVal(msg_t *pM, es_str_t *propName, uchar **pRes, rs_size_t *buflen, unsigned short *pbMustBeFreed); /* TODO: remove these five (so far used in action.c) */ uchar *getMSG(msg_t *pM); @@ -204,6 +205,7 @@ uchar *propIDToName(propid_t propID); rsRetVal msgGetCEEPropJSON(msg_t *pM, es_str_t *propName, struct json_object **pjson); rsRetVal msgSetJSONFromVar(msg_t *pMsg, uchar *varname, struct var *var); rsRetVal msgDelJSON(msg_t *pMsg, uchar *varname); +rsRetVal jsonFind(msg_t *pM, es_str_t *propName, struct json_object **jsonres); static inline rsRetVal msgUnsetJSON(msg_t *pMsg, uchar *varname) { diff --git a/runtime/ruleset.c b/runtime/ruleset.c index a40e2ed1..bcccb79d 100644 --- a/runtime/ruleset.c +++ b/runtime/ruleset.c @@ -347,7 +347,7 @@ evalPROPFILT(struct cnfstmt *stmt, msg_t *pMsg) unsigned short pbMustBeFreed; uchar *pszPropVal; int bRet = 0; - size_t propLen; + rs_size_t propLen; if(stmt->d.s_propfilt.propID == PROP_INVALID) goto done; diff --git a/runtime/typedefs.h b/runtime/typedefs.h index f994cbc4..b53c36f5 100644 --- a/runtime/typedefs.h +++ b/runtime/typedefs.h @@ -92,6 +92,8 @@ typedef struct cfgmodules_etry_s cfgmodules_etry_t; typedef struct outchannels_s outchannels_t; typedef struct modConfData_s modConfData_t; typedef struct instanceConf_s instanceConf_t; +typedef int rs_size_t; /* we do never need more than 2Gig strings, signed permits to + * use -1 as a special flag. */ typedef rsRetVal (*prsf_t)(struct vmstk_s*, int); /* pointer to a RainerScript function */ typedef uint64 qDeqID; /* queue Dequeue order ID. 32 bits is considered dangerously few */ |