Imported Upstream version 2.7
[ossec-hids.git] / src / os_regex / os_regex.c
1 /*   $OSSEC, os_regex.c, v0.4, 2006/01/02, Daniel B. Cid$   */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
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
9  * Foundation
10  */
11
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16
17 #include "os_regex.h"
18
19
20 /** int OS_Regex(char *pattern, char *str) v0.4
21  *
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.
26  */
27 int OS_Regex(char *pattern, char *str)
28 {
29     int r_code = 0;
30     OSRegex reg;
31
32     /* If the compilation failed, we don't need to free anything */
33     if(OSRegex_Compile(pattern, &reg, 0))
34     {
35         if(OSRegex_Execute(str, &reg))
36         {
37             r_code = 1;
38         }
39
40         OSRegex_FreePattern(&reg);
41     }
42
43     return(r_code);
44 }
45
46
47 /* EOF */