diff options
author | Jérôme Renard <jerome.renard@gmail.com> | 2012-08-26 14:13:26 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-08-26 14:13:26 +0200 |
commit | 744d7c426da4aa3229771358a5da27b79e2edf52 (patch) | |
tree | 060a3a287579367938152f1edf86884deaddfcff /runtime | |
parent | d1589cd43978c700e2c88747e04d29c64a25d185 (diff) | |
download | rsyslog-744d7c426da4aa3229771358a5da27b79e2edf52.tar.gz rsyslog-744d7c426da4aa3229771358a5da27b79e2edf52.tar.xz rsyslog-744d7c426da4aa3229771358a5da27b79e2edf52.zip |
add uuid property to message object
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/msg.c | 63 | ||||
-rw-r--r-- | runtime/msg.h | 2 | ||||
-rw-r--r-- | runtime/rsyslog.h | 1 |
3 files changed, 63 insertions, 3 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index 44d36fef..8d24ea66 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -43,6 +43,7 @@ #if HAVE_MALLOC_H # include <malloc.h> #endif +#include <uuid/uuid.h> #include "rsyslog.h" #include "srUtils.h" #include "stringbuf.h" @@ -568,6 +569,8 @@ propNameStrToID(uchar *pName, propid_t *pPropID) *pPropID = PROP_SYS_BOM; } else if(!strcmp((char*) pName, "$uptime")) { *pPropID = PROP_SYS_UPTIME; + } else if(!strcmp((char*) pName, "uuid")) { + *pPropID = PROP_UUID; } else { *pPropID = PROP_INVALID; iRet = RS_RET_VAR_NOT_FOUND; @@ -666,6 +669,8 @@ uchar *propIDToName(propid_t propID) return UCHAR_CONSTANT("$!all-json"); case PROP_SYS_BOM: return UCHAR_CONSTANT("$BOM"); + case PROP_UUID: + return UCHAR_CONSTANT("uuid"); default: return UCHAR_CONSTANT("*invalid property id*"); } @@ -745,6 +750,7 @@ static inline rsRetVal msgBaseConstruct(msg_t **ppThis) pM->pszRcvdAt_SecFrac[0] = '\0'; pM->pszTIMESTAMP_Unix[0] = '\0'; pM->pszRcvdAt_Unix[0] = '\0'; + pM->pszUUID = NULL; /* DEV debugging only! dbgprintf("msgConstruct\t0x%x, ref 1\n", (int)pM);*/ @@ -875,6 +881,8 @@ CODESTARTobjDestruct(msg) rsCStrDestruct(&pThis->pCSMSGID); if(pThis->event != NULL) ee_deleteEvent(pThis->event); + if(pThis->pszUUID != NULL) + free(pThis->pszUUID); # ifndef HAVE_ATOMIC_BUILTINS MsgUnlock(pThis); # endif @@ -1080,6 +1088,8 @@ static rsRetVal MsgSerialize(msg_t *pThis, strm_t *pStrm) objSerializePTR(pStrm, pCSPROCID, CSTR); objSerializePTR(pStrm, pCSMSGID, CSTR); + objSerializePTR(pStrm, pszUUID, PSZ); + if(pThis->pRuleset != NULL) { rulesetGetName(pThis->pRuleset); CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("pszRuleset"), PROPTYPE_PSZ, @@ -1242,6 +1252,54 @@ char *getProtocolVersionString(msg_t *pM) return(pM->iProtocolVersion ? "1" : "0"); } +void msgSetUUID(msg_t *pM) +{ + dbgprintf("[MsgSetUUID] START\n"); + assert(pM != NULL); + + dbgprintf("[MsgSetUUID] pM NOT null \n"); + + size_t lenRes = sizeof(uuid_t) * 2 + 1; + char hex_char [] = "0123456789ABCDEF"; + unsigned int byte_nbr; + uuid_t uuid; + + if((pM->pszUUID = (uchar*) MALLOC(lenRes)) == NULL) { + pM->pszUUID = (uchar *)""; + } else { + uuid_generate(uuid); + for (byte_nbr = 0; byte_nbr < sizeof (uuid_t); byte_nbr++) { + pM->pszUUID[byte_nbr * 2 + 0] = hex_char[uuid [byte_nbr] >> 4]; + pM->pszUUID[byte_nbr * 2 + 1] = hex_char[uuid [byte_nbr] & 15]; + } + + dbgprintf("[MsgSetUUID] UUID : %s LEN: %d \n", pM->pszUUID, (int)lenRes); + pM->pszUUID[lenRes] = '\0'; + } + dbgprintf("[MsgSetUUID] END\n"); +} + +void getUUID(msg_t *pM, uchar **pBuf, int *piLen) +{ + dbgprintf("[getUUID] START\n"); + if(pM == NULL) { + dbgprintf("[getUUID] pM is NULL\n"); + *pBuf= UCHAR_CONSTANT(""); + *piLen = 0; + } else { + if(pM->pszUUID == NULL) { + dbgprintf("[getUUID] pM->pszUUID is NULL\n"); + + msgSetUUID(pM); + } else { + /* UUID already there we reuse it */ + dbgprintf("[getUUID] pM->pszUUID already exists\n"); + } + *pBuf = pM->pszUUID; + *piLen = sizeof(uuid_t) * 2; + } + dbgprintf("[getUUID] END\n"); +} void getRawMsg(msg_t *pM, uchar **pBuf, int *piLen) @@ -1908,7 +1966,6 @@ static inline char *getStructuredData(msg_t *pM) return (char*) pszRet; } - /* check if we have a ProgramName, and, if not, try to aquire/emulate it. * rgerhards, 2009-06-26 */ @@ -2232,7 +2289,6 @@ finalize_it: RETiRet; } - /* set raw message in message object. Size of message is provided. * The function makes sure that the stored rawmsg is properly * terminated by '\0'. @@ -2774,6 +2830,9 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, } # endif break; + case PROP_UUID: + getUUID(pMsg, &pRes, &bufLen); + break; default: /* there is no point in continuing, we may even otherwise render the * error message unreadable. rgerhards, 2007-07-10 diff --git a/runtime/msg.h b/runtime/msg.h index ed2e9d04..f6b54a77 100644 --- a/runtime/msg.h +++ b/runtime/msg.h @@ -123,6 +123,7 @@ struct msg { char pszRcvdAt_SecFrac[7]; /* same as above. Both are fractional seconds for their respective timestamp */ char pszTIMESTAMP_Unix[12]; /* almost as small as a pointer! */ char pszRcvdAt_Unix[12]; + uchar *pszUUID; /* The message's UUID */ }; @@ -184,7 +185,6 @@ 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); - /* TODO: remove these five (so far used in action.c) */ uchar *getMSG(msg_t *pM); char *getHOSTNAME(msg_t *pM); diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index d802536a..57e8a05c 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -142,6 +142,7 @@ typedef uintTiny propid_t; #define PROP_CEE_ALL_JSON 201 #define PROP_SYS_BOM 159 #define PROP_SYS_UPTIME 160 +#define PROP_UUID 161 /* The error codes below are orginally "borrowed" from |