VirtualBox

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

Last change on this file since 78223 was 76562, checked in by vboxsync, 6 years ago

Main: Use MAIN_INCLUDED_ and MAIN_INCLUDED_SRC_ as header guard prefixes with scm.

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