[X2Go-Commits] [x2goserver] 69/99: x2goserver/bin/x2goupdateoptionsstring: generalize code looping through program arguments and split out transformation operation into own subroutine.
git-admin at x2go.org
git-admin at x2go.org
Mon Dec 28 06:10:50 CET 2020
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository x2goserver.
commit fd76f96dfda718585e88287c7f7f09996b2c8aa1
Author: Mihai Moldovan <ionic at ionic.de>
Date: Mon Nov 23 23:58:51 2020 +0100
x2goserver/bin/x2goupdateoptionsstring: generalize code looping through program arguments and split out transformation operation into own subroutine.
---
debian/changelog | 3 +
x2goserver/bin/x2goupdateoptionsstring | 134 +++++++++++++++++++++++----------
2 files changed, 97 insertions(+), 40 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index d5528dd6..93fa7fc5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -325,6 +325,9 @@ x2goserver (4.1.0.4-0x2go1.2) UNRELEASED; urgency=medium
adjust/fix the comments.
- x2goserver/bin/x2goupdateoptionsstring: more typo fixes in output
messages only.
+ - x2goserver/bin/x2goupdateoptionsstring: generalize code looping through
+ program arguments and split out transformation operation into own
+ subroutine.
* debian/control:
+ Build-depend upon lsb-release for distro version detection.
* debian/x2goserver.manpages:
diff --git a/x2goserver/bin/x2goupdateoptionsstring b/x2goserver/bin/x2goupdateoptionsstring
index 82577e74..cb3470ad 100755
--- a/x2goserver/bin/x2goupdateoptionsstring
+++ b/x2goserver/bin/x2goupdateoptionsstring
@@ -326,6 +326,78 @@ sub handle_mode {
return $ret;
}
+# Helper function applying a transformation to an intermediate options string.
+#
+# Takes an intermediate options string, a transformation string and a boolean
+# value indicating whether debugging is turned on or off as its parameters.
+#
+# Returns a modified intermediate options string.
+#
+# On error, returns undef.
+sub apply_transformation {
+ my $ret = undef;
+ my $error_detected = 0;
+
+ my $intermediate = shift;
+ my $transform = shift;
+ my $debug = shift;
+
+ if (!(defined ($intermediate))) {
+ print {*STDERR} "Invalid intermediate argument passed to transformation helper, erroring out.\n";
+ $error_detected = 1;
+ }
+
+ if ((!($error_detected)) && (!(defined ($transform)))) {
+ print {*STDERR} "Invalid transformation argument passed to transformation helper, erroring out.\n";
+ $error_detected = 1;
+ }
+
+ if ((!($error_detected)) && (!(defined ($debug)))) {
+ print {*STDERR} "Invalid debug argument passed to transformation helper, erroring out.\n";
+ $error_detected = 1;
+ }
+
+ my $interpreted_transform_ref = undef;
+
+ if (!($error_detected)) {
+ if ($debug) {
+ print {*STDERR} 'Parsing current raw transformation option: ' . Dumper ($transform);
+ }
+
+ $interpreted_transform_ref = X2Go::Server::Agent::NX::Options::interpret_transform ($transform);
+
+ if (!(defined ($interpreted_transform_ref))) {
+ print {*STDERR} "Invalid transformation passed, aborting.\n";
+ $error_detected = 1;
+ }
+ }
+
+ if (!($error_detected)) {
+ my ($transform_mode, $sanitized_transform) = @{$interpreted_transform_ref};
+
+ if ($debug) {
+ print {*STDERR} 'Parsed raw transformation option into mode \'' . $transform_mode . '\' and sanitized transform option \'' . Dumper ($sanitized_transform) . "'\n";
+ }
+
+ $intermediate = X2Go::Server::Agent::NX::Options::transform_intermediate ($intermediate, $transform_mode, $sanitized_transform);
+
+ if (!(defined ($intermediate))) {
+ print {*STDERR} "Error while transforming intermediate representation, aborting.\n";
+ $error_detected = 1;
+ }
+ }
+
+ if (!($error_detected)) {
+ if ($debug) {
+ print {*STDERR} 'Dumping transformed intermediate array: ' . Dumper ($intermediate);
+ }
+
+ $ret = $intermediate;
+ }
+
+ return $ret;
+}
+
# Main function, no code outside of it shall be executed.
#
# Expects @ARGV to be passed in.
@@ -453,44 +525,26 @@ sub Main {
}
}
+ my $out = undef;
+
if (!($error_detected)) {
$found_separator |= (0 + shift (@{$sanitized_options}));
$sanitized_options = shift (@{$sanitized_options});
@program_arguments = @{$sanitized_options};
- my $transformed = 0;
-
- while (defined (my $cur_transform = shift (@program_arguments))) {
- $transformed = 1;
+ my $operation = 0;
- if ($debug) {
- print {*STDERR} 'Parsing current raw transformation option: ' . Dumper ($cur_transform);
- }
+ while (defined (my $cur_arg = shift (@program_arguments))) {
+ $operation = 1;
- my $interpreted_transform_ref = X2Go::Server::Agent::NX::Options::interpret_transform ($cur_transform);
+ if ((MODE_TRANSFORM_DATA)[1] == $mode) {
+ $intermediate = apply_transformation ($intermediate, $cur_arg, $debug);
- if (!(defined ($interpreted_transform_ref))) {
- print {*STDERR} "Invalid transformation passed, aborting.\n";
- $error_detected = 10;
- last;
- }
-
- my ($transform_mode, $sanitized_transform) = @{$interpreted_transform_ref};
-
- if ($debug) {
- print {*STDERR} 'Parsed raw transformation option into mode \'' . $transform_mode . '\' and sanitized transform option \'' . Dumper ($sanitized_transform) . "'\n";
- }
-
- $intermediate = X2Go::Server::Agent::NX::Options::transform_intermediate ($intermediate, $transform_mode, $sanitized_transform);
-
- if (!(defined ($intermediate))) {
- print {*STDERR} "Error while transforming intermediate representation, aborting.\n";
- $error_detected = 11;
- last;
- }
-
- if ($debug) {
- print {*STDERR} 'Dumping transformed intermediate array: ' . Dumper ($intermediate);
+ if (!(defined ($intermediate))) {
+ print {*STDERR} 'Unable to apply transformation "' . $cur_arg . '"' . ", aborting.\n";
+ $error_detected = 10;
+ last;
+ }
}
# Skip pseudo-option, if necessary.
@@ -498,7 +552,7 @@ sub Main {
if (!(defined ($sanitized_options))) {
pod2usage (-exitval => 'NOEXIT');
- $error_detected = 12;
+ $error_detected = 11;
last;
}
elsif ($debug) {
@@ -510,20 +564,20 @@ sub Main {
@program_arguments = @{$sanitized_options};
}
- if ((!($error_detected)) && (!($transformed))) {
- print {*STDERR} "No transformation passed, aborting.\n";
- $error_detected = 13;
+ if ((!($error_detected)) && (!($operation))) {
+ print {*STDERR} "No operation carried out, aborting.\n";
+ $error_detected = 12;
}
}
- my $out = undef;
-
if (!($error_detected)) {
- $out = X2Go::Server::Agent::NX::Options::intermediate_to_string ($intermediate);
+ if ((MODE_TRANSFORM_DATA)[1] == $mode) {
+ $out = X2Go::Server::Agent::NX::Options::intermediate_to_string ($intermediate);
- if (!(defined ($out))) {
- print {*STDERR} "Unable to transform intermediate back into string, aborting.\n";
- $error_detected = 14;
+ if (!(defined ($out))) {
+ print {*STDERR} "Unable to transform intermediate back into string, aborting.\n";
+ $error_detected = 13;
+ }
}
}
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
More information about the x2go-commits
mailing list