strfilter.h 2.5 KB

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