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
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
|
/* $Id: VBoxGuestR3LibClipboard.cpp $ */
/** @file
* VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Shared Clipboard.
*/
/*
* Copyright (C) 2007-2023 Oracle and/or its affiliates.
*
* This file is part of VirtualBox base platform packages, as
* available from https://www.virtualbox.org.
*
* 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, in version 3 of the
* License.
*
* 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, see <https://www.gnu.org/licenses>.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
* in the VirtualBox distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#include <VBox/GuestHost/SharedClipboard.h>
#include <VBox/GuestHost/clipboard-helper.h>
#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
# include <VBox/GuestHost/SharedClipboard-transfers.h>
#endif
#include <VBox/HostServices/VBoxClipboardSvc.h>
#include <VBox/err.h>
#include <iprt/assert.h>
#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
# include <iprt/dir.h>
# include <iprt/file.h>
# include <iprt/path.h>
#endif
#include <iprt/string.h>
#include <iprt/cpp/ministring.h>
#include "VBoxGuestR3LibInternal.h"
/*
* Function naming convention:
*
* FunctionNameRecv = Receives a host message (request).
* FunctionNameReply = Replies to a host message (request).
* FunctionNameSend = Sends a guest message to the host.
*/
/*********************************************************************************************************************************
* Prototypes *
*********************************************************************************************************************************/
/**
* Connects to the Shared Clipboard service, legacy version, do not use anymore.
*
* @returns VBox status code
* @param pidClient Where to put the client id on success. The client id
* must be passed to all the other clipboard calls.
*/
VBGLR3DECL(int) VbglR3ClipboardConnect(HGCMCLIENTID *pidClient)
{
int rc = VbglR3HGCMConnect("VBoxSharedClipboard", pidClient);
if (RT_FAILURE(rc))
{
if (rc == VERR_HGCM_SERVICE_NOT_FOUND)
LogRel(("Shared Clipboard: Unabled to connect, as host service was not found, skipping\n"));
else
LogRel(("Shared Clipboard: Unabled to connect to host service, rc=%Rrc\n", rc));
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Connects to the Shared Clipboard service, extended version.
*
* @returns VBox status code.
* @param pCtx Command context. This will be initialized by this
* call.
* @param fGuestFeatures The guest features supported by this client,
* VBOX_SHCL_GF_0_XXX.
*/
VBGLR3DECL(int) VbglR3ClipboardConnectEx(PVBGLR3SHCLCMDCTX pCtx, uint64_t fGuestFeatures)
{
/*
* Intialize the context structure.
*/
pCtx->idClient = 0;
pCtx->fGuestFeatures = fGuestFeatures;
pCtx->fHostFeatures = 0;
pCtx->fUseLegacyProtocol = true;
pCtx->cParmsRecived = 0;
pCtx->idContext = 0;
#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
/* Init callback table. */
RT_ZERO(pCtx->Transfers.Callbacks);
/* Indicate that this guest supports Shared Clipboard file transfers. */
pCtx->fGuestFeatures |= VBOX_SHCL_GF_0_TRANSFERS;
# ifdef RT_OS_WINDOWS
/* Indicate that on Windows guest OSes we have our own IDataObject implementation which
* integrates nicely into the guest's Windows Explorer showing / handling the Shared Clipboard file transfers. */
pCtx->fGuestFeatures |= VBOX_SHCL_GF_0_TRANSFERS_FRONTEND;
# endif
pCtx->Transfers.cbChunkSize = VBOX_SHCL_DEFAULT_CHUNK_SIZE; /** @todo Make this configurable. */
pCtx->Transfers.cbMaxChunkSize = VBOX_SHCL_MAX_CHUNK_SIZE; /** @todo Ditto. */
#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
/*
* First step is connecting to the HGCM service.
*/
int rc = VbglR3ClipboardConnect(&pCtx->idClient);
if (RT_SUCCESS(rc))
{
/*
* Next is reporting our features. If this fails, assume older host.
*/
rc = VbglR3ClipboardReportFeatures(pCtx->idClient, pCtx->fGuestFeatures, &pCtx->fHostFeatures);
if (RT_SUCCESS(rc))
{
LogRel2(("Shared Clipboard: Guest features: %#RX64 - Host features: %#RX64\n",
pCtx->fGuestFeatures, pCtx->fHostFeatures));
if ( (pCtx->fHostFeatures & VBOX_SHCL_HF_0_CONTEXT_ID)
&& (pCtx->fGuestFeatures & VBOX_SHCL_GF_0_CONTEXT_ID) )
{
pCtx->fUseLegacyProtocol = false;
#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
if ( (pCtx->fHostFeatures & VBOX_SHCL_HF_0_TRANSFERS)
&& (pCtx->fGuestFeatures & VBOX_SHCL_GF_0_TRANSFERS) )
{
VBoxShClParmNegotiateChunkSize MsgChunkSize;
do
{
VBGL_HGCM_HDR_INIT(&MsgChunkSize.hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_NEGOTIATE_CHUNK_SIZE,
VBOX_SHCL_CPARMS_NEGOTIATE_CHUNK_SIZE);
MsgChunkSize.cb32MaxChunkSize.SetUInt32(pCtx->Transfers.cbMaxChunkSize);
MsgChunkSize.cb32ChunkSize.SetUInt32(0); /* If set to 0, let the host choose. */
rc = VbglR3HGCMCall(&MsgChunkSize.hdr, sizeof(MsgChunkSize));
} while (rc == VERR_INTERRUPTED);
if (RT_SUCCESS(rc))
{
Assert(MsgChunkSize.cb32ChunkSize.type == VMMDevHGCMParmType_32bit);
pCtx->Transfers.cbChunkSize = RT_MIN(MsgChunkSize.cb32ChunkSize.u.value32, pCtx->Transfers.cbChunkSize);
Assert(MsgChunkSize.cb32MaxChunkSize.type == VMMDevHGCMParmType_32bit);
pCtx->Transfers.cbMaxChunkSize = RT_MIN(MsgChunkSize.cb32MaxChunkSize.u.value32, pCtx->Transfers.cbMaxChunkSize);
LogRel2(("Shared Clipboard: Using chunk size %RU32 (maximum is %RU32)\n",
pCtx->Transfers.cbChunkSize, pCtx->Transfers.cbMaxChunkSize));
}
}
else
{
if (!(pCtx->fHostFeatures & VBOX_SHCL_HF_0_TRANSFERS))
LogRel2(("Shared Clipboard: Host does not support transfers\n"));
}
#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
}
else
{
if (!(pCtx->fHostFeatures & VBOX_SHCL_HF_0_CONTEXT_ID))
LogRel(("Shared Clipboard: Host does not support context IDs, using legacy protocol\n"));
pCtx->fUseLegacyProtocol = true;
}
}
else
{
AssertLogRelMsg(rc == VERR_NOT_SUPPORTED || rc == VERR_NOT_IMPLEMENTED,
("Reporting features failed: %Rrc\n", rc));
pCtx->fUseLegacyProtocol = true;
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Reports features to the host and retrieve host feature set.
*
* @returns VBox status code.
* @param idClient The client ID returned by VbglR3ClipboardConnect().
* @param fGuestFeatures Features to report, VBOX_SHCL_GF_XXX.
* @param pfHostFeatures Where to store the features VBOX_SHCL_HF_XXX.
*/
VBGLR3DECL(int) VbglR3ClipboardReportFeatures(uint32_t idClient, uint64_t fGuestFeatures, uint64_t *pfHostFeatures)
{
int rc;
do
{
struct
{
VBGLIOCHGCMCALL Hdr;
HGCMFunctionParameter f64Features0;
HGCMFunctionParameter f64Features1;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, VBOX_SHCL_GUEST_FN_REPORT_FEATURES, 2);
VbglHGCMParmUInt64Set(&Msg.f64Features0, fGuestFeatures);
VbglHGCMParmUInt64Set(&Msg.f64Features1, VBOX_SHCL_GF_1_MUST_BE_ONE);
rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
Assert(Msg.f64Features0.type == VMMDevHGCMParmType_64bit);
Assert(Msg.f64Features1.type == VMMDevHGCMParmType_64bit);
if (Msg.f64Features1.u.value64 & VBOX_SHCL_GF_1_MUST_BE_ONE)
rc = VERR_NOT_SUPPORTED;
else if (pfHostFeatures)
*pfHostFeatures = Msg.f64Features0.u.value64;
break;
}
} while (rc == VERR_INTERRUPTED);
return rc;
}
/**
* Disconnects from the Shared Clipboard service, legacy version, do not use anymore.
*
* @returns VBox status code.
* @param idClient The client id returned by VbglR3ClipboardConnect().
*/
VBGLR3DECL(int) VbglR3ClipboardDisconnect(HGCMCLIENTID idClient)
{
return VbglR3HGCMDisconnect(idClient);
}
/**
* Disconnects from the Shared Clipboard service, extended version.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
*/
VBGLR3DECL(int) VbglR3ClipboardDisconnectEx(PVBGLR3SHCLCMDCTX pCtx)
{
int rc = VbglR3ClipboardDisconnect(pCtx->idClient);
if (RT_SUCCESS(rc))
{
pCtx->idClient = 0;
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives reported formats from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the
* connection.
* @param pfFormats Where to store the received formats from the host.
*/
static int vbglR3ClipboardFormatsReportRecv(PVBGLR3SHCLCMDCTX pCtx, PSHCLFORMATS pfFormats)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pfFormats, VERR_INVALID_POINTER);
*pfFormats = 0;
struct
{
VBGLIOCHGCMCALL Hdr;
HGCMFunctionParameter id64Context;
HGCMFunctionParameter f32Formats;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_MSG_GET, 2);
Msg.id64Context.SetUInt32(VBOX_SHCL_HOST_MSG_FORMATS_REPORT);
Msg.f32Formats.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.f32Formats.GetUInt32(pfFormats);
AssertRC(rc);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Fetches a VBOX_SHCL_HOST_MSG_READ_DATA_CID message.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pfFormat Where to return the requested format.
*/
static int vbglR3ClipboardFetchReadDataCid(PVBGLR3SHCLCMDCTX pCtx, PSHCLFORMAT pfFormat)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pfFormat, VERR_INVALID_POINTER);
struct
{
VBGLIOCHGCMCALL Hdr;
HGCMFunctionParameter id64Context;
HGCMFunctionParameter f32Format;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_MSG_GET, 2);
Msg.id64Context.SetUInt64(VBOX_SHCL_HOST_MSG_READ_DATA_CID);
Msg.f32Format.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.id64Context.GetUInt64(&pCtx->idContext);
AssertRC(rc);
int rc2 = Msg.f32Format.GetUInt32(pfFormat);
AssertRCStmt(rc2, rc = rc2);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Fetches a VBOX_SHCL_HOST_MSG_READ_DATA message.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pfFormat Where to return the requested format.
*/
static int vbglR3ClipboardFetchReadData(PVBGLR3SHCLCMDCTX pCtx, PSHCLFORMAT pfFormat)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pfFormat, VERR_INVALID_POINTER);
struct
{
VBGLIOCHGCMCALL Hdr;
HGCMFunctionParameter id32Msg;
HGCMFunctionParameter f32Format;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_MSG_GET, 2);
Msg.id32Msg.SetUInt32(VBOX_SHCL_HOST_MSG_READ_DATA);
Msg.f32Format.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.f32Format.GetUInt32(pfFormat);
AssertRC(rc);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Get a host message, legacy version (which does not have VBOX_SHCL_GUEST_FN_MSG_GET). Do not use anymore.
*
* Note: This is the old message which still is being used for the non-URI Shared Clipboard transfers,
* to not break compatibility with older additions / VBox versions.
*
* This will block until a message becomes available.
*
* @returns VBox status code.
* @param idClient The client id returned by VbglR3ClipboardConnect().
* @param pidMsg Where to store the message id.
* @param pfFormats Where to store the format(s) the message applies to.
*/
VBGLR3DECL(int) VbglR3ClipboardGetHostMsgOld(HGCMCLIENTID idClient, uint32_t *pidMsg, uint32_t *pfFormats)
{
VBoxShClGetHostMsgOld Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHCL_GUEST_FN_MSG_OLD_GET_WAIT, VBOX_SHCL_CPARMS_GET_HOST_MSG_OLD);
VbglHGCMParmUInt32Set(&Msg.msg, 0);
VbglHGCMParmUInt32Set(&Msg.formats, 0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
int rc2 = VbglHGCMParmUInt32Get(&Msg.msg, pidMsg);
if (RT_SUCCESS(rc))
{
rc2 = VbglHGCMParmUInt32Get(&Msg.formats, pfFormats);
if (RT_SUCCESS(rc2))
return rc;
}
rc = rc2;
}
*pidMsg = UINT32_MAX - 1;
*pfFormats = UINT32_MAX;
return rc;
}
/**
* Reads data from the host clipboard.
*
* Legacy function, do not use anymore.
*
* @returns VBox status code.
* @retval VINF_BUFFER_OVERFLOW If there is more data available than the caller provided buffer space for.
*
* @param idClient The client id returned by VbglR3ClipboardConnect().
* @param fFormat The format we're requesting the data in.
* @param pvData Where to store the data.
* @param cbData The size of the buffer pointed to by \a pvData.
* @param pcbRead The actual size of the host clipboard data. May be larger than \a cbData.
*/
VBGLR3DECL(int) VbglR3ClipboardReadData(HGCMCLIENTID idClient, uint32_t fFormat, void *pvData, uint32_t cbData,
uint32_t *pcbRead)
{
LogFlowFuncEnter();
struct
{
VBGLIOCHGCMCALL Hdr;
VBoxShClParmDataRead Parms;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, VBOX_SHCL_GUEST_FN_DATA_READ, VBOX_SHCL_CPARMS_DATA_READ);
VbglHGCMParmUInt32Set(&Msg.Parms.f32Format, fFormat);
VbglHGCMParmPtrSet( &Msg.Parms.pData, pvData, cbData);
VbglHGCMParmUInt32Set(&Msg.Parms.cb32Needed, 0);
int rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
uint32_t cbRead;
rc = VbglHGCMParmUInt32Get(&Msg.Parms.cb32Needed, &cbRead);
if (RT_SUCCESS(rc))
{
LogFlowFunc(("cbRead=%RU32\n", cbRead));
if (cbRead > cbData)
rc = VINF_BUFFER_OVERFLOW;
*pcbRead = cbRead;
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Reads clipboard data from the host clipboard.
*
* @returns VBox status code.
* @retval VINF_BUFFER_OVERFLOW If there is more data available than the caller provided buffer space for.
*
* @param pCtx The command context returned by VbglR3ClipboardConnectEx().
* @param uFormat Clipboard format of clipboard data to be read.
* @param pvData Buffer where to store the read data.
* @param cbData Size (in bytes) of data buffer where to store the read data.
* @param pcbRead The actual size of the host clipboard data.
*/
VBGLR3DECL(int) VbglR3ClipboardReadDataEx(PVBGLR3SHCLCMDCTX pCtx,
SHCLFORMAT uFormat, void *pvData, uint32_t cbData, uint32_t *pcbRead)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pvData, VERR_INVALID_POINTER);
return VbglR3ClipboardReadData(pCtx->idClient, uFormat, pvData, cbData, pcbRead);
}
/**
* Query the host features.
*
* @returns VBox status code.
* @param idClient The client ID returned by VbglR3ClipboardConnect().
* @param pfHostFeatures Where to store the host feature, VBOX_SHCL_HF_XXX.
*/
VBGLR3DECL(int) VbglR3ClipboardQueryFeatures(uint32_t idClient, uint64_t *pfHostFeatures)
{
int rc;
do
{
struct
{
VBGLIOCHGCMCALL Hdr;
HGCMFunctionParameter f64Features0;
HGCMFunctionParameter f64Features1;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, VBOX_SHCL_GUEST_FN_QUERY_FEATURES, 2);
VbglHGCMParmUInt64Set(&Msg.f64Features0, 0);
VbglHGCMParmUInt64Set(&Msg.f64Features1, RT_BIT_64(63));
rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
Assert(Msg.f64Features0.type == VMMDevHGCMParmType_64bit);
Assert(Msg.f64Features1.type == VMMDevHGCMParmType_64bit);
if (Msg.f64Features1.u.value64 & RT_BIT_64(63))
rc = VERR_NOT_SUPPORTED;
else if (pfHostFeatures)
*pfHostFeatures = Msg.f64Features0.u.value64;
break;
}
} while (rc == VERR_INTERRUPTED);
return rc;
}
/**
* Peeks at the next host message, waiting for one to turn up.
*
* This glosses over the difference between new (6.1) and old (1.3.2) host
* service versions, however it does so by abusing @a pcParameters, so don't use
* it directly when in legacy mode, always pass it on to
* VbglR3ClipboardEventGetNext() or VbglR3ClipboardEventGetNextEx().
*
* @returns VBox status code.
* @retval VERR_INTERRUPTED if interrupted. Does the necessary cleanup, so
* caller just have to repeat this call.
* @retval VERR_VM_RESTORED if the VM has been restored (idRestoreCheck).
*
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pidMsg Where to store the message id.
* @param pcParameters Where to store the number of parameters which will
* be received in a second call to the host.
* @param pidRestoreCheck Pointer to the VbglR3GetSessionId() variable to use
* for the VM restore check. Optional.
*
* @note Restore check is only performed optimally with a 6.0 host.
*/
VBGLR3DECL(int) VbglR3ClipboardMsgPeekWait(PVBGLR3SHCLCMDCTX pCtx, uint32_t *pidMsg,
uint32_t *pcParameters, uint64_t *pidRestoreCheck)
{
AssertPtrReturn(pidMsg, VERR_INVALID_POINTER);
AssertPtrReturn(pcParameters, VERR_INVALID_POINTER);
struct
{
VBGLIOCHGCMCALL Hdr;
HGCMFunctionParameter idMsg; /* Doubles as restore check on input. */
HGCMFunctionParameter cParameters;
} Msg;
int rc;
if (!pCtx->fUseLegacyProtocol)
{
VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT, 2);
VbglHGCMParmUInt64Set(&Msg.idMsg, pidRestoreCheck ? *pidRestoreCheck : 0);
VbglHGCMParmUInt32Set(&Msg.cParameters, 0);
rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
LogFlowFunc(("VbglR3HGCMCall -> %Rrc\n", rc));
if (RT_SUCCESS(rc))
{
AssertMsgReturn( Msg.idMsg.type == VMMDevHGCMParmType_64bit
&& Msg.cParameters.type == VMMDevHGCMParmType_32bit,
("msg.type=%d num_parms.type=%d\n", Msg.idMsg.type, Msg.cParameters.type),
VERR_INTERNAL_ERROR_3);
*pidMsg = (uint32_t)Msg.idMsg.u.value64;
*pcParameters = Msg.cParameters.u.value32;
return rc;
}
/*
* If restored, update pidRestoreCheck.
*/
if (rc == VERR_VM_RESTORED && pidRestoreCheck)
*pidRestoreCheck = Msg.idMsg.u.value64;
}
else
{
/*
* We do some crude stuff here by putting the 2nd parameter (foramts) in the parameter count,
* however it's supposed to be passed directly to VbglR3ClipboardEventGetNext or
* VbglR3ClipboardEventGetNextEx, so that's fine...
*/
rc = VbglR3ClipboardGetHostMsgOld(pCtx->idClient, pidMsg, pcParameters);
if (RT_SUCCESS(rc))
return rc;
}
/*
* If interrupted we must cancel the call so it doesn't prevent us from making another one.
*/
if (rc == VERR_INTERRUPTED)
{
VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_MSG_CANCEL, 0);
int rc2 = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg.Hdr));
AssertRC(rc2);
}
*pidMsg = UINT32_MAX - 1;
*pcParameters = UINT32_MAX - 2;
return rc;
}
#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
/**
* Reads a root list header from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pRootListHdr Where to store the received root list header.
*/
static int vbglR3ClipboardRootListHdrRead(PVBGLR3SHCLCMDCTX pCtx, PSHCLROOTLISTHDR pRootListHdr)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pRootListHdr, VERR_INVALID_POINTER);
VBoxShClRootListHdrMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ, VBOX_SHCL_CPARMS_ROOT_LIST_HDR_READ);
Msg.ReqParms.uContext.SetUInt64(pCtx->idContext);
Msg.ReqParms.fRoots.SetUInt32(0);
Msg.cRoots.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.fRoots.GetUInt32(&pRootListHdr->fRoots); AssertRC(rc);
if (RT_SUCCESS(rc))
{
rc = Msg.cRoots.GetUInt32(&pRootListHdr->cRoots);
AssertRC(rc);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Reads a root list entry from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param uIndex Index of root list entry to read.
* @param pRootListEntry Where to store the root list entry read from the host.
*/
static int vbglR3ClipboardRootListEntryRead(PVBGLR3SHCLCMDCTX pCtx, uint32_t uIndex, PSHCLROOTLISTENTRY pRootListEntry)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pRootListEntry, VERR_INVALID_POINTER);
VBoxShClRootListEntryMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_READ, VBOX_SHCL_CPARMS_ROOT_LIST_ENTRY_READ);
Msg.Parms.uContext.SetUInt64(pCtx->idContext);
Msg.Parms.fInfo.SetUInt32(pRootListEntry->fInfo);
Msg.Parms.uIndex.SetUInt32(uIndex);
Msg.szName.SetPtr(pRootListEntry->pszName, pRootListEntry->cbName);
Msg.cbInfo.SetUInt32(pRootListEntry->cbInfo);
Msg.pvInfo.SetPtr(pRootListEntry->pvInfo, pRootListEntry->cbInfo);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.Parms.fInfo.GetUInt32(&pRootListEntry->fInfo); AssertRC(rc);
if (RT_SUCCESS(rc))
{
uint32_t cbInfo = 0;
rc = Msg.cbInfo.GetUInt32(&cbInfo); AssertRC(rc);
if (pRootListEntry->cbInfo != cbInfo)
rc = VERR_INVALID_PARAMETER;
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Reads the root list from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param ppRootList Where to store the (allocated) root list. Must be free'd by the caller with
* SharedClipboardTransferRootListFree().
*/
VBGLR3DECL(int) VbglR3ClipboardRootListRead(PVBGLR3SHCLCMDCTX pCtx, PSHCLROOTLIST *ppRootList)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(ppRootList, VERR_INVALID_POINTER);
int rc;
PSHCLROOTLIST pRootList = ShClTransferRootListAlloc();
if (pRootList)
{
SHCLROOTLISTHDR srcRootListHdr;
rc = vbglR3ClipboardRootListHdrRead(pCtx, &srcRootListHdr);
if (RT_SUCCESS(rc))
{
pRootList->Hdr.cRoots = srcRootListHdr.cRoots;
pRootList->Hdr.fRoots = 0; /** @todo Implement this. */
if (srcRootListHdr.cRoots)
{
pRootList->paEntries =
(PSHCLROOTLISTENTRY)RTMemAllocZ(srcRootListHdr.cRoots * sizeof(SHCLROOTLISTENTRY));
if (pRootList->paEntries)
{
for (uint32_t i = 0; i < srcRootListHdr.cRoots; i++)
{
SHCLROOTLISTENTRY *pEntry = &pRootList->paEntries[i];
AssertPtr(pEntry);
rc = ShClTransferRootListEntryInit(pEntry);
if (RT_SUCCESS(rc))
rc = vbglR3ClipboardRootListEntryRead(pCtx, i, pEntry);
if (RT_FAILURE(rc))
break;
}
}
else
rc = VERR_NO_MEMORY;
}
}
if (RT_SUCCESS(rc))
{
*ppRootList = pRootList;
}
else
ShClTransferRootListFree(pRootList);
}
else
rc = VERR_NO_MEMORY;
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a transfer status from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pEnmDir Where to store the transfer direction for the reported transfer.
* @param pReport Where to store the transfer (status) report.
*/
VBGLR3DECL(int) VbglR3ClipboarTransferStatusRecv(PVBGLR3SHCLCMDCTX pCtx,
PSHCLTRANSFERDIR pEnmDir, PSHCLTRANSFERREPORT pReport)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pReport, VERR_INVALID_POINTER);
AssertPtrReturn(pEnmDir, VERR_INVALID_POINTER);
VBoxShClTransferStatusMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_TRANSFER_STATUS);
Msg.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_STATUS);
Msg.enmDir.SetUInt32(0);
Msg.enmStatus.SetUInt32(0);
Msg.rc.SetUInt32(0);
Msg.fFlags.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.uContext.GetUInt64(&pCtx->idContext); AssertRC(rc);
if (RT_SUCCESS(rc))
{
rc = Msg.enmDir.GetUInt32((uint32_t *)pEnmDir);
AssertRC(rc);
}
if (RT_SUCCESS(rc))
{
rc = Msg.enmStatus.GetUInt32(&pReport->uStatus);
AssertRC(rc);
}
if (RT_SUCCESS(rc))
{
rc = Msg.rc.GetUInt32((uint32_t *)&pReport->rc);
AssertRC(rc);
}
if (RT_SUCCESS(rc))
{
rc = Msg.fFlags.GetUInt32(&pReport->fFlags);
AssertRC(rc);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies to a transfer report from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pTransfer Transfer of report to reply to.
* @param uStatus Tranfer status to reply.
* @param rcTransfer Result code (rc) to reply.
*/
VBGLR3DECL(int) VbglR3ClipboardTransferStatusReply(PVBGLR3SHCLCMDCTX pCtx, PSHCLTRANSFER pTransfer,
SHCLTRANSFERSTATUS uStatus, int rcTransfer)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
RT_NOREF(pTransfer);
VBoxShClReplyMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_REPLY, VBOX_SHCL_CPARMS_REPLY_MIN + 1);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.enmType.SetUInt32(VBOX_SHCL_REPLYMSGTYPE_TRANSFER_STATUS);
Msg.rc.SetUInt32((uint32_t )rcTransfer); /* int vs. uint32_t */
Msg.pvPayload.SetPtr(NULL, 0);
Msg.u.TransferStatus.enmStatus.SetUInt32((uint32_t)uStatus);
LogFlowFunc(("%s\n", ShClTransferStatusToStr(uStatus)));
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to read a root list header from the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pfRoots Where to store the root list header flags to use, requested by the host.
*/
VBGLR3DECL(int) VbglR3ClipboardRootListHdrReadReq(PVBGLR3SHCLCMDCTX pCtx, uint32_t *pfRoots)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pfRoots, VERR_INVALID_POINTER);
VBoxShClRootListReadReqMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_ROOT_LIST_HDR_READ_REQ);
Msg.ReqParms.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_READ);
Msg.ReqParms.fRoots.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.uContext.GetUInt64(&pCtx->idContext); AssertRC(rc);
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.fRoots.GetUInt32(pfRoots);
AssertRC(rc);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies to a root list header request.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pRootListHdr Root lsit header to reply to the host.
*/
VBGLR3DECL(int) VbglR3ClipboardRootListHdrReadReply(PVBGLR3SHCLCMDCTX pCtx, PSHCLROOTLISTHDR pRootListHdr)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pRootListHdr, VERR_INVALID_POINTER);
VBoxShClRootListHdrMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_WRITE, VBOX_SHCL_CPARMS_ROOT_LIST_HDR_WRITE);
Msg.ReqParms.uContext.SetUInt64(pCtx->idContext);
Msg.ReqParms.fRoots.SetUInt32(pRootListHdr->fRoots);
Msg.cRoots.SetUInt32(pRootListHdr->cRoots);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to read a root list entry from the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param puIndex Where to return the index of the root list entry the host wants to read.
* @param pfInfo Where to return the read flags the host wants to use.
*/
VBGLR3DECL(int) VbglR3ClipboardRootListEntryReadReq(PVBGLR3SHCLCMDCTX pCtx, uint32_t *puIndex, uint32_t *pfInfo)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(puIndex, VERR_INVALID_POINTER);
AssertPtrReturn(pfInfo, VERR_INVALID_POINTER);
VBoxShClRootListEntryReadReqMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_ROOT_LIST_ENTRY_READ_REQ);
Msg.Parms.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_ENTRY_READ);
Msg.Parms.fInfo.SetUInt32(0);
Msg.Parms.uIndex.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.Parms.uContext.GetUInt64(&pCtx->idContext); AssertRC(rc);
if (RT_SUCCESS(rc))
{
rc = Msg.Parms.fInfo.GetUInt32(pfInfo);
AssertRC(rc);
}
if (RT_SUCCESS(rc))
{
rc = Msg.Parms.uIndex.GetUInt32(puIndex);
AssertRC(rc);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies to a root list entry read request from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param uIndex Index of root list entry to reply.
* @param pEntry Actual root list entry to reply.
*/
VBGLR3DECL(int) VbglR3ClipboardRootListEntryReadReply(PVBGLR3SHCLCMDCTX pCtx, uint32_t uIndex, PSHCLROOTLISTENTRY pEntry)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pEntry, VERR_INVALID_POINTER);
VBoxShClRootListEntryMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_ROOT_LIST_ENTRY_WRITE, VBOX_SHCL_CPARMS_ROOT_LIST_ENTRY_WRITE);
Msg.Parms.uContext.SetUInt64(pCtx->idContext);
Msg.Parms.fInfo.SetUInt32(0);
Msg.Parms.uIndex.SetUInt32(uIndex);
Msg.szName.SetPtr(pEntry->pszName, pEntry->cbName);
Msg.cbInfo.SetUInt32(pEntry->cbInfo);
Msg.pvInfo.SetPtr(pEntry->pvInfo, pEntry->cbInfo);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to open a list handle to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pOpenParms List open parameters to use for the open request.
* @param phList Where to return the list handle received from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardListOpenSend(PVBGLR3SHCLCMDCTX pCtx, PSHCLLISTOPENPARMS pOpenParms,
PSHCLLISTHANDLE phList)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pOpenParms, VERR_INVALID_POINTER);
AssertPtrReturn(phList, VERR_INVALID_POINTER);
VBoxShClListOpenMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_LIST_OPEN, VBOX_SHCL_CPARMS_LIST_OPEN);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.fList.SetUInt32(0);
Msg.pvFilter.SetPtr(pOpenParms->pszFilter, pOpenParms->cbFilter);
Msg.pvPath.SetPtr(pOpenParms->pszPath, pOpenParms->cbPath);
Msg.uHandle.SetUInt64(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.uHandle.GetUInt64(phList); AssertRC(rc);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to open a list handle on the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pOpenParms Where to store the open parameters the host wants to use for opening the list handle.
*/
VBGLR3DECL(int) VbglR3ClipboardListOpenRecv(PVBGLR3SHCLCMDCTX pCtx, PSHCLLISTOPENPARMS pOpenParms)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pOpenParms, VERR_INVALID_POINTER);
VBoxShClListOpenMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_LIST_OPEN);
Msg.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_OPEN);
Msg.fList.SetUInt32(0);
Msg.pvPath.SetPtr(pOpenParms->pszPath, pOpenParms->cbPath);
Msg.pvFilter.SetPtr(pOpenParms->pszFilter, pOpenParms->cbFilter);
Msg.uHandle.SetUInt64(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
rc = Msg.fList.GetUInt32(&pOpenParms->fList);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies to a list open request from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param rcReply Return code to reply to the host.
* @param hList List handle of (guest) list to reply to the host.
*/
VBGLR3DECL(int) VbglR3ClipboardListOpenReply(PVBGLR3SHCLCMDCTX pCtx, int rcReply, SHCLLISTHANDLE hList)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
VBoxShClReplyMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_REPLY, VBOX_SHCL_CPARMS_REPLY_MIN + 1);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.enmType.SetUInt32(VBOX_SHCL_REPLYMSGTYPE_LIST_OPEN);
Msg.rc.SetUInt32((uint32_t)rcReply); /** int vs. uint32_t */
Msg.pvPayload.SetPtr(NULL, 0);
Msg.u.ListOpen.uHandle.SetUInt64(hList);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to close a list handle on the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param phList Where to store the list handle to close, received from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardListCloseRecv(PVBGLR3SHCLCMDCTX pCtx, PSHCLLISTHANDLE phList)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(phList, VERR_INVALID_POINTER);
VBoxShClListCloseMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_LIST_CLOSE);
Msg.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_CLOSE);
Msg.uHandle.SetUInt64(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
{
rc = Msg.uHandle.GetUInt64(phList);
AssertRC(rc);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies to a list handle close request from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param rcReply Return code to reply to the host.
* @param hList List handle the send the close reply for.
*/
VBGLR3DECL(int) VbglR3ClipboardListCloseReply(PVBGLR3SHCLCMDCTX pCtx, int rcReply, SHCLLISTHANDLE hList)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
VBoxShClReplyMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_REPLY, VBOX_SHCL_CPARMS_REPLY_MIN + 1);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.enmType.SetUInt32(VBOX_SHCL_REPLYMSGTYPE_LIST_CLOSE);
Msg.rc.SetUInt32((uint32_t)rcReply); /** int vs. uint32_t */
Msg.pvPayload.SetPtr(NULL, 0);
Msg.u.ListOpen.uHandle.SetUInt64(hList);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to close a list handle to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hList List handle to request for closing on the host.
*/
VBGLR3DECL(int) VbglR3ClipboardListCloseSend(PVBGLR3SHCLCMDCTX pCtx, SHCLLISTHANDLE hList)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
VBoxShClListCloseMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_LIST_CLOSE, VBOX_SHCL_CPARMS_LIST_CLOSE);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.uHandle.SetUInt64(hList);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to read a list header to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hList List handle to read list header for.
* @param fFlags List header read flags to use.
* @param pListHdr Where to return the list header received from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardListHdrRead(PVBGLR3SHCLCMDCTX pCtx, SHCLLISTHANDLE hList, uint32_t fFlags,
PSHCLLISTHDR pListHdr)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pListHdr, VERR_INVALID_POINTER);
VBoxShClListHdrMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_LIST_HDR_READ, VBOX_SHCL_CPARMS_LIST_HDR);
Msg.ReqParms.uContext.SetUInt64(pCtx->idContext);
Msg.ReqParms.uHandle.SetUInt64(hList);
Msg.ReqParms.fFlags.SetUInt32(fFlags);
Msg.fFeatures.SetUInt32(0);
Msg.cbTotalSize.SetUInt32(0);
Msg.cTotalObjects.SetUInt64(0);
Msg.cbTotalSize.SetUInt64(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.fFeatures.GetUInt32(&pListHdr->fFeatures);
if (RT_SUCCESS(rc))
rc = Msg.cTotalObjects.GetUInt64(&pListHdr->cTotalObjects);
if (RT_SUCCESS(rc))
rc = Msg.cbTotalSize.GetUInt64(&pListHdr->cbTotalSize);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to read a list header on the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param phList Where to return the list handle to read list header for.
* @param pfFlags Where to return the List header read flags to use.
*/
VBGLR3DECL(int) VbglR3ClipboardListHdrReadRecvReq(PVBGLR3SHCLCMDCTX pCtx, PSHCLLISTHANDLE phList, uint32_t *pfFlags)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(phList, VERR_INVALID_POINTER);
AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
VBoxShClListHdrReadReqMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_LIST_HDR_READ_REQ);
Msg.ReqParms.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_HDR_READ);
Msg.ReqParms.uHandle.SetUInt64(0);
Msg.ReqParms.fFlags.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
rc = Msg.ReqParms.uHandle.GetUInt64(phList);
if (RT_SUCCESS(rc))
rc = Msg.ReqParms.fFlags.GetUInt32(pfFlags);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends (writes) a list header to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hList List handle to write list header for.
* @param pListHdr List header to write.
*/
VBGLR3DECL(int) VbglR3ClipboardListHdrWrite(PVBGLR3SHCLCMDCTX pCtx, SHCLLISTHANDLE hList,
PSHCLLISTHDR pListHdr)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pListHdr, VERR_INVALID_POINTER);
VBoxShClListHdrMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_LIST_HDR_WRITE, VBOX_SHCL_CPARMS_LIST_HDR);
Msg.ReqParms.uContext.SetUInt64(pCtx->idContext);
Msg.ReqParms.uHandle.SetUInt64(hList);
Msg.ReqParms.fFlags.SetUInt32(0);
Msg.fFeatures.SetUInt32(0);
Msg.cbTotalSize.SetUInt32(pListHdr->fFeatures);
Msg.cTotalObjects.SetUInt64(pListHdr->cTotalObjects);
Msg.cbTotalSize.SetUInt64(pListHdr->cbTotalSize);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to read a list entry from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hList List handle to request to read a list entry for.
* @param pListEntry Where to return the list entry read from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardListEntryRead(PVBGLR3SHCLCMDCTX pCtx, SHCLLISTHANDLE hList,
PSHCLLISTENTRY pListEntry)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pListEntry, VERR_INVALID_POINTER);
VBoxShClListEntryMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_LIST_ENTRY_READ, VBOX_SHCL_CPARMS_LIST_ENTRY);
Msg.ReqParms.uContext.SetUInt64(pCtx->idContext);
Msg.ReqParms.uHandle.SetUInt64(hList);
Msg.ReqParms.fInfo.SetUInt32(0);
Msg.szName.SetPtr(pListEntry->pszName, pListEntry->cbName);
Msg.cbInfo.SetUInt32(pListEntry->cbInfo);
Msg.pvInfo.SetPtr(pListEntry->pvInfo, pListEntry->cbInfo);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.cbInfo.GetUInt32(&pListEntry->cbInfo); AssertRC(rc);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to read a list entry from the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param phList Where to return the list handle to read a list entry for.
* @param pfInfo Where to return the list read flags.
*/
VBGLR3DECL(int) VbglR3ClipboardListEntryReadRecvReq(PVBGLR3SHCLCMDCTX pCtx, PSHCLLISTHANDLE phList, uint32_t *pfInfo)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(phList, VERR_INVALID_POINTER);
AssertPtrReturn(pfInfo, VERR_INVALID_POINTER);
VBoxShClListEntryReadReqMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_LIST_ENTRY_READ);
Msg.ReqParms.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_READ);
Msg.ReqParms.uHandle.SetUInt64(0);
Msg.ReqParms.fInfo.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.uHandle.GetUInt64(phList);
AssertRC(rc);
}
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.fInfo.GetUInt32(pfInfo);
AssertRC(rc);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends (writes) a list entry to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hList List handle to write a list etnry for.
* @param pListEntry List entry to write.
*/
VBGLR3DECL(int) VbglR3ClipboardListEntryWrite(PVBGLR3SHCLCMDCTX pCtx, SHCLLISTHANDLE hList,
PSHCLLISTENTRY pListEntry)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pListEntry, VERR_INVALID_POINTER);
VBoxShClListEntryMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_LIST_ENTRY_WRITE, VBOX_SHCL_CPARMS_LIST_ENTRY);
Msg.ReqParms.uContext.SetUInt64(pCtx->idContext);
Msg.ReqParms.uHandle.SetUInt64(hList);
Msg.ReqParms.fInfo.SetUInt32(pListEntry->fInfo);
Msg.szName.SetPtr(pListEntry->pszName, pListEntry->cbName);
Msg.cbInfo.SetUInt32(pListEntry->cbInfo);
Msg.pvInfo.SetPtr(pListEntry->pvInfo, pListEntry->cbInfo);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to open an object on the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pCreateParms Where to store the object open/create parameters received from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardObjOpenRecv(PVBGLR3SHCLCMDCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pCreateParms, VERR_INVALID_POINTER);
VBoxShClObjOpenMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_OBJ_OPEN);
Msg.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_OPEN);
Msg.uHandle.SetUInt64(0);
Msg.szPath.SetPtr(pCreateParms->pszPath, pCreateParms->cbPath);
Msg.fCreate.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
rc = Msg.fCreate.GetUInt32(&pCreateParms->fCreate);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies a host request to open an object.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param rcReply Return code to reply to the host.
* @param hObj Object handle of opened object to reply to the host.
*/
VBGLR3DECL(int) VbglR3ClipboardObjOpenReply(PVBGLR3SHCLCMDCTX pCtx, int rcReply, SHCLOBJHANDLE hObj)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
VBoxShClReplyMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_REPLY, VBOX_SHCL_CPARMS_REPLY_MIN + 1);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.enmType.SetUInt32(VBOX_SHCL_REPLYMSGTYPE_OBJ_OPEN);
Msg.rc.SetUInt32((uint32_t)rcReply); /** int vs. uint32_t */
Msg.pvPayload.SetPtr(NULL, 0);
Msg.u.ObjOpen.uHandle.SetUInt64(hObj);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends an object open request to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param pCreateParms Object open/create parameters to use for opening the object on the host.
* @param phObj Where to return the object handle from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardObjOpenSend(PVBGLR3SHCLCMDCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
PSHCLOBJHANDLE phObj)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pCreateParms, VERR_INVALID_POINTER);
AssertPtrReturn(phObj, VERR_INVALID_POINTER);
VBoxShClObjOpenMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_OBJ_OPEN, VBOX_SHCL_CPARMS_OBJ_OPEN);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.uHandle.SetUInt64(0);
Msg.szPath.SetPtr((void *)pCreateParms->pszPath, pCreateParms->cbPath);
Msg.fCreate.SetUInt32(pCreateParms->fCreate);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
Msg.uHandle.GetUInt64(phObj);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to close an object on the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param phObj Where to return the object handle to close from the host.
*/
VBGLR3DECL(int) VbglR3ClipboardObjCloseRecv(PVBGLR3SHCLCMDCTX pCtx, PSHCLOBJHANDLE phObj)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(phObj, VERR_INVALID_POINTER);
VBoxShClObjCloseMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_OBJ_CLOSE);
Msg.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_CLOSE);
Msg.uHandle.SetUInt64(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
rc = Msg.uHandle.GetUInt64(phObj);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Replies to an object open request from the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param rcReply Return code to reply to the host.
* @param hObj Object handle to reply to the host.
*/
VBGLR3DECL(int) VbglR3ClipboardObjCloseReply(PVBGLR3SHCLCMDCTX pCtx, int rcReply, SHCLOBJHANDLE hObj)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
VBoxShClReplyMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_REPLY, VBOX_SHCL_CPARMS_REPLY_MIN + 1);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.enmType.SetUInt32(VBOX_SHCL_REPLYMSGTYPE_OBJ_CLOSE);
Msg.rc.SetUInt32((uint32_t)rcReply); /** int vs. uint32_t */
Msg.pvPayload.SetPtr(NULL, 0);
Msg.u.ObjClose.uHandle.SetUInt64(hObj);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to close an object to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hObj Object handle to close on the host.
*/
VBGLR3DECL(int) VbglR3ClipboardObjCloseSend(PVBGLR3SHCLCMDCTX pCtx, SHCLOBJHANDLE hObj)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
VBoxShClObjCloseMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_OBJ_CLOSE, VBOX_SHCL_CPARMS_OBJ_CLOSE);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.uHandle.SetUInt64(hObj);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Receives a host request to read from an object on the guest.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param phObj Where to return the object handle to read from.
* @param pcbToRead Where to return the amount (in bytes) to read.
* @param pfFlags Where to return the read flags.
*/
VBGLR3DECL(int) VbglR3ClipboardObjReadRecv(PVBGLR3SHCLCMDCTX pCtx, PSHCLOBJHANDLE phObj, uint32_t *pcbToRead,
uint32_t *pfFlags)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(phObj, VERR_INVALID_POINTER);
AssertPtrReturn(pcbToRead, VERR_INVALID_POINTER);
AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
VBoxShClObjReadReqMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_MSG_GET, VBOX_SHCL_CPARMS_OBJ_READ_REQ);
Msg.ReqParms.uContext.SetUInt64(VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_READ);
Msg.ReqParms.uHandle.SetUInt64(0);
Msg.ReqParms.cbToRead.SetUInt32(0);
Msg.ReqParms.fRead.SetUInt32(0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
rc = Msg.ReqParms.uContext.GetUInt64(&pCtx->idContext);
if (RT_SUCCESS(rc))
rc = Msg.ReqParms.uHandle.GetUInt64(phObj);
if (RT_SUCCESS(rc))
rc = Msg.ReqParms.cbToRead.GetUInt32(pcbToRead);
if (RT_SUCCESS(rc))
rc = Msg.ReqParms.fRead.GetUInt32(pfFlags);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to read from an object to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hObj Object handle of object to read from.
* @param pvData Buffer where to store the read object data.
* @param cbData Size (in bytes) of buffer.
* @param pcbRead Where to store the amount (in bytes) read from the object.
*/
VBGLR3DECL(int) VbglR3ClipboardObjReadSend(PVBGLR3SHCLCMDCTX pCtx, SHCLOBJHANDLE hObj,
void *pvData, uint32_t cbData, uint32_t *pcbRead)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pvData, VERR_INVALID_POINTER);
AssertReturn(cbData, VERR_INVALID_PARAMETER);
/* pcbRead is optional. */
VBoxShClObjReadWriteMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_OBJ_READ, VBOX_SHCL_CPARMS_OBJ_READ);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.uHandle.SetUInt64(hObj);
Msg.cbData.SetUInt32(cbData);
Msg.pvData.SetPtr(pvData, cbData);
Msg.cbChecksum.SetUInt32(0);
Msg.pvChecksum.SetPtr(NULL, 0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
/** @todo Add checksum support. */
if (pcbRead)
{
rc = Msg.cbData.GetUInt32(pcbRead); AssertRC(rc);
AssertReturn(cbData >= *pcbRead, VERR_TOO_MUCH_DATA);
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends a request to write to an object to the host.
*
* @returns VBox status code.
* @param pCtx Shared Clipboard command context to use for the connection.
* @param hObj Object handle of object to write to.
* @param pvData Buffer of data to write to object.
* @param cbData Size (in bytes) of buffer.
* @param pcbWritten Where to store the amount (in bytes) written to the object.
*/
VBGLR3DECL(int) VbglR3ClipboardObjWriteSend(PVBGLR3SHCLCMDCTX pCtx, SHCLOBJHANDLE hObj,
void *pvData, uint32_t cbData, uint32_t *pcbWritten)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pvData, VERR_INVALID_POINTER);
/* cbData can be 0. */
/* pcbWritten is optional. */
VBoxShClObjReadWriteMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->idClient,
VBOX_SHCL_GUEST_FN_OBJ_WRITE, VBOX_SHCL_CPARMS_OBJ_WRITE);
Msg.uContext.SetUInt64(pCtx->idContext);
Msg.uHandle.SetUInt64(hObj);
Msg.pvData.SetPtr(pvData, cbData);
Msg.pvChecksum.SetPtr(NULL, 0);
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_SUCCESS(rc))
{
/** @todo Add checksum support. */
if (pcbWritten)
*pcbWritten = cbData; /** @todo For now return all as being written. */
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/*********************************************************************************************************************************
* Transfer interface implementations *
*********************************************************************************************************************************/
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceGetRoots(PSHCLTXPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = VbglR3ClipboardRootListRead(pCmdCtx, ppRootList);
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceListOpen(PSHCLTXPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms,
PSHCLLISTHANDLE phList)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = VbglR3ClipboardListOpenSend(pCmdCtx, pOpenParms, phList);
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceListClose(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = VbglR3ClipboardListCloseSend(pCmdCtx, hList);
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceListHdrRead(PSHCLTXPROVIDERCTX pCtx,
SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = ShClTransferListHdrInit(pListHdr);
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
rc = VbglR3ClipboardListHdrRead(pCmdCtx, hList, 0 /* fFlags */, pListHdr);
}
else
ShClTransferListHdrDestroy(pListHdr);
}
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceListEntryRead(PSHCLTXPROVIDERCTX pCtx,
SHCLLISTHANDLE hList, PSHCLLISTENTRY pEntry)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = VbglR3ClipboardListEntryRead(pCmdCtx, hList, pEntry);
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceObjOpen(PSHCLTXPROVIDERCTX pCtx,
PSHCLOBJOPENCREATEPARMS pCreateParms, PSHCLOBJHANDLE phObj)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = VbglR3ClipboardObjOpenSend(pCmdCtx, pCreateParms, phObj);
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceObjClose(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
int rc = VbglR3ClipboardObjCloseSend(pCmdCtx, hObj);
LogFlowFuncLeaveRC(rc);
return rc;
}
static DECLCALLBACK(int) vbglR3ClipboardTransferIfaceObjRead(PSHCLTXPROVIDERCTX pCtx,
SHCLOBJHANDLE hObj, void *pvData, uint32_t cbData,
uint32_t fFlags, uint32_t *pcbRead)
{
LogFlowFuncEnter();
PVBGLR3SHCLCMDCTX pCmdCtx = (PVBGLR3SHCLCMDCTX)pCtx->pvUser;
AssertPtr(pCmdCtx);
RT_NOREF(fFlags); /* Not used yet. */
int rc = VbglR3ClipboardObjReadSend(pCmdCtx, hObj, pvData, cbData, pcbRead);
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Starts a transfer on the guest side.
*
* @returns VBox status code.
* @param pCmdCtx Command context to use.
* @param pTransferCtx Transfer context to create transfer for.
* @param uTransferID ID to use for transfer to start.
* @param enmDir Direction of transfer to start.
* @param enmSource Source of transfer to start.
* @param ppTransfer Where to return the transfer object on success. Optional.
*/
static int vbglR3ClipboardTransferStart(PVBGLR3SHCLCMDCTX pCmdCtx, PSHCLTRANSFERCTX pTransferCtx,
SHCLTRANSFERID uTransferID, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource,
PSHCLTRANSFER *ppTransfer)
{
PSHCLTRANSFER pTransfer;
int rc = ShClTransferCreate(&pTransfer);
if (RT_SUCCESS(rc))
{
ShClTransferSetCallbacks(pTransfer, &pCmdCtx->Transfers.Callbacks);
rc = ShClTransferInit(pTransfer, enmDir, enmSource);
if (RT_SUCCESS(rc))
{
rc = ShClTransferCtxTransferRegisterById(pTransferCtx, pTransfer, uTransferID);
if (RT_SUCCESS(rc))
{
/* If this is a read transfer (reading data from host), set the interface to use
* our VbglR3 routines here. */
if (enmDir == SHCLTRANSFERDIR_FROM_REMOTE)
{
SHCLTXPROVIDERCREATIONCTX creationCtx;
RT_ZERO(creationCtx);
creationCtx.Interface.pfnRootsGet = vbglR3ClipboardTransferIfaceGetRoots;
creationCtx.Interface.pfnListOpen = vbglR3ClipboardTransferIfaceListOpen;
creationCtx.Interface.pfnListClose = vbglR3ClipboardTransferIfaceListClose;
creationCtx.Interface.pfnListHdrRead = vbglR3ClipboardTransferIfaceListHdrRead;
creationCtx.Interface.pfnListEntryRead = vbglR3ClipboardTransferIfaceListEntryRead;
creationCtx.Interface.pfnObjOpen = vbglR3ClipboardTransferIfaceObjOpen;
creationCtx.Interface.pfnObjClose = vbglR3ClipboardTransferIfaceObjClose;
creationCtx.Interface.pfnObjRead = vbglR3ClipboardTransferIfaceObjRead;
creationCtx.pvUser = pCmdCtx;
rc = ShClTransferSetProviderIface(pTransfer, &creationCtx);
}
if (RT_SUCCESS(rc))
rc = ShClTransferStart(pTransfer);
}
if (RT_FAILURE(rc))
ShClTransferCtxTransferUnregister(pTransferCtx, uTransferID);
}
}
if (RT_SUCCESS(rc))
{
if (ppTransfer)
*ppTransfer = pTransfer;
LogRel2(("Shared Clipboard: Transfer ID=%RU32 (%s %s) successfully started\n",
uTransferID,
enmDir == SHCLTRANSFERDIR_FROM_REMOTE ? "reading from" : "writing to",
enmSource == SHCLSOURCE_LOCAL ? "local" : "remote"));
}
else
LogRel(("Shared Clipboard: Unable to start transfer ID=%RU32, rc=%Rrc\n", uTransferID, rc));
/* Send a reply in any case. */
int rc2 = VbglR3ClipboardTransferStatusReply(pCmdCtx, pTransfer,
RT_SUCCESS(rc)
? SHCLTRANSFERSTATUS_STARTED : SHCLTRANSFERSTATUS_ERROR, rc);
if (RT_SUCCESS(rc))
rc = rc2;
if (RT_FAILURE(rc))
{
ShClTransferDestroy(pTransfer);
pTransfer = NULL;
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Stops a transfer on the guest side.
*
* @returns VBox status code, or VERR_NOT_FOUND if transfer has not been found.
* @param pCmdCtx Command context to use.
* @param pTransferCtx Transfer context to stop transfer for.
* @param uTransferID ID of transfer to stop.
*/
static int vbglR3ClipboardTransferStop(PVBGLR3SHCLCMDCTX pCmdCtx, PSHCLTRANSFERCTX pTransferCtx,
SHCLTRANSFERID uTransferID)
{
int rc;
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx, uTransferID);
if (pTransfer)
{
rc = ShClTransferCtxTransferUnregister(pTransferCtx, uTransferID);
if (RT_SUCCESS(rc))
{
LogRel2(("Shared Clipboard: Transfer ID=%RU32 successfully stopped\n", uTransferID));
}
else
LogRel(("Shared Clipboard: Unable to stop transfer ID=%RU32, rc=%Rrc\n", uTransferID, rc));
/* Send a reply in any case. */
int rc2 = VbglR3ClipboardTransferStatusReply(pCmdCtx, pTransfer,
RT_SUCCESS(rc)
? SHCLTRANSFERSTATUS_STOPPED : SHCLTRANSFERSTATUS_ERROR, rc);
AssertRC(rc2);
}
else
rc = VERR_NOT_FOUND;
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sets transfer callbacks of a Shared Clipboard command context.
*
* @param pCmdCtx Command context to set callbacks for.
* @param pCallbacks Pointer to callback table to set.
*/
VBGLR3DECL(void) VbglR3ClipboardTransferSetCallbacks(PVBGLR3SHCLCMDCTX pCmdCtx, PSHCLTRANSFERCALLBACKTABLE pCallbacks)
{
AssertPtrReturnVoid(pCmdCtx);
AssertPtrReturnVoid(pCallbacks);
ShClTransferCopyCallbacks(&pCmdCtx->Transfers.Callbacks, pCallbacks);
}
VBGLR3DECL(int) VbglR3ClipboardEventGetNextEx(uint32_t idMsg, uint32_t cParms,
PVBGLR3SHCLCMDCTX pCmdCtx, PSHCLTRANSFERCTX pTransferCtx,
PVBGLR3CLIPBOARDEVENT pEvent)
{
AssertPtrReturn(pCmdCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pTransferCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
LogFunc(("Handling idMsg=%RU32 (%s), cParms=%RU32\n", idMsg, ShClHostMsgToStr(idMsg), cParms));
int rc;
if (!pCmdCtx->fUseLegacyProtocol)
{
bool fErrorSent = false; /* Whether an error has been reported back to the host already. */
switch (idMsg)
{
case VBOX_SHCL_HOST_MSG_TRANSFER_STATUS:
{
SHCLTRANSFERDIR enmDir;
SHCLTRANSFERREPORT transferReport;
rc = VbglR3ClipboarTransferStatusRecv(pCmdCtx, &enmDir, &transferReport);
if (RT_SUCCESS(rc))
{
const SHCLTRANSFERID uTransferID = VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext);
LogFlowFunc(("[Transfer %RU32] enmDir=%RU32, status=%s\n",
uTransferID, enmDir, ShClTransferStatusToStr(transferReport.uStatus)));
switch (transferReport.uStatus)
{
case SHCLTRANSFERSTATUS_INITIALIZED:
RT_FALL_THROUGH();
case SHCLTRANSFERSTATUS_STARTED:
{
SHCLSOURCE enmSource = SHCLSOURCE_INVALID;
/* The host announces the transfer direction from its point of view, so inverse the direction here. */
if (enmDir == SHCLTRANSFERDIR_TO_REMOTE)
{
enmDir = SHCLTRANSFERDIR_FROM_REMOTE;
enmSource = SHCLSOURCE_REMOTE;
}
else if (enmDir == SHCLTRANSFERDIR_FROM_REMOTE)
{
enmDir = SHCLTRANSFERDIR_TO_REMOTE;
enmSource = SHCLSOURCE_LOCAL;
}
else
AssertFailedBreakStmt(rc = VERR_INVALID_PARAMETER);
rc = vbglR3ClipboardTransferStart(pCmdCtx, pTransferCtx, uTransferID,
enmDir, enmSource, NULL /* ppTransfer */);
break;
}
case SHCLTRANSFERSTATUS_STOPPED:
RT_FALL_THROUGH();
case SHCLTRANSFERSTATUS_CANCELED:
RT_FALL_THROUGH();
case SHCLTRANSFERSTATUS_KILLED:
RT_FALL_THROUGH();
case SHCLTRANSFERSTATUS_ERROR:
{
rc = vbglR3ClipboardTransferStop(pCmdCtx, pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
break;
}
default:
rc = VERR_NOT_SUPPORTED;
break;
}
if (RT_SUCCESS(rc))
{
pEvent->u.TransferStatus.enmDir = enmDir;
pEvent->u.TransferStatus.Report = transferReport;
pEvent->u.TransferStatus.uID = VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext);
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_TRANSFER_STATUS;
LogRel2(("Shared Clipboard: Received status %s (rc=%Rrc) for transfer ID=%RU32\n",
ShClTransferStatusToStr(pEvent->u.TransferStatus.Report.uStatus), pEvent->u.TransferStatus.Report.rc,
pEvent->u.TransferStatus.uID));
}
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_HDR_READ:
{
uint32_t fRoots;
rc = VbglR3ClipboardRootListHdrReadReq(pCmdCtx, &fRoots);
/** @todo Validate / handle fRoots. */
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
SHCLROOTLISTHDR rootListHdr;
RT_ZERO(rootListHdr);
rootListHdr.cRoots = ShClTransferRootsCount(pTransfer);
LogFlowFunc(("cRoots=%RU32\n", rootListHdr.cRoots));
rc = VbglR3ClipboardRootListHdrReadReply(pCmdCtx, &rootListHdr);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_ROOT_LIST_ENTRY_READ:
{
uint32_t uIndex;
uint32_t fInfo;
rc = VbglR3ClipboardRootListEntryReadReq(pCmdCtx, &uIndex, &fInfo);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
SHCLROOTLISTENTRY rootListEntry;
rc = ShClTransferRootsEntry(pTransfer, uIndex, &rootListEntry);
if (RT_SUCCESS(rc))
rc = VbglR3ClipboardRootListEntryReadReply(pCmdCtx, uIndex, &rootListEntry);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_LIST_OPEN:
{
SHCLLISTOPENPARMS openParmsList;
rc = ShClTransferListOpenParmsInit(&openParmsList);
if (RT_SUCCESS(rc))
{
rc = VbglR3ClipboardListOpenRecv(pCmdCtx, &openParmsList);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
LogFlowFunc(("pszPath=%s\n", openParmsList.pszPath));
SHCLLISTHANDLE hList = SHCLLISTHANDLE_INVALID;
rc = ShClTransferListOpen(pTransfer, &openParmsList, &hList);
/* Reply in any case. */
int rc2 = VbglR3ClipboardListOpenReply(pCmdCtx, rc, hList);
AssertRC(rc2);
}
ShClTransferListOpenParmsDestroy(&openParmsList);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_LIST_CLOSE:
{
SHCLLISTHANDLE hList;
rc = VbglR3ClipboardListCloseRecv(pCmdCtx, &hList);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
rc = ShClTransferListClose(pTransfer, hList);
/* Reply in any case. */
int rc2 = VbglR3ClipboardListCloseReply(pCmdCtx, rc, hList);
AssertRC(rc2);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_LIST_HDR_READ:
{
/** @todo Handle filter + list features. */
SHCLLISTHANDLE hList = SHCLLISTHANDLE_INVALID;
uint32_t fFlags = 0;
rc = VbglR3ClipboardListHdrReadRecvReq(pCmdCtx, &hList, &fFlags);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
SHCLLISTHDR hdrList;
rc = ShClTransferListGetHeader(pTransfer, hList, &hdrList);
if (RT_SUCCESS(rc))
{
rc = VbglR3ClipboardListHdrWrite(pCmdCtx, hList, &hdrList);
ShClTransferListHdrDestroy(&hdrList);
}
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_READ:
{
LogFlowFunc(("VBOX_SHCL_HOST_MSG_TRANSFER_LIST_ENTRY_READ\n"));
SHCLLISTENTRY entryList;
rc = ShClTransferListEntryInit(&entryList);
if (RT_SUCCESS(rc))
{
SHCLLISTHANDLE hList;
uint32_t fInfo;
rc = VbglR3ClipboardListEntryReadRecvReq(pCmdCtx, &hList, &fInfo);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
rc = ShClTransferListRead(pTransfer, hList, &entryList);
if (RT_SUCCESS(rc))
{
PSHCLFSOBJINFO pObjInfo = (PSHCLFSOBJINFO)entryList.pvInfo;
Assert(entryList.cbInfo == sizeof(SHCLFSOBJINFO));
RT_NOREF(pObjInfo);
LogFlowFunc(("\t%s (%RU64 bytes)\n", entryList.pszName, pObjInfo->cbObject));
rc = VbglR3ClipboardListEntryWrite(pCmdCtx, hList, &entryList);
}
}
ShClTransferListEntryDestroy(&entryList);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_OPEN:
{
SHCLOBJOPENCREATEPARMS openParms;
rc = ShClTransferObjOpenParmsInit(&openParms);
if (RT_SUCCESS(rc))
{
rc = VbglR3ClipboardObjOpenRecv(pCmdCtx, &openParms);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
SHCLOBJHANDLE hObj;
rc = ShClTransferObjOpen(pTransfer, &openParms, &hObj);
/* Reply in any case. */
int rc2 = VbglR3ClipboardObjOpenReply(pCmdCtx, rc, hObj);
AssertRC(rc2);
}
ShClTransferObjOpenParmsDestroy(&openParms);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_CLOSE:
{
SHCLOBJHANDLE hObj;
rc = VbglR3ClipboardObjCloseRecv(pCmdCtx, &hObj);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
rc = ShClTransferObjClose(pTransfer, hObj);
/* Reply in any case. */
int rc2 = VbglR3ClipboardObjCloseReply(pCmdCtx, rc, hObj);
AssertRC(rc2);
}
break;
}
case VBOX_SHCL_HOST_MSG_TRANSFER_OBJ_READ:
{
SHCLOBJHANDLE hObj;
uint32_t cbBuf;
uint32_t fFlags;
rc = VbglR3ClipboardObjReadRecv(pCmdCtx, &hObj, &cbBuf, &fFlags);
if (RT_SUCCESS(rc))
{
PSHCLTRANSFER pTransfer = ShClTransferCtxGetTransferById(pTransferCtx,
VBOX_SHCL_CONTEXTID_GET_TRANSFER(pCmdCtx->idContext));
AssertPtrBreakStmt(pTransfer, rc = VERR_NOT_FOUND);
AssertBreakStmt(pCmdCtx->Transfers.cbChunkSize, rc = VERR_INVALID_PARAMETER);
const uint32_t cbToRead = RT_MIN(cbBuf, pCmdCtx->Transfers.cbChunkSize);
LogFlowFunc(("hObj=%RU64, cbBuf=%RU32, fFlags=0x%x -> cbChunkSize=%RU32, cbToRead=%RU32\n",
hObj, cbBuf, fFlags, pCmdCtx->Transfers.cbChunkSize, cbToRead));
void *pvBuf = RTMemAlloc(cbToRead);
if (pvBuf)
{
uint32_t cbRead;
rc = ShClTransferObjRead(pTransfer, hObj, pvBuf, cbToRead, fFlags, &cbRead);
if (RT_SUCCESS(rc))
rc = VbglR3ClipboardObjWriteSend(pCmdCtx, hObj, pvBuf, cbRead, NULL /* pcbWritten */);
RTMemFree(pvBuf);
}
else
rc = VERR_NO_MEMORY;
}
break;
}
default:
{
rc = VbglR3ClipboardEventGetNext(idMsg, cParms, pCmdCtx, pEvent);
if (RT_FAILURE(rc))
fErrorSent = true;
break;
}
}
if ( !fErrorSent
&& RT_FAILURE(rc))
{
/* Report error back to the host. */
int rc2 = VbglR3ClipboardWriteError(pCmdCtx->idClient, rc);
AssertRC(rc2);
}
}
else
{
/*
* This builds on what we did in VbglR3ClipboardMsgPeekWait, so
* !HACK ALERT! cParms is the format flag or flags.
*/
rc = VINF_SUCCESS;
switch (idMsg)
{
case VBOX_SHCL_HOST_MSG_FORMATS_REPORT:
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_REPORT_FORMATS;
pEvent->u.fReportedFormats = cParms;
break;
case VBOX_SHCL_HOST_MSG_READ_DATA:
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_READ_DATA;
pEvent->u.fReadData = cParms;
break;
case VBOX_SHCL_HOST_MSG_QUIT:
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_QUIT;
break;
default:
AssertMsgFailed(("%u (%#x)\n", idMsg, idMsg));
rc = VERR_NOT_SUPPORTED;
break;
}
}
LogFlowFuncLeaveRC(rc);
return rc;
}
#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
VBGLR3DECL(int) VbglR3ClipboardEventGetNext(uint32_t idMsg, uint32_t cParms, PVBGLR3SHCLCMDCTX pCtx, PVBGLR3CLIPBOARDEVENT pEvent)
{
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
RT_NOREF(cParms);
int rc;
if (!pCtx->fUseLegacyProtocol)
{
LogFunc(("Handling idMsg=%RU32 (%s)\n", idMsg, ShClHostMsgToStr(idMsg)));
switch (idMsg)
{
case VBOX_SHCL_HOST_MSG_FORMATS_REPORT:
{
rc = vbglR3ClipboardFormatsReportRecv(pCtx, &pEvent->u.fReportedFormats);
if (RT_SUCCESS(rc))
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_REPORT_FORMATS;
break;
}
case VBOX_SHCL_HOST_MSG_READ_DATA_CID:
{
rc = vbglR3ClipboardFetchReadDataCid(pCtx, &pEvent->u.fReadData);
if (RT_SUCCESS(rc))
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_READ_DATA;
break;
}
case VBOX_SHCL_HOST_MSG_READ_DATA:
{
rc = vbglR3ClipboardFetchReadData(pCtx, &pEvent->u.fReadData);
if (RT_SUCCESS(rc))
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_READ_DATA;
break;
}
case VBOX_SHCL_HOST_MSG_QUIT:
{
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_QUIT;
rc = VINF_SUCCESS;
break;
}
default:
{
/** @todo r=bird: BUGBUG - need a skip command here! */
rc = VERR_NOT_SUPPORTED;
break;
}
}
if (RT_SUCCESS(rc))
{
/* Copy over our command context to the event. */
pEvent->cmdCtx = *pCtx;
}
else
{
/* Report error back to the host. */
int rc2 = VbglR3ClipboardWriteError(pCtx->idClient, rc);
AssertRC(rc2);
}
}
else
{
/*
* This builds on what we did in VbglR3ClipboardMsgPeekWait, so
* !HACK ALERT! cParms is the format flag or flags.
*/
rc = VINF_SUCCESS;
switch (idMsg)
{
case VBOX_SHCL_HOST_MSG_FORMATS_REPORT:
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_REPORT_FORMATS;
pEvent->u.fReportedFormats = cParms;
break;
case VBOX_SHCL_HOST_MSG_READ_DATA:
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_READ_DATA;
pEvent->u.fReadData = cParms;
break;
case VBOX_SHCL_HOST_MSG_QUIT:
pEvent->enmType = VBGLR3CLIPBOARDEVENTTYPE_QUIT;
break;
default:
AssertMsgFailed(("%u (%#x)\n", idMsg, idMsg));
rc = VERR_NOT_SUPPORTED;
break;
}
pEvent->cmdCtx = *pCtx;
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Frees (destroys) a formerly allocated Shared Clipboard event.
*
* @returns IPRT status code.
* @param pEvent Event to free (destroy).
*/
VBGLR3DECL(void) VbglR3ClipboardEventFree(PVBGLR3CLIPBOARDEVENT pEvent)
{
if (!pEvent)
return;
/* Some messages require additional cleanup. */
switch (pEvent->enmType)
{
default:
break;
}
RTMemFree(pEvent);
pEvent = NULL;
}
/**
* Reports (advertises) guest clipboard formats to the host.
*
* Legacy function, do not use anymore.
*
* @returns VBox status code.
* @param idClient The client id returned by VbglR3ClipboardConnect().
* @param fFormats The formats to report.
*/
VBGLR3DECL(int) VbglR3ClipboardReportFormats(HGCMCLIENTID idClient, uint32_t fFormats)
{
struct
{
VBGLIOCHGCMCALL Hdr;
VBoxShClParmReportFormats Parms;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, VBOX_SHCL_GUEST_FN_REPORT_FORMATS, VBOX_SHCL_CPARMS_REPORT_FORMATS);
VbglHGCMParmUInt32Set(&Msg.Parms.f32Formats, fFormats);
int rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends guest clipboard data to the host.
*
* Legacy function kept for compatibility, do not use anymore.
*
* This is usually called in reply to a VBOX_SHCL_HOST_MSG_READ_DATA message
* from the host.
*
* @returns VBox status code.
* @param idClient The client id returned by VbglR3ClipboardConnect().
* @param fFormat The format of the data.
* @param pvData Pointer to the data to send. Can be NULL if @a cbData
* is zero.
* @param cbData Number of bytes of data to send. Zero is valid.
*/
VBGLR3DECL(int) VbglR3ClipboardWriteData(HGCMCLIENTID idClient, uint32_t fFormat, void *pv, uint32_t cb)
{
LogFlowFuncEnter();
struct
{
VBGLIOCHGCMCALL Hdr;
VBoxShClParmDataWriteOld Parms;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, VBOX_SHCL_GUEST_FN_DATA_WRITE, VBOX_SHCL_CPARMS_DATA_WRITE_OLD);
VbglHGCMParmUInt32Set(&Msg.Parms.f32Format, fFormat);
VbglHGCMParmPtrSet(&Msg.Parms.pData, pv, cb);
int rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Sends guest clipboard data to the host.
*
* This is usually called in reply to a VBOX_SHCL_HOST_MSG_READ_DATA message
* from the host.
*
* @returns VBox status code.
* @param pCtx The command context returned by VbglR3ClipboardConnectEx().
* @param fFormat Clipboard format to send.
* @param pvData Pointer to the data to send. Can be NULL if @a cbData
* is zero.
* @param cbData Number of bytes of data to send. Zero is valid.
*/
VBGLR3DECL(int) VbglR3ClipboardWriteDataEx(PVBGLR3SHCLCMDCTX pCtx, SHCLFORMAT fFormat, void *pvData, uint32_t cbData)
{
LogFlowFunc(("ENTER: fFormat=%#x pvData=%p cbData=%#x\n", fFormat, pvData, cbData));
AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
if (cbData > 0)
AssertPtrReturn(pvData, VERR_INVALID_POINTER);
int rc;
if (pCtx->fUseLegacyProtocol)
rc = VbglR3ClipboardWriteData(pCtx->idClient, fFormat, pvData, cbData);
else
{
struct
{
VBGLIOCHGCMCALL Hdr;
VBoxShClParmDataWrite Parms;
} Msg;
VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->idClient, VBOX_SHCL_GUEST_FN_DATA_WRITE, VBOX_SHCL_CPARMS_DATA_WRITE);
Msg.Parms.id64Context.SetUInt64(pCtx->idContext);
Msg.Parms.f32Format.SetUInt32(fFormat);
Msg.Parms.pData.SetPtr(pvData, cbData);
LogFlowFunc(("CID=%RU32\n", pCtx->idContext));
rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Writes an error to the host.
*
* @returns IPRT status code.
* @param idClient The client id returned by VbglR3ClipboardConnect().
* @param rcErr Error (IPRT-style) to send.
*/
VBGLR3DECL(int) VbglR3ClipboardWriteError(HGCMCLIENTID idClient, int rcErr)
{
AssertReturn(idClient, VERR_INVALID_PARAMETER);
VBoxShClWriteErrorMsg Msg;
VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHCL_GUEST_FN_ERROR, VBOX_SHCL_CPARMS_ERROR);
/** @todo Context ID not used yet. */
Msg.uContext.SetUInt64(0);
Msg.rc.SetUInt32((uint32_t)rcErr); /* uint32_t vs. int. */
int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
if (RT_FAILURE(rc))
LogFlowFunc(("Sending error %Rrc failed with rc=%Rrc\n", rcErr, rc));
if (rc == VERR_NOT_SUPPORTED)
rc = VINF_SUCCESS;
if (RT_FAILURE(rc))
LogRel(("Shared Clipboard: Reporting error %Rrc to the host failed with %Rrc\n", rcErr, rc));
LogFlowFuncLeaveRC(rc);
return rc;
}
|