VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/ApplianceImpl.cpp@ 84031

Last change on this file since 84031 was 84031, checked in by vboxsync, 5 years ago

bugre:9699. Added the function getManifest() into the IAppliance interface. Saving manifest name and manifest data in the string form after reading an appliance.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 64.8 KB
Line 
1/* $Id: ApplianceImpl.cpp 84031 2020-04-28 09:55:27Z vboxsync $ */
2/** @file
3 * IAppliance and IVirtualSystem COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2008-2020 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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_MAIN_APPLIANCE
23#include <iprt/path.h>
24#include <iprt/cpp/path.h>
25#include <iprt/cpp/utils.h>
26#include <VBox/com/array.h>
27#include <map>
28
29#include "ApplianceImpl.h"
30#include "VFSExplorerImpl.h"
31#include "VirtualBoxImpl.h"
32#include "GuestOSTypeImpl.h"
33#include "Global.h"
34#include "ProgressImpl.h"
35#include "MachineImpl.h"
36#include "SystemPropertiesImpl.h"
37#include "AutoCaller.h"
38#include "LoggingNew.h"
39#include "CertificateImpl.h"
40
41#include "ApplianceImplPrivate.h"
42
43using namespace std;
44
45
46/*********************************************************************************************************************************
47* Global Variables *
48*********************************************************************************************************************************/
49static const char * const g_pszISOURI = "http://www.ecma-international.org/publications/standards/Ecma-119.htm";
50static const char * const g_pszVMDKStreamURI = "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized";
51static const char * const g_pszVMDKSparseURI = "http://www.vmware.com/specifications/vmdk.html#sparse";
52static const char * const g_pszVMDKCompressedURI = "http://www.vmware.com/specifications/vmdk.html#compressed";
53static const char * const g_pszVMDKCompressedURI2 = "http://www.vmware.com/interfaces/specifications/vmdk.html#compressed";
54static const char * const g_pszrVHDURI = "http://go.microsoft.com/fwlink/?LinkId=137171";
55static char g_szIsoBackend[128];
56static char g_szVmdkBackend[128];
57static char g_szVhdBackend[128];
58/** Set after the g_szXxxxBackend variables has been initialized. */
59static bool volatile g_fInitializedBackendNames = false;
60
61static struct
62{
63 const char *pszUri, *pszBackend;
64} const g_aUriToBackend[] =
65{
66 { g_pszISOURI, g_szIsoBackend },
67 { g_pszVMDKStreamURI, g_szVmdkBackend },
68 { g_pszVMDKSparseURI, g_szVmdkBackend },
69 { g_pszVMDKCompressedURI, g_szVmdkBackend },
70 { g_pszVMDKCompressedURI2, g_szVmdkBackend },
71 { g_pszrVHDURI, g_szVhdBackend },
72};
73
74static std::map<Utf8Str, Utf8Str> supportedStandardsURI;
75
76static struct
77{
78 ovf::CIMOSType_T cim;
79 VBOXOSTYPE osType;
80} const g_aOsTypes[] =
81{
82 { ovf::CIMOSType_CIMOS_Unknown, VBOXOSTYPE_Unknown },
83 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2 },
84 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp3 },
85 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp4 },
86 { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp45 },
87 { ovf::CIMOSType_CIMOS_MSDOS, VBOXOSTYPE_DOS },
88 { ovf::CIMOSType_CIMOS_WIN3x, VBOXOSTYPE_Win31 },
89 { ovf::CIMOSType_CIMOS_WIN95, VBOXOSTYPE_Win95 },
90 { ovf::CIMOSType_CIMOS_WIN98, VBOXOSTYPE_Win98 },
91 { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT },
92 { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT4 },
93 { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT3x },
94 { ovf::CIMOSType_CIMOS_NetWare, VBOXOSTYPE_Netware },
95 { ovf::CIMOSType_CIMOS_NovellOES, VBOXOSTYPE_Netware },
96 { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_Solaris },
97 { ovf::CIMOSType_CIMOS_SunOS, VBOXOSTYPE_Solaris },
98 { ovf::CIMOSType_CIMOS_FreeBSD, VBOXOSTYPE_FreeBSD },
99 { ovf::CIMOSType_CIMOS_NetBSD, VBOXOSTYPE_NetBSD },
100 { ovf::CIMOSType_CIMOS_QNX, VBOXOSTYPE_QNX },
101 { ovf::CIMOSType_CIMOS_Windows2000, VBOXOSTYPE_Win2k },
102 { ovf::CIMOSType_CIMOS_WindowsMe, VBOXOSTYPE_WinMe },
103 { ovf::CIMOSType_CIMOS_OpenBSD, VBOXOSTYPE_OpenBSD },
104 { ovf::CIMOSType_CIMOS_WindowsXP, VBOXOSTYPE_WinXP },
105 { ovf::CIMOSType_CIMOS_WindowsXPEmbedded, VBOXOSTYPE_WinXP },
106 { ovf::CIMOSType_CIMOS_WindowsEmbeddedforPointofService, VBOXOSTYPE_WinXP },
107 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2003, VBOXOSTYPE_Win2k3 },
108 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2003_64, VBOXOSTYPE_Win2k3_x64 },
109 { ovf::CIMOSType_CIMOS_WindowsXP_64, VBOXOSTYPE_WinXP_x64 },
110 { ovf::CIMOSType_CIMOS_WindowsVista, VBOXOSTYPE_WinVista },
111 { ovf::CIMOSType_CIMOS_WindowsVista_64, VBOXOSTYPE_WinVista_x64 },
112 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008, VBOXOSTYPE_Win2k8 },
113 { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008_64, VBOXOSTYPE_Win2k8_x64 },
114 { ovf::CIMOSType_CIMOS_FreeBSD_64, VBOXOSTYPE_FreeBSD_x64 },
115 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS },
116 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS_x64 }, // there is no CIM 64-bit type for this
117 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106 },
118 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106_x64 },
119 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS107_x64 },
120 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS108_x64 },
121 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS109_x64 },
122 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1010_x64 },
123 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1011_x64 },
124 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1012_x64 },
125 { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1013_x64 },
126
127 // Linuxes
128 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat },
129 { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat_x64 },
130 { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_Solaris_x64 },
131 { ovf::CIMOSType_CIMOS_SUSE, VBOXOSTYPE_OpenSUSE },
132 { ovf::CIMOSType_CIMOS_SLES, VBOXOSTYPE_OpenSUSE },
133 { ovf::CIMOSType_CIMOS_NovellLinuxDesktop, VBOXOSTYPE_OpenSUSE },
134 { ovf::CIMOSType_CIMOS_SUSE_64, VBOXOSTYPE_OpenSUSE_x64 },
135 { ovf::CIMOSType_CIMOS_SLES_64, VBOXOSTYPE_OpenSUSE_x64 },
136 { ovf::CIMOSType_CIMOS_LINUX, VBOXOSTYPE_Linux },
137 { ovf::CIMOSType_CIMOS_LINUX, VBOXOSTYPE_Linux22 },
138 { ovf::CIMOSType_CIMOS_SunJavaDesktopSystem, VBOXOSTYPE_Linux },
139 { ovf::CIMOSType_CIMOS_TurboLinux, VBOXOSTYPE_Turbolinux },
140 { ovf::CIMOSType_CIMOS_TurboLinux_64, VBOXOSTYPE_Turbolinux_x64 },
141 { ovf::CIMOSType_CIMOS_Mandriva, VBOXOSTYPE_Mandriva },
142 { ovf::CIMOSType_CIMOS_Mandriva_64, VBOXOSTYPE_Mandriva_x64 },
143 { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu },
144 { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu_x64 },
145 { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian },
146 { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian_x64 },
147 { ovf::CIMOSType_CIMOS_Linux_2_4_x, VBOXOSTYPE_Linux24 },
148 { ovf::CIMOSType_CIMOS_Linux_2_4_x_64, VBOXOSTYPE_Linux24_x64 },
149 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Linux26 },
150 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Linux26_x64 },
151 { ovf::CIMOSType_CIMOS_Linux_64, VBOXOSTYPE_Linux26_x64 },
152
153 // types that we have support for but CIM doesn't
154 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_ArchLinux },
155 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_ArchLinux_x64 },
156 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_FedoraCore },
157 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_FedoraCore_x64 },
158 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Gentoo },
159 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Gentoo_x64 },
160 { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Xandros },
161 { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Xandros_x64 },
162 { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_OpenSolaris },
163 { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_OpenSolaris_x64 },
164
165 // types added with CIM 2.25.0 follow:
166 { ovf::CIMOSType_CIMOS_WindowsServer2008R2, VBOXOSTYPE_Win2k8 }, // duplicate, see above
167// { ovf::CIMOSType_CIMOS_VMwareESXi = 104, // we can't run ESX in a VM
168 { ovf::CIMOSType_CIMOS_Windows7, VBOXOSTYPE_Win7 },
169 { ovf::CIMOSType_CIMOS_Windows7, VBOXOSTYPE_Win7_x64 }, // there is no
170 // CIM 64-bit type for this
171 { ovf::CIMOSType_CIMOS_CentOS, VBOXOSTYPE_RedHat },
172 { ovf::CIMOSType_CIMOS_CentOS_64, VBOXOSTYPE_RedHat_x64 },
173 { ovf::CIMOSType_CIMOS_OracleLinux, VBOXOSTYPE_Oracle },
174 { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle_x64 },
175 { ovf::CIMOSType_CIMOS_eComStation, VBOXOSTYPE_ECS },
176
177 { ovf::CIMOSType_CIMOS_WindowsServer2011, VBOXOSTYPE_Win2k8_x64 }, // no 1:1 match on the VBox side
178 { ovf::CIMOSType_CIMOS_WindowsServer2012, VBOXOSTYPE_Win2k12_x64 },
179 { ovf::CIMOSType_CIMOS_Windows8, VBOXOSTYPE_Win8 },
180 { ovf::CIMOSType_CIMOS_Windows8_64, VBOXOSTYPE_Win8_x64 },
181 { ovf::CIMOSType_CIMOS_WindowsServer2012R2, VBOXOSTYPE_Win2k12_x64 },
182 { ovf::CIMOSType_CIMOS_Windows8_1, VBOXOSTYPE_Win81 },
183 { ovf::CIMOSType_CIMOS_Windows8_1_64, VBOXOSTYPE_Win81_x64 },
184 { ovf::CIMOSType_CIMOS_WindowsServer2016, VBOXOSTYPE_Win2k16_x64 },
185 { ovf::CIMOSType_CIMOS_Windows10, VBOXOSTYPE_Win10 },
186 { ovf::CIMOSType_CIMOS_Windows10_64, VBOXOSTYPE_Win10_x64 },
187 { ovf::CIMOSType_CIMOS_Windows10_64, VBOXOSTYPE_Win10_x64 },
188 { ovf::CIMOSType_CIMOS_WindowsServer2016, VBOXOSTYPE_Win2k19_x64 }, // no CIM type for this yet
189
190 // there are no CIM types for these, so these turn to "other" on export:
191 // VBOXOSTYPE_OpenBSD
192 // VBOXOSTYPE_OpenBSD_x64
193 // VBOXOSTYPE_NetBSD
194 // VBOXOSTYPE_NetBSD_x64
195
196};
197
198/* Pattern structure for matching the OS type description field */
199struct osTypePattern
200{
201 const char *pcszPattern;
202 VBOXOSTYPE osType;
203};
204
205/* These are the 32-Bit ones. They are sorted by priority. */
206static const osTypePattern g_aOsTypesPattern[] =
207{
208 {"Windows NT", VBOXOSTYPE_WinNT4},
209 {"Windows XP", VBOXOSTYPE_WinXP},
210 {"Windows 2000", VBOXOSTYPE_Win2k},
211 {"Windows 2003", VBOXOSTYPE_Win2k3},
212 {"Windows Vista", VBOXOSTYPE_WinVista},
213 {"Windows 2008", VBOXOSTYPE_Win2k8},
214 {"Windows 7", VBOXOSTYPE_Win7},
215 {"Windows 8.1", VBOXOSTYPE_Win81},
216 {"Windows 8", VBOXOSTYPE_Win8},
217 {"Windows 10", VBOXOSTYPE_Win10},
218 {"SUSE", VBOXOSTYPE_OpenSUSE},
219 {"Novell", VBOXOSTYPE_OpenSUSE},
220 {"Red Hat", VBOXOSTYPE_RedHat},
221 {"Mandriva", VBOXOSTYPE_Mandriva},
222 {"Ubuntu", VBOXOSTYPE_Ubuntu},
223 {"Debian", VBOXOSTYPE_Debian},
224 {"QNX", VBOXOSTYPE_QNX},
225 {"Linux 2.4", VBOXOSTYPE_Linux24},
226 {"Linux 2.6", VBOXOSTYPE_Linux26},
227 {"Linux", VBOXOSTYPE_Linux},
228 {"OpenSolaris", VBOXOSTYPE_OpenSolaris},
229 {"Solaris", VBOXOSTYPE_OpenSolaris},
230 {"FreeBSD", VBOXOSTYPE_FreeBSD},
231 {"NetBSD", VBOXOSTYPE_NetBSD},
232 {"Windows 95", VBOXOSTYPE_Win95},
233 {"Windows 98", VBOXOSTYPE_Win98},
234 {"Windows Me", VBOXOSTYPE_WinMe},
235 {"Windows 3.", VBOXOSTYPE_Win31},
236 {"DOS", VBOXOSTYPE_DOS},
237 {"OS2", VBOXOSTYPE_OS2}
238};
239
240/* These are the 64-Bit ones. They are sorted by priority. */
241static const osTypePattern g_aOsTypesPattern64[] =
242{
243 {"Windows XP", VBOXOSTYPE_WinXP_x64},
244 {"Windows 2003", VBOXOSTYPE_Win2k3_x64},
245 {"Windows Vista", VBOXOSTYPE_WinVista_x64},
246 {"Windows 2008", VBOXOSTYPE_Win2k8_x64},
247 {"Windows 7", VBOXOSTYPE_Win7_x64},
248 {"Windows 8.1", VBOXOSTYPE_Win81_x64},
249 {"Windows 8", VBOXOSTYPE_Win8_x64},
250 {"Windows 2012", VBOXOSTYPE_Win2k12_x64},
251 {"Windows 10", VBOXOSTYPE_Win10_x64},
252 {"Windows 2016", VBOXOSTYPE_Win2k16_x64},
253 {"Windows 2019", VBOXOSTYPE_Win2k19_x64},
254 {"SUSE", VBOXOSTYPE_OpenSUSE_x64},
255 {"Novell", VBOXOSTYPE_OpenSUSE_x64},
256 {"Red Hat", VBOXOSTYPE_RedHat_x64},
257 {"Mandriva", VBOXOSTYPE_Mandriva_x64},
258 {"Ubuntu", VBOXOSTYPE_Ubuntu_x64},
259 {"Debian", VBOXOSTYPE_Debian_x64},
260 {"Linux 2.4", VBOXOSTYPE_Linux24_x64},
261 {"Linux 2.6", VBOXOSTYPE_Linux26_x64},
262 {"Linux", VBOXOSTYPE_Linux26_x64},
263 {"OpenSolaris", VBOXOSTYPE_OpenSolaris_x64},
264 {"Solaris", VBOXOSTYPE_OpenSolaris_x64},
265 {"FreeBSD", VBOXOSTYPE_FreeBSD_x64},
266};
267
268/**
269 * Private helper func that suggests a VirtualBox guest OS type
270 * for the given OVF operating system type.
271 */
272void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr)
273{
274 /* First check if the type is other/other_64 */
275 if (c == ovf::CIMOSType_CIMOS_Other)
276 {
277 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypesPattern); ++i)
278 if (cStr.contains(g_aOsTypesPattern[i].pcszPattern, Utf8Str::CaseInsensitive))
279 {
280 strType = Global::OSTypeId(g_aOsTypesPattern[i].osType);
281 return;
282 }
283 }
284 else if (c == ovf::CIMOSType_CIMOS_Other_64)
285 {
286 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypesPattern64); ++i)
287 if (cStr.contains(g_aOsTypesPattern64[i].pcszPattern, Utf8Str::CaseInsensitive))
288 {
289 strType = Global::OSTypeId(g_aOsTypesPattern64[i].osType);
290 return;
291 }
292 }
293
294 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypes); ++i)
295 {
296 if (c == g_aOsTypes[i].cim)
297 {
298 strType = Global::OSTypeId(g_aOsTypes[i].osType);
299 return;
300 }
301 }
302
303 if (c == ovf::CIMOSType_CIMOS_Other_64)
304 strType = Global::OSTypeId(VBOXOSTYPE_Unknown_x64);
305 else
306 strType = Global::OSTypeId(VBOXOSTYPE_Unknown);
307}
308
309/**
310 * Private helper func that suggests a VirtualBox guest OS type
311 * for the given OVF operating system type.
312 * @returns CIM OS type.
313 * @param pcszVBox Our guest OS type identifier string.
314 * @param fLongMode Whether long mode is enabled and a 64-bit CIM type is
315 * preferred even if the VBox guest type isn't 64-bit.
316 */
317ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode)
318{
319 for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypes); ++i)
320 {
321 if (!RTStrICmp(pcszVBox, Global::OSTypeId(g_aOsTypes[i].osType)))
322 {
323 if (fLongMode && !(g_aOsTypes[i].osType & VBOXOSTYPE_x64))
324 {
325 VBOXOSTYPE enmDesiredOsType = (VBOXOSTYPE)((int)g_aOsTypes[i].osType | (int)VBOXOSTYPE_x64);
326 size_t j = i;
327 while (++j < RT_ELEMENTS(g_aOsTypes))
328 if (g_aOsTypes[j].osType == enmDesiredOsType)
329 return g_aOsTypes[j].cim;
330 j = i;
331 while (--j > 0)
332 if (g_aOsTypes[j].osType == enmDesiredOsType)
333 return g_aOsTypes[j].cim;
334 /* Not all OSes have 64-bit versions, so just return the 32-bit variant. */
335 }
336 return g_aOsTypes[i].cim;
337 }
338 }
339
340 return fLongMode ? ovf::CIMOSType_CIMOS_Other_64 : ovf::CIMOSType_CIMOS_Other;
341}
342
343Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type)
344{
345 Utf8Str strType;
346 switch (type)
347 {
348 case NetworkAttachmentType_NAT: strType = "NAT"; break;
349 case NetworkAttachmentType_Bridged: strType = "Bridged"; break;
350 case NetworkAttachmentType_Internal: strType = "Internal"; break;
351 case NetworkAttachmentType_HostOnly: strType = "HostOnly"; break;
352 case NetworkAttachmentType_Generic: strType = "Generic"; break;
353 case NetworkAttachmentType_NATNetwork: strType = "NATNetwork"; break;
354 case NetworkAttachmentType_Null: strType = "Null"; break;
355 case NetworkAttachmentType_Cloud: strType = "Cloud"; break;
356#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
357 case NetworkAttachmentType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
358#endif
359 }
360 return strType;
361}
362
363
364////////////////////////////////////////////////////////////////////////////////
365//
366// Appliance constructor / destructor
367//
368// ////////////////////////////////////////////////////////////////////////////////
369
370DEFINE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
371
372HRESULT VirtualSystemDescription::FinalConstruct()
373{
374 return BaseFinalConstruct();
375}
376
377void VirtualSystemDescription::FinalRelease()
378{
379 uninit();
380
381 BaseFinalRelease();
382}
383
384Appliance::Appliance()
385 : mVirtualBox(NULL)
386{
387}
388
389Appliance::~Appliance()
390{
391}
392
393
394HRESULT Appliance::FinalConstruct()
395{
396 return BaseFinalConstruct();
397}
398
399void Appliance::FinalRelease()
400{
401 uninit();
402
403 BaseFinalRelease();
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408//
409// Internal helpers
410//
411////////////////////////////////////////////////////////////////////////////////
412
413
414////////////////////////////////////////////////////////////////////////////////
415//
416// IVirtualBox public methods
417//
418////////////////////////////////////////////////////////////////////////////////
419
420// This code is here so we won't have to include the appliance headers in the
421// IVirtualBox implementation.
422
423/**
424 * Implementation for IVirtualBox::createAppliance.
425 *
426 * @param aAppliance IAppliance object created if S_OK is returned.
427 * @return S_OK or error.
428 */
429HRESULT VirtualBox::createAppliance(ComPtr<IAppliance> &aAppliance)
430{
431 ComObjPtr<Appliance> appliance;
432 HRESULT hrc = appliance.createObject();
433 if (SUCCEEDED(hrc))
434 {
435 hrc = appliance->init(this);
436 if (SUCCEEDED(hrc))
437 hrc = appliance.queryInterfaceTo(aAppliance.asOutParam());
438 }
439 return hrc;
440}
441
442/**
443 * Appliance COM initializer.
444 * @param aVirtualBox The VirtualBox object.
445 */
446HRESULT Appliance::init(VirtualBox *aVirtualBox)
447{
448 HRESULT rc = S_OK;
449 /* Enclose the state transition NotReady->InInit->Ready */
450 AutoInitSpan autoInitSpan(this);
451 AssertReturn(autoInitSpan.isOk(), E_FAIL);
452
453 /* Weak reference to a VirtualBox object */
454 unconst(mVirtualBox) = aVirtualBox;
455
456 // initialize data
457 m = new Data;
458 m->m_pSecretKeyStore = new SecretKeyStore(false /* fRequireNonPageable*/);
459 AssertReturn(m->m_pSecretKeyStore, E_FAIL);
460
461 rc = i_initBackendNames();
462
463 /* Confirm a successful initialization */
464 autoInitSpan.setSucceeded();
465
466 return rc;
467}
468
469/**
470 * Appliance COM uninitializer.
471 */
472void Appliance::uninit()
473{
474 /* Enclose the state transition Ready->InUninit->NotReady */
475 AutoUninitSpan autoUninitSpan(this);
476 if (autoUninitSpan.uninitDone())
477 return;
478
479 if (m->m_pSecretKeyStore)
480 delete m->m_pSecretKeyStore;
481
482 delete m;
483 m = NULL;
484}
485
486////////////////////////////////////////////////////////////////////////////////
487//
488// IAppliance public methods
489//
490////////////////////////////////////////////////////////////////////////////////
491
492/**
493 * Public method implementation.
494 */
495HRESULT Appliance::getPath(com::Utf8Str &aPath)
496{
497 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
498
499 aPath = m->locInfo.strPath;
500
501 return S_OK;
502}
503
504/**
505 * Public method implementation.
506 */
507HRESULT Appliance::getManifest(com::Utf8Str &aManifest, com::Utf8Str &aManifestName)
508{
509 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
510
511 aManifest = m->strManifest;
512 aManifestName = m->strManifestName;
513 return S_OK;
514}
515
516/**
517 * Public method implementation.
518 */
519HRESULT Appliance::getDisks(std::vector<com::Utf8Str> &aDisks)
520{
521 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
522
523 aDisks.resize(0);
524
525 if (m->pReader) // OVFReader instantiated?
526 {
527 aDisks.resize(m->pReader->m_mapDisks.size());
528
529 ovf::DiskImagesMap::const_iterator it;
530 size_t i = 0;
531 for (it = m->pReader->m_mapDisks.begin();
532 it != m->pReader->m_mapDisks.end();
533 ++it, ++i)
534 {
535 // create a string representing this disk
536 const ovf::DiskImage &d = it->second;
537 char *psz = NULL;
538 RTStrAPrintf(&psz,
539 "%s\t"
540 "%RI64\t"
541 "%RI64\t"
542 "%s\t"
543 "%s\t"
544 "%RI64\t"
545 "%RI64\t"
546 "%s",
547 d.strDiskId.c_str(),
548 d.iCapacity,
549 d.iPopulatedSize,
550 d.strFormat.c_str(),
551 d.strHref.c_str(),
552 d.iSize,
553 d.iChunkSize,
554 d.strCompression.c_str());
555 Utf8Str utf(psz);
556 aDisks[i] = utf;
557 RTStrFree(psz);
558 }
559 }
560
561 return S_OK;
562}
563
564/**
565 * Public method implementation.
566 */
567HRESULT Appliance::getCertificate(ComPtr<ICertificate> &aCertificateInfo)
568{
569 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
570
571 /* Can be NULL at this point, queryInterfaceto handles that. */
572 m->ptrCertificateInfo.queryInterfaceTo(aCertificateInfo.asOutParam());
573 return S_OK;
574}
575
576/**
577 * Public method implementation.
578 */
579HRESULT Appliance::getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions)
580{
581 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
582
583 aVirtualSystemDescriptions.resize(m->virtualSystemDescriptions.size());
584 std::list< ComObjPtr<VirtualSystemDescription> > vsds(m->virtualSystemDescriptions);
585 size_t i = 0;
586 for (std::list< ComObjPtr<VirtualSystemDescription> >::iterator it = vsds.begin(); it != vsds.end(); ++it, ++i)
587 {
588 (*it).queryInterfaceTo(aVirtualSystemDescriptions[i].asOutParam());
589 }
590 return S_OK;
591}
592
593/**
594 * Public method implementation.
595 */
596HRESULT Appliance::getMachines(std::vector<com::Utf8Str> &aMachines)
597{
598 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
599
600 aMachines.resize(m->llGuidsMachinesCreated.size());
601 size_t i = 0;
602 for (std::list<Guid>::const_iterator it = m->llGuidsMachinesCreated.begin();
603 it != m->llGuidsMachinesCreated.end();
604 ++it, ++i)
605 {
606 const Guid &uuid = *it;
607 aMachines[i] = uuid.toUtf16();
608 }
609 return S_OK;
610}
611
612HRESULT Appliance::createVFSExplorer(const com::Utf8Str &aURI, ComPtr<IVFSExplorer> &aExplorer)
613{
614 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
615
616 ComObjPtr<VFSExplorer> explorer;
617 HRESULT rc = S_OK;
618 try
619 {
620 Utf8Str uri(aURI);
621 /* Check which kind of export the user has requested */
622 LocationInfo li;
623 i_parseURI(aURI, li);
624 /* Create the explorer object */
625 explorer.createObject();
626 rc = explorer->init(li.storageType, li.strPath, li.strHostname, li.strUsername, li.strPassword, mVirtualBox);
627 }
628 catch (HRESULT aRC)
629 {
630 rc = aRC;
631 }
632
633 if (SUCCEEDED(rc))
634 /* Return explorer to the caller */
635 explorer.queryInterfaceTo(aExplorer.asOutParam());
636
637 return rc;
638}
639
640
641/**
642 * Public method implementation.
643 * Add the "aRequested" numbers of new empty objects of VSD into the list
644 * "virtualSystemDescriptions".
645 * The parameter "aCreated" keeps the actual number of the added objects.
646 * In case of exception all added objects are removed from the list.
647 */
648HRESULT Appliance::createVirtualSystemDescriptions(ULONG aRequested, ULONG *aCreated)
649{
650 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
651
652 HRESULT rc = S_OK;
653 uint32_t lQuantity = aRequested;
654 uint32_t i=0;
655
656 if (lQuantity < 1)
657 return setError(E_FAIL, tr("The number of VirtualSystemDescription objects must be at least 1 or more."));
658 try
659 {
660 for (; i<lQuantity; ++i)
661 {
662 ComObjPtr<VirtualSystemDescription> opVSD;
663 rc = opVSD.createObject();
664 if (SUCCEEDED(rc))
665 {
666 rc = opVSD->init();
667 if (SUCCEEDED(rc))
668 m->virtualSystemDescriptions.push_back(opVSD);
669 else
670 break;
671 }
672 else
673 break;
674 }
675
676 if (i<lQuantity)
677 LogRel(("Number of created VirtualSystemDescription objects is less than requested"
678 "(Requested %d, Created %d)",lQuantity, i));
679
680 *aCreated = i;
681 }
682 catch (HRESULT aRC)
683 {
684 for (; i>0; --i)
685 {
686 if (!m->virtualSystemDescriptions.empty())
687 m->virtualSystemDescriptions.pop_back();
688 else
689 break;
690 }
691 rc = aRC;
692 }
693
694 return rc;
695}
696
697/**
698 * Public method implementation.
699 */
700HRESULT Appliance::getWarnings(std::vector<com::Utf8Str> &aWarnings)
701{
702 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
703
704 aWarnings.resize(m->llWarnings.size());
705
706 list<Utf8Str>::const_iterator it;
707 size_t i = 0;
708 for (it = m->llWarnings.begin();
709 it != m->llWarnings.end();
710 ++it, ++i)
711 {
712 aWarnings[i] = *it;
713 }
714
715 return S_OK;
716}
717
718HRESULT Appliance::getPasswordIds(std::vector<com::Utf8Str> &aIdentifiers)
719{
720 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
721
722 aIdentifiers = m->m_vecPasswordIdentifiers;
723 return S_OK;
724}
725
726HRESULT Appliance::getMediumIdsForPasswordId(const com::Utf8Str &aPasswordId, std::vector<com::Guid> &aIdentifiers)
727{
728 HRESULT hrc = S_OK;
729 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
730
731 std::map<com::Utf8Str, GUIDVEC>::const_iterator it = m->m_mapPwIdToMediumIds.find(aPasswordId);
732 if (it != m->m_mapPwIdToMediumIds.end())
733 aIdentifiers = it->second;
734 else
735 hrc = setError(E_FAIL, tr("The given password identifier is not associated with any medium"));
736
737 return hrc;
738}
739
740HRESULT Appliance::addPasswords(const std::vector<com::Utf8Str> &aIdentifiers,
741 const std::vector<com::Utf8Str> &aPasswords)
742{
743 HRESULT hrc = S_OK;
744
745 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
746
747 /* Check that the IDs do not exist already before changing anything. */
748 for (unsigned i = 0; i < aIdentifiers.size(); i++)
749 {
750 SecretKey *pKey = NULL;
751 int rc = m->m_pSecretKeyStore->retainSecretKey(aIdentifiers[i], &pKey);
752 if (rc != VERR_NOT_FOUND)
753 {
754 AssertPtr(pKey);
755 if (pKey)
756 pKey->release();
757 return setError(VBOX_E_OBJECT_IN_USE, tr("A password with the given ID already exists"));
758 }
759 }
760
761 for (unsigned i = 0; i < aIdentifiers.size() && SUCCEEDED(hrc); i++)
762 {
763 size_t cbKey = aPasswords[i].length() + 1; /* Include terminator */
764 const uint8_t *pbKey = (const uint8_t *)aPasswords[i].c_str();
765
766 int rc = m->m_pSecretKeyStore->addSecretKey(aIdentifiers[i], pbKey, cbKey);
767 if (RT_SUCCESS(rc))
768 m->m_cPwProvided++;
769 else if (rc == VERR_NO_MEMORY)
770 hrc = setError(E_OUTOFMEMORY, tr("Failed to allocate enough secure memory for the key"));
771 else
772 hrc = setError(E_FAIL, tr("Unknown error happened while adding a password (%Rrc)"), rc);
773 }
774
775 return hrc;
776}
777
778////////////////////////////////////////////////////////////////////////////////
779//
780// Appliance private methods
781//
782////////////////////////////////////////////////////////////////////////////////
783
784HRESULT Appliance::i_initBackendNames()
785{
786 HRESULT hrc = S_OK;
787 if (!g_fInitializedBackendNames)
788 {
789 /*
790 * Use the system properties to translate file extensions into
791 * storage backend names.
792 */
793 static struct
794 {
795 const char *pszExt; /**< extension */
796 char *pszBackendName;
797 size_t cbBackendName;
798 } const s_aFormats[] =
799 {
800 { "iso", g_szIsoBackend, sizeof(g_szIsoBackend) },
801 { "vmdk", g_szVmdkBackend, sizeof(g_szVmdkBackend) },
802 { "vhd", g_szVhdBackend, sizeof(g_szVhdBackend) },
803 };
804 SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
805 for (unsigned i = 0; i < RT_ELEMENTS(s_aFormats); i++)
806 {
807 ComObjPtr<MediumFormat> trgFormat = pSysProps->i_mediumFormatFromExtension(s_aFormats[i].pszExt);
808 if (trgFormat.isNotNull())
809 {
810 const char *pszName = trgFormat->i_getName().c_str();
811 int vrc = RTStrCopy(s_aFormats[i].pszBackendName, s_aFormats[i].cbBackendName, pszName);
812 AssertRCStmt(vrc, hrc = setError(E_FAIL, "Unexpected storage backend name copy error %Rrc for %s.", vrc, pszName));
813 }
814 else
815 hrc = setError(E_FAIL, tr("Can't find appropriate medium format for ISO type of a virtual disk."));
816 }
817
818 if (SUCCEEDED(hrc))
819 g_fInitializedBackendNames = true;
820 }
821
822 return hrc;
823}
824
825Utf8Str Appliance::i_typeOfVirtualDiskFormatFromURI(Utf8Str uri) const
826{
827 Assert(g_fInitializedBackendNames);
828
829 unsigned i = RT_ELEMENTS(g_aUriToBackend);
830 while (i-- > 0)
831 if (RTStrICmp(g_aUriToBackend[i].pszUri, uri.c_str()) == 0)
832 return Utf8Str(g_aUriToBackend[i].pszBackend);
833 return Utf8Str();
834}
835
836#if 0 /* unused */
837std::set<Utf8Str> Appliance::i_URIFromTypeOfVirtualDiskFormat(Utf8Str type)
838{
839 Assert(g_fInitializedBackendNames);
840
841 std::set<Utf8Str> UriSet;
842 unsigned i = RT_ELEMENTS(g_aUriToBackend);
843 while (i-- > 0)
844 if (RTStrICmp(g_aUriToBackend[i].pszBackend, type.c_str()) == 0)
845 UriSet.insert(g_aUriToBackend[i].pszUri);
846 return UriSet;
847}
848#endif
849
850/**
851 * Returns a medium format object corresponding to the given
852 * disk image or null if no such format.
853 *
854 * @param di Disk Image
855 * @param mf Medium Format
856 *
857 * @return ComObjPtr<MediumFormat>
858 */
859HRESULT Appliance::i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf)
860{
861 HRESULT rc = S_OK;
862
863 /* Get the system properties. */
864 SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
865
866 /* We need a proper source format description */
867 /* Which format to use? */
868 Utf8Str strSrcFormat = i_typeOfVirtualDiskFormatFromURI(di.strFormat);
869
870 /*
871 * fallback, if we can't determine virtual disk format using URI from the attribute ovf:format
872 * in the corresponding section <Disk> in the OVF file.
873 */
874 if (strSrcFormat.isEmpty())
875 {
876 strSrcFormat = di.strHref;
877
878 /* check either file gzipped or not
879 * if "yes" then remove last extension,
880 * i.e. "image.vmdk.gz"->"image.vmdk"
881 */
882 if (di.strCompression == "gzip")
883 {
884 if (RTPathHasSuffix(strSrcFormat.c_str()))
885 {
886 strSrcFormat.stripSuffix();
887 }
888 else
889 {
890 mf.setNull();
891 rc = setError(E_FAIL,
892 tr("Internal inconsistency looking up medium format for the disk image '%s'"),
893 di.strHref.c_str());
894 return rc;
895 }
896 }
897 /* Figure out from extension which format the image of disk has. */
898 if (RTPathHasSuffix(strSrcFormat.c_str()))
899 {
900 const char *pszExt = RTPathSuffix(strSrcFormat.c_str());
901 if (pszExt)
902 pszExt++;
903 mf = pSysProps->i_mediumFormatFromExtension(pszExt);
904 }
905 else
906 mf.setNull();
907 }
908 else
909 mf = pSysProps->i_mediumFormat(strSrcFormat);
910
911 if (mf.isNull())
912 rc = setError(E_FAIL, tr("Internal inconsistency looking up medium format for the disk image '%s'"),
913 di.strHref.c_str());
914
915 return rc;
916}
917
918/**
919 * Setup automatic I/O stream digest calculation, adding it to hOurManifest.
920 *
921 * @returns Passthru I/O stream, of @a hVfsIos if no digest calc needed.
922 * @param hVfsIos The stream to wrap. Always consumed.
923 * @param pszManifestEntry The manifest entry.
924 * @param fRead Set if read stream, clear if write.
925 * @throws Nothing.
926 */
927RTVFSIOSTREAM Appliance::i_manifestSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry,
928 bool fRead /*= true */)
929{
930 int vrc;
931 Assert(!RTManifestPtIosIsInstanceOf(hVfsIos));
932
933 if (m->fDigestTypes == 0)
934 return hVfsIos;
935
936 /* Create the manifest if necessary. */
937 if (m->hOurManifest == NIL_RTMANIFEST)
938 {
939 vrc = RTManifestCreate(0 /*fFlags*/, &m->hOurManifest);
940 AssertRCReturnStmt(vrc, RTVfsIoStrmRelease(hVfsIos), NIL_RTVFSIOSTREAM);
941 }
942
943 /* Setup the stream. */
944 RTVFSIOSTREAM hVfsIosPt;
945 vrc = RTManifestEntryAddPassthruIoStream(m->hOurManifest, hVfsIos, pszManifestEntry, m->fDigestTypes, fRead, &hVfsIosPt);
946
947 RTVfsIoStrmRelease(hVfsIos); /* always consumed! */
948 if (RT_SUCCESS(vrc))
949 return hVfsIosPt;
950
951 setErrorVrc(vrc, "RTManifestEntryAddPassthruIoStream failed with rc=%Rrc", vrc);
952 return NIL_RTVFSIOSTREAM;
953}
954
955/**
956 * Returns true if the appliance is in "idle" state. This should always be the
957 * case unless an import or export is currently in progress. Similar to machine
958 * states, this permits the Appliance implementation code to let go of the
959 * Appliance object lock while a time-consuming disk conversion is in progress
960 * without exposing the appliance to conflicting calls.
961 *
962 * This sets an error on "this" (the appliance) and returns false if the appliance
963 * is busy. The caller should then return E_ACCESSDENIED.
964 *
965 * Must be called from under the object lock!
966 */
967bool Appliance::i_isApplianceIdle()
968{
969 if (m->state == ApplianceImporting)
970 setError(VBOX_E_INVALID_OBJECT_STATE, tr("The appliance is busy importing files"));
971 else if (m->state == ApplianceExporting)
972 setError(VBOX_E_INVALID_OBJECT_STATE, tr("The appliance is busy exporting files"));
973 else
974 return true;
975
976 return false;
977}
978
979HRESULT Appliance::i_searchUniqueVMName(Utf8Str& aName) const
980{
981 IMachine *machine = NULL;
982 char *tmpName = RTStrDup(aName.c_str());
983 int i = 1;
984 while (mVirtualBox->FindMachine(Bstr(tmpName).raw(), &machine) != VBOX_E_OBJECT_NOT_FOUND)
985 {
986 RTStrFree(tmpName);
987 RTStrAPrintf(&tmpName, "%s %d", aName.c_str(), i);
988 ++i;
989 }
990 aName = tmpName;
991 RTStrFree(tmpName);
992
993 return S_OK;
994}
995
996HRESULT Appliance::i_searchUniqueImageFilePath(const Utf8Str &aMachineFolder, DeviceType_T aDeviceType, Utf8Str &aName) const
997{
998 /*
999 * Check if the file exists or if a medium with this path is registered already
1000 */
1001 Utf8Str strAbsName;
1002 ssize_t offDashNum = -1;
1003 ssize_t cchDashNum = 0;
1004 for (unsigned i = 1;; i++)
1005 {
1006 /* Complete the path (could be relative to machine folder). */
1007 int rc = RTPathAbsExCxx(strAbsName, aMachineFolder, aName);
1008 AssertRCReturn(rc, Global::vboxStatusCodeToCOM(rc)); /** @todo stupid caller ignores this */
1009
1010 /* Check that the file does not exist and that there is no media somehow matching the name. */
1011 if (!RTPathExists(strAbsName.c_str()))
1012 {
1013 ComPtr<IMedium> ptrMedium;
1014 HRESULT hrc = mVirtualBox->OpenMedium(Bstr(strAbsName).raw(), aDeviceType, AccessMode_ReadWrite,
1015 FALSE /* fForceNewUuid */, ptrMedium.asOutParam());
1016 if (hrc == VBOX_E_OBJECT_NOT_FOUND)
1017 return S_OK;
1018 }
1019
1020 /* Insert '_%i' before the suffix and try again. */
1021 if (offDashNum < 0)
1022 {
1023 const char *pszSuffix = RTPathSuffix(aName.c_str());
1024 offDashNum = pszSuffix ? pszSuffix - aName.c_str() : aName.length();
1025 }
1026 char szTmp[32];
1027 size_t cchTmp = RTStrPrintf(szTmp, sizeof(szTmp), "_%u", i);
1028 aName.replace(offDashNum, cchDashNum, szTmp, cchTmp);
1029 cchDashNum = cchTmp;
1030 }
1031}
1032
1033/**
1034 * Called from Appliance::importImpl() and Appliance::writeImpl() to set up a
1035 * progress object with the proper weights and maximum progress values.
1036 */
1037HRESULT Appliance::i_setUpProgress(ComObjPtr<Progress> &pProgress,
1038 const Utf8Str &strDescription,
1039 SetUpProgressMode mode)
1040{
1041 HRESULT rc;
1042
1043 /* Create the progress object */
1044 try
1045 {
1046 rc = pProgress.createObject();
1047 if (FAILED(rc))
1048 return rc;
1049 }
1050 catch (std::bad_alloc &)
1051 {
1052 return E_OUTOFMEMORY;
1053 }
1054
1055 // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
1056 i_disksWeight();
1057
1058 m->ulWeightForManifestOperation = 0;
1059
1060 ULONG cOperations = 1 // one for XML setup
1061 + m->cDisks; // plus one per disk
1062 ULONG ulTotalOperationsWeight;
1063 if (m->ulTotalDisksMB)
1064 {
1065 m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100); // use 1% of the progress for the XML
1066 ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
1067 }
1068 else
1069 {
1070 // no disks to export:
1071 m->ulWeightForXmlOperation = 1;
1072 ulTotalOperationsWeight = 1;
1073 }
1074
1075 switch (mode)
1076 {
1077 case ImportFile:
1078 {
1079 break;
1080 }
1081 case WriteFile:
1082 {
1083 // assume that creating the manifest will take .1% of the time it takes to export the disks
1084 if (m->fManifest)
1085 {
1086 ++cOperations; // another one for creating the manifest
1087
1088 m->ulWeightForManifestOperation = (ULONG)((double)m->ulTotalDisksMB * .1 / 100); // use .5% of the
1089 // progress for the manifest
1090 ulTotalOperationsWeight += m->ulWeightForManifestOperation;
1091 }
1092 break;
1093 }
1094 case ImportS3:
1095 {
1096 cOperations += 1 + 1; // another one for the manifest file & another one for the import
1097 ulTotalOperationsWeight = m->ulTotalDisksMB;
1098 if (!m->ulTotalDisksMB)
1099 // no disks to export:
1100 ulTotalOperationsWeight = 1;
1101
1102 ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50 / 100); // use 50% for import
1103 ulTotalOperationsWeight += ulImportWeight;
1104
1105 m->ulWeightForXmlOperation = ulImportWeight; /* save for using later */
1106
1107 ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1 / 100); // use 0.1% for init
1108 ulTotalOperationsWeight += ulInitWeight;
1109 break;
1110 }
1111 case WriteS3:
1112 {
1113 cOperations += 1 + 1; // another one for the mf & another one for temporary creation
1114
1115 if (m->ulTotalDisksMB)
1116 {
1117 m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100); // use 1% of the progress
1118 // for OVF file upload
1119 // (we didn't know the
1120 // size at this point)
1121 ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
1122 }
1123 else
1124 {
1125 // no disks to export:
1126 ulTotalOperationsWeight = 1;
1127 m->ulWeightForXmlOperation = 1;
1128 }
1129 ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the
1130 creation of the OVF
1131 & the disks */
1132 ulTotalOperationsWeight += ulOVFCreationWeight;
1133 break;
1134 }
1135 case ExportCloud:
1136 case ImportCloud:
1137 break;
1138 }
1139 Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightForXmlOperation = %d\n",
1140 m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
1141
1142 return pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
1143 strDescription,
1144 TRUE /* aCancelable */,
1145 cOperations, // ULONG cOperations,
1146 ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
1147 strDescription, // CBSTR bstrFirstOperationDescription,
1148 m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
1149}
1150
1151void Appliance::i_addWarning(const char* aWarning, ...)
1152{
1153 try
1154 {
1155 va_list args;
1156 va_start(args, aWarning);
1157 Utf8Str str(aWarning, args);
1158 va_end(args);
1159 m->llWarnings.push_back(str);
1160 }
1161 catch (...)
1162 {
1163 AssertFailed();
1164 }
1165}
1166
1167/**
1168 * Refreshes the cDisks and ulTotalDisksMB members in the instance data.
1169 * Requires that virtual system descriptions are present.
1170 */
1171void Appliance::i_disksWeight()
1172{
1173 m->ulTotalDisksMB = 0;
1174 m->cDisks = 0;
1175 // weigh the disk images according to their sizes
1176 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
1177 for (it = m->virtualSystemDescriptions.begin();
1178 it != m->virtualSystemDescriptions.end();
1179 ++it)
1180 {
1181 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
1182 /* One for every medium of the Virtual System */
1183 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
1184 std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
1185 for (itH = avsdeHDs.begin();
1186 itH != avsdeHDs.end();
1187 ++itH)
1188 {
1189 const VirtualSystemDescriptionEntry *pHD = *itH;
1190 m->ulTotalDisksMB += pHD->ulSizeMB;
1191 ++m->cDisks;
1192 }
1193
1194 avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_CDROM);
1195 for (itH = avsdeHDs.begin();
1196 itH != avsdeHDs.end();
1197 ++itH)
1198 {
1199 const VirtualSystemDescriptionEntry *pHD = *itH;
1200 m->ulTotalDisksMB += pHD->ulSizeMB;
1201 ++m->cDisks;
1202 }
1203 }
1204
1205}
1206
1207void Appliance::i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket)
1208{
1209 /* Buckets are S3 specific. So parse the bucket out of the file path */
1210 if (!aPath.startsWith("/"))
1211 throw setError(E_INVALIDARG,
1212 tr("The path '%s' must start with /"), aPath.c_str());
1213 size_t bpos = aPath.find("/", 1);
1214 if (bpos != Utf8Str::npos)
1215 {
1216 aBucket = aPath.substr(1, bpos - 1); /* The bucket without any slashes */
1217 aPath = aPath.substr(bpos); /* The rest of the file path */
1218 }
1219 /* If there is no bucket name provided reject it */
1220 if (aBucket.isEmpty())
1221 throw setError(E_INVALIDARG,
1222 tr("You doesn't provide a bucket name in the URI '%s'"), aPath.c_str());
1223}
1224
1225/**
1226 * Worker for TaskOVF::handler.
1227 *
1228 * The TaskOVF is started in Appliance::readImpl() and Appliance::importImpl()
1229 * and Appliance::writeImpl().
1230 *
1231 * This will in turn call Appliance::readFS() or Appliance::importFS() or
1232 * Appliance::writeFS().
1233 *
1234 * @thread pTask The task.
1235 */
1236/* static */ void Appliance::i_importOrExportThreadTask(TaskOVF *pTask)
1237{
1238 LogFlowFuncEnter();
1239 AssertReturnVoid(pTask);
1240
1241 Appliance *pAppliance = pTask->pAppliance;
1242 LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
1243
1244 switch (pTask->taskType)
1245 {
1246 case TaskOVF::Read:
1247 pAppliance->m->resetReadData();
1248 if (pTask->locInfo.storageType == VFSType_File)
1249 pTask->rc = pAppliance->i_readFS(pTask);
1250 else
1251 pTask->rc = E_NOTIMPL;
1252 break;
1253
1254 case TaskOVF::Import:
1255 /** @todo allow overriding these? */
1256 if (!pAppliance->m->fSignatureValid && pAppliance->m->pbSignedDigest)
1257 pTask->rc = pAppliance->setError(E_FAIL, tr("The manifest signature for '%s' is not valid"),
1258 pTask->locInfo.strPath.c_str());
1259 else if (!pAppliance->m->fCertificateValid && pAppliance->m->pbSignedDigest)
1260 {
1261 if (pAppliance->m->strCertError.isNotEmpty())
1262 pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is not valid: %s"),
1263 pTask->locInfo.strPath.c_str(), pAppliance->m->strCertError.c_str());
1264 else
1265 pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is not valid"),
1266 pTask->locInfo.strPath.c_str());
1267 }
1268 // fusion does not consider this a show stopper (we've filed a warning during read).
1269 //else if (pAppliance->m->fCertificateMissingPath && pAppliance->m->pbSignedDigest)
1270 // pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is does not have a valid CA path"),
1271 // pTask->locInfo.strPath.c_str());
1272 else
1273 {
1274 if (pTask->locInfo.storageType == VFSType_File)
1275 pTask->rc = pAppliance->i_importFS(pTask);
1276 else
1277 pTask->rc = E_NOTIMPL;
1278 }
1279 break;
1280
1281 case TaskOVF::Write:
1282 if (pTask->locInfo.storageType == VFSType_File)
1283 pTask->rc = pAppliance->i_writeFS(pTask);
1284 else
1285 pTask->rc = E_NOTIMPL;
1286 break;
1287
1288 default:
1289 AssertFailed();
1290 pTask->rc = E_FAIL;
1291 break;
1292 }
1293
1294 if (!pTask->pProgress.isNull())
1295 pTask->pProgress->i_notifyComplete(pTask->rc);
1296
1297 LogFlowFuncLeave();
1298}
1299
1300/* static */ DECLCALLBACK(int) Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser)
1301{
1302 Appliance::TaskOVF* pTask = *(Appliance::TaskOVF**)pvUser;
1303
1304 if ( pTask
1305 && !pTask->pProgress.isNull())
1306 {
1307 BOOL fCanceled;
1308 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
1309 if (fCanceled)
1310 return -1;
1311 pTask->pProgress->SetCurrentOperationProgress(uPercent);
1312 }
1313 return VINF_SUCCESS;
1314}
1315
1316/**
1317 * Worker for TaskOPC::handler.
1318 * @thread pTask The task.
1319 */
1320/* static */
1321void Appliance::i_exportOPCThreadTask(TaskOPC *pTask)
1322{
1323 LogFlowFuncEnter();
1324 AssertReturnVoid(pTask);
1325
1326 Appliance *pAppliance = pTask->pAppliance;
1327 LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
1328
1329 switch (pTask->taskType)
1330 {
1331 case TaskOPC::Export:
1332 pTask->rc = pAppliance->i_writeFSOPC(pTask);
1333 break;
1334
1335 default:
1336 AssertFailed();
1337 pTask->rc = E_FAIL;
1338 break;
1339 }
1340
1341 if (!pTask->pProgress.isNull())
1342 pTask->pProgress->i_notifyComplete(pTask->rc);
1343
1344 LogFlowFuncLeave();
1345}
1346
1347/* static */
1348DECLCALLBACK(int) Appliance::TaskOPC::updateProgress(unsigned uPercent, void *pvUser)
1349{
1350 Appliance::TaskOPC* pTask = *(Appliance::TaskOPC**)pvUser;
1351
1352 if ( pTask
1353 && !pTask->pProgress.isNull())
1354 {
1355 BOOL fCanceled;
1356 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
1357 if (fCanceled)
1358 return -1;
1359 pTask->pProgress->SetCurrentOperationProgress(uPercent);
1360 }
1361 return VINF_SUCCESS;
1362}
1363
1364/**
1365 * Worker for TaskCloud::handler.
1366 * @thread pTask The task.
1367 */
1368/* static */
1369void Appliance::i_importOrExportCloudThreadTask(TaskCloud *pTask)
1370{
1371 LogFlowFuncEnter();
1372 AssertReturnVoid(pTask);
1373
1374 Appliance *pAppliance = pTask->pAppliance;
1375 LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
1376
1377 switch (pTask->taskType)
1378 {
1379 case TaskCloud::Export:
1380 pAppliance->i_setApplianceState(ApplianceExporting);
1381 pTask->rc = pAppliance->i_exportCloudImpl(pTask);
1382 break;
1383 case TaskCloud::Import:
1384 pAppliance->i_setApplianceState(ApplianceImporting);
1385 pTask->rc = pAppliance->i_importCloudImpl(pTask);
1386 break;
1387 case TaskCloud::ReadData:
1388 pAppliance->i_setApplianceState(ApplianceImporting);
1389 pTask->rc = pAppliance->i_gettingCloudData(pTask);
1390 break;
1391 default:
1392 AssertFailed();
1393 pTask->rc = E_FAIL;
1394 break;
1395 }
1396
1397 pAppliance->i_setApplianceState(ApplianceIdle);
1398
1399 if (!pTask->pProgress.isNull())
1400 pTask->pProgress->i_notifyComplete(pTask->rc);
1401
1402 LogFlowFuncLeave();
1403}
1404
1405/* static */
1406DECLCALLBACK(int) Appliance::TaskCloud::updateProgress(unsigned uPercent, void *pvUser)
1407{
1408 Appliance::TaskCloud* pTask = *(Appliance::TaskCloud**)pvUser;
1409
1410 if ( pTask
1411 && !pTask->pProgress.isNull())
1412 {
1413 BOOL fCanceled;
1414 pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
1415 if (fCanceled)
1416 return -1;
1417 pTask->pProgress->SetCurrentOperationProgress(uPercent);
1418 }
1419 return VINF_SUCCESS;
1420}
1421
1422void i_parseURI(Utf8Str strUri, LocationInfo &locInfo)
1423{
1424 /* Check the URI for the protocol */
1425 if (strUri.startsWith("file://", Utf8Str::CaseInsensitive)) /* File based */
1426 {
1427 locInfo.storageType = VFSType_File;
1428 strUri = strUri.substr(sizeof("file://") - 1);
1429 }
1430 else if (strUri.startsWith("SunCloud://", Utf8Str::CaseInsensitive)) /* Sun Cloud service */
1431 {
1432 locInfo.storageType = VFSType_S3;
1433 strUri = strUri.substr(sizeof("SunCloud://") - 1);
1434 }
1435 else if (strUri.startsWith("S3://", Utf8Str::CaseInsensitive)) /* S3 service */
1436 {
1437 locInfo.storageType = VFSType_S3;
1438 strUri = strUri.substr(sizeof("S3://") - 1);
1439 }
1440 else if (strUri.startsWith("OCI://", Utf8Str::CaseInsensitive)) /* OCI service (storage or compute) */
1441 {
1442 locInfo.storageType = VFSType_Cloud;
1443 locInfo.strProvider = "OCI";
1444 strUri = strUri.substr(sizeof("OCI://") - 1);
1445 }
1446 else if (strUri.startsWith("webdav://", Utf8Str::CaseInsensitive)) /* webdav service */
1447 throw E_NOTIMPL;
1448
1449 /* Not necessary on a file based URI */
1450// if (locInfo.storageType != VFSType_File)
1451// {
1452// size_t uppos = strUri.find("@"); /* username:password combo */
1453// if (uppos != Utf8Str::npos)
1454// {
1455// locInfo.strUsername = strUri.substr(0, uppos);
1456// strUri = strUri.substr(uppos + 1);
1457// size_t upos = locInfo.strUsername.find(":");
1458// if (upos != Utf8Str::npos)
1459// {
1460// locInfo.strPassword = locInfo.strUsername.substr(upos + 1);
1461// locInfo.strUsername = locInfo.strUsername.substr(0, upos);
1462// }
1463// }
1464// size_t hpos = strUri.find("/"); /* hostname part */
1465// if (hpos != Utf8Str::npos)
1466// {
1467// locInfo.strHostname = strUri.substr(0, hpos);
1468// strUri = strUri.substr(hpos);
1469// }
1470// }
1471
1472 locInfo.strPath = strUri;
1473}
1474
1475
1476////////////////////////////////////////////////////////////////////////////////
1477//
1478// IVirtualSystemDescription constructor / destructor
1479//
1480////////////////////////////////////////////////////////////////////////////////
1481
1482/**
1483 * COM initializer.
1484 * @return
1485 */
1486HRESULT VirtualSystemDescription::init()
1487{
1488 /* Enclose the state transition NotReady->InInit->Ready */
1489 AutoInitSpan autoInitSpan(this);
1490 AssertReturn(autoInitSpan.isOk(), E_FAIL);
1491
1492 /* Initialize data */
1493 m = new Data();
1494 m->pConfig = NULL;
1495
1496 /* Confirm a successful initialization */
1497 autoInitSpan.setSucceeded();
1498 return S_OK;
1499}
1500
1501/**
1502* COM uninitializer.
1503*/
1504
1505void VirtualSystemDescription::uninit()
1506{
1507 if (m->pConfig)
1508 delete m->pConfig;
1509 delete m;
1510 m = NULL;
1511}
1512
1513
1514////////////////////////////////////////////////////////////////////////////////
1515//
1516// IVirtualSystemDescription public methods
1517//
1518////////////////////////////////////////////////////////////////////////////////
1519
1520/**
1521 * Public method implementation.
1522 */
1523HRESULT VirtualSystemDescription::getCount(ULONG *aCount)
1524{
1525 if (!aCount)
1526 return E_POINTER;
1527
1528 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1529
1530 *aCount = (ULONG)m->maDescriptions.size();
1531 return S_OK;
1532}
1533
1534/**
1535 * Public method implementation.
1536 */
1537HRESULT VirtualSystemDescription::getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
1538 std::vector<com::Utf8Str> &aRefs,
1539 std::vector<com::Utf8Str> &aOVFValues,
1540 std::vector<com::Utf8Str> &aVBoxValues,
1541 std::vector<com::Utf8Str> &aExtraConfigValues)
1542
1543{
1544 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1545 size_t c = m->maDescriptions.size();
1546 aTypes.resize(c);
1547 aRefs.resize(c);
1548 aOVFValues.resize(c);
1549 aVBoxValues.resize(c);
1550 aExtraConfigValues.resize(c);
1551
1552 for (size_t i = 0; i < c; i++)
1553 {
1554 const VirtualSystemDescriptionEntry &vsde = m->maDescriptions[i];
1555 aTypes[i] = vsde.type;
1556 aRefs[i] = vsde.strRef;
1557 aOVFValues[i] = vsde.strOvf;
1558 aVBoxValues[i] = vsde.strVBoxCurrent;
1559 aExtraConfigValues[i] = vsde.strExtraConfigCurrent;
1560 }
1561 return S_OK;
1562}
1563
1564/**
1565 * Public method implementation.
1566 */
1567HRESULT VirtualSystemDescription::getDescriptionByType(VirtualSystemDescriptionType_T aType,
1568 std::vector<VirtualSystemDescriptionType_T> &aTypes,
1569 std::vector<com::Utf8Str> &aRefs,
1570 std::vector<com::Utf8Str> &aOVFValues,
1571 std::vector<com::Utf8Str> &aVBoxValues,
1572 std::vector<com::Utf8Str> &aExtraConfigValues)
1573{
1574 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1575 std::list<VirtualSystemDescriptionEntry*> vsd = i_findByType(aType);
1576
1577 size_t c = vsd.size();
1578 aTypes.resize(c);
1579 aRefs.resize(c);
1580 aOVFValues.resize(c);
1581 aVBoxValues.resize(c);
1582 aExtraConfigValues.resize(c);
1583
1584 size_t i = 0;
1585 for (list<VirtualSystemDescriptionEntry*>::const_iterator it = vsd.begin(); it != vsd.end(); ++it, ++i)
1586 {
1587 const VirtualSystemDescriptionEntry *vsde = (*it);
1588 aTypes[i] = vsde->type;
1589 aRefs[i] = vsde->strRef;
1590 aOVFValues[i] = vsde->strOvf;
1591 aVBoxValues[i] = vsde->strVBoxCurrent;
1592 aExtraConfigValues[i] = vsde->strExtraConfigCurrent;
1593 }
1594
1595 return S_OK;
1596}
1597
1598/**
1599 * Public method implementation.
1600 */
1601HRESULT VirtualSystemDescription::getValuesByType(VirtualSystemDescriptionType_T aType,
1602 VirtualSystemDescriptionValueType_T aWhich,
1603 std::vector<com::Utf8Str> &aValues)
1604{
1605 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1606
1607 std::list<VirtualSystemDescriptionEntry*> vsd = i_findByType (aType);
1608 aValues.resize((ULONG)vsd.size());
1609
1610 list<VirtualSystemDescriptionEntry*>::const_iterator it;
1611 size_t i = 0;
1612 for (it = vsd.begin();
1613 it != vsd.end();
1614 ++it, ++i)
1615 {
1616 const VirtualSystemDescriptionEntry *vsde = (*it);
1617
1618 Bstr bstr;
1619 switch (aWhich)
1620 {
1621 case VirtualSystemDescriptionValueType_Reference: aValues[i] = vsde->strRef; break;
1622 case VirtualSystemDescriptionValueType_Original: aValues[i] = vsde->strOvf; break;
1623 case VirtualSystemDescriptionValueType_Auto: aValues[i] = vsde->strVBoxCurrent; break;
1624 case VirtualSystemDescriptionValueType_ExtraConfig: aValues[i] = vsde->strExtraConfigCurrent; break;
1625#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
1626 case VirtualSystemDescriptionValueType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
1627#endif
1628 }
1629 }
1630
1631 return S_OK;
1632}
1633
1634/**
1635 * Public method implementation.
1636 */
1637HRESULT VirtualSystemDescription::setFinalValues(const std::vector<BOOL> &aEnabled,
1638 const std::vector<com::Utf8Str> &aVBoxValues,
1639 const std::vector<com::Utf8Str> &aExtraConfigValues)
1640{
1641#ifndef RT_OS_WINDOWS
1642 // NOREF(aEnabledSize);
1643#endif /* RT_OS_WINDOWS */
1644 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1645
1646 if ( (aEnabled.size() != m->maDescriptions.size())
1647 || (aVBoxValues.size() != m->maDescriptions.size())
1648 || (aExtraConfigValues.size() != m->maDescriptions.size())
1649 )
1650 return E_INVALIDARG;
1651
1652 size_t i = 0;
1653 for (vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1654 it != m->maDescriptions.end();
1655 ++it, ++i)
1656 {
1657 VirtualSystemDescriptionEntry& vsde = *it;
1658
1659 if (aEnabled[i])
1660 {
1661 vsde.strVBoxCurrent = aVBoxValues[i];
1662 vsde.strExtraConfigCurrent = aExtraConfigValues[i];
1663 }
1664 else
1665 vsde.type = VirtualSystemDescriptionType_Ignore;
1666 }
1667
1668 return S_OK;
1669}
1670
1671/**
1672 * Public method implementation.
1673 */
1674HRESULT VirtualSystemDescription::addDescription(VirtualSystemDescriptionType_T aType,
1675 const com::Utf8Str &aVBoxValue,
1676 const com::Utf8Str &aExtraConfigValue)
1677
1678{
1679 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1680 i_addEntry(aType, "", aVBoxValue, aVBoxValue, 0, aExtraConfigValue);
1681 return S_OK;
1682}
1683
1684/**
1685 * Internal method; adds a new description item to the member list.
1686 * @param aType Type of description for the new item.
1687 * @param strRef Reference item; only used with storage controllers.
1688 * @param aOvfValue Corresponding original value from OVF.
1689 * @param aVBoxValue Initial configuration value (can be overridden by caller with setFinalValues).
1690 * @param ulSizeMB Weight for IProgress
1691 * @param strExtraConfig Extra configuration; meaning dependent on type.
1692 */
1693void VirtualSystemDescription::i_addEntry(VirtualSystemDescriptionType_T aType,
1694 const Utf8Str &strRef,
1695 const Utf8Str &aOvfValue,
1696 const Utf8Str &aVBoxValue,
1697 uint32_t ulSizeMB,
1698 const Utf8Str &strExtraConfig /*= ""*/)
1699{
1700 VirtualSystemDescriptionEntry vsde;
1701 vsde.ulIndex = (uint32_t)m->maDescriptions.size(); // each entry gets an index so the client side can reference them
1702 vsde.type = aType;
1703 vsde.strRef = strRef;
1704 vsde.strOvf = aOvfValue;
1705 vsde.strVBoxSuggested /* remember original value */
1706 = vsde.strVBoxCurrent /* and set current value which can be overridden by setFinalValues() */
1707 = aVBoxValue;
1708 vsde.strExtraConfigSuggested
1709 = vsde.strExtraConfigCurrent
1710 = strExtraConfig;
1711 vsde.ulSizeMB = ulSizeMB;
1712
1713 vsde.skipIt = false;
1714
1715 m->maDescriptions.push_back(vsde);
1716}
1717
1718/**
1719 * Private method; returns a list of description items containing all the items from the member
1720 * description items of this virtual system that match the given type.
1721 */
1722std::list<VirtualSystemDescriptionEntry*> VirtualSystemDescription::i_findByType(VirtualSystemDescriptionType_T aType)
1723{
1724 std::list<VirtualSystemDescriptionEntry*> vsd;
1725 for (vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1726 it != m->maDescriptions.end();
1727 ++it)
1728 {
1729 if (it->type == aType)
1730 vsd.push_back(&(*it));
1731 }
1732
1733 return vsd;
1734}
1735
1736HRESULT VirtualSystemDescription::removeDescriptionByType(VirtualSystemDescriptionType_T aType)
1737{
1738 std::vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1739 while (it != m->maDescriptions.end())
1740 {
1741 if (it->type == aType)
1742 it = m->maDescriptions.erase(it);
1743 else
1744 ++it;
1745 }
1746
1747 return S_OK;
1748}
1749
1750/* Private method; delete all records from the list
1751 * m->llDescriptions that match the given type.
1752 */
1753void VirtualSystemDescription::i_removeByType(VirtualSystemDescriptionType_T aType)
1754{
1755 std::vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
1756 while (it != m->maDescriptions.end())
1757 {
1758 if (it->type == aType)
1759 it = m->maDescriptions.erase(it);
1760 else
1761 ++it;
1762 }
1763}
1764
1765/**
1766 * Private method; looks thru the member hardware items for the IDE, SATA, or SCSI controller with
1767 * the given reference ID. Useful when needing the controller for a particular
1768 * virtual disk.
1769 */
1770const VirtualSystemDescriptionEntry* VirtualSystemDescription::i_findControllerFromID(uint32_t id)
1771{
1772 Utf8Str strRef = Utf8StrFmt("%RI32", id);
1773 vector<VirtualSystemDescriptionEntry>::const_iterator it;
1774 for (it = m->maDescriptions.begin();
1775 it != m->maDescriptions.end();
1776 ++it)
1777 {
1778 const VirtualSystemDescriptionEntry &d = *it;
1779 switch (d.type)
1780 {
1781 case VirtualSystemDescriptionType_HardDiskControllerIDE:
1782 case VirtualSystemDescriptionType_HardDiskControllerSATA:
1783 case VirtualSystemDescriptionType_HardDiskControllerSCSI:
1784 case VirtualSystemDescriptionType_HardDiskControllerSAS:
1785 if (d.strRef == strRef)
1786 return &d;
1787 break;
1788 default: break; /* Shut up MSC. */
1789 }
1790 }
1791
1792 return NULL;
1793}
1794
1795/**
1796 * Method called from Appliance::Interpret() if the source OVF for a virtual system
1797 * contains a <vbox:Machine> element. This method then attempts to parse that and
1798 * create a MachineConfigFile instance from it which is stored in this instance data
1799 * and can then be used to create a machine.
1800 *
1801 * This must only be called once per instance.
1802 *
1803 * This rethrows all XML and logic errors from MachineConfigFile.
1804 *
1805 * @param elmMachine <vbox:Machine> element with attributes and subelements from some
1806 * DOM tree.
1807 */
1808void VirtualSystemDescription::i_importVBoxMachineXML(const xml::ElementNode &elmMachine)
1809{
1810 settings::MachineConfigFile *pConfig = NULL;
1811
1812 Assert(m->pConfig == NULL);
1813
1814 try
1815 {
1816 pConfig = new settings::MachineConfigFile(NULL);
1817 pConfig->importMachineXML(elmMachine);
1818
1819 m->pConfig = pConfig;
1820 }
1821 catch (...)
1822 {
1823 if (pConfig)
1824 delete pConfig;
1825 throw;
1826 }
1827}
1828
1829/**
1830 * Returns the machine config created by importVBoxMachineXML() or NULL if there's none.
1831 */
1832const settings::MachineConfigFile* VirtualSystemDescription::i_getMachineConfig() const
1833{
1834 return m->pConfig;
1835}
1836
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette