VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-utils.cpp@ 79267

Last change on this file since 79267 was 79267, checked in by vboxsync, 5 years ago

Shared Clipboard/URI: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.7 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-utils.cpp 79267 2019-06-21 10:11:59Z 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_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 */
42bool 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
92int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uFormats)
93{
94 AssertPtrReturn(pClientData, VERR_INVALID_POINTER);
95
96 RT_NOREF(uFormats);
97
98 if (!vboxSvcClipboardURIMsgIsAllowed(vboxSvcClipboardGetMode(), uMsg))
99 return VERR_ACCESS_DENIED;
100
101 int rc = VINF_SUCCESS;
102
103 switch (uMsg)
104 {
105 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR:
106 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_HDR\n"));
107 break;
108 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR:
109 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_HDR\n"));
110 break;
111 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK:
112 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DATA_CHUNK\n"));
113 break;
114 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK:
115 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DATA_CHUNK\n"));
116 break;
117 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR:
118 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_DIR\n"));
119 break;
120 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR:
121 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_DIR\n"));
122 break;
123 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR:
124 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_HDR\n"));
125 break;
126 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR:
127 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_HDR\n"));
128 break;
129 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA:
130 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_READ_FILE_DATA\n"));
131 break;
132 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA:
133 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_WRITE_FILE_DATA\n"));
134 break;
135 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL:
136 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_CANCEL\n"));
137 break;
138 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR:
139 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_ERROR\n"));
140 break;
141
142 default:
143 AssertMsgFailed(("Invalid message %RU32\n", uMsg));
144 rc = VERR_INVALID_PARAMETER;
145 break;
146 }
147
148 LogFlowFuncLeaveRC(rc);
149 return rc;
150}
151
152static bool s_fReqHdr = false;
153
154bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
155{
156 RT_NOREF(pClientData, cParms, paParms);
157
158 bool fHandled = false;
159
160#if 0
161 PSHAREDCLIPBOARDURITRANSFER pTransfer = SharedClipboardURICtxGetTransfer(&pClientData->URI, 0 /* Index */);
162 if (pTransfer)
163 {
164 if ( !s_fReqHdr
165 && !pTransfer->State.pHeader)
166 {
167 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA\n"));
168
169 HGCMSvcSetU32(&paParms[0], VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA);
170 HGCMSvcSetU32(&paParms[1], VBOX_SHARED_CLIPBOARD_FMT_URI_LIST /* fFormats */);
171 fHandled = true;
172
173 s_fReqHdr = true;
174 }
175 else
176 {
177 }
178 }
179#endif
180
181 LogFlowFunc(("fHandled=%RTbool\n", fHandled));
182 return fHandled;
183}
184#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
185
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette