1 | /* $Id: VBoxSharedClipboardSvc-utils.cpp 80858 2019-09-17 13:03:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard Service - Host service utility functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
23 | #include <VBox/log.h>
|
---|
24 |
|
---|
25 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
26 | #include <VBox/HostServices/VBoxClipboardExt.h>
|
---|
27 |
|
---|
28 | #include <iprt/errcore.h>
|
---|
29 | #include <iprt/path.h>
|
---|
30 |
|
---|
31 | #include "VBoxSharedClipboardSvc-internal.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
35 | /**
|
---|
36 | * Returns whether a HGCM message is allowed in a certain service mode or not.
|
---|
37 | *
|
---|
38 | * @returns \c true if message is allowed, \c false if not.
|
---|
39 | * @param uMode Service mode to check allowance for.
|
---|
40 | * @param uMsg HGCM message to check allowance for.
|
---|
41 | */
|
---|
42 | bool vboxSvcClipboardURIMsgIsAllowed(uint32_t uMode, uint32_t uMsg)
|
---|
43 | {
|
---|
44 | const bool fHostToGuest = uMode == VBOX_SHCL_MODE_HOST_TO_GUEST
|
---|
45 | || uMode == VBOX_SHCL_MODE_BIDIRECTIONAL;
|
---|
46 |
|
---|
47 | const bool fGuestToHost = uMode == VBOX_SHCL_MODE_GUEST_TO_HOST
|
---|
48 | || uMode == VBOX_SHCL_MODE_BIDIRECTIONAL;
|
---|
49 |
|
---|
50 | bool fAllowed = false; /* If in doubt, don't allow. */
|
---|
51 |
|
---|
52 | switch (uMsg)
|
---|
53 | {
|
---|
54 | case VBOX_SHCL_GUEST_FN_LIST_OPEN:
|
---|
55 | RT_FALL_THROUGH();
|
---|
56 | case VBOX_SHCL_GUEST_FN_LIST_CLOSE:
|
---|
57 | RT_FALL_THROUGH();
|
---|
58 | case VBOX_SHCL_GUEST_FN_LIST_HDR_READ:
|
---|
59 | RT_FALL_THROUGH();
|
---|
60 | case VBOX_SHCL_GUEST_FN_LIST_ENTRY_READ:
|
---|
61 | RT_FALL_THROUGH();
|
---|
62 | case VBOX_SHCL_GUEST_FN_OBJ_OPEN:
|
---|
63 | RT_FALL_THROUGH();
|
---|
64 | case VBOX_SHCL_GUEST_FN_OBJ_CLOSE:
|
---|
65 | RT_FALL_THROUGH();
|
---|
66 | case VBOX_SHCL_GUEST_FN_OBJ_READ:
|
---|
67 | fAllowed = fHostToGuest;
|
---|
68 | break;
|
---|
69 |
|
---|
70 | case VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT:
|
---|
71 | RT_FALL_THROUGH();
|
---|
72 | case VBOX_SHCL_GUEST_FN_MSG_PEEK_NOWAIT:
|
---|
73 | RT_FALL_THROUGH();
|
---|
74 | case VBOX_SHCL_GUEST_FN_MSG_GET:
|
---|
75 | RT_FALL_THROUGH();
|
---|
76 | case VBOX_SHCL_GUEST_FN_STATUS:
|
---|
77 | RT_FALL_THROUGH();
|
---|
78 | case VBOX_SHCL_GUEST_FN_CANCEL:
|
---|
79 | RT_FALL_THROUGH();
|
---|
80 | case VBOX_SHCL_GUEST_FN_ERROR:
|
---|
81 | fAllowed = fHostToGuest || fGuestToHost;
|
---|
82 | break;
|
---|
83 |
|
---|
84 | default:
|
---|
85 | break;
|
---|
86 | }
|
---|
87 |
|
---|
88 | fAllowed = true; /** @todo FIX !!!! */
|
---|
89 |
|
---|
90 | LogFlowFunc(("uMsg=%RU32, uMode=%RU32 -> fAllowed=%RTbool\n", uMsg, uMode, fAllowed));
|
---|
91 | return fAllowed;
|
---|
92 | }
|
---|
93 |
|
---|
94 | #if 0
|
---|
95 | int vboxSvcClipboardURIReportMsg(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t uParm)
|
---|
96 | {
|
---|
97 | AssertPtrReturn(pClient, VERR_INVALID_POINTER);
|
---|
98 |
|
---|
99 | int rc = VINF_SUCCESS;
|
---|
100 |
|
---|
101 | switch (uMsg)
|
---|
102 | {
|
---|
103 | case VBOX_SHCL_HOST_MSG_TRANSFER_TRANSFER_START:
|
---|
104 | {
|
---|
105 | Assert(pClient->State.URI.fTransferStart == false);
|
---|
106 |
|
---|
107 | LogFlowFunc(("VBOX_SHCL_HOST_MSG_TRANSFER_TRANSFER_START\n"));
|
---|
108 |
|
---|
109 | if ( sharedClipboardSvcGetMode() != VBOX_SHCL_MODE_HOST_TO_GUEST
|
---|
110 | && sharedClipboardSvcGetMode() != VBOX_SHCL_MODE_BIDIRECTIONAL)
|
---|
111 | {
|
---|
112 | LogFlowFunc(("Wrong clipboard mode, skipping\n"));
|
---|
113 | break;
|
---|
114 | }
|
---|
115 |
|
---|
116 | pClient->State.URI.fTransferStart = true;
|
---|
117 | pClient->State.URI.enmTransferDir = (SHCLTRANSFERDIR)uParm;
|
---|
118 | break;
|
---|
119 |
|
---|
120 | }
|
---|
121 |
|
---|
122 | default:
|
---|
123 | AssertMsgFailed(("Invalid message %RU32\n", uMsg));
|
---|
124 | rc = VERR_INVALID_PARAMETER;
|
---|
125 | break;
|
---|
126 | }
|
---|
127 |
|
---|
128 | LogFlowFuncLeaveRC(rc);
|
---|
129 | return rc;
|
---|
130 | }
|
---|
131 |
|
---|
132 | bool sharedClipboardSvcTransferReturnMsg(PSHCLCLIENT pClient, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
|
---|
133 | {
|
---|
134 | RT_NOREF(pClient, cParms, paParms);
|
---|
135 |
|
---|
136 | bool fHandled = false;
|
---|
137 |
|
---|
138 | if ( pClient->State.URI.fTransferStart
|
---|
139 | && cParms >= 2)
|
---|
140 | {
|
---|
141 | HGCMSvcSetU32(&paParms[0], VBOX_SHCL_HOST_MSG_TRANSFER_TRANSFER_START);
|
---|
142 | HGCMSvcSetU32(&paParms[1], pClient->State.URI.enmTransferDir);
|
---|
143 | pClient->State.URI.fTransferStart = false;
|
---|
144 |
|
---|
145 | fHandled = true;
|
---|
146 | }
|
---|
147 |
|
---|
148 | LogFlowFunc(("fHandled=%RTbool\n", fHandled));
|
---|
149 | return fHandled;
|
---|
150 | }
|
---|
151 | #endif
|
---|
152 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
|
---|
153 |
|
---|