VirtualBox

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

Last change on this file since 67231 was 67208, checked in by vboxsync, 8 years ago

Main,VBoxManage: More OPC hacking. Seems to be working now.

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