libfreerdp-client: fix bug in pInterface channel registration

This commit is contained in:
Marc-André Moreau 2013-12-05 16:55:28 -05:00
parent f963491ebe
commit 4d6f3b6de4
5 changed files with 79 additions and 94 deletions

View File

@ -57,7 +57,7 @@ CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr)
{
CliprdrClientContext* pInterface;
rdpSvcPlugin* plugin = (rdpSvcPlugin*) cliprdr;
pInterface = (CliprdrClientContext*) *(plugin->channel_entry_points.ppInterface);
pInterface = (CliprdrClientContext*) plugin->channel_entry_points.pInterface;
return pInterface;
}

View File

@ -42,7 +42,7 @@ RailClientContext* rail_get_client_interface(void* railObject)
{
RailClientContext* pInterface;
rdpSvcPlugin* plugin = (rdpSvcPlugin*) railObject;
pInterface = (RailClientContext*) *(plugin->channel_entry_points.ppInterface);
pInterface = (RailClientContext*) plugin->channel_entry_points.pInterface;
return pInterface;
}
@ -503,25 +503,25 @@ int rail_server_get_appid_response(RailClientContext* context, RAIL_GET_APPID_RE
int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{
railPlugin* _p;
railPlugin* rail;
RailClientContext* context;
CHANNEL_ENTRY_POINTS_EX* pEntryPointsEx;
_p = (railPlugin*) malloc(sizeof(railPlugin));
ZeroMemory(_p, sizeof(railPlugin));
rail = (railPlugin*) malloc(sizeof(railPlugin));
ZeroMemory(rail, sizeof(railPlugin));
_p->plugin.channel_def.options =
rail->plugin.channel_def.options =
CHANNEL_OPTION_INITIALIZED |
CHANNEL_OPTION_ENCRYPT_RDP |
CHANNEL_OPTION_COMPRESS_RDP |
CHANNEL_OPTION_SHOW_PROTOCOL;
strcpy(_p->plugin.channel_def.name, "rail");
strcpy(rail->plugin.channel_def.name, "rail");
_p->plugin.connect_callback = rail_process_connect;
_p->plugin.receive_callback = rail_process_receive;
_p->plugin.event_callback = rail_process_event;
_p->plugin.terminate_callback = rail_process_terminate;
rail->plugin.connect_callback = rail_process_connect;
rail->plugin.receive_callback = rail_process_receive;
rail->plugin.event_callback = rail_process_event;
rail->plugin.terminate_callback = rail_process_terminate;
pEntryPointsEx = (CHANNEL_ENTRY_POINTS_EX*) pEntryPoints;
@ -530,7 +530,7 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{
context = (RailClientContext*) malloc(sizeof(RailClientContext));
context->handle = (void*) _p;
context->handle = (void*) rail;
context->ClientExecute = rail_client_execute;
context->ClientActivate = rail_client_activate;
@ -557,11 +557,11 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
}
WLog_Init();
_p->log = WLog_Get("com.freerdp.channels.rail.client");
rail->log = WLog_Get("com.freerdp.channels.rail.client");
WLog_Print(_p->log, WLOG_DEBUG, "VirtualChannelEntry");
WLog_Print(rail->log, WLOG_DEBUG, "VirtualChannelEntry");
svc_plugin_init((rdpSvcPlugin*) _p, pEntryPoints);
svc_plugin_init((rdpSvcPlugin*) rail, pEntryPoints);
return 1;
}

View File

@ -109,7 +109,8 @@ struct _CHANNEL_ENTRY_POINTS_EX
/* Extended Fields */
UINT32 MagicNumber; /* identifies FreeRDP */
void* pExtendedData; /* extended initial data */
void** ppInterface; /* channel callback interface */
void* pInterface; /* channel callback interface, use after initialization */
void** ppInterface; /* channel callback interface, use for initialization */
PVIRTUALCHANNELEVENTPUSH pVirtualChannelEventPush;
};
typedef struct _CHANNEL_ENTRY_POINTS_EX CHANNEL_ENTRY_POINTS_EX;

View File

@ -50,8 +50,8 @@ struct rdp_svc_plugin
HANDLE thread;
wStream* data_in;
void* init_handle;
UINT32 open_handle;
void* InitHandle;
UINT32 OpenHandle;
wMessagePipe* MsgPipe;
};

View File

