FreeRDP
pf_input.c
1 
24 #include <winpr/assert.h>
25 
26 #include "pf_input.h"
27 #include <freerdp/server/proxy/proxy_config.h>
28 #include <freerdp/server/proxy/proxy_context.h>
29 
30 #include "proxy_modules.h"
31 
32 static BOOL pf_server_check_and_sync_input_state(pClientContext* pc)
33 {
34  WINPR_ASSERT(pc);
35 
36  if (!freerdp_is_active_state(&pc->context))
37  return FALSE;
38  if (pc->input_state_sync_pending)
39  {
40  BOOL rc = freerdp_input_send_synchronize_event(pc->context.input, pc->input_state);
41  if (rc)
42  pc->input_state_sync_pending = FALSE;
43  }
44  return TRUE;
45 }
46 
47 static BOOL pf_server_synchronize_event(rdpInput* input, UINT32 flags)
48 {
49  pServerContext* ps = NULL;
50  pClientContext* pc = NULL;
51 
52  WINPR_ASSERT(input);
53  ps = (pServerContext*)input->context;
54  WINPR_ASSERT(ps);
55  WINPR_ASSERT(ps->pdata);
56 
57  pc = ps->pdata->pc;
58  WINPR_ASSERT(pc);
59 
60  pc->input_state = flags;
61  pc->input_state_sync_pending = TRUE;
62 
63  return pf_server_check_and_sync_input_state(pc);
64 }
65 
66 static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
67 {
68  const proxyConfig* config = NULL;
69  proxyKeyboardEventInfo event = { 0 };
70  pServerContext* ps = NULL;
71  pClientContext* pc = NULL;
72 
73  WINPR_ASSERT(input);
74  ps = (pServerContext*)input->context;
75  WINPR_ASSERT(ps);
76  WINPR_ASSERT(ps->pdata);
77 
78  pc = ps->pdata->pc;
79  WINPR_ASSERT(pc);
80 
81  config = ps->pdata->config;
82  WINPR_ASSERT(config);
83 
84  if (!pf_server_check_and_sync_input_state(pc))
85  return TRUE;
86 
87  if (!config->Keyboard)
88  return TRUE;
89 
90  event.flags = flags;
91  event.rdp_scan_code = code;
92 
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);
95 
96  return TRUE;
97 }
98 
99 static BOOL pf_server_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
100 {
101  const proxyConfig* config = NULL;
102  proxyUnicodeEventInfo event = { 0 };
103  pServerContext* ps = NULL;
104  pClientContext* pc = NULL;
105 
106  WINPR_ASSERT(input);
107  ps = (pServerContext*)input->context;
108  WINPR_ASSERT(ps);
109  WINPR_ASSERT(ps->pdata);
110 
111  pc = ps->pdata->pc;
112  WINPR_ASSERT(pc);
113 
114  config = ps->pdata->config;
115  WINPR_ASSERT(config);
116 
117  if (!pf_server_check_and_sync_input_state(pc))
118  return TRUE;
119 
120  if (!config->Keyboard)
121  return TRUE;
122 
123  event.flags = flags;
124  event.code = code;
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);
127  return TRUE;
128 }
129 
130 static BOOL pf_server_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
131 {
132  proxyMouseEventInfo event = { 0 };
133  const proxyConfig* config = NULL;
134  pServerContext* ps = NULL;
135  pClientContext* pc = NULL;
136 
137  WINPR_ASSERT(input);
138  ps = (pServerContext*)input->context;
139  WINPR_ASSERT(ps);
140  WINPR_ASSERT(ps->pdata);
141 
142  pc = ps->pdata->pc;
143  WINPR_ASSERT(pc);
144 
145  config = ps->pdata->config;
146  WINPR_ASSERT(config);
147 
148  if (!pf_server_check_and_sync_input_state(pc))
149  return TRUE;
150 
151  if (!config->Mouse)
152  return TRUE;
153 
154  event.flags = flags;
155  event.x = x;
156  event.y = y;
157 
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);
160 
161  return TRUE;
162 }
163 
164 static BOOL pf_server_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
165 {
166  const proxyConfig* config = NULL;
167  proxyMouseExEventInfo event = { 0 };
168  pServerContext* ps = NULL;
169  pClientContext* pc = NULL;
170 
171  WINPR_ASSERT(input);
172  ps = (pServerContext*)input->context;
173  WINPR_ASSERT(ps);
174  WINPR_ASSERT(ps->pdata);
175 
176  pc = ps->pdata->pc;
177  WINPR_ASSERT(pc);
178 
179  config = ps->pdata->config;
180  WINPR_ASSERT(config);
181 
182  if (!pf_server_check_and_sync_input_state(pc))
183  return TRUE;
184 
185  if (!config->Mouse)
186  return TRUE;
187 
188  event.flags = flags;
189  event.x = x;
190  event.y = y;
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);
193  return TRUE;
194 }
195 
196 void pf_server_register_input_callbacks(rdpInput* input)
197 {
198  WINPR_ASSERT(input);
199 
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;
205 }