summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-08-31 14:12:49 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-08-31 14:12:49 +0200
commit197d9ef643b511fc230d6d190718adc338b64731 (patch)
tree046fde2026ec87a6074c22aaa829a43ceb6911ce
parent672f45733bbcfab03e1284afc41b4b516f4f5365 (diff)
downloadrsyslog-197d9ef643b511fc230d6d190718adc338b64731.tar.gz
rsyslog-197d9ef643b511fc230d6d190718adc338b64731.tar.bz2
rsyslog-197d9ef643b511fc230d6d190718adc338b64731.zip
add native json-passing to output modules using JSON API
-rw-r--r--runtime/msg.c35
-rw-r--r--runtime/msg.h1
-rw-r--r--template.c41
3 files changed, 66 insertions, 11 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 3f6916cb..25b4ceeb 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -2407,7 +2407,7 @@ static uchar *getNOW(eNOWType eNow)
#undef tmpBUFSIZE /* clean up */
-/* Get a CEE-Property */
+/* Get a CEE-Property as string value*/
static inline rsRetVal
getCEEPropVal(msg_t *pM, es_str_t *propName, uchar **pRes, int *buflen, unsigned short *pbMustBeFreed)
{
@@ -2446,6 +2446,39 @@ finalize_it:
}
+/* Get a CEE-Property as native json object
+ */
+rsRetVal
+msgGetCEEPropJSON(msg_t *pM, es_str_t *propName, struct json_object **pjson)
+{
+ uchar *name = NULL;
+ uchar *leaf;
+ struct json_object *parent;
+ struct json_object *field;
+ DEFiRet;
+
+dbgprintf("AAAA: enter getCEEPropJSON\n");
+ // TODO: mutex?
+ if(pM->json == NULL) {
+ ABORT_FINALIZE(RS_RET_NOT_FOUND);
+ }
+
+ name = (uchar*)es_str2cstr(propName, NULL);
+dbgprintf("AAAA: name to search '%s'\n", name);
+ leaf = jsonPathGetLeaf(name, ustrlen(name));
+dbgprintf("AAAA: leaf '%s'\n", leaf);
+ CHKiRet(jsonPathFindParent(pM, name, leaf, &parent, 1));
+ *pjson = json_object_object_get(parent, (char*)leaf);
+ if(*pjson == NULL) {
+ ABORT_FINALIZE(RS_RET_NOT_FOUND);
+ }
+
+finalize_it:
+ free(name);
+ RETiRet;
+}
+
+
/* 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.
diff --git a/runtime/msg.h b/runtime/msg.h
index 6c907692..857eb673 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -201,6 +201,7 @@ int getProgramNameLen(msg_t *pM, sbool bLockMutex);
uchar *getRcvFrom(msg_t *pM);
rsRetVal propNameToID(cstr_t *pCSPropName, propid_t *pPropID);
uchar *propIDToName(propid_t propID);
+rsRetVal msgGetCEEPropJSON(msg_t *pM, es_str_t *propName, struct json_object **pjson);
/* The MsgPrepareEnqueue() function is a macro for performance reasons.
diff --git a/template.c b/template.c
index 58933fc5..6bcca42b 100644
--- a/template.c
+++ b/template.c
@@ -44,6 +44,7 @@
#include "errmsg.h"
#include "strgen.h"
#include "rsconf.h"
+#include "msg.h"
#include "unicode-helper.h"
/* static data */
@@ -284,6 +285,7 @@ rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **pjso
unsigned short bMustBeFreed;
uchar *pVal;
struct json_object *json, *jsonf;
+ rsRetVal localRet;
DEFiRet;
assert(pTpl != NULL);
@@ -298,14 +300,33 @@ rsRetVal tplToJSON(struct template *pTpl, msg_t *pMsg, struct json_object **pjso
jsonf = json_object_new_string((char*) pTpe->data.constant.pConstant);
json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
} else if(pTpe->eEntryType == FIELD) {
- pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
- pTpe->data.field.propName, &propLen, &bMustBeFreed);
- if(pTpe->data.field.options.bMandatory || propLen > 0) {
- jsonf = json_object_new_string_len((char*)pVal, propLen);
- json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
- }
- if(bMustBeFreed) { /* json-c makes its own private copy! */
- free(pVal);
+ if(pTpe->data.field.propid == PROP_CEE) {
+ localRet = msgGetCEEPropJSON(pMsg, pTpe->data.field.propName, &jsonf);
+ if(localRet == RS_RET_OK) {
+ json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
+ } else {
+ DBGPRINTF("tplToJSON: error %d looking up property\n",
+ localRet);
+#if 0 /* TODO: as it looks, there currently is no way to define Null field values in json-c...
+ we need to think how we will handle that.
+ */
+ if(pTpe->data.field.options.bMandatory) {
+ jsonf = json_object_new(json_type_null); //json_object_new_null();
+ json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
+ }
+#endif
+ }
+ } else {
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
+ pTpe->data.field.propName, &propLen,
+ &bMustBeFreed);
+ if(pTpe->data.field.options.bMandatory || propLen > 0) {
+ jsonf = json_object_new_string_len((char*)pVal, propLen);
+ json_object_object_add(json, (char*)pTpe->fieldName, jsonf);
+ }
+ if(bMustBeFreed) { /* json-c makes its own private copy! */
+ free(pVal);
+ }
}
}
}
@@ -1475,8 +1496,8 @@ createPropertyTpe(struct template *pTpl, struct cnfobj *o)
CHKiRet(propNameToID(name, &pTpe->data.field.propid));
if(pTpe->data.field.propid == PROP_CEE) {
/* in CEE case, we need to preserve the actual property name */
- pTpe->data.field.propName = es_newStrFromCStr((char*)cstrGetSzStrNoNULL(name)+2,
- cstrLen(name)-2);
+ pTpe->data.field.propName = es_newStrFromCStr((char*)cstrGetSzStrNoNULL(name)+1,
+ cstrLen(name)-1);
}
pTpe->data.field.options.bDropLastLF = droplastlf;
pTpe->data.field.options.bSPIffNo1stSP = spifno1stsp;