annotate src/filter.c @ 194:a4e9a20e50e5 noffle

[svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c: Contrary to the documentation, the action of a filter if not specified was 'full'. Add a new 'default' action which makes the action that of the group's subscription mode. Make this the default action, and allow 'default' to be specified explicitly as the action in the filter definition. Adapted from patch submitted by Mirko Liss. Thanks, Mirko. * docs/noffle.conf.5: Correct small typo.
author bears
date Tue, 30 Oct 2001 12:42:13 +0000
parents fed1334d766b
children 24d4cd032da5
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
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
6 $Id: filter.c 313 2001-10-30 12:42:13Z 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,
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
195 * 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
196 * action fires, return the default read mode.
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
197 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
198 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
199 Flt_checkFilters( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
200 const Over *ov, FetchMode mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
201 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
202 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
203
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
204 for ( i = 0; i < filter.nFilters; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
205 if ( checkFilter( thisGrp, newsgroups, ov, filter.filters[ i ] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
206 {
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
207 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
208
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
209 Log_dbg( LOG_DBG_FILTER,
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
210 "Filter %d fired on message %s",
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
211 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
212 if ( action == FILTER_DEFAULT )
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
213 break;
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
214 else
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
215 return action;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
216 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
217
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
218 switch( mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
219 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
220 case FULL: return FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
221 case THREAD: return FILTER_THREAD;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
222 case OVER: return FILTER_XOVER;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
223 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
224
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
225 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
226 return FILTER_FULL; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
227 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
228
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
229 Filter *
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
230 new_Filter( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
231 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
232 Filter *f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
233
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
234 if ( ! ( f = ( Filter * ) malloc( sizeof( Filter ) ) ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
235 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
236 Log_err( "Cannot allocate Filter" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
237 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
238 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
239 f->nRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
240 f->maxRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
241 f->rules = NULL;
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
242 f->action = FILTER_DEFAULT;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
243 return f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
244 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
245
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
246 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
247 del_Filter( Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
248 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
249 if ( f == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
250 return;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
251
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
252 if ( f->rules != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
253 free( f->rules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
254 free( f );
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 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
258 Flt_action( 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->action;
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 int
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
264 Flt_nRules( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
265 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
266 return f->nRules;
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 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
270 * Do we have a rule requiring us to fetch the Newsgroups: headers of
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
271 * articles?
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
272 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
273 Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
274 Flt_getNewsgroups( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
275 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
276 return filter.needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
277 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
278
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
279 FilterRule
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
280 Flt_rule( const Filter *f, int ruleNo )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
281 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
282 ASSERT( ruleNo < f->nRules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
283 return f->rules[ ruleNo ];
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_setAction( Filter *f, FilterAction action )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
288 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
289 f->action = action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
290 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
291
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
292 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
293 Flt_addRule( Filter *f, FilterRule rule )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
294 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
295 /* Does the rule require Newsgroups: headers to be fetched? */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
296 if ( rule.type == RULE_NEWSGROUP ||
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
297 ( rule.type >= RULE_XPOSTS_LT && rule.type <= RULE_XPOSTS_GT ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
298 filter.needGroups = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
299
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
300 if ( f->nRules + 1 > f->maxRules )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
301 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
302 f->rules =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
303 ( FilterRule * ) realloc( f->rules,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
304 ( f->maxRules + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
305 * sizeof( FilterRule ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
306
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
307 if ( f->rules == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
308 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
309 Log_err( "Could not realloc rule list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
310 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
311 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
312 f->maxRules += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
313 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
314 f->rules[ f->nRules++ ] = rule;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
315 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
316
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
317