Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rdp_plugin.h « rdp « plugins - gitlab.com/Remmina/Remmina.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9dfa56d8789a4274c745df3b46c647eab8034e3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*
 * Remmina - The GTK+ Remote Desktop Client
 * Copyright (C) 2010-2011 Vic Lee
 * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
 * Copyright (C) 2016-2023 Antenore Gatta, Giovanni Panozzo
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 *  In addition, as a special exception, the copyright holders give
 *  permission to link the code of portions of this program with the
 *  OpenSSL library under certain conditions as described in each
 *  individual source file, and distribute linked combinations
 *  including the two.
 *  You must obey the GNU General Public License in all respects
 *  for all of the code used other than OpenSSL. *  If you modify
 *  file(s) with this exception, you may extend this exception to your
 *  version of the file(s), but you are not obligated to do so. *  If you
 *  do not wish to do so, delete this exception statement from your
 *  version. *  If you delete this exception statement from all source
 *  files in the program, then also delete it here.
 *
 */

#pragma once

#include "common/remmina_plugin.h"
#include <freerdp/freerdp.h>
#include <freerdp/version.h>
#include <freerdp/channels/channels.h>
#include <freerdp/codec/color.h>
#include <freerdp/codec/rfx.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/gdi/dc.h>
#include <freerdp/gdi/region.h>
#include <freerdp/client/cliprdr.h>
#include <freerdp/client/disp.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#elif defined(GDK_WINDOWING_WAYLAND)
#include <gdk/gdkwayland.h>
#endif

#include <winpr/clipboard.h>

/**
 * FREERDP_CHECK_VERSION:
 * @major: major version (e.g. 2 for version 2.1.0)
 * @minor: minor version (e.g. 0 for version 2.1.0)
 * @release: release version (e.g. 0 for version 2.1.0)
 *
 * Returns %TRUE if the version of the FRERDDP header files
 * is the same as or newer than the passed-in version.
 *
 * Returns: %TRUE if FREERDP headers are new enough
 */
#define FREERDP_CHECK_VERSION(major,minor,revision)                           \
	(FREERDP_VERSION_MAJOR > (major) ||                                       \
	 (FREERDP_VERSION_MAJOR == (major) && FREERDP_VERSION_MINOR > (minor)) || \
	 (FREERDP_VERSION_MAJOR == (major) && FREERDP_VERSION_MINOR == (minor) && \
	  FREERDP_VERSION_REVISION >= (revision)))

/**
 * Constants to workaround FreeRDP issue #5417 (min resolution in AVC mode)
 * Must be 4 aligned (multiple of 4).
 * We should instead check destRect and be sure the condition is met
 * See https://gitlab.com/Remmina/Remmina/-/issues/2507 for a deep discussion
 */
#define AVC_MIN_DESKTOP_WIDTH 644
#define AVC_MIN_DESKTOP_HEIGHT 480

typedef struct rf_context rfContext;

#define GET_PLUGIN_DATA(gp) (rfContext *)g_object_get_data(G_OBJECT(gp), "plugin-data")

/**
 * Performance Flags, from FreeRDP source
 *
 * PERF_FLAG_NONE 0x00000000
 * PERF_DISABLE_WALLPAPER 0x00000001
 * PERF_DISABLE_FULLWINDOWDRAG 0x00000002
 * PERF_DISABLE_MENUANIMATIONS 0x00000004
 * PERF_DISABLE_THEMING 0x00000008
 * PERF_DISABLE_CURSOR_SHADOW 0x00000020
 * PERF_DISABLE_CURSORSETTINGS 0x00000040
 * PERF_ENABLE_FONT_SMOOTHING 0x00000080
 * PERF_ENABLE_DESKTOP_COMPOSITION 0x00000100
 */
/* Poor (default) - all disabled */
#define DEFAULT_QUALITY_0       0x6f
/* Medium - only THEMING, CURSOR_SHADOW and CURSORSETTINGS enabled, all other disabled */
#define DEFAULT_QUALITY_1       0x07
/* Good - WALLPAPER, FONT_SMOOTHING, DESKTOP_COMPOSITION disabled, all other enabled */
#define DEFAULT_QUALITY_2       0x01
/* Best - DESKTOP_COMPOSITION disabled, all other enabled */
#define DEFAULT_QUALITY_9       0x80

extern RemminaPluginService *remmina_plugin_service;

