Restructure Xvnc/libvnc.so code to avoid C++ header hacks

The internal Xorg headers are very incompatible with C++ and we've had
to resort to all kinds of hacks in order to include them in our C++
code. This approach isn't really viable long term so restructure things
so that we have a glue layer written in C that bridges the Xorg core
with the RFB classes.
diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx
index b11a352..6e221d5 100644
--- a/common/rfb/ServerCore.cxx
+++ b/common/rfb/ServerCore.cxx
@@ -97,4 +97,8 @@
 ("QueryConnect",
  "Prompt the local user to accept or reject incoming connections.",
  false);
-
+rfb::IntParameter rfb::Server::queryConnectTimeout
+("QueryConnectTimeout",
+ "Number of seconds to show the Accept Connection dialog before "
+ "rejecting the connection",
+ 10);
diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h
index 5fc996f..c4d7d53 100644
--- a/common/rfb/ServerCore.h
+++ b/common/rfb/ServerCore.h
@@ -48,6 +48,7 @@
     static BoolParameter sendCutText;
     static BoolParameter acceptSetDesktopSize;
     static BoolParameter queryConnect;
+    static IntParameter queryConnectTimeout;
 
   };
 
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index e30b4f4..746bb90 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -1,5 +1,5 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
- * Copyright 2009-2014 Pierre Ossman for Cendio AB
+ * Copyright 2009-2015 Pierre Ossman for Cendio AB
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -66,7 +66,8 @@
 
 VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s,
                                    bool reverse)
-  : SConnection(reverse), sock(s), inProcessMessages(false),
+  : SConnection(reverse), sock(s),
+    queryConnectTimer(this), inProcessMessages(false),
     pendingSyncFence(false), syncFence(false), fenceFlags(0),
     fenceDataLen(0), fenceData(NULL),
     baseRTT(-1), minRTT(-1), seenCongestion(false), pingCounter(0),
@@ -434,8 +435,10 @@
   CharArray reason;
   VNCServerST::queryResult qr = server->queryConnection(sock, userName,
                                                         &reason.buf);
-  if (qr == VNCServerST::PENDING)
+  if (qr == VNCServerST::PENDING) {
+    queryConnectTimer.start(rfb::Server::queryConnectTimeout * 1000);
     return;
+  }
 
   // - If server returns ACCEPT/REJECT then pass result to SConnection
   approveConnection(qr == VNCServerST::ACCEPT, reason.buf);
@@ -714,6 +717,10 @@
       writeFramebufferUpdate();
     else if (t == &congestionTimer)
       updateCongestion();
+    else if (t == &queryConnectTimer) {
+      if (state() == RFBSTATE_QUERYING)
+        approveConnection(false, "The attempt to prompt the user to accept the connection failed");
+    }
   } catch (rdr::Exception& e) {
     close(e.str());
   }
diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h
index fd1897a..7b25570 100644
--- a/common/rfb/VNCSConnectionST.h
+++ b/common/rfb/VNCSConnectionST.h
@@ -174,6 +174,8 @@
     network::Socket* sock;
     CharArray peerEndpoint;
 
+    Timer queryConnectTimer;
+
     bool inProcessMessages;
 
     bool pendingSyncFence, syncFence;