channels/cliprdr: add missing messages in cliprdr server

This commit is contained in:
Marc-André Moreau 2014-12-15 17:05:32 -05:00
parent f1bd547580
commit a69eaddecd
3 changed files with 436 additions and 169 deletions

View File

@ -67,11 +67,12 @@ static int cliprdr_server_send_capabilities(CliprdrServerContext* context)
{
wStream* s;
BOOL status;
ULONG written;
UINT32 generalFlags;
CLIPRDR_HEADER header;
ULONG written;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
WLog_DBG(TAG, "CliprdrServerSendCapabilities");
WLog_DBG(TAG, "CliprdrServerCapabilities");
header.msgType = CB_CLIP_CAPS;
header.msgFlags = 0;
@ -79,7 +80,7 @@ static int cliprdr_server_send_capabilities(CliprdrServerContext* context)
generalFlags = 0;
if (context->priv->UseLongFormatNames)
if (cliprdr->useLongFormatNames)
generalFlags |= CB_USE_LONG_FORMAT_NAMES;
s = Stream_New(NULL, header.dataLen + CLIPRDR_HEADER_LENGTH);
@ -98,20 +99,23 @@ static int cliprdr_server_send_capabilities(CliprdrServerContext* context)
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
status = WTSVirtualChannelWrite(cliprdr->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return 0;
return 1;
}
static int cliprdr_server_send_monitor_ready(CliprdrServerContext* context)
{
wStream* s;
BOOL status;
CLIPRDR_HEADER header;
ULONG written;
WLog_DBG(TAG, "CliprdrServerSendMonitorReady");
CLIPRDR_HEADER header;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
WLog_DBG(TAG, "CliprdrServerMonitorReady");
header.msgType = CB_MONITOR_READY;
header.msgFlags = 0;
header.dataLen = 0;
@ -124,20 +128,23 @@ static int cliprdr_server_send_monitor_ready(CliprdrServerContext* context)
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
status = WTSVirtualChannelWrite(cliprdr->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return 0;
return 1;
}
static int cliprdr_server_send_format_list_response(CliprdrServerContext* context)
int cliprdr_server_send_format_list_response(CliprdrServerContext* context)
{
wStream* s;
BOOL status;
CLIPRDR_HEADER header;
ULONG written;
WLog_DBG(TAG, "CliprdrServerSendFormatListResponse");
CLIPRDR_HEADER header;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
WLog_DBG(TAG, "CliprdrServerFormatListResponse");
header.msgType = CB_FORMAT_LIST_RESPONSE;
header.msgFlags = CB_RESPONSE_OK;
header.dataLen = 0;
@ -150,32 +157,33 @@ static int cliprdr_server_send_format_list_response(CliprdrServerContext* contex
Stream_SealLength(s);
status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
status = WTSVirtualChannelWrite(cliprdr->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return 0;
return 1;
}
static int cliprdr_server_receive_general_capability(CliprdrServerContext* context, wStream* s)
{
UINT32 version;
UINT32 generalFlags;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
Stream_Read_UINT32(s, version); /* version (4 bytes) */
Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */
if (generalFlags & CB_USE_LONG_FORMAT_NAMES)
context->priv->UseLongFormatNames = TRUE;
cliprdr->useLongFormatNames = TRUE;
if (generalFlags & CB_STREAM_FILECLIP_ENABLED)
context->priv->StreamFileClipEnabled = TRUE;
cliprdr->streamFileClipEnabled = TRUE;
if (generalFlags & CB_FILECLIP_NO_FILE_PATHS)
context->priv->FileClipNoFilePaths = TRUE;
cliprdr->fileClipNoFilePaths = TRUE;
if (generalFlags & CB_CAN_LOCK_CLIPDATA)
context->priv->CanLockClipData = TRUE;
cliprdr->canLockClipData = TRUE;
return 1;
}
@ -187,6 +195,8 @@ static int cliprdr_server_receive_capabilities(CliprdrServerContext* context, wS
UINT16 capabilitySetType;
UINT16 lengthCapability;
WLog_DBG(TAG, "CliprdrClientCapabilities");
Stream_Read_UINT16(s, cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */
Stream_Seek_UINT16(s); /* pad1 (2 bytes) */
@ -212,7 +222,10 @@ static int cliprdr_server_receive_capabilities(CliprdrServerContext* context, wS
static int cliprdr_server_receive_temporary_directory(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
int length;
WCHAR* wszTempDir;
CLIPRDR_TEMP_DIRECTORY tempDirectory;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
if (Stream_GetRemainingLength(s) < 520)
return -1;
@ -222,134 +235,335 @@ static int cliprdr_server_receive_temporary_directory(CliprdrServerContext* cont
if (wszTempDir[260] != 0)
return -1;
free(cliprdr->temporaryDirectory);
cliprdr->temporaryDirectory = NULL;
ConvertFromUnicode(CP_UTF8, 0, wszTempDir, -1,
&(context->priv->ClientTemporaryDirectory), 0, NULL, NULL);
WLog_DBG(TAG, "ClientTemporaryDirectory: %s", context->priv->ClientTemporaryDirectory);
return 0;
}
&(cliprdr->temporaryDirectory), 0, NULL, NULL);
int cliprdr_wcslen(const WCHAR* str, const WCHAR* end)
{
WCHAR* p = (WCHAR*) str;
length = strlen(cliprdr->temporaryDirectory);
if (!p)
return -1;
if (length > 519)
length = 519;
while (*p)
{
if (p == end)
return -1;
CopyMemory(tempDirectory.szTempDir, cliprdr->temporaryDirectory, length);
tempDirectory.szTempDir[length] = '\0';
p++;
}
WLog_DBG(TAG, "CliprdrTemporaryDirectory: %s", cliprdr->temporaryDirectory);
return (p - str);
}
if (context->TempDirectory)
context->TempDirectory(context, &tempDirectory);
static void cliprdr_free_format_list(UINT32 count, CLIPRDR_FORMAT_NAME* formatNames)
{
int i;
if (formatNames)
{
for (i = 0; i < count; i++)
{
free(formatNames[i].name);
}
free(formatNames);
}
}
static int cliprdr_server_receive_long_format_list(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
int i;
WCHAR* end;
int length;
int position;
WLog_DBG(TAG, "");
position = Stream_GetPosition(s);
Stream_SetPosition(s, Stream_Length(s));
end = (WCHAR*) Stream_Pointer(s);
Stream_SetPosition(s, position);
cliprdr_free_format_list(context->priv->ClientFormatNameCount, context->priv->ClientFormatNames);
context->priv->ClientFormatNameCount = 0;
context->priv->ClientFormatNames = NULL;
while (Stream_GetRemainingLength(s) >= 6)
{
Stream_Seek(s, 4); /* formatId (4 bytes) */
length = cliprdr_wcslen((WCHAR*) Stream_Pointer(s), end);
if (length < 0)
return -1;
Stream_Seek(s, (length + 1) * 2); /* wszFormatName */
context->priv->ClientFormatNameCount++;
}
context->priv->ClientFormatNames = (CLIPRDR_FORMAT_NAME*)
malloc(sizeof(CLIPRDR_FORMAT_NAME) * context->priv->ClientFormatNameCount);
Stream_SetPosition(s, position);
for (i = 0; i < context->priv->ClientFormatNameCount; i++)
{
Stream_Read_UINT32(s, context->priv->ClientFormatNames[i].id); /* formatId (4 bytes) */
length = cliprdr_wcslen((WCHAR*) Stream_Pointer(s), end);
context->priv->ClientFormatNames[i].name = NULL;
if (length)
{
context->priv->ClientFormatNames[i].length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s),
-1, &(context->priv->ClientFormatNames[i].name), 0, NULL, NULL) - 1;
}
else
{
context->priv->ClientFormatNames[i].length = 0;
}
Stream_Seek(s, (length + 1) * 2); /* wszFormatName */
}
for (i = 0; i < context->priv->ClientFormatNameCount; i++)
{
WLog_DBG(TAG, "Format %d: Id: 0x%04X Name: %s Length: %d", i,
context->priv->ClientFormatNames[i].id,
context->priv->ClientFormatNames[i].name,
context->priv->ClientFormatNames[i].length);
}
return 0;
}
static int cliprdr_server_receive_short_format_list(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
WLog_ERR(TAG, "%s: unimplemented");
return 0;
return 1;
}
static int cliprdr_server_receive_format_list(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
int status;
UINT32 index;
UINT32 dataLen;
UINT32 position;
BOOL asciiNames;
int formatNameLength;
char* szFormatName;
WCHAR* wszFormatName;
CLIPRDR_FORMAT* formats = NULL;
CLIPRDR_FORMAT_LIST formatList;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
if (context->priv->UseLongFormatNames)
dataLen = header->dataLen;
asciiNames = (header->msgFlags & CB_ASCII_NAMES) ? TRUE : FALSE;
formatList.msgType = CB_FORMAT_LIST;
formatList.msgFlags = header->msgFlags;
formatList.dataLen = header->dataLen;
index = 0;
formatList.numFormats = 0;
position = Stream_GetPosition(s);
if (!cliprdr->useLongFormatNames)
{
status = cliprdr_server_receive_long_format_list(context, s, header);
formatList.numFormats = (dataLen / 36);
if ((formatList.numFormats * 36) != dataLen)
{
WLog_ERR(TAG, "Invalid short format list length: %d", dataLen);
return -1;
}
if (formatList.numFormats)
formats = (CLIPRDR_FORMAT*) calloc(formatList.numFormats, sizeof(CLIPRDR_FORMAT));
if (!formats)
return -1;
formatList.formats = formats;
while (dataLen)
{
Stream_Read_UINT32(s, formats[index].formatId); /* formatId (4 bytes) */
dataLen -= 4;
formats[index].formatName = NULL;
if (asciiNames)
{
szFormatName = (char*) Stream_Pointer(s);
if (szFormatName[0])
{
formats[index].formatName = (char*) malloc(32 + 1);
CopyMemory(formats[index].formatName, szFormatName, 32);
formats[index].formatName[32] = '\0';
}
}
else
{
status = cliprdr_server_receive_short_format_list(context, s, header);
wszFormatName = (WCHAR*) Stream_Pointer(s);
if (wszFormatName[0])
{
ConvertFromUnicode(CP_UTF8, 0, wszFormatName,
16, &(formats[index].formatName), 0, NULL, NULL);
}
}
cliprdr_server_send_format_list_response(context);
Stream_Seek(s, 32);
dataLen -= 32;
index++;
}
}
else
{
while (dataLen)
{
Stream_Seek(s, 4); /* formatId (4 bytes) */
dataLen -= 4;
return status;
wszFormatName = (WCHAR*) Stream_Pointer(s);
if (!wszFormatName[0])
formatNameLength = 0;
else
formatNameLength = _wcslen(wszFormatName);
Stream_Seek(s, (formatNameLength + 1) * 2);
dataLen -= ((formatNameLength + 1) * 2);
formatList.numFormats++;
}
dataLen = formatList.dataLen;
Stream_SetPosition(s, position);
if (formatList.numFormats)
formats = (CLIPRDR_FORMAT*) calloc(formatList.numFormats, sizeof(CLIPRDR_FORMAT));
if (!formats)
return -1;
formatList.formats = formats;
while (dataLen)
{
Stream_Read_UINT32(s, formats[index].formatId); /* formatId (4 bytes) */
dataLen -= 4;
formats[index].formatName = NULL;
wszFormatName = (WCHAR*) Stream_Pointer(s);
if (!wszFormatName[0])
formatNameLength = 0;
else
formatNameLength = _wcslen(wszFormatName);
if (formatNameLength)
{
ConvertFromUnicode(CP_UTF8, 0, wszFormatName,
-1, &(formats[index].formatName), 0, NULL, NULL);
}
Stream_Seek(s, (formatNameLength + 1) * 2);
dataLen -= ((formatNameLength + 1) * 2);
index++;
}
}
WLog_DBG(TAG, "ClientFormatList: numFormats: %d",
formatList.numFormats);
if (context->ClientFormatList)
context->ClientFormatList(context, &formatList);
for (index = 0; index < formatList.numFormats; index++)
{
if (formats[index].formatName)
free(formats[index].formatName);
}
free(formats);
return 1;
}
static int cliprdr_server_receive_format_list_response(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse;
WLog_DBG(TAG, "CliprdrClientFormatListResponse");
formatListResponse.msgType = CB_FORMAT_LIST_RESPONSE;
formatListResponse.msgFlags = header->msgFlags;
formatListResponse.dataLen = header->dataLen;
if (context->ClientFormatListResponse)
context->ClientFormatListResponse(context, &formatListResponse);
return 1;
}
static int cliprdr_server_receive_lock_clipdata(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData;
WLog_DBG(TAG, "CliprdrClientLockClipData");
if (Stream_GetRemainingLength(s) < 4)
return -1;
lockClipboardData.msgType = CB_LOCK_CLIPDATA;
lockClipboardData.msgFlags = header->msgFlags;
lockClipboardData.dataLen = header->dataLen;
Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */
if (context->ClientLockClipboardData)
context->ClientLockClipboardData(context, &lockClipboardData);
return 1;
}
static int cliprdr_server_receive_unlock_clipdata(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData;
WLog_DBG(TAG, "CliprdrClientUnlockClipData");
unlockClipboardData.msgType = CB_UNLOCK_CLIPDATA;
unlockClipboardData.msgFlags = header->msgFlags;
unlockClipboardData.dataLen = header->dataLen;
if (Stream_GetRemainingLength(s) < 4)
return -1;
Stream_Read_UINT32(s, unlockClipboardData.clipDataId); /* clipDataId (4 bytes) */
if (context->ClientUnlockClipboardData)
context->ClientUnlockClipboardData(context, &unlockClipboardData);
return 1;
}
static int cliprdr_server_receive_format_data_request(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest;
WLog_DBG(TAG, "CliprdrClientFormatDataRequest");
formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST;
formatDataRequest.msgFlags = header->msgFlags;
formatDataRequest.dataLen = header->dataLen;
if (Stream_GetRemainingLength(s) < 4)
return -1;
Stream_Read_UINT32(s, formatDataRequest.requestedFormatId); /* requestedFormatId (4 bytes) */
if (context->ClientFormatDataRequest)
context->ClientFormatDataRequest(context, &formatDataRequest);
return 1;
}
static int cliprdr_server_receive_format_data_response(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse;
WLog_DBG(TAG, "CliprdrClientFormatDataResponse");
formatDataResponse.msgType = CB_FORMAT_DATA_RESPONSE;
formatDataResponse.msgFlags = header->msgFlags;
formatDataResponse.dataLen = header->dataLen;
formatDataResponse.requestedFormatData = NULL;
if (Stream_GetRemainingLength(s) < header->dataLen)
return -1;
if (header->dataLen)
{
formatDataResponse.requestedFormatData = (BYTE*) malloc(header->dataLen);
Stream_Read(s, formatDataResponse.requestedFormatData, header->dataLen);
}
if (context->ClientFormatDataResponse)
context->ClientFormatDataResponse(context, &formatDataResponse);
free(formatDataResponse.requestedFormatData);
return 1;
}
static int cliprdr_server_receive_filecontents_request(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FILE_CONTENTS_REQUEST request;
WLog_DBG(TAG, "CliprdrClientFileContentsRequest");
request.msgType = CB_FILECONTENTS_REQUEST;
request.msgFlags = header->msgFlags;
request.dataLen = header->dataLen;
if (Stream_GetRemainingLength(s) < 28)
return -1;
Stream_Read_UINT32(s, request.streamId); /* streamId (4 bytes) */
Stream_Read_UINT32(s, request.listIndex); /* listIndex (4 bytes) */
Stream_Read_UINT32(s, request.dwFlags); /* dwFlags (4 bytes) */
Stream_Read_UINT32(s, request.nPositionLow); /* nPositionLow (4 bytes) */
Stream_Read_UINT32(s, request.nPositionHigh); /* nPositionHigh (4 bytes) */
Stream_Read_UINT32(s, request.cbRequested); /* cbRequested (4 bytes) */
Stream_Read_UINT32(s, request.clipDataId); /* clipDataId (4 bytes) */
if (context->ClientFileContentsRequest)
context->ClientFileContentsRequest(context, &request);
return 1;
}
static int cliprdr_server_receive_filecontents_response(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FILE_CONTENTS_RESPONSE response;
WLog_DBG(TAG, "CliprdrClientFileContentsResponse");
response.msgType = CB_FILECONTENTS_RESPONSE;
response.msgFlags = header->msgFlags;
response.dataLen = header->dataLen;
if (Stream_GetRemainingLength(s) < 4)
return -1;
Stream_Read_UINT32(s, response.streamId); /* streamId (4 bytes) */
response.cbRequested = header->dataLen - 4;
response.requestedData = Stream_Pointer(s); /* requestedFileContentsData */
if (context->ServerFileContentsResponse)
context->ServerFileContentsResponse(context, &response);
return 1;
}
static int cliprdr_server_receive_pdu(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
@ -372,24 +586,31 @@ static int cliprdr_server_receive_pdu(CliprdrServerContext* context, wStream* s,
break;
case CB_FORMAT_LIST_RESPONSE:
cliprdr_server_receive_format_list_response(context, s, header);
break;
case CB_LOCK_CLIPDATA:
cliprdr_server_receive_lock_clipdata(context, s, header);
break;
case CB_UNLOCK_CLIPDATA:
cliprdr_server_receive_unlock_clipdata(context, s, header);
break;
case CB_FORMAT_DATA_REQUEST:
cliprdr_server_receive_format_data_request(context, s, header);
break;
case CB_FORMAT_DATA_RESPONSE:
cliprdr_server_receive_format_data_response(context, s, header);
break;
case CB_FILECONTENTS_REQUEST:
cliprdr_server_receive_filecontents_request(context, s, header);
break;
case CB_FILECONTENTS_RESPONSE:
cliprdr_server_receive_filecontents_response(context, s, header);
break;
default:
@ -412,9 +633,8 @@ static void* cliprdr_server_thread(void* arg)
DWORD BytesReturned;
DWORD BytesToRead;
CLIPRDR_HEADER header;
CliprdrServerContext* context;
context = (CliprdrServerContext*) arg;
CliprdrServerContext* context = (CliprdrServerContext*) arg;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
buffer = NULL;
BytesReturned = 0;
@ -422,7 +642,7 @@ static void* cliprdr_server_thread(void* arg)
s = Stream_New(NULL, 4096);
if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
if (WTSVirtualChannelQuery(cliprdr->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
@ -432,7 +652,7 @@ static void* cliprdr_server_thread(void* arg)
nCount = 0;
events[nCount++] = ChannelEvent;
events[nCount++] = context->priv->StopEvent;
events[nCount++] = cliprdr->StopEvent;
cliprdr_server_send_capabilities(context);
cliprdr_server_send_monitor_ready(context);
@ -441,7 +661,7 @@ static void* cliprdr_server_thread(void* arg)
{
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0)
if (WaitForSingleObject(cliprdr->StopEvent, 0) == WAIT_OBJECT_0)
{
break;
}
@ -451,7 +671,7 @@ static void* cliprdr_server_thread(void* arg)
BytesReturned = 0;
BytesToRead = CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s);
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{
break;
@ -480,7 +700,7 @@ static void* cliprdr_server_thread(void* arg)
BytesReturned = 0;
BytesToRead = (header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s);
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{
break;
@ -507,7 +727,7 @@ static void* cliprdr_server_thread(void* arg)
BytesReturned = 0;
BytesToRead = 4;
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{
break;
@ -542,14 +762,16 @@ static void* cliprdr_server_thread(void* arg)
static int cliprdr_server_start(CliprdrServerContext* context)
{
context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "cliprdr");
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
if (!context->priv->ChannelHandle)
cliprdr->ChannelHandle = WTSVirtualChannelOpen(cliprdr->vcm, WTS_CURRENT_SESSION, "cliprdr");
if (!cliprdr->ChannelHandle)
return -1;
context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
cliprdr->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->priv->Thread = CreateThread(NULL, 0,
cliprdr->Thread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) cliprdr_server_thread, (void*) context, 0, NULL);
return 0;
@ -557,10 +779,11 @@ static int cliprdr_server_start(CliprdrServerContext* context)
static int cliprdr_server_stop(CliprdrServerContext* context)
{
SetEvent(context->priv->StopEvent);
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
WaitForSingleObject(context->priv->Thread, INFINITE);
CloseHandle(context->priv->Thread);
SetEvent(cliprdr->StopEvent);
WaitForSingleObject(cliprdr->Thread, INFINITE);
CloseHandle(cliprdr->Thread);
return 0;
}
@ -568,24 +791,24 @@ static int cliprdr_server_stop(CliprdrServerContext* context)
CliprdrServerContext* cliprdr_server_context_new(HANDLE vcm)
{
CliprdrServerContext* context;
CliprdrServerPrivate* cliprdr;
context = (CliprdrServerContext*) calloc(1, sizeof(CliprdrServerContext));
if (context)
{
context->vcm = vcm;
context->Start = cliprdr_server_start;
context->Stop = cliprdr_server_stop;
context->priv = (CliprdrServerPrivate*) calloc(1, sizeof(CliprdrServerPrivate));
cliprdr = context->handle = (CliprdrServerPrivate*) calloc(1, sizeof(CliprdrServerPrivate));
if (context->priv)
if (cliprdr)
{
context->priv->UseLongFormatNames = TRUE;
context->priv->StreamFileClipEnabled = TRUE;
context->priv->FileClipNoFilePaths = TRUE;
context->priv->CanLockClipData = TRUE;
cliprdr->vcm = vcm;
cliprdr->useLongFormatNames = TRUE;
cliprdr->streamFileClipEnabled = TRUE;
cliprdr->fileClipNoFilePaths = TRUE;
cliprdr->canLockClipData = TRUE;
}
}
@ -594,13 +817,17 @@ CliprdrServerContext* cliprdr_server_context_new(HANDLE vcm)
void cliprdr_server_context_free(CliprdrServerContext* context)
{
if (context)
CliprdrServerPrivate* cliprdr;
if (!context)
return;
cliprdr = (CliprdrServerPrivate*) context->handle;
if (cliprdr)
{
if (context->priv)
{
free(context->priv);
free(cliprdr->temporaryDirectory);
}
free(context);
}
}

View File

@ -28,23 +28,23 @@
#include <freerdp/channels/log.h>
#define TAG CHANNELS_TAG("cliprdr.server")
#define CLIPRDR_HEADER_LENGTH 8
struct _cliprdr_server_private
{
HANDLE vcm;
HANDLE Thread;
HANDLE StopEvent;
void* ChannelHandle;
BOOL UseLongFormatNames;
BOOL StreamFileClipEnabled;
BOOL FileClipNoFilePaths;
BOOL CanLockClipData;
BOOL useLongFormatNames;
BOOL streamFileClipEnabled;
BOOL fileClipNoFilePaths;
BOOL canLockClipData;
UINT32 ClientFormatNameCount;
CLIPRDR_FORMAT_NAME* ClientFormatNames;
char* ClientTemporaryDirectory;
char* temporaryDirectory;
};
typedef struct _cliprdr_server_private CliprdrServerPrivate;
#endif /* FREERDP_CHANNEL_SERVER_CLIPRDR_MAIN_H */

View File

@ -32,19 +32,59 @@
*/
typedef struct _cliprdr_server_context CliprdrServerContext;
typedef struct _cliprdr_server_private CliprdrServerPrivate;
typedef int (*psCliprdrStart)(CliprdrServerContext* context);
typedef int (*psCliprdrStop)(CliprdrServerContext* context);
typedef int (*psCliprdrServerCapabilities)(CliprdrServerContext* context, CLIPRDR_CAPABILITIES* capabilities);
typedef int (*psCliprdrClientCapabilities)(CliprdrServerContext* context, CLIPRDR_CAPABILITIES* capabilities);
typedef int (*psCliprdrMonitorReady)(CliprdrServerContext* context, CLIPRDR_MONITOR_READY* monitorReady);
typedef int (*psCliprdrTempDirectory)(CliprdrServerContext* context, CLIPRDR_TEMP_DIRECTORY* tempDirectory);
typedef int (*psCliprdrClientFormatList)(CliprdrServerContext* context, CLIPRDR_FORMAT_LIST* formatList);
typedef int (*psCliprdrServerFormatList)(CliprdrServerContext* context, CLIPRDR_FORMAT_LIST* formatList);
typedef int (*psCliprdrClientFormatListResponse)(CliprdrServerContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse);
typedef int (*psCliprdrServerFormatListResponse)(CliprdrServerContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse);
typedef int (*psCliprdrClientLockClipboardData)(CliprdrServerContext* context, CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData);
typedef int (*psCliprdrServerLockClipboardData)(CliprdrServerContext* context, CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData);
typedef int (*psCliprdrClientUnlockClipboardData)(CliprdrServerContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData);
typedef int (*psCliprdrServerUnlockClipboardData)(CliprdrServerContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData);
typedef int (*psCliprdrClientFormatDataRequest)(CliprdrServerContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest);
typedef int (*psCliprdrServerFormatDataRequest)(CliprdrServerContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest);
typedef int (*psCliprdrClientFormatDataResponse)(CliprdrServerContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse);
typedef int (*psCliprdrServerFormatDataResponse)(CliprdrServerContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse);
typedef int (*psCliprdrClientFileContentsRequest)(CliprdrServerContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest);
typedef int (*psCliprdrServerFileContentsRequest)(CliprdrServerContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest);
typedef int (*psCliprdrClientFileContentsResponse)(CliprdrServerContext* context, CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse);
typedef int (*psCliprdrServerFileContentsResponse)(CliprdrServerContext* context, CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse);
struct _cliprdr_server_context
{
HANDLE vcm;
void* handle;
void* custom;
psCliprdrStart Start;
psCliprdrStop Stop;
CliprdrServerPrivate* priv;
psCliprdrServerCapabilities ServerCapabilities;
psCliprdrClientCapabilities ClientCapabilities;
psCliprdrMonitorReady MonitorReady;
psCliprdrTempDirectory TempDirectory;
psCliprdrClientFormatList ClientFormatList;
psCliprdrServerFormatList ServerFormatList;
psCliprdrClientFormatListResponse ClientFormatListResponse;
psCliprdrServerFormatListResponse ServerFormatListResponse;
psCliprdrClientLockClipboardData ClientLockClipboardData;
psCliprdrServerLockClipboardData ServerLockClipboardData;
psCliprdrClientUnlockClipboardData ClientUnlockClipboardData;
psCliprdrServerUnlockClipboardData ServerUnlockClipboardData;
psCliprdrClientFormatDataRequest ClientFormatDataRequest;
psCliprdrServerFormatDataRequest ServerFormatDataRequest;
psCliprdrClientFormatDataResponse ClientFormatDataResponse;
psCliprdrServerFormatDataResponse ServerFormatDataResponse;
psCliprdrClientFileContentsRequest ClientFileContentsRequest;
psCliprdrServerFileContentsRequest ServerFileContentsRequest;
psCliprdrClientFileContentsResponse ClientFileContentsResponse;
psCliprdrServerFileContentsResponse ServerFileContentsResponse;
};
#ifdef __cplusplus