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>
|
2021-09-01 14:30:09 +03:00
|
|
|
* Copyright 2021 Armin Novak <anovak@thincast.com>
|
|
|
|
* Copyright 2021 Thincast Technologies GmbH
|
2019-05-17 15:32:54 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-08-24 13:50:13 +03:00
|
|
|
#include <winpr/assert.h>
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
#include "pf_input.h"
|
2021-08-24 13:50:13 +03:00
|
|
|
#include <freerdp/server/proxy/proxy_config.h>
|
|
|
|
#include <freerdp/server/proxy/proxy_context.h>
|
|
|
|
|
|
|
|
#include "proxy_modules.h"
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2021-09-10 11:39:07 +03:00
|
|
|
static BOOL pf_server_check_and_sync_input_state(pClientContext* pc)
|
|
|
|
{
|
2022-11-06 09:19:53 +03:00
|
|
|
WINPR_ASSERT(pc);
|
|
|
|
|
2021-09-10 11:39:07 +03:00
|
|
|
if (freerdp_get_state(&pc->context) < CONNECTION_STATE_ACTIVE)
|
|
|
|
return FALSE;
|
|
|
|
if (pc->input_state_sync_pending)
|
|
|
|
{
|
|
|
|
BOOL rc = freerdp_input_send_synchronize_event(pc->context.input, pc->input_state);
|
|
|
|
if (rc)
|
|
|
|
pc->input_state_sync_pending = FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
static BOOL pf_server_synchronize_event(rdpInput* input, UINT32 flags)
|
|
|
|
{
|
2021-08-24 13:50:13 +03:00
|
|
|
pServerContext* ps;
|
|
|
|
pClientContext* pc;
|
|
|
|
|
|
|
|
WINPR_ASSERT(input);
|
|
|
|
ps = (pServerContext*)input->context;
|
|
|
|
WINPR_ASSERT(ps);
|
|
|
|
WINPR_ASSERT(ps->pdata);
|
|
|
|
|
|
|
|
pc = ps->pdata->pc;
|
|
|
|
WINPR_ASSERT(pc);
|
2021-09-10 11:39:07 +03:00
|
|
|
|
|
|
|
pc->input_state = flags;
|
|
|
|
pc->input_state_sync_pending = TRUE;
|
|
|
|
|
|
|
|
pf_server_check_and_sync_input_state(pc);
|
|
|
|
return TRUE;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
|
|
|
|
2022-04-13 10:34:05 +03:00
|
|
|
static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
|
2019-05-17 15:32:54 +03:00
|
|
|
{
|
2021-08-24 13:50:13 +03:00
|
|
|
const proxyConfig* config;
|
2022-11-06 09:19:53 +03:00
|
|
|
proxyKeyboardEventInfo event = { 0 };
|
2021-08-24 13:50:13 +03:00
|
|
|
pServerContext* ps;
|
|
|
|
pClientContext* pc;
|
|
|
|
|
|
|
|
WINPR_ASSERT(input);
|
|
|
|
ps = (pServerContext*)input->context;
|
|
|
|
WINPR_ASSERT(ps);
|
|
|
|
WINPR_ASSERT(ps->pdata);
|
|
|
|
|
|
|
|
pc = ps->pdata->pc;
|
|
|
|
WINPR_ASSERT(pc);
|
|
|
|
|
|
|
|
config = ps->pdata->config;
|
|
|
|
WINPR_ASSERT(config);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2021-09-10 11:39:07 +03:00
|
|
|
if (!pf_server_check_and_sync_input_state(pc))
|
|
|
|
return TRUE;
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
if (!config->Keyboard)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-05-27 12:06:59 +03:00
|
|
|
event.flags = flags;
|
|
|
|
event.rdp_scan_code = code;
|
|
|
|
|
2021-08-24 13:50:13 +03:00
|
|
|
if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_KEYBOARD, pc->pdata, &event))
|
2019-09-09 11:25:09 +03:00
|
|
|
return freerdp_input_send_keyboard_event(pc->context.input, flags, code);
|
2019-08-19 16:06:42 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL pf_server_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
|
|
|
{
|
2021-08-24 13:50:13 +03:00
|
|
|
const proxyConfig* config;
|
2022-11-06 09:19:53 +03:00
|
|
|
proxyUnicodeEventInfo event = { 0 };
|
2021-08-24 13:50:13 +03:00
|
|
|
pServerContext* ps;
|
|
|
|
pClientContext* pc;
|
|
|
|
|
|
|
|
WINPR_ASSERT(input);
|
|
|
|
ps = (pServerContext*)input->context;
|
|
|
|
WINPR_ASSERT(ps);
|
|
|
|
WINPR_ASSERT(ps->pdata);
|
|
|
|
|
|
|
|
pc = ps->pdata->pc;
|
|
|
|
WINPR_ASSERT(pc);
|
|
|
|
|
|
|
|
config = ps->pdata->config;
|
|
|
|
WINPR_ASSERT(config);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2021-09-10 11:39:07 +03:00
|
|
|
if (!pf_server_check_and_sync_input_state(pc))
|
|
|
|
return TRUE;
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
if (!config->Keyboard)
|
|
|
|
return TRUE;
|
|
|
|
|
2022-11-06 09:19:53 +03:00
|
|
|
event.flags = flags;
|
|
|
|
event.code = code;
|
|
|
|
if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_UNICODE, pc->pdata, &event))
|
|
|
|
return freerdp_input_send_unicode_keyboard_event(pc->context.input, flags, code);
|
|
|
|
return TRUE;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL pf_server_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
|
|
|
{
|
2022-11-06 09:19:53 +03:00
|
|
|
proxyMouseEventInfo event = { 0 };
|
2021-08-24 13:50:13 +03:00
|
|
|
const proxyConfig* config;
|
|
|
|
pServerContext* ps;
|
|
|
|
pClientContext* pc;
|
|
|
|
|
|
|
|
WINPR_ASSERT(input);
|
|
|
|
ps = (pServerContext*)input->context;
|
|
|
|
WINPR_ASSERT(ps);
|
|
|
|
WINPR_ASSERT(ps->pdata);
|
|
|
|
|
|
|
|
pc = ps->pdata->pc;
|
|
|
|
WINPR_ASSERT(pc);
|
|
|
|
|
|
|
|
config = ps->pdata->config;
|
|
|
|
WINPR_ASSERT(config);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2021-09-10 11:39:07 +03:00
|
|
|
if (!pf_server_check_and_sync_input_state(pc))
|
|
|
|
return TRUE;
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
if (!config->Mouse)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-05-27 12:06:59 +03:00
|
|
|
event.flags = flags;
|
|
|
|
event.x = x;
|
|
|
|
event.y = y;
|
|
|
|
|
2021-08-24 13:50:13 +03:00
|
|
|
if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_MOUSE, pc->pdata, &event))
|
2019-09-09 11:25:09 +03:00
|
|
|
return freerdp_input_send_mouse_event(pc->context.input, flags, x, y);
|
2019-08-19 16:06:42 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL pf_server_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2019-05-17 15:32:54 +03:00
|
|
|
{
|
2021-08-24 13:50:13 +03:00
|
|
|
const proxyConfig* config;
|
2022-11-06 09:19:53 +03:00
|
|
|
proxyMouseExEventInfo event = { 0 };
|
2021-08-24 13:50:13 +03:00
|
|
|
pServerContext* ps;
|
|
|
|
pClientContext* pc;
|
|
|
|
|
|
|
|
WINPR_ASSERT(input);
|
|
|
|
ps = (pServerContext*)input->context;
|
|
|
|
WINPR_ASSERT(ps);
|
|
|
|
WINPR_ASSERT(ps->pdata);
|
|
|
|
|
|
|
|
pc = ps->pdata->pc;
|
|
|
|
WINPR_ASSERT(pc);
|
|
|
|
|
|
|
|
config = ps->pdata->config;
|
|
|
|
WINPR_ASSERT(config);
|
2019-05-17 15:32:54 +03:00
|
|
|
|
2021-09-10 11:39:07 +03:00
|
|
|
if (!pf_server_check_and_sync_input_state(pc))
|
|
|
|
return TRUE;
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
if (!config->Mouse)
|
|
|
|
return TRUE;
|
|
|
|
|
2022-11-06 09:19:53 +03:00
|
|
|
event.flags = flags;
|
|
|
|
event.x = x;
|
|
|
|
event.y = y;
|
|
|
|
if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_MOUSE, pc->pdata, &event))
|
|
|
|
return freerdp_input_send_extended_mouse_event(pc->context.input, flags, x, y);
|
|
|
|
return TRUE;
|
2019-05-17 15:32:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void pf_server_register_input_callbacks(rdpInput* input)
|
|
|
|
{
|
2021-08-24 13:50:13 +03:00
|
|
|
WINPR_ASSERT(input);
|
|
|
|
|
2019-05-17 15:32:54 +03:00
|
|
|
input->SynchronizeEvent = pf_server_synchronize_event;
|
|
|
|
input->KeyboardEvent = pf_server_keyboard_event;
|
|
|
|
input->UnicodeKeyboardEvent = pf_server_unicode_keyboard_event;
|
|
|
|
input->MouseEvent = pf_server_mouse_event;
|
|
|
|
input->ExtendedMouseEvent = pf_server_extended_mouse_event;
|
|
|
|
}
|