Improved clipboard API

Change the internal clipboard API to use a request based model in
order to be prepared for more advanced clipboard transfers.
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index 002ae92..cdd87b1 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-2018 Pierre Ossman for Cendio AB
+ * Copyright 2009-2019 Pierre Ossman for Cendio AB
  * Copyright 2018 Peter Astrand for Cendio AB
  * 
  * This is free software; you can redistribute it and/or modify
@@ -282,19 +282,6 @@
   }
 }
 
-void VNCSConnectionST::serverCutTextOrClose(const char *str)
-{
-  try {
-    if (!accessCheck(AccessCutText)) return;
-    if (!rfb::Server::sendCutText) return;
-    if (state() == RFBSTATE_NORMAL)
-      writer()->writeServerCutText(str);
-  } catch(rdr::Exception& e) {
-    close(e.str());
-  }
-}
-
-
 void VNCSConnectionST::setDesktopNameOrClose(const char *name)
 {
   try {
@@ -305,7 +292,6 @@
   }
 }
 
-
 void VNCSConnectionST::setCursorOrClose()
 {
   try {
@@ -316,7 +302,6 @@
   }
 }
 
-
 void VNCSConnectionST::setLEDStateOrClose(unsigned int state)
 {
   try {
@@ -327,6 +312,41 @@
   }
 }
 
+void VNCSConnectionST::requestClipboardOrClose()
+{
+  try {
+    if (!accessCheck(AccessCutText)) return;
+    if (!rfb::Server::acceptCutText) return;
+    if (state() != RFBSTATE_NORMAL) return;
+    requestClipboard();
+  } catch(rdr::Exception& e) {
+    close(e.str());
+  }
+}
+
+void VNCSConnectionST::announceClipboardOrClose(bool available)
+{
+  try {
+    if (!accessCheck(AccessCutText)) return;
+    if (!rfb::Server::sendCutText) return;
+    if (state() != RFBSTATE_NORMAL) return;
+    announceClipboard(available);
+  } catch(rdr::Exception& e) {
+    close(e.str());
+  }
+}
+
+void VNCSConnectionST::sendClipboardDataOrClose(const char* data)
+{
+  try {
+    if (!accessCheck(AccessCutText)) return;
+    if (!rfb::Server::sendCutText) return;
+    if (state() != RFBSTATE_NORMAL) return;
+    sendClipboardData(data);
+  } catch(rdr::Exception& e) {
+    close(e.str());
+  }
+}
 
 bool VNCSConnectionST::getComparerState()
 {
@@ -596,13 +616,6 @@
   server->keyEvent(keysym, keycode, down);
 }
 
-void VNCSConnectionST::clientCutText(const char* str)
-{
-  if (!accessCheck(AccessCutText)) return;
-  if (!rfb::Server::acceptCutText) return;
-  server->clientCutText(str);
-}
-
 void VNCSConnectionST::framebufferUpdateRequest(const Rect& r,bool incremental)
 {
   Rect safeRect;
@@ -719,6 +732,26 @@
   }
 }
 
+void VNCSConnectionST::handleClipboardRequest()
+{
+  if (!accessCheck(AccessCutText)) return;
+  server->handleClipboardRequest(this);
+}
+
+void VNCSConnectionST::handleClipboardAnnounce(bool available)
+{
+  if (!accessCheck(AccessCutText)) return;
+  if (!rfb::Server::acceptCutText) return;
+  server->handleClipboardAnnounce(this, available);
+}
+
+void VNCSConnectionST::handleClipboardData(const char* data)
+{
+  if (!accessCheck(AccessCutText)) return;
+  if (!rfb::Server::acceptCutText) return;
+  server->handleClipboardData(this, data);
+}
+
 // supportsLocalCursor() is called whenever the status of
 // client.supportsLocalCursor() has changed.  If the client does now support local
 // cursor, we make sure that the old server-side rendered cursor is cleaned up
@@ -756,7 +789,6 @@
   writer()->writeLEDState();
 }
 
-
 bool VNCSConnectionST::handleTimeout(Timer* t)
 {
   try {