Mercurial > noffle
comparison src/filter.c @ 481:0a5dc5f69746 noffle
[svn] * src/filter.c: Log filter matches when log category filter is selected.
author | bears |
---|---|
date | Wed, 13 Oct 2004 22:59:41 +0100 |
parents | 21300895412f |
children |
comparison
equal
deleted
inserted
replaced
480:5d32ceec7f25 | 481:0a5dc5f69746 |
---|---|
1 /* | 1 /* |
2 filter.c | 2 filter.c |
3 | 3 |
4 Article filtering. | 4 Article filtering. |
5 | 5 |
6 $Id: filter.c 517 2003-04-03 17:21:24Z bears $ | 6 $Id: filter.c 628 2004-10-13 21:59:41Z bears $ |
7 */ | 7 */ |
8 | 8 |
9 #if HAVE_CONFIG_H | 9 #if HAVE_CONFIG_H |
10 #include <config.h> | 10 #include <config.h> |
11 #endif | 11 #endif |
77 { | 77 { |
78 unsigned long ul; | 78 unsigned long ul; |
79 ItemList *grps; | 79 ItemList *grps; |
80 const char *p; | 80 const char *p; |
81 time_t articletime; | 81 time_t articletime; |
82 Bool res; | |
82 | 83 |
83 switch( r->type ) | 84 switch( r->type ) |
84 { | 85 { |
85 case RULE_NEWSGROUP: | 86 case RULE_NEWSGROUP: |
86 if ( Wld_match( thisGrp, r->data.grp ) ) | 87 if ( Wld_match( thisGrp, r->data.grp ) ) |
88 { | |
89 Log_dbg( LOG_DBG_FILTER, | |
90 "Newsgroup rule: %s matches current group", | |
91 r->data.grp, thisGrp ); | |
87 return TRUE; | 92 return TRUE; |
93 } | |
88 if ( newsgroups != NULL ) | 94 if ( newsgroups != NULL ) |
89 { | 95 { |
90 grps = new_Itl( newsgroups, " ,\t" ); | 96 grps = new_Itl( newsgroups, " ,\t" ); |
91 for ( p = Itl_first( grps ); p != NULL; p = Itl_next( grps ) ) | 97 for ( p = Itl_first( grps ); p != NULL; p = Itl_next( grps ) ) |
92 if ( Wld_match( p, r->data.grp ) ) | 98 if ( Wld_match( p, r->data.grp ) ) |
93 return TRUE; | 99 { |
100 Log_dbg( LOG_DBG_FILTER, | |
101 "Newsgroup rule: %s matched in %s", | |
102 r->data.grp, newsgroups ); | |
103 return TRUE; | |
104 } | |
94 del_Itl( grps ); | 105 del_Itl( grps ); |
95 } | 106 } |
96 return FALSE; | 107 return FALSE; |
97 | 108 |
98 case RULE_SUBJECT: | 109 case RULE_SUBJECT: |
99 return ( regexec( &r->data.regex, Ov_subj( ov ), 0, NULL, 0 ) == 0 ); | 110 res = ( regexec( &r->data.regex, Ov_subj( ov ), 0, NULL, 0 ) == 0 ); |
111 if ( res ) | |
112 Log_dbg( LOG_DBG_FILTER, | |
113 "Subject rule: %s matches", | |
114 Ov_subj( ov ) ); | |
115 return res; | |
100 | 116 |
101 case RULE_REFERENCE: /* kill thread by Msg-Id in References: */ | 117 case RULE_REFERENCE: /* kill thread by Msg-Id in References: */ |
102 return ( regexec( &r->data.regex, Ov_ref( ov ), 0, NULL, 0 ) == 0 ); | 118 res = ( regexec( &r->data.regex, Ov_ref( ov ), 0, NULL, 0 ) == 0 ); |
119 if ( res ) | |
120 Log_dbg( LOG_DBG_FILTER, | |
121 "Reference rule: %s matches", | |
122 Ov_ref( ov ) ); | |
123 return res; | |
103 | 124 |
104 case RULE_FROM: | 125 case RULE_FROM: |
105 return ( regexec( &r->data.regex, Ov_from( ov ), 0, NULL, 0 ) == 0 ); | 126 res = ( regexec( &r->data.regex, Ov_from( ov ), 0, NULL, 0 ) == 0 ); |
127 if ( res ) | |
128 Log_dbg( LOG_DBG_FILTER, | |
129 "From rule: %s matches", | |
130 Ov_from( ov ) ); | |
131 return res; | |
106 | 132 |
107 case RULE_BYTES_LT: | 133 case RULE_BYTES_LT: |
108 return ( Ov_bytes( ov ) < r->data.amount ); | 134 res = ( Ov_bytes( ov ) < r->data.amount ); |
135 if ( res ) | |
136 Log_dbg( LOG_DBG_FILTER, | |
137 "Length rule: bytes %d < %d", | |
138 Ov_bytes( ov ), r->data.amount ); | |
139 return res; | |
109 | 140 |
110 case RULE_BYTES_EQ: | 141 case RULE_BYTES_EQ: |
111 return ( Ov_bytes( ov ) == r->data.amount ); | 142 res = ( Ov_bytes( ov ) == r->data.amount ); |
143 if ( res ) | |
144 Log_dbg( LOG_DBG_FILTER, | |
145 "Length rule: bytes %d = %d", | |
146 Ov_bytes( ov ), r->data.amount ); | |
147 return res; | |
112 | 148 |
113 case RULE_BYTES_GT: | 149 case RULE_BYTES_GT: |
114 return ( Ov_bytes( ov ) > r->data.amount ); | 150 res = ( Ov_bytes( ov ) > r->data.amount ); |
151 if ( res ) | |
152 Log_dbg( LOG_DBG_FILTER, | |
153 "Length rule: bytes %d > %d", | |
154 Ov_bytes( ov ), r->data.amount ); | |
155 return res; | |
115 | 156 |
116 case RULE_LINES_LT: | 157 case RULE_LINES_LT: |
117 return ( Ov_lines( ov ) < r->data.amount ); | 158 res = ( Ov_lines( ov ) < r->data.amount ); |
159 if ( res ) | |
160 Log_dbg( LOG_DBG_FILTER, | |
161 "Length rule: lines %d < %d", | |
162 Ov_lines( ov ), r->data.amount ); | |
163 return res; | |
118 | 164 |
119 case RULE_LINES_EQ: | 165 case RULE_LINES_EQ: |
120 return ( Ov_lines( ov ) == r->data.amount ); | 166 res = ( Ov_lines( ov ) == r->data.amount ); |
167 if ( res ) | |
168 Log_dbg( LOG_DBG_FILTER, | |
169 "Length rule: lines %d = %d", | |
170 Ov_lines( ov ), r->data.amount ); | |
171 return res; | |
121 | 172 |
122 case RULE_LINES_GT: | 173 case RULE_LINES_GT: |
123 return ( Ov_lines( ov ) > r->data.amount ); | 174 res = ( Ov_lines( ov ) > r->data.amount ); |
175 if ( res ) | |
176 Log_dbg( LOG_DBG_FILTER, | |
177 "Length rule: lines %d > %d", | |
178 Ov_lines( ov ), r->data.amount ); | |
179 return res; | |
124 | 180 |
125 case RULE_MSGID: | 181 case RULE_MSGID: |
126 return ( regexec( &r->data.regex, Ov_msgId( ov ), 0, NULL, 0 ) == 0 ); | 182 res = ( regexec( &r->data.regex, Ov_msgId( ov ), 0, NULL, 0 ) == 0 ); |
183 if ( res ) | |
184 Log_dbg( LOG_DBG_FILTER, | |
185 "Msg-Id rule: %s matches", | |
186 Ov_msgId( ov ) ); | |
187 return res; | |
127 | 188 |
128 case RULE_DATE_LT: | 189 case RULE_DATE_LT: |
129 /* Utl_parseNewsDate() is quite picky. I'm not entirely happy | 190 /* Utl_parseNewsDate() is quite picky. I'm not entirely happy |
130 about this, but I won't implement a relaxed date parser. */ | 191 about this, but I won't implement a relaxed date parser. */ |
131 articletime = Utl_parseNewsDate( Ov_date( ov ) ); | 192 articletime = Utl_parseNewsDate( Ov_date( ov ) ); |
132 if ( articletime == (time_t) -1 ) | 193 if ( articletime == (time_t) -1 ) |
133 return FALSE; | 194 return FALSE; |
134 return ( articletime < r->data.reftime.calctime ); | 195 res = ( articletime < r->data.reftime.calctime ); |
196 if ( res ) | |
197 Log_dbg( LOG_DBG_FILTER, | |
198 "Date before rule: %s matches", | |
199 Ov_date( ov ) ); | |
200 return res; | |
135 | 201 |
136 case RULE_DATE_EQ: | 202 case RULE_DATE_EQ: |
137 articletime = Utl_parseNewsDate( Ov_date( ov ) ); | 203 articletime = Utl_parseNewsDate( Ov_date( ov ) ); |
138 if ( ( articletime == (time_t) -1) | 204 if ( ( articletime == (time_t) -1) |
139 && ( r->data.reftime.vartime == INVALID )) | 205 && ( r->data.reftime.vartime == INVALID )) |
140 return TRUE; | 206 { |
207 Log_dbg( LOG_DBG_FILTER, | |
208 "Date equals rule: invalid date matches" ); | |
209 return TRUE; | |
210 } | |
141 if ( ( articletime == (time_t) -1) | 211 if ( ( articletime == (time_t) -1) |
142 != ( r->data.reftime.vartime == INVALID )) | 212 != ( r->data.reftime.vartime == INVALID )) |
143 return FALSE; | 213 return FALSE; |
144 return ( ( articletime <= r->data.reftime.calctime | 214 res = ( ( articletime <= r->data.reftime.calctime |
145 + RULE_DATE_EQ_PRECISION ) | 215 + RULE_DATE_EQ_PRECISION ) |
146 && ( articletime >= r->data.reftime.calctime | 216 && ( articletime >= r->data.reftime.calctime |
147 - RULE_DATE_EQ_PRECISION ) ); | 217 - RULE_DATE_EQ_PRECISION ) ); |
218 if ( res ) | |
219 Log_dbg( LOG_DBG_FILTER, | |
220 "Date equals rule: %s matches", | |
221 Ov_date( ov ) ); | |
222 return res; | |
148 | 223 |
149 case RULE_DATE_GT: | 224 case RULE_DATE_GT: |
150 articletime = Utl_parseNewsDate( Ov_date( ov ) ); | 225 articletime = Utl_parseNewsDate( Ov_date( ov ) ); |
151 if ( articletime == (time_t) -1 ) | 226 if ( articletime == (time_t) -1 ) |
152 return FALSE; | 227 return FALSE; |
153 return ( articletime > r->data.reftime.calctime ); | 228 res = ( articletime > r->data.reftime.calctime ); |
229 if ( res ) | |
230 Log_dbg( LOG_DBG_FILTER, | |
231 "Date after rule: %s matches", | |
232 Ov_date( ov ) ); | |
233 return res; | |
154 | 234 |
155 case RULE_NOREFS_LT: | 235 case RULE_NOREFS_LT: |
156 ul = countRefs( Ov_ref( ov ) ); | 236 ul = countRefs( Ov_ref( ov ) ); |
157 return ( ul < r->data.amount ); | 237 res = ( ul < r->data.amount ); |
238 if ( res ) | |
239 Log_dbg( LOG_DBG_FILTER, | |
240 "Number of references rule: %d < %d", | |
241 ul, r->data.amount ); | |
242 return res; | |
158 | 243 |
159 case RULE_NOREFS_EQ: | 244 case RULE_NOREFS_EQ: |
160 ul = countRefs( Ov_ref( ov ) ); | 245 ul = countRefs( Ov_ref( ov ) ); |
161 return ( ul == r->data.amount ); | 246 res = ( ul == r->data.amount ); |
247 if ( res ) | |
248 Log_dbg( LOG_DBG_FILTER, | |
249 "Number of references rule: %d = %d", | |
250 ul, r->data.amount ); | |
251 return res; | |
162 | 252 |
163 case RULE_NOREFS_GT: | 253 case RULE_NOREFS_GT: |
164 ul = countRefs( Ov_ref( ov ) ); | 254 ul = countRefs( Ov_ref( ov ) ); |
165 return ( ul > r->data.amount ); | 255 res = ( ul > r->data.amount ); |
256 if ( res ) | |
257 Log_dbg( LOG_DBG_FILTER, | |
258 "Number of references rule: %d > %d", | |
259 ul, r->data.amount ); | |
260 return res; | |
166 | 261 |
167 case RULE_XPOSTS_LT: | 262 case RULE_XPOSTS_LT: |
168 if ( newsgroups == NULL ) | 263 if ( newsgroups == NULL ) |
169 return FALSE; | 264 return FALSE; |
170 ul = countGroups( newsgroups ); | 265 ul = countGroups( newsgroups ); |
171 return ( ul < r->data.amount ); | 266 res = ( ul < r->data.amount ); |
267 if ( res ) | |
268 Log_dbg( LOG_DBG_FILTER, | |
269 "Number of cross-posts rule: %d < %d", | |
270 ul, r->data.amount ); | |
271 return res; | |
172 | 272 |
173 case RULE_XPOSTS_EQ: | 273 case RULE_XPOSTS_EQ: |
174 if ( newsgroups == NULL ) | 274 if ( newsgroups == NULL ) |
175 return FALSE; | 275 return FALSE; |
176 ul = countGroups( newsgroups ); | 276 ul = countGroups( newsgroups ); |
177 return ( ul == r->data.amount ); | 277 res = ( ul == r->data.amount ); |
278 if ( res ) | |
279 Log_dbg( LOG_DBG_FILTER, | |
280 "Number of cross-posts rule: %d = %d", | |
281 ul, r->data.amount ); | |
282 return res; | |
178 | 283 |
179 case RULE_XPOSTS_GT: | 284 case RULE_XPOSTS_GT: |
180 if ( newsgroups == NULL ) | 285 if ( newsgroups == NULL ) |
181 return FALSE; | 286 return FALSE; |
182 ul = countGroups( newsgroups ); | 287 ul = countGroups( newsgroups ); |
183 return ( ul > r->data.amount ); | 288 res = ( ul > r->data.amount ); |
289 if ( res ) | |
290 Log_dbg( LOG_DBG_FILTER, | |
291 "Number of cross-posts rule: %d > %d", | |
292 ul, r->data.amount ); | |
293 return res; | |
184 | 294 |
185 case RULE_POST_STATUS: | 295 case RULE_POST_STATUS: |
186 if ( Grp_postAllow( thisGrp ) == r->data.postAllow ) | 296 if ( Grp_postAllow( thisGrp ) == r->data.postAllow ) |
297 { | |
298 Log_dbg( LOG_DBG_FILTER, | |
299 "Post status rule: group status matches %c", | |
300 r->data.postAllow ); | |
187 return TRUE; | 301 return TRUE; |
302 } | |
188 return FALSE; | 303 return FALSE; |
189 | 304 |
190 } | 305 } |
191 | 306 |
192 ASSERT( FALSE ); /* Shouldn't get here */ | 307 ASSERT( FALSE ); /* Shouldn't get here */ |