2019-05-17 15:32:54 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* FreeRDP Proxy Server
|
|
|
|
*
|
|
|
|
* Copyright 2019 Mati Shabtay <matishabtay@gmail.com>
|
|
|
|
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
|
|
|
* Copyright 2019 Idan Freiberg <speidy@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <freerdp/gdi/gfx.h>
|
|
|
|
|
|
|
|
#include <freerdp/client/rdpei.h>
|
|
|
|
#include <freerdp/client/tsmf.h>
|
|
|
|
#include <freerdp/client/rail.h>
|
|
|
|
#include <freerdp/client/cliprdr.h>
|
|
|
|
#include <freerdp/client/rdpgfx.h>
|
2019-06-11 17:13:42 +03:00
|
|
|
#include <freerdp/client/disp.h>
|
2019-05-17 15:32:54 +03:00
|
|
|
|
|
|
|
#include "pf_channels.h"
|
|
|
|
#include "pf_client.h"
|
|
|
|
#include "pf_context.h"
|
|
|
|
#include "pf_rdpgfx.h"
|
2019-08-04 17:41:43 +03:00
|
|
|
#include "pf_cliprdr.h"
|
2019-06-11 17:13:42 +03:00
|
|
|
#include "pf_disp.h"
|
2019-08-04 17:41:43 +03:00
|
|
|
#include "pf_log.h"
|
2019-08-19 16:06:42 +03:00
|
|
|
#include "pf_modules.h"
|
2019-08-13 13:53:36 +03:00
|
|
|
#include "pf_rdpsnd.h"
|
2019-05-17 15:32:54 +03:00
|
|
|
|
|
|
|
#define TAG PROXY_TAG("channels")
|
|
|
|
|
2019-08-28 18:25:23 +03:00
|
|
|
static void pf_channels_wait_for_server_dynvc(pServerContext* ps)
|
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "pf_channels_wait_for_server_dynvc(): waiting for server's drdynvc to be ready");
|
|
|
|
WaitForSingleObject(ps->dynvcReady, INFINITE);
|
|
|
|
WLog_DBG(TAG, "pf_channels_wait_for_server_dynvc(): server's drdynvc is ready!");
|
|
|
|
}
|
|
|
|
|
2019-08-01 16:55:50 +03:00
|
|
|
void pf_OnChannelConnectedEventHandler(void* data,
|
2019-05-17 15:32:54 +03:00
|
|
|
ChannelConnectedEventArgs* e)
|
|
|
|
{
|
2019-08-01 16:55:50 +03:00
|
|
|
pClientContext* pc = (pClientContext*) data;
|
2019-05-17 15:32:54 +03:00
|
|
|
pServerContext* ps = pc->pdata->ps;
|
2019-08-01 16:55:50 +03:00
|
|
|
|
|
|
|
WLog_INFO(TAG, "Channel connected: %s", e->name);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
|
|
|
if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
|
|
|
pc->rdpei = (RdpeiClientContext*) e->pInterface;
|
|
|
|
}
|
|
|
|
else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
2019-08-28 18:25:23 +03:00
|
|
|
pf_channels_wait_for_server_dynvc(ps);
|
|
|
|
|
2019-08-01 16:55:50 +03:00
|
|
|
if (!ps->gfx->Open(ps->gfx))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to open GFX server");
|
|
|
|
return;
|
|
|
|
}
|
2019-08-03 16:46:20 +03:00
|
|
|
|
2019-10-22 16:06:05 +03:00
|
|
|
pc->gfx_proxy = (RdpgfxClientContext*) e->pInterface;
|
|
|
|
pf_rdpgfx_pipeline_init(pc->gfx_proxy, ps->gfx, pc->pdata);
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
2019-06-11 17:13:42 +03:00
|
|
|
else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
2019-08-28 18:25:23 +03:00
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
ret = ps->disp->Open(ps->disp);
|
|
|
|
if (ret != CHANNEL_RC_OK)
|
2019-06-11 17:13:42 +03:00
|
|
|
{
|
2019-08-28 18:25:23 +03:00
|
|
|
if (ret == ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
/* client did not connect with disp */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pf_channels_wait_for_server_dynvc(ps);
|
|
|
|
if (ps->disp->Open(ps->disp) != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to open disp channel");
|
|
|
|
return;
|
|
|
|
}
|
2019-06-11 17:13:42 +03:00
|
|
|
}
|
2019-08-03 16:46:20 +03:00
|
|
|
|
2019-08-28 18:25:23 +03:00
|
|
|
pc->disp = (DispClientContext*)e->pInterface;
|
2019-08-03 16:46:20 +03:00
|
|
|
pf_disp_register_callbacks(pc->disp, ps->disp, pc->pdata);
|
2019-06-11 17:13:42 +03:00
|
|
|
}
|
2019-08-04 17:41:43 +03:00
|
|
|
else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
|
|
|
if (ps->cliprdr->Start(ps->cliprdr) != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to open cliprdr channel");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pc->cliprdr = (CliprdrClientContext*) e->pInterface;
|
|
|
|
pf_cliprdr_register_callbacks(pc->cliprdr, ps->cliprdr, pc->pdata);
|
|
|
|
}
|
2019-08-13 13:53:36 +03:00
|
|
|
else if (strcmp(e->name, "rdpsnd") == 0)
|
|
|
|
{
|
|
|
|
/* sound is disabled */
|
|
|
|
if (ps->rdpsnd == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ps->rdpsnd->Initialize(ps->rdpsnd, TRUE) != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to open rdpsnd channel");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
|
|
|
|
2019-08-01 16:55:50 +03:00
|
|
|
void pf_OnChannelDisconnectedEventHandler(void* data,
|
2019-05-17 15:32:54 +03:00
|
|
|
ChannelDisconnectedEventArgs* e)
|
|
|
|
{
|
2019-08-01 16:55:50 +03:00
|
|
|
rdpContext* context = (rdpContext*) data;
|
2019-05-17 15:32:54 +03:00
|
|
|
pClientContext* pc = (pClientContext*) context;
|
2019-08-01 16:55:50 +03:00
|
|
|
pServerContext* ps = pc->pdata->ps;
|
|
|
|
|
|
|
|
WLog_INFO(TAG, "Channel disconnected: %s", e->name);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
|
|
|
if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
|
|
|
pc->rdpei = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
2019-08-01 16:55:50 +03:00
|
|
|
if (!ps->gfx->Close(ps->gfx))
|
|
|
|
WLog_ERR(TAG, "failed to close gfx server");
|
|
|
|
|
2019-10-22 16:06:05 +03:00
|
|
|
gdi_graphics_pipeline_uninit(context->gdi, pc->gfx_decoder);
|
|
|
|
rdpgfx_client_context_free(pc->gfx_decoder);
|
2019-06-11 17:13:42 +03:00
|
|
|
}
|
|
|
|
else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
2019-08-01 16:55:50 +03:00
|
|
|
if (ps->disp->Close(ps->disp) != CHANNEL_RC_OK)
|
|
|
|
WLog_ERR(TAG, "failed to close disp server");
|
|
|
|
|
2019-06-11 17:13:42 +03:00
|
|
|
pc->disp = NULL;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
2019-08-04 17:41:43 +03:00
|
|
|
else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
|
|
|
{
|
|
|
|
if (ps->cliprdr->Stop(ps->cliprdr) != CHANNEL_RC_OK)
|
|
|
|
WLog_ERR(TAG, "failed to stop cliprdr server");
|
|
|
|
|
|
|
|
pc->cliprdr = NULL;
|
|
|
|
}
|
2019-08-13 13:53:36 +03:00
|
|
|
else if (strcmp(e->name, "rdpsnd") == 0)
|
|
|
|
{
|
|
|
|
/* sound is disabled */
|
|
|
|
if (ps->rdpsnd == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ps->rdpsnd->Stop(ps->rdpsnd) != CHANNEL_RC_OK)
|
|
|
|
WLog_ERR(TAG, "failed to close rdpsnd server");
|
|
|
|
}
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
2019-08-01 16:55:50 +03:00
|
|
|
|
|
|
|
BOOL pf_server_channels_init(pServerContext* ps)
|
|
|
|
{
|
2019-08-03 16:46:20 +03:00
|
|
|
rdpContext* context = (rdpContext*) ps;
|
2019-08-19 16:27:58 +03:00
|
|
|
rdpContext* client = (rdpContext*) ps->pdata->pc;
|
2019-08-03 16:46:20 +03:00
|
|
|
proxyConfig* config = ps->pdata->config;
|
|
|
|
|
|
|
|
if (context->settings->SupportGraphicsPipeline && config->GFX)
|
|
|
|
{
|
|
|
|
if (!pf_server_rdpgfx_init(ps))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-08-01 16:55:50 +03:00
|
|
|
|
2019-08-03 16:46:20 +03:00
|
|
|
if (config->DisplayControl)
|
|
|
|
{
|
|
|
|
if (!pf_server_disp_init(ps))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-08-01 16:55:50 +03:00
|
|
|
|
2019-08-04 17:41:43 +03:00
|
|
|
if (config->Clipboard && WTSVirtualChannelManagerIsChannelJoined(ps->vcm, CLIPRDR_SVC_CHANNEL_NAME))
|
|
|
|
{
|
2019-08-19 16:27:58 +03:00
|
|
|
client->settings->RedirectClipboard = TRUE;
|
|
|
|
|
2019-08-04 17:41:43 +03:00
|
|
|
if (!pf_server_cliprdr_init(ps))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-08-13 13:53:36 +03:00
|
|
|
if (config->AudioOutput && WTSVirtualChannelManagerIsChannelJoined(ps->vcm, "rdpsnd"))
|
|
|
|
{
|
|
|
|
if (!pf_server_rdpsnd_init(ps))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-08-19 16:06:42 +03:00
|
|
|
return pf_modules_run_hook(HOOK_TYPE_SERVER_CHANNELS_INIT, context);
|
2019-08-01 16:55:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void pf_server_channels_free(pServerContext* ps)
|
|
|
|
{
|
|
|
|
if (ps->gfx)
|
|
|
|
{
|
|
|
|
rdpgfx_server_context_free(ps->gfx);
|
|
|
|
ps->gfx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps->disp)
|
|
|
|
{
|
|
|
|
disp_server_context_free(ps->disp);
|
|
|
|
ps->disp = NULL;
|
|
|
|
}
|
2019-08-04 17:41:43 +03:00
|
|
|
|
|
|
|
if (ps->cliprdr)
|
|
|
|
{
|
|
|
|
cliprdr_server_context_free(ps->cliprdr);
|
|
|
|
ps->cliprdr = NULL;
|
|
|
|
}
|
2019-08-19 16:06:42 +03:00
|
|
|
|
2019-08-13 13:53:36 +03:00
|
|
|
if (ps->rdpsnd)
|
|
|
|
{
|
|
|
|
rdpsnd_server_context_free(ps->rdpsnd);
|
|
|
|
ps->rdpsnd = NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-19 16:06:42 +03:00
|
|
|
pf_modules_run_hook(HOOK_TYPE_SERVER_CHANNELS_FREE, (rdpContext*) ps);
|
2019-08-01 16:55:50 +03:00
|
|
|
}
|