VirtualBox

source: vbox/trunk/src/VBox/Main/include/ovfreader.h@ 107526

Last change on this file since 107526 was 107520, checked in by vboxsync, 4 weeks ago

src/VBox/Main/include/ovfreader.h: Fixed warning found by Parfait (uninitialized attributes). jiraref:VBP-1424

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.1 KB
Line 
1/* $Id: ovfreader.h 107520 2025-01-08 14:47:23Z vboxsync $ */
2/** @file
3 * VirtualBox Main - OVF reader declarations.
4 *
5 * Depends only on IPRT, including the RTCString and IPRT XML classes.
6 */
7
8/*
9 * Copyright (C) 2008-2024 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30#ifndef MAIN_INCLUDED_ovfreader_h
31#define MAIN_INCLUDED_ovfreader_h
32#ifndef RT_WITHOUT_PRAGMA_ONCE
33# pragma once
34#endif
35
36#include "iprt/cpp/xml.h"
37#include <map>
38#include <vector>
39
40namespace ovf
41{
42
43////////////////////////////////////////////////////////////////////////////////
44//
45// Errors
46//
47////////////////////////////////////////////////////////////////////////////////
48
49/**
50 * Thrown by OVFReader for any kind of error that is not an XML error but
51 * still makes the OVF impossible to parse. Based on xml::LogicError so
52 * that one catch() for all xml::LogicError can handle all possible errors.
53 */
54class OVFLogicError : public xml::LogicError
55{
56public:
57 OVFLogicError(const char *aFormat, ...);
58};
59
60
61////////////////////////////////////////////////////////////////////////////////
62//
63// Enumerations
64//
65////////////////////////////////////////////////////////////////////////////////
66
67/**
68 * CIM OS values.
69 *
70 * The OVF 1.10 spec refers to some CIM_OperatingSystem.mof doc. Could this be it:
71 * http://cvs.opengroup.org/cgi-bin/cvsweb.cgi/pegasus/Schemas/CIM231/DMTF/System/CIM_OperatingSystem.mof
72 *
73 * @todo r=bird: Why are the values are repeating 'CIMOS'. CIMOSType_T is also
74 * repeating it self, 'Type' and '_T'. Why not call it kCIOMOpSys,
75 * easier to read as well.
76 * Then also apply: s/CIMOSType_CIMOS_/kCIMOpSys_/g
77 */
78enum CIMOSType_T
79{
80 CIMOSType_CIMOS_Unknown = 0,
81 CIMOSType_CIMOS_Other = 1,
82 CIMOSType_CIMOS_MACOS = 2,
83 CIMOSType_CIMOS_ATTUNIX = 3,
84 CIMOSType_CIMOS_DGUX = 4,
85 CIMOSType_CIMOS_DECNT = 5,
86 CIMOSType_CIMOS_Tru64UNIX = 6,
87 CIMOSType_CIMOS_OpenVMS = 7,
88 CIMOSType_CIMOS_HPUX = 8,
89 CIMOSType_CIMOS_AIX = 9,
90 CIMOSType_CIMOS_MVS = 10,
91 CIMOSType_CIMOS_OS400 = 11,
92 CIMOSType_CIMOS_OS2 = 12,
93 CIMOSType_CIMOS_JavaVM = 13,
94 CIMOSType_CIMOS_MSDOS = 14,
95 CIMOSType_CIMOS_WIN3x = 15,
96 CIMOSType_CIMOS_WIN95 = 16,
97 CIMOSType_CIMOS_WIN98 = 17,
98 CIMOSType_CIMOS_WINNT = 18,
99 CIMOSType_CIMOS_WINCE = 19,
100 CIMOSType_CIMOS_NCR3000 = 20,
101 CIMOSType_CIMOS_NetWare = 21,
102 CIMOSType_CIMOS_OSF = 22,
103 CIMOSType_CIMOS_DCOS = 23,
104 CIMOSType_CIMOS_ReliantUNIX = 24,
105 CIMOSType_CIMOS_SCOUnixWare = 25,
106 CIMOSType_CIMOS_SCOOpenServer = 26,
107 CIMOSType_CIMOS_Sequent = 27,
108 CIMOSType_CIMOS_IRIX = 28,
109 CIMOSType_CIMOS_Solaris = 29,
110 CIMOSType_CIMOS_SunOS = 30,
111 CIMOSType_CIMOS_U6000 = 31,
112 CIMOSType_CIMOS_ASERIES = 32,
113 CIMOSType_CIMOS_HPNonStopOS = 33,
114 CIMOSType_CIMOS_HPNonStopOSS = 34,
115 CIMOSType_CIMOS_BS2000 = 35,
116 CIMOSType_CIMOS_LINUX = 36,
117 CIMOSType_CIMOS_Lynx = 37,
118 CIMOSType_CIMOS_XENIX = 38,
119 CIMOSType_CIMOS_VM = 39,
120 CIMOSType_CIMOS_InteractiveUNIX = 40,
121 CIMOSType_CIMOS_BSDUNIX = 41,
122 CIMOSType_CIMOS_FreeBSD = 42,
123 CIMOSType_CIMOS_NetBSD = 43,
124 CIMOSType_CIMOS_GNUHurd = 44,
125 CIMOSType_CIMOS_OS9 = 45,
126 CIMOSType_CIMOS_MACHKernel = 46,
127 CIMOSType_CIMOS_Inferno = 47,
128 CIMOSType_CIMOS_QNX = 48,
129 CIMOSType_CIMOS_EPOC = 49,
130 CIMOSType_CIMOS_IxWorks = 50,
131 CIMOSType_CIMOS_VxWorks = 51,
132 CIMOSType_CIMOS_MiNT = 52,
133 CIMOSType_CIMOS_BeOS = 53,
134 CIMOSType_CIMOS_HPMPE = 54,
135 CIMOSType_CIMOS_NextStep = 55,
136 CIMOSType_CIMOS_PalmPilot = 56,
137 CIMOSType_CIMOS_Rhapsody = 57,
138 CIMOSType_CIMOS_Windows2000 = 58,
139 CIMOSType_CIMOS_Dedicated = 59,
140 CIMOSType_CIMOS_OS390 = 60,
141 CIMOSType_CIMOS_VSE = 61,
142 CIMOSType_CIMOS_TPF = 62,
143 CIMOSType_CIMOS_WindowsMe = 63,
144 CIMOSType_CIMOS_CalderaOpenUNIX = 64,
145 CIMOSType_CIMOS_OpenBSD = 65,
146 CIMOSType_CIMOS_NotApplicable = 66,
147 CIMOSType_CIMOS_WindowsXP = 67,
148 CIMOSType_CIMOS_zOS = 68,
149 CIMOSType_CIMOS_MicrosoftWindowsServer2003 = 69,
150 CIMOSType_CIMOS_MicrosoftWindowsServer2003_64 = 70,
151 CIMOSType_CIMOS_WindowsXP_64 = 71,
152 CIMOSType_CIMOS_WindowsXPEmbedded = 72,
153 CIMOSType_CIMOS_WindowsVista = 73,
154 CIMOSType_CIMOS_WindowsVista_64 = 74,
155 CIMOSType_CIMOS_WindowsEmbeddedforPointofService = 75,
156 CIMOSType_CIMOS_MicrosoftWindowsServer2008 = 76,
157 CIMOSType_CIMOS_MicrosoftWindowsServer2008_64 = 77,
158 CIMOSType_CIMOS_FreeBSD_64 = 78,
159 CIMOSType_CIMOS_RedHatEnterpriseLinux = 79,
160 CIMOSType_CIMOS_RedHatEnterpriseLinux_64 = 80,
161 CIMOSType_CIMOS_Solaris_64 = 81,
162 CIMOSType_CIMOS_SUSE = 82,
163 CIMOSType_CIMOS_SUSE_64 = 83,
164 CIMOSType_CIMOS_SLES = 84,
165 CIMOSType_CIMOS_SLES_64 = 85,
166 CIMOSType_CIMOS_NovellOES = 86,
167 CIMOSType_CIMOS_NovellLinuxDesktop = 87,
168 CIMOSType_CIMOS_SunJavaDesktopSystem = 88,
169 CIMOSType_CIMOS_Mandriva = 89,
170 CIMOSType_CIMOS_Mandriva_64 = 90,
171 CIMOSType_CIMOS_TurboLinux = 91,
172 CIMOSType_CIMOS_TurboLinux_64 = 92,
173 CIMOSType_CIMOS_Ubuntu = 93,
174 CIMOSType_CIMOS_Ubuntu_64 = 94,
175 CIMOSType_CIMOS_Debian = 95,
176 CIMOSType_CIMOS_Debian_64 = 96,
177 CIMOSType_CIMOS_Linux_2_4_x = 97,
178 CIMOSType_CIMOS_Linux_2_4_x_64 = 98,
179 CIMOSType_CIMOS_Linux_2_6_x = 99,
180 CIMOSType_CIMOS_Linux_2_6_x_64 = 100,
181 CIMOSType_CIMOS_Linux_64 = 101,
182 CIMOSType_CIMOS_Other_64 = 102,
183 // types added with CIM 2.25.0 follow:
184 CIMOSType_CIMOS_WindowsServer2008R2 = 103,
185 CIMOSType_CIMOS_VMwareESXi = 104,
186 CIMOSType_CIMOS_Windows7 = 105,
187 CIMOSType_CIMOS_CentOS = 106,
188 CIMOSType_CIMOS_CentOS_64 = 107,
189 CIMOSType_CIMOS_OracleLinux = 108,
190 CIMOSType_CIMOS_OracleLinux_64 = 109,
191 CIMOSType_CIMOS_eComStation = 110,
192 // no new types added with CIM 2.26.0
193 CIMOSType_CIMOS_WindowsServer2011 = 111,
194 CIMOSType_CIMOS_WindowsServer2012 = 112,
195 CIMOSType_CIMOS_Windows8 = 113,
196 CIMOSType_CIMOS_Windows8_64 = 114,
197 CIMOSType_CIMOS_WindowsServer2012R2 = 115,
198 CIMOSType_CIMOS_Windows8_1 = 116,
199 CIMOSType_CIMOS_Windows8_1_64 = 117,
200 CIMOSType_CIMOS_WindowsServer2016 = 118,
201 CIMOSType_CIMOS_Windows10 = 119,
202 CIMOSType_CIMOS_Windows10_64 = 120,
203 // the above covers up to CIM 2.52.0, without checking when it was added
204};
205
206enum OVFVersion_T
207{
208 OVFVersion_unknown,
209 OVFVersion_0_9,
210 OVFVersion_1_0,
211 OVFVersion_2_0
212};
213
214const char* const OVF09_URI_string = "http://www.vmware.com/schema/ovf/1/envelope";
215const char* const OVF10_URI_string = "http://schemas.dmtf.org/ovf/envelope/1";
216const char* const OVF20_URI_string = "http://schemas.dmtf.org/ovf/envelope/2";
217
218const char* const DTMF_SPECS_URI = "http://schemas.dmtf.org/wbem/cim-html/2/";
219
220////////////////////////////////////////////////////////////////////////////////
221//
222// Envelope data
223//
224////////////////////////////////////////////////////////////////////////////////
225struct EnvelopeData
226{
227 OVFVersion_T version;//OVF standard version, it is used internally only by VirtualBox
228 RTCString lang;//language
229
230 OVFVersion_T getOVFVersion() const
231 {
232 return version;
233 }
234
235
236 RTCString getStringOVFVersion() const
237 {
238 if (version == OVFVersion_0_9)
239 return "0.9";
240 else if (version == OVFVersion_1_0)
241 return "1.0";
242 else if (version == OVFVersion_2_0)
243 return "2.0";
244 else
245 return "";
246 }
247
248 void setOVFVersion(OVFVersion_T v)
249 {
250 version = v;
251 }
252};
253
254
255struct FileReference
256{
257 RTCString strHref; // value from /References/File/@href (filename)
258 RTCString strDiskId; // value from /References/File/@id ()
259};
260
261typedef std::map<uint32_t, FileReference> FileReferenceMap;
262
263////////////////////////////////////////////////////////////////////////////////
264//
265// Hardware definition structs
266//
267////////////////////////////////////////////////////////////////////////////////
268
269struct DiskImage
270{
271 // fields from /DiskSection/Disk
272 RTCString strDiskId; // value from DiskSection/Disk/@diskId
273 int64_t iCapacity; // value from DiskSection/Disk/@capacity;
274 // (maximum size for dynamic images, I guess; we always translate this to bytes)
275 int64_t iPopulatedSize; // optional value from DiskSection/Disk/@populatedSize
276 // (actual used size of disk, always in bytes; can be an estimate of used disk
277 // space, but cannot be larger than iCapacity; -1 if not set)
278 RTCString strFormat; // value from DiskSection/Disk/@format
279 // typically http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized
280 RTCString uuidVBox; // optional; if the file was exported by VirtualBox >= 3.2,
281 // then this has the UUID with which the disk was registered
282
283 // fields from /References/File; the spec says the file reference from disk can be empty,
284 // so in that case, strFilename will be empty, then a new disk should be created
285 RTCString strHref; // value from /References/File/@href (filename); if empty, then the remaining fields are ignored
286 int64_t iSize; // value from /References/File/@size (optional according to spec; then we set -1 here)
287 int64_t iChunkSize; // value from /References/File/@chunkSize (optional, unsupported)
288 RTCString strCompression; // value from /References/File/@compression (optional, can be "gzip" according to spec)
289
290 // additional field which has a descriptive size in megabytes derived from the above; this can be used for progress reports
291 uint32_t ulSuggestedSizeMB;
292};
293
294enum ResourceType_T
295{
296 ResourceType_Invalid = 0,
297 ResourceType_Other = 1,
298 ResourceType_ComputerSystem = 2,
299 ResourceType_Processor = 3,
300 ResourceType_Memory = 4,
301 ResourceType_IDEController = 5,
302 ResourceType_ParallelSCSIHBA = 6,
303 ResourceType_FCHBA = 7,
304 ResourceType_iSCSIHBA = 8,
305 ResourceType_IBHCA = 9,
306 ResourceType_EthernetAdapter = 10,
307 ResourceType_OtherNetworkAdapter = 11,
308 ResourceType_IOSlot = 12,
309 ResourceType_IODevice = 13,
310 ResourceType_FloppyDrive = 14,
311 ResourceType_CDDrive = 15,
312 ResourceType_DVDDrive = 16,
313 ResourceType_HardDisk = 17,
314 ResourceType_TapeDrive = 18,
315 ResourceType_StorageExtent = 19,
316 ResourceType_OtherStorageDevice = 20,
317 ResourceType_SerialPort = 21,
318 ResourceType_ParallelPort = 22,
319 ResourceType_USBController = 23,
320 ResourceType_GraphicsController = 24,
321 ResourceType_IEEE1394Controller = 25,
322 ResourceType_PartitionableUnit = 26,
323 ResourceType_BasePartitionableUnit = 27,
324 ResourceType_Power = 28,
325 ResourceType_CoolingCapacity = 29,
326 ResourceType_EthernetSwitchPort = 30,
327 ResourceType_LogicalDisk = 31,
328 ResourceType_StorageVolume = 32,
329 ResourceType_EthernetConnection = 33,
330 ResourceType_SoundCard = 35 /**< @todo r=klaus: Not part of OVF/CIM spec, should use "Other" or some value from 0x8000..0xffff. */
331};
332
333
334enum StorageAccessType_T
335{ StorageAccessType_Unknown = 0,
336 StorageAccessType_Readable = 1,
337 StorageAccessType_Writeable = 2,
338 StorageAccessType_ReadWrite = 3
339};
340
341enum ComplianceType_T
342{ ComplianceType_No = 0,
343 ComplianceType_Soft = 1,
344 ComplianceType_Medium = 2,
345 ComplianceType_Strong = 3
346};
347
348class VirtualHardwareItem
349{
350public:
351 RTCString strDescription;
352 RTCString strCaption;
353 RTCString strElementName;
354
355 RTCString strInstanceID;
356 RTCString strParent;
357
358 ResourceType_T resourceType;
359 RTCString strOtherResourceType;
360 RTCString strResourceSubType;
361 bool fResourceRequired;
362
363 RTCString strHostResource; ///< "Abstractly specifies how a device shall connect to a resource on the deployment platform.
364 /// Not all devices need a backing." Used with disk items, for which this
365 /// references a virtual disk from the Disks section.
366 bool fAutomaticAllocation;
367 bool fAutomaticDeallocation;
368 RTCString strConnection; ///< "All Ethernet adapters that specify the same abstract network connection name within an OVF
369 /// package shall be deployed on the same network. The abstract network connection name shall be
370 /// listed in the NetworkSection at the outermost envelope level." We ignore this and only set up
371 /// a network adapter depending on the network name.
372 RTCString strAddress; ///< "Device-specific. For an Ethernet adapter, this specifies the MAC address."
373 int32_t lAddress; ///< strAddress as an integer, if applicable.
374 RTCString strAddressOnParent;///< "For a device, this specifies its location on the controller."
375 RTCString strAllocationUnits;///< "Specifies the units of allocation used. For example, “byte * 2^20”."
376 uint64_t ullVirtualQuantity; ///< "Specifies the quantity of resources presented. For example, “256”."
377 uint64_t ullReservation; ///< "Specifies the minimum quantity of resources guaranteed to be available."
378 uint64_t ullLimit; ///< "Specifies the maximum quantity of resources that will be granted."
379 uint64_t ullWeight; ///< "Specifies a relative priority for this allocation in relation to other allocations."
380
381 RTCString strConsumerVisibility;
382 RTCString strMappingBehavior;
383 RTCString strPoolID;
384 uint32_t ulBusNumber; ///< seen with IDE controllers, but not listed in OVF spec
385
386 int m_iLineNumber; ///< line number of \<Item\> element in XML source; cached for error messages
387
388 VirtualHardwareItem()
389 : resourceType(ResourceType_Invalid)
390 , fResourceRequired(false)
391 , fAutomaticAllocation(false)
392 , fAutomaticDeallocation(false)
393 , lAddress(0)
394 , ullVirtualQuantity(0)
395 , ullReservation(0)
396 , ullLimit(0)
397 , ullWeight(0)
398 , ulBusNumber(0)
399 , m_iLineNumber(0)
400 , fDefault(false)
401 {
402 itemName = "Item";
403 }
404
405 virtual ~VirtualHardwareItem() { /* Makes MSC happy. */ }
406
407 void fillItem(const xml::ElementNode *item);
408
409 void setDefaultFlag()
410 {
411 fDefault = true;
412 }
413
414 bool isThereDefaultValues() const
415 {
416 return fDefault;
417 }
418
419 void checkConsistencyAndCompliance() RT_THROW(OVFLogicError)
420 {
421 _checkConsistencyAndCompliance();
422 }
423
424protected:
425 virtual void _checkConsistencyAndCompliance() RT_THROW(OVFLogicError);
426 virtual const RTCString& getItemName()
427 {
428 return _getItemName();
429 }
430
431private:
432 RTCString itemName;
433 bool fDefault;//true means that some fields were absent in the XML and some default values were assigned to.
434
435 virtual const RTCString& _getItemName()
436 {
437 return itemName;
438 }
439};
440
441class StorageItem: public VirtualHardwareItem
442{
443 //see DMTF Schema Documentation http://schemas.dmtf.org/wbem/cim-html/2/
444 StorageAccessType_T accessType;
445 RTCString strHostExtentName;
446#if 0 /* unused */
447 int16_t hostExtentNameFormat;
448 int16_t hostExtentNameNamespace;
449 int64_t hostExtentStartingAddress;
450#endif
451 int64_t hostResourceBlockSize;
452 int64_t limit;
453 RTCString strOtherHostExtentNameFormat;
454 RTCString strOtherHostExtentNameNamespace;
455 int64_t reservation;
456 int64_t virtualQuantity;
457 RTCString strVirtualQuantityUnits;
458 int64_t virtualResourceBlockSize;
459
460public:
461 StorageItem()
462 : VirtualHardwareItem()
463 , accessType(StorageAccessType_Unknown)
464#if 0 /* unused */
465 , hostExtentNameFormat(-1)
466 , hostExtentNameNamespace(-1)
467 , hostExtentStartingAddress(-1)
468#endif
469 , hostResourceBlockSize(-1)
470 , limit(-1)
471 , reservation(-1)
472 , virtualQuantity(-1)
473 , virtualResourceBlockSize(-1)
474 {
475 itemName = "StorageItem";
476 };
477
478 void fillItem(const xml::ElementNode *item);
479
480protected:
481 virtual void _checkConsistencyAndCompliance() RT_THROW(OVFLogicError);
482private:
483 RTCString itemName;
484
485 virtual const RTCString& _getItemName()
486 {
487 return itemName;
488 }
489};
490
491
492class EthernetPortItem: public VirtualHardwareItem
493{
494 //see DMTF Schema Documentation http://schemas.dmtf.org/wbem/cim-html/2/
495#if 0 /* unused */
496 uint16_t DefaultPortVID;
497 uint16_t DefaultPriority;
498 uint16_t DesiredVLANEndpointMode;
499 uint32_t GroupID;
500 uint32_t ManagerID;
501 uint16_t NetworkPortProfileIDType;
502#endif
503 RTCString strNetworkPortProfileID;
504 RTCString strOtherEndpointMode;
505 RTCString strOtherNetworkPortProfileIDTypeInfo;
506 RTCString strPortCorrelationID;
507#if 0 /* unused */
508 uint16_t PortVID;
509 bool Promiscuous;
510 uint64_t ReceiveBandwidthLimit;
511 uint16_t ReceiveBandwidthReservation;
512 bool SourceMACFilteringEnabled;
513 uint32_t VSITypeID;
514 uint8_t VSITypeIDVersion;
515 uint16_t AllowedPriorities[256];
516 uint16_t AllowedToReceiveVLANs[256];
517 uint16_t AllowedToTransmitVLANs[256];
518#endif
519 RTCString strAllowedToReceiveMACAddresses;
520 RTCString strAllowedToTransmitMACAddresses;
521
522public:
523 EthernetPortItem() : VirtualHardwareItem()
524 {
525 itemName = "EthernetPortItem";
526 };
527
528 void fillItem(const xml::ElementNode *item);
529
530protected:
531 virtual void _checkConsistencyAndCompliance() RT_THROW(OVFLogicError);
532private:
533 RTCString itemName;
534
535 virtual const RTCString &_getItemName()
536 {
537 return itemName;
538 }
539};
540
541typedef std::map<RTCString, DiskImage> DiskImagesMap;
542
543struct VirtualSystem;
544
545
546/**
547 * VirtualHardwareItem pointer vector with safe cleanup.
548 *
549 * We need to use object pointers because we also want EthernetPortItem and
550 * StorageItems to go into the container.
551 */
552class HardwareItemVector : public std::vector<VirtualHardwareItem *>
553{
554public:
555 HardwareItemVector() : std::vector<VirtualHardwareItem *>() { }
556 ~HardwareItemVector()
557 {
558 for (iterator it = begin(); it != end(); ++it)
559 delete(*it);
560 clear();
561 }
562
563 /* We only support copying if the vector is empty, we'd need something like
564 shared_ptr for dealing with a populated list. (Problem found by VS 2022.) */
565 HardwareItemVector(const HardwareItemVector &a_rThat)
566 : std::vector<VirtualHardwareItem *>()
567 {
568 Assert(a_rThat.begin() == a_rThat.end());
569 RT_NOREF(a_rThat);
570 }
571
572private:
573#if RT_CPLUSPLUS_PREREQ(201100) /* VC2022: No copy assignment operator (see copy constructor). */
574 HardwareItemVector &operator=(const HardwareItemVector &) = delete;
575#else
576 HardwareItemVector &operator=(const HardwareItemVector &);
577#endif
578};
579
580struct HardDiskController
581{
582 RTCString strIdController; // instance ID (Item/InstanceId); this gets referenced from VirtualDisk
583
584 enum ControllerSystemType { IDE, SATA, SCSI, VIRTIOSCSI, NVMe };
585 ControllerSystemType system; // one of IDE, SATA, SCSI, VIRTIOSCSI, NVMe
586
587 RTCString strControllerType;
588 // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
589 // note that we treat LsiLogicSAS as a SCSI controller (system == SCSI) even though VirtualBox
590 // treats it as a fourth class besides IDE, SATA, SCSI
591
592 int32_t lAddress; // value from OVF "Address" element
593 bool fPrimary; // controller index; this is determined heuristically by the OVF reader and will
594 // be true for the first controller of this type (e.g. IDE primary ctler) or
595 // false for the next (e.g. IDE secondary ctler)
596
597 HardDiskController()
598 : system(IDE),
599 lAddress(0),
600 fPrimary(true)
601 { }
602};
603
604typedef std::map<RTCString, HardDiskController> ControllersMap;
605
606struct VirtualDisk
607{
608 RTCString strIdController; // SCSI (or IDE) controller this disk is connected to;
609 // this must match HardDiskController.strIdController and
610 // points into VirtualSystem.mapControllers
611 uint32_t ulAddressOnParent; // parsed strAddressOnParent of hardware item; will be 0 or 1 for IDE
612 // and possibly higher for disks attached to SCSI controllers (untested)
613 RTCString strDiskId; // if the hard disk has an ovf:/disk/<id> reference,
614 // this receives the <id> component; points to one of the
615 // references in Appliance::Data.mapDisks
616 bool fEmpty; //true - empty disk, e.g. the component <rasd:HostResource>...</rasd:HostResource> is absent.
617};
618
619typedef std::map<RTCString, VirtualDisk> VirtualDisksMap;
620
621/**
622 * A list of EthernetAdapters is contained in VirtualSystem, representing the
623 * ethernet adapters in the virtual system.
624 */
625struct EthernetAdapter
626{
627 RTCString strAdapterType; // "PCNet32" or "E1000" or whatever; from <rasd:ResourceSubType>
628 RTCString strNetworkName; // from <rasd:Connection>
629};
630
631typedef std::list<EthernetAdapter> EthernetAdaptersList;
632
633/**
634 * A list of VirtualSystem structs is created by OVFReader::read(). Each refers to
635 * a \<VirtualSystem\> block in the OVF file.
636 */
637struct VirtualSystem
638{
639 RTCString strName; // copy of VirtualSystem/@id
640
641 RTCString strDescription; // copy of VirtualSystem/AnnotationSection content, if any
642
643 CIMOSType_T cimos;
644 RTCString strCimosDesc; // readable description of the cimos type in the case of cimos = 0/1/102
645 RTCString strTypeVBox; // optional type from @vbox:ostype attribute (VirtualBox 4.0 or higher)
646
647 RTCString strVirtualSystemType; // generic hardware description; OVF says this can be something like "vmx-4" or "xen";
648 // VMware Workstation 6.5 is "vmx-07"
649
650 HardwareItemVector vecHardwareItems; //< vector containing all virtual hardware items in parsing order.
651
652 uint64_t ullMemorySize; // always in bytes, copied from llHardwareItems; default = 0 (unspecified)
653 uint16_t cCPUs; // no. of CPUs, copied from llHardwareItems; default = 1
654
655 EthernetAdaptersList llEthernetAdapters; // (one for each VirtualSystem/Item[@ResourceType=10]element)
656
657 ControllersMap mapControllers;
658 // list of hard disk controllers
659 // (one for each VirtualSystem/Item[@ResourceType=6] element with accumulated data from children)
660
661 VirtualDisksMap mapVirtualDisks;
662 // (one for each VirtualSystem/Item[@ResourceType=17] element with accumulated data from children)
663
664 bool fHasFloppyDrive; // true if there's a floppy item in mapHardwareItems
665 bool fHasCdromDrive; // true if there's a CD-ROM item in mapHardwareItems; ISO images are not yet supported by OVFtool
666 bool fHasUsbController; // true if there's a USB controller item in mapHardwareItems
667
668 RTCString strSoundCardType; // if not empty, then the system wants a soundcard; this then specifies the hardware;
669 // VMware Workstation 6.5 uses "ensoniq1371" for example
670
671 RTCString strLicenseText; // license info if any; receives contents of VirtualSystem/EulaSection/License
672
673 RTCString strProduct; // product info if any; receives contents of VirtualSystem/ProductSection/Product
674 RTCString strVendor; // product info if any; receives contents of VirtualSystem/ProductSection/Vendor
675 RTCString strVersion; // product info if any; receives contents of VirtualSystem/ProductSection/Version
676 RTCString strProductUrl; // product info if any; receives contents of VirtualSystem/ProductSection/ProductUrl
677 RTCString strVendorUrl; // product info if any; receives contents of VirtualSystem/ProductSection/VendorUrl
678
679 const xml::ElementNode *pelmVBoxMachine; // pointer to <vbox:Machine> element under <VirtualSystem> element or NULL if not present
680
681 VirtualSystem()
682 : cimos(CIMOSType_CIMOS_Unknown)
683 , ullMemorySize(0)
684 , cCPUs(1)
685 , fHasFloppyDrive(false)
686 , fHasCdromDrive(false)
687 , fHasUsbController(false)
688 , pelmVBoxMachine(NULL)
689 {
690 }
691
692#if RT_CPLUSPLUS_PREREQ(201100) /* VC2022: Excplit default copy constructor and copy assignment operator to avoid warnings. */
693 /* Note! HardwareItemVector only allow copying if it's empty. */
694 VirtualSystem(VirtualSystem const &) = default;
695 VirtualSystem &operator=(VirtualSystem const &) = delete;
696#endif
697};
698
699////////////////////////////////////////////////////////////////////////////////
700//
701// Class OVFReader
702//
703////////////////////////////////////////////////////////////////////////////////
704
705/**
706 * OVFReader attempts to open, read in and parse an OVF XML file. This is all done
707 * in the constructor; if there is any kind of error in the file -- filesystem error
708 * from IPRT, XML parsing errors from libxml, or OVF logical errors --, exceptions
709 * are thrown. These are all based on xml::Error.
710 *
711 * Hence, use this class as follows:
712<code>
713 OVFReader *pReader = NULL;
714 try
715 {
716 pReader = new("/path/to/file.ovf");
717 }
718 catch (xml::Error &e)
719 {
720 printf("A terrible thing happened: %s", e.what());
721 }
722 // now go look at pReader->m_llVirtualSystem and what's in there
723 if (pReader)
724 delete pReader;
725</code>
726 */
727class OVFReader
728{
729public:
730 OVFReader();
731 OVFReader(const void *pvBuf, size_t cbSize, const RTCString &path);
732 OVFReader(const RTCString &path);
733
734 // Data fields
735 EnvelopeData m_envelopeData; //data of root element "Envelope"
736 RTCString m_strPath; // file name given to constructor
737 DiskImagesMap m_mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId
738 std::list<VirtualSystem> m_llVirtualSystems; // list of virtual systems, created by and valid after read()
739
740private:
741 xml::Document m_doc;
742
743 void parse();
744 void LoopThruSections(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pCurElem);
745 void HandleDiskSection(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pSectionElem);
746 void HandleNetworkSection(const xml::ElementNode *pSectionElem);
747 void HandleVirtualSystemContent(const xml::ElementNode *pContentElem);
748};
749
750} // end namespace ovf
751
752#endif /* !MAIN_INCLUDED_ovfreader_h */
753
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