2 # The User/Sysop Filter module
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.
8 # This set of routines provide a means of maintaining the filter
9 # scripts which are compiled in when an entity connects.
11 # Copyright (c) 1999 Dirk Koopman G1TLH
15 # The NEW INSTRUCTIONS
17 # use the commands accept/spot|ann|wwv|wcy and reject/spot|ann|wwv|wcy
18 # also show/filter spot|ann|wwv|wcy
20 # The filters live in a directory tree of their own in $main::root/filter
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.
36 use vars qw ($filterbasefn $in);
38 $filterbasefn = "$main::root/filter";
41 # initial filter system
48 # this reads in a filter statement and returns it as a list
50 # The filter is stored in straight perl so that it can be parsed and read
51 # in with a 'do' statement. The 'do' statement reads the filter into
52 # @in which is a list of references
56 my ($sort, $call, $flag) = @_;
59 $flag = ($flag) ? "in_" : "";
61 my $fn = "$filterbasefn/$sort/$flag$call.pl";
66 $fn = "$filterbasefn/$sort/$flag$call.pl";
72 my $s = readfilestr($fn);
74 dbg('conn', "$@") if $@;
76 $newin = bless {filter => $in, name => "$flag$call.pl" }, 'Filter::Old'
83 # this writes out the filter in a form suitable to be read in by 'read_in'
84 # It expects a list of references to filter lines
102 # the OLD instructions!
104 # Each filter file has the same structure:-
108 # [ action, fieldno, fieldsort, comparison, action data ],
112 # The action is usually 1 or 0 but could be any numeric value
114 # The fieldno is the field no in the list of fields that is presented
117 # The fieldsort is the type of field that we are dealing with which
118 # currently can be 'a', 'n', 'r' or 'd'. 'a' is alphanumeric, 'n' is
119 # numeric, 'r' is ranges of pairs of numeric values and 'd' is default.
121 # Filter::it basically goes thru the list of comparisons from top to
122 # bottom and when one matches it will return the action and the action data as a list.
124 # are the element nos of the list that is presented to Filter::it. Element
125 # 0 is the first field of the list.
129 # takes the reference to the filter (the first argument) and applies
130 # it to the subsequent arguments and returns the action specified.
135 my $filter = $self->{filter}; # this is now a bless ref of course but so what
137 my ($action, $field, $fieldsort, $comp, $actiondata);
140 # default action is 1
143 return ($action, $actiondata) if !$filter;
145 for $ref (@{$filter}) {
146 ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref};
147 if ($fieldsort eq 'n') {
148 my $val = $_[$field];
149 return ($action, $actiondata) if grep $_ == $val, @{$comp};
150 } elsif ($fieldsort eq 'r') {
151 my $val = $_[$field];
153 my @range = @{$comp};
154 for ($i = 0; $i < @range; $i += 2) {
155 return ($action, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1];
157 } elsif ($fieldsort eq 'a') {
158 return ($action, $actiondata) if $_[$field] =~ m{$comp};
160 return ($action, $actiondata); # the default action