[X2Go-Commits] [x2goserver] 75/99: X2Go/Server/Agent/NX/Options.pm: simplify error handling by splitting intermediate checking out into a separate subroutine.
git-admin at x2go.org
git-admin at x2go.org
Mon Dec 28 06:10:51 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 1be4e179571c47d6860055a68d64429f7b4bedaf
Author: Mihai Moldovan <ionic at ionic.de>
Date: Sun Nov 29 08:05:38 2020 +0100
X2Go/Server/Agent/NX/Options.pm: simplify error handling by splitting intermediate checking out into a separate subroutine.
---
X2Go/Server/Agent/NX/Options.pm | 90 ++++++++++++++++++++---------------------
debian/changelog | 2 +
2 files changed, 47 insertions(+), 45 deletions(-)
diff --git a/X2Go/Server/Agent/NX/Options.pm b/X2Go/Server/Agent/NX/Options.pm
index 8a4c068b..b7ddcca3 100644
--- a/X2Go/Server/Agent/NX/Options.pm
+++ b/X2Go/Server/Agent/NX/Options.pm
@@ -214,6 +214,48 @@ sub parse_options {
return $ret;
}
+# Takes an intermediate options string representation array reference(!) and
+# checks its validity.
+# Returns true, iff the array reference contains at least one element (since
+# the terminating display port specifier is mandatory) and all elements are
+# defined.
+# Otherwise, returns false.
+sub validate_intermediate {
+ my $ret = 1;
+
+ my $intermediate = shift;
+
+ if (!(defined ($intermediate))) {
+ print {*STDERR} "Invalid options reference passed to check function (undefined), returning false.\n";
+ $ret = 0;
+ }
+
+ if ($ret) {
+ if ('ARRAY' ne ref ($intermediate)) {
+ print {*STDERR} 'Invalid options reference type passed to check function (' . ref ($intermediate) . "), returning false.\n";
+ $ret = 0;
+ }
+ }
+
+ if ($ret) {
+ if (0 == scalar (@{$intermediate})) {
+ print {*STDERR} "Empty options array reference passed to check function, returning false.\n";
+ $ret = 0;
+ }
+ }
+
+ if ($ret) {
+ foreach my $entry (@{$intermediate}) {
+ if (!defined ($entry)) {
+ print {*STDERR} "Invalid options array reference passed to check function, at least one element is undefined, returning false.\n";
+ $ret = 0;
+ }
+ }
+ }
+
+ return $ret;
+}
+
# Takes an intermediate options string representation array reference(!) and
# returns a string.
# This is essentially the opposite of parse_options.
@@ -227,21 +269,7 @@ sub intermediate_to_string {
my $options = shift;
- if ('ARRAY' ne ref ($options)) {
- print {*STDERR} 'Invalid options reference type passed (' . ref ($options) . "), returning undef.\n";
- $error_detected = 1;
- }
-
- if (!($error_detected)) {
- if (0 < scalar (@{$options})) {
- foreach my $entry (@{$options}) {
- if (!defined ($entry)) {
- print {*STDERR} "Invalid options array passed, returning undef.\n";
- $error_detected = 1;
- }
- }
- }
- }
+ $error_detected = (!(validate_intermediate ($options)));
if (!($error_detected)) {
# Last entry should contain the display port part only.
@@ -554,21 +582,7 @@ sub transform_intermediate {
my $mode = shift;
my $option = shift;
- if ('ARRAY' ne ref ($intermediate)) {
- print {*STDERR} 'Invalid options reference type passed (' . ref ($intermediate) . "), erroring out.\n";
- $error_detected = 1;
- }
-
- if (!($error_detected)) {
- if (0 < scalar (@{$intermediate})) {
- foreach my $entry (@{$intermediate}) {
- if (!defined ($entry)) {
- print {*STDERR} "Invalid options array passed, erroring out.\n";
- $error_detected = 1;
- }
- }
- }
- }
+ $error_detected = (!(validate_intermediate ($intermediate)));
if (!($error_detected)) {
if (!(defined ($mode)) || (MODE_INVALID == $mode)) {
@@ -724,21 +738,7 @@ sub compact_intermediate {
my $intermediate = shift;
- if ('ARRAY' ne ref ($intermediate)) {
- print {*STDERR} 'Invalid options reference type passed (' . ref ($intermediate) . "), erroring out.\n";
- $error_detected = 1;
- }
-
- if (!($error_detected)) {
- if (0 < scalar (@{$intermediate})) {
- foreach my $entry (@{$intermediate}) {
- if (!defined ($entry)) {
- print {*STDERR} "Invalid options array passed, erroring out.\n";
- $error_detected = 1;
- }
- }
- }
- }
+ $error_detected = (!(validate_intermediate ($intermediate)));
if (!($error_detected)) {
# First, save display number part.
diff --git a/debian/changelog b/debian/changelog
index 82572d4e..5494d6aa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -338,6 +338,8 @@ x2goserver (4.1.0.4-0x2go1.2) UNRELEASED; urgency=medium
mode. Needs proper implementation.
- x2goserver/bin/x2goupdateoptionsstring: fix syntax and strict mode
errors.
+ - X2Go/Server/Agent/NX/Options.pm: simplify error handling by splitting
+ intermediate checking out into a separate subroutine.
* debian/control:
+ Build-depend upon lsb-release for distro version detection.
* debian/x2goserver.manpages:
--
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