summaryrefslogtreecommitdiffstats
path: root/template.c
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2012-08-11 07:30:36 +0200
committerMiloslav Trmač <mitr@redhat.com>2012-08-28 10:26:42 +0200
commit30a43cc865f3d7247ec0356566e57b9252e2e6c1 (patch)
treee76b3d73c2b81c74781c952eb0cb82e8f2288181 /template.c
parent67039f21b40f711b2462b022b8c508af75ef3dcb (diff)
downloadrsyslog-30a43cc865f3d7247ec0356566e57b9252e2e6c1.zip
rsyslog-30a43cc865f3d7247ec0356566e57b9252e2e6c1.tar.gz
rsyslog-30a43cc865f3d7247ec0356566e57b9252e2e6c1.tar.xz
Implement ACT_FIELDS_PASSING, test in mongodb
The mongodb test contains only debug printfs. Example template, inspired by writeMongoDB_msg: $template MongoTemplate,"%hostname::::sys%%timereported::::time%%timegenerated::::time_rcvd%%msg%%syslogfacility-text::::syslog_fac%%syslogseverity-text::::syslog_server%%syslogtag::::syslog_tag%%programname::::procid%%procid::::pid%%$!foo::::foo%%$!abc::::renamed%" Note that JSON escaping is actually undesirable in this mode (should it be silently ignored?), $!all-json doesn't yet work as expected, and all data is stored as strings. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'template.c')
-rw-r--r--template.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/template.c b/template.c
index 768608f..d422f8e 100644
--- a/template.c
+++ b/template.c
@@ -269,6 +269,65 @@ finalize_it:
RETiRet;
}
+/* This functions converts a template into an array of templateField structures.
+ * For further general details, see the very similar funtion
+ * tpltoString().
+ * The caller is repsonsible for destroying that array as well as all of its
+ * elements (but not the fieldName strings).
+ */
+rsRetVal tplToFields(struct template *pTpl, msg_t *pMsg,
+ struct templateField **pFields)
+{
+ DEFiRet;
+ struct templateEntry *pTpe;
+ struct templateField *fields;
+ size_t i, propLen;
+ unsigned short bMustBeFreed;
+ uchar *pVal;
+
+ assert(pTpl != NULL);
+ assert(pMsg != NULL);
+ assert(pFields != NULL);
+
+ /* loop through the template. We obtain one value, create a
+ * private copy (if necessary), add it to the string array
+ * and then on to the next until we have processed everything.
+ */
+
+ /* The zeroization implicitly terminates the output array. */
+ CHKmalloc(fields = calloc(pTpl->tpenElements + 1, sizeof(*fields)));
+
+ i = 0;
+ for(pTpe = pTpl->pEntryRoot; pTpe != NULL; pTpe = pTpe->pNext) {
+ if(pTpe->eEntryType == CONSTANT) {
+ /* Completely ingore this - we don't know a field name
+ to use anyway. */
+ } else if(pTpe->eEntryType == FIELD) {
+ fields[i].fieldName = pTpe->data.field.fieldName;
+ pVal = MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
+ pTpe->data.field.propName, &propLen,
+ &bMustBeFreed);
+ if(bMustBeFreed) { /* if it must be freed, it is our own private copy... */
+ fields[i].value = pVal; /* ... so we can use it! */
+ } else {
+ CHKmalloc(fields[i].value = (uchar*)strdup((char*) pVal));
+ }
+ i++;
+ }
+ }
+
+finalize_it:
+ if(iRet != RS_RET_OK && fields != NULL) {
+ for(i = 0; fields[i].fieldName != NULL; i++)
+ free(fields[i].value);
+ free(fields);
+ fields = NULL;
+ }
+ *pFields = fields;
+
+ RETiRet;
+}
+
/* Helper to doEscape. This is called if doEscape
* runs out of memory allocating the escaped string.