This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 6a13ec94dc7e78580304862bd037e3d9de62475a Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 09:55:44 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: write wrapper that handles program options, creates intermediate, passes through transform chains, reconverts to a string and prints it. --- debian/changelog | 3 + x2goserver/lib/x2goupdateoptionsstring | 151 ++++++++++++++++++++++++++------- 2 files changed, 121 insertions(+), 33 deletions(-) diff --git a/debian/changelog b/debian/changelog index e7d59b9..d54fd18 100644 --- a/debian/changelog +++ b/debian/changelog @@ -46,6 +46,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: fix interpolated string warning. - x2goserver/lib/x2goupdateoptionsstring: add helper function for transform string interpretation. + - x2goserver/lib/x2goupdateoptionsstring: write wrapper that handles + program options, creates intermediate, passes through transform chains, + reconverts to a string and prints it. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goupdateoptionsstring b/x2goserver/lib/x2goupdateoptionsstring index 811bf6d..c562974 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -25,12 +25,19 @@ use warnings; #use X2Go::Utils qw (is_int); use English qw (-no_match_vars); -use Getopt::Long; +use Getopt::Long qw (GetOptionsFromArray); use Pod::Usage; use Storable qw (dclone); use Switch qw (fallthrough); use Data::Dumper qw (Dumper); +exit (Main (@ARGV)); + +BEGIN { +} + +# No code past this point should be getting executed! + # Accepts an option string and returns a reference to an array of hashes # (actually hash references) corresponding to the parsed key-value pairs. # @@ -661,59 +668,137 @@ sub interpret_transform { } } } + # Set up return value accordingly. $ret = [ $mode, $sanitized_transform ]; } + return $ret; } -Getopt::Long::Configure('gnu_getopt', 'no_auto_abbrev'); +# Main function, no code outside of it shall be executed. +# +# Expects @ARGV to be passed in. +sub Main { + my $error_detected = 0; -my $help = 0; -my $man = 0; -GetOptions('help|?|h' => \$help, 'man' => \$man) or pod2usage(2); -pod2usage(1) if $help; -pod2usage(-verbose => 2, -exitval => 0) if $man; + Getopt::Long::Configure ('gnu_getopt', 'no_auto_abbrev', 'pass_through'); -my $options = shift; + my $help = 0; + my $man = 0; + GetOptionsFromArray (\@_, 'help|?|h' => \$help, 'man' => \$man) or pod2usage (2); -my $intermediate = parse_options ($options); + if ($help) { + pod2usage (1); + } -print {*STDERR} Dumper ($intermediate) . "\n"; + if ($man) { + pod2usage (-verbose => 2, -exitval => 3); + } -print {*STDERR} Dumper (intermediate_to_string ($intermediate)) . "\n"; + my $options = shift; -my $option_to_remove = shift; + if (!(defined ($options))) { + print {*STDERR} "No or invalid options string given, aborting.\n"; + $error_detected = 4; + } -my $intermediate_removed = transform_intermediate ($intermediate, 1, $option_to_remove); + my $intermediate = undef; -print {*STDERR} Dumper ($intermediate_removed) . "\n"; + if (!($error_detected)) { + $intermediate = parse_options ($options); -print {*STDERR} Dumper (intermediate_to_string ($intermediate_removed)) . "\n"; + if (!(defined ($intermediate))) { + print {*STDERR} "Unable to parse option string, aborting.\n"; + $error_detected = 5; + } + } -my $option_to_add = shift; + if (!($error_detected)) { + my $cur_transform = shift; + + # Nasty trick (to some degree): "do"-blocks are not recognized as loops by + # Perl, but we can wrap the body in another block, which WILL BE recognized + # as a loop (one, that only executes once), oddly enough. + do {{ + # Shall only be relevant for the first run of the loop. + if (!(defined ($cur_transform))) { + print {*STDERR} "No transformation passed, aborting.\n"; + $error_detected = 6; + last; + } -my $intermediate_added = transform_intermediate ($intermediate_removed, 0, $option_to_add); + my $interpreted_transform_ref = interpret_transform ($cur_transform); -print {*STDERR} Dumper ($intermediate_added) . "\n"; + if (!(defined ($interpreted_transform_ref))) { + print {*STDERR} "Invalid transformation passed, aborting.\n"; + $error_detected = 7; + last; + } -print {*STDERR} Dumper (intermediate_to_string ($intermediate_added)) . "\n"; + my ($transform_mode, $sanitized_transform) = @{$interpreted_transform_ref}; -#my $value = shift; -#my $allow_negative = shift; -# -#if (!(defined ($value))) { -# print {*STDERR} "No value passed in, assuming empty string.\n"; -# $value = q{}; -#} -# -#if (!(defined ($allow_negative))) { -# $allow_negative = 0; -#} -# -#exit is_int ($value); + $intermediate = transform_intermediate ($intermediate, $transform_mode, $sanitized_transform); -exit 1; + if (!(defined ($intermediate))) { + print {*STDERR} "Error while transforming intermediate representation, aborting.\n"; + $error_detected = 7; + last; + } + }} while (defined ($cur_transform = shift)); + } + + my $out = undef; + + if (!($error_detected)) { + $out = intermediate_to_string ($intermediate); + + if (!(defined ($out))) { + print {*STDERR} "Unable to transform intermediate back into string, aborting.\n"; + $error_detected = 8; + } + } + + if (!($error_detected)) { + print {*STDOUT} $out . "\n"; + } + + #print {*STDERR} Dumper ($intermediate) . "\n"; + + #print {*STDERR} Dumper (intermediate_to_string ($intermediate)) . "\n"; + + #my $option_to_remove = shift; + + #my $intermediate_removed = transform_intermediate ($intermediate, 1, $option_to_remove); + + #print {*STDERR} Dumper ($intermediate_removed) . "\n"; + + #print {*STDERR} Dumper (intermediate_to_string ($intermediate_removed)) . "\n"; + + #my $option_to_add = shift; + + #my $intermediate_added = transform_intermediate ($intermediate_removed, 0, $option_to_add); + + #print {*STDERR} Dumper ($intermediate_added) . "\n"; + + #print {*STDERR} Dumper (intermediate_to_string ($intermediate_added)) . "\n"; + + #my $value = shift; + #my $allow_negative = shift; + # + #if (!(defined ($value))) { + # print {*STDERR} "No value passed in, assuming empty string.\n"; + # $value = q{}; + #} + # + #if (!(defined ($allow_negative))) { + # $allow_negative = 0; + #} + # + #exit is_int ($value); + + return $error_detected; +} __END__ -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git