summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2005-12-23 11:44:50 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2005-12-23 11:44:50 +0000
commit69d0a13b86476fb476769a9901169af36b4b204b (patch)
tree08a8ae416cdbb94b7c5fa063e6a7c096214ac504
parentcb4ebecb2f29c278af71414a0dc2aa28f39f8072 (diff)
downloadrsyslog-69d0a13b86476fb476769a9901169af36b4b204b.tar.gz
rsyslog-69d0a13b86476fb476769a9901169af36b4b204b.tar.xz
rsyslog-69d0a13b86476fb476769a9901169af36b4b204b.zip
finished field-based property replacer code
-rw-r--r--syslogd.c12
-rw-r--r--syslogd.h2
-rw-r--r--template.c50
3 files changed, 36 insertions, 28 deletions
diff --git a/syslogd.c b/syslogd.c
index b1ca2a2e..2f7b4c07 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -818,9 +818,7 @@ static void wallmsg(register struct filed *f);
static void reapchild();
static const char *cvthname(struct sockaddr_in *f);
static void debug_switch();
-static void logerror(char *type);
static void logerrorInt(char *type, int errCode);
-static void logerrorSz(char *type, char *errMsg);
static rsRetVal cfline(char *line, register struct filed *f);
static int decode(char *name, struct code *codetab);
static void sighup_handler();
@@ -3065,7 +3063,7 @@ static char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe,
*/
iCurrFld = 1;
pFld = pRes;
- while(*pFld && iCurrFld < pTpe->data.field.iFromPos) {
+ while(*pFld && iCurrFld < pTpe->data.field.iToPos) {
/* skip fields until the requested field or end of string is found */
while(*pFld && *pFld != '\t')
++pFld; /* skip to field terminator */
@@ -3074,10 +3072,10 @@ static char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe,
++iCurrFld;
}
}
- dprintf("field requested %d, field found %d\n", pTpe->data.field.iFromPos, iCurrFld);
+ dprintf("field requested %d, field found %d\n", pTpe->data.field.iToPos, iCurrFld);
- if(iCurrFld == pTpe->data.field.iFromPos) {
+ if(iCurrFld == pTpe->data.field.iToPos) {
/* field found, now extract it */
/* first of all, we need to find the end */
pFldEnd = pFld;
@@ -5482,7 +5480,7 @@ static void debug_switch()
* correctly formatted for it (containing a single %s param).
* rgerhards 2005-09-19
*/
-static void logerrorSz(char *type, char *errMsg)
+void logerrorSz(char *type, char *errMsg)
{
char buf[1024];
@@ -5508,7 +5506,7 @@ static void logerrorInt(char *type, int errCode)
/* Print syslogd errors some place.
*/
-static void logerror(char *type)
+void logerror(char *type)
{
char buf[1024];
diff --git a/syslogd.h b/syslogd.h
index 2ce1895f..ed11e76a 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -3,5 +3,7 @@
#define dprintf mydprintf
#endif /* __GLIBC__ */
void dprintf(char *, ...);
+void logerror(char *type);
+void logerrorSz(char *type, char *errMsg);
#include "rsyslog.h"
diff --git a/template.c b/template.c
index c4dafac0..e30856f6 100644
--- a/template.c
+++ b/template.c
@@ -276,10 +276,9 @@ static int do_Parameter(char **pp, struct template *pTpl)
if (*p != ':') {
/* There is something more than an R , this is invalid ! */
/* Complain on extra characters */
- dprintf
- ("error: extra character in frompos, only \"R\" and numbers are allowed: '%s'\n",
- p);
- /* TODO: rger- add/change to logerror? */
+ logerrorSz
+ ("error: invalid character in frompos after \"R\", property: '%%%s'",
+ *pp);
} else {
pTpe->data.field.has_regex = 1;
}
@@ -289,20 +288,30 @@ static int do_Parameter(char **pp, struct template *pTpl)
if(*p == 'F') {
/* we have a field counter, so indicate it in the template */
++p; /* eat 'F' */
- pTpe->data.field.has_fields = 1;
- }
- /* we now fall through, as this is only a modifier, but it is followed
- * by a count as usual. rgerhards, 2005-12-22
- */
- iNum = 0;
- while(isdigit(*p))
- iNum = iNum * 10 + *p++ - '0';
- pTpe->data.field.iFromPos = iNum;
- /* skip to next known good */
- while(*p && *p != '%' && *p != ':') {
- /* TODO: complain on extra characters */
- dprintf("error: extra character in frompos: '%s'\n", p);
- ++p;
+ if (*p != ':') {
+ /* There is something more than an F, this is invalid ! */
+ /* 2005-12-23 rgerhards: later, we will add modifiers, so
+ * extra characters will then be valid. this is the number 1
+ * reason why this code is NOT combined with the "R" case.
+ */
+ logerrorSz
+ ("error: invalid character in frompos after \"F\", property: '%%%s'",
+ *pp);
+ } else {
+ pTpe->data.field.has_fields = 1;
+ }
+ } else {
+ /* we now have a simple offset in frompos (the previously "normal" case) */
+ iNum = 0;
+ while(isdigit(*p))
+ iNum = iNum * 10 + *p++ - '0';
+ pTpe->data.field.iFromPos = iNum;
+ /* skip to next known good */
+ while(*p && *p != '%' && *p != ':') {
+ /* TODO: complain on extra characters */
+ dprintf("error: extra character in frompos: '%s'\n", p);
+ ++p;
+ }
}
#ifdef FEATURE_REGEXP
}
@@ -341,8 +350,7 @@ static int do_Parameter(char **pp, struct template *pTpl)
memcpy(regex_char, p, longitud);
regex_char[longitud] = '\0';
- dprintf("debug: regex detected: '%s'\n",
- regex_char);
+ dprintf("debug: regex detected: '%s'\n", regex_char);
/* Now i compile the regex */
/* Remember that the re is an attribute of the Template entry */
@@ -638,7 +646,7 @@ void tplPrintList(void)
}
if(pTpe->data.field.has_fields == 1) {
dprintf("[substring, field #%d only] ",
- pTpe->data.field.iFromPos);
+ pTpe->data.field.iToPos);
} else if(pTpe->data.field.iFromPos != 0 ||
pTpe->data.field.iToPos != 0) {
dprintf("[substring, from character %d to %d] ",