1 /* $OSSEC, os_regex.c, v0.4, 2006/01/02, 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
20 /** int OS_Match2(char *pattern, char *str) v0.4
22 * This function is a wrapper around the compile/execute
23 * functions. It should only be used when the pattern is
24 * only going to be used once.
25 * Returns 1 on success or 0 on failure.
27 int OS_Match2(char *pattern, char *str)
32 /* If the compilation failed, we don't need to free anything */
33 if(OSMatch_Compile(pattern, ®, 0))
35 if(OSMatch_Execute(str,strlen(str), ®))
40 OSMatch_FreePattern(®);
48 /** int OS_Match3(char *pattern, char *str) v2.6
50 * This function is used
51 * to match any values from a delimited string
52 * e.g. match pattern "abc" from string "123,abc,xyz"
54 int OS_Match3(char *pattern, char *str, char *delimiter)
61 /* debug2("1. str [%s], dupstr [%s], token[%s], delim [%s]", str, dupstr, token, delimiter); */
63 os_strdup(str, dupstr);
64 /* debug2("2. str [%s], dupstr [%s], token[%s], delim [%s]", str, dupstr, token, delimiter); */
66 token = strtok_r(dupstr, delimiter, &saveptr);
67 /* debug2("3. str [%s], dupstr [%s], token[%s], delim [%s]", str, dupstr, token, delimiter); */
71 debug2("Matching [%s] with [%s]", pattern, token);
72 if (!strcmp(pattern, token))
78 token = strtok_r(NULL, delimiter, &saveptr);
81 /* debug2("4. str [%s], dupstr [%s], token[%s], delim [%s]", str, dupstr, token, delimiter); */