summaryrefslogtreecommitdiffstats
path: root/template.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-04-03 12:51:02 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-04-03 12:51:02 +0200
commitec0e2c3e7df6addc02431628daddfeae49b92af7 (patch)
tree09377ca7ce8c0d67b7760f3db7680949ff480bc2 /template.c
parentd747083e54badeeb45f3d46df2916047e60021b4 (diff)
downloadrsyslog-ec0e2c3e7df6addc02431628daddfeae49b92af7.tar.gz
rsyslog-ec0e2c3e7df6addc02431628daddfeae49b92af7.tar.xz
rsyslog-ec0e2c3e7df6addc02431628daddfeae49b92af7.zip
added a new way how output plugins may be passed parameters.
This is more efficient for some outputs. They new can receive fields not only as a single string but rather in an array where each string is seperated.
Diffstat (limited to 'template.c')
-rw-r--r--template.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/template.c b/template.c
index 4f507ff6..4a12aa3b 100644
--- a/template.c
+++ b/template.c
@@ -47,6 +47,8 @@ static struct template *tplRoot = NULL; /* the root of the template list */
static struct template *tplLast = NULL; /* points to the last element of the template list */
static struct template *tplLastStatic = NULL; /* last static element of the template list */
+
+
/* This functions converts a template into a string. It should
* actually be in template.c, but this requires larger re-structuring
* of the code (because all the property-access functions are static
@@ -140,6 +142,60 @@ finalize_it:
RETiRet;
}
+
+/* This functions converts a template into an array of strings.
+ * For further general details, see the very similar funtion
+ * tpltoString().
+ * Instead of a string, an array of string pointers is returned by
+ * thus function. The caller is repsonsible for destroying that array as
+ * well as all of its elements. The array is of fixed size. It's end
+ * is indicated by a NULL pointer.
+ * rgerhards, 2009-04-03
+ */
+rsRetVal tplToArray(struct template *pTpl, msg_t *pMsg, uchar*** ppArr)
+{
+ DEFiRet;
+ struct templateEntry *pTpe;
+ uchar **pArr;
+ int iArr;
+ unsigned short bMustBeFreed;
+ uchar *pVal;
+
+ assert(pTpl != NULL);
+ assert(pMsg != NULL);
+ assert(ppArr != 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.
+ */
+
+ CHKmalloc(pArr = calloc(pTpl->tpenElements + 1, sizeof(uchar*)));
+ iArr = 0;
+
+ pTpe = pTpl->pEntryRoot;
+ while(pTpe != NULL) {
+ if(pTpe->eEntryType == CONSTANT) {
+ CHKmalloc(pArr[iArr] = (uchar*)strdup((char*) pTpe->data.constant.pConstant));
+ } else if(pTpe->eEntryType == FIELD) {
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, NULL, &bMustBeFreed);
+ if(bMustBeFreed) { /* if it must be freed, it is our own private copy... */
+ pArr[iArr] = pVal; /* ... so we can use it! */
+ } else {
+ CHKmalloc(pArr[iArr] = (uchar*)strdup((char*) pVal));
+ }
+ }
+ iArr++;
+ pTpe = pTpe->pNext;
+ }
+
+finalize_it:
+ *ppArr = (iRet == RS_RET_OK) ? pArr : NULL;
+
+ RETiRet;
+}
+
+
/* Helper to doSQLEscape. This is called if doSQLEscape
* runs out of memory allocating the escaped string.
* Then we are in trouble. We can