[X2Go-Commits] [x2goserver] 78/99: X2Go/Server/Agent/NX/Options.pm: add extract_element subroutine, used to extract key-value pairs.

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 9a22f595d654da226c657a1425488210d0ec5e82
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sun Nov 29 14:14:40 2020 +0100

    X2Go/Server/Agent/NX/Options.pm: add extract_element subroutine, used to extract key-value pairs.
    
    This one will be exportable, too.
    
    Documentation to be done.
---
 X2Go/Server/Agent/NX/Options.pm | 59 ++++++++++++++++++++++++++++++++++++++++-
 debian/changelog                |  3 +++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/X2Go/Server/Agent/NX/Options.pm b/X2Go/Server/Agent/NX/Options.pm
index 5b0ac0fe..41725a48 100644
--- a/X2Go/Server/Agent/NX/Options.pm
+++ b/X2Go/Server/Agent/NX/Options.pm
@@ -43,7 +43,7 @@ use English qw (-no_match_vars);
 use Storable qw (dclone);
 
 our @EXPORT_OK = qw (MODE_INVALID MODE_ADD_UPDATE MODE_REMOVE
-                     parse_options interpret_transform transform_intermediate intermediate_to_string compact_intermediate);
+                     parse_options interpret_transform transform_intermediate extract_element intermediate_to_string compact_intermediate);
 
 
 # These are actually supposed to be enums, but since Perl doesn't have a
@@ -674,6 +674,63 @@ sub transform_intermediate {
   return $ret;
 }
 
+# Extracts entries from the intermediate options array.
+#
+# Expects an intermediate options reference as its first parameter, and the
+# option-to-be-extracted as its parameter.
+#
+# This option can either be a full key-value pair, which is useful for testing
+# for existence, or just a key, which is useful for extracting unknown,
+# matching value(s).
+#
+# Returns a reference to a modified *copy* of the extracted elements. This is
+# an array of hash references, with each hash containing one element.
+#
+# On error, returns undef.
+sub extract_element {
+  my $ret = undef;
+  my $error_detected = 0;
+
+  my $intermediate = shift;
+  my $option = shift;
+
+  $error_detected = (!(validate_intermediate ($intermediate)));
+
+  if (!($error_detected)) {
+    if (!(defined ($option))) {
+      print {*STDERR} "No or invalid option to extract passed, erroring out.\n";
+      $error_detected = 1;
+    }
+  }
+
+  my $work_option_key = undef;
+  my $work_option_value = undef;
+
+  if (!($error_detected)) {
+    my $work_opt_kv = sanitize_workoption_filter ($option);
+
+    if (!(defined ($work_opt_kv))) {
+      print {*STDERR} "Unable to split up working option into key and value pair, returning undef.\n";
+      $error_detected = 1;
+    }
+    else {
+      $work_option_key = shift (@{$work_opt_kv});
+      $work_option_value = shift (@{$work_opt_kv});
+    }
+  }
+
+  if (!($error_detected)) {
+    my $elements_left = @{$intermediate};
+
+    my @results = grep { filter_find_key ($work_option_key, $work_option_value, $_, --$elements_left) } @{$intermediate};
+
+    # Okay, got the results, now let's clone that.
+    $ret = dclone (\@results);
+  }
+
+  return $ret;
+}
+
 # Helper function "interpreting" a transformation string.
 #
 # Takes the raw transformation string as its only parameter.
diff --git a/debian/changelog b/debian/changelog
index 6741b45a..6c473c2b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -346,6 +346,9 @@ x2goserver (4.1.0.4-0x2go1.2) UNRELEASED; urgency=medium
       that are not marked for export are internal and should not be used.
       Usually, that should implicitly be clear, but it doesn't hurt to be
       verbose with a disclaimer.
+    - X2Go/Server/Agent/NX/Options.pm: add extract_element subroutine, used to
+      extract key-value pairs. This one will be exportable, too. Documentation
+      to be done.
   * 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