VirtualBox

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

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

Shared Clipboard/URI: Update; more work on root list handling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.1 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-utils.cpp 80283 2019-08-15 08:47:23Z 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_GUEST_FN_LIST_OPEN:
55 RT_FALL_THROUGH();
56 case VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_CLOSE:
57 RT_FALL_THROUGH();
58 case VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_HDR_READ:
59 RT_FALL_THROUGH();
60 case VBOX_SHARED_CLIPBOARD_GUEST_FN_LIST_ENTRY_READ:
61 RT_FALL_THROUGH();
62 case VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_OPEN:
63 RT_FALL_THROUGH();
64 case VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_CLOSE:
65 RT_FALL_THROUGH();
66 case VBOX_SHARED_CLIPBOARD_GUEST_FN_OBJ_READ:
67 fAllowed = fHostToGuest;
68 break;
69
70 case VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_PEEK_WAIT:
71 RT_FALL_THROUGH();
72 case VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_PEEK_NOWAIT:
73 RT_FALL_THROUGH();
74 case VBOX_SHARED_CLIPBOARD_GUEST_FN_MSG_GET:
75 RT_FALL_THROUGH();
76 case VBOX_SHARED_CLIPBOARD_GUEST_FN_STATUS:
77 RT_FALL_THROUGH();
78 case VBOX_SHARED_CLIPBOARD_GUEST_FN_CANCEL:
79 RT_FALL_THROUGH();
80 case VBOX_SHARED_CLIPBOARD_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
94int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uParm)
95{
96 AssertPtrReturn(pClientData, VERR_INVALID_POINTER);
97
98 int rc = VINF_SUCCESS;
99
100 switch (uMsg)
101 {
102 case VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START:
103 {
104 LogFlowFunc(("VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START\n"));
105
106 if ( vboxSvcClipboardGetMode() != VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST
107 && vboxSvcClipboardGetMode() != VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL)
108 {
109 LogFlowFunc(("Wrong clipboard mode, skipping\n"));
110 break;
111 }
112
113 pClientData->State.URI.fTransferStart = true;
114 pClientData->State.URI.enmTransferDir = (SHAREDCLIPBOARDURITRANSFERDIR)uParm;
115 break;
116
117 }
118
119 default:
120 AssertMsgFailed(("Invalid message %RU32\n", uMsg));
121 rc = VERR_INVALID_PARAMETER;
122 break;
123 }
124
125 LogFlowFuncLeaveRC(rc);
126 return rc;
127}
128
129bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
130{
131 RT_NOREF(pClientData, cParms, paParms);
132
133 bool fHandled = false;
134
135 if ( pClientData->State.URI.fTransferStart
136 && cParms >= 2)
137 {
138 HGCMSvcSetU32(&paParms[0], VBOX_SHARED_CLIPBOARD_HOST_MSG_URI_TRANSFER_START);
139 HGCMSvcSetU32(&paParms[1], pClientData->State.URI.enmTransferDir);
140 pClientData->State.URI.fTransferStart = false;
141
142 fHandled = true;
143 }
144
145 LogFlowFunc(("fHandled=%RTbool\n", fHandled));
146 return fHandled;
147}
148#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
149
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