summaryrefslogtreecommitdiffstats
path: root/template.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2004-11-18 15:29:41 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2004-11-18 15:29:41 +0000
commitfb5606f892184461ba22c030090ec94913e4aeb1 (patch)
tree6f5aeace4b9484d3921f410e8281a569492ec463 /template.c
parent9a7c44921d6d17ae577c854f6c9606d5a1a0189e (diff)
downloadrsyslog-fb5606f892184461ba22c030090ec94913e4aeb1.tar.gz
rsyslog-fb5606f892184461ba22c030090ec94913e4aeb1.tar.xz
rsyslog-fb5606f892184461ba22c030090ec94913e4aeb1.zip
MsgObjNearlyCompleted
Diffstat (limited to 'template.c')
-rw-r--r--template.c100
1 files changed, 90 insertions, 10 deletions
diff --git a/template.c b/template.c
index a2ccfbb4..b3c5853a 100644
--- a/template.c
+++ b/template.c
@@ -40,12 +40,12 @@ struct templateEntry* tpeConstruct(struct template *pTpl)
pTpl->pEntryLast->pNext = pTpe;
pTpl->pEntryLast = pTpe;
}
+ pTpl->tpenElements++;
return(pTpe);
}
-
/* Constructs a template list object. Returns pointer to it
* or NULL (if it fails).
*/
@@ -80,6 +80,7 @@ static int do_Constant(char **pp, struct template *pTpl)
{
register char *p;
sbStrBObj *pStrB;
+ struct templateEntry *pTpe;
assert(pp != NULL);
assert(*pp != NULL);
@@ -91,14 +92,45 @@ static int do_Constant(char **pp, struct template *pTpl)
return 1;
sbStrBSetAllocIncrement(pStrB, 32);
/* TODO: implement escape characters! */
- while(*p && *p != '%') {
- if(*p == '\\')
- if(*++p == '\0')
- --p; /* the best we can do - it's invalid anyhow... */
- sbStrBAppendChar(pStrB, *p++);
+ while(*p && *p != '%' && *p != '\"') {
+ if(*p == '\\') {
+ switch(*++p) {
+ case '\0':
+ /* the best we can do - it's invalid anyhow... */
+ sbStrBAppendChar(pStrB, *p);
+ break;
+ case 'n':
+ sbStrBAppendChar(pStrB, '\n');
+ ++p;
+ break;
+ case '\\':
+ sbStrBAppendChar(pStrB, '\\');
+ ++p;
+ break;
+ case '%':
+ sbStrBAppendChar(pStrB, '%');
+ ++p;
+ break;
+ default:
+ sbStrBAppendChar(pStrB, *p++);
+ break;
+ }
+ }
+ else
+ sbStrBAppendChar(pStrB, *p++);
+ }
+
+ if((pTpe = tpeConstruct(pTpl)) == NULL) {
+ /* TODO: add handler */
+ return 1;
}
+ pTpe->eEntryType = CONSTANT;
+ pTpe->data.constant.pConstant = sbStrBFinish(pStrB);
+ /* we need to call strlen() below because of the escape sequneces.
+ * due to them p -*pp is NOT the rigt size!
+ */
+ pTpe->data.constant.iLenConstant = strlen(pTpe->data.constant.pConstant);
- printf("Constant: '%s'\n", sbStrBFinish(pStrB));
*pp = p;
return 0;
@@ -113,6 +145,7 @@ static int do_Parameter(char **pp, struct template *pTpl)
{
register char *p;
sbStrBObj *pStrB;
+ struct templateEntry *pTpe;
assert(pp != NULL);
assert(*pp != NULL);
@@ -126,7 +159,15 @@ static int do_Parameter(char **pp, struct template *pTpl)
sbStrBAppendChar(pStrB, *p++);
}
if(*p) ++p; /* eat '%' */
- printf("Parameter: '%s'\n", sbStrBFinish(pStrB));
+
+ /* now store param */
+ if((pTpe = tpeConstruct(pTpl)) == NULL) {
+ /* TODO: add handler */
+ dprintf("Could not allocate memory for template parameter!\n");
+ return 1;
+ }
+ pTpe->eEntryType = FIELD;
+ pTpe->data.pPropRepl = sbStrBFinish(pStrB);
*pp = p;
return 0;
@@ -204,10 +245,12 @@ struct template *tplAddLine(char* pName, char** ppRestOfConfLine)
do_Constant(&p, pTpl);
break;
}
+ if(*p == '\"') {/* end of template string? */
+ ++p; /* eat it! */
+ bDone = 1;
+ }
}
-printf("tplAddLine, Name '%s', restOfLine: %s", pTpl->pszName, p);
-
*ppRestOfConfLine = p;
return(pTpl);
}
@@ -236,6 +279,43 @@ struct template *tplFind(char *pName, int iLenName)
return(pTpl);
}
+/* Print the template structure. This is more or less a
+ * debug or test aid, but anyhow I think it's worth it...
+ */
+void tplPrintList(void)
+{
+ struct template *pTpl;
+ struct templateEntry *pTpe;
+
+ pTpl = tplRoot;
+ while(pTpl != NULL) {
+ dprintf("Template: Name='%s'\n", pTpl->pszName == NULL? "NULL" : pTpl->pszName);
+ pTpe = pTpl->pEntryRoot;
+ while(pTpe != NULL) {
+ dprintf("\tEntry: type %d, ", pTpe->eEntryType);
+ switch(pTpe->eEntryType) {
+ case UNDEFINED:
+ dprintf("(UNDEFINED)\n");
+ break;
+ case CONSTANT:
+ dprintf("(CONSTANT), value: '%s'\n",
+ pTpe->data.constant.pConstant);
+ break;
+ case FIELD:
+ dprintf("(FIELD), value: '%s'\n", pTpe->data.pPropRepl);
+ break;
+ }
+ pTpe = pTpe->pNext;
+ }
+ pTpl = pTpl->pNext; /* done, go next */
+ }
+}
+
+int tplGetEntryCount(struct template *pTpl)
+{
+ assert(pTpl != NULL);
+ return(pTpl->tpenElements);
+}
/*
* vi:set ai:
*/