+sub getfilters
+{
+ my $self = shift;
+ my @out;
+ my $key;
+ foreach $key (grep {/^filter/ } keys %$self) {
+ push @out, $self->{$key};
+ }
+ return @out;
+}
+
+sub getfilkeys
+{
+ my $self = shift;
+ return grep {/^filter/ } keys %$self;
+}
+
+#
+# This routine accepts a composite filter with a reject rule and then an accept rule.
+#
+# The filter returns 0 if an entry is matched by any reject rule and also if any
+# accept rule fails otherwise it returns 1
+#
+# Either set of rules may be missing meaning an implicit 'opposite' ie if it
+# a reject then ok else if an accept then not ok.
+#
+# you can set a default with either an accept/xxxx all or reject/xxxx all
+#
+# Unlike the old system, this is kept as a hash of hashes so that you can
+# easily change them by program.
+#
+# You can have 10 filter lines (0->9), they are tried in order until
+# one matches
+#
+# There is a parser that takes a Filter::Cmd object which describes all the possible
+# things you can filter on and then converts that to a bit of perl which is compiled
+# and stored as a function.
+#
+# The result of this is that in theory you can put together an arbritrarily complex
+# expression involving the things you can filter on including 'and' 'or' 'not' and
+# 'brackets'.
+#
+# eg:-
+#
+# accept/spots hf and by_zone 14,15,16 and not by pa,on
+#
+# accept/spots freq 0/30000 and by_zone 4,5
+#
+# accept/spots 2 vhf and (by_zone 14,15,16 or call_dxcc 61)
+#
+# no filter no implies filter 1
+#
+# The field nos are the same as for the 'Old' filters
+#
+#
+
+sub it
+{
+ my $self = shift;
+
+ my $filter;
+ my @keys = sort $self->getfilkeys;
+ my $key;
+ my $type = 'Dunno';
+ my $asc = '?';
+
+ my $r = @keys > 0 ? 0 : 1;
+ foreach $key (@keys) {
+ $filter = $self->{$key};
+ if ($filter->{reject} && exists $filter->{reject}->{code}) {
+ $type = 'reject';
+ $asc = $filter->{reject}->{user};
+ if (&{$filter->{reject}->{code}}(\@_)) {
+ $r = 0;
+ last;
+ } else {
+ $r = 1;
+ }
+ }
+ if ($filter->{accept} && exists $filter->{accept}->{code}) {
+ $type = 'accept';
+ $asc = $filter->{accept}->{user};
+ if (&{$filter->{accept}->{code}}(\@_)) {
+ $r = 1;
+ last;
+ } else {
+ $r = 0;
+ }
+ }
+ }
+
+ # hops are done differently (simply)
+ my $hops = $self->{hops} if exists $self->{hops};
+
+ if (isdbg('filter')) {
+ my $args = join '\',\'', @_;
+ my $true = $r ? "OK " : "REJ";
+ my $sort = $self->{sort};
+ my $dir = $self->{name} =~ /^in_/i ? "IN " : "OUT";
+
+ my $h = $hops || '';
+ dbg("$true $dir: $type/$sort with $asc on '$args' $h") if isdbg('filter');
+ }
+ return ($r, $hops);
+}
+