VirtualBox

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

Last change on this file since 81222 was 78923, checked in by vboxsync, 6 years ago

bugref:9416. Changed the choosing OS type logic for OCI import. Added small private helper function i_setApplianceState(). Moved ApplianceState from Appliance::Data to Appliance.

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