channels/drive: refactoring

This commit is contained in:
Marc-André Moreau 2013-11-03 19:10:33 -05:00
parent 13b6678977
commit 5406ebd5d8
5 changed files with 184 additions and 154 deletions

View File

@ -77,9 +77,9 @@ static wArrayList* g_ChannelsList = NULL;
int g_open_handle_sequence = 1;
/* For locking the global resources */
static HANDLE g_mutex_init = NULL;
static CRITICAL_SECTION g_channels_lock;
rdpChannels* freerdp_channels_find_by_open_handle(int open_handle, int* pindex)
rdpChannels* freerdp_channels_find_by_open_handle(int OpenHandle, int* pindex)
{
int i, j;
BOOL found = FALSE;
@ -94,7 +94,7 @@ rdpChannels* freerdp_channels_find_by_open_handle(int open_handle, int* pindex)
{
for (j = 0; j < channels->openDataCount; j++)
{
if (channels->openDataList[j].OpenHandle == open_handle)
if (channels->openDataList[j].OpenHandle == OpenHandle)
{
*pindex = j;
found = TRUE;
@ -324,11 +324,11 @@ UINT32 FreeRDP_VirtualChannelEventPush(UINT32 openHandle, wMessage* event)
*/
int freerdp_channels_global_init(void)
{
if (!g_mutex_init)
g_mutex_init = CreateMutex(NULL, FALSE, NULL);
if (!g_ChannelsList)
{
g_ChannelsList = ArrayList_New(TRUE);
InitializeCriticalSectionAndSpinCount(&g_channels_lock, 4000);
}
return 0;
}
@ -393,12 +393,12 @@ int freerdp_channels_client_load(rdpChannels* channels, rdpSettings* settings, v
channels->can_call_init = TRUE;
channels->settings = settings;
WaitForSingleObject(g_mutex_init, INFINITE);
EnterCriticalSection(&g_channels_lock);
g_ChannelInitData.channels = channels;
status = pChannelClientData->entry((PCHANNEL_ENTRY_POINTS) &ep);
ReleaseMutex(g_mutex_init);
LeaveCriticalSection(&g_channels_lock);
/* disable MyVirtualChannelInit */
channels->settings = NULL;
@ -495,16 +495,15 @@ int freerdp_channels_pre_connect(rdpChannels* channels, freerdp* instance)
int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance)
{
int index;
char* hostname;
int hostnameLength;
char* name;
char* hostname;
int hostnameLength;
CHANNEL_CLIENT_DATA* pChannelClientData;
channels->is_connected = 1;
hostname = instance->settings->ServerHostname;
hostnameLength = strlen(hostname);
DEBUG_CHANNELS("hostname [%s] channels->num_libs [%d]", hostname, channels->clientDataCount);
for (index = 0; index < channels->clientDataCount; index++)
{
pChannelClientData = &channels->clientDataList[index];
@ -518,10 +517,16 @@ int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance)
pChannelClientData->pChannelInitEventProc(pChannelClientData->pInitHandle, CHANNEL_EVENT_CONNECTED, hostname, hostnameLength);
name = (char*) malloc(9);
CopyMemory(name, pChannelOpenData->name, 8);
name[8] = '\0';
EventArgsInit(&e, "freerdp");
e.name = pChannelOpenData->name;
e.name = name;
e.pInterface = pChannelOpenData->pInterface;
PubSub_OnChannelConnected(instance->context->pubSub, instance->context, &e);
free(name);
}
}
@ -782,10 +787,12 @@ wMessage* freerdp_channels_pop_event(rdpChannels* channels)
void freerdp_channels_close(rdpChannels* channels, freerdp* instance)
{
int index;
char* name;
CHANNEL_OPEN_DATA* pChannelOpenData;
CHANNEL_CLIENT_DATA* pChannelClientData;
DEBUG_CHANNELS("closing");
channels->is_connected = 0;
freerdp_channels_check_fds(channels, instance);
@ -801,10 +808,16 @@ void freerdp_channels_close(rdpChannels* channels, freerdp* instance)
pChannelOpenData = &channels->openDataList[index];
name = (char*) malloc(9);
CopyMemory(name, pChannelOpenData->name, 8);
name[8] = '\0';
EventArgsInit(&e, "freerdp");
e.name = pChannelOpenData->name;
e.name = name;
e.pInterface = pChannelOpenData->pInterface;
PubSub_OnChannelDisconnected(instance->context->pubSub, instance->context, &e);
free(name);
}
/* Emit a quit signal to the internal message pipe. */

View File

@ -96,17 +96,17 @@ static UINT32 drive_map_posix_err(int fs_errno)
return rc;
}
static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* disk, UINT32 id)
static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* drive, UINT32 id)
{
DRIVE_FILE* file = NULL;
void* key = (void*) (size_t) id;
file = (DRIVE_FILE*) ListDictionary_GetItemValue(disk->files, key);
file = (DRIVE_FILE*) ListDictionary_GetItemValue(drive->files, key);
return file;
}
static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_create(DRIVE_DEVICE* drive, IRP* irp)
{
int status;
void* key;
@ -133,7 +133,7 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
FileId = irp->devman->id_sequence++;
file = drive_file_new(disk->path, path, FileId,
file = drive_file_new(drive->path, path, FileId,
DesiredAccess, CreateDisposition, CreateOptions);
if (!file)
@ -154,7 +154,7 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
else
{
key = (void*) (size_t) file->id;
ListDictionary_Add(disk->files, key, file);
ListDictionary_Add(drive->files, key, file);
switch (CreateDisposition)
{
@ -184,12 +184,12 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_close(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_close(DRIVE_DEVICE* drive, IRP* irp)
{
void* key;
DRIVE_FILE* file;
file = drive_get_file_by_id(disk, irp->FileId);
file = drive_get_file_by_id(drive, irp->FileId);
key = (void*) (size_t) irp->FileId;
@ -199,7 +199,7 @@ static void drive_process_irp_close(DRIVE_DEVICE* disk, IRP* irp)
}
else
{
ListDictionary_Remove(disk->files, key);
ListDictionary_Remove(drive->files, key);
drive_file_free(file);
}
@ -208,7 +208,7 @@ static void drive_process_irp_close(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp)
{
DRIVE_FILE* file;
UINT32 Length;
@ -218,7 +218,7 @@ static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp)
Stream_Read_UINT32(irp->input, Length);
Stream_Read_UINT64(irp->input, Offset);
file = drive_get_file_by_id(disk, irp->FileId);
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
{
@ -260,7 +260,7 @@ static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_write(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_write(DRIVE_DEVICE* drive, IRP* irp)
{
DRIVE_FILE* file;
UINT32 Length;
@ -270,7 +270,7 @@ static void drive_process_irp_write(DRIVE_DEVICE* disk, IRP* irp)
Stream_Read_UINT64(irp->input, Offset);
Stream_Seek(irp->input, 20); /* Padding */
file = drive_get_file_by_id(disk, irp->FileId);
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
{
@ -298,14 +298,14 @@ static void drive_process_irp_write(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_query_information(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_query_information(DRIVE_DEVICE* drive, IRP* irp)
{
DRIVE_FILE* file;
UINT32 FsInformationClass;
Stream_Read_UINT32(irp->input, FsInformationClass);
file = drive_get_file_by_id(disk, irp->FileId);
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
{
@ -323,7 +323,7 @@ static void drive_process_irp_query_information(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_set_information(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp)
{
DRIVE_FILE* file;
UINT32 FsInformationClass;
@ -333,7 +333,7 @@ static void drive_process_irp_set_information(DRIVE_DEVICE* disk, IRP* irp)
Stream_Read_UINT32(irp->input, Length);
Stream_Seek(irp->input, 24); /* Padding */
file = drive_get_file_by_id(disk, irp->FileId);
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
{
@ -353,7 +353,7 @@ static void drive_process_irp_set_information(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* irp)
{
UINT32 FsInformationClass;
wStream* output = irp->output;
@ -366,8 +366,8 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP*
Stream_Read_UINT32(irp->input, FsInformationClass);
STATVFS(disk->path, &svfst);
STAT(disk->path, &st);
STATVFS(drive->path, &svfst);
STAT(drive->path, &st);
switch (FsInformationClass)
{
@ -448,7 +448,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP*
/* http://msdn.microsoft.com/en-us/library/cc241518.aspx */
static void drive_process_irp_silent_ignore(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_silent_ignore(DRIVE_DEVICE* drive, IRP* irp)
{
UINT32 FsInformationClass;
wStream* output = irp->output;
@ -460,7 +460,7 @@ static void drive_process_irp_silent_ignore(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_query_directory(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp)
{
char* path = NULL;
int status;
@ -480,7 +480,7 @@ static void drive_process_irp_query_directory(DRIVE_DEVICE* disk, IRP* irp)
if (status < 1)
path = (char*) calloc(1, 1);
file = drive_get_file_by_id(disk, irp->FileId);
file = drive_get_file_by_id(drive, irp->FileId);
if (file == NULL)
{
@ -497,12 +497,12 @@ static void drive_process_irp_query_directory(DRIVE_DEVICE* disk, IRP* irp)
irp->Complete(irp);
}
static void drive_process_irp_directory_control(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_directory_control(DRIVE_DEVICE* drive, IRP* irp)
{
switch (irp->MinorFunction)
{
case IRP_MN_QUERY_DIRECTORY:
drive_process_irp_query_directory(disk, irp);
drive_process_irp_query_directory(drive, irp);
break;
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: /* TODO */
@ -517,56 +517,56 @@ static void drive_process_irp_directory_control(DRIVE_DEVICE* disk, IRP* irp)
}
}
static void drive_process_irp_device_control(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp_device_control(DRIVE_DEVICE* drive, IRP* irp)
{
Stream_Write_UINT32(irp->output, 0); /* OutputBufferLength */
irp->Complete(irp);
}
static void drive_process_irp(DRIVE_DEVICE* disk, IRP* irp)
static void drive_process_irp(DRIVE_DEVICE* drive, IRP* irp)
{
irp->IoStatus = STATUS_SUCCESS;
switch (irp->MajorFunction)
{
case IRP_MJ_CREATE:
drive_process_irp_create(disk, irp);
drive_process_irp_create(drive, irp);
break;
case IRP_MJ_CLOSE:
drive_process_irp_close(disk, irp);
drive_process_irp_close(drive, irp);
break;
case IRP_MJ_READ:
drive_process_irp_read(disk, irp);
drive_process_irp_read(drive, irp);
break;
case IRP_MJ_WRITE:
drive_process_irp_write(disk, irp);
drive_process_irp_write(drive, irp);
break;
case IRP_MJ_QUERY_INFORMATION:
drive_process_irp_query_information(disk, irp);
drive_process_irp_query_information(drive, irp);
break;
case IRP_MJ_SET_INFORMATION:
drive_process_irp_set_information(disk, irp);
drive_process_irp_set_information(drive, irp);
break;
case IRP_MJ_QUERY_VOLUME_INFORMATION:
drive_process_irp_query_volume_information(disk, irp);
drive_process_irp_query_volume_information(drive, irp);
break;
case IRP_MJ_LOCK_CONTROL:
drive_process_irp_silent_ignore(disk, irp);
drive_process_irp_silent_ignore(drive, irp);
break;
case IRP_MJ_DIRECTORY_CONTROL:
drive_process_irp_directory_control(disk, irp);
drive_process_irp_directory_control(drive, irp);
break;
case IRP_MJ_DEVICE_CONTROL:
drive_process_irp_device_control(disk, irp);
drive_process_irp_device_control(drive, irp);
break;
default:
@ -576,77 +576,87 @@ static void drive_process_irp(DRIVE_DEVICE* disk, IRP* irp)
}
}
static void drive_process_irp_list(DRIVE_DEVICE* disk)
static void drive_process_irp_list(DRIVE_DEVICE* drive)
{
IRP* irp;
while (1)
{
if (WaitForSingleObject(disk->stopEvent, 0) == WAIT_OBJECT_0)
if (WaitForSingleObject(drive->stopEvent, 0) == WAIT_OBJECT_0)
break;
irp = (IRP*) InterlockedPopEntrySList(disk->pIrpList);
irp = (IRP*) InterlockedPopEntrySList(drive->pIrpList);
if (irp == NULL)
break;
drive_process_irp(disk, irp);
drive_process_irp(drive, irp);
}
}
static void* drive_thread_func(void* arg)
{
DRIVE_DEVICE* disk = (DRIVE_DEVICE*) arg;
HANDLE hdl[] = {disk->irpEvent, disk->stopEvent};
DWORD status;
DWORD nCount;
HANDLE handles[8];
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) arg;
nCount = 0;
handles[nCount++] = drive->stopEvent;
handles[nCount++] = drive->irpEvent;
while (1)
{
DWORD rc = WaitForMultipleObjects(2, hdl, FALSE, INFINITE);
if (rc == WAIT_OBJECT_0 + 1)
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if (WaitForSingleObject(drive->stopEvent, 0) == WAIT_OBJECT_0)
{
break;
}
ResetEvent(disk->irpEvent);
drive_process_irp_list(disk);
ResetEvent(drive->irpEvent);
drive_process_irp_list(drive);
}
ExitThread(0);
ExitThread(0);
return NULL;
}
static void drive_irp_request(DEVICE* device, IRP* irp)
{
DRIVE_DEVICE* disk = (DRIVE_DEVICE*) device;
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
InterlockedPushEntrySList(disk->pIrpList, &(irp->ItemEntry));
InterlockedPushEntrySList(drive->pIrpList, &(irp->ItemEntry));
SetEvent(disk->irpEvent);
SetEvent(drive->irpEvent);
}
static void drive_free(DEVICE* device)
{
IRP* irp;
DRIVE_DEVICE* disk = (DRIVE_DEVICE*) device;
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
SetEvent(disk->stopEvent);
WaitForSingleObject(disk->thread, INFINITE);
CloseHandle(disk->thread);
CloseHandle(disk->irpEvent);
CloseHandle(disk->stopEvent);
SetEvent(drive->stopEvent);
WaitForSingleObject(drive->thread, INFINITE);
while ((irp = (IRP*) InterlockedPopEntrySList(disk->pIrpList)) != NULL)
CloseHandle(drive->thread);
CloseHandle(drive->irpEvent);
CloseHandle(drive->stopEvent);
while ((irp = (IRP*) InterlockedPopEntrySList(drive->pIrpList)) != NULL)
irp->Discard(irp);
_aligned_free(disk->pIrpList);
_aligned_free(drive->pIrpList);
ListDictionary_Free(disk->files);
ListDictionary_Free(drive->files);
free(disk);
free(drive);
}
void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)
{
int i, length;
DRIVE_DEVICE* disk;
DRIVE_DEVICE* drive;
#ifdef WIN32
/*
@ -664,35 +674,35 @@ void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char*
if (name[0] && path[0])
{
disk = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE));
ZeroMemory(disk, sizeof(DRIVE_DEVICE));
drive = (DRIVE_DEVICE*) malloc(sizeof(DRIVE_DEVICE));
ZeroMemory(drive, sizeof(DRIVE_DEVICE));
disk->device.type = RDPDR_DTYP_FILESYSTEM;
disk->device.name = name;
disk->device.IRPRequest = drive_irp_request;
disk->device.Free = drive_free;
drive->device.type = RDPDR_DTYP_FILESYSTEM;
drive->device.name = name;
drive->device.IRPRequest = drive_irp_request;
drive->device.Free = drive_free;
length = strlen(name);
disk->device.data = Stream_New(NULL, length + 1);
drive->device.data = Stream_New(NULL, length + 1);
for (i = 0; i <= length; i++)
Stream_Write_UINT8(disk->device.data, name[i] < 0 ? '_' : name[i]);
Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);
disk->path = path;
drive->path = path;
disk->files = ListDictionary_New(TRUE);
ListDictionary_Object(disk->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;
drive->files = ListDictionary_New(TRUE);
ListDictionary_Object(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;
disk->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
InitializeSListHead(disk->pIrpList);
drive->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
InitializeSListHead(drive->pIrpList);
disk->irpEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
disk->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
disk->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, disk, CREATE_SUSPENDED, NULL);
drive->irpEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
drive->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL);
pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) disk);
pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive);
ResumeThread(disk->thread);
ResumeThread(drive->thread);
}
}

View File

@ -204,6 +204,9 @@ static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use
}
}
if (pKeys)
free(pKeys);
pos = Stream_GetPosition(s);
Stream_SetPosition(s, count_pos);
Stream_Write_UINT32(s, count);
@ -289,12 +292,6 @@ static void rdpdr_process_receive(rdpdrPlugin* rdpdr, wStream* s)
Stream_Free(s, TRUE);
}
static void rdpdr_process_terminate(rdpdrPlugin* rdpdr)
{
devman_free(rdpdr->devman);
free(rdpdr);
}
/****************************************************************************************/
@ -366,7 +363,7 @@ int rdpdr_send(rdpdrPlugin* rdpdr, wStream* s)
return status;
}
static void rdpdr_virtual_channel_event_data_received(rdpdrPlugin* plugin,
static void rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr,
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
@ -384,13 +381,13 @@ static void rdpdr_virtual_channel_event_data_received(rdpdrPlugin* plugin,
if (dataFlags & CHANNEL_FLAG_FIRST)
{
if (plugin->data_in != NULL)
Stream_Free(plugin->data_in, TRUE);
if (rdpdr->data_in != NULL)
Stream_Free(rdpdr->data_in, TRUE);
plugin->data_in = Stream_New(NULL, totalLength);
rdpdr->data_in = Stream_New(NULL, totalLength);
}
data_in = plugin->data_in;
data_in = rdpdr->data_in;
Stream_EnsureRemainingCapacity(data_in, (int) dataLength);
Stream_Write(data_in, pData, dataLength);
@ -401,31 +398,31 @@ static void rdpdr_virtual_channel_event_data_received(rdpdrPlugin* plugin,
fprintf(stderr, "svc_plugin_process_received: read error\n");
}
plugin->data_in = NULL;
rdpdr->data_in = NULL;
Stream_SealLength(data_in);
Stream_SetPosition(data_in, 0);
MessageQueue_Post(plugin->MsgPipe->In, NULL, 0, (void*) data_in, NULL);
MessageQueue_Post(rdpdr->MsgPipe->In, NULL, 0, (void*) data_in, NULL);
}
}
static void rdpdr_virtual_channel_open_event(UINT32 openHandle, UINT32 event,
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
rdpdrPlugin* plugin;
rdpdrPlugin* rdpdr;
plugin = (rdpdrPlugin*) rdpdr_get_open_handle_data(openHandle);
rdpdr = (rdpdrPlugin*) rdpdr_get_open_handle_data(openHandle);
if (!plugin)
if (!rdpdr)
{
fprintf(stderr, "svc_plugin_open_event: error no match\n");
fprintf(stderr, "rdpdr_virtual_channel_open_event: error no match\n");
return;
}
switch (event)
{
case CHANNEL_EVENT_DATA_RECEIVED:
rdpdr_virtual_channel_event_data_received(plugin, pData, dataLength, totalLength, dataFlags);
rdpdr_virtual_channel_event_data_received(rdpdr, pData, dataLength, totalLength, dataFlags);
break;
case CHANNEL_EVENT_WRITE_COMPLETE:
@ -441,16 +438,16 @@ static void* rdpdr_virtual_channel_client_thread(void* arg)
{
wStream* data;
wMessage message;
rdpdrPlugin* plugin = (rdpdrPlugin*) arg;
rdpdrPlugin* rdpdr = (rdpdrPlugin*) arg;
rdpdr_process_connect(plugin);
rdpdr_process_connect(rdpdr);
while (1)
{
if (!MessageQueue_Wait(plugin->MsgPipe->In))
if (!MessageQueue_Wait(rdpdr->MsgPipe->In))
break;
if (MessageQueue_Peek(plugin->MsgPipe->In, &message, TRUE))
if (MessageQueue_Peek(rdpdr->MsgPipe->In, &message, TRUE))
{
if (message.id == WMQ_QUIT)
break;
@ -458,7 +455,7 @@ static void* rdpdr_virtual_channel_client_thread(void* arg)
if (message.id == 0)
{
data = (wStream*) message.wParam;
rdpdr_process_receive(plugin, data);
rdpdr_process_receive(rdpdr, data);
}
}
}
@ -467,72 +464,76 @@ static void* rdpdr_virtual_channel_client_thread(void* arg)
return NULL;
}
static void rdpdr_virtual_channel_event_connected(rdpdrPlugin* plugin, void* pData, UINT32 dataLength)
static void rdpdr_virtual_channel_event_connected(rdpdrPlugin* rdpdr, void* pData, UINT32 dataLength)
{
UINT32 status;
status = plugin->channelEntryPoints.pVirtualChannelOpen(plugin->InitHandle,
&plugin->OpenHandle, plugin->channelDef.name, rdpdr_virtual_channel_open_event);
status = rdpdr->channelEntryPoints.pVirtualChannelOpen(rdpdr->InitHandle,
&rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event);
rdpdr_add_open_handle_data(plugin->OpenHandle, plugin);
rdpdr_add_open_handle_data(rdpdr->OpenHandle, rdpdr);
if (status != CHANNEL_RC_OK)
{
fprintf(stderr, "svc_plugin_process_connected: open failed: status: %d\n", status);
fprintf(stderr, "rdpdr_virtual_channel_event_connected: open failed: status: %d\n", status);
return;
}
plugin->MsgPipe = MessagePipe_New();
rdpdr->MsgPipe = MessagePipe_New();
plugin->thread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) rdpdr_virtual_channel_client_thread, (void*) plugin, 0, NULL);
rdpdr->thread = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) rdpdr_virtual_channel_client_thread, (void*) rdpdr, 0, NULL);
}
static void rdpdr_virtual_channel_event_terminated(rdpdrPlugin* plugin)
static void rdpdr_virtual_channel_event_terminated(rdpdrPlugin* rdpdr)
{
MessagePipe_PostQuit(plugin->MsgPipe, 0);
WaitForSingleObject(plugin->thread, INFINITE);
MessagePipe_PostQuit(rdpdr->MsgPipe, 0);
WaitForSingleObject(rdpdr->thread, INFINITE);
MessagePipe_Free(plugin->MsgPipe);
CloseHandle(plugin->thread);
MessagePipe_Free(rdpdr->MsgPipe);
CloseHandle(rdpdr->thread);
plugin->channelEntryPoints.pVirtualChannelClose(plugin->OpenHandle);
rdpdr->channelEntryPoints.pVirtualChannelClose(rdpdr->OpenHandle);
if (plugin->data_in)
if (rdpdr->data_in)
{
Stream_Free(plugin->data_in, TRUE);
plugin->data_in = NULL;
Stream_Free(rdpdr->data_in, TRUE);
rdpdr->data_in = NULL;
}
rdpdr_process_terminate(plugin);
if (rdpdr->devman)
{
devman_free(rdpdr->devman);
rdpdr->devman = NULL;
}
rdpdr_remove_open_handle_data(plugin->OpenHandle);
rdpdr_remove_init_handle_data(plugin->InitHandle);
rdpdr_remove_open_handle_data(rdpdr->OpenHandle);
rdpdr_remove_init_handle_data(rdpdr->InitHandle);
}
static void rdpdr_virtual_channel_init_event(void* pInitHandle, UINT32 event, void* pData, UINT32 dataLength)
{
rdpdrPlugin* plugin;
rdpdrPlugin* rdpdr;
plugin = (rdpdrPlugin*) rdpdr_get_init_handle_data(pInitHandle);
rdpdr = (rdpdrPlugin*) rdpdr_get_init_handle_data(pInitHandle);
if (!plugin)
if (!rdpdr)
{
fprintf(stderr, "svc_plugin_init_event: error no match\n");
fprintf(stderr, "rdpdr_virtual_channel_init_event: error no match\n");
return;
}
switch (event)
{
case CHANNEL_EVENT_CONNECTED:
rdpdr_virtual_channel_event_connected(plugin, pData, dataLength);
rdpdr_virtual_channel_event_connected(rdpdr, pData, dataLength);
break;
case CHANNEL_EVENT_DISCONNECTED:
break;
case CHANNEL_EVENT_TERMINATED:
rdpdr_virtual_channel_event_terminated(plugin);
rdpdr_virtual_channel_event_terminated(rdpdr);
break;
}
}
@ -542,24 +543,24 @@ static void rdpdr_virtual_channel_init_event(void* pInitHandle, UINT32 event, vo
int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{
rdpdrPlugin* plugin;
rdpdrPlugin* rdpdr;
plugin = (rdpdrPlugin*) malloc(sizeof(rdpdrPlugin));
ZeroMemory(plugin, sizeof(rdpdrPlugin));
rdpdr = (rdpdrPlugin*) malloc(sizeof(rdpdrPlugin));
ZeroMemory(rdpdr, sizeof(rdpdrPlugin));
plugin->channelDef.options =
rdpdr->channelDef.options =
CHANNEL_OPTION_INITIALIZED |
CHANNEL_OPTION_ENCRYPT_RDP |
CHANNEL_OPTION_COMPRESS_RDP;
strcpy(plugin->channelDef.name, "rdpdr");
strcpy(rdpdr->channelDef.name, "rdpdr");
CopyMemory(&(plugin->channelEntryPoints), pEntryPoints, pEntryPoints->cbSize);
CopyMemory(&(rdpdr->channelEntryPoints), pEntryPoints, pEntryPoints->cbSize);
plugin->channelEntryPoints.pVirtualChannelInit(&plugin->InitHandle,
&plugin->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, rdpdr_virtual_channel_init_event);
rdpdr->channelEntryPoints.pVirtualChannelInit(&rdpdr->InitHandle,
&rdpdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, rdpdr_virtual_channel_init_event);
rdpdr_add_init_handle_data(plugin->InitHandle, (void*) plugin);
rdpdr_add_init_handle_data(rdpdr->InitHandle, (void*) rdpdr);
return 1;
}

View File

@ -297,8 +297,15 @@ void rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, wStream* s)
Stream_Read_UINT16(s, format->wBitsPerSample); /* wBitsPerSample */
Stream_Read_UINT16(s, format->cbSize); /* cbSize */
format->data = (BYTE*) malloc(format->cbSize);
Stream_Read(s, format->data, format->cbSize);
if (format->cbSize > 0)
{
format->data = (BYTE*) malloc(format->cbSize);
Stream_Read(s, format->data, format->cbSize);
}
else
{
format->data = NULL;
}
}
rdpsnd_select_supported_audio_formats(rdpsnd);

View File

@ -288,7 +288,6 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
{
BOOL status;
rdpSettings* settings = rdp->settings;
rdpRedirection* redirection = rdp->redirection;
rdp_client_disconnect(rdp);