@ -37,79 +37,57 @@
#include <freerdp/utils/event.h>
#include <freerdp/utils/svc_plugin.h>
static wArrayList* g_AddinList = NULL;
static wListDictionary* g_InitHandles;
static wListDictionary* g_OpenHandles;
rdpSvcPlugin* svc_plugin_find_by_init_handle(void* init_handle)
void svc_plugin_add_init_handle_data(void* pInitHandle, void* pUserData)
{
int index;
BOOL found = FALSE;
rdpSvcPlugin* plugin;
if (!g_InitHandles)
g_InitHandles = ListDictionary_New(TRUE);
ArrayList_Lock(g_AddinList);
index = 0;
plugin = (rdpSvcPlugin*) ArrayList_GetItem(g_AddinList, index++);
while (plugin)
{
if (plugin->init_handle == init_handle)
{
found = TRUE;
break;
}
plugin = (rdpSvcPlugin*) ArrayList_GetItem(g_AddinList, index++);
}
ArrayList_Unlock(g_AddinList);
return (found) ? plugin : NULL;
ListDictionary_Add(g_InitHandles, pInitHandle, pUserData);
}
rdpSvcPlugin* svc_plugin_find_by_open_handle(UINT32 open_handle)
void* svc_plugin_get_init_handle_data(void* pInitHandle)
{
int index;
BOOL found = FALSE;
rdpSvcPlugin* plugin;
ArrayList_Lock(g_AddinList);
index = 0;
plugin = (rdpSvcPlugin*) ArrayList_GetItem(g_AddinList, index++);
while (plugin)
{
if (plugin->open_handle == open_handle)
{
found = TRUE;
break;
}
plugin = (rdpSvcPlugin*) ArrayList_GetItem(g_AddinList, index++);
}
ArrayList_Unlock(g_AddinList);
return (found) ? plugin : NULL;
void* pUserData = NULL;
pUserData = ListDictionary_GetItemValue(g_InitHandles, pInitHandle);
return pUserData;
}
void svc_plugin_add(rdpSvcPlugin* plugin)
void svc_plugin_remove_init_handle_data(void* pInitHandle)
{
if (!g_AddinList)
g_AddinList = ArrayList_New(TRUE);
ArrayList_Add(g_AddinList, (void*) plugin);
ListDictionary_Remove(g_InitHandles, pInitHandle);
}
void svc_plugin_remove(rdpSvcPlugin* plugin)
void svc_plugin_add_open_handle_data(DWORD openHandle, void* pUserData)
{
ArrayList_Remove(g_AddinList, (void*) plugin);
void* pOpenHandle = (void*) (size_t) openHandle;
if (!g_OpenHandles)
g_OpenHandles = ListDictionary_New(TRUE);
ListDictionary_Add(g_OpenHandles, pOpenHandle, pUserData);
}
void* svc_plugin_get_open_handle_data(DWORD openHandle)
{
void* pUserData = NULL;
void* pOpenHandle = (void*) (size_t) openHandle;
pUserData = ListDictionary_GetItemValue(g_OpenHandles, pOpenHandle);
return pUserData;
}
void svc_plugin_remove_open_handle_data(DWORD openHandle)
{
void* pOpenHandle = (void*) (size_t) openHandle;
ListDictionary_Remove(g_OpenHandles, pOpenHandle);
}
static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT32 dataLength,
UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
wStream* s;
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
{
@ -130,22 +108,22 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT3
plugin->data_in = Stream_New(NULL, totalLength);
}
data_in = plugin->data_in;
Stream_EnsureRemainingCapacity(data_in, (int) dataLength);
Stream_Write(data_in, pData, dataLength);
s = plugin->data_in;
Stream_EnsureRemainingCapacity(s, (int) dataLength);
Stream_Write(s, pData, dataLength);
if (dataFlags & CHANNEL_FLAG_LAST)
{
if (Stream_Capacity(data_in) != Stream_GetPosition(data_in))
if (Stream_Capacity(s) != Stream_GetPosition(s))
{
fprintf(stderr, "svc_plugin_process_received: read error\n");
}
plugin->data_in = NULL;
Stream_SealLength(data_in);
Stream_SetPosition(data_in, 0);
Stream_SealLength(s);
Stream_SetPosition(s, 0);
MessageQueue_Post(plugin->MsgPipe->In, NULL, 0, (void*) data_in, NULL);
MessageQueue_Post(plugin->MsgPipe->In, NULL, 0, (void*) s, NULL);
}
}
@ -162,7 +140,7 @@ static void svc_plugin_open_event(UINT32 openHandle, UINT32 event, void* pData,
DEBUG_SVC("openHandle %d event %d dataLength %d totalLength %d dataFlags %d",
openHandle, event, dataLength, totalLength, dataFlags);
plugin = (rdpSvcPlugin*) svc_plugin_find_by_open_handle(openHandle);
plugin = (rdpSvcPlugin*) svc_plugin_get_open_handle_data(openHandle);
if (!plugin)
{
@ -233,8 +211,8 @@ static void svc_plugin_process_connected(rdpSvcPlugin* plugin, void* pData, UINT
{
UINT32 status;
status = plugin->channel_entry_points.pVirtualChannelOpen(plugin->init_handle,
&plugin->open_handle, plugin->channel_def.name, svc_plugin_open_event);
status = plugin->channel_entry_points.pVirtualChannelOpen(plugin->InitHandle,
&(plugin->OpenHandle), plugin->channel_def.name, svc_plugin_open_event);
if (status != CHANNEL_RC_OK)
{
@ -242,6 +220,8 @@ static void svc_plugin_process_connected(rdpSvcPlugin* plugin, void* pData, UINT
return;
}
svc_plugin_add_open_handle_data(plugin->OpenHandle, plugin);
plugin->MsgPipe = MessagePipe_New();
plugin->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) svc_plugin_thread_func, (void*) plugin, 0, NULL);
@ -255,9 +235,7 @@ static void svc_plugin_process_terminated(rdpSvcPlugin* plugin)
MessagePipe_Free(plugin->MsgPipe);
CloseHandle(plugin->thread);
plugin->channel_entry_points.pVirtualChannelClose(plugin->open_handle);
svc_plugin_remove(plugin);
plugin->channel_entry_points.pVirtualChannelClose(plugin->OpenHandle);
if (plugin->data_in)
{
@ -266,6 +244,9 @@ static void svc_plugin_process_terminated(rdpSvcPlugin* plugin)
}
IFCALL(plugin->terminate_callback, plugin);
svc_plugin_remove_open_handle_data(plugin->OpenHandle);
svc_plugin_remove_init_handle_data(plugin->InitHandle);
}
static void svc_plugin_init_event(void* pInitHandle, UINT32 event, void* pData, UINT32 dataLength)
@ -274,7 +255,7 @@ static void svc_plugin_init_event(void* pInitHandle, UINT32 event, void* pData,
DEBUG_SVC("event %d", event);
plugin = (rdpSvcPlugin*) svc_plugin_find_by_init_handle(pInitHandle);
plugin = (rdpSvcPlugin*) svc_plugin_get_init_handle_data(pInitHandle);
if (!plugin)
{
@ -304,12 +285,15 @@ void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints)
* VirtualChannelInit at a time. So this should be safe.
*/
CopyMemory(&plugin->channel_entry_points, pEntryPoints, pEntryPoints->cbSize);
CopyMemory(&(plugin->channel_entry_points), pEntryPoints, pEntryPoints->cbSize);
svc_plugin_add(plugin);
plugin->channel_entry_points.pVirtualChannelInit(&(plugin->InitHandle),
&(plugin->channel_def), 1, VIRTUAL_CHANNEL_VERSION_WIN2000, svc_plugin_init_event);
plugin->channel_entry_points.pVirtualChannelInit(&plugin->init_handle,
&plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, svc_plugin_init_event);
plugin->channel_entry_points.pInterface = *(plugin->channel_entry_points.ppInterface);
plugin->channel_entry_points.ppInterface = &(plugin->channel_entry_points.pInterface);
svc_plugin_add_init_handle_data(plugin->InitHandle, plugin);
}
int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out)
@ -321,7 +305,7 @@ int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out)
if (!plugin)
status = CHANNEL_RC_BAD_INIT_HANDLE;
else
status = plugin->channel_entry_points.pVirtualChannelWrite(plugin->open_handle,
status = plugin->channel_entry_points.pVirtualChannelWrite(plugin->OpenHandle,
Stream_Buffer(data_out), Stream_GetPosition(data_out), data_out);
if (status != CHANNEL_RC_OK)
@ -340,7 +324,7 @@ int svc_plugin_send_event(rdpSvcPlugin* plugin, wMessage* event)
DEBUG_SVC("event class: %d type: %d",
GetMessageClass(event->id), GetMessageType(event->id));
status = plugin->channel_entry_points.pVirtualChannelEventPush(plugin->open_handle, event);
status = plugin->channel_entry_points.pVirtualChannelEventPush(plugin->OpenHandle, event);
if (status != CHANNEL_RC_OK)
fprintf(stderr, "svc_plugin_send_event: VirtualChannelEventPush failed %d\n", status);