/src/FreeRDP/channels/location/client/location_main.c
Line | Count | Source |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * Location Virtual Channel Extension |
4 | | * |
5 | | * Copyright 2024 Armin Novak <anovak@thincast.com> |
6 | | * Copyright 2024 Thincast Technologies GmbH |
7 | | * |
8 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | | * you may not use this file except in compliance with the License. |
10 | | * You may obtain a copy of the License at |
11 | | * |
12 | | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | | * |
14 | | * Unless required by applicable law or agreed to in writing, software |
15 | | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | | * See the License for the specific language governing permissions and |
18 | | * limitations under the License. |
19 | | */ |
20 | | |
21 | | #include <freerdp/config.h> |
22 | | |
23 | | #include <stdio.h> |
24 | | #include <stdlib.h> |
25 | | #include <float.h> |
26 | | #include <math.h> |
27 | | |
28 | | #include <winpr/crt.h> |
29 | | #include <winpr/assert.h> |
30 | | #include <winpr/cast.h> |
31 | | #include <winpr/stream.h> |
32 | | |
33 | | #include <freerdp/client/channels.h> |
34 | | #include <freerdp/channels/log.h> |
35 | | #include <freerdp/channels/location.h> |
36 | | #include <freerdp/client/location.h> |
37 | | #include <freerdp/utils/encoded_types.h> |
38 | | |
39 | 0 | #define TAG CHANNELS_TAG("location.client") |
40 | | |
41 | | /* implement [MS-RDPEL] |
42 | | * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpel/4397a0af-c821-4b75-9068-476fb579c327 |
43 | | */ |
44 | | typedef struct |
45 | | { |
46 | | GENERIC_DYNVC_PLUGIN baseDynPlugin; |
47 | | LocationClientContext context; |
48 | | } LOCATION_PLUGIN; |
49 | | |
50 | | typedef struct |
51 | | { |
52 | | GENERIC_CHANNEL_CALLBACK baseCb; |
53 | | UINT32 serverVersion; |
54 | | UINT32 clientVersion; |
55 | | UINT32 serverFlags; |
56 | | UINT32 clientFlags; |
57 | | } LOCATION_CALLBACK; |
58 | | |
59 | | static BOOL location_read_header(wLog* log, wStream* s, UINT16* ppduType, UINT32* ppduLength) |
60 | 0 | { |
61 | 0 | WINPR_ASSERT(log); |
62 | 0 | WINPR_ASSERT(s); |
63 | 0 | WINPR_ASSERT(ppduType); |
64 | 0 | WINPR_ASSERT(ppduLength); |
65 | |
|
66 | 0 | if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 6)) |
67 | 0 | return FALSE; |
68 | 0 | Stream_Read_UINT16(s, *ppduType); |
69 | 0 | Stream_Read_UINT32(s, *ppduLength); |
70 | 0 | if (*ppduLength < 6) |
71 | 0 | { |
72 | 0 | WLog_Print(log, WLOG_ERROR, |
73 | 0 | "RDPLOCATION_HEADER::pduLengh=%" PRIu16 " < sizeof(RDPLOCATION_HEADER)[6]", |
74 | 0 | *ppduLength); |
75 | 0 | return FALSE; |
76 | 0 | } |
77 | 0 | return Stream_CheckAndLogRequiredLengthWLog(log, s, *ppduLength - 6ull); |
78 | 0 | } |
79 | | |
80 | | static BOOL location_write_header(wStream* s, UINT16 pduType, UINT32 pduLength) |
81 | 0 | { |
82 | 0 | if (!Stream_EnsureRemainingCapacity(s, 6)) |
83 | 0 | return FALSE; |
84 | 0 | Stream_Write_UINT16(s, pduType); |
85 | 0 | Stream_Write_UINT32(s, pduLength + 6); |
86 | 0 | return Stream_EnsureRemainingCapacity(s, pduLength); |
87 | 0 | } |
88 | | |
89 | | static BOOL location_read_server_ready_pdu(LOCATION_CALLBACK* callback, wStream* s, UINT32 pduSize) |
90 | 0 | { |
91 | 0 | if (pduSize < 6 + 4) |
92 | 0 | return FALSE; // Short message |
93 | | |
94 | 0 | Stream_Read_UINT32(s, callback->serverVersion); |
95 | 0 | if (pduSize >= 6 + 4 + 4) |
96 | 0 | Stream_Read_UINT32(s, callback->serverFlags); |
97 | 0 | return TRUE; |
98 | 0 | } |
99 | | |
100 | | static UINT location_channel_send(IWTSVirtualChannel* channel, wStream* s) |
101 | 0 | { |
102 | 0 | const size_t len = Stream_GetPosition(s); |
103 | 0 | if (len > UINT32_MAX) |
104 | 0 | return ERROR_INTERNAL_ERROR; |
105 | | |
106 | 0 | Stream_SetPosition(s, 2); |
107 | 0 | Stream_Write_UINT32(s, (UINT32)len); |
108 | |
|
109 | 0 | WINPR_ASSERT(channel); |
110 | 0 | WINPR_ASSERT(channel->Write); |
111 | 0 | return channel->Write(channel, (UINT32)len, Stream_Buffer(s), NULL); |
112 | 0 | } |
113 | | |
114 | | static UINT location_send_client_ready_pdu(const LOCATION_CALLBACK* callback) |
115 | 0 | { |
116 | 0 | wStream sbuffer = WINPR_C_ARRAY_INIT; |
117 | 0 | BYTE buffer[32] = WINPR_C_ARRAY_INIT; |
118 | 0 | wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); |
119 | 0 | WINPR_ASSERT(s); |
120 | |
|
121 | 0 | if (!location_write_header(s, PDUTYPE_CLIENT_READY, 8)) |
122 | 0 | return ERROR_OUTOFMEMORY; |
123 | | |
124 | 0 | Stream_Write_UINT32(s, callback->clientVersion); |
125 | 0 | Stream_Write_UINT32(s, callback->clientFlags); |
126 | 0 | return location_channel_send(callback->baseCb.channel, s); |
127 | 0 | } |
128 | | |
129 | | static const char* location_version_str(UINT32 version, char* buffer, size_t size) |
130 | 0 | { |
131 | 0 | const char* str = NULL; |
132 | 0 | switch (version) |
133 | 0 | { |
134 | 0 | case RDPLOCATION_PROTOCOL_VERSION_100: |
135 | 0 | str = "RDPLOCATION_PROTOCOL_VERSION_100"; |
136 | 0 | break; |
137 | 0 | case RDPLOCATION_PROTOCOL_VERSION_200: |
138 | 0 | str = "RDPLOCATION_PROTOCOL_VERSION_200"; |
139 | 0 | break; |
140 | 0 | default: |
141 | 0 | str = "RDPLOCATION_PROTOCOL_VERSION_UNKNOWN"; |
142 | 0 | break; |
143 | 0 | } |
144 | | |
145 | 0 | (void)_snprintf(buffer, size, "%s [0x%08" PRIx32 "]", str, version); |
146 | 0 | return buffer; |
147 | 0 | } |
148 | | |
149 | | /** |
150 | | * Function description |
151 | | * |
152 | | * @return 0 on success, otherwise a Win32 error code |
153 | | */ |
154 | | static UINT location_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) |
155 | 0 | { |
156 | 0 | LOCATION_CALLBACK* callback = (LOCATION_CALLBACK*)pChannelCallback; |
157 | |
|
158 | 0 | WINPR_ASSERT(callback); |
159 | |
|
160 | 0 | LOCATION_PLUGIN* plugin = (LOCATION_PLUGIN*)callback->baseCb.plugin; |
161 | 0 | WINPR_ASSERT(plugin); |
162 | |
|
163 | 0 | UINT16 pduType = 0; |
164 | 0 | UINT32 pduLength = 0; |
165 | 0 | if (!location_read_header(plugin->baseDynPlugin.log, data, &pduType, &pduLength)) |
166 | 0 | return ERROR_INVALID_DATA; |
167 | | |
168 | 0 | switch (pduType) |
169 | 0 | { |
170 | 0 | case PDUTYPE_SERVER_READY: |
171 | 0 | if (!location_read_server_ready_pdu(callback, data, pduLength)) |
172 | 0 | return ERROR_INVALID_DATA; |
173 | | |
174 | 0 | switch (callback->serverVersion) |
175 | 0 | { |
176 | 0 | case RDPLOCATION_PROTOCOL_VERSION_200: |
177 | 0 | callback->clientVersion = RDPLOCATION_PROTOCOL_VERSION_200; |
178 | 0 | break; |
179 | 0 | case RDPLOCATION_PROTOCOL_VERSION_100: |
180 | 0 | callback->clientVersion = RDPLOCATION_PROTOCOL_VERSION_100; |
181 | 0 | break; |
182 | 0 | default: |
183 | 0 | callback->clientVersion = RDPLOCATION_PROTOCOL_VERSION_100; |
184 | 0 | if (callback->serverVersion > RDPLOCATION_PROTOCOL_VERSION_200) |
185 | 0 | callback->clientVersion = RDPLOCATION_PROTOCOL_VERSION_200; |
186 | 0 | break; |
187 | 0 | } |
188 | | |
189 | 0 | { |
190 | 0 | char cbuffer[64] = WINPR_C_ARRAY_INIT; |
191 | 0 | char sbuffer[64] = WINPR_C_ARRAY_INIT; |
192 | 0 | WLog_Print(plugin->baseDynPlugin.log, WLOG_DEBUG, |
193 | 0 | "Server version %s, client version %s", |
194 | 0 | location_version_str(callback->serverVersion, sbuffer, sizeof(sbuffer)), |
195 | 0 | location_version_str(callback->clientVersion, cbuffer, sizeof(cbuffer))); |
196 | 0 | } |
197 | |
|
198 | 0 | if (!plugin->context.LocationStart) |
199 | 0 | { |
200 | 0 | WLog_Print(plugin->baseDynPlugin.log, WLOG_WARN, |
201 | 0 | "LocationStart=NULL, no location data will be sent"); |
202 | 0 | return CHANNEL_RC_OK; |
203 | 0 | } |
204 | | |
205 | 0 | { |
206 | 0 | const UINT res = |
207 | 0 | plugin->context.LocationStart(&plugin->context, callback->clientVersion, 0); |
208 | 0 | if (res != CHANNEL_RC_OK) |
209 | 0 | return res; |
210 | 0 | } |
211 | 0 | return location_send_client_ready_pdu(callback); |
212 | 0 | default: |
213 | 0 | WLog_WARN(TAG, "invalid pduType=%" PRIu16, pduType); |
214 | 0 | return ERROR_INVALID_DATA; |
215 | 0 | } |
216 | 0 | } |
217 | | |
218 | | static UINT location_send_base_location3d(IWTSVirtualChannel* channel, |
219 | | const RDPLOCATION_BASE_LOCATION3D_PDU* pdu) |
220 | 0 | { |
221 | 0 | wStream sbuffer = WINPR_C_ARRAY_INIT; |
222 | 0 | BYTE buffer[32] = WINPR_C_ARRAY_INIT; |
223 | 0 | wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); |
224 | 0 | WINPR_ASSERT(s); |
225 | 0 | WINPR_ASSERT(channel); |
226 | 0 | WINPR_ASSERT(pdu); |
227 | |
|
228 | 0 | if (pdu->source) |
229 | 0 | WLog_DBG(TAG, |
230 | 0 | "latitude=%lf, longitude=%lf, altitude=%" PRId32 |
231 | 0 | ", speed=%lf, heading=%lf, haccuracy=%lf, source=%" PRIu8, |
232 | 0 | pdu->latitude, pdu->longitude, pdu->altitude, pdu->speed ? *pdu->speed : FP_NAN, |
233 | 0 | pdu->heading ? *pdu->heading : FP_NAN, |
234 | 0 | pdu->horizontalAccuracy ? *pdu->horizontalAccuracy : FP_NAN, *pdu->source); |
235 | 0 | else |
236 | 0 | WLog_DBG(TAG, "latitude=%lf, longitude=%lf, altitude=%" PRId32, pdu->latitude, |
237 | 0 | pdu->longitude, pdu->altitude); |
238 | |
|
239 | 0 | if (!location_write_header(s, PDUTYPE_BASE_LOCATION3D, pdu->source ? 25 : 12)) |
240 | 0 | return ERROR_OUTOFMEMORY; |
241 | | |
242 | 0 | if (!freerdp_write_four_byte_float(s, pdu->latitude) || |
243 | 0 | !freerdp_write_four_byte_float(s, pdu->longitude) || |
244 | 0 | !freerdp_write_four_byte_signed_integer(s, pdu->altitude)) |
245 | 0 | return ERROR_INTERNAL_ERROR; |
246 | | |
247 | 0 | if (pdu->source) |
248 | 0 | { |
249 | 0 | if (!freerdp_write_four_byte_float(s, *pdu->speed) || |
250 | 0 | !freerdp_write_four_byte_float(s, *pdu->heading) || |
251 | 0 | !freerdp_write_four_byte_float(s, *pdu->horizontalAccuracy)) |
252 | 0 | return ERROR_INTERNAL_ERROR; |
253 | | |
254 | 0 | Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(UINT8, *pdu->source)); |
255 | 0 | } |
256 | | |
257 | 0 | return location_channel_send(channel, s); |
258 | 0 | } |
259 | | |
260 | | static UINT location_send_location2d_delta(IWTSVirtualChannel* channel, |
261 | | const RDPLOCATION_LOCATION2D_DELTA_PDU* pdu) |
262 | 0 | { |
263 | 0 | wStream sbuffer = WINPR_C_ARRAY_INIT; |
264 | 0 | BYTE buffer[32] = WINPR_C_ARRAY_INIT; |
265 | 0 | wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); |
266 | 0 | WINPR_ASSERT(s); |
267 | |
|
268 | 0 | WINPR_ASSERT(channel); |
269 | 0 | WINPR_ASSERT(pdu); |
270 | |
|
271 | 0 | const BOOL ext = pdu->speedDelta && pdu->headingDelta; |
272 | |
|
273 | 0 | if (ext) |
274 | 0 | WLog_DBG(TAG, "latitude=%lf, longitude=%lf, speed=%lf, heading=%lf", pdu->latitudeDelta, |
275 | 0 | pdu->longitudeDelta, pdu->speedDelta ? *pdu->speedDelta : FP_NAN, |
276 | 0 | pdu->headingDelta ? *pdu->headingDelta : FP_NAN); |
277 | 0 | else |
278 | 0 | WLog_DBG(TAG, "latitude=%lf, longitude=%lf", pdu->latitudeDelta, pdu->longitudeDelta); |
279 | |
|
280 | 0 | if (!location_write_header(s, PDUTYPE_LOCATION2D_DELTA, ext ? 16 : 8)) |
281 | 0 | return ERROR_OUTOFMEMORY; |
282 | | |
283 | 0 | if (!freerdp_write_four_byte_float(s, pdu->latitudeDelta) || |
284 | 0 | !freerdp_write_four_byte_float(s, pdu->longitudeDelta)) |
285 | 0 | return ERROR_INTERNAL_ERROR; |
286 | | |
287 | 0 | if (ext) |
288 | 0 | { |
289 | 0 | if (!freerdp_write_four_byte_float(s, *pdu->speedDelta) || |
290 | 0 | !freerdp_write_four_byte_float(s, *pdu->headingDelta)) |
291 | 0 | return ERROR_INTERNAL_ERROR; |
292 | 0 | } |
293 | | |
294 | 0 | return location_channel_send(channel, s); |
295 | 0 | } |
296 | | |
297 | | static UINT location_send_location3d_delta(IWTSVirtualChannel* channel, |
298 | | const RDPLOCATION_LOCATION3D_DELTA_PDU* pdu) |
299 | 0 | { |
300 | 0 | wStream sbuffer = WINPR_C_ARRAY_INIT; |
301 | 0 | BYTE buffer[32] = WINPR_C_ARRAY_INIT; |
302 | 0 | wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); |
303 | 0 | WINPR_ASSERT(s); |
304 | |
|
305 | 0 | WINPR_ASSERT(channel); |
306 | 0 | WINPR_ASSERT(pdu); |
307 | |
|
308 | 0 | const BOOL ext = pdu->speedDelta && pdu->headingDelta; |
309 | |
|
310 | 0 | if (ext) |
311 | 0 | WLog_DBG(TAG, "latitude=%lf, longitude=%lf, altitude=%" PRId32 ", speed=%lf, heading=%lf", |
312 | 0 | pdu->latitudeDelta, pdu->longitudeDelta, pdu->altitudeDelta, |
313 | 0 | pdu->speedDelta ? *pdu->speedDelta : FP_NAN, |
314 | 0 | pdu->headingDelta ? *pdu->headingDelta : FP_NAN); |
315 | 0 | else |
316 | 0 | WLog_DBG(TAG, "latitude=%lf, longitude=%lf, altitude=%" PRId32, pdu->latitudeDelta, |
317 | 0 | pdu->longitudeDelta, pdu->altitudeDelta); |
318 | |
|
319 | 0 | if (!location_write_header(s, PDUTYPE_LOCATION3D_DELTA, ext ? 20 : 12)) |
320 | 0 | return ERROR_OUTOFMEMORY; |
321 | | |
322 | 0 | if (!freerdp_write_four_byte_float(s, pdu->latitudeDelta) || |
323 | 0 | !freerdp_write_four_byte_float(s, pdu->longitudeDelta) || |
324 | 0 | !freerdp_write_four_byte_signed_integer(s, pdu->altitudeDelta)) |
325 | 0 | return ERROR_INTERNAL_ERROR; |
326 | | |
327 | 0 | if (ext) |
328 | 0 | { |
329 | 0 | if (!freerdp_write_four_byte_float(s, *pdu->speedDelta) || |
330 | 0 | !freerdp_write_four_byte_float(s, *pdu->headingDelta)) |
331 | 0 | return ERROR_INTERNAL_ERROR; |
332 | 0 | } |
333 | | |
334 | 0 | return location_channel_send(channel, s); |
335 | 0 | } |
336 | | |
337 | | static UINT location_send(LocationClientContext* context, LOCATION_PDUTYPE type, size_t count, ...) |
338 | 0 | { |
339 | 0 | WINPR_ASSERT(context); |
340 | |
|
341 | 0 | LOCATION_PLUGIN* loc = context->handle; |
342 | 0 | WINPR_ASSERT(loc); |
343 | |
|
344 | 0 | GENERIC_LISTENER_CALLBACK* cb = loc->baseDynPlugin.listener_callback; |
345 | 0 | WINPR_ASSERT(cb); |
346 | |
|
347 | 0 | IWTSVirtualChannel* channel = cb->channel; |
348 | 0 | WINPR_ASSERT(channel); |
349 | |
|
350 | 0 | const LOCATION_CALLBACK* callback = |
351 | 0 | (const LOCATION_CALLBACK*)loc->baseDynPlugin.channel_callbacks; |
352 | 0 | WINPR_ASSERT(callback); |
353 | |
|
354 | 0 | UINT32 res = ERROR_INTERNAL_ERROR; |
355 | 0 | va_list ap = WINPR_C_ARRAY_INIT; |
356 | 0 | va_start(ap, count); |
357 | 0 | switch (type) |
358 | 0 | { |
359 | 0 | case PDUTYPE_BASE_LOCATION3D: |
360 | 0 | if ((count != 3) && (count != 7)) |
361 | 0 | res = ERROR_INVALID_PARAMETER; |
362 | 0 | else |
363 | 0 | { |
364 | 0 | LOCATIONSOURCE source = LOCATIONSOURCE_IP; |
365 | 0 | double speed = FP_NAN; |
366 | 0 | double heading = FP_NAN; |
367 | 0 | double horizontalAccuracy = FP_NAN; |
368 | 0 | RDPLOCATION_BASE_LOCATION3D_PDU pdu = { .latitude = va_arg(ap, double), |
369 | 0 | .longitude = va_arg(ap, double), |
370 | 0 | .altitude = va_arg(ap, INT32), |
371 | 0 | .speed = NULL, |
372 | 0 | .heading = NULL, |
373 | 0 | .horizontalAccuracy = NULL, |
374 | 0 | .source = NULL }; |
375 | |
|
376 | 0 | if ((count > 3) && (callback->clientVersion >= RDPLOCATION_PROTOCOL_VERSION_200)) |
377 | 0 | { |
378 | 0 | speed = va_arg(ap, double); |
379 | 0 | heading = va_arg(ap, double); |
380 | 0 | horizontalAccuracy = va_arg(ap, double); |
381 | 0 | source = WINPR_ASSERTING_INT_CAST(LOCATIONSOURCE, va_arg(ap, int)); |
382 | 0 | pdu.speed = &speed; |
383 | 0 | pdu.heading = &heading; |
384 | 0 | pdu.horizontalAccuracy = &horizontalAccuracy; |
385 | 0 | pdu.source = &source; |
386 | 0 | } |
387 | 0 | res = location_send_base_location3d(channel, &pdu); |
388 | 0 | } |
389 | 0 | break; |
390 | 0 | case PDUTYPE_LOCATION2D_DELTA: |
391 | 0 | if ((count != 2) && (count != 4)) |
392 | 0 | res = ERROR_INVALID_PARAMETER; |
393 | 0 | else |
394 | 0 | { |
395 | 0 | RDPLOCATION_LOCATION2D_DELTA_PDU pdu = { .latitudeDelta = va_arg(ap, double), |
396 | 0 | .longitudeDelta = va_arg(ap, double), |
397 | 0 | .speedDelta = NULL, |
398 | 0 | .headingDelta = NULL }; |
399 | |
|
400 | 0 | double speedDelta = FP_NAN; |
401 | 0 | double headingDelta = FP_NAN; |
402 | 0 | if ((count > 2) && (callback->clientVersion >= RDPLOCATION_PROTOCOL_VERSION_200)) |
403 | 0 | { |
404 | 0 | speedDelta = va_arg(ap, double); |
405 | 0 | headingDelta = va_arg(ap, double); |
406 | 0 | pdu.speedDelta = &speedDelta; |
407 | 0 | pdu.headingDelta = &headingDelta; |
408 | 0 | } |
409 | 0 | res = location_send_location2d_delta(channel, &pdu); |
410 | 0 | } |
411 | 0 | break; |
412 | 0 | case PDUTYPE_LOCATION3D_DELTA: |
413 | 0 | if ((count != 3) && (count != 5)) |
414 | 0 | res = ERROR_INVALID_PARAMETER; |
415 | 0 | else |
416 | 0 | { |
417 | 0 | double speedDelta = FP_NAN; |
418 | 0 | double headingDelta = FP_NAN; |
419 | |
|
420 | 0 | RDPLOCATION_LOCATION3D_DELTA_PDU pdu = { .latitudeDelta = va_arg(ap, double), |
421 | 0 | .longitudeDelta = va_arg(ap, double), |
422 | 0 | .altitudeDelta = va_arg(ap, INT32), |
423 | 0 | .speedDelta = NULL, |
424 | 0 | .headingDelta = NULL }; |
425 | 0 | if ((count > 3) && (callback->clientVersion >= RDPLOCATION_PROTOCOL_VERSION_200)) |
426 | 0 | { |
427 | 0 | speedDelta = va_arg(ap, double); |
428 | 0 | headingDelta = va_arg(ap, double); |
429 | 0 | pdu.speedDelta = &speedDelta; |
430 | 0 | pdu.headingDelta = &headingDelta; |
431 | 0 | } |
432 | 0 | res = location_send_location3d_delta(channel, &pdu); |
433 | 0 | } |
434 | 0 | break; |
435 | 0 | default: |
436 | 0 | res = ERROR_INVALID_PARAMETER; |
437 | 0 | break; |
438 | 0 | } |
439 | 0 | va_end(ap); |
440 | 0 | return res; |
441 | 0 | } |
442 | | |
443 | | /** |
444 | | * Function description |
445 | | * |
446 | | * @return 0 on success, otherwise a Win32 error code |
447 | | */ |
448 | | static UINT location_on_close(IWTSVirtualChannelCallback* pChannelCallback) |
449 | 0 | { |
450 | 0 | UINT res = CHANNEL_RC_OK; |
451 | 0 | GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; |
452 | |
|
453 | 0 | if (callback) |
454 | 0 | { |
455 | 0 | LOCATION_PLUGIN* plugin = (LOCATION_PLUGIN*)callback->plugin; |
456 | 0 | WINPR_ASSERT(plugin); |
457 | |
|
458 | 0 | res = IFCALLRESULT(CHANNEL_RC_OK, plugin->context.LocationStop, &plugin->context); |
459 | 0 | } |
460 | 0 | free(callback); |
461 | |
|
462 | 0 | return res; |
463 | 0 | } |
464 | | |
465 | | static UINT location_init(GENERIC_DYNVC_PLUGIN* plugin, WINPR_ATTR_UNUSED rdpContext* context, |
466 | | WINPR_ATTR_UNUSED rdpSettings* settings) |
467 | 0 | { |
468 | 0 | LOCATION_PLUGIN* loc = (LOCATION_PLUGIN*)plugin; |
469 | |
|
470 | 0 | WINPR_ASSERT(loc); |
471 | |
|
472 | 0 | loc->context.LocationSend = location_send; |
473 | 0 | loc->context.handle = loc; |
474 | 0 | plugin->iface.pInterface = &loc->context; |
475 | 0 | return CHANNEL_RC_OK; |
476 | 0 | } |
477 | | |
478 | | static const IWTSVirtualChannelCallback location_callbacks = { location_on_data_received, |
479 | | NULL, /* Open */ |
480 | | location_on_close, NULL }; |
481 | | |
482 | | /** |
483 | | * Function description |
484 | | * |
485 | | * @return 0 on success, otherwise a Win32 error code |
486 | | */ |
487 | | FREERDP_ENTRY_POINT(UINT VCAPITYPE location_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) |
488 | 0 | { |
489 | 0 | return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, LOCATION_DVC_CHANNEL_NAME, |
490 | 0 | sizeof(LOCATION_PLUGIN), sizeof(LOCATION_CALLBACK), |
491 | | &location_callbacks, location_init, NULL); |
492 | 0 | } |