strfilter.h 2.5 KB

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