annotate src/filter.c @ 128:8897b7e3b108 noffle

[svn] Add article filtering
author bears
date Wed, 09 Aug 2000 22:19:17 +0100
parents
children fed1334d766b
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
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
6 $Id: filter.c 189 2000-08-09 21:19:17Z bears $
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 "filter.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
14
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
15 #include <ctype.h>
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
16 #include "common.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
17 #include "itemlist.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
18 #include "log.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
19 #include "wildmat.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
20
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
21 struct
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
22 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
23 int nFilters;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
24 int maxFilters;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
25 const Filter **filters;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
26 Bool needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
27 } filter = { 0, 0, NULL, FALSE };
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
28
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
29 static unsigned long
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
30 countGroups( const char *grps )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
31 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
32 unsigned long res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
33
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
34 res = 1;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
35 while ( *grps != '\0' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
36 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
37 if ( *grps == ',' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
38 res++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
39 grps++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
40 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
41
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
42 return res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
43 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
44 static unsigned long
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
45 countRefs( const char *refs )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
46 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
47 unsigned long res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
48 Bool inRef;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
49
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
50 res = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
51 inRef = FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
52
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
53 while ( *refs != '\0' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
54 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
55 if ( inRef )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
56 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
57 if ( *refs == '>' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
58 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
59 inRef = FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
60 res++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
61 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
62 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
63 else if ( *refs == '<' )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
64 inRef = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
65 refs++;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
66 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
67
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
68 return res;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
69 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
70
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
71 /* Check a single rule to see if it passes. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
72 static Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
73 checkRule( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
74 const Over *ov, const FilterRule *r )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
75 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
76 unsigned long ul;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
77 ItemList *grps;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
78 const char *p;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
79
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
80 switch( r->type )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
81 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
82 case RULE_NEWSGROUP:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
83 if ( Wld_match( thisGrp, r->data.grp ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
84 return TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
85 if ( newsgroups != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
86 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
87 grps = new_Itl( newsgroups, " ,\t" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
88 for ( p = Itl_first( grps ); p != NULL; p = Itl_next( grps ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
89 if ( Wld_match( p, r->data.grp ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
90 return TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
91 del_Itl( grps );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
92 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
93 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
94
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
95 case RULE_SUBJECT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
96 return ( regexec( &r->data.regex, Ov_subj( ov ), 0, NULL, 0 ) == 0 );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
97
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
98 case RULE_FROM:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
99 return ( regexec( &r->data.regex, Ov_from( ov ), 0, NULL, 0 ) == 0 );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
100
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
101 case RULE_BYTES_LT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
102 return ( Ov_bytes( ov ) < r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
103
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
104 case RULE_BYTES_EQ:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
105 return ( Ov_bytes( ov ) == r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
106
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
107 case RULE_BYTES_GT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
108 return ( Ov_bytes( ov ) > r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
109
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
110 case RULE_LINES_LT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
111 return ( Ov_lines( ov ) < r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
112
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
113 case RULE_LINES_EQ:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
114 return ( Ov_lines( ov ) == r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
115
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
116 case RULE_LINES_GT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
117 return ( Ov_lines( ov ) > r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
118
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
119 case RULE_MSGID:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
120 return ( regexec( &r->data.regex, Ov_msgId( ov ), 0, NULL, 0 ) == 0 );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
121
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
122 case RULE_NOREFS_LT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
123 ul = countRefs( Ov_ref( ov ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
124 return ( ul < r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
125
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
126 case RULE_NOREFS_EQ:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
127 ul = countRefs( Ov_ref( ov ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
128 return ( ul == r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
129
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
130 case RULE_NOREFS_GT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
131 ul = countRefs( Ov_ref( ov ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
132 return ( ul > r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
133
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
134 case RULE_XPOSTS_LT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
135 if ( newsgroups == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
136 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
137 ul = countGroups( newsgroups );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
138 return ( ul < r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
139
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
140 case RULE_XPOSTS_EQ:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
141 if ( newsgroups == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
142 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
143 ul = countGroups( newsgroups );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
144 return ( ul == r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
145
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
146 case RULE_XPOSTS_GT:
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
147 if ( newsgroups == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
148 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
149 ul = countGroups( newsgroups );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
150 return ( ul > r->data.amount );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
151 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
152
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
153 ASSERT( FALSE ); /* Shouldn't get here */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
154 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
155
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
156 /* Check a single filter to see if it fires. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
157 static Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
158 checkFilter( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
159 const Over *ov, const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
160 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
161 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
162
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
163 for ( i = 0; i < f->nRules; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
164 if ( ! checkRule( thisGrp, newsgroups, ov, &f->rules[i] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
165 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
166
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
167 return TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
168 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
169
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
170 /* Add a filter to the list of filters. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
171 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
172 Flt_addFilter( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
173 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
174 ASSERT( f != NULL );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
175
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
176 if ( ( filter.nFilters + 1 ) > filter.maxFilters )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
177 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
178 filter.filters =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
179 ( const Filter ** ) realloc( filter.filters,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
180 ( filter.maxFilters + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
181 * sizeof( Filter * ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
182 if ( filter.filters == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
183 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
184 Log_err( "Could not realloc filter list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
185 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
186 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
187 filter.maxFilters += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
188 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
189 filter.filters[ filter.nFilters++ ] = f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
190 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
191
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
192 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
193 * Run the rules over the supplied overview. If a specific rule fires,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
194 * returns its action. If no rule fires, return the default read mode.
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
195 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
196 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
197 Flt_checkFilters( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
198 const Over *ov, FetchMode mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
199 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
200 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
201
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
202 for ( i = 0; i < filter.nFilters; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
203 if ( checkFilter( thisGrp, newsgroups, ov, filter.filters[ i ] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
204 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
205 Log_dbg( "Filter %d fired on message %s", i, Ov_msgId( ov ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
206 return filter.filters[ i ]->action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
207 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
208
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
209 switch( mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
210 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
211 case FULL: return FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
212 case THREAD: return FILTER_THREAD;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
213 case OVER: return FILTER_XOVER;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
214 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
215
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
216 ASSERT( FALSE ); /* Shouldn't get here */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
217 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
218
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
219 Filter *
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
220 new_Filter( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
221 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
222 Filter *f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
223
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
224 if ( ! ( f = ( Filter * ) malloc( sizeof( Filter ) ) ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
225 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
226 Log_err( "Cannot allocate Filter" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
227 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
228 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
229 f->nRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
230 f->maxRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
231 f->rules = NULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
232 f->action = FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
233 return f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
234 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
235
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
236 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
237 del_Filter( Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
238 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
239 if ( f == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
240 return;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
241
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
242 if ( f->rules != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
243 free( f->rules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
244 free( f );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
245 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
246
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
247 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
248 Flt_action( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
249 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
250 return f->action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
251 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
252
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
253 int
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
254 Flt_nRules( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
255 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
256 return f->nRules;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
257 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
258
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
259 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
260 * Do we have a rule requiring us to fetch the Newsgroups: headers of
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
261 * articles?
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
262 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
263 Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
264 Flt_getNewsgroups( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
265 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
266 return filter.needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
267 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
268
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
269 FilterRule
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
270 Flt_rule( const Filter *f, int ruleNo )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
271 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
272 ASSERT( ruleNo < f->nRules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
273 return f->rules[ ruleNo ];
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
274 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
275
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
276 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
277 Flt_setAction( Filter *f, FilterAction action )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
278 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
279 f->action = action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
280 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
281
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
282 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
283 Flt_addRule( Filter *f, FilterRule rule )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
284 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
285 /* Does the rule require Newsgroups: headers to be fetched? */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
286 if ( rule.type == RULE_NEWSGROUP ||
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
287 ( rule.type >= RULE_XPOSTS_LT && rule.type <= RULE_XPOSTS_GT ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
288 filter.needGroups = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
289
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
290 if ( f->nRules + 1 > f->maxRules )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
291 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
292 f->rules =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
293 ( FilterRule * ) realloc( f->rules,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
294 ( f->maxRules + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
295 * sizeof( FilterRule ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
296
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
297 if ( f->rules == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
298 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
299 Log_err( "Could not realloc rule list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
300 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
301 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
302 f->maxRules += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
303 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
304 f->rules[ f->nRules++ ] = rule;
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