annotate src/filter.c @ 189:b1b6963fdd63 noffle

[svn] src/configfile.c: fix bug with missing initialization of user name and passwd
author enz
date Fri, 05 Oct 2001 16:44:04 +0100
parents fed1334d766b
children a4e9a20e50e5
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
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
6 $Id: filter.c 300 2001-08-05 08:24:22Z 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 "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 */
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
154 return 0; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
155 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
156
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
157 /* Check a single filter to see if it fires. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
158 static Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
159 checkFilter( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
160 const Over *ov, const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
161 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
162 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
163
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
164 for ( i = 0; i < f->nRules; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
165 if ( ! checkRule( thisGrp, newsgroups, ov, &f->rules[i] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
166 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
167
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
168 return TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
169 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
170
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
171 /* Add a filter to the list of filters. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
172 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
173 Flt_addFilter( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
174 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
175 ASSERT( f != NULL );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
176
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
177 if ( ( filter.nFilters + 1 ) > filter.maxFilters )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
178 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
179 filter.filters =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
180 ( const Filter ** ) realloc( filter.filters,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
181 ( filter.maxFilters + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
182 * sizeof( Filter * ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
183 if ( filter.filters == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
184 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
185 Log_err( "Could not realloc filter list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
186 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
187 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
188 filter.maxFilters += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
189 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
190 filter.filters[ filter.nFilters++ ] = f;
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 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
194 * Run the rules over the supplied overview. If a specific rule fires,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
195 * returns its action. If no rule fires, return the default read mode.
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
196 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
197 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
198 Flt_checkFilters( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
199 const Over *ov, FetchMode mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
200 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
201 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
202
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
203 for ( i = 0; i < filter.nFilters; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
204 if ( checkFilter( thisGrp, newsgroups, ov, filter.filters[ i ] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
205 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
206 Log_dbg( LOG_DBG_FILTER,
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
207 "Filter %d fired on message %s",
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
208 i, Ov_msgId( ov ) );
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
209 return filter.filters[ i ]->action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
210 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
211
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
212 switch( mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
213 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
214 case FULL: return FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
215 case THREAD: return FILTER_THREAD;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
216 case OVER: return FILTER_XOVER;
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 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
220 return FILTER_FULL; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
221 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
222
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
223 Filter *
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
224 new_Filter( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
225 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
226 Filter *f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
227
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
228 if ( ! ( f = ( Filter * ) malloc( sizeof( Filter ) ) ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
229 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
230 Log_err( "Cannot allocate Filter" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
231 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
232 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
233 f->nRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
234 f->maxRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
235 f->rules = NULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
236 f->action = FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
237 return f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
238 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
239
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
240 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
241 del_Filter( Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
242 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
243 if ( f == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
244 return;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
245
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
246 if ( f->rules != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
247 free( f->rules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
248 free( f );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
249 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
250
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
251 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
252 Flt_action( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
253 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
254 return f->action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
255 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
256
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
257 int
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
258 Flt_nRules( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
259 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
260 return f->nRules;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
261 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
262
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
263 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
264 * Do we have a rule requiring us to fetch the Newsgroups: headers of
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
265 * articles?
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
266 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
267 Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
268 Flt_getNewsgroups( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
269 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
270 return filter.needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
271 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
272
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
273 FilterRule
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
274 Flt_rule( const Filter *f, int ruleNo )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
275 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
276 ASSERT( ruleNo < f->nRules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
277 return f->rules[ ruleNo ];
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
278 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
279
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
280 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
281 Flt_setAction( Filter *f, FilterAction action )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
282 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
283 f->action = action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
284 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
285
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
286 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
287 Flt_addRule( Filter *f, FilterRule rule )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
288 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
289 /* Does the rule require Newsgroups: headers to be fetched? */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
290 if ( rule.type == RULE_NEWSGROUP ||
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
291 ( rule.type >= RULE_XPOSTS_LT && rule.type <= RULE_XPOSTS_GT ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
292 filter.needGroups = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
293
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
294 if ( f->nRules + 1 > f->maxRules )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
295 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
296 f->rules =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
297 ( FilterRule * ) realloc( f->rules,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
298 ( f->maxRules + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
299 * sizeof( FilterRule ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
300
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
301 if ( f->rules == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
302 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
303 Log_err( "Could not realloc rule list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
304 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
305 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
306 f->maxRules += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
307 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
308 f->rules[ f->nRules++ ] = rule;
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