VirtualBox

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

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

added HWVirtEx force property to API

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