diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/msg.c | 55 | ||||
-rw-r--r-- | runtime/msg.h | 1 | ||||
-rw-r--r-- | runtime/rsconf.c | 14 | ||||
-rw-r--r-- | runtime/rule.c | 2 |
4 files changed, 62 insertions, 10 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index c5cbb5c8..96fe1b2c 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -37,6 +37,7 @@ #include <ctype.h> #include <sys/socket.h> #include <netdb.h> +#include <libestr.h> #include <libee/libee.h> #if HAVE_MALLOC_H # include <malloc.h> @@ -480,16 +481,13 @@ getRcvFromIP(msg_t *pM) } - -/* map a property name (string) to a property ID */ -rsRetVal propNameToID(cstr_t *pCSPropName, propid_t *pPropID) +/* map a property name (C string) to a property ID */ +rsRetVal +propNameStrToID(uchar *pName, propid_t *pPropID) { - uchar *pName; DEFiRet; - assert(pCSPropName != NULL); - assert(pPropID != NULL); - pName = rsCStrGetSzStrNoNULL(pCSPropName); + assert(pName != NULL); /* sometimes there are aliases to the original MonitoWare * property names. These come after || in the ifs below. */ @@ -577,6 +575,21 @@ rsRetVal propNameToID(cstr_t *pCSPropName, propid_t *pPropID) } +/* map a property name (string) to a property ID */ +rsRetVal +propNameToID(cstr_t *pCSPropName, propid_t *pPropID) +{ + uchar *pName; + DEFiRet; + + assert(pCSPropName != NULL); + assert(pPropID != NULL); + pName = rsCStrGetSzStrNoNULL(pCSPropName); + iRet = propNameStrToID(pName, pPropID); + RETiRet; +} + + /* map a property ID to a name string (useful for displaying) */ uchar *propIDToName(propid_t propID) { @@ -3190,6 +3203,34 @@ finalize_it: } + +/* Return an es_str_t for given message property. + */ +es_str_t* +msgGetMsgVarNew(msg_t *pThis, uchar *name) +{ + size_t propLen; + uchar *pszProp = NULL; + propid_t propid; + unsigned short bMustBeFreed = 0; + es_str_t *estr; + + ISOBJ_TYPE_assert(pThis, msg); + + /* always call MsgGetProp() without a template specifier */ + /* TODO: optimize propNameToID() call -- rgerhards, 2009-06-26 */ + propNameStrToID(name, &propid); + pszProp = (uchar*) MsgGetProp(pThis, NULL, propid, NULL, &propLen, &bMustBeFreed); + +dbgprintf("ZZZZ: var %s returns '%s'\n", name, pszProp); + estr = es_newStrFromCStr((char*)pszProp, propLen); + if(bMustBeFreed) + free(pszProp); + + return estr; +} + + /* This function can be used as a generic way to set properties. * We have to handle a lot of legacy, so our return value is not always * 100% correct (called functions do not always provide one, should diff --git a/runtime/msg.h b/runtime/msg.h index 01a1e059..19debb03 100644 --- a/runtime/msg.h +++ b/runtime/msg.h @@ -170,6 +170,7 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, 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); rsRetVal MsgEnableThreadSafety(void); uchar *getRcvFrom(msg_t *pM); void getTAG(msg_t *pM, uchar **ppBuf, int *piLen); diff --git a/runtime/rsconf.c b/runtime/rsconf.c index cb8eac50..459c9a17 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -222,7 +222,6 @@ cnfDoActlst(struct cnfactlst *actlst, rule_t *pRule) { struct cnfcfsyslinelst *cflst; action_t *pAction; - rsRetVal localRet; uchar *str; DEFiRet; @@ -280,7 +279,7 @@ void cnfDoRule(struct cnfrule *cnfrule) { rule_t *pRule; uchar *str; - DEFiRet; + rsRetVal iRet = RS_RET_OK; //DEFiRet; dbgprintf("cnf:global:rule\n"); cnfrulePrint(cnfrule); @@ -346,6 +345,17 @@ void cnfDoBSDHost(char *ln) dbgprintf("cnf:global:BSD host: %s\n", ln); cflineProcessHostSelector((uchar**)&ln); } + +es_str_t* +cnfGetVar(char *name, void *usrptr) +{ + es_str_t *estr; + dbgprintf("ZZZZ: var '%s' requested", name); + if(name[0] == '$') { + estr = msgGetMsgVarNew((msg_t*) usrptr, (uchar*)name+1); + } + return estr; +} /*------------------------------ end interface to flex/bison parser ------------------------------*/ diff --git a/runtime/rule.c b/runtime/rule.c index 8976c898..67ef8650 100644 --- a/runtime/rule.c +++ b/runtime/rule.c @@ -196,7 +196,7 @@ shouldProcessThisMessage(rule_t *pRule, msg_t *pMsg, sbool *bProcessMsg) /* VM is destructed on function exit */ bRet = (pResult->val.num) ? 1 : 0; #endif - bRet = cnfexprEvalBool(pRule->f_filterData.expr); + bRet = cnfexprEvalBool(pRule->f_filterData.expr, pMsg); dbgprintf("result of rainerscript filter evaluation: %d\n", bRet); } else { assert(pRule->f_filter_type == FILTER_PROP); /* assert() just in case... */ |