1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
/* $Id: ApplianceImpl.h $ */
/** @file
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ____H_APPLIANCEIMPL
#define ____H_APPLIANCEIMPL
/* VBox includes */
#include "VirtualBoxBase.h"
/* Todo: This file needs massive cleanup. Split IAppliance in a public and
* private classes. */
#include <iprt/tar.h>
#include <iprt/circbuf.h>
#include <VBox/vd.h>
#include <iprt/sha.h>
#include "ovfreader.h"
#include <set>
/* VBox forward declarations */
class Progress;
class VirtualSystemDescription;
struct VirtualSystemDescriptionEntry;
struct LocationInfo;
typedef struct VDINTERFACE *PVDINTERFACE;
typedef struct VDINTERFACEIO *PVDINTERFACEIO;
typedef struct SHASTORAGE *PSHASTORAGE;
typedef enum applianceIOName { applianceIOTar, applianceIOFile, applianceIOSha } APPLIANCEIONAME;
namespace ovf
{
struct HardDiskController;
struct VirtualSystem;
class OVFReader;
struct DiskImage;
struct EnvelopeData;
}
namespace xml
{
class Document;
class ElementNode;
}
namespace settings
{
class MachineConfigFile;
}
class ATL_NO_VTABLE Appliance :
public VirtualBoxBase,
VBOX_SCRIPTABLE_IMPL(IAppliance)
{
public:
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Appliance, IAppliance)
DECLARE_NOT_AGGREGATABLE(Appliance)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(Appliance)
VBOX_DEFAULT_INTERFACE_ENTRIES(IAppliance)
END_COM_MAP()
DECLARE_EMPTY_CTOR_DTOR (Appliance)
// public initializer/uninitializer for internal purposes only
HRESULT FinalConstruct() { return BaseFinalConstruct(); }
void FinalRelease() { uninit(); BaseFinalRelease(); }
HRESULT init(VirtualBox *aVirtualBox);
void uninit();
/* IAppliance properties */
STDMETHOD(COMGETTER(Path))(BSTR *aPath);
STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines));
/* IAppliance methods */
/* Import methods */
STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
STDMETHOD(Interpret)(void);
STDMETHOD(ImportMachines)(ComSafeArrayIn(ImportOptions_T, options), IProgress **aProgress);
/* Export methods */
STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
STDMETHOD(Write)(IN_BSTR format, ComSafeArrayIn(ExportOptions_T, options), IN_BSTR path, IProgress **aProgress);
STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
/* public methods only for internal purposes */
static HRESULT setErrorStatic(HRESULT aResultCode,
const Utf8Str &aText)
{
return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
}
/* private instance data */
private:
/** weak VirtualBox parent */
VirtualBox* const mVirtualBox;
struct ImportStack;
struct TaskOVF;
struct Data; // opaque, defined in ApplianceImpl.cpp
Data *m;
enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
/*******************************************************************************
* General stuff
******************************************************************************/
bool isApplianceIdle();
HRESULT searchUniqueVMName(Utf8Str& aName) const;
HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
HRESULT setUpProgress(ComObjPtr<Progress> &pProgress,
const Bstr &bstrDescription,
SetUpProgressMode mode);
void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
void addWarning(const char* aWarning, ...);
void disksWeight();
void parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
HRESULT initSetOfSupportedStandardsURI();
Utf8Str typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
std::set<Utf8Str> URIFromTypeOfVirtualDiskFormat(Utf8Str type);
HRESULT initApplianceIONameMap();
Utf8Str applianceIOName(APPLIANCEIONAME type) const;
/*******************************************************************************
* Read stuff
******************************************************************************/
HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
HRESULT readFS(TaskOVF *pTask);
HRESULT readFSOVF(TaskOVF *pTask);
HRESULT readFSOVA(TaskOVF *pTask);
HRESULT readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
HRESULT readS3(TaskOVF *pTask);
/*******************************************************************************
* Import stuff
******************************************************************************/
HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
HRESULT importFS(TaskOVF *pTask);
HRESULT importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
HRESULT importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
HRESULT importS3(TaskOVF *pTask);
HRESULT readFileToBuf(const Utf8Str &strFile,
void **ppvBuf,
size_t *pcbSize,
bool fCreateDigest,
PVDINTERFACEIO pCallbacks,
PSHASTORAGE pStorage);
HRESULT readTarFileToBuf(RTTAR tar,
const Utf8Str &strFile,
void **ppvBuf,
size_t *pcbSize,
bool fCreateDigest,
PVDINTERFACEIO pCallbacks,
PSHASTORAGE pStorage);
HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
uint32_t ulAddressOnParent,
Bstr &controllerType,
int32_t &lControllerPort,
int32_t &lDevice);
void importOneDiskImage(const ovf::DiskImage &di,
Utf8Str *strTargetPath,
ComObjPtr<Medium> &pTargetHD,
ImportStack &stack,
PVDINTERFACEIO pCallbacks,
PSHASTORAGE pStorage);
void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
ComObjPtr<VirtualSystemDescription> &vsdescThis,
ComPtr<IMachine> &pNewMachine,
ImportStack &stack,
PVDINTERFACEIO pCallbacks,
PSHASTORAGE pStorage);
void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
ComPtr<IMachine> &pNewMachine,
ImportStack &stack,
PVDINTERFACEIO pCallbacks,
PSHASTORAGE pStorage);
void importMachines(ImportStack &stack,
PVDINTERFACEIO pCallbacks,
PSHASTORAGE pStorage);
/*******************************************************************************
* Write stuff
******************************************************************************/
HRESULT writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
HRESULT writeFS(TaskOVF *pTask);
HRESULT writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
HRESULT writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
HRESULT writeS3(TaskOVF *pTask);
struct XMLStack;
void buildXML(AutoWriteLockBase& writeLock,
xml::Document &doc,
XMLStack &stack,
const Utf8Str &strPath,
ovf::OVFVersion_T enFormat);
void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
xml::ElementNode &elmToAddVirtualSystemsTo,
std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
ComObjPtr<VirtualSystemDescription> &vsdescThis,
ovf::OVFVersion_T enFormat,
XMLStack &stack);
HRESULT preCheckImageAvailability(PSHASTORAGE pSHAStorage,
RTCString &availableImage);
friend class Machine;
};
void parseURI(Utf8Str strUri, LocationInfo &locInfo);
struct VirtualSystemDescriptionEntry
{
uint32_t ulIndex; // zero-based index of this entry within array
VirtualSystemDescriptionType_T type; // type of this entry
Utf8Str strRef; // reference number (hard disk controllers only)
Utf8Str strOvf; // original OVF value (type-dependent)
Utf8Str strVBoxSuggested; // configuration value (type-dependent); original value suggested by interpret()
Utf8Str strVBoxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
bool skipIt; ///< used during export to skip some parts if it's needed
};
class ATL_NO_VTABLE VirtualSystemDescription :
public VirtualBoxBase,
VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
{
friend class Appliance;
public:
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualSystemDescription, IVirtualSystemDescription)
DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(VirtualSystemDescription)
VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualSystemDescription)
END_COM_MAP()
DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
// public initializer/uninitializer for internal purposes only
HRESULT FinalConstruct() { return BaseFinalConstruct(); }
void FinalRelease() { uninit(); BaseFinalRelease(); }
HRESULT init();
void uninit();
/* IVirtualSystemDescription properties */
STDMETHOD(COMGETTER(Count))(ULONG *aCount);
/* IVirtualSystemDescription methods */
STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
ComSafeArrayOut(BSTR, aRefs),
ComSafeArrayOut(BSTR, aOvfValues),
ComSafeArrayOut(BSTR, aVBoxValues),
ComSafeArrayOut(BSTR, aExtraConfigValues));
STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
ComSafeArrayOut(BSTR, aRefs),
ComSafeArrayOut(BSTR, aOvfValues),
ComSafeArrayOut(BSTR, aVBoxValues),
ComSafeArrayOut(BSTR, aExtraConfigValues));
STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
VirtualSystemDescriptionValueType_T aWhich,
ComSafeArrayOut(BSTR, aValues));
STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
ComSafeArrayIn(IN_BSTR, aVBoxValues),
ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
IN_BSTR aVBoxValue,
IN_BSTR aExtraConfigValue);
/* public methods only for internal purposes */
void addEntry(VirtualSystemDescriptionType_T aType,
const Utf8Str &strRef,
const Utf8Str &aOvfValue,
const Utf8Str &aVBoxValue,
uint32_t ulSizeMB = 0,
const Utf8Str &strExtraConfig = "");
std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
void importVBoxMachineXML(const xml::ElementNode &elmMachine);
const settings::MachineConfigFile* getMachineConfig() const;
void removeByType(VirtualSystemDescriptionType_T aType);
/* private instance data */
private:
struct Data;
Data *m;
friend class Machine;
};
#endif // !____H_APPLIANCEIMPL
/* vi: set tabstop=4 shiftwidth=4 expandtab: */
|