summaryrefslogtreecommitdiffstats
path: root/runtime/msg.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/msg.c')
-rw-r--r--runtime/msg.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 22303adb..8e19d98f 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -735,7 +735,7 @@ int getPRIi(msg_t *pM)
}
-char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt)
+char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt, const char *sfmt)
{
if(pM == NULL)
return "";
@@ -807,11 +807,31 @@ char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt)
}
MsgUnlock(pM);
return(pM->pszTIMESTAMP_SecFrac);
+ case tplFmtStrftime:
+ MsgLock(pM);
+ if(pM->pszTIMESTAMP_Strftime == NULL) {
+ char *str, *rstr;
+ size_t actual;
+ struct tm local;
+ if((str = malloc(256)) == NULL) {
+ MsgUnlock(pM);
+ return ""; /* TODO: check this: can it cause a free() of constant memory?) */
+ }
+ localtime_r(&pM->tTIMESTAMP.epoch, &local);
+ actual = strftime(str, 256, sfmt, &local);
+ rstr = realloc(str, actual + 1);
+ if (rstr)
+ str = rstr;
+ pM->pszTIMESTAMP_Strftime = str;
+
+ }
+ MsgUnlock(pM);
+ return(pM->pszTIMESTAMP_Strftime);
}
return "INVALID eFmt OPTION!";
}
-char *getTimeGenerated(msg_t *pM, enum tplFormatTypes eFmt)
+char *getTimeGenerated(msg_t *pM, enum tplFormatTypes eFmt, const char *sfmt)
{
if(pM == NULL)
return "";
@@ -883,6 +903,26 @@ char *getTimeGenerated(msg_t *pM, enum tplFormatTypes eFmt)
}
MsgUnlock(pM);
return(pM->pszRcvdAt_SecFrac);
+ case tplFmtStrftime:
+ MsgLock(pM);
+ if(pM->pszRcvdAt_Strftime == NULL) {
+ char *str, *rstr;
+ size_t actual;
+ struct tm local;
+ if((str = malloc(256)) == NULL) {
+ MsgUnlock(pM);
+ return ""; /* TODO: check this: can it cause a free() of constant memory?) */
+ }
+ localtime_r(&pM->tRcvdAt.epoch, &local);
+ actual = strftime(str, 256, sfmt, &local);
+ rstr = realloc(str, actual + 1);
+ if (rstr)
+ str = rstr;
+ pM->pszRcvdAt_Strftime = str;
+
+ }
+ MsgUnlock(pM);
+ return(pM->pszRcvdAt_Strftime);
}
return "INVALID eFmt OPTION!";
}
@@ -1768,10 +1808,12 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
} else if(!strcmp((char*) pName, "syslogseverity-text") || !strcmp((char*) pName, "syslogpriority-text")) {
pRes = getSeverityStr(pMsg);
} else if(!strcmp((char*) pName, "timegenerated")) {
- pRes = getTimeGenerated(pMsg, pTpe->data.field.eDateFormat);
+ pRes = getTimeGenerated(pMsg, pTpe->data.field.eDateFormat,
+ pTpe->data.field.strftime_fmt);
} else if(!strcmp((char*) pName, "timereported")
|| !strcmp((char*) pName, "timestamp")) {
- pRes = getTimeReported(pMsg, pTpe->data.field.eDateFormat);
+ pRes = getTimeReported(pMsg, pTpe->data.field.eDateFormat,
+ pTpe->data.field.strftime_fmt);
} else if(!strcmp((char*) pName, "programname")) {
pRes = getProgramName(pMsg);
} else if(!strcmp((char*) pName, "protocol-version")) {