1 | /* $Id: VBoxSharedClipboardSvc-utils.cpp 79120 2019-06-13 10:08:33Z 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/err.h>
|
---|
26 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
27 | #include <VBox/HostServices/VBoxClipboardExt.h>
|
---|
28 |
|
---|
29 | #include <iprt/path.h>
|
---|
30 |
|
---|
31 | #include "VBoxSharedClipboardSvc-internal.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
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_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST
|
---|
45 | || uMode == VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
|
---|
46 |
|
---|
47 | const bool fGuestToHost = uMode == VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST
|
---|
48 | || uMode == VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
|
---|
49 |
|
---|
50 | bool fAllowed = false; /* If in doubt, don't allow. */
|
---|
51 |
|
---|
52 | switch (uMsg)
|
---|
53 | {
|
---|
54 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR:
|
---|
55 | RT_FALL_THROUGH();
|
---|
56 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK:
|
---|
57 | RT_FALL_THROUGH();
|
---|
58 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR:
|
---|
59 | RT_FALL_THROUGH();
|
---|
60 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR:
|
---|
61 | RT_FALL_THROUGH();
|
---|
62 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA:
|
---|
63 | fAllowed = fGuestToHost;
|
---|
64 | break;
|
---|
65 |
|
---|
66 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR:
|
---|
67 | RT_FALL_THROUGH();
|
---|
68 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK:
|
---|
69 | RT_FALL_THROUGH();
|
---|
70 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR:
|
---|
71 | RT_FALL_THROUGH();
|
---|
72 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR:
|
---|
73 | RT_FALL_THROUGH();
|
---|
74 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA:
|
---|
75 | fAllowed = fHostToGuest;
|
---|
76 | break;
|
---|
77 |
|
---|
78 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL:
|
---|
79 | RT_FALL_THROUGH();
|
---|
80 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR:
|
---|
81 | fAllowed = fHostToGuest || fGuestToHost;
|
---|
82 | break;
|
---|
83 |
|
---|
84 | default:
|
---|
85 | break;
|
---|
86 | }
|
---|
87 |
|
---|
88 | LogFlowFunc(("uMsg=%RU32, uMode=%RU32 -> fAllowed=%RTbool\n", uMsg, uMode, fAllowed));
|
---|
89 | return fAllowed;
|
---|
90 | }
|
---|
91 |
|
---|
92 | int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uFormats)
|
---|
93 | {
|
---|
94 | AssertPtrReturn(pClientData, VERR_INVALID_POINTER);
|
---|
95 |
|
---|
96 | RT_NOREF(uFormats);
|
---|
97 |
|
---|
98 | LogFlowFunc(("uMsg=%RU32\n", uMsg));
|
---|
99 |
|
---|
100 | if (!vboxSvcClipboardURIMsgIsAllowed(vboxSvcClipboardGetMode(), uMsg))
|
---|
101 | return VERR_ACCESS_DENIED;
|
---|
102 |
|
---|
103 | int rc = VINF_SUCCESS;
|
---|
104 |
|
---|
105 | switch (uMsg)
|
---|
106 | {
|
---|
107 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR:
|
---|
108 | {
|
---|
109 | if (SharedClipboardURICtxMaximumTransfersReached(&pClientData->URI))
|
---|
110 | {
|
---|
111 | rc = VERR_SHCLPB_MAX_TRANSFERS_REACHED;
|
---|
112 | break;
|
---|
113 | }
|
---|
114 |
|
---|
115 | break;
|
---|
116 | }
|
---|
117 |
|
---|
118 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR:
|
---|
119 | {
|
---|
120 | if (SharedClipboardURICtxMaximumTransfersReached(&pClientData->URI))
|
---|
121 | {
|
---|
122 | rc = VERR_SHCLPB_MAX_TRANSFERS_REACHED;
|
---|
123 | break;
|
---|
124 | }
|
---|
125 |
|
---|
126 | break;
|
---|
127 | }
|
---|
128 |
|
---|
129 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK:
|
---|
130 | break;
|
---|
131 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK:
|
---|
132 | break;
|
---|
133 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR:
|
---|
134 | break;
|
---|
135 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR:
|
---|
136 | break;
|
---|
137 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR:
|
---|
138 | break;
|
---|
139 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR:
|
---|
140 | break;
|
---|
141 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA:
|
---|
142 | break;
|
---|
143 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA:
|
---|
144 | break;
|
---|
145 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL:
|
---|
146 | break;
|
---|
147 | case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR:
|
---|
148 | break;
|
---|
149 |
|
---|
150 | default:
|
---|
151 | AssertMsgFailed(("Invalid message %RU32\n", uMsg));
|
---|
152 | rc = VERR_INVALID_PARAMETER;
|
---|
153 | break;
|
---|
154 | }
|
---|
155 |
|
---|
156 | LogFlowFuncLeaveRC(rc);
|
---|
157 | return rc;
|
---|
158 | }
|
---|
159 |
|
---|
160 | bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
|
---|
161 | {
|
---|
162 | RT_NOREF(cParms);
|
---|
163 | RT_NOREF(paParms, pClientData);
|
---|
164 |
|
---|
165 | bool fHandled = false;
|
---|
166 |
|
---|
167 | LogFlowFunc(("fHandled=%RTbool\n", fHandled));
|
---|
168 | return fHandled;
|
---|
169 | }
|
---|
170 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
171 |
|
---|