Blame channels/geometry/client/geometry_main.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 * Geometry tracking Virtual Channel Extension
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2017 David Fort <contact@hardening-consulting.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 <stdio.h>
Packit 1fb8d4
#include <stdlib.h>
Packit 1fb8d4
#include <string.h>
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/crt.h>
Packit 1fb8d4
#include <winpr/synch.h>
Packit 1fb8d4
#include <winpr/interlocked.h>
Packit 1fb8d4
#include <winpr/print.h>
Packit 1fb8d4
#include <winpr/stream.h>
Packit 1fb8d4
#include <winpr/cmdline.h>
Packit 1fb8d4
#include <winpr/collections.h>
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/addin.h>
Packit 1fb8d4
#include <freerdp/client/geometry.h>
Packit 1fb8d4
#include <freerdp/channels/log.h>
Packit 1fb8d4
Packit 1fb8d4
#define TAG CHANNELS_TAG("geometry.client")
Packit 1fb8d4
Packit 1fb8d4
#include "geometry_main.h"
Packit 1fb8d4
Packit 1fb8d4
struct _GEOMETRY_CHANNEL_CALLBACK
Packit 1fb8d4
{
Packit 1fb8d4
	IWTSVirtualChannelCallback iface;
Packit 1fb8d4
Packit 1fb8d4
	IWTSPlugin* plugin;
Packit 1fb8d4
	IWTSVirtualChannelManager* channel_mgr;
Packit 1fb8d4
	IWTSVirtualChannel* channel;
Packit 1fb8d4
};
Packit 1fb8d4
typedef struct _GEOMETRY_CHANNEL_CALLBACK GEOMETRY_CHANNEL_CALLBACK;
Packit 1fb8d4
Packit 1fb8d4
struct _GEOMETRY_LISTENER_CALLBACK
Packit 1fb8d4
{
Packit 1fb8d4
	IWTSListenerCallback iface;
Packit 1fb8d4
Packit 1fb8d4
	IWTSPlugin* plugin;
Packit 1fb8d4
	IWTSVirtualChannelManager* channel_mgr;
Packit 1fb8d4
	GEOMETRY_CHANNEL_CALLBACK* channel_callback;
Packit 1fb8d4
};
Packit 1fb8d4
typedef struct _GEOMETRY_LISTENER_CALLBACK GEOMETRY_LISTENER_CALLBACK;
Packit 1fb8d4
Packit 1fb8d4
struct _GEOMETRY_PLUGIN
Packit 1fb8d4
{
Packit 1fb8d4
	IWTSPlugin iface;
Packit 1fb8d4
Packit 1fb8d4
	IWTSListener* listener;
Packit 1fb8d4
	GEOMETRY_LISTENER_CALLBACK* listener_callback;
Packit 1fb8d4
Packit 1fb8d4
	GeometryClientContext* context;
Packit 1fb8d4
};
Packit 1fb8d4
typedef struct _GEOMETRY_PLUGIN GEOMETRY_PLUGIN;
Packit 1fb8d4
Packit Service 5a9772
static UINT32 mappedGeometryHash(UINT64* g)
Packit 1fb8d4
{
Packit 1fb8d4
	return (UINT32)((*g >> 32) + (*g & 0xffffffff));
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL mappedGeometryKeyCompare(UINT64* g1, UINT64* g2)
Packit 1fb8d4
{
Packit 1fb8d4
	return *g1 == *g2;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
void mappedGeometryRef(MAPPED_GEOMETRY* g)
Packit 1fb8d4
{
Packit 1fb8d4
	InterlockedIncrement(&g->refCounter);
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
void mappedGeometryUnref(MAPPED_GEOMETRY* g)
Packit 1fb8d4
{
Packit 1fb8d4
	if (InterlockedDecrement(&g->refCounter))
Packit 1fb8d4
		return;
Packit 1fb8d4
Packit 1fb8d4
	g->MappedGeometryUpdate = NULL;
Packit 1fb8d4
	g->MappedGeometryClear = NULL;
Packit 1fb8d4
	g->custom = NULL;
Packit 1fb8d4
	free(g->geometry.rects);
Packit 1fb8d4
	free(g);
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static void freerdp_rgndata_reset(FREERDP_RGNDATA* data)
Packit 1fb8d4
{
Packit 1fb8d4
	data->nRectCount = 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static UINT32 geometry_read_RGNDATA(wStream* s, UINT32 len, FREERDP_RGNDATA* rgndata)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT32 dwSize, iType;
Packit 1fb8d4
	INT32 right, bottom;
Packit Service 5a9772
	INT32 x, y, w, h;
Packit 1fb8d4
Packit 1fb8d4
	if (len < 32)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "invalid RGNDATA");
Packit 1fb8d4
		return ERROR_INVALID_DATA;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT32(s, dwSize);
Packit 1fb8d4
Packit 1fb8d4
	if (dwSize != 32)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "invalid RGNDATA dwSize");
Packit 1fb8d4
		return ERROR_INVALID_DATA;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT32(s, iType);
Packit 1fb8d4
Packit 1fb8d4
	if (iType != RDH_RECTANGLE)
Packit 1fb8d4
	{
Packit Service 5a9772
		WLog_ERR(TAG, "iType %" PRIu32 " for RGNDATA is not supported", iType);
Packit 1fb8d4
		return ERROR_UNSUPPORTED_TYPE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT32(s, rgndata->nRectCount);
Packit 1fb8d4
	Stream_Seek_UINT32(s); /* nRgnSize IGNORED */
Packit Service 5a9772
	Stream_Read_INT32(s, x);
Packit Service 5a9772
	Stream_Read_INT32(s, y);
Packit 1fb8d4
	Stream_Read_INT32(s, right);
Packit 1fb8d4
	Stream_Read_INT32(s, bottom);
Packit Service 5a9772
	if ((abs(x) > INT16_MAX) || (abs(y) > INT16_MAX))
Packit Service 5a9772
		return ERROR_INVALID_DATA;
Packit Service 5a9772
	w = right - x;
Packit Service 5a9772
	h = bottom - y;
Packit Service 5a9772
	if ((abs(w) > INT16_MAX) || (abs(h) > INT16_MAX))
Packit Service 5a9772
		return ERROR_INVALID_DATA;
Packit Service 5a9772
	rgndata->boundingRect.x = (INT16)x;
Packit Service 5a9772
	rgndata->boundingRect.y = (INT16)y;
Packit Service 5a9772
	rgndata->boundingRect.width = (INT16)w;
Packit Service 5a9772
	rgndata->boundingRect.height = (INT16)h;
Packit 1fb8d4
	len -= 32;
Packit 1fb8d4
Packit 1fb8d4
	if (len / (4 * 4) < rgndata->nRectCount)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "not enough data for region rectangles");
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (rgndata->nRectCount)
Packit 1fb8d4
	{
Packit Service 5a9772
		UINT32 i;
Packit Service 5a9772
		RDP_RECT* tmp = realloc(rgndata->rects, rgndata->nRectCount * sizeof(RDP_RECT));
Packit 1fb8d4
Packit 1fb8d4
		if (!tmp)
Packit 1fb8d4
		{
Packit Service 5a9772
			WLog_ERR(TAG, "unable to allocate memory for %" PRIu32 " RECTs", rgndata->nRectCount);
Packit 1fb8d4
			return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
		}
Packit 1fb8d4
		rgndata->rects = tmp;
Packit 1fb8d4
Packit 1fb8d4
		for (i = 0; i < rgndata->nRectCount; i++)
Packit 1fb8d4
		{
Packit Service 5a9772
			Stream_Read_INT32(s, x);
Packit Service 5a9772
			Stream_Read_INT32(s, y);
Packit 1fb8d4
			Stream_Read_INT32(s, right);
Packit 1fb8d4
			Stream_Read_INT32(s, bottom);
Packit Service 5a9772
			if ((abs(x) > INT16_MAX) || (abs(y) > INT16_MAX))
Packit Service 5a9772
				return ERROR_INVALID_DATA;
Packit Service 5a9772
			w = right - x;
Packit Service 5a9772
			h = bottom - y;
Packit Service 5a9772
			if ((abs(w) > INT16_MAX) || (abs(h) > INT16_MAX))
Packit Service 5a9772
				return ERROR_INVALID_DATA;
Packit Service 5a9772
			rgndata->rects[i].x = (INT16)x;
Packit Service 5a9772
			rgndata->rects[i].y = (INT16)y;
Packit Service 5a9772
			rgndata->rects[i].width = (INT16)w;
Packit Service 5a9772
			rgndata->rects[i].height = (INT16)h;
Packit 1fb8d4
		}
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 geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT32 length, cbGeometryBuffer;
Packit Service 5a9772
	MAPPED_GEOMETRY* mappedGeometry;
Packit 1fb8d4
	GEOMETRY_PLUGIN* geometry;
Packit Service 5a9772
	GeometryClientContext* context;
Packit 1fb8d4
	UINT ret = CHANNEL_RC_OK;
Packit 1fb8d4
	UINT32 version, updateType, geometryType;
Packit 1fb8d4
	UINT64 id;
Packit 1fb8d4
Packit Service 5a9772
	geometry = (GEOMETRY_PLUGIN*)callback->plugin;
Packit 1fb8d4
	context = (GeometryClientContext*)geometry->iface.pInterface;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 4)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "not enough remaining data");
Packit 1fb8d4
		return ERROR_INVALID_DATA;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT32(s, length); /* Length (4 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	if (length < 73 || Stream_GetRemainingLength(s) < (length - 4))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "invalid packet length");
Packit 1fb8d4
		return ERROR_INVALID_DATA;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT32(s, version);
Packit 1fb8d4
	Stream_Read_UINT64(s, id);
Packit 1fb8d4
	Stream_Read_UINT32(s, updateType);
Packit 1fb8d4
	Stream_Seek_UINT32(s); /* flags */
Packit 1fb8d4
Packit 1fb8d4
	mappedGeometry = HashTable_GetItemValue(context->geometries, &id;;
Packit 1fb8d4
Packit Service 5a9772
	if (updateType == GEOMETRY_CLEAR)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!mappedGeometry)
Packit 1fb8d4
		{
Packit Service 5a9772
			WLog_ERR(TAG, "geometry 0x%" PRIx64 " not found here, ignoring clear command", id);
Packit 1fb8d4
			return CHANNEL_RC_OK;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit Service 5a9772
		WLog_DBG(TAG, "clearing geometry 0x%" PRIx64 "", id);
Packit 1fb8d4
Packit Service 5a9772
		if (mappedGeometry->MappedGeometryClear &&
Packit Service 5a9772
		    !mappedGeometry->MappedGeometryClear(mappedGeometry))
Packit 1fb8d4
			return ERROR_INTERNAL_ERROR;
Packit 1fb8d4
Packit 1fb8d4
		if (!HashTable_Remove(context->geometries, &id))
Packit 1fb8d4
			WLog_ERR(TAG, "geometry not removed from geometries");
Packit 1fb8d4
	}
Packit 1fb8d4
	else if (updateType == GEOMETRY_UPDATE)
Packit 1fb8d4
	{
Packit 1fb8d4
		BOOL newOne = FALSE;
Packit 1fb8d4
Packit 1fb8d4
		if (!mappedGeometry)
Packit 1fb8d4
		{
Packit 1fb8d4
			newOne = TRUE;
Packit Service 5a9772
			WLog_DBG(TAG, "creating geometry 0x%" PRIx64 "", id);
Packit 1fb8d4
			mappedGeometry = calloc(1, sizeof(MAPPED_GEOMETRY));
Packit 1fb8d4
			if (!mappedGeometry)
Packit 1fb8d4
				return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
Packit 1fb8d4
			mappedGeometry->refCounter = 1;
Packit 1fb8d4
			mappedGeometry->mappingId = id;
Packit 1fb8d4
Packit Service 5a9772
			if (HashTable_Add(context->geometries, &(mappedGeometry->mappingId), mappedGeometry) <
Packit Service 5a9772
			    0)
Packit 1fb8d4
			{
Packit Service 5a9772
				WLog_ERR(TAG, "unable to register geometry 0x%" PRIx64 " in the table", id);
Packit 1fb8d4
				free(mappedGeometry);
Packit 1fb8d4
				return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
			}
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit Service 5a9772
			WLog_DBG(TAG, "updating geometry 0x%" PRIx64 "", id);
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		Stream_Read_UINT64(s, mappedGeometry->topLevelId);
Packit 1fb8d4
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->left);
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->top);
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->right);
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->bottom);
Packit 1fb8d4
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->topLevelLeft);
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->topLevelTop);
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->topLevelRight);
Packit 1fb8d4
		Stream_Read_INT32(s, mappedGeometry->topLevelBottom);
