holograph commented on a change in pull request #500:
URL: https://github.com/apache/guacamole-client/pull/500#discussion_r575814178
##########
File path:
guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java
##########
@@ -83,14 +111,24 @@ private GuacamoleInstruction expect(GuacamoleReader
reader, String opcode)
if (instruction == null)
throw new GuacamoleServerException("End of stream while waiting
for \"" + opcode + "\".");
+ // Handle server control commands
+ if ("disconnect".equals(instruction.getOpcode()))
+ throw new GuacamoleServerException("Server disconnected while
waiting for \"" + opcode + "\".");
+ if ("error".equals(instruction.getOpcode())) {
+ GuacamoleServerErrorCommandException e =
parseServerErrorCommandArgs(instruction.getArgs());
+ if (e == null)
+ throw new GuacamoleServerException("Invalid command received
from server: " + instruction);
Review comment:
Fair enough, incorporated the feedback. After a couple of iterations it
does look better, have a look.
##########
File path:
guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java
##########
@@ -63,12 +64,39 @@
*/
private GuacamoleProtocolVersion protocolVersion =
GuacamoleProtocolVersion.VERSION_1_0_0;
-
+
+ /**
+ * Parses the arguments for the Guacamole "error" server command and
returns
+ * the corresponding exception.
+ * @param args The arguments as provided by the server command.
+ * @return An instance of {@link GuacamoleServerErrorCommandException}
configured
+ * with the server-provided arguments, or {@literal null} if the
specified
+ * arguments are invalid.
+ */
+ private static GuacamoleServerErrorCommandException
parseServerErrorCommandArgs(List<String> args) {
+ if (args == null || args.size() != 2)
+ return null;
+
+ int code;
+ try {
+ code = Integer.parseInt(args.get(1));
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ GuacamoleStatus status = GuacamoleStatus.fromGuacamoleStatusCode(code);
+ return (status == null)
+ ? null
+ : new GuacamoleServerErrorCommandException(args.get(0),
status);
+ }
+
/**
* Waits for the instruction having the given opcode, returning that
* instruction once it has been read. If the instruction is never read,
* an exception is thrown.
- *
+ *
+ * Respects server control commands that are allowed during the handshake
Review comment:
Fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]