~arges/ubuntu/quantal/rsyslog/fix-lp1059592

« back to all changes in this revision

Viewing changes to template.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-15 21:56:23 UTC
  • mto: (3.2.4 squeeze) (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090215215623-xsycf628eo3kguc0
Tags: upstream-3.20.4
ImportĀ upstreamĀ versionĀ 3.20.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "syslogd-types.h"
34
34
#include "template.h"
35
35
#include "msg.h"
36
 
#include "syslogd.h"
 
36
#include "dirty.h"
37
37
#include "obj.h"
38
38
#include "errmsg.h"
39
39
 
440
440
                        pTpe->data.field.eDateFormat = tplFmtRFC3164Date;
441
441
                 } else if(!strcmp((char*)Buf, "date-rfc3339")) {
442
442
                        pTpe->data.field.eDateFormat = tplFmtRFC3339Date;
 
443
                 } else if(!strcmp((char*)Buf, "date-subseconds")) {
 
444
                        pTpe->data.field.eDateFormat = tplFmtSecFrac;
443
445
                 } else if(!strcmp((char*)Buf, "lowercase")) {
444
446
                        pTpe->data.field.eCaseConv = tplCaseConvLower;
445
447
                 } else if(!strcmp((char*)Buf, "uppercase")) {
516
518
        if(*p == ':') {
517
519
                ++p; /* eat ':' */
518
520
#ifdef FEATURE_REGEXP
519
 
                if (*p == 'R') {
 
521
                if(*p == 'R') {
520
522
                        /* APR: R found! regex alarm ! :) */
521
523
                        ++p;    /* eat ':' */
522
524
 
523
 
                        if (*p != ':') {
 
525
                        /* first come the regex type */
 
526
                        if(*p == ',') {
 
527
                                ++p; /* eat ',' */
 
528
                                if(p[0] == 'B' && p[1] == 'R' && p[2] == 'E' && (p[3] == ',' || p[3] == ':')) {
 
529
                                        pTpe->data.field.typeRegex = TPL_REGEX_BRE;
 
530
                                        p += 3; /* eat indicator sequence */
 
531
                                } else if(p[0] == 'E' && p[1] == 'R' && p[2] == 'E' && (p[3] == ',' || p[3] == ':')) {
 
532
                                        pTpe->data.field.typeRegex = TPL_REGEX_ERE;
 
533
                                        p += 3; /* eat indicator sequence */
 
534
                                } else {
 
535
                                        errmsg.LogError(0, NO_ERRCODE, "error: invalid regular expression type, rest of line %s",
 
536
                                               (char*) p);
 
537
                                }
 
538
                        }
 
539
 
 
540
                        /* now check for submatch ID */
 
541
                        pTpe->data.field.iSubMatchToUse = 0;
 
542
                        if(*p == ',') {
 
543
                                /* in this case a number follows, which indicates which match
 
544
                                 * shall be used. This must be a single digit.
 
545
                                 */
 
546
                                ++p; /* eat ',' */
 
547
                                if(isdigit((int) *p)) {
 
548
                                        pTpe->data.field.iSubMatchToUse = *p - '0';
 
549
                                        ++p; /* eat digit */
 
550
                                }
 
551
                        }
 
552
 
 
553
                        /* now pull what to do if we do not find a match */
 
554
                        if(*p == ',') {
 
555
                                ++p; /* eat ',' */
 
556
                                if(p[0] == 'D' && p[1] == 'F' && p[2] == 'L' && p[3] == 'T'
 
557
                                   && (p[4] == ',' || p[4] == ':')) {
 
558
                                        pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_DFLTSTR;
 
559
                                        p += 4; /* eat indicator sequence */
 
560
                                } else if(p[0] == 'B' && p[1] == 'L' && p[2] == 'A' && p[3] == 'N' && p[4] == 'K'
 
561
                                          && (p[5] == ',' || p[5] == ':')) {
 
562
                                        pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_BLANK;
 
563
                                        p += 5; /* eat indicator sequence */
 
564
                                } else if(p[0] == 'F' && p[1] == 'I' && p[2] == 'E' && p[3] == 'L' && p[4] == 'D'
 
565
                                          && (p[5] == ',' || p[5] == ':')) {
 
566
                                        pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_WHOLE_FIELD;
 
567
                                        p += 5; /* eat indicator sequence */
 
568
                                } else if(p[0] == 'Z' && p[1] == 'E' && p[2] == 'R' && p[3] == 'O'
 
569
                                          && (p[4] == ',' || p[4] == ':')) {
 
570
                                        pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_ZERO;
 
571
                                        p += 4; /* eat indicator sequence */
 
572
                                } else if(p[0] == ',') { /* empty, use default */
 
573
                                        pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_DFLTSTR;
 
574
                                         /* do NOT eat indicator sequence, as this was already eaten - the 
 
575
                                          * comma itself is already part of the next field.
 
576
                                          */
 
577
                                } else {
 
578
                                        errmsg.LogError(0, NO_ERRCODE, "error: invalid regular expression type, rest of line %s",
 
579
                                               (char*) p);
 
580
                                }
 
581
                        }
 
582
 
 
583
                        /* now check for match ID */
 
584
                        pTpe->data.field.iMatchToUse = 0;
 
585
                        if(*p == ',') {
 
586
                                /* in this case a number follows, which indicates which match
 
587
                                 * shall be used. This must be a single digit.
 
588
                                 */
 
589
                                ++p; /* eat ',' */
 
590
                                if(isdigit((int) *p)) {
 
591
                                        pTpe->data.field.iMatchToUse = *p - '0';
 
592
                                        ++p; /* eat digit */
 
593
                                }
 
594
                        }
 
595
 
 
596
                        if(*p != ':') {
524
597
                                /* There is something more than an R , this is invalid ! */
525
598
                                /* Complain on extra characters */
526
 
                                errmsg.LogError(NO_ERRCODE, "error: invalid character in frompos after \"R\", property: '%%%s'",
 
599
                                errmsg.LogError(0, NO_ERRCODE, "error: invalid character in frompos after \"R\", property: '%%%s'",
527
600
                                    (char*) *pp);
528
601
                        } else {
529
602
                                pTpe->data.field.has_regex = 1;
 
603
                                dbgprintf("we have a regexp and use match #%d, submatch #%d\n",
 
604
                                          pTpe->data.field.iMatchToUse, pTpe->data.field.iSubMatchToUse);
530
605
                        }
531
606
                } else {
532
607
                        /* now we fall through the "regular" FromPos code */
547
622
                                        pTpe->data.field.has_fields = 1;
548
623
                                        if(!isdigit((int)*p)) {
549
624
                                                /* complain and use default */
550
 
                                                errmsg.LogError(NO_ERRCODE, "error: invalid character in frompos after \"F,\", property: '%%%s' - using 9 (HT) as field delimiter",
 
625
                                                errmsg.LogError(0, NO_ERRCODE, "error: invalid character in frompos after \"F,\", property: '%%%s' - using 9 (HT) as field delimiter",
551
626
                                                    (char*) *pp);
552
627
                                                pTpe->data.field.field_delim = 9;
553
628
                                        } else {
555
630
                                                while(isdigit((int)*p))
556
631
                                                        iNum = iNum * 10 + *p++ - '0';
557
632
                                                if(iNum < 0 || iNum > 255) {
558
 
                                                        errmsg.LogError(NO_ERRCODE, "error: non-USASCII delimiter character value %d in template - using 9 (HT) as substitute", iNum);
 
633
                                                        errmsg.LogError(0, NO_ERRCODE, "error: non-USASCII delimiter character value %d in template - using 9 (HT) as substitute", iNum);
559
634
                                                        pTpe->data.field.field_delim = 9;
560
635
                                                  } else {
561
636
                                                        pTpe->data.field.field_delim = iNum;
565
640
                                        /* invalid character after F, so we need to reject
566
641
                                         * this.
567
642
                                         */
568
 
                                        errmsg.LogError(NO_ERRCODE, "error: invalid character in frompos after \"F\", property: '%%%s'",
 
643
                                        errmsg.LogError(0, NO_ERRCODE, "error: invalid character in frompos after \"F\", property: '%%%s'",
569
644
                                            (char*) *pp);
570
645
                                }
571
646
                        } else {
622
697
                                /* Now i compile the regex */
623
698
                                /* Remember that the re is an attribute of the Template entry */
624
699
                                if((iRetLocal = objUse(regexp, LM_REGEXP_FILENAME)) == RS_RET_OK) {
625
 
dbgprintf("compile data.field.re ptr: %p (pTpe %p)\n", (&(pTpe->data.field.re)), pTpe);
626
 
                                        if(regexp.regcomp(&(pTpe->data.field.re), (char*) regex_char, 0) != 0) {
 
700
                                        int iOptions;
 
701
                                        iOptions = (pTpe->data.field.typeRegex == TPL_REGEX_ERE) ? REG_EXTENDED : 0;
 
702
                                        if(regexp.regcomp(&(pTpe->data.field.re), (char*) regex_char, iOptions) != 0) {
627
703
                                                dbgprintf("error: can not compile regex: '%s'\n", regex_char);
628
704
                                                pTpe->data.field.has_regex = 2;
629
705
                                        }
633
709
                                                  iRetLocal);
634
710
                                        if(bFirstRegexpErrmsg) { /* prevent flood of messages, maybe even an endless loop! */
635
711
                                                bFirstRegexpErrmsg = 0;
636
 
                                                errmsg.LogError(NO_ERRCODE, "regexp library could not be loaded (error %d), "
 
712
                                                errmsg.LogError(0, NO_ERRCODE, "regexp library could not be loaded (error %d), "
637
713
                                                                "regexp ignored", iRetLocal);
638
714
                                        }
639
715
                                        pTpe->data.field.has_regex = 2;