From 0744df13d6fe0e5f820afdfdd43f471d3778ca06 Mon Sep 17 00:00:00 2001 From: teastep Date: Tue, 7 Apr 2009 03:22:30 +0000 Subject: [PATCH] Reimplement object_enable/disable Signed-off-by: Tom Eastep git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@9824 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall/Perl/Shorewall/Compiler.pm | 8 ++++++++ Shorewall/Perl/Shorewall/Config.pm | 29 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Shorewall/Perl/Shorewall/Compiler.pm b/Shorewall/Perl/Shorewall/Compiler.pm index 08105ecd0..36727bd31 100644 --- a/Shorewall/Perl/Shorewall/Compiler.pm +++ b/Shorewall/Perl/Shorewall/Compiler.pm @@ -640,6 +640,7 @@ sub compiler { setup_notrack; unless ( $command eq 'check' ) { + enable_object; # # Place Header in the object # @@ -682,6 +683,7 @@ sub compiler { unless ( $command eq 'check' ) { pop_indent; emit '}'; + disable_object; } # @@ -689,6 +691,8 @@ sub compiler { # (Writes the setup_routing_and_traffic_shaping() function to the compiled script) # unless ( $command eq 'check' ) { + enable_object; + emit( "\n#", '# Setup routing and traffic shaping', '#', @@ -709,6 +713,7 @@ sub compiler { unless ( $command eq 'check' ) { pop_indent; emit "}\n"; + disable_object; } # @@ -781,6 +786,7 @@ sub compiler { progress_message3 "Shorewall6 configuration verified"; } } else { + enable_object; # # I N I T I A L I Z E # (Writes the initialize() function to the compiled script) @@ -810,6 +816,8 @@ sub compiler { copy $globals{SHAREDIRPL} . 'prog.footer6'; } } + + disable_object; # # Close, rename and secure the object # diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 450a85566..591fcfc8a 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -56,6 +56,8 @@ our @EXPORT_OK = qw( $shorewall_dir initialize read_a_line1 set_config_path shor our %EXPORT_TAGS = ( internal => [ qw( create_temp_object finalize_object + enable_object + disable_object numeric_value numeric_value1 in_hex @@ -145,6 +147,10 @@ our $timestamp; # our $object; # +# When 'true', writes to the object are enabled. Used to catch code emission between functions +# +our $object_enabled; +# # True, if last line emitted is blank # our $lastlineblank; @@ -296,6 +302,7 @@ sub initialize( $ ) { $log_verbose = -1; # Verbosity of log. $timestamp = ''; # If true, we are to timestamp each progress message $object = 0; # Object (script) file Handle Reference + $object_enabled = 0; # Object (script) file Handle Reference $lastlineblank = 0; # Avoid extra blank lines in the output $indent1 = ''; # Current indentation tabs $indent2 = ''; # Current indentation spaces @@ -757,6 +764,8 @@ sub in_hex8( $ ) { # Replaces leading spaces with tabs as appropriate and suppresses consecutive blank lines. # sub emit { + assert( $object_enabled ); + if ( $object ) { # # 'compile' as opposed to 'check' @@ -781,6 +790,8 @@ sub emit { # Write passed message to the object with newline but no indentation. # sub emit_unindented( $ ) { + assert( $object_enabled ); + print $object "$_[0]\n" if $object; } @@ -972,6 +983,8 @@ sub pop_indent() { # Functions for copying files into the object # sub copy( $ ) { + assert( $object_enabled ); + if ( $object ) { my $file = $_[0]; @@ -1002,6 +1015,8 @@ sub copy( $ ) { # This one handles line continuation and 'here documents' sub copy1( $ ) { + assert( $object_enabled ); + if ( $object ) { my $file = $_[0]; @@ -1112,6 +1127,20 @@ sub finalize_aux_config() { progress_message3 "Shorewall configuration compiled to $file"; } +# +# Enable writes to the object file +# +sub enable_object() { + $object_enabled = 1; +} + +# +# Diusable writes to the object file +# +sub disable_object() { + $object_enabled = 0; +} + # # Set $config{CONFIG_PATH} #