rdpsnd: using new VirtualChannelEx api

This commit is contained in:
Martin Haimberger 2016-11-22 05:47:20 -08:00
parent 088a04fa44
commit d29848f383
3 changed files with 32 additions and 38 deletions

View File

@ -1288,7 +1288,7 @@ BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID p
cliprdr->InitHandle = pInitHandle;
rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx((void*) cliprdr, &cliprdr->InitHandle,
rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx((void*) cliprdr, pInitHandle,
&cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
cliprdr_virtual_channel_init_event_ex);

View File

@ -21,7 +21,7 @@ set(${MODULE_PREFIX}_SRCS
rdpsnd_main.c
rdpsnd_main.h)
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry")
add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntryEx")

View File

@ -52,7 +52,7 @@
struct rdpsnd_plugin
{
CHANNEL_DEF channelDef;
CHANNEL_ENTRY_POINTS_FREERDP channelEntryPoints;
CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints;
HANDLE thread;
wStream* data_in;
@ -93,8 +93,6 @@ struct rdpsnd_plugin
rdpContext* rdpcontext;
};
static rdpChannelHandles g_ChannelHandles = { NULL, NULL };
/**
* Function description
*
@ -1130,14 +1128,14 @@ UINT rdpsnd_virtual_channel_write(rdpsndPlugin* rdpsnd, wStream* s)
}
else
{
status = rdpsnd->channelEntryPoints.pVirtualChannelWrite(rdpsnd->OpenHandle,
status = rdpsnd->channelEntryPoints.pVirtualChannelWriteEx(rdpsnd->InitHandle, rdpsnd->OpenHandle,
Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
WLog_ERR(TAG, "pVirtualChannelWriteEx failed with %s [%08X]",
WTSErrorToString(status), status);
}
@ -1205,16 +1203,15 @@ static UINT rdpsnd_virtual_channel_event_data_received(rdpsndPlugin* plugin,
return CHANNEL_RC_OK;
}
static VOID VCAPITYPE rdpsnd_virtual_channel_open_event(DWORD openHandle,
UINT event,
static VOID VCAPITYPE rdpsnd_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, UINT event,
LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
UINT error = CHANNEL_RC_OK;
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) freerdp_channel_get_open_handle_data(&g_ChannelHandles, openHandle);
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) lpUserParam;
if (!rdpsnd || (rdpsnd->OpenHandle != openHandle))
{
WLog_ERR(TAG, "rdpsnd_virtual_channel_open_event: error no match");
WLog_ERR(TAG, "error no match");
return;
}
@ -1238,7 +1235,7 @@ static VOID VCAPITYPE rdpsnd_virtual_channel_open_event(DWORD openHandle,
if (error && rdpsnd->rdpcontext)
setChannelError(rdpsnd->rdpcontext, error,
"rdpsnd_virtual_channel_open_event reported an error");
"rdpsnd_virtual_channel_open_event_ex reported an error");
}
static void* rdpsnd_virtual_channel_client_thread(void* arg)
@ -1305,19 +1302,17 @@ static UINT rdpsnd_virtual_channel_event_connected(rdpsndPlugin* rdpsnd,
LPVOID pData, UINT32 dataLength)
{
UINT32 status;
status = rdpsnd->channelEntryPoints.pVirtualChannelOpen(rdpsnd->InitHandle,
status = rdpsnd->channelEntryPoints.pVirtualChannelOpenEx(rdpsnd->InitHandle,
&rdpsnd->OpenHandle, rdpsnd->channelDef.name,
rdpsnd_virtual_channel_open_event);
rdpsnd_virtual_channel_open_event_ex);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
WLog_ERR(TAG, "pVirtualChannelOpenEx failed with %s [%08X]",
WTSErrorToString(status), status);
return status;
}
freerdp_channel_add_open_handle_data(&g_ChannelHandles, rdpsnd->OpenHandle, (void*) rdpsnd);
rdpsnd->MsgPipe = MessagePipe_New();
if (!rdpsnd->MsgPipe)
@ -1360,11 +1355,11 @@ static UINT rdpsnd_virtual_channel_event_disconnected(rdpsndPlugin* rdpsnd)
CloseHandle(rdpsnd->thread);
rdpsnd->thread = NULL;
error = rdpsnd->channelEntryPoints.pVirtualChannelClose(rdpsnd->OpenHandle);
error = rdpsnd->channelEntryPoints.pVirtualChannelCloseEx(rdpsnd->InitHandle, rdpsnd->OpenHandle);
if (CHANNEL_RC_OK != error)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
WLog_ERR(TAG, "pVirtualChannelCloseEx failed with %s [%08X]",
WTSErrorToString(error), error);
return error;
}
@ -1404,27 +1399,24 @@ static UINT rdpsnd_virtual_channel_event_disconnected(rdpsndPlugin* rdpsnd)
rdpsnd->device_name = NULL;
}
freerdp_channel_remove_open_handle_data(&g_ChannelHandles, rdpsnd->OpenHandle);
return CHANNEL_RC_OK;
}
static void rdpsnd_virtual_channel_event_terminated(rdpsndPlugin* rdpsnd)
{
freerdp_channel_remove_init_handle_data(&g_ChannelHandles, (void*) rdpsnd);
rdpsnd->InitHandle = 0;
free(rdpsnd);
}
static VOID VCAPITYPE rdpsnd_virtual_channel_init_event(LPVOID pInitHandle,
static VOID VCAPITYPE rdpsnd_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle,
UINT event, LPVOID pData, UINT dataLength)
{
UINT error = CHANNEL_RC_OK;
rdpsndPlugin* plugin = (rdpsndPlugin*) freerdp_channel_get_init_handle_data(&g_ChannelHandles, pInitHandle);
rdpsndPlugin* plugin = (rdpsndPlugin*) lpUserParam;
if (!plugin || (plugin->InitHandle != pInitHandle))
{
WLog_ERR(TAG, "rdpsnd_virtual_channel_init_event: error no match");
WLog_ERR(TAG, "error no match");
return;
}
@ -1461,13 +1453,13 @@ static VOID VCAPITYPE rdpsnd_virtual_channel_init_event(LPVOID pInitHandle,
}
/* rdpsnd is always built-in */
#define VirtualChannelEntry rdpsnd_VirtualChannelEntry
#define VirtualChannelEntryEx rdpsnd_VirtualChannelEntryEx
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID pInitHandle)
{
UINT rc;
rdpsndPlugin* rdpsnd;
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx;
if (!pEntryPoints)
{
@ -1493,31 +1485,33 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
rdpsnd->channelDef.options =
CHANNEL_OPTION_INITIALIZED |
CHANNEL_OPTION_ENCRYPT_RDP;
strcpy(rdpsnd->channelDef.name, "rdpsnd");
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP*) pEntryPoints;
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP)) &&
strcpy(rdpsnd->channelDef.name, "rdpsnd");
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*) pEntryPoints;
if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) &&
(pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER))
{
rdpsnd->rdpcontext = pEntryPointsEx->context;
}
CopyMemory(&(rdpsnd->channelEntryPoints), pEntryPoints,
sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rdpsnd->log = WLog_Get("com.freerdp.channels.rdpsnd.client");
rc = rdpsnd->channelEntryPoints.pVirtualChannelInit(&rdpsnd->InitHandle,
CopyMemory(&(rdpsnd->channelEntryPoints), pEntryPoints,
sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX));
rdpsnd->InitHandle = pInitHandle;
rc = rdpsnd->channelEntryPoints.pVirtualChannelInitEx((void*)rdpsnd, pInitHandle,
&rdpsnd->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
rdpsnd_virtual_channel_init_event);
rdpsnd_virtual_channel_init_event_ex);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
WLog_ERR(TAG, "pVirtualChannelInitEx failed with %s [%08X]",
WTSErrorToString(rc), rc);
free(rdpsnd);
return FALSE;
}
freerdp_channel_add_init_handle_data(&g_ChannelHandles, rdpsnd->InitHandle, (void*) rdpsnd);
return TRUE;
}