use DXUtil;
use DXDebug;
use Data::Dumper;
+use Prefix;
use strict;
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
use vars qw ($filterbasefn $in);
$filterbasefn = "$main::root/filter";
my $rr;
if ($ref->{$ar} && exists $ref->{$ar}->{asc}) {
- $ref->{$ar}->{code} = eval "sub { my \$r=shift; return $ref->{$ar}->{asc}; }" ;
+ my $s = $ref->{$ar}->{asc}; # an optimisation?
+ $s =~ s/\$r/\$_[0]/g;
+ $ref->{$ar}->{code} = eval "sub { $s }" ;
if ($@) {
my $sort = $ref->{sort};
my $name = $ref->{name};
- dbg('err', "Error compiling $ar $sort $name: $@");
+ dbg("Error compiling $ar $sort $name: $@");
Log('err', "Error compiling $ar $sort $name: $@");
}
$rr = $@;
$in = undef;
my $s = readfilestr($fn);
my $newin = eval $s;
- dbg('conn', "$@") if $@;
+ dbg($@) if $@;
if ($in) {
$newin = new('Filter::Old', $sort, $call, $flag);
$newin->{filter} = $in;
{
my $self = shift;
- my $hops = undef;
-
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;
}
}
if ($filter->{accept} && exists $filter->{accept}->{code}) {
+ $type = 'accept';
+ $asc = $filter->{accept}->{user};
if (&{$filter->{accept}->{code}}(\@_)) {
$r = 1;
last;
}
}
- # hops are done differently
- if ($self->{hops}) {
- my ($comp, $ref);
- while (($comp, $ref) = each %{$self->{hops}}) {
- my ($field, $h) = @$ref;
- if ($_[$field] =~ m{$comp}) {
- $hops = $h;
- last;
- }
- }
+ # hops are done differently (simply)
+ my $hops = $self->{hops} if exists $self->{hops};
+
+ if (isdbg('filter')) {
+ my $args = join '\',\'', map {defined $_ ? $_ : 'undef'} @_;
+ 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);
}
my $remove = shift;
my $name = uc $self->{name};
my $sort = $self->{sort};
- my ($in) = $name =~ s/^IN_//;
+ my $in = "";
+ $in = "in" if $name =~ s/^IN_//;
$name =~ s/.PL$//;
- my $dxchan = DXChannel->get($name);
- if ($dxchan) {
- $in = lc $in if $in;
+ my $dxchan;
+ my @dxchan;
+ if ($name eq 'NODE_DEFAULT') {
+ @dxchan = DXChannel::get_all_nodes();
+ } elsif ($name eq 'USER_DEFAULT') {
+ @dxchan = DXChannel::get_all_users();
+ } else {
+ $dxchan = DXChannel->get($name);
+ push @dxchan, $dxchan if $dxchan;
+ }
+ foreach $dxchan (@dxchan) {
my $n = "$in$sort" . "filter";
- $dxchan->$n($remove ? undef : $self);
+ my $i = $in ? 'IN_' : '';
+ my $ref = $dxchan->$n();
+ if (!$ref || ($ref && uc $ref->{name} eq "$i$name.PL")) {
+ $dxchan->$n($remove ? undef : $self);
+ }
}
}
my $user;
# check the line for non legal characters
- return ('ill', $dxchan->msg('e19')) if $line =~ /[^\s\w,_\-\*\/\(\)]/;
+ return ('ill', $dxchan->msg('e19')) if $line =~ /[^\s\w,_\-\*\/\(\)!]/;
# add some spaces for ease of parsing
$line =~ s/([\(\)])/ $1 /g;
}
$filter = Filter::read_in($sort, $call, $flag);
- $filter = Filter->new($sort, $call, $flag) unless $filter;
+ $filter = Filter->new($sort, $call, $flag) if !$filter || $filter->isa('Filter::Old');
$ntoken++;
next;
if ($s) {
$s .= $conj ;
- $s .= $not;
$user .= $conj;
- $user .= $not;
$conj = ' && ';
- $not = "";
}
+
+ if ($not) {
+ $s .= $not;
+ $user .= $not;
+ $not = '';
+ }
+
$user .= "$tok $val";
my $fref;
push @t, "\$r->[$fref->[2]]==$_";
}
$s .= "(" . join(' || ', @t) . ")";
+ } elsif ($fref->[1] =~ /^n[ciz]$/ ) { # for DXCC, ITU, CQ Zone
+ my $cmd = $fref->[1];
+ my @pre = Prefix::to_ciz($cmd, @val);
+ return ('numpre', $dxchan->msg('e27', $_)) unless @pre;
+ $s .= "(" . join(' || ', map {"\$r->[$fref->[2]]==$_"} @pre) . ")";
+ } elsif ($fref->[1] =~ /^ns$/ ) { # for DXCC, ITU, CQ Zone
+ my $cmd = $fref->[1];
+ my @pre = Prefix::to_ciz($cmd, @val);
+ return ('numpre', $dxchan->msg('e27', $_)) unless @pre;
+ $s .= "(" . "!\$USDB::present || grep \$r->[$fref->[2]] eq \$_, qw(" . join(' ' ,map {uc} @pre) . "))";
} elsif ($fref->[1] eq 'r') {
my @t;
for (@val) {
push @t, "(\$r->[$fref->[2]]>=$1 && \$r->[$fref->[2]]<=$2)";
}
$s .= "(" . join(' || ', @t) . ")";
+ } elsif ($fref->[1] eq 't') {
+ my @t;
+ for (@val) {
+ s/\*//g;
+ push @t, "\$r->[$fref->[2]]=~/$_/i";
+ }
+ $s .= "(" . join(' || ', @t) . ")";
} else {
confess("invalid letter $fref->[1]");
}
return $dxchan->msg('filter5') unless $line;
my ($r, $filter, $fno, $user, $s) = $self->parse($dxchan, $sort, $line);
- return (1,$filter) if $r;
+ my $u = DXUser->get_current($user);
+ return (1, $dxchan->msg('isow', $user)) if $u && $u->isolate;
+ return (1, $filter) if $r;
my $fn = "filter$fno";