summaryrefslogtreecommitdiff
path: root/runtime/msg.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2014-04-03 03:08:50 +0200
committerMichael Biebl <biebl@debian.org>2014-04-03 03:08:50 +0200
commit9374a46543e9c43c009f80def8c3b2506b0b377e (patch)
tree8853fd40ee8d55ff24304ff8a4421640f3493c58 /runtime/msg.c
parent209e193f14ec562df5aad945f04cd88b227cc602 (diff)
downloadrsyslog-9374a46543e9c43c009f80def8c3b2506b0b377e.tar.gz
Imported Upstream version 8.2.0upstream/8.2.0
Diffstat (limited to 'runtime/msg.c')
-rw-r--r--runtime/msg.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 8863a67..2959796 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -1605,7 +1605,7 @@ getTimeReported(msg_t * const pM, enum tplFormatTypes eFmt)
return "INVALID eFmt OPTION!";
}
-static inline char *getTimeGenerated(msg_t * const pM, enum tplFormatTypes eFmt)
+static char *getTimeGenerated(msg_t * const pM, enum tplFormatTypes eFmt)
{
BEGINfunc
if(pM == NULL)
@@ -2622,14 +2622,17 @@ finalize_it:
/* Encode a JSON value and add it to provided string. Note that
* the string object may be NULL. In this case, it is created
- * if and only if escaping is needed.
+ * if and only if escaping is needed. if escapeAll is false, previously
+ * escaped strings are left as is
*/
static rsRetVal
-jsonAddVal(uchar *pSrc, unsigned buflen, es_str_t **dst)
+jsonAddVal(uchar *pSrc, unsigned buflen, es_str_t **dst, int escapeAll)
{
unsigned char c;
es_size_t i;
char numbuf[4];
+ unsigned ni;
+ unsigned char nc;
int j;
DEFiRet;
@@ -2665,6 +2668,23 @@ jsonAddVal(uchar *pSrc, unsigned buflen, es_str_t **dst)
es_addBuf(dst, "\\/", 2);
break;
case '\\':
+ if (escapeAll == RSFALSE) {
+ ni = i + 1;
+ if (ni <= buflen) {
+ nc = pSrc[ni];
+
+ /* Attempt to not double encode */
+ if ( nc == '"' || nc == '/' || nc == '\\' || nc == 'b' || nc == 'f'
+ || nc == 'n' || nc == 'r' || nc == 't' || nc == 'u') {
+
+ es_addChar(dst, c);
+ es_addChar(dst, nc);
+ i = ni;
+ break;
+ }
+ }
+ }
+
es_addBuf(dst, "\\\\", 2);
break;
case '\010':
@@ -2710,7 +2730,7 @@ finalize_it:
* rgerhards, 2012-03-16
*/
static rsRetVal
-jsonEncode(uchar **ppRes, unsigned short *pbMustBeFreed, int *pBufLen)
+jsonEncode(uchar **ppRes, unsigned short *pbMustBeFreed, int *pBufLen, int escapeAll)
{
unsigned buflen;
uchar *pSrc;
@@ -2719,7 +2739,7 @@ jsonEncode(uchar **ppRes, unsigned short *pbMustBeFreed, int *pBufLen)
pSrc = *ppRes;
buflen = (*pBufLen == -1) ? ustrlen(pSrc) : *pBufLen;
- CHKiRet(jsonAddVal(pSrc, buflen, &dst));
+ CHKiRet(jsonAddVal(pSrc, buflen, &dst, escapeAll));
if(dst != NULL) {
/* we updated the string and need to replace the
@@ -2748,7 +2768,7 @@ finalize_it:
* something to consider at a later stage. rgerhards, 2012-04-19
*/
static rsRetVal
-jsonField(struct templateEntry *pTpe, uchar **ppRes, unsigned short *pbMustBeFreed, int *pBufLen)
+jsonField(struct templateEntry *pTpe, uchar **ppRes, unsigned short *pbMustBeFreed, int *pBufLen, int escapeAll)
{
unsigned buflen;
uchar *pSrc;
@@ -2762,7 +2782,7 @@ jsonField(struct templateEntry *pTpe, uchar **ppRes, unsigned short *pbMustBeFre
es_addChar(&dst, '"');
es_addBuf(&dst, (char*)pTpe->fieldName, pTpe->lenFieldName);
es_addBufConstcstr(&dst, "\":\"");
- CHKiRet(jsonAddVal(pSrc, buflen, &dst));
+ CHKiRet(jsonAddVal(pSrc, buflen, &dst, escapeAll));
es_addChar(&dst, '"');
if(*pbMustBeFreed)
@@ -2819,9 +2839,9 @@ finalize_it:
#define RET_OUT_OF_MEMORY { *pbMustBeFreed = 0;\
*pPropLen = sizeof("**OUT OF MEMORY**") - 1; \
return(UCHAR_CONSTANT("**OUT OF MEMORY**"));}
-uchar *MsgGetProp(msg_t * const pMsg, struct templateEntry *pTpe,
- msgPropDescr_t *pProp, rs_size_t *pPropLen,
- unsigned short *pbMustBeFreed, struct syslogTime *ttNow)
+uchar *MsgGetProp(msg_t *__restrict__ const pMsg, struct templateEntry *__restrict__ const pTpe,
+ msgPropDescr_t *pProp, rs_size_t *__restrict__ const pPropLen,
+ unsigned short *__restrict__ const pbMustBeFreed, struct syslogTime * const ttNow)
{
uchar *pRes; /* result pointer */
rs_size_t bufLen = -1; /* length of string or -1, if not known */
@@ -3674,9 +3694,13 @@ uchar *MsgGetProp(msg_t * const pMsg, struct templateEntry *pTpe,
bufLen = -1;
*pbMustBeFreed = 1;
} else if(pTpe->data.field.options.bJSON) {
- jsonEncode(&pRes, pbMustBeFreed, &bufLen);
+ jsonEncode(&pRes, pbMustBeFreed, &bufLen, RSTRUE);
} else if(pTpe->data.field.options.bJSONf) {
- jsonField(pTpe, &pRes, pbMustBeFreed, &bufLen);
+ jsonField(pTpe, &pRes, pbMustBeFreed, &bufLen, RSTRUE);
+ } else if(pTpe->data.field.options.bJSONr) {
+ jsonEncode(&pRes, pbMustBeFreed, &bufLen, RSFALSE);
+ } else if(pTpe->data.field.options.bJSONfr) {
+ jsonField(pTpe, &pRes, pbMustBeFreed, &bufLen, RSFALSE);
}
*pPropLen = (bufLen == -1) ? ustrlen(pRes) : bufLen;