2014-06-24 00:18:03 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Multiparty Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-06-08 15:44:10 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
|
|
|
* Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2014-06-24 00:18:03 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-07-01 01:17:06 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
|
2014-08-11 11:12:01 +04:00
|
|
|
#include <freerdp/channels/log.h>
|
2014-06-24 00:18:03 +04:00
|
|
|
#include <freerdp/client/encomsp.h>
|
|
|
|
|
|
|
|
#include "encomsp_main.h"
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_read_header(wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-07-16 00:34:15 +04:00
|
|
|
{
|
|
|
|
if (Stream_GetRemainingLength(s) < ENCOMSP_ORDER_HEADER_SIZE)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-07-16 00:34:15 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT16(s, header->Type); /* Type (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, header->Length); /* Length (2 bytes) */
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-07-16 00:34:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_write_header(wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-07-16 00:34:15 +04:00
|
|
|
{
|
|
|
|
Stream_Write_UINT16(s, header->Type); /* Type (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, header->Length); /* Length (2 bytes) */
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-07-16 00:34:15 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_read_unicode_string(wStream* s, ENCOMSP_UNICODE_STRING* str)
|
2014-07-16 00:34:15 +04:00
|
|
|
{
|
|
|
|
ZeroMemory(str, sizeof(ENCOMSP_UNICODE_STRING));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 2)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-07-16 00:34:15 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT16(s, str->cchString); /* cchString (2 bytes) */
|
|
|
|
|
|
|
|
if (str->cchString > 1024)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "cchString was %d but has to be < 1025!", str->cchString);
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-07-16 00:34:15 +04:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)(str->cchString * 2))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-07-16 00:34:15 +04:00
|
|
|
|
|
|
|
Stream_Read(s, &(str->wString), (str->cchString * 2)); /* String (variable) */
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-07-16 00:34:15 +04:00
|
|
|
}
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
static EncomspClientContext* encomsp_get_client_interface(
|
|
|
|
encomspPlugin* encomsp)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2014-06-24 02:17:26 +04:00
|
|
|
EncomspClientContext* pInterface;
|
|
|
|
pInterface = (EncomspClientContext*) encomsp->channelEntryPoints.pInterface;
|
|
|
|
return pInterface;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_virtual_channel_write(encomspPlugin* encomsp, wStream* s)
|
2014-07-01 01:17:06 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status;
|
2014-07-01 01:17:06 +04:00
|
|
|
|
|
|
|
if (!encomsp)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-07-01 01:17:06 +04:00
|
|
|
|
|
|
|
#if 0
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_INFO(TAG, "EncomspWrite (%d)", Stream_Length(s));
|
2014-07-01 01:17:06 +04:00
|
|
|
winpr_HexDump(Stream_Buffer(s), Stream_Length(s));
|
|
|
|
#endif
|
2016-11-22 14:08:33 +03:00
|
|
|
status = encomsp->channelEntryPoints.pVirtualChannelWriteEx(encomsp->InitHandle, encomsp->OpenHandle,
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Buffer(s), (UINT32) Stream_Length(s), s);
|
2014-07-01 01:17:06 +04:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
2016-11-22 14:08:33 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWriteEx failed with %s [%08X]",
|
2016-09-26 13:12:37 +03:00
|
|
|
WTSErrorToString(status), status);
|
2014-07-01 01:17:06 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return status;
|
2014-07-01 01:17:06 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_filter_updated_pdu(encomspPlugin* encomsp, wStream* s,
|
2016-09-26 13:12:37 +03:00
|
|
|
ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_FILTER_UPDATED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT8(s, pdu.Flags); /* Flags (1 byte) */
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->FilterUpdated, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->FilterUpdated failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_application_created_pdu(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_APPLICATION_CREATED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.AppId); /* AppId (4 bytes) */
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if ((error = encomsp_read_unicode_string(s, &(pdu.Name))))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_read_unicode_string failed with error %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->ApplicationCreated, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->ApplicationCreated failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_application_removed_pdu(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_APPLICATION_REMOVED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, pdu.AppId); /* AppId (4 bytes) */
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->ApplicationRemoved, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->ApplicationRemoved failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_window_created_pdu(encomspPlugin* encomsp, wStream* s,
|
2016-09-26 13:12:37 +03:00
|
|
|
ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_WINDOW_CREATED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 10)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.AppId); /* AppId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.WndId); /* WndId (4 bytes) */
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_read_unicode_string(s, &(pdu.Name))))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_read_unicode_string failed with error %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->WindowCreated, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->WindowCreated failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_window_removed_pdu(encomspPlugin* encomsp, wStream* s,
|
2016-09-26 13:12:37 +03:00
|
|
|
ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_WINDOW_REMOVED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, pdu.WndId); /* WndId (4 bytes) */
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->WindowRemoved, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->WindowRemoved failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_show_window_pdu(encomspPlugin* encomsp, wStream* s,
|
2016-09-26 13:12:37 +03:00
|
|
|
ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_SHOW_WINDOW_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, pdu.WndId); /* WndId (4 bytes) */
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->ShowWindow, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->ShowWindow failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_participant_created_pdu(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_PARTICIPANT_CREATED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 10)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, pdu.ParticipantId); /* ParticipantId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.GroupId); /* GroupId (4 bytes) */
|
|
|
|
Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_read_unicode_string(s, &(pdu.FriendlyName))))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_read_unicode_string failed with error %lu", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->ParticipantCreated, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->ParticipantCreated failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_participant_removed_pdu(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_PARTICIPANT_REMOVED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT32(s, pdu.ParticipantId); /* ParticipantId (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.DiscType); /* DiscType (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.DiscCode); /* DiscCode (4 bytes) */
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->ParticipantRemoved, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->ParticipantRemoved failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_change_participant_control_level_pdu(
|
|
|
|
encomspPlugin* encomsp, wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */
|
|
|
|
Stream_Read_UINT32(s, pdu.ParticipantId); /* ParticipantId (4 bytes) */
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->ChangeParticipantControlLevel, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "context->ChangeParticipantControlLevel failed with error %lu",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_send_change_participant_control_level_pdu(
|
|
|
|
EncomspClientContext* context,
|
|
|
|
ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* pdu)
|
2014-07-01 01:17:06 +04:00
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
encomspPlugin* encomsp;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error;
|
2014-07-01 01:17:06 +04:00
|
|
|
encomsp = (encomspPlugin*) context->handle;
|
|
|
|
pdu->Type = ODTYPE_PARTICIPANT_CTRL_CHANGED;
|
|
|
|
pdu->Length = ENCOMSP_ORDER_HEADER_SIZE + 6;
|
|
|
|
s = Stream_New(NULL, pdu->Length);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-07-01 01:17:06 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_write_header(s, (ENCOMSP_ORDER_HEADER*) pdu)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_write_header failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-07-01 01:17:06 +04:00
|
|
|
|
|
|
|
Stream_Write_UINT16(s, pdu->Flags); /* Flags (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, pdu->ParticipantId); /* ParticipantId (4 bytes) */
|
|
|
|
Stream_SealLength(s);
|
2015-06-08 15:44:10 +03:00
|
|
|
return encomsp_virtual_channel_write(encomsp, s);
|
2014-07-01 01:17:06 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_graphics_stream_paused_pdu(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->GraphicsStreamPaused, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->GraphicsStreamPaused failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_recv_graphics_stream_resumed_pdu(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
wStream* s, ENCOMSP_ORDER_HEADER* header)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
|
|
|
int beg, end;
|
|
|
|
EncomspClientContext* context;
|
|
|
|
ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU pdu;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
context = encomsp_get_client_interface(encomsp);
|
|
|
|
|
|
|
|
if (!context)
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
|
|
|
|
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
|
|
|
|
end = (int) Stream_GetPosition(s);
|
|
|
|
|
|
|
|
if ((beg + header->Length) < end)
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
if ((beg + header->Length) > end)
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t)((beg + header->Length) - end))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Not enought data!");
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
|
|
|
Stream_SetPosition(s, (beg + header->Length));
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
IFCALLRET(context->GraphicsStreamResumed, error, context, &pdu);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (error)
|
|
|
|
WLog_ERR(TAG, "context->GraphicsStreamResumed failed with error %lu", error);
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_process_receive(encomspPlugin* encomsp, wStream* s)
|
2014-06-24 02:17:26 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2014-06-24 02:17:26 +04:00
|
|
|
ENCOMSP_ORDER_HEADER header;
|
|
|
|
|
|
|
|
while (Stream_GetRemainingLength(s) > 0)
|
|
|
|
{
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_read_header(s, &header)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_read_header failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2014-06-24 02:17:26 +04:00
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
//WLog_DBG(TAG, "EncomspReceive: Type: %d Length: %d", header.Type, header.Length);
|
2014-07-01 01:17:06 +04:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
switch (header.Type)
|
|
|
|
{
|
|
|
|
case ODTYPE_FILTER_STATE_UPDATED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_filter_updated_pdu(encomsp, s, &header)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_recv_filter_updated_pdu failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_APP_REMOVED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_application_removed_pdu(encomsp, s, &header)))
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_recv_application_removed_pdu failed with error %lu!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_APP_CREATED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_application_created_pdu(encomsp, s, &header)))
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_recv_application_removed_pdu failed with error %lu!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_WND_REMOVED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_window_removed_pdu(encomsp, s, &header)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_recv_window_removed_pdu failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_WND_CREATED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_window_created_pdu(encomsp, s, &header)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_recv_window_created_pdu failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_WND_SHOW:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_show_window_pdu(encomsp, s, &header)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "encomsp_recv_show_window_pdu failed with error %lu!", error);
|
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_PARTICIPANT_REMOVED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_participant_removed_pdu(encomsp, s, &header)))
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_recv_participant_removed_pdu failed with error %lu!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_PARTICIPANT_CREATED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_participant_created_pdu(encomsp, s, &header)))
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_recv_participant_created_pdu failed with error %lu!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_PARTICIPANT_CTRL_CHANGED:
|
2016-08-09 13:04:06 +03:00
|
|
|
if ((error = encomsp_recv_change_participant_control_level_pdu(encomsp, s,
|
2016-09-26 13:12:37 +03:00
|
|
|
&header)))
|
2015-06-08 15:44:10 +03:00
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-09-26 13:12:37 +03:00
|
|
|
"encomsp_recv_change_participant_control_level_pdu failed with error %lu!",
|
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_GRAPHICS_STREAM_PAUSED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_graphics_stream_paused_pdu(encomsp, s, &header)))
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_recv_graphics_stream_paused_pdu failed with error %lu!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ODTYPE_GRAPHICS_STREAM_RESUMED:
|
2015-06-08 15:44:10 +03:00
|
|
|
if ((error = encomsp_recv_graphics_stream_resumed_pdu(encomsp, s, &header)))
|
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_recv_graphics_stream_resumed_pdu failed with error %lu!",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-06-08 15:44:10 +03:00
|
|
|
WLog_ERR(TAG, "header.Type %d not found", header.Type);
|
|
|
|
return ERROR_INVALID_DATA;
|
2014-06-24 02:17:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return error;
|
2014-06-24 02:17:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void encomsp_process_connect(encomspPlugin* encomsp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
static int encomsp_send(encomspPlugin* encomsp, wStream* s)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
|
|
|
UINT32 status = 0;
|
|
|
|
encomspPlugin* plugin = (encomspPlugin*) encomsp;
|
|
|
|
|
|
|
|
if (!plugin)
|
|
|
|
{
|
|
|
|
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-22 14:08:33 +03:00
|
|
|
status = plugin->channelEntryPoints.pVirtualChannelWriteEx(plugin->InitHandle, plugin->OpenHandle,
|
2016-09-26 13:12:37 +03:00
|
|
|
Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2016-11-22 14:08:33 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWriteEx failed with %s [%08X]",
|
2016-09-26 13:12:37 +03:00
|
|
|
WTSErrorToString(status), status);
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_virtual_channel_event_data_received(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
|
|
|
wStream* data_in;
|
|
|
|
|
|
|
|
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-06-24 00:18:03 +04:00
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
|
|
|
if (encomsp->data_in)
|
|
|
|
Stream_Free(encomsp->data_in, TRUE);
|
|
|
|
|
|
|
|
encomsp->data_in = Stream_New(NULL, totalLength);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (!encomsp->data_in)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
data_in = encomsp->data_in;
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(data_in, (int) dataLength))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 00:18:03 +04:00
|
|
|
Stream_Write(data_in, pData, dataLength);
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
|
|
|
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "encomsp_plugin_process_received: read error");
|
2015-06-08 15:44:10 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
encomsp->data_in = NULL;
|
|
|
|
Stream_SealLength(data_in);
|
|
|
|
Stream_SetPosition(data_in, 0);
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!MessageQueue_Post(encomsp->queue, NULL, 0, (void*) data_in, NULL))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Post failed!");
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:08:33 +03:00
|
|
|
static VOID VCAPITYPE encomsp_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, UINT event,
|
2016-09-26 13:12:37 +03:00
|
|
|
LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2016-11-22 14:08:33 +03:00
|
|
|
encomspPlugin* encomsp = (encomspPlugin*) lpUserParam;
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (!encomsp || (encomsp->OpenHandle != openHandle))
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2016-11-22 14:08:33 +03:00
|
|
|
WLog_ERR(TAG, "error no match");
|
2014-06-24 00:18:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_DATA_RECEIVED:
|
2016-08-09 13:04:06 +03:00
|
|
|
if ((error = encomsp_virtual_channel_event_data_received(encomsp, pData,
|
2016-09-26 13:12:37 +03:00
|
|
|
dataLength, totalLength, dataFlags)))
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-09-26 13:12:37 +03:00
|
|
|
"encomsp_virtual_channel_event_data_received failed with error %lu", error);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 00:18:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_WRITE_COMPLETE:
|
|
|
|
Stream_Free((wStream*) pData, TRUE);
|
|
|
|
break;
|
2015-01-20 13:58:09 +03:00
|
|
|
|
|
|
|
case CHANNEL_EVENT_USER:
|
|
|
|
break;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && encomsp->rdpcontext)
|
2016-11-22 14:08:33 +03:00
|
|
|
setChannelError(encomsp->rdpcontext, error, "encomsp_virtual_channel_open_event reported an error");
|
2015-07-15 10:50:35 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void* encomsp_virtual_channel_client_thread(void* arg)
|
|
|
|
{
|
|
|
|
wStream* data;
|
|
|
|
wMessage message;
|
|
|
|
encomspPlugin* encomsp = (encomspPlugin*) arg;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2016-11-15 19:41:01 +03:00
|
|
|
|
2014-06-24 00:18:03 +04:00
|
|
|
encomsp_process_connect(encomsp);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2014-12-27 23:20:29 +03:00
|
|
|
if (!MessageQueue_Wait(encomsp->queue))
|
2015-07-15 10:50:35 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "MessageQueue_Wait failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
2014-06-24 00:18:03 +04:00
|
|
|
break;
|
2015-07-15 10:50:35 +03:00
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (!MessageQueue_Peek(encomsp->queue, &message, TRUE))
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2015-07-15 10:50:35 +03:00
|
|
|
WLog_ERR(TAG, "MessageQueue_Peek failed!");
|
|
|
|
error = ERROR_INTERNAL_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (message.id == 0)
|
|
|
|
{
|
|
|
|
data = (wStream*) message.wParam;
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if ((error = encomsp_process_receive(encomsp, data)))
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2015-07-15 10:50:35 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_process_receive failed with error %lu!", error);
|
|
|
|
break;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 10:50:35 +03:00
|
|
|
if (error && encomsp->rdpcontext)
|
2016-08-09 13:04:06 +03:00
|
|
|
setChannelError(encomsp->rdpcontext, error,
|
2016-09-26 13:12:37 +03:00
|
|
|
"encomsp_virtual_channel_client_thread reported an error");
|
2015-07-15 10:50:35 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
ExitThread((DWORD)error);
|
2014-06-24 00:18:03 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-08-09 13:04:06 +03:00
|
|
|
static UINT encomsp_virtual_channel_event_connected(encomspPlugin* encomsp,
|
2016-09-26 13:12:37 +03:00
|
|
|
LPVOID pData, UINT32 dataLength)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
|
|
|
UINT32 status;
|
2016-11-22 14:08:33 +03:00
|
|
|
status = encomsp->channelEntryPoints.pVirtualChannelOpenEx(encomsp->InitHandle,
|
2016-09-26 13:12:37 +03:00
|
|
|
&encomsp->OpenHandle, encomsp->channelDef.name,
|
2016-11-22 14:08:33 +03:00
|
|
|
encomsp_virtual_channel_open_event_ex);
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2015-05-18 12:28:00 +03:00
|
|
|
{
|
2015-06-08 15:44:10 +03:00
|
|
|
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
|
2016-09-26 13:12:37 +03:00
|
|
|
WTSErrorToString(status), status);
|
2015-06-08 15:44:10 +03:00
|
|
|
return status;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
2014-12-27 23:20:29 +03:00
|
|
|
encomsp->queue = MessageQueue_New(NULL);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-05-18 12:28:00 +03:00
|
|
|
if (!encomsp->queue)
|
|
|
|
{
|
2015-06-08 15:44:10 +03:00
|
|
|
WLog_ERR(TAG, "MessageQueue_New failed!");
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2015-05-18 12:28:00 +03:00
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (!(encomsp->thread = CreateThread(NULL, 0,
|
2016-09-26 13:12:37 +03:00
|
|
|
(LPTHREAD_START_ROUTINE) encomsp_virtual_channel_client_thread, (void*) encomsp,
|
|
|
|
0, NULL)))
|
2015-05-18 12:28:00 +03:00
|
|
|
{
|
2015-06-08 15:44:10 +03:00
|
|
|
WLog_ERR(TAG, "CreateThread failed!");
|
|
|
|
MessageQueue_Free(encomsp->queue);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-05-18 12:28:00 +03:00
|
|
|
}
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_virtual_channel_event_disconnected(encomspPlugin* encomsp)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2015-01-20 13:58:09 +03:00
|
|
|
UINT rc;
|
2015-05-23 23:47:18 +03:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (MessageQueue_PostQuit(encomsp->queue, 0)
|
|
|
|
&& (WaitForSingleObject(encomsp->thread, INFINITE) == WAIT_FAILED))
|
|
|
|
{
|
|
|
|
rc = GetLastError();
|
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2015-01-20 13:58:09 +03:00
|
|
|
MessageQueue_Free(encomsp->queue);
|
|
|
|
CloseHandle(encomsp->thread);
|
|
|
|
encomsp->queue = NULL;
|
|
|
|
encomsp->thread = NULL;
|
2016-11-22 14:08:33 +03:00
|
|
|
rc = encomsp->channelEntryPoints.pVirtualChannelCloseEx(encomsp->InitHandle, encomsp->OpenHandle);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-01-20 13:58:09 +03:00
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
|
2016-09-26 13:12:37 +03:00
|
|
|
WTSErrorToString(rc), rc);
|
2015-06-08 15:44:10 +03:00
|
|
|
return rc;
|
2015-01-20 13:58:09 +03:00
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
encomsp->OpenHandle = 0;
|
|
|
|
|
2014-06-24 00:18:03 +04:00
|
|
|
if (encomsp->data_in)
|
|
|
|
{
|
|
|
|
Stream_Free(encomsp->data_in, TRUE);
|
|
|
|
encomsp->data_in = NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2015-01-20 13:58:09 +03:00
|
|
|
}
|
2014-12-27 23:20:29 +03:00
|
|
|
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT encomsp_virtual_channel_event_terminated(encomspPlugin* encomsp)
|
2015-01-20 13:58:09 +03:00
|
|
|
{
|
2016-08-09 13:04:06 +03:00
|
|
|
encomsp->InitHandle = 0;
|
2014-12-27 23:20:29 +03:00
|
|
|
free(encomsp);
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:08:33 +03:00
|
|
|
static VOID VCAPITYPE encomsp_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
|
|
|
|
UINT event, LPVOID pData, UINT dataLength)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2016-11-22 14:08:33 +03:00
|
|
|
encomspPlugin* encomsp = (encomspPlugin*) lpUserParam;
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
if (!encomsp || (encomsp->InitHandle != pInitHandle))
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2016-11-22 14:08:33 +03:00
|
|
|
WLog_ERR(TAG, "error no match");
|
2016-03-14 15:19:08 +03:00
|
|
|
return;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_CONNECTED:
|
2016-08-09 13:04:06 +03:00
|
|
|
if ((error = encomsp_virtual_channel_event_connected(encomsp, pData,
|
2016-09-26 13:12:37 +03:00
|
|
|
dataLength)))
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG, "encomsp_virtual_channel_event_connected failed with error %lu",
|
2016-09-26 13:12:37 +03:00
|
|
|
error);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 00:18:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DISCONNECTED:
|
2015-07-15 10:50:35 +03:00
|
|
|
if ((error = encomsp_virtual_channel_event_disconnected(encomsp)))
|
2016-08-09 13:04:06 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-09-26 13:12:37 +03:00
|
|
|
"encomsp_virtual_channel_event_disconnected failed with error %lu", error);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2014-06-24 00:18:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_TERMINATED:
|
|
|
|
encomsp_virtual_channel_event_terminated(encomsp);
|
|
|
|
break;
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
default:
|
2015-07-29 18:32:09 +03:00
|
|
|
WLog_ERR(TAG, "Unhandled event type %d", event);
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
2015-07-15 10:50:35 +03:00
|
|
|
|
|
|
|
if (error && encomsp->rdpcontext)
|
2016-11-22 14:08:33 +03:00
|
|
|
setChannelError(encomsp->rdpcontext, error, "encomsp_virtual_channel_init_event reported an error");
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* encomsp is always built-in */
|
2016-11-22 14:08:33 +03:00
|
|
|
#define VirtualChannelEntryEx encomsp_VirtualChannelEntryEx
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2016-11-22 14:08:33 +03:00
|
|
|
BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS_EX pEntryPoints, PVOID pInitHandle)
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
2015-01-20 13:58:09 +03:00
|
|
|
UINT rc;
|
2014-06-24 00:18:03 +04:00
|
|
|
encomspPlugin* encomsp;
|
2016-09-26 13:12:14 +03:00
|
|
|
EncomspClientContext* context = NULL;
|
2016-11-22 14:08:33 +03:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx;
|
2015-06-08 15:44:10 +03:00
|
|
|
BOOL isFreerdp = FALSE;
|
2014-06-24 00:18:03 +04:00
|
|
|
encomsp = (encomspPlugin*) calloc(1, sizeof(encomspPlugin));
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (!encomsp)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
|
|
|
|
encomsp->channelDef.options =
|
2016-08-09 13:04:06 +03:00
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP |
|
|
|
|
CHANNEL_OPTION_COMPRESS_RDP |
|
|
|
|
CHANNEL_OPTION_SHOW_PROTOCOL;
|
2014-06-24 00:18:03 +04:00
|
|
|
strcpy(encomsp->channelDef.name, "encomsp");
|
2016-11-22 14:08:33 +03:00
|
|
|
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*) pEntryPoints;
|
2014-06-24 00:18:03 +04:00
|
|
|
|
2016-11-22 14:08:33 +03:00
|
|
|
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) &&
|
2016-08-09 13:04:06 +03:00
|
|
|
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
|
2014-06-24 00:18:03 +04:00
|
|
|
{
|
|
|
|
context = (EncomspClientContext*) calloc(1, sizeof(EncomspClientContext));
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "calloc failed!");
|
|
|
|
goto error_out;
|
|
|
|
}
|
2014-06-24 00:18:03 +04:00
|
|
|
|
|
|
|
context->handle = (void*) encomsp;
|
2014-06-24 02:17:26 +04:00
|
|
|
context->FilterUpdated = NULL;
|
|
|
|
context->ApplicationCreated = NULL;
|
|
|
|
context->ApplicationRemoved = NULL;
|
|
|
|
context->WindowCreated = NULL;
|
|
|
|
context->WindowRemoved = NULL;
|
|
|
|
context->ShowWindow = NULL;
|
|
|
|
context->ParticipantCreated = NULL;
|
|
|
|
context->ParticipantRemoved = NULL;
|
2016-08-09 13:04:06 +03:00
|
|
|
context->ChangeParticipantControlLevel =
|
|
|
|
encomsp_send_change_participant_control_level_pdu;
|
2014-06-24 02:17:26 +04:00
|
|
|
context->GraphicsStreamPaused = NULL;
|
|
|
|
context->GraphicsStreamResumed = NULL;
|
2014-06-24 00:18:03 +04:00
|
|
|
*(pEntryPointsEx->ppInterface) = (void*) context;
|
2014-12-27 23:20:29 +03:00
|
|
|
encomsp->context = context;
|
2015-07-15 10:50:35 +03:00
|
|
|
encomsp->rdpcontext = pEntryPointsEx->context;
|
2015-06-08 15:44:10 +03:00
|
|
|
isFreerdp = TRUE;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
CopyMemory(&(encomsp->channelEntryPoints), pEntryPoints,
|
2016-11-22 14:08:33 +03:00
|
|
|
sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX));
|
|
|
|
encomsp->InitHandle = pInitHandle;
|
|
|
|
rc = encomsp->channelEntryPoints.pVirtualChannelInitEx((void*) encomsp, pInitHandle,
|
2016-09-26 13:12:37 +03:00
|
|
|
&encomsp->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
|
2016-11-22 14:08:33 +03:00
|
|
|
encomsp_virtual_channel_init_event_ex);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-01-20 13:58:09 +03:00
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
2016-11-22 14:08:33 +03:00
|
|
|
WLog_ERR(TAG, "failed with %s [%08X]",
|
2016-09-26 13:12:37 +03:00
|
|
|
WTSErrorToString(rc), rc);
|
2015-06-08 15:44:10 +03:00
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
|
2016-08-09 13:04:06 +03:00
|
|
|
encomsp->channelEntryPoints.pInterface = *
|
2016-09-26 13:12:37 +03:00
|
|
|
(encomsp->channelEntryPoints.ppInterface);
|
2016-08-09 13:04:06 +03:00
|
|
|
encomsp->channelEntryPoints.ppInterface = &
|
2016-09-26 13:12:37 +03:00
|
|
|
(encomsp->channelEntryPoints.pInterface);
|
2016-11-14 23:23:05 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
return TRUE;
|
|
|
|
error_out:
|
2016-09-26 13:12:37 +03:00
|
|
|
|
2016-09-26 13:12:14 +03:00
|
|
|
if (context)
|
|
|
|
*(pEntryPointsEx->ppInterface) = NULL;
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
if (isFreerdp)
|
|
|
|
free(encomsp->context);
|
2016-08-09 13:04:06 +03:00
|
|
|
|
2015-06-08 15:44:10 +03:00
|
|
|
free(encomsp);
|
|
|
|
return FALSE;
|
2014-06-24 00:18:03 +04:00
|
|
|
}
|