X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_regex%2Fos_regex_match.c;h=5097b31df8d3349809d2f836df58d6cf77fd1418;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=dfc24af207a12d3f0e5934fb99294efd87aaffd5;hpb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;p=ossec-hids.git diff --git a/src/os_regex/os_regex_match.c b/src/os_regex/os_regex_match.c old mode 100755 new mode 100644 index dfc24af..5097b31 --- a/src/os_regex/os_regex_match.c +++ b/src/os_regex/os_regex_match.c @@ -1,5 +1,3 @@ -/* $OSSEC, os_regex_match.c, v0.3, 2005/06/09, Daniel B. Cid$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -9,50 +7,44 @@ * Foundation */ - #include #include #include #include + +#include "os_regex.h" #include "os_regex_internal.h" /* Algorithm: - * Go as faster as you can :) + * Go as fast as you can :) * * Supports: * '|' to separate multiple OR patterns - * '^' to match the begining of a string + * '^' to match the beginning of a string */ +/* Prototypes */ +static int _InternalMatch(const char *pattern, const char *str, size_t count) __attribute__((nonnull)); -/** Prototypes **/ -int _InternalMatch(char *pattern, char *str,int count); - -/* OS_WordMatch v0.3: - * Searches for pattern in the string - */ -int OS_WordMatch(char *pattern, char *str) +/* Search for pattern in the string */ +int OS_WordMatch(const char *pattern, const char *str) { - int count = 0; + size_t count = 0; - if(*pattern == '\0') - return(FALSE); + if (*pattern == '\0') { + return (FALSE); + } - do - { - if(pattern[count] == '|') - { + do { + if (pattern[count] == '|') { /* If we match '|' , search with * we have so far. */ - if(_InternalMatch(pattern, str, count)) - { - return(TRUE); - } - else - { - pattern += count+1; + if (_InternalMatch(pattern, str, count)) { + return (TRUE); + } else { + pattern += count + 1; count = 0; continue; } @@ -60,76 +52,70 @@ int OS_WordMatch(char *pattern, char *str) count++; - }while(pattern[count] != '\0'); + } while (pattern[count] != '\0'); /* Last check until end of string */ - return(_InternalMatch(pattern, str,count)); + return (_InternalMatch(pattern, str, count)); } -/* Internal match function */ -int _InternalMatch(char *pattern, char *str, int pattern_size) +static int _InternalMatch(const char *pattern, const char *str, size_t pattern_size) { - uchar *pt = (uchar *)pattern; - uchar *st = (uchar *)str; - - uchar last_char = pattern[pattern_size]; - - - /* Return true for some odd expressions */ - if(*pattern == '\0') - return(TRUE); + const uchar *pt = (const uchar *)pattern; + const uchar *st = (const uchar *)str; + const uchar last_char = (const uchar) pattern[pattern_size]; + if (*pattern == '\0') { + return (TRUE); + } /* If '^' specified, just do a strncasecmp */ - else if(*pattern == '^') - { + else if (*pattern == '^') { pattern++; pattern_size --; - /* Compare two string */ - if(strncasecmp(pattern,str,pattern_size) == 0) - return(TRUE); - return(FALSE); + /* Compare two strings */ + if (strncasecmp(pattern, str, pattern_size) == 0) { + return (TRUE); + } + return (FALSE); } - /* Null line */ - else if(*st == '\0') - return(FALSE); - + else if (*st == '\0') { + return (FALSE); + } /* Look to match the first pattern */ - do - { + do { /* Match */ - if(charmap[*st] == charmap[*pt]) - { - str = (char *)st++; + if (charmap[*st] == charmap[*pt]) { + str = (const char *)st++; pt++; - while(*pt != last_char) - { - if(*st == '\0') - return(FALSE); + while (*pt != last_char) { + if (*st == '\0') { + return (FALSE); + } - else if(charmap[*pt] != charmap[*st]) + else if (charmap[*pt] != charmap[*st]) { goto error; + } - st++;pt++; + st++; + pt++; } /* Return here if pt == last_char */ - return(TRUE); - - error: - st = (uchar *)str; - pt = (uchar *)pattern; + return (TRUE); +error: + st = (const uchar *)str; + pt = (const uchar *)pattern; } st++; - }while(*st != '\0'); + } while (*st != '\0'); - return(FALSE); + return (FALSE); } -/* EOF */ +