boolean WTSVirtualChannelClose( /* __in */ void* hChannelHandle) { wts_data_item* item; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; if (channel != NULL) { if (channel->index < channel->client->settings->num_channels) channel->client->settings->channels[channel->index].handle = NULL; stream_free(channel->receive_data); if (channel->receive_event) wait_obj_free(channel->receive_event); if (channel->receive_queue) { while ((item = (wts_data_item*) list_dequeue(channel->receive_queue)) != NULL) { wts_data_item_free(item); } list_free(channel->receive_queue); } if (channel->mutex) freerdp_mutex_free(channel->mutex); xfree(channel); } return true; }
void WTSDestroyVirtualChannelManager(WTSVirtualChannelManager* vcm) { wts_data_item* item; rdpPeerChannel* channel; if (vcm != NULL) { while ((channel = (rdpPeerChannel*) list_dequeue(vcm->dvc_channel_list)) != NULL) { WTSVirtualChannelClose(channel); } list_free(vcm->dvc_channel_list); if (vcm->drdynvc_channel != NULL) { WTSVirtualChannelClose(vcm->drdynvc_channel); vcm->drdynvc_channel = NULL; } CloseHandle(vcm->send_event); while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL) { wts_data_item_free(item); } list_free(vcm->send_queue); CloseHandle(vcm->mutex); free(vcm); } }
boolean WTSVirtualChannelRead( /* __in */ void* hChannelHandle, /* __in */ uint32 TimeOut, /* __out */ uint8* Buffer, /* __in */ uint32 BufferSize, /* __out */ uint32* pBytesRead) { wts_data_item* item; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; item = (wts_data_item*) list_peek(channel->receive_queue); if (item == NULL) { wait_obj_clear(channel->receive_event); *pBytesRead = 0; return true; } *pBytesRead = item->length; if (item->length > BufferSize) return false; /* remove the first element (same as what we just peek) */ freerdp_mutex_lock(channel->mutex); list_dequeue(channel->receive_queue); if (list_size(channel->receive_queue) == 0) wait_obj_clear(channel->receive_event); freerdp_mutex_unlock(channel->mutex); memcpy(Buffer, item->buffer, item->length); wts_data_item_free(item) ; return true; }
BOOL WTSVirtualChannelClose( /* __in */ void* hChannelHandle) { wStream* s; wts_data_item* item; WTSVirtualChannelManager* vcm; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; if (channel) { vcm = channel->vcm; if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_SVC) { if (channel->index < channel->client->settings->ChannelCount) channel->client->settings->ChannelDefArray[channel->index].handle = NULL; } else { WaitForSingleObject(vcm->mutex, INFINITE); list_remove(vcm->dvc_channel_list, channel); ReleaseMutex(vcm->mutex); if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED) { s = stream_new(8); wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channel_id); WTSVirtualChannelWrite(vcm->drdynvc_channel, stream_get_head(s), stream_get_length(s), NULL); stream_free(s); } } if (channel->receive_data) stream_free(channel->receive_data); if (channel->receive_event) CloseHandle(channel->receive_event); if (channel->receive_queue) { while ((item = (wts_data_item*) list_dequeue(channel->receive_queue)) != NULL) { wts_data_item_free(item); } list_free(channel->receive_queue); } if (channel->mutex) CloseHandle(channel->mutex); free(channel); } return TRUE; }
boolean WTSVirtualChannelClose( /* __in */ void* hChannelHandle) { STREAM* s; wts_data_item* item; WTSVirtualChannelManager* vcm; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; if (channel) { vcm = channel->vcm; if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_SVC) { if (channel->index < channel->client->settings->num_channels) channel->client->settings->channels[channel->index].handle = NULL; } else { freerdp_mutex_lock(vcm->mutex); list_remove(vcm->dvc_channel_list, channel); freerdp_mutex_unlock(vcm->mutex); if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED) { s = stream_new(8); wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channel_id); WTSVirtualChannelWrite(vcm->drdynvc_channel, stream_get_head(s), stream_get_length(s), NULL); stream_free(s); } } if (channel->receive_data) stream_free(channel->receive_data); if (channel->receive_event) wait_obj_free(channel->receive_event); if (channel->receive_queue) { while ((item = (wts_data_item*) list_dequeue(channel->receive_queue)) != NULL) { wts_data_item_free(item); } list_free(channel->receive_queue); } if (channel->mutex) freerdp_mutex_free(channel->mutex); xfree(channel); } return true; }
BOOL WTSVirtualChannelManagerCheckFileDescriptor(WTSVirtualChannelManager* vcm) { BOOL result = TRUE; wts_data_item* item; rdpPeerChannel* channel; UINT32 dynvc_caps; if (vcm->drdynvc_state == DRDYNVC_STATE_NONE && vcm->client->activated) { /* Initialize drdynvc channel once and only once. */ vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED; channel = WTSVirtualChannelOpenEx(vcm, "drdynvc", 0); if (channel) { vcm->drdynvc_channel = channel; dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */ WTSVirtualChannelWrite(channel, (BYTE*) &dynvc_caps, sizeof(dynvc_caps), NULL); } } ResetEvent(vcm->send_event); WaitForSingleObject(vcm->mutex, INFINITE); while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL) { if (vcm->client->SendChannelData(vcm->client, item->channel_id, item->buffer, item->length) == FALSE) { result = FALSE; } wts_data_item_free(item); if (result == FALSE) break; } ReleaseMutex(vcm->mutex); return result; }
boolean WTSVirtualChannelManagerCheckFileDescriptor(WTSVirtualChannelManager* vcm) { boolean result = true; wts_data_item* item; wait_obj_clear(vcm->send_event); freerdp_mutex_lock(vcm->mutex); while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL) { if (vcm->client->SendChannelData(vcm->client, item->channel_id, item->buffer, item->length) == false) { result = false; } wts_data_item_free(item); if (result == false) break; } freerdp_mutex_unlock(vcm->mutex); return result; }
void WTSDestroyVirtualChannelManager(WTSVirtualChannelManager* vcm) { wts_data_item* item; if (vcm != NULL) { if (vcm->drdynvc_channel != NULL) { WTSVirtualChannelClose(vcm->drdynvc_channel); vcm->drdynvc_channel = NULL; } wait_obj_free(vcm->send_event); while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL) { wts_data_item_free(item); } list_free(vcm->send_queue); freerdp_mutex_free(vcm->mutex); xfree(vcm); } }
BOOL WTSVirtualChannelRead( /* __in */ void* hChannelHandle, /* __in */ UINT32 TimeOut, /* __out */ BYTE* Buffer, /* __in */ UINT32 BufferSize, /* __out */ UINT32* pBytesRead) { wts_data_item* item; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; item = (wts_data_item*) list_peek(channel->receive_queue); if (item == NULL) { ResetEvent(channel->receive_event); *pBytesRead = 0; return TRUE; } *pBytesRead = item->length; if (item->length > BufferSize) return FALSE; /* remove the first element (same as what we just peek) */ WaitForSingleObject(channel->mutex, INFINITE); list_dequeue(channel->receive_queue); if (list_size(channel->receive_queue) == 0) ResetEvent(channel->receive_event); ReleaseMutex(channel->mutex); CopyMemory(Buffer, item->buffer, item->length); wts_data_item_free(item) ; return TRUE; }
boolean WTSVirtualChannelManagerCheckFileDescriptor(WTSVirtualChannelManager* vcm) { boolean result = true; wts_data_item* item; rdpPeerChannel* channel; uint32 dynvc_caps; if (vcm->drdynvc_state == DRDYNVC_STATE_NONE && vcm->client->activated) { /* Initialize drdynvc channel once and only once. */ vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED; channel = WTSVirtualChannelOpenEx(vcm, "drdynvc", 0); if (channel) { vcm->drdynvc_channel = channel; dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */ WTSVirtualChannelWrite(channel, (uint8*) &dynvc_caps, sizeof(dynvc_caps), NULL); } } wait_obj_clear(vcm->send_event); freerdp_mutex_lock(vcm->mutex); while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL) { if (vcm->client->SendChannelData(vcm->client, item->channel_id, item->buffer, item->length) == false) { result = false; } wts_data_item_free(item); if (result == false) break; } freerdp_mutex_unlock(vcm->mutex); return result; }