1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 **/
19 #ifndef ZABBIX_ZBXREGEXP_H
20 #define ZABBIX_ZBXREGEXP_H
21 
22 #include "zbxalgo.h"
23 
24 #define ZBX_REGEXP_NO_MATCH	0
25 #define ZBX_REGEXP_MATCH	1
26 
27 typedef struct zbx_regexp zbx_regexp_t;
28 
29 typedef struct
30 {
31 	char		*name;
32 	char		*expression;
33 	int		expression_type;
34 	char		exp_delimiter;
35 	unsigned char	case_sensitive;
36 }
37 zbx_expression_t;
38 
39 /* regular expressions */
40 int	zbx_regexp_compile(const char *pattern, zbx_regexp_t **regexp, const char **err_msg_static);
41 int	zbx_regexp_compile_ext(const char *pattern, zbx_regexp_t **regexp, int flags, const char **err_msg_static);
42 void	zbx_regexp_free(zbx_regexp_t *regexp);
43 int	zbx_regexp_match_precompiled(const char *string, const zbx_regexp_t *regexp);
44 char	*zbx_regexp_match(const char *string, const char *pattern, int *len);
45 int	zbx_regexp_sub(const char *string, const char *pattern, const char *output_template, char **out);
46 int	zbx_mregexp_sub(const char *string, const char *pattern, const char *output_template, char **out);
47 int	zbx_iregexp_sub(const char *string, const char *pattern, const char *output_template, char **out);
48 int	zbx_mregexp_sub_precompiled(const char *string, const zbx_regexp_t *regexp, const char *output_template,
49 		size_t limit, char **out);
50 
51 void	zbx_regexp_clean_expressions(zbx_vector_ptr_t *expressions);
52 
53 void	add_regexp_ex(zbx_vector_ptr_t *regexps, const char *name, const char *expression, int expression_type,
54 		char exp_delimiter, int case_sensitive);
55 int	regexp_match_ex(const zbx_vector_ptr_t *regexps, const char *string, const char *pattern, int case_sensitive);
56 int	regexp_sub_ex(const zbx_vector_ptr_t *regexps, const char *string, const char *pattern, int case_sensitive,
57 		const char *output_template, char **output);
58 int	zbx_global_regexp_exists(const char *name, const zbx_vector_ptr_t *regexps);
59 void	zbx_regexp_escape(char **string);
60 
61 /* wildcards */
62 void	zbx_wildcard_minimize(char *str);
63 int	zbx_wildcard_match(const char *value, const char *wildcard);
64 
65 #endif /* ZABBIX_ZBXREGEXP_H */
66