2011-07-19 10:07:15 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-19 10:07:15 +04:00
|
|
|
* Dynamic Virtual Channel Manager
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-10-09 07:42:01 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-10-04 01:53:03 +04:00
|
|
|
#include <winpr/synch.h>
|
2013-05-14 00:07:42 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-10-04 01:53:03 +04:00
|
|
|
|
2012-11-18 07:03:04 +04:00
|
|
|
#include <freerdp/addin.h>
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
#include "drdynvc_types.h"
|
|
|
|
#include "dvcman.h"
|
|
|
|
|
2012-02-10 04:48:52 +04:00
|
|
|
static int dvcman_get_configuration(IWTSListener* pListener, void** ppPropertyBag)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
*ppPropertyBag = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr,
|
2012-10-09 11:26:39 +04:00
|
|
|
const char* pszChannelName, UINT32 ulFlags,
|
2012-02-10 04:48:52 +04:00
|
|
|
IWTSListenerCallback* pListenerCallback, IWTSListener** ppListener)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-11-22 05:21:08 +04:00
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2011-07-19 10:07:15 +04:00
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
|
|
|
|
if (dvcman->num_listeners < MAX_PLUGINS)
|
|
|
|
{
|
|
|
|
DEBUG_DVC("%d.%s.", dvcman->num_listeners, pszChannelName);
|
2012-11-22 05:21:08 +04:00
|
|
|
|
|
|
|
listener = (DVCMAN_LISTENER*) malloc(sizeof(DVCMAN_LISTENER));
|
|
|
|
ZeroMemory(listener, sizeof(DVCMAN_LISTENER));
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
listener->iface.GetConfiguration = dvcman_get_configuration;
|
2013-05-14 00:07:42 +04:00
|
|
|
listener->iface.pInterface = NULL;
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
listener->dvcman = dvcman;
|
2012-10-09 07:42:01 +04:00
|
|
|
listener->channel_name = _strdup(pszChannelName);
|
2011-07-19 10:07:15 +04:00
|
|
|
listener->flags = ulFlags;
|
|
|
|
listener->listener_callback = pListenerCallback;
|
|
|
|
|
|
|
|
if (ppListener)
|
2013-05-14 00:07:42 +04:00
|
|
|
*ppListener = (IWTSListener*) listener;
|
2012-10-04 01:53:03 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
dvcman->listeners[dvcman->num_listeners++] = (IWTSListener*) listener;
|
2012-10-04 01:53:03 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("Maximum DVC listener number reached.");
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
static int dvcman_push_event(IWTSVirtualChannelManager* pChannelMgr, wMessage* pEvent)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-04 01:53:03 +04:00
|
|
|
int status;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
status = drdynvc_push_event(dvcman->drdynvc, pEvent);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
if (status == 0)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2013-03-29 04:23:16 +04:00
|
|
|
DEBUG_DVC("event_type %d pushed.", GetMessageType(pEvent->id));
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("event_type %d push failed.", GetMessageType(pEvent->id));
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2012-02-10 04:48:52 +04:00
|
|
|
static int dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name, IWTSPlugin* pPlugin)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
if (dvcman->num_plugins < MAX_PLUGINS)
|
|
|
|
{
|
|
|
|
DEBUG_DVC("num_plugins %d", dvcman->num_plugins);
|
|
|
|
dvcman->plugin_names[dvcman->num_plugins] = name;
|
|
|
|
dvcman->plugins[dvcman->num_plugins++] = pPlugin;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("Maximum DVC plugin number reached.");
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-10 04:48:52 +04:00
|
|
|
IWTSPlugin* dvcman_get_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int i;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_plugins; i++)
|
|
|
|
{
|
|
|
|
if (dvcman->plugin_names[i] == name ||
|
|
|
|
strcmp(dvcman->plugin_names[i], name) == 0)
|
|
|
|
{
|
|
|
|
return dvcman->plugins[i];
|
|
|
|
}
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
ADDIN_ARGV* dvcman_get_plugin_data(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
return ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->args;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 22:35:03 +04:00
|
|
|
void* dvcman_get_rdp_settings(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
return (void*) ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->settings;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dvcman_get_channel_id(IWTSVirtualChannel * channel)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
return ((DVCMAN_CHANNEL*) channel)->channel_id;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
IWTSVirtualChannel* dvcman_find_channel_by_id(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2013-05-14 00:07:42 +04:00
|
|
|
int index;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
DVCMAN_CHANNEL* channel;
|
2012-04-25 22:26:35 +04:00
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
ArrayList_Lock(dvcman->channels);
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
channel = (DVCMAN_CHANNEL*) ArrayList_GetItem(dvcman->channels, index++);
|
|
|
|
|
|
|
|
while (channel)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2013-05-14 00:07:42 +04:00
|
|
|
if (channel->channel_id == ChannelId)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2013-05-14 00:07:42 +04:00
|
|
|
found = TRUE;
|
|
|
|
break;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2013-05-14 00:07:42 +04:00
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) ArrayList_GetItem(dvcman->channels, index++);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
ArrayList_Unlock(dvcman->channels);
|
|
|
|
|
|
|
|
return (found) ? ((IWTSVirtualChannel*) channel) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* dvcman_get_channel_interface_by_name(IWTSVirtualChannelManager* pChannelMgr, const char* ChannelName)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
void* pInterface = NULL;
|
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_listeners; i++)
|
|
|
|
{
|
|
|
|
listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
|
|
|
|
|
|
|
|
if (strcmp(listener->channel_name, ChannelName) == 0)
|
|
|
|
{
|
|
|
|
pInterface = listener->iface.pInterface;
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (found) ? pInterface : NULL;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
IWTSVirtualChannelManager* dvcman_new(drdynvcPlugin* plugin)
|
|
|
|
{
|
|
|
|
DVCMAN* dvcman;
|
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
dvcman = (DVCMAN*) calloc(1, sizeof(DVCMAN));
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
dvcman->iface.CreateListener = dvcman_create_listener;
|
|
|
|
dvcman->iface.PushEvent = dvcman_push_event;
|
2012-04-25 22:26:35 +04:00
|
|
|
dvcman->iface.FindChannelById = dvcman_find_channel_by_id;
|
|
|
|
dvcman->iface.GetChannelId = dvcman_get_channel_id;
|
2011-07-19 10:07:15 +04:00
|
|
|
dvcman->drdynvc = plugin;
|
2013-05-14 00:07:42 +04:00
|
|
|
dvcman->channels = ArrayList_New(TRUE);
|
2014-06-12 20:03:08 +04:00
|
|
|
dvcman->pool = StreamPool_New(TRUE, 10);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2012-02-10 04:48:52 +04:00
|
|
|
return (IWTSVirtualChannelManager*) dvcman;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 22:35:03 +04:00
|
|
|
int dvcman_load_addin(IWTSVirtualChannelManager* pChannelMgr, ADDIN_ARGV* args, rdpSettings* settings)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
DVCMAN_ENTRY_POINTS entryPoints;
|
|
|
|
PDVC_PLUGIN_ENTRY pDVCPluginEntry = NULL;
|
|
|
|
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR( "Loading Dynamic Virtual Channel %s\n", args->argv[0]);
|
2012-11-18 09:08:03 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
pDVCPluginEntry = (PDVC_PLUGIN_ENTRY) freerdp_load_channel_addin_entry(args->argv[0],
|
|
|
|
NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (pDVCPluginEntry)
|
2012-11-20 07:31:15 +04:00
|
|
|
{
|
|
|
|
entryPoints.iface.RegisterPlugin = dvcman_register_plugin;
|
|
|
|
entryPoints.iface.GetPlugin = dvcman_get_plugin;
|
|
|
|
entryPoints.iface.GetPluginData = dvcman_get_plugin_data;
|
2014-07-03 22:35:03 +04:00
|
|
|
entryPoints.iface.GetRdpSettings = dvcman_get_rdp_settings;
|
2012-11-20 07:31:15 +04:00
|
|
|
entryPoints.dvcman = (DVCMAN*) pChannelMgr;
|
|
|
|
entryPoints.args = args;
|
2014-07-03 22:35:03 +04:00
|
|
|
entryPoints.settings = settings;
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2012-11-20 07:31:15 +04:00
|
|
|
pDVCPluginEntry((IDRDYNVC_ENTRY_POINTS*) &entryPoints);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
static void dvcman_channel_free(DVCMAN_CHANNEL* channel)
|
|
|
|
{
|
|
|
|
if (channel->channel_callback)
|
|
|
|
channel->channel_callback->OnClose(channel->channel_callback);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
DeleteCriticalSection(&(channel->lock));
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(channel);
|
2011-08-04 18:02:46 +04:00
|
|
|
}
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
void dvcman_free(IWTSVirtualChannelManager* pChannelMgr)
|
|
|
|
{
|
|
|
|
int i;
|
2013-05-14 00:07:42 +04:00
|
|
|
int count;
|
2011-07-19 10:07:15 +04:00
|
|
|
IWTSPlugin* pPlugin;
|
|
|
|
DVCMAN_LISTENER* listener;
|
2011-08-04 18:02:46 +04:00
|
|
|
DVCMAN_CHANNEL* channel;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
ArrayList_Lock(dvcman->channels);
|
|
|
|
|
|
|
|
count = ArrayList_Count(dvcman->channels);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
channel = (DVCMAN_CHANNEL*) ArrayList_GetItem(dvcman->channels, i);
|
2011-08-04 18:02:46 +04:00
|
|
|
dvcman_channel_free(channel);
|
2013-05-14 00:07:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList_Unlock(dvcman->channels);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
ArrayList_Free(dvcman->channels);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
for (i = 0; i < dvcman->num_listeners; i++)
|
|
|
|
{
|
2012-02-10 04:48:52 +04:00
|
|
|
listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
|
2012-10-09 07:21:26 +04:00
|
|
|
free(listener->channel_name);
|
|
|
|
free(listener);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
for (i = 0; i < dvcman->num_plugins; i++)
|
|
|
|
{
|
|
|
|
pPlugin = dvcman->plugins[i];
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
if (pPlugin->Terminated)
|
|
|
|
pPlugin->Terminated(pPlugin);
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
StreamPool_Free(dvcman->pool);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(dvcman);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int dvcman_init(IWTSVirtualChannelManager* pChannelMgr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
IWTSPlugin* pPlugin;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
for (i = 0; i < dvcman->num_plugins; i++)
|
|
|
|
{
|
|
|
|
pPlugin = dvcman->plugins[i];
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
if (pPlugin->Initialize)
|
|
|
|
pPlugin->Initialize(pPlugin, pChannelMgr);
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static int dvcman_write_channel(IWTSVirtualChannel* pChannel, UINT32 cbSize, BYTE* pBuffer, void* pReserved)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2012-10-04 01:53:03 +04:00
|
|
|
int status;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
EnterCriticalSection(&(channel->lock));
|
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
status = drdynvc_write_data(channel->dvcman->drdynvc, channel->channel_id, pBuffer, cbSize);
|
2014-06-17 21:34:23 +04:00
|
|
|
|
|
|
|
LeaveCriticalSection(&(channel->lock));
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dvcman_close_channel_iface(IWTSVirtualChannel* pChannel)
|
|
|
|
{
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
|
2011-07-19 10:07:15 +04:00
|
|
|
DVCMAN* dvcman = channel->dvcman;
|
|
|
|
|
|
|
|
DEBUG_DVC("id=%d", channel->channel_id);
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
ArrayList_Remove(dvcman->channels, channel);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-08-04 18:02:46 +04:00
|
|
|
dvcman_channel_free(channel);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
int dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId, const char* ChannelName)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
int i;
|
2012-02-10 04:48:52 +04:00
|
|
|
int bAccept;
|
2011-07-19 10:07:15 +04:00
|
|
|
DVCMAN_LISTENER* listener;
|
|
|
|
DVCMAN_CHANNEL* channel;
|
2013-05-14 01:39:53 +04:00
|
|
|
DrdynvcClientContext* context;
|
2011-07-19 10:07:15 +04:00
|
|
|
IWTSVirtualChannelCallback* pCallback;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2014-06-17 21:34:23 +04:00
|
|
|
channel = (DVCMAN_CHANNEL*) calloc(1, sizeof(DVCMAN_CHANNEL));
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
return -1;
|
2013-05-20 23:23:54 +04:00
|
|
|
|
|
|
|
channel->dvcman = dvcman;
|
|
|
|
channel->channel_id = ChannelId;
|
|
|
|
channel->channel_name = _strdup(ChannelName);
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
for (i = 0; i < dvcman->num_listeners; i++)
|
|
|
|
{
|
2012-11-20 07:31:15 +04:00
|
|
|
listener = (DVCMAN_LISTENER*) dvcman->listeners[i];
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
if (strcmp(listener->channel_name, ChannelName) == 0)
|
|
|
|
{
|
|
|
|
channel->iface.Write = dvcman_write_channel;
|
|
|
|
channel->iface.Close = dvcman_close_channel_iface;
|
2014-06-17 21:34:23 +04:00
|
|
|
|
|
|
|
InitializeCriticalSection(&(channel->lock));
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
bAccept = 1;
|
|
|
|
pCallback = NULL;
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
if (listener->listener_callback->OnNewChannelConnection(listener->listener_callback,
|
2012-02-10 04:48:52 +04:00
|
|
|
(IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback) == 0 && bAccept == 1)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2011-07-27 03:14:11 +04:00
|
|
|
DEBUG_DVC("listener %s created new channel %d",
|
|
|
|
listener->channel_name, channel->channel_id);
|
2013-05-14 00:07:42 +04:00
|
|
|
|
2013-05-20 23:23:54 +04:00
|
|
|
channel->status = 0;
|
2011-07-19 10:07:15 +04:00
|
|
|
channel->channel_callback = pCallback;
|
2013-05-20 23:23:54 +04:00
|
|
|
channel->pInterface = listener->iface.pInterface;
|
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
ArrayList_Add(dvcman->channels, channel);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
context = dvcman->drdynvc->context;
|
|
|
|
IFCALL(context->OnChannelConnected, context, ChannelName, listener->iface.pInterface);
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("channel rejected by plugin");
|
2013-05-20 23:23:54 +04:00
|
|
|
|
2013-06-12 00:49:27 +04:00
|
|
|
free(channel);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-06-12 00:49:27 +04:00
|
|
|
free(channel);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:49:00 +04:00
|
|
|
int dvcman_open_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId)
|
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
IWTSVirtualChannelCallback* pCallback;
|
|
|
|
|
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
|
|
|
|
|
|
|
if (!channel)
|
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("ChannelId %d not found!", ChannelId);
|
2014-06-03 17:49:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->status == 0)
|
|
|
|
{
|
|
|
|
pCallback = channel->channel_callback;
|
2014-06-27 23:46:27 +04:00
|
|
|
if (pCallback->OnOpen)
|
|
|
|
pCallback->OnOpen(pCallback);
|
2014-06-03 17:49:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
int dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
IWTSVirtualChannel* ichannel;
|
2013-05-20 23:23:54 +04:00
|
|
|
DrdynvcClientContext* context;
|
|
|
|
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (!channel)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("ChannelId %d not found!", ChannelId);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
if (channel->dvc_data)
|
|
|
|
{
|
2014-06-12 20:03:08 +04:00
|
|
|
Stream_Release(channel->dvc_data);
|
2011-07-19 10:07:15 +04:00
|
|
|
channel->dvc_data = NULL;
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-05-20 23:23:54 +04:00
|
|
|
if (channel->status == 0)
|
|
|
|
{
|
|
|
|
context = dvcman->drdynvc->context;
|
|
|
|
|
|
|
|
IFCALL(context->OnChannelDisconnected, context, channel->channel_name, channel->pInterface);
|
|
|
|
|
2014-02-11 13:28:12 +04:00
|
|
|
free(channel->channel_name);
|
|
|
|
|
2013-05-20 23:23:54 +04:00
|
|
|
DEBUG_DVC("dvcman_close_channel: channel %d closed", ChannelId);
|
|
|
|
ichannel = (IWTSVirtualChannel*) channel;
|
|
|
|
ichannel->Close(ichannel);
|
|
|
|
}
|
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
int dvcman_receive_channel_data_first(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId, UINT32 length)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
|
|
|
DVCMAN_CHANNEL* channel;
|
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (!channel)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("ChannelId %d not found!", ChannelId);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2011-07-19 10:07:15 +04:00
|
|
|
if (channel->dvc_data)
|
2014-06-12 20:03:08 +04:00
|
|
|
Stream_Release(channel->dvc_data);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
channel->dvc_data = StreamPool_Take(channel->dvcman->pool, length);
|
2014-08-28 19:16:32 +04:00
|
|
|
channel->dvc_data_length = length;
|
2011-07-19 10:07:15 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
int dvcman_receive_channel_data(IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId, wStream* data)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-06-20 21:52:13 +04:00
|
|
|
int status = 0;
|
2012-02-10 04:48:52 +04:00
|
|
|
DVCMAN_CHANNEL* channel;
|
2014-06-12 20:03:08 +04:00
|
|
|
UINT32 dataSize = Stream_GetRemainingLength(data);
|
2011-07-19 10:07:15 +04:00
|
|
|
|
2012-10-04 01:53:03 +04:00
|
|
|
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2013-05-14 00:07:42 +04:00
|
|
|
if (!channel)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("ChannelId %d not found!", ChannelId);
|
2011-07-19 10:07:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel->dvc_data)
|
|
|
|
{
|
|
|
|
/* Fragmented data */
|
2014-06-12 20:03:08 +04:00
|
|
|
if (Stream_GetPosition(channel->dvc_data) + dataSize > (UINT32) Stream_Capacity(channel->dvc_data))
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-08-11 11:12:01 +04:00
|
|
|
CLOG_ERR("data exceeding declared length!");
|
2014-06-12 20:03:08 +04:00
|
|
|
Stream_Release(channel->dvc_data);
|
2011-07-19 10:07:15 +04:00
|
|
|
channel->dvc_data = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2014-06-12 20:03:08 +04:00
|
|
|
Stream_Write(channel->dvc_data, Stream_Pointer(data), dataSize);
|
2012-02-10 04:48:52 +04:00
|
|
|
|
2014-08-28 19:16:32 +04:00
|
|
|
if (((size_t) Stream_GetPosition(channel->dvc_data)) >= channel->dvc_data_length)
|
2011-07-19 10:07:15 +04:00
|
|
|
{
|
2014-06-12 20:03:08 +04:00
|
|
|
Stream_SealLength(channel->dvc_data);
|
|
|
|
Stream_SetPosition(channel->dvc_data, 0);
|
2014-06-20 21:52:13 +04:00
|
|
|
status = channel->channel_callback->OnDataReceived(channel->channel_callback, channel->dvc_data);
|
2014-06-12 20:03:08 +04:00
|
|
|
Stream_Release(channel->dvc_data);
|
2011-07-19 10:07:15 +04:00
|
|
|
channel->dvc_data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 21:52:13 +04:00
|
|
|
status = channel->channel_callback->OnDataReceived(channel->channel_callback, data);
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 21:52:13 +04:00
|
|
|
return status;
|
2011-07-19 10:07:15 +04:00
|
|
|
}
|
2014-05-23 15:04:51 +04:00
|
|
|
|