annotate src/filter.c @ 500:614a3177b15c noffle tip

Add mail-from option. Some modern mail systems will try and ensure the sender email is a legitimate address. Which will fail if there isn't such an address.
author Jim Hague <jim.hague@acm.org>
date Wed, 14 Aug 2013 12:04:39 +0100
parents 0a5dc5f69746
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
1 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
2 filter.c
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
3
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
4 Article filtering.
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
5
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
6 $Id: filter.c 628 2004-10-13 21:59:41Z bears $
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
7 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
8
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
9 #if HAVE_CONFIG_H
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
10 #include <config.h>
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
11 #endif
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
12
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
13 #include <ctype.h>
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
14 #include "common.h"
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
15 #include "configfile.h"
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
16 #include "itemlist.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
17 #include "log.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
18 #include "wildmat.h"
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
19 #include "group.h"
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
20 #include "util.h"
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
21 #include "filter.h"
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
22
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
23 struct
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
24 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
25 int nFilters;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
26 int maxFilters;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
27 const Filter **filters;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
28 Bool needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
29 } filter = { 0, 0, NULL, FALSE };
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
30
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
31 static unsigned long
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
32 countGroups( const char *grps )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
33 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
34 unsigned long res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
35
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
36 res = 1;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
37 while ( *grps != '\0' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
38 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
39 if ( *grps == ',' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
40 res++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
41 grps++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
42 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
43
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
44 return res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
45 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
46 static unsigned long
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
47 countRefs( const char *refs )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
48 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
49 unsigned long res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
50 Bool inRef;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
51
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
52 res = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
53 inRef = FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
54
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
55 while ( *refs != '\0' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
56 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
57 if ( inRef )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
58 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
59 if ( *refs == '>' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
60 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
61 inRef = FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
62 res++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
63 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
64 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
65 else if ( *refs == '<' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
66 inRef = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
67 refs++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
68 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
69
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
70 return res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
71 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
72
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
73 /* Check a single rule to see if it passes. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
74 static Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
75 checkRule( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
76 const Over *ov, const FilterRule *r )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
77 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
78 unsigned long ul;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
79 ItemList *grps;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
80 const char *p;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
81 time_t articletime;
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
82 Bool res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
83
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
84 switch( r->type )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
85 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
86 case RULE_NEWSGROUP:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
87 if ( Wld_match( thisGrp, r->data.grp ) )
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
88 {
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
89 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
90 "Newsgroup rule: %s matches current group",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
91 r->data.grp, thisGrp );
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
92 return TRUE;
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
93 }
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
94 if ( newsgroups != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
95 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
96 grps = new_Itl( newsgroups, " ,\t" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
97 for ( p = Itl_first( grps ); p != NULL; p = Itl_next( grps ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
98 if ( Wld_match( p, r->data.grp ) )
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
99 {
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
100 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
101 "Newsgroup rule: %s matched in %s",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
102 r->data.grp, newsgroups );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
103 return TRUE;
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
104 }
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
105 del_Itl( grps );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
106 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
107 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
108
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
109 case RULE_SUBJECT:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
110 res = ( regexec( &r->data.regex, Ov_subj( ov ), 0, NULL, 0 ) == 0 );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
111 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
112 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
113 "Subject rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
114 Ov_subj( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
115 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
116
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
117 case RULE_REFERENCE: /* kill thread by Msg-Id in References: */
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
118 res = ( regexec( &r->data.regex, Ov_ref( ov ), 0, NULL, 0 ) == 0 );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
119 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
120 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
121 "Reference rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
122 Ov_ref( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
123 return res;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
124
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
125 case RULE_FROM:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
126 res = ( regexec( &r->data.regex, Ov_from( ov ), 0, NULL, 0 ) == 0 );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
127 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
128 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
129 "From rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
130 Ov_from( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
131 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
132
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
133 case RULE_BYTES_LT:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
134 res = ( Ov_bytes( ov ) < r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
135 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
136 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
137 "Length rule: bytes %d < %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
138 Ov_bytes( ov ), r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
139 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
140
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
141 case RULE_BYTES_EQ:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
142 res = ( Ov_bytes( ov ) == r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
143 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
144 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
145 "Length rule: bytes %d = %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
146 Ov_bytes( ov ), r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
147 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
148
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
149 case RULE_BYTES_GT:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
150 res = ( Ov_bytes( ov ) > r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
151 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
152 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
153 "Length rule: bytes %d > %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
154 Ov_bytes( ov ), r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
155 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
156
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
157 case RULE_LINES_LT:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
158 res = ( Ov_lines( ov ) < r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
159 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
160 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
161 "Length rule: lines %d < %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
162 Ov_lines( ov ), r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
163 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
164
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
165 case RULE_LINES_EQ:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
166 res = ( Ov_lines( ov ) == r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
167 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
168 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
169 "Length rule: lines %d = %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
170 Ov_lines( ov ), r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
171 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
172
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
173 case RULE_LINES_GT:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
174 res = ( Ov_lines( ov ) > r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
175 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
176 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
177 "Length rule: lines %d > %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
178 Ov_lines( ov ), r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
179 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
180
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
181 case RULE_MSGID:
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
182 res = ( regexec( &r->data.regex, Ov_msgId( ov ), 0, NULL, 0 ) == 0 );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
183 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
184 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
185 "Msg-Id rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
186 Ov_msgId( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
187 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
188
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
189 case RULE_DATE_LT:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
190 /* Utl_parseNewsDate() is quite picky. I'm not entirely happy
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
191 about this, but I won't implement a relaxed date parser. */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
192 articletime = Utl_parseNewsDate( Ov_date( ov ) );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
193 if ( articletime == (time_t) -1 )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
194 return FALSE;
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
195 res = ( articletime < r->data.reftime.calctime );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
196 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
197 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
198 "Date before rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
199 Ov_date( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
200 return res;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
201
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
202 case RULE_DATE_EQ:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
203 articletime = Utl_parseNewsDate( Ov_date( ov ) );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
204 if ( ( articletime == (time_t) -1)
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
205 && ( r->data.reftime.vartime == INVALID ))
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
206 {
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
207 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
208 "Date equals rule: invalid date matches" );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
209 return TRUE;
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
210 }
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
211 if ( ( articletime == (time_t) -1)
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
212 != ( r->data.reftime.vartime == INVALID ))
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
213 return FALSE;
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
214 res = ( ( articletime <= r->data.reftime.calctime
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
215 + RULE_DATE_EQ_PRECISION )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
216 && ( articletime >= r->data.reftime.calctime
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
217 - RULE_DATE_EQ_PRECISION ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
218 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
219 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
220 "Date equals rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
221 Ov_date( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
222 return res;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
223
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
224 case RULE_DATE_GT:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
225 articletime = Utl_parseNewsDate( Ov_date( ov ) );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
226 if ( articletime == (time_t) -1 )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
227 return FALSE;
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
228 res = ( articletime > r->data.reftime.calctime );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
229 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
230 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
231 "Date after rule: %s matches",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
232 Ov_date( ov ) );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
233 return res;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
234
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
235 case RULE_NOREFS_LT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
236 ul = countRefs( Ov_ref( ov ) );
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
237 res = ( ul < r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
238 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
239 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
240 "Number of references rule: %d < %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
241 ul, r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
242 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
243
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
244 case RULE_NOREFS_EQ:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
245 ul = countRefs( Ov_ref( ov ) );
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
246 res = ( ul == r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
247 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
248 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
249 "Number of references rule: %d = %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
250 ul, r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
251 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
252
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
253 case RULE_NOREFS_GT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
254 ul = countRefs( Ov_ref( ov ) );
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
255 res = ( ul > r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
256 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
257 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
258 "Number of references rule: %d > %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
259 ul, r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
260 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
261
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
262 case RULE_XPOSTS_LT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
263 if ( newsgroups == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
264 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
265 ul = countGroups( newsgroups );
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
266 res = ( ul < r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
267 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
268 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
269 "Number of cross-posts rule: %d < %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
270 ul, r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
271 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
272
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
273 case RULE_XPOSTS_EQ:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
274 if ( newsgroups == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
275 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
276 ul = countGroups( newsgroups );
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
277 res = ( ul == r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
278 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
279 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
280 "Number of cross-posts rule: %d = %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
281 ul, r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
282 return res;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
283
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
284 case RULE_XPOSTS_GT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
285 if ( newsgroups == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
286 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
287 ul = countGroups( newsgroups );
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
288 res = ( ul > r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
289 if ( res )
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
290 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
291 "Number of cross-posts rule: %d > %d",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
292 ul, r->data.amount );
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
293 return res;
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
294
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
295 case RULE_POST_STATUS:
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
296 if ( Grp_postAllow( thisGrp ) == r->data.postAllow )
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
297 {
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
298 Log_dbg( LOG_DBG_FILTER,
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
299 "Post status rule: group status matches %c",
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
300 r->data.postAllow );
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
301 return TRUE;
481
0a5dc5f69746 [svn] * src/filter.c: Log filter matches when log category filter is selected.
bears
parents: 377
diff changeset
302 }
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
303 return FALSE;
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
304
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
305 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
306
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
307 ASSERT( FALSE ); /* Shouldn't get here */
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
308 return 0; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
309 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
310
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
311 /* Check a single filter to see if it fires. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
312 static Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
313 checkFilter( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
314 const Over *ov, const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
315 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
316 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
317
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
318 for ( i = 0; i < f->nRules; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
319 if ( ! checkRule( thisGrp, newsgroups, ov, &f->rules[i] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
320 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
321
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
322 return TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
323 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
324
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
325 /* Add a filter to the list of filters. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
326 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
327 Flt_addFilter( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
328 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
329 ASSERT( f != NULL );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
330
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
331 if ( ( filter.nFilters + 1 ) > filter.maxFilters )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
332 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
333 filter.filters =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
334 ( const Filter ** ) realloc( filter.filters,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
335 ( filter.maxFilters + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
336 * sizeof( Filter * ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
337 if ( filter.filters == NULL )
281
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 249
diff changeset
338 Log_fatal( "Could not realloc filter list" );
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
339 filter.maxFilters += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
340 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
341 filter.filters[ filter.nFilters++ ] = f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
342 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
343
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
344
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
345 /*
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
346 * Called by Fetch_init().
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
347 * Must be called before
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
348 * Fetch_getNewGrps(), Client_getNewgrps(), client.c:processGrps()
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
349 * because processGrps() sets the stampfile needed by lastupdate.
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
350 */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
351 void
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
352 Flt_init( const char * server )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
353 {
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
354 int index1, index2;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
355 time_t now, lastupdate;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
356 FilterRule * thisRule ;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
357 Str filename;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
358
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
359 time ( &now );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
360 lastupdate = (time_t) 0; /* defaults to start of epoch */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
361
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
362 snprintf( filename, MAXCHAR, "%s/lastupdate.%s",
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
363 Cfg_spoolDir(), server );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
364 if ( !Utl_getStamp( &lastupdate , filename ) )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
365 /* There's no stamp file if server has never been queried.
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
366 *
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
367 */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
368 Log_dbg( LOG_DBG_FILTER,
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
369 "Filter unable to get stamp file %s . Please query server.", filename );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
370
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
371 /* traverse all rules of all filters */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
372
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
373 for ( index1 = 0; index1 < filter.nFilters; index1++ )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
374 {
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
375 for ( index2 = 0; index2 < filter.filters[ index1 ] -> nRules; index2++ )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
376 {
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
377 thisRule = & ( filter.filters[ index1 ] -> rules[ index2 ] );
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
378 switch ( thisRule -> type )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
379 {
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
380 /* evaluate variable date specs */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
381 case RULE_DATE_LT:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
382 case RULE_DATE_EQ:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
383 case RULE_DATE_GT:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
384 thisRule -> data.reftime.calctime =
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
385 thisRule ->data.reftime.timeoffset;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
386 switch ( thisRule ->data.reftime.vartime )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
387 {
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
388 case NOW:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
389 thisRule -> data.reftime.calctime += now;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
390 break;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
391 case LASTUPDATE:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
392 thisRule -> data.reftime.calctime += lastupdate;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
393 break;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
394 default:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
395 break;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
396 } /* end switch( ... vartime) */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
397
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
398 /* Silently fix absolute dates before the epoch.
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
399 * This is not the place to mock about strange dates.
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
400 */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
401 if ( thisRule -> data.reftime.calctime < (time_t) 0 )
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
402 thisRule -> data.reftime.calctime = (time_t) 0 ;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
403
377
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
404 #if 0
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
405 Log_dbg( LOG_DBG_FILTER, "%d: %dl = %dl + %d",
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
406 thisRule -> type,
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
407 (long) thisRule -> data.reftime.calctime,
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
408 (long) thisRule ->data.reftime.timeoffset,
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
409 (int) thisRule ->data.reftime.vartime == NOW
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
410 ? now
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
411 : thisRule ->data.reftime.vartime == LASTUPDATE
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
412 ? lastupdate
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
413 : thisRule ->data.reftime.vartime );
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
414 #endif
21300895412f [svn] * src/common.h,src/control.c,src/noffle.c,src/post.c: Find actual bug
bears
parents: 281
diff changeset
415 break;
249
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
416 default:
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
417 break;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
418 } /* end switch( ... -> type) */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
419 } /* end for() */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
420 } /* end for() */
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
421 return ;
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
422 }
0340b9c17edc [svn] *** empty log message ***
mirkol
parents: 212
diff changeset
423
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
424 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
425 * Run the rules over the supplied overview. If a specific rule fires,
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
426 * returns its action. If no rule fires, or a rule specifying the default
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
427 * action fires, return the default read mode.
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
428 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
429 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
430 Flt_checkFilters( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
431 const Over *ov, FetchMode mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
432 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
433 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
434
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
435 for ( i = 0; i < filter.nFilters; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
436 if ( checkFilter( thisGrp, newsgroups, ov, filter.filters[ i ] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
437 {
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
438 FilterAction action = filter.filters[ i ]->action;
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
439
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
440 Log_dbg( LOG_DBG_FILTER,
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
441 "Filter %d fired on message %s",
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
442 i, Ov_msgId( ov ) );
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
443 if ( action == FILTER_DEFAULT )
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
444 break;
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
445 else
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
446 return action;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
447 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
448
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
449 switch( mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
450 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
451 case FULL: return FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
452 case THREAD: return FILTER_THREAD;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
453 case OVER: return FILTER_XOVER;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
454 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
455
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
456 ASSERT( FALSE ); /* Shouldn't get here */
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
457 return FILTER_FULL; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
458 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
459
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
460 Filter *
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
461 new_Filter( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
462 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
463 Filter *f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
464
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
465 if ( ! ( f = ( Filter * ) malloc( sizeof( Filter ) ) ) )
281
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 249
diff changeset
466 Log_fatal( "Cannot allocate Filter" );
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
467 f->nRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
468 f->maxRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
469 f->rules = NULL;
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
470 f->action = FILTER_DEFAULT;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
471 return f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
472 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
473
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
474 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
475 del_Filter( Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
476 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
477 if ( f == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
478 return;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
479
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
480 if ( f->rules != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
481 free( f->rules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
482 free( f );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
483 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
484
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
485 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
486 Flt_action( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
487 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
488 return f->action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
489 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
490
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
491 int
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
492 Flt_nRules( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
493 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
494 return f->nRules;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
495 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
496
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
497 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
498 * Do we have a rule requiring us to fetch the Newsgroups: headers of
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
499 * articles?
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
500 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
501 Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
502 Flt_getNewsgroups( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
503 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
504 return filter.needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
505 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
506
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
507 FilterRule
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
508 Flt_rule( const Filter *f, int ruleNo )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
509 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
510 ASSERT( ruleNo < f->nRules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
511 return f->rules[ ruleNo ];
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
512 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
513
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
514 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
515 Flt_setAction( Filter *f, FilterAction action )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
516 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
517 f->action = action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
518 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
519
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
520 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
521 Flt_addRule( Filter *f, FilterRule rule )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
522 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
523 /* Does the rule require Newsgroups: headers to be fetched? */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
524 if ( rule.type == RULE_NEWSGROUP ||
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
525 ( rule.type >= RULE_XPOSTS_LT && rule.type <= RULE_XPOSTS_GT ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
526 filter.needGroups = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
527
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
528 if ( f->nRules + 1 > f->maxRules )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
529 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
530 f->rules =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
531 ( FilterRule * ) realloc( f->rules,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
532 ( f->maxRules + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
533 * sizeof( FilterRule ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
534
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
535 if ( f->rules == NULL )
281
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 249
diff changeset
536 Log_fatal( "Could not realloc rule list" );
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
537 f->maxRules += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
538 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
539 f->rules[ f->nRules++ ] = rule;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
540 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
541
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
542