[proxy] add mouse ex and unicode event filters

This commit is contained in:
Armin Novak 2022-11-06 07:19:53 +01:00 committed by David Fort
parent f40522e34f
commit 6a0df205b0
6 changed files with 135 additions and 6 deletions

View File

@ -91,8 +91,9 @@ struct proxy_plugin
proxyFilterFn ServerFetchTargetAddr; /* 133 */
proxyFilterFn ServerPeerLogon; /* 134 */
proxyFilterFn ChannelCreate; /* 135 passthrough drdynvc channel create data */
UINT64 reserved5[160 - 136]; /* 136-159 */
proxyFilterFn UnicodeEvent; /* 136 */
proxyFilterFn MouseExEvent; /* 137 */
UINT64 reserved5[160 - 138]; /* 138-159 */
/* Runtime data fields */
proxyPluginsManager* mgr; /* 160 */ /** Set during plugin registration */
@ -140,6 +141,12 @@ typedef struct proxy_keyboard_event_info
UINT16 rdp_scan_code;
} proxyKeyboardEventInfo;
typedef struct proxy_unicode_event_info
{
UINT16 flags;
UINT16 code;
} proxyUnicodeEventInfo;
typedef struct proxy_mouse_event_info
{
UINT16 flags;
@ -147,6 +154,13 @@ typedef struct proxy_mouse_event_info
UINT16 y;
} proxyMouseEventInfo;
typedef struct proxy_mouse_ex_event_info
{
UINT16 flags;
UINT16 x;
UINT16 y;
} proxyMouseExEventInfo;
typedef struct
{
/* channel metadata */

View File

@ -212,6 +212,31 @@ static BOOL demo_filter_keyboard_event(proxyPlugin* plugin, proxyData* pdata, vo
return TRUE;
}
static BOOL demo_filter_unicode_event(proxyPlugin* plugin, proxyData* pdata, void* param)
{
proxyPluginsManager* mgr;
auto event_data = static_cast<const proxyUnicodeEventInfo*>(param);
WINPR_ASSERT(plugin);
WINPR_ASSERT(pdata);
WINPR_ASSERT(event_data);
mgr = plugin->mgr;
WINPR_ASSERT(mgr);
if (event_data == nullptr)
return FALSE;
if (event_data->code == 'b')
{
/* user typed 'B', that means bye :) */
std::cout << "C++ demo plugin: aborting connection" << std::endl;
mgr->AbortConnect(mgr, pdata);
}
return TRUE;
}
static BOOL demo_mouse_event(proxyPlugin* plugin, proxyData* pdata, void* param)
{
auto event_data = static_cast<const proxyMouseEventInfo*>(param);
@ -224,6 +249,18 @@ static BOOL demo_mouse_event(proxyPlugin* plugin, proxyData* pdata, void* param)
return TRUE;
}
static BOOL demo_mouse_ex_event(proxyPlugin* plugin, proxyData* pdata, void* param)
{
auto event_data = static_cast<const proxyMouseExEventInfo*>(param);
WINPR_ASSERT(plugin);
WINPR_ASSERT(pdata);
WINPR_ASSERT(event_data);
WLog_INFO(TAG, "%s", __FUNCTION__);
return TRUE;
}
static BOOL demo_client_channel_data(proxyPlugin* plugin, proxyData* pdata, void* param)
{
const proxyChannelDataEventInfo* channel = static_cast<const proxyChannelDataEventInfo*>(param);
@ -319,7 +356,9 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda
plugin.ServerChannelsFree = demo_server_channels_free;
plugin.ServerSessionEnd = demo_server_session_end;
plugin.KeyboardEvent = demo_filter_keyboard_event;
plugin.UnicodeEvent = demo_filter_unicode_event;
plugin.MouseEvent = demo_mouse_event;
plugin.MouseExEvent = demo_mouse_ex_event;
plugin.ClientChannelData = demo_client_channel_data;
plugin.ServerChannelData = demo_server_channel_data;
plugin.DynamicChannelCreate = demo_dynamic_channel_create;

View File

@ -867,6 +867,30 @@ static BOOL config_plugin_keyboard_event(proxyPlugin* plugin, proxyData* pdata,
return rc;
}
static BOOL config_plugin_unicode_event(proxyPlugin* plugin, proxyData* pdata, void* param)
{
BOOL rc;
const struct config_plugin_data* custom;
const proxyConfig* cfg;
const proxyUnicodeEventInfo* event_data = (const proxyUnicodeEventInfo*)(param);
WINPR_ASSERT(plugin);
WINPR_ASSERT(pdata);
WINPR_ASSERT(event_data);
WINPR_UNUSED(event_data);
custom = plugin->custom;
WINPR_ASSERT(custom);
cfg = custom->config;
WINPR_ASSERT(cfg);
rc = cfg->Keyboard;
WLog_DBG(TAG, "%s: %s", __FUNCTION__, rc ? "TRUE" : "FALSE");
return rc;
}
static BOOL config_plugin_mouse_event(proxyPlugin* plugin, proxyData* pdata, void* param)
{
BOOL rc;
@ -890,6 +914,29 @@ static BOOL config_plugin_mouse_event(proxyPlugin* plugin, proxyData* pdata, voi
return rc;
}
static BOOL config_plugin_mouse_ex_event(proxyPlugin* plugin, proxyData* pdata, void* param)
{
BOOL rc;
const struct config_plugin_data* custom;
const proxyConfig* cfg;
const proxyMouseExEventInfo* event_data = (const proxyMouseExEventInfo*)(param);
WINPR_ASSERT(plugin);
WINPR_ASSERT(pdata);
WINPR_ASSERT(event_data);
WINPR_UNUSED(event_data);
custom = plugin->custom;
WINPR_ASSERT(custom);
cfg = custom->config;
WINPR_ASSERT(cfg);
rc = cfg->Mouse;
return rc;
}
static BOOL config_plugin_client_channel_data(proxyPlugin* plugin, proxyData* pdata, void* param)
{
const proxyChannelDataEventInfo* channel = (const proxyChannelDataEventInfo*)(param);
@ -1048,7 +1095,9 @@ BOOL pf_config_plugin(proxyPluginsManager* plugins_manager, void* userdata)
plugin.PluginUnload = config_plugin_unload;
plugin.KeyboardEvent = config_plugin_keyboard_event;
plugin.UnicodeEvent = config_plugin_unicode_event;
plugin.MouseEvent = config_plugin_mouse_event;
plugin.MouseExEvent = config_plugin_mouse_ex_event;
plugin.ClientChannelData = config_plugin_client_channel_data;
plugin.ServerChannelData = config_plugin_server_channel_data;
plugin.ChannelCreate = config_plugin_channel_create;

View File

@ -31,6 +31,8 @@
static BOOL pf_server_check_and_sync_input_state(pClientContext* pc)
{
WINPR_ASSERT(pc);
if (freerdp_get_state(&pc->context) < CONNECTION_STATE_ACTIVE)
return FALSE;
if (pc->input_state_sync_pending)
@ -65,7 +67,7 @@ static BOOL pf_server_synchronize_event(rdpInput* input, UINT32 flags)
static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
{
const proxyConfig* config;
proxyKeyboardEventInfo event;
proxyKeyboardEventInfo event = { 0 };
pServerContext* ps;
pClientContext* pc;
@ -98,6 +100,7 @@ static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
static BOOL pf_server_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
const proxyConfig* config;
proxyUnicodeEventInfo event = { 0 };
pServerContext* ps;
pClientContext* pc;
@ -118,12 +121,16 @@ static BOOL pf_server_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT
if (!config->Keyboard)
return TRUE;
return freerdp_input_send_unicode_keyboard_event(pc->context.input, flags, code);
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;
}
static BOOL pf_server_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
proxyMouseEventInfo event;
proxyMouseEventInfo event = { 0 };
const proxyConfig* config;
pServerContext* ps;
pClientContext* pc;
@ -158,6 +165,7 @@ static BOOL pf_server_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT1
static BOOL pf_server_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
const proxyConfig* config;
proxyMouseExEventInfo event = { 0 };
pServerContext* ps;
pClientContext* pc;
@ -178,7 +186,12 @@ static BOOL pf_server_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16
if (!config->Mouse)
return TRUE;
return freerdp_input_send_extended_mouse_event(pc->context.input, flags, x, y);
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;
}
void pf_server_register_input_callbacks(rdpInput* input)

View File

@ -52,8 +52,12 @@ static const char* pf_modules_get_filter_type_string(PF_FILTER_TYPE result)
{
case FILTER_TYPE_KEYBOARD:
return "FILTER_TYPE_KEYBOARD";
case FILTER_TYPE_UNICODE:
return "FILTER_TYPE_UNICODE";
case FILTER_TYPE_MOUSE:
return "FILTER_TYPE_MOUSE";
case FILTER_TYPE_MOUSE_EX:
return "FILTER_TYPE_MOUSE_EX";
case FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA:
return "FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA";
case FILTER_TYPE_SERVER_PASSTHROUGH_CHANNEL_DATA:
@ -252,10 +256,18 @@ static BOOL pf_modules_ArrayList_ForEachFkt(void* data, size_t index, va_list ap
result = IFCALLRESULT(TRUE, plugin->KeyboardEvent, plugin, pdata, param);
break;
case FILTER_TYPE_UNICODE:
result = IFCALLRESULT(TRUE, plugin->UnicodeEvent, plugin, pdata, param);
break;
case FILTER_TYPE_MOUSE:
result = IFCALLRESULT(TRUE, plugin->MouseEvent, plugin, pdata, param);
break;
case FILTER_TYPE_MOUSE_EX:
result = IFCALLRESULT(TRUE, plugin->MouseExEvent, plugin, pdata, param);
break;
case FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA:
result = IFCALLRESULT(TRUE, plugin->ClientChannelData, plugin, pdata, param);
break;

View File

@ -29,7 +29,9 @@
typedef enum
{
FILTER_TYPE_KEYBOARD, /* proxyKeyboardEventInfo */
FILTER_TYPE_UNICODE, /* proxyUnicodeEventInfo */
FILTER_TYPE_MOUSE, /* proxyMouseEventInfo */
FILTER_TYPE_MOUSE_EX, /* proxyMouseExEventInfo */
FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA, /* proxyChannelDataEventInfo */
FILTER_TYPE_SERVER_PASSTHROUGH_CHANNEL_DATA, /* proxyChannelDataEventInfo */
FILTER_TYPE_CLIENT_PASSTHROUGH_DYN_CHANNEL_CREATE, /* proxyChannelDataEventInfo */