compositor: quick fix for sub-surface mapping
[profile/ivi/weston-ivi-shell.git] / src / compositor-rdp.c
1 /*
2  * Copyright © 2013 Hardening <rdp.effort@gmail.com>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "config.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <linux/input.h>
29
30 #if HAVE_FREERDP_VERSION_H
31 #include <freerdp/version.h>
32 #else
33 /* assume it's a early 1.1 version */
34 #define FREERDP_VERSION_MAJOR 1
35 #define FREERDP_VERSION_MINOR 1
36 #endif
37
38 #include <freerdp/freerdp.h>
39 #include <freerdp/listener.h>
40 #include <freerdp/update.h>
41 #include <freerdp/input.h>
42 #include <freerdp/codec/color.h>
43 #include <freerdp/codec/rfx.h>
44 #include <freerdp/codec/nsc.h>
45 #include <freerdp/locale/keyboard.h>
46 #include <winpr/input.h>
47
48 #include "compositor.h"
49 #include "pixman-renderer.h"
50
51 #define MAX_FREERDP_FDS 32
52 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
53 #define RDP_MODE_FREQ 60 * 1000
54
55 struct rdp_compositor_config {
56         int width;
57         int height;
58         char *bind_address;
59         int port;
60         char *rdp_key;
61         char *server_cert;
62         char *server_key;
63         int env_socket;
64         int no_clients_resize;
65 };
66
67 struct rdp_output;
68
69 struct rdp_compositor {
70         struct weston_compositor base;
71
72         freerdp_listener *listener;
73         struct wl_event_source *listener_events[MAX_FREERDP_FDS];
74         struct rdp_output *output;
75
76         char *server_cert;
77         char *server_key;
78         char *rdp_key;
79         int tls_enabled;
80         int no_clients_resize;
81 };
82
83 enum peer_item_flags {
84         RDP_PEER_ACTIVATED      = (1 << 0),
85         RDP_PEER_OUTPUT_ENABLED = (1 << 1),
86 };
87
88 struct rdp_peers_item {
89         int flags;
90         freerdp_peer *peer;
91         struct weston_seat seat;
92
93         struct wl_list link;
94 };
95
96 struct rdp_output {
97         struct weston_output base;
98         struct wl_event_source *finish_frame_timer;
99         pixman_image_t *shadow_surface;
100
101         struct wl_list peers;
102 };
103
104 struct rdp_peer_context {
105         rdpContext _p;
106
107         struct rdp_compositor *rdpCompositor;
108         struct wl_event_source *events[MAX_FREERDP_FDS];
109         RFX_CONTEXT *rfx_context;
110         wStream *encode_stream;
111         RFX_RECT *rfx_rects;
112         NSC_CONTEXT *nsc_context;
113
114         struct rdp_peers_item item;
115 };
116 typedef struct rdp_peer_context RdpPeerContext;
117
118 static void
119 rdp_compositor_config_init(struct rdp_compositor_config *config) {
120         config->width = 640;
121         config->height = 480;
122         config->bind_address = NULL;
123         config->port = 3389;
124         config->rdp_key = NULL;
125         config->server_cert = NULL;
126         config->server_key = NULL;
127         config->env_socket = 0;
128         config->no_clients_resize = 0;
129 }
130
131 static void
132 rdp_peer_refresh_rfx(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer)
133 {
134         int width, height, nrects, i;
135         pixman_box32_t *region, *rects;
136         uint32_t *ptr;
137         RFX_RECT *rfxRect;
138         rdpUpdate *update = peer->update;
139         SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command;
140         RdpPeerContext *context = (RdpPeerContext *)peer->context;
141
142         Stream_Clear(context->encode_stream);
143         Stream_SetPosition(context->encode_stream, 0);
144
145         width = (damage->extents.x2 - damage->extents.x1);
146         height = (damage->extents.y2 - damage->extents.y1);
147
148         cmd->destLeft = damage->extents.x1;
149         cmd->destTop = damage->extents.y1;
150         cmd->destRight = damage->extents.x2;
151         cmd->destBottom = damage->extents.y2;
152         cmd->bpp = 32;
153         cmd->codecID = peer->settings->RemoteFxCodecId;
154         cmd->width = width;
155         cmd->height = height;
156
157         ptr = pixman_image_get_data(image) + damage->extents.x1 +
158                                 damage->extents.y1 * (pixman_image_get_stride(image) / sizeof(uint32_t));
159
160         rects = pixman_region32_rectangles(damage, &nrects);
161         context->rfx_rects = realloc(context->rfx_rects, nrects * sizeof *rfxRect);
162
163         for (i = 0; i < nrects; i++) {
164                 region = &rects[i];
165                 rfxRect = &context->rfx_rects[i];
166
167                 rfxRect->x = (region->x1 - damage->extents.x1);
168                 rfxRect->y = (region->y1 - damage->extents.y1);
169                 rfxRect->width = (region->x2 - region->x1);
170                 rfxRect->height = (region->y2 - region->y1);
171         }
172
173         rfx_compose_message(context->rfx_context, context->encode_stream, context->rfx_rects, nrects,
174                         (BYTE *)ptr, width, height,
175                         pixman_image_get_stride(image)
176         );
177
178         cmd->bitmapDataLength = Stream_GetPosition(context->encode_stream);
179         cmd->bitmapData = Stream_Buffer(context->encode_stream);
180
181         update->SurfaceBits(update->context, cmd);
182 }
183
184
185 static void
186 rdp_peer_refresh_nsc(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer)
187 {
188         int width, height;
189         uint32_t *ptr;
190         rdpUpdate *update = peer->update;
191         SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command;
192         RdpPeerContext *context = (RdpPeerContext *)peer->context;
193
194         Stream_Clear(context->encode_stream);
195         Stream_SetPosition(context->encode_stream, 0);
196
197         width = (damage->extents.x2 - damage->extents.x1);
198         height = (damage->extents.y2 - damage->extents.y1);
199
200         cmd->destLeft = damage->extents.x1;
201         cmd->destTop = damage->extents.y1;
202         cmd->destRight = damage->extents.x2;
203         cmd->destBottom = damage->extents.y2;
204         cmd->bpp = 32;
205         cmd->codecID = peer->settings->NSCodecId;
206         cmd->width = width;
207         cmd->height = height;
208
209         ptr = pixman_image_get_data(image) + damage->extents.x1 +
210                                 damage->extents.y1 * (pixman_image_get_stride(image) / sizeof(uint32_t));
211
212         nsc_compose_message(context->nsc_context, context->encode_stream, (BYTE *)ptr,
213                         cmd->width,     cmd->height,
214                         pixman_image_get_stride(image));
215         cmd->bitmapDataLength = Stream_GetPosition(context->encode_stream);
216         cmd->bitmapData = Stream_Buffer(context->encode_stream);
217         update->SurfaceBits(update->context, cmd);
218 }
219
220 static void
221 pixman_image_flipped_subrect(const pixman_box32_t *rect, pixman_image_t *img, BYTE *dest) {
222         int stride = pixman_image_get_stride(img);
223         int h;
224         int toCopy = (rect->x2 - rect->x1) * 4;
225         int height = (rect->y2 - rect->y1);
226         const BYTE *src = (const BYTE *)pixman_image_get_data(img);
227         src += ((rect->y2-1) * stride) + (rect->x1 * 4);
228
229         for (h = 0; h < height; h++, src -= stride, dest += toCopy)
230                    memcpy(dest, src, toCopy);
231 }
232
233 static void
234 rdp_peer_refresh_raw(pixman_region32_t *region, pixman_image_t *image, freerdp_peer *peer)
235 {
236         rdpUpdate *update = peer->update;
237         SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command;
238         SURFACE_FRAME_MARKER *marker = &update->surface_frame_marker;
239         pixman_box32_t *rect, subrect;
240         int nrects, i;
241         int heightIncrement, remainingHeight, top;
242
243         rect = pixman_region32_rectangles(region, &nrects);
244         if (!nrects)
245                 return;
246
247         marker->frameId++;
248         marker->frameAction = SURFACECMD_FRAMEACTION_BEGIN;
249         update->SurfaceFrameMarker(peer->context, marker);
250
251         cmd->bpp = 32;
252         cmd->codecID = 0;
253
254         for (i = 0; i < nrects; i++, rect++) {
255                 /*weston_log("rect(%d,%d, %d,%d)\n", rect->x1, rect->y1, rect->x2, rect->y2);*/
256                 cmd->destLeft = rect->x1;
257                 cmd->destRight = rect->x2;
258                 cmd->width = rect->x2 - rect->x1;
259
260                 heightIncrement = peer->settings->MultifragMaxRequestSize / (16 + cmd->width * 4);
261                 remainingHeight = rect->y2 - rect->y1;
262                 top = rect->y1;
263
264                 subrect.x1 = rect->x1;
265                 subrect.x2 = rect->x2;
266
267                 while (remainingHeight) {
268                            cmd->height = (remainingHeight > heightIncrement) ? heightIncrement : remainingHeight;
269                            cmd->destTop = top;
270                            cmd->destBottom = top + cmd->height;
271                            cmd->bitmapDataLength = cmd->width * cmd->height * 4;
272                            cmd->bitmapData = (BYTE *)realloc(cmd->bitmapData, cmd->bitmapDataLength);
273
274                            subrect.y1 = top;
275                            subrect.y2 = top + cmd->height;
276                            pixman_image_flipped_subrect(&subrect, image, cmd->bitmapData);
277
278                            /*weston_log("*  sending (%d,%d, %d,%d)\n", subrect.x1, subrect.y1, subrect.x2, subrect.y2); */
279                            update->SurfaceBits(peer->context, cmd);
280
281                            remainingHeight -= cmd->height;
282                            top += cmd->height;
283                 }
284         }
285
286         marker->frameAction = SURFACECMD_FRAMEACTION_END;
287         update->SurfaceFrameMarker(peer->context, marker);
288 }
289
290 static void
291 rdp_peer_refresh_region(pixman_region32_t *region, freerdp_peer *peer)
292 {
293         RdpPeerContext *context = (RdpPeerContext *)peer->context;
294         struct rdp_output *output = context->rdpCompositor->output;
295         rdpSettings *settings = peer->settings;
296
297         if (settings->RemoteFxCodec)
298                 rdp_peer_refresh_rfx(region, output->shadow_surface, peer);
299         else if (settings->NSCodec)
300                 rdp_peer_refresh_nsc(region, output->shadow_surface, peer);
301         else
302                 rdp_peer_refresh_raw(region, output->shadow_surface, peer);
303 }
304
305 static void
306 rdp_output_start_repaint_loop(struct weston_output *output)
307 {
308         uint32_t msec;
309         struct timeval tv;
310
311         gettimeofday(&tv, NULL);
312         msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
313         weston_output_finish_frame(output, msec);
314 }
315
316 static int
317 rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
318 {
319         struct rdp_output *output = container_of(output_base, struct rdp_output, base);
320         struct weston_compositor *ec = output->base.compositor;
321         struct rdp_peers_item *outputPeer;
322
323         pixman_renderer_output_set_buffer(output_base, output->shadow_surface);
324         ec->renderer->repaint_output(&output->base, damage);
325
326         if (pixman_region32_not_empty(damage)) {
327                 wl_list_for_each(outputPeer, &output->peers, link) {
328                         if ((outputPeer->flags & RDP_PEER_ACTIVATED) &&
329                                         (outputPeer->flags & RDP_PEER_OUTPUT_ENABLED))
330                         {
331                                 rdp_peer_refresh_region(damage, outputPeer->peer);
332                         }
333                 }
334         }
335
336         pixman_region32_subtract(&ec->primary_plane.damage,
337                                  &ec->primary_plane.damage, damage);
338
339         wl_event_source_timer_update(output->finish_frame_timer, 16);
340         return 0;
341 }
342
343 static void
344 rdp_output_destroy(struct weston_output *output_base)
345 {
346         struct rdp_output *output = (struct rdp_output *)output_base;
347
348         wl_event_source_remove(output->finish_frame_timer);
349         free(output);
350 }
351
352 static int
353 finish_frame_handler(void *data)
354 {
355         rdp_output_start_repaint_loop(data);
356
357         return 1;
358 }
359
360 static struct weston_mode *
361 rdp_insert_new_mode(struct weston_output *output, int width, int height, int rate) {
362         struct weston_mode *ret;
363         ret = zalloc(sizeof *ret);
364         if (!ret)
365                 return NULL;
366         ret->width = width;
367         ret->height = height;
368         ret->refresh = rate;
369         wl_list_insert(&output->mode_list, &ret->link);
370         return ret;
371 }
372
373 static struct weston_mode *
374 ensure_matching_mode(struct weston_output *output, struct weston_mode *target) {
375         struct weston_mode *local;
376
377         wl_list_for_each(local, &output->mode_list, link) {
378                 if ((local->width == target->width) && (local->height == target->height))
379                         return local;
380         }
381
382         return rdp_insert_new_mode(output, target->width, target->height, RDP_MODE_FREQ);
383 }
384
385 static int
386 rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
387         struct rdp_output *rdpOutput = container_of(output, struct rdp_output, base);
388         struct rdp_peers_item *rdpPeer;
389         rdpSettings *settings;
390         pixman_image_t *new_shadow_buffer;
391         struct weston_mode *local_mode;
392
393         local_mode = ensure_matching_mode(output, target_mode);
394         if (!local_mode) {
395                 weston_log("mode %dx%d not available\n", target_mode->width, target_mode->height);
396                 return -ENOENT;
397         }
398
399         if (local_mode == output->current_mode)
400                 return 0;
401
402         output->current_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
403
404         output->current_mode = local_mode;
405         output->current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
406
407         pixman_renderer_output_destroy(output);
408         pixman_renderer_output_create(output);
409
410         new_shadow_buffer = pixman_image_create_bits(PIXMAN_x8r8g8b8, target_mode->width,
411                         target_mode->height, 0, target_mode->width * 4);
412         pixman_image_composite32(PIXMAN_OP_SRC, rdpOutput->shadow_surface, 0, new_shadow_buffer,
413                         0, 0, 0, 0, 0, 0, target_mode->width, target_mode->height);
414         pixman_image_unref(rdpOutput->shadow_surface);
415         rdpOutput->shadow_surface = new_shadow_buffer;
416
417         wl_list_for_each(rdpPeer, &rdpOutput->peers, link) {
418                 settings = rdpPeer->peer->settings;
419                 if (settings->DesktopWidth == (UINT32)target_mode->width &&
420                                 settings->DesktopHeight == (UINT32)target_mode->height)
421                         continue;
422
423                 if (!settings->DesktopResize) {
424                         /* too bad this peer does not support desktop resize */
425                         rdpPeer->peer->Close(rdpPeer->peer);
426                 } else {
427                         settings->DesktopWidth = target_mode->width;
428                         settings->DesktopHeight = target_mode->height;
429                         rdpPeer->peer->update->DesktopResize(rdpPeer->peer->context);
430                 }
431         }
432         return 0;
433 }
434
435 static int
436 rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
437 {
438         struct rdp_output *output;
439         struct wl_event_loop *loop;
440         struct weston_mode *currentMode;
441         struct weston_mode initMode;
442
443         output = zalloc(sizeof *output);
444         if (output == NULL)
445                 return -1;
446
447         wl_list_init(&output->peers);
448         wl_list_init(&output->base.mode_list);
449
450         initMode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
451         initMode.width = width;
452         initMode.height = height;
453         initMode.refresh = RDP_MODE_FREQ;
454
455         currentMode = ensure_matching_mode(&output->base, &initMode);
456         if (!currentMode)
457                 goto out_free_output;
458
459         output->base.current_mode = output->base.native_mode = currentMode;
460         weston_output_init(&output->base, &c->base, 0, 0, width, height,
461                            WL_OUTPUT_TRANSFORM_NORMAL, 1);
462
463         output->base.make = "weston";
464         output->base.model = "rdp";
465         output->shadow_surface = pixman_image_create_bits(PIXMAN_x8r8g8b8,
466                         width, height,
467                     NULL,
468                     width * 4);
469         if (output->shadow_surface == NULL) {
470                 weston_log("Failed to create surface for frame buffer.\n");
471                 goto out_output;
472         }
473
474         if (pixman_renderer_output_create(&output->base) < 0)
475                 goto out_shadow_surface;
476
477         loop = wl_display_get_event_loop(c->base.wl_display);
478         output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output);
479
480         output->base.start_repaint_loop = rdp_output_start_repaint_loop;
481         output->base.repaint = rdp_output_repaint;
482         output->base.destroy = rdp_output_destroy;
483         output->base.assign_planes = NULL;
484         output->base.set_backlight = NULL;
485         output->base.set_dpms = NULL;
486         output->base.switch_mode = rdp_switch_mode;
487         c->output = output;
488
489         wl_list_insert(c->base.output_list.prev, &output->base.link);
490         return 0;
491
492 out_shadow_surface:
493         pixman_image_unref(output->shadow_surface);
494 out_output:
495         weston_output_destroy(&output->base);
496 out_free_output:
497         free(output);
498         return -1;
499 }
500
501 static void
502 rdp_restore(struct weston_compositor *ec)
503 {
504 }
505
506 static void
507 rdp_destroy(struct weston_compositor *ec)
508 {
509         weston_compositor_shutdown(ec);
510
511         free(ec);
512 }
513
514 static
515 int rdp_listener_activity(int fd, uint32_t mask, void *data) {
516         freerdp_listener* instance = (freerdp_listener *)data;
517
518         if (!(mask & WL_EVENT_READABLE))
519                 return 0;
520         if (!instance->CheckFileDescriptor(instance))
521         {
522                 weston_log("failed to check FreeRDP file descriptor\n");
523                 return -1;
524         }
525         return 0;
526 }
527
528 static
529 int rdp_implant_listener(struct rdp_compositor *c, freerdp_listener* instance) {
530         int i, fd;
531         int rcount = 0;
532         void* rfds[MAX_FREERDP_FDS];
533         struct wl_event_loop *loop;
534
535         if (!instance->GetFileDescriptor(instance, rfds, &rcount)) {
536                 weston_log("Failed to get FreeRDP file descriptor\n");
537                 return -1;
538         }
539
540         loop = wl_display_get_event_loop(c->base.wl_display);
541         for (i = 0; i < rcount; i++) {
542                 fd = (int)(long)(rfds[i]);
543                 c->listener_events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
544                                 rdp_listener_activity, instance);
545         }
546
547         for( ; i < MAX_FREERDP_FDS; i++)
548                 c->listener_events[i] = 0;
549         return 0;
550 }
551
552
553 static void
554 rdp_peer_context_new(freerdp_peer* client, RdpPeerContext* context)
555 {
556         context->item.peer = client;
557         context->item.flags = RDP_PEER_OUTPUT_ENABLED;
558
559 #if FREERDP_VERSION_MAJOR == 1 && FREERDP_VERSION_MINOR == 1
560         context->rfx_context = rfx_context_new();
561 #else
562         context->rfx_context = rfx_context_new(TRUE);
563 #endif
564         context->rfx_context->mode = RLGR3;
565         context->rfx_context->width = client->settings->DesktopWidth;
566         context->rfx_context->height = client->settings->DesktopHeight;
567         rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
568
569         context->nsc_context = nsc_context_new();
570         nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8);
571
572         context->encode_stream = Stream_New(NULL, 65536);
573 }
574
575 static void
576 rdp_peer_context_free(freerdp_peer* client, RdpPeerContext* context)
577 {
578         int i;
579         if (!context)
580                 return;
581
582         wl_list_remove(&context->item.link);
583         for(i = 0; i < MAX_FREERDP_FDS; i++) {
584                 if (context->events[i])
585                         wl_event_source_remove(context->events[i]);
586         }
587
588         if (context->item.flags & RDP_PEER_ACTIVATED) {
589                 weston_seat_release_keyboard(&context->item.seat);
590                 weston_seat_release_pointer(&context->item.seat);
591                 weston_seat_release(&context->item.seat);
592         }
593         Stream_Free(context->encode_stream, TRUE);
594         nsc_context_free(context->nsc_context);
595         rfx_context_free(context->rfx_context);
596         free(context->rfx_rects);
597 }
598
599
600 static int
601 rdp_client_activity(int fd, uint32_t mask, void *data) {
602         freerdp_peer* client = (freerdp_peer *)data;
603
604         if (!client->CheckFileDescriptor(client)) {
605                 weston_log("unable to checkDescriptor for %p\n", client);
606                 goto out_clean;
607         }
608         return 0;
609
610 out_clean:
611         freerdp_peer_context_free(client);
612         freerdp_peer_free(client);
613         return 0;
614 }
615
616 static BOOL
617 xf_peer_capabilities(freerdp_peer* client)
618 {
619         return TRUE;
620 }
621
622 struct rdp_to_xkb_keyboard_layout {
623         UINT32 rdpLayoutCode;
624         const char *xkbLayout;
625         const char *xkbVariant;
626 };
627
628 /* table reversed from
629         https://github.com/awakecoding/FreeRDP/blob/master/libfreerdp/locale/xkb_layout_ids.c#L811 */
630 static
631 struct rdp_to_xkb_keyboard_layout rdp_keyboards[] = {
632         {KBD_ARABIC_101, "ara", 0},
633         {KBD_BULGARIAN, 0, 0},
634         {KBD_CHINESE_TRADITIONAL_US, 0},
635         {KBD_CZECH, "cz", 0},
636         {KBD_CZECH_PROGRAMMERS, "cz", "bksl"},
637         {KBD_CZECH_QWERTY, "cz", "qwerty"},
638         {KBD_DANISH, "dk", 0},
639         {KBD_GERMAN, "de", 0},
640         {KBD_GERMAN_NEO, "de", "neo"},
641         {KBD_GERMAN_IBM, "de", "qwerty"},
642         {KBD_GREEK, "gr", 0},
643         {KBD_GREEK_220, "gr", "simple"},
644         {KBD_GREEK_319, "gr", "extended"},
645         {KBD_GREEK_POLYTONIC, "gr", "polytonic"},
646         {KBD_US, "us", 0},
647         {KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L, "ara", "buckwalter"},
648         {KBD_SPANISH, "es", 0},
649         {KBD_SPANISH_VARIATION, "es", "nodeadkeys"},
650         {KBD_FINNISH, "fi", 0},
651         {KBD_FRENCH, "fr", 0},
652         {KBD_HEBREW, "il", 0},
653         {KBD_HUNGARIAN, "hu", 0},
654         {KBD_HUNGARIAN_101_KEY, "hu", "standard"},
655         {KBD_ICELANDIC, "is", 0},
656         {KBD_ITALIAN, "it", 0},
657         {KBD_ITALIAN_142, "it", "nodeadkeys"},
658         {KBD_JAPANESE, "jp", 0},
659         {KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002, "jp", "kana"},
660         {KBD_KOREAN, "kr", 0},
661         {KBD_KOREAN_INPUT_SYSTEM_IME_2000, "kr", "kr104"},
662         {KBD_DUTCH, "nl", 0},
663         {KBD_NORWEGIAN, "no", 0},
664         {KBD_POLISH_PROGRAMMERS, "pl", 0},
665         {KBD_POLISH_214, "pl", "qwertz"},
666         // {KBD_PORTUGUESE_BRAZILIAN_ABN0416, 0},
667         {KBD_ROMANIAN, "ro", 0},
668         {KBD_RUSSIAN, "ru", 0},
669         {KBD_RUSSIAN_TYPEWRITER, "ru", "typewriter"},
670         {KBD_CROATIAN, "hr", 0},
671         {KBD_SLOVAK, "sk", 0},
672         {KBD_SLOVAK_QWERTY, "sk", "qwerty"},
673         {KBD_ALBANIAN, 0, 0},
674         {KBD_SWEDISH, "se", 0},
675         {KBD_THAI_KEDMANEE, "th", 0},
676         {KBD_THAI_KEDMANEE_NON_SHIFTLOCK, "th", "tis"},
677         {KBD_TURKISH_Q, "tr", 0},
678         {KBD_TURKISH_F, "tr", "f"},
679         {KBD_URDU, "in", "urd-phonetic3"},
680         {KBD_UKRAINIAN, "ua", 0},
681         {KBD_BELARUSIAN, "by", 0},
682         {KBD_SLOVENIAN, "si", 0},
683         {KBD_ESTONIAN, "ee", 0},
684         {KBD_LATVIAN, "lv", 0},
685         {KBD_LITHUANIAN_IBM, "lt", "ibm"},
686         {KBD_FARSI, "af", 0},
687         {KBD_VIETNAMESE, "vn", 0},
688         {KBD_ARMENIAN_EASTERN, "am", 0},
689         {KBD_AZERI_LATIN, 0, 0},
690         {KBD_FYRO_MACEDONIAN, "mk", 0},
691         {KBD_GEORGIAN, "ge", 0},
692         {KBD_FAEROESE, 0, 0},
693         {KBD_DEVANAGARI_INSCRIPT, 0, 0},
694         {KBD_MALTESE_47_KEY, 0, 0},
695         {KBD_NORWEGIAN_WITH_SAMI, "no", "smi"},
696         {KBD_KAZAKH, "kz", 0},
697         {KBD_KYRGYZ_CYRILLIC, "kg", "phonetic"},
698         {KBD_TATAR, "ru", "tt"},
699         {KBD_BENGALI, "bd", 0},
700         {KBD_BENGALI_INSCRIPT, "bd", "probhat"},
701         {KBD_PUNJABI, 0, 0},
702         {KBD_GUJARATI, "in", "guj"},
703         {KBD_TAMIL, "in", "tam"},
704         {KBD_TELUGU, "in", "tel"},
705         {KBD_KANNADA, "in", "kan"},
706         {KBD_MALAYALAM, "in", "mal"},
707         {KBD_HINDI_TRADITIONAL, "in", 0},
708         {KBD_MARATHI, 0, 0},
709         {KBD_MONGOLIAN_CYRILLIC, "mn", 0},
710         {KBD_UNITED_KINGDOM_EXTENDED, "gb", "intl"},
711         {KBD_SYRIAC, "syc", 0},
712         {KBD_SYRIAC_PHONETIC, "syc", "syc_phonetic"},
713         {KBD_NEPALI, "np", 0},
714         {KBD_PASHTO, "af", "ps"},
715         {KBD_DIVEHI_PHONETIC, 0, 0},
716         {KBD_LUXEMBOURGISH, 0, 0},
717         {KBD_MAORI, "mao", 0},
718         {KBD_CHINESE_SIMPLIFIED_US, 0, 0},
719         {KBD_SWISS_GERMAN, "ch", "de_nodeadkeys"},
720         {KBD_UNITED_KINGDOM, "gb", 0},
721         {KBD_LATIN_AMERICAN, "latam", 0},
722         {KBD_BELGIAN_FRENCH, "be", 0},
723         {KBD_BELGIAN_PERIOD, "be", "oss_sundeadkeys"},
724         {KBD_PORTUGUESE, "pt", 0},
725         {KBD_SERBIAN_LATIN, "rs", 0},
726         {KBD_AZERI_CYRILLIC, "az", "cyrillic"},
727         {KBD_SWEDISH_WITH_SAMI, "se", "smi"},
728         {KBD_UZBEK_CYRILLIC, "af", "uz"},
729         {KBD_INUKTITUT_LATIN, "ca", "ike"},
730         {KBD_CANADIAN_FRENCH_LEGACY, "ca", "fr-legacy"},
731         {KBD_SERBIAN_CYRILLIC, "rs", 0},
732         {KBD_CANADIAN_FRENCH, "ca", "fr-legacy"},
733         {KBD_SWISS_FRENCH, "ch", "fr"},
734         {KBD_BOSNIAN, "ba", 0},
735         {KBD_IRISH, 0, 0},
736         {KBD_BOSNIAN_CYRILLIC, "ba", "us"},
737         {KBD_UNITED_STATES_DVORAK, "us", "dvorak"},
738         {KBD_PORTUGUESE_BRAZILIAN_ABNT2, "br", "nativo"},
739         {KBD_CANADIAN_MULTILINGUAL_STANDARD, "ca", "multix"},
740         {KBD_GAELIC, "ie", "CloGaelach"},
741
742         {0x00000000, 0, 0},
743 };
744
745 /* taken from 2.2.7.1.6 Input Capability Set (TS_INPUT_CAPABILITYSET) */
746 static char *rdp_keyboard_types[] = {
747         "",     /* 0: unused */
748         "", /* 1: IBM PC/XT or compatible (83-key) keyboard */
749         "", /* 2: Olivetti "ICO" (102-key) keyboard */
750         "", /* 3: IBM PC/AT (84-key) or similar keyboard */
751         "pc102",/* 4: IBM enhanced (101- or 102-key) keyboard */
752         "", /* 5: Nokia 1050 and similar keyboards */
753         "",     /* 6: Nokia 9140 and similar keyboards */
754         ""      /* 7: Japanese keyboard */
755 };
756
757 static BOOL
758 xf_peer_post_connect(freerdp_peer* client)
759 {
760         RdpPeerContext *peerCtx;
761         struct rdp_compositor *c;
762         struct rdp_output *output;
763         rdpSettings *settings;
764         rdpPointerUpdate *pointer;
765         struct xkb_context *xkbContext;
766         struct xkb_rule_names xkbRuleNames;
767         struct xkb_keymap *keymap;
768         int i;
769         pixman_box32_t box;
770         pixman_region32_t damage;
771
772
773         peerCtx = (RdpPeerContext *)client->context;
774         c = peerCtx->rdpCompositor;
775         output = c->output;
776         settings = client->settings;
777
778         if (!settings->SurfaceCommandsEnabled) {
779                 weston_log("client doesn't support required SurfaceCommands\n");
780                 return FALSE;
781         }
782
783         if (output->base.width != (int)settings->DesktopWidth ||
784                         output->base.height != (int)settings->DesktopHeight)
785         {
786                 if (c->no_clients_resize) {
787                         /* RDP peers don't dictate their resolution to weston */
788                         if (!settings->DesktopResize) {
789                                 /* peer does not support desktop resize */
790                                 weston_log("%s: client doesn't support resizing, closing connection\n", __FUNCTION__);
791                                 return FALSE;
792                         } else {
793                                 settings->DesktopWidth = output->base.width;
794                                 settings->DesktopHeight = output->base.height;
795                                 client->update->DesktopResize(client->context);
796                         }
797                 } else {
798                         /* ask weston to adjust size */
799                         struct weston_mode new_mode;
800                         struct weston_mode *target_mode;
801                         new_mode.width = (int)settings->DesktopWidth;
802                         new_mode.height = (int)settings->DesktopHeight;
803                         target_mode = ensure_matching_mode(&output->base, &new_mode);
804                         if (!target_mode) {
805                                 weston_log("client mode not found\n");
806                                 return FALSE;
807                         }
808                         weston_output_switch_mode(&output->base, target_mode, 1, WESTON_MODE_SWITCH_SET_NATIVE);
809                         output->base.width = new_mode.width;
810                         output->base.height = new_mode.height;
811                 }
812         }
813
814         weston_log("kbd_layout:%x kbd_type:%x kbd_subType:%x kbd_functionKeys:%x\n",
815                         settings->KeyboardLayout, settings->KeyboardType, settings->KeyboardSubType,
816                         settings->KeyboardFunctionKey);
817
818         memset(&xkbRuleNames, 0, sizeof(xkbRuleNames));
819         if (settings->KeyboardType <= 7)
820                 xkbRuleNames.model = rdp_keyboard_types[settings->KeyboardType];
821         for(i = 0; rdp_keyboards[i].rdpLayoutCode; i++) {
822                 if (rdp_keyboards[i].rdpLayoutCode == settings->KeyboardLayout) {
823                         xkbRuleNames.layout = rdp_keyboards[i].xkbLayout;
824                         xkbRuleNames.variant = rdp_keyboards[i].xkbVariant;
825                         weston_log("%s: matching layout=%s variant=%s\n", __FUNCTION__,
826                                         xkbRuleNames.layout, xkbRuleNames.variant);
827                         break;
828                 }
829         }
830
831         keymap = NULL;
832         if (xkbRuleNames.layout) {
833                 xkbContext = xkb_context_new(0);
834                 if (!xkbContext) {
835                         weston_log("unable to create a xkb_context\n");
836                         return FALSE;
837                 }
838
839                 keymap = xkb_keymap_new_from_names(xkbContext, &xkbRuleNames, 0);
840         }
841         weston_seat_init_keyboard(&peerCtx->item.seat, keymap);
842         weston_seat_init_pointer(&peerCtx->item.seat);
843
844         peerCtx->item.flags |= RDP_PEER_ACTIVATED;
845
846         /* disable pointer on the client side */
847         pointer = client->update->pointer;
848         pointer->pointer_system.type = SYSPTR_NULL;
849         pointer->PointerSystem(client->context, &pointer->pointer_system);
850
851         /* sends a full refresh */
852         box.x1 = 0;
853         box.y1 = 0;
854         box.x2 = output->base.width;
855         box.y2 = output->base.height;
856         pixman_region32_init_with_extents(&damage, &box);
857
858         rdp_peer_refresh_region(&damage, client);
859
860         pixman_region32_fini(&damage);
861
862         return TRUE;
863 }
864
865 static BOOL
866 xf_peer_activate(freerdp_peer *client)
867 {
868         RdpPeerContext *context = (RdpPeerContext *)client->context;
869         rfx_context_reset(context->rfx_context);
870         return TRUE;
871 }
872
873 static void
874 xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
875         wl_fixed_t wl_x, wl_y, axis;
876         RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
877         struct rdp_output *output;
878         uint32_t button = 0;
879
880         if (flags & PTR_FLAGS_MOVE) {
881                 output = peerContext->rdpCompositor->output;
882                 if (x < output->base.width && y < output->base.height) {
883                         wl_x = wl_fixed_from_int((int)x);
884                         wl_y = wl_fixed_from_int((int)y);
885                         notify_motion_absolute(&peerContext->item.seat, weston_compositor_get_time(),
886                                         wl_x, wl_y);
887                 }
888         }
889
890         if (flags & PTR_FLAGS_BUTTON1)
891                 button = BTN_LEFT;
892         else if (flags & PTR_FLAGS_BUTTON2)
893                 button = BTN_RIGHT;
894         else if (flags & PTR_FLAGS_BUTTON3)
895                 button = BTN_MIDDLE;
896
897         if (button) {
898                 notify_button(&peerContext->item.seat, weston_compositor_get_time(), button,
899                         (flags & PTR_FLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED
900                 );
901         }
902
903         if (flags & PTR_FLAGS_WHEEL) {
904                 /* DEFAULT_AXIS_STEP_DISTANCE is stolen from compositor-x11.c
905                  * The RDP specs says the lower bits of flags contains the "the number of rotation
906                  * units the mouse wheel was rotated".
907                  *
908                  * http://blogs.msdn.com/b/oldnewthing/archive/2013/01/23/10387366.aspx explains the 120 value
909                  */
910                 axis = (DEFAULT_AXIS_STEP_DISTANCE * (flags & 0xff)) / 120;
911                 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
912                         axis = -axis;
913
914                 notify_axis(&peerContext->item.seat, weston_compositor_get_time(),
915                                             WL_POINTER_AXIS_VERTICAL_SCROLL,
916                                             axis);
917         }
918 }
919
920 static void
921 xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
922         wl_fixed_t wl_x, wl_y;
923         RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
924         struct rdp_output *output;
925
926         output = peerContext->rdpCompositor->output;
927         if (x < output->base.width && y < output->base.height) {
928                 wl_x = wl_fixed_from_int((int)x);
929                 wl_y = wl_fixed_from_int((int)y);
930                 notify_motion_absolute(&peerContext->item.seat, weston_compositor_get_time(),
931                                 wl_x, wl_y);
932         }
933 }
934
935
936 static void
937 xf_input_synchronize_event(rdpInput *input, UINT32 flags)
938 {
939         freerdp_peer *client = input->context->peer;
940         RdpPeerContext *peerCtx = (RdpPeerContext *)input->context;
941         struct rdp_output *output = peerCtx->rdpCompositor->output;
942         pixman_box32_t box;
943         pixman_region32_t damage;
944
945         /* sends a full refresh */
946         box.x1 = 0;
947         box.y1 = 0;
948         box.x2 = output->base.width;
949         box.y2 = output->base.height;
950         pixman_region32_init_with_extents(&damage, &box);
951
952         rdp_peer_refresh_region(&damage, client);
953
954         pixman_region32_fini(&damage);
955 }
956
957
958 static void
959 xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
960 {
961         uint32_t scan_code, vk_code, full_code;
962         enum wl_keyboard_key_state keyState;
963         RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
964         int notify = 0;
965
966         if (flags & KBD_FLAGS_DOWN) {
967                 keyState = WL_KEYBOARD_KEY_STATE_PRESSED;
968                 notify = 1;
969         } else if (flags & KBD_FLAGS_RELEASE) {
970                 keyState = WL_KEYBOARD_KEY_STATE_RELEASED;
971                 notify = 1;
972         }
973
974         if (notify) {
975                 full_code = code;
976                 if (flags & KBD_FLAGS_EXTENDED)
977                         full_code |= KBD_FLAGS_EXTENDED;
978
979                 vk_code = GetVirtualKeyCodeFromVirtualScanCode(full_code, 4);
980                 if(flags & KBD_FLAGS_EXTENDED)
981                         vk_code |= KBDEXT;
982
983                 scan_code = GetKeycodeFromVirtualKeyCode(vk_code, KEYCODE_TYPE_EVDEV);
984
985                 /*weston_log("code=%x ext=%d vk_code=%x scan_code=%x\n", code, (flags & KBD_FLAGS_EXTENDED) ? 1 : 0,
986                                 vk_code, scan_code);*/
987                 notify_key(&peerContext->item.seat, weston_compositor_get_time(),
988                                         scan_code - 8, keyState, STATE_UPDATE_AUTOMATIC);
989         }
990 }
991
992 static void
993 xf_input_unicode_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
994 {
995         weston_log("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
996 }
997
998
999 static void
1000 xf_suppress_output(rdpContext *context, BYTE allow, RECTANGLE_16 *area) {
1001         RdpPeerContext *peerContext = (RdpPeerContext *)context;
1002         if (allow)
1003                 peerContext->item.flags |= RDP_PEER_OUTPUT_ENABLED;
1004         else
1005                 peerContext->item.flags &= (~RDP_PEER_OUTPUT_ENABLED);
1006 }
1007
1008 static int
1009 rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
1010 {
1011         int rcount = 0;
1012         void *rfds[MAX_FREERDP_FDS];
1013         int i, fd;
1014         struct wl_event_loop *loop;
1015         rdpSettings     *settings;
1016         rdpInput *input;
1017         RdpPeerContext *peerCtx;
1018         char seat_name[32];
1019
1020         client->ContextSize = sizeof(RdpPeerContext);
1021         client->ContextNew = (psPeerContextNew)rdp_peer_context_new;
1022         client->ContextFree = (psPeerContextFree)rdp_peer_context_free;
1023         freerdp_peer_context_new(client);
1024
1025         peerCtx = (RdpPeerContext *) client->context;
1026         peerCtx->rdpCompositor = c;
1027
1028         settings = client->settings;
1029         settings->RdpKeyFile = c->rdp_key;
1030         if (c->tls_enabled) {
1031                 settings->CertificateFile = c->server_cert;
1032                 settings->PrivateKeyFile = c->server_key;
1033         } else {
1034                 settings->TlsSecurity = FALSE;
1035         }
1036
1037         settings->NlaSecurity = FALSE;
1038
1039         client->Capabilities = xf_peer_capabilities;
1040         client->PostConnect = xf_peer_post_connect;
1041         client->Activate = xf_peer_activate;
1042
1043         client->update->SuppressOutput = xf_suppress_output;
1044
1045         input = client->input;
1046         input->SynchronizeEvent = xf_input_synchronize_event;
1047         input->MouseEvent = xf_mouseEvent;
1048         input->ExtendedMouseEvent = xf_extendedMouseEvent;
1049         input->KeyboardEvent = xf_input_keyboard_event;
1050         input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event;
1051
1052         if (snprintf(seat_name, 32, "rdp:%d:%s", client->sockfd, client->hostname) >= 32)
1053                 seat_name[31] = '\0';
1054
1055         weston_seat_init(&peerCtx->item.seat, &c->base, seat_name);
1056
1057         client->Initialize(client);
1058
1059         if (!client->GetFileDescriptor(client, rfds, &rcount)) {
1060                 weston_log("unable to retrieve client fds\n");
1061                 return -1;
1062         }
1063
1064         loop = wl_display_get_event_loop(c->base.wl_display);
1065         for(i = 0; i < rcount; i++) {
1066                 fd = (int)(long)(rfds[i]);
1067
1068                 peerCtx->events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
1069                                 rdp_client_activity, client);
1070         }
1071         for ( ; i < MAX_FREERDP_FDS; i++)
1072                 peerCtx->events[i] = 0;
1073
1074         wl_list_insert(&c->output->peers, &peerCtx->item.link);
1075         return 0;
1076 }
1077
1078
1079 static void
1080 rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
1081 {
1082         struct rdp_compositor *c = (struct rdp_compositor *)instance->param4;
1083         if (rdp_peer_init(client, c) < 0)
1084                 return;
1085 }
1086
1087 static struct weston_compositor *
1088 rdp_compositor_create(struct wl_display *display,
1089                 struct rdp_compositor_config *config,
1090                 int *argc, char *argv[], struct weston_config *wconfig)
1091 {
1092         struct rdp_compositor *c;
1093         char *fd_str;
1094         int fd;
1095
1096         c = zalloc(sizeof *c);
1097         if (c == NULL)
1098                 return NULL;
1099
1100         if (weston_compositor_init(&c->base, display, argc, argv, wconfig) < 0)
1101                 goto err_free;
1102
1103         c->base.destroy = rdp_destroy;
1104         c->base.restore = rdp_restore;
1105         c->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;
1106         c->no_clients_resize = config->no_clients_resize;
1107
1108         /* activate TLS only if certificate/key are available */
1109         if (config->server_cert && config->server_key) {
1110                 weston_log("TLS support activated\n");
1111                 c->server_cert = strdup(config->server_cert);
1112                 c->server_key = strdup(config->server_key);
1113                 if (!c->server_cert || !c->server_key)
1114                         goto err_free_strings;
1115                 c->tls_enabled = 1;
1116         }
1117
1118         if (pixman_renderer_init(&c->base) < 0)
1119                 goto err_compositor;
1120
1121         if (rdp_compositor_create_output(c, config->width, config->height) < 0)
1122                 goto err_compositor;
1123
1124         c->base.capabilities |= WESTON_CAP_ARBITRARY_MODES;
1125
1126         if(!config->env_socket) {
1127                 c->listener = freerdp_listener_new();
1128                 c->listener->PeerAccepted = rdp_incoming_peer;
1129                 c->listener->param4 = c;
1130                 if (!c->listener->Open(c->listener, config->bind_address, config->port)) {
1131                         weston_log("unable to bind rdp socket\n");
1132                         goto err_listener;
1133                 }
1134
1135                 if (rdp_implant_listener(c, c->listener) < 0)
1136                         goto err_compositor;
1137         } else {
1138                 /* get the socket from RDP_FD var */
1139                 fd_str = getenv("RDP_FD");
1140                 if (!fd_str) {
1141                         weston_log("RDP_FD env variable not set");
1142                         goto err_output;
1143                 }
1144
1145                 fd = strtoul(fd_str, NULL, 10);
1146                 if (rdp_peer_init(freerdp_peer_new(fd), c))
1147                         goto err_output;
1148         }
1149
1150         return &c->base;
1151
1152 err_listener:
1153         freerdp_listener_free(c->listener);
1154 err_output:
1155         weston_output_destroy(&c->output->base);
1156 err_compositor:
1157         weston_compositor_shutdown(&c->base);
1158 err_free_strings:
1159         if (c->rdp_key)
1160                 free(c->rdp_key);
1161         if (c->server_cert)
1162                 free(c->server_cert);
1163         if (c->server_key)
1164                 free(c->server_key);
1165 err_free:
1166         free(c);
1167         return NULL;
1168 }
1169
1170 WL_EXPORT struct weston_compositor *
1171 backend_init(struct wl_display *display, int *argc, char *argv[],
1172              struct weston_config *wconfig)
1173 {
1174         struct rdp_compositor_config config;
1175         rdp_compositor_config_init(&config);
1176         int major, minor, revision;
1177
1178         freerdp_get_version(&major, &minor, &revision);
1179         weston_log("using FreeRDP version %d.%d.%d\n", major, minor, revision);
1180
1181         const struct weston_option rdp_options[] = {
1182                 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1183                 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
1184                 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
1185                 { WESTON_OPTION_STRING,  "address", 0, &config.bind_address },
1186                 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1187                 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1188                 { WESTON_OPTION_STRING,  "rdp4-key", 0, &config.rdp_key },
1189                 { WESTON_OPTION_STRING,  "rdp-tls-cert", 0, &config.server_cert },
1190                 { WESTON_OPTION_STRING,  "rdp-tls-key", 0, &config.server_key }
1191         };
1192
1193         parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1194         return rdp_compositor_create(display, &config, argc, argv, wconfig);
1195 }