2016-05-14 00:35:41 +00:00
|
|
|
#if __ORCAC__
|
|
|
|
#pragma lint -1
|
2015-09-24 00:40:17 +00:00
|
|
|
#pragma noroot
|
2016-05-14 02:44:12 +00:00
|
|
|
segment "VNCview GS";
|
2016-05-14 00:35:41 +00:00
|
|
|
#endif
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#include <window.h>
|
|
|
|
#include <quickdraw.h>
|
|
|
|
#include <qdaux.h>
|
|
|
|
#include <desk.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <resources.h>
|
|
|
|
#include <tcpip.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <control.h>
|
|
|
|
#include <misctool.h>
|
|
|
|
#include <scrap.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <event.h>
|
|
|
|
#include <limits.h>
|
2016-05-14 00:35:41 +00:00
|
|
|
#include <orca.h>
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#include "vncsession.h"
|
|
|
|
#include "vncview.h"
|
|
|
|
#include "vncdisplay.h"
|
2016-09-16 03:25:02 +00:00
|
|
|
#include "readtcp.h"
|
2015-09-24 00:40:17 +00:00
|
|
|
#include "clipboard.h"
|
|
|
|
|
2016-09-17 23:01:31 +00:00
|
|
|
/*
|
|
|
|
* Tables for character set conversion. The current RFB spec says
|
|
|
|
* that the clipboard data should use the ISO 8859-1 character set.
|
|
|
|
* In practice, several servers actually use Windows-1252 (which is
|
|
|
|
* a superset of ISO 8859-1), and even those that don't seem to be
|
|
|
|
* able to gracefully discard the extra characters from it.
|
|
|
|
* We also use Windows-1252, for compatibility with servers that
|
|
|
|
* may send it and because it enables us to map more of the MacRoman
|
|
|
|
* characters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned char macRomanToWindows1252[128] = {
|
|
|
|
/* 80 - 87 */ 0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1,
|
|
|
|
/* 88 - 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0XF0, 0XF0, 0xd8,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-09-18 04:40:10 +00:00
|
|
|
static unsigned long textLen;
|
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Update the Scrap Manager clipboard with new data sent from server.
|
|
|
|
*/
|
|
|
|
void DoServerCutText (void) {
|
2015-09-24 01:26:03 +00:00
|
|
|
if (! DoWaitingReadTCP (3)) { /* Read & ignore padding */
|
|
|
|
DoClose(vncWindow);
|
2015-09-24 00:40:17 +00:00
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
if (! DoWaitingReadTCP (4)) {
|
|
|
|
DoClose(vncWindow);
|
2015-09-24 00:40:17 +00:00
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2016-09-16 02:40:39 +00:00
|
|
|
textLen = SwapBytes4(*(unsigned long *)readBufferPtr);
|
2016-09-18 04:40:10 +00:00
|
|
|
|
|
|
|
/* Set up to wait for clipboard data. Treat this like a
|
|
|
|
* "display in progress," although it's really not. */
|
|
|
|
displayInProgress = TRUE;
|
|
|
|
GetClipboard();
|
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-09-18 04:40:10 +00:00
|
|
|
void GetClipboard (void) {
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
if (! DoReadTCP(textLen)) {
|
2015-09-24 00:40:17 +00:00
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
};
|
2015-09-24 01:26:03 +00:00
|
|
|
if (allowClipboardTransfers) {
|
2015-09-24 00:40:17 +00:00
|
|
|
ZeroScrap();
|
|
|
|
|
2016-09-17 23:01:31 +00:00
|
|
|
/* Convert lf->cr and convert Windows-1252 or ISO 8859-1 charset
|
|
|
|
* to MacRoman. Use pointer arithmetic so we can go over 64k. */
|
|
|
|
for (i = 0; i < textLen; i++) {
|
|
|
|
if (*(readBufferPtr+i) == '\n') {
|
2016-09-16 02:40:39 +00:00
|
|
|
*(readBufferPtr+i) = '\r';
|
2016-09-17 23:01:31 +00:00
|
|
|
} else if (*(readBufferPtr+i) & 0x80) {
|
|
|
|
*(readBufferPtr+i) =
|
|
|
|
windows1252ToMacRoman[*(readBufferPtr+i) & 0x7f];
|
|
|
|
}
|
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
/* Below function call requires <scrap.h> to be fixed */
|
2016-09-16 02:40:39 +00:00
|
|
|
PutScrap(textLen, textScrap, (Pointer) readBufferPtr);
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Potential errors (e.g. out of memory) ignored */
|
2016-05-29 02:59:35 +00:00
|
|
|
DoneWithReadBuffer();
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2016-09-18 04:40:10 +00:00
|
|
|
|
|
|
|
displayInProgress = FALSE;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
void DoSendClipboard (void) {
|
2015-09-24 01:26:03 +00:00
|
|
|
static struct clientCutText {
|
|
|
|
unsigned char messageType;
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned char padding1;
|
|
|
|
unsigned int padding2;
|
|
|
|
unsigned long length;
|
2015-09-24 01:56:33 +00:00
|
|
|
} clientCutTextStruct = { 6 /* Message type 6 */ };
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
Handle scrapHandle;
|
2016-09-17 23:01:31 +00:00
|
|
|
unsigned char *scrapPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned long i;
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
/* Only proceed if we're connected to the server and not view-only */
|
|
|
|
if (vncConnected && !viewOnlyMode) {
|
|
|
|
clientCutTextStruct.length = GetScrapSize(textScrap);
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
if (clientCutTextStruct.length == 0)
|
2015-09-24 01:26:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
clientCutTextStruct.length = SwapBytes4(clientCutTextStruct.length);
|
2015-09-24 01:26:03 +00:00
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
scrapHandle = NewHandle(1, userid(), 0x0000, NULL);
|
|
|
|
GetScrap(scrapHandle, textScrap);
|
|
|
|
if (toolerror())
|
2015-09-24 01:26:03 +00:00
|
|
|
goto end; /* abort if error */
|
|
|
|
if (TCPIPWriteTCP(hostIpid, &clientCutTextStruct.messageType,
|
|
|
|
sizeof(clientCutTextStruct), FALSE, FALSE))
|
|
|
|
goto end; /* abort if error */
|
2015-09-24 00:40:17 +00:00
|
|
|
if (toolerror())
|
2015-09-24 01:26:03 +00:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
clientCutTextStruct.length = SwapBytes4(clientCutTextStruct.length);
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
HLock(scrapHandle);
|
2016-09-17 23:01:31 +00:00
|
|
|
scrapPtr = *(unsigned char **)scrapHandle;
|
|
|
|
/* Convert cr->lf and convert MacRoman to Windows-1252 charset.
|
|
|
|
* Use pointer arithmetic so we can go over 64k. */
|
|
|
|
for (i = 0; i < clientCutTextStruct.length; i++) {
|
|
|
|
if (*(scrapPtr+i) == '\r') {
|
|
|
|
*(scrapPtr+i) = '\n';
|
|
|
|
} else if (*(scrapPtr+i) & 0x80) {
|
|
|
|
*(scrapPtr+i) =
|
|
|
|
macRomanToWindows1252[*(scrapPtr+i) & 0x7f];
|
|
|
|
}
|
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
TCPIPWriteTCP(hostIpid, (Pointer) *scrapHandle,
|
|
|
|
clientCutTextStruct.length, TRUE, FALSE);
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Can't handle errors usefully here */
|
|
|
|
HUnlock(scrapHandle);
|
|
|
|
|
|
|
|
end:
|
|
|
|
DisposeHandle(scrapHandle);
|
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|