diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-07 17:26:49 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-07 17:26:49 +0000 |
commit | 571d21a33a46707deabc80769b4c8cb7d0f7c161 (patch) | |
tree | bab2d123fb14afa219f841cc41d809d541b57dc2 /msg.c | |
parent | 918f281d8226689f5c997a07c0bcd9a691ddb178 (diff) | |
download | rsyslog-571d21a33a46707deabc80769b4c8cb7d0f7c161.tar.gz rsyslog-571d21a33a46707deabc80769b4c8cb7d0f7c161.tar.xz rsyslog-571d21a33a46707deabc80769b4c8cb7d0f7c161.zip |
- MsgSetProperty() implemented
- defined a property class
- implemented deserializer (needs some more work)
Diffstat (limited to 'msg.c')
-rw-r--r-- | msg.c | 67 |
1 files changed, 57 insertions, 10 deletions
@@ -38,6 +38,7 @@ #include <ctype.h> #include "syslogd.h" #include "srUtils.h" +#include "stringbuf.h" #include "template.h" #include "msg.h" @@ -203,22 +204,28 @@ rsRetVal MsgEnableThreadSafety(void) * An object constructed via this function should only be destroyed * via "MsgDestruct()". */ -msg_t* MsgConstruct(void) +rsRetVal MsgConstruct(msg_t **ppThis) { + DEFiRet; msg_t *pM; - if((pM = calloc(1, sizeof(msg_t))) != NULL) - { /* initialize members that are non-zero */ - pM->iRefCount = 1; - pM->iSeverity = -1; - pM->iFacility = -1; - getCurrTime(&(pM->tRcvdAt)); - objConstructSetObjInfo(pM); - } + assert(ppThis != NULL); + if((pM = calloc(1, sizeof(msg_t))) == NULL) + ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + + /* initialize members that are non-zero */ + pM->iRefCount = 1; + pM->iSeverity = -1; + pM->iFacility = -1; + getCurrTime(&(pM->tRcvdAt)); + objConstructSetObjInfo(pM); /* DEV debugging only! dbgprintf("MsgConstruct\t0x%x, ref 1\n", (int)pM);*/ - return(pM); + *ppThis = pM; + +finalize_it: + return iRet; } @@ -2076,12 +2083,52 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, } +/* 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 + * change over time). + * rgerhards, 2008-01-07 + */ +#define isProp(name) !rsCStrSzStrCmp(pProp->pcsName, (uchar*) name, sizeof(name) - 1) +rsRetVal MsgSetProperty(msg_t *pThis, property_t *pProp) +{ + DEFiRet; + + assert(pThis != NULL); + assert(pProp != NULL); + + if(isProp("iProtocolVersion")) { + setProtocolVersion(pThis, pProp->val.vShort); + } else if(isProp("iSeverity")) { + pThis->iSeverity = pProp->val.vShort; + } else if(isProp("iFacility")) { + pThis->iFacility = pProp->val.vShort; + } else if(isProp("msgFlags")) { + pThis->msgFlags = pProp->val.vInt; + } else if(isProp("pszRawMsg")) { + MsgSetRawMsg(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.vpCStr)); + } else if(isProp("pszMSG")) { + MsgSetMSG(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.vpCStr)); + } else if(isProp("pszTAG")) { + MsgSetTAG(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.vpCStr)); + } else if(isProp("pszHOSTNAME")) { + MsgSetHOSTNAME(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.vpCStr)); + } else if(isProp("pszUxTradMsg")) { + MsgSetUxTradMsg(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.vpCStr)); + } + + return iRet; +} +#undef isProp + + /* Initialize the message class. Must be called as the very first method * before anything else is called inside this class. * rgerhards, 2008-01-04 */ BEGINObjClassInit(Msg, 1) OBJSetMethodHandler(objMethod_SERIALIZE, MsgSerialize); + OBJSetMethodHandler(objMethod_SETPROPERTY, MsgSetProperty); /* initially, we have no need to lock message objects */ funcLock = MsgLockingDummy; funcUnlock = MsgLockingDummy; |