new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_regex / os_regex_internal.h
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 #ifndef __OS_INTERNAL_H
11 #define __OS_INTERNAL_H
12
13 /* Prototype for the _OsMatch */
14 int _OS_Match(const char *pattern, const char *str, size_t str_len, size_t size) __attribute__((nonnull));
15 int _os_strncmp(const char *pattern, const char *str, size_t str_len, size_t size) __attribute__((nonnull));
16 int _os_strcmp_last(const char *pattern, const char *str, size_t str_len, size_t size) __attribute__((nonnull));
17 int _os_strcmp(const char *pattern, const char *str, size_t str_len, size_t size) __attribute__((nonnull));
18 int _os_strmatch(const char *pattern, const char *str, size_t str_len, size_t size) __attribute__((nonnull));
19
20 #define BACKSLASH   '\\'
21 #define ENDSTR      '\0'
22 #define ENDLINE     '\n'
23 #define BEGINREGEX  '^'
24 #define ENDREGEX    '$'
25 #define OR          '|'
26 #define AND         '&'
27
28 #define TRUE         1
29 #define FALSE        0
30
31 /* Pattern flags */
32 #define BEGIN_SET   0000200
33 #define END_SET     0000400
34
35 /* uchar */
36 typedef unsigned char uchar;
37
38 /* _IsD Returns 1 if it is a number */
39 #define _IsD(x) ((x >= 48) && (x <= 57))
40
41 /* Is it a character?
42  * a-z or A-Z or 0-9
43  * Returns 1 if true
44  */
45 #define _IsW(x) ((x >= 48 && x <= 57 )|| \
46                  (x >= 65 && x <= 90 )|| \
47                  (x >= 97 && x <= 122))
48
49 /* Is it a ' ' (blank)
50  * Ascii 32
51  * Returns 1 if true
52  */
53 #define _IsS(x) (x == 32)
54
55 /* Check for parenthesis */
56 #define prts(x) (x == '(')
57
58 /* Is it '+' or '*'
59  * Returns 1 on success
60  */
61 #define isPlus(x)    ((x == '+') || (x == '*'))
62
63 /* True char */
64 #define TRUECHAR    1
65
66 /* Is "y" a valid "x"?.
67  * Returns 1 on success
68  */
69 #define Regex(x,y)   (regexmap[x][y] == TRUECHAR)
70 #define Regex2(x,y)   (x == 'd' && y >= 48 && y <= 57)|| \
71                      (x == 's' && y == 32)|| \
72                      ((x == 'p') && \
73                       ((y >= 40 && y <= 46)|| \
74                       (y >= 58 && y <= 63)))|| \
75                      ((x == 'w') && \
76                       ((y == '_')|| \
77                       (y >= 48 && y <= 57)|| \
78                       (y >= 65 && y <= 90)|| \
79                       (y >= 97 && y <= 122)))|| \
80                      (x == '.')|| \
81                      ((x == '\\') && (y == '\\'))|| \
82                      ((x == 'n') && (y == '\n'))|| \
83                      (x == 'S' && y != 32)|| \
84                      (x == 'D' && (y < 48 || y > 57))|| \
85                      (x == 'W' && (y < 48 || y > 122 || \
86                      (y > 57 && y <65)||(y > 90 && y< 97)))
87
88 /* Charmap for case insensitive search */
89 extern const uchar charmap[256];
90
91 /* Regex mapping
92  * 0  = none
93  * 1  = \d
94  * 2  = \w
95  * 3  = \s
96  * 4  = \p
97  * 5  = \(
98  * 6  = \)
99  * 7  = \\
100  * 8  = \D
101  * 9  = \W
102  * 10 = \S
103  * 11 = \.
104  * 12 = \t
105  * 13 = \$
106  * 14 = |
107  * 15 = <
108  */
109 extern const uchar regexmap[][256];
110
111 #endif /* __OS_INTERNAL_H */
112