1 /* $OSSEC, os_regex_match.c, v0.3, 2005/06/09, Daniel B. Cid$ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
17 #include "os_regex_internal.h"
20 * Go as faster as you can :)
23 * '|' to separate multiple OR patterns
24 * '^' to match the begining of a string
29 int _InternalMatch(char *pattern, char *str,int count);
33 * Searches for pattern in the string
35 int OS_WordMatch(char *pattern, char *str)
44 if(pattern[count] == '|')
46 /* If we match '|' , search with
49 if(_InternalMatch(pattern, str, count))
63 }while(pattern[count] != '\0');
65 /* Last check until end of string */
66 return(_InternalMatch(pattern, str,count));
69 /* Internal match function */
70 int _InternalMatch(char *pattern, char *str, int pattern_size)
72 uchar *pt = (uchar *)pattern;
73 uchar *st = (uchar *)str;
75 uchar last_char = pattern[pattern_size];
78 /* Return true for some odd expressions */
83 /* If '^' specified, just do a strncasecmp */
84 else if(*pattern == '^')
89 /* Compare two string */
90 if(strncasecmp(pattern,str,pattern_size) == 0)
101 /* Look to match the first pattern */
105 if(charmap[*st] == charmap[*pt])
110 while(*pt != last_char)
115 else if(charmap[*pt] != charmap[*st])
121 /* Return here if pt == last_char */
126 pt = (uchar *)pattern;