diff --git a/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java b/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java index b14f9aa19..a9b9898d7 100644 --- a/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java +++ b/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java @@ -19,7 +19,6 @@ package org.apache.guacamole.protocol; - import java.util.List; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleServerException; @@ -56,6 +55,15 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket { */ private String id; + /** + * The protocol version that will be used to communicate with guacd. The + * default is 1.0.0, and, if the server does not provide a specific version + * it will be assumed that it operates at this version and certain features + * may be unavailable. + */ + private GuacamoleProtocolVersion protocol = + GuacamoleProtocolVersion.VERSION_1_0_0; + /** * Waits for the instruction having the given opcode, returning that * instruction once it has been read. If the instruction is never read, @@ -137,6 +145,13 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket { // Build args list off provided names and config List arg_names = args.getArgs(); + + // Check for protocol version as first argument + if (arg_names.get(0).startsWith("VERSION_")) { + String protocolArg = arg_names.get(0); + protocol = GuacamoleProtocolVersion.valueOf(protocolArg); + } + String[] arg_values = new String[arg_names.size()]; for (int i=0; i otherVersion.getMajor()) + return true; + + // Major version is less than or equal to. + else { + + // Major version is less than + if (major < otherVersion.getMajor()) + return false; + + // Major version is equal, minor version is greater + if (minor > otherVersion.getMinor()) + return true; + + // Minor version is less than or equal to. + else { + + // Minor version is less than + if (minor < otherVersion.getMinor()) + return false; + + // Patch version is greater or equal + if (patch >= otherVersion.getPatch()) + return true; + } + } + + // Version is either less than or equal to. + return false; + + } + + /** + * Parses the given string version, returning the GuacamoleProtocolVersion + * object that matches the string version. If a matching version is not + * found an exception is thrown. + * + * @param version + * The String representation of a version to parse. + * + * @return + * The GuacamoleProtocolVersion that matches the string version + * that has been provided. + * + * @throws GuacamoleException + * If the string version does not match any known enum values. + */ + public static GuacamoleProtocolVersion parseVersion(String version) + throws GuacamoleException { + + for (GuacamoleProtocolVersion v : GuacamoleProtocolVersion.values()) { + if (v.getVersion().equals(version)) + return v; + } + + throw new GuacamoleUnsupportedException("Version " + version + + " of Guacamole protocol is not valid."); + + } + + /** + * Parse the version provided as individual version components to the + * matching enum version. If a match is not found an exception is + * thrown. + * + * @param major + * The integer major version. + * + * @param minor + * The integer minor version. + * + * @param patch + * The integer patch version. + * + * @return + * The GuacamoleProtocolVersion that matches the individual components + * that were provided. + * + * @throws GuacamoleException + * If the provided components do not match any known enum value. + */ + public static GuacamoleProtocolVersion parseVersion(int major, int minor, int patch) + throws GuacamoleException { + + for (GuacamoleProtocolVersion v : GuacamoleProtocolVersion.values()) { + if (v.getMajor() == major + && v.getMinor() == minor + && v.getPatch() == patch) + return v; + } + + throw new GuacamoleUnsupportedException("Version " + + Integer.toString(major) + "." + + Integer.toString(minor) + "." + + Integer.toString(patch) + + " is not valid."); + + } + +}