From 86334c2d9a133bd8e8c6259d62b04774a0cf17d4 Mon Sep 17 00:00:00 2001 From: DRC Date: Thu, 5 Mar 2020 12:49:11 -0600 Subject: [PATCH] SessMgr: Make 'vncserver -sessionlist' extensible This commit modifies the SessionList() function in vncserver so that it prepends the session list with a session count and field size and separates fields with tabs instead of spaces. The field size is currently 1 but can be increased later, if we decide to add more session information to the -sessionlist output. That session information can now easily contain spaces as well, since we're using tabs as field separators. This commit also modifies the Session Manager parser so that it reads and verifies the session count and field size, as well as (for future-proofness) ignores any fields other than the ones it needs. Refer to #148 --- java/com/turbovnc/vncviewer/SessionManager.java | 13 ++++++++++++- unix/vncserver.in | 7 +++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/java/com/turbovnc/vncviewer/SessionManager.java b/java/com/turbovnc/vncviewer/SessionManager.java index 03aa9dece..d2a18bdd6 100644 --- a/java/com/turbovnc/vncviewer/SessionManager.java +++ b/java/com/turbovnc/vncviewer/SessionManager.java @@ -113,7 +113,18 @@ private static String[] getSessions(Session sshSession, String host) if (!result.startsWith("[TURBOVNC] ")) continue; result = result.replace("[TURBOVNC] ", ""); if (error == null && result.length() > 0) error = result; - sessions = result.split(" "); + String[] splitResult = result.split("\t"); + if (splitResult.length >= 2) { + int numSessions = Integer.parseInt(splitResult[0]); + int numFields = Integer.parseInt(splitResult[1]); + if (numSessions > 0 && numFields > 0 && + splitResult.length == numSessions * numFields + 2) { + ArrayList sessionList = new ArrayList(); + for (int index = 2; index < splitResult.length; index += numFields) + sessionList.add(splitResult[index]); + sessions = sessionList.toArray(new String[numSessions]); + } + } break; } diff --git a/unix/vncserver.in b/unix/vncserver.in index 9f78496b1..eaa7b4f45 100644 --- a/unix/vncserver.in +++ b/unix/vncserver.in @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# Copyright (C) 2009-2018 D. R. Commander. All Rights Reserved. +# Copyright (C) 2009-2018, 2020 D. R. Commander. All Rights Reserved. # Copyright (C) 2010 University Corporation for Atmospheric Research. # All Rights Reserved. # Copyright (C) 2005-2006 Sun Microsystems, Inc. All Rights Reserved. @@ -890,10 +890,13 @@ sub SessionList } if (scalar(@sessions)) { @sessions = sort { $a <=> $b } @sessions; + print scalar(@sessions)."\t1\t"; foreach my $session (@sessions) { - print ":".$session." "; + print ":".$session."\t"; } print "\n"; + } else { + print "0\t1\n"; } exit; }