#define REMMINA_PLUGIN_INFO(fmt, ...) \
		remmina_plugin_service->_remmina_info(__func__, fmt, ##__VA_ARGS__)

#define REMMINA_PLUGIN_MESSAGE(fmt, ...) \
		remmina_plugin_service->_remmina_message(__func, fmt, ##__VA_ARGS__)

#define REMMINA_PLUGIN_DEBUG(fmt, ...) \
		remmina_plugin_service->_remmina_debug(__func__, fmt, ##__VA_ARGS__)

#define REMMINA_PLUGIN_WARNING(fmt, ...) \
		remmina_plugin_service->_remmina_warning(__func__, fmt, ##__VA_ARGS__)

/* This will intentionally crash Remmina */
#define REMMINA_PLUGIN_ERROR(fmt, ...) \
		remmina_plugin_service->_remmina_error(__func__, fmt, ##__VA_ARGS__)

#define REMMINA_PLUGIN_CRITICAL(fmt, ...) \
		remmina_plugin_service->_remmina_critical(__func__, fmt, ##__VA_ARGS__)
#define REMMINA_PLUGIN_AUDIT(fmt, ...) \
		remmina_plugin_service->_remmina_audit(__func__, fmt, ##__VA_ARGS__)

struct rf_clipboard {
	rfContext *		rfi;
	CliprdrClientContext *	context;
	wClipboard *		system;
	int			requestedFormatId;

	UINT32			format;
	gulong			clipboard_handler;

	pthread_mutex_t		transfer_clip_mutex;
	pthread_cond_t		transfer_clip_cond;
	enum  { SCDW_NONE, SCDW_BUSY_WAIT, SCDW_ABORTING } srv_clip_data_wait;
	gpointer		srv_data;
	pthread_mutex_t	srv_data_mutex;

	UINT32			server_html_format_id;

	/* Stats for clipboard download */
	struct timeval clientformatdatarequest_tv;
};
typedef struct rf_clipboard rfClipboard;


struct rf_pointer {
	rdpPointer	pointer;
	GdkCursor *	cursor;
};
typedef struct rf_pointer rfPointer;

#ifdef RF_BITMAP
struct rf_bitmap {
	rdpBitmap		bitmap;
	Pixmap			pixmap;
	cairo_surface_t *	surface;
};
typedef struct rf_bitmap rfBitmap;
#endif

#ifdef RF_GLYPH
struct rf_glyph {
	rdpGlyph	glyph;
	Pixmap		pixmap;
};
typedef struct rf_glyph rfGlyph;
#endif

typedef enum {
	REMMINA_RDP_EVENT_TYPE_SCANCODE,
	REMMINA_RDP_EVENT_TYPE_SCANCODE_UNICODE,
	REMMINA_RDP_EVENT_TYPE_MOUSE,
	REMMINA_RDP_EVENT_TYPE_CLIPBOARD_SEND_CLIENT_FORMAT_LIST,
	REMMINA_RDP_EVENT_TYPE_CLIPBOARD_SEND_CLIENT_FORMAT_DATA_RESPONSE,
	REMMINA_RDP_EVENT_TYPE_CLIPBOARD_SEND_CLIENT_FORMAT_DATA_REQUEST,
	REMMINA_RDP_EVENT_TYPE_SEND_MONITOR_LAYOUT,
	REMMINA_RDP_EVENT_DISCONNECT
} RemminaPluginRdpEventType;

struct remmina_plugin_rdp_event {
	RemminaPluginRdpEventType type;
	union {
		struct {
			BOOL	up;
			BOOL	extended;
			UINT8	key_code;
			UINT32	unicode_code;
		} key_event;
		struct {
			UINT16	flags;
			UINT16	x;
			UINT16	y;
			BOOL	extended;
		} mouse_event;
		struct {
			CLIPRDR_FORMAT_LIST *pFormatList;
		} clipboard_formatlist;
		struct {
			BYTE *	data;
			int	size;
		} clipboard_formatdataresponse;
		struct {
			CLIPRDR_FORMAT_DATA_REQUEST *pFormatDataRequest;
		} clipboard_formatdatarequest;
		struct {
			gint    Flags;
			gint    Left;
			gint    Top;
			gint	width;
			gint	height;
			gint	desktopOrientation;
			gint	desktopScaleFactor;
			gint	deviceScaleFactor;
			gint    physicalWidth;
			gint    physicalHeight;
		} monitor_layout;
	};
};
typedef struct remmina_plugin_rdp_event RemminaPluginRdpEvent;

typedef enum {
	REMMINA_RDP_UI_UPDATE_REGIONS = 0,
	REMMINA_RDP_UI_CONNECTED,
	REMMINA_RDP_UI_RECONNECT_PROGRESS,
	REMMINA_RDP_UI_CURSOR,
	REMMINA_RDP_UI_NOCODEC,
	REMMINA_RDP_UI_CLIPBOARD,
	REMMINA_RDP_UI_EVENT
} RemminaPluginRdpUiType;

typedef enum {
	REMMINA_RDP_UI_CLIPBOARD_FORMATLIST,
	REMMINA_RDP_UI_CLIPBOARD_GET_DATA,
	REMMINA_RDP_UI_CLIPBOARD_SET_DATA
} RemminaPluginRdpUiClipboardType;

typedef enum {
	REMMINA_RDP_POINTER_NEW,
	REMMINA_RDP_POINTER_FREE,
	REMMINA_RDP_POINTER_SET,
	REMMINA_RDP_POINTER_NULL,
	REMMINA_RDP_POINTER_DEFAULT,
	REMMINA_RDP_POINTER_SETPOS
} RemminaPluginRdpUiPointerType;

typedef enum {
	REMMINA_RDP_UI_EVENT_UPDATE_SCALE,
	REMMINA_RDP_UI_EVENT_DESTROY_CAIRO_SURFACE
} RemminaPluginRdpUiEeventType;

typedef struct {
	gint x, y, w, h;
} region;

struct remmina_plugin_rdp_ui_object {
	RemminaPluginRdpUiType	type;
	gboolean		sync;
	gboolean		complete;
	pthread_mutex_t		sync_wait_mutex;
	pthread_cond_t		sync_wait_cond;
	union {
		struct {
			region *ureg;
			gint	ninvalid;
		} reg;
		struct {
			rdpContext *			context;
			rfPointer *			pointer;
			RemminaPluginRdpUiPointerType	type;
		} cursor;
		struct {
			gint		left;
			gint		top;
			RFX_MESSAGE *	message;
		} rfx;
		struct {
			gint	left;
			gint	top;
			gint	width;
			gint	height;
			UINT8 * bitmap;
		} nocodec;
		struct {
			RemminaPluginRdpUiClipboardType type;
			GtkTargetList *			targetlist;
			UINT32				format;
			rfClipboard *			clipboard;
			gpointer			data;
		} clipboard;
		struct {
			RemminaPluginRdpUiEeventType type;
		} event;
		struct {
			gint	x;
			gint	y;
		} pos;
	};
	/* We can also return values here, usually integers*/
	int	retval;
	/* Some functions also may return a pointer. */
	void *	retptr;
};

typedef struct remmina_plugin_rdp_keymap_entry {
	unsigned	orig_keycode;
	unsigned	translated_keycode;
} RemminaPluginRdpKeymapEntry;

struct rf_context {
	rdpContext		context;
	DEFINE_RDP_CLIENT_COMMON();

	RemminaProtocolWidget * protocol_widget;

	/* main */
	rdpSettings *		settings;
	freerdp *		instance;

	pthread_t		remmina_plugin_thread;
	RemminaScaleMode	scale;
	gboolean		user_cancelled;
	gboolean		thread_cancelled;

	CliprdrClientContext *	cliprdr;
	DispClientContext *	dispcontext;

	RDP_PLUGIN_DATA		rdpdr_data[5];
	RDP_PLUGIN_DATA		drdynvc_data[5];
	gchar			rdpsnd_options[20];

	gboolean		rdpgfxchan;

	gboolean		connected;
	gboolean		is_reconnecting;
	gboolean		stop_reconnecting_requested;
	/* orphaned: rf_context has still one or more libfreerdp thread active,
	 * but no longer maintained by an open RemminaProtocolWidget/tab.
	 * When the orphaned thread terminates, we must cleanup rf_context.
	 */
	gboolean		orphaned;
	int			reconnect_maxattempts;
	int			reconnect_nattempt;

	gboolean		sw_gdi;
	GtkWidget *		drawing_area;
	gint			scale_width;
	gint			scale_height;
	gdouble			scale_x;
	gdouble			scale_y;
	guint			delayed_monitor_layout_handler;
	gboolean		use_client_keymap;

	gint			srcBpp;
	GdkDisplay *		display;
	GdkVisual *		visual;
	cairo_surface_t *	surface;
	cairo_format_t		cairo_format;
	gint			bpp;
	gint			scanline_pad;
	gint *			colormap;

	guint			object_id_seq;
	GHashTable *		object_table;

	GAsyncQueue *		ui_queue;
	pthread_mutex_t		ui_queue_mutex;
	guint			ui_handler;

	GArray *		pressed_keys;
	GAsyncQueue *		event_queue;
	gint			event_pipe[2];
	HANDLE			event_handle;
	UINT16         	last_x;
	UINT16         	last_y;

	rfClipboard		clipboard;

	GArray *		keymap; /* Array of RemminaPluginRdpKeymapEntry */

	gboolean		attempt_interactive_authentication;

	enum { REMMINA_POSTCONNECT_ERROR_OK = 0, REMMINA_POSTCONNECT_ERROR_GDI_INIT = 1, REMMINA_POSTCONNECT_ERROR_NO_H264 } postconnect_error;
};

typedef struct remmina_plugin_rdp_ui_object RemminaPluginRdpUiObject;

void rf_init(RemminaProtocolWidget *gp);
void rf_uninit(RemminaProtocolWidget *gp);
void rf_get_fds(RemminaProtocolWidget *gp, void **rfds, int *rcount);
BOOL rf_check_fds(RemminaProtocolWidget *gp);
void rf_object_free(RemminaProtocolWidget *gp, RemminaPluginRdpUiObject *obj);

void remmina_rdp_event_event_push(RemminaProtocolWidget *gp, const RemminaPluginRdpEvent *e);