PageRenderTime 42ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-1-1-4/noffle/src/filter.h

#
C++ Header | 127 lines | 79 code | 25 blank | 23 comment | 0 complexity | a9027183a09618d07b7e33daadf62c97 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. filter.h
  3. Article filtering.
  4. $Id: filter.h 381 2002-05-14 14:25:45Z mirkol $
  5. */
  6. #ifndef FILTER_H
  7. #define FILTER_H
  8. #include <sys/types.h>
  9. #include <regex.h>
  10. #include "fetchlist.h"
  11. #include "over.h"
  12. /* The possible actions in a filter. */
  13. typedef enum {
  14. FILTER_FULL,
  15. FILTER_XOVER,
  16. FILTER_THREAD,
  17. FILTER_DISCARD,
  18. FILTER_DEFAULT
  19. } FilterAction;
  20. /* Representation of a rule. */
  21. typedef enum {
  22. RULE_NEWSGROUP, /* Wildmat data */
  23. RULE_SUBJECT, /* Regex data */
  24. RULE_REFERENCE,
  25. RULE_FROM,
  26. RULE_MSGID,
  27. RULE_BYTES_LT, RULE_BYTES_EQ, RULE_BYTES_GT, /* Number data */
  28. RULE_LINES_LT, RULE_LINES_EQ, RULE_LINES_GT,
  29. RULE_NOREFS_LT, RULE_NOREFS_EQ, RULE_NOREFS_GT,
  30. RULE_XPOSTS_LT, RULE_XPOSTS_EQ, RULE_XPOSTS_GT,
  31. RULE_DATE_LT, RULE_DATE_EQ, RULE_DATE_GT,
  32. RULE_POST_STATUS /* 'y','n','m' */
  33. } FilterRuleType;
  34. /* Data for Date: header parsing. */
  35. #define RULE_DATE_EQ_PRECISION ((time_t) (24*60*60)) /* +/- 24 hours precision */
  36. typedef enum {
  37. NOW, /* beginning of fetch */
  38. LASTUPDATE, /* of last fetch */
  39. INVALID, /* invalid dates, only RULE_DATE_EQ */
  40. FIXED /* fixed time */
  41. } FilterRuleDateEnumType;
  42. typedef struct {
  43. time_t calctime; /* calctime = vartime + timeoffset */
  44. time_t timeoffset;
  45. FilterRuleDateEnumType vartime;
  46. } FilterRuleDateType;
  47. typedef union {
  48. regex_t regex;
  49. unsigned long amount;
  50. char *grp;
  51. char postAllow; /* 'y','n','m' */
  52. FilterRuleDateType reftime;
  53. } FilterRuleData;
  54. typedef struct {
  55. FilterRuleType type;
  56. FilterRuleData data;
  57. } FilterRule;
  58. /* A single filter is a collection of rules with an action. */
  59. typedef struct {
  60. int nRules;
  61. int maxRules;
  62. FilterRule *rules;
  63. FilterAction action;
  64. } Filter;
  65. /* Add a filter to the list of filters. */
  66. void
  67. Flt_addFilter( const Filter *f );
  68. /*
  69. * Called by client.c once before processing a batch of overviews
  70. * with Flt_checkFilters().
  71. */
  72. void
  73. Flt_init( const char *filename );
  74. /*
  75. * Run the rules over the supplied overview. If a specific rule fires,
  76. * returns its action. If no rule fires, return the default read mode.
  77. */
  78. FilterAction
  79. Flt_checkFilters( const char *thisGrp, const char *newsgroups,
  80. const Over *ov, FetchMode mode );
  81. /*
  82. * Build and access a filter
  83. */
  84. Filter *
  85. new_Filter( void );
  86. void
  87. del_Filter( Filter *f );
  88. FilterAction
  89. Flt_action( const Filter *f );
  90. int
  91. Flt_nRules( const Filter *f );
  92. Bool
  93. Flt_getNewsgroups( void );
  94. FilterRule
  95. Flt_rule( const Filter *f, int ruleNo );
  96. void
  97. Flt_setAction( Filter *f, FilterAction action );
  98. void
  99. Flt_addRule( Filter *f, FilterRule rule );
  100. #endif /* FILTER_H */