This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch master in repository x2goserver. from 8e27e1e debian/x2goserver.manpages: install x2gocleansessions man page. new 8f69b5d X2Go/Utils.pm: fix missing semicolons. new 3e24f32 X2Go/Utils.pm: add new is_int subroutine, checking if the provided value is an integer. new ccd65e9 x2goserver/lib: new x2goisint wrapper. new 98b0d81 x2goserver.spec: install new x2goisint wrapper. new 25fb903 x2goserver/lib/x2gois{int,true}: add newlines to (error) output. new 730abed x2goserver/lib/x2gois{int,true}: add optional warnings. new 6fa680a x2goserver/sbin/x2gocleansessions: rework manpage/POD. new e705462 x2goserver/lib: add new (stub) file x2goupdateoptionsstring to deal with options string manipulations. new 538bb7b x2goserver/lib/x2goupdateoptionsstring: add function to transform the intermediate options string representation back into a string and some code that uses this new function. new 5d9e416 x2goserver/lib/x2go{is{int,true},updateoptionsstring}: use q{} instead of empty quotes as per some... coding standard. new 3bbaa19 x2goserver/lib/x2go{is{int,true},updateoptionsstring}: wrap print calls with filehandles in curly braces. new 2d99fd4 x2goserver/lib/x2goupdateoptionsstring: fix some "errors" reported by Perl::Critic in brutal mode. new 4f95c1d x2goserver/lib/x2goupdateoptionsstring: add functionality for options removal. new 71f94f8 x2goserver/lib/x2goupdateoptionsstring: update documentation to include the notion of the +key[=value] syntax, which makes sense to use if key starts with a dash and would be ambiguously interpreted as a removal. new 0bb8339 x2goserver/lib/x2goupdateoptionsstring: refactor remove_option subprocedure into a more general transform_intermediate one and add code for the modification/addition case. new e20033a x2goserver/lib/x2goupdateoptionsstring: ignore some very noisy Perl::Critic warnings that we're going to ignore anyway. new ea949fb x2goserver/lib/x2goupdateoptionsstring: fix interpolated string warning. new 5517537 x2goserver/lib/x2goupdateoptionsstring: add helper function for transform string interpretation. new 6a13ec9 x2goserver/lib/x2goupdateoptionsstring: write wrapper that handles program options, creates intermediate, passes through transform chains, reconverts to a string and prints it. new 4971a60 x2goserver/lib/x2goupdateoptionsstring: add debug option and some debugging output. new 7f717e4 x2goserver/lib/x2goupdateoptionsstring: remove dead code. new b74def0 x2goserver/lib/x2goupdateoptionsstring: update documentation and clarify risks of option parsing. new b5f6c03 x2goserver/lib/x2goupdateoptionsstring: don't debug-output the intermediate representation if we know that parsing failed. new 043c662 x2goserver/lib/x2goupdateoptionsstring: fix debug string and add another one dumping the raw options string. new 0d08681 x2goserver/lib/x2goupdateoptionsstring: fix parsing of transformation strings by replacing the switch statement with if statements. new 1759ca1 x2goserver/lib/x2goupdateoptionsstring: handle options in a more robust way. new 517db0a x2goserver/lib/x2goupdateoptionsstring: fix another Perl::Critic nit. new 4db3e01 x2goserver/lib/x2goupdateoptionsstring: move into x2goserver/bin, since it's really a standalone program and also useful for non-X2Go-internal usage. new 9a9f3a9 x2goserver/Makefile: add x2goupdateoptionsstring POD-to-man-page handling. new 0a789a7 debian/x2goserver.install: install bin/x2goupdateoptionsstring. The 30 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: X2Go/Utils.pm | 23 +- debian/changelog | 64 ++ debian/x2goserver.install | 1 + x2goserver.spec | 1 + x2goserver/Makefile | 2 +- x2goserver/bin/x2goupdateoptionsstring | 1016 ++++++++++++++++++++++++++++++ x2goserver/lib/{x2goistrue => x2goisint} | 16 +- x2goserver/lib/x2goistrue | 5 +- x2goserver/sbin/x2gocleansessions | 29 +- 9 files changed, 1132 insertions(+), 25 deletions(-) create mode 100755 x2goserver/bin/x2goupdateoptionsstring copy x2goserver/lib/{x2goistrue => x2goisint} (72%) -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 8f69b5d8421b3b2153d65b9b9192bf8aa90ea200 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 5 08:25:00 2018 +0100 X2Go/Utils.pm: fix missing semicolons. --- X2Go/Utils.pm | 4 ++-- debian/changelog | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/X2Go/Utils.pm b/X2Go/Utils.pm index 5fd1483..234702c 100644 --- a/X2Go/Utils.pm +++ b/X2Go/Utils.pm @@ -56,9 +56,9 @@ sub load_module { sub is_true { my $value = shift; if ( $value =~ m/(1|yes|Yes|YES|on|On|ON|True|true|TRUE)/ ) { - return 1 + return 1; } - return 0 + return 0; } diff --git a/debian/changelog b/debian/changelog index 0ad9882..4e58012 100644 --- a/debian/changelog +++ b/debian/changelog @@ -14,6 +14,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/sbin/x2gocleansessions: add newline before POD block. - x2goserver-x2goagent/man/man1/x2goagent.1: add version and date. - x2goserver/Makefile: generate man pages from Perl POD. + - X2Go/Utils.pm: fix missing semicolons. * 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
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 3e24f3211617aa10d3c0a48610181ec90f541624 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 5 08:30:48 2018 +0100 X2Go/Utils.pm: add new is_int subroutine, checking if the provided value is an integer. --- X2Go/Utils.pm | 19 ++++++++++++++++++- debian/changelog | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/X2Go/Utils.pm b/X2Go/Utils.pm index 234702c..4a4c7a2 100644 --- a/X2Go/Utils.pm +++ b/X2Go/Utils.pm @@ -37,7 +37,7 @@ use strict; use base 'Exporter'; -our @EXPORT = ( 'load_module', 'is_true', +our @EXPORT = ( 'load_module', 'is_true', 'is_int', 'source_environment', 'clups', 'sanitizer', 'system_capture_merged_output', 'system_capture_stdout_output', 'check_x2go_sessionid'); @@ -61,6 +61,23 @@ sub is_true { return 0; } +sub is_int { + my $value = shift; + my $allow_negative = shift; + + if (!(defined ($allow_negative))) { + $allow_negative = 0; + } + + if ($allow_negative) { + return 1 if $value =~ m/-?\d+/; + } + else { + return 1 if $value =~ m/\d+/; + } + + return 0; +} sub source_environment { my $name = shift; diff --git a/debian/changelog b/debian/changelog index 4e58012..e92aa36 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,6 +15,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver-x2goagent/man/man1/x2goagent.1: add version and date. - x2goserver/Makefile: generate man pages from Perl POD. - X2Go/Utils.pm: fix missing semicolons. + - X2Go/Utils.pm: add new is_int subroutine, checking if the provided value + is an integer. * 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
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit ccd65e9d446261af5d358b4fde1f7b72837eb552 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 5 08:37:43 2018 +0100 x2goserver/lib: new x2goisint wrapper. --- debian/changelog | 1 + x2goserver/lib/x2goisint | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/debian/changelog b/debian/changelog index e92aa36..8f1fd30 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - X2Go/Utils.pm: fix missing semicolons. - X2Go/Utils.pm: add new is_int subroutine, checking if the provided value is an integer. + - x2goserver/lib: new x2goisint wrapper. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goisint b/x2goserver/lib/x2goisint new file mode 100755 index 0000000..eef7f0b --- /dev/null +++ b/x2goserver/lib/x2goisint @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +# Copyright (C) 2018 X2Go Project - https://wiki.x2go.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +use strict; + +use X2Go::Utils qw (is_int); + +my $value = shift; +my $allow_negative = shift; + +if (!(defined ($value))) { + print STDERR 'No value passed in, assuming empty string.'; + $value = ''; +} + +if (!(defined ($allow_negative))) { + $allow_negative = 0; +} + +exit is_int ($value); -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 98b0d8170b14ec08d29f9a649d22e5dd374387a0 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 5 08:39:39 2018 +0100 x2goserver.spec: install new x2goisint wrapper. --- debian/changelog | 2 ++ x2goserver.spec | 1 + 2 files changed, 3 insertions(+) diff --git a/debian/changelog b/debian/changelog index 8f1fd30..8cef333 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: + Install x2gocleansessions man page. + * x2goserver.spec: + + Install new x2goisint wrapper. -- X2Go Release Manager <git-admin@x2go.org> Thu, 29 Nov 2018 07:57:20 +0100 diff --git a/x2goserver.spec b/x2goserver.spec index e66851c..de338e2 100644 --- a/x2goserver.spec +++ b/x2goserver.spec @@ -886,6 +886,7 @@ fi %{_libdir}/x2go/x2goinsertport %{_libdir}/x2go/x2goinsertsession %{_libdir}/x2go/x2goinsertshadowsession +%{_libdir}/x2go/x2goisint %{_libdir}/x2go/x2goistrue %{_libdir}/x2go/x2golistsessions_sql %{_libdir}/x2go/x2gologlevel -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 25fb903047987e46343a8e4f5b583a661be7d60c Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 6 02:52:17 2018 +0100 x2goserver/lib/x2gois{int,true}: add newlines to (error) output. --- debian/changelog | 1 + x2goserver/lib/x2goisint | 2 +- x2goserver/lib/x2goistrue | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8cef333..4d4eae9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - X2Go/Utils.pm: add new is_int subroutine, checking if the provided value is an integer. - x2goserver/lib: new x2goisint wrapper. + - x2goserver/lib/x2gois{int,true}: add newlines to (error) output. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goisint b/x2goserver/lib/x2goisint index eef7f0b..58250a4 100755 --- a/x2goserver/lib/x2goisint +++ b/x2goserver/lib/x2goisint @@ -25,7 +25,7 @@ my $value = shift; my $allow_negative = shift; if (!(defined ($value))) { - print STDERR 'No value passed in, assuming empty string.'; + print STDERR "No value passed in, assuming empty string.\n"; $value = ''; } diff --git a/x2goserver/lib/x2goistrue b/x2goserver/lib/x2goistrue index 5978436..0683cc4 100755 --- a/x2goserver/lib/x2goistrue +++ b/x2goserver/lib/x2goistrue @@ -24,7 +24,7 @@ use X2Go::Utils qw (is_true); my $value = shift; if (!(defined ($value))) { - print STDERR "No value passed in, assuming empty string."; + print STDERR "No value passed in, assuming empty string.\n"; $value = ""; } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 730abed8558c0c94694b6a0a3856655c4bbfe02e Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 6 03:47:16 2018 +0100 x2goserver/lib/x2gois{int,true}: add optional warnings. --- debian/changelog | 1 + x2goserver/lib/x2goisint | 1 + x2goserver/lib/x2goistrue | 1 + 3 files changed, 3 insertions(+) diff --git a/debian/changelog b/debian/changelog index 4d4eae9..764223e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium is an integer. - x2goserver/lib: new x2goisint wrapper. - x2goserver/lib/x2gois{int,true}: add newlines to (error) output. + - x2goserver/lib/x2gois{int,true}: add optional warnings. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goisint b/x2goserver/lib/x2goisint index 58250a4..da0a8dc 100755 --- a/x2goserver/lib/x2goisint +++ b/x2goserver/lib/x2goisint @@ -18,6 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. use strict; +use warnings; use X2Go::Utils qw (is_int); diff --git a/x2goserver/lib/x2goistrue b/x2goserver/lib/x2goistrue index 0683cc4..51cbce8 100755 --- a/x2goserver/lib/x2goistrue +++ b/x2goserver/lib/x2goistrue @@ -18,6 +18,7 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. use strict; +use warnings; use X2Go::Utils qw (is_true); -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 6fa680ae896857124ca69f8e3023940ddacda4f2 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 6 04:16:01 2018 +0100 x2goserver/sbin/x2gocleansessions: rework manpage/POD. --- debian/changelog | 1 + x2goserver/sbin/x2gocleansessions | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/debian/changelog b/debian/changelog index 764223e..05a9893 100644 --- a/debian/changelog +++ b/debian/changelog @@ -20,6 +20,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib: new x2goisint wrapper. - x2goserver/lib/x2gois{int,true}: add newlines to (error) output. - x2goserver/lib/x2gois{int,true}: add optional warnings. + - x2goserver/sbin/x2gocleansessions: rework manpage/POD. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/sbin/x2gocleansessions b/x2goserver/sbin/x2gocleansessions index 4aa67f7..4852137 100755 --- a/x2goserver/sbin/x2gocleansessions +++ b/x2goserver/sbin/x2gocleansessions @@ -373,18 +373,28 @@ x2gocleansessions - X2Go Server Cleanup Daemon =head1 SYNOPSIS -x2gocleansessions [options] +=over - Options: - --help|-h|-? brief help message - --man full documentation - --debug|-d enable debugging and don't daemonize +=item B<x2gocleansessions> B<--help>|B<-h>|B<-?> + +=item B<x2gocleansessions> B<--man> + +=item B<x2gocleansessions> [B<--debug>|B<-d>] + +=back + +=head1 DESCRIPTION + +B<x2gocleansessions> is run as a service on X2Go servers to handle the cleanup +of stale sessions and synchronizing database state with on-disk state. + +B<x2gocleansessions> must be run (as a service) with root privileges. =head1 OPTIONS =over 8 -=item B<--help>|B<-?>|B<-h> +=item B<--help>|B<-h>|B<-?> Print a brief help message and exits. @@ -399,13 +409,6 @@ instead of daemonizing. =back -=head1 DESCRIPTION - -B<x2gocleansessions> is run as a service on X2Go servers to handle the cleanup -of stale sessions. - -B<x2gocleansessions> must be run (as a service) with root privileges. - =head1 AUTHOR This manual has been written by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit e705462a3b9f81960cdb12f4b9eb8b0a83724a81 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 6 10:38:18 2018 +0100 x2goserver/lib: add new (stub) file x2goupdateoptionsstring to deal with options string manipulations. Currently only parsing into an intermediate state is supported, the script dumps that state for now. --- debian/changelog | 3 + x2goserver/lib/x2goupdateoptionsstring | 287 +++++++++++++++++++++++++++++++++ 2 files changed, 290 insertions(+) diff --git a/debian/changelog b/debian/changelog index 05a9893..c1567f5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -21,6 +21,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2gois{int,true}: add newlines to (error) output. - x2goserver/lib/x2gois{int,true}: add optional warnings. - x2goserver/sbin/x2gocleansessions: rework manpage/POD. + - x2goserver/lib: add new (stub) file x2goupdateoptionsstring to deal with + options string manipulations. Currently only parsing into an + intermediate state is supported, the script dumps that state for now. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goupdateoptionsstring b/x2goserver/lib/x2goupdateoptionsstring new file mode 100755 index 0000000..f710339 --- /dev/null +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -0,0 +1,287 @@ +#!/usr/bin/perl + +# Copyright (C) 2018 X2Go Project - https://wiki.x2go.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + +use strict; +use warnings; + +#use X2Go::Utils qw (is_int); +use Data::Dumper qw (Dumper); +use Getopt::Long; +use Pod::Usage; + +# Accepts an option string and returns a reference to an array of hashes +# (actually hash references) corresponding to the parsed key-value pairs. +# +# Empty components are allowed, but will issue a warning message. In such a +# case, the hash at the corresponding array position will be empty. +# +# Keys that do not have a value assigned will be given a value of "undef" in +# order to be able to distinguish them from keys with an empty string as their +# value. +# +# Caveat: the last component will be split from the port definition. DO NOT +# SIMPLY JOIN THE LIST OR YOU WILL ADD A TRAILING COMMA! The port component +# hash retains the colon separator. +# +# On error, returns an undef reference. +sub parse_options { + my $ret = undef; + my @intermediate = (); + my $error_detected = 0; + my $options = shift; + my $next_discard = shift; + + if (defined ($next_discard)) { + print STDERR "Multiple arguments passed in, all but the first one are ignored!\n"; + } + + if (!(defined ($options))) { + print STDERR "No argument provided for options string, returning undef.\n"; + $error_detected = 1; + } + + if (!($error_detected)) { + my @components = split (/,/sxm, $options, -1); + foreach my $option (@components) { + # We use undef to denote that some component was not provided at all + # to disambiguate non-provided and empty strings. + my ($key, $value) = (undef, undef); + my %kv_hash = (); + + my @kv = split (/=/, $option, 2); + + if (1 > scalar (@kv)) { + print STDERR "Options string has empty component, this is deprecated. Adding empty element.\n"; + + push (@intermediate, \%kv_hash); + } + elsif (3 <= scalar (@kv)) { + print STDERR "Options string has three or more components, this is a bug in $0. Erroring out.\n"; + $error_detected = 1; + last; + } + else { + $key = shift (@kv); + $value = shift (@kv); + + # Add to hash - every hash will contain a single key-value pair only. + $kv_hash{$key} = $value; + + # Then add the hash as an entry in our return array - by reference. + push (@intermediate, \%kv_hash); + } + } + + # Special handling for the last option, which does not use a comma as the + # delimiter but a colon. + # + # Note that it can either be part of the key or the value. + if (!($error_detected)) { + if ((0 < scalar (@intermediate)) && (defined ($intermediate[0]))) { + my $last_hash_ref = pop (@intermediate); + my $hash_count = 0; + my $last_component = ''; + my $in_value = 0; + my $last_component_key = undef; + + # Fetch last component and check for sanity. + # An empty hash is implicitly handled by initializing $last_component to + # an empty string, which will fail the splitting later on. + foreach my $key (keys %{$last_hash_ref}) { + ++$hash_count; + + if (1 < $hash_count) { + print STDERR "More than one element found in last element's hash, this is a bug in $0. Ignoring subsequent entries.\n"; + last; + } + + $last_component = $last_component_key = $key; + + if (defined ($last_hash_ref->{$key})) { + # If a value exists, the display specifier can not be part of the + # key. + $in_value = 1; + $last_component = $last_hash_ref->{$key}; + } + } + + # Don't use split() here. While we could use a more or less complex + # regex to extract the last(!) port specifier only, this would render + # the LIMIT parameter to split() useless (since additional capture + # groups are not part of the limit). + # Thus going the manual route here. + my $last_pos = rindex ($last_component, ':'); + + if ($[ > $last_pos) { + print STDERR "No display port seperator found in the options string. Erroring out.\n"; + $error_detected = 1; + } + else { + my $last_component_left = substr ($last_component, 0, $last_pos); + my $last_component_right = substr ($last_component, $last_pos); + + my %last_component_hash = (); + + if ($in_value) { + $last_component_hash{$last_component_key} = $last_component_left; + } + else { + # Sanity check on the key. If it's empty, issue a warning and don't + # use it. + if (0 == length ($last_component_left)) { + print STDERR "Options string has empty component, this is deprecated. Adding empty element.\n"; + } + else { + $last_component_hash{$last_component_left} = undef; + } + } + + # Now add the last component hash to the array again. + push (@intermediate, \%last_component_hash); + + # Prepare a new hash object, with the key set to the display port part + # and value to undef to mark it invalid. + my %display_port_hash = (); + $display_port_hash{$last_component_right} = undef; + + # Add this to the return value as well. + push (@intermediate, \%display_port_hash); + } + } + } + } + + if (!($error_detected)) { + $ret = \@intermediate; + } + + return $ret; +} + +Getopt::Long::Configure("gnu_getopt", "no_auto_abbrev"); + +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; + +my $options = shift; + +print STDERR Dumper (parse_options ($options)) . "\n"; + +#my $value = shift; +#my $allow_negative = shift; +# +#if (!(defined ($value))) { +# print STDERR "No value passed in, assuming empty string.\n"; +# $value = ''; +#} +# +#if (!(defined ($allow_negative))) { +# $allow_negative = 0; +#} +# +#exit is_int ($value); + +exit 1; + +__END__ + +=head1 NAME + +x2goupdateoptionsstring - X2Go Agent Options String Manipulator + +=head1 SYNOPSIS + +=over + +=item B<x2goupdateoptionsstring> B<--help>|B<-h>|B<-?> + +=item B<x2goupdateoptionsstring> B<--man> + +=item B<x2goupdateoptionsstring> I<options> [B<->]I<key>[B<=>I<value>] ... + +=back + +=head1 DESCRIPTION + +B<x2goupdateoptionsstring> is a utility for manipulating options strings as +passed to X2Go Agent/NX Agent. + +Called it with the options string as the first parameter and the options you +want to manipulate as additional parameters. At least one additional parameter +must be provided. + +It can either add, remove or replace components. + +To add or replace a component, pass I<key>[B<=>I<value>] as a parameter. If the +options string does not include a B<key> key, it will be appended to the end of +the options string. If it already exists, either with no value or a different +value, the component will be replaced with the provided value. + +To fully remove a component, pass B<->I<key>. To only remove it if it is set to +a specific value, pass B<->I<key>B<=>I<value>. + +=head1 OPTIONS + +=over 8 + +=item B<--help>|B<-?>|B<-h> + +Print a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=back + +=head1 EXAMPLE + +For an options string such as + + nx/nx,clipboard=both,foo:50 + +calling C<x2goupdateoptionsstring 'nx/nx,clipboard=both,foo:50' +'-clipboard'> shall return + + nx/nx,foo:50 + +while calling C<x2goupdateoptionsstring 'nx/nx,clipboard=both,foo:50' +'-clipboard=server'> shall return + + nx/nx,clipboard=both,foo:50 + +Calling C<x2goupdateoptionsstring 'nx/nx,clipboard=both,foo:50' 'bar'> shall +return + + nx/nx,clipboard=both,foo,bar:50 + +and calling C<x2goupdateoptionsstring 'nx/nx,clipboard=both,foo:50' 'bar' +'foo=gulp' '-clipboard=client'> shall return + + nx/nx,clipboard=both,foo=gulp,bar:50 + +=head1 AUTHOR + +This manual has been written by Mihai Moldovan <ionic@ionic.de> for the X2Go +project (https://www.x2go.org). + +=cut -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 538bb7b66eb60e2e528be97364e44656548b9d8f Author: Mihai Moldovan <ionic@ionic.de> Date: Fri Dec 7 10:56:20 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: add function to transform the intermediate options string representation back into a string and some code that uses this new function. --- debian/changelog | 3 + x2goserver/lib/x2goupdateoptionsstring | 117 ++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index c1567f5..ffd4e5d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -24,6 +24,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib: add new (stub) file x2goupdateoptionsstring to deal with options string manipulations. Currently only parsing into an intermediate state is supported, the script dumps that state for now. + - x2goserver/lib/x2goupdateoptionsstring: add function to transform the + intermediate options string representation back into a string and some + code that uses this new function. * 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 f710339..d0f2ee2 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -174,6 +174,117 @@ sub parse_options { return $ret; } +# Takes an intermediate options string representation array reference(!) and +# returns a string. +# This is essentially the opposite of parse_options. +# Parsing an options string and passing the result through this function again +# SHOULD (if initial options string has been a valid one to begin with) yield +# the initial options string again. +# On error, returns undef. +sub intermediate_to_string { + my $ret = undef; + my $error_detected = 0; + + 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 (1 == scalar (@$options)) { + foreach my $entry (@$options) { + if (!defined ($entry)) { + print STDERR "Invalid options array passed, returning undef.\n"; + $error_detected = 1; + } + } + } + } + + if (!($error_detected)) { + # Last entry should contain the display port part only. + # We can detect it through counting. + my $elements_left = @$options; + + # Handle entries iteratively, merging then into one string. + foreach my $entry (@$options) { + --$elements_left; + + if (!defined ($entry)) { + print STDERR "Invalid options entry encountered, returning undef.\n"; + $error_detected = 1; + last; + } + + if ('HASH' ne ref ($entry)) { + print STDERR "Entry in array has invalid type (" . ref ($entry) ."), returning undef.\n"; + $error_detected = 1; + last; + } + + if (1 < scalar (keys (%$entry))) { + print STDERR "More than one entry encountered in hash of current element, returning undef.\n"; + $error_detected = 1; + last; + } + + # Must be either empty or have one element, so... go for it. + if (0 == scalar (keys (%$entry))) { + if (0 != $elements_left) { + if (defined ($ret)) { + $ret .= ','; + } + else { + # Mark first entry as empty. Don't remove this, or else. + $ret = ''; + } + } + else { + # Special handling for last element, which is always supposed to + # contain the display port. + print STDERR "No entry found in display port hash, returning undef.\n"; + $error_detected = 1; + last; + } + } + else { + # This foreach loop may look weird because, at that point, we know that + # the hash contains one key exactly, but it's still an elegant way to + # fetch the key and pseudo-iterate over it. + foreach my $key (keys (%$entry)) { + my $tmp = $key; + + if (0 != $elements_left) { + if (defined ($entry->{$key})) { + $tmp .= '=' . $entry->{$key}; + } + } + + if (defined ($ret)) { + if (0 != $elements_left) { + $ret = join (',', ($ret, $tmp)); + } + else { + $ret .= $tmp; + } + } + else { + $ret = $tmp; + } + } + } + } + } + + if ($error_detected) { + $ret = undef; + } + + return $ret; +} + Getopt::Long::Configure("gnu_getopt", "no_auto_abbrev"); my $help = 0; @@ -184,7 +295,11 @@ pod2usage(-verbose => 2, -exitval => 0) if $man; my $options = shift; -print STDERR Dumper (parse_options ($options)) . "\n"; +my $intermediate = parse_options ($options); + +print STDERR Dumper ($intermediate) . "\n"; + +print STDERR Dumper (intermediate_to_string ($intermediate)) . "\n"; #my $value = shift; #my $allow_negative = shift; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 5d9e416f81be6b52c828f71e4dec0785d6b4722b Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Dec 8 01:37:15 2018 +0100 x2goserver/lib/x2go{is{int,true},updateoptionsstring}: use q{} instead of empty quotes as per some... coding standard. --- debian/changelog | 2 ++ x2goserver/lib/x2goisint | 2 +- x2goserver/lib/x2goistrue | 2 +- x2goserver/lib/x2goupdateoptionsstring | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index ffd4e5d..0bf8354 100644 --- a/debian/changelog +++ b/debian/changelog @@ -27,6 +27,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: add function to transform the intermediate options string representation back into a string and some code that uses this new function. + - x2goserver/lib/x2go{is{int,true},updateoptionsstring}: use q{} instead + of empty quotes as per some... coding standard. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goisint b/x2goserver/lib/x2goisint index da0a8dc..c7e013e 100755 --- a/x2goserver/lib/x2goisint +++ b/x2goserver/lib/x2goisint @@ -27,7 +27,7 @@ my $allow_negative = shift; if (!(defined ($value))) { print STDERR "No value passed in, assuming empty string.\n"; - $value = ''; + $value = q{}; } if (!(defined ($allow_negative))) { diff --git a/x2goserver/lib/x2goistrue b/x2goserver/lib/x2goistrue index 51cbce8..f2ab8d8 100755 --- a/x2goserver/lib/x2goistrue +++ b/x2goserver/lib/x2goistrue @@ -26,7 +26,7 @@ my $value = shift; if (!(defined ($value))) { print STDERR "No value passed in, assuming empty string.\n"; - $value = ""; + $value = q{}; } print is_true ($value) . "\n"; diff --git a/x2goserver/lib/x2goupdateoptionsstring b/x2goserver/lib/x2goupdateoptionsstring index d0f2ee2..b9b3fe8 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -96,7 +96,7 @@ sub parse_options { if ((0 < scalar (@intermediate)) && (defined ($intermediate[0]))) { my $last_hash_ref = pop (@intermediate); my $hash_count = 0; - my $last_component = ''; + my $last_component = q{}; my $in_value = 0; my $last_component_key = undef; @@ -238,7 +238,7 @@ sub intermediate_to_string { } else { # Mark first entry as empty. Don't remove this, or else. - $ret = ''; + $ret = q{}; } } else { @@ -306,7 +306,7 @@ print STDERR Dumper (intermediate_to_string ($intermediate)) . "\n"; # #if (!(defined ($value))) { # print STDERR "No value passed in, assuming empty string.\n"; -# $value = ''; +# $value = q{}; #} # #if (!(defined ($allow_negative))) { -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 3bbaa1965c12e169eae3f8ebe090c6252ff1cde9 Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Dec 8 01:47:27 2018 +0100 x2goserver/lib/x2go{is{int,true},updateoptionsstring}: wrap print calls with filehandles in curly braces. --- debian/changelog | 2 ++ x2goserver/lib/x2goisint | 2 +- x2goserver/lib/x2goistrue | 2 +- x2goserver/lib/x2goupdateoptionsstring | 32 ++++++++++++++++---------------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0bf8354..a96df9e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -29,6 +29,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium code that uses this new function. - x2goserver/lib/x2go{is{int,true},updateoptionsstring}: use q{} instead of empty quotes as per some... coding standard. + - x2goserver/lib/x2go{is{int,true},updateoptionsstring}: wrap print calls + with filehandles in curly braces. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goisint b/x2goserver/lib/x2goisint index c7e013e..add1008 100755 --- a/x2goserver/lib/x2goisint +++ b/x2goserver/lib/x2goisint @@ -26,7 +26,7 @@ my $value = shift; my $allow_negative = shift; if (!(defined ($value))) { - print STDERR "No value passed in, assuming empty string.\n"; + print {*STDERR} "No value passed in, assuming empty string.\n"; $value = q{}; } diff --git a/x2goserver/lib/x2goistrue b/x2goserver/lib/x2goistrue index f2ab8d8..b231ae9 100755 --- a/x2goserver/lib/x2goistrue +++ b/x2goserver/lib/x2goistrue @@ -25,7 +25,7 @@ use X2Go::Utils qw (is_true); my $value = shift; if (!(defined ($value))) { - print STDERR "No value passed in, assuming empty string.\n"; + print {*STDERR} "No value passed in, assuming empty string.\n"; $value = q{}; } diff --git a/x2goserver/lib/x2goupdateoptionsstring b/x2goserver/lib/x2goupdateoptionsstring index b9b3fe8..901a409 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -48,11 +48,11 @@ sub parse_options { my $next_discard = shift; if (defined ($next_discard)) { - print STDERR "Multiple arguments passed in, all but the first one are ignored!\n"; + print {*STDERR} "Multiple arguments passed in, all but the first one are ignored!\n"; } if (!(defined ($options))) { - print STDERR "No argument provided for options string, returning undef.\n"; + print {*STDERR} "No argument provided for options string, returning undef.\n"; $error_detected = 1; } @@ -67,12 +67,12 @@ sub parse_options { my @kv = split (/=/, $option, 2); if (1 > scalar (@kv)) { - print STDERR "Options string has empty component, this is deprecated. Adding empty element.\n"; + print {*STDERR} "Options string has empty component, this is deprecated. Adding empty element.\n"; push (@intermediate, \%kv_hash); } elsif (3 <= scalar (@kv)) { - print STDERR "Options string has three or more components, this is a bug in $0. Erroring out.\n"; + print {*STDERR} "Options string has three or more components, this is a bug in $0. Erroring out.\n"; $error_detected = 1; last; } @@ -107,7 +107,7 @@ sub parse_options { ++$hash_count; if (1 < $hash_count) { - print STDERR "More than one element found in last element's hash, this is a bug in $0. Ignoring subsequent entries.\n"; + print {*STDERR} "More than one element found in last element's hash, this is a bug in $0. Ignoring subsequent entries.\n"; last; } @@ -129,7 +129,7 @@ sub parse_options { my $last_pos = rindex ($last_component, ':'); if ($[ > $last_pos) { - print STDERR "No display port seperator found in the options string. Erroring out.\n"; + print {*STDERR} "No display port seperator found in the options string. Erroring out.\n"; $error_detected = 1; } else { @@ -145,7 +145,7 @@ sub parse_options { # Sanity check on the key. If it's empty, issue a warning and don't # use it. if (0 == length ($last_component_left)) { - print STDERR "Options string has empty component, this is deprecated. Adding empty element.\n"; + print {*STDERR} "Options string has empty component, this is deprecated. Adding empty element.\n"; } else { $last_component_hash{$last_component_left} = undef; @@ -188,7 +188,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"; + print {*STDERR} "Invalid options reference type passed (" . ref ($options) . "), returning undef.\n"; $error_detected = 1; } @@ -196,7 +196,7 @@ sub intermediate_to_string { if (1 == scalar (@$options)) { foreach my $entry (@$options) { if (!defined ($entry)) { - print STDERR "Invalid options array passed, returning undef.\n"; + print {*STDERR} "Invalid options array passed, returning undef.\n"; $error_detected = 1; } } @@ -213,19 +213,19 @@ sub intermediate_to_string { --$elements_left; if (!defined ($entry)) { - print STDERR "Invalid options entry encountered, returning undef.\n"; + print {*STDERR} "Invalid options entry encountered, returning undef.\n"; $error_detected = 1; last; } if ('HASH' ne ref ($entry)) { - print STDERR "Entry in array has invalid type (" . ref ($entry) ."), returning undef.\n"; + print {*STDERR} "Entry in array has invalid type (" . ref ($entry) ."), returning undef.\n"; $error_detected = 1; last; } if (1 < scalar (keys (%$entry))) { - print STDERR "More than one entry encountered in hash of current element, returning undef.\n"; + print {*STDERR} "More than one entry encountered in hash of current element, returning undef.\n"; $error_detected = 1; last; } @@ -244,7 +244,7 @@ sub intermediate_to_string { else { # Special handling for last element, which is always supposed to # contain the display port. - print STDERR "No entry found in display port hash, returning undef.\n"; + print {*STDERR} "No entry found in display port hash, returning undef.\n"; $error_detected = 1; last; } @@ -297,15 +297,15 @@ my $options = shift; my $intermediate = parse_options ($options); -print STDERR Dumper ($intermediate) . "\n"; +print {*STDERR} Dumper ($intermediate) . "\n"; -print STDERR Dumper (intermediate_to_string ($intermediate)) . "\n"; +print {*STDERR} Dumper (intermediate_to_string ($intermediate)) . "\n"; #my $value = shift; #my $allow_negative = shift; # #if (!(defined ($value))) { -# print STDERR "No value passed in, assuming empty string.\n"; +# print {*STDERR} "No value passed in, assuming empty string.\n"; # $value = q{}; #} # -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 2d99fd422e75b7f2e012b2c9bf063489ef9d3738 Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Dec 8 02:18:49 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: fix some "errors" reported by Perl::Critic in brutal mode. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 33 +++++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/debian/changelog b/debian/changelog index a96df9e..04a6f6f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -31,6 +31,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium of empty quotes as per some... coding standard. - x2goserver/lib/x2go{is{int,true},updateoptionsstring}: wrap print calls with filehandles in curly braces. + - x2goserver/lib/x2goupdateoptionsstring: fix some "errors" reported by + Perl::Critic in brutal mode. * 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 901a409..694567c 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -24,6 +24,7 @@ use warnings; use Data::Dumper qw (Dumper); use Getopt::Long; use Pod::Usage; +use English qw (-no_match_vars); # Accepts an option string and returns a reference to an array of hashes # (actually hash references) corresponding to the parsed key-value pairs. @@ -64,7 +65,7 @@ sub parse_options { my ($key, $value) = (undef, undef); my %kv_hash = (); - my @kv = split (/=/, $option, 2); + my @kv = split (/=/sxm, $option, 2); if (1 > scalar (@kv)) { print {*STDERR} "Options string has empty component, this is deprecated. Adding empty element.\n"; @@ -72,7 +73,7 @@ sub parse_options { push (@intermediate, \%kv_hash); } elsif (3 <= scalar (@kv)) { - print {*STDERR} "Options string has three or more components, this is a bug in $0. Erroring out.\n"; + print {*STDERR} "Options string has three or more components, this is a bug in $PROGRAM_NAME. Erroring out.\n"; $error_detected = 1; last; } @@ -107,7 +108,7 @@ sub parse_options { ++$hash_count; if (1 < $hash_count) { - print {*STDERR} "More than one element found in last element's hash, this is a bug in $0. Ignoring subsequent entries.\n"; + print {*STDERR} "More than one element found in last element's hash, this is a bug in $PROGRAM_NAME. Ignoring subsequent entries.\n"; last; } @@ -126,7 +127,7 @@ sub parse_options { # the LIMIT parameter to split() useless (since additional capture # groups are not part of the limit). # Thus going the manual route here. - my $last_pos = rindex ($last_component, ':'); + my $last_pos = rindex ($last_component, q{:}); if ($[ > $last_pos) { print {*STDERR} "No display port seperator found in the options string. Erroring out.\n"; @@ -188,13 +189,13 @@ sub intermediate_to_string { my $options = shift; if ('ARRAY' ne ref ($options)) { - print {*STDERR} "Invalid options reference type passed (" . ref ($options) . "), returning undef.\n"; + print {*STDERR} 'Invalid options reference type passed (' . ref ($options) . "), returning undef.\n"; $error_detected = 1; } if (!($error_detected)) { - if (1 == scalar (@$options)) { - foreach my $entry (@$options) { + if (1 == scalar (@{$options})) { + foreach my $entry (@{$options}) { if (!defined ($entry)) { print {*STDERR} "Invalid options array passed, returning undef.\n"; $error_detected = 1; @@ -206,10 +207,10 @@ sub intermediate_to_string { if (!($error_detected)) { # Last entry should contain the display port part only. # We can detect it through counting. - my $elements_left = @$options; + my $elements_left = @{$options}; # Handle entries iteratively, merging then into one string. - foreach my $entry (@$options) { + foreach my $entry (@{$options}) { --$elements_left; if (!defined ($entry)) { @@ -224,17 +225,17 @@ sub intermediate_to_string { last; } - if (1 < scalar (keys (%$entry))) { + if (1 < scalar (keys (%{$entry}))) { print {*STDERR} "More than one entry encountered in hash of current element, returning undef.\n"; $error_detected = 1; last; } # Must be either empty or have one element, so... go for it. - if (0 == scalar (keys (%$entry))) { + if (0 == scalar (keys (%{$entry}))) { if (0 != $elements_left) { if (defined ($ret)) { - $ret .= ','; + $ret .= q{,}; } else { # Mark first entry as empty. Don't remove this, or else. @@ -253,18 +254,18 @@ sub intermediate_to_string { # This foreach loop may look weird because, at that point, we know that # the hash contains one key exactly, but it's still an elegant way to # fetch the key and pseudo-iterate over it. - foreach my $key (keys (%$entry)) { + foreach my $key (keys (%{$entry})) { my $tmp = $key; if (0 != $elements_left) { if (defined ($entry->{$key})) { - $tmp .= '=' . $entry->{$key}; + $tmp .= q{=} . $entry->{$key}; } } if (defined ($ret)) { if (0 != $elements_left) { - $ret = join (',', ($ret, $tmp)); + $ret = join (q{,}, ($ret, $tmp)); } else { $ret .= $tmp; @@ -285,7 +286,7 @@ sub intermediate_to_string { return $ret; } -Getopt::Long::Configure("gnu_getopt", "no_auto_abbrev"); +Getopt::Long::Configure('gnu_getopt', 'no_auto_abbrev'); my $help = 0; my $man = 0; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 4f95c1d54c3aa8381252823d3acaa223fe6ae1db Author: Mihai Moldovan <ionic@ionic.de> Date: Sun Dec 9 02:05:36 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: add functionality for options removal. --- debian/changelog | 2 + x2goserver/lib/x2goupdateoptionsstring | 149 ++++++++++++++++++++++++++++++++- 2 files changed, 149 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 04a6f6f..8df7ab8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,6 +33,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium with filehandles in curly braces. - x2goserver/lib/x2goupdateoptionsstring: fix some "errors" reported by Perl::Critic in brutal mode. + - x2goserver/lib/x2goupdateoptionsstring: add functionality for options + removal. * 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 694567c..4bbe0f5 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -21,10 +21,11 @@ use strict; use warnings; #use X2Go::Utils qw (is_int); -use Data::Dumper qw (Dumper); +use English qw (-no_match_vars); use Getopt::Long; use Pod::Usage; -use English qw (-no_match_vars); +use Storable qw (dclone); +use Data::Dumper qw (Dumper); # Accepts an option string and returns a reference to an array of hashes # (actually hash references) corresponding to the parsed key-value pairs. @@ -286,6 +287,144 @@ sub intermediate_to_string { return $ret; } +# Helper for a grep operation on the intermediate options array. +# +# Takes the option to remove, the current element and amount of elements left +# in the array as arguments and returns true if the element is not to be +# removed, false otherwise. +sub filter_option_remove { + my $ret = 1; + my $error_detected = 0; + my $to_remove = shift; + my $cur_option = shift; + my $elems_left = shift; + + if (!((defined ($to_remove)) && (defined ($cur_option)) && (defined ($elems_left)))) { + # Undefined values are an error in this context, but erroring out in a + # comparison function is... weird, so let's treat such errors as "don't + # modify the array". + print {*STDERR} "Invalid options passed to removal filter, keeping entry.\n"; + $error_detected = 1; + } + + if (!($error_detected)) { + if ('HASH' ne ref ($cur_option)) { + print {*STDERR} "Option passed to removal filter is not a hash reference, keeping entry.\n"; + $error_detected = 1; + } + } + + if (!($error_detected)) { + if (1 < scalar (keys (%{$cur_option}))) { + print {*STDERR} "Option passed to removal filter has more than one entry in hash, keeping entry.\n"; + $error_detected = 1; + } + } + + my $to_remove_key = undef; + my $to_remove_value = undef; + my @to_remove_kv = split (/=/smx, $to_remove, 2); + + if (!($error_detected)) { + if (2 < scalar (@to_remove_kv)) { + print {*STDERR} "Option-to-be-removed string in removal filter has three or more components, this is a bug in $PROGRAM_NAME. Keeping entry.\n"; + $error_detected = 1; + } + } + + if (!($error_detected) && (0 < $elems_left)) { + $to_remove_key = shift (@to_remove_kv); + + # Key can be undef if splitting failed, e.g., due to an empty input string. + # We don't consider this an error, so reset the key to an empty string. + if (!(defined ($to_remove_key))) { + $to_remove_key = q{}; + } + + $to_remove_value = shift (@to_remove_kv); + + my $option_key = q{}; + my $option_value = undef; + + foreach my $tmp_option_key (keys (%{$cur_option})) { + $option_key = $tmp_option_key; + $option_value = $cur_option->{$tmp_option_key}; + } + + if ($to_remove_key eq $option_key) { + # Okay, we've got a match. But we might have to also check the value... + if (defined ($to_remove_value)) { + # Yep, value must match, too, but beware of undef values in the current + # option entry. + if ((defined ($option_value)) && ($to_remove_value eq $option_value)) { + # Everything matches, mark for removal. + $ret = 0; + } + } + else { + $ret = 0; + } + } + } + + return $ret; +} + +# Removes an entry from the intermediate options array. +# +# If only a key is specified, removes any entry that matches this key, +# regardless of its value. +# +# If both a key and a value are specified, only matching combinations will be +# removed from the array. That is, if the array already contains such a key +# with either no value or a different value, it will be unaffected. +# +# Returns a reference to a modified copy of the intermediate options array. +# +# On error, returns a reference to undef. +sub remove_option { + my $ret = undef; + my $error_detected = 0; + + my $options = shift; + my $option = shift; + + if ('ARRAY' ne ref ($options)) { + print {*STDERR} 'Invalid options reference type passed (' . ref ($options) . "), erroring out.\n"; + $error_detected = 1; + } + + if (!($error_detected)) { + if (1 == scalar (@{$options})) { + foreach my $entry (@{$options}) { + if (!defined ($entry)) { + print {*STDERR} "Invalid options array passed, erroring out.\n"; + $error_detected = 1; + } + } + } + } + + if (!($error_detected)) { + if (!(defined ($option))) { + print {*STDERR} "No or invalid option to be removed passed, erroring out.\n"; + $error_detected = 1; + } + } + + if (!($error_detected)) { + # Set return value to a *deep copy* of our original array. + $ret = dclone ($options); + + my $elements_left = @{$ret}; + + # Let the filter function handle the actual work. + @{$ret} = grep { filter_option_remove ($option, $_, --$elements_left) } (@{$ret}); + } + + return $ret; +} + Getopt::Long::Configure('gnu_getopt', 'no_auto_abbrev'); my $help = 0; @@ -302,6 +441,12 @@ print {*STDERR} Dumper ($intermediate) . "\n"; print {*STDERR} Dumper (intermediate_to_string ($intermediate)) . "\n"; +my $option_to_remove = shift; + +print {*STDERR} Dumper (remove_option ($intermediate, $option_to_remove)) . "\n"; + +print {*STDERR} Dumper (intermediate_to_string (remove_option ($intermediate, $option_to_remove))) . "\n"; + #my $value = shift; #my $allow_negative = shift; # -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 71f94f85b0ebe3056c78d91f5135cf06682a420c Author: Mihai Moldovan <ionic@ionic.de> Date: Sun Dec 9 02:13:57 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: update documentation to include the notion of the +key[=value] syntax, which makes sense to use if key starts with a dash and would be ambiguously interpreted as a removal. --- debian/changelog | 3 +++ x2goserver/lib/x2goupdateoptionsstring | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8df7ab8..cdcb15d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -35,6 +35,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium Perl::Critic in brutal mode. - x2goserver/lib/x2goupdateoptionsstring: add functionality for options removal. + - x2goserver/lib/x2goupdateoptionsstring: update documentation to include + the notion of the +key[=value] syntax, which makes sense to use if key + starts with a dash and would be ambiguously interpreted as a removal. * 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 4bbe0f5..c51fd73 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -477,7 +477,7 @@ x2goupdateoptionsstring - X2Go Agent Options String Manipulator =item B<x2goupdateoptionsstring> B<--man> -=item B<x2goupdateoptionsstring> I<options> [B<->]I<key>[B<=>I<value>] ... +=item B<x2goupdateoptionsstring> I<options> [B<->|B<+>]I<key>[B<=>I<value>] ... =back @@ -492,10 +492,12 @@ must be provided. It can either add, remove or replace components. -To add or replace a component, pass I<key>[B<=>I<value>] as a parameter. If the -options string does not include a B<key> key, it will be appended to the end of -the options string. If it already exists, either with no value or a different -value, the component will be replaced with the provided value. +To add or replace a component, pass I<key>[B<=>I<value>] or +B<+>I<key>[B<=>I<value>] as a parameter. The latter syntax is useful if I<key> +starts with a dash and would therefore be interpreted as a removal operation. +If the options string does not include a B<key> key, it will be appended to the +end of the options string. If it already exists, either with no value or a +different value, the component will be replaced with the provided value. To fully remove a component, pass B<->I<key>. To only remove it if it is set to a specific value, pass B<->I<key>B<=>I<value>. @@ -535,10 +537,10 @@ return nx/nx,clipboard=both,foo,bar:50 -and calling C<x2goupdateoptionsstring 'nx/nx,clipboard=both,foo:50' 'bar' +and calling C<x2goupdateoptionsstring 'nx/nx,clipboard=both,foo:50' '+-bar' 'foo=gulp' '-clipboard=client'> shall return - nx/nx,clipboard=both,foo=gulp,bar:50 + nx/nx,clipboard=both,foo=gulp,-bar:50 =head1 AUTHOR -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 0bb83397360a24fa35f6586629395126506132cb Author: Mihai Moldovan <ionic@ionic.de> Date: Sun Dec 9 11:23:57 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: refactor remove_option subprocedure into a more general transform_intermediate one and add code for the modification/addition case. --- debian/changelog | 3 + x2goserver/lib/x2goupdateoptionsstring | 290 +++++++++++++++++++++++++++------ 2 files changed, 247 insertions(+), 46 deletions(-) diff --git a/debian/changelog b/debian/changelog index cdcb15d..82a67e2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -38,6 +38,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: update documentation to include the notion of the +key[=value] syntax, which makes sense to use if key starts with a dash and would be ambiguously interpreted as a removal. + - x2goserver/lib/x2goupdateoptionsstring: refactor remove_option + subprocedure into a more general transform_intermediate one and add code + for the modification/addition case. * 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 c51fd73..f49d403 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -287,62 +287,101 @@ sub intermediate_to_string { return $ret; } -# Helper for a grep operation on the intermediate options array. +# Helper function that checks for errors in options passed as filter +# parameters (which, in turn, are the parameter this function expects). # -# Takes the option to remove, the current element and amount of elements left -# in the array as arguments and returns true if the element is not to be -# removed, false otherwise. -sub filter_option_remove { +# Returns true if all checks passed, false otherwise. +sub sanitize_input_filter { my $ret = 1; - my $error_detected = 0; - my $to_remove = shift; + + my $work_option_key = shift; + my $work_option_value = shift; my $cur_option = shift; my $elems_left = shift; - if (!((defined ($to_remove)) && (defined ($cur_option)) && (defined ($elems_left)))) { - # Undefined values are an error in this context, but erroring out in a - # comparison function is... weird, so let's treat such errors as "don't - # modify the array". - print {*STDERR} "Invalid options passed to removal filter, keeping entry.\n"; - $error_detected = 1; + if (!((defined ($work_option_key)) && (defined ($cur_option)) && (defined ($elems_left)))) { + print {*STDERR} "Invalid options passed to filter, keeping entry.\n"; + $ret = 0; } - if (!($error_detected)) { + if ($ret) { if ('HASH' ne ref ($cur_option)) { - print {*STDERR} "Option passed to removal filter is not a hash reference, keeping entry.\n"; - $error_detected = 1; + print {*STDERR} "Option passed to filter is not a hash reference, keeping entry.\n"; + $ret = 0; } } - if (!($error_detected)) { + if ($ret) { if (1 < scalar (keys (%{$cur_option}))) { - print {*STDERR} "Option passed to removal filter has more than one entry in hash, keeping entry.\n"; - $error_detected = 1; + print {*STDERR} "Option passed to filter has more than one entry in hash, keeping entry.\n"; + $ret = 0; } } - my $to_remove_key = undef; - my $to_remove_value = undef; - my @to_remove_kv = split (/=/smx, $to_remove, 2); + return $ret; +} - if (!($error_detected)) { - if (2 < scalar (@to_remove_kv)) { - print {*STDERR} "Option-to-be-removed string in removal filter has three or more components, this is a bug in $PROGRAM_NAME. Keeping entry.\n"; +# Helper function that splits up the working option into a key and a value. +# +# Expects the working option as its only parameter. +# +# Returns a reference to an array with two entries - the key and the value. +# Caveat: the key cannot be undef (it's set to the empty string if it would +# be), but the value can be undef. +# +# In case of errors, returns a reference to undef. +sub sanitize_workoption_filter { + my $ret = undef; + my $error_detected = 0; + + my $working_option = shift; + + if (defined ($working_option)) { + my $work_key = undef; + my $work_value = undef; + my @work_kv = split (/=/smx, $working_option, 2); + + if (2 < scalar (@work_kv)) { + print {*STDERR} "Option-to-be-acted-upon string in filter has three or more components, this is a bug in $PROGRAM_NAME. Returning error.\n"; $error_detected = 1; } - } - if (!($error_detected) && (0 < $elems_left)) { - $to_remove_key = shift (@to_remove_kv); + if (!($error_detected)) { + $work_key = shift (@work_kv); + + # Key can be undef if splitting failed, e.g., due to an empty input + # string. We don't consider this an error, so reset the key to an empty + # string. + if (!(defined ($work_key))) { + $work_key = q{}; + } - # Key can be undef if splitting failed, e.g., due to an empty input string. - # We don't consider this an error, so reset the key to an empty string. - if (!(defined ($to_remove_key))) { - $to_remove_key = q{}; + $work_value = shift (@work_kv); + + $ret = [ $work_key, $work_value ]; } + } - $to_remove_value = shift (@to_remove_kv); + return $ret; +} +# Helper for a grep operation on the intermediate options array. +# +# Takes the option-to-remove's key and value, the current element and amount +# of elements left in the array as arguments and returns true if the element is +# not to be removed, false otherwise. +sub filter_option_remove { + my $ret = 1; + my $skip = 0; + my $to_remove_key = shift; + my $to_remove_value = shift; + my $cur_option = shift; + my $elems_left = shift; + + $skip = ((!(sanitize_input_filter ($to_remove_key, $to_remove_value, $cur_option, $elems_left))) + || (0 == $elems_left)); + + if (!($skip)) { my $option_key = q{}; my $option_value = undef; @@ -370,23 +409,111 @@ sub filter_option_remove { return $ret; } -# Removes an entry from the intermediate options array. +# Helper for a grep operation on the intermediate options array. +# +# Takes the option-to-find's key and value, the current element and amount of +# elements left in the array as arguments and returns true if the element has +# the same as the option we search for, false otherwise. +sub filter_find_key { + my $ret = 0; + my $skip = 0; + my $needle_key = shift; + my $needle_value = shift; + my $cur_option = shift; + my $elems_left = shift; + + $skip = ((!(sanitize_input_filter ($needle_key, $needle_value, $cur_option, $elems_left))) + || (0 == $elems_left)); + + if (!($skip)) { + # We don't care about the values this time around. + + my $option_key = q{}; + + foreach my $tmp_option_key (keys (%{$cur_option})) { + $option_key = $tmp_option_key; + } + + if ($option_key eq $needle_key) { + $ret = 1; + } + } + + return $ret; +} + +# Helper for a map operation on the intermediate options array. # -# If only a key is specified, removes any entry that matches this key, -# regardless of its value. +# Takes the option-to-modify's key and value, the current element and amount of +# elements left in the array as arguments and returns the modified element or +# the original one, if modification was not necessary. +sub filter_option_modify { + my $skip = 0; + my $needle_key = shift; + my $needle_value = shift; + my $cur_option = shift; + my $elems_left = shift; + + my @ret = ( $cur_option ); + + $skip = ((!(sanitize_input_filter ($needle_key, $needle_value, $cur_option, $elems_left))) + || (0 == $elems_left)); + + if (!($skip)) { + my $option_key = q{}; + + foreach my $tmp_option_key (keys (%{$cur_option})) { + $option_key = $tmp_option_key; + } + + if ($option_key eq $needle_key) { + my $new_opt = { }; + + # Don't add empty options as an empty string key with undef value; even + # though that's technically legit we want to represent this situation by + # an empty hash. + if (!(($needle_key) || (defined ($needle_value)))) { + print {*STDERR} "Empty option addition/modification requested, this is deprecated. Adding empty hash.\n"; + } + else { + $new_opt->{$needle_key} = $needle_value; + } + + @ret = ( $new_opt ); + } + } + + return @ret; +} + +# Removes from, adds to or modifies an entry in the intermediate options array. +# +# Expects an intermediate options reference as its first parameter, a boolean +# value which should be set to true for removals or false for +# modifications/additions and the option-to-be-modified as a third parameter. # -# If both a key and a value are specified, only matching combinations will be -# removed from the array. That is, if the array already contains such a key -# with either no value or a different value, it will be unaffected. +# For removals, the function behaves like this: +# - If only a key is specified, removes any entry that matches this key, +# regardless of its value. +# - If both a key and a value are specified, only matching combinations will +# be removed from the array. That is, if the array already contains such a +# key with either no value or a different value, it will be unaffected. # -# Returns a reference to a modified copy of the intermediate options array. +# Additions or modifications are handled like this: +# - If a given key is part of the intermediate representation, all such +# occurrences will be replaced by the new value. +# - Otherwise, the new value will be added at the end of the intermediate +# representation. +# +# Returns a reference to a modified *copy* of the intermediate options array. # # On error, returns a reference to undef. -sub remove_option { +sub transform_intermediate { my $ret = undef; my $error_detected = 0; my $options = shift; + my $remove = shift; my $option = shift; if ('ARRAY' ne ref ($options)) { @@ -406,20 +533,81 @@ sub remove_option { } if (!($error_detected)) { + if (!(defined ($remove))) { + print {*STDERR} "Invalid mode option boolean passed, erroring out.\n"; + $error_detected = 1; + } + } + + if (!($error_detected)) { if (!(defined ($option))) { - print {*STDERR} "No or invalid option to be removed passed, erroring out.\n"; + print {*STDERR} "No or invalid new option 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)) { # Set return value to a *deep copy* of our original array. $ret = dclone ($options); my $elements_left = @{$ret}; - # Let the filter function handle the actual work. - @{$ret} = grep { filter_option_remove ($option, $_, --$elements_left) } (@{$ret}); + if ($remove) { + # Let the filter function handle the actual work. + @{$ret} = grep { filter_option_remove ($work_option_key, $work_option_value, $_, --$elements_left) } (@{$ret}); + + # Check to see if the intermediate representation is empty now (save for + # the display port entry) and add an empty element if it is. + if (1 == scalar (@{$ret})) { + print {*STDERR} "Removal operation led to option string being empty, adding empty element though deprecated.\n"; + unshift (@{$ret}, { }); + } + } + else { + # Yes, grep () isn't a great choice for a boolean comparison. It will do + # what we need just fine, but doesn't short-circuit after finding the + # first match, hence uselessly continuing through the full array. + # List::MoreUtils::any would be more appropriate here, but this would add + # another dependency and option strings are pretty small, so don't + # overoptimize here. + if (scalar (grep { filter_find_key ($work_option_key, $work_option_value, $_, --$elements_left) } (@{$ret}))) { + # Such an option already exists, we'll modify all occurrences. + $elements_left = @{$ret}; + $ret = [ map { filter_option_modify ($work_option_key, $work_option_value, $_, --$elements_left) } (@{$ret}) ]; + } + else { + my $new_opt = { $work_option_key => $work_option_value }; + + # No such option exists, we'll add it to the end of the current + # options. + # At least in theory. Practically, there's one special case: if the + # only "real" element is an empty one, for instance because the option + # string was empty to begin with save the display port specifier, then + # we want to replace this option instead. + if ((2 == scalar (@{$ret})) && (!(scalar (keys (%{$ret->[0]}))))) { + splice (@{$ret}, 0, 1, $new_opt); + } + else { + splice (@{$ret}, -1, 0, $new_opt); + } + } + } } return $ret; @@ -443,9 +631,19 @@ print {*STDERR} Dumper (intermediate_to_string ($intermediate)) . "\n"; my $option_to_remove = shift; -print {*STDERR} Dumper (remove_option ($intermediate, $option_to_remove)) . "\n"; +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 (remove_option ($intermediate, $option_to_remove))) . "\n"; +print {*STDERR} Dumper (intermediate_to_string ($intermediate_added)) . "\n"; #my $value = shift; #my $allow_negative = shift; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit e20033a73822b4a17e16ffd966e5f9125456e7bc Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Dec 10 12:41:50 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: ignore some very noisy Perl::Critic warnings that we're going to ignore anyway. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 3 +++ 2 files changed, 5 insertions(+) diff --git a/debian/changelog b/debian/changelog index 82a67e2..b83710f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -41,6 +41,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: refactor remove_option subprocedure into a more general transform_intermediate one and add code for the modification/addition case. + - x2goserver/lib/x2goupdateoptionsstring: ignore some very noisy + Perl::Critic warnings that we're going to ignore anyway. * 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 f49d403..57092ca 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -17,6 +17,9 @@ # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +# Disable some Perl::Critic violations. +## no critic (ProhibitParensWithBuiltins) + use strict; use warnings; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit ea949fba9a898c6248a78453d68f89ba9e892110 Author: Mihai Moldovan <ionic@ionic.de> Date: Mon Dec 10 12:42:19 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: fix interpolated string warning. --- debian/changelog | 1 + x2goserver/lib/x2goupdateoptionsstring | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index b83710f..bb6bea6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -43,6 +43,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium for the modification/addition case. - x2goserver/lib/x2goupdateoptionsstring: ignore some very noisy Perl::Critic warnings that we're going to ignore anyway. + - x2goserver/lib/x2goupdateoptionsstring: fix interpolated string warning. * 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 57092ca..9f64bfd 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -224,7 +224,7 @@ sub intermediate_to_string { } if ('HASH' ne ref ($entry)) { - print {*STDERR} "Entry in array has invalid type (" . ref ($entry) ."), returning undef.\n"; + print {*STDERR} 'Entry in array has invalid type (' . ref ($entry) ."), returning undef.\n"; $error_detected = 1; last; } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 5517537c1174eefab820f4c14bbe4d8651e406e2 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 09:49:22 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: add helper function for transform string interpretation. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/debian/changelog b/debian/changelog index bb6bea6..e7d59b9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -44,6 +44,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: ignore some very noisy Perl::Critic warnings that we're going to ignore anyway. - x2goserver/lib/x2goupdateoptionsstring: fix interpolated string warning. + - x2goserver/lib/x2goupdateoptionsstring: add helper function for + transform string interpretation. * 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 9f64bfd..811bf6d 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -28,6 +28,7 @@ use English qw (-no_match_vars); use Getopt::Long; use Pod::Usage; use Storable qw (dclone); +use Switch qw (fallthrough); use Data::Dumper qw (Dumper); # Accepts an option string and returns a reference to an array of hashes @@ -616,6 +617,56 @@ sub transform_intermediate { return $ret; } +# Helper function "interpreting" a transformation string. +# +# Takes the raw transformation string as its only parameter. +# +# Returns an array reference containing two elements: the transformation mode +# and a sanitized version of the transformation string, suitable for passing to +# transform_intermediate (). +# +# On error, returns undef. +sub interpret_transform { + my $ret = undef; + + my $transform = shift; + + if (defined ($transform)) { + my $mode = 0; + my $sanitized_transform = $transform; + + # Check if non-empty, empty transform strings can only mean an + # append/modify operation. + if ($transform) { + switch (substr ($transform, 0, 1)) { + case (q{-}) { + # Option starts with a dash, so must be a removal + # operation. + $mode = 1; + } + case (q{+}) { + # Options starting with a plus character are add/modify + # operations. The default mode option here is fine, but + # we'll need to strip the initial character. + # Careful: switch-fallthrough, even for the previous + # case(s)! + $sanitized_transform = substr ($sanitized_transform, 1); + last; + } + else { + # Everything else does not feature an explicit modifier, + # so we can take the transformation string verbatim. + # No need to actually do anything here, handled by the + # initialization. + } + } + } + # Set up return value accordingly. + $ret = [ $mode, $sanitized_transform ]; + } + return $ret; +} + Getopt::Long::Configure('gnu_getopt', 'no_auto_abbrev'); my $help = 0; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
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
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 4971a608244d3e25a13adf9cb154655431719e3a Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 10:11:20 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: add debug option and some debugging output. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 31 ++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index d54fd18..6745fc3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -49,6 +49,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: write wrapper that handles program options, creates intermediate, passes through transform chains, reconverts to a string and prints it. + - x2goserver/lib/x2goupdateoptionsstring: add debug option and some + debugging output. * 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 c562974..a88c79d 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -686,7 +686,8 @@ sub Main { my $help = 0; my $man = 0; - GetOptionsFromArray (\@_, 'help|?|h' => \$help, 'man' => \$man) or pod2usage (2); + my $debug = 0; + GetOptionsFromArray (\@_, 'help|?|h' => \$help, 'man' => \$man, 'debug|d' => \$debug) or pod2usage (2); if ($help) { pod2usage (1); @@ -714,6 +715,10 @@ sub Main { } } + if ($debug) { + print {*STDERR} 'Dumping intermediate array after initial parsing: ' . Dumper ($intermediate); + } + if (!($error_detected)) { my $cur_transform = shift; @@ -728,6 +733,10 @@ sub Main { last; } + if ($debug) { + print {*STDERR} 'Parsing current raw transformation option: ' . Dumper ($cur_transform); + } + my $interpreted_transform_ref = interpret_transform ($cur_transform); if (!(defined ($interpreted_transform_ref))) { @@ -738,6 +747,10 @@ sub Main { 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 = transform_intermediate ($intermediate, $transform_mode, $sanitized_transform); if (!(defined ($intermediate))) { @@ -745,6 +758,10 @@ sub Main { $error_detected = 7; last; } + + if ($debug) { + print {*STDERR} 'Dumping transformed intermediate array: ' . Dumper ($intermediate); + } }} while (defined ($cur_transform = shift)); } @@ -814,7 +831,7 @@ x2goupdateoptionsstring - X2Go Agent Options String Manipulator =item B<x2goupdateoptionsstring> B<--man> -=item B<x2goupdateoptionsstring> I<options> [B<->|B<+>]I<key>[B<=>I<value>] ... +=item B<x2goupdateoptionsstring> [B<--debug>|B<-d>] [B<-->] [B<->|B<+>]I<key>[B<=>I<value>] ... =back @@ -823,9 +840,9 @@ x2goupdateoptionsstring - X2Go Agent Options String Manipulator B<x2goupdateoptionsstring> is a utility for manipulating options strings as passed to X2Go Agent/NX Agent. -Called it with the options string as the first parameter and the options you -want to manipulate as additional parameters. At least one additional parameter -must be provided. +Call it with optional flags, the options string as the first parameter and the +options you want to manipulate as additional parameters. At least one +additional parameter must be provided. It can either add, remove or replace components. @@ -851,6 +868,10 @@ Print a brief help message and exits. Prints the manual page and exits. +=item B<--debug>|B<-d> + +Enables noisy debug output. + =back =head1 EXAMPLE -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 7f717e48a5acc1516827573fae521b188df0b94f Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 10:12:33 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: remove dead code. --- debian/changelog | 1 + x2goserver/lib/x2goupdateoptionsstring | 34 ---------------------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6745fc3..613fcb1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -51,6 +51,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium reconverts to a string and prints it. - x2goserver/lib/x2goupdateoptionsstring: add debug option and some debugging output. + - x2goserver/lib/x2goupdateoptionsstring: remove dead code. * 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 a88c79d..1dcab20 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -780,40 +780,6 @@ sub Main { 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; } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit b74def088c12188ef1e632c6cdaa78af76147f9f Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 10:19:49 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: update documentation and clarify risks of option parsing. It's better to always use -- to terminate program options parsing when no longer needed. --- debian/changelog | 3 +++ x2goserver/lib/x2goupdateoptionsstring | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/debian/changelog b/debian/changelog index 613fcb1..f6909d5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -52,6 +52,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: add debug option and some debugging output. - x2goserver/lib/x2goupdateoptionsstring: remove dead code. + - x2goserver/lib/x2goupdateoptionsstring: update documentation and clarify + risks of option parsing. It's better to always use -- to terminate + program options parsing when no longer needed. * 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 1dcab20..6e304e8 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -822,6 +822,11 @@ different value, the component will be replaced with the provided value. To fully remove a component, pass B<->I<key>. To only remove it if it is set to a specific value, pass B<->I<key>B<=>I<value>. +You can terminate program options parsing via a standard double-dash (B<-->) +pseudo-option. It is recommended to always do so if you pass removal +transformation operations, even if no actual options are used to avoid +misinterpreting such transformation options as options/flags to the program. + =head1 OPTIONS =over 8 -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit b5f6c039e99787ebf8b56a02cd157ab8a3c9d634 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 10:22:36 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: don't debug-output the intermediate representation if we know that parsing failed. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index f6909d5..07deb10 100644 --- a/debian/changelog +++ b/debian/changelog @@ -55,6 +55,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: update documentation and clarify risks of option parsing. It's better to always use -- to terminate program options parsing when no longer needed. + - x2goserver/lib/x2goupdateoptionsstring: don't debug-output the + intermediate representation if we know that parsing failed. * 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 6e304e8..48da644 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -715,13 +715,13 @@ sub Main { } } - if ($debug) { - print {*STDERR} 'Dumping intermediate array after initial parsing: ' . Dumper ($intermediate); - } - if (!($error_detected)) { my $cur_transform = shift; + if ($debug) { + print {*STDERR} 'Dumping intermediate array after initial parsing: ' . Dumper ($intermediate); + } + # 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. -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 043c6623a4922de503cc9449fbf98d2dec5196ab Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 10:30:27 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: fix debug string and add another one dumping the raw options string. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 07deb10..e26f649 100644 --- a/debian/changelog +++ b/debian/changelog @@ -57,6 +57,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium program options parsing when no longer needed. - x2goserver/lib/x2goupdateoptionsstring: don't debug-output the intermediate representation if we know that parsing failed. + - x2goserver/lib/x2goupdateoptionsstring: fix debug string and add another + one dumping the raw options string. * 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 48da644..06d82a5 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -700,13 +700,17 @@ sub Main { my $options = shift; if (!(defined ($options))) { - print {*STDERR} "No or invalid options string given, aborting.\n"; + print {*STDERR} "No options string given, aborting.\n"; $error_detected = 4; } my $intermediate = undef; if (!($error_detected)) { + if ($debug) { + print {*STDERR} 'Fetched options string as: ' . Dumper (\$options); + } + $intermediate = parse_options ($options); if (!(defined ($intermediate))) { -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 0d086816198d5c55e8e1b2a34291f3d6ed744af6 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 13 08:29:10 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: fix parsing of transformation strings by replacing the switch statement with if statements. "Fallthrough" doesn't mean the same thing as in C, apparently. Buyer beware. --- debian/changelog | 4 ++++ x2goserver/lib/x2goupdateoptionsstring | 36 +++++++++++++--------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/debian/changelog b/debian/changelog index e26f649..8ee6e8d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -59,6 +59,10 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium intermediate representation if we know that parsing failed. - x2goserver/lib/x2goupdateoptionsstring: fix debug string and add another one dumping the raw options string. + - x2goserver/lib/x2goupdateoptionsstring: fix parsing of transformation + strings by replacing the switch statement with if statements. + "Fallthrough" doesn't mean the same thing as in C, apparently. Buyer + beware. * 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 06d82a5..1521d3e 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -28,7 +28,6 @@ use English qw (-no_match_vars); use Getopt::Long qw (GetOptionsFromArray); use Pod::Usage; use Storable qw (dclone); -use Switch qw (fallthrough); use Data::Dumper qw (Dumper); exit (Main (@ARGV)); @@ -645,28 +644,21 @@ sub interpret_transform { # Check if non-empty, empty transform strings can only mean an # append/modify operation. if ($transform) { - switch (substr ($transform, 0, 1)) { - case (q{-}) { - # Option starts with a dash, so must be a removal - # operation. - $mode = 1; - } - case (q{+}) { - # Options starting with a plus character are add/modify - # operations. The default mode option here is fine, but - # we'll need to strip the initial character. - # Careful: switch-fallthrough, even for the previous - # case(s)! - $sanitized_transform = substr ($sanitized_transform, 1); - last; - } - else { - # Everything else does not feature an explicit modifier, - # so we can take the transformation string verbatim. - # No need to actually do anything here, handled by the - # initialization. - } + if (q{-} eq substr ($transform, 0, 1)) { + # Option starts with a dash, so must be a removal operation. + $mode = 1; + $sanitized_transform = substr ($sanitized_transform, 1); } + elsif ((q{+}) eq substr ($transform, 0, 1)) { + # Options starting with a plus character are add/modify operations. The + # default mode option here is fine, but we'll need to strip the initial + # character. + $sanitized_transform = substr ($sanitized_transform, 1); + } + + # Everything else does not feature an explicit modifier, so we can take + # the transformation string verbatim. + # No need to actually do anything here, handled by the initialization. } # Set up return value accordingly. -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 1759ca1e39f2c2a91abc9d37d5a40cef1bf902d2 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 13 08:52:15 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: handle options in a more robust way. First, we scan for unknown options and error out. If we find a separating "--" pseudo-option, we keep that in mind and will not process further options next time. Do this for every run of the transformation loop. --- debian/changelog | 5 + x2goserver/lib/x2goupdateoptionsstring | 164 ++++++++++++++++++++++++++++++--- 2 files changed, 157 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8ee6e8d..24a3137 100644 --- a/debian/changelog +++ b/debian/changelog @@ -63,6 +63,11 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium strings by replacing the switch statement with if statements. "Fallthrough" doesn't mean the same thing as in C, apparently. Buyer beware. + - x2goserver/lib/x2goupdateoptionsstring: handle options in a more robust + way. First, we scan for unknown options and error out. If we find a + separating "--" pseudo-option, we keep that in mind and will not process + further options next time. Do this for every run of the transformation + loop. * 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 1521d3e..6330d39 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -668,11 +668,107 @@ sub interpret_transform { return $ret; } +# Helper function handling unknown options or ignoring the well-known +# separator. It scans for options until hitting the first non-option entry. +# +# Takes an array reference with unparsed options and a boolean value denoting +# whether the separating "--" pseudo-option should be skipped or not as its +# parameters. +# +# Returns an array reference containing a boolean value denoting whether a +# separating "--" pseudo-option has been found *and* skipping it was requested, +# and the sanitized version of the original array reference. +# +# On error, returns undef. +sub sanitize_program_options { + my $ret = undef; + my $error_detected = 0; + my $found_separator = 0; + + my $args = shift; + my $skip_separator = shift; + + if ((!(defined ($args))) || ('ARRAY' ne ref ($args))) { + print {*STDERR} "Invalid argument array reference passed to program sanitization helper, erroring out.\n"; + $error_detected = 1; + } + + if (!($error_detected)) { + if (!(defined ($skip_separator))) { + print {*STDERR} "No skip-separator parameter passed to program sanitization helper, erroring out.\n"; + $error_detected = 1; + } + } + + if (!($error_detected)) { + $args = dclone ($args); + + my $opt = 1; + for (my $cur_arg = shift (@{$args}); ((defined ($cur_arg)) && ($opt)); $cur_arg = shift (@{$args})) { + if (q{-} eq substr ($cur_arg, 0, 1)) { + # Looks like an option so far. Let's continue scanning. + + if (1 == length ($cur_arg)) { + # But isn't a real option. Add back to argument list and stop + # processing. + unshift (@{$args}, $cur_arg); + last; + } + elsif ((2 == length ($cur_arg)) && (q{-} eq substr ($cur_arg, 1, 1))) { + if ($skip_separator) { + # Found separating "--" pseudo-option, but skipping requested. Only + # set the boolean value for our return value. + $found_separator = 1; + } + else { + # Not skipping separating "--" pseudo-option - i.e., we'll treat this + # as a non-option. + unshift (@{$args}, $cur_arg); + last; + } + } + else { + # Otherwise this is an actual option. + # We either want to error out, if no previous separating "--" + # pseudo-option was found, or ignore it. + # The weird 0 + (...) construct here is forcing an arithmetic + # context. Otherwise, the interpreter might use a string context, + # in which the value "0" is dualvar'd to both an arithmetic 0 and + # an empty string. + my $separator_found = (0 + ((!($skip_separator)) | ($found_separator))); + if ($separator_found) { + # Put back into array. We'll handle this as not-an-option. + unshift (@{$args}, $cur_arg); + last; + } + else { + print {*STDERR} "Unknown option encountered: " . $cur_arg ."; erroring out.\n"; + $error_detected = 1; + last; + } + } + } + else { + # Definitely not an option, add back to array. + unshift (@{$args}, $cur_arg); + last; + } + } + } + + if (!($error_detected)) { + $ret = [ $found_separator, $args ]; + } + + return $ret; +} + # Main function, no code outside of it shall be executed. # # Expects @ARGV to be passed in. sub Main { my $error_detected = 0; + my $found_separator = 0; Getopt::Long::Configure ('gnu_getopt', 'no_auto_abbrev', 'pass_through'); @@ -689,13 +785,28 @@ sub Main { pod2usage (-verbose => 2, -exitval => 3); } - my $options = shift; + my $sanitized_options = sanitize_program_options (\@_, (!($found_separator))); - if (!(defined ($options))) { - print {*STDERR} "No options string given, aborting.\n"; + if (!(defined ($sanitized_options))) { + pod2usage (-exitval => 'NOEXIT'); $error_detected = 4; } + my $options = undef; + + if (!($error_detected)) { + $found_separator |= (0 + shift (@{$sanitized_options})); + $sanitized_options = shift (@{$sanitized_options}); + @_ = @{$sanitized_options}; + + $options = shift; + + if (!(defined ($options))) { + print {*STDERR} "No options string given, aborting.\n"; + $error_detected = 5; + } + } + my $intermediate = undef; if (!($error_detected)) { @@ -707,11 +818,24 @@ sub Main { if (!(defined ($intermediate))) { print {*STDERR} "Unable to parse option string, aborting.\n"; - $error_detected = 5; + $error_detected = 6; } } if (!($error_detected)) { + $sanitized_options = sanitize_program_options (\@_, (!($found_separator))); + + if (!(defined ($sanitized_options))) { + pod2usage (-exitval => 'NOEXIT'); + $error_detected = 7; + } + } + + if (!($error_detected)) { + $found_separator |= (0 + shift (@{$sanitized_options})); + $sanitized_options = shift (@{$sanitized_options}); + @_ = @{$sanitized_options}; + my $cur_transform = shift; if ($debug) { @@ -719,13 +843,16 @@ sub Main { } # 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 {{ + # Perl, but we could wrap the body in another block, which WILL BE recognized + # as a loop (one, that only executes once), oddly enough. However, using + # "last" won't work in such a situation, but rather behave like "next". + # Worse, the condition will also not be checked in such a case. + # Thus, we'd better use a real loop. + while (1) { # 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; + $error_detected = 8; last; } @@ -737,7 +864,7 @@ sub Main { if (!(defined ($interpreted_transform_ref))) { print {*STDERR} "Invalid transformation passed, aborting.\n"; - $error_detected = 7; + $error_detected = 9; last; } @@ -751,14 +878,27 @@ sub Main { if (!(defined ($intermediate))) { print {*STDERR} "Error while transforming intermediate representation, aborting.\n"; - $error_detected = 7; + $error_detected = 10; last; } if ($debug) { print {*STDERR} 'Dumping transformed intermediate array: ' . Dumper ($intermediate); } - }} while (defined ($cur_transform = shift)); + + # Skip pseudo-option, if necessary. + $sanitized_options = sanitize_program_options (\@_, (!($found_separator))); + + if (!(defined ($sanitized_options))) { + pod2usage (-exitval => 'NOEXIT'); + $error_detected = 11; + last; + } + + $found_separator |= (0 + shift (@{$sanitized_options})); + $sanitized_options = shift (@{$sanitized_options}); + @_ = @{$sanitized_options}; + } continue { last unless (defined ($cur_transform = shift)) }; } my $out = undef; @@ -768,7 +908,7 @@ sub Main { if (!(defined ($out))) { print {*STDERR} "Unable to transform intermediate back into string, aborting.\n"; - $error_detected = 8; + $error_detected = 12; } } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 517db0a657e4c2e77d764b600abb526a62422325 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 13 11:11:13 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: fix another Perl::Critic nit. --- debian/changelog | 1 + x2goserver/lib/x2goupdateoptionsstring | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index 24a3137..c19cbb1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -68,6 +68,7 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium separating "--" pseudo-option, we keep that in mind and will not process further options next time. Do this for every run of the transformation loop. + - x2goserver/lib/x2goupdateoptionsstring: fix another Perl::Critic nit. * 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 6330d39..561fd3f 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -767,6 +767,7 @@ sub sanitize_program_options { # # Expects @ARGV to be passed in. sub Main { + my @program_arguments = @_; my $error_detected = 0; my $found_separator = 0; @@ -775,7 +776,7 @@ sub Main { my $help = 0; my $man = 0; my $debug = 0; - GetOptionsFromArray (\@_, 'help|?|h' => \$help, 'man' => \$man, 'debug|d' => \$debug) or pod2usage (2); + GetOptionsFromArray (\@program_arguments, 'help|?|h' => \$help, 'man' => \$man, 'debug|d' => \$debug) or pod2usage (2); if ($help) { pod2usage (1); @@ -785,7 +786,7 @@ sub Main { pod2usage (-verbose => 2, -exitval => 3); } - my $sanitized_options = sanitize_program_options (\@_, (!($found_separator))); + my $sanitized_options = sanitize_program_options (\@program_arguments, (!($found_separator))); if (!(defined ($sanitized_options))) { pod2usage (-exitval => 'NOEXIT'); @@ -797,9 +798,9 @@ sub Main { if (!($error_detected)) { $found_separator |= (0 + shift (@{$sanitized_options})); $sanitized_options = shift (@{$sanitized_options}); - @_ = @{$sanitized_options}; + @program_arguments = @{$sanitized_options}; - $options = shift; + $options = shift (@program_arguments); if (!(defined ($options))) { print {*STDERR} "No options string given, aborting.\n"; @@ -823,7 +824,7 @@ sub Main { } if (!($error_detected)) { - $sanitized_options = sanitize_program_options (\@_, (!($found_separator))); + $sanitized_options = sanitize_program_options (\@program_arguments, (!($found_separator))); if (!(defined ($sanitized_options))) { pod2usage (-exitval => 'NOEXIT'); @@ -834,9 +835,9 @@ sub Main { if (!($error_detected)) { $found_separator |= (0 + shift (@{$sanitized_options})); $sanitized_options = shift (@{$sanitized_options}); - @_ = @{$sanitized_options}; + @program_arguments = @{$sanitized_options}; - my $cur_transform = shift; + my $cur_transform = shift (@program_arguments); if ($debug) { print {*STDERR} 'Dumping intermediate array after initial parsing: ' . Dumper ($intermediate); @@ -887,7 +888,7 @@ sub Main { } # Skip pseudo-option, if necessary. - $sanitized_options = sanitize_program_options (\@_, (!($found_separator))); + $sanitized_options = sanitize_program_options (\@program_arguments, (!($found_separator))); if (!(defined ($sanitized_options))) { pod2usage (-exitval => 'NOEXIT'); @@ -897,8 +898,8 @@ sub Main { $found_separator |= (0 + shift (@{$sanitized_options})); $sanitized_options = shift (@{$sanitized_options}); - @_ = @{$sanitized_options}; - } continue { last unless (defined ($cur_transform = shift)) }; + @program_arguments = @{$sanitized_options}; + } continue { last unless (defined ($cur_transform = shift (@program_arguments))) }; } my $out = undef; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 4db3e0155e6310eafe38a4ef40616aa3236125b3 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 13 11:16:30 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: move into x2goserver/bin, since it's really a standalone program and also useful for non-X2Go-internal usage. --- debian/changelog | 3 +++ x2goserver/{lib => bin}/x2goupdateoptionsstring | 0 2 files changed, 3 insertions(+) diff --git a/debian/changelog b/debian/changelog index c19cbb1..26d7659 100644 --- a/debian/changelog +++ b/debian/changelog @@ -69,6 +69,9 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium further options next time. Do this for every run of the transformation loop. - x2goserver/lib/x2goupdateoptionsstring: fix another Perl::Critic nit. + - x2goserver/lib/x2goupdateoptionsstring: move into x2goserver/bin, since + it's really a standalone program and also useful for non-X2Go-internal + usage. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goupdateoptionsstring b/x2goserver/bin/x2goupdateoptionsstring similarity index 100% rename from x2goserver/lib/x2goupdateoptionsstring rename to x2goserver/bin/x2goupdateoptionsstring -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 9a9f3a9bf8870f94061a014fe0037fb3c4c7130c Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 13 11:18:31 2018 +0100 x2goserver/Makefile: add x2goupdateoptionsstring POD-to-man-page handling. --- debian/changelog | 2 ++ x2goserver/Makefile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 26d7659..928967d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -72,6 +72,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: move into x2goserver/bin, since it's really a standalone program and also useful for non-X2Go-internal usage. + - x2goserver/Makefile: add x2goupdateoptionsstring POD-to-man-page + handling. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/Makefile b/x2goserver/Makefile index fb53980..f76fdf2 100755 --- a/x2goserver/Makefile +++ b/x2goserver/Makefile @@ -23,7 +23,7 @@ BIN_SCRIPTS=$(shell cd bin && echo *) SBIN_SCRIPTS=$(shell cd sbin && echo *) LIB_FILES=$(shell cd lib && echo *) FEATURE_SCRIPTS=$(shell cd share/x2gofeature.d && echo *.features) -POD_SCRIPTS="sbin/x2gocleansessions.8" +POD_SCRIPTS="sbin/x2gocleansessions.8 bin/x2goupdateoptionsstring.1" man_pages = `cd man && find * -type f` -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 0a789a74ca1fea17a758c39381a2a74edaf4eaf2 Author: Mihai Moldovan <ionic@ionic.de> Date: Thu Dec 13 11:20:24 2018 +0100 debian/x2goserver.install: install bin/x2goupdateoptionsstring. --- debian/changelog | 2 ++ debian/x2goserver.install | 1 + 2 files changed, 3 insertions(+) diff --git a/debian/changelog b/debian/changelog index 928967d..935db04 100644 --- a/debian/changelog +++ b/debian/changelog @@ -80,6 +80,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium + Install x2gocleansessions man page. * x2goserver.spec: + Install new x2goisint wrapper. + * debian/x2goserver.install: + + Install bin/x2goupdateoptionsstring. -- X2Go Release Manager <git-admin@x2go.org> Thu, 29 Nov 2018 07:57:20 +0100 diff --git a/debian/x2goserver.install b/debian/x2goserver.install index 10f6d7d..c76a876 100644 --- a/debian/x2goserver.install +++ b/debian/x2goserver.install @@ -22,6 +22,7 @@ usr/bin/x2gosuspend-session usr/bin/x2goterminate-session usr/bin/x2goumount-session usr/bin/x2goumount_session +usr/bin/x2goupdateoptionsstring usr/bin/x2goversion usr/lib/x2go/x2go* usr/sbin/x2go* -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git