diff options
-rw-r--r-- | msg.c | 59 | ||||
-rw-r--r-- | msg.h | 5 | ||||
-rw-r--r-- | obj.c | 33 | ||||
-rw-r--r-- | obj.h | 8 |
4 files changed, 63 insertions, 42 deletions
@@ -210,7 +210,6 @@ msg_t* MsgConstruct(void) if((pM = calloc(1, sizeof(msg_t))) != NULL) { /* initialize members that are non-zero */ pM->iRefCount = 1; - pM->iSyslogVers = -1; pM->iSeverity = -1; pM->iFacility = -1; getCurrTime(&(pM->tRcvdAt)); @@ -334,8 +333,6 @@ msg_t* MsgDup(msg_t* pOld) /* now copy the message properties */ pNew->iRefCount = 1; - pNew->iSyslogVers = pOld->iSyslogVers; - pNew->bParseHOSTNAME = pOld->bParseHOSTNAME; pNew->iSeverity = pOld->iSeverity; pNew->iFacility = pOld->iFacility; pNew->bParseHOSTNAME = pOld->bParseHOSTNAME; @@ -378,7 +375,9 @@ msg_t* MsgDup(msg_t* pOld) * on-disk representation of the message object. * We do not serialize the cache properties. We re-create them when needed. * This saves us a lot of memory. Performance is no concern, as serializing - * is a so slow operation that recration of the caches does not count. + * is a so slow operation that recration of the caches does not count. Also, + * we do not serialize bParseHOSTNAME, as this is only a helper variable + * during msg construction - and never again used later. * rgerhards, 2008-01-03 */ static rsRetVal MsgSerialize(msg_t *pThis, uchar **ppOutBuf, size_t *pLenBuf) @@ -386,47 +385,35 @@ static rsRetVal MsgSerialize(msg_t *pThis, uchar **ppOutBuf, size_t *pLenBuf) DEFiRet; rsCStrObj *pCStr; -dbgprintf("MsgSerialize in\n"); assert(ppOutBuf != NULL); assert(pLenBuf != NULL); assert(pThis != NULL); -# define mySerializeINT(propName) \ - CHKiRet(objSerializeProp(pCStr, (uchar*) #propName, PROPTYPE_SHORT, (void*) &pThis->propName)); CHKiRet(objBeginSerialize(&pCStr, (obj_t*) pThis)); -dbgprintf("syslog vers: %d, bparsehost: %d, sever %d\n", pThis->iSyslogVers, pThis->bParseHOSTNAME, pThis->iSeverity); - mySerializeINT(iSyslogVers); - mySerializeINT(bParseHOSTNAME); - mySerializeINT(iSeverity); - - CHKiRet(objSerializeProp(pCStr, (uchar*) "pszRawMsg", PROPTYPE_PSZ, (void*) pThis->pszRawMsg)); - CHKiRet(objSerializeProp(pCStr, (uchar*) "pszMSG", PROPTYPE_PSZ, (void*) pThis->pszMSG)); - CHKiRet(objSerializeProp(pCStr, (uchar*) "pszUxTradMsg", PROPTYPE_PSZ, (void*) pThis->pszUxTradMsg)); - CHKiRet(objSerializeProp(pCStr, (uchar*) "pszTAG", PROPTYPE_PSZ, (void*) pThis->pszTAG)); - CHKiRet(objSerializeProp(pCStr, (uchar*) "pszHOSTNAME", PROPTYPE_PSZ, (void*) pThis->pszHOSTNAME)); - CHKiRet(objSerializeProp(pCStr, (uchar*) "pszRcvFrom", PROPTYPE_PSZ, (void*) pThis->pszRcvFrom)); - //CHKiRet(objSerializeProp(pCStr, (uchar*) "psz", PROPTYPE_PSZ, (void*) pThis->psz)); + objSerializeSCALAR(iProtocolVersion, SHORT); + objSerializeSCALAR(iSeverity, SHORT); + objSerializeSCALAR(iFacility, SHORT); + objSerializeSCALAR(msgFlags, INT); + objSerializeSCALAR(tRcvdAt, SYSLOGTIME); + objSerializeSCALAR(tTIMESTAMP, SYSLOGTIME); + + objSerializePTR(pszRawMsg, PSZ); + objSerializePTR(pszMSG, PSZ); + objSerializePTR(pszUxTradMsg, PSZ); + objSerializePTR(pszTAG, PSZ); + objSerializePTR(pszHOSTNAME, PSZ); + objSerializePTR(pszRcvFrom, PSZ); + + objSerializePTR(pCSProgName, CSTR); + objSerializePTR(pCSStrucData, CSTR); + objSerializePTR(pCSAPPNAME, CSTR); + objSerializePTR(pCSPROCID, CSTR); + objSerializePTR(pCSMSGID, CSTR); + CHKiRet(objEndSerialize(pCStr, ppOutBuf)); pCStr = NULL; -# undef mySerialize - -/* - if(rsCStrAppendChar(pStrB, (escapeMode == 0) ? '\'' : '\\') != RS_RET_OK) - - pNew->iFacility = pOld->iFacility; - pNew->bParseHOSTNAME = pOld->bParseHOSTNAME; - pNew->msgFlags = pOld->msgFlags; - pNew->iProtocolVersion = pOld->iProtocolVersion; - memcpy(&pNew->tRcvdAt, &pOld->tRcvdAt, sizeof(struct syslogTime)); - memcpy(&pNew->tTIMESTAMP, &pOld->tTIMESTAMP, sizeof(struct syslogTime)); - tmpCOPYCSTR(ProgName); - tmpCOPYCSTR(StrucData); - tmpCOPYCSTR(APPNAME); - tmpCOPYCSTR(PROCID); - tmpCOPYCSTR(MSGID); -*/ finalize_it: if(pCStr != NULL) rsCStrDestruct(pCStr); @@ -50,9 +50,6 @@ struct msg { pthread_mutexattr_t mutAttr; pthread_mutex_t mut; int iRefCount; /* reference counter (0 = unused) */ - short iSyslogVers; /* version of syslog protocol - * 0 - RFC 3164 - * 1 - RFC draft-protocol-08 */ short bParseHOSTNAME; /* should the hostname be parsed from the message? */ /* background: the hostname is not present on "regular" messages * received via UNIX domain sockets from the same machine. However, @@ -87,7 +84,7 @@ struct msg { int iLenHOSTNAME; /* Length of HOSTNAME */ uchar *pszRcvFrom; /* System message was received from */ int iLenRcvFrom; /* Length of pszRcvFrom */ - int iProtocolVersion;/* protocol version of message received 0 - legacy, 1 syslog-protocol) */ + short iProtocolVersion;/* protocol version of message received 0 - legacy, 1 syslog-protocol) */ rsCStrObj *pCSProgName; /* the (BSD) program name */ rsCStrObj *pCSStrucData;/* STRUCTURED-DATA */ rsCStrObj *pCSAPPNAME; /* APP-NAME */ @@ -27,11 +27,13 @@ */ #include "config.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include "rsyslog.h" +#include "syslogd-types.h" #include "srUtils.h" #include "obj.h" @@ -149,8 +151,10 @@ rsRetVal objSerializeProp(rsCStrObj *pCStr, uchar *pszPropName, propertyType_t p * TODO: think if that's the righ point of view * rgerhards, 2008-01-06 */ - if(pUsr == NULL) + if(pUsr == NULL) { +dbgprintf("ptr is NULL\n"); ABORT_FINALIZE(RS_RET_OK); + } switch(propType) { case PROPTYPE_PSZ: @@ -167,6 +171,33 @@ rsRetVal objSerializeProp(rsCStrObj *pCStr, uchar *pszPropName, propertyType_t p pszBuf = szBuf; lenBuf = strlen((char*) szBuf); break; + case PROPTYPE_LONG: + CHKiRet(srUtilItoA((char*) szBuf, sizeof(szBuf), *((long*) pUsr))); + pszBuf = szBuf; + lenBuf = strlen((char*) szBuf); + break; + case PROPTYPE_CSTR: + pszBuf = rsCStrGetSzStrNoNULL((rsCStrObj *) pUsr); + lenBuf = strlen((char*) pszBuf); + break; + case PROPTYPE_SYSLOGTIME: + lenBuf = snprintf((char*) szBuf, sizeof(szBuf), "%d %d %d %d %d %d %d %d %d %c %d %d", + ((struct syslogTime*)pUsr)->timeType, + ((struct syslogTime*)pUsr)->year, + ((struct syslogTime*)pUsr)->month, + ((struct syslogTime*)pUsr)->day, + ((struct syslogTime*)pUsr)->hour, + ((struct syslogTime*)pUsr)->minute, + ((struct syslogTime*)pUsr)->second, + ((struct syslogTime*)pUsr)->secfrac, + ((struct syslogTime*)pUsr)->secfracPrecision, + ((struct syslogTime*)pUsr)->OffsetMode, + ((struct syslogTime*)pUsr)->OffsetHour, + ((struct syslogTime*)pUsr)->OffsetMinute); + if(lenBuf > sizeof(szBuf) - 1) + ABORT_FINALIZE(RS_RET_PROVIDED_BUFFER_TOO_SMALL); + pszBuf = szBuf; + break; } /* name */ @@ -33,7 +33,9 @@ typedef enum { /* do NOT start at 0 to detect uninitialized types after calloc( PROPTYPE_PSZ = 1, PROPTYPE_SHORT = 2, PROPTYPE_INT = 3, - PROPTYPE_LONG = 4 + PROPTYPE_LONG = 4, + PROPTYPE_CSTR = 5, + PROPTYPE_SYSLOGTIME = 6 } propertyType_t; /* object Types */ @@ -65,6 +67,10 @@ typedef struct obj { /* the dummy struct that each derived class can be casted t /* macros */ +#define objSerializeSCALAR(propName, propType) \ + CHKiRet(objSerializeProp(pCStr, (uchar*) #propName, PROPTYPE_##propType, (void*) &pThis->propName)); +#define objSerializePTR(propName, propType) \ + CHKiRet(objSerializeProp(pCStr, (uchar*) #propName, PROPTYPE_##propType, (void*) pThis->propName)); #define DEFobjStaticHelpers static objInfo_t *pObjInfoOBJ = NULL; #define BEGINobjInstance objInfo_t *pObjInfo #define objGetName(pThis) (((obj_t*) (pThis))->pObjInfo->pszName) |