Extantiate params during module processing

This commit is contained in:
Tom Eastep 2010-12-25 14:48:14 -08:00
parent bdc3ca16a4
commit 758a50fa84
2 changed files with 39 additions and 1 deletions

View File

@ -96,6 +96,8 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
close_file close_file
push_open push_open
pop_open pop_open
push_params
pop_params
read_a_line read_a_line
validate_level validate_level
which which
@ -274,6 +276,10 @@ our @openstack;
# From the params file # From the params file
# #
our %params; our %params;
#
# Action parameters
#
our %actparms;
our $currentline; # Current config file line image our $currentline; # Current config file line image
our $currentfile; # File handle reference our $currentfile; # File handle reference
@ -717,6 +723,8 @@ sub initialize( $ ) {
command => '', command => '',
files => '', files => '',
destination => '' ); destination => '' );
%actparms = ();
} }
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
@ -1781,6 +1789,27 @@ sub embedded_perl( $ ) {
} }
} }
#
# Push/pop action params
#
sub push_params( $ ) {
my @params = split /,/, $_[0];
my $oldparams = \%actparms;
%actparms = ();
for ( my $i = 1; $i <= @params; $i++ ) {
$actparms{$i} = $params[$i - 1];
}
$oldparams;
}
sub pop_params( $ ) {
my $oldparms = shift;
%actparms = %$oldparms;
}
# #
# Read a line from the current include stack. # Read a line from the current include stack.
# #
@ -1866,7 +1895,8 @@ sub read_a_line(;$) {
$params{$3} = $ENV{$3} if exists $ENV{$3}; $params{$3} = $ENV{$3} if exists $ENV{$3};
} }
my $val = $params{$3};
my $val = exists $params{$3} ? $params{$3} : $actparms{$3};
unless ( defined $val ) { unless ( defined $val ) {
fatal_error "Undefined shell variable (\$$3)" unless exists $params{$3} || exists $ENV{$3}; fatal_error "Undefined shell variable (\$$3)" unless exists $params{$3} || exists $ENV{$3};

View File

@ -279,6 +279,8 @@ sub process_action2( $ ) {
push_open( $actionfile ); push_open( $actionfile );
my $oldparms = push_params( $param );
while ( read_a_line ) { while ( read_a_line ) {
my ($wholetarget, @rest ) = split_line1 1, 13, 'action file' , $rule_commands; my ($wholetarget, @rest ) = split_line1 1, 13, 'action file' , $rule_commands;
@ -309,6 +311,8 @@ sub process_action2( $ ) {
pop_open; pop_open;
--$action_nest_level; --$action_nest_level;
pop_params( $oldparms );
} }
sub process_actions1() { sub process_actions1() {
@ -398,6 +402,8 @@ sub process_action3( $$$$$$ ) {
open_file $actionfile; open_file $actionfile;
my $oldparms = push_params( $param );
while ( read_a_line ) { while ( read_a_line ) {
my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers ); my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers );
@ -424,6 +430,8 @@ sub process_action3( $$$$$$ ) {
} }
clear_comment; clear_comment;
pop_params( $oldparms );
} }
# #