summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--action.c23
-rw-r--r--template.c45
2 files changed, 56 insertions, 12 deletions
diff --git a/action.c b/action.c
index 5d9211e2..8f8371f7 100644
--- a/action.c
+++ b/action.c
@@ -98,6 +98,7 @@
#include <strings.h>
#include <time.h>
#include <errno.h>
+#include <json/json.h>
#include "dirty.h"
#include "template.h"
@@ -803,6 +804,7 @@ static rsRetVal prepareDoActionParams(action_t *pAction, batch_obj_t *pElem)
{
int i;
msg_t *pMsg;
+ struct json_object *json;
DEFiRet;
ASSERT(pAction != NULL);
@@ -824,7 +826,8 @@ static rsRetVal prepareDoActionParams(action_t *pAction, batch_obj_t *pElem)
pElem->staticActParams[i] = (void*) pMsg;
break;
case ACT_JSON_PASSING:
- // TODO: implement
+ CHKiRet(tplToJSON(pAction->ppTpl[i], pMsg, &json));
+ pElem->staticActParams[i] = (void*) json;
break;
default:dbgprintf("software bug/error: unknown pAction->eParamPassing %d in prepareDoActionParams\n",
(int) pAction->eParamPassing);
@@ -877,7 +880,6 @@ static rsRetVal releaseBatch(action_t *pAction, batch_t *pBatch)
break;
case ACT_STRING_PASSING:
case ACT_MSG_PASSING:
- case ACT_JSON_PASSING:
/* nothing to do in that case */
/* TODO ... and yet we do something ;) This is considered not
* really needed, but I was not bold enough to remove that while
@@ -889,6 +891,13 @@ static rsRetVal releaseBatch(action_t *pAction, batch_t *pBatch)
((uchar**)pElem->staticActParams)[j] = NULL;
}
break;
+ case ACT_JSON_PASSING:
+ for(j = 0 ; j < pAction->iNumTpls ; ++j) {
+ json_object_put((struct json_object*)
+ pElem->staticActParams[j]);
+ pElem->staticActParams[j] = NULL;
+ }
+ break;
}
}
}
@@ -1098,16 +1107,6 @@ finalize_it:
RETiRet;
}
-/* debug aid */
-static void displayBatchState(batch_t *pBatch)
-{
- int i;
- for(i = 0 ; i < pBatch->nElem ; ++i) {
- dbgprintf("XXXXX: displayBatchState2 %p[%d]: %d\n", pBatch, i, pBatch->pElem[i].state);
- }
-}
-
-
/* submit a batch for actual action processing.
* The first nElem elements are processed. This function calls itself
* recursively if it needs to handle errors.
diff --git a/template.c b/template.c
index 768608f1..a3d2b8d6 100644
--- a/template.c
+++ b/template.c
@@ -34,6 +34,7 @@
#include <string.h>
#include <ctype.h>
#include <assert.h>
+#include <json/json.h>
#include "stringbuf.h"
#include "syslogd-types.h"
#include "template.h"
@@ -270,6 +271,50 @@ finalize_it:
}
+/* This functions converts a template into a json object.
+ * For further general details, see the very similar funtion
+ * tpltoString().
+ * rgerhards, 2012-08-29
+ */
+rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **pjson)
+{
+ struct templateEntry *pTpe;
+ char *cstr;
+ size_t propLen;
+ unsigned short bMustBeFreed;
+ uchar *pVal;
+ struct json_object *json, *jsonf;
+ DEFiRet;
+
+ assert(pTpl != NULL);
+ assert(pMsg != NULL);
+ assert(json != NULL);
+
+ json = json_object_new_object();
+ for(pTpe = pTpl->pEntryRoot ; pTpe != NULL ; pTpe = pTpe->pNext) {
+ if(pTpe->eEntryType == CONSTANT) {
+ if(pTpe->fieldName == NULL)
+ continue;
+ jsonf = json_object_new_string((char*) pTpe->data.constant.pConstant);
+ } else if(pTpe->eEntryType == FIELD) {
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
+ pTpe->data.field.propName, &propLen, &bMustBeFreed);
+ jsonf = json_object_new_string_len((char*)pVal, propLen);
+ if(bMustBeFreed) { /* json-c makes its own private copy! */
+ free(pVal);
+ }
+ }
+ /* TODO: unify strings, handling currently quite inefficient! */
+ cstr = es_str2cstr(pTpe->fieldName, NULL);
+ json_object_object_add(json, cstr, jsonf);
+ free(cstr);
+ }
+
+ *pjson = (iRet == RS_RET_OK) ? json : NULL;
+ RETiRet;
+}
+
+
/* Helper to doEscape. This is called if doEscape
* runs out of memory allocating the escaped string.
* Then we are in trouble. We can