~ubuntu-branches/ubuntu/lucid/rsyslog/lucid-updates

« back to all changes in this revision

Viewing changes to runtime/stringbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-06-23 12:12:43 UTC
  • mfrom: (1.1.11 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20090623121243-d2fejarzidywnn17
Tags: 4.2.0-1
* New upstream release of the now stable v4 branch.
  - Fix warnings when /etc/rsyslog.d/ is empty. Closes: #530228
* debian/patches/imudp_multiple_udp_sockets.patch
  - Removed, merged upstream.
* debian/rsyslog.default
  - Set default compat mode to '4'.
* debian/rsyslog.logcheck.ignore.server
  - Update logcheck rules files to also ignore rsyslogd and imklog stop
    messages.
* debian/control
  - Bump Standards-Version to 3.8.2. No further changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
694
694
                return -1; /* pCS1 is less then psz */
695
695
}
696
696
 
 
697
 
697
698
/* check if a CStr object matches a regex.
698
699
 * msamia@redhat.com 2007-07-12
699
700
 * @return returns 0 if matched
701
702
 * rgerhards, 2007-07-16: bug is no real bug, because rsyslogd ensures there
702
703
 * never is a \0 *inside* a property string.
703
704
 * Note that the function returns -1 if regexp functionality is not available.
704
 
 * TODO: change calling interface! -- rgerhards, 2008-03-07
 
705
 * rgerhards: 2009-03-04: ERE support added, via parameter iType: 0 - BRE, 1 - ERE
 
706
 * Arnaud Cornet/rgerhards: 2009-04-02: performance improvement by caching compiled regex
 
707
 * If a caller does not need the cached version, it must still provide memory for it
 
708
 * and must call rsCStrRegexDestruct() afterwards.
705
709
 */
706
 
int rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz)
 
710
rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType, void *rc)
707
711
{
708
 
        regex_t preq;
 
712
        regex_t **cache = (regex_t**) rc;
709
713
        int ret;
 
714
        DEFiRet;
710
715
 
711
 
        BEGINfunc
 
716
        assert(pCS1 != NULL);
 
717
        assert(psz != NULL);
 
718
        assert(cache != NULL);
712
719
 
713
720
        if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
714
 
                regexp.regcomp(&preq, (char*) rsCStrGetSzStr(pCS1), 0);
715
 
                ret = regexp.regexec(&preq, (char*) psz, 0, NULL, 0);
716
 
                regexp.regfree(&preq);
 
721
                if (*cache == NULL) {
 
722
                        *cache = calloc(sizeof(regex_t), 1);
 
723
                        regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), (iType == 1 ? REG_EXTENDED : 0) | REG_NOSUB);
 
724
                }
 
725
                ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0);
 
726
                if(ret != 0)
 
727
                        ABORT_FINALIZE(RS_RET_NOT_FOUND);
717
728
        } else {
718
 
                ret = 1; /* simulate "not found" */
719
 
        }
720
 
 
721
 
        ENDfunc
722
 
        return ret;
 
729
                ABORT_FINALIZE(RS_RET_NOT_FOUND);
 
730
        }
 
731
 
 
732
finalize_it:
 
733
        RETiRet;
 
734
}
 
735
 
 
736
 
 
737
/* free a cached compiled regex
 
738
 * Caller must provide a pointer to a buffer that was created by
 
739
 * rsCStrSzStrMatchRegexCache()
 
740
 */
 
741
void rsCStrRegexDestruct(void *rc)
 
742
{
 
743
        regex_t **cache = rc;
 
744
        
 
745
        assert(cache != NULL);
 
746
        assert(*cache != NULL);
 
747
 
 
748
        if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
 
749
                regexp.regfree(*cache);
 
750
                free(*cache);
 
751
                *cache = NULL;
 
752
        }
723
753
}
724
754
 
725
755