Mercurial > noffle
annotate src/filter.c @ 493:4d3a1597813a noffle
[svn] updated FSF address
| author | godisch |
|---|---|
| date | Sun, 16 Apr 2006 07:20:58 +0100 |
| parents | 0a5dc5f69746 |
| children |
| rev | line source |
|---|---|
| 128 | 1 /* |
| 2 filter.c | |
| 3 | |
| 4 Article filtering. | |
| 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 | 7 */ |
| 8 | |
| 9 #if HAVE_CONFIG_H | |
| 10 #include <config.h> | |
| 11 #endif | |
| 12 | |
| 13 #include <ctype.h> | |
| 14 #include "common.h" | |
| 249 | 15 #include "configfile.h" |
| 128 | 16 #include "itemlist.h" |
| 17 #include "log.h" | |
| 18 #include "wildmat.h" | |
| 212 | 19 #include "group.h" |
| 249 | 20 #include "util.h" |
| 21 #include "filter.h" | |
| 128 | 22 |
| 23 struct | |
| 24 { | |
| 25 int nFilters; | |
| 26 int maxFilters; | |
| 27 const Filter **filters; | |
| 28 Bool needGroups; | |
| 29 } filter = { 0, 0, NULL, FALSE }; | |
| 30 | |
| 31 static unsigned long | |
| 32 countGroups( const char *grps ) | |
| 33 { | |
| 34 unsigned long res; | |
| 35 | |
| 36 res = 1; | |
| 37 while ( *grps != '\0' ) | |
| 38 { | |
| 39 if ( *grps == ',' ) | |
| 40 res++; | |
| 41 grps++; | |
| 42 } | |
| 43 | |
| 44 return res; | |
| 45 } | |
| 46 static unsigned long | |
| 47 countRefs( const char *refs ) | |
| 48 { | |
| 49 unsigned long res; | |
| 50 Bool inRef; | |
| 51 | |
| 52 res = 0; | |
| 53 inRef = FALSE; | |
| 54 | |
| 55 while ( *refs != '\0' ) | |
| 56 { | |
| 57 if ( inRef ) | |
| 58 { | |
| 59 if ( *refs == '>' ) | |
| 60 { | |
| 61 inRef = FALSE; | |
| 62 res++; | |
| 63 } | |
| 64 } | |
| 65 else if ( *refs == '<' ) | |
| 66 inRef = TRUE; | |
| 67 refs++; | |
| 68 } | |
| 69 | |
| 70 return res; | |
| 71 } | |
| 72 | |
| 73 /* Check a single rule to see if it passes. */ | |
| 74 static Bool | |
| 75 checkRule( const char *thisGrp, const char *newsgroups, | |
| 76 const Over *ov, const FilterRule *r ) | |
| 77 { | |
| 78 unsigned long ul; | |
| 79 ItemList *grps; | |
| 80 const char *p; | |
| 249 | 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 | 83 |
| 84 switch( r->type ) | |
| 85 { | |
| 86 case RULE_NEWSGROUP: | |
| 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 | 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 | 94 if ( newsgroups != NULL ) |
| 95 { | |
| 96 grps = new_Itl( newsgroups, " ,\t" ); | |
| 97 for ( p = Itl_first( grps ); p != NULL; p = Itl_next( grps ) ) | |
| 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 | 105 del_Itl( grps ); |
| 106 } | |
| 107 return FALSE; | |
| 108 | |
| 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 | 116 |
| 249 | 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 | 124 |
| 128 | 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 | 132 |
| 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 | 140 |
| 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 | 148 |
| 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 | 156 |
| 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 | 164 |
| 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 | 172 |
| 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 | 180 |
| 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 | 188 |
| 249 | 189 case RULE_DATE_LT: |
| 190 /* Utl_parseNewsDate() is quite picky. I'm not entirely happy | |
| 191 about this, but I won't implement a relaxed date parser. */ | |
| 192 articletime = Utl_parseNewsDate( Ov_date( ov ) ); | |
| 193 if ( articletime == (time_t) -1 ) | |
| 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 | 201 |
| 202 case RULE_DATE_EQ: | |
| 203 articletime = Utl_parseNewsDate( Ov_date( ov ) ); | |
| 204 if ( ( articletime == (time_t) -1) | |
| 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 | 211 if ( ( articletime == (time_t) -1) |
| 212 != ( r->data.reftime.vartime == INVALID )) | |
| 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 | 223 |
| 224 case RULE_DATE_GT: | |
| 225 articletime = Utl_parseNewsDate( Ov_date( ov ) ); | |
| 226 if ( articletime == (time_t) -1 ) | |
| 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 | 234 |
| 128 | 235 case RULE_NOREFS_LT: |
| 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 | 243 |
| 244 case RULE_NOREFS_EQ: | |
| 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 | 252 |
| 253 case RULE_NOREFS_GT: | |
| 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 | 261 |
| 262 case RULE_XPOSTS_LT: | |
| 263 if ( newsgroups == NULL ) | |
| 264 return FALSE; | |
| 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 | 272 |
| 273 case RULE_XPOSTS_EQ: | |
| 274 if ( newsgroups == NULL ) | |
| 275 return FALSE; | |
| 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 | 283 |
| 284 case RULE_XPOSTS_GT: | |
| 285 if ( newsgroups == NULL ) | |
| 286 return FALSE; | |
| 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 | 294 |
| 295 case RULE_POST_STATUS: | |
| 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 | 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 | 303 return FALSE; |
| 304 | |
| 128 | 305 } |
| 306 | |
| 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 | 309 } |
| 310 | |
| 311 /* Check a single filter to see if it fires. */ | |
| 312 static Bool | |
| 313 checkFilter( const char *thisGrp, const char *newsgroups, | |
| 314 const Over *ov, const Filter *f ) | |
| 315 { | |
| 316 int i; | |
| 317 | |
| 318 for ( i = 0; i < f->nRules; i++ ) | |
| 319 if ( ! checkRule( thisGrp, newsgroups, ov, &f->rules[i] ) ) | |
| 320 return FALSE; | |
| 321 | |
| 322 return TRUE; | |
| 323 } | |
| 324 | |
| 325 /* Add a filter to the list of filters. */ | |
| 326 void | |
| 327 Flt_addFilter( const Filter *f ) | |
| 328 { | |
| 329 ASSERT( f != NULL ); | |
| 330 | |
| 331 if ( ( filter.nFilters + 1 ) > filter.maxFilters ) | |
| 332 { | |
| 333 filter.filters = | |
| 334 ( const Filter ** ) realloc( filter.filters, | |
| 335 ( filter.maxFilters + 5 ) | |
| 336 * sizeof( Filter * ) ); | |
| 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 | 339 filter.maxFilters += 5; |
| 340 } | |
| 341 filter.filters[ filter.nFilters++ ] = f; | |
| 342 } | |
| 343 | |
| 249 | 344 |
| 345 /* | |
| 346 * Called by Fetch_init(). | |
| 347 * Must be called before | |
| 348 * Fetch_getNewGrps(), Client_getNewgrps(), client.c:processGrps() | |
| 349 * because processGrps() sets the stampfile needed by lastupdate. | |
| 350 */ | |
| 351 void | |
| 352 Flt_init( const char * server ) | |
| 353 { | |
| 354 int index1, index2; | |
| 355 time_t now, lastupdate; | |
| 356 FilterRule * thisRule ; | |
| 357 Str filename; | |
| 358 | |
| 359 time ( &now ); | |
| 360 lastupdate = (time_t) 0; /* defaults to start of epoch */ | |
| 361 | |
| 362 snprintf( filename, MAXCHAR, "%s/lastupdate.%s", | |
| 363 Cfg_spoolDir(), server ); | |
| 364 if ( !Utl_getStamp( &lastupdate , filename ) ) | |
| 365 /* There's no stamp file if server has never been queried. | |
| 366 * | |
| 367 */ | |
| 368 Log_dbg( LOG_DBG_FILTER, | |
| 369 "Filter unable to get stamp file %s . Please query server.", filename ); | |
| 370 | |
| 371 /* traverse all rules of all filters */ | |
| 372 | |
| 373 for ( index1 = 0; index1 < filter.nFilters; index1++ ) | |
| 374 { | |
| 375 for ( index2 = 0; index2 < filter.filters[ index1 ] -> nRules; index2++ ) | |
| 376 { | |
| 377 thisRule = & ( filter.filters[ index1 ] -> rules[ index2 ] ); | |
| 378 switch ( thisRule -> type ) | |
| 379 { | |
| 380 /* evaluate variable date specs */ | |
| 381 case RULE_DATE_LT: | |
| 382 case RULE_DATE_EQ: | |
| 383 case RULE_DATE_GT: | |
| 384 thisRule -> data.reftime.calctime = | |
| 385 thisRule ->data.reftime.timeoffset; | |
| 386 switch ( thisRule ->data.reftime.vartime ) | |
| 387 { | |
| 388 case NOW: | |
| 389 thisRule -> data.reftime.calctime += now; | |
| 390 break; | |
| 391 case LASTUPDATE: | |
| 392 thisRule -> data.reftime.calctime += lastupdate; | |
| 393 break; | |
| 394 default: | |
| 395 break; | |
| 396 } /* end switch( ... vartime) */ | |
| 397 | |
| 398 /* Silently fix absolute dates before the epoch. | |
| 399 * This is not the place to mock about strange dates. | |
| 400 */ | |
| 401 if ( thisRule -> data.reftime.calctime < (time_t) 0 ) | |
| 402 thisRule -> data.reftime.calctime = (time_t) 0 ; | |
| 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 | 416 default: |
| 417 break; | |
| 418 } /* end switch( ... -> type) */ | |
| 419 } /* end for() */ | |
| 420 } /* end for() */ | |
| 421 return ; | |
| 422 } | |
| 423 | |
| 128 | 424 /* |
| 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 | 428 */ |
| 429 FilterAction | |
| 430 Flt_checkFilters( const char *thisGrp, const char *newsgroups, | |
| 431 const Over *ov, FetchMode mode ) | |
| 432 { | |
| 433 int i; | |
| 434 | |
| 435 for ( i = 0; i < filter.nFilters; i++ ) | |
| 436 if ( checkFilter( thisGrp, newsgroups, ov, filter.filters[ i ] ) ) | |
| 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 | 447 } |
| 448 | |
| 449 switch( mode ) | |
| 450 { | |
| 451 case FULL: return FILTER_FULL; | |
| 452 case THREAD: return FILTER_THREAD; | |
| 453 case OVER: return FILTER_XOVER; | |
| 454 } | |
| 455 | |
| 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 | 458 } |
| 459 | |
| 460 Filter * | |
| 461 new_Filter( void ) | |
| 462 { | |
| 463 Filter *f; | |
| 464 | |
| 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 | 467 f->nRules = 0; |
| 468 f->maxRules = 0; | |
| 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 | 471 return f; |
| 472 } | |
| 473 | |
| 474 void | |
| 475 del_Filter( Filter *f ) | |
| 476 { | |
| 477 if ( f == NULL ) | |
| 478 return; | |
| 479 | |
| 480 if ( f->rules != NULL ) | |
| 481 free( f->rules ); | |
| 482 free( f ); | |
| 483 } | |
| 484 | |
| 485 FilterAction | |
| 486 Flt_action( const Filter *f ) | |
| 487 { | |
| 488 return f->action; | |
| 489 } | |
| 490 | |
| 491 int | |
| 492 Flt_nRules( const Filter *f ) | |
| 493 { | |
| 494 return f->nRules; | |
| 495 } | |
| 496 | |
| 497 /* | |
| 498 * Do we have a rule requiring us to fetch the Newsgroups: headers of | |
| 499 * articles? | |
| 500 */ | |
| 501 Bool | |
| 502 Flt_getNewsgroups( void ) | |
| 503 { | |
| 504 return filter.needGroups; | |
| 505 } | |
| 506 | |
| 507 FilterRule | |
| 508 Flt_rule( const Filter *f, int ruleNo ) | |
| 509 { | |
| 510 ASSERT( ruleNo < f->nRules ); | |
| 511 return f->rules[ ruleNo ]; | |
| 512 } | |
| 513 | |
| 514 void | |
| 515 Flt_setAction( Filter *f, FilterAction action ) | |
| 516 { | |
| 517 f->action = action; | |
| 518 } | |
| 519 | |
| 520 void | |
| 521 Flt_addRule( Filter *f, FilterRule rule ) | |
| 522 { | |
| 523 /* Does the rule require Newsgroups: headers to be fetched? */ | |
| 524 if ( rule.type == RULE_NEWSGROUP || | |
| 525 ( rule.type >= RULE_XPOSTS_LT && rule.type <= RULE_XPOSTS_GT ) ) | |
| 526 filter.needGroups = TRUE; | |
| 527 | |
| 528 if ( f->nRules + 1 > f->maxRules ) | |
| 529 { | |
| 530 f->rules = | |
| 531 ( FilterRule * ) realloc( f->rules, | |
| 532 ( f->maxRules + 5 ) | |
| 533 * sizeof( FilterRule ) ); | |
| 534 | |
| 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 | 537 f->maxRules += 5; |
| 538 } | |
| 539 f->rules[ f->nRules++ ] = rule; | |
| 540 } | |
| 541 | |
| 542 |
