summaryrefslogtreecommitdiffstats
path: root/runtime/msg.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-04-02 12:48:07 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-04-02 12:48:07 +0200
commit3954f2e166c3cbd78c71819c8d6c25120042dbcf (patch)
tree2c70fa3bb36f763490146e1fa6e205600f5afb34 /runtime/msg.c
parente4f012eb60f6531f964557ba9eac54048ae2bef8 (diff)
downloadrsyslog-3954f2e166c3cbd78c71819c8d6c25120042dbcf.tar.gz
rsyslog-3954f2e166c3cbd78c71819c8d6c25120042dbcf.tar.xz
rsyslog-3954f2e166c3cbd78c71819c8d6c25120042dbcf.zip
added new "csv" property replacer option
to enable simple creation of CSV-formatted outputs (format from RFC4180 is used)
Diffstat (limited to 'runtime/msg.c')
-rw-r--r--runtime/msg.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 9aa2ce84..5d1f21fd 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -2405,6 +2405,40 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
}
}
+ /* finally, we need to check if the property should be formatted in CSV
+ * format (we use RFC 4180, and always use double quotes). As of this writing,
+ * this should be the last action carried out on the property, but in the
+ * future there may be reasons to change that. -- rgerhards, 2009-04-02
+ */
+ if(pTpe->data.field.options.bCSV) {
+ /* we need to obtain a private copy, as we need to at least add the double quotes */
+ int iBufLen = strlen(pRes);
+ char *pBStart;
+ char *pDst;
+ char *pSrc;
+ /* the malloc may be optimized, we currently use the worst case... */
+ pBStart = pDst = malloc((2 * iBufLen + 3) * sizeof(char));
+ if(pDst == NULL) {
+ if(*pbMustBeFreed == 1)
+ free(pRes);
+ *pbMustBeFreed = 0;
+ return "**OUT OF MEMORY**";
+ }
+ pSrc = pRes;
+ *pDst++ = '"'; /* starting quote */
+ while(*pSrc) {
+ if(*pSrc == '"')
+ *pDst++ = '"'; /* need to add double double quote (see RFC4180) */
+ *pDst++ = *pSrc++;
+ }
+ *pDst++ = '"'; /* ending quote */
+ *pDst = '\0';
+ if(*pbMustBeFreed == 1)
+ free(pRes);
+ pRes = pBStart;
+ *pbMustBeFreed = 1;
+ }
+
/*dbgprintf("MsgGetProp(\"%s\"): \"%s\"\n", pName, pRes); only for verbose debug logging */
return(pRes);
}