VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImpl.h@ 60034

Last change on this file since 60034 was 59621, checked in by vboxsync, 9 years ago

ApplianceImplImport.cpp,++: Pushed the IPRT VFS stuff futher down, only going to the VD I/O wrappers when start getting down into the media code during import. Reworked the OVA releated import code to skip files it doesn't care about (like message resource xml files which we don't implement) and not be picky about which order files the OVF, MF and CERT files come in (todo: make sure it isn't picky about the order of disks either). Read the manifest and certificate file during the read() method.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1/* $Id: ApplianceImpl.h 59621 2016-02-10 00:51:35Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2013 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_APPLIANCEIMPL
19#define ____H_APPLIANCEIMPL
20
21/* VBox includes */
22#include <VBox/settings.h>
23#include "VirtualSystemDescriptionWrap.h"
24#include "ApplianceWrap.h"
25#include "MediumFormatImpl.h"
26
27/* Todo: This file needs massive cleanup. Split IAppliance in a public and
28 * private classes. */
29#include <iprt/tar.h>
30#include "ovfreader.h"
31#include <set>
32
33/* VBox forward declarations */
34class Progress;
35class VirtualSystemDescription;
36struct VirtualSystemDescriptionEntry;
37struct LocationInfo;
38typedef struct VDINTERFACE *PVDINTERFACE;
39typedef struct VDINTERFACEIO *PVDINTERFACEIO;
40typedef struct SHASTORAGE *PSHASTORAGE;
41
42typedef enum applianceIOName { applianceIOTar, applianceIOFile, applianceIOSha } APPLIANCEIONAME;
43
44namespace ovf
45{
46 struct HardDiskController;
47 struct VirtualSystem;
48 class OVFReader;
49 struct DiskImage;
50 struct EnvelopeData;
51}
52
53namespace xml
54{
55 class Document;
56 class ElementNode;
57}
58
59namespace settings
60{
61 class MachineConfigFile;
62}
63
64class ATL_NO_VTABLE Appliance :
65 public ApplianceWrap
66{
67public:
68
69 DECLARE_EMPTY_CTOR_DTOR(Appliance)
70
71 HRESULT FinalConstruct();
72 void FinalRelease();
73
74
75 HRESULT init(VirtualBox *aVirtualBox);
76 void uninit();
77
78 /* public methods only for internal purposes */
79
80 static HRESULT i_setErrorStatic(HRESULT aResultCode,
81 const Utf8Str &aText)
82 {
83 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
84 }
85
86 /* private instance data */
87private:
88 // wrapped IAppliance properties
89 HRESULT getPath(com::Utf8Str &aPath);
90 HRESULT getDisks(std::vector<com::Utf8Str> &aDisks);
91 HRESULT getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions);
92 HRESULT getMachines(std::vector<com::Utf8Str> &aMachines);
93
94 // wrapped IAppliance methods
95 HRESULT read(const com::Utf8Str &aFile,
96 ComPtr<IProgress> &aProgress);
97 HRESULT interpret();
98 HRESULT importMachines(const std::vector<ImportOptions_T> &aOptions,
99 ComPtr<IProgress> &aProgress);
100 HRESULT createVFSExplorer(const com::Utf8Str &aURI,
101 ComPtr<IVFSExplorer> &aExplorer);
102 HRESULT write(const com::Utf8Str &aFormat,
103 const std::vector<ExportOptions_T> &aOptions,
104 const com::Utf8Str &aPath,
105 ComPtr<IProgress> &aProgress);
106 HRESULT getWarnings(std::vector<com::Utf8Str> &aWarnings);
107 HRESULT getPasswordIds(std::vector<com::Utf8Str> &aIdentifiers);
108 HRESULT getMediumIdsForPasswordId(const com::Utf8Str &aPasswordId, std::vector<com::Guid> &aIdentifiers);
109 HRESULT addPasswords(const std::vector<com::Utf8Str> &aIdentifiers,
110 const std::vector<com::Utf8Str> &aPasswords);
111
112 /** weak VirtualBox parent */
113 VirtualBox* const mVirtualBox;
114
115 struct ImportStack;
116 class TaskOVF;
117 struct Data; // opaque, defined in ApplianceImpl.cpp
118 Data *m;
119
120 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
121
122 /** @name General stuff
123 * @{
124 */
125 bool i_isApplianceIdle();
126 HRESULT i_searchUniqueVMName(Utf8Str& aName) const;
127 HRESULT i_searchUniqueDiskImageFilePath(Utf8Str& aName) const;
128 HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress,
129 const Bstr &bstrDescription,
130 SetUpProgressMode mode);
131 void i_waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
132 void i_addWarning(const char* aWarning, ...);
133 void i_disksWeight();
134 void i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
135
136 static DECLCALLBACK(int) i_taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
137
138 HRESULT i_initSetOfSupportedStandardsURI();
139
140 Utf8Str i_typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
141
142 std::set<Utf8Str> i_URIFromTypeOfVirtualDiskFormat(Utf8Str type);
143
144 HRESULT i_initApplianceIONameMap();
145
146 Utf8Str i_applianceIOName(APPLIANCEIONAME type) const;
147
148 HRESULT i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
149 /** @} */
150
151 /** @name Read stuff
152 * @{
153 */
154 void i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
155
156 HRESULT i_readFS(TaskOVF *pTask);
157 HRESULT i_readFSOVF(TaskOVF *pTask);
158 HRESULT i_readFSOVA(TaskOVF *pTask);
159 HRESULT i_readOVFFile(TaskOVF *pTask, RTVFSIOSTREAM hIosOvf, const char *pszManifestEntry);
160 HRESULT i_readManifestFile(TaskOVF *pTask, RTVFSIOSTREAM hIosMf, const char *pszSubFileNm);
161 HRESULT i_readSignatureFile(TaskOVF *pTask, RTVFSIOSTREAM hIosCert, const char *pszSubFileNm);
162 HRESULT i_readTailProcessing(TaskOVF *pTask);
163 /** @} */
164
165 /** @name Import stuff
166 * @}
167 */
168 HRESULT i_importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
169
170 HRESULT i_importFS(TaskOVF *pTask);
171 HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
172 HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
173 HRESULT i_importDoIt(TaskOVF *pTask, AutoWriteLockBase &rWriteLock, RTVFSFSSTREAM hVfsFssOva = NIL_RTVFSFSSTREAM);
174
175 HRESULT i_verifyManifestFile(ImportStack &stack);
176
177 void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
178 uint32_t ulAddressOnParent,
179 Bstr &controllerType,
180 int32_t &lControllerPort,
181 int32_t &lDevice);
182
183 void i_importOneDiskImage(const ovf::DiskImage &di,
184 Utf8Str *strTargetPath,
185 ComObjPtr<Medium> &pTargetHD,
186 ImportStack &stack);
187
188 void i_importMachineGeneric(const ovf::VirtualSystem &vsysThis,
189 ComObjPtr<VirtualSystemDescription> &vsdescThis,
190 ComPtr<IMachine> &pNewMachine,
191 ImportStack &stack);
192 void i_importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
193 ComPtr<IMachine> &pNewMachine,
194 ImportStack &stack);
195 void i_importMachines(ImportStack &stack);
196
197 HRESULT i_preCheckImageAvailability(ImportStack &stack);
198 bool i_importEnsureOvaLookAhead(ImportStack &stack);
199 RTVFSIOSTREAM i_importSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry);
200 RTVFSIOSTREAM i_importOpenSourceFile(ImportStack &stack, Utf8Str const &rstrSrcPath, const char *pszManifestEntry);
201 HRESULT i_importCreateAndWriteDestinationFile(Utf8Str const &rstrDstPath,
202 RTVFSIOSTREAM hVfsIosSrc, Utf8Str const &rstrSrcLogNm);
203
204 void i_importCopyFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
205 const char *pszManifestEntry);
206 void i_importDecompressFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
207 const char *pszManifestEntry);
208 /** @} */
209
210 /** @name Write stuff
211 * @{
212 */
213 HRESULT i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
214
215 HRESULT i_writeFS(TaskOVF *pTask);
216 HRESULT i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
217 HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
218 HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
219
220 struct XMLStack;
221
222 void i_buildXML(AutoWriteLockBase& writeLock,
223 xml::Document &doc,
224 XMLStack &stack,
225 const Utf8Str &strPath,
226 ovf::OVFVersion_T enFormat);
227 void i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
228 xml::ElementNode &elmToAddVirtualSystemsTo,
229 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
230 ComObjPtr<VirtualSystemDescription> &vsdescThis,
231 ovf::OVFVersion_T enFormat,
232 XMLStack &stack);
233 /** @} */
234
235 friend class Machine;
236};
237
238void i_parseURI(Utf8Str strUri, LocationInfo &locInfo);
239
240struct VirtualSystemDescriptionEntry
241{
242 uint32_t ulIndex; ///< zero-based index of this entry within array
243 VirtualSystemDescriptionType_T type; ///< type of this entry
244 Utf8Str strRef; ///< reference number (hard disk controllers only)
245 Utf8Str strOvf; ///< original OVF value (type-dependent)
246 Utf8Str strVBoxSuggested; ///< configuration value (type-dependent); original value suggested by interpret()
247 Utf8Str strVBoxCurrent; ///< configuration value (type-dependent); current value, either from interpret() or setFinalValue()
248 Utf8Str strExtraConfigSuggested; ///< extra configuration key=value strings (type-dependent); original value suggested by interpret()
249 Utf8Str strExtraConfigCurrent; ///< extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
250
251 uint32_t ulSizeMB; ///< hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
252 bool skipIt; ///< used during export to skip some parts if it's needed
253};
254
255class ATL_NO_VTABLE VirtualSystemDescription :
256 public VirtualSystemDescriptionWrap
257{
258 friend class Appliance;
259
260public:
261
262 DECLARE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
263
264 HRESULT FinalConstruct();
265 void FinalRelease();
266
267 HRESULT init();
268 void uninit();
269
270 /* public methods only for internal purposes */
271 void i_addEntry(VirtualSystemDescriptionType_T aType,
272 const Utf8Str &strRef,
273 const Utf8Str &aOvfValue,
274 const Utf8Str &aVBoxValue,
275 uint32_t ulSizeMB = 0,
276 const Utf8Str &strExtraConfig = "");
277
278 std::list<VirtualSystemDescriptionEntry*> i_findByType(VirtualSystemDescriptionType_T aType);
279 const VirtualSystemDescriptionEntry* i_findControllerFromID(uint32_t id);
280
281 void i_importVBoxMachineXML(const xml::ElementNode &elmMachine);
282 const settings::MachineConfigFile* i_getMachineConfig() const;
283
284 /* private instance data */
285private:
286
287 // wrapped IVirtualSystemDescription properties
288 HRESULT getCount(ULONG *aCount);
289
290 // wrapped IVirtualSystemDescription methods
291 HRESULT getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
292 std::vector<com::Utf8Str> &aRefs,
293 std::vector<com::Utf8Str> &aOVFValues,
294 std::vector<com::Utf8Str> &aVBoxValues,
295 std::vector<com::Utf8Str> &aExtraConfigValues);
296 HRESULT getDescriptionByType(VirtualSystemDescriptionType_T aType,
297 std::vector<VirtualSystemDescriptionType_T> &aTypes,
298 std::vector<com::Utf8Str> &aRefs,
299 std::vector<com::Utf8Str> &aOVFValues,
300 std::vector<com::Utf8Str> &aVBoxValues,
301 std::vector<com::Utf8Str> &aExtraConfigValues);
302 HRESULT getValuesByType(VirtualSystemDescriptionType_T aType,
303 VirtualSystemDescriptionValueType_T aWhich,
304 std::vector<com::Utf8Str> &aValues);
305 HRESULT setFinalValues(const std::vector<BOOL> &aEnabled,
306 const std::vector<com::Utf8Str> &aVBoxValues,
307 const std::vector<com::Utf8Str> &aExtraConfigValues);
308 HRESULT addDescription(VirtualSystemDescriptionType_T aType,
309 const com::Utf8Str &aVBoxValue,
310 const com::Utf8Str &aExtraConfigValue);
311 void i_removeByType(VirtualSystemDescriptionType_T aType);
312
313 struct Data;
314 Data *m;
315
316 friend class Machine;
317};
318
319#endif // !____H_APPLIANCEIMPL
320/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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