1 | /** @file
|
---|
2 | *
|
---|
3 | * Internal helpers/structures for guest control functionality.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2012 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 | #ifndef ____H_GUESTIMPLPRIVATE
|
---|
19 | #define ____H_GUESTIMPLPRIVATE
|
---|
20 |
|
---|
21 | #include <iprt/semaphore.h>
|
---|
22 |
|
---|
23 | #include <VBox/com/com.h>
|
---|
24 | #include <VBox/com/ErrorInfo.h>
|
---|
25 | #include <VBox/com/string.h>
|
---|
26 | #include <VBox/com/VirtualBox.h>
|
---|
27 |
|
---|
28 | #include <map>
|
---|
29 | #include <vector>
|
---|
30 |
|
---|
31 | using namespace com;
|
---|
32 |
|
---|
33 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
34 | # include <VBox/HostServices/GuestControlSvc.h>
|
---|
35 | using namespace guestControl;
|
---|
36 | #endif
|
---|
37 |
|
---|
38 |
|
---|
39 | /* Builds a context ID out of the session ID, process ID and an
|
---|
40 | * increasing count. */
|
---|
41 | #define VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession, uProcess, uCount) \
|
---|
42 | ( (uint32_t)((uSession) & 0xff) << 24 \
|
---|
43 | | (uint32_t)((uProcess) & 0xff) << 16 \
|
---|
44 | | (uint32_t)((uCount) & 0xffff) \
|
---|
45 | )
|
---|
46 |
|
---|
47 |
|
---|
48 | typedef std::vector <LONG> ProcessAffinity;
|
---|
49 | typedef std::vector <Utf8Str> ProcessArguments;
|
---|
50 | typedef std::map <Utf8Str, Utf8Str> ProcessEnvironmentMap;
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Generic class for a all guest control callbacks.
|
---|
55 | */
|
---|
56 | class GuestCtrlCallback
|
---|
57 | {
|
---|
58 | public:
|
---|
59 |
|
---|
60 | GuestCtrlCallback(void);
|
---|
61 |
|
---|
62 | GuestCtrlCallback(eVBoxGuestCtrlCallbackType enmType);
|
---|
63 |
|
---|
64 | virtual ~GuestCtrlCallback(void);
|
---|
65 |
|
---|
66 | /** @todo Copy/comparison operator? */
|
---|
67 |
|
---|
68 | public:
|
---|
69 |
|
---|
70 | int Init(eVBoxGuestCtrlCallbackType enmType);
|
---|
71 |
|
---|
72 | void Destroy(void);
|
---|
73 |
|
---|
74 | eVBoxGuestCtrlCallbackType Type(void);
|
---|
75 |
|
---|
76 | int Wait(RTMSINTERVAL timeoutMS);
|
---|
77 |
|
---|
78 | protected:
|
---|
79 |
|
---|
80 | /** The callback type. */
|
---|
81 | eVBoxGuestCtrlCallbackType mType;
|
---|
82 | /** Callback flags. */
|
---|
83 | uint32_t mFlags;
|
---|
84 | /** Pointer to user-supplied data. */
|
---|
85 | void *pvData;
|
---|
86 | /** Size of user-supplied data. */
|
---|
87 | size_t cbData;
|
---|
88 | /** The event semaphore triggering the*/
|
---|
89 | RTSEMEVENT mEventSem;
|
---|
90 | /** Extended error information, if any. */
|
---|
91 | ErrorInfo mErrorInfo;
|
---|
92 | };
|
---|
93 | typedef std::map <uint32_t, GuestCtrlCallback> GuestCtrlCallbacks;
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Simple structure mantaining guest credentials.
|
---|
97 | */
|
---|
98 | class GuestCredentials
|
---|
99 | {
|
---|
100 | public:
|
---|
101 |
|
---|
102 |
|
---|
103 | public:
|
---|
104 |
|
---|
105 | Utf8Str mUser;
|
---|
106 | Utf8Str mPassword;
|
---|
107 | Utf8Str mDomain;
|
---|
108 | };
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Structure for keeping all the relevant process
|
---|
112 | * starting parameters around.
|
---|
113 | */
|
---|
114 | struct GuestProcessInfo
|
---|
115 | {
|
---|
116 | Utf8Str mCommand;
|
---|
117 | ProcessArguments mArguments;
|
---|
118 | ProcessEnvironmentMap mEnvironment;
|
---|
119 | uint32_t mFlags;
|
---|
120 | ULONG mTimeoutMS;
|
---|
121 | ProcessPriority_T mPriority;
|
---|
122 | ProcessAffinity mAffinity;
|
---|
123 | };
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Class representing the "value" side of a "key=value" pair.
|
---|
127 | */
|
---|
128 | class GuestProcessStreamValue
|
---|
129 | {
|
---|
130 | public:
|
---|
131 |
|
---|
132 | GuestProcessStreamValue() { }
|
---|
133 | GuestProcessStreamValue(const char *pszValue)
|
---|
134 | : mValue(pszValue) {}
|
---|
135 |
|
---|
136 | GuestProcessStreamValue(const GuestProcessStreamValue& aThat)
|
---|
137 | : mValue(aThat.mValue) {}
|
---|
138 |
|
---|
139 | Utf8Str mValue;
|
---|
140 | };
|
---|
141 |
|
---|
142 | /** Map containing "key=value" pairs of a guest process stream. */
|
---|
143 | typedef std::pair< Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPair;
|
---|
144 | typedef std::map < Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPairMap;
|
---|
145 | typedef std::map < Utf8Str, GuestProcessStreamValue >::iterator GuestCtrlStreamPairMapIter;
|
---|
146 | typedef std::map < Utf8Str, GuestProcessStreamValue >::const_iterator GuestCtrlStreamPairMapIterConst;
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Class representing a block of stream pairs (key=value). Each block in a raw guest
|
---|
150 | * output stream is separated by "\0\0", each pair is separated by "\0". The overall
|
---|
151 | * end of a guest stream is marked by "\0\0\0\0".
|
---|
152 | */
|
---|
153 | class GuestProcessStreamBlock
|
---|
154 | {
|
---|
155 | public:
|
---|
156 |
|
---|
157 | GuestProcessStreamBlock();
|
---|
158 |
|
---|
159 | //GuestProcessStreamBlock(GuestProcessStreamBlock &);
|
---|
160 |
|
---|
161 | virtual ~GuestProcessStreamBlock();
|
---|
162 |
|
---|
163 | public:
|
---|
164 |
|
---|
165 | void Clear();
|
---|
166 |
|
---|
167 | #ifdef DEBUG
|
---|
168 | void Dump();
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | int GetInt64Ex(const char *pszKey, int64_t *piVal);
|
---|
172 |
|
---|
173 | int64_t GetInt64(const char *pszKey);
|
---|
174 |
|
---|
175 | size_t GetCount();
|
---|
176 |
|
---|
177 | const char* GetString(const char *pszKey);
|
---|
178 |
|
---|
179 | int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
|
---|
180 |
|
---|
181 | uint32_t GetUInt32(const char *pszKey);
|
---|
182 |
|
---|
183 | int SetValue(const char *pszKey, const char *pszValue);
|
---|
184 |
|
---|
185 | protected:
|
---|
186 |
|
---|
187 | GuestCtrlStreamPairMap m_mapPairs;
|
---|
188 | };
|
---|
189 |
|
---|
190 | /** Vector containing multiple allocated stream pair objects. */
|
---|
191 | typedef std::vector< GuestProcessStreamBlock > GuestCtrlStreamObjects;
|
---|
192 | typedef std::vector< GuestProcessStreamBlock >::iterator GuestCtrlStreamObjectsIter;
|
---|
193 | typedef std::vector< GuestProcessStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Class for parsing machine-readable guest process output by VBoxService'
|
---|
197 | * toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
|
---|
198 | */
|
---|
199 | class GuestProcessStream
|
---|
200 | {
|
---|
201 |
|
---|
202 | public:
|
---|
203 |
|
---|
204 | GuestProcessStream();
|
---|
205 |
|
---|
206 | virtual ~GuestProcessStream();
|
---|
207 |
|
---|
208 | public:
|
---|
209 |
|
---|
210 | int AddData(const BYTE *pbData, size_t cbData);
|
---|
211 |
|
---|
212 | void Destroy();
|
---|
213 |
|
---|
214 | #ifdef DEBUG
|
---|
215 | void Dump(const char *pszFile);
|
---|
216 | #endif
|
---|
217 |
|
---|
218 | uint32_t GetOffset();
|
---|
219 |
|
---|
220 | uint32_t GetSize();
|
---|
221 |
|
---|
222 | int ParseBlock(GuestProcessStreamBlock &streamBlock);
|
---|
223 |
|
---|
224 | protected:
|
---|
225 |
|
---|
226 | /** Currently allocated size of internal stream buffer. */
|
---|
227 | uint32_t m_cbAllocated;
|
---|
228 | /** Currently used size of allocated internal stream buffer. */
|
---|
229 | uint32_t m_cbSize;
|
---|
230 | /** Current offset within the internal stream buffer. */
|
---|
231 | uint32_t m_cbOffset;
|
---|
232 | /** Internal stream buffer. */
|
---|
233 | BYTE *m_pbBuffer;
|
---|
234 | };
|
---|
235 |
|
---|
236 | class Guest;
|
---|
237 | class Progress;
|
---|
238 |
|
---|
239 | class GuestTask
|
---|
240 | {
|
---|
241 |
|
---|
242 | public:
|
---|
243 |
|
---|
244 | enum TaskType
|
---|
245 | {
|
---|
246 | /** Copies a file from host to the guest. */
|
---|
247 | TaskType_CopyFileToGuest = 50,
|
---|
248 | /** Copies a file from guest to the host. */
|
---|
249 | TaskType_CopyFileFromGuest = 55,
|
---|
250 | /** Update Guest Additions by directly copying the required installer
|
---|
251 | * off the .ISO file, transfer it to the guest and execute the installer
|
---|
252 | * with system privileges. */
|
---|
253 | TaskType_UpdateGuestAdditions = 100
|
---|
254 | };
|
---|
255 |
|
---|
256 | GuestTask(TaskType aTaskType, Guest *aThat, Progress *aProgress);
|
---|
257 |
|
---|
258 | virtual ~GuestTask();
|
---|
259 |
|
---|
260 | int startThread();
|
---|
261 |
|
---|
262 | static int taskThread(RTTHREAD aThread, void *pvUser);
|
---|
263 | static int uploadProgress(unsigned uPercent, void *pvUser);
|
---|
264 | static HRESULT setProgressSuccess(ComObjPtr<Progress> pProgress);
|
---|
265 | static HRESULT setProgressErrorMsg(HRESULT hr,
|
---|
266 | ComObjPtr<Progress> pProgress, const char * pszText, ...);
|
---|
267 | static HRESULT setProgressErrorParent(HRESULT hr,
|
---|
268 | ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest);
|
---|
269 |
|
---|
270 | TaskType taskType;
|
---|
271 | ComObjPtr<Guest> pGuest;
|
---|
272 | ComObjPtr<Progress> pProgress;
|
---|
273 | HRESULT rc;
|
---|
274 |
|
---|
275 | /* Task data. */
|
---|
276 | Utf8Str strSource;
|
---|
277 | Utf8Str strDest;
|
---|
278 | Utf8Str strUserName;
|
---|
279 | Utf8Str strPassword;
|
---|
280 | ULONG uFlags;
|
---|
281 | };
|
---|
282 | #endif // ____H_GUESTIMPLPRIVATE
|
---|
283 |
|
---|