VirtualBox

source: vbox/trunk/src/VBox/Main/xml/Settings.cpp@ 33201

Last change on this file since 33201 was 33201, checked in by vboxsync, 14 years ago

reverted r66739

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 182.1 KB
Line 
1/* $Id: Settings.cpp 33201 2010-10-18 14:37:33Z vboxsync $ */
2/** @file
3 * Settings File Manipulation API.
4 *
5 * Two classes, MainConfigFile and MachineConfigFile, represent the VirtualBox.xml and
6 * machine XML files. They share a common ancestor class, ConfigFileBase, which shares
7 * functionality such as talking to the XML back-end classes and settings version management.
8 *
9 * The code can read all VirtualBox settings files version 1.3 and higher. That version was
10 * written by VirtualBox 2.0. It can write settings version 1.7 (used by VirtualBox 2.2 and
11 * 3.0) and 1.9 (used by VirtualBox 3.1) and newer ones obviously.
12 *
13 * The settings versions enum is defined in src/VBox/Main/idl/VirtualBox.xidl. To introduce
14 * a new settings version (should be necessary at most once per VirtualBox major release,
15 * if at all), add a new SettingsVersion value to that enum and grep for the previously
16 * highest value to see which code in here needs adjusting.
17 *
18 * Certainly ConfigFileBase::ConfigFileBase() will. Change VBOX_XML_VERSION below as well.
19 *
20 * Once a new settings version has been added, these are the rules for introducing a new
21 * setting: If an XML element or attribute or value is introduced that was not present in
22 * previous versions, then settings version checks need to be introduced. See the
23 * SettingsVersion enumeration in src/VBox/Main/idl/VirtualBox.xidl for details about which
24 * version was used when.
25 *
26 * The settings versions checks are necessary because since version 3.1, VirtualBox no longer
27 * automatically converts XML settings files but only if necessary, that is, if settings are
28 * present that the old format does not support. If we write an element or attribute to a
29 * settings file of an older version, then an old VirtualBox (before 3.1) will attempt to
30 * validate it with XML schema, and that will certainly fail.
31 *
32 * So, to introduce a new setting:
33 *
34 * 1) Make sure the constructor of corresponding settings structure has a proper default.
35 *
36 * 2) In the settings reader method, try to read the setting; if it's there, great, if not,
37 * the default value will have been set by the constructor. The rule is to be tolerant
38 * here.
39 *
40 * 3) In MachineConfigFile::bumpSettingsVersionIfNeeded(), check if the new setting has
41 * a non-default value (i.e. that differs from the constructor). If so, bump the
42 * settings version to the current version so the settings writer (4) can write out
43 * the non-default value properly.
44 *
45 * So far a corresponding method for MainConfigFile has not been necessary since there
46 * have been no incompatible changes yet.
47 *
48 * 4) In the settings writer method, write the setting _only_ if the current settings
49 * version (stored in m->sv) is high enough. That is, for VirtualBox 4.0, write it
50 * only if (m->sv >= SettingsVersion_v1_11).
51 */
52
53/*
54 * Copyright (C) 2007-2010 Oracle Corporation
55 *
56 * This file is part of VirtualBox Open Source Edition (OSE), as
57 * available from http://www.virtualbox.org. This file is free software;
58 * you can redistribute it and/or modify it under the terms of the GNU
59 * General Public License (GPL) as published by the Free Software
60 * Foundation, in version 2 as it comes in the "COPYING" file of the
61 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
62 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
63 */
64
65#include "VBox/com/string.h"
66#include "VBox/settings.h"
67#include <iprt/cpp/xml.h>
68#include <iprt/stream.h>
69#include <iprt/ctype.h>
70#include <iprt/file.h>
71#include <iprt/process.h>
72#include <iprt/ldr.h>
73#include <iprt/cpp/lock.h>
74
75// generated header
76#include "SchemaDefs.h"
77
78#include "Logging.h"
79
80using namespace com;
81using namespace settings;
82
83////////////////////////////////////////////////////////////////////////////////
84//
85// Defines
86//
87////////////////////////////////////////////////////////////////////////////////
88
89/** VirtualBox XML settings namespace */
90#define VBOX_XML_NAMESPACE "http://www.innotek.de/VirtualBox-settings"
91
92/** VirtualBox XML settings version number substring ("x.y") */
93#define VBOX_XML_VERSION "1.11"
94
95/** VirtualBox XML settings version platform substring */
96#if defined (RT_OS_DARWIN)
97# define VBOX_XML_PLATFORM "macosx"
98#elif defined (RT_OS_FREEBSD)
99# define VBOX_XML_PLATFORM "freebsd"
100#elif defined (RT_OS_LINUX)
101# define VBOX_XML_PLATFORM "linux"
102#elif defined (RT_OS_NETBSD)
103# define VBOX_XML_PLATFORM "netbsd"
104#elif defined (RT_OS_OPENBSD)
105# define VBOX_XML_PLATFORM "openbsd"
106#elif defined (RT_OS_OS2)
107# define VBOX_XML_PLATFORM "os2"
108#elif defined (RT_OS_SOLARIS)
109# define VBOX_XML_PLATFORM "solaris"
110#elif defined (RT_OS_WINDOWS)
111# define VBOX_XML_PLATFORM "windows"
112#else
113# error Unsupported platform!
114#endif
115
116/** VirtualBox XML settings full version string ("x.y-platform") */
117#define VBOX_XML_VERSION_FULL VBOX_XML_VERSION "-" VBOX_XML_PLATFORM
118
119////////////////////////////////////////////////////////////////////////////////
120//
121// Internal data
122//
123////////////////////////////////////////////////////////////////////////////////
124
125/**
126 * Opaque data structore for ConfigFileBase (only declared
127 * in header, defined only here).
128 */
129
130struct ConfigFileBase::Data
131{
132 Data()
133 : pDoc(NULL),
134 pelmRoot(NULL),
135 sv(SettingsVersion_Null),
136 svRead(SettingsVersion_Null)
137 {}
138
139 ~Data()
140 {
141 cleanup();
142 }
143
144 iprt::MiniString strFilename;
145 bool fFileExists;
146
147 xml::Document *pDoc;
148 xml::ElementNode *pelmRoot;
149
150 com::Utf8Str strSettingsVersionFull; // e.g. "1.7-linux"
151 SettingsVersion_T sv; // e.g. SettingsVersion_v1_7
152
153 SettingsVersion_T svRead; // settings version that the original file had when it was read,
154 // or SettingsVersion_Null if none
155
156 void copyFrom(const Data &d)
157 {
158 strFilename = d.strFilename;
159 fFileExists = d.fFileExists;
160 strSettingsVersionFull = d.strSettingsVersionFull;
161 sv = d.sv;
162 svRead = d.svRead;
163 }
164
165 void cleanup()
166 {
167 if (pDoc)
168 {
169 delete pDoc;
170 pDoc = NULL;
171 pelmRoot = NULL;
172 }
173 }
174};
175
176/**
177 * Private exception class (not in the header file) that makes
178 * throwing xml::LogicError instances easier. That class is public
179 * and should be caught by client code.
180 */
181class settings::ConfigFileError : public xml::LogicError
182{
183public:
184 ConfigFileError(const ConfigFileBase *file,
185 const xml::Node *pNode,
186 const char *pcszFormat, ...)
187 : xml::LogicError()
188 {
189 va_list args;
190 va_start(args, pcszFormat);
191 Utf8StrFmtVA strWhat(pcszFormat, args);
192 va_end(args);
193
194 Utf8Str strLine;
195 if (pNode)
196 strLine = Utf8StrFmt(" (line %RU32)", pNode->getLineNumber());
197
198 const char *pcsz = strLine.c_str();
199 Utf8StrFmt str(N_("Error in %s%s -- %s"),
200 file->m->strFilename.c_str(),
201 (pcsz) ? pcsz : "",
202 strWhat.c_str());
203
204 setWhat(str.c_str());
205 }
206};
207
208////////////////////////////////////////////////////////////////////////////////
209//
210// MediaRegistry
211//
212////////////////////////////////////////////////////////////////////////////////
213
214bool Medium::operator==(const Medium &m) const
215{
216 return (uuid == m.uuid)
217 && (strLocation == m.strLocation)
218 && (strDescription == m.strDescription)
219 && (strFormat == m.strFormat)
220 && (fAutoReset == m.fAutoReset)
221 && (properties == m.properties)
222 && (hdType == m.hdType)
223 && (llChildren== m.llChildren); // this is deep and recurses
224}
225
226bool MediaRegistry::operator==(const MediaRegistry &m) const
227{
228 return llHardDisks == m.llHardDisks
229 && llDvdImages == m.llDvdImages
230 && llFloppyImages == m.llFloppyImages;
231}
232
233////////////////////////////////////////////////////////////////////////////////
234//
235// ConfigFileBase
236//
237////////////////////////////////////////////////////////////////////////////////
238
239/**
240 * Constructor. Allocates the XML internals, parses the XML file if
241 * pstrFilename is != NULL and reads the settings version from it.
242 * @param strFilename
243 */
244ConfigFileBase::ConfigFileBase(const com::Utf8Str *pstrFilename)
245 : m(new Data)
246{
247 Utf8Str strMajor;
248 Utf8Str strMinor;
249
250 m->fFileExists = false;
251
252 if (pstrFilename)
253 {
254 // reading existing settings file:
255 m->strFilename = *pstrFilename;
256
257 xml::XmlFileParser parser;
258 m->pDoc = new xml::Document;
259 parser.read(*pstrFilename,
260 *m->pDoc);
261
262 m->fFileExists = true;
263
264 m->pelmRoot = m->pDoc->getRootElement();
265 if (!m->pelmRoot || !m->pelmRoot->nameEquals("VirtualBox"))
266 throw ConfigFileError(this, NULL, N_("Root element in VirtualBox settings files must be \"VirtualBox\"."));
267
268 if (!(m->pelmRoot->getAttributeValue("version", m->strSettingsVersionFull)))
269 throw ConfigFileError(this, m->pelmRoot, N_("Required VirtualBox/@version attribute is missing"));
270
271 LogRel(("Loading settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
272
273 // parse settings version; allow future versions but fail if file is older than 1.6
274 m->sv = SettingsVersion_Null;
275 if (m->strSettingsVersionFull.length() > 3)
276 {
277 const char *pcsz = m->strSettingsVersionFull.c_str();
278 char c;
279
280 while ( (c = *pcsz)
281 && RT_C_IS_DIGIT(c)
282 )
283 {
284 strMajor.append(c);
285 ++pcsz;
286 }
287
288 if (*pcsz++ == '.')
289 {
290 while ( (c = *pcsz)
291 && RT_C_IS_DIGIT(c)
292 )
293 {
294 strMinor.append(c);
295 ++pcsz;
296 }
297 }
298
299 uint32_t ulMajor = RTStrToUInt32(strMajor.c_str());
300 uint32_t ulMinor = RTStrToUInt32(strMinor.c_str());
301
302 if (ulMajor == 1)
303 {
304 if (ulMinor == 3)
305 m->sv = SettingsVersion_v1_3;
306 else if (ulMinor == 4)
307 m->sv = SettingsVersion_v1_4;
308 else if (ulMinor == 5)
309 m->sv = SettingsVersion_v1_5;
310 else if (ulMinor == 6)
311 m->sv = SettingsVersion_v1_6;
312 else if (ulMinor == 7)
313 m->sv = SettingsVersion_v1_7;
314 else if (ulMinor == 8)
315 m->sv = SettingsVersion_v1_8;
316 else if (ulMinor == 9)
317 m->sv = SettingsVersion_v1_9;
318 else if (ulMinor == 10)
319 m->sv = SettingsVersion_v1_10;
320 else if (ulMinor == 11)
321 m->sv = SettingsVersion_v1_11;
322 else if (ulMinor > 11)
323 m->sv = SettingsVersion_Future;
324 }
325 else if (ulMajor > 1)
326 m->sv = SettingsVersion_Future;
327
328 LogRel(("Parsed settings version %d.%d to enum value %d\n", ulMajor, ulMinor, m->sv));
329 }
330
331 if (m->sv == SettingsVersion_Null)
332 throw ConfigFileError(this, m->pelmRoot, N_("Cannot handle settings version '%s'"), m->strSettingsVersionFull.c_str());
333
334 // remember the settings version we read in case it gets upgraded later,
335 // so we know when to make backups
336 m->svRead = m->sv;
337 }
338 else
339 {
340 // creating new settings file:
341 m->strSettingsVersionFull = VBOX_XML_VERSION_FULL;
342 m->sv = SettingsVersion_v1_11;
343 }
344}
345
346/**
347 * Clean up.
348 */
349ConfigFileBase::~ConfigFileBase()
350{
351 if (m)
352 {
353 delete m;
354 m = NULL;
355 }
356}
357
358/**
359 * Helper function that parses a UUID in string form into
360 * a com::Guid item. Accepts UUIDs both with and without
361 * "{}" brackets. Throws on errors.
362 * @param guid
363 * @param strUUID
364 */
365void ConfigFileBase::parseUUID(Guid &guid,
366 const Utf8Str &strUUID) const
367{
368 guid = strUUID.c_str();
369 if (guid.isEmpty())
370 throw ConfigFileError(this, NULL, N_("UUID \"%s\" has invalid format"), strUUID.c_str());
371}
372
373/**
374 * Parses the given string in str and attempts to treat it as an ISO
375 * date/time stamp to put into timestamp. Throws on errors.
376 * @param timestamp
377 * @param str
378 */
379void ConfigFileBase::parseTimestamp(RTTIMESPEC &timestamp,
380 const com::Utf8Str &str) const
381{
382 const char *pcsz = str.c_str();
383 // yyyy-mm-ddThh:mm:ss
384 // "2009-07-10T11:54:03Z"
385 // 01234567890123456789
386 // 1
387 if (str.length() > 19)
388 {
389 // timezone must either be unspecified or 'Z' for UTC
390 if ( (pcsz[19])
391 && (pcsz[19] != 'Z')
392 )
393 throw ConfigFileError(this, NULL, N_("Cannot handle ISO timestamp '%s': is not UTC date"), str.c_str());
394
395 int32_t yyyy;
396 uint32_t mm, dd, hh, min, secs;
397 if ( (pcsz[4] == '-')
398 && (pcsz[7] == '-')
399 && (pcsz[10] == 'T')
400 && (pcsz[13] == ':')
401 && (pcsz[16] == ':')
402 )
403 {
404 int rc;
405 if ( (RT_SUCCESS(rc = RTStrToInt32Ex(pcsz, NULL, 0, &yyyy)))
406 // could theoretically be negative but let's assume that nobody
407 // created virtual machines before the Christian era
408 && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 5, NULL, 0, &mm)))
409 && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 8, NULL, 0, &dd)))
410 && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 11, NULL, 0, &hh)))
411 && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 14, NULL, 0, &min)))
412 && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 17, NULL, 0, &secs)))
413 )
414 {
415 RTTIME time =
416 {
417 yyyy,
418 (uint8_t)mm,
419 0,
420 0,
421 (uint8_t)dd,
422 (uint8_t)hh,
423 (uint8_t)min,
424 (uint8_t)secs,
425 0,
426 RTTIME_FLAGS_TYPE_UTC,
427 0
428 };
429 if (RTTimeNormalize(&time))
430 if (RTTimeImplode(&timestamp, &time))
431 return;
432 }
433
434 throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': runtime error, %Rra"), str.c_str(), rc);
435 }
436
437 throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': invalid format"), str.c_str());
438 }
439}
440
441/**
442 * Helper to create a string for a RTTIMESPEC for writing out ISO timestamps.
443 * @param stamp
444 * @return
445 */
446com::Utf8Str ConfigFileBase::makeString(const RTTIMESPEC &stamp)
447{
448 RTTIME time;
449 if (!RTTimeExplode(&time, &stamp))
450 throw ConfigFileError(this, NULL, N_("Timespec %lld ms is invalid"), RTTimeSpecGetMilli(&stamp));
451
452 return Utf8StrFmt("%04ld-%02hd-%02hdT%02hd:%02hd:%02hdZ",
453 time.i32Year,
454 (uint16_t)time.u8Month,
455 (uint16_t)time.u8MonthDay,
456 (uint16_t)time.u8Hour,
457 (uint16_t)time.u8Minute,
458 (uint16_t)time.u8Second);
459}
460
461/**
462 * Helper method to read in an ExtraData subtree and stores its contents
463 * in the given map of extradata items. Used for both main and machine
464 * extradata (MainConfigFile and MachineConfigFile).
465 * @param elmExtraData
466 * @param map
467 */
468void ConfigFileBase::readExtraData(const xml::ElementNode &elmExtraData,
469 StringsMap &map)
470{
471 xml::NodesLoop nlLevel4(elmExtraData);
472 const xml::ElementNode *pelmExtraDataItem;
473 while ((pelmExtraDataItem = nlLevel4.forAllNodes()))
474 {
475 if (pelmExtraDataItem->nameEquals("ExtraDataItem"))
476 {
477 // <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/>
478 Utf8Str strName, strValue;
479 if ( ((pelmExtraDataItem->getAttributeValue("name", strName)))
480 && ((pelmExtraDataItem->getAttributeValue("value", strValue)))
481 )
482 map[strName] = strValue;
483 else
484 throw ConfigFileError(this, pelmExtraDataItem, N_("Required ExtraDataItem/@name or @value attribute is missing"));
485 }
486 }
487}
488
489/**
490 * Reads <USBDeviceFilter> entries from under the given elmDeviceFilters node and
491 * stores them in the given linklist. This is in ConfigFileBase because it's used
492 * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
493 * filters).
494 * @param elmDeviceFilters
495 * @param ll
496 */
497void ConfigFileBase::readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
498 USBDeviceFiltersList &ll)
499{
500 xml::NodesLoop nl1(elmDeviceFilters, "DeviceFilter");
501 const xml::ElementNode *pelmLevel4Child;
502 while ((pelmLevel4Child = nl1.forAllNodes()))
503 {
504 USBDeviceFilter flt;
505 flt.action = USBDeviceFilterAction_Ignore;
506 Utf8Str strAction;
507 if ( (pelmLevel4Child->getAttributeValue("name", flt.strName))
508 && (pelmLevel4Child->getAttributeValue("active", flt.fActive))
509 )
510 {
511 if (!pelmLevel4Child->getAttributeValue("vendorId", flt.strVendorId))
512 pelmLevel4Child->getAttributeValue("vendorid", flt.strVendorId); // used before 1.3
513 if (!pelmLevel4Child->getAttributeValue("productId", flt.strProductId))
514 pelmLevel4Child->getAttributeValue("productid", flt.strProductId); // used before 1.3
515 pelmLevel4Child->getAttributeValue("revision", flt.strRevision);
516 pelmLevel4Child->getAttributeValue("manufacturer", flt.strManufacturer);
517 pelmLevel4Child->getAttributeValue("product", flt.strProduct);
518 if (!pelmLevel4Child->getAttributeValue("serialNumber", flt.strSerialNumber))
519 pelmLevel4Child->getAttributeValue("serialnumber", flt.strSerialNumber); // used before 1.3
520 pelmLevel4Child->getAttributeValue("port", flt.strPort);
521
522 // the next 2 are irrelevant for host USB objects
523 pelmLevel4Child->getAttributeValue("remote", flt.strRemote);
524 pelmLevel4Child->getAttributeValue("maskedInterfaces", flt.ulMaskedInterfaces);
525
526 // action is only used with host USB objects
527 if (pelmLevel4Child->getAttributeValue("action", strAction))
528 {
529 if (strAction == "Ignore")
530 flt.action = USBDeviceFilterAction_Ignore;
531 else if (strAction == "Hold")
532 flt.action = USBDeviceFilterAction_Hold;
533 else
534 throw ConfigFileError(this, pelmLevel4Child, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
535 }
536
537 ll.push_back(flt);
538 }
539 }
540}
541
542/**
543 * Reads a media registry entry from the main VirtualBox.xml file.
544 *
545 * Whereas the current media registry code is fairly straightforward, it was quite a mess
546 * with settings format before 1.4 (VirtualBox 2.0 used settings format 1.3). The elements
547 * in the media registry were much more inconsistent, and different elements were used
548 * depending on the type of device and image.
549 *
550 * @param t
551 * @param elmMedium
552 * @param llMedia
553 */
554void ConfigFileBase::readMedium(MediaType t,
555 const xml::ElementNode &elmMedium, // HardDisk node if root; if recursing,
556 // child HardDisk node or DiffHardDisk node for pre-1.4
557 MediaList &llMedia) // list to append medium to (root disk or child list)
558{
559 // <HardDisk uuid="{5471ecdb-1ddb-4012-a801-6d98e226868b}" location="/mnt/innotek-unix/vdis/Windows XP.vdi" format="VDI" type="Normal">
560 settings::Medium med;
561 Utf8Str strUUID;
562 if (!(elmMedium.getAttributeValue("uuid", strUUID)))
563 throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName());
564
565 parseUUID(med.uuid, strUUID);
566
567 bool fNeedsLocation = true;
568
569 if (t == HardDisk)
570 {
571 if (m->sv < SettingsVersion_v1_4)
572 {
573 // here the system is:
574 // <HardDisk uuid="{....}" type="normal">
575 // <VirtualDiskImage filePath="/path/to/xxx.vdi"/>
576 // </HardDisk>
577
578 fNeedsLocation = false;
579 bool fNeedsFilePath = true;
580 const xml::ElementNode *pelmImage;
581 if ((pelmImage = elmMedium.findChildElement("VirtualDiskImage")))
582 med.strFormat = "VDI";
583 else if ((pelmImage = elmMedium.findChildElement("VMDKImage")))
584 med.strFormat = "VMDK";
585 else if ((pelmImage = elmMedium.findChildElement("VHDImage")))
586 med.strFormat = "VHD";
587 else if ((pelmImage = elmMedium.findChildElement("ISCSIHardDisk")))
588 {
589 med.strFormat = "iSCSI";
590
591 fNeedsFilePath = false;
592 // location is special here: current settings specify an "iscsi://user@server:port/target/lun"
593 // string for the location and also have several disk properties for these, whereas this used
594 // to be hidden in several sub-elements before 1.4, so compose a location string and set up
595 // the properties:
596 med.strLocation = "iscsi://";
597 Utf8Str strUser, strServer, strPort, strTarget, strLun;
598 if (pelmImage->getAttributeValue("userName", strUser))
599 {
600 med.strLocation.append(strUser);
601 med.strLocation.append("@");
602 }
603 Utf8Str strServerAndPort;
604 if (pelmImage->getAttributeValue("server", strServer))
605 {
606 strServerAndPort = strServer;
607 }
608 if (pelmImage->getAttributeValue("port", strPort))
609 {
610 if (strServerAndPort.length())
611 strServerAndPort.append(":");
612 strServerAndPort.append(strPort);
613 }
614 med.strLocation.append(strServerAndPort);
615 if (pelmImage->getAttributeValue("target", strTarget))
616 {
617 med.strLocation.append("/");
618 med.strLocation.append(strTarget);
619 }
620 if (pelmImage->getAttributeValue("lun", strLun))
621 {
622 med.strLocation.append("/");
623 med.strLocation.append(strLun);
624 }
625
626 if (strServer.length() && strPort.length())
627 med.properties["TargetAddress"] = strServerAndPort;
628 if (strTarget.length())
629 med.properties["TargetName"] = strTarget;
630 if (strUser.length())
631 med.properties["InitiatorUsername"] = strUser;
632 Utf8Str strPassword;
633 if (pelmImage->getAttributeValue("password", strPassword))
634 med.properties["InitiatorSecret"] = strPassword;
635 if (strLun.length())
636 med.properties["LUN"] = strLun;
637 }
638 else if ((pelmImage = elmMedium.findChildElement("CustomHardDisk")))
639 {
640 fNeedsFilePath = false;
641 fNeedsLocation = true;
642 // also requires @format attribute, which will be queried below
643 }
644 else
645 throw ConfigFileError(this, &elmMedium, N_("Required %s/VirtualDiskImage element is missing"), elmMedium.getName());
646
647 if (fNeedsFilePath)
648 if (!(pelmImage->getAttributeValue("filePath", med.strLocation)))
649 throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
650 }
651
652 if (med.strFormat.isEmpty()) // not set with 1.4 format above, or 1.4 Custom format?
653 if (!(elmMedium.getAttributeValue("format", med.strFormat)))
654 throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName());
655
656 if (!(elmMedium.getAttributeValue("autoReset", med.fAutoReset)))
657 med.fAutoReset = false;
658
659 Utf8Str strType;
660 if ((elmMedium.getAttributeValue("type", strType)))
661 {
662 // pre-1.4 used lower case, so make this case-insensitive
663 strType.toUpper();
664 if (strType == "NORMAL")
665 med.hdType = MediumType_Normal;
666 else if (strType == "IMMUTABLE")
667 med.hdType = MediumType_Immutable;
668 else if (strType == "WRITETHROUGH")
669 med.hdType = MediumType_Writethrough;
670 else if (strType == "SHAREABLE")
671 med.hdType = MediumType_Shareable;
672 else
673 throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable or Writethrough"));
674 }
675 }
676 else if (m->sv < SettingsVersion_v1_4)
677 {
678 // DVD and floppy images before 1.4 had "src" attribute instead of "location"
679 if (!(elmMedium.getAttributeValue("src", med.strLocation)))
680 throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
681
682 fNeedsLocation = false;
683 }
684
685 if (fNeedsLocation)
686 // current files and 1.4 CustomHardDisk elements must have a location attribute
687 if (!(elmMedium.getAttributeValue("location", med.strLocation)))
688 throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName());
689
690 elmMedium.getAttributeValue("Description", med.strDescription); // optional
691
692 // recurse to handle children
693 xml::NodesLoop nl2(elmMedium);
694 const xml::ElementNode *pelmHDChild;
695 while ((pelmHDChild = nl2.forAllNodes()))
696 {
697 if ( t == HardDisk
698 && ( pelmHDChild->nameEquals("HardDisk")
699 || ( (m->sv < SettingsVersion_v1_4)
700 && (pelmHDChild->nameEquals("DiffHardDisk"))
701 )
702 )
703 )
704 // recurse with this element and push the child onto our current children list
705 readMedium(t,
706 *pelmHDChild,
707 med.llChildren);
708 else if (pelmHDChild->nameEquals("Property"))
709 {
710 Utf8Str strPropName, strPropValue;
711 if ( (pelmHDChild->getAttributeValue("name", strPropName))
712 && (pelmHDChild->getAttributeValue("value", strPropValue))
713 )
714 med.properties[strPropName] = strPropValue;
715 else
716 throw ConfigFileError(this, pelmHDChild, N_("Required HardDisk/Property/@name or @value attribute is missing"));
717 }
718 }
719
720 llMedia.push_back(med);
721}
722
723/**
724 * Reads in the entire <MediaRegistry> chunk and stores its media in the lists
725 * of the given MediaRegistry structure.
726 *
727 * This is used in both MainConfigFile and MachineConfigFile since starting with
728 * VirtualBox 4.0, we can have media registries in both.
729 *
730 * For pre-1.4 files, this gets called with the <DiskRegistry> chunk instead.
731 *
732 * @param elmMediaRegistry
733 */
734void ConfigFileBase::readMediaRegistry(const xml::ElementNode &elmMediaRegistry,
735 MediaRegistry &mr)
736{
737 xml::NodesLoop nl1(elmMediaRegistry);
738 const xml::ElementNode *pelmChild1;
739 while ((pelmChild1 = nl1.forAllNodes()))
740 {
741 MediaType t = Error;
742 if (pelmChild1->nameEquals("HardDisks"))
743 t = HardDisk;
744 else if (pelmChild1->nameEquals("DVDImages"))
745 t = DVDImage;
746 else if (pelmChild1->nameEquals("FloppyImages"))
747 t = FloppyImage;
748 else
749 continue;
750
751 xml::NodesLoop nl2(*pelmChild1);
752 const xml::ElementNode *pelmMedium;
753 while ((pelmMedium = nl2.forAllNodes()))
754 {
755 if ( t == HardDisk
756 && (pelmMedium->nameEquals("HardDisk"))
757 )
758 readMedium(t,
759 *pelmMedium,
760 mr.llHardDisks); // list to append hard disk data to: the root list
761 else if ( t == DVDImage
762 && (pelmMedium->nameEquals("Image"))
763 )
764 readMedium(t,
765 *pelmMedium,
766 mr.llDvdImages); // list to append dvd images to: the root list
767 else if ( t == FloppyImage
768 && (pelmMedium->nameEquals("Image"))
769 )
770 readMedium(t,
771 *pelmMedium,
772 mr.llFloppyImages); // list to append floppy images to: the root list
773 }
774 }
775}
776
777/**
778 * Adds a "version" attribute to the given XML element with the
779 * VirtualBox settings version (e.g. "1.10-linux"). Used by
780 * the XML format for the root element and by the OVF export
781 * for the vbox:Machine element.
782 * @param elm
783 */
784void ConfigFileBase::setVersionAttribute(xml::ElementNode &elm)
785{
786 const char *pcszVersion = NULL;
787 switch (m->sv)
788 {
789 case SettingsVersion_v1_8:
790 pcszVersion = "1.8";
791 break;
792
793 case SettingsVersion_v1_9:
794 pcszVersion = "1.9";
795 break;
796
797 case SettingsVersion_v1_10:
798 pcszVersion = "1.10";
799 break;
800
801 case SettingsVersion_v1_11:
802 pcszVersion = "1.11";
803 break;
804
805 case SettingsVersion_Future:
806 // can be set if this code runs on XML files that were created by a future version of VBox;
807 // in that case, downgrade to current version when writing since we can't write future versions...
808 pcszVersion = "1.11";
809 m->sv = SettingsVersion_v1_10;
810 break;
811
812 default:
813 // silently upgrade if this is less than 1.7 because that's the oldest we can write
814 pcszVersion = "1.7";
815 m->sv = SettingsVersion_v1_7;
816 break;
817 }
818
819 elm.setAttribute("version", Utf8StrFmt("%s-%s",
820 pcszVersion,
821 VBOX_XML_PLATFORM)); // e.g. "linux"
822}
823
824/**
825 * Creates a new stub xml::Document in the m->pDoc member with the
826 * root "VirtualBox" element set up. This is used by both
827 * MainConfigFile and MachineConfigFile at the beginning of writing
828 * out their XML.
829 *
830 * Before calling this, it is the responsibility of the caller to
831 * set the "sv" member to the required settings version that is to
832 * be written. For newly created files, the settings version will be
833 * the latest (1.11); for files read in from disk earlier, it will be
834 * the settings version indicated in the file. However, this method
835 * will silently make sure that the settings version is always
836 * at least 1.7 and change it if necessary, since there is no write
837 * support for earlier settings versions.
838 */
839void ConfigFileBase::createStubDocument()
840{
841 Assert(m->pDoc == NULL);
842 m->pDoc = new xml::Document;
843
844 m->pelmRoot = m->pDoc->createRootElement("VirtualBox");
845 m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
846
847 // add settings version attribute to root element
848 setVersionAttribute(*m->pelmRoot);
849
850 // since this gets called before the XML document is actually written out,
851 // this is where we must check whether we're upgrading the settings version
852 // and need to make a backup, so the user can go back to an earlier
853 // VirtualBox version and recover his old settings files.
854 if ( (m->svRead != SettingsVersion_Null) // old file exists?
855 && (m->svRead < m->sv) // we're upgrading?
856 )
857 {
858 // compose new filename: strip off trailing ".xml"/".vbox"
859 Utf8Str strFilenameNew;
860 Utf8Str strExt = ".xml";
861 if (m->strFilename.endsWith(".xml"))
862 strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
863 else if (m->strFilename.endsWith(".vbox"))
864 {
865 strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 5);
866 strExt = ".vbox";
867 }
868
869 // and append something likd "-1.3-linux.xml"
870 strFilenameNew.append("-");
871 strFilenameNew.append(m->strSettingsVersionFull); // e.g. "1.3-linux"
872 strFilenameNew.append(strExt); // .xml for main config, .vbox for machine config
873
874 RTFileMove(m->strFilename.c_str(),
875 strFilenameNew.c_str(),
876 0); // no RTFILEMOVE_FLAGS_REPLACE
877
878 // do this only once
879 m->svRead = SettingsVersion_Null;
880 }
881}
882
883/**
884 * Creates an <ExtraData> node under the given parent element with
885 * <ExtraDataItem> childern according to the contents of the given
886 * map.
887 *
888 * This is in ConfigFileBase because it's used in both MainConfigFile
889 * and MachineConfigFile, which both can have extradata.
890 *
891 * @param elmParent
892 * @param me
893 */
894void ConfigFileBase::buildExtraData(xml::ElementNode &elmParent,
895 const StringsMap &me)
896{
897 if (me.size())
898 {
899 xml::ElementNode *pelmExtraData = elmParent.createChild("ExtraData");
900 for (StringsMap::const_iterator it = me.begin();
901 it != me.end();
902 ++it)
903 {
904 const Utf8Str &strName = it->first;
905 const Utf8Str &strValue = it->second;
906 xml::ElementNode *pelmThis = pelmExtraData->createChild("ExtraDataItem");
907 pelmThis->setAttribute("name", strName);
908 pelmThis->setAttribute("value", strValue);
909 }
910 }
911}
912
913/**
914 * Creates <DeviceFilter> nodes under the given parent element according to
915 * the contents of the given USBDeviceFiltersList. This is in ConfigFileBase
916 * because it's used in both MainConfigFile (for host filters) and
917 * MachineConfigFile (for machine filters).
918 *
919 * If fHostMode is true, this means that we're supposed to write filters
920 * for the IHost interface (respect "action", omit "strRemote" and
921 * "ulMaskedInterfaces" in struct USBDeviceFilter).
922 *
923 * @param elmParent
924 * @param ll
925 * @param fHostMode
926 */
927void ConfigFileBase::buildUSBDeviceFilters(xml::ElementNode &elmParent,
928 const USBDeviceFiltersList &ll,
929 bool fHostMode)
930{
931 for (USBDeviceFiltersList::const_iterator it = ll.begin();
932 it != ll.end();
933 ++it)
934 {
935 const USBDeviceFilter &flt = *it;
936 xml::ElementNode *pelmFilter = elmParent.createChild("DeviceFilter");
937 pelmFilter->setAttribute("name", flt.strName);
938 pelmFilter->setAttribute("active", flt.fActive);
939 if (flt.strVendorId.length())
940 pelmFilter->setAttribute("vendorId", flt.strVendorId);
941 if (flt.strProductId.length())
942 pelmFilter->setAttribute("productId", flt.strProductId);
943 if (flt.strRevision.length())
944 pelmFilter->setAttribute("revision", flt.strRevision);
945 if (flt.strManufacturer.length())
946 pelmFilter->setAttribute("manufacturer", flt.strManufacturer);
947 if (flt.strProduct.length())
948 pelmFilter->setAttribute("product", flt.strProduct);
949 if (flt.strSerialNumber.length())
950 pelmFilter->setAttribute("serialNumber", flt.strSerialNumber);
951 if (flt.strPort.length())
952 pelmFilter->setAttribute("port", flt.strPort);
953
954 if (fHostMode)
955 {
956 const char *pcsz =
957 (flt.action == USBDeviceFilterAction_Ignore) ? "Ignore"
958 : /*(flt.action == USBDeviceFilterAction_Hold) ?*/ "Hold";
959 pelmFilter->setAttribute("action", pcsz);
960 }
961 else
962 {
963 if (flt.strRemote.length())
964 pelmFilter->setAttribute("remote", flt.strRemote);
965 if (flt.ulMaskedInterfaces)
966 pelmFilter->setAttribute("maskedInterfaces", flt.ulMaskedInterfaces);
967 }
968 }
969}
970
971/**
972 * Creates a single <HardDisk> element for the given Medium structure
973 * and recurses to write the child hard disks underneath. Called from
974 * MainConfigFile::write().
975 *
976 * @param elmMedium
977 * @param m
978 * @param level
979 */
980void ConfigFileBase::buildHardDisk(xml::ElementNode &elmMedium,
981 const Medium &mdm,
982 uint32_t level) // 0 for "root" call, incremented with each recursion
983{
984 xml::ElementNode *pelmHardDisk = elmMedium.createChild("HardDisk");
985 pelmHardDisk->setAttribute("uuid", mdm.uuid.toStringCurly());
986 pelmHardDisk->setAttribute("location", mdm.strLocation);
987 pelmHardDisk->setAttribute("format", mdm.strFormat);
988 if (mdm.fAutoReset)
989 pelmHardDisk->setAttribute("autoReset", mdm.fAutoReset);
990 if (mdm.strDescription.length())
991 pelmHardDisk->setAttribute("Description", mdm.strDescription);
992
993 for (StringsMap::const_iterator it = mdm.properties.begin();
994 it != mdm.properties.end();
995 ++it)
996 {
997 xml::ElementNode *pelmProp = pelmHardDisk->createChild("Property");
998 pelmProp->setAttribute("name", it->first);
999 pelmProp->setAttribute("value", it->second);
1000 }
1001
1002 // only for base hard disks, save the type
1003 if (level == 0)
1004 {
1005 const char *pcszType =
1006 mdm.hdType == MediumType_Normal ? "Normal" :
1007 mdm.hdType == MediumType_Immutable ? "Immutable" :
1008 mdm.hdType == MediumType_Writethrough ? "Writethrough" :
1009 mdm.hdType == MediumType_Shareable ? "Shareable" : "INVALID";
1010 pelmHardDisk->setAttribute("type", pcszType);
1011 }
1012
1013 for (MediaList::const_iterator it = mdm.llChildren.begin();
1014 it != mdm.llChildren.end();
1015 ++it)
1016 {
1017 // recurse for children
1018 buildHardDisk(*pelmHardDisk, // parent
1019 *it, // settings::Medium
1020 ++level); // recursion level
1021 }
1022}
1023
1024/**
1025 * Creates a <MediaRegistry> node under the given parent and writes out all
1026 * hard disks and DVD and floppy images from the lists in the given MediaRegistry
1027 * structure under it.
1028 *
1029 * This is used in both MainConfigFile and MachineConfigFile since starting with
1030 * VirtualBox 4.0, we can have media registries in both.
1031 *
1032 * @param elmParent
1033 * @param mr
1034 */
1035void ConfigFileBase::buildMediaRegistry(xml::ElementNode &elmParent,
1036 const MediaRegistry &mr)
1037{
1038 xml::ElementNode *pelmMediaRegistry = elmParent.createChild("MediaRegistry");
1039
1040 xml::ElementNode *pelmHardDisks = pelmMediaRegistry->createChild("HardDisks");
1041 for (MediaList::const_iterator it = mr.llHardDisks.begin();
1042 it != mr.llHardDisks.end();
1043 ++it)
1044 {
1045 buildHardDisk(*pelmHardDisks, *it, 0);
1046 }
1047
1048 xml::ElementNode *pelmDVDImages = pelmMediaRegistry->createChild("DVDImages");
1049 for (MediaList::const_iterator it = mr.llDvdImages.begin();
1050 it != mr.llDvdImages.end();
1051 ++it)
1052 {
1053 const Medium &mdm = *it;
1054 xml::ElementNode *pelmMedium = pelmDVDImages->createChild("Image");
1055 pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
1056 pelmMedium->setAttribute("location", mdm.strLocation);
1057 if (mdm.strDescription.length())
1058 pelmMedium->setAttribute("Description", mdm.strDescription);
1059 }
1060
1061 xml::ElementNode *pelmFloppyImages = pelmMediaRegistry->createChild("FloppyImages");
1062 for (MediaList::const_iterator it = mr.llFloppyImages.begin();
1063 it != mr.llFloppyImages.end();
1064 ++it)
1065 {
1066 const Medium &mdm = *it;
1067 xml::ElementNode *pelmMedium = pelmFloppyImages->createChild("Image");
1068 pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
1069 pelmMedium->setAttribute("location", mdm.strLocation);
1070 if (mdm.strDescription.length())
1071 pelmMedium->setAttribute("Description", mdm.strDescription);
1072 }
1073}
1074
1075/**
1076 * Cleans up memory allocated by the internal XML parser. To be called by
1077 * descendant classes when they're done analyzing the DOM tree to discard it.
1078 */
1079void ConfigFileBase::clearDocument()
1080{
1081 m->cleanup();
1082}
1083
1084/**
1085 * Returns true only if the underlying config file exists on disk;
1086 * either because the file has been loaded from disk, or it's been written
1087 * to disk, or both.
1088 * @return
1089 */
1090bool ConfigFileBase::fileExists()
1091{
1092 return m->fFileExists;
1093}
1094
1095/**
1096 * Copies the base variables from another instance. Used by Machine::saveSettings
1097 * so that the settings version does not get lost when a copy of the Machine settings
1098 * file is made to see if settings have actually changed.
1099 * @param b
1100 */
1101void ConfigFileBase::copyBaseFrom(const ConfigFileBase &b)
1102{
1103 m->copyFrom(*b.m);
1104}
1105
1106////////////////////////////////////////////////////////////////////////////////
1107//
1108// Structures shared between Machine XML and VirtualBox.xml
1109//
1110////////////////////////////////////////////////////////////////////////////////
1111
1112/**
1113 * Comparison operator. This gets called from MachineConfigFile::operator==,
1114 * which in turn gets called from Machine::saveSettings to figure out whether
1115 * machine settings have really changed and thus need to be written out to disk.
1116 */
1117bool USBDeviceFilter::operator==(const USBDeviceFilter &u) const
1118{
1119 return ( (this == &u)
1120 || ( (strName == u.strName)
1121 && (fActive == u.fActive)
1122 && (strVendorId == u.strVendorId)
1123 && (strProductId == u.strProductId)
1124 && (strRevision == u.strRevision)
1125 && (strManufacturer == u.strManufacturer)
1126 && (strProduct == u.strProduct)
1127 && (strSerialNumber == u.strSerialNumber)
1128 && (strPort == u.strPort)
1129 && (action == u.action)
1130 && (strRemote == u.strRemote)
1131 && (ulMaskedInterfaces == u.ulMaskedInterfaces)
1132 )
1133 );
1134}
1135
1136////////////////////////////////////////////////////////////////////////////////
1137//
1138// MainConfigFile
1139//
1140////////////////////////////////////////////////////////////////////////////////
1141
1142/**
1143 * Reads one <MachineEntry> from the main VirtualBox.xml file.
1144 * @param elmMachineRegistry
1145 */
1146void MainConfigFile::readMachineRegistry(const xml::ElementNode &elmMachineRegistry)
1147{
1148 // <MachineEntry uuid="{ xxx }" src=" xxx "/>
1149 xml::NodesLoop nl1(elmMachineRegistry);
1150 const xml::ElementNode *pelmChild1;
1151 while ((pelmChild1 = nl1.forAllNodes()))
1152 {
1153 if (pelmChild1->nameEquals("MachineEntry"))
1154 {
1155 MachineRegistryEntry mre;
1156 Utf8Str strUUID;
1157 if ( ((pelmChild1->getAttributeValue("uuid", strUUID)))
1158 && ((pelmChild1->getAttributeValue("src", mre.strSettingsFile)))
1159 )
1160 {
1161 parseUUID(mre.uuid, strUUID);
1162 llMachines.push_back(mre);
1163 }
1164 else
1165 throw ConfigFileError(this, pelmChild1, N_("Required MachineEntry/@uuid or @src attribute is missing"));
1166 }
1167 }
1168}
1169
1170/**
1171 * Reads in the <DHCPServers> chunk.
1172 * @param elmDHCPServers
1173 */
1174void MainConfigFile::readDHCPServers(const xml::ElementNode &elmDHCPServers)
1175{
1176 xml::NodesLoop nl1(elmDHCPServers);
1177 const xml::ElementNode *pelmServer;
1178 while ((pelmServer = nl1.forAllNodes()))
1179 {
1180 if (pelmServer->nameEquals("DHCPServer"))
1181 {
1182 DHCPServer srv;
1183 if ( (pelmServer->getAttributeValue("networkName", srv.strNetworkName))
1184 && (pelmServer->getAttributeValue("IPAddress", srv.strIPAddress))
1185 && (pelmServer->getAttributeValue("networkMask", srv.strIPNetworkMask))
1186 && (pelmServer->getAttributeValue("lowerIP", srv.strIPLower))
1187 && (pelmServer->getAttributeValue("upperIP", srv.strIPUpper))
1188 && (pelmServer->getAttributeValue("enabled", srv.fEnabled))
1189 )
1190 llDhcpServers.push_back(srv);
1191 else
1192 throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
1193 }
1194 }
1195}
1196
1197/**
1198 * Constructor.
1199 *
1200 * If pstrFilename is != NULL, this reads the given settings file into the member
1201 * variables and various substructures and lists. Otherwise, the member variables
1202 * are initialized with default values.
1203 *
1204 * Throws variants of xml::Error for I/O, XML and logical content errors, which
1205 * the caller should catch; if this constructor does not throw, then the member
1206 * variables contain meaningful values (either from the file or defaults).
1207 *
1208 * @param strFilename
1209 */
1210MainConfigFile::MainConfigFile(const Utf8Str *pstrFilename)
1211 : ConfigFileBase(pstrFilename)
1212{
1213 if (pstrFilename)
1214 {
1215 // the ConfigFileBase constructor has loaded the XML file, so now
1216 // we need only analyze what is in there
1217 xml::NodesLoop nlRootChildren(*m->pelmRoot);
1218 const xml::ElementNode *pelmRootChild;
1219 while ((pelmRootChild = nlRootChildren.forAllNodes()))
1220 {
1221 if (pelmRootChild->nameEquals("Global"))
1222 {
1223 xml::NodesLoop nlGlobalChildren(*pelmRootChild);
1224 const xml::ElementNode *pelmGlobalChild;
1225 while ((pelmGlobalChild = nlGlobalChildren.forAllNodes()))
1226 {
1227 if (pelmGlobalChild->nameEquals("SystemProperties"))
1228 {
1229 pelmGlobalChild->getAttributeValue("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
1230 if (!pelmGlobalChild->getAttributeValue("defaultHardDiskFolder", systemProperties.strDefaultHardDiskFolder))
1231 // pre-1.4 used @defaultVDIFolder instead
1232 pelmGlobalChild->getAttributeValue("defaultVDIFolder", systemProperties.strDefaultHardDiskFolder);
1233 pelmGlobalChild->getAttributeValue("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
1234 pelmGlobalChild->getAttributeValue("remoteDisplayAuthLibrary", systemProperties.strRemoteDisplayAuthLibrary);
1235 pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
1236 pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.ulLogHistoryCount);
1237 }
1238 else if (pelmGlobalChild->nameEquals("ExtraData"))
1239 readExtraData(*pelmGlobalChild, mapExtraDataItems);
1240 else if (pelmGlobalChild->nameEquals("MachineRegistry"))
1241 readMachineRegistry(*pelmGlobalChild);
1242 else if ( (pelmGlobalChild->nameEquals("MediaRegistry"))
1243 || ( (m->sv < SettingsVersion_v1_4)
1244 && (pelmGlobalChild->nameEquals("DiskRegistry"))
1245 )
1246 )
1247 readMediaRegistry(*pelmGlobalChild, mediaRegistry);
1248 else if (pelmGlobalChild->nameEquals("NetserviceRegistry"))
1249 {
1250 xml::NodesLoop nlLevel4(*pelmGlobalChild);
1251 const xml::ElementNode *pelmLevel4Child;
1252 while ((pelmLevel4Child = nlLevel4.forAllNodes()))
1253 {
1254 if (pelmLevel4Child->nameEquals("DHCPServers"))
1255 readDHCPServers(*pelmLevel4Child);
1256 }
1257 }
1258 else if (pelmGlobalChild->nameEquals("USBDeviceFilters"))
1259 readUSBDeviceFilters(*pelmGlobalChild, host.llUSBDeviceFilters);
1260 }
1261 } // end if (pelmRootChild->nameEquals("Global"))
1262 }
1263
1264 clearDocument();
1265 }
1266
1267 // DHCP servers were introduced with settings version 1.7; if we're loading
1268 // from an older version OR this is a fresh install, then add one DHCP server
1269 // with default settings
1270 if ( (!llDhcpServers.size())
1271 && ( (!pstrFilename) // empty VirtualBox.xml file
1272 || (m->sv < SettingsVersion_v1_7) // upgrading from before 1.7
1273 )
1274 )
1275 {
1276 DHCPServer srv;
1277 srv.strNetworkName =
1278#ifdef RT_OS_WINDOWS
1279 "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter";
1280#else
1281 "HostInterfaceNetworking-vboxnet0";
1282#endif
1283 srv.strIPAddress = "192.168.56.100";
1284 srv.strIPNetworkMask = "255.255.255.0";
1285 srv.strIPLower = "192.168.56.101";
1286 srv.strIPUpper = "192.168.56.254";
1287 srv.fEnabled = true;
1288 llDhcpServers.push_back(srv);
1289 }
1290}
1291
1292/**
1293 * Called from the IVirtualBox interface to write out VirtualBox.xml. This
1294 * builds an XML DOM tree and writes it out to disk.
1295 */
1296void MainConfigFile::write(const com::Utf8Str strFilename)
1297{
1298 m->strFilename = strFilename;
1299 createStubDocument();
1300
1301 xml::ElementNode *pelmGlobal = m->pelmRoot->createChild("Global");
1302
1303 buildExtraData(*pelmGlobal, mapExtraDataItems);
1304
1305 xml::ElementNode *pelmMachineRegistry = pelmGlobal->createChild("MachineRegistry");
1306 for (MachinesRegistry::const_iterator it = llMachines.begin();
1307 it != llMachines.end();
1308 ++it)
1309 {
1310 // <MachineEntry uuid="{5f102a55-a51b-48e3-b45a-b28d33469488}" src="/mnt/innotek-unix/vbox-machines/Windows 5.1 XP 1 (Office 2003)/Windows 5.1 XP 1 (Office 2003).xml"/>
1311 const MachineRegistryEntry &mre = *it;
1312 xml::ElementNode *pelmMachineEntry = pelmMachineRegistry->createChild("MachineEntry");
1313 pelmMachineEntry->setAttribute("uuid", mre.uuid.toStringCurly());
1314 pelmMachineEntry->setAttribute("src", mre.strSettingsFile);
1315 }
1316
1317 buildMediaRegistry(*pelmGlobal, mediaRegistry);
1318
1319 xml::ElementNode *pelmNetserviceRegistry = pelmGlobal->createChild("NetserviceRegistry");
1320 xml::ElementNode *pelmDHCPServers = pelmNetserviceRegistry->createChild("DHCPServers");
1321 for (DHCPServersList::const_iterator it = llDhcpServers.begin();
1322 it != llDhcpServers.end();
1323 ++it)
1324 {
1325 const DHCPServer &d = *it;
1326 xml::ElementNode *pelmThis = pelmDHCPServers->createChild("DHCPServer");
1327 pelmThis->setAttribute("networkName", d.strNetworkName);
1328 pelmThis->setAttribute("IPAddress", d.strIPAddress);
1329 pelmThis->setAttribute("networkMask", d.strIPNetworkMask);
1330 pelmThis->setAttribute("lowerIP", d.strIPLower);
1331 pelmThis->setAttribute("upperIP", d.strIPUpper);
1332 pelmThis->setAttribute("enabled", (d.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
1333 }
1334
1335 xml::ElementNode *pelmSysProps = pelmGlobal->createChild("SystemProperties");
1336 if (systemProperties.strDefaultMachineFolder.length())
1337 pelmSysProps->setAttribute("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
1338 if (systemProperties.strDefaultHardDiskFolder.length())
1339 pelmSysProps->setAttribute("defaultHardDiskFolder", systemProperties.strDefaultHardDiskFolder);
1340 if (systemProperties.strDefaultHardDiskFormat.length())
1341 pelmSysProps->setAttribute("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
1342 if (systemProperties.strRemoteDisplayAuthLibrary.length())
1343 pelmSysProps->setAttribute("remoteDisplayAuthLibrary", systemProperties.strRemoteDisplayAuthLibrary);
1344 if (systemProperties.strWebServiceAuthLibrary.length())
1345 pelmSysProps->setAttribute("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
1346 pelmSysProps->setAttribute("LogHistoryCount", systemProperties.ulLogHistoryCount);
1347
1348 buildUSBDeviceFilters(*pelmGlobal->createChild("USBDeviceFilters"),
1349 host.llUSBDeviceFilters,
1350 true); // fHostMode
1351
1352 // now go write the XML
1353 xml::XmlFileWriter writer(*m->pDoc);
1354 writer.write(m->strFilename.c_str(), true /*fSafe*/);
1355
1356 m->fFileExists = true;
1357
1358 clearDocument();
1359}
1360
1361////////////////////////////////////////////////////////////////////////////////
1362//
1363// Machine XML structures
1364//
1365////////////////////////////////////////////////////////////////////////////////
1366
1367/**
1368 * Comparison operator. This gets called from MachineConfigFile::operator==,
1369 * which in turn gets called from Machine::saveSettings to figure out whether
1370 * machine settings have really changed and thus need to be written out to disk.
1371 */
1372bool VRDPSettings::operator==(const VRDPSettings& v) const
1373{
1374 return ( (this == &v)
1375 || ( (fEnabled == v.fEnabled)
1376 && (strPort == v.strPort)
1377 && (strNetAddress == v.strNetAddress)
1378 && (authType == v.authType)
1379 && (ulAuthTimeout == v.ulAuthTimeout)
1380 && (fAllowMultiConnection == v.fAllowMultiConnection)
1381 && (fReuseSingleConnection == v.fReuseSingleConnection)
1382 && (fVideoChannel == v.fVideoChannel)
1383 && (ulVideoChannelQuality == v.ulVideoChannelQuality)
1384 )
1385 );
1386}
1387
1388/**
1389 * Comparison operator. This gets called from MachineConfigFile::operator==,
1390 * which in turn gets called from Machine::saveSettings to figure out whether
1391 * machine settings have really changed and thus need to be written out to disk.
1392 */
1393bool BIOSSettings::operator==(const BIOSSettings &d) const
1394{
1395 return ( (this == &d)
1396 || ( fACPIEnabled == d.fACPIEnabled
1397 && fIOAPICEnabled == d.fIOAPICEnabled
1398 && fLogoFadeIn == d.fLogoFadeIn
1399 && fLogoFadeOut == d.fLogoFadeOut
1400 && ulLogoDisplayTime == d.ulLogoDisplayTime
1401 && strLogoImagePath == d.strLogoImagePath
1402 && biosBootMenuMode == d.biosBootMenuMode
1403 && fPXEDebugEnabled == d.fPXEDebugEnabled
1404 && llTimeOffset == d.llTimeOffset)
1405 );
1406}
1407
1408/**
1409 * Comparison operator. This gets called from MachineConfigFile::operator==,
1410 * which in turn gets called from Machine::saveSettings to figure out whether
1411 * machine settings have really changed and thus need to be written out to disk.
1412 */
1413bool USBController::operator==(const USBController &u) const
1414{
1415 return ( (this == &u)
1416 || ( (fEnabled == u.fEnabled)
1417 && (fEnabledEHCI == u.fEnabledEHCI)
1418 && (llDeviceFilters == u.llDeviceFilters)
1419 )
1420 );
1421}
1422
1423/**
1424 * Comparison operator. This gets called from MachineConfigFile::operator==,
1425 * which in turn gets called from Machine::saveSettings to figure out whether
1426 * machine settings have really changed and thus need to be written out to disk.
1427 */
1428bool NetworkAdapter::operator==(const NetworkAdapter &n) const
1429{
1430 return ( (this == &n)
1431 || ( (ulSlot == n.ulSlot)
1432 && (type == n.type)
1433 && (fEnabled == n.fEnabled)
1434 && (strMACAddress == n.strMACAddress)
1435 && (fCableConnected == n.fCableConnected)
1436 && (ulLineSpeed == n.ulLineSpeed)
1437 && (fTraceEnabled == n.fTraceEnabled)
1438 && (strTraceFile == n.strTraceFile)
1439 && (mode == n.mode)
1440 && (nat == n.nat)
1441 && (strName == n.strName)
1442 && (ulBootPriority == n.ulBootPriority)
1443 && (fHasDisabledNAT == n.fHasDisabledNAT)
1444 )
1445 );
1446}
1447
1448/**
1449 * Comparison operator. This gets called from MachineConfigFile::operator==,
1450 * which in turn gets called from Machine::saveSettings to figure out whether
1451 * machine settings have really changed and thus need to be written out to disk.
1452 */
1453bool SerialPort::operator==(const SerialPort &s) const
1454{
1455 return ( (this == &s)
1456 || ( (ulSlot == s.ulSlot)
1457 && (fEnabled == s.fEnabled)
1458 && (ulIOBase == s.ulIOBase)
1459 && (ulIRQ == s.ulIRQ)
1460 && (portMode == s.portMode)
1461 && (strPath == s.strPath)
1462 && (fServer == s.fServer)
1463 )
1464 );
1465}
1466
1467/**
1468 * Comparison operator. This gets called from MachineConfigFile::operator==,
1469 * which in turn gets called from Machine::saveSettings to figure out whether
1470 * machine settings have really changed and thus need to be written out to disk.
1471 */
1472bool ParallelPort::operator==(const ParallelPort &s) const
1473{
1474 return ( (this == &s)
1475 || ( (ulSlot == s.ulSlot)
1476 && (fEnabled == s.fEnabled)
1477 && (ulIOBase == s.ulIOBase)
1478 && (ulIRQ == s.ulIRQ)
1479 && (strPath == s.strPath)
1480 )
1481 );
1482}
1483
1484/**
1485 * Comparison operator. This gets called from MachineConfigFile::operator==,
1486 * which in turn gets called from Machine::saveSettings to figure out whether
1487 * machine settings have really changed and thus need to be written out to disk.
1488 */
1489bool SharedFolder::operator==(const SharedFolder &g) const
1490{
1491 return ( (this == &g)
1492 || ( (strName == g.strName)
1493 && (strHostPath == g.strHostPath)
1494 && (fWritable == g.fWritable)
1495 && (fAutoMount == g.fAutoMount)
1496 )
1497 );
1498}
1499
1500/**
1501 * Comparison operator. This gets called from MachineConfigFile::operator==,
1502 * which in turn gets called from Machine::saveSettings to figure out whether
1503 * machine settings have really changed and thus need to be written out to disk.
1504 */
1505bool GuestProperty::operator==(const GuestProperty &g) const
1506{
1507 return ( (this == &g)
1508 || ( (strName == g.strName)
1509 && (strValue == g.strValue)
1510 && (timestamp == g.timestamp)
1511 && (strFlags == g.strFlags)
1512 )
1513 );
1514}
1515
1516// use a define for the platform-dependent default value of
1517// hwvirt exclusivity, since we'll need to check that value
1518// in bumpSettingsVersionIfNeeded()
1519#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
1520 #define HWVIRTEXCLUSIVEDEFAULT false
1521#else
1522 #define HWVIRTEXCLUSIVEDEFAULT true
1523#endif
1524
1525/**
1526 * Hardware struct constructor.
1527 */
1528Hardware::Hardware()
1529 : strVersion("1"),
1530 fHardwareVirt(true),
1531 fHardwareVirtExclusive(HWVIRTEXCLUSIVEDEFAULT),
1532 fNestedPaging(true),
1533 fLargePages(false),
1534 fVPID(true),
1535 fHardwareVirtForce(false),
1536 fSyntheticCpu(false),
1537 fPAE(false),
1538 cCPUs(1),
1539 fCpuHotPlug(false),
1540 fHpetEnabled(false),
1541 ulCpuExecutionCap(100),
1542 ulMemorySizeMB((uint32_t)-1),
1543 ulVRAMSizeMB(8),
1544 cMonitors(1),
1545 fAccelerate3D(false),
1546 fAccelerate2DVideo(false),
1547 firmwareType(FirmwareType_BIOS),
1548 pointingHidType(PointingHidType_PS2Mouse),
1549 keyboardHidType(KeyboardHidType_PS2Keyboard),
1550 chipsetType(ChipsetType_PIIX3),
1551 clipboardMode(ClipboardMode_Bidirectional),
1552 ulMemoryBalloonSize(0),
1553 fPageFusionEnabled(false)
1554{
1555 mapBootOrder[0] = DeviceType_Floppy;
1556 mapBootOrder[1] = DeviceType_DVD;
1557 mapBootOrder[2] = DeviceType_HardDisk;
1558
1559 /* The default value for PAE depends on the host:
1560 * - 64 bits host -> always true
1561 * - 32 bits host -> true for Windows & Darwin (masked off if the host cpu doesn't support it anyway)
1562 */
1563#if HC_ARCH_BITS == 64 || defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN)
1564 fPAE = true;
1565#endif
1566}
1567
1568/**
1569 * Comparison operator. This gets called from MachineConfigFile::operator==,
1570 * which in turn gets called from Machine::saveSettings to figure out whether
1571 * machine settings have really changed and thus need to be written out to disk.
1572 */
1573bool Hardware::operator==(const Hardware& h) const
1574{
1575 return ( (this == &h)
1576 || ( (strVersion == h.strVersion)
1577 && (uuid == h.uuid)
1578 && (fHardwareVirt == h.fHardwareVirt)
1579 && (fHardwareVirtExclusive == h.fHardwareVirtExclusive)
1580 && (fNestedPaging == h.fNestedPaging)
1581 && (fLargePages == h.fLargePages)
1582 && (fVPID == h.fVPID)
1583 && (fHardwareVirtForce == h.fHardwareVirtForce)
1584 && (fSyntheticCpu == h.fSyntheticCpu)
1585 && (fPAE == h.fPAE)
1586 && (cCPUs == h.cCPUs)
1587 && (fCpuHotPlug == h.fCpuHotPlug)
1588 && (ulCpuExecutionCap == h.ulCpuExecutionCap)
1589 && (fHpetEnabled == h.fHpetEnabled)
1590 && (llCpus == h.llCpus)
1591 && (llCpuIdLeafs == h.llCpuIdLeafs)
1592 && (ulMemorySizeMB == h.ulMemorySizeMB)
1593 && (mapBootOrder == h.mapBootOrder)
1594 && (ulVRAMSizeMB == h.ulVRAMSizeMB)
1595 && (cMonitors == h.cMonitors)
1596 && (fAccelerate3D == h.fAccelerate3D)
1597 && (fAccelerate2DVideo == h.fAccelerate2DVideo)
1598 && (firmwareType == h.firmwareType)
1599 && (pointingHidType == h.pointingHidType)
1600 && (keyboardHidType == h.keyboardHidType)
1601 && (chipsetType == h.chipsetType)
1602 && (vrdpSettings == h.vrdpSettings)
1603 && (biosSettings == h.biosSettings)
1604 && (usbController == h.usbController)
1605 && (llNetworkAdapters == h.llNetworkAdapters)
1606 && (llSerialPorts == h.llSerialPorts)
1607 && (llParallelPorts == h.llParallelPorts)
1608 && (audioAdapter == h.audioAdapter)
1609 && (llSharedFolders == h.llSharedFolders)
1610 && (clipboardMode == h.clipboardMode)
1611 && (ulMemoryBalloonSize == h.ulMemoryBalloonSize)
1612 && (fPageFusionEnabled == h.fPageFusionEnabled)
1613 && (llGuestProperties == h.llGuestProperties)
1614 && (strNotificationPatterns == h.strNotificationPatterns)
1615 )
1616 );
1617}
1618
1619/**
1620 * Comparison operator. This gets called from MachineConfigFile::operator==,
1621 * which in turn gets called from Machine::saveSettings to figure out whether
1622 * machine settings have really changed and thus need to be written out to disk.
1623 */
1624bool AttachedDevice::operator==(const AttachedDevice &a) const
1625{
1626 return ( (this == &a)
1627 || ( (deviceType == a.deviceType)
1628 && (fPassThrough == a.fPassThrough)
1629 && (lPort == a.lPort)
1630 && (lDevice == a.lDevice)
1631 && (uuid == a.uuid)
1632 && (strHostDriveSrc == a.strHostDriveSrc)
1633 && (ulBandwidthLimit == a.ulBandwidthLimit)
1634 )
1635 );
1636}
1637
1638/**
1639 * Comparison operator. This gets called from MachineConfigFile::operator==,
1640 * which in turn gets called from Machine::saveSettings to figure out whether
1641 * machine settings have really changed and thus need to be written out to disk.
1642 */
1643bool StorageController::operator==(const StorageController &s) const
1644{
1645 return ( (this == &s)
1646 || ( (strName == s.strName)
1647 && (storageBus == s.storageBus)
1648 && (controllerType == s.controllerType)
1649 && (ulPortCount == s.ulPortCount)
1650 && (ulInstance == s.ulInstance)
1651 && (fUseHostIOCache == s.fUseHostIOCache)
1652 && (lIDE0MasterEmulationPort == s.lIDE0MasterEmulationPort)
1653 && (lIDE0SlaveEmulationPort == s.lIDE0SlaveEmulationPort)
1654 && (lIDE1MasterEmulationPort == s.lIDE1MasterEmulationPort)
1655 && (lIDE1SlaveEmulationPort == s.lIDE1SlaveEmulationPort)
1656 && (llAttachedDevices == s.llAttachedDevices)
1657 )
1658 );
1659}
1660
1661/**
1662 * Comparison operator. This gets called from MachineConfigFile::operator==,
1663 * which in turn gets called from Machine::saveSettings to figure out whether
1664 * machine settings have really changed and thus need to be written out to disk.
1665 */
1666bool Storage::operator==(const Storage &s) const
1667{
1668 return ( (this == &s)
1669 || (llStorageControllers == s.llStorageControllers) // deep compare
1670 );
1671}
1672
1673/**
1674 * Comparison operator. This gets called from MachineConfigFile::operator==,
1675 * which in turn gets called from Machine::saveSettings to figure out whether
1676 * machine settings have really changed and thus need to be written out to disk.
1677 */
1678bool Snapshot::operator==(const Snapshot &s) const
1679{
1680 return ( (this == &s)
1681 || ( (uuid == s.uuid)
1682 && (strName == s.strName)
1683 && (strDescription == s.strDescription)
1684 && (RTTimeSpecIsEqual(&timestamp, &s.timestamp))
1685 && (strStateFile == s.strStateFile)
1686 && (hardware == s.hardware) // deep compare
1687 && (storage == s.storage) // deep compare
1688 && (llChildSnapshots == s.llChildSnapshots) // deep compare
1689 )
1690 );
1691}
1692
1693/**
1694 * IoSettings constructor.
1695 */
1696IoSettings::IoSettings()
1697{
1698 fIoCacheEnabled = true;
1699 ulIoCacheSize = 5;
1700}
1701
1702////////////////////////////////////////////////////////////////////////////////
1703//
1704// MachineConfigFile
1705//
1706////////////////////////////////////////////////////////////////////////////////
1707
1708/**
1709 * Constructor.
1710 *
1711 * If pstrFilename is != NULL, this reads the given settings file into the member
1712 * variables and various substructures and lists. Otherwise, the member variables
1713 * are initialized with default values.
1714 *
1715 * Throws variants of xml::Error for I/O, XML and logical content errors, which
1716 * the caller should catch; if this constructor does not throw, then the member
1717 * variables contain meaningful values (either from the file or defaults).
1718 *
1719 * @param strFilename
1720 */
1721MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename)
1722 : ConfigFileBase(pstrFilename),
1723 fCurrentStateModified(true),
1724 fAborted(false)
1725{
1726 RTTimeNow(&timeLastStateChange);
1727
1728 if (pstrFilename)
1729 {
1730 // the ConfigFileBase constructor has loaded the XML file, so now
1731 // we need only analyze what is in there
1732
1733 xml::NodesLoop nlRootChildren(*m->pelmRoot);
1734 const xml::ElementNode *pelmRootChild;
1735 while ((pelmRootChild = nlRootChildren.forAllNodes()))
1736 {
1737 if (pelmRootChild->nameEquals("Machine"))
1738 readMachine(*pelmRootChild);
1739 }
1740
1741 // clean up memory allocated by XML engine
1742 clearDocument();
1743 }
1744}
1745
1746/**
1747 * Public routine which returns true if this machine config file can have its
1748 * own media registry (which is true for settings version v1.11 and higher,
1749 * i.e. files created by VirtualBox 4.0 and higher).
1750 * @return
1751 */
1752bool MachineConfigFile::canHaveOwnMediaRegistry() const
1753{
1754 return (m->sv >= SettingsVersion_v1_11);
1755}
1756
1757/**
1758 * Public routine which allows for importing machine XML from an external DOM tree.
1759 * Use this after having called the constructor with a NULL argument.
1760 *
1761 * This is used by the OVF code if a <vbox:Machine> element has been encountered
1762 * in an OVF VirtualSystem element.
1763 *
1764 * @param elmMachine
1765 */
1766void MachineConfigFile::importMachineXML(const xml::ElementNode &elmMachine)
1767{
1768 readMachine(elmMachine);
1769}
1770
1771/**
1772 * Comparison operator. This gets called from Machine::saveSettings to figure out
1773 * whether machine settings have really changed and thus need to be written out to disk.
1774 *
1775 * Even though this is called operator==, this does NOT compare all fields; the "equals"
1776 * should be understood as "has the same machine config as". The following fields are
1777 * NOT compared:
1778 * -- settings versions and file names inherited from ConfigFileBase;
1779 * -- fCurrentStateModified because that is considered separately in Machine::saveSettings!!
1780 *
1781 * The "deep" comparisons marked below will invoke the operator== functions of the
1782 * structs defined in this file, which may in turn go into comparing lists of
1783 * other structures. As a result, invoking this can be expensive, but it's
1784 * less expensive than writing out XML to disk.
1785 */
1786bool MachineConfigFile::operator==(const MachineConfigFile &c) const
1787{
1788 return ( (this == &c)
1789 || ( (uuid == c.uuid)
1790 && (machineUserData == c.machineUserData)
1791 && (strStateFile == c.strStateFile)
1792 && (uuidCurrentSnapshot == c.uuidCurrentSnapshot)
1793 // skip fCurrentStateModified!
1794 && (RTTimeSpecIsEqual(&timeLastStateChange, &c.timeLastStateChange))
1795 && (fAborted == c.fAborted)
1796 && (hardwareMachine == c.hardwareMachine) // this one's deep
1797 && (storageMachine == c.storageMachine) // this one's deep
1798 && (mediaRegistry == c.mediaRegistry) // this one's deep
1799 && (mapExtraDataItems == c.mapExtraDataItems) // this one's deep
1800 && (llFirstSnapshot == c.llFirstSnapshot) // this one's deep
1801 )
1802 );
1803}
1804
1805/**
1806 * Called from MachineConfigFile::readHardware() to read cpu information.
1807 * @param elmCpuid
1808 * @param ll
1809 */
1810void MachineConfigFile::readCpuTree(const xml::ElementNode &elmCpu,
1811 CpuList &ll)
1812{
1813 xml::NodesLoop nl1(elmCpu, "Cpu");
1814 const xml::ElementNode *pelmCpu;
1815 while ((pelmCpu = nl1.forAllNodes()))
1816 {
1817 Cpu cpu;
1818
1819 if (!pelmCpu->getAttributeValue("id", cpu.ulId))
1820 throw ConfigFileError(this, pelmCpu, N_("Required Cpu/@id attribute is missing"));
1821
1822 ll.push_back(cpu);
1823 }
1824}
1825
1826/**
1827 * Called from MachineConfigFile::readHardware() to cpuid information.
1828 * @param elmCpuid
1829 * @param ll
1830 */
1831void MachineConfigFile::readCpuIdTree(const xml::ElementNode &elmCpuid,
1832 CpuIdLeafsList &ll)
1833{
1834 xml::NodesLoop nl1(elmCpuid, "CpuIdLeaf");
1835 const xml::ElementNode *pelmCpuIdLeaf;
1836 while ((pelmCpuIdLeaf = nl1.forAllNodes()))
1837 {
1838 CpuIdLeaf leaf;
1839
1840 if (!pelmCpuIdLeaf->getAttributeValue("id", leaf.ulId))
1841 throw ConfigFileError(this, pelmCpuIdLeaf, N_("Required CpuId/@id attribute is missing"));
1842
1843 pelmCpuIdLeaf->getAttributeValue("eax", leaf.ulEax);
1844 pelmCpuIdLeaf->getAttributeValue("ebx", leaf.ulEbx);
1845 pelmCpuIdLeaf->getAttributeValue("ecx", leaf.ulEcx);
1846 pelmCpuIdLeaf->getAttributeValue("edx", leaf.ulEdx);
1847
1848 ll.push_back(leaf);
1849 }
1850}
1851
1852/**
1853 * Called from MachineConfigFile::readHardware() to network information.
1854 * @param elmNetwork
1855 * @param ll
1856 */
1857void MachineConfigFile::readNetworkAdapters(const xml::ElementNode &elmNetwork,
1858 NetworkAdaptersList &ll)
1859{
1860 xml::NodesLoop nl1(elmNetwork, "Adapter");
1861 const xml::ElementNode *pelmAdapter;
1862 while ((pelmAdapter = nl1.forAllNodes()))
1863 {
1864 NetworkAdapter nic;
1865
1866 if (!pelmAdapter->getAttributeValue("slot", nic.ulSlot))
1867 throw ConfigFileError(this, pelmAdapter, N_("Required Adapter/@slot attribute is missing"));
1868
1869 Utf8Str strTemp;
1870 if (pelmAdapter->getAttributeValue("type", strTemp))
1871 {
1872 if (strTemp == "Am79C970A")
1873 nic.type = NetworkAdapterType_Am79C970A;
1874 else if (strTemp == "Am79C973")
1875 nic.type = NetworkAdapterType_Am79C973;
1876 else if (strTemp == "82540EM")
1877 nic.type = NetworkAdapterType_I82540EM;
1878 else if (strTemp == "82543GC")
1879 nic.type = NetworkAdapterType_I82543GC;
1880 else if (strTemp == "82545EM")
1881 nic.type = NetworkAdapterType_I82545EM;
1882 else if (strTemp == "virtio")
1883 nic.type = NetworkAdapterType_Virtio;
1884 else
1885 throw ConfigFileError(this, pelmAdapter, N_("Invalid value '%s' in Adapter/@type attribute"), strTemp.c_str());
1886 }
1887
1888 pelmAdapter->getAttributeValue("enabled", nic.fEnabled);
1889 pelmAdapter->getAttributeValue("MACAddress", nic.strMACAddress);
1890 pelmAdapter->getAttributeValue("cable", nic.fCableConnected);
1891 pelmAdapter->getAttributeValue("speed", nic.ulLineSpeed);
1892 pelmAdapter->getAttributeValue("trace", nic.fTraceEnabled);
1893 pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
1894 pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority);
1895 pelmAdapter->getAttributeValue("bandwidthLimit", nic.ulBandwidthLimit);
1896
1897 xml::ElementNodesList llNetworkModes;
1898 pelmAdapter->getChildElements(llNetworkModes);
1899 xml::ElementNodesList::iterator it;
1900 /* We should have only active mode descriptor and disabled modes set */
1901 if (llNetworkModes.size() > 2)
1902 {
1903 throw ConfigFileError(this, pelmAdapter, N_("Invalid number of modes ('%d') attached to Adapter attribute"), llNetworkModes.size());
1904 }
1905 for (it = llNetworkModes.begin(); it != llNetworkModes.end(); ++it)
1906 {
1907 const xml::ElementNode *pelmNode = *it;
1908 if (pelmNode->nameEquals("DisabledModes"))
1909 {
1910 xml::ElementNodesList llDisabledNetworkModes;
1911 xml::ElementNodesList::iterator itDisabled;
1912 pelmNode->getChildElements(llDisabledNetworkModes);
1913 /* run over disabled list and load settings */
1914 for (itDisabled = llDisabledNetworkModes.begin();
1915 itDisabled != llDisabledNetworkModes.end(); ++itDisabled)
1916 {
1917 const xml::ElementNode *pelmDisabledNode = *itDisabled;
1918 readAttachedNetworkMode(*pelmDisabledNode, false, nic);
1919 }
1920 }
1921 else
1922 readAttachedNetworkMode(*pelmNode, true, nic);
1923 }
1924 // else: default is NetworkAttachmentType_Null
1925
1926 ll.push_back(nic);
1927 }
1928}
1929
1930void MachineConfigFile::readAttachedNetworkMode(const xml::ElementNode &elmMode, bool fEnabled, NetworkAdapter &nic)
1931{
1932 if (elmMode.nameEquals("NAT"))
1933 {
1934 if (fEnabled)
1935 nic.mode = NetworkAttachmentType_NAT;
1936
1937 nic.fHasDisabledNAT = (nic.mode != NetworkAttachmentType_NAT && !fEnabled);
1938 elmMode.getAttributeValue("network", nic.nat.strNetwork); // optional network name
1939 elmMode.getAttributeValue("hostip", nic.nat.strBindIP);
1940 elmMode.getAttributeValue("mtu", nic.nat.u32Mtu);
1941 elmMode.getAttributeValue("sockrcv", nic.nat.u32SockRcv);
1942 elmMode.getAttributeValue("socksnd", nic.nat.u32SockSnd);
1943 elmMode.getAttributeValue("tcprcv", nic.nat.u32TcpRcv);
1944 elmMode.getAttributeValue("tcpsnd", nic.nat.u32TcpSnd);
1945 const xml::ElementNode *pelmDNS;
1946 if ((pelmDNS = elmMode.findChildElement("DNS")))
1947 {
1948 pelmDNS->getAttributeValue("pass-domain", nic.nat.fDnsPassDomain);
1949 pelmDNS->getAttributeValue("use-proxy", nic.nat.fDnsProxy);
1950 pelmDNS->getAttributeValue("use-host-resolver", nic.nat.fDnsUseHostResolver);
1951 }
1952 const xml::ElementNode *pelmAlias;
1953 if ((pelmAlias = elmMode.findChildElement("Alias")))
1954 {
1955 pelmAlias->getAttributeValue("logging", nic.nat.fAliasLog);
1956 pelmAlias->getAttributeValue("proxy-only", nic.nat.fAliasProxyOnly);
1957 pelmAlias->getAttributeValue("use-same-ports", nic.nat.fAliasUseSamePorts);
1958 }
1959 const xml::ElementNode *pelmTFTP;
1960 if ((pelmTFTP = elmMode.findChildElement("TFTP")))
1961 {
1962 pelmTFTP->getAttributeValue("prefix", nic.nat.strTftpPrefix);
1963 pelmTFTP->getAttributeValue("boot-file", nic.nat.strTftpBootFile);
1964 pelmTFTP->getAttributeValue("next-server", nic.nat.strTftpNextServer);
1965 }
1966 xml::ElementNodesList plstNatPF;
1967 elmMode.getChildElements(plstNatPF, "Forwarding");
1968 for (xml::ElementNodesList::iterator pf = plstNatPF.begin(); pf != plstNatPF.end(); ++pf)
1969 {
1970 NATRule rule;
1971 uint32_t port = 0;
1972 (*pf)->getAttributeValue("name", rule.strName);
1973 (*pf)->getAttributeValue("proto", rule.u32Proto);
1974 (*pf)->getAttributeValue("hostip", rule.strHostIP);
1975 (*pf)->getAttributeValue("hostport", port);
1976 rule.u16HostPort = port;
1977 (*pf)->getAttributeValue("guestip", rule.strGuestIP);
1978 (*pf)->getAttributeValue("guestport", port);
1979 rule.u16GuestPort = port;
1980 nic.nat.llRules.push_back(rule);
1981 }
1982 }
1983 else if ( fEnabled
1984 && ( (elmMode.nameEquals("HostInterface"))
1985 || (elmMode.nameEquals("BridgedInterface")))
1986 )
1987 {
1988 nic.mode = NetworkAttachmentType_Bridged;
1989 elmMode.getAttributeValue("name", nic.strName); // optional host interface name
1990 }
1991 else if ( fEnabled
1992 && elmMode.nameEquals("InternalNetwork"))
1993 {
1994 nic.mode = NetworkAttachmentType_Internal;
1995 if (!elmMode.getAttributeValue("name", nic.strName)) // required network name
1996 throw ConfigFileError(this, &elmMode, N_("Required InternalNetwork/@name element is missing"));
1997 }
1998 else if ( fEnabled
1999 && elmMode.nameEquals("HostOnlyInterface"))
2000 {
2001 nic.mode = NetworkAttachmentType_HostOnly;
2002 if (!elmMode.getAttributeValue("name", nic.strName)) // required network name
2003 throw ConfigFileError(this, &elmMode, N_("Required HostOnlyInterface/@name element is missing"));
2004 }
2005#if defined(VBOX_WITH_VDE)
2006 else if ( fEnabled
2007 && elmMode.nameEquals("VDE"))
2008 {
2009 nic.mode = NetworkAttachmentType_VDE;
2010 elmMode.getAttributeValue("network", nic.strName); // optional network name
2011 }
2012#endif
2013}
2014
2015/**
2016 * Called from MachineConfigFile::readHardware() to read serial port information.
2017 * @param elmUART
2018 * @param ll
2019 */
2020void MachineConfigFile::readSerialPorts(const xml::ElementNode &elmUART,
2021 SerialPortsList &ll)
2022{
2023 xml::NodesLoop nl1(elmUART, "Port");
2024 const xml::ElementNode *pelmPort;
2025 while ((pelmPort = nl1.forAllNodes()))
2026 {
2027 SerialPort port;
2028 if (!pelmPort->getAttributeValue("slot", port.ulSlot))
2029 throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@slot attribute is missing"));
2030
2031 // slot must be unique
2032 for (SerialPortsList::const_iterator it = ll.begin();
2033 it != ll.end();
2034 ++it)
2035 if ((*it).ulSlot == port.ulSlot)
2036 throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in UART/Port/@slot attribute: value is not unique"), port.ulSlot);
2037
2038 if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
2039 throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@enabled attribute is missing"));
2040 if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
2041 throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IOBase attribute is missing"));
2042 if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
2043 throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IRQ attribute is missing"));
2044
2045 Utf8Str strPortMode;
2046 if (!pelmPort->getAttributeValue("hostMode", strPortMode))
2047 throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@hostMode attribute is missing"));
2048 if (strPortMode == "RawFile")
2049 port.portMode = PortMode_RawFile;
2050 else if (strPortMode == "HostPipe")
2051 port.portMode = PortMode_HostPipe;
2052 else if (strPortMode == "HostDevice")
2053 port.portMode = PortMode_HostDevice;
2054 else if (strPortMode == "Disconnected")
2055 port.portMode = PortMode_Disconnected;
2056 else
2057 throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
2058
2059 pelmPort->getAttributeValue("path", port.strPath);
2060 pelmPort->getAttributeValue("server", port.fServer);
2061
2062 ll.push_back(port);
2063 }
2064}
2065
2066/**
2067 * Called from MachineConfigFile::readHardware() to read parallel port information.
2068 * @param elmLPT
2069 * @param ll
2070 */
2071void MachineConfigFile::readParallelPorts(const xml::ElementNode &elmLPT,
2072 ParallelPortsList &ll)
2073{
2074 xml::NodesLoop nl1(elmLPT, "Port");
2075 const xml::ElementNode *pelmPort;
2076 while ((pelmPort = nl1.forAllNodes()))
2077 {
2078 ParallelPort port;
2079 if (!pelmPort->getAttributeValue("slot", port.ulSlot))
2080 throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@slot attribute is missing"));
2081
2082 // slot must be unique
2083 for (ParallelPortsList::const_iterator it = ll.begin();
2084 it != ll.end();
2085 ++it)
2086 if ((*it).ulSlot == port.ulSlot)
2087 throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in LPT/Port/@slot attribute: value is not unique"), port.ulSlot);
2088
2089 if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
2090 throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@enabled attribute is missing"));
2091 if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
2092 throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IOBase attribute is missing"));
2093 if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
2094 throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IRQ attribute is missing"));
2095
2096 pelmPort->getAttributeValue("path", port.strPath);
2097
2098 ll.push_back(port);
2099 }
2100}
2101
2102/**
2103 * Called from MachineConfigFile::readHardware() to read audio adapter information
2104 * and maybe fix driver information depending on the current host hardware.
2105 *
2106 * @param elmAudioAdapter "AudioAdapter" XML element.
2107 * @param hw
2108 */
2109void MachineConfigFile::readAudioAdapter(const xml::ElementNode &elmAudioAdapter,
2110 AudioAdapter &aa)
2111{
2112 elmAudioAdapter.getAttributeValue("enabled", aa.fEnabled);
2113
2114 Utf8Str strTemp;
2115 if (elmAudioAdapter.getAttributeValue("controller", strTemp))
2116 {
2117 if (strTemp == "SB16")
2118 aa.controllerType = AudioControllerType_SB16;
2119 else if (strTemp == "AC97")
2120 aa.controllerType = AudioControllerType_AC97;
2121 else if (strTemp == "HDA")
2122 aa.controllerType = AudioControllerType_HDA;
2123 else
2124 throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
2125 }
2126
2127 if (elmAudioAdapter.getAttributeValue("driver", strTemp))
2128 {
2129 // settings before 1.3 used lower case so make sure this is case-insensitive
2130 strTemp.toUpper();
2131 if (strTemp == "NULL")
2132 aa.driverType = AudioDriverType_Null;
2133 else if (strTemp == "WINMM")
2134 aa.driverType = AudioDriverType_WinMM;
2135 else if ( (strTemp == "DIRECTSOUND") || (strTemp == "DSOUND") )
2136 aa.driverType = AudioDriverType_DirectSound;
2137 else if (strTemp == "SOLAUDIO")
2138 aa.driverType = AudioDriverType_SolAudio;
2139 else if (strTemp == "ALSA")
2140 aa.driverType = AudioDriverType_ALSA;
2141 else if (strTemp == "PULSE")
2142 aa.driverType = AudioDriverType_Pulse;
2143 else if (strTemp == "OSS")
2144 aa.driverType = AudioDriverType_OSS;
2145 else if (strTemp == "COREAUDIO")
2146 aa.driverType = AudioDriverType_CoreAudio;
2147 else if (strTemp == "MMPM")
2148 aa.driverType = AudioDriverType_MMPM;
2149 else
2150 throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@driver attribute"), strTemp.c_str());
2151
2152 // now check if this is actually supported on the current host platform;
2153 // people might be opening a file created on a Windows host, and that
2154 // VM should still start on a Linux host
2155 if (!isAudioDriverAllowedOnThisHost(aa.driverType))
2156 aa.driverType = getHostDefaultAudioDriver();
2157 }
2158}
2159
2160/**
2161 * Called from MachineConfigFile::readHardware() to read guest property information.
2162 * @param elmGuestProperties
2163 * @param hw
2164 */
2165void MachineConfigFile::readGuestProperties(const xml::ElementNode &elmGuestProperties,
2166 Hardware &hw)
2167{
2168 xml::NodesLoop nl1(elmGuestProperties, "GuestProperty");
2169 const xml::ElementNode *pelmProp;
2170 while ((pelmProp = nl1.forAllNodes()))
2171 {
2172 GuestProperty prop;
2173 pelmProp->getAttributeValue("name", prop.strName);
2174 pelmProp->getAttributeValue("value", prop.strValue);
2175
2176 pelmProp->getAttributeValue("timestamp", prop.timestamp);
2177 pelmProp->getAttributeValue("flags", prop.strFlags);
2178 hw.llGuestProperties.push_back(prop);
2179 }
2180
2181 elmGuestProperties.getAttributeValue("notificationPatterns", hw.strNotificationPatterns);
2182}
2183
2184/**
2185 * Helper function to read attributes that are common to <SATAController> (pre-1.7)
2186 * and <StorageController>.
2187 * @param elmStorageController
2188 * @param strg
2189 */
2190void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
2191 StorageController &sctl)
2192{
2193 elmStorageController.getAttributeValue("PortCount", sctl.ulPortCount);
2194 elmStorageController.getAttributeValue("IDE0MasterEmulationPort", sctl.lIDE0MasterEmulationPort);
2195 elmStorageController.getAttributeValue("IDE0SlaveEmulationPort", sctl.lIDE0SlaveEmulationPort);
2196 elmStorageController.getAttributeValue("IDE1MasterEmulationPort", sctl.lIDE1MasterEmulationPort);
2197 elmStorageController.getAttributeValue("IDE1SlaveEmulationPort", sctl.lIDE1SlaveEmulationPort);
2198
2199 elmStorageController.getAttributeValue("useHostIOCache", sctl.fUseHostIOCache);
2200}
2201
2202/**
2203 * Reads in a <Hardware> block and stores it in the given structure. Used
2204 * both directly from readMachine and from readSnapshot, since snapshots
2205 * have their own hardware sections.
2206 *
2207 * For legacy pre-1.7 settings we also need a storage structure because
2208 * the IDE and SATA controllers used to be defined under <Hardware>.
2209 *
2210 * @param elmHardware
2211 * @param hw
2212 */
2213void MachineConfigFile::readHardware(const xml::ElementNode &elmHardware,
2214 Hardware &hw,
2215 Storage &strg)
2216{
2217 if (!elmHardware.getAttributeValue("version", hw.strVersion))
2218 {
2219 /* KLUDGE ALERT! For a while during the 3.1 development this was not
2220 written because it was thought to have a default value of "2". For
2221 sv <= 1.3 it defaults to "1" because the attribute didn't exist,
2222 while for 1.4+ it is sort of mandatory. Now, the buggy XML writer
2223 code only wrote 1.7 and later. So, if it's a 1.7+ XML file and it's
2224 missing the hardware version, then it probably should be "2" instead
2225 of "1". */
2226 if (m->sv < SettingsVersion_v1_7)
2227 hw.strVersion = "1";
2228 else
2229 hw.strVersion = "2";
2230 }
2231 Utf8Str strUUID;
2232 if (elmHardware.getAttributeValue("uuid", strUUID))
2233 parseUUID(hw.uuid, strUUID);
2234
2235 xml::NodesLoop nl1(elmHardware);
2236 const xml::ElementNode *pelmHwChild;
2237 while ((pelmHwChild = nl1.forAllNodes()))
2238 {
2239 if (pelmHwChild->nameEquals("CPU"))
2240 {
2241 if (!pelmHwChild->getAttributeValue("count", hw.cCPUs))
2242 {
2243 // pre-1.5 variant; not sure if this actually exists in the wild anywhere
2244 const xml::ElementNode *pelmCPUChild;
2245 if ((pelmCPUChild = pelmHwChild->findChildElement("CPUCount")))
2246 pelmCPUChild->getAttributeValue("count", hw.cCPUs);
2247 }
2248
2249 pelmHwChild->getAttributeValue("hotplug", hw.fCpuHotPlug);
2250 pelmHwChild->getAttributeValue("executionCap", hw.ulCpuExecutionCap);
2251
2252 const xml::ElementNode *pelmCPUChild;
2253 if (hw.fCpuHotPlug)
2254 {
2255 if ((pelmCPUChild = pelmHwChild->findChildElement("CpuTree")))
2256 readCpuTree(*pelmCPUChild, hw.llCpus);
2257 }
2258
2259 if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtEx")))
2260 {
2261 pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirt);
2262 pelmCPUChild->getAttributeValue("exclusive", hw.fHardwareVirtExclusive); // settings version 1.9
2263 }
2264 if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExNestedPaging")))
2265 pelmCPUChild->getAttributeValue("enabled", hw.fNestedPaging);
2266 if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExLargePages")))
2267 pelmCPUChild->getAttributeValue("enabled", hw.fLargePages);
2268 if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExVPID")))
2269 pelmCPUChild->getAttributeValue("enabled", hw.fVPID);
2270 if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtForce")))
2271 pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirtForce);
2272
2273 if (!(pelmCPUChild = pelmHwChild->findChildElement("PAE")))
2274 {
2275 /* The default for pre 3.1 was false, so we must respect that. */
2276 if (m->sv < SettingsVersion_v1_9)
2277 hw.fPAE = false;
2278 }
2279 else
2280 pelmCPUChild->getAttributeValue("enabled", hw.fPAE);
2281
2282 if ((pelmCPUChild = pelmHwChild->findChildElement("SyntheticCpu")))
2283 pelmCPUChild->getAttributeValue("enabled", hw.fSyntheticCpu);
2284 if ((pelmCPUChild = pelmHwChild->findChildElement("CpuIdTree")))
2285 readCpuIdTree(*pelmCPUChild, hw.llCpuIdLeafs);
2286 }
2287 else if (pelmHwChild->nameEquals("Memory"))
2288 {
2289 pelmHwChild->getAttributeValue("RAMSize", hw.ulMemorySizeMB);
2290 pelmHwChild->getAttributeValue("PageFusion", hw.fPageFusionEnabled);
2291 }
2292 else if (pelmHwChild->nameEquals("Firmware"))
2293 {
2294 Utf8Str strFirmwareType;
2295 if (pelmHwChild->getAttributeValue("type", strFirmwareType))
2296 {
2297 if ( (strFirmwareType == "BIOS")
2298 || (strFirmwareType == "1") // some trunk builds used the number here
2299 )
2300 hw.firmwareType = FirmwareType_BIOS;
2301 else if ( (strFirmwareType == "EFI")
2302 || (strFirmwareType == "2") // some trunk builds used the number here
2303 )
2304 hw.firmwareType = FirmwareType_EFI;
2305 else if ( strFirmwareType == "EFI32")
2306 hw.firmwareType = FirmwareType_EFI32;
2307 else if ( strFirmwareType == "EFI64")
2308 hw.firmwareType = FirmwareType_EFI64;
2309 else if ( strFirmwareType == "EFIDUAL")
2310 hw.firmwareType = FirmwareType_EFIDUAL;
2311 else
2312 throw ConfigFileError(this,
2313 pelmHwChild,
2314 N_("Invalid value '%s' in Firmware/@type"),
2315 strFirmwareType.c_str());
2316 }
2317 }
2318 else if (pelmHwChild->nameEquals("HID"))
2319 {
2320 Utf8Str strHidType;
2321 if (pelmHwChild->getAttributeValue("Keyboard", strHidType))
2322 {
2323 if (strHidType == "None")
2324 hw.keyboardHidType = KeyboardHidType_None;
2325 else if (strHidType == "USBKeyboard")
2326 hw.keyboardHidType = KeyboardHidType_USBKeyboard;
2327 else if (strHidType == "PS2Keyboard")
2328 hw.keyboardHidType = KeyboardHidType_PS2Keyboard;
2329 else if (strHidType == "ComboKeyboard")
2330 hw.keyboardHidType = KeyboardHidType_ComboKeyboard;
2331 else
2332 throw ConfigFileError(this,
2333 pelmHwChild,
2334 N_("Invalid value '%s' in HID/Keyboard/@type"),
2335 strHidType.c_str());
2336 }
2337 if (pelmHwChild->getAttributeValue("Pointing", strHidType))
2338 {
2339 if (strHidType == "None")
2340 hw.pointingHidType = PointingHidType_None;
2341 else if (strHidType == "USBMouse")
2342 hw.pointingHidType = PointingHidType_USBMouse;
2343 else if (strHidType == "USBTablet")
2344 hw.pointingHidType = PointingHidType_USBTablet;
2345 else if (strHidType == "PS2Mouse")
2346 hw.pointingHidType = PointingHidType_PS2Mouse;
2347 else if (strHidType == "ComboMouse")
2348 hw.pointingHidType = PointingHidType_ComboMouse;
2349 else
2350 throw ConfigFileError(this,
2351 pelmHwChild,
2352 N_("Invalid value '%s' in HID/Pointing/@type"),
2353 strHidType.c_str());
2354 }
2355 }
2356 else if (pelmHwChild->nameEquals("Chipset"))
2357 {
2358 Utf8Str strChipsetType;
2359 if (pelmHwChild->getAttributeValue("type", strChipsetType))
2360 {
2361 if (strChipsetType == "PIIX3")
2362 hw.chipsetType = ChipsetType_PIIX3;
2363 else if (strChipsetType == "ICH9")
2364 hw.chipsetType = ChipsetType_ICH9;
2365 else
2366 throw ConfigFileError(this,
2367 pelmHwChild,
2368 N_("Invalid value '%s' in Chipset/@type"),
2369 strChipsetType.c_str());
2370 }
2371 }
2372 else if (pelmHwChild->nameEquals("HPET"))
2373 {
2374 pelmHwChild->getAttributeValue("enabled", hw.fHpetEnabled);
2375 }
2376 else if (pelmHwChild->nameEquals("Boot"))
2377 {
2378 hw.mapBootOrder.clear();
2379
2380 xml::NodesLoop nl2(*pelmHwChild, "Order");
2381 const xml::ElementNode *pelmOrder;
2382 while ((pelmOrder = nl2.forAllNodes()))
2383 {
2384 uint32_t ulPos;
2385 Utf8Str strDevice;
2386 if (!pelmOrder->getAttributeValue("position", ulPos))
2387 throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@position attribute is missing"));
2388
2389 if ( ulPos < 1
2390 || ulPos > SchemaDefs::MaxBootPosition
2391 )
2392 throw ConfigFileError(this,
2393 pelmOrder,
2394 N_("Invalid value '%RU32' in Boot/Order/@position: must be greater than 0 and less than %RU32"),
2395 ulPos,
2396 SchemaDefs::MaxBootPosition + 1);
2397 // XML is 1-based but internal data is 0-based
2398 --ulPos;
2399
2400 if (hw.mapBootOrder.find(ulPos) != hw.mapBootOrder.end())
2401 throw ConfigFileError(this, pelmOrder, N_("Invalid value '%RU32' in Boot/Order/@position: value is not unique"), ulPos);
2402
2403 if (!pelmOrder->getAttributeValue("device", strDevice))
2404 throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@device attribute is missing"));
2405
2406 DeviceType_T type;
2407 if (strDevice == "None")
2408 type = DeviceType_Null;
2409 else if (strDevice == "Floppy")
2410 type = DeviceType_Floppy;
2411 else if (strDevice == "DVD")
2412 type = DeviceType_DVD;
2413 else if (strDevice == "HardDisk")
2414 type = DeviceType_HardDisk;
2415 else if (strDevice == "Network")
2416 type = DeviceType_Network;
2417 else
2418 throw ConfigFileError(this, pelmOrder, N_("Invalid value '%s' in Boot/Order/@device attribute"), strDevice.c_str());
2419 hw.mapBootOrder[ulPos] = type;
2420 }
2421 }
2422 else if (pelmHwChild->nameEquals("Display"))
2423 {
2424 pelmHwChild->getAttributeValue("VRAMSize", hw.ulVRAMSizeMB);
2425 if (!pelmHwChild->getAttributeValue("monitorCount", hw.cMonitors))
2426 pelmHwChild->getAttributeValue("MonitorCount", hw.cMonitors); // pre-v1.5 variant
2427 if (!pelmHwChild->getAttributeValue("accelerate3D", hw.fAccelerate3D))
2428 pelmHwChild->getAttributeValue("Accelerate3D", hw.fAccelerate3D); // pre-v1.5 variant
2429 pelmHwChild->getAttributeValue("accelerate2DVideo", hw.fAccelerate2DVideo);
2430 }
2431 else if (pelmHwChild->nameEquals("RemoteDisplay"))
2432 {
2433 pelmHwChild->getAttributeValue("enabled", hw.vrdpSettings.fEnabled);
2434 pelmHwChild->getAttributeValue("port", hw.vrdpSettings.strPort);
2435 pelmHwChild->getAttributeValue("netAddress", hw.vrdpSettings.strNetAddress);
2436
2437 Utf8Str strAuthType;
2438 if (pelmHwChild->getAttributeValue("authType", strAuthType))
2439 {
2440 // settings before 1.3 used lower case so make sure this is case-insensitive
2441 strAuthType.toUpper();
2442 if (strAuthType == "NULL")
2443 hw.vrdpSettings.authType = VRDPAuthType_Null;
2444 else if (strAuthType == "GUEST")
2445 hw.vrdpSettings.authType = VRDPAuthType_Guest;
2446 else if (strAuthType == "EXTERNAL")
2447 hw.vrdpSettings.authType = VRDPAuthType_External;
2448 else
2449 throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in RemoteDisplay/@authType attribute"), strAuthType.c_str());
2450 }
2451
2452 pelmHwChild->getAttributeValue("authTimeout", hw.vrdpSettings.ulAuthTimeout);
2453 pelmHwChild->getAttributeValue("allowMultiConnection", hw.vrdpSettings.fAllowMultiConnection);
2454 pelmHwChild->getAttributeValue("reuseSingleConnection", hw.vrdpSettings.fReuseSingleConnection);
2455
2456 const xml::ElementNode *pelmVideoChannel;
2457 if ((pelmVideoChannel = pelmHwChild->findChildElement("VideoChannel")))
2458 {
2459 pelmVideoChannel->getAttributeValue("enabled", hw.vrdpSettings.fVideoChannel);
2460 pelmVideoChannel->getAttributeValue("quality", hw.vrdpSettings.ulVideoChannelQuality);
2461 hw.vrdpSettings.ulVideoChannelQuality = RT_CLAMP(hw.vrdpSettings.ulVideoChannelQuality, 10, 100);
2462 }
2463 }
2464 else if (pelmHwChild->nameEquals("BIOS"))
2465 {
2466 const xml::ElementNode *pelmBIOSChild;
2467 if ((pelmBIOSChild = pelmHwChild->findChildElement("ACPI")))
2468 pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fACPIEnabled);
2469 if ((pelmBIOSChild = pelmHwChild->findChildElement("IOAPIC")))
2470 pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fIOAPICEnabled);
2471 if ((pelmBIOSChild = pelmHwChild->findChildElement("Logo")))
2472 {
2473 pelmBIOSChild->getAttributeValue("fadeIn", hw.biosSettings.fLogoFadeIn);
2474 pelmBIOSChild->getAttributeValue("fadeOut", hw.biosSettings.fLogoFadeOut);
2475 pelmBIOSChild->getAttributeValue("displayTime", hw.biosSettings.ulLogoDisplayTime);
2476 pelmBIOSChild->getAttributeValue("imagePath", hw.biosSettings.strLogoImagePath);
2477 }
2478 if ((pelmBIOSChild = pelmHwChild->findChildElement("BootMenu")))
2479 {
2480 Utf8Str strBootMenuMode;
2481 if (pelmBIOSChild->getAttributeValue("mode", strBootMenuMode))
2482 {
2483 // settings before 1.3 used lower case so make sure this is case-insensitive
2484 strBootMenuMode.toUpper();
2485 if (strBootMenuMode == "DISABLED")
2486 hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_Disabled;
2487 else if (strBootMenuMode == "MENUONLY")
2488 hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MenuOnly;
2489 else if (strBootMenuMode == "MESSAGEANDMENU")
2490 hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MessageAndMenu;
2491 else
2492 throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' in BootMenu/@mode attribute"), strBootMenuMode.c_str());
2493 }
2494 }
2495 if ((pelmBIOSChild = pelmHwChild->findChildElement("PXEDebug")))
2496 pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fPXEDebugEnabled);
2497 if ((pelmBIOSChild = pelmHwChild->findChildElement("TimeOffset")))
2498 pelmBIOSChild->getAttributeValue("value", hw.biosSettings.llTimeOffset);
2499
2500 // legacy BIOS/IDEController (pre 1.7)
2501 if ( (m->sv < SettingsVersion_v1_7)
2502 && ((pelmBIOSChild = pelmHwChild->findChildElement("IDEController")))
2503 )
2504 {
2505 StorageController sctl;
2506 sctl.strName = "IDE Controller";
2507 sctl.storageBus = StorageBus_IDE;
2508
2509 Utf8Str strType;
2510 if (pelmBIOSChild->getAttributeValue("type", strType))
2511 {
2512 if (strType == "PIIX3")
2513 sctl.controllerType = StorageControllerType_PIIX3;
2514 else if (strType == "PIIX4")
2515 sctl.controllerType = StorageControllerType_PIIX4;
2516 else if (strType == "ICH6")
2517 sctl.controllerType = StorageControllerType_ICH6;
2518 else
2519 throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' for IDEController/@type attribute"), strType.c_str());
2520 }
2521 sctl.ulPortCount = 2;
2522 strg.llStorageControllers.push_back(sctl);
2523 }
2524 }
2525 else if (pelmHwChild->nameEquals("USBController"))
2526 {
2527 pelmHwChild->getAttributeValue("enabled", hw.usbController.fEnabled);
2528 pelmHwChild->getAttributeValue("enabledEhci", hw.usbController.fEnabledEHCI);
2529
2530 readUSBDeviceFilters(*pelmHwChild,
2531 hw.usbController.llDeviceFilters);
2532 }
2533 else if ( (m->sv < SettingsVersion_v1_7)
2534 && (pelmHwChild->nameEquals("SATAController"))
2535 )
2536 {
2537 bool f;
2538 if ( (pelmHwChild->getAttributeValue("enabled", f))
2539 && (f)
2540 )
2541 {
2542 StorageController sctl;
2543 sctl.strName = "SATA Controller";
2544 sctl.storageBus = StorageBus_SATA;
2545 sctl.controllerType = StorageControllerType_IntelAhci;
2546
2547 readStorageControllerAttributes(*pelmHwChild, sctl);
2548
2549 strg.llStorageControllers.push_back(sctl);
2550 }
2551 }
2552 else if (pelmHwChild->nameEquals("Network"))
2553 readNetworkAdapters(*pelmHwChild, hw.llNetworkAdapters);
2554 else if (pelmHwChild->nameEquals("RTC"))
2555 {
2556 Utf8Str strLocalOrUTC;
2557 machineUserData.fRTCUseUTC = pelmHwChild->getAttributeValue("localOrUTC", strLocalOrUTC)
2558 && strLocalOrUTC == "UTC";
2559 }
2560 else if ( (pelmHwChild->nameEquals("UART"))
2561 || (pelmHwChild->nameEquals("Uart")) // used before 1.3
2562 )
2563 readSerialPorts(*pelmHwChild, hw.llSerialPorts);
2564 else if ( (pelmHwChild->nameEquals("LPT"))
2565 || (pelmHwChild->nameEquals("Lpt")) // used before 1.3
2566 )
2567 readParallelPorts(*pelmHwChild, hw.llParallelPorts);
2568 else if (pelmHwChild->nameEquals("AudioAdapter"))
2569 readAudioAdapter(*pelmHwChild, hw.audioAdapter);
2570 else if (pelmHwChild->nameEquals("SharedFolders"))
2571 {
2572 xml::NodesLoop nl2(*pelmHwChild, "SharedFolder");
2573 const xml::ElementNode *pelmFolder;
2574 while ((pelmFolder = nl2.forAllNodes()))
2575 {
2576 SharedFolder sf;
2577 pelmFolder->getAttributeValue("name", sf.strName);
2578 pelmFolder->getAttributeValue("hostPath", sf.strHostPath);
2579 pelmFolder->getAttributeValue("writable", sf.fWritable);
2580 pelmFolder->getAttributeValue("autoMount", sf.fAutoMount);
2581 hw.llSharedFolders.push_back(sf);
2582 }
2583 }
2584 else if (pelmHwChild->nameEquals("Clipboard"))
2585 {
2586 Utf8Str strTemp;
2587 if (pelmHwChild->getAttributeValue("mode", strTemp))
2588 {
2589 if (strTemp == "Disabled")
2590 hw.clipboardMode = ClipboardMode_Disabled;
2591 else if (strTemp == "HostToGuest")
2592 hw.clipboardMode = ClipboardMode_HostToGuest;
2593 else if (strTemp == "GuestToHost")
2594 hw.clipboardMode = ClipboardMode_GuestToHost;
2595 else if (strTemp == "Bidirectional")
2596 hw.clipboardMode = ClipboardMode_Bidirectional;
2597 else
2598 throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Clipboard/@mode attribute"), strTemp.c_str());
2599 }
2600 }
2601 else if (pelmHwChild->nameEquals("Guest"))
2602 {
2603 if (!pelmHwChild->getAttributeValue("memoryBalloonSize", hw.ulMemoryBalloonSize))
2604 pelmHwChild->getAttributeValue("MemoryBalloonSize", hw.ulMemoryBalloonSize); // used before 1.3
2605 }
2606 else if (pelmHwChild->nameEquals("GuestProperties"))
2607 readGuestProperties(*pelmHwChild, hw);
2608 else if (pelmHwChild->nameEquals("IO"))
2609 {
2610 const xml::ElementNode *pelmIoChild;
2611
2612 if ((pelmIoChild = pelmHwChild->findChildElement("IoCache")))
2613 {
2614 pelmIoChild->getAttributeValue("enabled", hw.ioSettings.fIoCacheEnabled);
2615 pelmIoChild->getAttributeValue("size", hw.ioSettings.ulIoCacheSize);
2616 }
2617 }
2618 }
2619
2620 if (hw.ulMemorySizeMB == (uint32_t)-1)
2621 throw ConfigFileError(this, &elmHardware, N_("Required Memory/@RAMSize element/attribute is missing"));
2622}
2623
2624/**
2625 * This gets called instead of readStorageControllers() for legacy pre-1.7 settings
2626 * files which have a <HardDiskAttachments> node and storage controller settings
2627 * hidden in the <Hardware> settings. We set the StorageControllers fields just the
2628 * same, just from different sources.
2629 * @param elmHardware <Hardware> XML node.
2630 * @param elmHardDiskAttachments <HardDiskAttachments> XML node.
2631 * @param strg
2632 */
2633void MachineConfigFile::readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments,
2634 Storage &strg)
2635{
2636 StorageController *pIDEController = NULL;
2637 StorageController *pSATAController = NULL;
2638
2639 for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
2640 it != strg.llStorageControllers.end();
2641 ++it)
2642 {
2643 StorageController &s = *it;
2644 if (s.storageBus == StorageBus_IDE)
2645 pIDEController = &s;
2646 else if (s.storageBus == StorageBus_SATA)
2647 pSATAController = &s;
2648 }
2649
2650 xml::NodesLoop nl1(elmHardDiskAttachments, "HardDiskAttachment");
2651 const xml::ElementNode *pelmAttachment;
2652 while ((pelmAttachment = nl1.forAllNodes()))
2653 {
2654 AttachedDevice att;
2655 Utf8Str strUUID, strBus;
2656
2657 if (!pelmAttachment->getAttributeValue("hardDisk", strUUID))
2658 throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@hardDisk attribute is missing"));
2659 parseUUID(att.uuid, strUUID);
2660
2661 if (!pelmAttachment->getAttributeValue("bus", strBus))
2662 throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@bus attribute is missing"));
2663 // pre-1.7 'channel' is now port
2664 if (!pelmAttachment->getAttributeValue("channel", att.lPort))
2665 throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@channel attribute is missing"));
2666 // pre-1.7 'device' is still device
2667 if (!pelmAttachment->getAttributeValue("device", att.lDevice))
2668 throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@device attribute is missing"));
2669
2670 att.deviceType = DeviceType_HardDisk;
2671
2672 if (strBus == "IDE")
2673 {
2674 if (!pIDEController)
2675 throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'IDE' but cannot find IDE controller"));
2676 pIDEController->llAttachedDevices.push_back(att);
2677 }
2678 else if (strBus == "SATA")
2679 {
2680 if (!pSATAController)
2681 throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'SATA' but cannot find SATA controller"));
2682 pSATAController->llAttachedDevices.push_back(att);
2683 }
2684 else
2685 throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus attribute has illegal value '%s'"), strBus.c_str());
2686 }
2687}
2688
2689/**
2690 * Reads in a <StorageControllers> block and stores it in the given Storage structure.
2691 * Used both directly from readMachine and from readSnapshot, since snapshots
2692 * have their own storage controllers sections.
2693 *
2694 * This is only called for settings version 1.7 and above; see readHardDiskAttachments_pre1_7()
2695 * for earlier versions.
2696 *
2697 * @param elmStorageControllers
2698 */
2699void MachineConfigFile::readStorageControllers(const xml::ElementNode &elmStorageControllers,
2700 Storage &strg)
2701{
2702 xml::NodesLoop nlStorageControllers(elmStorageControllers, "StorageController");
2703 const xml::ElementNode *pelmController;
2704 while ((pelmController = nlStorageControllers.forAllNodes()))
2705 {
2706 StorageController sctl;
2707
2708 if (!pelmController->getAttributeValue("name", sctl.strName))
2709 throw ConfigFileError(this, pelmController, N_("Required StorageController/@name attribute is missing"));
2710 // canonicalize storage controller names for configs in the switchover
2711 // period.
2712 if (m->sv < SettingsVersion_v1_9)
2713 {
2714 if (sctl.strName == "IDE")
2715 sctl.strName = "IDE Controller";
2716 else if (sctl.strName == "SATA")
2717 sctl.strName = "SATA Controller";
2718 else if (sctl.strName == "SCSI")
2719 sctl.strName = "SCSI Controller";
2720 }
2721
2722 pelmController->getAttributeValue("Instance", sctl.ulInstance);
2723 // default from constructor is 0
2724
2725 Utf8Str strType;
2726 if (!pelmController->getAttributeValue("type", strType))
2727 throw ConfigFileError(this, pelmController, N_("Required StorageController/@type attribute is missing"));
2728
2729 if (strType == "AHCI")
2730 {
2731 sctl.storageBus = StorageBus_SATA;
2732 sctl.controllerType = StorageControllerType_IntelAhci;
2733 }
2734 else if (strType == "LsiLogic")
2735 {
2736 sctl.storageBus = StorageBus_SCSI;
2737 sctl.controllerType = StorageControllerType_LsiLogic;
2738 }
2739 else if (strType == "BusLogic")
2740 {
2741 sctl.storageBus = StorageBus_SCSI;
2742 sctl.controllerType = StorageControllerType_BusLogic;
2743 }
2744 else if (strType == "PIIX3")
2745 {
2746 sctl.storageBus = StorageBus_IDE;
2747 sctl.controllerType = StorageControllerType_PIIX3;
2748 }
2749 else if (strType == "PIIX4")
2750 {
2751 sctl.storageBus = StorageBus_IDE;
2752 sctl.controllerType = StorageControllerType_PIIX4;
2753 }
2754 else if (strType == "ICH6")
2755 {
2756 sctl.storageBus = StorageBus_IDE;
2757 sctl.controllerType = StorageControllerType_ICH6;
2758 }
2759 else if ( (m->sv >= SettingsVersion_v1_9)
2760 && (strType == "I82078")
2761 )
2762 {
2763 sctl.storageBus = StorageBus_Floppy;
2764 sctl.controllerType = StorageControllerType_I82078;
2765 }
2766 else if (strType == "LsiLogicSas")
2767 {
2768 sctl.storageBus = StorageBus_SAS;
2769 sctl.controllerType = StorageControllerType_LsiLogicSas;
2770 }
2771 else
2772 throw ConfigFileError(this, pelmController, N_("Invalid value '%s' for StorageController/@type attribute"), strType.c_str());
2773
2774 readStorageControllerAttributes(*pelmController, sctl);
2775
2776 xml::NodesLoop nlAttached(*pelmController, "AttachedDevice");
2777 const xml::ElementNode *pelmAttached;
2778 while ((pelmAttached = nlAttached.forAllNodes()))
2779 {
2780 AttachedDevice att;
2781 Utf8Str strTemp;
2782 pelmAttached->getAttributeValue("type", strTemp);
2783
2784 if (strTemp == "HardDisk")
2785 att.deviceType = DeviceType_HardDisk;
2786 else if (m->sv >= SettingsVersion_v1_9)
2787 {
2788 // starting with 1.9 we list DVD and floppy drive info + attachments under <StorageControllers>
2789 if (strTemp == "DVD")
2790 {
2791 att.deviceType = DeviceType_DVD;
2792 pelmAttached->getAttributeValue("passthrough", att.fPassThrough);
2793 }
2794 else if (strTemp == "Floppy")
2795 att.deviceType = DeviceType_Floppy;
2796 }
2797
2798 if (att.deviceType != DeviceType_Null)
2799 {
2800 const xml::ElementNode *pelmImage;
2801 // all types can have images attached, but for HardDisk it's required
2802 if (!(pelmImage = pelmAttached->findChildElement("Image")))
2803 {
2804 if (att.deviceType == DeviceType_HardDisk)
2805 throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image element is missing"));
2806 else
2807 {
2808 // DVDs and floppies can also have <HostDrive> instead of <Image>
2809 const xml::ElementNode *pelmHostDrive;
2810 if ((pelmHostDrive = pelmAttached->findChildElement("HostDrive")))
2811 if (!pelmHostDrive->getAttributeValue("src", att.strHostDriveSrc))
2812 throw ConfigFileError(this, pelmHostDrive, N_("Required AttachedDevice/HostDrive/@src attribute is missing"));
2813 }
2814 }
2815 else
2816 {
2817 if (!pelmImage->getAttributeValue("uuid", strTemp))
2818 throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image/@uuid attribute is missing"));
2819 parseUUID(att.uuid, strTemp);
2820 }
2821
2822 if (!pelmAttached->getAttributeValue("port", att.lPort))
2823 throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@port attribute is missing"));
2824 if (!pelmAttached->getAttributeValue("device", att.lDevice))
2825 throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@device attribute is missing"));
2826
2827 pelmAttached->getAttributeValue("bandwidthLimit", att.ulBandwidthLimit);
2828 sctl.llAttachedDevices.push_back(att);
2829 }
2830 }
2831
2832 strg.llStorageControllers.push_back(sctl);
2833 }
2834}
2835
2836/**
2837 * This gets called for legacy pre-1.9 settings files after having parsed the
2838 * <Hardware> and <StorageControllers> sections to parse <Hardware> once more
2839 * for the <DVDDrive> and <FloppyDrive> sections.
2840 *
2841 * Before settings version 1.9, DVD and floppy drives were specified separately
2842 * under <Hardware>; we then need this extra loop to make sure the storage
2843 * controller structs are already set up so we can add stuff to them.
2844 *
2845 * @param elmHardware
2846 * @param strg
2847 */
2848void MachineConfigFile::readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware,
2849 Storage &strg)
2850{
2851 xml::NodesLoop nl1(elmHardware);
2852 const xml::ElementNode *pelmHwChild;
2853 while ((pelmHwChild = nl1.forAllNodes()))
2854 {
2855 if (pelmHwChild->nameEquals("DVDDrive"))
2856 {
2857 // create a DVD "attached device" and attach it to the existing IDE controller
2858 AttachedDevice att;
2859 att.deviceType = DeviceType_DVD;
2860 // legacy DVD drive is always secondary master (port 1, device 0)
2861 att.lPort = 1;
2862 att.lDevice = 0;
2863 pelmHwChild->getAttributeValue("passthrough", att.fPassThrough);
2864
2865 const xml::ElementNode *pDriveChild;
2866 Utf8Str strTmp;
2867 if ( ((pDriveChild = pelmHwChild->findChildElement("Image")))
2868 && (pDriveChild->getAttributeValue("uuid", strTmp))
2869 )
2870 parseUUID(att.uuid, strTmp);
2871 else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
2872 pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
2873
2874 // find the IDE controller and attach the DVD drive
2875 bool fFound = false;
2876 for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
2877 it != strg.llStorageControllers.end();
2878 ++it)
2879 {
2880 StorageController &sctl = *it;
2881 if (sctl.storageBus == StorageBus_IDE)
2882 {
2883 sctl.llAttachedDevices.push_back(att);
2884 fFound = true;
2885 break;
2886 }
2887 }
2888
2889 if (!fFound)
2890 throw ConfigFileError(this, pelmHwChild, N_("Internal error: found DVD drive but IDE controller does not exist"));
2891 // shouldn't happen because pre-1.9 settings files always had at least one IDE controller in the settings
2892 // which should have gotten parsed in <StorageControllers> before this got called
2893 }
2894 else if (pelmHwChild->nameEquals("FloppyDrive"))
2895 {
2896 bool fEnabled;
2897 if ( (pelmHwChild->getAttributeValue("enabled", fEnabled))
2898 && (fEnabled)
2899 )
2900 {
2901 // create a new floppy controller and attach a floppy "attached device"
2902 StorageController sctl;
2903 sctl.strName = "Floppy Controller";
2904 sctl.storageBus = StorageBus_Floppy;
2905 sctl.controllerType = StorageControllerType_I82078;
2906 sctl.ulPortCount = 1;
2907
2908 AttachedDevice att;
2909 att.deviceType = DeviceType_Floppy;
2910 att.lPort = 0;
2911 att.lDevice = 0;
2912
2913 const xml::ElementNode *pDriveChild;
2914 Utf8Str strTmp;
2915 if ( ((pDriveChild = pelmHwChild->findChildElement("Image")))
2916 && (pDriveChild->getAttributeValue("uuid", strTmp))
2917 )
2918 parseUUID(att.uuid, strTmp);
2919 else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
2920 pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
2921
2922 // store attachment with controller
2923 sctl.llAttachedDevices.push_back(att);
2924 // store controller with storage
2925 strg.llStorageControllers.push_back(sctl);
2926 }
2927 }
2928 }
2929}
2930
2931/**
2932 * Called initially for the <Snapshot> element under <Machine>, if present,
2933 * to store the snapshot's data into the given Snapshot structure (which is
2934 * then the one in the Machine struct). This might then recurse if
2935 * a <Snapshots> (plural) element is found in the snapshot, which should
2936 * contain a list of child snapshots; such lists are maintained in the
2937 * Snapshot structure.
2938 *
2939 * @param elmSnapshot
2940 * @param snap
2941 */
2942void MachineConfigFile::readSnapshot(const xml::ElementNode &elmSnapshot,
2943 Snapshot &snap)
2944{
2945 Utf8Str strTemp;
2946
2947 if (!elmSnapshot.getAttributeValue("uuid", strTemp))
2948 throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@uuid attribute is missing"));
2949 parseUUID(snap.uuid, strTemp);
2950
2951 if (!elmSnapshot.getAttributeValue("name", snap.strName))
2952 throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@name attribute is missing"));
2953
2954 // earlier 3.1 trunk builds had a bug and added Description as an attribute, read it silently and write it back as an element
2955 elmSnapshot.getAttributeValue("Description", snap.strDescription);
2956
2957 if (!elmSnapshot.getAttributeValue("timeStamp", strTemp))
2958 throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@timeStamp attribute is missing"));
2959 parseTimestamp(snap.timestamp, strTemp);
2960
2961 elmSnapshot.getAttributeValue("stateFile", snap.strStateFile); // online snapshots only
2962
2963 // parse Hardware before the other elements because other things depend on it
2964 const xml::ElementNode *pelmHardware;
2965 if (!(pelmHardware = elmSnapshot.findChildElement("Hardware")))
2966 throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@Hardware element is missing"));
2967 readHardware(*pelmHardware, snap.hardware, snap.storage);
2968
2969 xml::NodesLoop nlSnapshotChildren(elmSnapshot);
2970 const xml::ElementNode *pelmSnapshotChild;
2971 while ((pelmSnapshotChild = nlSnapshotChildren.forAllNodes()))
2972 {
2973 if (pelmSnapshotChild->nameEquals("Description"))
2974 snap.strDescription = pelmSnapshotChild->getValue();
2975 else if ( (m->sv < SettingsVersion_v1_7)
2976 && (pelmSnapshotChild->nameEquals("HardDiskAttachments"))
2977 )
2978 readHardDiskAttachments_pre1_7(*pelmSnapshotChild, snap.storage);
2979 else if ( (m->sv >= SettingsVersion_v1_7)
2980 && (pelmSnapshotChild->nameEquals("StorageControllers"))
2981 )
2982 readStorageControllers(*pelmSnapshotChild, snap.storage);
2983 else if (pelmSnapshotChild->nameEquals("Snapshots"))
2984 {
2985 xml::NodesLoop nlChildSnapshots(*pelmSnapshotChild);
2986 const xml::ElementNode *pelmChildSnapshot;
2987 while ((pelmChildSnapshot = nlChildSnapshots.forAllNodes()))
2988 {
2989 if (pelmChildSnapshot->nameEquals("Snapshot"))
2990 {
2991 Snapshot child;
2992 readSnapshot(*pelmChildSnapshot, child);
2993 snap.llChildSnapshots.push_back(child);
2994 }
2995 }
2996 }
2997 }
2998
2999 if (m->sv < SettingsVersion_v1_9)
3000 // go through Hardware once more to repair the settings controller structures
3001 // with data from old DVDDrive and FloppyDrive elements
3002 readDVDAndFloppies_pre1_9(*pelmHardware, snap.storage);
3003}
3004
3005const struct {
3006 const char *pcszOld;
3007 const char *pcszNew;
3008} aConvertOSTypes[] =
3009{
3010 { "unknown", "Other" },
3011 { "dos", "DOS" },
3012 { "win31", "Windows31" },
3013 { "win95", "Windows95" },
3014 { "win98", "Windows98" },
3015 { "winme", "WindowsMe" },
3016 { "winnt4", "WindowsNT4" },
3017 { "win2k", "Windows2000" },
3018 { "winxp", "WindowsXP" },
3019 { "win2k3", "Windows2003" },
3020 { "winvista", "WindowsVista" },
3021 { "win2k8", "Windows2008" },
3022 { "os2warp3", "OS2Warp3" },
3023 { "os2warp4", "OS2Warp4" },
3024 { "os2warp45", "OS2Warp45" },
3025 { "ecs", "OS2eCS" },
3026 { "linux22", "Linux22" },
3027 { "linux24", "Linux24" },
3028 { "linux26", "Linux26" },
3029 { "archlinux", "ArchLinux" },
3030 { "debian", "Debian" },
3031 { "opensuse", "OpenSUSE" },
3032 { "fedoracore", "Fedora" },
3033 { "gentoo", "Gentoo" },
3034 { "mandriva", "Mandriva" },
3035 { "redhat", "RedHat" },
3036 { "ubuntu", "Ubuntu" },
3037 { "xandros", "Xandros" },
3038 { "freebsd", "FreeBSD" },
3039 { "openbsd", "OpenBSD" },
3040 { "netbsd", "NetBSD" },
3041 { "netware", "Netware" },
3042 { "solaris", "Solaris" },
3043 { "opensolaris", "OpenSolaris" },
3044 { "l4", "L4" }
3045};
3046
3047void MachineConfigFile::convertOldOSType_pre1_5(Utf8Str &str)
3048{
3049 for (unsigned u = 0;
3050 u < RT_ELEMENTS(aConvertOSTypes);
3051 ++u)
3052 {
3053 if (str == aConvertOSTypes[u].pcszOld)
3054 {
3055 str = aConvertOSTypes[u].pcszNew;
3056 break;
3057 }
3058 }
3059}
3060
3061/**
3062 * Called from the constructor to actually read in the <Machine> element
3063 * of a machine config file.
3064 * @param elmMachine
3065 */
3066void MachineConfigFile::readMachine(const xml::ElementNode &elmMachine)
3067{
3068 Utf8Str strUUID;
3069 if ( (elmMachine.getAttributeValue("uuid", strUUID))
3070 && (elmMachine.getAttributeValue("name", machineUserData.strName))
3071 )
3072 {
3073 parseUUID(uuid, strUUID);
3074
3075 elmMachine.getAttributeValue("nameSync", machineUserData.fNameSync);
3076
3077 Utf8Str str;
3078 elmMachine.getAttributeValue("Description", machineUserData.strDescription);
3079
3080 elmMachine.getAttributeValue("OSType", machineUserData.strOsType);
3081 if (m->sv < SettingsVersion_v1_5)
3082 convertOldOSType_pre1_5(machineUserData.strOsType);
3083
3084 elmMachine.getAttributeValue("stateFile", strStateFile);
3085 if (elmMachine.getAttributeValue("currentSnapshot", str))
3086 parseUUID(uuidCurrentSnapshot, str);
3087 elmMachine.getAttributeValue("snapshotFolder", machineUserData.strSnapshotFolder);
3088 if (!elmMachine.getAttributeValue("currentStateModified", fCurrentStateModified))
3089 fCurrentStateModified = true;
3090 if (elmMachine.getAttributeValue("lastStateChange", str))
3091 parseTimestamp(timeLastStateChange, str);
3092 // constructor has called RTTimeNow(&timeLastStateChange) before
3093
3094 // parse Hardware before the other elements because other things depend on it
3095 const xml::ElementNode *pelmHardware;
3096 if (!(pelmHardware = elmMachine.findChildElement("Hardware")))
3097 throw ConfigFileError(this, &elmMachine, N_("Required Machine/Hardware element is missing"));
3098 readHardware(*pelmHardware, hardwareMachine, storageMachine);
3099
3100 xml::NodesLoop nlRootChildren(elmMachine);
3101 const xml::ElementNode *pelmMachineChild;
3102 while ((pelmMachineChild = nlRootChildren.forAllNodes()))
3103 {
3104 if (pelmMachineChild->nameEquals("ExtraData"))
3105 readExtraData(*pelmMachineChild,
3106 mapExtraDataItems);
3107 else if ( (m->sv < SettingsVersion_v1_7)
3108 && (pelmMachineChild->nameEquals("HardDiskAttachments"))
3109 )
3110 readHardDiskAttachments_pre1_7(*pelmMachineChild, storageMachine);
3111 else if ( (m->sv >= SettingsVersion_v1_7)
3112 && (pelmMachineChild->nameEquals("StorageControllers"))
3113 )
3114 readStorageControllers(*pelmMachineChild, storageMachine);
3115 else if (pelmMachineChild->nameEquals("Snapshot"))
3116 {
3117 Snapshot snap;
3118 // this will recurse into child snapshots, if necessary
3119 readSnapshot(*pelmMachineChild, snap);
3120 llFirstSnapshot.push_back(snap);
3121 }
3122 else if (pelmMachineChild->nameEquals("Description"))
3123 machineUserData.strDescription = pelmMachineChild->getValue();
3124 else if (pelmMachineChild->nameEquals("Teleporter"))
3125 {
3126 pelmMachineChild->getAttributeValue("enabled", machineUserData.fTeleporterEnabled);
3127 pelmMachineChild->getAttributeValue("port", machineUserData.uTeleporterPort);
3128 pelmMachineChild->getAttributeValue("address", machineUserData.strTeleporterAddress);
3129 pelmMachineChild->getAttributeValue("password", machineUserData.strTeleporterPassword);
3130 }
3131 else if (pelmMachineChild->nameEquals("FaultTolerance"))
3132 {
3133 Utf8Str strFaultToleranceSate;
3134 if (pelmMachineChild->getAttributeValue("state", strFaultToleranceSate))
3135 {
3136 if (strFaultToleranceSate == "master")
3137 machineUserData.enmFaultToleranceState = FaultToleranceState_Master;
3138 else
3139 if (strFaultToleranceSate == "standby")
3140 machineUserData.enmFaultToleranceState = FaultToleranceState_Standby;
3141 else
3142 machineUserData.enmFaultToleranceState = FaultToleranceState_Inactive;
3143 }
3144 pelmMachineChild->getAttributeValue("port", machineUserData.uFaultTolerancePort);
3145 pelmMachineChild->getAttributeValue("address", machineUserData.strFaultToleranceAddress);
3146 pelmMachineChild->getAttributeValue("interval", machineUserData.uFaultToleranceInterval);
3147 pelmMachineChild->getAttributeValue("password", machineUserData.strFaultTolerancePassword);
3148 }
3149 else if (pelmMachineChild->nameEquals("MediaRegistry"))
3150 readMediaRegistry(*pelmMachineChild, mediaRegistry);
3151 }
3152
3153 if (m->sv < SettingsVersion_v1_9)
3154 // go through Hardware once more to repair the settings controller structures
3155 // with data from old DVDDrive and FloppyDrive elements
3156 readDVDAndFloppies_pre1_9(*pelmHardware, storageMachine);
3157 }
3158 else
3159 throw ConfigFileError(this, &elmMachine, N_("Required Machine/@uuid or @name attributes is missing"));
3160}
3161
3162/**
3163 * Creates a <Hardware> node under elmParent and then writes out the XML
3164 * keys under that. Called for both the <Machine> node and for snapshots.
3165 * @param elmParent
3166 * @param st
3167 */
3168void MachineConfigFile::buildHardwareXML(xml::ElementNode &elmParent,
3169 const Hardware &hw,
3170 const Storage &strg)
3171{
3172 xml::ElementNode *pelmHardware = elmParent.createChild("Hardware");
3173
3174 if (m->sv >= SettingsVersion_v1_4)
3175 pelmHardware->setAttribute("version", hw.strVersion);
3176 if ( (m->sv >= SettingsVersion_v1_9)
3177 && (!hw.uuid.isEmpty())
3178 )
3179 pelmHardware->setAttribute("uuid", hw.uuid.toStringCurly());
3180
3181 xml::ElementNode *pelmCPU = pelmHardware->createChild("CPU");
3182
3183 xml::ElementNode *pelmHwVirtEx = pelmCPU->createChild("HardwareVirtEx");
3184 pelmHwVirtEx->setAttribute("enabled", hw.fHardwareVirt);
3185 if (m->sv >= SettingsVersion_v1_9)
3186 pelmHwVirtEx->setAttribute("exclusive", hw.fHardwareVirtExclusive);
3187
3188 pelmCPU->createChild("HardwareVirtExNestedPaging")->setAttribute("enabled", hw.fNestedPaging);
3189 pelmCPU->createChild("HardwareVirtExVPID")->setAttribute("enabled", hw.fVPID);
3190 pelmCPU->createChild("PAE")->setAttribute("enabled", hw.fPAE);
3191
3192 if (hw.fSyntheticCpu)
3193 pelmCPU->createChild("SyntheticCpu")->setAttribute("enabled", hw.fSyntheticCpu);
3194 pelmCPU->setAttribute("count", hw.cCPUs);
3195 if (hw.ulCpuExecutionCap != 100)
3196 pelmCPU->setAttribute("executionCap", hw.ulCpuExecutionCap);
3197
3198 if (hw.fLargePages)
3199 pelmCPU->createChild("HardwareVirtExLargePages")->setAttribute("enabled", hw.fLargePages);
3200
3201 if (m->sv >= SettingsVersion_v1_9)
3202 pelmCPU->createChild("HardwareVirtForce")->setAttribute("enabled", hw.fHardwareVirtForce);
3203
3204 if (m->sv >= SettingsVersion_v1_10)
3205 {
3206 pelmCPU->setAttribute("hotplug", hw.fCpuHotPlug);
3207
3208 xml::ElementNode *pelmCpuTree = NULL;
3209 for (CpuList::const_iterator it = hw.llCpus.begin();
3210 it != hw.llCpus.end();
3211 ++it)
3212 {
3213 const Cpu &cpu = *it;
3214
3215 if (pelmCpuTree == NULL)
3216 pelmCpuTree = pelmCPU->createChild("CpuTree");
3217
3218 xml::ElementNode *pelmCpu = pelmCpuTree->createChild("Cpu");
3219 pelmCpu->setAttribute("id", cpu.ulId);
3220 }
3221 }
3222
3223 xml::ElementNode *pelmCpuIdTree = NULL;
3224 for (CpuIdLeafsList::const_iterator it = hw.llCpuIdLeafs.begin();
3225 it != hw.llCpuIdLeafs.end();
3226 ++it)
3227 {
3228 const CpuIdLeaf &leaf = *it;
3229
3230 if (pelmCpuIdTree == NULL)
3231 pelmCpuIdTree = pelmCPU->createChild("CpuIdTree");
3232
3233 xml::ElementNode *pelmCpuIdLeaf = pelmCpuIdTree->createChild("CpuIdLeaf");
3234 pelmCpuIdLeaf->setAttribute("id", leaf.ulId);
3235 pelmCpuIdLeaf->setAttribute("eax", leaf.ulEax);
3236 pelmCpuIdLeaf->setAttribute("ebx", leaf.ulEbx);
3237 pelmCpuIdLeaf->setAttribute("ecx", leaf.ulEcx);
3238 pelmCpuIdLeaf->setAttribute("edx", leaf.ulEdx);
3239 }
3240
3241 xml::ElementNode *pelmMemory = pelmHardware->createChild("Memory");
3242 pelmMemory->setAttribute("RAMSize", hw.ulMemorySizeMB);
3243 if (m->sv >= SettingsVersion_v1_10)
3244 {
3245 pelmMemory->setAttribute("PageFusion", hw.fPageFusionEnabled);
3246 }
3247
3248 if ( (m->sv >= SettingsVersion_v1_9)
3249 && (hw.firmwareType >= FirmwareType_EFI)
3250 )
3251 {
3252 xml::ElementNode *pelmFirmware = pelmHardware->createChild("Firmware");
3253 const char *pcszFirmware;
3254
3255 switch (hw.firmwareType)
3256 {
3257 case FirmwareType_EFI: pcszFirmware = "EFI"; break;
3258 case FirmwareType_EFI32: pcszFirmware = "EFI32"; break;
3259 case FirmwareType_EFI64: pcszFirmware = "EFI64"; break;
3260 case FirmwareType_EFIDUAL: pcszFirmware = "EFIDUAL"; break;
3261 default: pcszFirmware = "None"; break;
3262 }
3263 pelmFirmware->setAttribute("type", pcszFirmware);
3264 }
3265
3266 if ( (m->sv >= SettingsVersion_v1_10)
3267 )
3268 {
3269 xml::ElementNode *pelmHid = pelmHardware->createChild("HID");
3270 const char *pcszHid;
3271
3272 switch (hw.pointingHidType)
3273 {
3274 case PointingHidType_USBMouse: pcszHid = "USBMouse"; break;
3275 case PointingHidType_USBTablet: pcszHid = "USBTablet"; break;
3276 case PointingHidType_PS2Mouse: pcszHid = "PS2Mouse"; break;
3277 case PointingHidType_ComboMouse: pcszHid = "ComboMouse"; break;
3278 case PointingHidType_None: pcszHid = "None"; break;
3279 default: Assert(false); pcszHid = "PS2Mouse"; break;
3280 }
3281 pelmHid->setAttribute("Pointing", pcszHid);
3282
3283 switch (hw.keyboardHidType)
3284 {
3285 case KeyboardHidType_USBKeyboard: pcszHid = "USBKeyboard"; break;
3286 case KeyboardHidType_PS2Keyboard: pcszHid = "PS2Keyboard"; break;
3287 case KeyboardHidType_ComboKeyboard: pcszHid = "ComboKeyboard"; break;
3288 case KeyboardHidType_None: pcszHid = "None"; break;
3289 default: Assert(false); pcszHid = "PS2Keyboard"; break;
3290 }
3291 pelmHid->setAttribute("Keyboard", pcszHid);
3292 }
3293
3294 if ( (m->sv >= SettingsVersion_v1_10)
3295 )
3296 {
3297 xml::ElementNode *pelmHpet = pelmHardware->createChild("HPET");
3298 pelmHpet->setAttribute("enabled", hw.fHpetEnabled);
3299 }
3300
3301 if ( (m->sv >= SettingsVersion_v1_11)
3302 )
3303 {
3304 xml::ElementNode *pelmChipset = pelmHardware->createChild("Chipset");
3305 const char *pcszChipset;
3306
3307 switch (hw.chipsetType)
3308 {
3309 case ChipsetType_PIIX3: pcszChipset = "PIIX3"; break;
3310 case ChipsetType_ICH9: pcszChipset = "ICH9"; break;
3311 default: Assert(false); pcszChipset = "PIIX3"; break;
3312 }
3313 pelmChipset->setAttribute("type", pcszChipset);
3314 }
3315
3316 xml::ElementNode *pelmBoot = pelmHardware->createChild("Boot");
3317 for (BootOrderMap::const_iterator it = hw.mapBootOrder.begin();
3318 it != hw.mapBootOrder.end();
3319 ++it)
3320 {
3321 uint32_t i = it->first;
3322 DeviceType_T type = it->second;
3323 const char *pcszDevice;
3324
3325 switch (type)
3326 {
3327 case DeviceType_Floppy: pcszDevice = "Floppy"; break;
3328 case DeviceType_DVD: pcszDevice = "DVD"; break;
3329 case DeviceType_HardDisk: pcszDevice = "HardDisk"; break;
3330 case DeviceType_Network: pcszDevice = "Network"; break;
3331 default: /*case DeviceType_Null:*/ pcszDevice = "None"; break;
3332 }
3333
3334 xml::ElementNode *pelmOrder = pelmBoot->createChild("Order");
3335 pelmOrder->setAttribute("position",
3336 i + 1); // XML is 1-based but internal data is 0-based
3337 pelmOrder->setAttribute("device", pcszDevice);
3338 }
3339
3340 xml::ElementNode *pelmDisplay = pelmHardware->createChild("Display");
3341 pelmDisplay->setAttribute("VRAMSize", hw.ulVRAMSizeMB);
3342 pelmDisplay->setAttribute("monitorCount", hw.cMonitors);
3343 pelmDisplay->setAttribute("accelerate3D", hw.fAccelerate3D);
3344
3345 if (m->sv >= SettingsVersion_v1_8)
3346 pelmDisplay->setAttribute("accelerate2DVideo", hw.fAccelerate2DVideo);
3347
3348 xml::ElementNode *pelmVRDP = pelmHardware->createChild("RemoteDisplay");
3349 pelmVRDP->setAttribute("enabled", hw.vrdpSettings.fEnabled);
3350 Utf8Str strPort = hw.vrdpSettings.strPort;
3351 if (!strPort.length())
3352 strPort = "3389";
3353 pelmVRDP->setAttribute("port", strPort);
3354 if (hw.vrdpSettings.strNetAddress.length())
3355 pelmVRDP->setAttribute("netAddress", hw.vrdpSettings.strNetAddress);
3356 const char *pcszAuthType;
3357 switch (hw.vrdpSettings.authType)
3358 {
3359 case VRDPAuthType_Guest: pcszAuthType = "Guest"; break;
3360 case VRDPAuthType_External: pcszAuthType = "External"; break;
3361 default: /*case VRDPAuthType_Null:*/ pcszAuthType = "Null"; break;
3362 }
3363 pelmVRDP->setAttribute("authType", pcszAuthType);
3364
3365 if (hw.vrdpSettings.ulAuthTimeout != 0)
3366 pelmVRDP->setAttribute("authTimeout", hw.vrdpSettings.ulAuthTimeout);
3367 if (hw.vrdpSettings.fAllowMultiConnection)
3368 pelmVRDP->setAttribute("allowMultiConnection", hw.vrdpSettings.fAllowMultiConnection);
3369 if (hw.vrdpSettings.fReuseSingleConnection)
3370 pelmVRDP->setAttribute("reuseSingleConnection", hw.vrdpSettings.fReuseSingleConnection);
3371
3372 if (m->sv >= SettingsVersion_v1_10)
3373 {
3374 xml::ElementNode *pelmVideoChannel = pelmVRDP->createChild("VideoChannel");
3375 pelmVideoChannel->setAttribute("enabled", hw.vrdpSettings.fVideoChannel);
3376 pelmVideoChannel->setAttribute("quality", hw.vrdpSettings.ulVideoChannelQuality);
3377 }
3378
3379 xml::ElementNode *pelmBIOS = pelmHardware->createChild("BIOS");
3380 pelmBIOS->createChild("ACPI")->setAttribute("enabled", hw.biosSettings.fACPIEnabled);
3381 pelmBIOS->createChild("IOAPIC")->setAttribute("enabled", hw.biosSettings.fIOAPICEnabled);
3382
3383 xml::ElementNode *pelmLogo = pelmBIOS->createChild("Logo");
3384 pelmLogo->setAttribute("fadeIn", hw.biosSettings.fLogoFadeIn);
3385 pelmLogo->setAttribute("fadeOut", hw.biosSettings.fLogoFadeOut);
3386 pelmLogo->setAttribute("displayTime", hw.biosSettings.ulLogoDisplayTime);
3387 if (hw.biosSettings.strLogoImagePath.length())
3388 pelmLogo->setAttribute("imagePath", hw.biosSettings.strLogoImagePath);
3389
3390 const char *pcszBootMenu;
3391 switch (hw.biosSettings.biosBootMenuMode)
3392 {
3393 case BIOSBootMenuMode_Disabled: pcszBootMenu = "Disabled"; break;
3394 case BIOSBootMenuMode_MenuOnly: pcszBootMenu = "MenuOnly"; break;
3395 default: /*BIOSBootMenuMode_MessageAndMenu*/ pcszBootMenu = "MessageAndMenu"; break;
3396 }
3397 pelmBIOS->createChild("BootMenu")->setAttribute("mode", pcszBootMenu);
3398 pelmBIOS->createChild("TimeOffset")->setAttribute("value", hw.biosSettings.llTimeOffset);
3399 pelmBIOS->createChild("PXEDebug")->setAttribute("enabled", hw.biosSettings.fPXEDebugEnabled);
3400
3401 if (m->sv < SettingsVersion_v1_9)
3402 {
3403 // settings formats before 1.9 had separate DVDDrive and FloppyDrive items under Hardware;
3404 // run thru the storage controllers to see if we have a DVD or floppy drives
3405 size_t cDVDs = 0;
3406 size_t cFloppies = 0;
3407
3408 xml::ElementNode *pelmDVD = pelmHardware->createChild("DVDDrive");
3409 xml::ElementNode *pelmFloppy = pelmHardware->createChild("FloppyDrive");
3410
3411 for (StorageControllersList::const_iterator it = strg.llStorageControllers.begin();
3412 it != strg.llStorageControllers.end();
3413 ++it)
3414 {
3415 const StorageController &sctl = *it;
3416 // in old settings format, the DVD drive could only have been under the IDE controller
3417 if (sctl.storageBus == StorageBus_IDE)
3418 {
3419 for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
3420 it2 != sctl.llAttachedDevices.end();
3421 ++it2)
3422 {
3423 const AttachedDevice &att = *it2;
3424 if (att.deviceType == DeviceType_DVD)
3425 {
3426 if (cDVDs > 0)
3427 throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one DVD drive with old settings format"));
3428
3429 ++cDVDs;
3430
3431 pelmDVD->setAttribute("passthrough", att.fPassThrough);
3432 if (!att.uuid.isEmpty())
3433 pelmDVD->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
3434 else if (att.strHostDriveSrc.length())
3435 pelmDVD->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
3436 }
3437 }
3438 }
3439 else if (sctl.storageBus == StorageBus_Floppy)
3440 {
3441 size_t cFloppiesHere = sctl.llAttachedDevices.size();
3442 if (cFloppiesHere > 1)
3443 throw ConfigFileError(this, NULL, N_("Internal error: floppy controller cannot have more than one device attachment"));
3444 if (cFloppiesHere)
3445 {
3446 const AttachedDevice &att = sctl.llAttachedDevices.front();
3447 pelmFloppy->setAttribute("enabled", true);
3448 if (!att.uuid.isEmpty())
3449 pelmFloppy->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
3450 else if (att.strHostDriveSrc.length())
3451 pelmFloppy->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
3452 }
3453
3454 cFloppies += cFloppiesHere;
3455 }
3456 }
3457
3458 if (cFloppies == 0)
3459 pelmFloppy->setAttribute("enabled", false);
3460 else if (cFloppies > 1)
3461 throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one floppy drive with old settings format"));
3462 }
3463
3464 xml::ElementNode *pelmUSB = pelmHardware->createChild("USBController");
3465 pelmUSB->setAttribute("enabled", hw.usbController.fEnabled);
3466 pelmUSB->setAttribute("enabledEhci", hw.usbController.fEnabledEHCI);
3467
3468 buildUSBDeviceFilters(*pelmUSB,
3469 hw.usbController.llDeviceFilters,
3470 false); // fHostMode
3471
3472 xml::ElementNode *pelmNetwork = pelmHardware->createChild("Network");
3473 for (NetworkAdaptersList::const_iterator it = hw.llNetworkAdapters.begin();
3474 it != hw.llNetworkAdapters.end();
3475 ++it)
3476 {
3477 const NetworkAdapter &nic = *it;
3478
3479 xml::ElementNode *pelmAdapter = pelmNetwork->createChild("Adapter");
3480 pelmAdapter->setAttribute("slot", nic.ulSlot);
3481 pelmAdapter->setAttribute("enabled", nic.fEnabled);
3482 pelmAdapter->setAttribute("MACAddress", nic.strMACAddress);
3483 pelmAdapter->setAttribute("cable", nic.fCableConnected);
3484 pelmAdapter->setAttribute("speed", nic.ulLineSpeed);
3485 if (nic.ulBootPriority != 0)
3486 {
3487 pelmAdapter->setAttribute("bootPriority", nic.ulBootPriority);
3488 }
3489 if (nic.fTraceEnabled)
3490 {
3491 pelmAdapter->setAttribute("trace", nic.fTraceEnabled);
3492 pelmAdapter->setAttribute("tracefile", nic.strTraceFile);
3493 }
3494 if (nic.ulBandwidthLimit)
3495 pelmAdapter->setAttribute("bandwidthLimit", nic.ulBandwidthLimit);
3496
3497 const char *pcszType;
3498 switch (nic.type)
3499 {
3500 case NetworkAdapterType_Am79C973: pcszType = "Am79C973"; break;
3501 case NetworkAdapterType_I82540EM: pcszType = "82540EM"; break;
3502 case NetworkAdapterType_I82543GC: pcszType = "82543GC"; break;
3503 case NetworkAdapterType_I82545EM: pcszType = "82545EM"; break;
3504 case NetworkAdapterType_Virtio: pcszType = "virtio"; break;
3505 default: /*case NetworkAdapterType_Am79C970A:*/ pcszType = "Am79C970A"; break;
3506 }
3507 pelmAdapter->setAttribute("type", pcszType);
3508
3509 xml::ElementNode *pelmNAT;
3510 if (m->sv < SettingsVersion_v1_10)
3511 {
3512 switch (nic.mode)
3513 {
3514 case NetworkAttachmentType_NAT:
3515 pelmNAT = pelmAdapter->createChild("NAT");
3516 if (nic.nat.strNetwork.length())
3517 pelmNAT->setAttribute("network", nic.nat.strNetwork);
3518 break;
3519
3520 case NetworkAttachmentType_Bridged:
3521 pelmAdapter->createChild("BridgedInterface")->setAttribute("name", nic.strName);
3522 break;
3523
3524 case NetworkAttachmentType_Internal:
3525 pelmAdapter->createChild("InternalNetwork")->setAttribute("name", nic.strName);
3526 break;
3527
3528 case NetworkAttachmentType_HostOnly:
3529 pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strName);
3530 break;
3531
3532#if defined(VBOX_WITH_VDE)
3533 case NetworkAttachmentType_VDE:
3534 pelmAdapter->createChild("VDE")->setAttribute("network", nic.strName);
3535 break;
3536#endif
3537
3538 default: /*case NetworkAttachmentType_Null:*/
3539 break;
3540 }
3541 }
3542 else
3543 {
3544 /* m->sv >= SettingsVersion_v1_10 */
3545 xml::ElementNode *pelmDisabledNode= NULL;
3546 if (nic.fHasDisabledNAT)
3547 pelmDisabledNode = pelmAdapter->createChild("DisabledModes");
3548 if (nic.fHasDisabledNAT)
3549 buildNetworkXML(NetworkAttachmentType_NAT, *pelmDisabledNode, nic);
3550 buildNetworkXML(nic.mode, *pelmAdapter, nic);
3551 }
3552 }
3553
3554 xml::ElementNode *pelmPorts = pelmHardware->createChild("UART");
3555 for (SerialPortsList::const_iterator it = hw.llSerialPorts.begin();
3556 it != hw.llSerialPorts.end();
3557 ++it)
3558 {
3559 const SerialPort &port = *it;
3560 xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
3561 pelmPort->setAttribute("slot", port.ulSlot);
3562 pelmPort->setAttribute("enabled", port.fEnabled);
3563 pelmPort->setAttributeHex("IOBase", port.ulIOBase);
3564 pelmPort->setAttribute("IRQ", port.ulIRQ);
3565
3566 const char *pcszHostMode;
3567 switch (port.portMode)
3568 {
3569 case PortMode_HostPipe: pcszHostMode = "HostPipe"; break;
3570 case PortMode_HostDevice: pcszHostMode = "HostDevice"; break;
3571 case PortMode_RawFile: pcszHostMode = "RawFile"; break;
3572 default: /*case PortMode_Disconnected:*/ pcszHostMode = "Disconnected"; break;
3573 }
3574 switch (port.portMode)
3575 {
3576 case PortMode_HostPipe:
3577 pelmPort->setAttribute("server", port.fServer);
3578 /* no break */
3579 case PortMode_HostDevice:
3580 case PortMode_RawFile:
3581 pelmPort->setAttribute("path", port.strPath);
3582 break;
3583
3584 default:
3585 break;
3586 }
3587 pelmPort->setAttribute("hostMode", pcszHostMode);
3588 }
3589
3590 pelmPorts = pelmHardware->createChild("LPT");
3591 for (ParallelPortsList::const_iterator it = hw.llParallelPorts.begin();
3592 it != hw.llParallelPorts.end();
3593 ++it)
3594 {
3595 const ParallelPort &port = *it;
3596 xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
3597 pelmPort->setAttribute("slot", port.ulSlot);
3598 pelmPort->setAttribute("enabled", port.fEnabled);
3599 pelmPort->setAttributeHex("IOBase", port.ulIOBase);
3600 pelmPort->setAttribute("IRQ", port.ulIRQ);
3601 if (port.strPath.length())
3602 pelmPort->setAttribute("path", port.strPath);
3603 }
3604
3605 xml::ElementNode *pelmAudio = pelmHardware->createChild("AudioAdapter");
3606 const char *pcszController;
3607 switch (hw.audioAdapter.controllerType)
3608 {
3609 case AudioControllerType_SB16:
3610 pcszController = "SB16";
3611 break;
3612 case AudioControllerType_HDA:
3613 if (m->sv >= SettingsVersion_v1_11)
3614 {
3615 pcszController = "HDA";
3616 break;
3617 }
3618 /* fall through */
3619 case AudioControllerType_AC97:
3620 default:
3621 pcszController = "AC97"; break;
3622 }
3623 pelmAudio->setAttribute("controller", pcszController);
3624
3625 if (m->sv >= SettingsVersion_v1_10)
3626 {
3627 xml::ElementNode *pelmRTC = pelmHardware->createChild("RTC");
3628 pelmRTC->setAttribute("localOrUTC", machineUserData.fRTCUseUTC ? "UTC" : "local");
3629 }
3630
3631 const char *pcszDriver;
3632 switch (hw.audioAdapter.driverType)
3633 {
3634 case AudioDriverType_WinMM: pcszDriver = "WinMM"; break;
3635 case AudioDriverType_DirectSound: pcszDriver = "DirectSound"; break;
3636 case AudioDriverType_SolAudio: pcszDriver = "SolAudio"; break;
3637 case AudioDriverType_ALSA: pcszDriver = "ALSA"; break;
3638 case AudioDriverType_Pulse: pcszDriver = "Pulse"; break;
3639 case AudioDriverType_OSS: pcszDriver = "OSS"; break;
3640 case AudioDriverType_CoreAudio: pcszDriver = "CoreAudio"; break;
3641 case AudioDriverType_MMPM: pcszDriver = "MMPM"; break;
3642 default: /*case AudioDriverType_Null:*/ pcszDriver = "Null"; break;
3643 }
3644 pelmAudio->setAttribute("driver", pcszDriver);
3645
3646 pelmAudio->setAttribute("enabled", hw.audioAdapter.fEnabled);
3647
3648 xml::ElementNode *pelmSharedFolders = pelmHardware->createChild("SharedFolders");
3649 for (SharedFoldersList::const_iterator it = hw.llSharedFolders.begin();
3650 it != hw.llSharedFolders.end();
3651 ++it)
3652 {
3653 const SharedFolder &sf = *it;
3654 xml::ElementNode *pelmThis = pelmSharedFolders->createChild("SharedFolder");
3655 pelmThis->setAttribute("name", sf.strName);
3656 pelmThis->setAttribute("hostPath", sf.strHostPath);
3657 pelmThis->setAttribute("writable", sf.fWritable);
3658 pelmThis->setAttribute("autoMount", sf.fAutoMount);
3659 }
3660
3661 xml::ElementNode *pelmClip = pelmHardware->createChild("Clipboard");
3662 const char *pcszClip;
3663 switch (hw.clipboardMode)
3664 {
3665 case ClipboardMode_Disabled: pcszClip = "Disabled"; break;
3666 case ClipboardMode_HostToGuest: pcszClip = "HostToGuest"; break;
3667 case ClipboardMode_GuestToHost: pcszClip = "GuestToHost"; break;
3668 default: /*case ClipboardMode_Bidirectional:*/ pcszClip = "Bidirectional"; break;
3669 }
3670 pelmClip->setAttribute("mode", pcszClip);
3671
3672 if (m->sv >= SettingsVersion_v1_10)
3673 {
3674 xml::ElementNode *pelmIo = pelmHardware->createChild("IO");
3675 xml::ElementNode *pelmIoCache;
3676 xml::ElementNode *pelmIoBandwidth;
3677
3678 pelmIoCache = pelmIo->createChild("IoCache");
3679 pelmIoCache->setAttribute("enabled", hw.ioSettings.fIoCacheEnabled);
3680 pelmIoCache->setAttribute("size", hw.ioSettings.ulIoCacheSize);
3681 pelmIoBandwidth = pelmIo->createChild("IoBandwidth");
3682 }
3683
3684 xml::ElementNode *pelmGuest = pelmHardware->createChild("Guest");
3685 pelmGuest->setAttribute("memoryBalloonSize", hw.ulMemoryBalloonSize);
3686
3687 xml::ElementNode *pelmGuestProps = pelmHardware->createChild("GuestProperties");
3688 for (GuestPropertiesList::const_iterator it = hw.llGuestProperties.begin();
3689 it != hw.llGuestProperties.end();
3690 ++it)
3691 {
3692 const GuestProperty &prop = *it;
3693 xml::ElementNode *pelmProp = pelmGuestProps->createChild("GuestProperty");
3694 pelmProp->setAttribute("name", prop.strName);
3695 pelmProp->setAttribute("value", prop.strValue);
3696 pelmProp->setAttribute("timestamp", prop.timestamp);
3697 pelmProp->setAttribute("flags", prop.strFlags);
3698 }
3699
3700 if (hw.strNotificationPatterns.length())
3701 pelmGuestProps->setAttribute("notificationPatterns", hw.strNotificationPatterns);
3702}
3703
3704/**
3705 * Fill a <Network> node. Only relevant for XML version >= v1_10.
3706 * @param mode
3707 * @param elmParent
3708 * @param nice
3709 */
3710void MachineConfigFile::buildNetworkXML(NetworkAttachmentType_T mode,
3711 xml::ElementNode &elmParent,
3712 const NetworkAdapter &nic)
3713{
3714 switch (mode)
3715 {
3716 case NetworkAttachmentType_NAT:
3717 xml::ElementNode *pelmNAT;
3718 pelmNAT = elmParent.createChild("NAT");
3719
3720 if (nic.nat.strNetwork.length())
3721 pelmNAT->setAttribute("network", nic.nat.strNetwork);
3722 if (nic.nat.strBindIP.length())
3723 pelmNAT->setAttribute("hostip", nic.nat.strBindIP);
3724 if (nic.nat.u32Mtu)
3725 pelmNAT->setAttribute("mtu", nic.nat.u32Mtu);
3726 if (nic.nat.u32SockRcv)
3727 pelmNAT->setAttribute("sockrcv", nic.nat.u32SockRcv);
3728 if (nic.nat.u32SockSnd)
3729 pelmNAT->setAttribute("socksnd", nic.nat.u32SockSnd);
3730 if (nic.nat.u32TcpRcv)
3731 pelmNAT->setAttribute("tcprcv", nic.nat.u32TcpRcv);
3732 if (nic.nat.u32TcpSnd)
3733 pelmNAT->setAttribute("tcpsnd", nic.nat.u32TcpSnd);
3734 xml::ElementNode *pelmDNS;
3735 pelmDNS = pelmNAT->createChild("DNS");
3736 pelmDNS->setAttribute("pass-domain", nic.nat.fDnsPassDomain);
3737 pelmDNS->setAttribute("use-proxy", nic.nat.fDnsProxy);
3738 pelmDNS->setAttribute("use-host-resolver", nic.nat.fDnsUseHostResolver);
3739
3740 xml::ElementNode *pelmAlias;
3741 pelmAlias = pelmNAT->createChild("Alias");
3742 pelmAlias->setAttribute("logging", nic.nat.fAliasLog);
3743 pelmAlias->setAttribute("proxy-only", nic.nat.fAliasProxyOnly);
3744 pelmAlias->setAttribute("use-same-ports", nic.nat.fAliasUseSamePorts);
3745
3746 if ( nic.nat.strTftpPrefix.length()
3747 || nic.nat.strTftpBootFile.length()
3748 || nic.nat.strTftpNextServer.length())
3749 {
3750 xml::ElementNode *pelmTFTP;
3751 pelmTFTP = pelmNAT->createChild("TFTP");
3752 if (nic.nat.strTftpPrefix.length())
3753 pelmTFTP->setAttribute("prefix", nic.nat.strTftpPrefix);
3754 if (nic.nat.strTftpBootFile.length())
3755 pelmTFTP->setAttribute("boot-file", nic.nat.strTftpBootFile);
3756 if (nic.nat.strTftpNextServer.length())
3757 pelmTFTP->setAttribute("next-server", nic.nat.strTftpNextServer);
3758 }
3759 for (NATRuleList::const_iterator rule = nic.nat.llRules.begin();
3760 rule != nic.nat.llRules.end(); ++rule)
3761 {
3762 xml::ElementNode *pelmPF;
3763 pelmPF = pelmNAT->createChild("Forwarding");
3764 if ((*rule).strName.length())
3765 pelmPF->setAttribute("name", (*rule).strName);
3766 pelmPF->setAttribute("proto", (*rule).u32Proto);
3767 if ((*rule).strHostIP.length())
3768 pelmPF->setAttribute("hostip", (*rule).strHostIP);
3769 if ((*rule).u16HostPort)
3770 pelmPF->setAttribute("hostport", (*rule).u16HostPort);
3771 if ((*rule).strGuestIP.length())
3772 pelmPF->setAttribute("guestip", (*rule).strGuestIP);
3773 if ((*rule).u16GuestPort)
3774 pelmPF->setAttribute("guestport", (*rule).u16GuestPort);
3775 }
3776 break;
3777
3778 case NetworkAttachmentType_Bridged:
3779 elmParent.createChild("BridgedInterface")->setAttribute("name", nic.strName);
3780 break;
3781
3782 case NetworkAttachmentType_Internal:
3783 elmParent.createChild("InternalNetwork")->setAttribute("name", nic.strName);
3784 break;
3785
3786 case NetworkAttachmentType_HostOnly:
3787 elmParent.createChild("HostOnlyInterface")->setAttribute("name", nic.strName);
3788 break;
3789
3790#ifdef VBOX_WITH_VDE
3791 case NetworkAttachmentType_VDE:
3792 elmParent.createChild("VDE")->setAttribute("network", nic.strName);
3793 break;
3794#endif
3795
3796 default: /*case NetworkAttachmentType_Null:*/
3797 break;
3798 }
3799}
3800
3801/**
3802 * Creates a <StorageControllers> node under elmParent and then writes out the XML
3803 * keys under that. Called for both the <Machine> node and for snapshots.
3804 * @param elmParent
3805 * @param st
3806 * @param fSkipRemovableMedia If true, DVD and floppy attachments are skipped and
3807 * an empty drive is always written instead. This is for the OVF export case.
3808 * This parameter is ignored unless the settings version is at least v1.9, which
3809 * is always the case when this gets called for OVF export.
3810 * @param pllElementsWithUuidAttributes If not NULL, must point to a list of element node
3811 * pointers to which we will append all allements that we created here that contain
3812 * UUID attributes. This allows the OVF export code to quickly replace the internal
3813 * media UUIDs with the UUIDs of the media that were exported.
3814 */
3815void MachineConfigFile::buildStorageControllersXML(xml::ElementNode &elmParent,
3816 const Storage &st,
3817 bool fSkipRemovableMedia,
3818 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
3819{
3820 xml::ElementNode *pelmStorageControllers = elmParent.createChild("StorageControllers");
3821
3822 for (StorageControllersList::const_iterator it = st.llStorageControllers.begin();
3823 it != st.llStorageControllers.end();
3824 ++it)
3825 {
3826 const StorageController &sc = *it;
3827
3828 if ( (m->sv < SettingsVersion_v1_9)
3829 && (sc.controllerType == StorageControllerType_I82078)
3830 )
3831 // floppy controller already got written into <Hardware>/<FloppyController> in writeHardware()
3832 // for pre-1.9 settings
3833 continue;
3834
3835 xml::ElementNode *pelmController = pelmStorageControllers->createChild("StorageController");
3836 com::Utf8Str name = sc.strName;
3837 if (m->sv < SettingsVersion_v1_8)
3838 {
3839 // pre-1.8 settings use shorter controller names, they are
3840 // expanded when reading the settings
3841 if (name == "IDE Controller")
3842 name = "IDE";
3843 else if (name == "SATA Controller")
3844 name = "SATA";
3845 else if (name == "SCSI Controller")
3846 name = "SCSI";
3847 }
3848 pelmController->setAttribute("name", sc.strName);
3849
3850 const char *pcszType;
3851 switch (sc.controllerType)
3852 {
3853 case StorageControllerType_IntelAhci: pcszType = "AHCI"; break;
3854 case StorageControllerType_LsiLogic: pcszType = "LsiLogic"; break;
3855 case StorageControllerType_BusLogic: pcszType = "BusLogic"; break;
3856 case StorageControllerType_PIIX4: pcszType = "PIIX4"; break;
3857 case StorageControllerType_ICH6: pcszType = "ICH6"; break;
3858 case StorageControllerType_I82078: pcszType = "I82078"; break;
3859 case StorageControllerType_LsiLogicSas: pcszType = "LsiLogicSas"; break;
3860 default: /*case StorageControllerType_PIIX3:*/ pcszType = "PIIX3"; break;
3861 }
3862 pelmController->setAttribute("type", pcszType);
3863
3864 pelmController->setAttribute("PortCount", sc.ulPortCount);
3865
3866 if (m->sv >= SettingsVersion_v1_9)
3867 if (sc.ulInstance)
3868 pelmController->setAttribute("Instance", sc.ulInstance);
3869
3870 if (m->sv >= SettingsVersion_v1_10)
3871 pelmController->setAttribute("useHostIOCache", sc.fUseHostIOCache);
3872
3873 if (sc.controllerType == StorageControllerType_IntelAhci)
3874 {
3875 pelmController->setAttribute("IDE0MasterEmulationPort", sc.lIDE0MasterEmulationPort);
3876 pelmController->setAttribute("IDE0SlaveEmulationPort", sc.lIDE0SlaveEmulationPort);
3877 pelmController->setAttribute("IDE1MasterEmulationPort", sc.lIDE1MasterEmulationPort);
3878 pelmController->setAttribute("IDE1SlaveEmulationPort", sc.lIDE1SlaveEmulationPort);
3879 }
3880
3881 for (AttachedDevicesList::const_iterator it2 = sc.llAttachedDevices.begin();
3882 it2 != sc.llAttachedDevices.end();
3883 ++it2)
3884 {
3885 const AttachedDevice &att = *it2;
3886
3887 // For settings version before 1.9, DVDs and floppies are in hardware, not storage controllers,
3888 // so we shouldn't write them here; we only get here for DVDs though because we ruled out
3889 // the floppy controller at the top of the loop
3890 if ( att.deviceType == DeviceType_DVD
3891 && m->sv < SettingsVersion_v1_9
3892 )
3893 continue;
3894
3895 xml::ElementNode *pelmDevice = pelmController->createChild("AttachedDevice");
3896
3897 pcszType = NULL;
3898
3899 switch (att.deviceType)
3900 {
3901 case DeviceType_HardDisk:
3902 pcszType = "HardDisk";
3903 break;
3904
3905 case DeviceType_DVD:
3906 pcszType = "DVD";
3907 pelmDevice->setAttribute("passthrough", att.fPassThrough);
3908 break;
3909
3910 case DeviceType_Floppy:
3911 pcszType = "Floppy";
3912 break;
3913 }
3914
3915 pelmDevice->setAttribute("type", pcszType);
3916
3917 pelmDevice->setAttribute("port", att.lPort);
3918 pelmDevice->setAttribute("device", att.lDevice);
3919
3920 if (att.ulBandwidthLimit)
3921 pelmDevice->setAttribute("bandwidthLimit", att.ulBandwidthLimit);
3922
3923 // attached image, if any
3924 if ( !att.uuid.isEmpty()
3925 && ( att.deviceType == DeviceType_HardDisk
3926 || !fSkipRemovableMedia
3927 )
3928 )
3929 {
3930 xml::ElementNode *pelmImage = pelmDevice->createChild("Image");
3931 pelmImage->setAttribute("uuid", att.uuid.toStringCurly());
3932
3933 // if caller wants a list of UUID elements, give it to them
3934 if (pllElementsWithUuidAttributes)
3935 pllElementsWithUuidAttributes->push_back(pelmImage);
3936 }
3937 else if ( (m->sv >= SettingsVersion_v1_9)
3938 && (att.strHostDriveSrc.length())
3939 )
3940 pelmDevice->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
3941 }
3942 }
3943}
3944
3945/**
3946 * Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
3947 * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
3948 * <Machine> node to which <Snapshot> must be added. This may then recurse for child snapshots.
3949 * @param elmParent
3950 * @param snap
3951 */
3952void MachineConfigFile::buildSnapshotXML(xml::ElementNode &elmParent,
3953 const Snapshot &snap)
3954{
3955 xml::ElementNode *pelmSnapshot = elmParent.createChild("Snapshot");
3956
3957 pelmSnapshot->setAttribute("uuid", snap.uuid.toStringCurly());
3958 pelmSnapshot->setAttribute("name", snap.strName);
3959 pelmSnapshot->setAttribute("timeStamp", makeString(snap.timestamp));
3960
3961 if (snap.strStateFile.length())
3962 pelmSnapshot->setAttribute("stateFile", snap.strStateFile);
3963
3964 if (snap.strDescription.length())
3965 pelmSnapshot->createChild("Description")->addContent(snap.strDescription);
3966
3967 buildHardwareXML(*pelmSnapshot, snap.hardware, snap.storage);
3968 buildStorageControllersXML(*pelmSnapshot,
3969 snap.storage,
3970 false /* fSkipRemovableMedia */,
3971 NULL); /* pllElementsWithUuidAttributes */
3972 // we only skip removable media for OVF, but we never get here for OVF
3973 // since snapshots never get written then
3974
3975 if (snap.llChildSnapshots.size())
3976 {
3977 xml::ElementNode *pelmChildren = pelmSnapshot->createChild("Snapshots");
3978 for (SnapshotsList::const_iterator it = snap.llChildSnapshots.begin();
3979 it != snap.llChildSnapshots.end();
3980 ++it)
3981 {
3982 const Snapshot &child = *it;
3983 buildSnapshotXML(*pelmChildren, child);
3984 }
3985 }
3986}
3987
3988/**
3989 * Builds the XML DOM tree for the machine config under the given XML element.
3990 *
3991 * This has been separated out from write() so it can be called from elsewhere,
3992 * such as the OVF code, to build machine XML in an existing XML tree.
3993 *
3994 * As a result, this gets called from two locations:
3995 *
3996 * -- MachineConfigFile::write();
3997 *
3998 * -- Appliance::buildXMLForOneVirtualSystem()
3999 *
4000 * In fl, the following flag bits are recognized:
4001 *
4002 * -- BuildMachineXML_MediaRegistry: If set, the machine's media registry will
4003 * be written, if present. This is not set when called from OVF because OVF
4004 * has its own variant of a media registry. This flag is ignored unless the
4005 * settings version is at least v1.11 (VirtualBox 4.0).
4006 *
4007 * -- BuildMachineXML_IncludeSnapshots: If set, descend into the snapshots tree
4008 * of the machine and write out <Snapshot> and possibly more snapshots under
4009 * that, if snapshots are present. Otherwise all snapshots are suppressed
4010 * (when called from OVF).
4011 *
4012 * -- BuildMachineXML_WriteVboxVersionAttribute: If set, add a settingsVersion
4013 * attribute to the machine tag with the vbox settings version. This is for
4014 * the OVF export case in which we don't have the settings version set in
4015 * the root element.
4016 *
4017 * -- BuildMachineXML_SkipRemovableMedia: If set, removable media attachments
4018 * (DVDs, floppies) are silently skipped. This is for the OVF export case
4019 * until we support copying ISO and RAW media as well. This flag is ignored
4020 * unless the settings version is at least v1.9, which is always the case
4021 * when this gets called for OVF export.
4022 *
4023 * @param elmMachine XML <Machine> element to add attributes and elements to.
4024 * @param fl Flags.
4025 * @param pllElementsWithUuidAttributes pointer to list that should receive UUID elements or NULL;
4026 * see buildStorageControllersXML() for details.
4027 */
4028void MachineConfigFile::buildMachineXML(xml::ElementNode &elmMachine,
4029 uint32_t fl,
4030 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
4031{
4032 if (fl & BuildMachineXML_WriteVboxVersionAttribute)
4033 // add settings version attribute to machine element
4034 setVersionAttribute(elmMachine);
4035
4036 elmMachine.setAttribute("uuid", uuid.toStringCurly());
4037 elmMachine.setAttribute("name", machineUserData.strName);
4038 if (!machineUserData.fNameSync)
4039 elmMachine.setAttribute("nameSync", machineUserData.fNameSync);
4040 if (machineUserData.strDescription.length())
4041 elmMachine.createChild("Description")->addContent(machineUserData.strDescription);
4042 elmMachine.setAttribute("OSType", machineUserData.strOsType);
4043 if (strStateFile.length())
4044 elmMachine.setAttribute("stateFile", strStateFile);
4045 if ( (fl & BuildMachineXML_IncludeSnapshots)
4046 && !uuidCurrentSnapshot.isEmpty())
4047 elmMachine.setAttribute("currentSnapshot", uuidCurrentSnapshot.toStringCurly());
4048 if (machineUserData.strSnapshotFolder.length())
4049 elmMachine.setAttribute("snapshotFolder", machineUserData.strSnapshotFolder);
4050 if (!fCurrentStateModified)
4051 elmMachine.setAttribute("currentStateModified", fCurrentStateModified);
4052 elmMachine.setAttribute("lastStateChange", makeString(timeLastStateChange));
4053 if (fAborted)
4054 elmMachine.setAttribute("aborted", fAborted);
4055 if ( m->sv >= SettingsVersion_v1_9
4056 && ( machineUserData.fTeleporterEnabled
4057 || machineUserData.uTeleporterPort
4058 || !machineUserData.strTeleporterAddress.isEmpty()
4059 || !machineUserData.strTeleporterPassword.isEmpty()
4060 )
4061 )
4062 {
4063 xml::ElementNode *pelmTeleporter = elmMachine.createChild("Teleporter");
4064 pelmTeleporter->setAttribute("enabled", machineUserData.fTeleporterEnabled);
4065 pelmTeleporter->setAttribute("port", machineUserData.uTeleporterPort);
4066 pelmTeleporter->setAttribute("address", machineUserData.strTeleporterAddress);
4067 pelmTeleporter->setAttribute("password", machineUserData.strTeleporterPassword);
4068 }
4069
4070 if ( m->sv >= SettingsVersion_v1_11
4071 && ( machineUserData.enmFaultToleranceState != FaultToleranceState_Inactive
4072 || machineUserData.uFaultTolerancePort
4073 || machineUserData.uFaultToleranceInterval
4074 || !machineUserData.strFaultToleranceAddress.isEmpty()
4075 )
4076 )
4077 {
4078 xml::ElementNode *pelmFaultTolerance = elmMachine.createChild("FaultTolerance");
4079 switch (machineUserData.enmFaultToleranceState)
4080 {
4081 case FaultToleranceState_Inactive:
4082 pelmFaultTolerance->setAttribute("state", "inactive");
4083 break;
4084 case FaultToleranceState_Master:
4085 pelmFaultTolerance->setAttribute("state", "master");
4086 break;
4087 case FaultToleranceState_Standby:
4088 pelmFaultTolerance->setAttribute("state", "standby");
4089 break;
4090 }
4091
4092 pelmFaultTolerance->setAttribute("port", machineUserData.uFaultTolerancePort);
4093 pelmFaultTolerance->setAttribute("address", machineUserData.strFaultToleranceAddress);
4094 pelmFaultTolerance->setAttribute("interval", machineUserData.uFaultToleranceInterval);
4095 pelmFaultTolerance->setAttribute("password", machineUserData.strFaultTolerancePassword);
4096 }
4097
4098 if ( (fl & BuildMachineXML_MediaRegistry)
4099 && (m->sv >= SettingsVersion_v1_11)
4100 )
4101 buildMediaRegistry(elmMachine, mediaRegistry);
4102
4103 buildExtraData(elmMachine, mapExtraDataItems);
4104
4105 if ( (fl & BuildMachineXML_IncludeSnapshots)
4106 && llFirstSnapshot.size())
4107 buildSnapshotXML(elmMachine, llFirstSnapshot.front());
4108
4109 buildHardwareXML(elmMachine, hardwareMachine, storageMachine);
4110 buildStorageControllersXML(elmMachine,
4111 storageMachine,
4112 !!(fl & BuildMachineXML_SkipRemovableMedia),
4113 pllElementsWithUuidAttributes);
4114}
4115
4116/**
4117 * Returns true only if the given AudioDriverType is supported on
4118 * the current host platform. For example, this would return false
4119 * for AudioDriverType_DirectSound when compiled on a Linux host.
4120 * @param drv AudioDriverType_* enum to test.
4121 * @return true only if the current host supports that driver.
4122 */
4123/*static*/
4124bool MachineConfigFile::isAudioDriverAllowedOnThisHost(AudioDriverType_T drv)
4125{
4126 switch (drv)
4127 {
4128 case AudioDriverType_Null:
4129#ifdef RT_OS_WINDOWS
4130# ifdef VBOX_WITH_WINMM
4131 case AudioDriverType_WinMM:
4132# endif
4133 case AudioDriverType_DirectSound:
4134#endif /* RT_OS_WINDOWS */
4135#ifdef RT_OS_SOLARIS
4136 case AudioDriverType_SolAudio:
4137#endif
4138#ifdef RT_OS_LINUX
4139# ifdef VBOX_WITH_ALSA
4140 case AudioDriverType_ALSA:
4141# endif
4142# ifdef VBOX_WITH_PULSE
4143 case AudioDriverType_Pulse:
4144# endif
4145#endif /* RT_OS_LINUX */
4146#if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
4147 case AudioDriverType_OSS:
4148#endif
4149#ifdef RT_OS_FREEBSD
4150# ifdef VBOX_WITH_PULSE
4151 case AudioDriverType_Pulse:
4152# endif
4153#endif
4154#ifdef RT_OS_DARWIN
4155 case AudioDriverType_CoreAudio:
4156#endif
4157#ifdef RT_OS_OS2
4158 case AudioDriverType_MMPM:
4159#endif
4160 return true;
4161 }
4162
4163 return false;
4164}
4165
4166/**
4167 * Returns the AudioDriverType_* which should be used by default on this
4168 * host platform. On Linux, this will check at runtime whether PulseAudio
4169 * or ALSA are actually supported on the first call.
4170 * @return
4171 */
4172/*static*/
4173AudioDriverType_T MachineConfigFile::getHostDefaultAudioDriver()
4174{
4175#if defined(RT_OS_WINDOWS)
4176# ifdef VBOX_WITH_WINMM
4177 return AudioDriverType_WinMM;
4178# else /* VBOX_WITH_WINMM */
4179 return AudioDriverType_DirectSound;
4180# endif /* !VBOX_WITH_WINMM */
4181#elif defined(RT_OS_SOLARIS)
4182 return AudioDriverType_SolAudio;
4183#elif defined(RT_OS_LINUX)
4184 // on Linux, we need to check at runtime what's actually supported...
4185 static RTLockMtx s_mtx;
4186 static AudioDriverType_T s_linuxDriver = -1;
4187 RTLock lock(s_mtx);
4188 if (s_linuxDriver == (AudioDriverType_T)-1)
4189 {
4190# if defined(VBOX_WITH_PULSE)
4191 /* Check for the pulse library & that the pulse audio daemon is running. */
4192 if (RTProcIsRunningByName("pulseaudio") &&
4193 RTLdrIsLoadable("libpulse.so.0"))
4194 s_linuxDriver = AudioDriverType_Pulse;
4195 else
4196# endif /* VBOX_WITH_PULSE */
4197# if defined(VBOX_WITH_ALSA)
4198 /* Check if we can load the ALSA library */
4199 if (RTLdrIsLoadable("libasound.so.2"))
4200 s_linuxDriver = AudioDriverType_ALSA;
4201 else
4202# endif /* VBOX_WITH_ALSA */
4203 s_linuxDriver = AudioDriverType_OSS;
4204 }
4205 return s_linuxDriver;
4206// end elif defined(RT_OS_LINUX)
4207#elif defined(RT_OS_DARWIN)
4208 return AudioDriverType_CoreAudio;
4209#elif defined(RT_OS_OS2)
4210 return AudioDriverType_MMP;
4211#elif defined(RT_OS_FREEBSD)
4212 return AudioDriverType_OSS;
4213#else
4214 return AudioDriverType_Null;
4215#endif
4216}
4217
4218/**
4219 * Called from write() before calling ConfigFileBase::createStubDocument().
4220 * This adjusts the settings version in m->sv if incompatible settings require
4221 * a settings bump, whereas otherwise we try to preserve the settings version
4222 * to avoid breaking compatibility with older versions.
4223 *
4224 * We do the checks in here in reverse order: newest first, oldest last, so
4225 * that we avoid unnecessary checks since some of these are expensive.
4226 */
4227void MachineConfigFile::bumpSettingsVersionIfNeeded()
4228{
4229 if (m->sv < SettingsVersion_v1_11)
4230 {
4231 // VirtualBox 4.0 adds HD audio, CPU priorities, fault tolerance and per-machine media registries
4232 if ( hardwareMachine.audioAdapter.controllerType == AudioControllerType_HDA
4233 || hardwareMachine.ulCpuExecutionCap != 100
4234 || machineUserData.enmFaultToleranceState != FaultToleranceState_Inactive
4235 || machineUserData.uFaultTolerancePort
4236 || machineUserData.uFaultToleranceInterval
4237 || !machineUserData.strFaultToleranceAddress.isEmpty()
4238 || mediaRegistry.llHardDisks.size()
4239 || mediaRegistry.llDvdImages.size()
4240 || mediaRegistry.llFloppyImages.size()
4241 )
4242 m->sv = SettingsVersion_v1_11;
4243 }
4244
4245 // settings version 1.9 is required if there is not exactly one DVD
4246 // or more than one floppy drive present or the DVD is not at the secondary
4247 // master; this check is a bit more complicated
4248 //
4249 // settings version 1.10 is required if the host cache should be disabled
4250 //
4251 // settings version 1.11 is required for bandwidth limits
4252 if (m->sv < SettingsVersion_v1_11)
4253 {
4254 // count attached DVDs and floppies (only if < v1.9)
4255 size_t cDVDs = 0;
4256 size_t cFloppies = 0;
4257
4258 // need to run thru all the storage controllers and attached devices to figure this out
4259 for (StorageControllersList::const_iterator it = storageMachine.llStorageControllers.begin();
4260 it != storageMachine.llStorageControllers.end();
4261 ++it)
4262 {
4263 const StorageController &sctl = *it;
4264 for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
4265 it2 != sctl.llAttachedDevices.end();
4266 ++it2)
4267 {
4268 const AttachedDevice &att = *it2;
4269
4270 // Bandwidth limitations are new in VirtualBox 4.0 (1.11)
4271 if ( (m->sv < SettingsVersion_v1_11)
4272 && (att.ulBandwidthLimit != 0)
4273 )
4274 {
4275 m->sv = SettingsVersion_v1_11;
4276 break; /* abort the loop -- we will not raise the version further */
4277 }
4278
4279 // disabling the host IO cache requires settings version 1.10
4280 if ( (m->sv < SettingsVersion_v1_10)
4281 && (!sctl.fUseHostIOCache)
4282 )
4283 m->sv = SettingsVersion_v1_10;
4284
4285 // we can only write the StorageController/@Instance attribute with v1.9
4286 if ( (m->sv < SettingsVersion_v1_9)
4287 && (sctl.ulInstance != 0)
4288 )
4289 m->sv = SettingsVersion_v1_9;
4290
4291 if (m->sv < SettingsVersion_v1_9)
4292 {
4293 if (att.deviceType == DeviceType_DVD)
4294 {
4295 if ( (sctl.storageBus != StorageBus_IDE) // DVD at bus other than DVD?
4296 || (att.lPort != 1) // DVDs not at secondary master?
4297 || (att.lDevice != 0)
4298 )
4299 m->sv = SettingsVersion_v1_9;
4300
4301 ++cDVDs;
4302 }
4303 else if (att.deviceType == DeviceType_Floppy)
4304 ++cFloppies;
4305 }
4306 }
4307 }
4308
4309 // VirtualBox before 3.1 had zero or one floppy and exactly one DVD,
4310 // so any deviation from that will require settings version 1.9
4311 if ( (m->sv < SettingsVersion_v1_9)
4312 && ( (cDVDs != 1)
4313 || (cFloppies > 1)
4314 )
4315 )
4316 m->sv = SettingsVersion_v1_9;
4317 }
4318
4319 // VirtualBox 3.2: Check for non default I/O settings
4320 if (m->sv < SettingsVersion_v1_10)
4321 {
4322 if ( (hardwareMachine.ioSettings.fIoCacheEnabled != true)
4323 || (hardwareMachine.ioSettings.ulIoCacheSize != 5)
4324 // and VRDP video channel
4325 || (hardwareMachine.vrdpSettings.fVideoChannel)
4326 // and page fusion
4327 || (hardwareMachine.fPageFusionEnabled)
4328 // and CPU hotplug, RTC timezone control, HID type and HPET
4329 || machineUserData.fRTCUseUTC
4330 || hardwareMachine.fCpuHotPlug
4331 || hardwareMachine.pointingHidType != PointingHidType_PS2Mouse
4332 || hardwareMachine.keyboardHidType != KeyboardHidType_PS2Keyboard
4333 || hardwareMachine.fHpetEnabled
4334 )
4335 m->sv = SettingsVersion_v1_10;
4336 }
4337
4338 // VirtualBox 3.2 adds NAT and boot priority to the NIC config in Main
4339 if (m->sv < SettingsVersion_v1_10)
4340 {
4341 NetworkAdaptersList::const_iterator netit;
4342 for (netit = hardwareMachine.llNetworkAdapters.begin();
4343 netit != hardwareMachine.llNetworkAdapters.end();
4344 ++netit)
4345 {
4346 if ( (m->sv < SettingsVersion_v1_11)
4347 && (netit->ulBandwidthLimit)
4348 )
4349 {
4350 /* New in VirtualBox 4.0 */
4351 m->sv = SettingsVersion_v1_11;
4352 break;
4353 }
4354 else if ( (m->sv < SettingsVersion_v1_10)
4355 && (netit->fEnabled)
4356 && (netit->mode == NetworkAttachmentType_NAT)
4357 && ( netit->nat.u32Mtu != 0
4358 || netit->nat.u32SockRcv != 0
4359 || netit->nat.u32SockSnd != 0
4360 || netit->nat.u32TcpRcv != 0
4361 || netit->nat.u32TcpSnd != 0
4362 || !netit->nat.fDnsPassDomain
4363 || netit->nat.fDnsProxy
4364 || netit->nat.fDnsUseHostResolver
4365 || netit->nat.fAliasLog
4366 || netit->nat.fAliasProxyOnly
4367 || netit->nat.fAliasUseSamePorts
4368 || netit->nat.strTftpPrefix.length()
4369 || netit->nat.strTftpBootFile.length()
4370 || netit->nat.strTftpNextServer.length()
4371 || netit->nat.llRules.size()
4372 )
4373 )
4374 {
4375 m->sv = SettingsVersion_v1_10;
4376 // no break because we still might need v1.11 above
4377 }
4378 else if ( (m->sv < SettingsVersion_v1_10)
4379 && (netit->fEnabled)
4380 && (netit->ulBootPriority != 0)
4381 )
4382 {
4383 m->sv = SettingsVersion_v1_10;
4384 // no break because we still might need v1.11 above
4385 }
4386 }
4387 }
4388
4389 // all the following require settings version 1.9
4390 if ( (m->sv < SettingsVersion_v1_9)
4391 && ( (hardwareMachine.firmwareType >= FirmwareType_EFI)
4392 || (hardwareMachine.fHardwareVirtExclusive != HWVIRTEXCLUSIVEDEFAULT)
4393 || machineUserData.fTeleporterEnabled
4394 || machineUserData.uTeleporterPort
4395 || !machineUserData.strTeleporterAddress.isEmpty()
4396 || !machineUserData.strTeleporterPassword.isEmpty()
4397 || !hardwareMachine.uuid.isEmpty()
4398 )
4399 )
4400 m->sv = SettingsVersion_v1_9;
4401
4402 // "accelerate 2d video" requires settings version 1.8
4403 if ( (m->sv < SettingsVersion_v1_8)
4404 && (hardwareMachine.fAccelerate2DVideo)
4405 )
4406 m->sv = SettingsVersion_v1_8;
4407
4408 // The hardware versions other than "1" requires settings version 1.4 (2.1+).
4409 if ( m->sv < SettingsVersion_v1_4
4410 && hardwareMachine.strVersion != "1"
4411 )
4412 m->sv = SettingsVersion_v1_4;
4413}
4414
4415/**
4416 * Called from Main code to write a machine config file to disk. This builds a DOM tree from
4417 * the member variables and then writes the XML file; it throws xml::Error instances on errors,
4418 * in particular if the file cannot be written.
4419 */
4420void MachineConfigFile::write(const com::Utf8Str &strFilename)
4421{
4422 try
4423 {
4424 // createStubDocument() sets the settings version to at least 1.7; however,
4425 // we might need to enfore a later settings version if incompatible settings
4426 // are present:
4427 bumpSettingsVersionIfNeeded();
4428
4429 m->strFilename = strFilename;
4430 createStubDocument();
4431
4432 xml::ElementNode *pelmMachine = m->pelmRoot->createChild("Machine");
4433 buildMachineXML(*pelmMachine,
4434 MachineConfigFile::BuildMachineXML_IncludeSnapshots
4435 | MachineConfigFile::BuildMachineXML_MediaRegistry,
4436 // but not BuildMachineXML_WriteVboxVersionAttribute
4437 NULL); /* pllElementsWithUuidAttributes */
4438
4439 // now go write the XML
4440 xml::XmlFileWriter writer(*m->pDoc);
4441 writer.write(m->strFilename.c_str(), true /*fSafe*/);
4442
4443 m->fFileExists = true;
4444 clearDocument();
4445 }
4446 catch (...)
4447 {
4448 clearDocument();
4449 throw;
4450 }
4451}
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