Added CHANNEL_EVENT_DISCONNECTED handling.

Additional error checks and logging.
This commit is contained in:
Armin Novak 2015-01-20 11:58:09 +01:00
parent 9e5ed07556
commit 865bcc5d63

View File

@ -92,7 +92,8 @@ int encomsp_virtual_channel_write(encomspPlugin* encomsp, wStream* s)
if (status != CHANNEL_RC_OK) if (status != CHANNEL_RC_OK)
{ {
WLog_ERR(TAG, "encomsp_virtual_channel_write: VirtualChannelWrite failed %d", status); WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
WTSErrorToString(status), status);
return -1; return -1;
} }
@ -723,7 +724,8 @@ int encomsp_send(encomspPlugin* encomsp, wStream* s)
if (status != CHANNEL_RC_OK) if (status != CHANNEL_RC_OK)
{ {
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
WLog_ERR(TAG, "encomsp_send: VirtualChannelWrite failed %d", status); WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
WTSErrorToString(status), status);
} }
return status; return status;
@ -788,6 +790,9 @@ static VOID VCAPITYPE encomsp_virtual_channel_open_event(DWORD openHandle, UINT
case CHANNEL_EVENT_WRITE_COMPLETE: case CHANNEL_EVENT_WRITE_COMPLETE:
Stream_Free((wStream*) pData, TRUE); Stream_Free((wStream*) pData, TRUE);
break; break;
case CHANNEL_EVENT_USER:
break;
} }
} }
@ -832,7 +837,8 @@ static void encomsp_virtual_channel_event_connected(encomspPlugin* encomsp, LPVO
if (status != CHANNEL_RC_OK) if (status != CHANNEL_RC_OK)
{ {
WLog_ERR(TAG, "encomsp_virtual_channel_event_connected: open failed: status: %d", status); WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
WTSErrorToString(status), status);
return; return;
} }
@ -842,22 +848,25 @@ static void encomsp_virtual_channel_event_connected(encomspPlugin* encomsp, LPVO
(LPTHREAD_START_ROUTINE) encomsp_virtual_channel_client_thread, (void*) encomsp, 0, NULL); (LPTHREAD_START_ROUTINE) encomsp_virtual_channel_client_thread, (void*) encomsp, 0, NULL);
} }
static void encomsp_virtual_channel_event_terminated(encomspPlugin* encomsp) static void encomsp_virtual_channel_event_disconnected(encomspPlugin* encomsp)
{ {
if (encomsp->queue) UINT rc;
MessageQueue_PostQuit(encomsp->queue, 0);
WaitForSingleObject(encomsp->thread, INFINITE);
MessageQueue_Free(encomsp->queue);
CloseHandle(encomsp->thread);
encomsp->queue = NULL;
encomsp->thread = NULL;
rc = encomsp->channelEntryPoints.pVirtualChannelClose(encomsp->OpenHandle);
if (CHANNEL_RC_OK != rc)
{ {
MessageQueue_PostQuit(encomsp->queue, 0); WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
WaitForSingleObject(encomsp->thread, INFINITE); WTSErrorToString(rc), rc);
MessageQueue_Free(encomsp->queue);
encomsp->queue = NULL;
CloseHandle(encomsp->thread);
encomsp->thread = NULL;
} }
encomsp->channelEntryPoints.pVirtualChannelClose(encomsp->OpenHandle);
if (encomsp->data_in) if (encomsp->data_in)
{ {
Stream_Free(encomsp->data_in, TRUE); Stream_Free(encomsp->data_in, TRUE);
@ -865,10 +874,12 @@ static void encomsp_virtual_channel_event_terminated(encomspPlugin* encomsp)
} }
encomsp_remove_open_handle_data(encomsp->OpenHandle); encomsp_remove_open_handle_data(encomsp->OpenHandle);
}
static void encomsp_virtual_channel_event_terminated(encomspPlugin* encomsp)
{
encomsp_remove_init_handle_data(encomsp->InitHandle); encomsp_remove_init_handle_data(encomsp->InitHandle);
free(encomsp->context);
free(encomsp); free(encomsp);
} }
@ -891,6 +902,7 @@ static VOID VCAPITYPE encomsp_virtual_channel_init_event(LPVOID pInitHandle, UIN
break; break;
case CHANNEL_EVENT_DISCONNECTED: case CHANNEL_EVENT_DISCONNECTED:
encomsp_virtual_channel_event_disconnected(encomsp);
break; break;
case CHANNEL_EVENT_TERMINATED: case CHANNEL_EVENT_TERMINATED:
@ -904,6 +916,7 @@ static VOID VCAPITYPE encomsp_virtual_channel_init_event(LPVOID pInitHandle, UIN
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{ {
UINT rc;
encomspPlugin* encomsp; encomspPlugin* encomsp;
EncomspClientContext* context; EncomspClientContext* context;
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx; CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
@ -945,9 +958,15 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
CopyMemory(&(encomsp->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP)); CopyMemory(&(encomsp->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
encomsp->channelEntryPoints.pVirtualChannelInit(&encomsp->InitHandle, rc = encomsp->channelEntryPoints.pVirtualChannelInit(&encomsp->InitHandle,
&encomsp->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, encomsp_virtual_channel_init_event); &encomsp->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, encomsp_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
WTSErrorToString(rc), rc);
free(encomsp);
return -1;
}
encomsp->channelEntryPoints.pInterface = *(encomsp->channelEntryPoints.ppInterface); encomsp->channelEntryPoints.pInterface = *(encomsp->channelEntryPoints.ppInterface);
encomsp->channelEntryPoints.ppInterface = &(encomsp->channelEntryPoints.pInterface); encomsp->channelEntryPoints.ppInterface = &(encomsp->channelEntryPoints.pInterface);