new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_regex / os_match.c
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All right reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13
14 #include "os_regex.h"
15
16
17 /*  This function is a wrapper around the compile/execute
18  *  functions. It should only be used when the pattern is
19  *  only going to be used once.
20  *  Returns 1 on success or 0 on failure.
21  */
22 int OS_Match2(const char *pattern, const char *str)
23 {
24     int r_code = 0;
25     OSMatch reg;
26
27     /* If the compilation failed, we don't need to free anything */
28     if (OSMatch_Compile(pattern, &reg, 0)) {
29         if (OSMatch_Execute(str, strlen(str), &reg)) {
30             r_code = 1;
31         }
32
33         OSMatch_FreePattern(&reg);
34     }
35
36     return (r_code);
37 }
38