VirtualBox

source: vbox/trunk/include/VBox/settings.h@ 55461

Last change on this file since 55461 was 54948, checked in by vboxsync, 10 years ago

Main/Medium+Snapshot: make all code recursing over trees (objects containing lists of child objects) use as little stack as possible, and establish safe depth limits to avoid crashes, plus related cleanups in related code areas

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 44.3 KB
Line 
1/** @file
2 * Settings file data structures.
3 *
4 * These structures are created by the settings file loader and filled with values
5 * copied from the raw XML data. This was all new with VirtualBox 3.1 and allows us
6 * to finally make the XML reader version-independent and read VirtualBox XML files
7 * from earlier and even newer (future) versions without requiring complicated,
8 * tedious and error-prone XSLT conversions.
9 *
10 * It is this file that defines all structures that map VirtualBox global and
11 * machine settings to XML files. These structures are used by the rest of Main,
12 * even though this header file does not require anything else in Main.
13 *
14 * Note: Headers in Main code have been tweaked to only declare the structures
15 * defined here so that this header need only be included from code files that
16 * actually use these structures.
17 */
18
19/*
20 * Copyright (C) 2007-2015 Oracle Corporation
21 *
22 * This file is part of VirtualBox Open Source Edition (OSE), as
23 * available from http://www.virtualbox.org. This file is free software;
24 * you can redistribute it and/or modify it under the terms of the GNU
25 * General Public License (GPL) as published by the Free Software
26 * Foundation, in version 2 as it comes in the "COPYING" file of the
27 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
28 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
29 *
30 * The contents of this file may alternatively be used under the terms
31 * of the Common Development and Distribution License Version 1.0
32 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
33 * VirtualBox OSE distribution, in which case the provisions of the
34 * CDDL are applicable instead of those of the GPL.
35 *
36 * You may elect to license modified versions of this file under the
37 * terms and conditions of either the GPL or the CDDL or both.
38 */
39
40#ifndef ___VBox_settings_h
41#define ___VBox_settings_h
42
43#include <iprt/time.h>
44
45#include "VBox/com/VirtualBox.h"
46
47#include <VBox/com/Guid.h>
48#include <VBox/com/string.h>
49
50#include <list>
51#include <map>
52
53/**
54 * Maximum depth of a medium tree, to prevent stack overflows.
55 * XPCOM has a relatively low stack size for its workers, and we have
56 * to avoid crashes due to exceeding the limit both on reading and
57 * writing config files.
58 */
59#define SETTINGS_MEDIUM_DEPTH_MAX 300
60
61/**
62 * Maximum depth of the snapshot tree, to prevent stack overflows.
63 * XPCOM has a relatively low stack size for its workers, and we have
64 * to avoid crashes due to exceeding the limit both on reading and
65 * writing config files. The bottleneck is reading config files with
66 * deep snapshot nesting, as libxml2 needs quite some stack space,
67 * so with the current stack size the margin isn't big.
68 */
69#define SETTINGS_SNAPSHOT_DEPTH_MAX 250
70
71namespace xml
72{
73 class ElementNode;
74}
75
76namespace settings
77{
78
79class ConfigFileError;
80
81////////////////////////////////////////////////////////////////////////////////
82//
83// Structures shared between Machine XML and VirtualBox.xml
84//
85////////////////////////////////////////////////////////////////////////////////
86
87/**
88 * USB device filter definition. This struct is used both in MainConfigFile
89 * (for global USB filters) and MachineConfigFile (for machine filters).
90 *
91 * NOTE: If you add any fields in here, you must update a) the constructor and b)
92 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
93 * your settings might never get saved.
94 */
95struct USBDeviceFilter
96{
97 USBDeviceFilter()
98 : fActive(false),
99 action(USBDeviceFilterAction_Null),
100 ulMaskedInterfaces(0)
101 {}
102
103 bool operator==(const USBDeviceFilter&u) const;
104
105 com::Utf8Str strName;
106 bool fActive;
107 com::Utf8Str strVendorId,
108 strProductId,
109 strRevision,
110 strManufacturer,
111 strProduct,
112 strSerialNumber,
113 strPort;
114 USBDeviceFilterAction_T action; // only used with host USB filters
115 com::Utf8Str strRemote; // irrelevant for host USB objects
116 uint32_t ulMaskedInterfaces; // irrelevant for host USB objects
117};
118
119typedef std::map<com::Utf8Str, com::Utf8Str> StringsMap;
120typedef std::list<com::Utf8Str> StringsList;
121
122// ExtraDataItem (used by both VirtualBox.xml and machines XML)
123struct USBDeviceFilter;
124typedef std::list<USBDeviceFilter> USBDeviceFiltersList;
125
126struct Medium;
127typedef std::list<Medium> MediaList;
128
129/**
130 * NOTE: If you add any fields in here, you must update a) the constructor and b)
131 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
132 * your settings might never get saved.
133 */
134struct Medium
135{
136 Medium()
137 : fAutoReset(false),
138 hdType(MediumType_Normal)
139 {}
140
141 com::Guid uuid;
142 com::Utf8Str strLocation;
143 com::Utf8Str strDescription;
144
145 // the following are for hard disks only:
146 com::Utf8Str strFormat;
147 bool fAutoReset; // optional, only for diffs, default is false
148 StringsMap properties;
149 MediumType_T hdType;
150
151 MediaList llChildren; // only used with hard disks
152
153 bool operator==(const Medium &m) const;
154};
155
156extern const struct Medium g_MediumEmpty;
157
158/**
159 * A media registry. Starting with VirtualBox 3.3, this can appear in both the
160 * VirtualBox.xml file as well as machine XML files with settings version 1.11
161 * or higher, so these lists are now in ConfigFileBase.
162 *
163 * NOTE: If you add any fields in here, you must update a) the constructor and b)
164 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
165 * your settings might never get saved.
166 */
167struct MediaRegistry
168{
169 MediaList llHardDisks,
170 llDvdImages,
171 llFloppyImages;
172
173 bool operator==(const MediaRegistry &m) const;
174};
175
176/**
177 *
178 */
179struct NATRule
180{
181 NATRule()
182 : proto(NATProtocol_TCP),
183 u16HostPort(0),
184 u16GuestPort(0)
185 {}
186
187 bool operator==(const NATRule &r) const
188 {
189 return strName == r.strName
190 && proto == r.proto
191 && u16HostPort == r.u16HostPort
192 && strHostIP == r.strHostIP
193 && u16GuestPort == r.u16GuestPort
194 && strGuestIP == r.strGuestIP;
195 }
196
197 com::Utf8Str strName;
198 NATProtocol_T proto;
199 uint16_t u16HostPort;
200 com::Utf8Str strHostIP;
201 uint16_t u16GuestPort;
202 com::Utf8Str strGuestIP;
203};
204typedef std::list<NATRule> NATRuleList;
205
206
207struct NATHostLoopbackOffset
208{
209 /** Note: 128/8 is only acceptable */
210 com::Utf8Str strLoopbackHostAddress;
211 uint32_t u32Offset;
212 bool operator == (const com::Utf8Str& strAddr)
213 {
214 return (strLoopbackHostAddress == strAddr);
215 }
216
217 bool operator == (uint32_t off)
218 {
219 return (this->u32Offset == off);
220 }
221};
222typedef std::list<NATHostLoopbackOffset> NATLoopbackOffsetList;
223
224/**
225 * Common base class for both MainConfigFile and MachineConfigFile
226 * which contains some common logic for both.
227 */
228class ConfigFileBase
229{
230public:
231 bool fileExists();
232
233 void copyBaseFrom(const ConfigFileBase &b);
234
235protected:
236 ConfigFileBase(const com::Utf8Str *pstrFilename);
237 /* Note: this copy constructor doesn't create a full copy of other, cause
238 * the file based stuff (xml doc) could not be copied. */
239 ConfigFileBase(const ConfigFileBase &other);
240
241 ~ConfigFileBase();
242
243 typedef enum {Error, HardDisk, DVDImage, FloppyImage} MediaType;
244
245 static const char *stringifyMediaType(MediaType t);
246 void parseUUID(com::Guid &guid,
247 const com::Utf8Str &strUUID) const;
248 void parseTimestamp(RTTIMESPEC &timestamp,
249 const com::Utf8Str &str) const;
250 com::Utf8Str stringifyTimestamp(const RTTIMESPEC &tm) const;
251
252 void readExtraData(const xml::ElementNode &elmExtraData,
253 StringsMap &map);
254 void readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
255 USBDeviceFiltersList &ll);
256 void readMediumOne(MediaType t, const xml::ElementNode &elmMedium, Medium &med);
257 void readMedium(MediaType t, uint32_t depth, const xml::ElementNode &elmMedium, Medium &med);
258 void readMediaRegistry(const xml::ElementNode &elmMediaRegistry, MediaRegistry &mr);
259 void readNATForwardRuleList(const xml::ElementNode &elmParent, NATRuleList &llRules);
260 void readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopBacks);
261
262 void setVersionAttribute(xml::ElementNode &elm);
263 void createStubDocument();
264
265 void buildExtraData(xml::ElementNode &elmParent, const StringsMap &me);
266 void buildUSBDeviceFilters(xml::ElementNode &elmParent,
267 const USBDeviceFiltersList &ll,
268 bool fHostMode);
269 void buildMedium(MediaType t,
270 uint32_t depth,
271 xml::ElementNode &elmMedium,
272 const Medium &mdm);
273 void buildMediaRegistry(xml::ElementNode &elmParent,
274 const MediaRegistry &mr);
275 void buildNATForwardRuleList(xml::ElementNode &elmParent, const NATRuleList &natRuleList);
276 void buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackList);
277 void clearDocument();
278
279 struct Data;
280 Data *m;
281
282 friend class ConfigFileError;
283};
284
285////////////////////////////////////////////////////////////////////////////////
286//
287// VirtualBox.xml structures
288//
289////////////////////////////////////////////////////////////////////////////////
290
291struct Host
292{
293 USBDeviceFiltersList llUSBDeviceFilters;
294};
295
296struct SystemProperties
297{
298 SystemProperties()
299 : ulLogHistoryCount(3)
300#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
301 , fExclusiveHwVirt(false)
302#else
303 , fExclusiveHwVirt(true)
304#endif
305 {}
306
307 com::Utf8Str strDefaultMachineFolder;
308 com::Utf8Str strDefaultHardDiskFolder;
309 com::Utf8Str strDefaultHardDiskFormat;
310 com::Utf8Str strVRDEAuthLibrary;
311 com::Utf8Str strWebServiceAuthLibrary;
312 com::Utf8Str strDefaultVRDEExtPack;
313 com::Utf8Str strAutostartDatabasePath;
314 com::Utf8Str strDefaultAdditionsISO;
315 com::Utf8Str strDefaultFrontend;
316 com::Utf8Str strLoggingLevel;
317 uint32_t ulLogHistoryCount;
318 bool fExclusiveHwVirt;
319};
320
321struct MachineRegistryEntry
322{
323 com::Guid uuid;
324 com::Utf8Str strSettingsFile;
325};
326typedef std::list<MachineRegistryEntry> MachinesRegistry;
327
328struct DhcpOptValue
329{
330 enum Encoding {
331 LEGACY = DhcpOptEncoding_Legacy,
332 HEX = DhcpOptEncoding_Hex
333 };
334
335 com::Utf8Str text;
336 Encoding encoding;
337
338 DhcpOptValue()
339 : text(), encoding(LEGACY) {}
340
341 DhcpOptValue(const com::Utf8Str &aText, Encoding aEncoding = LEGACY)
342 : text(aText), encoding(aEncoding) {}
343};
344
345typedef std::map<DhcpOpt_T, DhcpOptValue> DhcpOptionMap;
346typedef DhcpOptionMap::value_type DhcpOptValuePair;
347typedef DhcpOptionMap::iterator DhcpOptIterator;
348typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
349
350typedef struct VmNameSlotKey
351{
352 VmNameSlotKey(const com::Utf8Str& aVmName, LONG aSlot): VmName(aVmName),
353 Slot(aSlot){}
354 const com::Utf8Str VmName;
355 LONG Slot;
356 bool operator< (const VmNameSlotKey& that) const
357 {
358 if (VmName == that.VmName)
359 return Slot < that.Slot;
360 else return VmName < that.VmName;
361 }
362} VmNameSlotKey;
363typedef std::map<VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap;
364typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair;
365typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator;
366typedef VmSlot2OptionsMap::const_iterator VmSlot2OptionsConstIterator;
367
368struct DHCPServer
369{
370 DHCPServer()
371 : fEnabled(false)
372 {}
373
374 com::Utf8Str strNetworkName,
375 strIPAddress,
376 strIPLower,
377 strIPUpper;
378 bool fEnabled;
379 DhcpOptionMap GlobalDhcpOptions;
380 VmSlot2OptionsMap VmSlot2OptionsM;
381};
382typedef std::list<DHCPServer> DHCPServersList;
383
384
385/**
386 * Nat Networking settings (NAT service).
387 */
388struct NATNetwork
389{
390 com::Utf8Str strNetworkName;
391 bool fEnabled;
392 com::Utf8Str strNetwork;
393 bool fIPv6;
394 com::Utf8Str strIPv6Prefix;
395 uint32_t u32HostLoopback6Offset;
396 NATLoopbackOffsetList llHostLoopbackOffsetList;
397 bool fAdvertiseDefaultIPv6Route;
398 bool fNeedDhcpServer;
399 NATRuleList llPortForwardRules4;
400 NATRuleList llPortForwardRules6;
401 NATNetwork():fEnabled(true),
402 fAdvertiseDefaultIPv6Route(false),
403 fNeedDhcpServer(true)
404 {}
405 bool operator==(const NATNetwork &n) const
406 {
407 return strNetworkName == n.strNetworkName
408 && strNetwork == n.strNetwork;
409 }
410
411};
412typedef std::list<NATNetwork> NATNetworksList;
413
414
415class MainConfigFile : public ConfigFileBase
416{
417public:
418 MainConfigFile(const com::Utf8Str *pstrFilename);
419
420 void readMachineRegistry(const xml::ElementNode &elmMachineRegistry);
421 void readDHCPServers(const xml::ElementNode &elmDHCPServers);
422 void readDhcpOptions(DhcpOptionMap& map, const xml::ElementNode& options);
423 void readNATNetworks(const xml::ElementNode &elmNATNetworks);
424
425 void write(const com::Utf8Str strFilename);
426
427 Host host;
428 SystemProperties systemProperties;
429 MediaRegistry mediaRegistry;
430 MachinesRegistry llMachines;
431 DHCPServersList llDhcpServers;
432 NATNetworksList llNATNetworks;
433 StringsMap mapExtraDataItems;
434
435private:
436 void bumpSettingsVersionIfNeeded();
437};
438
439////////////////////////////////////////////////////////////////////////////////
440//
441// Machine XML structures
442//
443////////////////////////////////////////////////////////////////////////////////
444
445/**
446 * NOTE: If you add any fields in here, you must update a) the constructor and b)
447 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
448 * your settings might never get saved.
449 */
450struct VRDESettings
451{
452 VRDESettings()
453 : fEnabled(true),
454 authType(AuthType_Null),
455 ulAuthTimeout(5000),
456 fAllowMultiConnection(false),
457 fReuseSingleConnection(false)
458 {}
459
460 bool operator==(const VRDESettings& v) const;
461
462 bool fEnabled;
463 AuthType_T authType;
464 uint32_t ulAuthTimeout;
465 com::Utf8Str strAuthLibrary;
466 bool fAllowMultiConnection,
467 fReuseSingleConnection;
468 com::Utf8Str strVrdeExtPack;
469 StringsMap mapProperties;
470};
471
472/**
473 * NOTE: If you add any fields in here, you must update a) the constructor and b)
474 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
475 * your settings might never get saved.
476 */
477struct BIOSSettings
478{
479 BIOSSettings()
480 : fACPIEnabled(true),
481 fIOAPICEnabled(false),
482 fLogoFadeIn(true),
483 fLogoFadeOut(true),
484 ulLogoDisplayTime(0),
485 biosBootMenuMode(BIOSBootMenuMode_MessageAndMenu),
486 fPXEDebugEnabled(false),
487 llTimeOffset(0)
488 {}
489
490 bool operator==(const BIOSSettings &d) const;
491
492 bool fACPIEnabled,
493 fIOAPICEnabled,
494 fLogoFadeIn,
495 fLogoFadeOut;
496 uint32_t ulLogoDisplayTime;
497 com::Utf8Str strLogoImagePath;
498 BIOSBootMenuMode_T biosBootMenuMode;
499 bool fPXEDebugEnabled;
500 int64_t llTimeOffset;
501};
502
503/**
504 * NOTE: If you add any fields in here, you must update a) the constructor and b)
505 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
506 * your settings might never get saved.
507 */
508struct USBController
509{
510 USBController()
511 : enmType(USBControllerType_Null)
512 {}
513
514 bool operator==(const USBController &u) const;
515
516 com::Utf8Str strName;
517 USBControllerType_T enmType;
518};
519typedef std::list<USBController> USBControllerList;
520
521struct USB
522{
523 USB() {}
524
525 bool operator==(const USB &u) const;
526
527 /** List of USB controllers present. */
528 USBControllerList llUSBControllers;
529 /** List of USB device filters. */
530 USBDeviceFiltersList llDeviceFilters;
531};
532
533 struct NAT
534 {
535 NAT()
536 : u32Mtu(0),
537 u32SockRcv(0),
538 u32SockSnd(0),
539 u32TcpRcv(0),
540 u32TcpSnd(0),
541 fDNSPassDomain(true), /* historically this value is true */
542 fDNSProxy(false),
543 fDNSUseHostResolver(false),
544 fAliasLog(false),
545 fAliasProxyOnly(false),
546 fAliasUseSamePorts(false)
547 {}
548
549 bool operator==(const NAT &n) const
550 {
551 return strNetwork == n.strNetwork
552 && strBindIP == n.strBindIP
553 && u32Mtu == n.u32Mtu
554 && u32SockRcv == n.u32SockRcv
555 && u32SockSnd == n.u32SockSnd
556 && u32TcpSnd == n.u32TcpSnd
557 && u32TcpRcv == n.u32TcpRcv
558 && strTFTPPrefix == n.strTFTPPrefix
559 && strTFTPBootFile == n.strTFTPBootFile
560 && strTFTPNextServer == n.strTFTPNextServer
561 && fDNSPassDomain == n.fDNSPassDomain
562 && fDNSProxy == n.fDNSProxy
563 && fDNSUseHostResolver == n.fDNSUseHostResolver
564 && fAliasLog == n.fAliasLog
565 && fAliasProxyOnly == n.fAliasProxyOnly
566 && fAliasUseSamePorts == n.fAliasUseSamePorts
567 && llRules == n.llRules;
568 }
569
570 com::Utf8Str strNetwork;
571 com::Utf8Str strBindIP;
572 uint32_t u32Mtu;
573 uint32_t u32SockRcv;
574 uint32_t u32SockSnd;
575 uint32_t u32TcpRcv;
576 uint32_t u32TcpSnd;
577 com::Utf8Str strTFTPPrefix;
578 com::Utf8Str strTFTPBootFile;
579 com::Utf8Str strTFTPNextServer;
580 bool fDNSPassDomain;
581 bool fDNSProxy;
582 bool fDNSUseHostResolver;
583 bool fAliasLog;
584 bool fAliasProxyOnly;
585 bool fAliasUseSamePorts;
586 NATRuleList llRules;
587 };
588
589/**
590 * NOTE: If you add any fields in here, you must update a) the constructor and b)
591 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
592 * your settings might never get saved.
593 */
594struct NetworkAdapter
595{
596 NetworkAdapter()
597 : ulSlot(0),
598 type(NetworkAdapterType_Am79C970A),
599 fEnabled(false),
600 fCableConnected(false),
601 ulLineSpeed(0),
602 enmPromiscModePolicy(NetworkAdapterPromiscModePolicy_Deny),
603 fTraceEnabled(false),
604 mode(NetworkAttachmentType_Null),
605 ulBootPriority(0)
606 {}
607
608 bool operator==(const NetworkAdapter &n) const;
609
610 uint32_t ulSlot;
611
612 NetworkAdapterType_T type;
613 bool fEnabled;
614 com::Utf8Str strMACAddress;
615 bool fCableConnected;
616 uint32_t ulLineSpeed;
617 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
618 bool fTraceEnabled;
619 com::Utf8Str strTraceFile;
620
621 NetworkAttachmentType_T mode;
622 NAT nat;
623 com::Utf8Str strBridgedName;
624 com::Utf8Str strHostOnlyName;
625 com::Utf8Str strInternalNetworkName;
626 com::Utf8Str strGenericDriver;
627 StringsMap genericProperties;
628 com::Utf8Str strNATNetworkName;
629 uint32_t ulBootPriority;
630 com::Utf8Str strBandwidthGroup; // requires settings version 1.13 (VirtualBox 4.2)
631};
632typedef std::list<NetworkAdapter> NetworkAdaptersList;
633
634/**
635 * NOTE: If you add any fields in here, you must update a) the constructor and b)
636 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
637 * your settings might never get saved.
638 */
639struct SerialPort
640{
641 SerialPort()
642 : ulSlot(0),
643 fEnabled(false),
644 ulIOBase(0x3f8),
645 ulIRQ(4),
646 portMode(PortMode_Disconnected),
647 fServer(false)
648 {}
649
650 bool operator==(const SerialPort &n) const;
651
652 uint32_t ulSlot;
653
654 bool fEnabled;
655 uint32_t ulIOBase;
656 uint32_t ulIRQ;
657 PortMode_T portMode;
658 com::Utf8Str strPath;
659 bool fServer;
660};
661typedef std::list<SerialPort> SerialPortsList;
662
663/**
664 * NOTE: If you add any fields in here, you must update a) the constructor and b)
665 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
666 * your settings might never get saved.
667 */
668struct ParallelPort
669{
670 ParallelPort()
671 : ulSlot(0),
672 fEnabled(false),
673 ulIOBase(0x378),
674 ulIRQ(7)
675 {}
676
677 bool operator==(const ParallelPort &d) const;
678
679 uint32_t ulSlot;
680
681 bool fEnabled;
682 uint32_t ulIOBase;
683 uint32_t ulIRQ;
684 com::Utf8Str strPath;
685};
686typedef std::list<ParallelPort> ParallelPortsList;
687
688/**
689 * NOTE: If you add any fields in here, you must update a) the constructor and b)
690 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
691 * your settings might never get saved.
692 */
693struct AudioAdapter
694{
695 AudioAdapter()
696 : fEnabled(true),
697 controllerType(AudioControllerType_AC97),
698 driverType(AudioDriverType_Null)
699 {}
700
701 bool operator==(const AudioAdapter &a) const
702 {
703 return (this == &a)
704 || ( (fEnabled == a.fEnabled)
705 && (controllerType == a.controllerType)
706 && (driverType == a.driverType)
707 );
708 }
709
710 bool fEnabled;
711 AudioControllerType_T controllerType;
712 AudioDriverType_T driverType;
713};
714
715/**
716 * NOTE: If you add any fields in here, you must update a) the constructor and b)
717 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
718 * your settings might never get saved.
719 */
720struct SharedFolder
721{
722 SharedFolder()
723 : fWritable(false)
724 , fAutoMount(false)
725 {}
726
727 bool operator==(const SharedFolder &a) const;
728
729 com::Utf8Str strName,
730 strHostPath;
731 bool fWritable;
732 bool fAutoMount;
733};
734typedef std::list<SharedFolder> SharedFoldersList;
735
736/**
737 * NOTE: If you add any fields in here, you must update a) the constructor and b)
738 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
739 * your settings might never get saved.
740 */
741struct GuestProperty
742{
743 GuestProperty()
744 : timestamp(0)
745 {};
746
747 bool operator==(const GuestProperty &g) const;
748
749 com::Utf8Str strName,
750 strValue;
751 uint64_t timestamp;
752 com::Utf8Str strFlags;
753};
754typedef std::list<GuestProperty> GuestPropertiesList;
755
756typedef std::map<uint32_t, DeviceType_T> BootOrderMap;
757
758/**
759 * NOTE: If you add any fields in here, you must update a) the constructor and b)
760 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
761 * your settings might never get saved.
762 */
763struct CpuIdLeaf
764{
765 CpuIdLeaf()
766 : ulId(UINT32_MAX),
767 ulEax(0),
768 ulEbx(0),
769 ulEcx(0),
770 ulEdx(0)
771 {}
772
773 bool operator==(const CpuIdLeaf &c) const
774 {
775 return ( (this == &c)
776 || ( (ulId == c.ulId)
777 && (ulEax == c.ulEax)
778 && (ulEbx == c.ulEbx)
779 && (ulEcx == c.ulEcx)
780 && (ulEdx == c.ulEdx)
781 )
782 );
783 }
784
785 uint32_t ulId;
786 uint32_t ulEax;
787 uint32_t ulEbx;
788 uint32_t ulEcx;
789 uint32_t ulEdx;
790};
791typedef std::list<CpuIdLeaf> CpuIdLeafsList;
792
793/**
794 * NOTE: If you add any fields in here, you must update a) the constructor and b)
795 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
796 * your settings might never get saved.
797 */
798struct Cpu
799{
800 Cpu()
801 : ulId(UINT32_MAX)
802 {}
803
804 bool operator==(const Cpu &c) const
805 {
806 return (ulId == c.ulId);
807 }
808
809 uint32_t ulId;
810};
811typedef std::list<Cpu> CpuList;
812
813/**
814 * NOTE: If you add any fields in here, you must update a) the constructor and b)
815 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
816 * your settings might never get saved.
817 */
818struct BandwidthGroup
819{
820 BandwidthGroup()
821 : cMaxBytesPerSec(0),
822 enmType(BandwidthGroupType_Null)
823 {}
824
825 bool operator==(const BandwidthGroup &i) const
826 {
827 return ( (strName == i.strName)
828 && (cMaxBytesPerSec == i.cMaxBytesPerSec)
829 && (enmType == i.enmType));
830 }
831
832 com::Utf8Str strName;
833 uint64_t cMaxBytesPerSec;
834 BandwidthGroupType_T enmType;
835};
836typedef std::list<BandwidthGroup> BandwidthGroupList;
837
838/**
839 * NOTE: If you add any fields in here, you must update a) the constructor and b)
840 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
841 * your settings might never get saved.
842 */
843struct IOSettings
844{
845 IOSettings();
846
847 bool operator==(const IOSettings &i) const
848 {
849 return ( (fIOCacheEnabled == i.fIOCacheEnabled)
850 && (ulIOCacheSize == i.ulIOCacheSize)
851 && (llBandwidthGroups == i.llBandwidthGroups));
852 }
853
854 bool fIOCacheEnabled;
855 uint32_t ulIOCacheSize;
856 BandwidthGroupList llBandwidthGroups;
857};
858
859/**
860 * NOTE: If you add any fields in here, you must update a) the constructor and b)
861 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
862 * your settings might never get saved.
863 */
864struct HostPCIDeviceAttachment
865{
866 HostPCIDeviceAttachment()
867 : uHostAddress(0),
868 uGuestAddress(0)
869 {}
870
871 bool operator==(const HostPCIDeviceAttachment &a) const
872 {
873 return ( (uHostAddress == a.uHostAddress)
874 && (uGuestAddress == a.uGuestAddress)
875 && (strDeviceName == a.strDeviceName)
876 );
877 }
878
879 com::Utf8Str strDeviceName;
880 uint32_t uHostAddress;
881 uint32_t uGuestAddress;
882};
883typedef std::list<HostPCIDeviceAttachment> HostPCIDeviceAttachmentList;
884
885/**
886 * Representation of Machine hardware; this is used in the MachineConfigFile.hardwareMachine
887 * field.
888 *
889 * NOTE: If you add any fields in here, you must update a) the constructor and b)
890 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
891 * your settings might never get saved.
892 */
893struct Hardware
894{
895 Hardware();
896
897 bool operator==(const Hardware&) const;
898
899 bool areParavirtDefaultSettings() const
900 {
901 return paravirtProvider == ParavirtProvider_Legacy;
902 }
903
904 com::Utf8Str strVersion; // hardware version, optional
905 com::Guid uuid; // hardware uuid, optional (null).
906
907 bool fHardwareVirt,
908 fNestedPaging,
909 fLargePages,
910 fVPID,
911 fUnrestrictedExecution,
912 fHardwareVirtForce,
913 fSyntheticCpu,
914 fTripleFaultReset,
915 fPAE;
916 typedef enum LongModeType { LongMode_Enabled, LongMode_Disabled, LongMode_Legacy } LongModeType;
917 LongModeType enmLongMode;
918 uint32_t cCPUs;
919 bool fCpuHotPlug; // requires settings version 1.10 (VirtualBox 3.2)
920 CpuList llCpus; // requires settings version 1.10 (VirtualBox 3.2)
921 bool fHPETEnabled; // requires settings version 1.10 (VirtualBox 3.2)
922 uint32_t ulCpuExecutionCap; // requires settings version 1.11 (VirtualBox 3.3)
923
924 CpuIdLeafsList llCpuIdLeafs;
925
926 uint32_t ulMemorySizeMB;
927
928 BootOrderMap mapBootOrder; // item 0 has highest priority
929
930 GraphicsControllerType_T graphicsControllerType;
931 uint32_t ulVRAMSizeMB;
932 uint32_t cMonitors;
933 bool fAccelerate3D,
934 fAccelerate2DVideo; // requires settings version 1.8 (VirtualBox 3.1)
935
936 uint32_t ulVideoCaptureHorzRes; // requires settings version 1.14 (VirtualBox 4.3)
937 uint32_t ulVideoCaptureVertRes; // requires settings version 1.14 (VirtualBox 4.3)
938 uint32_t ulVideoCaptureRate; // requires settings version 1.14 (VirtualBox 4.3)
939 uint32_t ulVideoCaptureFPS; // requires settings version 1.14 (VirtualBox 4.3)
940 uint32_t ulVideoCaptureMaxTime; // requires settings version 1.14 (VirtualBox 4.3)
941 uint32_t ulVideoCaptureMaxSize; // requires settings version 1.14 (VirtualBox 4.3)
942 bool fVideoCaptureEnabled; // requires settings version 1.14 (VirtualBox 4.3)
943 uint64_t u64VideoCaptureScreens; // requires settings version 1.14 (VirtualBox 4.3)
944 com::Utf8Str strVideoCaptureFile; // requires settings version 1.14 (VirtualBox 4.3)
945
946 FirmwareType_T firmwareType; // requires settings version 1.9 (VirtualBox 3.1)
947
948 PointingHIDType_T pointingHIDType; // requires settings version 1.10 (VirtualBox 3.2)
949 KeyboardHIDType_T keyboardHIDType; // requires settings version 1.10 (VirtualBox 3.2)
950
951 ChipsetType_T chipsetType; // requires settings version 1.11 (VirtualBox 4.0)
952 ParavirtProvider_T paravirtProvider; // requires settings version 1.15 (VirtualBox 4.4)
953
954 bool fEmulatedUSBCardReader; // 1.12 (VirtualBox 4.1)
955
956 VRDESettings vrdeSettings;
957
958 BIOSSettings biosSettings;
959 USB usbSettings;
960 NetworkAdaptersList llNetworkAdapters;
961 SerialPortsList llSerialPorts;
962 ParallelPortsList llParallelPorts;
963 AudioAdapter audioAdapter;
964
965 // technically these two have no business in the hardware section, but for some
966 // clever reason <Hardware> is where they are in the XML....
967 SharedFoldersList llSharedFolders;
968 ClipboardMode_T clipboardMode;
969 DnDMode_T dndMode;
970
971 uint32_t ulMemoryBalloonSize;
972 bool fPageFusionEnabled;
973
974 GuestPropertiesList llGuestProperties;
975 com::Utf8Str strNotificationPatterns;
976
977 IOSettings ioSettings; // requires settings version 1.10 (VirtualBox 3.2)
978 HostPCIDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
979
980 com::Utf8Str strDefaultFrontend; // requires settings version 1.14 (VirtualBox 4.3)
981};
982
983/**
984 * A device attached to a storage controller. This can either be a
985 * hard disk or a DVD drive or a floppy drive and also specifies
986 * which medium is "in" the drive; as a result, this is a combination
987 * of the Main IMedium and IMediumAttachment interfaces.
988 *
989 * NOTE: If you add any fields in here, you must update a) the constructor and b)
990 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
991 * your settings might never get saved.
992 */
993struct AttachedDevice
994{
995 AttachedDevice()
996 : deviceType(DeviceType_Null),
997 fPassThrough(false),
998 fTempEject(false),
999 fNonRotational(false),
1000 fDiscard(false),
1001 fHotPluggable(false),
1002 lPort(0),
1003 lDevice(0)
1004 {}
1005
1006 bool operator==(const AttachedDevice &a) const;
1007
1008 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
1009
1010 // DVDs can be in pass-through mode:
1011 bool fPassThrough;
1012
1013 // Whether guest-triggered eject of DVDs will keep the medium in the
1014 // VM config or not:
1015 bool fTempEject;
1016
1017 // Whether the medium is non-rotational:
1018 bool fNonRotational;
1019
1020 // Whether the medium supports discarding unused blocks:
1021 bool fDiscard;
1022
1023 // Whether the medium is hot-pluggable:
1024 bool fHotPluggable;
1025
1026 int32_t lPort;
1027 int32_t lDevice;
1028
1029 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
1030 // this is its UUID; it depends on deviceType which media registry this then needs to
1031 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
1032 com::Guid uuid;
1033
1034 // for DVDs and floppies, the attachment can also be a host device:
1035 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
1036
1037 // Bandwidth group the device is attached to.
1038 com::Utf8Str strBwGroup;
1039};
1040typedef std::list<AttachedDevice> AttachedDevicesList;
1041
1042/**
1043 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1044 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1045 * your settings might never get saved.
1046 */
1047struct StorageController
1048{
1049 StorageController()
1050 : storageBus(StorageBus_IDE),
1051 controllerType(StorageControllerType_PIIX3),
1052 ulPortCount(2),
1053 ulInstance(0),
1054 fUseHostIOCache(true),
1055 fBootable(true),
1056 lIDE0MasterEmulationPort(0),
1057 lIDE0SlaveEmulationPort(0),
1058 lIDE1MasterEmulationPort(0),
1059 lIDE1SlaveEmulationPort(0)
1060 {}
1061
1062 bool operator==(const StorageController &s) const;
1063
1064 com::Utf8Str strName;
1065 StorageBus_T storageBus; // _SATA, _SCSI, _IDE, _SAS
1066 StorageControllerType_T controllerType;
1067 uint32_t ulPortCount;
1068 uint32_t ulInstance;
1069 bool fUseHostIOCache;
1070 bool fBootable;
1071
1072 // only for when controllerType == StorageControllerType_IntelAhci:
1073 int32_t lIDE0MasterEmulationPort,
1074 lIDE0SlaveEmulationPort,
1075 lIDE1MasterEmulationPort,
1076 lIDE1SlaveEmulationPort;
1077
1078 AttachedDevicesList llAttachedDevices;
1079};
1080typedef std::list<StorageController> StorageControllersList;
1081
1082/**
1083 * We wrap the storage controllers list into an extra struct so we can
1084 * use an undefined struct without needing std::list<> in all the headers.
1085 *
1086 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1087 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1088 * your settings might never get saved.
1089 */
1090struct Storage
1091{
1092 bool operator==(const Storage &s) const;
1093
1094 StorageControllersList llStorageControllers;
1095};
1096
1097/**
1098 * Settings that has to do with debugging.
1099 */
1100struct Debugging
1101{
1102 Debugging()
1103 : fTracingEnabled(false),
1104 fAllowTracingToAccessVM(false),
1105 strTracingConfig()
1106 { }
1107
1108 bool operator==(const Debugging &rOther) const
1109 {
1110 return fTracingEnabled == rOther.fTracingEnabled
1111 && fAllowTracingToAccessVM == rOther.fAllowTracingToAccessVM
1112 && strTracingConfig == rOther.strTracingConfig;
1113 }
1114
1115 bool areDefaultSettings() const
1116 {
1117 return !fTracingEnabled
1118 && !fAllowTracingToAccessVM
1119 && strTracingConfig.isEmpty();
1120 }
1121
1122 bool fTracingEnabled;
1123 bool fAllowTracingToAccessVM;
1124 com::Utf8Str strTracingConfig;
1125};
1126
1127/**
1128 * Settings that has to do with autostart.
1129 */
1130struct Autostart
1131{
1132 Autostart()
1133 : fAutostartEnabled(false),
1134 uAutostartDelay(0),
1135 enmAutostopType(AutostopType_Disabled)
1136 { }
1137
1138 bool operator==(const Autostart &rOther) const
1139 {
1140 return fAutostartEnabled == rOther.fAutostartEnabled
1141 && uAutostartDelay == rOther.uAutostartDelay
1142 && enmAutostopType == rOther.enmAutostopType;
1143 }
1144
1145 bool areDefaultSettings() const
1146 {
1147 return !fAutostartEnabled
1148 && !uAutostartDelay
1149 && enmAutostopType == AutostopType_Disabled;
1150 }
1151
1152 bool fAutostartEnabled;
1153 uint32_t uAutostartDelay;
1154 AutostopType_T enmAutostopType;
1155};
1156
1157struct Snapshot;
1158typedef std::list<Snapshot> SnapshotsList;
1159
1160/**
1161 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1162 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1163 * your settings might never get saved.
1164 */
1165struct Snapshot
1166{
1167 Snapshot()
1168 {
1169 RTTimeSpecSetNano(&timestamp, 0);
1170 }
1171
1172 bool operator==(const Snapshot &s) const;
1173
1174 com::Guid uuid;
1175 com::Utf8Str strName,
1176 strDescription; // optional
1177 RTTIMESPEC timestamp;
1178
1179 com::Utf8Str strStateFile; // for online snapshots only
1180
1181 Hardware hardware;
1182 Storage storage;
1183
1184 Debugging debugging;
1185 Autostart autostart;
1186
1187 SnapshotsList llChildSnapshots;
1188};
1189
1190struct MachineUserData
1191{
1192 MachineUserData()
1193 : fDirectoryIncludesUUID(false),
1194 fNameSync(true),
1195 fTeleporterEnabled(false),
1196 uTeleporterPort(0),
1197 enmFaultToleranceState(FaultToleranceState_Inactive),
1198 uFaultTolerancePort(0),
1199 uFaultToleranceInterval(0),
1200 fRTCUseUTC(false)
1201 {
1202 llGroups.push_back("/");
1203 }
1204
1205 bool operator==(const MachineUserData &c) const
1206 {
1207 return (strName == c.strName)
1208 && (fDirectoryIncludesUUID == c.fDirectoryIncludesUUID)
1209 && (fNameSync == c.fNameSync)
1210 && (strDescription == c.strDescription)
1211 && (llGroups == c.llGroups)
1212 && (strOsType == c.strOsType)
1213 && (strSnapshotFolder == c.strSnapshotFolder)
1214 && (fTeleporterEnabled == c.fTeleporterEnabled)
1215 && (uTeleporterPort == c.uTeleporterPort)
1216 && (strTeleporterAddress == c.strTeleporterAddress)
1217 && (strTeleporterPassword == c.strTeleporterPassword)
1218 && (enmFaultToleranceState == c.enmFaultToleranceState)
1219 && (uFaultTolerancePort == c.uFaultTolerancePort)
1220 && (uFaultToleranceInterval == c.uFaultToleranceInterval)
1221 && (strFaultToleranceAddress == c.strFaultToleranceAddress)
1222 && (strFaultTolerancePassword == c.strFaultTolerancePassword)
1223 && (fRTCUseUTC == c.fRTCUseUTC)
1224 && (ovIcon == c.ovIcon);
1225 }
1226
1227 com::Utf8Str strName;
1228 bool fDirectoryIncludesUUID;
1229 bool fNameSync;
1230 com::Utf8Str strDescription;
1231 StringsList llGroups;
1232 com::Utf8Str strOsType;
1233 com::Utf8Str strSnapshotFolder;
1234 bool fTeleporterEnabled;
1235 uint32_t uTeleporterPort;
1236 com::Utf8Str strTeleporterAddress;
1237 com::Utf8Str strTeleporterPassword;
1238 FaultToleranceState_T enmFaultToleranceState;
1239 uint32_t uFaultTolerancePort;
1240 com::Utf8Str strFaultToleranceAddress;
1241 com::Utf8Str strFaultTolerancePassword;
1242 uint32_t uFaultToleranceInterval;
1243 bool fRTCUseUTC;
1244 com::Utf8Str ovIcon;
1245};
1246
1247extern const struct Snapshot g_SnapshotEmpty;
1248
1249/**
1250 * MachineConfigFile represents an XML machine configuration. All the machine settings
1251 * that go out to the XML (or are read from it) are in here.
1252 *
1253 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1254 * the operator== which is used by Machine::saveSettings(), or otherwise your settings
1255 * might never get saved.
1256 */
1257class MachineConfigFile : public ConfigFileBase
1258{
1259public:
1260 com::Guid uuid;
1261
1262 MachineUserData machineUserData;
1263
1264 com::Utf8Str strStateFile;
1265 bool fCurrentStateModified; // optional, default is true
1266 RTTIMESPEC timeLastStateChange; // optional, defaults to now
1267 bool fAborted; // optional, default is false
1268
1269 com::Guid uuidCurrentSnapshot;
1270
1271 Hardware hardwareMachine;
1272 Storage storageMachine;
1273 MediaRegistry mediaRegistry;
1274 Debugging debugging;
1275 Autostart autostart;
1276
1277 StringsMap mapExtraDataItems;
1278
1279 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
1280
1281 MachineConfigFile(const com::Utf8Str *pstrFilename);
1282
1283 bool operator==(const MachineConfigFile &m) const;
1284
1285 bool canHaveOwnMediaRegistry() const;
1286
1287 void importMachineXML(const xml::ElementNode &elmMachine);
1288
1289 void write(const com::Utf8Str &strFilename);
1290
1291 enum
1292 {
1293 BuildMachineXML_IncludeSnapshots = 0x01,
1294 BuildMachineXML_WriteVBoxVersionAttribute = 0x02,
1295 BuildMachineXML_SkipRemovableMedia = 0x04,
1296 BuildMachineXML_MediaRegistry = 0x08,
1297 BuildMachineXML_SuppressSavedState = 0x10
1298 };
1299 void buildMachineXML(xml::ElementNode &elmMachine,
1300 uint32_t fl,
1301 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1302
1303 static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T drv);
1304 static AudioDriverType_T getHostDefaultAudioDriver();
1305
1306private:
1307 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
1308 void readAttachedNetworkMode(const xml::ElementNode &pelmMode, bool fEnabled, NetworkAdapter &nic);
1309 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
1310 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
1311 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
1312 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
1313 void readAudioAdapter(const xml::ElementNode &elmAudioAdapter, AudioAdapter &aa);
1314 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
1315 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
1316 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw, Storage &strg);
1317 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
1318 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
1319 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
1320 void readTeleporter(const xml::ElementNode *pElmTeleporter, MachineUserData *pUserData);
1321 void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
1322 void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
1323 void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
1324 bool readSnapshot(const com::Guid &curSnapshotUuid, uint32_t depth, const xml::ElementNode &elmSnapshot, Snapshot &snap);
1325 void convertOldOSType_pre1_5(com::Utf8Str &str);
1326 void readMachine(const xml::ElementNode &elmMachine);
1327
1328 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, const Storage &strg);
1329 void buildNetworkXML(NetworkAttachmentType_T mode, xml::ElementNode &elmParent, bool fEnabled, const NetworkAdapter &nic);
1330 void buildStorageControllersXML(xml::ElementNode &elmParent,
1331 const Storage &st,
1332 bool fSkipRemovableMedia,
1333 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1334 void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
1335 void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
1336 void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
1337 void buildSnapshotXML(uint32_t depth, xml::ElementNode &elmParent, const Snapshot &snap);
1338
1339 void bumpSettingsVersionIfNeeded();
1340};
1341
1342} // namespace settings
1343
1344
1345#endif /* ___VBox_settings_h */
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