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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
|
/*
* Remmina - The GTK+ Remote Desktop Client
* Copyright (C) 2009-2011 Vic Lee
* Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
* Copyright (C) 2016-2018 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.
*
*/
#include "config.h"
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <glib/gi18n.h>
#include <stdlib.h>
#include "remmina_chat_window.h"
#include "remmina_masterthread_exec.h"
#include "remmina_ext_exec.h"
#include "remmina_plugin_manager.h"
#include "remmina_pref.h"
#include "remmina_protocol_widget.h"
#include "remmina_public.h"
#include "remmina_ssh.h"
#include "remmina_log.h"
#include "remmina/remmina_trace_calls.h"
struct _RemminaProtocolWidgetPriv {
RemminaFile* remmina_file;
RemminaProtocolPlugin* plugin;
RemminaProtocolFeature* features;
gint width;
gint height;
RemminaScaleMode scalemode;
gboolean scaler_expand;
gboolean has_error;
gchar* error_message;
RemminaSSHTunnel* ssh_tunnel;
RemminaTunnelInitFunc init_func;
GtkWidget* chat_window;
gboolean closed;
RemminaHostkeyFunc hostkey_func;
gint profile_remote_width;
gint profile_remote_height;
/* Data saved from the last message_panel when the user confirm */
gchar *username;
gchar *password;
gchar *domain;
gboolean save_password;
gchar *cacert;
gchar *cacrl;
gchar *clientcert;
gchar *clientkey;
};
G_DEFINE_TYPE(RemminaProtocolWidget, remmina_protocol_widget, GTK_TYPE_EVENT_BOX)
enum {
CONNECT_SIGNAL,
DISCONNECT_SIGNAL,
DESKTOP_RESIZE_SIGNAL,
UPDATE_ALIGN_SIGNAL,
UNLOCK_DYNRES_SIGNAL,
LAST_SIGNAL
};
typedef struct _RemminaProtocolWidgetSignalData {
RemminaProtocolWidget* gp;
const gchar* signal_name;
} RemminaProtocolWidgetSignalData;
static guint remmina_protocol_widget_signals[LAST_SIGNAL] =
{ 0 };
static void remmina_protocol_widget_class_init(RemminaProtocolWidgetClass *klass)
{
TRACE_CALL(__func__);
remmina_protocol_widget_signals[CONNECT_SIGNAL] = g_signal_new("connect", G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET(RemminaProtocolWidgetClass, connect), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
remmina_protocol_widget_signals[DISCONNECT_SIGNAL] = g_signal_new("disconnect", G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET(RemminaProtocolWidgetClass, disconnect), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
remmina_protocol_widget_signals[DESKTOP_RESIZE_SIGNAL] = g_signal_new("desktop-resize", G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET(RemminaProtocolWidgetClass, desktop_resize), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
remmina_protocol_widget_signals[UPDATE_ALIGN_SIGNAL] = g_signal_new("update-align", G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET(RemminaProtocolWidgetClass, update_align), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
remmina_protocol_widget_signals[UNLOCK_DYNRES_SIGNAL] = g_signal_new("unlock-dynres", G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET(RemminaProtocolWidgetClass, unlock_dynres), NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}
static void remmina_protocol_widget_destroy(RemminaProtocolWidget* gp, gpointer data)
{
TRACE_CALL(__func__);
remmina_connection_object_hide_message_panel(gp->cnnobj);
g_free(gp->priv->username);
gp->priv->username = NULL;
g_free(gp->priv->password);
gp->priv->password = NULL;
g_free(gp->priv->domain);
gp->priv->domain = NULL;
g_free(gp->priv->cacert);
gp->priv->cacert = NULL;
g_free(gp->priv->cacrl);
gp->priv->cacrl = NULL;
g_free(gp->priv->clientcert);
gp->priv->clientcert = NULL;
g_free(gp->priv->clientkey);
gp->priv->clientkey = NULL;
g_free(gp->priv->features);
gp->priv->features = NULL;
g_free(gp->priv->error_message);
gp->priv->error_message = NULL;
g_free(gp->priv->remmina_file);
gp->priv->remmina_file = NULL;
g_free(gp->priv);
gp->priv = NULL;
}
static void remmina_protocol_widget_connect(RemminaProtocolWidget* gp, gpointer data)
{
TRACE_CALL(__func__);
#ifdef HAVE_LIBSSH
if (gp->priv->ssh_tunnel) {
remmina_ssh_tunnel_cancel_accept(gp->priv->ssh_tunnel);
}
#endif
remmina_connection_object_hide_message_panel(gp->cnnobj);
}
static void remmina_protocol_widget_disconnect(RemminaProtocolWidget* gp, gpointer data)
{
TRACE_CALL(__func__);
remmina_connection_object_hide_message_panel(gp->cnnobj);
}
void remmina_protocol_widget_grab_focus(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
GtkWidget* child;
child = gtk_bin_get_child(GTK_BIN(gp));
if (child) {
gtk_widget_set_can_focus(child, TRUE);
gtk_widget_grab_focus(child);
}
}
static void remmina_protocol_widget_init(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
RemminaProtocolWidgetPriv *priv;
priv = g_new0(RemminaProtocolWidgetPriv, 1);
gp->priv = priv;
g_signal_connect(G_OBJECT(gp), "destroy", G_CALLBACK(remmina_protocol_widget_destroy), NULL);
g_signal_connect(G_OBJECT(gp), "connect", G_CALLBACK(remmina_protocol_widget_connect), NULL);
g_signal_connect(G_OBJECT(gp), "disconnect", G_CALLBACK(remmina_protocol_widget_disconnect), NULL);
}
void remmina_protocol_widget_open_connection_real(gpointer data)
{
TRACE_CALL(__func__);
RemminaProtocolWidget* gp = REMMINA_PROTOCOL_WIDGET(data);
RemminaProtocolPlugin *plugin;
RemminaProtocolFeature* feature;
gint num_plugin;
gint num_ssh;
plugin = gp->priv->plugin;
plugin->init(gp);
for (num_plugin = 0, feature = (RemminaProtocolFeature*)plugin->features; feature && feature->type; num_plugin++, feature++) {
}
num_ssh = 0;
#ifdef HAVE_LIBSSH
if (remmina_file_get_int(gp->priv->remmina_file, "ssh_enabled", FALSE)) {
num_ssh += 2;
}
#endif
if (num_plugin + num_ssh == 0) {
gp->priv->features = NULL;
}else {
gp->priv->features = g_new0(RemminaProtocolFeature, num_plugin + num_ssh + 1);
feature = gp->priv->features;
if (plugin->features) {
memcpy(feature, plugin->features, sizeof(RemminaProtocolFeature) * num_plugin);
feature += num_plugin;
}
#ifdef HAVE_LIBSSH
if (num_ssh) {
feature->type = REMMINA_PROTOCOL_FEATURE_TYPE_TOOL;
feature->id = REMMINA_PROTOCOL_FEATURE_TOOL_SSH;
feature->opt1 = _("Open Secure Shell in New Terminal...");
feature->opt2 = "utilities-terminal";
feature++;
feature->type = REMMINA_PROTOCOL_FEATURE_TYPE_TOOL;
feature->id = REMMINA_PROTOCOL_FEATURE_TOOL_SFTP;
feature->opt1 = _("Open Secure File Transfer...");
feature->opt2 = "folder-remote";
feature++;
}
feature->type = REMMINA_PROTOCOL_FEATURE_TYPE_END;
#endif
}
if (!plugin->open_connection(gp)) {
remmina_protocol_widget_close_connection(gp);
}
}
void remmina_protocol_widget_open_connection(RemminaProtocolWidget* gp, RemminaFile* remminafile)
{
TRACE_CALL(__func__);
gchar *s;
const gchar *name;
RemminaMessagePanel *mp;
gp->priv->remmina_file = remminafile;
gp->priv->scalemode = remmina_file_get_int(remminafile, "scale", FALSE);
gp->priv->scaler_expand = remmina_file_get_int(remminafile, "scaler_expand", FALSE);
/* Exec precommand before everything else */
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, _("Executing external commands..."));
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
remmina_ext_exec_new(remminafile, "precommand");
name = remmina_file_get_string(remminafile, "name");
s = g_strdup_printf(_("Connecting to '%s'..."), (name ? name : "*"));
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, s);
g_free(s);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
remmina_protocol_widget_open_connection_real(gp);
}
gboolean remmina_protocol_widget_close_connection(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
GdkDisplay *display;
#if GTK_CHECK_VERSION(3, 20, 0)
GdkSeat *seat;
#else
GdkDeviceManager *manager;
#endif
GdkDevice *device = NULL;
gboolean retval;
if (!GTK_IS_WIDGET(gp) || gp->priv->closed)
return FALSE;
gp->priv->closed = TRUE;
display = gtk_widget_get_display(GTK_WIDGET(gp));
#if GTK_CHECK_VERSION(3, 20, 0)
seat = gdk_display_get_default_seat(display);
device = gdk_seat_get_pointer(seat);
#else
manager = gdk_display_get_device_manager(display);
device = gdk_device_manager_get_client_pointer(manager);
#endif
if (device != NULL) {
#if GTK_CHECK_VERSION(3, 20, 0)
gdk_seat_ungrab(seat);
#else
gdk_device_ungrab(device, GDK_CURRENT_TIME);
#endif
}
if (gp->priv->chat_window) {
gtk_widget_destroy(gp->priv->chat_window);
gp->priv->chat_window = NULL;
}
if (!gp->priv->plugin || !gp->priv->plugin->close_connection) {
remmina_protocol_widget_emit_signal(gp, "disconnect");
return FALSE;
}
retval = gp->priv->plugin->close_connection(gp);
#ifdef HAVE_LIBSSH
if (gp->priv->ssh_tunnel) {
remmina_ssh_tunnel_free(gp->priv->ssh_tunnel);
gp->priv->ssh_tunnel = NULL;
}
#endif
/* Exec postcommand before to close the connection */
remmina_ext_exec_new(gp->priv->remmina_file, "postcommand");
return retval;
}
/** Check if the plugin accepts keystrokes.
*/
gboolean remmina_protocol_widget_plugin_receives_keystrokes(RemminaProtocolWidget* gp)
{
return gp->priv->plugin->send_keystrokes ? TRUE : FALSE;
}
/**
* Send to the plugin some keystrokes.
*/
void remmina_protocol_widget_send_keystrokes(RemminaProtocolWidget* gp, GtkMenuItem *widget)
{
TRACE_CALL(__func__);
gchar *keystrokes = g_object_get_data(G_OBJECT(widget), "keystrokes");
guint *keyvals;
gint i;
GdkKeymap *keymap = gdk_keymap_get_for_display(gdk_display_get_default());
gchar *iter = keystrokes;
gunichar character;
guint keyval;
GdkKeymapKey *keys;
gint n_keys;
/* Single keystroke replace */
typedef struct _KeystrokeReplace {
gchar *search;
gchar *replace;
guint keyval;
} KeystrokeReplace;
/* Special characters to replace */
KeystrokeReplace keystrokes_replaces[] =
{
{ "\\n", "\n", GDK_KEY_Return },
{ "\\t", "\t", GDK_KEY_Tab },
{ "\\b", "\b", GDK_KEY_BackSpace },
{ "\\e", "\e", GDK_KEY_Escape },
{ "\\\\", "\\", GDK_KEY_backslash },
{ NULL, NULL, 0 }
};
/* Keystrokes can be sent only to plugins that accepts them */
if (remmina_protocol_widget_plugin_receives_keystrokes(gp)) {
/* Replace special characters */
for (i = 0; keystrokes_replaces[i].replace; i++) {
remmina_public_str_replace_in_place(keystrokes,
keystrokes_replaces[i].search,
keystrokes_replaces[i].replace);
}
keyvals = (guint*)g_malloc(strlen(keystrokes));
while (TRUE) {
/* Process each character in the keystrokes */
character = g_utf8_get_char_validated(iter, -1);
if (character == 0)
break;
keyval = gdk_unicode_to_keyval(character);
/* Replace all the special character with its keyval */
for (i = 0; keystrokes_replaces[i].replace; i++) {
if (character == keystrokes_replaces[i].replace[0]) {
keys = g_new0(GdkKeymapKey, 1);
keyval = keystrokes_replaces[i].keyval;
/* A special character was generated, no keyval lookup needed */
character = 0;
break;
}
}
/* Decode character if it's not a special character */
if (character) {
/* get keyval without modifications */
if (!gdk_keymap_get_entries_for_keyval(keymap, keyval, &keys, &n_keys)) {
g_warning("keyval 0x%04x has no keycode!", keyval);
iter = g_utf8_find_next_char(iter, NULL);
continue;
}
}
/* Add modifier keys */
n_keys = 0;
if (keys->level & 1)
keyvals[n_keys++] = GDK_KEY_Shift_L;
if (keys->level & 2)
keyvals[n_keys++] = GDK_KEY_Alt_R;
keyvals[n_keys++] = keyval;
/* Send keystroke to the plugin */
gp->priv->plugin->send_keystrokes(gp, keyvals, n_keys);
g_free(keys);
/* Process next character in the keystrokes */
iter = g_utf8_find_next_char(iter, NULL);
}
g_free(keyvals);
}
g_free(keystrokes);
return;
}
gboolean remmina_protocol_widget_plugin_screenshot(RemminaProtocolWidget* gp, RemminaPluginScreenshotData *rpsd)
{
if (!gp->priv->plugin->get_plugin_screenshot) {
remmina_log_printf("plugin screenshot function is not implemented\n");
return FALSE;
}
return gp->priv->plugin->get_plugin_screenshot(gp, rpsd);
}
void remmina_protocol_widget_emit_signal(RemminaProtocolWidget* gp, const gchar* signal_name)
{
TRACE_CALL(__func__);
if ( !remmina_masterthread_exec_is_main_thread() ) {
/* Allow the execution of this function from a non main thread */
RemminaMTExecData *d;
d = (RemminaMTExecData*)g_malloc( sizeof(RemminaMTExecData) );
d->func = FUNC_PROTOCOLWIDGET_EMIT_SIGNAL;
d->p.protocolwidget_emit_signal.signal_name = signal_name;
d->p.protocolwidget_emit_signal.gp = gp;
remmina_masterthread_exec_and_wait(d);
g_free(d);
return;
}
g_signal_emit_by_name(G_OBJECT(gp), signal_name);
}
const RemminaProtocolFeature* remmina_protocol_widget_get_features(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->features;
}
const gchar* remmina_protocol_widget_get_domain(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->plugin->domain;
}
gboolean remmina_protocol_widget_query_feature_by_type(RemminaProtocolWidget* gp, RemminaProtocolFeatureType type)
{
TRACE_CALL(__func__);
const RemminaProtocolFeature *feature;
#ifdef HAVE_LIBSSH
if (type == REMMINA_PROTOCOL_FEATURE_TYPE_TOOL &&
remmina_file_get_int(gp->priv->remmina_file, "ssh_enabled", FALSE)) {
return TRUE;
}
#endif
for (feature = gp->priv->plugin->features; feature && feature->type; feature++) {
if (feature->type == type)
return TRUE;
}
return FALSE;
}
gboolean remmina_protocol_widget_query_feature_by_ref(RemminaProtocolWidget* gp, const RemminaProtocolFeature *feature)
{
TRACE_CALL(__func__);
return gp->priv->plugin->query_feature(gp, feature);
}
void remmina_protocol_widget_call_feature_by_type(RemminaProtocolWidget* gp, RemminaProtocolFeatureType type, gint id)
{
TRACE_CALL(__func__);
const RemminaProtocolFeature *feature;
for (feature = gp->priv->plugin->features; feature && feature->type; feature++) {
if (feature->type == type && (id == 0 || feature->id == id)) {
remmina_protocol_widget_call_feature_by_ref(gp, feature);
break;
}
}
}
void remmina_protocol_widget_call_feature_by_ref(RemminaProtocolWidget* gp, const RemminaProtocolFeature *feature)
{
TRACE_CALL(__func__);
switch (feature->id) {
#ifdef HAVE_LIBSSH
case REMMINA_PROTOCOL_FEATURE_TOOL_SSH:
if (gp->priv->ssh_tunnel) {
remmina_connection_window_open_from_file_full(
remmina_file_dup_temp_protocol(gp->priv->remmina_file, "SSH"), NULL, gp->priv->ssh_tunnel, NULL);
return;
}
break;
case REMMINA_PROTOCOL_FEATURE_TOOL_SFTP:
if (gp->priv->ssh_tunnel) {
remmina_connection_window_open_from_file_full(
remmina_file_dup_temp_protocol(gp->priv->remmina_file, "SFTP"), NULL, gp->priv->ssh_tunnel, NULL);
return;
}
break;
#endif
default:
break;
}
gp->priv->plugin->call_feature(gp, feature);
}
static gboolean remmina_protocol_widget_on_key_press(GtkWidget *widget, GdkEventKey *event, RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
if (gp->priv->hostkey_func) {
return gp->priv->hostkey_func(gp, event->keyval, FALSE);
}
return FALSE;
}
static gboolean remmina_protocol_widget_on_key_release(GtkWidget *widget, GdkEventKey *event, RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
if (gp->priv->hostkey_func) {
return gp->priv->hostkey_func(gp, event->keyval, TRUE);
}
return FALSE;
}
void remmina_protocol_widget_register_hostkey(RemminaProtocolWidget* gp, GtkWidget *widget)
{
TRACE_CALL(__func__);
g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(remmina_protocol_widget_on_key_press), gp);
g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(remmina_protocol_widget_on_key_release), gp);
}
void remmina_protocol_widget_set_hostkey_func(RemminaProtocolWidget* gp, RemminaHostkeyFunc func)
{
TRACE_CALL(__func__);
gp->priv->hostkey_func = func;
}
#ifdef HAVE_LIBSSH
static gboolean remmina_protocol_widget_init_tunnel(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
RemminaSSHTunnel *tunnel;
gint ret;
gchar* msg;
RemminaMessagePanel* mp;
/* Reuse existing SSH connection if it's reconnecting to destination */
if (gp->priv->ssh_tunnel == NULL) {
tunnel = remmina_ssh_tunnel_new_from_file(gp->priv->remmina_file);
msg = g_strdup_printf(_("Connecting to SSH server %s..."), REMMINA_SSH(tunnel)->server);
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, msg);
g_free(msg);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
if (!remmina_ssh_init_session(REMMINA_SSH(tunnel))) {
remmina_protocol_widget_set_error(gp, REMMINA_SSH(tunnel)->error);
remmina_ssh_tunnel_free(tunnel);
return FALSE;
}
ret = remmina_ssh_auth_gui(REMMINA_SSH(tunnel), gp->cnnobj, gp->priv->remmina_file);
if (ret <= 0) {
if (ret == 0) {
remmina_protocol_widget_set_error(gp, REMMINA_SSH(tunnel)->error);
}
remmina_ssh_tunnel_free(tunnel);
return FALSE;
}
gp->priv->ssh_tunnel = tunnel;
}
return TRUE;
}
#endif
/**
* Start an SSH tunnel if possible and return the host:port string.
*
*/
gchar* remmina_protocol_widget_start_direct_tunnel(RemminaProtocolWidget* gp, gint default_port, gboolean port_plus)
{
TRACE_CALL(__func__);
const gchar *server;
gchar *host, *dest;
gint port;
gchar *msg;
RemminaMessagePanel *mp;
server = remmina_file_get_string(gp->priv->remmina_file, "server");
if (!server) {
return g_strdup("");
}
remmina_public_get_server_port(server, default_port, &host, &port);
if (port_plus && port < 100) {
/* Protocols like VNC supports using instance number :0, :1, etc as port number. */
port += default_port;
}
#ifdef HAVE_LIBSSH
if (!remmina_file_get_int(gp->priv->remmina_file, "ssh_enabled", FALSE)) {
dest = g_strdup_printf("[%s]:%i", host, port);
g_free(host);
return dest;
}
/* If we have a previous ssh tunnel, destroy it */
if (gp->priv->ssh_tunnel) {
remmina_ssh_tunnel_free(gp->priv->ssh_tunnel);
gp->priv->ssh_tunnel = NULL;
}
if (!remmina_protocol_widget_init_tunnel(gp)) {
g_free(host);
return NULL;
}
msg = g_strdup_printf(_("Connecting to %s through SSH tunnel..."), server);
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, msg);
g_free(msg);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
if (remmina_file_get_int(gp->priv->remmina_file, "ssh_loopback", FALSE)) {
g_free(host);
host = g_strdup("127.0.0.1");
}
if (!remmina_ssh_tunnel_open(gp->priv->ssh_tunnel, host, port, remmina_pref.sshtunnel_port)) {
g_free(host);
remmina_protocol_widget_set_error(gp, REMMINA_SSH(gp->priv->ssh_tunnel)->error);
return NULL;
}
g_free(host);
return g_strdup_printf("127.0.0.1:%i", remmina_pref.sshtunnel_port);
#else
dest = g_strdup_printf("[%s]:%i", host, port);
g_free(host);
return dest;
#endif
}
gboolean remmina_protocol_widget_start_reverse_tunnel(RemminaProtocolWidget* gp, gint local_port)
{
TRACE_CALL(__func__);
#ifdef HAVE_LIBSSH
gchar *msg;
RemminaMessagePanel *mp;
if (!remmina_file_get_int(gp->priv->remmina_file, "ssh_enabled", FALSE)) {
return TRUE;
}
if (!remmina_protocol_widget_init_tunnel(gp)) {
return FALSE;
}
msg = g_strdup_printf(_("Waiting for an incoming SSH tunnel at port %i..."), remmina_file_get_int(gp->priv->remmina_file, "listenport", 0));
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, msg);
g_free(msg);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
if (!remmina_ssh_tunnel_reverse(gp->priv->ssh_tunnel, remmina_file_get_int(gp->priv->remmina_file, "listenport", 0), local_port)) {
remmina_protocol_widget_set_error(gp, REMMINA_SSH(gp->priv->ssh_tunnel)->error);
return FALSE;
}
#endif
return TRUE;
}
gboolean remmina_protocol_widget_ssh_exec(RemminaProtocolWidget* gp, gboolean wait, const gchar *fmt, ...)
{
TRACE_CALL(__func__);
#ifdef HAVE_LIBSSH
RemminaSSHTunnel *tunnel = gp->priv->ssh_tunnel;
ssh_channel channel;
gint status;
gboolean ret = FALSE;
gchar *cmd, *ptr;
va_list args;
if ((channel = ssh_channel_new(REMMINA_SSH(tunnel)->session)) == NULL) {
return FALSE;
}
va_start(args, fmt);
cmd = g_strdup_vprintf(fmt, args);
va_end(args);
if (ssh_channel_open_session(channel) == SSH_OK &&
ssh_channel_request_exec(channel, cmd) == SSH_OK) {
if (wait) {
ssh_channel_send_eof(channel);
status = ssh_channel_get_exit_status(channel);
ptr = strchr(cmd, ' ');
if (ptr) *ptr = '\0';
switch (status) {
case 0:
ret = TRUE;
break;
case 127:
remmina_ssh_set_application_error(REMMINA_SSH(tunnel),
_("Command %s not found on SSH server"), cmd);
break;
default:
remmina_ssh_set_application_error(REMMINA_SSH(tunnel),
_("Command %s failed on SSH server (status = %i)."), cmd, status);
break;
}
}else {
ret = TRUE;
}
}else {
remmina_ssh_set_error(REMMINA_SSH(tunnel), _("Failed to execute command: %s"));
}
g_free(cmd);
if (wait)
ssh_channel_close(channel);
ssh_channel_free(channel);
return ret;
#else
return FALSE;
#endif
}
#ifdef HAVE_LIBSSH
static gboolean remmina_protocol_widget_tunnel_init_callback(RemminaSSHTunnel *tunnel, gpointer data)
{
TRACE_CALL(__func__);
RemminaProtocolWidget* gp = REMMINA_PROTOCOL_WIDGET(data);
gchar *server;
gint port;
gboolean ret;
remmina_public_get_server_port(remmina_file_get_string(gp->priv->remmina_file, "server"), 177, &server, &port);
ret = ((RemminaXPortTunnelInitFunc)gp->priv->init_func)(gp,
tunnel->remotedisplay, (tunnel->bindlocalhost ? "localhost" : server), port);
g_free(server);
return ret;
}
static gboolean remmina_protocol_widget_tunnel_connect_callback(RemminaSSHTunnel* tunnel, gpointer data)
{
TRACE_CALL(__func__);
return TRUE;
}
static gboolean remmina_protocol_widget_tunnel_disconnect_callback(RemminaSSHTunnel* tunnel, gpointer data)
{
TRACE_CALL(__func__);
RemminaProtocolWidget* gp = REMMINA_PROTOCOL_WIDGET(data);
if (REMMINA_SSH(tunnel)->error) {
remmina_protocol_widget_set_error(gp, "%s", REMMINA_SSH(tunnel)->error);
}
IDLE_ADD((GSourceFunc)remmina_protocol_widget_close_connection, gp);
return TRUE;
}
#endif
gboolean remmina_protocol_widget_start_xport_tunnel(RemminaProtocolWidget* gp, RemminaXPortTunnelInitFunc init_func)
{
TRACE_CALL(__func__);
#ifdef HAVE_LIBSSH
gboolean bindlocalhost;
gchar *server;
gchar *msg;
RemminaMessagePanel *mp;
if (!remmina_protocol_widget_init_tunnel(gp)) return FALSE;
msg = g_strdup_printf(_("Connecting to %s through SSH tunnel..."), remmina_file_get_string(gp->priv->remmina_file, "server"));
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, msg);
g_free(msg);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
gp->priv->init_func = init_func;
gp->priv->ssh_tunnel->init_func = remmina_protocol_widget_tunnel_init_callback;
gp->priv->ssh_tunnel->connect_func = remmina_protocol_widget_tunnel_connect_callback;
gp->priv->ssh_tunnel->disconnect_func = remmina_protocol_widget_tunnel_disconnect_callback;
gp->priv->ssh_tunnel->callback_data = gp;
remmina_public_get_server_port(remmina_file_get_string(gp->priv->remmina_file, "server"), 0, &server, NULL);
bindlocalhost = (g_strcmp0(REMMINA_SSH(gp->priv->ssh_tunnel)->server, server) == 0);
g_free(server);
if (!remmina_ssh_tunnel_xport(gp->priv->ssh_tunnel, bindlocalhost)) {
remmina_protocol_widget_set_error(gp, "Failed to open channel : %s",
ssh_get_error(REMMINA_SSH(gp->priv->ssh_tunnel)->session));
return FALSE;
}
return TRUE;
#else
return FALSE;
#endif
}
void remmina_protocol_widget_set_display(RemminaProtocolWidget* gp, gint display)
{
TRACE_CALL(__func__);
#ifdef HAVE_LIBSSH
if (gp->priv->ssh_tunnel->localdisplay) g_free(gp->priv->ssh_tunnel->localdisplay);
gp->priv->ssh_tunnel->localdisplay = g_strdup_printf("unix:%i", display);
#endif
}
gint remmina_protocol_widget_get_profile_remote_width(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
/* Returns the width of remote desktop as choosen by the user profile */
return gp->priv->profile_remote_width;
}
gint remmina_protocol_widget_get_profile_remote_height(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
/* Returns the height of remote desktop as choosen by the user profile */
return gp->priv->profile_remote_height;
}
gint remmina_protocol_widget_get_width(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->width;
}
void remmina_protocol_widget_set_width(RemminaProtocolWidget* gp, gint width)
{
TRACE_CALL(__func__);
gp->priv->width = width;
}
gint remmina_protocol_widget_get_height(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->height;
}
void remmina_protocol_widget_set_height(RemminaProtocolWidget* gp, gint height)
{
TRACE_CALL(__func__);
gp->priv->height = height;
}
RemminaScaleMode remmina_protocol_widget_get_current_scale_mode(RemminaProtocolWidget *gp)
{
TRACE_CALL(__func__);
return gp->priv->scalemode;
}
void remmina_protocol_widget_set_current_scale_mode(RemminaProtocolWidget *gp, RemminaScaleMode scalemode)
{
TRACE_CALL(__func__);
gp->priv->scalemode = scalemode;
}
gboolean remmina_protocol_widget_get_expand(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->scaler_expand;
}
void remmina_protocol_widget_set_expand(RemminaProtocolWidget* gp, gboolean expand)
{
TRACE_CALL(__func__);
gp->priv->scaler_expand = expand;
return;
}
gboolean remmina_protocol_widget_has_error(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->has_error;
}
const gchar* remmina_protocol_widget_get_error_message(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->error_message;
}
void remmina_protocol_widget_set_error(RemminaProtocolWidget* gp, const gchar *fmt, ...)
{
TRACE_CALL(__func__);
va_list args;
if (gp->priv->error_message) g_free(gp->priv->error_message);
if (fmt == NULL) {
gp->priv->has_error = FALSE;
gp->priv->error_message = NULL;
return;
}
va_start(args, fmt);
gp->priv->error_message = g_strdup_vprintf(fmt, args);
va_end(args);
gp->priv->has_error = TRUE;
}
gboolean remmina_protocol_widget_is_closed(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->closed;
}
RemminaFile* remmina_protocol_widget_get_file(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return gp->priv->remmina_file;
}
gint remmina_protocol_widget_init_authpwd(RemminaProtocolWidget* gp, RemminaAuthpwdType authpwd_type, gboolean allow_password_saving)
{
TRACE_CALL(__func__);
RemminaFile* remminafile = gp->priv->remmina_file;
gchar* s;
gint ret;
RemminaMessagePanel* mp;
unsigned pflags;
switch (authpwd_type) {
case REMMINA_AUTHPWD_TYPE_PROTOCOL:
s = g_strdup_printf(_("%s password"), remmina_file_get_string(remminafile, "protocol"));
break;
case REMMINA_AUTHPWD_TYPE_SSH_PWD:
s = g_strdup(_("SSH password"));
break;
case REMMINA_AUTHPWD_TYPE_SSH_PRIVKEY:
s = g_strdup(_("SSH private key passphrase"));
break;
default:
s = g_strdup(_("Password"));
break;
}
mp = remmina_message_panel_new();
/* ToDo: init mp with username, password, and checkbox */
pflags = 0;
if (!remminafile->prevent_saving && allow_password_saving)
pflags |= REMMINA_MESSAGE_PANEL_FLAG_SAVEPASSRORD;
remmina_message_panel_setup_auth(mp, s, pflags);
g_free(s);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
ret = remmina_message_panel_wait_user_answer(mp);
/* ToDo: take parameters from mp and save in gp->priv->password */
g_clear_object(&mp);
return ret;
}
gint remmina_protocol_widget_init_authuserpwd(RemminaProtocolWidget* gp, gboolean want_domain, gboolean allow_password_saving)
{
TRACE_CALL(__func__);
RemminaFile* remminafile = gp->priv->remmina_file;
unsigned pflags;
RemminaMessagePanel* mp;
gint ret;
pflags = REMMINA_MESSAGE_PANEL_FLAG_USERNAME;
if (remmina_file_get_filename(remminafile) != NULL &&
!remminafile->prevent_saving && allow_password_saving)
pflags |= REMMINA_MESSAGE_PANEL_FLAG_SAVEPASSRORD;
if (want_domain)
pflags |= REMMINA_MESSAGE_PANEL_FLAG_DOMAIN;
mp = remmina_message_panel_new();
/* ToDo: init mp with username, password, domain (if want_domain) and checkbox */
remmina_message_panel_setup_auth(mp, _("Enter authentication credentials"), pflags);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
ret = remmina_message_panel_wait_user_answer(mp);
/* ToDo: take parameters from mp and save in gp->priv->username/password/domain */
g_clear_object(&mp);
return ret;
/* Original code:
return remmina_init_dialog_authuserpwd(
REMMINA_INIT_DIALOG(gp->priv->init_dialog),
want_domain,
remmina_file_get_string(remminafile, "username"),
want_domain ? remmina_file_get_string(remminafile, "domain") : NULL,
(remmina_file_get_filename(remminafile) != NULL &&
!remminafile->prevent_saving && allow_password_saving));
*
*/
}
gint remmina_protocol_widget_init_certificate(RemminaProtocolWidget* gp, const gchar* subject, const gchar* issuer, const gchar* fingerprint)
{
TRACE_CALL(__func__);
RemminaMessagePanel* mp;
gint ret;
mp = remmina_message_panel_new();
remmina_message_panel_setup_cert(mp, subject, issuer, fingerprint, NULL);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
ret = remmina_message_panel_wait_user_answer(mp);
g_clear_object(&mp);
return ret;
}
gint remmina_protocol_widget_changed_certificate(RemminaProtocolWidget *gp, const gchar* subject, const gchar* issuer, const gchar* new_fingerprint, const gchar* old_fingerprint)
{
TRACE_CALL(__func__);
RemminaMessagePanel* mp;
gint ret;
mp = remmina_message_panel_new();
remmina_message_panel_setup_cert(mp, subject, issuer, new_fingerprint, old_fingerprint);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
ret = remmina_message_panel_wait_user_answer(mp);
g_clear_object(&mp);
return ret;
}
gchar* remmina_protocol_widget_init_get_username(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return g_strdup(gp->priv->username);
}
gchar* remmina_protocol_widget_init_get_password(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return g_strdup(gp->priv->password);
}
gchar* remmina_protocol_widget_init_get_domain(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
return g_strdup(gp->priv->domain);
}
gboolean remmina_protocol_widget_init_get_savepassword(RemminaProtocolWidget *gp)
{
TRACE_CALL(__func__);
return gp->priv->save_password;
}
gint remmina_protocol_widget_init_authx509(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
RemminaFile* remminafile = gp->priv->remmina_file;
RemminaMessagePanel *mp;
gint ret;
mp = remmina_message_panel_new();
remmina_message_panel_setup_auth_x509(mp,
remmina_file_get_string(remminafile, "cacert"), remmina_file_get_string(remminafile, "cacrl"),
remmina_file_get_string(remminafile, "clientcert"), remmina_file_get_string(remminafile, "clientkey"));
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
ret = remmina_message_panel_wait_user_answer(mp);
/* ToDo: save cacert, cacrl, clientcert, clientkey into apposite gp->priv-> strings */
g_clear_object(&mp);
return ret;
}
gchar* remmina_protocol_widget_init_get_cacert(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
gchar* s;
s = gp->priv->cacert;
return (s && s[0] ? g_strdup(s) : NULL);
}
gchar* remmina_protocol_widget_init_get_cacrl(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
gchar* s;
s = gp->priv->cacrl;
return (s && s[0] ? g_strdup(s) : NULL);
}
gchar* remmina_protocol_widget_init_get_clientcert(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
gchar* s;
s = gp->priv->clientcert;
return (s && s[0] ? g_strdup(s) : NULL);
}
gchar* remmina_protocol_widget_init_get_clientkey(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
gchar* s;
s = gp->priv->clientkey;
return (s && s[0] ? g_strdup(s) : NULL);
}
void remmina_protocol_widget_init_save_cred(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
RemminaFile* remminafile = gp->priv->remmina_file;
gchar* s;
gboolean save = FALSE;
if ( !remmina_masterthread_exec_is_main_thread() ) {
/* Allow the execution of this function from a non main thread */
RemminaMTExecData *d;
d = (RemminaMTExecData*)g_malloc( sizeof(RemminaMTExecData) );
d->func = FUNC_INIT_SAVE_CRED;
d->p.init_save_creds.gp = gp;
remmina_masterthread_exec_and_wait(d);
g_free(d);
return;
}
/* Save user name and certificates if any; save the password if it's requested to do so */
s = gp->priv->username;
if (s && s[0]) {
remmina_file_set_string(remminafile, "username", s);
save = TRUE;
}
s = gp->priv->cacert;
if (s && s[0]) {
remmina_file_set_string(remminafile, "cacert", s);
save = TRUE;
}
s = gp->priv->cacrl;
if (s && s[0]) {
remmina_file_set_string(remminafile, "cacrl", s);
save = TRUE;
}
s = gp->priv->clientcert;
if (s && s[0]) {
remmina_file_set_string(remminafile, "clientcert", s);
save = TRUE;
}
s = gp->priv->clientkey;
if (s && s[0]) {
remmina_file_set_string(remminafile, "clientkey", s);
save = TRUE;
}
if (gp->priv->save_password) {
remmina_file_set_string(remminafile, "password", gp->priv->password);
save = TRUE;
}
if (save) {
remmina_file_save(remminafile);
}
}
void remmina_protocol_widget_init_show_listen(RemminaProtocolWidget* gp, gint port)
{
TRACE_CALL(__func__);
RemminaMessagePanel *mp;
gchar* s;
mp = remmina_message_panel_new();
s = g_strdup_printf(
_("Listening on port %i for an incoming %s connection..."), port,
remmina_file_get_string(gp->priv->remmina_file, "protocol"));
remmina_message_panel_setup_progress(mp, s);
g_free(s);
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
}
void remmina_protocol_widget_init_show_retry(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
RemminaMessagePanel *mp;
mp = remmina_message_panel_new();
remmina_message_panel_setup_progress(mp, _("Authentication failed. Trying to reconnect..."));
remmina_connection_object_show_message_panel(gp->cnnobj, mp);
}
void remmina_protocol_widget_init_show(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
printf("REMMINA: error, function %s is not implemented\n", __func__);
}
void remmina_protocol_widget_init_hide(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
remmina_connection_object_hide_message_panel(gp->cnnobj);
}
static void remmina_protocol_widget_chat_on_destroy(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
gp->priv->chat_window = NULL;
}
void remmina_protocol_widget_chat_open(RemminaProtocolWidget* gp, const gchar *name,
void (*on_send)(RemminaProtocolWidget* gp, const gchar *text), void (*on_destroy)(RemminaProtocolWidget* gp))
{
TRACE_CALL(__func__);
if (gp->priv->chat_window) {
gtk_window_present(GTK_WINDOW(gp->priv->chat_window));
}else {
gp->priv->chat_window = remmina_chat_window_new(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(gp))), name);
g_signal_connect_swapped(G_OBJECT(gp->priv->chat_window), "send", G_CALLBACK(on_send), gp);
g_signal_connect_swapped(G_OBJECT(gp->priv->chat_window), "destroy",
G_CALLBACK(remmina_protocol_widget_chat_on_destroy), gp);
g_signal_connect_swapped(G_OBJECT(gp->priv->chat_window), "destroy", G_CALLBACK(on_destroy), gp);
gtk_widget_show(gp->priv->chat_window);
}
}
void remmina_protocol_widget_chat_close(RemminaProtocolWidget* gp)
{
TRACE_CALL(__func__);
if (gp->priv->chat_window) {
gtk_widget_destroy(gp->priv->chat_window);
}
}
void remmina_protocol_widget_chat_receive(RemminaProtocolWidget* gp, const gchar* text)
{
TRACE_CALL(__func__);
/* This function can be called from a non main thread */
if (gp->priv->chat_window) {
if ( !remmina_masterthread_exec_is_main_thread() ) {
/* Allow the execution of this function from a non main thread */
RemminaMTExecData *d;
d = (RemminaMTExecData*)g_malloc( sizeof(RemminaMTExecData) );
d->func = FUNC_CHAT_RECEIVE;
d->p.chat_receive.gp = gp;
d->p.chat_receive.text = text;
remmina_masterthread_exec_and_wait(d);
g_free(d);
return;
}
remmina_chat_window_receive(REMMINA_CHAT_WINDOW(gp->priv->chat_window), _("Server"), text);
gtk_window_present(GTK_WINDOW(gp->priv->chat_window));
}
}
void remmina_protocol_widget_setup(RemminaProtocolWidget *gp, RemminaFile* remminafile, RemminaConnectionObject* cnnobj)
{
RemminaProtocolPlugin *plugin;
gp->priv->remmina_file = remminafile;
gp->cnnobj = cnnobj;
/* Locate the protocol plugin */
plugin = (RemminaProtocolPlugin*)remmina_plugin_manager_get_plugin(REMMINA_PLUGIN_TYPE_PROTOCOL,
remmina_file_get_string(remminafile, "protocol"));
if (!plugin || !plugin->init || !plugin->open_connection) {
remmina_protocol_widget_set_error(gp, _("Protocol plugin %s is not installed."),
remmina_file_get_string(remminafile, "protocol"));
gp->priv->plugin = NULL;
return;
}
gp->priv->plugin = plugin;
}
GtkWidget* remmina_protocol_widget_new(void)
{
return GTK_WIDGET(g_object_new(REMMINA_TYPE_PROTOCOL_WIDGET, NULL));
}
/* Send one or more keystrokes to a specific widget by firing key-press and
* key-release events.
* GdkEventType action can be GDK_KEY_PRESS or GDK_KEY_RELEASE or both to
* press the keys and release them in reversed order. */
void remmina_protocol_widget_send_keys_signals(GtkWidget *widget, const guint *keyvals, int keyvals_length, GdkEventType action)
{
TRACE_CALL(__func__);
int i;
GdkEventKey event;
gboolean result;
GdkKeymap *keymap = gdk_keymap_get_for_display(gdk_display_get_default());
event.window = gtk_widget_get_window(widget);
event.send_event = TRUE;
event.time = GDK_CURRENT_TIME;
event.state = 0;
event.length = 0;
event.string = "";
event.group = 0;
if (action & GDK_KEY_PRESS) {
/* Press the requested buttons */
event.type = GDK_KEY_PRESS;
for (i = 0; i < keyvals_length; i++) {
event.keyval = keyvals[i];
event.hardware_keycode = remmina_public_get_keycode_for_keyval(keymap, event.keyval);
event.is_modifier = (int)remmina_public_get_modifier_for_keycode(keymap, event.hardware_keycode);
g_signal_emit_by_name(G_OBJECT(widget), "key-press-event", &event, &result);
}
}
if (action & GDK_KEY_RELEASE) {
/* Release the requested buttons in reverse order */
event.type = GDK_KEY_RELEASE;
for (i = (keyvals_length - 1); i >= 0; i--) {
event.keyval = keyvals[i];
event.hardware_keycode = remmina_public_get_keycode_for_keyval(keymap, event.keyval);
event.is_modifier = (int)remmina_public_get_modifier_for_keycode(keymap, event.hardware_keycode);
g_signal_emit_by_name(G_OBJECT(widget), "key-release-event", &event, &result);
}
}
}
void remmina_protocol_widget_update_remote_resolution(RemminaProtocolWidget* gp, gint w, gint h)
{
TRACE_CALL(__func__);
GdkDisplay *display;
#if GTK_CHECK_VERSION(3, 20, 0)
/** @todo rename to "seat" */
GdkSeat *seat;
GdkDevice *device;
#else
GdkDeviceManager *device_manager;
GdkDevice *device;
#endif
GdkScreen *screen;
#if GTK_CHECK_VERSION(3, 22, 0)
GdkMonitor *monitor;
#else
gint monitor;
#endif
gint x, y;
GdkRectangle rect;
if (w <= 0 || h <= 0) {
display = gdk_display_get_default();
/* gdk_display_get_device_manager deprecated since 3.20, Use gdk_display_get_default_seat */
#if GTK_CHECK_VERSION(3, 20, 0)
seat = gdk_display_get_default_seat(display);
device = gdk_seat_get_pointer(seat);
#else
device_manager = gdk_display_get_device_manager(display);
device = gdk_device_manager_get_client_pointer(device_manager);
#endif
gdk_device_get_position(device, &screen, &x, &y);
#if GTK_CHECK_VERSION(3, 22, 0)
monitor = gdk_display_get_monitor_at_point(display, x, y);
gdk_monitor_get_geometry(monitor, &rect);
#else
monitor = gdk_screen_get_monitor_at_point(screen, x, y);
gdk_screen_get_monitor_geometry(screen, monitor, &rect);
#endif
w = rect.width;
h = rect.height;
}
gp->priv->profile_remote_width = w;
gp->priv->profile_remote_height = h;
}
|