Named arguments to Shorewall::Compiler::compiler()

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@7826 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-12-05 00:14:30 +00:00
parent dea79aa763
commit 20bedd04d7
4 changed files with 94 additions and 20 deletions

View File

@ -95,6 +95,36 @@ Other changes in Shorewall 4.1.2.
The --log option is ignored when --log_verbosity is not supplied or
is supplied with value -1.
To avoid a proliferation of parameters to
Shorewall::Compiler::compile(), that function has been changed to
use named parameters. Parameter names are:
object Object file. If omitted or '', the
configuration is syntax checked.
directory Directory. If omitted or '', configuration
files are located using
CONFIG_PATH. Otherwise, the directory named by
this parameter is searched first.
verbosity Verbosity; range -1 to 2
timestamp 0|1 -- timestamp messages.
debug 0|1 -- include stack trace in warning/error
messages.
export 0|1 -- compile for export.
chains List of chains to be reloaded by 'refresh'.
log File to log compiler messages to.
log_verbosity Log Verbosity; range -1 to 2.
Those parameters that are supplied must have defined values.
Example:
use lib '/usr/share/shorewall-perl/';
use Shorewall::Compiler;
compiler( object => '/root/firewall',
log => '/root/compile.log',
log_verbosity => 2 );
2) Previously, when HIGH_ROUTE_MARKS=Yes, Shorewall allowed non-zero
mark values < 256 to be assigned in the OUTPUT chain. This has been
changed so that only high mark values may be assigned

View File

@ -701,12 +701,44 @@ EOF
# If the first argument is non-null, it names the script file to generate.
# Otherwise, this is a 'check' command and no script is produced.
#
sub compiler( $$$$$$$ ) {
sub compiler {
my ( $objectfile, $directory, $verbosity, $options , $chains , $log , $log_verbosity ) = @_;
my ( $objectfile, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity ) =
( '', '', -1, '', 0, '', '', -1 );
$export = 0;
sub edit_boolean( $ ) {
my $val = numeric_value1( shift );
defined $val && $val >= 0 && $val < 2;
}
sub edit_verbosity( $ ) {
my $val = numeric_value1( shift );
defined $val && $val >= -1 && $val < 3;
}
my %elbat = ( object => { store => \$objectfile },
directory => { store => \$directory },
verbosity => { store => \$verbosity , edit => \&edit_verbosity } ,
timestamp => { store => \$timestamp, edit => \&edit_boolean } ,
debug => { store => \$debug, edit => \&edit_boolean } ,
export => { store => \$export , edit => \&edit_boolean } ,
chains => { store => \$chains },
log => { store => \$log },
log_verbosity => { store => \$log_verbosity, edit => \&edit_verbosity } ,
);
while ( defined ( my $name = shift ) ) {
fatal_error "Unknown parameter ($name)" unless my $ref = $elbat{$name};
fatal_error "Undefined value supplied for parameter $name" unless defined ( my $val = shift ) ;
if ( $ref->{edit} ) {
fatal_error "Invalid value ( $val ) supplied for parameter $name" unless $ref->{edit}->($val);
}
${$ref->{store}} = $val;
}
reinitialize if $reused++;
if ( $directory ne '' ) {
@ -714,11 +746,10 @@ sub compiler( $$$$$$$ ) {
set_shorewall_dir( $directory );
}
set_verbose( $verbosity ) unless $verbosity eq '';
set_verbose( $verbosity );
set_log($log, $log_verbosity) if $log;
$export = 1 if $options & EXPORT;
set_timestamp( 1 ) if $options & TIMESTAMP;
set_debug( 1 ) if $options & DEBUG;
set_timestamp( $timestamp );
set_debug( $debug );
#
# Get shorewall.conf and capabilities.
#

View File

@ -55,6 +55,7 @@ our @EXPORT_OK = qw( $shorewall_dir initialize read_a_line1 set_config_path shor
our %EXPORT_TAGS = ( internal => [ qw( create_temp_object
finalize_object
numeric_value
numeric_value1
emit
emit_unindented
save_progress_message
@ -510,6 +511,12 @@ sub numeric_value ( $ ) {
$mark =~ /^0/ ? oct $mark : $mark;
}
sub numeric_value1 ( $ ) {
my $mark = lc $_[0];
return undef unless $mark =~ /^-?(0x[a-f0-9]+|0[0-7]*|[1-9]\d*)$/;
$mark =~ /^0/ ? oct $mark : $mark;
}
#
# Write the arguments to the object file (if any) with the current indentation.
#

View File

@ -42,7 +42,7 @@ use lib "$FindBin::Bin";
use Shorewall::Compiler;
use Getopt::Long;
sub usage() {
sub usage( $ ) {
print STDERR 'usage: compiler.pl [ <option> ... ] <filename> ]
options are:
@ -55,7 +55,7 @@ sub usage() {
[ --log=<filename> ]
[ --log-verbose={-1|0-2} ]
';
exit 1;
exit shift @_;
}
#
@ -64,15 +64,18 @@ sub usage() {
my $export = 0;
my $shorewall_dir = '';
my $verbose = 0;
my $timestamp = '';
my $timestamp = 0;
my $debug = 0;
my $chains = '';
my $log = '';
my $log_verbose = 0;
my $help = 0;
Getopt::Long::Configure ('bundling');
my $result = GetOptions('export' => \$export,
my $result = GetOptions('h' => \$help,
'--help' => \$help,
'export' => \$export,
'e' => \$export,
'directory=s' => \$shorewall_dir,
'd=s' => \$shorewall_dir,
@ -88,12 +91,15 @@ my $result = GetOptions('export' => \$export,
'log_verbosity=i' => \$log_verbose,
);
usage unless $result && @ARGV < 2;
usage(1) unless $result && @ARGV < 2;
usage(0) if $help;
my $options = 0;
$options |= EXPORT if $export;
$options |= TIMESTAMP if $timestamp;
$options |= DEBUG if $debug;
compiler $ARGV[0], $shorewall_dir, $verbose, $options, $chains, $log , $log_verbose;
compiler( object => defined $ARGV[0] ? $ARGV[0] : '',
directory => $shorewall_dir,
verbosity => $verbose,
timestamp => $timestamp,
debug => $debug,
export => $export,
chains => $chains,
log => $log,
log_verbosity => $log_verbose );