GUACAMOLE-249: Remove RAIL callback typecasts, relying instead on configure tests to check need for const.
diff --git a/configure.ac b/configure.ac
index f245da3..ef8f661 100644
--- a/configure.ac
+++ b/configure.ac
@@ -627,6 +627,36 @@
 
 fi
 
+# RAIL callback variants
+if test "x${have_freerdp2}" = "xyes"
+then
+
+    # FreeRDP 2.0.0-rc3 and older did not use const for RAIL callbacks
+    AC_MSG_CHECKING([whether RAIL callbacks require const for their final parameter])
+    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+
+        #include <freerdp/client/rail.h>
+        #include <winpr/wtypes.h>
+
+        UINT test_server_handshake(RailClientContext* rail,
+                const RAIL_HANDSHAKE_ORDER* handshake);
+
+        RailClientContext context = {
+            .ServerHandshake = test_server_handshake
+        };
+
+        int main() {
+            return (int) context.ServerHandshake(NULL, NULL);
+        }
+
+    ]])],
+    [AC_MSG_RESULT([yes])]
+    [AC_DEFINE([FREERDP_RAIL_CALLBACKS_REQUIRE_CONST],,
+               [Whether RAIL callbacks require const for the final parameter])],
+    [AC_MSG_RESULT([no])])
+
+fi
+
 AM_CONDITIONAL([ENABLE_RDP], [test "x${have_freerdp2}" = "xyes"])
 
 #
diff --git a/src/protocols/rdp/channels/rail.c b/src/protocols/rdp/channels/rail.c
index 60ead63..3e80007 100644
--- a/src/protocols/rdp/channels/rail.c
+++ b/src/protocols/rdp/channels/rail.c
@@ -33,6 +33,20 @@
 #include <stddef.h>
 #include <string.h>
 
+#ifdef FREERDP_RAIL_CALLBACKS_REQUIRE_CONST
+/**
+ * FreeRDP 2.0.0-rc4 and newer requires the final argument for all RAIL
+ * callbacks to be const.
+ */
+#define RAIL_CONST const
+#else
+/**
+ * FreeRDP 2.0.0-rc3 and older requires the final argument for all RAIL
+ * callbacks to NOT be const.
+ */
+#define RAIL_CONST
+#endif
+
 /**
  * Completes initialization of the RemoteApp session, sending client system
  * parameters and executing the desired RemoteApp command using the Client
@@ -102,7 +116,7 @@
  *     (non-zero) otherwise.
  */
 static UINT guac_rdp_rail_handshake(RailClientContext* rail,
-        const RAIL_HANDSHAKE_ORDER* handshake) {
+        RAIL_CONST RAIL_HANDSHAKE_ORDER* handshake) {
     return guac_rdp_rail_complete_handshake(rail);
 }
 
@@ -126,7 +140,7 @@
  *     (non-zero) otherwise.
  */
 static UINT guac_rdp_rail_handshake_ex(RailClientContext* rail,
-        const RAIL_HANDSHAKE_EX_ORDER* handshake_ex) {
+        RAIL_CONST RAIL_HANDSHAKE_EX_ORDER* handshake_ex) {
     return guac_rdp_rail_complete_handshake(rail);
 }
 
@@ -164,8 +178,8 @@
     /* Init FreeRDP RAIL context, ensuring the guac_client can be accessed from
      * within any RAIL-specific callbacks */
     rail->custom = client;
-    rail->ServerHandshake = (pcRailServerHandshake) guac_rdp_rail_handshake;
-    rail->ServerHandshakeEx = (pcRailServerHandshakeEx) guac_rdp_rail_handshake_ex;
+    rail->ServerHandshake = guac_rdp_rail_handshake;
+    rail->ServerHandshakeEx = guac_rdp_rail_handshake_ex;
 
     guac_client_log(client, GUAC_LOG_DEBUG, "RAIL (RemoteApp) channel "
             "connected.");