VirtualBox

source: vbox/trunk/include/VBox/GuestHost/SharedClipboard-x11.h@ 91980

最後變更 在這個檔案從91980是 89947,由 vboxsync 提交於 4 年 前

X11: Host Services: Shared Clipboard: improve error code path handling, bugref:10038.

This commit improves error code path handling for X11 part of host Shared Clipboard
service. In particular, it adjusts initialization calls to match to its de-init counterpart.
It also adds more resources release on error path. In addition, this commit limits number of
simmultaneous HGCM connections to ShCl host service in order to prevent potential host flooding.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 7.9 KB
 
1/** @file
2 * Shared Clipboard - Common X11 code.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h
27#define VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <X11/Intrinsic.h>
33
34#include <iprt/thread.h>
35
36#include <VBox/GuestHost/SharedClipboard.h>
37#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
38# include <VBox/GuestHost/SharedClipboard-transfers.h>
39#endif
40
41/**
42 * The maximum number of simultaneous connections to shared clipboard service.
43 * This constant limits amount of GUEST -> HOST connections to shared clipboard host service
44 * for X11 host only. Once amount of connections reaches this number, all the
45 * further attempts to CONNECT will be dropped on an early stage. Possibility to connect
46 * is available again after one of existing connections is closed by DISCONNECT call.
47 */
48#define VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX (20)
49
50/** Enables the Xt busy / update handling. */
51#define VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY 1
52
53/**
54 * Enumeration for all clipboard formats which we support on X11.
55 */
56typedef enum _SHCLX11FMT
57{
58 SHCLX11FMT_INVALID = 0,
59 SHCLX11FMT_TARGETS,
60 SHCLX11FMT_TEXT, /* Treat this as UTF-8, but it may really be ascii */
61 SHCLX11FMT_UTF8,
62 SHCLX11FMT_BMP,
63 SHCLX11FMT_HTML
64#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
65 , SHCLX11FMT_URI_LIST
66#endif
67} SHCLX11FMT;
68
69/**
70 * The table maps X11 names to data formats
71 * and to the corresponding VBox clipboard formats.
72 */
73typedef struct SHCLX11FMTTABLE
74{
75 /** The X11 atom name of the format (several names can match one format). */
76 const char *pcszAtom;
77 /** The format corresponding to the name. */
78 SHCLX11FMT enmFmtX11;
79 /** The corresponding VBox clipboard format. */
80 SHCLFORMAT uFmtVBox;
81} SHCLX11FMTTABLE;
82
83#define NIL_CLIPX11FORMAT 0
84
85/** Defines an index of the X11 clipboad format table. */
86typedef unsigned SHCLX11FMTIDX;
87
88/**
89 * Structure for maintaining a Shared Clipboard context on X11 platforms.
90 */
91typedef struct _SHCLX11CTX
92{
93 /** Opaque data structure describing the front-end. */
94 PSHCLCONTEXT pFrontend;
95 /** Is an X server actually available? */
96 bool fHaveX11;
97 /** The X Toolkit application context structure. */
98 XtAppContext pAppContext;
99
100 /** We have a separate thread to wait for window and clipboard events. */
101 RTTHREAD Thread;
102 /** Flag indicating that the thread is in a started state. */
103 bool fThreadStarted;
104
105 /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
106 Widget pWidget;
107
108 /** Should we try to grab the clipboard on startup? */
109 bool fGrabClipboardOnStart;
110
111 /** The best text format X11 has to offer, as an index into the formats table. */
112 SHCLX11FMTIDX idxFmtText;
113 /** The best bitmap format X11 has to offer, as an index into the formats table. */
114 SHCLX11FMTIDX idxFmtBmp;
115 /** The best HTML format X11 has to offer, as an index into the formats table. */
116 SHCLX11FMTIDX idxFmtHTML;
117#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
118 /** The best HTML format X11 has to offer, as an index into the formats table. */
119 SHCLX11FMTIDX idxFmtURI;
120# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
121 /** HTTP transfer context data. */
122 SHCLHTTPCONTEXT HttpCtx;
123# endif
124#endif
125 /** What kind of formats does VBox have to offer? */
126 SHCLFORMATS vboxFormats;
127 /** Cache of the last unicode data that we received. */
128 void *pvUnicodeCache;
129 /** Size of the unicode data in the cache. */
130 uint32_t cbUnicodeCache;
131 /** When we wish the clipboard to exit, we have to wake up the event
132 * loop. We do this by writing into a pipe. This end of the pipe is
133 * the end that another thread can write to. */
134 int wakeupPipeWrite;
135 /** The reader end of the pipe. */
136 int wakeupPipeRead;
137 /** A pointer to the XFixesSelectSelectionInput function. */
138 void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
139 /** The first XFixes event number. */
140 int fixesEventBase;
141#ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
142 /** XtGetSelectionValue on some versions of libXt isn't re-entrant
143 * so block overlapping requests on this flag. */
144 bool fXtBusy;
145 /** If a request is blocked on the previous flag, set this flag to request
146 * an update later - the first callback should check and clear this flag
147 * before processing the callback event. */
148 bool fXtNeedsUpdate;
149#endif
150} SHCLX11CTX, *PSHCLX11CTX;
151
152/** @name Shared Clipboard APIs for X11.
153 * @{
154 */
155int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCONTEXT pParent, bool fHeadless);
156void ShClX11Destroy(PSHCLX11CTX pCtx);
157int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
158int ShClX11ThreadStop(PSHCLX11CTX pCtx);
159int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
160int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
161/** @} */
162
163/** @name Shared Clipboard callbacks which have to be implemented the X11 backend and host service.
164 * @{
165 */
166/**
167 * Callback for reading clipboard data from the guest.
168 * The function will be invoked for every single target the clipboard requests.
169 *
170 * @note Runs in Xt event thread.
171 *
172 * @returns VBox status code. VERR_NO_DATA if no data available.
173 * @param pCtx Pointer to the host clipboard structure.
174 * @param uFmt The format in which the data should be transferred
175 * (VBOX_SHCL_FMT_XXX).
176 * @param ppv Returns an allocated buffer with data read from the guest on success.
177 * Needs to be free'd with RTMemFree() by the caller.
178 * @param pcb Returns the amount of data read (in bytes) on success.
179 */
180DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb);
181
182/**
183 * Reports formats available in the X11 clipboard to VBox.
184 *
185 * @note Runs in Xt event thread.
186 *
187 * @param pCtx Opaque context pointer for the glue code.
188 * @param fFormats The formats available.
189 */
190DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS fFormats);
191
192/**
193 * Called by the backend to tell us that a request for data from X11 has completed.
194 *
195 * @param pCtx Our context information.
196 * @param rcCompletion The completion status of the request.
197 * @param pReq The request structure that we passed in when we started
198 * the request. We RTMemFree() this in this function.
199 * @param pv The clipboard data returned from X11 if the request succeeded (see @a rcCompletion).
200 * @param cb The size of the data in @a pv.
201 */
202DECLCALLBACK(void) ShClX11RequestFromX11CompleteCallback(PSHCLCONTEXT pCtx, int rcCompletion,
203 CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
204/** @} */
205
206#endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
207
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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