Blame channels/encomsp/client/encomsp_main.c

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