blob: cff5eda88728b20e9ebae22d7476ed14f367869c [file] [log] [blame]
Masami Hiramatsu68baa432011-01-20 23:15:30 +09001#ifndef __PERF_STRFILTER_H
2#define __PERF_STRFILTER_H
3/* General purpose glob matching filter */
4
5#include <linux/list.h>
6#include <stdbool.h>
7
8/* A node of string filter */
9struct strfilter_node {
10 struct strfilter_node *l; /* Tree left branche (for &,|) */
11 struct strfilter_node *r; /* Tree right branche (for !,&,|) */
12 const char *p; /* Operator or rule */
13};
14
15/* String filter */
16struct strfilter {
17 struct strfilter_node *root;
18};
19
20/**
21 * strfilter__new - Create a new string filter
22 * @rules: Filter rule, which is a combination of glob expressions.
23 * @err: Pointer which points an error detected on @rules
24 *
25 * Parse @rules and return new strfilter. Return NULL if an error detected.
26 * In that case, *@err will indicate where it is detected, and *@err is NULL
27 * if a memory allocation is failed.
28 */
29struct strfilter *strfilter__new(const char *rules, const char **err);
30
31/**
Masami Hiramatsu4e60a2c2015-04-24 18:47:44 +090032 * strfilter__or - Append an additional rule by logical-or
33 * @filter: Original string filter
34 * @rules: Filter rule to be appended at left of the root of
35 * @filter by using logical-or.
36 * @err: Pointer which points an error detected on @rules
37 *
38 * Parse @rules and join it to the @filter by using logical-or.
39 * Return 0 if success, or return the error code.
40 */
41int strfilter__or(struct strfilter *filter,
42 const char *rules, const char **err);
43
44/**
45 * strfilter__add - Append an additional rule by logical-and
46 * @filter: Original string filter
47 * @rules: Filter rule to be appended at left of the root of
48 * @filter by using logical-and.
49 * @err: Pointer which points an error detected on @rules
50 *
51 * Parse @rules and join it to the @filter by using logical-and.
52 * Return 0 if success, or return the error code.
53 */
54int strfilter__and(struct strfilter *filter,
55 const char *rules, const char **err);
56
57/**
Masami Hiramatsu68baa432011-01-20 23:15:30 +090058 * strfilter__compare - compare given string and a string filter
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030059 * @filter: String filter
Masami Hiramatsu68baa432011-01-20 23:15:30 +090060 * @str: target string
61 *
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030062 * Compare @str and @filter. Return true if the str match the rule
Masami Hiramatsu68baa432011-01-20 23:15:30 +090063 */
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030064bool strfilter__compare(struct strfilter *filter, const char *str);
Masami Hiramatsu68baa432011-01-20 23:15:30 +090065
66/**
67 * strfilter__delete - delete a string filter
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030068 * @filter: String filter to delete
Masami Hiramatsu68baa432011-01-20 23:15:30 +090069 *
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030070 * Delete @filter.
Masami Hiramatsu68baa432011-01-20 23:15:30 +090071 */
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030072void strfilter__delete(struct strfilter *filter);
Masami Hiramatsu68baa432011-01-20 23:15:30 +090073
Masami Hiramatsu3f519722015-04-24 18:47:46 +090074/**
75 * strfilter__string - Reconstruct a rule string from filter
76 * @filter: String filter to reconstruct
77 *
78 * Reconstruct a rule string from @filter. This will be good for
79 * debug messages. Note that returning string must be freed afterward.
80 */
81char *strfilter__string(struct strfilter *filter);
82
Masami Hiramatsu68baa432011-01-20 23:15:30 +090083#endif