X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FFilter.pm;h=2be5cd5bbb48537ed6d7d05333b799389cbf8ba7;hb=e7a28420ced12c94812516b17194c997dcc759e9;hp=b71ee95a5b81833acb4a1fc566592b832071529f;hpb=ab811a0c902225075a9bd69749f65594079433a9;p=spider.git diff --git a/perl/Filter.pm b/perl/Filter.pm index b71ee95a..2be5cd5b 100644 --- a/perl/Filter.pm +++ b/perl/Filter.pm @@ -364,7 +364,7 @@ use vars qw(@ISA); # this is called as a subroutine not as a method sub parse { - my ($self, $dxchan, $sort, $line) = @_; + my ($self, $dxchan, $sort, $line, $forcenew) = @_; my $ntoken = 0; my $fno = 1; my $filter; @@ -373,7 +373,8 @@ sub parse my $user; # check the line for non legal characters - return ('ill', $dxchan->msg('e19')) if $line =~ /[^\s\w,_\-\*\/\(\)!]/; + dbg("Filter::parse line: '$line'") if isdbg('filter'); + return ('ill', $dxchan->msg('e19')) if $line !~ /{.*}/ && $line =~ /[^\s\w,_\-\*\/\(\)\$!]/; # add some spaces for ease of parsing $line =~ s/([\(\)])/ $1 /g; @@ -385,7 +386,7 @@ sub parse while (@f) { if ($ntoken == 0) { - if (@f && $dxchan->priv >= 8 && ((is_callsign(uc $f[0]) && DXUser::get(uc $f[0])) || $f[0] =~ /(?:node|user)_default/)) { + if (!$forcenew && @f && $dxchan->priv >= 8 && ((is_callsign(uc $f[0]) && DXUser::get(uc $f[0])) || $f[0] =~ /(?:node|user)_default/)) { $call = shift @f; if ($f[0] eq 'input') { shift @f; @@ -399,7 +400,7 @@ sub parse $fno = shift @f; } - $filter = Filter::read_in($sort, $call, $flag); + $filter = Filter::read_in($sort, $call, $flag) unless $forcenew; $filter = Filter->new($sort, $call, $flag) if !$filter || $filter->isa('Filter::Old'); $ntoken++; @@ -473,18 +474,23 @@ sub parse } @val = @nval; } - if ($fref->[1] eq 'a') { + if ($fref->[1] eq 'a' || $fref->[1] eq 't') { my @t; for (@val) { - s/\*//g; - push @t, "\$r->[$fref->[2]]=~/$_/i"; + s/\*//g; # remove any trailing * + if (/^\{.*\}$/) { # we have a regex + s/^\{//; + s/\}$//; + return ('regex', $dxchan->msg('e38', $_)) unless (qr{$_}) + } + push @t, "\$r->[$fref->[2]]=~m{$_}i"; } $s .= "(" . join(' || ', @t) . ")"; } elsif ($fref->[1] eq 'c') { my @t; for (@val) { s/\*//g; - push @t, "\$r->[$fref->[2]]=~/^\U$_/"; + push @t, "\$r->[$fref->[2]]=~m{^\U$_}"; } $s .= "(" . join(' || ', @t) . ")"; } elsif ($fref->[1] eq 'n') { @@ -511,15 +517,8 @@ sub parse 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]"); + confess("invalid filter function $fref->[1]"); } ++$found; last; @@ -539,7 +538,7 @@ sub parse $user =~ s/\!/ not /g; $user =~ s/\s+/ /g; - return (0, $filter, $fno, $user, "$s"); + return (0, $filter, $fno, $user, $s); } # a filter accept/reject command @@ -597,8 +596,11 @@ use vars qw(@ISA); # to 'Filter::it' # # The fieldsort is the type of field that we are dealing with which -# currently can be 'a', 'n', 'r' or 'd'. 'a' is alphanumeric, 'n' is -# numeric, 'r' is ranges of pairs of numeric values and 'd' is default. +# currently can be 'a', 'n', 'r' or 'd'. +# 'a' is alphanumeric +# 'n' is# numeric +# 'r' is ranges of pairs of numeric values +# 'd' is default (effectively, don't filter) # # Filter::it basically goes thru the list of comparisons from top to # bottom and when one matches it will return the action and the action data as a list. @@ -637,9 +639,9 @@ sub it return ($action, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1]; } } elsif ($fieldsort eq 'a') { - return ($action, $actiondata) if $_[$field] =~ m{$comp}; + return ($action, $actiondata) if $_[$field] =~ m{$comp}i; } else { - return ($action, $actiondata); # the default action + return ($action, $actiondata); # the default action (just pass through) } } }