strfilter.h (2591B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __PERF_STRFILTER_H 3#define __PERF_STRFILTER_H 4/* General purpose glob matching filter */ 5 6#include <linux/list.h> 7#include <stdbool.h> 8 9/* A node of string filter */ 10struct strfilter_node { 11 struct strfilter_node *l; /* Tree left branch (for &,|) */ 12 struct strfilter_node *r; /* Tree right branch (for !,&,|) */ 13 const char *p; /* Operator or rule */ 14}; 15 16/* String filter */ 17struct strfilter { 18 struct strfilter_node *root; 19}; 20 21/** 22 * strfilter__new - Create a new string filter 23 * @rules: Filter rule, which is a combination of glob expressions. 24 * @err: Pointer which points an error detected on @rules 25 * 26 * Parse @rules and return new strfilter. Return NULL if an error detected. 27 * In that case, *@err will indicate where it is detected, and *@err is NULL 28 * if a memory allocation is failed. 29 */ 30struct strfilter *strfilter__new(const char *rules, const char **err); 31 32/** 33 * strfilter__or - Append an additional rule by logical-or 34 * @filter: Original string filter 35 * @rules: Filter rule to be appended at left of the root of 36 * @filter by using logical-or. 37 * @err: Pointer which points an error detected on @rules 38 * 39 * Parse @rules and join it to the @filter by using logical-or. 40 * Return 0 if success, or return the error code. 41 */ 42int strfilter__or(struct strfilter *filter, 43 const char *rules, const char **err); 44 45/** 46 * strfilter__add - Append an additional rule by logical-and 47 * @filter: Original string filter 48 * @rules: Filter rule to be appended at left of the root of 49 * @filter by using logical-and. 50 * @err: Pointer which points an error detected on @rules 51 * 52 * Parse @rules and join it to the @filter by using logical-and. 53 * Return 0 if success, or return the error code. 54 */ 55int strfilter__and(struct strfilter *filter, 56 const char *rules, const char **err); 57 58/** 59 * strfilter__compare - compare given string and a string filter 60 * @filter: String filter 61 * @str: target string 62 * 63 * Compare @str and @filter. Return true if the str match the rule 64 */ 65bool strfilter__compare(struct strfilter *filter, const char *str); 66 67/** 68 * strfilter__delete - delete a string filter 69 * @filter: String filter to delete 70 * 71 * Delete @filter. 72 */ 73void strfilter__delete(struct strfilter *filter); 74 75/** 76 * strfilter__string - Reconstruct a rule string from filter 77 * @filter: String filter to reconstruct 78 * 79 * Reconstruct a rule string from @filter. This will be good for 80 * debug messages. Note that returning string must be freed afterward. 81 */ 82char *strfilter__string(struct strfilter *filter); 83 84#endif