From 865bcc5d63807426a62c5484badbdfef94867ea3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 20 Jan 2015 11:58:09 +0100 Subject: [PATCH] Added CHANNEL_EVENT_DISCONNECTED handling. Additional error checks and logging. --- channels/encomsp/client/encomsp_main.c | 59 +++++++++++++++++--------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/channels/encomsp/client/encomsp_main.c b/channels/encomsp/client/encomsp_main.c index f8042befa..3c373da32 100644 --- a/channels/encomsp/client/encomsp_main.c +++ b/channels/encomsp/client/encomsp_main.c @@ -92,7 +92,8 @@ int encomsp_virtual_channel_write(encomspPlugin* encomsp, wStream* s) 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; } @@ -723,7 +724,8 @@ int encomsp_send(encomspPlugin* encomsp, wStream* s) if (status != CHANNEL_RC_OK) { 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; @@ -788,6 +790,9 @@ static VOID VCAPITYPE encomsp_virtual_channel_open_event(DWORD openHandle, UINT case CHANNEL_EVENT_WRITE_COMPLETE: Stream_Free((wStream*) pData, TRUE); 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) { - 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; } @@ -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); } -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); - WaitForSingleObject(encomsp->thread, INFINITE); - - MessageQueue_Free(encomsp->queue); - encomsp->queue = NULL; - - CloseHandle(encomsp->thread); - encomsp->thread = NULL; + WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]", + WTSErrorToString(rc), rc); } - encomsp->channelEntryPoints.pVirtualChannelClose(encomsp->OpenHandle); - if (encomsp->data_in) { 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); +} + + +static void encomsp_virtual_channel_event_terminated(encomspPlugin* encomsp) +{ encomsp_remove_init_handle_data(encomsp->InitHandle); - - free(encomsp->context); - free(encomsp); } @@ -891,6 +902,7 @@ static VOID VCAPITYPE encomsp_virtual_channel_init_event(LPVOID pInitHandle, UIN break; case CHANNEL_EVENT_DISCONNECTED: + encomsp_virtual_channel_event_disconnected(encomsp); break; 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) { + UINT rc; encomspPlugin* encomsp; EncomspClientContext* context; 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)); - encomsp->channelEntryPoints.pVirtualChannelInit(&encomsp->InitHandle, + rc = encomsp->channelEntryPoints.pVirtualChannelInit(&encomsp->InitHandle, &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.ppInterface = &(encomsp->channelEntryPoints.pInterface);