24 #include <freerdp/api.h>
25 #include <freerdp/scancode.h>
26 #include <freerdp/server/proxy/proxy_modules_api.h>
28 #define TAG MODULE_TAG("demo")
30 struct demo_custom_data
32 proxyPluginsManager* mgr;
36 static constexpr
char plugin_name[] =
"demo";
37 static constexpr
char plugin_desc[] =
"this is a test plugin";
39 static BOOL demo_plugin_unload(proxyPlugin* plugin)
43 std::cout <<
"C++ demo plugin: unloading..." << std::endl;
47 delete static_cast<struct demo_custom_data*
>(plugin->custom);
52 static BOOL demo_client_init_connect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
58 WLog_INFO(TAG,
"called");
62 static BOOL demo_client_uninit_connect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
68 WLog_INFO(TAG,
"called");
72 static BOOL demo_client_pre_connect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
78 WLog_INFO(TAG,
"called");
82 static BOOL demo_client_post_connect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
88 WLog_INFO(TAG,
"called");
92 static BOOL demo_client_post_disconnect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
98 WLog_INFO(TAG,
"called");
102 static BOOL demo_client_x509_certificate(proxyPlugin* plugin, proxyData* pdata,
void* custom)
104 WINPR_ASSERT(plugin);
106 WINPR_ASSERT(custom);
108 WLog_INFO(TAG,
"called");
112 static BOOL demo_client_login_failure(proxyPlugin* plugin, proxyData* pdata,
void* custom)
114 WINPR_ASSERT(plugin);
116 WINPR_ASSERT(custom);
118 WLog_INFO(TAG,
"called");
122 static BOOL demo_client_end_paint(proxyPlugin* plugin, proxyData* pdata,
void* custom)
124 WINPR_ASSERT(plugin);
126 WINPR_ASSERT(custom);
128 WLog_INFO(TAG,
"called");
132 static BOOL demo_client_redirect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
134 WINPR_ASSERT(plugin);
136 WINPR_ASSERT(custom);
138 WLog_INFO(TAG,
"called");
142 static BOOL demo_server_post_connect(proxyPlugin* plugin, proxyData* pdata,
void* custom)
144 WINPR_ASSERT(plugin);
146 WINPR_ASSERT(custom);
148 WLog_INFO(TAG,
"called");
152 static BOOL demo_server_peer_activate(proxyPlugin* plugin, proxyData* pdata,
void* custom)
154 WINPR_ASSERT(plugin);
156 WINPR_ASSERT(custom);
158 WLog_INFO(TAG,
"called");
162 static BOOL demo_server_channels_init(proxyPlugin* plugin, proxyData* pdata,
void* custom)
164 WINPR_ASSERT(plugin);
166 WINPR_ASSERT(custom);
168 WLog_INFO(TAG,
"called");
172 static BOOL demo_server_channels_free(proxyPlugin* plugin, proxyData* pdata,
void* custom)
174 WINPR_ASSERT(plugin);
176 WINPR_ASSERT(custom);
178 WLog_INFO(TAG,
"called");
182 static BOOL demo_server_session_end(proxyPlugin* plugin, proxyData* pdata,
void* custom)
184 WINPR_ASSERT(plugin);
186 WINPR_ASSERT(custom);
188 WLog_INFO(TAG,
"called");
192 static BOOL demo_filter_keyboard_event(proxyPlugin* plugin, proxyData* pdata,
void* param)
194 proxyPluginsManager* mgr =
nullptr;
197 WINPR_ASSERT(plugin);
199 WINPR_ASSERT(event_data);
204 if (event_data ==
nullptr)
207 if (event_data->rdp_scan_code == RDP_SCANCODE_KEY_B)
210 std::cout <<
"C++ demo plugin: aborting connection" << std::endl;
211 mgr->AbortConnect(mgr, pdata);
217 static BOOL demo_filter_unicode_event(proxyPlugin* plugin, proxyData* pdata,
void* param)
219 proxyPluginsManager* mgr =
nullptr;
222 WINPR_ASSERT(plugin);
224 WINPR_ASSERT(event_data);
229 if (event_data ==
nullptr)
232 if (event_data->code ==
'b')
235 std::cout <<
"C++ demo plugin: aborting connection" << std::endl;
236 mgr->AbortConnect(mgr, pdata);
242 static BOOL demo_mouse_event(proxyPlugin* plugin, proxyData* pdata,
void* param)
246 WINPR_ASSERT(plugin);
248 WINPR_ASSERT(event_data);
250 WLog_INFO(TAG,
"called %p", event_data);
254 static BOOL demo_mouse_ex_event(proxyPlugin* plugin, proxyData* pdata,
void* param)
258 WINPR_ASSERT(plugin);
260 WINPR_ASSERT(event_data);
262 WLog_INFO(TAG,
"called %p", event_data);
266 static BOOL demo_client_channel_data(proxyPlugin* plugin, proxyData* pdata,
void* param)
270 WINPR_ASSERT(plugin);
272 WINPR_ASSERT(channel);
274 WLog_INFO(TAG,
"%s [0x%04" PRIx16
"] got %" PRIuz, channel->channel_name, channel->channel_id,
279 static BOOL demo_server_channel_data(proxyPlugin* plugin, proxyData* pdata,
void* param)
283 WINPR_ASSERT(plugin);
285 WINPR_ASSERT(channel);
287 WLog_WARN(TAG,
"%s [0x%04" PRIx16
"] got %" PRIuz, channel->channel_name, channel->channel_id,
292 static BOOL demo_dynamic_channel_create(proxyPlugin* plugin, proxyData* pdata,
void* param)
296 WINPR_ASSERT(plugin);
298 WINPR_ASSERT(channel);
300 WLog_WARN(TAG,
"%s [0x%04" PRIx16
"]", channel->channel_name, channel->channel_id);
304 static BOOL demo_server_fetch_target_addr(proxyPlugin* plugin, proxyData* pdata,
void* param)
308 WINPR_ASSERT(plugin);
310 WINPR_ASSERT(event_data);
312 WLog_INFO(TAG,
"called %p", event_data);
316 static BOOL demo_server_peer_logon(proxyPlugin* plugin, proxyData* pdata,
void* param)
319 WINPR_ASSERT(plugin);
322 WINPR_ASSERT(info->identity);
324 WLog_INFO(TAG,
"%d", info->automatic);
328 static BOOL demo_dyn_channel_intercept_list(proxyPlugin* plugin, proxyData* pdata,
void* arg)
332 WINPR_ASSERT(plugin);
336 WLog_INFO(TAG,
"%s: %p", __func__, data);
340 static BOOL demo_static_channel_intercept_list(proxyPlugin* plugin, proxyData* pdata,
void* arg)
344 WINPR_ASSERT(plugin);
348 WLog_INFO(TAG,
"%s: %p", __func__, data);
352 static BOOL demo_dyn_channel_intercept(proxyPlugin* plugin, proxyData* pdata,
void* arg)
356 WINPR_ASSERT(plugin);
360 WLog_INFO(TAG,
"%s: %p", __func__, data);
368 FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager,
void* userdata);
373 BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager,
void* userdata)
375 struct demo_custom_data* custom =
nullptr;
376 proxyPlugin plugin = {};
378 plugin.name = plugin_name;
379 plugin.description = plugin_desc;
380 plugin.PluginUnload = demo_plugin_unload;
381 plugin.ClientInitConnect = demo_client_init_connect;
382 plugin.ClientUninitConnect = demo_client_uninit_connect;
383 plugin.ClientPreConnect = demo_client_pre_connect;
384 plugin.ClientPostConnect = demo_client_post_connect;
385 plugin.ClientPostDisconnect = demo_client_post_disconnect;
386 plugin.ClientX509Certificate = demo_client_x509_certificate;
387 plugin.ClientLoginFailure = demo_client_login_failure;
388 plugin.ClientEndPaint = demo_client_end_paint;
389 plugin.ClientRedirect = demo_client_redirect;
390 plugin.ServerPostConnect = demo_server_post_connect;
391 plugin.ServerPeerActivate = demo_server_peer_activate;
392 plugin.ServerChannelsInit = demo_server_channels_init;
393 plugin.ServerChannelsFree = demo_server_channels_free;
394 plugin.ServerSessionEnd = demo_server_session_end;
395 plugin.KeyboardEvent = demo_filter_keyboard_event;
396 plugin.UnicodeEvent = demo_filter_unicode_event;
397 plugin.MouseEvent = demo_mouse_event;
398 plugin.MouseExEvent = demo_mouse_ex_event;
399 plugin.ClientChannelData = demo_client_channel_data;
400 plugin.ServerChannelData = demo_server_channel_data;
401 plugin.DynamicChannelCreate = demo_dynamic_channel_create;
402 plugin.ServerFetchTargetAddr = demo_server_fetch_target_addr;
403 plugin.ServerPeerLogon = demo_server_peer_logon;
405 plugin.StaticChannelToIntercept = demo_static_channel_intercept_list;
406 plugin.DynChannelToIntercept = demo_dyn_channel_intercept_list;
407 plugin.DynChannelIntercept = demo_dyn_channel_intercept;
409 plugin.userdata = userdata;
411 custom =
new (
struct demo_custom_data);
415 custom->mgr = plugins_manager;
416 custom->somesetting = 42;
418 plugin.custom = custom;
419 plugin.userdata = userdata;
421 return plugins_manager->RegisterPlugin(plugins_manager, &plugin);