From 2f229a8b958ca1091e57dfd04212f030a1f16fc0 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 23 Apr 2007 21:22:18 +0000 Subject: [PATCH] ebl tweak bregex.c to get REG_ICASE working with regcomp and re_search git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4610 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/breg.c | 10 ---------- bacula/src/lib/breg.h | 1 - bacula/src/lib/bregex.c | 35 +++++++++++++++++++++++++++++++---- bacula/src/lib/bregex.h | 2 +- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/bacula/src/lib/breg.c b/bacula/src/lib/breg.c index 6c9a4ef560..8c53e6a93b 100644 --- a/bacula/src/lib/breg.c +++ b/bacula/src/lib/breg.c @@ -245,17 +245,7 @@ char *BREGEXP::replace(const char *fname) { success = false; /* use this.success to known if it's ok */ int flen = strlen(fname); -#ifndef HAVE_REGEX_H - int i; - check_pool_memory_size(lcase, flen); - for(i=0; fname[i] ; i++) { - lcase[i] = tolower(fname[i]); - } - lcase[i] = '\0'; - int rc = re_search(&preg, (BREGEX_CAST char*) lcase, flen, 0, flen, ®s); -#else int rc = re_search(&preg, (BREGEX_CAST char*) fname, flen, 0, flen, ®s); -#endif if (rc < 0) { Dmsg0(500, "bregexp: regex mismatch\n"); diff --git a/bacula/src/lib/breg.h b/bacula/src/lib/breg.h index fa639f17a8..9c1e50a8c7 100644 --- a/bacula/src/lib/breg.h +++ b/bacula/src/lib/breg.h @@ -68,7 +68,6 @@ public: /* private */ POOLMEM *expr; /* search epression */ POOLMEM *subst; /* substitution */ - POOLMEM *lcase; /* fname in lower case when using bregexp.c */ regex_t preg; /* regex_t result of regcomp() */ struct re_registers regs; /* contains match */ char *eor; /* end of regexp in expr */ diff --git a/bacula/src/lib/bregex.c b/bacula/src/lib/bregex.c index 9ded1b67be..939c84cdc2 100644 --- a/bacula/src/lib/bregex.c +++ b/bacula/src/lib/bregex.c @@ -30,6 +30,9 @@ * * This file modified to work with Bacula and C++ by * Kern Sibbald, April 2006 + * + * This file modified to work with REG_ICASE and Bacula by + * Eric Bollengier April 2007 */ /* Bacula® - The Network Backup Solution @@ -1461,9 +1464,15 @@ int regcomp(regex_t * bufp, const char *regex, int cflags) memset(bufp, 0, sizeof(regex_t)); bufp->cflags = cflags; if (bufp->cflags & REG_ICASE) { - // ICI passer regex en lcase + char *p, *lcase = bstrdup(regex); + for( p = lcase; *p ; p++) { + *p = tolower(*p); + } + re_compile_pattern(bufp, (unsigned char *)lcase); + bfree(lcase); + } else { + re_compile_pattern(bufp, (unsigned char *)regex); } - re_compile_pattern(bufp, (unsigned char *)regex); if (got_error) { return -1; } @@ -1475,7 +1484,6 @@ int regexec(regex_t * preg, const char *string, size_t nmatch, { int stat; int len = strlen(string); - // ICI passer string en lcase struct re_registers regs; stat = re_search(preg, (unsigned char *)string, len, 0, len, ®s); /* stat is the start position in the string base 0 where @@ -1492,6 +1500,10 @@ size_t regerror(int errcode, regex_t * preg, char *errbuf, size_t errbuf_size) void regfree(regex_t * preg) { + if (preg->lcase) { + free_pool_memory(preg->lcase); + preg->lcase = NULL; + } } int re_match(regex_t * bufp, unsigned char *string, int size, int pos, @@ -1890,7 +1902,7 @@ int re_match(regex_t * bufp, unsigned char *string, int size, int pos, #undef PREFETCH #undef NEXTCHAR -int re_search(regex_t * bufp, unsigned char *string, int size, int pos, +int re_search(regex_t * bufp, unsigned char *str, int size, int pos, int range, regexp_registers_t regs) { unsigned char *fastmap; @@ -1901,6 +1913,21 @@ int re_search(regex_t * bufp, unsigned char *string, int size, int pos, int dir; int ret; unsigned char anchor; + unsigned char *string = str; + + if (bufp->cflags & REG_ICASE) { /* we must use string in lowercase */ + int len = strlen((const char *)str); + if (!bufp->lcase) { + bufp->lcase = get_pool_memory(PM_FNAME); + } + check_pool_memory_size(bufp->lcase, len+1); + unsigned char *dst = (unsigned char *)bufp->lcase; + while (*string) { + *dst++ = tolower(*string++); + } + *dst = '\0'; + string = (unsigned char *)bufp->lcase; + } // assert(size >= 0 && pos >= 0); // assert(pos + range >= 0 && pos + range <= size); /* Bugfix by ylo */ diff --git a/bacula/src/lib/bregex.h b/bacula/src/lib/bregex.h index 8c7778d1c3..aaef2a8a68 100644 --- a/bacula/src/lib/bregex.h +++ b/bacula/src/lib/bregex.h @@ -107,7 +107,7 @@ struct regex_t unsigned char anchor; /* anchor: 0=none 1=begline 2=begbuf */ char *errmsg; int cflags; /* compilation flags */ - POOLMEM *str_lcase; /* use to store expression in lcase */ + POOLMEM *lcase; /* used by REG_ICASE */ }; -- 2.39.5