Skip to content

Commit

Permalink
SessMgr: Make 'vncserver -sessionlist' extensible
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dcommander committed Mar 5, 2020
1 parent 44c5a1a commit 86334c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 12 additions & 1 deletion java/com/turbovnc/vncviewer/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> sessionList = new ArrayList<String>();
for (int index = 2; index < splitResult.length; index += numFields)
sessionList.add(splitResult[index]);
sessions = sessionList.toArray(new String[numSessions]);
}
}
break;
}

Expand Down
7 changes: 5 additions & 2 deletions unix/vncserver.in
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 86334c2

Please sign in to comment.