24 #include <winpr/assert.h>
27 #include <freerdp/server/proxy/proxy_config.h>
28 #include <freerdp/server/proxy/proxy_context.h>
30 #include "proxy_modules.h"
32 static BOOL pf_server_check_and_sync_input_state(pClientContext* pc)
36 if (!freerdp_is_active_state(&pc->context))
38 if (pc->input_state_sync_pending)
40 BOOL rc = freerdp_input_send_synchronize_event(pc->context.input, pc->input_state);
42 pc->input_state_sync_pending = FALSE;
47 static BOOL pf_server_synchronize_event(rdpInput* input, UINT32 flags)
49 pServerContext* ps = NULL;
50 pClientContext* pc = NULL;
53 ps = (pServerContext*)input->context;
55 WINPR_ASSERT(ps->pdata);
60 pc->input_state = flags;
61 pc->input_state_sync_pending = TRUE;
63 return pf_server_check_and_sync_input_state(pc);
66 static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
68 const proxyConfig* config = NULL;
70 pServerContext* ps = NULL;
71 pClientContext* pc = NULL;
74 ps = (pServerContext*)input->context;
76 WINPR_ASSERT(ps->pdata);
81 config = ps->pdata->config;
84 if (!pf_server_check_and_sync_input_state(pc))
87 if (!config->Keyboard)
91 event.rdp_scan_code = code;
93 if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_KEYBOARD, pc->pdata, &event))
94 return freerdp_input_send_keyboard_event(pc->context.input, flags, code);
99 static BOOL pf_server_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
101 const proxyConfig* config = NULL;
103 pServerContext* ps = NULL;
104 pClientContext* pc = NULL;
107 ps = (pServerContext*)input->context;
109 WINPR_ASSERT(ps->pdata);
114 config = ps->pdata->config;
115 WINPR_ASSERT(config);
117 if (!pf_server_check_and_sync_input_state(pc))
120 if (!config->Keyboard)
125 if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_UNICODE, pc->pdata, &event))
126 return freerdp_input_send_unicode_keyboard_event(pc->context.input, flags, code);
130 static BOOL pf_server_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
133 const proxyConfig* config = NULL;
134 pServerContext* ps = NULL;
135 pClientContext* pc = NULL;
138 ps = (pServerContext*)input->context;
140 WINPR_ASSERT(ps->pdata);
145 config = ps->pdata->config;
146 WINPR_ASSERT(config);
148 if (!pf_server_check_and_sync_input_state(pc))
158 if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_MOUSE, pc->pdata, &event))
159 return freerdp_input_send_mouse_event(pc->context.input, flags, x, y);
164 static BOOL pf_server_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
166 const proxyConfig* config = NULL;
168 pServerContext* ps = NULL;
169 pClientContext* pc = NULL;
172 ps = (pServerContext*)input->context;
174 WINPR_ASSERT(ps->pdata);
179 config = ps->pdata->config;
180 WINPR_ASSERT(config);
182 if (!pf_server_check_and_sync_input_state(pc))
191 if (pf_modules_run_filter(pc->pdata->module, FILTER_TYPE_MOUSE, pc->pdata, &event))
192 return freerdp_input_send_extended_mouse_event(pc->context.input, flags, x, y);
196 void pf_server_register_input_callbacks(rdpInput* input)
200 input->SynchronizeEvent = pf_server_synchronize_event;
201 input->KeyboardEvent = pf_server_keyboard_event;
202 input->UnicodeKeyboardEvent = pf_server_unicode_keyboard_event;
203 input->MouseEvent = pf_server_mouse_event;
204 input->ExtendedMouseEvent = pf_server_extended_mouse_event;