1#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/** 32 * 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/** 58 * strfilter__compare - compare given string and a string filter 59 * @filter: String filter 60 * @str: target string 61 * 62 * Compare @str and @filter. Return true if the str match the rule 63 */ 64bool strfilter__compare(struct strfilter *filter, const char *str); 65 66/** 67 * strfilter__delete - delete a string filter 68 * @filter: String filter to delete 69 * 70 * Delete @filter. 71 */ 72void strfilter__delete(struct strfilter *filter); 73 74/** 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 83#endif 84