brintos

brintos / linux-shallow public Read only

0
0
Text · 2.5 KiB · c05aca9 Raw
85 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2#ifndef __PERF_STRFILTER_H3#define __PERF_STRFILTER_H4/* 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 filter23 * @rules: Filter rule, which is a combination of glob expressions.24 * @err: Pointer which points an error detected on @rules25 *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 NULL28 * 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-or34 * @filter: Original string filter35 * @rules: Filter rule to be appended at left of the root of36 *         @filter by using logical-or.37 * @err: Pointer which points an error detected on @rules38 *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-and47 * @filter: Original string filter48 * @rules: Filter rule to be appended at left of the root of49 *         @filter by using logical-and.50 * @err: Pointer which points an error detected on @rules51 *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 filter60 * @filter: String filter61 * @str: target string62 *63 * Compare @str and @filter. Return true if the str match the rule64 */65bool strfilter__compare(struct strfilter *filter, const char *str);66 67/**68 * strfilter__delete - delete a string filter69 * @filter: String filter to delete70 *71 * Delete @filter.72 */73void strfilter__delete(struct strfilter *filter);74 75/**76 * strfilter__string - Reconstruct a rule string from filter77 * @filter: String filter to reconstruct78 *79 * Reconstruct a rule string from @filter. This will be good for80 * debug messages. Note that returning string must be freed afterward.81 */82char *strfilter__string(struct strfilter *filter);83 84#endif85