WIP spot deduping
[spider.git] / perl / Filter.pm
1 #
2 # The User/Sysop Filter module
3 #
4 # The way this works is that the filter routine is actually
5 # a predefined function that returns 0 if it is OK and 1 if it
6 # is not when presented with a list of things.
7 #
8 # This set of routines provide a means of maintaining the filter
9 # scripts which are compiled in when an entity connects.
10 #
11 # Copyright (c) 1999 Dirk Koopman G1TLH
12 #
13 #
14 #
15 # The NEW INSTRUCTIONS
16 #
17 # use the commands accept/spot|ann|wwv|wcy and reject/spot|ann|wwv|wcy
18 # also show/filter spot|ann|wwv|wcy
19 #
20 # The filters live in a directory tree of their own in $main::root/filter
21 #
22 # Each type of filter (e.g. spot, wwv) live in a tree of their own so you
23 # can have different filters for different things for the same callsign.
24 #
25
26
27 package Filter;
28
29 use DXVars;
30 use DXUtil;
31 use DXDebug;
32 use Data::Dumper;
33 use Prefix;
34 use DXLog;
35 use DXJSON;
36
37 use strict;
38
39 use vars qw ($filterbasefn $in);
40
41 $filterbasefn = "$main::root/filter";
42 $in = undef;
43 my $json;
44
45
46 # initial filter system
47 sub init
48 {
49         $json = DXJSON->new->indent(1);
50 }
51
52 sub new
53 {
54         my ($class, $sort, $call, $flag) = @_;
55         $flag = ($flag) ? "in_" : "";
56         return bless {sort => $sort, name => "$flag$call.pl" }, $class;
57 }
58
59 # standard filename generator
60 sub getfn
61 {
62         my ($sort, $call, $flag) = @_;
63
64     # first uppercase
65         $flag = ($flag) ? "in_" : "";
66         $call = uc $call;
67         my $fn = "$filterbasefn/$sort/$flag$call.pl";
68
69         # otherwise lowercase
70         unless (-e $fn) {
71                 $call = lc $call;
72                 $fn = "$filterbasefn/$sort/$flag$call.pl";
73         }
74         $fn = undef unless -e $fn;
75         return $fn;
76 }
77
78 # this reads in a filter statement and returns it as a list
79
80 # The filter is stored in straight perl so that it can be parsed and read
81 # in with a 'do' statement. The 'do' statement reads the filter into
82 # @in which is a list of references
83 #
84 sub compile
85 {
86         my $self = shift;
87         my $fname = shift;
88         my $ar = shift;
89         my $ref = $self->{$fname};
90         my $rr;
91         
92         if ($ref->{$ar} && exists $ref->{$ar}->{asc}) {
93                 my $s = $ref->{$ar}->{asc};     # an optimisation?
94                 $s =~ s/\$r/\$_[0]/g;
95 #               $s =~ s/\\\\/\\/g;
96                 $ref->{$ar}->{code} = eval "sub { $s }" ;
97                 if ($@) {
98                         my $sort = $ref->{sort};
99                         my $name = $ref->{name};
100                         dbg("Error compiling $ar $sort $name: $@");
101                         Log('err', "Error compiling $ar $sort $name: $@");
102                 }
103                 $rr = $@;
104         }
105         return $rr;
106 }
107
108 sub read_in
109 {
110         my ($sort, $call, $flag) = @_;
111         my $fn;
112         
113         # load it
114         if ($fn = getfn($sort, $call, $flag)) {
115                 $in = undef; 
116                 my $s = readfilestr($fn);
117                 my $newin;
118                 if ($s =~ /^\s*{/) {
119                         eval {$newin = $json->decode($s, __PACKAGE__)};
120                 } else {        
121                         $newin = eval $s;
122                 }
123                 if ($@) {
124                         dbg($@);
125                         unlink($fn);
126                         return undef;
127                 }
128                 if ($in) {
129                         $newin = new('Filter::Old', $sort, $call, $flag);
130                         $newin->{filter} = $in;
131                 } elsif (ref $newin && $newin->can('getfilkeys')) {
132                         my $filter;
133                         my $key;
134                         foreach $key ($newin->getfilkeys) {
135                                 $newin->compile($key, 'reject');
136                                 $newin->compile($key, 'accept');
137                         }
138                 } else {
139                         # error on reading file, delete and exit
140                         dbg("empty or unreadable filter: $fn, deleted");
141                         unlink($fn);
142                         return undef;
143                 }
144                 return $newin;
145         }
146         return undef;
147 }
148
149
150 # this writes out the filter in a form suitable to be read in by 'read_in'
151 # It expects a list of references to filter lines
152 sub write
153 {
154         my $self = shift;
155         my $sort = $self->{sort};
156         my $name = $self->{name};
157         my $dir = "$filterbasefn/$sort";
158         my $fn = "$dir/$name";
159
160         mkdir $dir, 0775 unless -e $dir; 
161     rename $fn, "$fn.o" if -e $fn;
162         my $fh = new IO::File ">$fn";
163         if ($fh) {
164 #               my $dd = new Data::Dumper([ $self ]);
165 #               $dd->Indent(1);
166 #               $dd->Terse(1);
167 #               $dd->Quotekeys($] < 5.005 ? 1 : 0);
168                 #               $fh->print($dd->Dumpxs);
169
170                 # remove code references, do the encode, then put them back again (they can't be represented anyway)
171                 my $key;
172                 foreach $key ($self->getfilkeys) {
173                         $self->{$key}->{reject}->{code} = undef if exists $self->{$key}->{reject};
174                         $self->{$key}->{accept}->{code} = undef if exists $self->{$key}->{accept};
175                 }
176                 $fh->print($json->encode($self));
177                 foreach $key ($self->getfilkeys) {
178                         $self->compile($key, 'reject');
179                         $self->compile($key, 'accept');
180                 }
181                 $fh->close;
182         } else {
183                 rename "$fn.o", $fn if -e "$fn.o";
184                 return "$fn $!";
185         }
186         return undef;
187 }
188
189 sub getfilters
190 {
191         my $self = shift;
192         my @out;
193         my $key;
194         foreach $key (grep {/^filter/ } keys %$self) {
195                 push @out, $self->{$key};
196         }
197         return @out;
198 }
199
200 sub getfilkeys
201 {
202         my $self = shift;
203         return grep {/^filter/ } keys %$self;
204 }
205
206 #
207 # This routine accepts a composite filter with a reject rule and then an accept rule.
208 #
209 # The filter returns 0 if an entry is matched by any reject rule and also if any
210 # accept rule fails otherwise it returns 1
211 #
212 # Either set of rules may be missing meaning an implicit 'opposite' ie if it
213 # a reject then ok else if an accept then not ok.
214 #
215 # you can set a default with either an accept/xxxx all or reject/xxxx all
216 #
217 # Unlike the old system, this is kept as a hash of hashes so that you can
218 # easily change them by program.
219 #
220 # You can have 10 filter lines (0->9), they are tried in order until 
221 # one matches
222 #
223 # There is a parser that takes a Filter::Cmd object which describes all the possible
224 # things you can filter on and then converts that to a bit of perl which is compiled
225 # and stored as a function.
226 #
227 # The result of this is that in theory you can put together an arbritrarily complex 
228 # expression involving the things you can filter on including 'and' 'or' 'not' and 
229 # 'brackets'.
230 #
231 # eg:-
232 #
233 # accept/spots hf and by_zone 14,15,16 and not by pa,on
234 #  
235 # accept/spots freq 0/30000 and by_zone 4,5
236
237 # accept/spots 2 vhf and (by_zone 14,15,16 or call_dxcc 61) 
238 #
239 # no filter no implies filter 1
240 #
241 # The field nos are the same as for the 'Old' filters
242 #
243
244
245 sub it
246 {
247         my $self = shift;
248         
249         my $filter;
250         my @keys = sort $self->getfilkeys;
251         my $key;
252         my $type = 'Dunno';
253         my $asc = '?';
254
255         my $r = @keys > 0 ? 0 : 1;
256         foreach $key (@keys) {
257                 $filter = $self->{$key};
258                 if ($filter->{reject} && exists $filter->{reject}->{code}) {
259                         $type = 'reject';
260                         $asc = $filter->{reject}->{user};
261                         if (&{$filter->{reject}->{code}}(ref $_[0] ? $_[0] : \@_)) {
262                                 $r = 0;
263                                 last;
264                         } else {
265                                 $r = 1;
266                         }               
267                 }
268                 if ($filter->{accept} && exists $filter->{accept}->{code}) {
269                         $type = 'accept';
270                         $asc = $filter->{accept}->{user};
271                         if (&{$filter->{accept}->{code}}(ref $_[0] ? $_[0] : \@_)) {
272                                 $r = 1;
273                                 last;
274                         } else {
275                                 $r = 0;
276                         }                       
277                 } 
278         }
279
280         # hops are done differently (simply) 
281         my $hops = $self->{hops} if exists $self->{hops};
282
283         if (isdbg('filter')) {
284                 my $call = $self->{name};
285                 my $args = join '\',\'', map {defined $_ ? $_ : 'undef'} (ref $_[0] ? @{$_[0]} : @_);
286                 my $true = $r ? "OK " : "REJ";
287                 my $sort = $self->{sort};
288                 my $dir = $self->{name} =~ /^in_/i ? "IN " : "OUT";
289
290                 $call =~ s/\.PL$//i;
291                 my $h = $hops || '';
292                 dbg("Filter: $call $true $dir: $type/$sort with '$asc' on '$args' $h") if isdbg('filter');
293         }
294         return ($r, $hops);
295 }
296
297 sub print
298 {
299         my $self = shift;
300         my $name = shift || $self->{name};
301         my $sort = shift || $self->{sort};
302         my $flag = shift || "";
303         my @out;
304         $name =~ s/.pl$//;
305         
306         push @out, join(' ',  $name , ':', $sort, $flag);
307         my $filter;
308         my $key;
309         foreach $key (sort $self->getfilkeys) {
310                 my $filter = $self->{$key};
311                 if (exists $filter->{reject} && exists $filter->{reject}->{user}) {
312                         push @out, ' ' . join(' ', $key, 'reject', $filter->{reject}->{user});
313                 }
314                 if (exists $filter->{accept} && exists $filter->{accept}->{user}) {
315                         push @out, ' ' . join(' ', $key, 'accept', $filter->{accept}->{user});
316                 } 
317         }
318         return @out;
319 }
320
321 sub install
322 {
323         my $self = shift;
324         my $remove = shift;
325         my $name = uc $self->{name};
326         my $sort = $self->{sort};
327         my $in = "";
328         $in = "in" if $name =~ s/^IN_//;
329         $name =~ s/.PL$//;
330         my $nossid = $name;
331         $nossid =~ s/-\d+$//;
332         my $dxchan = shift;
333
334         my @dxchan;
335         if ($name eq 'NODE_DEFAULT') {
336                 @dxchan = DXChannel::get_all_nodes();
337         } elsif ($name eq 'USER_DEFAULT') {
338                 @dxchan = DXChannel::get_all_users();
339         } elsif ($dxchan) {
340                 push @dxchan, $dxchan;
341         } else {
342                 $dxchan = DXChannel::get($name);
343                 push @dxchan, $dxchan if $dxchan;
344         }
345         foreach $dxchan (@dxchan) {
346                 my $n = "$in$sort" . "filter";
347                 my $i = $in ? 'IN_' : '';
348                 if ($remove) {
349                         $dxchan->{$n} = undef;
350                 }
351                 Filter::load_dxchan($dxchan, $sort, $in);
352         }
353 }
354
355 # This simply fixes up an existing (or recently modified) Filter into
356 # an existing dxchan
357 sub load_dxchan
358 {
359         my $dxchan = shift;
360         my $sort = lc shift;
361         my $in = shift;
362         $in = $in ? 'in' : '';          # to cope with older perls that did not like a ternary expression with 'shift' as a conditional
363         my $nossid = $dxchan->call;
364         $nossid =~ s/-\d+$//;
365         my $n = "$in$sort" . "filter";
366         
367         $dxchan->{$n} =
368                 Filter::read_in($sort, $dxchan->call,  $in)     ||
369                         Filter::read_in($sort, $nossid,  $in) ||
370                                 Filter::read_in($sort, $dxchan->is_user ? 'user_default' : 'node_default', $in);
371 }
372
373 sub delete
374 {
375         my ($sort, $call, $flag, $fno, $dxchan) = @_;
376         
377         # look for the file
378         my $fn = getfn($sort, $call, $flag);
379         my $filter = read_in($sort, $call, $flag);
380         if ($filter) {
381                 if ($fno eq 'all') {
382                         my $key;
383                         foreach $key ($filter->getfilkeys) {
384                                 delete $filter->{$key};
385                         }
386                         delete $filter->{getfilkeys};
387                 } elsif (exists $filter->{"filter$fno"}) {
388                         delete $filter->{"filter$fno"}; 
389                 }
390                 
391                 # get rid 
392                 if ($filter->{hops} || $filter->getfilkeys) {
393                         $filter->write;
394                         Filter::load_dxchan($dxchan, $sort, $in);
395                 } else {
396                         unlink $fn;
397                         $filter->install(1, $dxchan);
398                 }
399         }
400 }
401
402
403
404 package Filter::Cmd;
405
406 use strict;
407 use DXVars;
408 use DXUtil;
409 use DXDebug;
410 use vars qw(@ISA);
411 @ISA = qw(Filter);
412
413 sub encode_regex
414 {
415         my $s = shift;
416         $s =~ s/\{(.*?)\}/'{'. unpack('H*', $1) . '}'/eg if $s;
417         return $s;
418 }
419
420 sub decode_regex
421 {
422         my $r = shift;
423         my ($v) = $r =~ /^\{(.*?)}$/;
424         return pack('H*', $v);
425 }
426
427
428 # the general purpose command processor
429 # this is called as a subroutine not as a method
430 sub parse
431 {
432         my ($self, $dxchan, $sort, $line, $forcenew) = @_;
433         my $ntoken = 0;
434         my $fno = 1;
435         my $filter;
436         my ($flag, $call);
437         my $s;
438         my $user = '';
439         
440         # check the line for non legal characters
441         dbg("Filter::parse line: '$line'") if isdbg('filter');
442         my @ch = $line =~ m|([^\s\w,_\.:\/\-\*\(\)\$!])|g;
443         return ('ill', $dxchan->msg('e19', join(' ', @ch))) if $line !~ /{.*}/ && @ch;
444
445         $line = lc $line;
446
447         # disguise regexes
448
449         dbg("Filter parse line after regex check: '$line'") if isdbg('filter');
450         $line = encode_regex($line);
451         
452         # add some spaces for ease of parsing
453         $line =~ s/([\(\!\)])/ $1 /g;
454         
455         my @f = split /\s+/, $line;
456         dbg("filter parse: tokens '" . join("' '", @f) . "'") if isdbg('filter');
457         
458         my $lasttok = '';
459         while (@f) {
460                 if ($ntoken == 0) {
461                         
462                         if (!$forcenew &&  @f && $dxchan->priv >= 8 && ((is_callsign(uc $f[0]) && DXUser::get(uc $f[0])) || $f[0] =~ /(?:node|user)_default/)) {
463                                 $call = shift @f;
464                                 if ($f[0] eq 'input') {
465                                         shift @f;
466                                         $flag++;
467                                 }
468                         } else {
469                                 $call = $dxchan->call;
470                         }
471
472                         if (@f && $f[0] =~ /^\d$/) {
473                                 $fno = shift @f;
474                         }
475
476                         $filter = Filter::read_in($sort, $call, $flag) unless $forcenew;
477                         $filter = Filter->new($sort, $call, $flag) if !$filter || $filter->isa('Filter::Old');
478                         
479                         $ntoken++;
480                         next;
481                 }
482
483                 # do the rest of the filter tokens
484                 if (@f) {
485                         my $tok = shift @f;
486
487                         dbg("filter::parse: tok '$tok'") if isdbg('filter');
488                         
489                         if ($tok eq 'all') {
490                                 $s .= '1';
491                                 $user .= $tok;
492                                 last;
493                         } elsif (grep $tok eq $_, qw{and or not ( )}) {
494                                 $s .= ' && ' if $tok eq 'and';
495                                 $s .= ' || ' if $tok eq 'or';
496                                 $s .= ' !' if $tok eq 'not';
497                                 $s .=  $tok if $tok eq '(' or $tok eq ')';
498                                 $user .= " $tok ";
499                                 next;
500                         } elsif ($tok eq '') {
501                                 next;
502                         }
503                         
504                         if (@f) {
505                                 my $val = shift @f;
506                                 my @val = split /,/, $val;
507
508                                 dbg("filter::parse: tok '$tok' val '$val'") if isdbg('filter');
509                                 $user .= " $tok $val";
510                                 
511                                 my $fref;
512                                 my $found;
513                                 foreach $fref (@$self) {
514                                         
515                                         if ($fref->[0] eq $tok) {
516                                                 if ($fref->[4]) {
517                                                         my @nval;
518                                                         for (@val) {
519                                                                 push @nval, split(',', &{$fref->[4]}($dxchan, $_));
520                                                         }
521                                                         @val = @nval;
522                                                 }
523                                                 if ($fref->[1] eq 'a' || $fref->[1] eq 't') {
524                                                         my @t;
525                                                         foreach my $v (@val) {
526                                                                 $v =~ s/\*//g;        # remove any trailing *
527                                                                 if (my ($r) = $v =~ /^\{(.*)\}$/) { # we have a regex
528                                                                         dbg("Filter::parse regex b: '\{$r\}'") if isdbg('filter'); 
529                                                                         $v = decode_regex($v);
530                                                                         dbg("Filter::parse regex a: '$v'") if isdbg('filter'); 
531                                                                         return  ('regex', $dxchan->msg('e38', $v)) unless (qr{$v});
532                                                                         push @t, "\$r->[$fref->[2]]=~m{$v}i";
533                                                                         $v = "{$r}"; # put it back together again for humans
534                                                                 } else {
535                                                                         push @t, "\$r->[$fref->[2]]=~m{$v}i";
536                                                                 }
537                                                         }
538                                                         $s .= "(" . join(' || ', @t) . ")";
539                                                         dbg("filter parse: s '$s'") if isdbg('filter');
540                                                 } elsif ($fref->[1] eq 'c') {
541                                                         my @t;
542                                                         for (@val) {
543                                                                 s/\*//g;
544                                                                 push @t, "\$r->[$fref->[2]]=~m{^\U$_}";
545                                                         }
546                                                         $s .= "(" . join(' || ', @t) . ")";
547                                                         dbg("filter parse: s '$s'") if isdbg('filter');
548                                                 } elsif ($fref->[1] eq 'n') {
549                                                         my @t;
550                                                         for (@val) {
551                                                                 return ('num', $dxchan->msg('e21', $_)) unless /^\d+$/;
552                                                                 push @t, "\$r->[$fref->[2]]==$_";
553                                                         }
554                                                         $s .= "(" . join(' || ', @t) . ")";
555                                                         dbg("filter parse: s '$s'") if isdbg('filter');
556                                                 } elsif ($fref->[1] =~ /^n[ciz]$/ ) {    # for DXCC, ITU, CQ Zone    
557                                                         my $cmd = $fref->[1];
558                                                         my @pre = Prefix::to_ciz($cmd, @val);
559                                                         return ('numpre', $dxchan->msg('e27', $_)) unless @pre;
560                                                         $s .= "(" . join(' || ', map {"\$r->[$fref->[2]]==$_"} @pre) . ")";
561                                                         dbg("filter parse: s '$s'") if isdbg('filter');
562                                                 } elsif ($fref->[1] =~ /^ns$/ ) {    # for DXCC, ITU, CQ Zone    
563                                                         my $cmd = $fref->[1];
564                                                         my @pre = Prefix::to_ciz($cmd, @val);
565                                                         return ('numpre', $dxchan->msg('e27', $_)) unless @pre;
566                                                         $s .= "(" . "!\$USDB::present || grep \$r->[$fref->[2]] eq \$_, qw(" . join(' ' ,map {uc} @pre) . "))";
567                                                         dbg("filter parse: s '$s'") if isdbg('filter');
568                                                 } elsif ($fref->[1] eq 'r') {
569                                                         my @t;
570                                                         for (@val) {
571                                                                 return ('range', $dxchan->msg('e23', $_)) unless /^(\d+)\/(\d+)$/;
572                                                                 push @t, "(\$r->[$fref->[2]]>=$1 && \$r->[$fref->[2]]<=$2)";
573                                                         }
574                                                         $s .= "(" . join(' || ', @t) . ")";
575                                                         dbg("filter parse: s '$s'") if isdbg('filter');
576                                                 } else {
577                                                         confess("invalid filter function $fref->[1]");
578                                                 }
579                                                 ++$found;
580                                                 last;
581                                         }
582                                 }
583                                 return (1, $dxchan->msg('e20', $tok)) unless $found;
584                         } else {
585                                 $s = $tok =~ /^{.*}$/ ? '{' . decode_regex($tok) . '}' : $tok;
586                                 return (1, $dxchan->msg('filter2', $s));
587                         }
588                         $lasttok = $tok;
589                 }
590         }
591
592         # tidy up the user string (why I have to stick in an if statement when I have initialised it I have no idea! 5.28 bug)?
593         if ($user) {
594                 $user =~ s/\)\s*\(/ and /g;
595                 $user =~ s/\&\&/ and /g;
596                 $user =~ s/\|\|/ or /g;
597                 $user =~ s/\!/ not /g;
598                 $user =~ s/\s+/ /g;
599                 $user =~ s/\{(.*?)\}/'{'. pack('H*', $1) . '}'/eg;
600                 $user =~ s/^\s+//;
601                 dbg("filter parse: user '$user'") if isdbg('filter');
602         }
603
604         if ($s) {
605                 $s =~ s/\)\s*\(/ && /g;
606                 dbg("filter parse: s '$s'") if isdbg('filter');
607         }
608
609         
610         return (0, $filter, $fno, $user, $s);
611 }
612
613 # a filter accept/reject command
614 sub cmd
615 {
616         my ($self, $dxchan, $sort, $type, $line) = @_;
617         return $dxchan->msg('filter5') unless $line;
618
619         my ($r, $filter, $fno, $user, $s) = $self->parse($dxchan, $sort, $line);
620         return (1, $filter) if $r;
621         
622         my $u = DXUser::get_current($user);
623         return (1, $dxchan->msg('isow', $user)) if $u && $u->isolate;
624
625         my $fn = "filter$fno";
626
627         $filter->{$fn} = {} unless exists $filter->{$fn};
628         $filter->{$fn}->{$type} = {} unless exists $filter->{$fn}->{$type};
629
630         $filter->{$fn}->{$type}->{user} = $user;
631         $filter->{$fn}->{$type}->{asc} = $s;
632         $r = $filter->compile($fn, $type);   # NOTE: returns an ERROR, therefore 0 = success
633         return (0,$r) if $r;
634         
635         $r = $filter->write;
636         return (1,$r) if $r;
637
638         $filter->install(1);            # 'delete'
639         $filter->install;
640
641     return (0, $filter, $fno);
642 }
643
644 package Filter::Old;
645
646 use strict;
647 use DXVars;
648 use DXUtil;
649 use DXDebug;
650 use vars qw(@ISA);
651 @ISA = qw(Filter);
652
653 # the OLD instructions!
654 #
655 # Each filter file has the same structure:-
656 #
657 # <some comment>
658 # @in = (
659 #      [ action, fieldno, fieldsort, comparison, action data ],
660 #      ...
661 # );
662 #
663 # The action is usually 1 or 0 but could be any numeric value
664 #
665 # The fieldno is the field no in the list of fields that is presented
666 # to 'Filter::it' 
667 #
668 # The fieldsort is the type of field that we are dealing with which 
669 # currently can be 'a', 'n', 'r' or 'd'.
670 #    'a' is alphanumeric
671 #    'n' is# numeric
672 #    'r' is ranges of pairs of numeric values
673 #    'd' is default (effectively, don't filter)
674 #
675 # Filter::it basically goes thru the list of comparisons from top to
676 # bottom and when one matches it will return the action and the action data as a list. 
677 # The fields
678 # are the element nos of the list that is presented to Filter::it. Element
679 # 0 is the first field of the list.
680 #
681
682 #
683 # takes the reference to the filter (the first argument) and applies
684 # it to the subsequent arguments and returns the action specified.
685 #
686 sub it
687 {
688         my $self = shift;
689         my $filter = $self->{filter};            # this is now a bless ref of course but so what
690         
691         my ($action, $field, $fieldsort, $comp, $actiondata);
692         my $ref;
693
694         # default action is 1
695         $action = 1;
696         $actiondata = "";
697         return ($action, $actiondata) if !$filter;
698
699         for $ref (@{$filter}) {
700                 ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref};
701                 if ($fieldsort eq 'n') {
702                         my $val = $_[$field];
703                         return ($action, $actiondata)  if grep $_ == $val, @{$comp};
704                 } elsif ($fieldsort eq 'r') {
705                         my $val = $_[$field];
706                         my $i;
707                         my @range = @{$comp};
708                         for ($i = 0; $i < @range; $i += 2) {
709                                 return ($action, $actiondata)  if $val >= $range[$i] && $val <= $range[$i+1];
710                         }
711                 } elsif ($fieldsort eq 'a') {
712                         return ($action, $actiondata)  if $_[$field] =~ m{$comp}i;
713                 } else {
714                         return ($action, $actiondata);      # the default action (just pass through)
715                 }
716         }
717 }
718
719 sub print
720 {
721         my $self = shift;
722         my $call = shift;
723         my $sort = shift;
724         my $flag = shift || "";
725         return "$call: Old Style Filter $flag $sort";
726 }
727
728 1;
729 __END__