annotate src/filter.c @ 248:cd022deb8390 noffle

[svn] I've hopefully no further bugs introduced.
author mirkol
date Tue, 26 Mar 2002 17:52:48 +0000
parents 21200ce10e68
children 0340b9c17edc
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
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
6 $Id: filter.c 331 2001-11-22 12:04:45Z mirkol $
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 <ctype.h>
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
14 #include "common.h"
197
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 194
diff changeset
15 #include "filter.h"
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
16 #include "itemlist.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
17 #include "log.h"
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
18 #include "wildmat.h"
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
19 #include "group.h"
128
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 );
212
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
151
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
152 case RULE_POST_STATUS:
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
153 if ( Grp_postAllow( thisGrp ) == r->data.postAllow )
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
154 return TRUE;
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
155 return FALSE;
21200ce10e68 [svn] filter post-status=mod|yes|no.
mirkol
parents: 197
diff changeset
156
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
157 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
158
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
159 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
160 return 0; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
161 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
162
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
163 /* Check a single filter to see if it fires. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
164 static Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
165 checkFilter( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
166 const Over *ov, const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
167 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
168 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
169
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
170 for ( i = 0; i < f->nRules; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
171 if ( ! checkRule( thisGrp, newsgroups, ov, &f->rules[i] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
172 return FALSE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
173
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
174 return TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
175 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
176
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
177 /* Add a filter to the list of filters. */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
178 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
179 Flt_addFilter( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
180 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
181 ASSERT( f != NULL );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
182
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
183 if ( ( filter.nFilters + 1 ) > filter.maxFilters )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
184 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
185 filter.filters =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
186 ( const Filter ** ) realloc( filter.filters,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
187 ( filter.maxFilters + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
188 * sizeof( Filter * ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
189 if ( filter.filters == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
190 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
191 Log_err( "Could not realloc filter list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
192 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
193 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
194 filter.maxFilters += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
195 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
196 filter.filters[ filter.nFilters++ ] = f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
197 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
198
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
199 /*
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
200 * 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
201 * 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
202 * action fires, return the default read mode.
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
203 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
204 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
205 Flt_checkFilters( const char *thisGrp, const char *newsgroups,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
206 const Over *ov, FetchMode mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
207 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
208 int i;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
209
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
210 for ( i = 0; i < filter.nFilters; i++ )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
211 if ( checkFilter( thisGrp, newsgroups, ov, filter.filters[ i ] ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
212 {
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
213 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
214
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
215 Log_dbg( LOG_DBG_FILTER,
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
216 "Filter %d fired on message %s",
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 128
diff changeset
217 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
218 if ( action == FILTER_DEFAULT )
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
219 break;
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
220 else
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
221 return action;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
222 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
223
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
224 switch( mode )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
225 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
226 case FULL: return FILTER_FULL;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
227 case THREAD: return FILTER_THREAD;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
228 case OVER: return FILTER_XOVER;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
229 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
230
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
231 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
232 return FILTER_FULL; /* Keep compiler quiet */
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
233 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
234
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
235 Filter *
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
236 new_Filter( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
237 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
238 Filter *f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
239
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
240 if ( ! ( f = ( Filter * ) malloc( sizeof( Filter ) ) ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
241 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
242 Log_err( "Cannot allocate Filter" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
243 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
244 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
245 f->nRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
246 f->maxRules = 0;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
247 f->rules = NULL;
194
a4e9a20e50e5 [svn] * docs/noffle.conf.5,src/configfile.c,src/filter.h,src/filter.c:
bears
parents: 185
diff changeset
248 f->action = FILTER_DEFAULT;
128
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
249 return f;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
250 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
251
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
252 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
253 del_Filter( Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
254 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
255 if ( f == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
256 return;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
257
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
258 if ( f->rules != NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
259 free( f->rules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
260 free( f );
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 FilterAction
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
264 Flt_action( 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->action;
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 int
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
270 Flt_nRules( const Filter *f )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
271 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
272 return f->nRules;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
273 }
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 * Do we have a rule requiring us to fetch the Newsgroups: headers of
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
277 * articles?
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
278 */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
279 Bool
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
280 Flt_getNewsgroups( void )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
281 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
282 return filter.needGroups;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
283 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
284
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
285 FilterRule
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
286 Flt_rule( const Filter *f, int ruleNo )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
287 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
288 ASSERT( ruleNo < f->nRules );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
289 return f->rules[ ruleNo ];
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_setAction( Filter *f, FilterAction action )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
294 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
295 f->action = action;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
296 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
297
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
298 void
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
299 Flt_addRule( Filter *f, FilterRule rule )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
300 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
301 /* Does the rule require Newsgroups: headers to be fetched? */
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
302 if ( rule.type == RULE_NEWSGROUP ||
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
303 ( rule.type >= RULE_XPOSTS_LT && rule.type <= RULE_XPOSTS_GT ) )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
304 filter.needGroups = TRUE;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
305
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
306 if ( f->nRules + 1 > f->maxRules )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
307 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
308 f->rules =
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
309 ( FilterRule * ) realloc( f->rules,
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
310 ( f->maxRules + 5 )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
311 * sizeof( FilterRule ) );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
312
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
313 if ( f->rules == NULL )
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
314 {
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
315 Log_err( "Could not realloc rule list" );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
316 exit( EXIT_FAILURE );
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
317 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
318 f->maxRules += 5;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
319 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
320 f->rules[ f->nRules++ ] = rule;
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
321 }
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
322
8897b7e3b108 [svn] Add article filtering
bears
parents:
diff changeset
323