Packit 1fb8d4
Packit 1fb8d4
		Stream_Read_UINT32(s, geometryType);
Packit 1fb8d4
Packit 1fb8d4
		Stream_Read_UINT32(s, cbGeometryBuffer);
Packit 1fb8d4
		if (Stream_GetRemainingLength(s) < cbGeometryBuffer)
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "invalid packet length");
Packit 1fb8d4
			return ERROR_INVALID_DATA;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (cbGeometryBuffer)
Packit 1fb8d4
		{
Packit 1fb8d4
			ret = geometry_read_RGNDATA(s, cbGeometryBuffer, &mappedGeometry->geometry);
Packit 1fb8d4
			if (ret != CHANNEL_RC_OK)
Packit 1fb8d4
				return ret;
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit 1fb8d4
			freerdp_rgndata_reset(&mappedGeometry->geometry);
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (newOne)
Packit 1fb8d4
		{
Packit Service 5a9772
			if (context->MappedGeometryAdded &&
Packit Service 5a9772
			    !context->MappedGeometryAdded(context, mappedGeometry))
Packit 1fb8d4
			{
Packit 1fb8d4
				WLog_ERR(TAG, "geometry added callback failed");
Packit 1fb8d4
				ret = ERROR_INTERNAL_ERROR;
Packit 1fb8d4
			}
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit Service 5a9772
			if (mappedGeometry->MappedGeometryUpdate &&
Packit Service 5a9772
			    !mappedGeometry->MappedGeometryUpdate(mappedGeometry))
Packit 1fb8d4
			{
Packit 1fb8d4
				WLog_ERR(TAG, "geometry update callback failed");
Packit 1fb8d4
				ret = ERROR_INTERNAL_ERROR;
Packit 1fb8d4
			}
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
	else
Packit 1fb8d4
	{
Packit Service 5a9772
		WLog_ERR(TAG, "unknown updateType=%" PRIu32 "", updateType);
Packit 1fb8d4
		ret = CHANNEL_RC_OK;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return ret;
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 geometry_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
Packit 1fb8d4
{
Packit Service 5a9772
	GEOMETRY_CHANNEL_CALLBACK* callback = (GEOMETRY_CHANNEL_CALLBACK*)pChannelCallback;
Packit 1fb8d4
	return geometry_recv_pdu(callback, data);
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 geometry_on_close(IWTSVirtualChannelCallback* pChannelCallback)
Packit 1fb8d4
{
Packit 1fb8d4
	free(pChannelCallback);
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 geometry_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
Packit Service 5a9772
                                               IWTSVirtualChannel* pChannel, BYTE* Data,
Packit Service 5a9772
                                               BOOL* pbAccept,
Packit Service 5a9772
                                               IWTSVirtualChannelCallback** ppCallback)
Packit 1fb8d4
{
Packit 1fb8d4
	GEOMETRY_CHANNEL_CALLBACK* callback;
Packit Service 5a9772
	GEOMETRY_LISTENER_CALLBACK* listener_callback = (GEOMETRY_LISTENER_CALLBACK*)pListenerCallback;
Packit Service 5a9772
Packit Service 5a9772
	WINPR_UNUSED(Data);
Packit Service 5a9772
	WINPR_UNUSED(pbAccept);
Packit Service 5a9772
Packit Service 5a9772
	callback = (GEOMETRY_CHANNEL_CALLBACK*)calloc(1, sizeof(GEOMETRY_CHANNEL_CALLBACK));
Packit 1fb8d4
Packit 1fb8d4
	if (!callback)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "calloc failed!");
Packit 1fb8d4
		return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	callback->iface.OnDataReceived = geometry_on_data_received;
Packit 1fb8d4
	callback->iface.OnClose = geometry_on_close;
Packit 1fb8d4
	callback->plugin = listener_callback->plugin;
Packit 1fb8d4
	callback->channel_mgr = listener_callback->channel_mgr;
Packit 1fb8d4
	callback->channel = pChannel;
Packit 1fb8d4
	listener_callback->channel_callback = callback;
Packit Service 5a9772
	*ppCallback = (IWTSVirtualChannelCallback*)callback;
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 geometry_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT status;
Packit Service 5a9772
	GEOMETRY_PLUGIN* geometry = (GEOMETRY_PLUGIN*)pPlugin;
Packit Service 5a9772
	geometry->listener_callback =
Packit Service 5a9772
	    (GEOMETRY_LISTENER_CALLBACK*)calloc(1, sizeof(GEOMETRY_LISTENER_CALLBACK));
Packit 1fb8d4
Packit 1fb8d4
	if (!geometry->listener_callback)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "calloc failed!");
Packit 1fb8d4
		return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	geometry->listener_callback->iface.OnNewChannelConnection = geometry_on_new_channel_connection;
Packit 1fb8d4
	geometry->listener_callback->plugin = pPlugin;
Packit 1fb8d4
	geometry->listener_callback->channel_mgr = pChannelMgr;
Packit Service 5a9772
	status =
Packit Service 5a9772
	    pChannelMgr->CreateListener(pChannelMgr, GEOMETRY_DVC_CHANNEL_NAME, 0,
Packit Service 5a9772
	                                &geometry->listener_callback->iface, &(geometry->listener));
Packit 1fb8d4
	geometry->listener->pInterface = geometry->iface.pInterface;
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 geometry_plugin_terminated(IWTSPlugin* pPlugin)
Packit 1fb8d4
{
Packit Service 5a9772
	GEOMETRY_PLUGIN* geometry = (GEOMETRY_PLUGIN*)pPlugin;
Packit Service 5a9772
	GeometryClientContext* context = (GeometryClientContext*)geometry->iface.pInterface;
Packit Service 5a9772
Packit Service 5a9772
	if (geometry && geometry->listener_callback)
Packit Service 5a9772
	{
Packit Service 5a9772
		IWTSVirtualChannelManager* mgr = geometry->listener_callback->channel_mgr;
Packit Service 5a9772
		if (mgr)
Packit Service 5a9772
			IFCALL(mgr->DestroyListener, mgr, geometry->listener);
Packit Service 5a9772
	}
Packit 1fb8d4
Packit 1fb8d4
	if (context)
Packit 1fb8d4
		HashTable_Free(context->geometries);
Packit 1fb8d4
Packit 1fb8d4
	free(geometry->listener_callback);
Packit 1fb8d4
	free(geometry->iface.pInterface);
Packit 1fb8d4
	free(pPlugin);
Packit 1fb8d4
	return CHANNEL_RC_OK;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
/**
Packit 1fb8d4
 * Channel Client Interface
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef BUILTIN_CHANNELS
Packit Service 5a9772
#define DVCPluginEntry geometry_DVCPluginEntry
Packit 1fb8d4
#else
Packit Service 5a9772
#define DVCPluginEntry FREERDP_API DVCPluginEntry
Packit 1fb8d4
#endif
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
UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT error = CHANNEL_RC_OK;
Packit 1fb8d4
	GEOMETRY_PLUGIN* geometry;
Packit 1fb8d4
	GeometryClientContext* context;
Packit Service 5a9772
	geometry = (GEOMETRY_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, "geometry");
Packit 1fb8d4
Packit 1fb8d4
	if (!geometry)
Packit 1fb8d4
	{
Packit Service 5a9772
		geometry = (GEOMETRY_PLUGIN*)calloc(1, sizeof(GEOMETRY_PLUGIN));
Packit 1fb8d4
Packit 1fb8d4
		if (!geometry)
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "calloc failed!");
Packit 1fb8d4
			return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		geometry->iface.Initialize = geometry_plugin_initialize;
Packit 1fb8d4
		geometry->iface.Connected = NULL;
Packit 1fb8d4
		geometry->iface.Disconnected = NULL;
Packit 1fb8d4
		geometry->iface.Terminated = geometry_plugin_terminated;
Packit Service 5a9772
		context = (GeometryClientContext*)calloc(1, sizeof(GeometryClientContext));
Packit 1fb8d4
Packit 1fb8d4
		if (!context)
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "calloc failed!");
Packit 1fb8d4
			goto error_context;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		context->geometries = HashTable_New(FALSE);
Packit 1fb8d4
		context->geometries->hash = (HASH_TABLE_HASH_FN)mappedGeometryHash;
Packit 1fb8d4
		context->geometries->keyCompare = (HASH_TABLE_KEY_COMPARE_FN)mappedGeometryKeyCompare;
Packit 1fb8d4
		context->geometries->valueFree = (HASH_TABLE_VALUE_FREE_FN)mappedGeometryUnref;
Packit 1fb8d4
Packit Service 5a9772
		context->handle = (void*)geometry;
Packit Service 5a9772
		geometry->iface.pInterface = (void*)context;
Packit 1fb8d4
		geometry->context = context;
Packit Service 5a9772
		error = pEntryPoints->RegisterPlugin(pEntryPoints, "geometry", (IWTSPlugin*)geometry);
Packit 1fb8d4
	}
Packit 1fb8d4
	else
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "could not get geometry Plugin.");
Packit 1fb8d4
		return CHANNEL_RC_BAD_CHANNEL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return error;
Packit 1fb8d4
Packit 1fb8d4
error_context:
Packit 1fb8d4
	free(geometry);
Packit 1fb8d4
	return CHANNEL_RC_NO_MEMORY;
Packit 1fb8d4
}