1 | /* $Id: Settings.cpp 50196 2014-01-23 18:15:23Z 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 | * VBOX_XML_VERSION does not have to be changed if the settings for a default VM do not
|
---|
20 | * touch newly introduced attributes or tags. It has the benefit that older VirtualBox
|
---|
21 | * versions do not trigger their "newer" code path.
|
---|
22 | *
|
---|
23 | * Once a new settings version has been added, these are the rules for introducing a new
|
---|
24 | * setting: If an XML element or attribute or value is introduced that was not present in
|
---|
25 | * previous versions, then settings version checks need to be introduced. See the
|
---|
26 | * SettingsVersion enumeration in src/VBox/Main/idl/VirtualBox.xidl for details about which
|
---|
27 | * version was used when.
|
---|
28 | *
|
---|
29 | * The settings versions checks are necessary because since version 3.1, VirtualBox no longer
|
---|
30 | * automatically converts XML settings files but only if necessary, that is, if settings are
|
---|
31 | * present that the old format does not support. If we write an element or attribute to a
|
---|
32 | * settings file of an older version, then an old VirtualBox (before 3.1) will attempt to
|
---|
33 | * validate it with XML schema, and that will certainly fail.
|
---|
34 | *
|
---|
35 | * So, to introduce a new setting:
|
---|
36 | *
|
---|
37 | * 1) Make sure the constructor of corresponding settings structure has a proper default.
|
---|
38 | *
|
---|
39 | * 2) In the settings reader method, try to read the setting; if it's there, great, if not,
|
---|
40 | * the default value will have been set by the constructor. The rule is to be tolerant
|
---|
41 | * here.
|
---|
42 | *
|
---|
43 | * 3) In MachineConfigFile::bumpSettingsVersionIfNeeded(), check if the new setting has
|
---|
44 | * a non-default value (i.e. that differs from the constructor). If so, bump the
|
---|
45 | * settings version to the current version so the settings writer (4) can write out
|
---|
46 | * the non-default value properly.
|
---|
47 | *
|
---|
48 | * So far a corresponding method for MainConfigFile has not been necessary since there
|
---|
49 | * have been no incompatible changes yet.
|
---|
50 | *
|
---|
51 | * 4) In the settings writer method, write the setting _only_ if the current settings
|
---|
52 | * version (stored in m->sv) is high enough. That is, for VirtualBox 4.0, write it
|
---|
53 | * only if (m->sv >= SettingsVersion_v1_11).
|
---|
54 | */
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * Copyright (C) 2007-2013 Oracle Corporation
|
---|
58 | *
|
---|
59 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
60 | * available from http://www.virtualbox.org. This file is free software;
|
---|
61 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
62 | * General Public License (GPL) as published by the Free Software
|
---|
63 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
64 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
65 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
66 | */
|
---|
67 |
|
---|
68 | #include "VBox/com/string.h"
|
---|
69 | #include "VBox/settings.h"
|
---|
70 | #include <iprt/cpp/xml.h>
|
---|
71 | #include <iprt/stream.h>
|
---|
72 | #include <iprt/ctype.h>
|
---|
73 | #include <iprt/file.h>
|
---|
74 | #include <iprt/process.h>
|
---|
75 | #include <iprt/ldr.h>
|
---|
76 | #include <iprt/cpp/lock.h>
|
---|
77 |
|
---|
78 | // generated header
|
---|
79 | #include "SchemaDefs.h"
|
---|
80 |
|
---|
81 | #include "Logging.h"
|
---|
82 | #include "HashedPw.h"
|
---|
83 |
|
---|
84 | using namespace com;
|
---|
85 | using namespace settings;
|
---|
86 |
|
---|
87 | ////////////////////////////////////////////////////////////////////////////////
|
---|
88 | //
|
---|
89 | // Defines
|
---|
90 | //
|
---|
91 | ////////////////////////////////////////////////////////////////////////////////
|
---|
92 |
|
---|
93 | /** VirtualBox XML settings namespace */
|
---|
94 | #define VBOX_XML_NAMESPACE "http://www.innotek.de/VirtualBox-settings"
|
---|
95 |
|
---|
96 | /** VirtualBox XML settings version number substring ("x.y") */
|
---|
97 | #define VBOX_XML_VERSION "1.12"
|
---|
98 |
|
---|
99 | /** VirtualBox XML settings version platform substring */
|
---|
100 | #if defined (RT_OS_DARWIN)
|
---|
101 | # define VBOX_XML_PLATFORM "macosx"
|
---|
102 | #elif defined (RT_OS_FREEBSD)
|
---|
103 | # define VBOX_XML_PLATFORM "freebsd"
|
---|
104 | #elif defined (RT_OS_LINUX)
|
---|
105 | # define VBOX_XML_PLATFORM "linux"
|
---|
106 | #elif defined (RT_OS_NETBSD)
|
---|
107 | # define VBOX_XML_PLATFORM "netbsd"
|
---|
108 | #elif defined (RT_OS_OPENBSD)
|
---|
109 | # define VBOX_XML_PLATFORM "openbsd"
|
---|
110 | #elif defined (RT_OS_OS2)
|
---|
111 | # define VBOX_XML_PLATFORM "os2"
|
---|
112 | #elif defined (RT_OS_SOLARIS)
|
---|
113 | # define VBOX_XML_PLATFORM "solaris"
|
---|
114 | #elif defined (RT_OS_WINDOWS)
|
---|
115 | # define VBOX_XML_PLATFORM "windows"
|
---|
116 | #else
|
---|
117 | # error Unsupported platform!
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | /** VirtualBox XML settings full version string ("x.y-platform") */
|
---|
121 | #define VBOX_XML_VERSION_FULL VBOX_XML_VERSION "-" VBOX_XML_PLATFORM
|
---|
122 |
|
---|
123 | ////////////////////////////////////////////////////////////////////////////////
|
---|
124 | //
|
---|
125 | // Internal data
|
---|
126 | //
|
---|
127 | ////////////////////////////////////////////////////////////////////////////////
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Opaque data structore for ConfigFileBase (only declared
|
---|
131 | * in header, defined only here).
|
---|
132 | */
|
---|
133 |
|
---|
134 | struct ConfigFileBase::Data
|
---|
135 | {
|
---|
136 | Data()
|
---|
137 | : pDoc(NULL),
|
---|
138 | pelmRoot(NULL),
|
---|
139 | sv(SettingsVersion_Null),
|
---|
140 | svRead(SettingsVersion_Null)
|
---|
141 | {}
|
---|
142 |
|
---|
143 | ~Data()
|
---|
144 | {
|
---|
145 | cleanup();
|
---|
146 | }
|
---|
147 |
|
---|
148 | RTCString strFilename;
|
---|
149 | bool fFileExists;
|
---|
150 |
|
---|
151 | xml::Document *pDoc;
|
---|
152 | xml::ElementNode *pelmRoot;
|
---|
153 |
|
---|
154 | com::Utf8Str strSettingsVersionFull; // e.g. "1.7-linux"
|
---|
155 | SettingsVersion_T sv; // e.g. SettingsVersion_v1_7
|
---|
156 |
|
---|
157 | SettingsVersion_T svRead; // settings version that the original file had when it was read,
|
---|
158 | // or SettingsVersion_Null if none
|
---|
159 |
|
---|
160 | void copyFrom(const Data &d)
|
---|
161 | {
|
---|
162 | strFilename = d.strFilename;
|
---|
163 | fFileExists = d.fFileExists;
|
---|
164 | strSettingsVersionFull = d.strSettingsVersionFull;
|
---|
165 | sv = d.sv;
|
---|
166 | svRead = d.svRead;
|
---|
167 | }
|
---|
168 |
|
---|
169 | void cleanup()
|
---|
170 | {
|
---|
171 | if (pDoc)
|
---|
172 | {
|
---|
173 | delete pDoc;
|
---|
174 | pDoc = NULL;
|
---|
175 | pelmRoot = NULL;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | };
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Private exception class (not in the header file) that makes
|
---|
182 | * throwing xml::LogicError instances easier. That class is public
|
---|
183 | * and should be caught by client code.
|
---|
184 | */
|
---|
185 | class settings::ConfigFileError : public xml::LogicError
|
---|
186 | {
|
---|
187 | public:
|
---|
188 | ConfigFileError(const ConfigFileBase *file,
|
---|
189 | const xml::Node *pNode,
|
---|
190 | const char *pcszFormat, ...)
|
---|
191 | : xml::LogicError()
|
---|
192 | {
|
---|
193 | va_list args;
|
---|
194 | va_start(args, pcszFormat);
|
---|
195 | Utf8Str strWhat(pcszFormat, args);
|
---|
196 | va_end(args);
|
---|
197 |
|
---|
198 | Utf8Str strLine;
|
---|
199 | if (pNode)
|
---|
200 | strLine = Utf8StrFmt(" (line %RU32)", pNode->getLineNumber());
|
---|
201 |
|
---|
202 | const char *pcsz = strLine.c_str();
|
---|
203 | Utf8StrFmt str(N_("Error in %s%s -- %s"),
|
---|
204 | file->m->strFilename.c_str(),
|
---|
205 | (pcsz) ? pcsz : "",
|
---|
206 | strWhat.c_str());
|
---|
207 |
|
---|
208 | setWhat(str.c_str());
|
---|
209 | }
|
---|
210 | };
|
---|
211 |
|
---|
212 | ////////////////////////////////////////////////////////////////////////////////
|
---|
213 | //
|
---|
214 | // MediaRegistry
|
---|
215 | //
|
---|
216 | ////////////////////////////////////////////////////////////////////////////////
|
---|
217 |
|
---|
218 | bool Medium::operator==(const Medium &m) const
|
---|
219 | {
|
---|
220 | return (uuid == m.uuid)
|
---|
221 | && (strLocation == m.strLocation)
|
---|
222 | && (strDescription == m.strDescription)
|
---|
223 | && (strFormat == m.strFormat)
|
---|
224 | && (fAutoReset == m.fAutoReset)
|
---|
225 | && (properties == m.properties)
|
---|
226 | && (hdType == m.hdType)
|
---|
227 | && (llChildren== m.llChildren); // this is deep and recurses
|
---|
228 | }
|
---|
229 |
|
---|
230 | bool MediaRegistry::operator==(const MediaRegistry &m) const
|
---|
231 | {
|
---|
232 | return llHardDisks == m.llHardDisks
|
---|
233 | && llDvdImages == m.llDvdImages
|
---|
234 | && llFloppyImages == m.llFloppyImages;
|
---|
235 | }
|
---|
236 |
|
---|
237 | ////////////////////////////////////////////////////////////////////////////////
|
---|
238 | //
|
---|
239 | // ConfigFileBase
|
---|
240 | //
|
---|
241 | ////////////////////////////////////////////////////////////////////////////////
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Constructor. Allocates the XML internals, parses the XML file if
|
---|
245 | * pstrFilename is != NULL and reads the settings version from it.
|
---|
246 | * @param strFilename
|
---|
247 | */
|
---|
248 | ConfigFileBase::ConfigFileBase(const com::Utf8Str *pstrFilename)
|
---|
249 | : m(new Data)
|
---|
250 | {
|
---|
251 | Utf8Str strMajor;
|
---|
252 | Utf8Str strMinor;
|
---|
253 |
|
---|
254 | m->fFileExists = false;
|
---|
255 |
|
---|
256 | if (pstrFilename)
|
---|
257 | {
|
---|
258 | // reading existing settings file:
|
---|
259 | m->strFilename = *pstrFilename;
|
---|
260 |
|
---|
261 | xml::XmlFileParser parser;
|
---|
262 | m->pDoc = new xml::Document;
|
---|
263 | parser.read(*pstrFilename,
|
---|
264 | *m->pDoc);
|
---|
265 |
|
---|
266 | m->fFileExists = true;
|
---|
267 |
|
---|
268 | m->pelmRoot = m->pDoc->getRootElement();
|
---|
269 | if (!m->pelmRoot || !m->pelmRoot->nameEquals("VirtualBox"))
|
---|
270 | throw ConfigFileError(this, NULL, N_("Root element in VirtualBox settings files must be \"VirtualBox\"."));
|
---|
271 |
|
---|
272 | if (!(m->pelmRoot->getAttributeValue("version", m->strSettingsVersionFull)))
|
---|
273 | throw ConfigFileError(this, m->pelmRoot, N_("Required VirtualBox/@version attribute is missing"));
|
---|
274 |
|
---|
275 | LogRel(("Loading settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
|
---|
276 |
|
---|
277 | // parse settings version; allow future versions but fail if file is older than 1.6
|
---|
278 | m->sv = SettingsVersion_Null;
|
---|
279 | if (m->strSettingsVersionFull.length() > 3)
|
---|
280 | {
|
---|
281 | const char *pcsz = m->strSettingsVersionFull.c_str();
|
---|
282 | char c;
|
---|
283 |
|
---|
284 | while ( (c = *pcsz)
|
---|
285 | && RT_C_IS_DIGIT(c)
|
---|
286 | )
|
---|
287 | {
|
---|
288 | strMajor.append(c);
|
---|
289 | ++pcsz;
|
---|
290 | }
|
---|
291 |
|
---|
292 | if (*pcsz++ == '.')
|
---|
293 | {
|
---|
294 | while ( (c = *pcsz)
|
---|
295 | && RT_C_IS_DIGIT(c)
|
---|
296 | )
|
---|
297 | {
|
---|
298 | strMinor.append(c);
|
---|
299 | ++pcsz;
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | uint32_t ulMajor = RTStrToUInt32(strMajor.c_str());
|
---|
304 | uint32_t ulMinor = RTStrToUInt32(strMinor.c_str());
|
---|
305 |
|
---|
306 | if (ulMajor == 1)
|
---|
307 | {
|
---|
308 | if (ulMinor == 3)
|
---|
309 | m->sv = SettingsVersion_v1_3;
|
---|
310 | else if (ulMinor == 4)
|
---|
311 | m->sv = SettingsVersion_v1_4;
|
---|
312 | else if (ulMinor == 5)
|
---|
313 | m->sv = SettingsVersion_v1_5;
|
---|
314 | else if (ulMinor == 6)
|
---|
315 | m->sv = SettingsVersion_v1_6;
|
---|
316 | else if (ulMinor == 7)
|
---|
317 | m->sv = SettingsVersion_v1_7;
|
---|
318 | else if (ulMinor == 8)
|
---|
319 | m->sv = SettingsVersion_v1_8;
|
---|
320 | else if (ulMinor == 9)
|
---|
321 | m->sv = SettingsVersion_v1_9;
|
---|
322 | else if (ulMinor == 10)
|
---|
323 | m->sv = SettingsVersion_v1_10;
|
---|
324 | else if (ulMinor == 11)
|
---|
325 | m->sv = SettingsVersion_v1_11;
|
---|
326 | else if (ulMinor == 12)
|
---|
327 | m->sv = SettingsVersion_v1_12;
|
---|
328 | else if (ulMinor == 13)
|
---|
329 | m->sv = SettingsVersion_v1_13;
|
---|
330 | else if (ulMinor == 14)
|
---|
331 | m->sv = SettingsVersion_v1_14;
|
---|
332 | else if (ulMinor == 15)
|
---|
333 | m->sv = SettingsVersion_v1_15;
|
---|
334 | else if (ulMinor > 15)
|
---|
335 | m->sv = SettingsVersion_Future;
|
---|
336 | }
|
---|
337 | else if (ulMajor > 1)
|
---|
338 | m->sv = SettingsVersion_Future;
|
---|
339 |
|
---|
340 | Log(("Parsed settings version %d.%d to enum value %d\n", ulMajor, ulMinor, m->sv));
|
---|
341 | }
|
---|
342 |
|
---|
343 | if (m->sv == SettingsVersion_Null)
|
---|
344 | throw ConfigFileError(this, m->pelmRoot, N_("Cannot handle settings version '%s'"), m->strSettingsVersionFull.c_str());
|
---|
345 |
|
---|
346 | // remember the settings version we read in case it gets upgraded later,
|
---|
347 | // so we know when to make backups
|
---|
348 | m->svRead = m->sv;
|
---|
349 | }
|
---|
350 | else
|
---|
351 | {
|
---|
352 | // creating new settings file:
|
---|
353 | m->strSettingsVersionFull = VBOX_XML_VERSION_FULL;
|
---|
354 | m->sv = SettingsVersion_v1_12;
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | ConfigFileBase::ConfigFileBase(const ConfigFileBase &other)
|
---|
359 | : m(new Data)
|
---|
360 | {
|
---|
361 | copyBaseFrom(other);
|
---|
362 | m->strFilename = "";
|
---|
363 | m->fFileExists = false;
|
---|
364 | }
|
---|
365 |
|
---|
366 | /**
|
---|
367 | * Clean up.
|
---|
368 | */
|
---|
369 | ConfigFileBase::~ConfigFileBase()
|
---|
370 | {
|
---|
371 | if (m)
|
---|
372 | {
|
---|
373 | delete m;
|
---|
374 | m = NULL;
|
---|
375 | }
|
---|
376 | }
|
---|
377 |
|
---|
378 | /**
|
---|
379 | * Helper function that parses a UUID in string form into
|
---|
380 | * a com::Guid item. Accepts UUIDs both with and without
|
---|
381 | * "{}" brackets. Throws on errors.
|
---|
382 | * @param guid
|
---|
383 | * @param strUUID
|
---|
384 | */
|
---|
385 | void ConfigFileBase::parseUUID(Guid &guid,
|
---|
386 | const Utf8Str &strUUID) const
|
---|
387 | {
|
---|
388 | guid = strUUID.c_str();
|
---|
389 | if (guid.isZero())
|
---|
390 | throw ConfigFileError(this, NULL, N_("UUID \"%s\" has zero format"), strUUID.c_str());
|
---|
391 | else if (!guid.isValid())
|
---|
392 | throw ConfigFileError(this, NULL, N_("UUID \"%s\" has invalid format"), strUUID.c_str());
|
---|
393 | }
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Parses the given string in str and attempts to treat it as an ISO
|
---|
397 | * date/time stamp to put into timestamp. Throws on errors.
|
---|
398 | * @param timestamp
|
---|
399 | * @param str
|
---|
400 | */
|
---|
401 | void ConfigFileBase::parseTimestamp(RTTIMESPEC ×tamp,
|
---|
402 | const com::Utf8Str &str) const
|
---|
403 | {
|
---|
404 | const char *pcsz = str.c_str();
|
---|
405 | // yyyy-mm-ddThh:mm:ss
|
---|
406 | // "2009-07-10T11:54:03Z"
|
---|
407 | // 01234567890123456789
|
---|
408 | // 1
|
---|
409 | if (str.length() > 19)
|
---|
410 | {
|
---|
411 | // timezone must either be unspecified or 'Z' for UTC
|
---|
412 | if ( (pcsz[19])
|
---|
413 | && (pcsz[19] != 'Z')
|
---|
414 | )
|
---|
415 | throw ConfigFileError(this, NULL, N_("Cannot handle ISO timestamp '%s': is not UTC date"), str.c_str());
|
---|
416 |
|
---|
417 | int32_t yyyy;
|
---|
418 | uint32_t mm, dd, hh, min, secs;
|
---|
419 | if ( (pcsz[4] == '-')
|
---|
420 | && (pcsz[7] == '-')
|
---|
421 | && (pcsz[10] == 'T')
|
---|
422 | && (pcsz[13] == ':')
|
---|
423 | && (pcsz[16] == ':')
|
---|
424 | )
|
---|
425 | {
|
---|
426 | int rc;
|
---|
427 | if ( (RT_SUCCESS(rc = RTStrToInt32Ex(pcsz, NULL, 0, &yyyy)))
|
---|
428 | // could theoretically be negative but let's assume that nobody
|
---|
429 | // created virtual machines before the Christian era
|
---|
430 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 5, NULL, 0, &mm)))
|
---|
431 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 8, NULL, 0, &dd)))
|
---|
432 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 11, NULL, 0, &hh)))
|
---|
433 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 14, NULL, 0, &min)))
|
---|
434 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 17, NULL, 0, &secs)))
|
---|
435 | )
|
---|
436 | {
|
---|
437 | RTTIME time =
|
---|
438 | {
|
---|
439 | yyyy,
|
---|
440 | (uint8_t)mm,
|
---|
441 | 0,
|
---|
442 | 0,
|
---|
443 | (uint8_t)dd,
|
---|
444 | (uint8_t)hh,
|
---|
445 | (uint8_t)min,
|
---|
446 | (uint8_t)secs,
|
---|
447 | 0,
|
---|
448 | RTTIME_FLAGS_TYPE_UTC,
|
---|
449 | 0
|
---|
450 | };
|
---|
451 | if (RTTimeNormalize(&time))
|
---|
452 | if (RTTimeImplode(×tamp, &time))
|
---|
453 | return;
|
---|
454 | }
|
---|
455 |
|
---|
456 | throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': runtime error, %Rra"), str.c_str(), rc);
|
---|
457 | }
|
---|
458 |
|
---|
459 | throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': invalid format"), str.c_str());
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | /**
|
---|
464 | * Helper to create a string for a RTTIMESPEC for writing out ISO timestamps.
|
---|
465 | * @param stamp
|
---|
466 | * @return
|
---|
467 | */
|
---|
468 | com::Utf8Str ConfigFileBase::makeString(const RTTIMESPEC &stamp)
|
---|
469 | {
|
---|
470 | RTTIME time;
|
---|
471 | if (!RTTimeExplode(&time, &stamp))
|
---|
472 | throw ConfigFileError(this, NULL, N_("Timespec %lld ms is invalid"), RTTimeSpecGetMilli(&stamp));
|
---|
473 |
|
---|
474 | return Utf8StrFmt("%04u-%02u-%02uT%02u:%02u:%02uZ",
|
---|
475 | time.i32Year, time.u8Month, time.u8MonthDay,
|
---|
476 | time.u8Hour, time.u8Minute, time.u8Second);
|
---|
477 | }
|
---|
478 |
|
---|
479 | /**
|
---|
480 | * Helper method to read in an ExtraData subtree and stores its contents
|
---|
481 | * in the given map of extradata items. Used for both main and machine
|
---|
482 | * extradata (MainConfigFile and MachineConfigFile).
|
---|
483 | * @param elmExtraData
|
---|
484 | * @param map
|
---|
485 | */
|
---|
486 | void ConfigFileBase::readExtraData(const xml::ElementNode &elmExtraData,
|
---|
487 | StringsMap &map)
|
---|
488 | {
|
---|
489 | xml::NodesLoop nlLevel4(elmExtraData);
|
---|
490 | const xml::ElementNode *pelmExtraDataItem;
|
---|
491 | while ((pelmExtraDataItem = nlLevel4.forAllNodes()))
|
---|
492 | {
|
---|
493 | if (pelmExtraDataItem->nameEquals("ExtraDataItem"))
|
---|
494 | {
|
---|
495 | // <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/>
|
---|
496 | Utf8Str strName, strValue;
|
---|
497 | if ( pelmExtraDataItem->getAttributeValue("name", strName)
|
---|
498 | && pelmExtraDataItem->getAttributeValue("value", strValue) )
|
---|
499 | map[strName] = strValue;
|
---|
500 | else
|
---|
501 | throw ConfigFileError(this, pelmExtraDataItem, N_("Required ExtraDataItem/@name or @value attribute is missing"));
|
---|
502 | }
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | /**
|
---|
507 | * Reads <USBDeviceFilter> entries from under the given elmDeviceFilters node and
|
---|
508 | * stores them in the given linklist. This is in ConfigFileBase because it's used
|
---|
509 | * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
|
---|
510 | * filters).
|
---|
511 | * @param elmDeviceFilters
|
---|
512 | * @param ll
|
---|
513 | */
|
---|
514 | void ConfigFileBase::readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
|
---|
515 | USBDeviceFiltersList &ll)
|
---|
516 | {
|
---|
517 | xml::NodesLoop nl1(elmDeviceFilters, "DeviceFilter");
|
---|
518 | const xml::ElementNode *pelmLevel4Child;
|
---|
519 | while ((pelmLevel4Child = nl1.forAllNodes()))
|
---|
520 | {
|
---|
521 | USBDeviceFilter flt;
|
---|
522 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
523 | Utf8Str strAction;
|
---|
524 | if ( pelmLevel4Child->getAttributeValue("name", flt.strName)
|
---|
525 | && pelmLevel4Child->getAttributeValue("active", flt.fActive))
|
---|
526 | {
|
---|
527 | if (!pelmLevel4Child->getAttributeValue("vendorId", flt.strVendorId))
|
---|
528 | pelmLevel4Child->getAttributeValue("vendorid", flt.strVendorId); // used before 1.3
|
---|
529 | if (!pelmLevel4Child->getAttributeValue("productId", flt.strProductId))
|
---|
530 | pelmLevel4Child->getAttributeValue("productid", flt.strProductId); // used before 1.3
|
---|
531 | pelmLevel4Child->getAttributeValue("revision", flt.strRevision);
|
---|
532 | pelmLevel4Child->getAttributeValue("manufacturer", flt.strManufacturer);
|
---|
533 | pelmLevel4Child->getAttributeValue("product", flt.strProduct);
|
---|
534 | if (!pelmLevel4Child->getAttributeValue("serialNumber", flt.strSerialNumber))
|
---|
535 | pelmLevel4Child->getAttributeValue("serialnumber", flt.strSerialNumber); // used before 1.3
|
---|
536 | pelmLevel4Child->getAttributeValue("port", flt.strPort);
|
---|
537 |
|
---|
538 | // the next 2 are irrelevant for host USB objects
|
---|
539 | pelmLevel4Child->getAttributeValue("remote", flt.strRemote);
|
---|
540 | pelmLevel4Child->getAttributeValue("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
541 |
|
---|
542 | // action is only used with host USB objects
|
---|
543 | if (pelmLevel4Child->getAttributeValue("action", strAction))
|
---|
544 | {
|
---|
545 | if (strAction == "Ignore")
|
---|
546 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
547 | else if (strAction == "Hold")
|
---|
548 | flt.action = USBDeviceFilterAction_Hold;
|
---|
549 | else
|
---|
550 | throw ConfigFileError(this, pelmLevel4Child, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
|
---|
551 | }
|
---|
552 |
|
---|
553 | ll.push_back(flt);
|
---|
554 | }
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 | /**
|
---|
559 | * Reads a media registry entry from the main VirtualBox.xml file.
|
---|
560 | *
|
---|
561 | * Whereas the current media registry code is fairly straightforward, it was quite a mess
|
---|
562 | * with settings format before 1.4 (VirtualBox 2.0 used settings format 1.3). The elements
|
---|
563 | * in the media registry were much more inconsistent, and different elements were used
|
---|
564 | * depending on the type of device and image.
|
---|
565 | *
|
---|
566 | * @param t
|
---|
567 | * @param elmMedium
|
---|
568 | * @param llMedia
|
---|
569 | */
|
---|
570 | void ConfigFileBase::readMedium(MediaType t,
|
---|
571 | const xml::ElementNode &elmMedium, // HardDisk node if root; if recursing,
|
---|
572 | // child HardDisk node or DiffHardDisk node for pre-1.4
|
---|
573 | MediaList &llMedia) // list to append medium to (root disk or child list)
|
---|
574 | {
|
---|
575 | // <HardDisk uuid="{5471ecdb-1ddb-4012-a801-6d98e226868b}" location="/mnt/innotek-unix/vdis/Windows XP.vdi" format="VDI" type="Normal">
|
---|
576 | settings::Medium med;
|
---|
577 | Utf8Str strUUID;
|
---|
578 | if (!elmMedium.getAttributeValue("uuid", strUUID))
|
---|
579 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName());
|
---|
580 |
|
---|
581 | parseUUID(med.uuid, strUUID);
|
---|
582 |
|
---|
583 | bool fNeedsLocation = true;
|
---|
584 |
|
---|
585 | if (t == HardDisk)
|
---|
586 | {
|
---|
587 | if (m->sv < SettingsVersion_v1_4)
|
---|
588 | {
|
---|
589 | // here the system is:
|
---|
590 | // <HardDisk uuid="{....}" type="normal">
|
---|
591 | // <VirtualDiskImage filePath="/path/to/xxx.vdi"/>
|
---|
592 | // </HardDisk>
|
---|
593 |
|
---|
594 | fNeedsLocation = false;
|
---|
595 | bool fNeedsFilePath = true;
|
---|
596 | const xml::ElementNode *pelmImage;
|
---|
597 | if ((pelmImage = elmMedium.findChildElement("VirtualDiskImage")))
|
---|
598 | med.strFormat = "VDI";
|
---|
599 | else if ((pelmImage = elmMedium.findChildElement("VMDKImage")))
|
---|
600 | med.strFormat = "VMDK";
|
---|
601 | else if ((pelmImage = elmMedium.findChildElement("VHDImage")))
|
---|
602 | med.strFormat = "VHD";
|
---|
603 | else if ((pelmImage = elmMedium.findChildElement("ISCSIHardDisk")))
|
---|
604 | {
|
---|
605 | med.strFormat = "iSCSI";
|
---|
606 |
|
---|
607 | fNeedsFilePath = false;
|
---|
608 | // location is special here: current settings specify an "iscsi://user@server:port/target/lun"
|
---|
609 | // string for the location and also have several disk properties for these, whereas this used
|
---|
610 | // to be hidden in several sub-elements before 1.4, so compose a location string and set up
|
---|
611 | // the properties:
|
---|
612 | med.strLocation = "iscsi://";
|
---|
613 | Utf8Str strUser, strServer, strPort, strTarget, strLun;
|
---|
614 | if (pelmImage->getAttributeValue("userName", strUser))
|
---|
615 | {
|
---|
616 | med.strLocation.append(strUser);
|
---|
617 | med.strLocation.append("@");
|
---|
618 | }
|
---|
619 | Utf8Str strServerAndPort;
|
---|
620 | if (pelmImage->getAttributeValue("server", strServer))
|
---|
621 | {
|
---|
622 | strServerAndPort = strServer;
|
---|
623 | }
|
---|
624 | if (pelmImage->getAttributeValue("port", strPort))
|
---|
625 | {
|
---|
626 | if (strServerAndPort.length())
|
---|
627 | strServerAndPort.append(":");
|
---|
628 | strServerAndPort.append(strPort);
|
---|
629 | }
|
---|
630 | med.strLocation.append(strServerAndPort);
|
---|
631 | if (pelmImage->getAttributeValue("target", strTarget))
|
---|
632 | {
|
---|
633 | med.strLocation.append("/");
|
---|
634 | med.strLocation.append(strTarget);
|
---|
635 | }
|
---|
636 | if (pelmImage->getAttributeValue("lun", strLun))
|
---|
637 | {
|
---|
638 | med.strLocation.append("/");
|
---|
639 | med.strLocation.append(strLun);
|
---|
640 | }
|
---|
641 |
|
---|
642 | if (strServer.length() && strPort.length())
|
---|
643 | med.properties["TargetAddress"] = strServerAndPort;
|
---|
644 | if (strTarget.length())
|
---|
645 | med.properties["TargetName"] = strTarget;
|
---|
646 | if (strUser.length())
|
---|
647 | med.properties["InitiatorUsername"] = strUser;
|
---|
648 | Utf8Str strPassword;
|
---|
649 | if (pelmImage->getAttributeValue("password", strPassword))
|
---|
650 | med.properties["InitiatorSecret"] = strPassword;
|
---|
651 | if (strLun.length())
|
---|
652 | med.properties["LUN"] = strLun;
|
---|
653 | }
|
---|
654 | else if ((pelmImage = elmMedium.findChildElement("CustomHardDisk")))
|
---|
655 | {
|
---|
656 | fNeedsFilePath = false;
|
---|
657 | fNeedsLocation = true;
|
---|
658 | // also requires @format attribute, which will be queried below
|
---|
659 | }
|
---|
660 | else
|
---|
661 | throw ConfigFileError(this, &elmMedium, N_("Required %s/VirtualDiskImage element is missing"), elmMedium.getName());
|
---|
662 |
|
---|
663 | if (fNeedsFilePath)
|
---|
664 | {
|
---|
665 | if (!(pelmImage->getAttributeValuePath("filePath", med.strLocation)))
|
---|
666 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
|
---|
667 | }
|
---|
668 | }
|
---|
669 |
|
---|
670 | if (med.strFormat.isEmpty()) // not set with 1.4 format above, or 1.4 Custom format?
|
---|
671 | if (!elmMedium.getAttributeValue("format", med.strFormat))
|
---|
672 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName());
|
---|
673 |
|
---|
674 | if (!elmMedium.getAttributeValue("autoReset", med.fAutoReset))
|
---|
675 | med.fAutoReset = false;
|
---|
676 |
|
---|
677 | Utf8Str strType;
|
---|
678 | if (elmMedium.getAttributeValue("type", strType))
|
---|
679 | {
|
---|
680 | // pre-1.4 used lower case, so make this case-insensitive
|
---|
681 | strType.toUpper();
|
---|
682 | if (strType == "NORMAL")
|
---|
683 | med.hdType = MediumType_Normal;
|
---|
684 | else if (strType == "IMMUTABLE")
|
---|
685 | med.hdType = MediumType_Immutable;
|
---|
686 | else if (strType == "WRITETHROUGH")
|
---|
687 | med.hdType = MediumType_Writethrough;
|
---|
688 | else if (strType == "SHAREABLE")
|
---|
689 | med.hdType = MediumType_Shareable;
|
---|
690 | else if (strType == "READONLY")
|
---|
691 | med.hdType = MediumType_Readonly;
|
---|
692 | else if (strType == "MULTIATTACH")
|
---|
693 | med.hdType = MediumType_MultiAttach;
|
---|
694 | else
|
---|
695 | throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable, Writethrough, Shareable, Readonly or MultiAttach"));
|
---|
696 | }
|
---|
697 | }
|
---|
698 | else
|
---|
699 | {
|
---|
700 | if (m->sv < SettingsVersion_v1_4)
|
---|
701 | {
|
---|
702 | // DVD and floppy images before 1.4 had "src" attribute instead of "location"
|
---|
703 | if (!elmMedium.getAttributeValue("src", med.strLocation))
|
---|
704 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
|
---|
705 |
|
---|
706 | fNeedsLocation = false;
|
---|
707 | }
|
---|
708 |
|
---|
709 | if (!elmMedium.getAttributeValue("format", med.strFormat))
|
---|
710 | {
|
---|
711 | // DVD and floppy images before 1.11 had no format attribute. assign the default.
|
---|
712 | med.strFormat = "RAW";
|
---|
713 | }
|
---|
714 |
|
---|
715 | if (t == DVDImage)
|
---|
716 | med.hdType = MediumType_Readonly;
|
---|
717 | else if (t == FloppyImage)
|
---|
718 | med.hdType = MediumType_Writethrough;
|
---|
719 | }
|
---|
720 |
|
---|
721 | if (fNeedsLocation)
|
---|
722 | // current files and 1.4 CustomHardDisk elements must have a location attribute
|
---|
723 | if (!elmMedium.getAttributeValue("location", med.strLocation))
|
---|
724 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName());
|
---|
725 |
|
---|
726 | elmMedium.getAttributeValue("Description", med.strDescription); // optional
|
---|
727 |
|
---|
728 | // recurse to handle children
|
---|
729 | xml::NodesLoop nl2(elmMedium);
|
---|
730 | const xml::ElementNode *pelmHDChild;
|
---|
731 | while ((pelmHDChild = nl2.forAllNodes()))
|
---|
732 | {
|
---|
733 | if ( t == HardDisk
|
---|
734 | && ( pelmHDChild->nameEquals("HardDisk")
|
---|
735 | || ( (m->sv < SettingsVersion_v1_4)
|
---|
736 | && (pelmHDChild->nameEquals("DiffHardDisk"))
|
---|
737 | )
|
---|
738 | )
|
---|
739 | )
|
---|
740 | // recurse with this element and push the child onto our current children list
|
---|
741 | readMedium(t,
|
---|
742 | *pelmHDChild,
|
---|
743 | med.llChildren);
|
---|
744 | else if (pelmHDChild->nameEquals("Property"))
|
---|
745 | {
|
---|
746 | Utf8Str strPropName, strPropValue;
|
---|
747 | if ( pelmHDChild->getAttributeValue("name", strPropName)
|
---|
748 | && pelmHDChild->getAttributeValue("value", strPropValue) )
|
---|
749 | med.properties[strPropName] = strPropValue;
|
---|
750 | else
|
---|
751 | throw ConfigFileError(this, pelmHDChild, N_("Required HardDisk/Property/@name or @value attribute is missing"));
|
---|
752 | }
|
---|
753 | }
|
---|
754 |
|
---|
755 | llMedia.push_back(med);
|
---|
756 | }
|
---|
757 |
|
---|
758 | /**
|
---|
759 | * Reads in the entire <MediaRegistry> chunk and stores its media in the lists
|
---|
760 | * of the given MediaRegistry structure.
|
---|
761 | *
|
---|
762 | * This is used in both MainConfigFile and MachineConfigFile since starting with
|
---|
763 | * VirtualBox 4.0, we can have media registries in both.
|
---|
764 | *
|
---|
765 | * For pre-1.4 files, this gets called with the <DiskRegistry> chunk instead.
|
---|
766 | *
|
---|
767 | * @param elmMediaRegistry
|
---|
768 | */
|
---|
769 | void ConfigFileBase::readMediaRegistry(const xml::ElementNode &elmMediaRegistry,
|
---|
770 | MediaRegistry &mr)
|
---|
771 | {
|
---|
772 | xml::NodesLoop nl1(elmMediaRegistry);
|
---|
773 | const xml::ElementNode *pelmChild1;
|
---|
774 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
775 | {
|
---|
776 | MediaType t = Error;
|
---|
777 | if (pelmChild1->nameEquals("HardDisks"))
|
---|
778 | t = HardDisk;
|
---|
779 | else if (pelmChild1->nameEquals("DVDImages"))
|
---|
780 | t = DVDImage;
|
---|
781 | else if (pelmChild1->nameEquals("FloppyImages"))
|
---|
782 | t = FloppyImage;
|
---|
783 | else
|
---|
784 | continue;
|
---|
785 |
|
---|
786 | xml::NodesLoop nl2(*pelmChild1);
|
---|
787 | const xml::ElementNode *pelmMedium;
|
---|
788 | while ((pelmMedium = nl2.forAllNodes()))
|
---|
789 | {
|
---|
790 | if ( t == HardDisk
|
---|
791 | && (pelmMedium->nameEquals("HardDisk"))
|
---|
792 | )
|
---|
793 | readMedium(t,
|
---|
794 | *pelmMedium,
|
---|
795 | mr.llHardDisks); // list to append hard disk data to: the root list
|
---|
796 | else if ( t == DVDImage
|
---|
797 | && (pelmMedium->nameEquals("Image"))
|
---|
798 | )
|
---|
799 | readMedium(t,
|
---|
800 | *pelmMedium,
|
---|
801 | mr.llDvdImages); // list to append dvd images to: the root list
|
---|
802 | else if ( t == FloppyImage
|
---|
803 | && (pelmMedium->nameEquals("Image"))
|
---|
804 | )
|
---|
805 | readMedium(t,
|
---|
806 | *pelmMedium,
|
---|
807 | mr.llFloppyImages); // list to append floppy images to: the root list
|
---|
808 | }
|
---|
809 | }
|
---|
810 | }
|
---|
811 |
|
---|
812 | /**
|
---|
813 | * This is common version for reading NAT port forward rule in per-_machine's_adapter_ and
|
---|
814 | * per-network approaches.
|
---|
815 | * Note: this function doesn't in fill given list from xml::ElementNodesList, because there is conflicting
|
---|
816 | * declaration in ovmfreader.h.
|
---|
817 | */
|
---|
818 | void ConfigFileBase::readNATForwardRuleList(const xml::ElementNode &elmParent, NATRuleList &llRules)
|
---|
819 | {
|
---|
820 | xml::ElementNodesList plstRules;
|
---|
821 | elmParent.getChildElements(plstRules, "Forwarding");
|
---|
822 | for (xml::ElementNodesList::iterator pf = plstRules.begin(); pf != plstRules.end(); ++pf)
|
---|
823 | {
|
---|
824 | NATRule rule;
|
---|
825 | uint32_t port = 0;
|
---|
826 | (*pf)->getAttributeValue("name", rule.strName);
|
---|
827 | (*pf)->getAttributeValue("proto", (uint32_t&)rule.proto);
|
---|
828 | (*pf)->getAttributeValue("hostip", rule.strHostIP);
|
---|
829 | (*pf)->getAttributeValue("hostport", port);
|
---|
830 | rule.u16HostPort = port;
|
---|
831 | (*pf)->getAttributeValue("guestip", rule.strGuestIP);
|
---|
832 | (*pf)->getAttributeValue("guestport", port);
|
---|
833 | rule.u16GuestPort = port;
|
---|
834 | llRules.push_back(rule);
|
---|
835 | }
|
---|
836 | }
|
---|
837 |
|
---|
838 | void ConfigFileBase::readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopbacks)
|
---|
839 | {
|
---|
840 | xml::ElementNodesList plstLoopbacks;
|
---|
841 | elmParent.getChildElements(plstLoopbacks, "Loopback4");
|
---|
842 | for (xml::ElementNodesList::iterator lo = plstLoopbacks.begin();
|
---|
843 | lo != plstLoopbacks.end(); ++lo)
|
---|
844 | {
|
---|
845 | NATHostLoopbackOffset loopback;
|
---|
846 | (*lo)->getAttributeValue("address", loopback.strLoopbackHostAddress);
|
---|
847 | (*lo)->getAttributeValue("offset", (uint32_t&)loopback.u32Offset);
|
---|
848 | llLoopbacks.push_back(loopback);
|
---|
849 | }
|
---|
850 | }
|
---|
851 |
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * Adds a "version" attribute to the given XML element with the
|
---|
855 | * VirtualBox settings version (e.g. "1.10-linux"). Used by
|
---|
856 | * the XML format for the root element and by the OVF export
|
---|
857 | * for the vbox:Machine element.
|
---|
858 | * @param elm
|
---|
859 | */
|
---|
860 | void ConfigFileBase::setVersionAttribute(xml::ElementNode &elm)
|
---|
861 | {
|
---|
862 | const char *pcszVersion = NULL;
|
---|
863 | switch (m->sv)
|
---|
864 | {
|
---|
865 | case SettingsVersion_v1_8:
|
---|
866 | pcszVersion = "1.8";
|
---|
867 | break;
|
---|
868 |
|
---|
869 | case SettingsVersion_v1_9:
|
---|
870 | pcszVersion = "1.9";
|
---|
871 | break;
|
---|
872 |
|
---|
873 | case SettingsVersion_v1_10:
|
---|
874 | pcszVersion = "1.10";
|
---|
875 | break;
|
---|
876 |
|
---|
877 | case SettingsVersion_v1_11:
|
---|
878 | pcszVersion = "1.11";
|
---|
879 | break;
|
---|
880 |
|
---|
881 | case SettingsVersion_v1_12:
|
---|
882 | pcszVersion = "1.12";
|
---|
883 | break;
|
---|
884 |
|
---|
885 | case SettingsVersion_v1_13:
|
---|
886 | pcszVersion = "1.13";
|
---|
887 | break;
|
---|
888 |
|
---|
889 | case SettingsVersion_v1_14:
|
---|
890 | pcszVersion = "1.14";
|
---|
891 | break;
|
---|
892 |
|
---|
893 | case SettingsVersion_v1_15:
|
---|
894 | pcszVersion = "1.15";
|
---|
895 | break;
|
---|
896 |
|
---|
897 | case SettingsVersion_Future:
|
---|
898 | // can be set if this code runs on XML files that were created by a future version of VBox;
|
---|
899 | // in that case, downgrade to current version when writing since we can't write future versions...
|
---|
900 | pcszVersion = "1.15";
|
---|
901 | m->sv = SettingsVersion_v1_15;
|
---|
902 | break;
|
---|
903 |
|
---|
904 | default:
|
---|
905 | // silently upgrade if this is less than 1.7 because that's the oldest we can write
|
---|
906 | pcszVersion = "1.7";
|
---|
907 | m->sv = SettingsVersion_v1_7;
|
---|
908 | break;
|
---|
909 | }
|
---|
910 |
|
---|
911 | elm.setAttribute("version", Utf8StrFmt("%s-%s",
|
---|
912 | pcszVersion,
|
---|
913 | VBOX_XML_PLATFORM)); // e.g. "linux"
|
---|
914 | }
|
---|
915 |
|
---|
916 | /**
|
---|
917 | * Creates a new stub xml::Document in the m->pDoc member with the
|
---|
918 | * root "VirtualBox" element set up. This is used by both
|
---|
919 | * MainConfigFile and MachineConfigFile at the beginning of writing
|
---|
920 | * out their XML.
|
---|
921 | *
|
---|
922 | * Before calling this, it is the responsibility of the caller to
|
---|
923 | * set the "sv" member to the required settings version that is to
|
---|
924 | * be written. For newly created files, the settings version will be
|
---|
925 | * the latest (1.12); for files read in from disk earlier, it will be
|
---|
926 | * the settings version indicated in the file. However, this method
|
---|
927 | * will silently make sure that the settings version is always
|
---|
928 | * at least 1.7 and change it if necessary, since there is no write
|
---|
929 | * support for earlier settings versions.
|
---|
930 | */
|
---|
931 | void ConfigFileBase::createStubDocument()
|
---|
932 | {
|
---|
933 | Assert(m->pDoc == NULL);
|
---|
934 | m->pDoc = new xml::Document;
|
---|
935 |
|
---|
936 | m->pelmRoot = m->pDoc->createRootElement("VirtualBox",
|
---|
937 | "\n"
|
---|
938 | "** DO NOT EDIT THIS FILE.\n"
|
---|
939 | "** If you make changes to this file while any VirtualBox related application\n"
|
---|
940 | "** is running, your changes will be overwritten later, without taking effect.\n"
|
---|
941 | "** Use VBoxManage or the VirtualBox Manager GUI to make changes.\n"
|
---|
942 | );
|
---|
943 | m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
|
---|
944 |
|
---|
945 | // add settings version attribute to root element
|
---|
946 | setVersionAttribute(*m->pelmRoot);
|
---|
947 |
|
---|
948 | // since this gets called before the XML document is actually written out,
|
---|
949 | // this is where we must check whether we're upgrading the settings version
|
---|
950 | // and need to make a backup, so the user can go back to an earlier
|
---|
951 | // VirtualBox version and recover his old settings files.
|
---|
952 | if ( (m->svRead != SettingsVersion_Null) // old file exists?
|
---|
953 | && (m->svRead < m->sv) // we're upgrading?
|
---|
954 | )
|
---|
955 | {
|
---|
956 | // compose new filename: strip off trailing ".xml"/".vbox"
|
---|
957 | Utf8Str strFilenameNew;
|
---|
958 | Utf8Str strExt = ".xml";
|
---|
959 | if (m->strFilename.endsWith(".xml"))
|
---|
960 | strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
|
---|
961 | else if (m->strFilename.endsWith(".vbox"))
|
---|
962 | {
|
---|
963 | strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 5);
|
---|
964 | strExt = ".vbox";
|
---|
965 | }
|
---|
966 |
|
---|
967 | // and append something like "-1.3-linux.xml"
|
---|
968 | strFilenameNew.append("-");
|
---|
969 | strFilenameNew.append(m->strSettingsVersionFull); // e.g. "1.3-linux"
|
---|
970 | strFilenameNew.append(strExt); // .xml for main config, .vbox for machine config
|
---|
971 |
|
---|
972 | RTFileMove(m->strFilename.c_str(),
|
---|
973 | strFilenameNew.c_str(),
|
---|
974 | 0); // no RTFILEMOVE_FLAGS_REPLACE
|
---|
975 |
|
---|
976 | // do this only once
|
---|
977 | m->svRead = SettingsVersion_Null;
|
---|
978 | }
|
---|
979 | }
|
---|
980 |
|
---|
981 | /**
|
---|
982 | * Creates an <ExtraData> node under the given parent element with
|
---|
983 | * <ExtraDataItem> childern according to the contents of the given
|
---|
984 | * map.
|
---|
985 | *
|
---|
986 | * This is in ConfigFileBase because it's used in both MainConfigFile
|
---|
987 | * and MachineConfigFile, which both can have extradata.
|
---|
988 | *
|
---|
989 | * @param elmParent
|
---|
990 | * @param me
|
---|
991 | */
|
---|
992 | void ConfigFileBase::buildExtraData(xml::ElementNode &elmParent,
|
---|
993 | const StringsMap &me)
|
---|
994 | {
|
---|
995 | if (me.size())
|
---|
996 | {
|
---|
997 | xml::ElementNode *pelmExtraData = elmParent.createChild("ExtraData");
|
---|
998 | for (StringsMap::const_iterator it = me.begin();
|
---|
999 | it != me.end();
|
---|
1000 | ++it)
|
---|
1001 | {
|
---|
1002 | const Utf8Str &strName = it->first;
|
---|
1003 | const Utf8Str &strValue = it->second;
|
---|
1004 | xml::ElementNode *pelmThis = pelmExtraData->createChild("ExtraDataItem");
|
---|
1005 | pelmThis->setAttribute("name", strName);
|
---|
1006 | pelmThis->setAttribute("value", strValue);
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | /**
|
---|
1012 | * Creates <DeviceFilter> nodes under the given parent element according to
|
---|
1013 | * the contents of the given USBDeviceFiltersList. This is in ConfigFileBase
|
---|
1014 | * because it's used in both MainConfigFile (for host filters) and
|
---|
1015 | * MachineConfigFile (for machine filters).
|
---|
1016 | *
|
---|
1017 | * If fHostMode is true, this means that we're supposed to write filters
|
---|
1018 | * for the IHost interface (respect "action", omit "strRemote" and
|
---|
1019 | * "ulMaskedInterfaces" in struct USBDeviceFilter).
|
---|
1020 | *
|
---|
1021 | * @param elmParent
|
---|
1022 | * @param ll
|
---|
1023 | * @param fHostMode
|
---|
1024 | */
|
---|
1025 | void ConfigFileBase::buildUSBDeviceFilters(xml::ElementNode &elmParent,
|
---|
1026 | const USBDeviceFiltersList &ll,
|
---|
1027 | bool fHostMode)
|
---|
1028 | {
|
---|
1029 | for (USBDeviceFiltersList::const_iterator it = ll.begin();
|
---|
1030 | it != ll.end();
|
---|
1031 | ++it)
|
---|
1032 | {
|
---|
1033 | const USBDeviceFilter &flt = *it;
|
---|
1034 | xml::ElementNode *pelmFilter = elmParent.createChild("DeviceFilter");
|
---|
1035 | pelmFilter->setAttribute("name", flt.strName);
|
---|
1036 | pelmFilter->setAttribute("active", flt.fActive);
|
---|
1037 | if (flt.strVendorId.length())
|
---|
1038 | pelmFilter->setAttribute("vendorId", flt.strVendorId);
|
---|
1039 | if (flt.strProductId.length())
|
---|
1040 | pelmFilter->setAttribute("productId", flt.strProductId);
|
---|
1041 | if (flt.strRevision.length())
|
---|
1042 | pelmFilter->setAttribute("revision", flt.strRevision);
|
---|
1043 | if (flt.strManufacturer.length())
|
---|
1044 | pelmFilter->setAttribute("manufacturer", flt.strManufacturer);
|
---|
1045 | if (flt.strProduct.length())
|
---|
1046 | pelmFilter->setAttribute("product", flt.strProduct);
|
---|
1047 | if (flt.strSerialNumber.length())
|
---|
1048 | pelmFilter->setAttribute("serialNumber", flt.strSerialNumber);
|
---|
1049 | if (flt.strPort.length())
|
---|
1050 | pelmFilter->setAttribute("port", flt.strPort);
|
---|
1051 |
|
---|
1052 | if (fHostMode)
|
---|
1053 | {
|
---|
1054 | const char *pcsz =
|
---|
1055 | (flt.action == USBDeviceFilterAction_Ignore) ? "Ignore"
|
---|
1056 | : /*(flt.action == USBDeviceFilterAction_Hold) ?*/ "Hold";
|
---|
1057 | pelmFilter->setAttribute("action", pcsz);
|
---|
1058 | }
|
---|
1059 | else
|
---|
1060 | {
|
---|
1061 | if (flt.strRemote.length())
|
---|
1062 | pelmFilter->setAttribute("remote", flt.strRemote);
|
---|
1063 | if (flt.ulMaskedInterfaces)
|
---|
1064 | pelmFilter->setAttribute("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * Creates a single <HardDisk> element for the given Medium structure
|
---|
1071 | * and recurses to write the child hard disks underneath. Called from
|
---|
1072 | * MainConfigFile::write().
|
---|
1073 | *
|
---|
1074 | * @param elmMedium
|
---|
1075 | * @param m
|
---|
1076 | * @param level
|
---|
1077 | */
|
---|
1078 | void ConfigFileBase::buildMedium(xml::ElementNode &elmMedium,
|
---|
1079 | DeviceType_T devType,
|
---|
1080 | const Medium &mdm,
|
---|
1081 | uint32_t level) // 0 for "root" call, incremented with each recursion
|
---|
1082 | {
|
---|
1083 | xml::ElementNode *pelmMedium;
|
---|
1084 |
|
---|
1085 | if (devType == DeviceType_HardDisk)
|
---|
1086 | pelmMedium = elmMedium.createChild("HardDisk");
|
---|
1087 | else
|
---|
1088 | pelmMedium = elmMedium.createChild("Image");
|
---|
1089 |
|
---|
1090 | pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
|
---|
1091 |
|
---|
1092 | pelmMedium->setAttributePath("location", mdm.strLocation);
|
---|
1093 |
|
---|
1094 | if (devType == DeviceType_HardDisk || RTStrICmp(mdm.strFormat.c_str(), "RAW"))
|
---|
1095 | pelmMedium->setAttribute("format", mdm.strFormat);
|
---|
1096 | if ( devType == DeviceType_HardDisk
|
---|
1097 | && mdm.fAutoReset)
|
---|
1098 | pelmMedium->setAttribute("autoReset", mdm.fAutoReset);
|
---|
1099 | if (mdm.strDescription.length())
|
---|
1100 | pelmMedium->setAttribute("Description", mdm.strDescription);
|
---|
1101 |
|
---|
1102 | for (StringsMap::const_iterator it = mdm.properties.begin();
|
---|
1103 | it != mdm.properties.end();
|
---|
1104 | ++it)
|
---|
1105 | {
|
---|
1106 | xml::ElementNode *pelmProp = pelmMedium->createChild("Property");
|
---|
1107 | pelmProp->setAttribute("name", it->first);
|
---|
1108 | pelmProp->setAttribute("value", it->second);
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 | // only for base hard disks, save the type
|
---|
1112 | if (level == 0)
|
---|
1113 | {
|
---|
1114 | // no need to save the usual DVD/floppy medium types
|
---|
1115 | if ( ( devType != DeviceType_DVD
|
---|
1116 | || ( mdm.hdType != MediumType_Writethrough // shouldn't happen
|
---|
1117 | && mdm.hdType != MediumType_Readonly))
|
---|
1118 | && ( devType != DeviceType_Floppy
|
---|
1119 | || mdm.hdType != MediumType_Writethrough))
|
---|
1120 | {
|
---|
1121 | const char *pcszType =
|
---|
1122 | mdm.hdType == MediumType_Normal ? "Normal" :
|
---|
1123 | mdm.hdType == MediumType_Immutable ? "Immutable" :
|
---|
1124 | mdm.hdType == MediumType_Writethrough ? "Writethrough" :
|
---|
1125 | mdm.hdType == MediumType_Shareable ? "Shareable" :
|
---|
1126 | mdm.hdType == MediumType_Readonly ? "Readonly" :
|
---|
1127 | mdm.hdType == MediumType_MultiAttach ? "MultiAttach" :
|
---|
1128 | "INVALID";
|
---|
1129 | pelmMedium->setAttribute("type", pcszType);
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | for (MediaList::const_iterator it = mdm.llChildren.begin();
|
---|
1134 | it != mdm.llChildren.end();
|
---|
1135 | ++it)
|
---|
1136 | {
|
---|
1137 | // recurse for children
|
---|
1138 | buildMedium(*pelmMedium, // parent
|
---|
1139 | devType, // device type
|
---|
1140 | *it, // settings::Medium
|
---|
1141 | ++level); // recursion level
|
---|
1142 | }
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | /**
|
---|
1146 | * Creates a <MediaRegistry> node under the given parent and writes out all
|
---|
1147 | * hard disks and DVD and floppy images from the lists in the given MediaRegistry
|
---|
1148 | * structure under it.
|
---|
1149 | *
|
---|
1150 | * This is used in both MainConfigFile and MachineConfigFile since starting with
|
---|
1151 | * VirtualBox 4.0, we can have media registries in both.
|
---|
1152 | *
|
---|
1153 | * @param elmParent
|
---|
1154 | * @param mr
|
---|
1155 | */
|
---|
1156 | void ConfigFileBase::buildMediaRegistry(xml::ElementNode &elmParent,
|
---|
1157 | const MediaRegistry &mr)
|
---|
1158 | {
|
---|
1159 | xml::ElementNode *pelmMediaRegistry = elmParent.createChild("MediaRegistry");
|
---|
1160 |
|
---|
1161 | xml::ElementNode *pelmHardDisks = pelmMediaRegistry->createChild("HardDisks");
|
---|
1162 | for (MediaList::const_iterator it = mr.llHardDisks.begin();
|
---|
1163 | it != mr.llHardDisks.end();
|
---|
1164 | ++it)
|
---|
1165 | {
|
---|
1166 | buildMedium(*pelmHardDisks, DeviceType_HardDisk, *it, 0);
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | xml::ElementNode *pelmDVDImages = pelmMediaRegistry->createChild("DVDImages");
|
---|
1170 | for (MediaList::const_iterator it = mr.llDvdImages.begin();
|
---|
1171 | it != mr.llDvdImages.end();
|
---|
1172 | ++it)
|
---|
1173 | {
|
---|
1174 | buildMedium(*pelmDVDImages, DeviceType_DVD, *it, 0);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | xml::ElementNode *pelmFloppyImages = pelmMediaRegistry->createChild("FloppyImages");
|
---|
1178 | for (MediaList::const_iterator it = mr.llFloppyImages.begin();
|
---|
1179 | it != mr.llFloppyImages.end();
|
---|
1180 | ++it)
|
---|
1181 | {
|
---|
1182 | buildMedium(*pelmFloppyImages, DeviceType_Floppy, *it, 0);
|
---|
1183 | }
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | /**
|
---|
1187 | * Serialize NAT port-forwarding rules in parent container.
|
---|
1188 | * Note: it's responsibility of caller to create parent of the list tag.
|
---|
1189 | * because this method used for serializing per-_mahine's_adapter_ and per-network approaches.
|
---|
1190 | */
|
---|
1191 | void ConfigFileBase::buildNATForwardRuleList(xml::ElementNode &elmParent, const NATRuleList &natRuleList)
|
---|
1192 | {
|
---|
1193 | for (NATRuleList::const_iterator r = natRuleList.begin();
|
---|
1194 | r != natRuleList.end(); ++r)
|
---|
1195 | {
|
---|
1196 | xml::ElementNode *pelmPF;
|
---|
1197 | pelmPF = elmParent.createChild("Forwarding");
|
---|
1198 | if ((*r).strName.length())
|
---|
1199 | pelmPF->setAttribute("name", (*r).strName);
|
---|
1200 | pelmPF->setAttribute("proto", (*r).proto);
|
---|
1201 | if ((*r).strHostIP.length())
|
---|
1202 | pelmPF->setAttribute("hostip", (*r).strHostIP);
|
---|
1203 | if ((*r).u16HostPort)
|
---|
1204 | pelmPF->setAttribute("hostport", (*r).u16HostPort);
|
---|
1205 | if ((*r).strGuestIP.length())
|
---|
1206 | pelmPF->setAttribute("guestip", (*r).strGuestIP);
|
---|
1207 | if ((*r).u16GuestPort)
|
---|
1208 | pelmPF->setAttribute("guestport", (*r).u16GuestPort);
|
---|
1209 | }
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 |
|
---|
1213 | void ConfigFileBase::buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackOffsetList)
|
---|
1214 | {
|
---|
1215 | for (NATLoopbackOffsetList::const_iterator lo = natLoopbackOffsetList.begin();
|
---|
1216 | lo != natLoopbackOffsetList.end(); ++lo)
|
---|
1217 | {
|
---|
1218 | xml::ElementNode *pelmLo;
|
---|
1219 | pelmLo = elmParent.createChild("Loopback4");
|
---|
1220 | pelmLo->setAttribute("address", (*lo).strLoopbackHostAddress);
|
---|
1221 | pelmLo->setAttribute("offset", (*lo).u32Offset);
|
---|
1222 | }
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | /**
|
---|
1226 | * Cleans up memory allocated by the internal XML parser. To be called by
|
---|
1227 | * descendant classes when they're done analyzing the DOM tree to discard it.
|
---|
1228 | */
|
---|
1229 | void ConfigFileBase::clearDocument()
|
---|
1230 | {
|
---|
1231 | m->cleanup();
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | /**
|
---|
1235 | * Returns true only if the underlying config file exists on disk;
|
---|
1236 | * either because the file has been loaded from disk, or it's been written
|
---|
1237 | * to disk, or both.
|
---|
1238 | * @return
|
---|
1239 | */
|
---|
1240 | bool ConfigFileBase::fileExists()
|
---|
1241 | {
|
---|
1242 | return m->fFileExists;
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | /**
|
---|
1246 | * Copies the base variables from another instance. Used by Machine::saveSettings
|
---|
1247 | * so that the settings version does not get lost when a copy of the Machine settings
|
---|
1248 | * file is made to see if settings have actually changed.
|
---|
1249 | * @param b
|
---|
1250 | */
|
---|
1251 | void ConfigFileBase::copyBaseFrom(const ConfigFileBase &b)
|
---|
1252 | {
|
---|
1253 | m->copyFrom(*b.m);
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1257 | //
|
---|
1258 | // Structures shared between Machine XML and VirtualBox.xml
|
---|
1259 | //
|
---|
1260 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1261 |
|
---|
1262 | /**
|
---|
1263 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1264 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1265 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1266 | */
|
---|
1267 | bool USBDeviceFilter::operator==(const USBDeviceFilter &u) const
|
---|
1268 | {
|
---|
1269 | return ( (this == &u)
|
---|
1270 | || ( (strName == u.strName)
|
---|
1271 | && (fActive == u.fActive)
|
---|
1272 | && (strVendorId == u.strVendorId)
|
---|
1273 | && (strProductId == u.strProductId)
|
---|
1274 | && (strRevision == u.strRevision)
|
---|
1275 | && (strManufacturer == u.strManufacturer)
|
---|
1276 | && (strProduct == u.strProduct)
|
---|
1277 | && (strSerialNumber == u.strSerialNumber)
|
---|
1278 | && (strPort == u.strPort)
|
---|
1279 | && (action == u.action)
|
---|
1280 | && (strRemote == u.strRemote)
|
---|
1281 | && (ulMaskedInterfaces == u.ulMaskedInterfaces)
|
---|
1282 | )
|
---|
1283 | );
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1287 | //
|
---|
1288 | // MainConfigFile
|
---|
1289 | //
|
---|
1290 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1291 |
|
---|
1292 | /**
|
---|
1293 | * Reads one <MachineEntry> from the main VirtualBox.xml file.
|
---|
1294 | * @param elmMachineRegistry
|
---|
1295 | */
|
---|
1296 | void MainConfigFile::readMachineRegistry(const xml::ElementNode &elmMachineRegistry)
|
---|
1297 | {
|
---|
1298 | // <MachineEntry uuid="{ xxx }" src=" xxx "/>
|
---|
1299 | xml::NodesLoop nl1(elmMachineRegistry);
|
---|
1300 | const xml::ElementNode *pelmChild1;
|
---|
1301 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
1302 | {
|
---|
1303 | if (pelmChild1->nameEquals("MachineEntry"))
|
---|
1304 | {
|
---|
1305 | MachineRegistryEntry mre;
|
---|
1306 | Utf8Str strUUID;
|
---|
1307 | if ( pelmChild1->getAttributeValue("uuid", strUUID)
|
---|
1308 | && pelmChild1->getAttributeValue("src", mre.strSettingsFile) )
|
---|
1309 | {
|
---|
1310 | parseUUID(mre.uuid, strUUID);
|
---|
1311 | llMachines.push_back(mre);
|
---|
1312 | }
|
---|
1313 | else
|
---|
1314 | throw ConfigFileError(this, pelmChild1, N_("Required MachineEntry/@uuid or @src attribute is missing"));
|
---|
1315 | }
|
---|
1316 | }
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | /**
|
---|
1320 | * Reads in the <DHCPServers> chunk.
|
---|
1321 | * @param elmDHCPServers
|
---|
1322 | */
|
---|
1323 | void MainConfigFile::readDHCPServers(const xml::ElementNode &elmDHCPServers)
|
---|
1324 | {
|
---|
1325 | xml::NodesLoop nl1(elmDHCPServers);
|
---|
1326 | const xml::ElementNode *pelmServer;
|
---|
1327 | while ((pelmServer = nl1.forAllNodes()))
|
---|
1328 | {
|
---|
1329 | if (pelmServer->nameEquals("DHCPServer"))
|
---|
1330 | {
|
---|
1331 | DHCPServer srv;
|
---|
1332 | if ( pelmServer->getAttributeValue("networkName", srv.strNetworkName)
|
---|
1333 | && pelmServer->getAttributeValue("IPAddress", srv.strIPAddress)
|
---|
1334 | && pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask])
|
---|
1335 | && pelmServer->getAttributeValue("lowerIP", srv.strIPLower)
|
---|
1336 | && pelmServer->getAttributeValue("upperIP", srv.strIPUpper)
|
---|
1337 | && pelmServer->getAttributeValue("enabled", srv.fEnabled) )
|
---|
1338 | {
|
---|
1339 | xml::NodesLoop nlOptions(*pelmServer, "Options");
|
---|
1340 | const xml::ElementNode *options;
|
---|
1341 | /* XXX: Options are in 1:1 relation to DHCPServer */
|
---|
1342 |
|
---|
1343 | while ((options = nlOptions.forAllNodes()))
|
---|
1344 | {
|
---|
1345 | readDhcpOptions(srv.GlobalDhcpOptions, *options);
|
---|
1346 | } /* end of forall("Options") */
|
---|
1347 | xml::NodesLoop nlConfig(*pelmServer, "Config");
|
---|
1348 | const xml::ElementNode *cfg;
|
---|
1349 | while ((cfg = nlConfig.forAllNodes()))
|
---|
1350 | {
|
---|
1351 | com::Utf8Str strVmName;
|
---|
1352 | uint32_t u32Slot;
|
---|
1353 | cfg->getAttributeValue("vm-name", strVmName);
|
---|
1354 | cfg->getAttributeValue("slot", u32Slot);
|
---|
1355 | readDhcpOptions(srv.VmSlot2OptionsM[VmNameSlotKey(strVmName, u32Slot)], *cfg);
|
---|
1356 | }
|
---|
1357 | llDhcpServers.push_back(srv);
|
---|
1358 | }
|
---|
1359 | else
|
---|
1360 | throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
|
---|
1361 | }
|
---|
1362 | }
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | void MainConfigFile::readDhcpOptions(DhcpOptionMap& map,
|
---|
1366 | const xml::ElementNode& options)
|
---|
1367 | {
|
---|
1368 | xml::NodesLoop nl2(options, "Option");
|
---|
1369 | const xml::ElementNode *opt;
|
---|
1370 | while ((opt = nl2.forAllNodes()))
|
---|
1371 | {
|
---|
1372 | DhcpOpt_T OptName;
|
---|
1373 | com::Utf8Str OptValue;
|
---|
1374 | opt->getAttributeValue("name", (uint32_t&)OptName);
|
---|
1375 |
|
---|
1376 | if (OptName == DhcpOpt_SubnetMask)
|
---|
1377 | continue;
|
---|
1378 |
|
---|
1379 | opt->getAttributeValue("value", OptValue);
|
---|
1380 |
|
---|
1381 | map.insert(std::map<DhcpOpt_T, Utf8Str>::value_type(OptName, OptValue));
|
---|
1382 | } /* end of forall("Option") */
|
---|
1383 |
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | /**
|
---|
1387 | * Reads in the <NATNetworks> chunk.
|
---|
1388 | * @param elmNATNetworks
|
---|
1389 | */
|
---|
1390 | void MainConfigFile::readNATNetworks(const xml::ElementNode &elmNATNetworks)
|
---|
1391 | {
|
---|
1392 | xml::NodesLoop nl1(elmNATNetworks);
|
---|
1393 | const xml::ElementNode *pelmNet;
|
---|
1394 | while ((pelmNet = nl1.forAllNodes()))
|
---|
1395 | {
|
---|
1396 | if (pelmNet->nameEquals("NATNetwork"))
|
---|
1397 | {
|
---|
1398 | NATNetwork net;
|
---|
1399 | if ( pelmNet->getAttributeValue("networkName", net.strNetworkName)
|
---|
1400 | && pelmNet->getAttributeValue("enabled", net.fEnabled)
|
---|
1401 | && pelmNet->getAttributeValue("network", net.strNetwork)
|
---|
1402 | && pelmNet->getAttributeValue("ipv6", net.fIPv6)
|
---|
1403 | && pelmNet->getAttributeValue("ipv6prefix", net.strIPv6Prefix)
|
---|
1404 | && pelmNet->getAttributeValue("advertiseDefaultIPv6Route", net.fAdvertiseDefaultIPv6Route)
|
---|
1405 | && pelmNet->getAttributeValue("needDhcp", net.fNeedDhcpServer) )
|
---|
1406 | {
|
---|
1407 | pelmNet->getAttributeValue("loopback6", net.u32HostLoopback6Offset);
|
---|
1408 | const xml::ElementNode *pelmMappings;
|
---|
1409 | if ((pelmMappings = pelmNet->findChildElement("Mappings")))
|
---|
1410 | readNATLoopbacks(*pelmMappings, net.llHostLoopbackOffsetList);
|
---|
1411 |
|
---|
1412 | const xml::ElementNode *pelmPortForwardRules4;
|
---|
1413 | if ((pelmPortForwardRules4 = pelmNet->findChildElement("PortForwarding4")))
|
---|
1414 | readNATForwardRuleList(*pelmPortForwardRules4,
|
---|
1415 | net.llPortForwardRules4);
|
---|
1416 |
|
---|
1417 | const xml::ElementNode *pelmPortForwardRules6;
|
---|
1418 | if ((pelmPortForwardRules6 = pelmNet->findChildElement("PortForwarding6")))
|
---|
1419 | readNATForwardRuleList(*pelmPortForwardRules6,
|
---|
1420 | net.llPortForwardRules6);
|
---|
1421 |
|
---|
1422 | llNATNetworks.push_back(net);
|
---|
1423 | }
|
---|
1424 | else
|
---|
1425 | throw ConfigFileError(this, pelmNet, N_("Required NATNetwork/@networkName, @gateway, @network,@advertiseDefaultIpv6Route , @needDhcp or @enabled attribute is missing"));
|
---|
1426 | }
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 |
|
---|
1430 | /**
|
---|
1431 | * Constructor.
|
---|
1432 | *
|
---|
1433 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
1434 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
1435 | * are initialized with default values.
|
---|
1436 | *
|
---|
1437 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
1438 | * the caller should catch; if this constructor does not throw, then the member
|
---|
1439 | * variables contain meaningful values (either from the file or defaults).
|
---|
1440 | *
|
---|
1441 | * @param strFilename
|
---|
1442 | */
|
---|
1443 | MainConfigFile::MainConfigFile(const Utf8Str *pstrFilename)
|
---|
1444 | : ConfigFileBase(pstrFilename)
|
---|
1445 | {
|
---|
1446 | if (pstrFilename)
|
---|
1447 | {
|
---|
1448 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
1449 | // we need only analyze what is in there
|
---|
1450 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
1451 | const xml::ElementNode *pelmRootChild;
|
---|
1452 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
1453 | {
|
---|
1454 | if (pelmRootChild->nameEquals("Global"))
|
---|
1455 | {
|
---|
1456 | xml::NodesLoop nlGlobalChildren(*pelmRootChild);
|
---|
1457 | const xml::ElementNode *pelmGlobalChild;
|
---|
1458 | while ((pelmGlobalChild = nlGlobalChildren.forAllNodes()))
|
---|
1459 | {
|
---|
1460 | if (pelmGlobalChild->nameEquals("SystemProperties"))
|
---|
1461 | {
|
---|
1462 | pelmGlobalChild->getAttributeValue("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
1463 | pelmGlobalChild->getAttributeValue("LoggingLevel", systemProperties.strLoggingLevel);
|
---|
1464 | pelmGlobalChild->getAttributeValue("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
1465 | if (!pelmGlobalChild->getAttributeValue("VRDEAuthLibrary", systemProperties.strVRDEAuthLibrary))
|
---|
1466 | // pre-1.11 used @remoteDisplayAuthLibrary instead
|
---|
1467 | pelmGlobalChild->getAttributeValue("remoteDisplayAuthLibrary", systemProperties.strVRDEAuthLibrary);
|
---|
1468 | pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
1469 | pelmGlobalChild->getAttributeValue("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
|
---|
1470 | pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.ulLogHistoryCount);
|
---|
1471 | pelmGlobalChild->getAttributeValue("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
|
---|
1472 | pelmGlobalChild->getAttributeValue("defaultFrontend", systemProperties.strDefaultFrontend);
|
---|
1473 | pelmGlobalChild->getAttributeValue("exclusiveHwVirt", systemProperties.fExclusiveHwVirt);
|
---|
1474 | }
|
---|
1475 | else if (pelmGlobalChild->nameEquals("ExtraData"))
|
---|
1476 | readExtraData(*pelmGlobalChild, mapExtraDataItems);
|
---|
1477 | else if (pelmGlobalChild->nameEquals("MachineRegistry"))
|
---|
1478 | readMachineRegistry(*pelmGlobalChild);
|
---|
1479 | else if ( (pelmGlobalChild->nameEquals("MediaRegistry"))
|
---|
1480 | || ( (m->sv < SettingsVersion_v1_4)
|
---|
1481 | && (pelmGlobalChild->nameEquals("DiskRegistry"))
|
---|
1482 | )
|
---|
1483 | )
|
---|
1484 | readMediaRegistry(*pelmGlobalChild, mediaRegistry);
|
---|
1485 | else if (pelmGlobalChild->nameEquals("NetserviceRegistry"))
|
---|
1486 | {
|
---|
1487 | xml::NodesLoop nlLevel4(*pelmGlobalChild);
|
---|
1488 | const xml::ElementNode *pelmLevel4Child;
|
---|
1489 | while ((pelmLevel4Child = nlLevel4.forAllNodes()))
|
---|
1490 | {
|
---|
1491 | if (pelmLevel4Child->nameEquals("DHCPServers"))
|
---|
1492 | readDHCPServers(*pelmLevel4Child);
|
---|
1493 | if (pelmLevel4Child->nameEquals("NATNetworks"))
|
---|
1494 | readNATNetworks(*pelmLevel4Child);
|
---|
1495 | }
|
---|
1496 | }
|
---|
1497 | else if (pelmGlobalChild->nameEquals("USBDeviceFilters"))
|
---|
1498 | readUSBDeviceFilters(*pelmGlobalChild, host.llUSBDeviceFilters);
|
---|
1499 | }
|
---|
1500 | } // end if (pelmRootChild->nameEquals("Global"))
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 | clearDocument();
|
---|
1504 | }
|
---|
1505 |
|
---|
1506 | // DHCP servers were introduced with settings version 1.7; if we're loading
|
---|
1507 | // from an older version OR this is a fresh install, then add one DHCP server
|
---|
1508 | // with default settings
|
---|
1509 | if ( (!llDhcpServers.size())
|
---|
1510 | && ( (!pstrFilename) // empty VirtualBox.xml file
|
---|
1511 | || (m->sv < SettingsVersion_v1_7) // upgrading from before 1.7
|
---|
1512 | )
|
---|
1513 | )
|
---|
1514 | {
|
---|
1515 | DHCPServer srv;
|
---|
1516 | srv.strNetworkName =
|
---|
1517 | #ifdef RT_OS_WINDOWS
|
---|
1518 | "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter";
|
---|
1519 | #else
|
---|
1520 | "HostInterfaceNetworking-vboxnet0";
|
---|
1521 | #endif
|
---|
1522 | srv.strIPAddress = "192.168.56.100";
|
---|
1523 | srv.GlobalDhcpOptions[DhcpOpt_SubnetMask] = "255.255.255.0";
|
---|
1524 | srv.strIPLower = "192.168.56.101";
|
---|
1525 | srv.strIPUpper = "192.168.56.254";
|
---|
1526 | srv.fEnabled = true;
|
---|
1527 | llDhcpServers.push_back(srv);
|
---|
1528 | }
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | void MainConfigFile::bumpSettingsVersionIfNeeded()
|
---|
1532 | {
|
---|
1533 | if (m->sv < SettingsVersion_v1_14)
|
---|
1534 | {
|
---|
1535 | // VirtualBox 4.3 adds NAT networks.
|
---|
1536 | if ( !llNATNetworks.empty())
|
---|
1537 | m->sv = SettingsVersion_v1_14;
|
---|
1538 | }
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 |
|
---|
1542 | /**
|
---|
1543 | * Called from the IVirtualBox interface to write out VirtualBox.xml. This
|
---|
1544 | * builds an XML DOM tree and writes it out to disk.
|
---|
1545 | */
|
---|
1546 | void MainConfigFile::write(const com::Utf8Str strFilename)
|
---|
1547 | {
|
---|
1548 | bumpSettingsVersionIfNeeded();
|
---|
1549 |
|
---|
1550 | m->strFilename = strFilename;
|
---|
1551 | createStubDocument();
|
---|
1552 |
|
---|
1553 | xml::ElementNode *pelmGlobal = m->pelmRoot->createChild("Global");
|
---|
1554 |
|
---|
1555 | buildExtraData(*pelmGlobal, mapExtraDataItems);
|
---|
1556 |
|
---|
1557 | xml::ElementNode *pelmMachineRegistry = pelmGlobal->createChild("MachineRegistry");
|
---|
1558 | for (MachinesRegistry::const_iterator it = llMachines.begin();
|
---|
1559 | it != llMachines.end();
|
---|
1560 | ++it)
|
---|
1561 | {
|
---|
1562 | // <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"/>
|
---|
1563 | const MachineRegistryEntry &mre = *it;
|
---|
1564 | xml::ElementNode *pelmMachineEntry = pelmMachineRegistry->createChild("MachineEntry");
|
---|
1565 | pelmMachineEntry->setAttribute("uuid", mre.uuid.toStringCurly());
|
---|
1566 | pelmMachineEntry->setAttribute("src", mre.strSettingsFile);
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | buildMediaRegistry(*pelmGlobal, mediaRegistry);
|
---|
1570 |
|
---|
1571 | xml::ElementNode *pelmNetserviceRegistry = pelmGlobal->createChild("NetserviceRegistry");
|
---|
1572 | xml::ElementNode *pelmDHCPServers = pelmNetserviceRegistry->createChild("DHCPServers");
|
---|
1573 | for (DHCPServersList::const_iterator it = llDhcpServers.begin();
|
---|
1574 | it != llDhcpServers.end();
|
---|
1575 | ++it)
|
---|
1576 | {
|
---|
1577 | const DHCPServer &d = *it;
|
---|
1578 | xml::ElementNode *pelmThis = pelmDHCPServers->createChild("DHCPServer");
|
---|
1579 | DhcpOptConstIterator itOpt;
|
---|
1580 | itOpt = d.GlobalDhcpOptions.find(DhcpOpt_SubnetMask);
|
---|
1581 |
|
---|
1582 | pelmThis->setAttribute("networkName", d.strNetworkName);
|
---|
1583 | pelmThis->setAttribute("IPAddress", d.strIPAddress);
|
---|
1584 | if (itOpt != d.GlobalDhcpOptions.end())
|
---|
1585 | pelmThis->setAttribute("networkMask", itOpt->second);
|
---|
1586 | pelmThis->setAttribute("lowerIP", d.strIPLower);
|
---|
1587 | pelmThis->setAttribute("upperIP", d.strIPUpper);
|
---|
1588 | pelmThis->setAttribute("enabled", (d.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
1589 | /* We assume that if there're only 1 element it means that */
|
---|
1590 | int cOpt = d.GlobalDhcpOptions.size();
|
---|
1591 | /* We don't want duplicate validation check of networkMask here*/
|
---|
1592 | if ( ( itOpt == d.GlobalDhcpOptions.end()
|
---|
1593 | && cOpt > 0)
|
---|
1594 | || cOpt > 1)
|
---|
1595 | {
|
---|
1596 | xml::ElementNode *pelmOptions = pelmThis->createChild("Options");
|
---|
1597 | for (itOpt = d.GlobalDhcpOptions.begin();
|
---|
1598 | itOpt != d.GlobalDhcpOptions.end();
|
---|
1599 | ++itOpt)
|
---|
1600 | {
|
---|
1601 | if (itOpt->first == DhcpOpt_SubnetMask)
|
---|
1602 | continue;
|
---|
1603 |
|
---|
1604 | xml::ElementNode *pelmOpt = pelmOptions->createChild("Option");
|
---|
1605 |
|
---|
1606 | if (!pelmOpt)
|
---|
1607 | break;
|
---|
1608 |
|
---|
1609 | pelmOpt->setAttribute("name", itOpt->first);
|
---|
1610 | pelmOpt->setAttribute("value", itOpt->second);
|
---|
1611 | }
|
---|
1612 | } /* end of if */
|
---|
1613 |
|
---|
1614 | if (d.VmSlot2OptionsM.size() > 0)
|
---|
1615 | {
|
---|
1616 | VmSlot2OptionsConstIterator itVmSlot;
|
---|
1617 | DhcpOptConstIterator itOpt1;
|
---|
1618 | for(itVmSlot = d.VmSlot2OptionsM.begin();
|
---|
1619 | itVmSlot != d.VmSlot2OptionsM.end();
|
---|
1620 | ++itVmSlot)
|
---|
1621 | {
|
---|
1622 | xml::ElementNode *pelmCfg = pelmThis->createChild("Config");
|
---|
1623 | pelmCfg->setAttribute("vm-name", itVmSlot->first.VmName);
|
---|
1624 | pelmCfg->setAttribute("slot", itVmSlot->first.Slot);
|
---|
1625 |
|
---|
1626 | for (itOpt1 = itVmSlot->second.begin();
|
---|
1627 | itOpt1 != itVmSlot->second.end();
|
---|
1628 | ++itOpt1)
|
---|
1629 | {
|
---|
1630 | xml::ElementNode *pelmOpt = pelmCfg->createChild("Option");
|
---|
1631 | pelmOpt->setAttribute("name", itOpt1->first);
|
---|
1632 | pelmOpt->setAttribute("value", itOpt1->second);
|
---|
1633 | }
|
---|
1634 | }
|
---|
1635 | } /* and of if */
|
---|
1636 |
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 | xml::ElementNode *pelmNATNetworks;
|
---|
1640 | /* don't create entry if no NAT networks are registered. */
|
---|
1641 | if (!llNATNetworks.empty())
|
---|
1642 | {
|
---|
1643 | pelmNATNetworks = pelmNetserviceRegistry->createChild("NATNetworks");
|
---|
1644 | for (NATNetworksList::const_iterator it = llNATNetworks.begin();
|
---|
1645 | it != llNATNetworks.end();
|
---|
1646 | ++it)
|
---|
1647 | {
|
---|
1648 | const NATNetwork &n = *it;
|
---|
1649 | xml::ElementNode *pelmThis = pelmNATNetworks->createChild("NATNetwork");
|
---|
1650 | pelmThis->setAttribute("networkName", n.strNetworkName);
|
---|
1651 | pelmThis->setAttribute("network", n.strNetwork);
|
---|
1652 | pelmThis->setAttribute("ipv6", n.fIPv6 ? 1 : 0);
|
---|
1653 | pelmThis->setAttribute("ipv6prefix", n.strIPv6Prefix);
|
---|
1654 | pelmThis->setAttribute("advertiseDefaultIPv6Route", (n.fAdvertiseDefaultIPv6Route)? 1 : 0);
|
---|
1655 | pelmThis->setAttribute("needDhcp", (n.fNeedDhcpServer) ? 1 : 0);
|
---|
1656 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
1657 | if (n.llPortForwardRules4.size())
|
---|
1658 | {
|
---|
1659 | xml::ElementNode *pelmPf4 = pelmThis->createChild("PortForwarding4");
|
---|
1660 | buildNATForwardRuleList(*pelmPf4, n.llPortForwardRules4);
|
---|
1661 | }
|
---|
1662 | if (n.llPortForwardRules6.size())
|
---|
1663 | {
|
---|
1664 | xml::ElementNode *pelmPf6 = pelmThis->createChild("PortForwarding6");
|
---|
1665 | buildNATForwardRuleList(*pelmPf6, n.llPortForwardRules6);
|
---|
1666 | }
|
---|
1667 |
|
---|
1668 | if (n.llHostLoopbackOffsetList.size())
|
---|
1669 | {
|
---|
1670 | xml::ElementNode *pelmMappings = pelmThis->createChild("Mappings");
|
---|
1671 | buildNATLoopbacks(*pelmMappings, n.llHostLoopbackOffsetList);
|
---|
1672 |
|
---|
1673 | }
|
---|
1674 | }
|
---|
1675 | }
|
---|
1676 |
|
---|
1677 |
|
---|
1678 | xml::ElementNode *pelmSysProps = pelmGlobal->createChild("SystemProperties");
|
---|
1679 | if (systemProperties.strDefaultMachineFolder.length())
|
---|
1680 | pelmSysProps->setAttribute("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
1681 | if (systemProperties.strLoggingLevel.length())
|
---|
1682 | pelmSysProps->setAttribute("LoggingLevel", systemProperties.strLoggingLevel);
|
---|
1683 | if (systemProperties.strDefaultHardDiskFormat.length())
|
---|
1684 | pelmSysProps->setAttribute("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
1685 | if (systemProperties.strVRDEAuthLibrary.length())
|
---|
1686 | pelmSysProps->setAttribute("VRDEAuthLibrary", systemProperties.strVRDEAuthLibrary);
|
---|
1687 | if (systemProperties.strWebServiceAuthLibrary.length())
|
---|
1688 | pelmSysProps->setAttribute("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
1689 | if (systemProperties.strDefaultVRDEExtPack.length())
|
---|
1690 | pelmSysProps->setAttribute("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
|
---|
1691 | pelmSysProps->setAttribute("LogHistoryCount", systemProperties.ulLogHistoryCount);
|
---|
1692 | if (systemProperties.strAutostartDatabasePath.length())
|
---|
1693 | pelmSysProps->setAttribute("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
|
---|
1694 | if (systemProperties.strDefaultFrontend.length())
|
---|
1695 | pelmSysProps->setAttribute("defaultFrontend", systemProperties.strDefaultFrontend);
|
---|
1696 | pelmSysProps->setAttribute("exclusiveHwVirt", systemProperties.fExclusiveHwVirt);
|
---|
1697 |
|
---|
1698 | buildUSBDeviceFilters(*pelmGlobal->createChild("USBDeviceFilters"),
|
---|
1699 | host.llUSBDeviceFilters,
|
---|
1700 | true); // fHostMode
|
---|
1701 |
|
---|
1702 | // now go write the XML
|
---|
1703 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
1704 | writer.write(m->strFilename.c_str(), true /*fSafe*/);
|
---|
1705 |
|
---|
1706 | m->fFileExists = true;
|
---|
1707 |
|
---|
1708 | clearDocument();
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1712 | //
|
---|
1713 | // Machine XML structures
|
---|
1714 | //
|
---|
1715 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1716 |
|
---|
1717 | /**
|
---|
1718 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1719 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1720 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1721 | */
|
---|
1722 | bool VRDESettings::operator==(const VRDESettings& v) const
|
---|
1723 | {
|
---|
1724 | return ( (this == &v)
|
---|
1725 | || ( (fEnabled == v.fEnabled)
|
---|
1726 | && (authType == v.authType)
|
---|
1727 | && (ulAuthTimeout == v.ulAuthTimeout)
|
---|
1728 | && (strAuthLibrary == v.strAuthLibrary)
|
---|
1729 | && (fAllowMultiConnection == v.fAllowMultiConnection)
|
---|
1730 | && (fReuseSingleConnection == v.fReuseSingleConnection)
|
---|
1731 | && (strVrdeExtPack == v.strVrdeExtPack)
|
---|
1732 | && (mapProperties == v.mapProperties)
|
---|
1733 | )
|
---|
1734 | );
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 | /**
|
---|
1738 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1739 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1740 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1741 | */
|
---|
1742 | bool BIOSSettings::operator==(const BIOSSettings &d) const
|
---|
1743 | {
|
---|
1744 | return ( (this == &d)
|
---|
1745 | || ( fACPIEnabled == d.fACPIEnabled
|
---|
1746 | && fIOAPICEnabled == d.fIOAPICEnabled
|
---|
1747 | && fLogoFadeIn == d.fLogoFadeIn
|
---|
1748 | && fLogoFadeOut == d.fLogoFadeOut
|
---|
1749 | && ulLogoDisplayTime == d.ulLogoDisplayTime
|
---|
1750 | && strLogoImagePath == d.strLogoImagePath
|
---|
1751 | && biosBootMenuMode == d.biosBootMenuMode
|
---|
1752 | && fPXEDebugEnabled == d.fPXEDebugEnabled
|
---|
1753 | && llTimeOffset == d.llTimeOffset)
|
---|
1754 | );
|
---|
1755 | }
|
---|
1756 |
|
---|
1757 | /**
|
---|
1758 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1759 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1760 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1761 | */
|
---|
1762 | bool USBController::operator==(const USBController &u) const
|
---|
1763 | {
|
---|
1764 | return ( (this == &u)
|
---|
1765 | || ( (strName == u.strName)
|
---|
1766 | && (enmType == u.enmType)
|
---|
1767 | )
|
---|
1768 | );
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 | /**
|
---|
1772 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1773 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1774 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1775 | */
|
---|
1776 | bool USB::operator==(const USB &u) const
|
---|
1777 | {
|
---|
1778 | return ( (this == &u)
|
---|
1779 | || ( (llUSBControllers == u.llUSBControllers)
|
---|
1780 | && (llDeviceFilters == u.llDeviceFilters)
|
---|
1781 | )
|
---|
1782 | );
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | /**
|
---|
1786 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1787 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1788 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1789 | */
|
---|
1790 | bool NetworkAdapter::operator==(const NetworkAdapter &n) const
|
---|
1791 | {
|
---|
1792 | return ( (this == &n)
|
---|
1793 | || ( (ulSlot == n.ulSlot)
|
---|
1794 | && (type == n.type)
|
---|
1795 | && (fEnabled == n.fEnabled)
|
---|
1796 | && (strMACAddress == n.strMACAddress)
|
---|
1797 | && (fCableConnected == n.fCableConnected)
|
---|
1798 | && (ulLineSpeed == n.ulLineSpeed)
|
---|
1799 | && (enmPromiscModePolicy == n.enmPromiscModePolicy)
|
---|
1800 | && (fTraceEnabled == n.fTraceEnabled)
|
---|
1801 | && (strTraceFile == n.strTraceFile)
|
---|
1802 | && (mode == n.mode)
|
---|
1803 | && (nat == n.nat)
|
---|
1804 | && (strBridgedName == n.strBridgedName)
|
---|
1805 | && (strHostOnlyName == n.strHostOnlyName)
|
---|
1806 | && (strInternalNetworkName == n.strInternalNetworkName)
|
---|
1807 | && (strGenericDriver == n.strGenericDriver)
|
---|
1808 | && (genericProperties == n.genericProperties)
|
---|
1809 | && (ulBootPriority == n.ulBootPriority)
|
---|
1810 | && (strBandwidthGroup == n.strBandwidthGroup)
|
---|
1811 | )
|
---|
1812 | );
|
---|
1813 | }
|
---|
1814 |
|
---|
1815 | /**
|
---|
1816 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1817 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1818 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1819 | */
|
---|
1820 | bool SerialPort::operator==(const SerialPort &s) const
|
---|
1821 | {
|
---|
1822 | return ( (this == &s)
|
---|
1823 | || ( (ulSlot == s.ulSlot)
|
---|
1824 | && (fEnabled == s.fEnabled)
|
---|
1825 | && (ulIOBase == s.ulIOBase)
|
---|
1826 | && (ulIRQ == s.ulIRQ)
|
---|
1827 | && (portMode == s.portMode)
|
---|
1828 | && (strPath == s.strPath)
|
---|
1829 | && (fServer == s.fServer)
|
---|
1830 | )
|
---|
1831 | );
|
---|
1832 | }
|
---|
1833 |
|
---|
1834 | /**
|
---|
1835 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1836 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1837 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1838 | */
|
---|
1839 | bool ParallelPort::operator==(const ParallelPort &s) const
|
---|
1840 | {
|
---|
1841 | return ( (this == &s)
|
---|
1842 | || ( (ulSlot == s.ulSlot)
|
---|
1843 | && (fEnabled == s.fEnabled)
|
---|
1844 | && (ulIOBase == s.ulIOBase)
|
---|
1845 | && (ulIRQ == s.ulIRQ)
|
---|
1846 | && (strPath == s.strPath)
|
---|
1847 | )
|
---|
1848 | );
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 | /**
|
---|
1852 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1853 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1854 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1855 | */
|
---|
1856 | bool SharedFolder::operator==(const SharedFolder &g) const
|
---|
1857 | {
|
---|
1858 | return ( (this == &g)
|
---|
1859 | || ( (strName == g.strName)
|
---|
1860 | && (strHostPath == g.strHostPath)
|
---|
1861 | && (fWritable == g.fWritable)
|
---|
1862 | && (fAutoMount == g.fAutoMount)
|
---|
1863 | )
|
---|
1864 | );
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | /**
|
---|
1868 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1869 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1870 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1871 | */
|
---|
1872 | bool GuestProperty::operator==(const GuestProperty &g) const
|
---|
1873 | {
|
---|
1874 | return ( (this == &g)
|
---|
1875 | || ( (strName == g.strName)
|
---|
1876 | && (strValue == g.strValue)
|
---|
1877 | && (timestamp == g.timestamp)
|
---|
1878 | && (strFlags == g.strFlags)
|
---|
1879 | )
|
---|
1880 | );
|
---|
1881 | }
|
---|
1882 |
|
---|
1883 | Hardware::Hardware()
|
---|
1884 | : strVersion("1"),
|
---|
1885 | fHardwareVirt(true),
|
---|
1886 | fNestedPaging(true),
|
---|
1887 | fVPID(true),
|
---|
1888 | fUnrestrictedExecution(true),
|
---|
1889 | fHardwareVirtForce(false),
|
---|
1890 | fSyntheticCpu(false),
|
---|
1891 | fTripleFaultReset(false),
|
---|
1892 | fPAE(false),
|
---|
1893 | enmLongMode(HC_ARCH_BITS == 64 ? Hardware::LongMode_Enabled : Hardware::LongMode_Disabled),
|
---|
1894 | cCPUs(1),
|
---|
1895 | fCpuHotPlug(false),
|
---|
1896 | fHPETEnabled(false),
|
---|
1897 | ulCpuExecutionCap(100),
|
---|
1898 | ulMemorySizeMB((uint32_t)-1),
|
---|
1899 | graphicsControllerType(GraphicsControllerType_VBoxVGA),
|
---|
1900 | ulVRAMSizeMB(8),
|
---|
1901 | cMonitors(1),
|
---|
1902 | fAccelerate3D(false),
|
---|
1903 | fAccelerate2DVideo(false),
|
---|
1904 | ulVideoCaptureHorzRes(1024),
|
---|
1905 | ulVideoCaptureVertRes(768),
|
---|
1906 | ulVideoCaptureRate(512),
|
---|
1907 | ulVideoCaptureFPS(25),
|
---|
1908 | fVideoCaptureEnabled(false),
|
---|
1909 | u64VideoCaptureScreens(UINT64_C(0xffffffffffffffff)),
|
---|
1910 | strVideoCaptureFile(""),
|
---|
1911 | firmwareType(FirmwareType_BIOS),
|
---|
1912 | pointingHIDType(PointingHIDType_PS2Mouse),
|
---|
1913 | keyboardHIDType(KeyboardHIDType_PS2Keyboard),
|
---|
1914 | chipsetType(ChipsetType_PIIX3),
|
---|
1915 | fEmulatedUSBCardReader(false),
|
---|
1916 | clipboardMode(ClipboardMode_Disabled),
|
---|
1917 | dragAndDropMode(DragAndDropMode_Disabled),
|
---|
1918 | ulMemoryBalloonSize(0),
|
---|
1919 | fPageFusionEnabled(false)
|
---|
1920 | {
|
---|
1921 | mapBootOrder[0] = DeviceType_Floppy;
|
---|
1922 | mapBootOrder[1] = DeviceType_DVD;
|
---|
1923 | mapBootOrder[2] = DeviceType_HardDisk;
|
---|
1924 |
|
---|
1925 | /* The default value for PAE depends on the host:
|
---|
1926 | * - 64 bits host -> always true
|
---|
1927 | * - 32 bits host -> true for Windows & Darwin (masked off if the host cpu doesn't support it anyway)
|
---|
1928 | */
|
---|
1929 | #if HC_ARCH_BITS == 64 || defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN)
|
---|
1930 | fPAE = true;
|
---|
1931 | #endif
|
---|
1932 |
|
---|
1933 | /* The default value of large page supports depends on the host:
|
---|
1934 | * - 64 bits host -> true, unless it's Linux (pending further prediction work due to excessively expensive large page allocations)
|
---|
1935 | * - 32 bits host -> false
|
---|
1936 | */
|
---|
1937 | #if HC_ARCH_BITS == 64 && !defined(RT_OS_LINUX)
|
---|
1938 | fLargePages = true;
|
---|
1939 | #else
|
---|
1940 | /* Not supported on 32 bits hosts. */
|
---|
1941 | fLargePages = false;
|
---|
1942 | #endif
|
---|
1943 | }
|
---|
1944 |
|
---|
1945 | /**
|
---|
1946 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1947 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1948 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1949 | */
|
---|
1950 | bool Hardware::operator==(const Hardware& h) const
|
---|
1951 | {
|
---|
1952 | return ( (this == &h)
|
---|
1953 | || ( (strVersion == h.strVersion)
|
---|
1954 | && (uuid == h.uuid)
|
---|
1955 | && (fHardwareVirt == h.fHardwareVirt)
|
---|
1956 | && (fNestedPaging == h.fNestedPaging)
|
---|
1957 | && (fLargePages == h.fLargePages)
|
---|
1958 | && (fVPID == h.fVPID)
|
---|
1959 | && (fUnrestrictedExecution == h.fUnrestrictedExecution)
|
---|
1960 | && (fHardwareVirtForce == h.fHardwareVirtForce)
|
---|
1961 | && (fSyntheticCpu == h.fSyntheticCpu)
|
---|
1962 | && (fPAE == h.fPAE)
|
---|
1963 | && (enmLongMode == h.enmLongMode)
|
---|
1964 | && (fTripleFaultReset == h.fTripleFaultReset)
|
---|
1965 | && (cCPUs == h.cCPUs)
|
---|
1966 | && (fCpuHotPlug == h.fCpuHotPlug)
|
---|
1967 | && (ulCpuExecutionCap == h.ulCpuExecutionCap)
|
---|
1968 | && (fHPETEnabled == h.fHPETEnabled)
|
---|
1969 | && (llCpus == h.llCpus)
|
---|
1970 | && (llCpuIdLeafs == h.llCpuIdLeafs)
|
---|
1971 | && (ulMemorySizeMB == h.ulMemorySizeMB)
|
---|
1972 | && (mapBootOrder == h.mapBootOrder)
|
---|
1973 | && (graphicsControllerType == h.graphicsControllerType)
|
---|
1974 | && (ulVRAMSizeMB == h.ulVRAMSizeMB)
|
---|
1975 | && (cMonitors == h.cMonitors)
|
---|
1976 | && (fAccelerate3D == h.fAccelerate3D)
|
---|
1977 | && (fAccelerate2DVideo == h.fAccelerate2DVideo)
|
---|
1978 | && (fVideoCaptureEnabled == h.fVideoCaptureEnabled)
|
---|
1979 | && (u64VideoCaptureScreens == h.u64VideoCaptureScreens)
|
---|
1980 | && (strVideoCaptureFile == h.strVideoCaptureFile)
|
---|
1981 | && (ulVideoCaptureHorzRes == h.ulVideoCaptureHorzRes)
|
---|
1982 | && (ulVideoCaptureVertRes == h.ulVideoCaptureVertRes)
|
---|
1983 | && (ulVideoCaptureRate == h.ulVideoCaptureRate)
|
---|
1984 | && (ulVideoCaptureFPS == h.ulVideoCaptureFPS)
|
---|
1985 | && (firmwareType == h.firmwareType)
|
---|
1986 | && (pointingHIDType == h.pointingHIDType)
|
---|
1987 | && (keyboardHIDType == h.keyboardHIDType)
|
---|
1988 | && (chipsetType == h.chipsetType)
|
---|
1989 | && (fEmulatedUSBCardReader == h.fEmulatedUSBCardReader)
|
---|
1990 | && (vrdeSettings == h.vrdeSettings)
|
---|
1991 | && (biosSettings == h.biosSettings)
|
---|
1992 | && (usbSettings == h.usbSettings)
|
---|
1993 | && (llNetworkAdapters == h.llNetworkAdapters)
|
---|
1994 | && (llSerialPorts == h.llSerialPorts)
|
---|
1995 | && (llParallelPorts == h.llParallelPorts)
|
---|
1996 | && (audioAdapter == h.audioAdapter)
|
---|
1997 | && (llSharedFolders == h.llSharedFolders)
|
---|
1998 | && (clipboardMode == h.clipboardMode)
|
---|
1999 | && (dragAndDropMode == h.dragAndDropMode)
|
---|
2000 | && (ulMemoryBalloonSize == h.ulMemoryBalloonSize)
|
---|
2001 | && (fPageFusionEnabled == h.fPageFusionEnabled)
|
---|
2002 | && (llGuestProperties == h.llGuestProperties)
|
---|
2003 | && (strNotificationPatterns == h.strNotificationPatterns)
|
---|
2004 | && (ioSettings == h.ioSettings)
|
---|
2005 | && (pciAttachments == h.pciAttachments)
|
---|
2006 | && (strDefaultFrontend == h.strDefaultFrontend)
|
---|
2007 | )
|
---|
2008 | );
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | /**
|
---|
2012 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2013 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2014 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2015 | */
|
---|
2016 | bool AttachedDevice::operator==(const AttachedDevice &a) const
|
---|
2017 | {
|
---|
2018 | return ( (this == &a)
|
---|
2019 | || ( (deviceType == a.deviceType)
|
---|
2020 | && (fPassThrough == a.fPassThrough)
|
---|
2021 | && (fTempEject == a.fTempEject)
|
---|
2022 | && (fNonRotational == a.fNonRotational)
|
---|
2023 | && (fDiscard == a.fDiscard)
|
---|
2024 | && (fHotPluggable == a.fHotPluggable)
|
---|
2025 | && (lPort == a.lPort)
|
---|
2026 | && (lDevice == a.lDevice)
|
---|
2027 | && (uuid == a.uuid)
|
---|
2028 | && (strHostDriveSrc == a.strHostDriveSrc)
|
---|
2029 | && (strBwGroup == a.strBwGroup)
|
---|
2030 | )
|
---|
2031 | );
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | /**
|
---|
2035 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2036 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2037 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2038 | */
|
---|
2039 | bool StorageController::operator==(const StorageController &s) const
|
---|
2040 | {
|
---|
2041 | return ( (this == &s)
|
---|
2042 | || ( (strName == s.strName)
|
---|
2043 | && (storageBus == s.storageBus)
|
---|
2044 | && (controllerType == s.controllerType)
|
---|
2045 | && (ulPortCount == s.ulPortCount)
|
---|
2046 | && (ulInstance == s.ulInstance)
|
---|
2047 | && (fUseHostIOCache == s.fUseHostIOCache)
|
---|
2048 | && (lIDE0MasterEmulationPort == s.lIDE0MasterEmulationPort)
|
---|
2049 | && (lIDE0SlaveEmulationPort == s.lIDE0SlaveEmulationPort)
|
---|
2050 | && (lIDE1MasterEmulationPort == s.lIDE1MasterEmulationPort)
|
---|
2051 | && (lIDE1SlaveEmulationPort == s.lIDE1SlaveEmulationPort)
|
---|
2052 | && (llAttachedDevices == s.llAttachedDevices)
|
---|
2053 | )
|
---|
2054 | );
|
---|
2055 | }
|
---|
2056 |
|
---|
2057 | /**
|
---|
2058 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2059 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2060 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2061 | */
|
---|
2062 | bool Storage::operator==(const Storage &s) const
|
---|
2063 | {
|
---|
2064 | return ( (this == &s)
|
---|
2065 | || (llStorageControllers == s.llStorageControllers) // deep compare
|
---|
2066 | );
|
---|
2067 | }
|
---|
2068 |
|
---|
2069 | /**
|
---|
2070 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2071 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2072 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2073 | */
|
---|
2074 | bool Snapshot::operator==(const Snapshot &s) const
|
---|
2075 | {
|
---|
2076 | return ( (this == &s)
|
---|
2077 | || ( (uuid == s.uuid)
|
---|
2078 | && (strName == s.strName)
|
---|
2079 | && (strDescription == s.strDescription)
|
---|
2080 | && (RTTimeSpecIsEqual(×tamp, &s.timestamp))
|
---|
2081 | && (strStateFile == s.strStateFile)
|
---|
2082 | && (hardware == s.hardware) // deep compare
|
---|
2083 | && (storage == s.storage) // deep compare
|
---|
2084 | && (llChildSnapshots == s.llChildSnapshots) // deep compare
|
---|
2085 | && debugging == s.debugging
|
---|
2086 | && autostart == s.autostart
|
---|
2087 | )
|
---|
2088 | );
|
---|
2089 | }
|
---|
2090 |
|
---|
2091 | /**
|
---|
2092 | * IOSettings constructor.
|
---|
2093 | */
|
---|
2094 | IOSettings::IOSettings()
|
---|
2095 | {
|
---|
2096 | fIOCacheEnabled = true;
|
---|
2097 | ulIOCacheSize = 5;
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2101 | //
|
---|
2102 | // MachineConfigFile
|
---|
2103 | //
|
---|
2104 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2105 |
|
---|
2106 | /**
|
---|
2107 | * Constructor.
|
---|
2108 | *
|
---|
2109 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
2110 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
2111 | * are initialized with default values.
|
---|
2112 | *
|
---|
2113 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
2114 | * the caller should catch; if this constructor does not throw, then the member
|
---|
2115 | * variables contain meaningful values (either from the file or defaults).
|
---|
2116 | *
|
---|
2117 | * @param strFilename
|
---|
2118 | */
|
---|
2119 | MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename)
|
---|
2120 | : ConfigFileBase(pstrFilename),
|
---|
2121 | fCurrentStateModified(true),
|
---|
2122 | fAborted(false)
|
---|
2123 | {
|
---|
2124 | RTTimeNow(&timeLastStateChange);
|
---|
2125 |
|
---|
2126 | if (pstrFilename)
|
---|
2127 | {
|
---|
2128 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
2129 | // we need only analyze what is in there
|
---|
2130 |
|
---|
2131 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
2132 | const xml::ElementNode *pelmRootChild;
|
---|
2133 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
2134 | {
|
---|
2135 | if (pelmRootChild->nameEquals("Machine"))
|
---|
2136 | readMachine(*pelmRootChild);
|
---|
2137 | }
|
---|
2138 |
|
---|
2139 | // clean up memory allocated by XML engine
|
---|
2140 | clearDocument();
|
---|
2141 | }
|
---|
2142 | }
|
---|
2143 |
|
---|
2144 | /**
|
---|
2145 | * Public routine which returns true if this machine config file can have its
|
---|
2146 | * own media registry (which is true for settings version v1.11 and higher,
|
---|
2147 | * i.e. files created by VirtualBox 4.0 and higher).
|
---|
2148 | * @return
|
---|
2149 | */
|
---|
2150 | bool MachineConfigFile::canHaveOwnMediaRegistry() const
|
---|
2151 | {
|
---|
2152 | return (m->sv >= SettingsVersion_v1_11);
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 | /**
|
---|
2156 | * Public routine which allows for importing machine XML from an external DOM tree.
|
---|
2157 | * Use this after having called the constructor with a NULL argument.
|
---|
2158 | *
|
---|
2159 | * This is used by the OVF code if a <vbox:Machine> element has been encountered
|
---|
2160 | * in an OVF VirtualSystem element.
|
---|
2161 | *
|
---|
2162 | * @param elmMachine
|
---|
2163 | */
|
---|
2164 | void MachineConfigFile::importMachineXML(const xml::ElementNode &elmMachine)
|
---|
2165 | {
|
---|
2166 | readMachine(elmMachine);
|
---|
2167 | }
|
---|
2168 |
|
---|
2169 | /**
|
---|
2170 | * Comparison operator. This gets called from Machine::saveSettings to figure out
|
---|
2171 | * whether machine settings have really changed and thus need to be written out to disk.
|
---|
2172 | *
|
---|
2173 | * Even though this is called operator==, this does NOT compare all fields; the "equals"
|
---|
2174 | * should be understood as "has the same machine config as". The following fields are
|
---|
2175 | * NOT compared:
|
---|
2176 | * -- settings versions and file names inherited from ConfigFileBase;
|
---|
2177 | * -- fCurrentStateModified because that is considered separately in Machine::saveSettings!!
|
---|
2178 | *
|
---|
2179 | * The "deep" comparisons marked below will invoke the operator== functions of the
|
---|
2180 | * structs defined in this file, which may in turn go into comparing lists of
|
---|
2181 | * other structures. As a result, invoking this can be expensive, but it's
|
---|
2182 | * less expensive than writing out XML to disk.
|
---|
2183 | */
|
---|
2184 | bool MachineConfigFile::operator==(const MachineConfigFile &c) const
|
---|
2185 | {
|
---|
2186 | return ( (this == &c)
|
---|
2187 | || ( (uuid == c.uuid)
|
---|
2188 | && (machineUserData == c.machineUserData)
|
---|
2189 | && (strStateFile == c.strStateFile)
|
---|
2190 | && (uuidCurrentSnapshot == c.uuidCurrentSnapshot)
|
---|
2191 | // skip fCurrentStateModified!
|
---|
2192 | && (RTTimeSpecIsEqual(&timeLastStateChange, &c.timeLastStateChange))
|
---|
2193 | && (fAborted == c.fAborted)
|
---|
2194 | && (hardwareMachine == c.hardwareMachine) // this one's deep
|
---|
2195 | && (storageMachine == c.storageMachine) // this one's deep
|
---|
2196 | && (mediaRegistry == c.mediaRegistry) // this one's deep
|
---|
2197 | && (mapExtraDataItems == c.mapExtraDataItems) // this one's deep
|
---|
2198 | && (llFirstSnapshot == c.llFirstSnapshot) // this one's deep
|
---|
2199 | )
|
---|
2200 | );
|
---|
2201 | }
|
---|
2202 |
|
---|
2203 | /**
|
---|
2204 | * Called from MachineConfigFile::readHardware() to read cpu information.
|
---|
2205 | * @param elmCpuid
|
---|
2206 | * @param ll
|
---|
2207 | */
|
---|
2208 | void MachineConfigFile::readCpuTree(const xml::ElementNode &elmCpu,
|
---|
2209 | CpuList &ll)
|
---|
2210 | {
|
---|
2211 | xml::NodesLoop nl1(elmCpu, "Cpu");
|
---|
2212 | const xml::ElementNode *pelmCpu;
|
---|
2213 | while ((pelmCpu = nl1.forAllNodes()))
|
---|
2214 | {
|
---|
2215 | Cpu cpu;
|
---|
2216 |
|
---|
2217 | if (!pelmCpu->getAttributeValue("id", cpu.ulId))
|
---|
2218 | throw ConfigFileError(this, pelmCpu, N_("Required Cpu/@id attribute is missing"));
|
---|
2219 |
|
---|
2220 | ll.push_back(cpu);
|
---|
2221 | }
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | /**
|
---|
2225 | * Called from MachineConfigFile::readHardware() to cpuid information.
|
---|
2226 | * @param elmCpuid
|
---|
2227 | * @param ll
|
---|
2228 | */
|
---|
2229 | void MachineConfigFile::readCpuIdTree(const xml::ElementNode &elmCpuid,
|
---|
2230 | CpuIdLeafsList &ll)
|
---|
2231 | {
|
---|
2232 | xml::NodesLoop nl1(elmCpuid, "CpuIdLeaf");
|
---|
2233 | const xml::ElementNode *pelmCpuIdLeaf;
|
---|
2234 | while ((pelmCpuIdLeaf = nl1.forAllNodes()))
|
---|
2235 | {
|
---|
2236 | CpuIdLeaf leaf;
|
---|
2237 |
|
---|
2238 | if (!pelmCpuIdLeaf->getAttributeValue("id", leaf.ulId))
|
---|
2239 | throw ConfigFileError(this, pelmCpuIdLeaf, N_("Required CpuId/@id attribute is missing"));
|
---|
2240 |
|
---|
2241 | pelmCpuIdLeaf->getAttributeValue("eax", leaf.ulEax);
|
---|
2242 | pelmCpuIdLeaf->getAttributeValue("ebx", leaf.ulEbx);
|
---|
2243 | pelmCpuIdLeaf->getAttributeValue("ecx", leaf.ulEcx);
|
---|
2244 | pelmCpuIdLeaf->getAttributeValue("edx", leaf.ulEdx);
|
---|
2245 |
|
---|
2246 | ll.push_back(leaf);
|
---|
2247 | }
|
---|
2248 | }
|
---|
2249 |
|
---|
2250 | /**
|
---|
2251 | * Called from MachineConfigFile::readHardware() to network information.
|
---|
2252 | * @param elmNetwork
|
---|
2253 | * @param ll
|
---|
2254 | */
|
---|
2255 | void MachineConfigFile::readNetworkAdapters(const xml::ElementNode &elmNetwork,
|
---|
2256 | NetworkAdaptersList &ll)
|
---|
2257 | {
|
---|
2258 | xml::NodesLoop nl1(elmNetwork, "Adapter");
|
---|
2259 | const xml::ElementNode *pelmAdapter;
|
---|
2260 | while ((pelmAdapter = nl1.forAllNodes()))
|
---|
2261 | {
|
---|
2262 | NetworkAdapter nic;
|
---|
2263 |
|
---|
2264 | if (!pelmAdapter->getAttributeValue("slot", nic.ulSlot))
|
---|
2265 | throw ConfigFileError(this, pelmAdapter, N_("Required Adapter/@slot attribute is missing"));
|
---|
2266 |
|
---|
2267 | Utf8Str strTemp;
|
---|
2268 | if (pelmAdapter->getAttributeValue("type", strTemp))
|
---|
2269 | {
|
---|
2270 | if (strTemp == "Am79C970A")
|
---|
2271 | nic.type = NetworkAdapterType_Am79C970A;
|
---|
2272 | else if (strTemp == "Am79C973")
|
---|
2273 | nic.type = NetworkAdapterType_Am79C973;
|
---|
2274 | else if (strTemp == "82540EM")
|
---|
2275 | nic.type = NetworkAdapterType_I82540EM;
|
---|
2276 | else if (strTemp == "82543GC")
|
---|
2277 | nic.type = NetworkAdapterType_I82543GC;
|
---|
2278 | else if (strTemp == "82545EM")
|
---|
2279 | nic.type = NetworkAdapterType_I82545EM;
|
---|
2280 | else if (strTemp == "virtio")
|
---|
2281 | nic.type = NetworkAdapterType_Virtio;
|
---|
2282 | else
|
---|
2283 | throw ConfigFileError(this, pelmAdapter, N_("Invalid value '%s' in Adapter/@type attribute"), strTemp.c_str());
|
---|
2284 | }
|
---|
2285 |
|
---|
2286 | pelmAdapter->getAttributeValue("enabled", nic.fEnabled);
|
---|
2287 | pelmAdapter->getAttributeValue("MACAddress", nic.strMACAddress);
|
---|
2288 | pelmAdapter->getAttributeValue("cable", nic.fCableConnected);
|
---|
2289 | pelmAdapter->getAttributeValue("speed", nic.ulLineSpeed);
|
---|
2290 |
|
---|
2291 | if (pelmAdapter->getAttributeValue("promiscuousModePolicy", strTemp))
|
---|
2292 | {
|
---|
2293 | if (strTemp == "Deny")
|
---|
2294 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
|
---|
2295 | else if (strTemp == "AllowNetwork")
|
---|
2296 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
|
---|
2297 | else if (strTemp == "AllowAll")
|
---|
2298 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
|
---|
2299 | else
|
---|
2300 | throw ConfigFileError(this, pelmAdapter,
|
---|
2301 | N_("Invalid value '%s' in Adapter/@promiscuousModePolicy attribute"), strTemp.c_str());
|
---|
2302 | }
|
---|
2303 |
|
---|
2304 | pelmAdapter->getAttributeValue("trace", nic.fTraceEnabled);
|
---|
2305 | pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
|
---|
2306 | pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority);
|
---|
2307 | pelmAdapter->getAttributeValue("bandwidthGroup", nic.strBandwidthGroup);
|
---|
2308 |
|
---|
2309 | xml::ElementNodesList llNetworkModes;
|
---|
2310 | pelmAdapter->getChildElements(llNetworkModes);
|
---|
2311 | xml::ElementNodesList::iterator it;
|
---|
2312 | /* We should have only active mode descriptor and disabled modes set */
|
---|
2313 | if (llNetworkModes.size() > 2)
|
---|
2314 | {
|
---|
2315 | throw ConfigFileError(this, pelmAdapter, N_("Invalid number of modes ('%d') attached to Adapter attribute"), llNetworkModes.size());
|
---|
2316 | }
|
---|
2317 | for (it = llNetworkModes.begin(); it != llNetworkModes.end(); ++it)
|
---|
2318 | {
|
---|
2319 | const xml::ElementNode *pelmNode = *it;
|
---|
2320 | if (pelmNode->nameEquals("DisabledModes"))
|
---|
2321 | {
|
---|
2322 | xml::ElementNodesList llDisabledNetworkModes;
|
---|
2323 | xml::ElementNodesList::iterator itDisabled;
|
---|
2324 | pelmNode->getChildElements(llDisabledNetworkModes);
|
---|
2325 | /* run over disabled list and load settings */
|
---|
2326 | for (itDisabled = llDisabledNetworkModes.begin();
|
---|
2327 | itDisabled != llDisabledNetworkModes.end(); ++itDisabled)
|
---|
2328 | {
|
---|
2329 | const xml::ElementNode *pelmDisabledNode = *itDisabled;
|
---|
2330 | readAttachedNetworkMode(*pelmDisabledNode, false, nic);
|
---|
2331 | }
|
---|
2332 | }
|
---|
2333 | else
|
---|
2334 | readAttachedNetworkMode(*pelmNode, true, nic);
|
---|
2335 | }
|
---|
2336 | // else: default is NetworkAttachmentType_Null
|
---|
2337 |
|
---|
2338 | ll.push_back(nic);
|
---|
2339 | }
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | void MachineConfigFile::readAttachedNetworkMode(const xml::ElementNode &elmMode, bool fEnabled, NetworkAdapter &nic)
|
---|
2343 | {
|
---|
2344 | NetworkAttachmentType_T enmAttachmentType = NetworkAttachmentType_Null;
|
---|
2345 |
|
---|
2346 | if (elmMode.nameEquals("NAT"))
|
---|
2347 | {
|
---|
2348 | enmAttachmentType = NetworkAttachmentType_NAT;
|
---|
2349 |
|
---|
2350 | elmMode.getAttributeValue("network", nic.nat.strNetwork);
|
---|
2351 | elmMode.getAttributeValue("hostip", nic.nat.strBindIP);
|
---|
2352 | elmMode.getAttributeValue("mtu", nic.nat.u32Mtu);
|
---|
2353 | elmMode.getAttributeValue("sockrcv", nic.nat.u32SockRcv);
|
---|
2354 | elmMode.getAttributeValue("socksnd", nic.nat.u32SockSnd);
|
---|
2355 | elmMode.getAttributeValue("tcprcv", nic.nat.u32TcpRcv);
|
---|
2356 | elmMode.getAttributeValue("tcpsnd", nic.nat.u32TcpSnd);
|
---|
2357 | const xml::ElementNode *pelmDNS;
|
---|
2358 | if ((pelmDNS = elmMode.findChildElement("DNS")))
|
---|
2359 | {
|
---|
2360 | pelmDNS->getAttributeValue("pass-domain", nic.nat.fDNSPassDomain);
|
---|
2361 | pelmDNS->getAttributeValue("use-proxy", nic.nat.fDNSProxy);
|
---|
2362 | pelmDNS->getAttributeValue("use-host-resolver", nic.nat.fDNSUseHostResolver);
|
---|
2363 | }
|
---|
2364 | const xml::ElementNode *pelmAlias;
|
---|
2365 | if ((pelmAlias = elmMode.findChildElement("Alias")))
|
---|
2366 | {
|
---|
2367 | pelmAlias->getAttributeValue("logging", nic.nat.fAliasLog);
|
---|
2368 | pelmAlias->getAttributeValue("proxy-only", nic.nat.fAliasProxyOnly);
|
---|
2369 | pelmAlias->getAttributeValue("use-same-ports", nic.nat.fAliasUseSamePorts);
|
---|
2370 | }
|
---|
2371 | const xml::ElementNode *pelmTFTP;
|
---|
2372 | if ((pelmTFTP = elmMode.findChildElement("TFTP")))
|
---|
2373 | {
|
---|
2374 | pelmTFTP->getAttributeValue("prefix", nic.nat.strTFTPPrefix);
|
---|
2375 | pelmTFTP->getAttributeValue("boot-file", nic.nat.strTFTPBootFile);
|
---|
2376 | pelmTFTP->getAttributeValue("next-server", nic.nat.strTFTPNextServer);
|
---|
2377 | }
|
---|
2378 |
|
---|
2379 | readNATForwardRuleList(elmMode, nic.nat.llRules);
|
---|
2380 | }
|
---|
2381 | else if ( elmMode.nameEquals("HostInterface")
|
---|
2382 | || elmMode.nameEquals("BridgedInterface"))
|
---|
2383 | {
|
---|
2384 | enmAttachmentType = NetworkAttachmentType_Bridged;
|
---|
2385 |
|
---|
2386 | elmMode.getAttributeValue("name", nic.strBridgedName); // optional bridged interface name
|
---|
2387 | }
|
---|
2388 | else if (elmMode.nameEquals("InternalNetwork"))
|
---|
2389 | {
|
---|
2390 | enmAttachmentType = NetworkAttachmentType_Internal;
|
---|
2391 |
|
---|
2392 | if (!elmMode.getAttributeValue("name", nic.strInternalNetworkName)) // required network name
|
---|
2393 | throw ConfigFileError(this, &elmMode, N_("Required InternalNetwork/@name element is missing"));
|
---|
2394 | }
|
---|
2395 | else if (elmMode.nameEquals("HostOnlyInterface"))
|
---|
2396 | {
|
---|
2397 | enmAttachmentType = NetworkAttachmentType_HostOnly;
|
---|
2398 |
|
---|
2399 | if (!elmMode.getAttributeValue("name", nic.strHostOnlyName)) // required network name
|
---|
2400 | throw ConfigFileError(this, &elmMode, N_("Required HostOnlyInterface/@name element is missing"));
|
---|
2401 | }
|
---|
2402 | else if (elmMode.nameEquals("GenericInterface"))
|
---|
2403 | {
|
---|
2404 | enmAttachmentType = NetworkAttachmentType_Generic;
|
---|
2405 |
|
---|
2406 | elmMode.getAttributeValue("driver", nic.strGenericDriver); // optional network attachment driver
|
---|
2407 |
|
---|
2408 | // get all properties
|
---|
2409 | xml::NodesLoop nl(elmMode);
|
---|
2410 | const xml::ElementNode *pelmModeChild;
|
---|
2411 | while ((pelmModeChild = nl.forAllNodes()))
|
---|
2412 | {
|
---|
2413 | if (pelmModeChild->nameEquals("Property"))
|
---|
2414 | {
|
---|
2415 | Utf8Str strPropName, strPropValue;
|
---|
2416 | if ( pelmModeChild->getAttributeValue("name", strPropName)
|
---|
2417 | && pelmModeChild->getAttributeValue("value", strPropValue) )
|
---|
2418 | nic.genericProperties[strPropName] = strPropValue;
|
---|
2419 | else
|
---|
2420 | throw ConfigFileError(this, pelmModeChild, N_("Required GenericInterface/Property/@name or @value attribute is missing"));
|
---|
2421 | }
|
---|
2422 | }
|
---|
2423 | }
|
---|
2424 | else if (elmMode.nameEquals("NATNetwork"))
|
---|
2425 | {
|
---|
2426 | enmAttachmentType = NetworkAttachmentType_NATNetwork;
|
---|
2427 |
|
---|
2428 | if (!elmMode.getAttributeValue("name", nic.strNATNetworkName)) // required network name
|
---|
2429 | throw ConfigFileError(this, &elmMode, N_("Required NATNetwork/@name element is missing"));
|
---|
2430 | }
|
---|
2431 | else if (elmMode.nameEquals("VDE"))
|
---|
2432 | {
|
---|
2433 | enmAttachmentType = NetworkAttachmentType_Generic;
|
---|
2434 |
|
---|
2435 | com::Utf8Str strVDEName;
|
---|
2436 | elmMode.getAttributeValue("network", strVDEName); // optional network name
|
---|
2437 | nic.strGenericDriver = "VDE";
|
---|
2438 | nic.genericProperties["network"] = strVDEName;
|
---|
2439 | }
|
---|
2440 |
|
---|
2441 | if (fEnabled && enmAttachmentType != NetworkAttachmentType_Null)
|
---|
2442 | nic.mode = enmAttachmentType;
|
---|
2443 | }
|
---|
2444 |
|
---|
2445 | /**
|
---|
2446 | * Called from MachineConfigFile::readHardware() to read serial port information.
|
---|
2447 | * @param elmUART
|
---|
2448 | * @param ll
|
---|
2449 | */
|
---|
2450 | void MachineConfigFile::readSerialPorts(const xml::ElementNode &elmUART,
|
---|
2451 | SerialPortsList &ll)
|
---|
2452 | {
|
---|
2453 | xml::NodesLoop nl1(elmUART, "Port");
|
---|
2454 | const xml::ElementNode *pelmPort;
|
---|
2455 | while ((pelmPort = nl1.forAllNodes()))
|
---|
2456 | {
|
---|
2457 | SerialPort port;
|
---|
2458 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
2459 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@slot attribute is missing"));
|
---|
2460 |
|
---|
2461 | // slot must be unique
|
---|
2462 | for (SerialPortsList::const_iterator it = ll.begin();
|
---|
2463 | it != ll.end();
|
---|
2464 | ++it)
|
---|
2465 | if ((*it).ulSlot == port.ulSlot)
|
---|
2466 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in UART/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
2467 |
|
---|
2468 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
2469 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@enabled attribute is missing"));
|
---|
2470 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
2471 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IOBase attribute is missing"));
|
---|
2472 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
2473 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IRQ attribute is missing"));
|
---|
2474 |
|
---|
2475 | Utf8Str strPortMode;
|
---|
2476 | if (!pelmPort->getAttributeValue("hostMode", strPortMode))
|
---|
2477 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@hostMode attribute is missing"));
|
---|
2478 | if (strPortMode == "RawFile")
|
---|
2479 | port.portMode = PortMode_RawFile;
|
---|
2480 | else if (strPortMode == "HostPipe")
|
---|
2481 | port.portMode = PortMode_HostPipe;
|
---|
2482 | else if (strPortMode == "HostDevice")
|
---|
2483 | port.portMode = PortMode_HostDevice;
|
---|
2484 | else if (strPortMode == "Disconnected")
|
---|
2485 | port.portMode = PortMode_Disconnected;
|
---|
2486 | else
|
---|
2487 | throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
|
---|
2488 |
|
---|
2489 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
2490 | pelmPort->getAttributeValue("server", port.fServer);
|
---|
2491 |
|
---|
2492 | ll.push_back(port);
|
---|
2493 | }
|
---|
2494 | }
|
---|
2495 |
|
---|
2496 | /**
|
---|
2497 | * Called from MachineConfigFile::readHardware() to read parallel port information.
|
---|
2498 | * @param elmLPT
|
---|
2499 | * @param ll
|
---|
2500 | */
|
---|
2501 | void MachineConfigFile::readParallelPorts(const xml::ElementNode &elmLPT,
|
---|
2502 | ParallelPortsList &ll)
|
---|
2503 | {
|
---|
2504 | xml::NodesLoop nl1(elmLPT, "Port");
|
---|
2505 | const xml::ElementNode *pelmPort;
|
---|
2506 | while ((pelmPort = nl1.forAllNodes()))
|
---|
2507 | {
|
---|
2508 | ParallelPort port;
|
---|
2509 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
2510 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@slot attribute is missing"));
|
---|
2511 |
|
---|
2512 | // slot must be unique
|
---|
2513 | for (ParallelPortsList::const_iterator it = ll.begin();
|
---|
2514 | it != ll.end();
|
---|
2515 | ++it)
|
---|
2516 | if ((*it).ulSlot == port.ulSlot)
|
---|
2517 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in LPT/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
2518 |
|
---|
2519 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
2520 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@enabled attribute is missing"));
|
---|
2521 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
2522 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IOBase attribute is missing"));
|
---|
2523 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
2524 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IRQ attribute is missing"));
|
---|
2525 |
|
---|
2526 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
2527 |
|
---|
2528 | ll.push_back(port);
|
---|
2529 | }
|
---|
2530 | }
|
---|
2531 |
|
---|
2532 | /**
|
---|
2533 | * Called from MachineConfigFile::readHardware() to read audio adapter information
|
---|
2534 | * and maybe fix driver information depending on the current host hardware.
|
---|
2535 | *
|
---|
2536 | * @param elmAudioAdapter "AudioAdapter" XML element.
|
---|
2537 | * @param hw
|
---|
2538 | */
|
---|
2539 | void MachineConfigFile::readAudioAdapter(const xml::ElementNode &elmAudioAdapter,
|
---|
2540 | AudioAdapter &aa)
|
---|
2541 | {
|
---|
2542 | elmAudioAdapter.getAttributeValue("enabled", aa.fEnabled);
|
---|
2543 |
|
---|
2544 | Utf8Str strTemp;
|
---|
2545 | if (elmAudioAdapter.getAttributeValue("controller", strTemp))
|
---|
2546 | {
|
---|
2547 | if (strTemp == "SB16")
|
---|
2548 | aa.controllerType = AudioControllerType_SB16;
|
---|
2549 | else if (strTemp == "AC97")
|
---|
2550 | aa.controllerType = AudioControllerType_AC97;
|
---|
2551 | else if (strTemp == "HDA")
|
---|
2552 | aa.controllerType = AudioControllerType_HDA;
|
---|
2553 | else
|
---|
2554 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
|
---|
2555 | }
|
---|
2556 |
|
---|
2557 | if (elmAudioAdapter.getAttributeValue("driver", strTemp))
|
---|
2558 | {
|
---|
2559 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
2560 | strTemp.toUpper();
|
---|
2561 | if (strTemp == "NULL")
|
---|
2562 | aa.driverType = AudioDriverType_Null;
|
---|
2563 | else if (strTemp == "WINMM")
|
---|
2564 | aa.driverType = AudioDriverType_WinMM;
|
---|
2565 | else if ( (strTemp == "DIRECTSOUND") || (strTemp == "DSOUND") )
|
---|
2566 | aa.driverType = AudioDriverType_DirectSound;
|
---|
2567 | else if (strTemp == "SOLAUDIO")
|
---|
2568 | aa.driverType = AudioDriverType_SolAudio;
|
---|
2569 | else if (strTemp == "ALSA")
|
---|
2570 | aa.driverType = AudioDriverType_ALSA;
|
---|
2571 | else if (strTemp == "PULSE")
|
---|
2572 | aa.driverType = AudioDriverType_Pulse;
|
---|
2573 | else if (strTemp == "OSS")
|
---|
2574 | aa.driverType = AudioDriverType_OSS;
|
---|
2575 | else if (strTemp == "COREAUDIO")
|
---|
2576 | aa.driverType = AudioDriverType_CoreAudio;
|
---|
2577 | else if (strTemp == "MMPM")
|
---|
2578 | aa.driverType = AudioDriverType_MMPM;
|
---|
2579 | else
|
---|
2580 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@driver attribute"), strTemp.c_str());
|
---|
2581 |
|
---|
2582 | // now check if this is actually supported on the current host platform;
|
---|
2583 | // people might be opening a file created on a Windows host, and that
|
---|
2584 | // VM should still start on a Linux host
|
---|
2585 | if (!isAudioDriverAllowedOnThisHost(aa.driverType))
|
---|
2586 | aa.driverType = getHostDefaultAudioDriver();
|
---|
2587 | }
|
---|
2588 | }
|
---|
2589 |
|
---|
2590 | /**
|
---|
2591 | * Called from MachineConfigFile::readHardware() to read guest property information.
|
---|
2592 | * @param elmGuestProperties
|
---|
2593 | * @param hw
|
---|
2594 | */
|
---|
2595 | void MachineConfigFile::readGuestProperties(const xml::ElementNode &elmGuestProperties,
|
---|
2596 | Hardware &hw)
|
---|
2597 | {
|
---|
2598 | xml::NodesLoop nl1(elmGuestProperties, "GuestProperty");
|
---|
2599 | const xml::ElementNode *pelmProp;
|
---|
2600 | while ((pelmProp = nl1.forAllNodes()))
|
---|
2601 | {
|
---|
2602 | GuestProperty prop;
|
---|
2603 | pelmProp->getAttributeValue("name", prop.strName);
|
---|
2604 | pelmProp->getAttributeValue("value", prop.strValue);
|
---|
2605 |
|
---|
2606 | pelmProp->getAttributeValue("timestamp", prop.timestamp);
|
---|
2607 | pelmProp->getAttributeValue("flags", prop.strFlags);
|
---|
2608 | hw.llGuestProperties.push_back(prop);
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 | elmGuestProperties.getAttributeValue("notificationPatterns", hw.strNotificationPatterns);
|
---|
2612 | }
|
---|
2613 |
|
---|
2614 | /**
|
---|
2615 | * Helper function to read attributes that are common to <SATAController> (pre-1.7)
|
---|
2616 | * and <StorageController>.
|
---|
2617 | * @param elmStorageController
|
---|
2618 | * @param strg
|
---|
2619 | */
|
---|
2620 | void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
|
---|
2621 | StorageController &sctl)
|
---|
2622 | {
|
---|
2623 | elmStorageController.getAttributeValue("PortCount", sctl.ulPortCount);
|
---|
2624 | elmStorageController.getAttributeValue("IDE0MasterEmulationPort", sctl.lIDE0MasterEmulationPort);
|
---|
2625 | elmStorageController.getAttributeValue("IDE0SlaveEmulationPort", sctl.lIDE0SlaveEmulationPort);
|
---|
2626 | elmStorageController.getAttributeValue("IDE1MasterEmulationPort", sctl.lIDE1MasterEmulationPort);
|
---|
2627 | elmStorageController.getAttributeValue("IDE1SlaveEmulationPort", sctl.lIDE1SlaveEmulationPort);
|
---|
2628 |
|
---|
2629 | elmStorageController.getAttributeValue("useHostIOCache", sctl.fUseHostIOCache);
|
---|
2630 | }
|
---|
2631 |
|
---|
2632 | /**
|
---|
2633 | * Reads in a <Hardware> block and stores it in the given structure. Used
|
---|
2634 | * both directly from readMachine and from readSnapshot, since snapshots
|
---|
2635 | * have their own hardware sections.
|
---|
2636 | *
|
---|
2637 | * For legacy pre-1.7 settings we also need a storage structure because
|
---|
2638 | * the IDE and SATA controllers used to be defined under <Hardware>.
|
---|
2639 | *
|
---|
2640 | * @param elmHardware
|
---|
2641 | * @param hw
|
---|
2642 | */
|
---|
2643 | void MachineConfigFile::readHardware(const xml::ElementNode &elmHardware,
|
---|
2644 | Hardware &hw,
|
---|
2645 | Storage &strg)
|
---|
2646 | {
|
---|
2647 | if (!elmHardware.getAttributeValue("version", hw.strVersion))
|
---|
2648 | {
|
---|
2649 | /* KLUDGE ALERT! For a while during the 3.1 development this was not
|
---|
2650 | written because it was thought to have a default value of "2". For
|
---|
2651 | sv <= 1.3 it defaults to "1" because the attribute didn't exist,
|
---|
2652 | while for 1.4+ it is sort of mandatory. Now, the buggy XML writer
|
---|
2653 | code only wrote 1.7 and later. So, if it's a 1.7+ XML file and it's
|
---|
2654 | missing the hardware version, then it probably should be "2" instead
|
---|
2655 | of "1". */
|
---|
2656 | if (m->sv < SettingsVersion_v1_7)
|
---|
2657 | hw.strVersion = "1";
|
---|
2658 | else
|
---|
2659 | hw.strVersion = "2";
|
---|
2660 | }
|
---|
2661 | Utf8Str strUUID;
|
---|
2662 | if (elmHardware.getAttributeValue("uuid", strUUID))
|
---|
2663 | parseUUID(hw.uuid, strUUID);
|
---|
2664 |
|
---|
2665 | xml::NodesLoop nl1(elmHardware);
|
---|
2666 | const xml::ElementNode *pelmHwChild;
|
---|
2667 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
2668 | {
|
---|
2669 | if (pelmHwChild->nameEquals("CPU"))
|
---|
2670 | {
|
---|
2671 | if (!pelmHwChild->getAttributeValue("count", hw.cCPUs))
|
---|
2672 | {
|
---|
2673 | // pre-1.5 variant; not sure if this actually exists in the wild anywhere
|
---|
2674 | const xml::ElementNode *pelmCPUChild;
|
---|
2675 | if ((pelmCPUChild = pelmHwChild->findChildElement("CPUCount")))
|
---|
2676 | pelmCPUChild->getAttributeValue("count", hw.cCPUs);
|
---|
2677 | }
|
---|
2678 |
|
---|
2679 | pelmHwChild->getAttributeValue("hotplug", hw.fCpuHotPlug);
|
---|
2680 | pelmHwChild->getAttributeValue("executionCap", hw.ulCpuExecutionCap);
|
---|
2681 |
|
---|
2682 | const xml::ElementNode *pelmCPUChild;
|
---|
2683 | if (hw.fCpuHotPlug)
|
---|
2684 | {
|
---|
2685 | if ((pelmCPUChild = pelmHwChild->findChildElement("CpuTree")))
|
---|
2686 | readCpuTree(*pelmCPUChild, hw.llCpus);
|
---|
2687 | }
|
---|
2688 |
|
---|
2689 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtEx")))
|
---|
2690 | {
|
---|
2691 | pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirt);
|
---|
2692 | }
|
---|
2693 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExNestedPaging")))
|
---|
2694 | pelmCPUChild->getAttributeValue("enabled", hw.fNestedPaging);
|
---|
2695 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExLargePages")))
|
---|
2696 | pelmCPUChild->getAttributeValue("enabled", hw.fLargePages);
|
---|
2697 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExVPID")))
|
---|
2698 | pelmCPUChild->getAttributeValue("enabled", hw.fVPID);
|
---|
2699 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExUX")))
|
---|
2700 | pelmCPUChild->getAttributeValue("enabled", hw.fUnrestrictedExecution);
|
---|
2701 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtForce")))
|
---|
2702 | pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirtForce);
|
---|
2703 |
|
---|
2704 | if (!(pelmCPUChild = pelmHwChild->findChildElement("PAE")))
|
---|
2705 | {
|
---|
2706 | /* The default for pre 3.1 was false, so we must respect that. */
|
---|
2707 | if (m->sv < SettingsVersion_v1_9)
|
---|
2708 | hw.fPAE = false;
|
---|
2709 | }
|
---|
2710 | else
|
---|
2711 | pelmCPUChild->getAttributeValue("enabled", hw.fPAE);
|
---|
2712 |
|
---|
2713 | bool fLongMode;
|
---|
2714 | if ( (pelmCPUChild = pelmHwChild->findChildElement("LongMode"))
|
---|
2715 | && pelmCPUChild->getAttributeValue("enabled", fLongMode) )
|
---|
2716 | hw.enmLongMode = fLongMode ? Hardware::LongMode_Enabled : Hardware::LongMode_Disabled;
|
---|
2717 | else
|
---|
2718 | hw.enmLongMode = Hardware::LongMode_Legacy;
|
---|
2719 |
|
---|
2720 | if ((pelmCPUChild = pelmHwChild->findChildElement("SyntheticCpu")))
|
---|
2721 | pelmCPUChild->getAttributeValue("enabled", hw.fSyntheticCpu);
|
---|
2722 |
|
---|
2723 | if ((pelmCPUChild = pelmHwChild->findChildElement("TripleFaultReset")))
|
---|
2724 | pelmCPUChild->getAttributeValue("enabled", hw.fTripleFaultReset);
|
---|
2725 |
|
---|
2726 | if ((pelmCPUChild = pelmHwChild->findChildElement("CpuIdTree")))
|
---|
2727 | readCpuIdTree(*pelmCPUChild, hw.llCpuIdLeafs);
|
---|
2728 | }
|
---|
2729 | else if (pelmHwChild->nameEquals("Memory"))
|
---|
2730 | {
|
---|
2731 | pelmHwChild->getAttributeValue("RAMSize", hw.ulMemorySizeMB);
|
---|
2732 | pelmHwChild->getAttributeValue("PageFusion", hw.fPageFusionEnabled);
|
---|
2733 | }
|
---|
2734 | else if (pelmHwChild->nameEquals("Firmware"))
|
---|
2735 | {
|
---|
2736 | Utf8Str strFirmwareType;
|
---|
2737 | if (pelmHwChild->getAttributeValue("type", strFirmwareType))
|
---|
2738 | {
|
---|
2739 | if ( (strFirmwareType == "BIOS")
|
---|
2740 | || (strFirmwareType == "1") // some trunk builds used the number here
|
---|
2741 | )
|
---|
2742 | hw.firmwareType = FirmwareType_BIOS;
|
---|
2743 | else if ( (strFirmwareType == "EFI")
|
---|
2744 | || (strFirmwareType == "2") // some trunk builds used the number here
|
---|
2745 | )
|
---|
2746 | hw.firmwareType = FirmwareType_EFI;
|
---|
2747 | else if ( strFirmwareType == "EFI32")
|
---|
2748 | hw.firmwareType = FirmwareType_EFI32;
|
---|
2749 | else if ( strFirmwareType == "EFI64")
|
---|
2750 | hw.firmwareType = FirmwareType_EFI64;
|
---|
2751 | else if ( strFirmwareType == "EFIDUAL")
|
---|
2752 | hw.firmwareType = FirmwareType_EFIDUAL;
|
---|
2753 | else
|
---|
2754 | throw ConfigFileError(this,
|
---|
2755 | pelmHwChild,
|
---|
2756 | N_("Invalid value '%s' in Firmware/@type"),
|
---|
2757 | strFirmwareType.c_str());
|
---|
2758 | }
|
---|
2759 | }
|
---|
2760 | else if (pelmHwChild->nameEquals("HID"))
|
---|
2761 | {
|
---|
2762 | Utf8Str strHIDType;
|
---|
2763 | if (pelmHwChild->getAttributeValue("Keyboard", strHIDType))
|
---|
2764 | {
|
---|
2765 | if (strHIDType == "None")
|
---|
2766 | hw.keyboardHIDType = KeyboardHIDType_None;
|
---|
2767 | else if (strHIDType == "USBKeyboard")
|
---|
2768 | hw.keyboardHIDType = KeyboardHIDType_USBKeyboard;
|
---|
2769 | else if (strHIDType == "PS2Keyboard")
|
---|
2770 | hw.keyboardHIDType = KeyboardHIDType_PS2Keyboard;
|
---|
2771 | else if (strHIDType == "ComboKeyboard")
|
---|
2772 | hw.keyboardHIDType = KeyboardHIDType_ComboKeyboard;
|
---|
2773 | else
|
---|
2774 | throw ConfigFileError(this,
|
---|
2775 | pelmHwChild,
|
---|
2776 | N_("Invalid value '%s' in HID/Keyboard/@type"),
|
---|
2777 | strHIDType.c_str());
|
---|
2778 | }
|
---|
2779 | if (pelmHwChild->getAttributeValue("Pointing", strHIDType))
|
---|
2780 | {
|
---|
2781 | if (strHIDType == "None")
|
---|
2782 | hw.pointingHIDType = PointingHIDType_None;
|
---|
2783 | else if (strHIDType == "USBMouse")
|
---|
2784 | hw.pointingHIDType = PointingHIDType_USBMouse;
|
---|
2785 | else if (strHIDType == "USBTablet")
|
---|
2786 | hw.pointingHIDType = PointingHIDType_USBTablet;
|
---|
2787 | else if (strHIDType == "PS2Mouse")
|
---|
2788 | hw.pointingHIDType = PointingHIDType_PS2Mouse;
|
---|
2789 | else if (strHIDType == "ComboMouse")
|
---|
2790 | hw.pointingHIDType = PointingHIDType_ComboMouse;
|
---|
2791 | else if (strHIDType == "USBMultiTouch")
|
---|
2792 | hw.pointingHIDType = PointingHIDType_USBMultiTouch;
|
---|
2793 | else
|
---|
2794 | throw ConfigFileError(this,
|
---|
2795 | pelmHwChild,
|
---|
2796 | N_("Invalid value '%s' in HID/Pointing/@type"),
|
---|
2797 | strHIDType.c_str());
|
---|
2798 | }
|
---|
2799 | }
|
---|
2800 | else if (pelmHwChild->nameEquals("Chipset"))
|
---|
2801 | {
|
---|
2802 | Utf8Str strChipsetType;
|
---|
2803 | if (pelmHwChild->getAttributeValue("type", strChipsetType))
|
---|
2804 | {
|
---|
2805 | if (strChipsetType == "PIIX3")
|
---|
2806 | hw.chipsetType = ChipsetType_PIIX3;
|
---|
2807 | else if (strChipsetType == "ICH9")
|
---|
2808 | hw.chipsetType = ChipsetType_ICH9;
|
---|
2809 | else
|
---|
2810 | throw ConfigFileError(this,
|
---|
2811 | pelmHwChild,
|
---|
2812 | N_("Invalid value '%s' in Chipset/@type"),
|
---|
2813 | strChipsetType.c_str());
|
---|
2814 | }
|
---|
2815 | }
|
---|
2816 | else if (pelmHwChild->nameEquals("HPET"))
|
---|
2817 | {
|
---|
2818 | pelmHwChild->getAttributeValue("enabled", hw.fHPETEnabled);
|
---|
2819 | }
|
---|
2820 | else if (pelmHwChild->nameEquals("Boot"))
|
---|
2821 | {
|
---|
2822 | hw.mapBootOrder.clear();
|
---|
2823 |
|
---|
2824 | xml::NodesLoop nl2(*pelmHwChild, "Order");
|
---|
2825 | const xml::ElementNode *pelmOrder;
|
---|
2826 | while ((pelmOrder = nl2.forAllNodes()))
|
---|
2827 | {
|
---|
2828 | uint32_t ulPos;
|
---|
2829 | Utf8Str strDevice;
|
---|
2830 | if (!pelmOrder->getAttributeValue("position", ulPos))
|
---|
2831 | throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@position attribute is missing"));
|
---|
2832 |
|
---|
2833 | if ( ulPos < 1
|
---|
2834 | || ulPos > SchemaDefs::MaxBootPosition
|
---|
2835 | )
|
---|
2836 | throw ConfigFileError(this,
|
---|
2837 | pelmOrder,
|
---|
2838 | N_("Invalid value '%RU32' in Boot/Order/@position: must be greater than 0 and less than %RU32"),
|
---|
2839 | ulPos,
|
---|
2840 | SchemaDefs::MaxBootPosition + 1);
|
---|
2841 | // XML is 1-based but internal data is 0-based
|
---|
2842 | --ulPos;
|
---|
2843 |
|
---|
2844 | if (hw.mapBootOrder.find(ulPos) != hw.mapBootOrder.end())
|
---|
2845 | throw ConfigFileError(this, pelmOrder, N_("Invalid value '%RU32' in Boot/Order/@position: value is not unique"), ulPos);
|
---|
2846 |
|
---|
2847 | if (!pelmOrder->getAttributeValue("device", strDevice))
|
---|
2848 | throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@device attribute is missing"));
|
---|
2849 |
|
---|
2850 | DeviceType_T type;
|
---|
2851 | if (strDevice == "None")
|
---|
2852 | type = DeviceType_Null;
|
---|
2853 | else if (strDevice == "Floppy")
|
---|
2854 | type = DeviceType_Floppy;
|
---|
2855 | else if (strDevice == "DVD")
|
---|
2856 | type = DeviceType_DVD;
|
---|
2857 | else if (strDevice == "HardDisk")
|
---|
2858 | type = DeviceType_HardDisk;
|
---|
2859 | else if (strDevice == "Network")
|
---|
2860 | type = DeviceType_Network;
|
---|
2861 | else
|
---|
2862 | throw ConfigFileError(this, pelmOrder, N_("Invalid value '%s' in Boot/Order/@device attribute"), strDevice.c_str());
|
---|
2863 | hw.mapBootOrder[ulPos] = type;
|
---|
2864 | }
|
---|
2865 | }
|
---|
2866 | else if (pelmHwChild->nameEquals("Display"))
|
---|
2867 | {
|
---|
2868 | Utf8Str strGraphicsControllerType;
|
---|
2869 | if (!pelmHwChild->getAttributeValue("controller", strGraphicsControllerType))
|
---|
2870 | hw.graphicsControllerType = GraphicsControllerType_VBoxVGA;
|
---|
2871 | else
|
---|
2872 | {
|
---|
2873 | strGraphicsControllerType.toUpper();
|
---|
2874 | GraphicsControllerType_T type;
|
---|
2875 | if (strGraphicsControllerType == "VBOXVGA")
|
---|
2876 | type = GraphicsControllerType_VBoxVGA;
|
---|
2877 | else if (strGraphicsControllerType == "VMSVGA")
|
---|
2878 | type = GraphicsControllerType_VMSVGA;
|
---|
2879 | else if (strGraphicsControllerType == "NONE")
|
---|
2880 | type = GraphicsControllerType_Null;
|
---|
2881 | else
|
---|
2882 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Display/@controller attribute"), strGraphicsControllerType.c_str());
|
---|
2883 | hw.graphicsControllerType = type;
|
---|
2884 | }
|
---|
2885 | pelmHwChild->getAttributeValue("VRAMSize", hw.ulVRAMSizeMB);
|
---|
2886 | if (!pelmHwChild->getAttributeValue("monitorCount", hw.cMonitors))
|
---|
2887 | pelmHwChild->getAttributeValue("MonitorCount", hw.cMonitors); // pre-v1.5 variant
|
---|
2888 | if (!pelmHwChild->getAttributeValue("accelerate3D", hw.fAccelerate3D))
|
---|
2889 | pelmHwChild->getAttributeValue("Accelerate3D", hw.fAccelerate3D); // pre-v1.5 variant
|
---|
2890 | pelmHwChild->getAttributeValue("accelerate2DVideo", hw.fAccelerate2DVideo);
|
---|
2891 | }
|
---|
2892 | else if (pelmHwChild->nameEquals("VideoCapture"))
|
---|
2893 | {
|
---|
2894 | pelmHwChild->getAttributeValue("enabled", hw.fVideoCaptureEnabled);
|
---|
2895 | pelmHwChild->getAttributeValue("screens", hw.u64VideoCaptureScreens);
|
---|
2896 | pelmHwChild->getAttributeValuePath("file", hw.strVideoCaptureFile);
|
---|
2897 | pelmHwChild->getAttributeValue("horzRes", hw.ulVideoCaptureHorzRes);
|
---|
2898 | pelmHwChild->getAttributeValue("vertRes", hw.ulVideoCaptureVertRes);
|
---|
2899 | pelmHwChild->getAttributeValue("rate", hw.ulVideoCaptureRate);
|
---|
2900 | pelmHwChild->getAttributeValue("fps", hw.ulVideoCaptureFPS);
|
---|
2901 | }
|
---|
2902 | else if (pelmHwChild->nameEquals("RemoteDisplay"))
|
---|
2903 | {
|
---|
2904 | pelmHwChild->getAttributeValue("enabled", hw.vrdeSettings.fEnabled);
|
---|
2905 |
|
---|
2906 | Utf8Str str;
|
---|
2907 | if (pelmHwChild->getAttributeValue("port", str))
|
---|
2908 | hw.vrdeSettings.mapProperties["TCP/Ports"] = str;
|
---|
2909 | if (pelmHwChild->getAttributeValue("netAddress", str))
|
---|
2910 | hw.vrdeSettings.mapProperties["TCP/Address"] = str;
|
---|
2911 |
|
---|
2912 | Utf8Str strAuthType;
|
---|
2913 | if (pelmHwChild->getAttributeValue("authType", strAuthType))
|
---|
2914 | {
|
---|
2915 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
2916 | strAuthType.toUpper();
|
---|
2917 | if (strAuthType == "NULL")
|
---|
2918 | hw.vrdeSettings.authType = AuthType_Null;
|
---|
2919 | else if (strAuthType == "GUEST")
|
---|
2920 | hw.vrdeSettings.authType = AuthType_Guest;
|
---|
2921 | else if (strAuthType == "EXTERNAL")
|
---|
2922 | hw.vrdeSettings.authType = AuthType_External;
|
---|
2923 | else
|
---|
2924 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in RemoteDisplay/@authType attribute"), strAuthType.c_str());
|
---|
2925 | }
|
---|
2926 |
|
---|
2927 | pelmHwChild->getAttributeValue("authLibrary", hw.vrdeSettings.strAuthLibrary);
|
---|
2928 | pelmHwChild->getAttributeValue("authTimeout", hw.vrdeSettings.ulAuthTimeout);
|
---|
2929 | pelmHwChild->getAttributeValue("allowMultiConnection", hw.vrdeSettings.fAllowMultiConnection);
|
---|
2930 | pelmHwChild->getAttributeValue("reuseSingleConnection", hw.vrdeSettings.fReuseSingleConnection);
|
---|
2931 |
|
---|
2932 | /* 3.2 and 4.0 betas, 4.0 has this information in VRDEProperties. */
|
---|
2933 | const xml::ElementNode *pelmVideoChannel;
|
---|
2934 | if ((pelmVideoChannel = pelmHwChild->findChildElement("VideoChannel")))
|
---|
2935 | {
|
---|
2936 | bool fVideoChannel = false;
|
---|
2937 | pelmVideoChannel->getAttributeValue("enabled", fVideoChannel);
|
---|
2938 | hw.vrdeSettings.mapProperties["VideoChannel/Enabled"] = fVideoChannel? "true": "false";
|
---|
2939 |
|
---|
2940 | uint32_t ulVideoChannelQuality = 75;
|
---|
2941 | pelmVideoChannel->getAttributeValue("quality", ulVideoChannelQuality);
|
---|
2942 | ulVideoChannelQuality = RT_CLAMP(ulVideoChannelQuality, 10, 100);
|
---|
2943 | char *pszBuffer = NULL;
|
---|
2944 | if (RTStrAPrintf(&pszBuffer, "%d", ulVideoChannelQuality) >= 0)
|
---|
2945 | {
|
---|
2946 | hw.vrdeSettings.mapProperties["VideoChannel/Quality"] = pszBuffer;
|
---|
2947 | RTStrFree(pszBuffer);
|
---|
2948 | }
|
---|
2949 | else
|
---|
2950 | hw.vrdeSettings.mapProperties["VideoChannel/Quality"] = "75";
|
---|
2951 | }
|
---|
2952 | pelmHwChild->getAttributeValue("VRDEExtPack", hw.vrdeSettings.strVrdeExtPack);
|
---|
2953 |
|
---|
2954 | const xml::ElementNode *pelmProperties = pelmHwChild->findChildElement("VRDEProperties");
|
---|
2955 | if (pelmProperties != NULL)
|
---|
2956 | {
|
---|
2957 | xml::NodesLoop nl(*pelmProperties);
|
---|
2958 | const xml::ElementNode *pelmProperty;
|
---|
2959 | while ((pelmProperty = nl.forAllNodes()))
|
---|
2960 | {
|
---|
2961 | if (pelmProperty->nameEquals("Property"))
|
---|
2962 | {
|
---|
2963 | /* <Property name="TCP/Ports" value="3000-3002"/> */
|
---|
2964 | Utf8Str strName, strValue;
|
---|
2965 | if ( pelmProperty->getAttributeValue("name", strName)
|
---|
2966 | && pelmProperty->getAttributeValue("value", strValue))
|
---|
2967 | hw.vrdeSettings.mapProperties[strName] = strValue;
|
---|
2968 | else
|
---|
2969 | throw ConfigFileError(this, pelmProperty, N_("Required VRDE Property/@name or @value attribute is missing"));
|
---|
2970 | }
|
---|
2971 | }
|
---|
2972 | }
|
---|
2973 | }
|
---|
2974 | else if (pelmHwChild->nameEquals("BIOS"))
|
---|
2975 | {
|
---|
2976 | const xml::ElementNode *pelmBIOSChild;
|
---|
2977 | if ((pelmBIOSChild = pelmHwChild->findChildElement("ACPI")))
|
---|
2978 | pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fACPIEnabled);
|
---|
2979 | if ((pelmBIOSChild = pelmHwChild->findChildElement("IOAPIC")))
|
---|
2980 | pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fIOAPICEnabled);
|
---|
2981 | if ((pelmBIOSChild = pelmHwChild->findChildElement("Logo")))
|
---|
2982 | {
|
---|
2983 | pelmBIOSChild->getAttributeValue("fadeIn", hw.biosSettings.fLogoFadeIn);
|
---|
2984 | pelmBIOSChild->getAttributeValue("fadeOut", hw.biosSettings.fLogoFadeOut);
|
---|
2985 | pelmBIOSChild->getAttributeValue("displayTime", hw.biosSettings.ulLogoDisplayTime);
|
---|
2986 | pelmBIOSChild->getAttributeValue("imagePath", hw.biosSettings.strLogoImagePath);
|
---|
2987 | }
|
---|
2988 | if ((pelmBIOSChild = pelmHwChild->findChildElement("BootMenu")))
|
---|
2989 | {
|
---|
2990 | Utf8Str strBootMenuMode;
|
---|
2991 | if (pelmBIOSChild->getAttributeValue("mode", strBootMenuMode))
|
---|
2992 | {
|
---|
2993 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
2994 | strBootMenuMode.toUpper();
|
---|
2995 | if (strBootMenuMode == "DISABLED")
|
---|
2996 | hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_Disabled;
|
---|
2997 | else if (strBootMenuMode == "MENUONLY")
|
---|
2998 | hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MenuOnly;
|
---|
2999 | else if (strBootMenuMode == "MESSAGEANDMENU")
|
---|
3000 | hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MessageAndMenu;
|
---|
3001 | else
|
---|
3002 | throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' in BootMenu/@mode attribute"), strBootMenuMode.c_str());
|
---|
3003 | }
|
---|
3004 | }
|
---|
3005 | if ((pelmBIOSChild = pelmHwChild->findChildElement("PXEDebug")))
|
---|
3006 | pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fPXEDebugEnabled);
|
---|
3007 | if ((pelmBIOSChild = pelmHwChild->findChildElement("TimeOffset")))
|
---|
3008 | pelmBIOSChild->getAttributeValue("value", hw.biosSettings.llTimeOffset);
|
---|
3009 |
|
---|
3010 | // legacy BIOS/IDEController (pre 1.7)
|
---|
3011 | if ( (m->sv < SettingsVersion_v1_7)
|
---|
3012 | && (pelmBIOSChild = pelmHwChild->findChildElement("IDEController"))
|
---|
3013 | )
|
---|
3014 | {
|
---|
3015 | StorageController sctl;
|
---|
3016 | sctl.strName = "IDE Controller";
|
---|
3017 | sctl.storageBus = StorageBus_IDE;
|
---|
3018 |
|
---|
3019 | Utf8Str strType;
|
---|
3020 | if (pelmBIOSChild->getAttributeValue("type", strType))
|
---|
3021 | {
|
---|
3022 | if (strType == "PIIX3")
|
---|
3023 | sctl.controllerType = StorageControllerType_PIIX3;
|
---|
3024 | else if (strType == "PIIX4")
|
---|
3025 | sctl.controllerType = StorageControllerType_PIIX4;
|
---|
3026 | else if (strType == "ICH6")
|
---|
3027 | sctl.controllerType = StorageControllerType_ICH6;
|
---|
3028 | else
|
---|
3029 | throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' for IDEController/@type attribute"), strType.c_str());
|
---|
3030 | }
|
---|
3031 | sctl.ulPortCount = 2;
|
---|
3032 | strg.llStorageControllers.push_back(sctl);
|
---|
3033 | }
|
---|
3034 | }
|
---|
3035 | else if ( (m->sv <= SettingsVersion_v1_14)
|
---|
3036 | && pelmHwChild->nameEquals("USBController"))
|
---|
3037 | {
|
---|
3038 | bool fEnabled = false;
|
---|
3039 |
|
---|
3040 | pelmHwChild->getAttributeValue("enabled", fEnabled);
|
---|
3041 | if (fEnabled)
|
---|
3042 | {
|
---|
3043 | /* Create OHCI controller with default name. */
|
---|
3044 | USBController ctrl;
|
---|
3045 |
|
---|
3046 | ctrl.strName = "OHCI";
|
---|
3047 | ctrl.enmType = USBControllerType_OHCI;
|
---|
3048 | hw.usbSettings.llUSBControllers.push_back(ctrl);
|
---|
3049 | }
|
---|
3050 |
|
---|
3051 | pelmHwChild->getAttributeValue("enabledEhci", fEnabled);
|
---|
3052 | if (fEnabled)
|
---|
3053 | {
|
---|
3054 | /* Create OHCI controller with default name. */
|
---|
3055 | USBController ctrl;
|
---|
3056 |
|
---|
3057 | ctrl.strName = "EHCI";
|
---|
3058 | ctrl.enmType = USBControllerType_EHCI;
|
---|
3059 | hw.usbSettings.llUSBControllers.push_back(ctrl);
|
---|
3060 | }
|
---|
3061 |
|
---|
3062 | readUSBDeviceFilters(*pelmHwChild,
|
---|
3063 | hw.usbSettings.llDeviceFilters);
|
---|
3064 | }
|
---|
3065 | else if (pelmHwChild->nameEquals("USB"))
|
---|
3066 | {
|
---|
3067 | const xml::ElementNode *pelmUSBChild;
|
---|
3068 |
|
---|
3069 | if ((pelmUSBChild = pelmHwChild->findChildElement("Controllers")))
|
---|
3070 | {
|
---|
3071 | xml::NodesLoop nl2(*pelmUSBChild, "Controller");
|
---|
3072 | const xml::ElementNode *pelmCtrl;
|
---|
3073 |
|
---|
3074 | while ((pelmCtrl = nl2.forAllNodes()))
|
---|
3075 | {
|
---|
3076 | USBController ctrl;
|
---|
3077 | com::Utf8Str strCtrlType;
|
---|
3078 |
|
---|
3079 | pelmCtrl->getAttributeValue("name", ctrl.strName);
|
---|
3080 |
|
---|
3081 | if (pelmCtrl->getAttributeValue("type", strCtrlType))
|
---|
3082 | {
|
---|
3083 | if (strCtrlType == "OHCI")
|
---|
3084 | ctrl.enmType = USBControllerType_OHCI;
|
---|
3085 | else if (strCtrlType == "EHCI")
|
---|
3086 | ctrl.enmType = USBControllerType_EHCI;
|
---|
3087 | else
|
---|
3088 | throw ConfigFileError(this, pelmCtrl, N_("Invalid value '%s' for Controller/@type attribute"), strCtrlType.c_str());
|
---|
3089 | }
|
---|
3090 |
|
---|
3091 | hw.usbSettings.llUSBControllers.push_back(ctrl);
|
---|
3092 | }
|
---|
3093 | }
|
---|
3094 |
|
---|
3095 | if ((pelmUSBChild = pelmHwChild->findChildElement("DeviceFilters")))
|
---|
3096 | readUSBDeviceFilters(*pelmUSBChild, hw.usbSettings.llDeviceFilters);
|
---|
3097 | }
|
---|
3098 | else if ( m->sv < SettingsVersion_v1_7
|
---|
3099 | && pelmHwChild->nameEquals("SATAController"))
|
---|
3100 | {
|
---|
3101 | bool f;
|
---|
3102 | if ( pelmHwChild->getAttributeValue("enabled", f)
|
---|
3103 | && f)
|
---|
3104 | {
|
---|
3105 | StorageController sctl;
|
---|
3106 | sctl.strName = "SATA Controller";
|
---|
3107 | sctl.storageBus = StorageBus_SATA;
|
---|
3108 | sctl.controllerType = StorageControllerType_IntelAhci;
|
---|
3109 |
|
---|
3110 | readStorageControllerAttributes(*pelmHwChild, sctl);
|
---|
3111 |
|
---|
3112 | strg.llStorageControllers.push_back(sctl);
|
---|
3113 | }
|
---|
3114 | }
|
---|
3115 | else if (pelmHwChild->nameEquals("Network"))
|
---|
3116 | readNetworkAdapters(*pelmHwChild, hw.llNetworkAdapters);
|
---|
3117 | else if (pelmHwChild->nameEquals("RTC"))
|
---|
3118 | {
|
---|
3119 | Utf8Str strLocalOrUTC;
|
---|
3120 | machineUserData.fRTCUseUTC = pelmHwChild->getAttributeValue("localOrUTC", strLocalOrUTC)
|
---|
3121 | && strLocalOrUTC == "UTC";
|
---|
3122 | }
|
---|
3123 | else if ( pelmHwChild->nameEquals("UART")
|
---|
3124 | || pelmHwChild->nameEquals("Uart") // used before 1.3
|
---|
3125 | )
|
---|
3126 | readSerialPorts(*pelmHwChild, hw.llSerialPorts);
|
---|
3127 | else if ( pelmHwChild->nameEquals("LPT")
|
---|
3128 | || pelmHwChild->nameEquals("Lpt") // used before 1.3
|
---|
3129 | )
|
---|
3130 | readParallelPorts(*pelmHwChild, hw.llParallelPorts);
|
---|
3131 | else if (pelmHwChild->nameEquals("AudioAdapter"))
|
---|
3132 | readAudioAdapter(*pelmHwChild, hw.audioAdapter);
|
---|
3133 | else if (pelmHwChild->nameEquals("SharedFolders"))
|
---|
3134 | {
|
---|
3135 | xml::NodesLoop nl2(*pelmHwChild, "SharedFolder");
|
---|
3136 | const xml::ElementNode *pelmFolder;
|
---|
3137 | while ((pelmFolder = nl2.forAllNodes()))
|
---|
3138 | {
|
---|
3139 | SharedFolder sf;
|
---|
3140 | pelmFolder->getAttributeValue("name", sf.strName);
|
---|
3141 | pelmFolder->getAttributeValue("hostPath", sf.strHostPath);
|
---|
3142 | pelmFolder->getAttributeValue("writable", sf.fWritable);
|
---|
3143 | pelmFolder->getAttributeValue("autoMount", sf.fAutoMount);
|
---|
3144 | hw.llSharedFolders.push_back(sf);
|
---|
3145 | }
|
---|
3146 | }
|
---|
3147 | else if (pelmHwChild->nameEquals("Clipboard"))
|
---|
3148 | {
|
---|
3149 | Utf8Str strTemp;
|
---|
3150 | if (pelmHwChild->getAttributeValue("mode", strTemp))
|
---|
3151 | {
|
---|
3152 | if (strTemp == "Disabled")
|
---|
3153 | hw.clipboardMode = ClipboardMode_Disabled;
|
---|
3154 | else if (strTemp == "HostToGuest")
|
---|
3155 | hw.clipboardMode = ClipboardMode_HostToGuest;
|
---|
3156 | else if (strTemp == "GuestToHost")
|
---|
3157 | hw.clipboardMode = ClipboardMode_GuestToHost;
|
---|
3158 | else if (strTemp == "Bidirectional")
|
---|
3159 | hw.clipboardMode = ClipboardMode_Bidirectional;
|
---|
3160 | else
|
---|
3161 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Clipboard/@mode attribute"), strTemp.c_str());
|
---|
3162 | }
|
---|
3163 | }
|
---|
3164 | else if (pelmHwChild->nameEquals("DragAndDrop"))
|
---|
3165 | {
|
---|
3166 | Utf8Str strTemp;
|
---|
3167 | if (pelmHwChild->getAttributeValue("mode", strTemp))
|
---|
3168 | {
|
---|
3169 | if (strTemp == "Disabled")
|
---|
3170 | hw.dragAndDropMode = DragAndDropMode_Disabled;
|
---|
3171 | else if (strTemp == "HostToGuest")
|
---|
3172 | hw.dragAndDropMode = DragAndDropMode_HostToGuest;
|
---|
3173 | else if (strTemp == "GuestToHost")
|
---|
3174 | hw.dragAndDropMode = DragAndDropMode_GuestToHost;
|
---|
3175 | else if (strTemp == "Bidirectional")
|
---|
3176 | hw.dragAndDropMode = DragAndDropMode_Bidirectional;
|
---|
3177 | else
|
---|
3178 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in DragAndDrop/@mode attribute"), strTemp.c_str());
|
---|
3179 | }
|
---|
3180 | }
|
---|
3181 | else if (pelmHwChild->nameEquals("Guest"))
|
---|
3182 | {
|
---|
3183 | if (!pelmHwChild->getAttributeValue("memoryBalloonSize", hw.ulMemoryBalloonSize))
|
---|
3184 | pelmHwChild->getAttributeValue("MemoryBalloonSize", hw.ulMemoryBalloonSize); // used before 1.3
|
---|
3185 | }
|
---|
3186 | else if (pelmHwChild->nameEquals("GuestProperties"))
|
---|
3187 | readGuestProperties(*pelmHwChild, hw);
|
---|
3188 | else if (pelmHwChild->nameEquals("IO"))
|
---|
3189 | {
|
---|
3190 | const xml::ElementNode *pelmBwGroups;
|
---|
3191 | const xml::ElementNode *pelmIOChild;
|
---|
3192 |
|
---|
3193 | if ((pelmIOChild = pelmHwChild->findChildElement("IoCache")))
|
---|
3194 | {
|
---|
3195 | pelmIOChild->getAttributeValue("enabled", hw.ioSettings.fIOCacheEnabled);
|
---|
3196 | pelmIOChild->getAttributeValue("size", hw.ioSettings.ulIOCacheSize);
|
---|
3197 | }
|
---|
3198 |
|
---|
3199 | if ((pelmBwGroups = pelmHwChild->findChildElement("BandwidthGroups")))
|
---|
3200 | {
|
---|
3201 | xml::NodesLoop nl2(*pelmBwGroups, "BandwidthGroup");
|
---|
3202 | const xml::ElementNode *pelmBandwidthGroup;
|
---|
3203 | while ((pelmBandwidthGroup = nl2.forAllNodes()))
|
---|
3204 | {
|
---|
3205 | BandwidthGroup gr;
|
---|
3206 | Utf8Str strTemp;
|
---|
3207 |
|
---|
3208 | pelmBandwidthGroup->getAttributeValue("name", gr.strName);
|
---|
3209 |
|
---|
3210 | if (pelmBandwidthGroup->getAttributeValue("type", strTemp))
|
---|
3211 | {
|
---|
3212 | if (strTemp == "Disk")
|
---|
3213 | gr.enmType = BandwidthGroupType_Disk;
|
---|
3214 | else if (strTemp == "Network")
|
---|
3215 | gr.enmType = BandwidthGroupType_Network;
|
---|
3216 | else
|
---|
3217 | throw ConfigFileError(this, pelmBandwidthGroup, N_("Invalid value '%s' in BandwidthGroup/@type attribute"), strTemp.c_str());
|
---|
3218 | }
|
---|
3219 | else
|
---|
3220 | throw ConfigFileError(this, pelmBandwidthGroup, N_("Missing BandwidthGroup/@type attribute"));
|
---|
3221 |
|
---|
3222 | if (!pelmBandwidthGroup->getAttributeValue("maxBytesPerSec", gr.cMaxBytesPerSec))
|
---|
3223 | {
|
---|
3224 | pelmBandwidthGroup->getAttributeValue("maxMbPerSec", gr.cMaxBytesPerSec);
|
---|
3225 | gr.cMaxBytesPerSec *= _1M;
|
---|
3226 | }
|
---|
3227 | hw.ioSettings.llBandwidthGroups.push_back(gr);
|
---|
3228 | }
|
---|
3229 | }
|
---|
3230 | }
|
---|
3231 | else if (pelmHwChild->nameEquals("HostPci"))
|
---|
3232 | {
|
---|
3233 | const xml::ElementNode *pelmDevices;
|
---|
3234 |
|
---|
3235 | if ((pelmDevices = pelmHwChild->findChildElement("Devices")))
|
---|
3236 | {
|
---|
3237 | xml::NodesLoop nl2(*pelmDevices, "Device");
|
---|
3238 | const xml::ElementNode *pelmDevice;
|
---|
3239 | while ((pelmDevice = nl2.forAllNodes()))
|
---|
3240 | {
|
---|
3241 | HostPCIDeviceAttachment hpda;
|
---|
3242 |
|
---|
3243 | if (!pelmDevice->getAttributeValue("host", hpda.uHostAddress))
|
---|
3244 | throw ConfigFileError(this, pelmDevice, N_("Missing Device/@host attribute"));
|
---|
3245 |
|
---|
3246 | if (!pelmDevice->getAttributeValue("guest", hpda.uGuestAddress))
|
---|
3247 | throw ConfigFileError(this, pelmDevice, N_("Missing Device/@guest attribute"));
|
---|
3248 |
|
---|
3249 | /* name is optional */
|
---|
3250 | pelmDevice->getAttributeValue("name", hpda.strDeviceName);
|
---|
3251 |
|
---|
3252 | hw.pciAttachments.push_back(hpda);
|
---|
3253 | }
|
---|
3254 | }
|
---|
3255 | }
|
---|
3256 | else if (pelmHwChild->nameEquals("EmulatedUSB"))
|
---|
3257 | {
|
---|
3258 | const xml::ElementNode *pelmCardReader;
|
---|
3259 |
|
---|
3260 | if ((pelmCardReader = pelmHwChild->findChildElement("CardReader")))
|
---|
3261 | {
|
---|
3262 | pelmCardReader->getAttributeValue("enabled", hw.fEmulatedUSBCardReader);
|
---|
3263 | }
|
---|
3264 | }
|
---|
3265 | else if (pelmHwChild->nameEquals("Frontend"))
|
---|
3266 | {
|
---|
3267 | const xml::ElementNode *pelmDefault;
|
---|
3268 |
|
---|
3269 | if ((pelmDefault = pelmHwChild->findChildElement("Default")))
|
---|
3270 | {
|
---|
3271 | pelmDefault->getAttributeValue("type", hw.strDefaultFrontend);
|
---|
3272 | }
|
---|
3273 | }
|
---|
3274 | }
|
---|
3275 |
|
---|
3276 | if (hw.ulMemorySizeMB == (uint32_t)-1)
|
---|
3277 | throw ConfigFileError(this, &elmHardware, N_("Required Memory/@RAMSize element/attribute is missing"));
|
---|
3278 | }
|
---|
3279 |
|
---|
3280 | /**
|
---|
3281 | * This gets called instead of readStorageControllers() for legacy pre-1.7 settings
|
---|
3282 | * files which have a <HardDiskAttachments> node and storage controller settings
|
---|
3283 | * hidden in the <Hardware> settings. We set the StorageControllers fields just the
|
---|
3284 | * same, just from different sources.
|
---|
3285 | * @param elmHardware <Hardware> XML node.
|
---|
3286 | * @param elmHardDiskAttachments <HardDiskAttachments> XML node.
|
---|
3287 | * @param strg
|
---|
3288 | */
|
---|
3289 | void MachineConfigFile::readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments,
|
---|
3290 | Storage &strg)
|
---|
3291 | {
|
---|
3292 | StorageController *pIDEController = NULL;
|
---|
3293 | StorageController *pSATAController = NULL;
|
---|
3294 |
|
---|
3295 | for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
|
---|
3296 | it != strg.llStorageControllers.end();
|
---|
3297 | ++it)
|
---|
3298 | {
|
---|
3299 | StorageController &s = *it;
|
---|
3300 | if (s.storageBus == StorageBus_IDE)
|
---|
3301 | pIDEController = &s;
|
---|
3302 | else if (s.storageBus == StorageBus_SATA)
|
---|
3303 | pSATAController = &s;
|
---|
3304 | }
|
---|
3305 |
|
---|
3306 | xml::NodesLoop nl1(elmHardDiskAttachments, "HardDiskAttachment");
|
---|
3307 | const xml::ElementNode *pelmAttachment;
|
---|
3308 | while ((pelmAttachment = nl1.forAllNodes()))
|
---|
3309 | {
|
---|
3310 | AttachedDevice att;
|
---|
3311 | Utf8Str strUUID, strBus;
|
---|
3312 |
|
---|
3313 | if (!pelmAttachment->getAttributeValue("hardDisk", strUUID))
|
---|
3314 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@hardDisk attribute is missing"));
|
---|
3315 | parseUUID(att.uuid, strUUID);
|
---|
3316 |
|
---|
3317 | if (!pelmAttachment->getAttributeValue("bus", strBus))
|
---|
3318 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@bus attribute is missing"));
|
---|
3319 | // pre-1.7 'channel' is now port
|
---|
3320 | if (!pelmAttachment->getAttributeValue("channel", att.lPort))
|
---|
3321 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@channel attribute is missing"));
|
---|
3322 | // pre-1.7 'device' is still device
|
---|
3323 | if (!pelmAttachment->getAttributeValue("device", att.lDevice))
|
---|
3324 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@device attribute is missing"));
|
---|
3325 |
|
---|
3326 | att.deviceType = DeviceType_HardDisk;
|
---|
3327 |
|
---|
3328 | if (strBus == "IDE")
|
---|
3329 | {
|
---|
3330 | if (!pIDEController)
|
---|
3331 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'IDE' but cannot find IDE controller"));
|
---|
3332 | pIDEController->llAttachedDevices.push_back(att);
|
---|
3333 | }
|
---|
3334 | else if (strBus == "SATA")
|
---|
3335 | {
|
---|
3336 | if (!pSATAController)
|
---|
3337 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'SATA' but cannot find SATA controller"));
|
---|
3338 | pSATAController->llAttachedDevices.push_back(att);
|
---|
3339 | }
|
---|
3340 | else
|
---|
3341 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus attribute has illegal value '%s'"), strBus.c_str());
|
---|
3342 | }
|
---|
3343 | }
|
---|
3344 |
|
---|
3345 | /**
|
---|
3346 | * Reads in a <StorageControllers> block and stores it in the given Storage structure.
|
---|
3347 | * Used both directly from readMachine and from readSnapshot, since snapshots
|
---|
3348 | * have their own storage controllers sections.
|
---|
3349 | *
|
---|
3350 | * This is only called for settings version 1.7 and above; see readHardDiskAttachments_pre1_7()
|
---|
3351 | * for earlier versions.
|
---|
3352 | *
|
---|
3353 | * @param elmStorageControllers
|
---|
3354 | */
|
---|
3355 | void MachineConfigFile::readStorageControllers(const xml::ElementNode &elmStorageControllers,
|
---|
3356 | Storage &strg)
|
---|
3357 | {
|
---|
3358 | xml::NodesLoop nlStorageControllers(elmStorageControllers, "StorageController");
|
---|
3359 | const xml::ElementNode *pelmController;
|
---|
3360 | while ((pelmController = nlStorageControllers.forAllNodes()))
|
---|
3361 | {
|
---|
3362 | StorageController sctl;
|
---|
3363 |
|
---|
3364 | if (!pelmController->getAttributeValue("name", sctl.strName))
|
---|
3365 | throw ConfigFileError(this, pelmController, N_("Required StorageController/@name attribute is missing"));
|
---|
3366 | // canonicalize storage controller names for configs in the switchover
|
---|
3367 | // period.
|
---|
3368 | if (m->sv < SettingsVersion_v1_9)
|
---|
3369 | {
|
---|
3370 | if (sctl.strName == "IDE")
|
---|
3371 | sctl.strName = "IDE Controller";
|
---|
3372 | else if (sctl.strName == "SATA")
|
---|
3373 | sctl.strName = "SATA Controller";
|
---|
3374 | else if (sctl.strName == "SCSI")
|
---|
3375 | sctl.strName = "SCSI Controller";
|
---|
3376 | }
|
---|
3377 |
|
---|
3378 | pelmController->getAttributeValue("Instance", sctl.ulInstance);
|
---|
3379 | // default from constructor is 0
|
---|
3380 |
|
---|
3381 | pelmController->getAttributeValue("Bootable", sctl.fBootable);
|
---|
3382 | // default from constructor is true which is true
|
---|
3383 | // for settings below version 1.11 because they allowed only
|
---|
3384 | // one controller per type.
|
---|
3385 |
|
---|
3386 | Utf8Str strType;
|
---|
3387 | if (!pelmController->getAttributeValue("type", strType))
|
---|
3388 | throw ConfigFileError(this, pelmController, N_("Required StorageController/@type attribute is missing"));
|
---|
3389 |
|
---|
3390 | if (strType == "AHCI")
|
---|
3391 | {
|
---|
3392 | sctl.storageBus = StorageBus_SATA;
|
---|
3393 | sctl.controllerType = StorageControllerType_IntelAhci;
|
---|
3394 | }
|
---|
3395 | else if (strType == "LsiLogic")
|
---|
3396 | {
|
---|
3397 | sctl.storageBus = StorageBus_SCSI;
|
---|
3398 | sctl.controllerType = StorageControllerType_LsiLogic;
|
---|
3399 | }
|
---|
3400 | else if (strType == "BusLogic")
|
---|
3401 | {
|
---|
3402 | sctl.storageBus = StorageBus_SCSI;
|
---|
3403 | sctl.controllerType = StorageControllerType_BusLogic;
|
---|
3404 | }
|
---|
3405 | else if (strType == "PIIX3")
|
---|
3406 | {
|
---|
3407 | sctl.storageBus = StorageBus_IDE;
|
---|
3408 | sctl.controllerType = StorageControllerType_PIIX3;
|
---|
3409 | }
|
---|
3410 | else if (strType == "PIIX4")
|
---|
3411 | {
|
---|
3412 | sctl.storageBus = StorageBus_IDE;
|
---|
3413 | sctl.controllerType = StorageControllerType_PIIX4;
|
---|
3414 | }
|
---|
3415 | else if (strType == "ICH6")
|
---|
3416 | {
|
---|
3417 | sctl.storageBus = StorageBus_IDE;
|
---|
3418 | sctl.controllerType = StorageControllerType_ICH6;
|
---|
3419 | }
|
---|
3420 | else if ( (m->sv >= SettingsVersion_v1_9)
|
---|
3421 | && (strType == "I82078")
|
---|
3422 | )
|
---|
3423 | {
|
---|
3424 | sctl.storageBus = StorageBus_Floppy;
|
---|
3425 | sctl.controllerType = StorageControllerType_I82078;
|
---|
3426 | }
|
---|
3427 | else if (strType == "LsiLogicSas")
|
---|
3428 | {
|
---|
3429 | sctl.storageBus = StorageBus_SAS;
|
---|
3430 | sctl.controllerType = StorageControllerType_LsiLogicSas;
|
---|
3431 | }
|
---|
3432 | else if (strType == "USB")
|
---|
3433 | {
|
---|
3434 | sctl.storageBus = StorageBus_USB;
|
---|
3435 | sctl.controllerType = StorageControllerType_USB;
|
---|
3436 | }
|
---|
3437 | else
|
---|
3438 | throw ConfigFileError(this, pelmController, N_("Invalid value '%s' for StorageController/@type attribute"), strType.c_str());
|
---|
3439 |
|
---|
3440 | readStorageControllerAttributes(*pelmController, sctl);
|
---|
3441 |
|
---|
3442 | xml::NodesLoop nlAttached(*pelmController, "AttachedDevice");
|
---|
3443 | const xml::ElementNode *pelmAttached;
|
---|
3444 | while ((pelmAttached = nlAttached.forAllNodes()))
|
---|
3445 | {
|
---|
3446 | AttachedDevice att;
|
---|
3447 | Utf8Str strTemp;
|
---|
3448 | pelmAttached->getAttributeValue("type", strTemp);
|
---|
3449 |
|
---|
3450 | att.fDiscard = false;
|
---|
3451 | att.fNonRotational = false;
|
---|
3452 | att.fHotPluggable = false;
|
---|
3453 |
|
---|
3454 | if (strTemp == "HardDisk")
|
---|
3455 | {
|
---|
3456 | att.deviceType = DeviceType_HardDisk;
|
---|
3457 | pelmAttached->getAttributeValue("nonrotational", att.fNonRotational);
|
---|
3458 | pelmAttached->getAttributeValue("discard", att.fDiscard);
|
---|
3459 | }
|
---|
3460 | else if (m->sv >= SettingsVersion_v1_9)
|
---|
3461 | {
|
---|
3462 | // starting with 1.9 we list DVD and floppy drive info + attachments under <StorageControllers>
|
---|
3463 | if (strTemp == "DVD")
|
---|
3464 | {
|
---|
3465 | att.deviceType = DeviceType_DVD;
|
---|
3466 | pelmAttached->getAttributeValue("passthrough", att.fPassThrough);
|
---|
3467 | pelmAttached->getAttributeValue("tempeject", att.fTempEject);
|
---|
3468 | }
|
---|
3469 | else if (strTemp == "Floppy")
|
---|
3470 | att.deviceType = DeviceType_Floppy;
|
---|
3471 | }
|
---|
3472 |
|
---|
3473 | if (att.deviceType != DeviceType_Null)
|
---|
3474 | {
|
---|
3475 | const xml::ElementNode *pelmImage;
|
---|
3476 | // all types can have images attached, but for HardDisk it's required
|
---|
3477 | if (!(pelmImage = pelmAttached->findChildElement("Image")))
|
---|
3478 | {
|
---|
3479 | if (att.deviceType == DeviceType_HardDisk)
|
---|
3480 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image element is missing"));
|
---|
3481 | else
|
---|
3482 | {
|
---|
3483 | // DVDs and floppies can also have <HostDrive> instead of <Image>
|
---|
3484 | const xml::ElementNode *pelmHostDrive;
|
---|
3485 | if ((pelmHostDrive = pelmAttached->findChildElement("HostDrive")))
|
---|
3486 | if (!pelmHostDrive->getAttributeValue("src", att.strHostDriveSrc))
|
---|
3487 | throw ConfigFileError(this, pelmHostDrive, N_("Required AttachedDevice/HostDrive/@src attribute is missing"));
|
---|
3488 | }
|
---|
3489 | }
|
---|
3490 | else
|
---|
3491 | {
|
---|
3492 | if (!pelmImage->getAttributeValue("uuid", strTemp))
|
---|
3493 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image/@uuid attribute is missing"));
|
---|
3494 | parseUUID(att.uuid, strTemp);
|
---|
3495 | }
|
---|
3496 |
|
---|
3497 | if (!pelmAttached->getAttributeValue("port", att.lPort))
|
---|
3498 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@port attribute is missing"));
|
---|
3499 | if (!pelmAttached->getAttributeValue("device", att.lDevice))
|
---|
3500 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@device attribute is missing"));
|
---|
3501 |
|
---|
3502 | /* AHCI controller ports are hotpluggable by default, keep compatibility with existing settings. */
|
---|
3503 | if (m->sv >= SettingsVersion_v1_15)
|
---|
3504 | pelmAttached->getAttributeValue("hotpluggable", att.fHotPluggable);
|
---|
3505 | else if (sctl.controllerType == StorageControllerType_IntelAhci)
|
---|
3506 | att.fHotPluggable = true;
|
---|
3507 |
|
---|
3508 | pelmAttached->getAttributeValue("bandwidthGroup", att.strBwGroup);
|
---|
3509 | sctl.llAttachedDevices.push_back(att);
|
---|
3510 | }
|
---|
3511 | }
|
---|
3512 |
|
---|
3513 | strg.llStorageControllers.push_back(sctl);
|
---|
3514 | }
|
---|
3515 | }
|
---|
3516 |
|
---|
3517 | /**
|
---|
3518 | * This gets called for legacy pre-1.9 settings files after having parsed the
|
---|
3519 | * <Hardware> and <StorageControllers> sections to parse <Hardware> once more
|
---|
3520 | * for the <DVDDrive> and <FloppyDrive> sections.
|
---|
3521 | *
|
---|
3522 | * Before settings version 1.9, DVD and floppy drives were specified separately
|
---|
3523 | * under <Hardware>; we then need this extra loop to make sure the storage
|
---|
3524 | * controller structs are already set up so we can add stuff to them.
|
---|
3525 | *
|
---|
3526 | * @param elmHardware
|
---|
3527 | * @param strg
|
---|
3528 | */
|
---|
3529 | void MachineConfigFile::readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware,
|
---|
3530 | Storage &strg)
|
---|
3531 | {
|
---|
3532 | xml::NodesLoop nl1(elmHardware);
|
---|
3533 | const xml::ElementNode *pelmHwChild;
|
---|
3534 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
3535 | {
|
---|
3536 | if (pelmHwChild->nameEquals("DVDDrive"))
|
---|
3537 | {
|
---|
3538 | // create a DVD "attached device" and attach it to the existing IDE controller
|
---|
3539 | AttachedDevice att;
|
---|
3540 | att.deviceType = DeviceType_DVD;
|
---|
3541 | // legacy DVD drive is always secondary master (port 1, device 0)
|
---|
3542 | att.lPort = 1;
|
---|
3543 | att.lDevice = 0;
|
---|
3544 | pelmHwChild->getAttributeValue("passthrough", att.fPassThrough);
|
---|
3545 | pelmHwChild->getAttributeValue("tempeject", att.fTempEject);
|
---|
3546 |
|
---|
3547 | const xml::ElementNode *pDriveChild;
|
---|
3548 | Utf8Str strTmp;
|
---|
3549 | if ( (pDriveChild = pelmHwChild->findChildElement("Image")) != NULL
|
---|
3550 | && pDriveChild->getAttributeValue("uuid", strTmp))
|
---|
3551 | parseUUID(att.uuid, strTmp);
|
---|
3552 | else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
|
---|
3553 | pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
|
---|
3554 |
|
---|
3555 | // find the IDE controller and attach the DVD drive
|
---|
3556 | bool fFound = false;
|
---|
3557 | for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
|
---|
3558 | it != strg.llStorageControllers.end();
|
---|
3559 | ++it)
|
---|
3560 | {
|
---|
3561 | StorageController &sctl = *it;
|
---|
3562 | if (sctl.storageBus == StorageBus_IDE)
|
---|
3563 | {
|
---|
3564 | sctl.llAttachedDevices.push_back(att);
|
---|
3565 | fFound = true;
|
---|
3566 | break;
|
---|
3567 | }
|
---|
3568 | }
|
---|
3569 |
|
---|
3570 | if (!fFound)
|
---|
3571 | throw ConfigFileError(this, pelmHwChild, N_("Internal error: found DVD drive but IDE controller does not exist"));
|
---|
3572 | // shouldn't happen because pre-1.9 settings files always had at least one IDE controller in the settings
|
---|
3573 | // which should have gotten parsed in <StorageControllers> before this got called
|
---|
3574 | }
|
---|
3575 | else if (pelmHwChild->nameEquals("FloppyDrive"))
|
---|
3576 | {
|
---|
3577 | bool fEnabled;
|
---|
3578 | if ( pelmHwChild->getAttributeValue("enabled", fEnabled)
|
---|
3579 | && fEnabled)
|
---|
3580 | {
|
---|
3581 | // create a new floppy controller and attach a floppy "attached device"
|
---|
3582 | StorageController sctl;
|
---|
3583 | sctl.strName = "Floppy Controller";
|
---|
3584 | sctl.storageBus = StorageBus_Floppy;
|
---|
3585 | sctl.controllerType = StorageControllerType_I82078;
|
---|
3586 | sctl.ulPortCount = 1;
|
---|
3587 |
|
---|
3588 | AttachedDevice att;
|
---|
3589 | att.deviceType = DeviceType_Floppy;
|
---|
3590 | att.lPort = 0;
|
---|
3591 | att.lDevice = 0;
|
---|
3592 |
|
---|
3593 | const xml::ElementNode *pDriveChild;
|
---|
3594 | Utf8Str strTmp;
|
---|
3595 | if ( (pDriveChild = pelmHwChild->findChildElement("Image"))
|
---|
3596 | && pDriveChild->getAttributeValue("uuid", strTmp) )
|
---|
3597 | parseUUID(att.uuid, strTmp);
|
---|
3598 | else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
|
---|
3599 | pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
|
---|
3600 |
|
---|
3601 | // store attachment with controller
|
---|
3602 | sctl.llAttachedDevices.push_back(att);
|
---|
3603 | // store controller with storage
|
---|
3604 | strg.llStorageControllers.push_back(sctl);
|
---|
3605 | }
|
---|
3606 | }
|
---|
3607 | }
|
---|
3608 | }
|
---|
3609 |
|
---|
3610 | /**
|
---|
3611 | * Called for reading the <Teleporter> element under <Machine>.
|
---|
3612 | */
|
---|
3613 | void MachineConfigFile::readTeleporter(const xml::ElementNode *pElmTeleporter,
|
---|
3614 | MachineUserData *pUserData)
|
---|
3615 | {
|
---|
3616 | pElmTeleporter->getAttributeValue("enabled", pUserData->fTeleporterEnabled);
|
---|
3617 | pElmTeleporter->getAttributeValue("port", pUserData->uTeleporterPort);
|
---|
3618 | pElmTeleporter->getAttributeValue("address", pUserData->strTeleporterAddress);
|
---|
3619 | pElmTeleporter->getAttributeValue("password", pUserData->strTeleporterPassword);
|
---|
3620 |
|
---|
3621 | if ( pUserData->strTeleporterPassword.isNotEmpty()
|
---|
3622 | && !VBoxIsPasswordHashed(&pUserData->strTeleporterPassword))
|
---|
3623 | VBoxHashPassword(&pUserData->strTeleporterPassword);
|
---|
3624 | }
|
---|
3625 |
|
---|
3626 | /**
|
---|
3627 | * Called for reading the <Debugging> element under <Machine> or <Snapshot>.
|
---|
3628 | */
|
---|
3629 | void MachineConfigFile::readDebugging(const xml::ElementNode *pElmDebugging, Debugging *pDbg)
|
---|
3630 | {
|
---|
3631 | if (!pElmDebugging || m->sv < SettingsVersion_v1_13)
|
---|
3632 | return;
|
---|
3633 |
|
---|
3634 | const xml::ElementNode * const pelmTracing = pElmDebugging->findChildElement("Tracing");
|
---|
3635 | if (pelmTracing)
|
---|
3636 | {
|
---|
3637 | pelmTracing->getAttributeValue("enabled", pDbg->fTracingEnabled);
|
---|
3638 | pelmTracing->getAttributeValue("allowTracingToAccessVM", pDbg->fAllowTracingToAccessVM);
|
---|
3639 | pelmTracing->getAttributeValue("config", pDbg->strTracingConfig);
|
---|
3640 | }
|
---|
3641 | }
|
---|
3642 |
|
---|
3643 | /**
|
---|
3644 | * Called for reading the <Autostart> element under <Machine> or <Snapshot>.
|
---|
3645 | */
|
---|
3646 | void MachineConfigFile::readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart)
|
---|
3647 | {
|
---|
3648 | Utf8Str strAutostop;
|
---|
3649 |
|
---|
3650 | if (!pElmAutostart || m->sv < SettingsVersion_v1_13)
|
---|
3651 | return;
|
---|
3652 |
|
---|
3653 | pElmAutostart->getAttributeValue("enabled", pAutostart->fAutostartEnabled);
|
---|
3654 | pElmAutostart->getAttributeValue("delay", pAutostart->uAutostartDelay);
|
---|
3655 | pElmAutostart->getAttributeValue("autostop", strAutostop);
|
---|
3656 | if (strAutostop == "Disabled")
|
---|
3657 | pAutostart->enmAutostopType = AutostopType_Disabled;
|
---|
3658 | else if (strAutostop == "SaveState")
|
---|
3659 | pAutostart->enmAutostopType = AutostopType_SaveState;
|
---|
3660 | else if (strAutostop == "PowerOff")
|
---|
3661 | pAutostart->enmAutostopType = AutostopType_PowerOff;
|
---|
3662 | else if (strAutostop == "AcpiShutdown")
|
---|
3663 | pAutostart->enmAutostopType = AutostopType_AcpiShutdown;
|
---|
3664 | else
|
---|
3665 | throw ConfigFileError(this, pElmAutostart, N_("Invalid value '%s' for Autostart/@autostop attribute"), strAutostop.c_str());
|
---|
3666 | }
|
---|
3667 |
|
---|
3668 | /**
|
---|
3669 | * Called for reading the <Groups> element under <Machine>.
|
---|
3670 | */
|
---|
3671 | void MachineConfigFile::readGroups(const xml::ElementNode *pElmGroups, StringsList *pllGroups)
|
---|
3672 | {
|
---|
3673 | pllGroups->clear();
|
---|
3674 | if (!pElmGroups || m->sv < SettingsVersion_v1_13)
|
---|
3675 | {
|
---|
3676 | pllGroups->push_back("/");
|
---|
3677 | return;
|
---|
3678 | }
|
---|
3679 |
|
---|
3680 | xml::NodesLoop nlGroups(*pElmGroups);
|
---|
3681 | const xml::ElementNode *pelmGroup;
|
---|
3682 | while ((pelmGroup = nlGroups.forAllNodes()))
|
---|
3683 | {
|
---|
3684 | if (pelmGroup->nameEquals("Group"))
|
---|
3685 | {
|
---|
3686 | Utf8Str strGroup;
|
---|
3687 | if (!pelmGroup->getAttributeValue("name", strGroup))
|
---|
3688 | throw ConfigFileError(this, pelmGroup, N_("Required Group/@name attribute is missing"));
|
---|
3689 | pllGroups->push_back(strGroup);
|
---|
3690 | }
|
---|
3691 | }
|
---|
3692 | }
|
---|
3693 |
|
---|
3694 | /**
|
---|
3695 | * Called initially for the <Snapshot> element under <Machine>, if present,
|
---|
3696 | * to store the snapshot's data into the given Snapshot structure (which is
|
---|
3697 | * then the one in the Machine struct). This might then recurse if
|
---|
3698 | * a <Snapshots> (plural) element is found in the snapshot, which should
|
---|
3699 | * contain a list of child snapshots; such lists are maintained in the
|
---|
3700 | * Snapshot structure.
|
---|
3701 | *
|
---|
3702 | * @param curSnapshotUuid
|
---|
3703 | * @param depth
|
---|
3704 | * @param elmSnapshot
|
---|
3705 | * @param snap
|
---|
3706 | * @returns true if curSnapshotUuid is in this snapshot subtree, otherwise false
|
---|
3707 | */
|
---|
3708 | bool MachineConfigFile::readSnapshot(const Guid &curSnapshotUuid,
|
---|
3709 | uint32_t depth,
|
---|
3710 | const xml::ElementNode &elmSnapshot,
|
---|
3711 | Snapshot &snap)
|
---|
3712 | {
|
---|
3713 | if (depth > SETTINGS_SNAPSHOT_DEPTH_MAX)
|
---|
3714 | throw ConfigFileError(this, &elmSnapshot, N_("Maximum snapshot tree depth of %u exceeded"), depth);
|
---|
3715 |
|
---|
3716 | Utf8Str strTemp;
|
---|
3717 |
|
---|
3718 | if (!elmSnapshot.getAttributeValue("uuid", strTemp))
|
---|
3719 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@uuid attribute is missing"));
|
---|
3720 | parseUUID(snap.uuid, strTemp);
|
---|
3721 | bool foundCurrentSnapshot = (snap.uuid == curSnapshotUuid);
|
---|
3722 |
|
---|
3723 | if (!elmSnapshot.getAttributeValue("name", snap.strName))
|
---|
3724 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@name attribute is missing"));
|
---|
3725 |
|
---|
3726 | // earlier 3.1 trunk builds had a bug and added Description as an attribute, read it silently and write it back as an element
|
---|
3727 | elmSnapshot.getAttributeValue("Description", snap.strDescription);
|
---|
3728 |
|
---|
3729 | if (!elmSnapshot.getAttributeValue("timeStamp", strTemp))
|
---|
3730 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@timeStamp attribute is missing"));
|
---|
3731 | parseTimestamp(snap.timestamp, strTemp);
|
---|
3732 |
|
---|
3733 | elmSnapshot.getAttributeValuePath("stateFile", snap.strStateFile); // online snapshots only
|
---|
3734 |
|
---|
3735 | // parse Hardware before the other elements because other things depend on it
|
---|
3736 | const xml::ElementNode *pelmHardware;
|
---|
3737 | if (!(pelmHardware = elmSnapshot.findChildElement("Hardware")))
|
---|
3738 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@Hardware element is missing"));
|
---|
3739 | readHardware(*pelmHardware, snap.hardware, snap.storage);
|
---|
3740 |
|
---|
3741 | xml::NodesLoop nlSnapshotChildren(elmSnapshot);
|
---|
3742 | const xml::ElementNode *pelmSnapshotChild;
|
---|
3743 | while ((pelmSnapshotChild = nlSnapshotChildren.forAllNodes()))
|
---|
3744 | {
|
---|
3745 | if (pelmSnapshotChild->nameEquals("Description"))
|
---|
3746 | snap.strDescription = pelmSnapshotChild->getValue();
|
---|
3747 | else if ( m->sv < SettingsVersion_v1_7
|
---|
3748 | && pelmSnapshotChild->nameEquals("HardDiskAttachments"))
|
---|
3749 | readHardDiskAttachments_pre1_7(*pelmSnapshotChild, snap.storage);
|
---|
3750 | else if ( m->sv >= SettingsVersion_v1_7
|
---|
3751 | && pelmSnapshotChild->nameEquals("StorageControllers"))
|
---|
3752 | readStorageControllers(*pelmSnapshotChild, snap.storage);
|
---|
3753 | else if (pelmSnapshotChild->nameEquals("Snapshots"))
|
---|
3754 | {
|
---|
3755 | xml::NodesLoop nlChildSnapshots(*pelmSnapshotChild);
|
---|
3756 | const xml::ElementNode *pelmChildSnapshot;
|
---|
3757 | while ((pelmChildSnapshot = nlChildSnapshots.forAllNodes()))
|
---|
3758 | {
|
---|
3759 | if (pelmChildSnapshot->nameEquals("Snapshot"))
|
---|
3760 | {
|
---|
3761 | // Use the heap to reduce the stack footprint. Each
|
---|
3762 | // recursion needs over 1K, and there can be VMs with
|
---|
3763 | // deeply nested snapshots. The stack can be quite
|
---|
3764 | // small, especially with XPCOM.
|
---|
3765 | Snapshot *child = new Snapshot();
|
---|
3766 | bool found = readSnapshot(curSnapshotUuid, depth + 1, *pelmChildSnapshot, *child);
|
---|
3767 | foundCurrentSnapshot = foundCurrentSnapshot || found;
|
---|
3768 | snap.llChildSnapshots.push_back(*child);
|
---|
3769 | delete child;
|
---|
3770 | }
|
---|
3771 | }
|
---|
3772 | }
|
---|
3773 | }
|
---|
3774 |
|
---|
3775 | if (m->sv < SettingsVersion_v1_9)
|
---|
3776 | // go through Hardware once more to repair the settings controller structures
|
---|
3777 | // with data from old DVDDrive and FloppyDrive elements
|
---|
3778 | readDVDAndFloppies_pre1_9(*pelmHardware, snap.storage);
|
---|
3779 |
|
---|
3780 | readDebugging(elmSnapshot.findChildElement("Debugging"), &snap.debugging);
|
---|
3781 | readAutostart(elmSnapshot.findChildElement("Autostart"), &snap.autostart);
|
---|
3782 | // note: Groups exist only for Machine, not for Snapshot
|
---|
3783 |
|
---|
3784 | return foundCurrentSnapshot;
|
---|
3785 | }
|
---|
3786 |
|
---|
3787 | const struct {
|
---|
3788 | const char *pcszOld;
|
---|
3789 | const char *pcszNew;
|
---|
3790 | } aConvertOSTypes[] =
|
---|
3791 | {
|
---|
3792 | { "unknown", "Other" },
|
---|
3793 | { "dos", "DOS" },
|
---|
3794 | { "win31", "Windows31" },
|
---|
3795 | { "win95", "Windows95" },
|
---|
3796 | { "win98", "Windows98" },
|
---|
3797 | { "winme", "WindowsMe" },
|
---|
3798 | { "winnt4", "WindowsNT4" },
|
---|
3799 | { "win2k", "Windows2000" },
|
---|
3800 | { "winxp", "WindowsXP" },
|
---|
3801 | { "win2k3", "Windows2003" },
|
---|
3802 | { "winvista", "WindowsVista" },
|
---|
3803 | { "win2k8", "Windows2008" },
|
---|
3804 | { "os2warp3", "OS2Warp3" },
|
---|
3805 | { "os2warp4", "OS2Warp4" },
|
---|
3806 | { "os2warp45", "OS2Warp45" },
|
---|
3807 | { "ecs", "OS2eCS" },
|
---|
3808 | { "linux22", "Linux22" },
|
---|
3809 | { "linux24", "Linux24" },
|
---|
3810 | { "linux26", "Linux26" },
|
---|
3811 | { "archlinux", "ArchLinux" },
|
---|
3812 | { "debian", "Debian" },
|
---|
3813 | { "opensuse", "OpenSUSE" },
|
---|
3814 | { "fedoracore", "Fedora" },
|
---|
3815 | { "gentoo", "Gentoo" },
|
---|
3816 | { "mandriva", "Mandriva" },
|
---|
3817 | { "redhat", "RedHat" },
|
---|
3818 | { "ubuntu", "Ubuntu" },
|
---|
3819 | { "xandros", "Xandros" },
|
---|
3820 | { "freebsd", "FreeBSD" },
|
---|
3821 | { "openbsd", "OpenBSD" },
|
---|
3822 | { "netbsd", "NetBSD" },
|
---|
3823 | { "netware", "Netware" },
|
---|
3824 | { "solaris", "Solaris" },
|
---|
3825 | { "opensolaris", "OpenSolaris" },
|
---|
3826 | { "l4", "L4" }
|
---|
3827 | };
|
---|
3828 |
|
---|
3829 | void MachineConfigFile::convertOldOSType_pre1_5(Utf8Str &str)
|
---|
3830 | {
|
---|
3831 | for (unsigned u = 0;
|
---|
3832 | u < RT_ELEMENTS(aConvertOSTypes);
|
---|
3833 | ++u)
|
---|
3834 | {
|
---|
3835 | if (str == aConvertOSTypes[u].pcszOld)
|
---|
3836 | {
|
---|
3837 | str = aConvertOSTypes[u].pcszNew;
|
---|
3838 | break;
|
---|
3839 | }
|
---|
3840 | }
|
---|
3841 | }
|
---|
3842 |
|
---|
3843 | /**
|
---|
3844 | * Called from the constructor to actually read in the <Machine> element
|
---|
3845 | * of a machine config file.
|
---|
3846 | * @param elmMachine
|
---|
3847 | */
|
---|
3848 | void MachineConfigFile::readMachine(const xml::ElementNode &elmMachine)
|
---|
3849 | {
|
---|
3850 | Utf8Str strUUID;
|
---|
3851 | if ( elmMachine.getAttributeValue("uuid", strUUID)
|
---|
3852 | && elmMachine.getAttributeValue("name", machineUserData.strName))
|
---|
3853 | {
|
---|
3854 | parseUUID(uuid, strUUID);
|
---|
3855 |
|
---|
3856 | elmMachine.getAttributeValue("directoryIncludesUUID", machineUserData.fDirectoryIncludesUUID);
|
---|
3857 | elmMachine.getAttributeValue("nameSync", machineUserData.fNameSync);
|
---|
3858 |
|
---|
3859 | Utf8Str str;
|
---|
3860 | elmMachine.getAttributeValue("Description", machineUserData.strDescription);
|
---|
3861 | elmMachine.getAttributeValue("OSType", machineUserData.strOsType);
|
---|
3862 | if (m->sv < SettingsVersion_v1_5)
|
---|
3863 | convertOldOSType_pre1_5(machineUserData.strOsType);
|
---|
3864 |
|
---|
3865 | elmMachine.getAttributeValuePath("stateFile", strStateFile);
|
---|
3866 |
|
---|
3867 | if (elmMachine.getAttributeValue("currentSnapshot", str))
|
---|
3868 | parseUUID(uuidCurrentSnapshot, str);
|
---|
3869 |
|
---|
3870 | elmMachine.getAttributeValuePath("snapshotFolder", machineUserData.strSnapshotFolder);
|
---|
3871 |
|
---|
3872 | if (!elmMachine.getAttributeValue("currentStateModified", fCurrentStateModified))
|
---|
3873 | fCurrentStateModified = true;
|
---|
3874 | if (elmMachine.getAttributeValue("lastStateChange", str))
|
---|
3875 | parseTimestamp(timeLastStateChange, str);
|
---|
3876 | // constructor has called RTTimeNow(&timeLastStateChange) before
|
---|
3877 | if (elmMachine.getAttributeValue("aborted", fAborted))
|
---|
3878 | fAborted = true;
|
---|
3879 |
|
---|
3880 | elmMachine.getAttributeValue("icon", machineUserData.ovIcon);
|
---|
3881 |
|
---|
3882 | // parse Hardware before the other elements because other things depend on it
|
---|
3883 | const xml::ElementNode *pelmHardware;
|
---|
3884 | if (!(pelmHardware = elmMachine.findChildElement("Hardware")))
|
---|
3885 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/Hardware element is missing"));
|
---|
3886 | readHardware(*pelmHardware, hardwareMachine, storageMachine);
|
---|
3887 |
|
---|
3888 | xml::NodesLoop nlRootChildren(elmMachine);
|
---|
3889 | const xml::ElementNode *pelmMachineChild;
|
---|
3890 | while ((pelmMachineChild = nlRootChildren.forAllNodes()))
|
---|
3891 | {
|
---|
3892 | if (pelmMachineChild->nameEquals("ExtraData"))
|
---|
3893 | readExtraData(*pelmMachineChild,
|
---|
3894 | mapExtraDataItems);
|
---|
3895 | else if ( (m->sv < SettingsVersion_v1_7)
|
---|
3896 | && (pelmMachineChild->nameEquals("HardDiskAttachments"))
|
---|
3897 | )
|
---|
3898 | readHardDiskAttachments_pre1_7(*pelmMachineChild, storageMachine);
|
---|
3899 | else if ( (m->sv >= SettingsVersion_v1_7)
|
---|
3900 | && (pelmMachineChild->nameEquals("StorageControllers"))
|
---|
3901 | )
|
---|
3902 | readStorageControllers(*pelmMachineChild, storageMachine);
|
---|
3903 | else if (pelmMachineChild->nameEquals("Snapshot"))
|
---|
3904 | {
|
---|
3905 | if (uuidCurrentSnapshot.isZero())
|
---|
3906 | throw ConfigFileError(this, &elmMachine, N_("Snapshots present but required Machine/@currentSnapshot attribute is missing"));
|
---|
3907 | bool foundCurrentSnapshot = false;
|
---|
3908 | Snapshot snap;
|
---|
3909 | // this will recurse into child snapshots, if necessary
|
---|
3910 | foundCurrentSnapshot = readSnapshot(uuidCurrentSnapshot, 1, *pelmMachineChild, snap);
|
---|
3911 | if (!foundCurrentSnapshot)
|
---|
3912 | throw ConfigFileError(this, &elmMachine, N_("Snapshots present but none matches the UUID in the Machine/@currentSnapshot attribute"));
|
---|
3913 | llFirstSnapshot.push_back(snap);
|
---|
3914 | }
|
---|
3915 | else if (pelmMachineChild->nameEquals("Description"))
|
---|
3916 | machineUserData.strDescription = pelmMachineChild->getValue();
|
---|
3917 | else if (pelmMachineChild->nameEquals("Teleporter"))
|
---|
3918 | readTeleporter(pelmMachineChild, &machineUserData);
|
---|
3919 | else if (pelmMachineChild->nameEquals("FaultTolerance"))
|
---|
3920 | {
|
---|
3921 | Utf8Str strFaultToleranceSate;
|
---|
3922 | if (pelmMachineChild->getAttributeValue("state", strFaultToleranceSate))
|
---|
3923 | {
|
---|
3924 | if (strFaultToleranceSate == "master")
|
---|
3925 | machineUserData.enmFaultToleranceState = FaultToleranceState_Master;
|
---|
3926 | else
|
---|
3927 | if (strFaultToleranceSate == "standby")
|
---|
3928 | machineUserData.enmFaultToleranceState = FaultToleranceState_Standby;
|
---|
3929 | else
|
---|
3930 | machineUserData.enmFaultToleranceState = FaultToleranceState_Inactive;
|
---|
3931 | }
|
---|
3932 | pelmMachineChild->getAttributeValue("port", machineUserData.uFaultTolerancePort);
|
---|
3933 | pelmMachineChild->getAttributeValue("address", machineUserData.strFaultToleranceAddress);
|
---|
3934 | pelmMachineChild->getAttributeValue("interval", machineUserData.uFaultToleranceInterval);
|
---|
3935 | pelmMachineChild->getAttributeValue("password", machineUserData.strFaultTolerancePassword);
|
---|
3936 | }
|
---|
3937 | else if (pelmMachineChild->nameEquals("MediaRegistry"))
|
---|
3938 | readMediaRegistry(*pelmMachineChild, mediaRegistry);
|
---|
3939 | else if (pelmMachineChild->nameEquals("Debugging"))
|
---|
3940 | readDebugging(pelmMachineChild, &debugging);
|
---|
3941 | else if (pelmMachineChild->nameEquals("Autostart"))
|
---|
3942 | readAutostart(pelmMachineChild, &autostart);
|
---|
3943 | else if (pelmMachineChild->nameEquals("Groups"))
|
---|
3944 | readGroups(pelmMachineChild, &machineUserData.llGroups);
|
---|
3945 | }
|
---|
3946 |
|
---|
3947 | if (m->sv < SettingsVersion_v1_9)
|
---|
3948 | // go through Hardware once more to repair the settings controller structures
|
---|
3949 | // with data from old DVDDrive and FloppyDrive elements
|
---|
3950 | readDVDAndFloppies_pre1_9(*pelmHardware, storageMachine);
|
---|
3951 | }
|
---|
3952 | else
|
---|
3953 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/@uuid or @name attributes is missing"));
|
---|
3954 | }
|
---|
3955 |
|
---|
3956 | /**
|
---|
3957 | * Creates a <Hardware> node under elmParent and then writes out the XML
|
---|
3958 | * keys under that. Called for both the <Machine> node and for snapshots.
|
---|
3959 | * @param elmParent
|
---|
3960 | * @param st
|
---|
3961 | */
|
---|
3962 | void MachineConfigFile::buildHardwareXML(xml::ElementNode &elmParent,
|
---|
3963 | const Hardware &hw,
|
---|
3964 | const Storage &strg)
|
---|
3965 | {
|
---|
3966 | xml::ElementNode *pelmHardware = elmParent.createChild("Hardware");
|
---|
3967 |
|
---|
3968 | if (m->sv >= SettingsVersion_v1_4)
|
---|
3969 | pelmHardware->setAttribute("version", hw.strVersion);
|
---|
3970 |
|
---|
3971 | if ((m->sv >= SettingsVersion_v1_9)
|
---|
3972 | && !hw.uuid.isZero()
|
---|
3973 | && hw.uuid.isValid()
|
---|
3974 | )
|
---|
3975 | pelmHardware->setAttribute("uuid", hw.uuid.toStringCurly());
|
---|
3976 |
|
---|
3977 | xml::ElementNode *pelmCPU = pelmHardware->createChild("CPU");
|
---|
3978 |
|
---|
3979 | xml::ElementNode *pelmHwVirtEx = pelmCPU->createChild("HardwareVirtEx");
|
---|
3980 | pelmHwVirtEx->setAttribute("enabled", hw.fHardwareVirt);
|
---|
3981 |
|
---|
3982 | pelmCPU->createChild("HardwareVirtExNestedPaging")->setAttribute("enabled", hw.fNestedPaging);
|
---|
3983 | pelmCPU->createChild("HardwareVirtExVPID")->setAttribute("enabled", hw.fVPID);
|
---|
3984 | pelmCPU->createChild("HardwareVirtExUX")->setAttribute("enabled", hw.fUnrestrictedExecution);
|
---|
3985 | pelmCPU->createChild("PAE")->setAttribute("enabled", hw.fPAE);
|
---|
3986 | if (m->sv >= SettingsVersion_v1_14 && hw.enmLongMode != Hardware::LongMode_Legacy)
|
---|
3987 | pelmCPU->createChild("LongMode")->setAttribute("enabled", hw.enmLongMode == Hardware::LongMode_Enabled);
|
---|
3988 |
|
---|
3989 | if (hw.fSyntheticCpu)
|
---|
3990 | pelmCPU->createChild("SyntheticCpu")->setAttribute("enabled", hw.fSyntheticCpu);
|
---|
3991 | if (hw.fTripleFaultReset)
|
---|
3992 | pelmCPU->createChild("TripleFaultReset")->setAttribute("enabled", hw.fTripleFaultReset);
|
---|
3993 | pelmCPU->setAttribute("count", hw.cCPUs);
|
---|
3994 | if (hw.ulCpuExecutionCap != 100)
|
---|
3995 | pelmCPU->setAttribute("executionCap", hw.ulCpuExecutionCap);
|
---|
3996 |
|
---|
3997 | /* Always save this setting as we have changed the default in 4.0 (on for large memory 64-bit systems). */
|
---|
3998 | pelmCPU->createChild("HardwareVirtExLargePages")->setAttribute("enabled", hw.fLargePages);
|
---|
3999 |
|
---|
4000 | if (m->sv >= SettingsVersion_v1_9)
|
---|
4001 | pelmCPU->createChild("HardwareVirtForce")->setAttribute("enabled", hw.fHardwareVirtForce);
|
---|
4002 |
|
---|
4003 | if (m->sv >= SettingsVersion_v1_10)
|
---|
4004 | {
|
---|
4005 | pelmCPU->setAttribute("hotplug", hw.fCpuHotPlug);
|
---|
4006 |
|
---|
4007 | xml::ElementNode *pelmCpuTree = NULL;
|
---|
4008 | for (CpuList::const_iterator it = hw.llCpus.begin();
|
---|
4009 | it != hw.llCpus.end();
|
---|
4010 | ++it)
|
---|
4011 | {
|
---|
4012 | const Cpu &cpu = *it;
|
---|
4013 |
|
---|
4014 | if (pelmCpuTree == NULL)
|
---|
4015 | pelmCpuTree = pelmCPU->createChild("CpuTree");
|
---|
4016 |
|
---|
4017 | xml::ElementNode *pelmCpu = pelmCpuTree->createChild("Cpu");
|
---|
4018 | pelmCpu->setAttribute("id", cpu.ulId);
|
---|
4019 | }
|
---|
4020 | }
|
---|
4021 |
|
---|
4022 | xml::ElementNode *pelmCpuIdTree = NULL;
|
---|
4023 | for (CpuIdLeafsList::const_iterator it = hw.llCpuIdLeafs.begin();
|
---|
4024 | it != hw.llCpuIdLeafs.end();
|
---|
4025 | ++it)
|
---|
4026 | {
|
---|
4027 | const CpuIdLeaf &leaf = *it;
|
---|
4028 |
|
---|
4029 | if (pelmCpuIdTree == NULL)
|
---|
4030 | pelmCpuIdTree = pelmCPU->createChild("CpuIdTree");
|
---|
4031 |
|
---|
4032 | xml::ElementNode *pelmCpuIdLeaf = pelmCpuIdTree->createChild("CpuIdLeaf");
|
---|
4033 | pelmCpuIdLeaf->setAttribute("id", leaf.ulId);
|
---|
4034 | pelmCpuIdLeaf->setAttribute("eax", leaf.ulEax);
|
---|
4035 | pelmCpuIdLeaf->setAttribute("ebx", leaf.ulEbx);
|
---|
4036 | pelmCpuIdLeaf->setAttribute("ecx", leaf.ulEcx);
|
---|
4037 | pelmCpuIdLeaf->setAttribute("edx", leaf.ulEdx);
|
---|
4038 | }
|
---|
4039 |
|
---|
4040 | xml::ElementNode *pelmMemory = pelmHardware->createChild("Memory");
|
---|
4041 | pelmMemory->setAttribute("RAMSize", hw.ulMemorySizeMB);
|
---|
4042 | if (m->sv >= SettingsVersion_v1_10)
|
---|
4043 | {
|
---|
4044 | pelmMemory->setAttribute("PageFusion", hw.fPageFusionEnabled);
|
---|
4045 | }
|
---|
4046 |
|
---|
4047 | if ( (m->sv >= SettingsVersion_v1_9)
|
---|
4048 | && (hw.firmwareType >= FirmwareType_EFI)
|
---|
4049 | )
|
---|
4050 | {
|
---|
4051 | xml::ElementNode *pelmFirmware = pelmHardware->createChild("Firmware");
|
---|
4052 | const char *pcszFirmware;
|
---|
4053 |
|
---|
4054 | switch (hw.firmwareType)
|
---|
4055 | {
|
---|
4056 | case FirmwareType_EFI: pcszFirmware = "EFI"; break;
|
---|
4057 | case FirmwareType_EFI32: pcszFirmware = "EFI32"; break;
|
---|
4058 | case FirmwareType_EFI64: pcszFirmware = "EFI64"; break;
|
---|
4059 | case FirmwareType_EFIDUAL: pcszFirmware = "EFIDUAL"; break;
|
---|
4060 | default: pcszFirmware = "None"; break;
|
---|
4061 | }
|
---|
4062 | pelmFirmware->setAttribute("type", pcszFirmware);
|
---|
4063 | }
|
---|
4064 |
|
---|
4065 | if ( (m->sv >= SettingsVersion_v1_10)
|
---|
4066 | )
|
---|
4067 | {
|
---|
4068 | xml::ElementNode *pelmHID = pelmHardware->createChild("HID");
|
---|
4069 | const char *pcszHID;
|
---|
4070 |
|
---|
4071 | switch (hw.pointingHIDType)
|
---|
4072 | {
|
---|
4073 | case PointingHIDType_USBMouse: pcszHID = "USBMouse"; break;
|
---|
4074 | case PointingHIDType_USBTablet: pcszHID = "USBTablet"; break;
|
---|
4075 | case PointingHIDType_PS2Mouse: pcszHID = "PS2Mouse"; break;
|
---|
4076 | case PointingHIDType_ComboMouse: pcszHID = "ComboMouse"; break;
|
---|
4077 | case PointingHIDType_USBMultiTouch: pcszHID = "USBMultiTouch";break;
|
---|
4078 | case PointingHIDType_None: pcszHID = "None"; break;
|
---|
4079 | default: Assert(false); pcszHID = "PS2Mouse"; break;
|
---|
4080 | }
|
---|
4081 | pelmHID->setAttribute("Pointing", pcszHID);
|
---|
4082 |
|
---|
4083 | switch (hw.keyboardHIDType)
|
---|
4084 | {
|
---|
4085 | case KeyboardHIDType_USBKeyboard: pcszHID = "USBKeyboard"; break;
|
---|
4086 | case KeyboardHIDType_PS2Keyboard: pcszHID = "PS2Keyboard"; break;
|
---|
4087 | case KeyboardHIDType_ComboKeyboard: pcszHID = "ComboKeyboard"; break;
|
---|
4088 | case KeyboardHIDType_None: pcszHID = "None"; break;
|
---|
4089 | default: Assert(false); pcszHID = "PS2Keyboard"; break;
|
---|
4090 | }
|
---|
4091 | pelmHID->setAttribute("Keyboard", pcszHID);
|
---|
4092 | }
|
---|
4093 |
|
---|
4094 | if ( (m->sv >= SettingsVersion_v1_10)
|
---|
4095 | )
|
---|
4096 | {
|
---|
4097 | xml::ElementNode *pelmHPET = pelmHardware->createChild("HPET");
|
---|
4098 | pelmHPET->setAttribute("enabled", hw.fHPETEnabled);
|
---|
4099 | }
|
---|
4100 |
|
---|
4101 | if ( (m->sv >= SettingsVersion_v1_11)
|
---|
4102 | )
|
---|
4103 | {
|
---|
4104 | xml::ElementNode *pelmChipset = pelmHardware->createChild("Chipset");
|
---|
4105 | const char *pcszChipset;
|
---|
4106 |
|
---|
4107 | switch (hw.chipsetType)
|
---|
4108 | {
|
---|
4109 | case ChipsetType_PIIX3: pcszChipset = "PIIX3"; break;
|
---|
4110 | case ChipsetType_ICH9: pcszChipset = "ICH9"; break;
|
---|
4111 | default: Assert(false); pcszChipset = "PIIX3"; break;
|
---|
4112 | }
|
---|
4113 | pelmChipset->setAttribute("type", pcszChipset);
|
---|
4114 | }
|
---|
4115 |
|
---|
4116 | xml::ElementNode *pelmBoot = pelmHardware->createChild("Boot");
|
---|
4117 | for (BootOrderMap::const_iterator it = hw.mapBootOrder.begin();
|
---|
4118 | it != hw.mapBootOrder.end();
|
---|
4119 | ++it)
|
---|
4120 | {
|
---|
4121 | uint32_t i = it->first;
|
---|
4122 | DeviceType_T type = it->second;
|
---|
4123 | const char *pcszDevice;
|
---|
4124 |
|
---|
4125 | switch (type)
|
---|
4126 | {
|
---|
4127 | case DeviceType_Floppy: pcszDevice = "Floppy"; break;
|
---|
4128 | case DeviceType_DVD: pcszDevice = "DVD"; break;
|
---|
4129 | case DeviceType_HardDisk: pcszDevice = "HardDisk"; break;
|
---|
4130 | case DeviceType_Network: pcszDevice = "Network"; break;
|
---|
4131 | default: /*case DeviceType_Null:*/ pcszDevice = "None"; break;
|
---|
4132 | }
|
---|
4133 |
|
---|
4134 | xml::ElementNode *pelmOrder = pelmBoot->createChild("Order");
|
---|
4135 | pelmOrder->setAttribute("position",
|
---|
4136 | i + 1); // XML is 1-based but internal data is 0-based
|
---|
4137 | pelmOrder->setAttribute("device", pcszDevice);
|
---|
4138 | }
|
---|
4139 |
|
---|
4140 | xml::ElementNode *pelmDisplay = pelmHardware->createChild("Display");
|
---|
4141 | if (hw.graphicsControllerType != GraphicsControllerType_VBoxVGA)
|
---|
4142 | {
|
---|
4143 | const char *pcszGraphics;
|
---|
4144 | switch (hw.graphicsControllerType)
|
---|
4145 | {
|
---|
4146 | case GraphicsControllerType_VBoxVGA: pcszGraphics = "VBoxVGA"; break;
|
---|
4147 | case GraphicsControllerType_VMSVGA: pcszGraphics = "VMSVGA"; break;
|
---|
4148 | default: /*case GraphicsControllerType_Null:*/ pcszGraphics = "None"; break;
|
---|
4149 | }
|
---|
4150 | pelmDisplay->setAttribute("controller", pcszGraphics);
|
---|
4151 | }
|
---|
4152 | pelmDisplay->setAttribute("VRAMSize", hw.ulVRAMSizeMB);
|
---|
4153 | pelmDisplay->setAttribute("monitorCount", hw.cMonitors);
|
---|
4154 | pelmDisplay->setAttribute("accelerate3D", hw.fAccelerate3D);
|
---|
4155 |
|
---|
4156 | if (m->sv >= SettingsVersion_v1_8)
|
---|
4157 | pelmDisplay->setAttribute("accelerate2DVideo", hw.fAccelerate2DVideo);
|
---|
4158 | xml::ElementNode *pelmVideoCapture = pelmHardware->createChild("VideoCapture");
|
---|
4159 |
|
---|
4160 | if (m->sv >= SettingsVersion_v1_14)
|
---|
4161 | {
|
---|
4162 | pelmVideoCapture->setAttribute("enabled", hw.fVideoCaptureEnabled);
|
---|
4163 | pelmVideoCapture->setAttribute("screens", hw.u64VideoCaptureScreens);
|
---|
4164 | if (!hw.strVideoCaptureFile.isEmpty())
|
---|
4165 | pelmVideoCapture->setAttributePath("file", hw.strVideoCaptureFile);
|
---|
4166 | pelmVideoCapture->setAttribute("horzRes", hw.ulVideoCaptureHorzRes);
|
---|
4167 | pelmVideoCapture->setAttribute("vertRes", hw.ulVideoCaptureVertRes);
|
---|
4168 | pelmVideoCapture->setAttribute("rate", hw.ulVideoCaptureRate);
|
---|
4169 | pelmVideoCapture->setAttribute("fps", hw.ulVideoCaptureFPS);
|
---|
4170 | }
|
---|
4171 |
|
---|
4172 | xml::ElementNode *pelmVRDE = pelmHardware->createChild("RemoteDisplay");
|
---|
4173 | pelmVRDE->setAttribute("enabled", hw.vrdeSettings.fEnabled);
|
---|
4174 | if (m->sv < SettingsVersion_v1_11)
|
---|
4175 | {
|
---|
4176 | /* In VBox 4.0 these attributes are replaced with "Properties". */
|
---|
4177 | Utf8Str strPort;
|
---|
4178 | StringsMap::const_iterator it = hw.vrdeSettings.mapProperties.find("TCP/Ports");
|
---|
4179 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
4180 | strPort = it->second;
|
---|
4181 | if (!strPort.length())
|
---|
4182 | strPort = "3389";
|
---|
4183 | pelmVRDE->setAttribute("port", strPort);
|
---|
4184 |
|
---|
4185 | Utf8Str strAddress;
|
---|
4186 | it = hw.vrdeSettings.mapProperties.find("TCP/Address");
|
---|
4187 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
4188 | strAddress = it->second;
|
---|
4189 | if (strAddress.length())
|
---|
4190 | pelmVRDE->setAttribute("netAddress", strAddress);
|
---|
4191 | }
|
---|
4192 | const char *pcszAuthType;
|
---|
4193 | switch (hw.vrdeSettings.authType)
|
---|
4194 | {
|
---|
4195 | case AuthType_Guest: pcszAuthType = "Guest"; break;
|
---|
4196 | case AuthType_External: pcszAuthType = "External"; break;
|
---|
4197 | default: /*case AuthType_Null:*/ pcszAuthType = "Null"; break;
|
---|
4198 | }
|
---|
4199 | pelmVRDE->setAttribute("authType", pcszAuthType);
|
---|
4200 |
|
---|
4201 | if (hw.vrdeSettings.ulAuthTimeout != 0)
|
---|
4202 | pelmVRDE->setAttribute("authTimeout", hw.vrdeSettings.ulAuthTimeout);
|
---|
4203 | if (hw.vrdeSettings.fAllowMultiConnection)
|
---|
4204 | pelmVRDE->setAttribute("allowMultiConnection", hw.vrdeSettings.fAllowMultiConnection);
|
---|
4205 | if (hw.vrdeSettings.fReuseSingleConnection)
|
---|
4206 | pelmVRDE->setAttribute("reuseSingleConnection", hw.vrdeSettings.fReuseSingleConnection);
|
---|
4207 |
|
---|
4208 | if (m->sv == SettingsVersion_v1_10)
|
---|
4209 | {
|
---|
4210 | xml::ElementNode *pelmVideoChannel = pelmVRDE->createChild("VideoChannel");
|
---|
4211 |
|
---|
4212 | /* In 4.0 videochannel settings were replaced with properties, so look at properties. */
|
---|
4213 | Utf8Str str;
|
---|
4214 | StringsMap::const_iterator it = hw.vrdeSettings.mapProperties.find("VideoChannel/Enabled");
|
---|
4215 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
4216 | str = it->second;
|
---|
4217 | bool fVideoChannel = RTStrICmp(str.c_str(), "true") == 0
|
---|
4218 | || RTStrCmp(str.c_str(), "1") == 0;
|
---|
4219 | pelmVideoChannel->setAttribute("enabled", fVideoChannel);
|
---|
4220 |
|
---|
4221 | it = hw.vrdeSettings.mapProperties.find("VideoChannel/Quality");
|
---|
4222 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
4223 | str = it->second;
|
---|
4224 | uint32_t ulVideoChannelQuality = RTStrToUInt32(str.c_str()); /* This returns 0 on invalid string which is ok. */
|
---|
4225 | if (ulVideoChannelQuality == 0)
|
---|
4226 | ulVideoChannelQuality = 75;
|
---|
4227 | else
|
---|
4228 | ulVideoChannelQuality = RT_CLAMP(ulVideoChannelQuality, 10, 100);
|
---|
4229 | pelmVideoChannel->setAttribute("quality", ulVideoChannelQuality);
|
---|
4230 | }
|
---|
4231 | if (m->sv >= SettingsVersion_v1_11)
|
---|
4232 | {
|
---|
4233 | if (hw.vrdeSettings.strAuthLibrary.length())
|
---|
4234 | pelmVRDE->setAttribute("authLibrary", hw.vrdeSettings.strAuthLibrary);
|
---|
4235 | if (hw.vrdeSettings.strVrdeExtPack.isNotEmpty())
|
---|
4236 | pelmVRDE->setAttribute("VRDEExtPack", hw.vrdeSettings.strVrdeExtPack);
|
---|
4237 | if (hw.vrdeSettings.mapProperties.size() > 0)
|
---|
4238 | {
|
---|
4239 | xml::ElementNode *pelmProperties = pelmVRDE->createChild("VRDEProperties");
|
---|
4240 | for (StringsMap::const_iterator it = hw.vrdeSettings.mapProperties.begin();
|
---|
4241 | it != hw.vrdeSettings.mapProperties.end();
|
---|
4242 | ++it)
|
---|
4243 | {
|
---|
4244 | const Utf8Str &strName = it->first;
|
---|
4245 | const Utf8Str &strValue = it->second;
|
---|
4246 | xml::ElementNode *pelm = pelmProperties->createChild("Property");
|
---|
4247 | pelm->setAttribute("name", strName);
|
---|
4248 | pelm->setAttribute("value", strValue);
|
---|
4249 | }
|
---|
4250 | }
|
---|
4251 | }
|
---|
4252 |
|
---|
4253 | xml::ElementNode *pelmBIOS = pelmHardware->createChild("BIOS");
|
---|
4254 | pelmBIOS->createChild("ACPI")->setAttribute("enabled", hw.biosSettings.fACPIEnabled);
|
---|
4255 | pelmBIOS->createChild("IOAPIC")->setAttribute("enabled", hw.biosSettings.fIOAPICEnabled);
|
---|
4256 |
|
---|
4257 | xml::ElementNode *pelmLogo = pelmBIOS->createChild("Logo");
|
---|
4258 | pelmLogo->setAttribute("fadeIn", hw.biosSettings.fLogoFadeIn);
|
---|
4259 | pelmLogo->setAttribute("fadeOut", hw.biosSettings.fLogoFadeOut);
|
---|
4260 | pelmLogo->setAttribute("displayTime", hw.biosSettings.ulLogoDisplayTime);
|
---|
4261 | if (hw.biosSettings.strLogoImagePath.length())
|
---|
4262 | pelmLogo->setAttribute("imagePath", hw.biosSettings.strLogoImagePath);
|
---|
4263 |
|
---|
4264 | const char *pcszBootMenu;
|
---|
4265 | switch (hw.biosSettings.biosBootMenuMode)
|
---|
4266 | {
|
---|
4267 | case BIOSBootMenuMode_Disabled: pcszBootMenu = "Disabled"; break;
|
---|
4268 | case BIOSBootMenuMode_MenuOnly: pcszBootMenu = "MenuOnly"; break;
|
---|
4269 | default: /*BIOSBootMenuMode_MessageAndMenu*/ pcszBootMenu = "MessageAndMenu"; break;
|
---|
4270 | }
|
---|
4271 | pelmBIOS->createChild("BootMenu")->setAttribute("mode", pcszBootMenu);
|
---|
4272 | pelmBIOS->createChild("TimeOffset")->setAttribute("value", hw.biosSettings.llTimeOffset);
|
---|
4273 | pelmBIOS->createChild("PXEDebug")->setAttribute("enabled", hw.biosSettings.fPXEDebugEnabled);
|
---|
4274 |
|
---|
4275 | if (m->sv < SettingsVersion_v1_9)
|
---|
4276 | {
|
---|
4277 | // settings formats before 1.9 had separate DVDDrive and FloppyDrive items under Hardware;
|
---|
4278 | // run thru the storage controllers to see if we have a DVD or floppy drives
|
---|
4279 | size_t cDVDs = 0;
|
---|
4280 | size_t cFloppies = 0;
|
---|
4281 |
|
---|
4282 | xml::ElementNode *pelmDVD = pelmHardware->createChild("DVDDrive");
|
---|
4283 | xml::ElementNode *pelmFloppy = pelmHardware->createChild("FloppyDrive");
|
---|
4284 |
|
---|
4285 | for (StorageControllersList::const_iterator it = strg.llStorageControllers.begin();
|
---|
4286 | it != strg.llStorageControllers.end();
|
---|
4287 | ++it)
|
---|
4288 | {
|
---|
4289 | const StorageController &sctl = *it;
|
---|
4290 | // in old settings format, the DVD drive could only have been under the IDE controller
|
---|
4291 | if (sctl.storageBus == StorageBus_IDE)
|
---|
4292 | {
|
---|
4293 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
4294 | it2 != sctl.llAttachedDevices.end();
|
---|
4295 | ++it2)
|
---|
4296 | {
|
---|
4297 | const AttachedDevice &att = *it2;
|
---|
4298 | if (att.deviceType == DeviceType_DVD)
|
---|
4299 | {
|
---|
4300 | if (cDVDs > 0)
|
---|
4301 | throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one DVD drive with old settings format"));
|
---|
4302 |
|
---|
4303 | ++cDVDs;
|
---|
4304 |
|
---|
4305 | pelmDVD->setAttribute("passthrough", att.fPassThrough);
|
---|
4306 | if (att.fTempEject)
|
---|
4307 | pelmDVD->setAttribute("tempeject", att.fTempEject);
|
---|
4308 |
|
---|
4309 | if (!att.uuid.isZero() && att.uuid.isValid())
|
---|
4310 | pelmDVD->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
|
---|
4311 | else if (att.strHostDriveSrc.length())
|
---|
4312 | pelmDVD->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
4313 | }
|
---|
4314 | }
|
---|
4315 | }
|
---|
4316 | else if (sctl.storageBus == StorageBus_Floppy)
|
---|
4317 | {
|
---|
4318 | size_t cFloppiesHere = sctl.llAttachedDevices.size();
|
---|
4319 | if (cFloppiesHere > 1)
|
---|
4320 | throw ConfigFileError(this, NULL, N_("Internal error: floppy controller cannot have more than one device attachment"));
|
---|
4321 | if (cFloppiesHere)
|
---|
4322 | {
|
---|
4323 | const AttachedDevice &att = sctl.llAttachedDevices.front();
|
---|
4324 | pelmFloppy->setAttribute("enabled", true);
|
---|
4325 |
|
---|
4326 | if (!att.uuid.isZero() && att.uuid.isValid())
|
---|
4327 | pelmFloppy->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
|
---|
4328 | else if (att.strHostDriveSrc.length())
|
---|
4329 | pelmFloppy->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
4330 | }
|
---|
4331 |
|
---|
4332 | cFloppies += cFloppiesHere;
|
---|
4333 | }
|
---|
4334 | }
|
---|
4335 |
|
---|
4336 | if (cFloppies == 0)
|
---|
4337 | pelmFloppy->setAttribute("enabled", false);
|
---|
4338 | else if (cFloppies > 1)
|
---|
4339 | throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one floppy drive with old settings format"));
|
---|
4340 | }
|
---|
4341 |
|
---|
4342 | if (m->sv < SettingsVersion_v1_14)
|
---|
4343 | {
|
---|
4344 | bool fOhciEnabled = false;
|
---|
4345 | bool fEhciEnabled = false;
|
---|
4346 | xml::ElementNode *pelmUSB = pelmHardware->createChild("USBController");
|
---|
4347 |
|
---|
4348 | for (USBControllerList::const_iterator it = hardwareMachine.usbSettings.llUSBControllers.begin();
|
---|
4349 | it != hardwareMachine.usbSettings.llUSBControllers.end();
|
---|
4350 | ++it)
|
---|
4351 | {
|
---|
4352 | const USBController &ctrl = *it;
|
---|
4353 |
|
---|
4354 | switch (ctrl.enmType)
|
---|
4355 | {
|
---|
4356 | case USBControllerType_OHCI:
|
---|
4357 | fOhciEnabled = true;
|
---|
4358 | break;
|
---|
4359 | case USBControllerType_EHCI:
|
---|
4360 | fEhciEnabled = true;
|
---|
4361 | break;
|
---|
4362 | default:
|
---|
4363 | AssertMsgFailed(("Unknown USB controller type %d\n", ctrl.enmType));
|
---|
4364 | }
|
---|
4365 | }
|
---|
4366 |
|
---|
4367 | pelmUSB->setAttribute("enabled", fOhciEnabled);
|
---|
4368 | pelmUSB->setAttribute("enabledEhci", fEhciEnabled);
|
---|
4369 |
|
---|
4370 | buildUSBDeviceFilters(*pelmUSB, hw.usbSettings.llDeviceFilters, false /* fHostMode */);
|
---|
4371 | }
|
---|
4372 | else
|
---|
4373 | {
|
---|
4374 | xml::ElementNode *pelmUSB = pelmHardware->createChild("USB");
|
---|
4375 | xml::ElementNode *pelmCtrls = pelmUSB->createChild("Controllers");
|
---|
4376 |
|
---|
4377 | for (USBControllerList::const_iterator it = hardwareMachine.usbSettings.llUSBControllers.begin();
|
---|
4378 | it != hardwareMachine.usbSettings.llUSBControllers.end();
|
---|
4379 | ++it)
|
---|
4380 | {
|
---|
4381 | const USBController &ctrl = *it;
|
---|
4382 | com::Utf8Str strType;
|
---|
4383 | xml::ElementNode *pelmCtrl = pelmCtrls->createChild("Controller");
|
---|
4384 |
|
---|
4385 | switch (ctrl.enmType)
|
---|
4386 | {
|
---|
4387 | case USBControllerType_OHCI:
|
---|
4388 | strType = "OHCI";
|
---|
4389 | break;
|
---|
4390 | case USBControllerType_EHCI:
|
---|
4391 | strType = "EHCI";
|
---|
4392 | break;
|
---|
4393 | default:
|
---|
4394 | AssertMsgFailed(("Unknown USB controller type %d\n", ctrl.enmType));
|
---|
4395 | }
|
---|
4396 |
|
---|
4397 | pelmCtrl->setAttribute("name", ctrl.strName);
|
---|
4398 | pelmCtrl->setAttribute("type", strType);
|
---|
4399 | }
|
---|
4400 |
|
---|
4401 | xml::ElementNode *pelmFilters = pelmUSB->createChild("DeviceFilters");
|
---|
4402 | buildUSBDeviceFilters(*pelmFilters, hw.usbSettings.llDeviceFilters, false /* fHostMode */);
|
---|
4403 | }
|
---|
4404 |
|
---|
4405 | xml::ElementNode *pelmNetwork = pelmHardware->createChild("Network");
|
---|
4406 | for (NetworkAdaptersList::const_iterator it = hw.llNetworkAdapters.begin();
|
---|
4407 | it != hw.llNetworkAdapters.end();
|
---|
4408 | ++it)
|
---|
4409 | {
|
---|
4410 | const NetworkAdapter &nic = *it;
|
---|
4411 |
|
---|
4412 | xml::ElementNode *pelmAdapter = pelmNetwork->createChild("Adapter");
|
---|
4413 | pelmAdapter->setAttribute("slot", nic.ulSlot);
|
---|
4414 | pelmAdapter->setAttribute("enabled", nic.fEnabled);
|
---|
4415 | pelmAdapter->setAttribute("MACAddress", nic.strMACAddress);
|
---|
4416 | pelmAdapter->setAttribute("cable", nic.fCableConnected);
|
---|
4417 | pelmAdapter->setAttribute("speed", nic.ulLineSpeed);
|
---|
4418 | if (nic.ulBootPriority != 0)
|
---|
4419 | {
|
---|
4420 | pelmAdapter->setAttribute("bootPriority", nic.ulBootPriority);
|
---|
4421 | }
|
---|
4422 | if (nic.fTraceEnabled)
|
---|
4423 | {
|
---|
4424 | pelmAdapter->setAttribute("trace", nic.fTraceEnabled);
|
---|
4425 | pelmAdapter->setAttribute("tracefile", nic.strTraceFile);
|
---|
4426 | }
|
---|
4427 | if (nic.strBandwidthGroup.isNotEmpty())
|
---|
4428 | pelmAdapter->setAttribute("bandwidthGroup", nic.strBandwidthGroup);
|
---|
4429 |
|
---|
4430 | const char *pszPolicy;
|
---|
4431 | switch (nic.enmPromiscModePolicy)
|
---|
4432 | {
|
---|
4433 | case NetworkAdapterPromiscModePolicy_Deny: pszPolicy = NULL; break;
|
---|
4434 | case NetworkAdapterPromiscModePolicy_AllowNetwork: pszPolicy = "AllowNetwork"; break;
|
---|
4435 | case NetworkAdapterPromiscModePolicy_AllowAll: pszPolicy = "AllowAll"; break;
|
---|
4436 | default: pszPolicy = NULL; AssertFailed(); break;
|
---|
4437 | }
|
---|
4438 | if (pszPolicy)
|
---|
4439 | pelmAdapter->setAttribute("promiscuousModePolicy", pszPolicy);
|
---|
4440 |
|
---|
4441 | const char *pcszType;
|
---|
4442 | switch (nic.type)
|
---|
4443 | {
|
---|
4444 | case NetworkAdapterType_Am79C973: pcszType = "Am79C973"; break;
|
---|
4445 | case NetworkAdapterType_I82540EM: pcszType = "82540EM"; break;
|
---|
4446 | case NetworkAdapterType_I82543GC: pcszType = "82543GC"; break;
|
---|
4447 | case NetworkAdapterType_I82545EM: pcszType = "82545EM"; break;
|
---|
4448 | case NetworkAdapterType_Virtio: pcszType = "virtio"; break;
|
---|
4449 | default: /*case NetworkAdapterType_Am79C970A:*/ pcszType = "Am79C970A"; break;
|
---|
4450 | }
|
---|
4451 | pelmAdapter->setAttribute("type", pcszType);
|
---|
4452 |
|
---|
4453 | xml::ElementNode *pelmNAT;
|
---|
4454 | if (m->sv < SettingsVersion_v1_10)
|
---|
4455 | {
|
---|
4456 | switch (nic.mode)
|
---|
4457 | {
|
---|
4458 | case NetworkAttachmentType_NAT:
|
---|
4459 | pelmNAT = pelmAdapter->createChild("NAT");
|
---|
4460 | if (nic.nat.strNetwork.length())
|
---|
4461 | pelmNAT->setAttribute("network", nic.nat.strNetwork);
|
---|
4462 | break;
|
---|
4463 |
|
---|
4464 | case NetworkAttachmentType_Bridged:
|
---|
4465 | pelmAdapter->createChild("BridgedInterface")->setAttribute("name", nic.strBridgedName);
|
---|
4466 | break;
|
---|
4467 |
|
---|
4468 | case NetworkAttachmentType_Internal:
|
---|
4469 | pelmAdapter->createChild("InternalNetwork")->setAttribute("name", nic.strInternalNetworkName);
|
---|
4470 | break;
|
---|
4471 |
|
---|
4472 | case NetworkAttachmentType_HostOnly:
|
---|
4473 | pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strHostOnlyName);
|
---|
4474 | break;
|
---|
4475 |
|
---|
4476 | default: /*case NetworkAttachmentType_Null:*/
|
---|
4477 | break;
|
---|
4478 | }
|
---|
4479 | }
|
---|
4480 | else
|
---|
4481 | {
|
---|
4482 | /* m->sv >= SettingsVersion_v1_10 */
|
---|
4483 | xml::ElementNode *pelmDisabledNode = NULL;
|
---|
4484 | pelmDisabledNode = pelmAdapter->createChild("DisabledModes");
|
---|
4485 | if (nic.mode != NetworkAttachmentType_NAT)
|
---|
4486 | buildNetworkXML(NetworkAttachmentType_NAT, *pelmDisabledNode, false, nic);
|
---|
4487 | if (nic.mode != NetworkAttachmentType_Bridged)
|
---|
4488 | buildNetworkXML(NetworkAttachmentType_Bridged, *pelmDisabledNode, false, nic);
|
---|
4489 | if (nic.mode != NetworkAttachmentType_Internal)
|
---|
4490 | buildNetworkXML(NetworkAttachmentType_Internal, *pelmDisabledNode, false, nic);
|
---|
4491 | if (nic.mode != NetworkAttachmentType_HostOnly)
|
---|
4492 | buildNetworkXML(NetworkAttachmentType_HostOnly, *pelmDisabledNode, false, nic);
|
---|
4493 | if (nic.mode != NetworkAttachmentType_Generic)
|
---|
4494 | buildNetworkXML(NetworkAttachmentType_Generic, *pelmDisabledNode, false, nic);
|
---|
4495 | if (nic.mode != NetworkAttachmentType_NATNetwork)
|
---|
4496 | buildNetworkXML(NetworkAttachmentType_NATNetwork, *pelmDisabledNode, false, nic);
|
---|
4497 | buildNetworkXML(nic.mode, *pelmAdapter, true, nic);
|
---|
4498 | }
|
---|
4499 | }
|
---|
4500 |
|
---|
4501 | xml::ElementNode *pelmPorts = pelmHardware->createChild("UART");
|
---|
4502 | for (SerialPortsList::const_iterator it = hw.llSerialPorts.begin();
|
---|
4503 | it != hw.llSerialPorts.end();
|
---|
4504 | ++it)
|
---|
4505 | {
|
---|
4506 | const SerialPort &port = *it;
|
---|
4507 | xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
|
---|
4508 | pelmPort->setAttribute("slot", port.ulSlot);
|
---|
4509 | pelmPort->setAttribute("enabled", port.fEnabled);
|
---|
4510 | pelmPort->setAttributeHex("IOBase", port.ulIOBase);
|
---|
4511 | pelmPort->setAttribute("IRQ", port.ulIRQ);
|
---|
4512 |
|
---|
4513 | const char *pcszHostMode;
|
---|
4514 | switch (port.portMode)
|
---|
4515 | {
|
---|
4516 | case PortMode_HostPipe: pcszHostMode = "HostPipe"; break;
|
---|
4517 | case PortMode_HostDevice: pcszHostMode = "HostDevice"; break;
|
---|
4518 | case PortMode_RawFile: pcszHostMode = "RawFile"; break;
|
---|
4519 | default: /*case PortMode_Disconnected:*/ pcszHostMode = "Disconnected"; break;
|
---|
4520 | }
|
---|
4521 | switch (port.portMode)
|
---|
4522 | {
|
---|
4523 | case PortMode_HostPipe:
|
---|
4524 | pelmPort->setAttribute("server", port.fServer);
|
---|
4525 | /* no break */
|
---|
4526 | case PortMode_HostDevice:
|
---|
4527 | case PortMode_RawFile:
|
---|
4528 | pelmPort->setAttribute("path", port.strPath);
|
---|
4529 | break;
|
---|
4530 |
|
---|
4531 | default:
|
---|
4532 | break;
|
---|
4533 | }
|
---|
4534 | pelmPort->setAttribute("hostMode", pcszHostMode);
|
---|
4535 | }
|
---|
4536 |
|
---|
4537 | pelmPorts = pelmHardware->createChild("LPT");
|
---|
4538 | for (ParallelPortsList::const_iterator it = hw.llParallelPorts.begin();
|
---|
4539 | it != hw.llParallelPorts.end();
|
---|
4540 | ++it)
|
---|
4541 | {
|
---|
4542 | const ParallelPort &port = *it;
|
---|
4543 | xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
|
---|
4544 | pelmPort->setAttribute("slot", port.ulSlot);
|
---|
4545 | pelmPort->setAttribute("enabled", port.fEnabled);
|
---|
4546 | pelmPort->setAttributeHex("IOBase", port.ulIOBase);
|
---|
4547 | pelmPort->setAttribute("IRQ", port.ulIRQ);
|
---|
4548 | if (port.strPath.length())
|
---|
4549 | pelmPort->setAttribute("path", port.strPath);
|
---|
4550 | }
|
---|
4551 |
|
---|
4552 | xml::ElementNode *pelmAudio = pelmHardware->createChild("AudioAdapter");
|
---|
4553 | const char *pcszController;
|
---|
4554 | switch (hw.audioAdapter.controllerType)
|
---|
4555 | {
|
---|
4556 | case AudioControllerType_SB16:
|
---|
4557 | pcszController = "SB16";
|
---|
4558 | break;
|
---|
4559 | case AudioControllerType_HDA:
|
---|
4560 | if (m->sv >= SettingsVersion_v1_11)
|
---|
4561 | {
|
---|
4562 | pcszController = "HDA";
|
---|
4563 | break;
|
---|
4564 | }
|
---|
4565 | /* fall through */
|
---|
4566 | case AudioControllerType_AC97:
|
---|
4567 | default:
|
---|
4568 | pcszController = "AC97";
|
---|
4569 | break;
|
---|
4570 | }
|
---|
4571 | pelmAudio->setAttribute("controller", pcszController);
|
---|
4572 |
|
---|
4573 | if (m->sv >= SettingsVersion_v1_10)
|
---|
4574 | {
|
---|
4575 | xml::ElementNode *pelmRTC = pelmHardware->createChild("RTC");
|
---|
4576 | pelmRTC->setAttribute("localOrUTC", machineUserData.fRTCUseUTC ? "UTC" : "local");
|
---|
4577 | }
|
---|
4578 |
|
---|
4579 | const char *pcszDriver;
|
---|
4580 | switch (hw.audioAdapter.driverType)
|
---|
4581 | {
|
---|
4582 | case AudioDriverType_WinMM: pcszDriver = "WinMM"; break;
|
---|
4583 | case AudioDriverType_DirectSound: pcszDriver = "DirectSound"; break;
|
---|
4584 | case AudioDriverType_SolAudio: pcszDriver = "SolAudio"; break;
|
---|
4585 | case AudioDriverType_ALSA: pcszDriver = "ALSA"; break;
|
---|
4586 | case AudioDriverType_Pulse: pcszDriver = "Pulse"; break;
|
---|
4587 | case AudioDriverType_OSS: pcszDriver = "OSS"; break;
|
---|
4588 | case AudioDriverType_CoreAudio: pcszDriver = "CoreAudio"; break;
|
---|
4589 | case AudioDriverType_MMPM: pcszDriver = "MMPM"; break;
|
---|
4590 | default: /*case AudioDriverType_Null:*/ pcszDriver = "Null"; break;
|
---|
4591 | }
|
---|
4592 | pelmAudio->setAttribute("driver", pcszDriver);
|
---|
4593 |
|
---|
4594 | pelmAudio->setAttribute("enabled", hw.audioAdapter.fEnabled);
|
---|
4595 |
|
---|
4596 | xml::ElementNode *pelmSharedFolders = pelmHardware->createChild("SharedFolders");
|
---|
4597 | for (SharedFoldersList::const_iterator it = hw.llSharedFolders.begin();
|
---|
4598 | it != hw.llSharedFolders.end();
|
---|
4599 | ++it)
|
---|
4600 | {
|
---|
4601 | const SharedFolder &sf = *it;
|
---|
4602 | xml::ElementNode *pelmThis = pelmSharedFolders->createChild("SharedFolder");
|
---|
4603 | pelmThis->setAttribute("name", sf.strName);
|
---|
4604 | pelmThis->setAttribute("hostPath", sf.strHostPath);
|
---|
4605 | pelmThis->setAttribute("writable", sf.fWritable);
|
---|
4606 | pelmThis->setAttribute("autoMount", sf.fAutoMount);
|
---|
4607 | }
|
---|
4608 |
|
---|
4609 | xml::ElementNode *pelmClip = pelmHardware->createChild("Clipboard");
|
---|
4610 | const char *pcszClip;
|
---|
4611 | switch (hw.clipboardMode)
|
---|
4612 | {
|
---|
4613 | default: /*case ClipboardMode_Disabled:*/ pcszClip = "Disabled"; break;
|
---|
4614 | case ClipboardMode_HostToGuest: pcszClip = "HostToGuest"; break;
|
---|
4615 | case ClipboardMode_GuestToHost: pcszClip = "GuestToHost"; break;
|
---|
4616 | case ClipboardMode_Bidirectional: pcszClip = "Bidirectional"; break;
|
---|
4617 | }
|
---|
4618 | pelmClip->setAttribute("mode", pcszClip);
|
---|
4619 |
|
---|
4620 | xml::ElementNode *pelmDragAndDrop = pelmHardware->createChild("DragAndDrop");
|
---|
4621 | const char *pcszDragAndDrop;
|
---|
4622 | switch (hw.dragAndDropMode)
|
---|
4623 | {
|
---|
4624 | default: /*case DragAndDropMode_Disabled:*/ pcszDragAndDrop = "Disabled"; break;
|
---|
4625 | case DragAndDropMode_HostToGuest: pcszDragAndDrop = "HostToGuest"; break;
|
---|
4626 | case DragAndDropMode_GuestToHost: pcszDragAndDrop = "GuestToHost"; break;
|
---|
4627 | case DragAndDropMode_Bidirectional: pcszDragAndDrop = "Bidirectional"; break;
|
---|
4628 | }
|
---|
4629 | pelmDragAndDrop->setAttribute("mode", pcszDragAndDrop);
|
---|
4630 |
|
---|
4631 | if (m->sv >= SettingsVersion_v1_10)
|
---|
4632 | {
|
---|
4633 | xml::ElementNode *pelmIO = pelmHardware->createChild("IO");
|
---|
4634 | xml::ElementNode *pelmIOCache;
|
---|
4635 |
|
---|
4636 | pelmIOCache = pelmIO->createChild("IoCache");
|
---|
4637 | pelmIOCache->setAttribute("enabled", hw.ioSettings.fIOCacheEnabled);
|
---|
4638 | pelmIOCache->setAttribute("size", hw.ioSettings.ulIOCacheSize);
|
---|
4639 |
|
---|
4640 | if (m->sv >= SettingsVersion_v1_11)
|
---|
4641 | {
|
---|
4642 | xml::ElementNode *pelmBandwidthGroups = pelmIO->createChild("BandwidthGroups");
|
---|
4643 | for (BandwidthGroupList::const_iterator it = hw.ioSettings.llBandwidthGroups.begin();
|
---|
4644 | it != hw.ioSettings.llBandwidthGroups.end();
|
---|
4645 | ++it)
|
---|
4646 | {
|
---|
4647 | const BandwidthGroup &gr = *it;
|
---|
4648 | const char *pcszType;
|
---|
4649 | xml::ElementNode *pelmThis = pelmBandwidthGroups->createChild("BandwidthGroup");
|
---|
4650 | pelmThis->setAttribute("name", gr.strName);
|
---|
4651 | switch (gr.enmType)
|
---|
4652 | {
|
---|
4653 | case BandwidthGroupType_Network: pcszType = "Network"; break;
|
---|
4654 | default: /* BandwidthGrouptype_Disk */ pcszType = "Disk"; break;
|
---|
4655 | }
|
---|
4656 | pelmThis->setAttribute("type", pcszType);
|
---|
4657 | if (m->sv >= SettingsVersion_v1_13)
|
---|
4658 | pelmThis->setAttribute("maxBytesPerSec", gr.cMaxBytesPerSec);
|
---|
4659 | else
|
---|
4660 | pelmThis->setAttribute("maxMbPerSec", gr.cMaxBytesPerSec / _1M);
|
---|
4661 | }
|
---|
4662 | }
|
---|
4663 | }
|
---|
4664 |
|
---|
4665 | if (m->sv >= SettingsVersion_v1_12)
|
---|
4666 | {
|
---|
4667 | xml::ElementNode *pelmPCI = pelmHardware->createChild("HostPci");
|
---|
4668 | xml::ElementNode *pelmPCIDevices = pelmPCI->createChild("Devices");
|
---|
4669 |
|
---|
4670 | for (HostPCIDeviceAttachmentList::const_iterator it = hw.pciAttachments.begin();
|
---|
4671 | it != hw.pciAttachments.end();
|
---|
4672 | ++it)
|
---|
4673 | {
|
---|
4674 | const HostPCIDeviceAttachment &hpda = *it;
|
---|
4675 |
|
---|
4676 | xml::ElementNode *pelmThis = pelmPCIDevices->createChild("Device");
|
---|
4677 |
|
---|
4678 | pelmThis->setAttribute("host", hpda.uHostAddress);
|
---|
4679 | pelmThis->setAttribute("guest", hpda.uGuestAddress);
|
---|
4680 | pelmThis->setAttribute("name", hpda.strDeviceName);
|
---|
4681 | }
|
---|
4682 | }
|
---|
4683 |
|
---|
4684 | if (m->sv >= SettingsVersion_v1_12)
|
---|
4685 | {
|
---|
4686 | xml::ElementNode *pelmEmulatedUSB = pelmHardware->createChild("EmulatedUSB");
|
---|
4687 |
|
---|
4688 | xml::ElementNode *pelmCardReader = pelmEmulatedUSB->createChild("CardReader");
|
---|
4689 | pelmCardReader->setAttribute("enabled", hw.fEmulatedUSBCardReader);
|
---|
4690 | }
|
---|
4691 |
|
---|
4692 | if ( m->sv >= SettingsVersion_v1_14
|
---|
4693 | && !hw.strDefaultFrontend.isEmpty())
|
---|
4694 | {
|
---|
4695 | xml::ElementNode *pelmFrontend = pelmHardware->createChild("Frontend");
|
---|
4696 | xml::ElementNode *pelmDefault = pelmFrontend->createChild("Default");
|
---|
4697 | pelmDefault->setAttribute("type", hw.strDefaultFrontend);
|
---|
4698 | }
|
---|
4699 |
|
---|
4700 | xml::ElementNode *pelmGuest = pelmHardware->createChild("Guest");
|
---|
4701 | pelmGuest->setAttribute("memoryBalloonSize", hw.ulMemoryBalloonSize);
|
---|
4702 |
|
---|
4703 | xml::ElementNode *pelmGuestProps = pelmHardware->createChild("GuestProperties");
|
---|
4704 | for (GuestPropertiesList::const_iterator it = hw.llGuestProperties.begin();
|
---|
4705 | it != hw.llGuestProperties.end();
|
---|
4706 | ++it)
|
---|
4707 | {
|
---|
4708 | const GuestProperty &prop = *it;
|
---|
4709 | xml::ElementNode *pelmProp = pelmGuestProps->createChild("GuestProperty");
|
---|
4710 | pelmProp->setAttribute("name", prop.strName);
|
---|
4711 | pelmProp->setAttribute("value", prop.strValue);
|
---|
4712 | pelmProp->setAttribute("timestamp", prop.timestamp);
|
---|
4713 | pelmProp->setAttribute("flags", prop.strFlags);
|
---|
4714 | }
|
---|
4715 |
|
---|
4716 | if (hw.strNotificationPatterns.length())
|
---|
4717 | pelmGuestProps->setAttribute("notificationPatterns", hw.strNotificationPatterns);
|
---|
4718 | }
|
---|
4719 |
|
---|
4720 | /**
|
---|
4721 | * Fill a <Network> node. Only relevant for XML version >= v1_10.
|
---|
4722 | * @param mode
|
---|
4723 | * @param elmParent
|
---|
4724 | * @param fEnabled
|
---|
4725 | * @param nic
|
---|
4726 | */
|
---|
4727 | void MachineConfigFile::buildNetworkXML(NetworkAttachmentType_T mode,
|
---|
4728 | xml::ElementNode &elmParent,
|
---|
4729 | bool fEnabled,
|
---|
4730 | const NetworkAdapter &nic)
|
---|
4731 | {
|
---|
4732 | switch (mode)
|
---|
4733 | {
|
---|
4734 | case NetworkAttachmentType_NAT:
|
---|
4735 | xml::ElementNode *pelmNAT;
|
---|
4736 | pelmNAT = elmParent.createChild("NAT");
|
---|
4737 |
|
---|
4738 | if (nic.nat.strNetwork.length())
|
---|
4739 | pelmNAT->setAttribute("network", nic.nat.strNetwork);
|
---|
4740 | if (nic.nat.strBindIP.length())
|
---|
4741 | pelmNAT->setAttribute("hostip", nic.nat.strBindIP);
|
---|
4742 | if (nic.nat.u32Mtu)
|
---|
4743 | pelmNAT->setAttribute("mtu", nic.nat.u32Mtu);
|
---|
4744 | if (nic.nat.u32SockRcv)
|
---|
4745 | pelmNAT->setAttribute("sockrcv", nic.nat.u32SockRcv);
|
---|
4746 | if (nic.nat.u32SockSnd)
|
---|
4747 | pelmNAT->setAttribute("socksnd", nic.nat.u32SockSnd);
|
---|
4748 | if (nic.nat.u32TcpRcv)
|
---|
4749 | pelmNAT->setAttribute("tcprcv", nic.nat.u32TcpRcv);
|
---|
4750 | if (nic.nat.u32TcpSnd)
|
---|
4751 | pelmNAT->setAttribute("tcpsnd", nic.nat.u32TcpSnd);
|
---|
4752 | xml::ElementNode *pelmDNS;
|
---|
4753 | pelmDNS = pelmNAT->createChild("DNS");
|
---|
4754 | pelmDNS->setAttribute("pass-domain", nic.nat.fDNSPassDomain);
|
---|
4755 | pelmDNS->setAttribute("use-proxy", nic.nat.fDNSProxy);
|
---|
4756 | pelmDNS->setAttribute("use-host-resolver", nic.nat.fDNSUseHostResolver);
|
---|
4757 |
|
---|
4758 | xml::ElementNode *pelmAlias;
|
---|
4759 | pelmAlias = pelmNAT->createChild("Alias");
|
---|
4760 | pelmAlias->setAttribute("logging", nic.nat.fAliasLog);
|
---|
4761 | pelmAlias->setAttribute("proxy-only", nic.nat.fAliasProxyOnly);
|
---|
4762 | pelmAlias->setAttribute("use-same-ports", nic.nat.fAliasUseSamePorts);
|
---|
4763 |
|
---|
4764 | if ( nic.nat.strTFTPPrefix.length()
|
---|
4765 | || nic.nat.strTFTPBootFile.length()
|
---|
4766 | || nic.nat.strTFTPNextServer.length())
|
---|
4767 | {
|
---|
4768 | xml::ElementNode *pelmTFTP;
|
---|
4769 | pelmTFTP = pelmNAT->createChild("TFTP");
|
---|
4770 | if (nic.nat.strTFTPPrefix.length())
|
---|
4771 | pelmTFTP->setAttribute("prefix", nic.nat.strTFTPPrefix);
|
---|
4772 | if (nic.nat.strTFTPBootFile.length())
|
---|
4773 | pelmTFTP->setAttribute("boot-file", nic.nat.strTFTPBootFile);
|
---|
4774 | if (nic.nat.strTFTPNextServer.length())
|
---|
4775 | pelmTFTP->setAttribute("next-server", nic.nat.strTFTPNextServer);
|
---|
4776 | }
|
---|
4777 | buildNATForwardRuleList(*pelmNAT, nic.nat.llRules);
|
---|
4778 | break;
|
---|
4779 |
|
---|
4780 | case NetworkAttachmentType_Bridged:
|
---|
4781 | if (fEnabled || !nic.strBridgedName.isEmpty())
|
---|
4782 | elmParent.createChild("BridgedInterface")->setAttribute("name", nic.strBridgedName);
|
---|
4783 | break;
|
---|
4784 |
|
---|
4785 | case NetworkAttachmentType_Internal:
|
---|
4786 | if (fEnabled || !nic.strInternalNetworkName.isEmpty())
|
---|
4787 | elmParent.createChild("InternalNetwork")->setAttribute("name", nic.strInternalNetworkName);
|
---|
4788 | break;
|
---|
4789 |
|
---|
4790 | case NetworkAttachmentType_HostOnly:
|
---|
4791 | if (fEnabled || !nic.strHostOnlyName.isEmpty())
|
---|
4792 | elmParent.createChild("HostOnlyInterface")->setAttribute("name", nic.strHostOnlyName);
|
---|
4793 | break;
|
---|
4794 |
|
---|
4795 | case NetworkAttachmentType_Generic:
|
---|
4796 | if (fEnabled || !nic.strGenericDriver.isEmpty() || nic.genericProperties.size())
|
---|
4797 | {
|
---|
4798 | xml::ElementNode *pelmMode = elmParent.createChild("GenericInterface");
|
---|
4799 | pelmMode->setAttribute("driver", nic.strGenericDriver);
|
---|
4800 | for (StringsMap::const_iterator it = nic.genericProperties.begin();
|
---|
4801 | it != nic.genericProperties.end();
|
---|
4802 | ++it)
|
---|
4803 | {
|
---|
4804 | xml::ElementNode *pelmProp = pelmMode->createChild("Property");
|
---|
4805 | pelmProp->setAttribute("name", it->first);
|
---|
4806 | pelmProp->setAttribute("value", it->second);
|
---|
4807 | }
|
---|
4808 | }
|
---|
4809 | break;
|
---|
4810 |
|
---|
4811 | case NetworkAttachmentType_NATNetwork:
|
---|
4812 | if (fEnabled || !nic.strNATNetworkName.isEmpty())
|
---|
4813 | elmParent.createChild("NATNetwork")->setAttribute("name", nic.strNATNetworkName);
|
---|
4814 | break;
|
---|
4815 |
|
---|
4816 | default: /*case NetworkAttachmentType_Null:*/
|
---|
4817 | break;
|
---|
4818 | }
|
---|
4819 | }
|
---|
4820 |
|
---|
4821 | /**
|
---|
4822 | * Creates a <StorageControllers> node under elmParent and then writes out the XML
|
---|
4823 | * keys under that. Called for both the <Machine> node and for snapshots.
|
---|
4824 | * @param elmParent
|
---|
4825 | * @param st
|
---|
4826 | * @param fSkipRemovableMedia If true, DVD and floppy attachments are skipped and
|
---|
4827 | * an empty drive is always written instead. This is for the OVF export case.
|
---|
4828 | * This parameter is ignored unless the settings version is at least v1.9, which
|
---|
4829 | * is always the case when this gets called for OVF export.
|
---|
4830 | * @param pllElementsWithUuidAttributes If not NULL, must point to a list of element node
|
---|
4831 | * pointers to which we will append all elements that we created here that contain
|
---|
4832 | * UUID attributes. This allows the OVF export code to quickly replace the internal
|
---|
4833 | * media UUIDs with the UUIDs of the media that were exported.
|
---|
4834 | */
|
---|
4835 | void MachineConfigFile::buildStorageControllersXML(xml::ElementNode &elmParent,
|
---|
4836 | const Storage &st,
|
---|
4837 | bool fSkipRemovableMedia,
|
---|
4838 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
|
---|
4839 | {
|
---|
4840 | xml::ElementNode *pelmStorageControllers = elmParent.createChild("StorageControllers");
|
---|
4841 |
|
---|
4842 | for (StorageControllersList::const_iterator it = st.llStorageControllers.begin();
|
---|
4843 | it != st.llStorageControllers.end();
|
---|
4844 | ++it)
|
---|
4845 | {
|
---|
4846 | const StorageController &sc = *it;
|
---|
4847 |
|
---|
4848 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
4849 | && (sc.controllerType == StorageControllerType_I82078)
|
---|
4850 | )
|
---|
4851 | // floppy controller already got written into <Hardware>/<FloppyController> in buildHardwareXML()
|
---|
4852 | // for pre-1.9 settings
|
---|
4853 | continue;
|
---|
4854 |
|
---|
4855 | xml::ElementNode *pelmController = pelmStorageControllers->createChild("StorageController");
|
---|
4856 | com::Utf8Str name = sc.strName;
|
---|
4857 | if (m->sv < SettingsVersion_v1_8)
|
---|
4858 | {
|
---|
4859 | // pre-1.8 settings use shorter controller names, they are
|
---|
4860 | // expanded when reading the settings
|
---|
4861 | if (name == "IDE Controller")
|
---|
4862 | name = "IDE";
|
---|
4863 | else if (name == "SATA Controller")
|
---|
4864 | name = "SATA";
|
---|
4865 | else if (name == "SCSI Controller")
|
---|
4866 | name = "SCSI";
|
---|
4867 | }
|
---|
4868 | pelmController->setAttribute("name", sc.strName);
|
---|
4869 |
|
---|
4870 | const char *pcszType;
|
---|
4871 | switch (sc.controllerType)
|
---|
4872 | {
|
---|
4873 | case StorageControllerType_IntelAhci: pcszType = "AHCI"; break;
|
---|
4874 | case StorageControllerType_LsiLogic: pcszType = "LsiLogic"; break;
|
---|
4875 | case StorageControllerType_BusLogic: pcszType = "BusLogic"; break;
|
---|
4876 | case StorageControllerType_PIIX4: pcszType = "PIIX4"; break;
|
---|
4877 | case StorageControllerType_ICH6: pcszType = "ICH6"; break;
|
---|
4878 | case StorageControllerType_I82078: pcszType = "I82078"; break;
|
---|
4879 | case StorageControllerType_LsiLogicSas: pcszType = "LsiLogicSas"; break;
|
---|
4880 | case StorageControllerType_USB: pcszType = "USB"; break;
|
---|
4881 | default: /*case StorageControllerType_PIIX3:*/ pcszType = "PIIX3"; break;
|
---|
4882 | }
|
---|
4883 | pelmController->setAttribute("type", pcszType);
|
---|
4884 |
|
---|
4885 | pelmController->setAttribute("PortCount", sc.ulPortCount);
|
---|
4886 |
|
---|
4887 | if (m->sv >= SettingsVersion_v1_9)
|
---|
4888 | if (sc.ulInstance)
|
---|
4889 | pelmController->setAttribute("Instance", sc.ulInstance);
|
---|
4890 |
|
---|
4891 | if (m->sv >= SettingsVersion_v1_10)
|
---|
4892 | pelmController->setAttribute("useHostIOCache", sc.fUseHostIOCache);
|
---|
4893 |
|
---|
4894 | if (m->sv >= SettingsVersion_v1_11)
|
---|
4895 | pelmController->setAttribute("Bootable", sc.fBootable);
|
---|
4896 |
|
---|
4897 | if (sc.controllerType == StorageControllerType_IntelAhci)
|
---|
4898 | {
|
---|
4899 | pelmController->setAttribute("IDE0MasterEmulationPort", sc.lIDE0MasterEmulationPort);
|
---|
4900 | pelmController->setAttribute("IDE0SlaveEmulationPort", sc.lIDE0SlaveEmulationPort);
|
---|
4901 | pelmController->setAttribute("IDE1MasterEmulationPort", sc.lIDE1MasterEmulationPort);
|
---|
4902 | pelmController->setAttribute("IDE1SlaveEmulationPort", sc.lIDE1SlaveEmulationPort);
|
---|
4903 | }
|
---|
4904 |
|
---|
4905 | for (AttachedDevicesList::const_iterator it2 = sc.llAttachedDevices.begin();
|
---|
4906 | it2 != sc.llAttachedDevices.end();
|
---|
4907 | ++it2)
|
---|
4908 | {
|
---|
4909 | const AttachedDevice &att = *it2;
|
---|
4910 |
|
---|
4911 | // For settings version before 1.9, DVDs and floppies are in hardware, not storage controllers,
|
---|
4912 | // so we shouldn't write them here; we only get here for DVDs though because we ruled out
|
---|
4913 | // the floppy controller at the top of the loop
|
---|
4914 | if ( att.deviceType == DeviceType_DVD
|
---|
4915 | && m->sv < SettingsVersion_v1_9
|
---|
4916 | )
|
---|
4917 | continue;
|
---|
4918 |
|
---|
4919 | xml::ElementNode *pelmDevice = pelmController->createChild("AttachedDevice");
|
---|
4920 |
|
---|
4921 | pcszType = NULL;
|
---|
4922 |
|
---|
4923 | switch (att.deviceType)
|
---|
4924 | {
|
---|
4925 | case DeviceType_HardDisk:
|
---|
4926 | pcszType = "HardDisk";
|
---|
4927 | if (att.fNonRotational)
|
---|
4928 | pelmDevice->setAttribute("nonrotational", att.fNonRotational);
|
---|
4929 | if (att.fDiscard)
|
---|
4930 | pelmDevice->setAttribute("discard", att.fDiscard);
|
---|
4931 | break;
|
---|
4932 |
|
---|
4933 | case DeviceType_DVD:
|
---|
4934 | pcszType = "DVD";
|
---|
4935 | pelmDevice->setAttribute("passthrough", att.fPassThrough);
|
---|
4936 | if (att.fTempEject)
|
---|
4937 | pelmDevice->setAttribute("tempeject", att.fTempEject);
|
---|
4938 | break;
|
---|
4939 |
|
---|
4940 | case DeviceType_Floppy:
|
---|
4941 | pcszType = "Floppy";
|
---|
4942 | break;
|
---|
4943 | }
|
---|
4944 |
|
---|
4945 | pelmDevice->setAttribute("type", pcszType);
|
---|
4946 |
|
---|
4947 | if (m->sv >= SettingsVersion_v1_15)
|
---|
4948 | pelmDevice->setAttribute("hotpluggable", att.fHotPluggable);
|
---|
4949 |
|
---|
4950 | pelmDevice->setAttribute("port", att.lPort);
|
---|
4951 | pelmDevice->setAttribute("device", att.lDevice);
|
---|
4952 |
|
---|
4953 | if (att.strBwGroup.length())
|
---|
4954 | pelmDevice->setAttribute("bandwidthGroup", att.strBwGroup);
|
---|
4955 |
|
---|
4956 | // attached image, if any
|
---|
4957 | if (!att.uuid.isZero()
|
---|
4958 | && att.uuid.isValid()
|
---|
4959 | && (att.deviceType == DeviceType_HardDisk
|
---|
4960 | || !fSkipRemovableMedia
|
---|
4961 | )
|
---|
4962 | )
|
---|
4963 | {
|
---|
4964 | xml::ElementNode *pelmImage = pelmDevice->createChild("Image");
|
---|
4965 | pelmImage->setAttribute("uuid", att.uuid.toStringCurly());
|
---|
4966 |
|
---|
4967 | // if caller wants a list of UUID elements, give it to them
|
---|
4968 | if (pllElementsWithUuidAttributes)
|
---|
4969 | pllElementsWithUuidAttributes->push_back(pelmImage);
|
---|
4970 | }
|
---|
4971 | else if ( (m->sv >= SettingsVersion_v1_9)
|
---|
4972 | && (att.strHostDriveSrc.length())
|
---|
4973 | )
|
---|
4974 | pelmDevice->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
4975 | }
|
---|
4976 | }
|
---|
4977 | }
|
---|
4978 |
|
---|
4979 | /**
|
---|
4980 | * Creates a <Debugging> node under elmParent and then writes out the XML
|
---|
4981 | * keys under that. Called for both the <Machine> node and for snapshots.
|
---|
4982 | *
|
---|
4983 | * @param pElmParent Pointer to the parent element.
|
---|
4984 | * @param pDbg Pointer to the debugging settings.
|
---|
4985 | */
|
---|
4986 | void MachineConfigFile::buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg)
|
---|
4987 | {
|
---|
4988 | if (m->sv < SettingsVersion_v1_13 || pDbg->areDefaultSettings())
|
---|
4989 | return;
|
---|
4990 |
|
---|
4991 | xml::ElementNode *pElmDebugging = pElmParent->createChild("Debugging");
|
---|
4992 | xml::ElementNode *pElmTracing = pElmDebugging->createChild("Tracing");
|
---|
4993 | pElmTracing->setAttribute("enabled", pDbg->fTracingEnabled);
|
---|
4994 | pElmTracing->setAttribute("allowTracingToAccessVM", pDbg->fAllowTracingToAccessVM);
|
---|
4995 | pElmTracing->setAttribute("config", pDbg->strTracingConfig);
|
---|
4996 | }
|
---|
4997 |
|
---|
4998 | /**
|
---|
4999 | * Creates a <Autostart> node under elmParent and then writes out the XML
|
---|
5000 | * keys under that. Called for both the <Machine> node and for snapshots.
|
---|
5001 | *
|
---|
5002 | * @param pElmParent Pointer to the parent element.
|
---|
5003 | * @param pAutostart Pointer to the autostart settings.
|
---|
5004 | */
|
---|
5005 | void MachineConfigFile::buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart)
|
---|
5006 | {
|
---|
5007 | const char *pcszAutostop = NULL;
|
---|
5008 |
|
---|
5009 | if (m->sv < SettingsVersion_v1_13 || pAutostart->areDefaultSettings())
|
---|
5010 | return;
|
---|
5011 |
|
---|
5012 | xml::ElementNode *pElmAutostart = pElmParent->createChild("Autostart");
|
---|
5013 | pElmAutostart->setAttribute("enabled", pAutostart->fAutostartEnabled);
|
---|
5014 | pElmAutostart->setAttribute("delay", pAutostart->uAutostartDelay);
|
---|
5015 |
|
---|
5016 | switch (pAutostart->enmAutostopType)
|
---|
5017 | {
|
---|
5018 | case AutostopType_Disabled: pcszAutostop = "Disabled"; break;
|
---|
5019 | case AutostopType_SaveState: pcszAutostop = "SaveState"; break;
|
---|
5020 | case AutostopType_PowerOff: pcszAutostop = "PowerOff"; break;
|
---|
5021 | case AutostopType_AcpiShutdown: pcszAutostop = "AcpiShutdown"; break;
|
---|
5022 | default: Assert(false); pcszAutostop = "Disabled"; break;
|
---|
5023 | }
|
---|
5024 | pElmAutostart->setAttribute("autostop", pcszAutostop);
|
---|
5025 | }
|
---|
5026 |
|
---|
5027 | /**
|
---|
5028 | * Creates a <Groups> node under elmParent and then writes out the XML
|
---|
5029 | * keys under that. Called for the <Machine> node only.
|
---|
5030 | *
|
---|
5031 | * @param pElmParent Pointer to the parent element.
|
---|
5032 | * @param pllGroups Pointer to the groups list.
|
---|
5033 | */
|
---|
5034 | void MachineConfigFile::buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups)
|
---|
5035 | {
|
---|
5036 | if ( m->sv < SettingsVersion_v1_13 || pllGroups->size() == 0
|
---|
5037 | || (pllGroups->size() == 1 && pllGroups->front() == "/"))
|
---|
5038 | return;
|
---|
5039 |
|
---|
5040 | xml::ElementNode *pElmGroups = pElmParent->createChild("Groups");
|
---|
5041 | for (StringsList::const_iterator it = pllGroups->begin();
|
---|
5042 | it != pllGroups->end();
|
---|
5043 | ++it)
|
---|
5044 | {
|
---|
5045 | const Utf8Str &group = *it;
|
---|
5046 | xml::ElementNode *pElmGroup = pElmGroups->createChild("Group");
|
---|
5047 | pElmGroup->setAttribute("name", group);
|
---|
5048 | }
|
---|
5049 | }
|
---|
5050 |
|
---|
5051 | /**
|
---|
5052 | * Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
|
---|
5053 | * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
|
---|
5054 | * <Machine> node to which <Snapshot> must be added. This may then recurse for child snapshots.
|
---|
5055 | *
|
---|
5056 | * @param depth
|
---|
5057 | * @param elmParent
|
---|
5058 | * @param snap
|
---|
5059 | */
|
---|
5060 | void MachineConfigFile::buildSnapshotXML(uint32_t depth,
|
---|
5061 | xml::ElementNode &elmParent,
|
---|
5062 | const Snapshot &snap)
|
---|
5063 | {
|
---|
5064 | if (depth > SETTINGS_SNAPSHOT_DEPTH_MAX)
|
---|
5065 | throw ConfigFileError(this, NULL, N_("Maximum snapshot tree depth of %u exceeded"), SETTINGS_SNAPSHOT_DEPTH_MAX);
|
---|
5066 |
|
---|
5067 | xml::ElementNode *pelmSnapshot = elmParent.createChild("Snapshot");
|
---|
5068 |
|
---|
5069 | pelmSnapshot->setAttribute("uuid", snap.uuid.toStringCurly());
|
---|
5070 | pelmSnapshot->setAttribute("name", snap.strName);
|
---|
5071 | pelmSnapshot->setAttribute("timeStamp", makeString(snap.timestamp));
|
---|
5072 |
|
---|
5073 | if (snap.strStateFile.length())
|
---|
5074 | pelmSnapshot->setAttributePath("stateFile", snap.strStateFile);
|
---|
5075 |
|
---|
5076 | if (snap.strDescription.length())
|
---|
5077 | pelmSnapshot->createChild("Description")->addContent(snap.strDescription);
|
---|
5078 |
|
---|
5079 | buildHardwareXML(*pelmSnapshot, snap.hardware, snap.storage);
|
---|
5080 | buildStorageControllersXML(*pelmSnapshot,
|
---|
5081 | snap.storage,
|
---|
5082 | false /* fSkipRemovableMedia */,
|
---|
5083 | NULL); /* pllElementsWithUuidAttributes */
|
---|
5084 | // we only skip removable media for OVF, but we never get here for OVF
|
---|
5085 | // since snapshots never get written then
|
---|
5086 | buildDebuggingXML(pelmSnapshot, &snap.debugging);
|
---|
5087 | buildAutostartXML(pelmSnapshot, &snap.autostart);
|
---|
5088 | // note: Groups exist only for Machine, not for Snapshot
|
---|
5089 |
|
---|
5090 | if (snap.llChildSnapshots.size())
|
---|
5091 | {
|
---|
5092 | xml::ElementNode *pelmChildren = pelmSnapshot->createChild("Snapshots");
|
---|
5093 | for (SnapshotsList::const_iterator it = snap.llChildSnapshots.begin();
|
---|
5094 | it != snap.llChildSnapshots.end();
|
---|
5095 | ++it)
|
---|
5096 | {
|
---|
5097 | const Snapshot &child = *it;
|
---|
5098 | buildSnapshotXML(depth + 1, *pelmChildren, child);
|
---|
5099 | }
|
---|
5100 | }
|
---|
5101 | }
|
---|
5102 |
|
---|
5103 | /**
|
---|
5104 | * Builds the XML DOM tree for the machine config under the given XML element.
|
---|
5105 | *
|
---|
5106 | * This has been separated out from write() so it can be called from elsewhere,
|
---|
5107 | * such as the OVF code, to build machine XML in an existing XML tree.
|
---|
5108 | *
|
---|
5109 | * As a result, this gets called from two locations:
|
---|
5110 | *
|
---|
5111 | * -- MachineConfigFile::write();
|
---|
5112 | *
|
---|
5113 | * -- Appliance::buildXMLForOneVirtualSystem()
|
---|
5114 | *
|
---|
5115 | * In fl, the following flag bits are recognized:
|
---|
5116 | *
|
---|
5117 | * -- BuildMachineXML_MediaRegistry: If set, the machine's media registry will
|
---|
5118 | * be written, if present. This is not set when called from OVF because OVF
|
---|
5119 | * has its own variant of a media registry. This flag is ignored unless the
|
---|
5120 | * settings version is at least v1.11 (VirtualBox 4.0).
|
---|
5121 | *
|
---|
5122 | * -- BuildMachineXML_IncludeSnapshots: If set, descend into the snapshots tree
|
---|
5123 | * of the machine and write out <Snapshot> and possibly more snapshots under
|
---|
5124 | * that, if snapshots are present. Otherwise all snapshots are suppressed
|
---|
5125 | * (when called from OVF).
|
---|
5126 | *
|
---|
5127 | * -- BuildMachineXML_WriteVBoxVersionAttribute: If set, add a settingsVersion
|
---|
5128 | * attribute to the machine tag with the vbox settings version. This is for
|
---|
5129 | * the OVF export case in which we don't have the settings version set in
|
---|
5130 | * the root element.
|
---|
5131 | *
|
---|
5132 | * -- BuildMachineXML_SkipRemovableMedia: If set, removable media attachments
|
---|
5133 | * (DVDs, floppies) are silently skipped. This is for the OVF export case
|
---|
5134 | * until we support copying ISO and RAW media as well. This flag is ignored
|
---|
5135 | * unless the settings version is at least v1.9, which is always the case
|
---|
5136 | * when this gets called for OVF export.
|
---|
5137 | *
|
---|
5138 | * -- BuildMachineXML_SuppressSavedState: If set, the Machine/@stateFile
|
---|
5139 | * attribute is never set. This is also for the OVF export case because we
|
---|
5140 | * cannot save states with OVF.
|
---|
5141 | *
|
---|
5142 | * @param elmMachine XML <Machine> element to add attributes and elements to.
|
---|
5143 | * @param fl Flags.
|
---|
5144 | * @param pllElementsWithUuidAttributes pointer to list that should receive UUID elements or NULL;
|
---|
5145 | * see buildStorageControllersXML() for details.
|
---|
5146 | */
|
---|
5147 | void MachineConfigFile::buildMachineXML(xml::ElementNode &elmMachine,
|
---|
5148 | uint32_t fl,
|
---|
5149 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
|
---|
5150 | {
|
---|
5151 | if (fl & BuildMachineXML_WriteVBoxVersionAttribute)
|
---|
5152 | // add settings version attribute to machine element
|
---|
5153 | setVersionAttribute(elmMachine);
|
---|
5154 |
|
---|
5155 | elmMachine.setAttribute("uuid", uuid.toStringCurly());
|
---|
5156 | elmMachine.setAttribute("name", machineUserData.strName);
|
---|
5157 | if (machineUserData.fDirectoryIncludesUUID)
|
---|
5158 | elmMachine.setAttribute("directoryIncludesUUID", machineUserData.fDirectoryIncludesUUID);
|
---|
5159 | if (!machineUserData.fNameSync)
|
---|
5160 | elmMachine.setAttribute("nameSync", machineUserData.fNameSync);
|
---|
5161 | if (machineUserData.strDescription.length())
|
---|
5162 | elmMachine.createChild("Description")->addContent(machineUserData.strDescription);
|
---|
5163 | elmMachine.setAttribute("OSType", machineUserData.strOsType);
|
---|
5164 | if ( strStateFile.length()
|
---|
5165 | && !(fl & BuildMachineXML_SuppressSavedState)
|
---|
5166 | )
|
---|
5167 | elmMachine.setAttributePath("stateFile", strStateFile);
|
---|
5168 |
|
---|
5169 | if ((fl & BuildMachineXML_IncludeSnapshots)
|
---|
5170 | && !uuidCurrentSnapshot.isZero()
|
---|
5171 | && uuidCurrentSnapshot.isValid())
|
---|
5172 | elmMachine.setAttribute("currentSnapshot", uuidCurrentSnapshot.toStringCurly());
|
---|
5173 |
|
---|
5174 | if (machineUserData.strSnapshotFolder.length())
|
---|
5175 | elmMachine.setAttributePath("snapshotFolder", machineUserData.strSnapshotFolder);
|
---|
5176 | if (!fCurrentStateModified)
|
---|
5177 | elmMachine.setAttribute("currentStateModified", fCurrentStateModified);
|
---|
5178 | elmMachine.setAttribute("lastStateChange", makeString(timeLastStateChange));
|
---|
5179 | if (fAborted)
|
---|
5180 | elmMachine.setAttribute("aborted", fAborted);
|
---|
5181 | // Please keep the icon last so that one doesn't have to check if there
|
---|
5182 | // is anything in the line after this very long attribute in the XML.
|
---|
5183 | if (machineUserData.ovIcon.length())
|
---|
5184 | elmMachine.setAttribute("icon", machineUserData.ovIcon);
|
---|
5185 | if ( m->sv >= SettingsVersion_v1_9
|
---|
5186 | && ( machineUserData.fTeleporterEnabled
|
---|
5187 | || machineUserData.uTeleporterPort
|
---|
5188 | || !machineUserData.strTeleporterAddress.isEmpty()
|
---|
5189 | || !machineUserData.strTeleporterPassword.isEmpty()
|
---|
5190 | )
|
---|
5191 | )
|
---|
5192 | {
|
---|
5193 | xml::ElementNode *pelmTeleporter = elmMachine.createChild("Teleporter");
|
---|
5194 | pelmTeleporter->setAttribute("enabled", machineUserData.fTeleporterEnabled);
|
---|
5195 | pelmTeleporter->setAttribute("port", machineUserData.uTeleporterPort);
|
---|
5196 | pelmTeleporter->setAttribute("address", machineUserData.strTeleporterAddress);
|
---|
5197 | pelmTeleporter->setAttribute("password", machineUserData.strTeleporterPassword);
|
---|
5198 | }
|
---|
5199 |
|
---|
5200 | if ( m->sv >= SettingsVersion_v1_11
|
---|
5201 | && ( machineUserData.enmFaultToleranceState != FaultToleranceState_Inactive
|
---|
5202 | || machineUserData.uFaultTolerancePort
|
---|
5203 | || machineUserData.uFaultToleranceInterval
|
---|
5204 | || !machineUserData.strFaultToleranceAddress.isEmpty()
|
---|
5205 | )
|
---|
5206 | )
|
---|
5207 | {
|
---|
5208 | xml::ElementNode *pelmFaultTolerance = elmMachine.createChild("FaultTolerance");
|
---|
5209 | switch (machineUserData.enmFaultToleranceState)
|
---|
5210 | {
|
---|
5211 | case FaultToleranceState_Inactive:
|
---|
5212 | pelmFaultTolerance->setAttribute("state", "inactive");
|
---|
5213 | break;
|
---|
5214 | case FaultToleranceState_Master:
|
---|
5215 | pelmFaultTolerance->setAttribute("state", "master");
|
---|
5216 | break;
|
---|
5217 | case FaultToleranceState_Standby:
|
---|
5218 | pelmFaultTolerance->setAttribute("state", "standby");
|
---|
5219 | break;
|
---|
5220 | }
|
---|
5221 |
|
---|
5222 | pelmFaultTolerance->setAttribute("port", machineUserData.uFaultTolerancePort);
|
---|
5223 | pelmFaultTolerance->setAttribute("address", machineUserData.strFaultToleranceAddress);
|
---|
5224 | pelmFaultTolerance->setAttribute("interval", machineUserData.uFaultToleranceInterval);
|
---|
5225 | pelmFaultTolerance->setAttribute("password", machineUserData.strFaultTolerancePassword);
|
---|
5226 | }
|
---|
5227 |
|
---|
5228 | if ( (fl & BuildMachineXML_MediaRegistry)
|
---|
5229 | && (m->sv >= SettingsVersion_v1_11)
|
---|
5230 | )
|
---|
5231 | buildMediaRegistry(elmMachine, mediaRegistry);
|
---|
5232 |
|
---|
5233 | buildExtraData(elmMachine, mapExtraDataItems);
|
---|
5234 |
|
---|
5235 | if ( (fl & BuildMachineXML_IncludeSnapshots)
|
---|
5236 | && llFirstSnapshot.size())
|
---|
5237 | buildSnapshotXML(1, elmMachine, llFirstSnapshot.front());
|
---|
5238 |
|
---|
5239 | buildHardwareXML(elmMachine, hardwareMachine, storageMachine);
|
---|
5240 | buildStorageControllersXML(elmMachine,
|
---|
5241 | storageMachine,
|
---|
5242 | !!(fl & BuildMachineXML_SkipRemovableMedia),
|
---|
5243 | pllElementsWithUuidAttributes);
|
---|
5244 | buildDebuggingXML(&elmMachine, &debugging);
|
---|
5245 | buildAutostartXML(&elmMachine, &autostart);
|
---|
5246 | buildGroupsXML(&elmMachine, &machineUserData.llGroups);
|
---|
5247 | }
|
---|
5248 |
|
---|
5249 | /**
|
---|
5250 | * Returns true only if the given AudioDriverType is supported on
|
---|
5251 | * the current host platform. For example, this would return false
|
---|
5252 | * for AudioDriverType_DirectSound when compiled on a Linux host.
|
---|
5253 | * @param drv AudioDriverType_* enum to test.
|
---|
5254 | * @return true only if the current host supports that driver.
|
---|
5255 | */
|
---|
5256 | /*static*/
|
---|
5257 | bool MachineConfigFile::isAudioDriverAllowedOnThisHost(AudioDriverType_T drv)
|
---|
5258 | {
|
---|
5259 | switch (drv)
|
---|
5260 | {
|
---|
5261 | case AudioDriverType_Null:
|
---|
5262 | #ifdef RT_OS_WINDOWS
|
---|
5263 | # ifdef VBOX_WITH_WINMM
|
---|
5264 | case AudioDriverType_WinMM:
|
---|
5265 | # endif
|
---|
5266 | case AudioDriverType_DirectSound:
|
---|
5267 | #endif /* RT_OS_WINDOWS */
|
---|
5268 | #ifdef RT_OS_SOLARIS
|
---|
5269 | case AudioDriverType_SolAudio:
|
---|
5270 | #endif
|
---|
5271 | #ifdef RT_OS_LINUX
|
---|
5272 | # ifdef VBOX_WITH_ALSA
|
---|
5273 | case AudioDriverType_ALSA:
|
---|
5274 | # endif
|
---|
5275 | # ifdef VBOX_WITH_PULSE
|
---|
5276 | case AudioDriverType_Pulse:
|
---|
5277 | # endif
|
---|
5278 | #endif /* RT_OS_LINUX */
|
---|
5279 | #if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
|
---|
5280 | case AudioDriverType_OSS:
|
---|
5281 | #endif
|
---|
5282 | #ifdef RT_OS_FREEBSD
|
---|
5283 | # ifdef VBOX_WITH_PULSE
|
---|
5284 | case AudioDriverType_Pulse:
|
---|
5285 | # endif
|
---|
5286 | #endif
|
---|
5287 | #ifdef RT_OS_DARWIN
|
---|
5288 | case AudioDriverType_CoreAudio:
|
---|
5289 | #endif
|
---|
5290 | #ifdef RT_OS_OS2
|
---|
5291 | case AudioDriverType_MMPM:
|
---|
5292 | #endif
|
---|
5293 | return true;
|
---|
5294 | }
|
---|
5295 |
|
---|
5296 | return false;
|
---|
5297 | }
|
---|
5298 |
|
---|
5299 | /**
|
---|
5300 | * Returns the AudioDriverType_* which should be used by default on this
|
---|
5301 | * host platform. On Linux, this will check at runtime whether PulseAudio
|
---|
5302 | * or ALSA are actually supported on the first call.
|
---|
5303 | * @return
|
---|
5304 | */
|
---|
5305 | /*static*/
|
---|
5306 | AudioDriverType_T MachineConfigFile::getHostDefaultAudioDriver()
|
---|
5307 | {
|
---|
5308 | #if defined(RT_OS_WINDOWS)
|
---|
5309 | # ifdef VBOX_WITH_WINMM
|
---|
5310 | return AudioDriverType_WinMM;
|
---|
5311 | # else /* VBOX_WITH_WINMM */
|
---|
5312 | return AudioDriverType_DirectSound;
|
---|
5313 | # endif /* !VBOX_WITH_WINMM */
|
---|
5314 | #elif defined(RT_OS_SOLARIS)
|
---|
5315 | return AudioDriverType_SolAudio;
|
---|
5316 | #elif defined(RT_OS_LINUX)
|
---|
5317 | // on Linux, we need to check at runtime what's actually supported...
|
---|
5318 | static RTCLockMtx s_mtx;
|
---|
5319 | static AudioDriverType_T s_linuxDriver = -1;
|
---|
5320 | RTCLock lock(s_mtx);
|
---|
5321 | if (s_linuxDriver == (AudioDriverType_T)-1)
|
---|
5322 | {
|
---|
5323 | # if defined(VBOX_WITH_PULSE)
|
---|
5324 | /* Check for the pulse library & that the pulse audio daemon is running. */
|
---|
5325 | if (RTProcIsRunningByName("pulseaudio") &&
|
---|
5326 | RTLdrIsLoadable("libpulse.so.0"))
|
---|
5327 | s_linuxDriver = AudioDriverType_Pulse;
|
---|
5328 | else
|
---|
5329 | # endif /* VBOX_WITH_PULSE */
|
---|
5330 | # if defined(VBOX_WITH_ALSA)
|
---|
5331 | /* Check if we can load the ALSA library */
|
---|
5332 | if (RTLdrIsLoadable("libasound.so.2"))
|
---|
5333 | s_linuxDriver = AudioDriverType_ALSA;
|
---|
5334 | else
|
---|
5335 | # endif /* VBOX_WITH_ALSA */
|
---|
5336 | s_linuxDriver = AudioDriverType_OSS;
|
---|
5337 | }
|
---|
5338 | return s_linuxDriver;
|
---|
5339 | // end elif defined(RT_OS_LINUX)
|
---|
5340 | #elif defined(RT_OS_DARWIN)
|
---|
5341 | return AudioDriverType_CoreAudio;
|
---|
5342 | #elif defined(RT_OS_OS2)
|
---|
5343 | return AudioDriverType_MMPM;
|
---|
5344 | #elif defined(RT_OS_FREEBSD)
|
---|
5345 | return AudioDriverType_OSS;
|
---|
5346 | #else
|
---|
5347 | return AudioDriverType_Null;
|
---|
5348 | #endif
|
---|
5349 | }
|
---|
5350 |
|
---|
5351 | /**
|
---|
5352 | * Called from write() before calling ConfigFileBase::createStubDocument().
|
---|
5353 | * This adjusts the settings version in m->sv if incompatible settings require
|
---|
5354 | * a settings bump, whereas otherwise we try to preserve the settings version
|
---|
5355 | * to avoid breaking compatibility with older versions.
|
---|
5356 | *
|
---|
5357 | * We do the checks in here in reverse order: newest first, oldest last, so
|
---|
5358 | * that we avoid unnecessary checks since some of these are expensive.
|
---|
5359 | */
|
---|
5360 | void MachineConfigFile::bumpSettingsVersionIfNeeded()
|
---|
5361 | {
|
---|
5362 | if (m->sv < SettingsVersion_v1_15)
|
---|
5363 | {
|
---|
5364 | /*
|
---|
5365 | * Check whether the hotpluggable flag of all storage devices differs
|
---|
5366 | * from the default for old settings.
|
---|
5367 | * AHCI ports are hotpluggable by default every other device is not.
|
---|
5368 | */
|
---|
5369 | for (StorageControllersList::const_iterator it = storageMachine.llStorageControllers.begin();
|
---|
5370 | it != storageMachine.llStorageControllers.end();
|
---|
5371 | ++it)
|
---|
5372 | {
|
---|
5373 | bool fSettingsBumped = false;
|
---|
5374 | const StorageController &sctl = *it;
|
---|
5375 |
|
---|
5376 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
5377 | it2 != sctl.llAttachedDevices.end();
|
---|
5378 | ++it2)
|
---|
5379 | {
|
---|
5380 | const AttachedDevice &att = *it2;
|
---|
5381 |
|
---|
5382 | if ( ( att.fHotPluggable
|
---|
5383 | && sctl.controllerType != StorageControllerType_IntelAhci)
|
---|
5384 | || ( !att.fHotPluggable
|
---|
5385 | && sctl.controllerType == StorageControllerType_IntelAhci))
|
---|
5386 | {
|
---|
5387 | m->sv = SettingsVersion_v1_15;
|
---|
5388 | fSettingsBumped = true;
|
---|
5389 | break;
|
---|
5390 | }
|
---|
5391 | }
|
---|
5392 |
|
---|
5393 | /* Abort early if possible. */
|
---|
5394 | if (fSettingsBumped)
|
---|
5395 | break;
|
---|
5396 | }
|
---|
5397 | }
|
---|
5398 |
|
---|
5399 | if (m->sv < SettingsVersion_v1_14)
|
---|
5400 | {
|
---|
5401 | // VirtualBox 4.3 adds default frontend setting, graphics controller
|
---|
5402 | // setting, explicit long mode setting, video capturing and NAT networking.
|
---|
5403 | if ( !hardwareMachine.strDefaultFrontend.isEmpty()
|
---|
5404 | || hardwareMachine.graphicsControllerType != GraphicsControllerType_VBoxVGA
|
---|
5405 | || hardwareMachine.enmLongMode != Hardware::LongMode_Legacy
|
---|
5406 | || machineUserData.ovIcon.length() > 0
|
---|
5407 | || hardwareMachine.fVideoCaptureEnabled)
|
---|
5408 | {
|
---|
5409 | m->sv = SettingsVersion_v1_14;
|
---|
5410 | return;
|
---|
5411 | }
|
---|
5412 | NetworkAdaptersList::const_iterator netit;
|
---|
5413 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
5414 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
5415 | ++netit)
|
---|
5416 | {
|
---|
5417 | if (netit->mode == NetworkAttachmentType_NATNetwork)
|
---|
5418 | {
|
---|
5419 | m->sv = SettingsVersion_v1_14;
|
---|
5420 | break;
|
---|
5421 | }
|
---|
5422 | }
|
---|
5423 | }
|
---|
5424 |
|
---|
5425 | if (m->sv < SettingsVersion_v1_14)
|
---|
5426 | {
|
---|
5427 | unsigned cOhciCtrls = 0;
|
---|
5428 | unsigned cEhciCtrls = 0;
|
---|
5429 | bool fNonStdName = false;
|
---|
5430 |
|
---|
5431 | for (USBControllerList::const_iterator it = hardwareMachine.usbSettings.llUSBControllers.begin();
|
---|
5432 | it != hardwareMachine.usbSettings.llUSBControllers.end();
|
---|
5433 | ++it)
|
---|
5434 | {
|
---|
5435 | const USBController &ctrl = *it;
|
---|
5436 |
|
---|
5437 | switch (ctrl.enmType)
|
---|
5438 | {
|
---|
5439 | case USBControllerType_OHCI:
|
---|
5440 | cOhciCtrls++;
|
---|
5441 | if (ctrl.strName != "OHCI")
|
---|
5442 | fNonStdName = true;
|
---|
5443 | break;
|
---|
5444 | case USBControllerType_EHCI:
|
---|
5445 | cEhciCtrls++;
|
---|
5446 | if (ctrl.strName != "EHCI")
|
---|
5447 | fNonStdName = true;
|
---|
5448 | break;
|
---|
5449 | default:
|
---|
5450 | AssertMsgFailed(("Unknown USB controller type %d\n", ctrl.enmType));
|
---|
5451 | }
|
---|
5452 |
|
---|
5453 | /* Skip checking other controllers if the settings bump is necessary. */
|
---|
5454 | if (cOhciCtrls > 1 || cEhciCtrls > 1 || fNonStdName)
|
---|
5455 | {
|
---|
5456 | m->sv = SettingsVersion_v1_14;
|
---|
5457 | break;
|
---|
5458 | }
|
---|
5459 | }
|
---|
5460 | }
|
---|
5461 |
|
---|
5462 | if (m->sv < SettingsVersion_v1_13)
|
---|
5463 | {
|
---|
5464 | // VirtualBox 4.2 adds tracing, autostart, UUID in directory and groups.
|
---|
5465 | if ( !debugging.areDefaultSettings()
|
---|
5466 | || !autostart.areDefaultSettings()
|
---|
5467 | || machineUserData.fDirectoryIncludesUUID
|
---|
5468 | || machineUserData.llGroups.size() > 1
|
---|
5469 | || machineUserData.llGroups.front() != "/")
|
---|
5470 | m->sv = SettingsVersion_v1_13;
|
---|
5471 | }
|
---|
5472 |
|
---|
5473 | if (m->sv < SettingsVersion_v1_13)
|
---|
5474 | {
|
---|
5475 | // VirtualBox 4.2 changes the units for bandwidth group limits.
|
---|
5476 | for (BandwidthGroupList::const_iterator it = hardwareMachine.ioSettings.llBandwidthGroups.begin();
|
---|
5477 | it != hardwareMachine.ioSettings.llBandwidthGroups.end();
|
---|
5478 | ++it)
|
---|
5479 | {
|
---|
5480 | const BandwidthGroup &gr = *it;
|
---|
5481 | if (gr.cMaxBytesPerSec % _1M)
|
---|
5482 | {
|
---|
5483 | // Bump version if a limit cannot be expressed in megabytes
|
---|
5484 | m->sv = SettingsVersion_v1_13;
|
---|
5485 | break;
|
---|
5486 | }
|
---|
5487 | }
|
---|
5488 | }
|
---|
5489 |
|
---|
5490 | if (m->sv < SettingsVersion_v1_12)
|
---|
5491 | {
|
---|
5492 | // VirtualBox 4.1 adds PCI passthrough and emulated USB Smart Card reader
|
---|
5493 | if ( hardwareMachine.pciAttachments.size()
|
---|
5494 | || hardwareMachine.fEmulatedUSBCardReader)
|
---|
5495 | m->sv = SettingsVersion_v1_12;
|
---|
5496 | }
|
---|
5497 |
|
---|
5498 | if (m->sv < SettingsVersion_v1_12)
|
---|
5499 | {
|
---|
5500 | // VirtualBox 4.1 adds a promiscuous mode policy to the network
|
---|
5501 | // adapters and a generic network driver transport.
|
---|
5502 | NetworkAdaptersList::const_iterator netit;
|
---|
5503 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
5504 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
5505 | ++netit)
|
---|
5506 | {
|
---|
5507 | if ( netit->enmPromiscModePolicy != NetworkAdapterPromiscModePolicy_Deny
|
---|
5508 | || netit->mode == NetworkAttachmentType_Generic
|
---|
5509 | || !netit->strGenericDriver.isEmpty()
|
---|
5510 | || netit->genericProperties.size()
|
---|
5511 | )
|
---|
5512 | {
|
---|
5513 | m->sv = SettingsVersion_v1_12;
|
---|
5514 | break;
|
---|
5515 | }
|
---|
5516 | }
|
---|
5517 | }
|
---|
5518 |
|
---|
5519 | if (m->sv < SettingsVersion_v1_11)
|
---|
5520 | {
|
---|
5521 | // VirtualBox 4.0 adds HD audio, CPU priorities, fault tolerance,
|
---|
5522 | // per-machine media registries, VRDE, JRockitVE, bandwidth groups,
|
---|
5523 | // ICH9 chipset
|
---|
5524 | if ( hardwareMachine.audioAdapter.controllerType == AudioControllerType_HDA
|
---|
5525 | || hardwareMachine.ulCpuExecutionCap != 100
|
---|
5526 | || machineUserData.enmFaultToleranceState != FaultToleranceState_Inactive
|
---|
5527 | || machineUserData.uFaultTolerancePort
|
---|
5528 | || machineUserData.uFaultToleranceInterval
|
---|
5529 | || !machineUserData.strFaultToleranceAddress.isEmpty()
|
---|
5530 | || mediaRegistry.llHardDisks.size()
|
---|
5531 | || mediaRegistry.llDvdImages.size()
|
---|
5532 | || mediaRegistry.llFloppyImages.size()
|
---|
5533 | || !hardwareMachine.vrdeSettings.strVrdeExtPack.isEmpty()
|
---|
5534 | || !hardwareMachine.vrdeSettings.strAuthLibrary.isEmpty()
|
---|
5535 | || machineUserData.strOsType == "JRockitVE"
|
---|
5536 | || hardwareMachine.ioSettings.llBandwidthGroups.size()
|
---|
5537 | || hardwareMachine.chipsetType == ChipsetType_ICH9
|
---|
5538 | )
|
---|
5539 | m->sv = SettingsVersion_v1_11;
|
---|
5540 | }
|
---|
5541 |
|
---|
5542 | if (m->sv < SettingsVersion_v1_10)
|
---|
5543 | {
|
---|
5544 | /* If the properties contain elements other than "TCP/Ports" and "TCP/Address",
|
---|
5545 | * then increase the version to at least VBox 3.2, which can have video channel properties.
|
---|
5546 | */
|
---|
5547 | unsigned cOldProperties = 0;
|
---|
5548 |
|
---|
5549 | StringsMap::const_iterator it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Ports");
|
---|
5550 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
5551 | cOldProperties++;
|
---|
5552 | it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Address");
|
---|
5553 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
5554 | cOldProperties++;
|
---|
5555 |
|
---|
5556 | if (hardwareMachine.vrdeSettings.mapProperties.size() != cOldProperties)
|
---|
5557 | m->sv = SettingsVersion_v1_10;
|
---|
5558 | }
|
---|
5559 |
|
---|
5560 | if (m->sv < SettingsVersion_v1_11)
|
---|
5561 | {
|
---|
5562 | /* If the properties contain elements other than "TCP/Ports", "TCP/Address",
|
---|
5563 | * "VideoChannel/Enabled" and "VideoChannel/Quality" then increase the version to VBox 4.0.
|
---|
5564 | */
|
---|
5565 | unsigned cOldProperties = 0;
|
---|
5566 |
|
---|
5567 | StringsMap::const_iterator it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Ports");
|
---|
5568 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
5569 | cOldProperties++;
|
---|
5570 | it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Address");
|
---|
5571 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
5572 | cOldProperties++;
|
---|
5573 | it = hardwareMachine.vrdeSettings.mapProperties.find("VideoChannel/Enabled");
|
---|
5574 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
5575 | cOldProperties++;
|
---|
5576 | it = hardwareMachine.vrdeSettings.mapProperties.find("VideoChannel/Quality");
|
---|
5577 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
5578 | cOldProperties++;
|
---|
5579 |
|
---|
5580 | if (hardwareMachine.vrdeSettings.mapProperties.size() != cOldProperties)
|
---|
5581 | m->sv = SettingsVersion_v1_11;
|
---|
5582 | }
|
---|
5583 |
|
---|
5584 | // settings version 1.9 is required if there is not exactly one DVD
|
---|
5585 | // or more than one floppy drive present or the DVD is not at the secondary
|
---|
5586 | // master; this check is a bit more complicated
|
---|
5587 | //
|
---|
5588 | // settings version 1.10 is required if the host cache should be disabled
|
---|
5589 | //
|
---|
5590 | // settings version 1.11 is required for bandwidth limits and if more than
|
---|
5591 | // one controller of each type is present.
|
---|
5592 | if (m->sv < SettingsVersion_v1_11)
|
---|
5593 | {
|
---|
5594 | // count attached DVDs and floppies (only if < v1.9)
|
---|
5595 | size_t cDVDs = 0;
|
---|
5596 | size_t cFloppies = 0;
|
---|
5597 |
|
---|
5598 | // count storage controllers (if < v1.11)
|
---|
5599 | size_t cSata = 0;
|
---|
5600 | size_t cScsiLsi = 0;
|
---|
5601 | size_t cScsiBuslogic = 0;
|
---|
5602 | size_t cSas = 0;
|
---|
5603 | size_t cIde = 0;
|
---|
5604 | size_t cFloppy = 0;
|
---|
5605 |
|
---|
5606 | // need to run thru all the storage controllers and attached devices to figure this out
|
---|
5607 | for (StorageControllersList::const_iterator it = storageMachine.llStorageControllers.begin();
|
---|
5608 | it != storageMachine.llStorageControllers.end();
|
---|
5609 | ++it)
|
---|
5610 | {
|
---|
5611 | const StorageController &sctl = *it;
|
---|
5612 |
|
---|
5613 | // count storage controllers of each type; 1.11 is required if more than one
|
---|
5614 | // controller of one type is present
|
---|
5615 | switch (sctl.storageBus)
|
---|
5616 | {
|
---|
5617 | case StorageBus_IDE:
|
---|
5618 | cIde++;
|
---|
5619 | break;
|
---|
5620 | case StorageBus_SATA:
|
---|
5621 | cSata++;
|
---|
5622 | break;
|
---|
5623 | case StorageBus_SAS:
|
---|
5624 | cSas++;
|
---|
5625 | break;
|
---|
5626 | case StorageBus_SCSI:
|
---|
5627 | if (sctl.controllerType == StorageControllerType_LsiLogic)
|
---|
5628 | cScsiLsi++;
|
---|
5629 | else
|
---|
5630 | cScsiBuslogic++;
|
---|
5631 | break;
|
---|
5632 | case StorageBus_Floppy:
|
---|
5633 | cFloppy++;
|
---|
5634 | break;
|
---|
5635 | default:
|
---|
5636 | // Do nothing
|
---|
5637 | break;
|
---|
5638 | }
|
---|
5639 |
|
---|
5640 | if ( cSata > 1
|
---|
5641 | || cScsiLsi > 1
|
---|
5642 | || cScsiBuslogic > 1
|
---|
5643 | || cSas > 1
|
---|
5644 | || cIde > 1
|
---|
5645 | || cFloppy > 1)
|
---|
5646 | {
|
---|
5647 | m->sv = SettingsVersion_v1_11;
|
---|
5648 | break; // abort the loop -- we will not raise the version further
|
---|
5649 | }
|
---|
5650 |
|
---|
5651 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
5652 | it2 != sctl.llAttachedDevices.end();
|
---|
5653 | ++it2)
|
---|
5654 | {
|
---|
5655 | const AttachedDevice &att = *it2;
|
---|
5656 |
|
---|
5657 | // Bandwidth limitations are new in VirtualBox 4.0 (1.11)
|
---|
5658 | if (m->sv < SettingsVersion_v1_11)
|
---|
5659 | {
|
---|
5660 | if (att.strBwGroup.length() != 0)
|
---|
5661 | {
|
---|
5662 | m->sv = SettingsVersion_v1_11;
|
---|
5663 | break; // abort the loop -- we will not raise the version further
|
---|
5664 | }
|
---|
5665 | }
|
---|
5666 |
|
---|
5667 | // disabling the host IO cache requires settings version 1.10
|
---|
5668 | if ( (m->sv < SettingsVersion_v1_10)
|
---|
5669 | && (!sctl.fUseHostIOCache)
|
---|
5670 | )
|
---|
5671 | m->sv = SettingsVersion_v1_10;
|
---|
5672 |
|
---|
5673 | // we can only write the StorageController/@Instance attribute with v1.9
|
---|
5674 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
5675 | && (sctl.ulInstance != 0)
|
---|
5676 | )
|
---|
5677 | m->sv = SettingsVersion_v1_9;
|
---|
5678 |
|
---|
5679 | if (m->sv < SettingsVersion_v1_9)
|
---|
5680 | {
|
---|
5681 | if (att.deviceType == DeviceType_DVD)
|
---|
5682 | {
|
---|
5683 | if ( (sctl.storageBus != StorageBus_IDE) // DVD at bus other than DVD?
|
---|
5684 | || (att.lPort != 1) // DVDs not at secondary master?
|
---|
5685 | || (att.lDevice != 0)
|
---|
5686 | )
|
---|
5687 | m->sv = SettingsVersion_v1_9;
|
---|
5688 |
|
---|
5689 | ++cDVDs;
|
---|
5690 | }
|
---|
5691 | else if (att.deviceType == DeviceType_Floppy)
|
---|
5692 | ++cFloppies;
|
---|
5693 | }
|
---|
5694 | }
|
---|
5695 |
|
---|
5696 | if (m->sv >= SettingsVersion_v1_11)
|
---|
5697 | break; // abort the loop -- we will not raise the version further
|
---|
5698 | }
|
---|
5699 |
|
---|
5700 | // VirtualBox before 3.1 had zero or one floppy and exactly one DVD,
|
---|
5701 | // so any deviation from that will require settings version 1.9
|
---|
5702 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
5703 | && ( (cDVDs != 1)
|
---|
5704 | || (cFloppies > 1)
|
---|
5705 | )
|
---|
5706 | )
|
---|
5707 | m->sv = SettingsVersion_v1_9;
|
---|
5708 | }
|
---|
5709 |
|
---|
5710 | // VirtualBox 3.2: Check for non default I/O settings
|
---|
5711 | if (m->sv < SettingsVersion_v1_10)
|
---|
5712 | {
|
---|
5713 | if ( (hardwareMachine.ioSettings.fIOCacheEnabled != true)
|
---|
5714 | || (hardwareMachine.ioSettings.ulIOCacheSize != 5)
|
---|
5715 | // and page fusion
|
---|
5716 | || (hardwareMachine.fPageFusionEnabled)
|
---|
5717 | // and CPU hotplug, RTC timezone control, HID type and HPET
|
---|
5718 | || machineUserData.fRTCUseUTC
|
---|
5719 | || hardwareMachine.fCpuHotPlug
|
---|
5720 | || hardwareMachine.pointingHIDType != PointingHIDType_PS2Mouse
|
---|
5721 | || hardwareMachine.keyboardHIDType != KeyboardHIDType_PS2Keyboard
|
---|
5722 | || hardwareMachine.fHPETEnabled
|
---|
5723 | )
|
---|
5724 | m->sv = SettingsVersion_v1_10;
|
---|
5725 | }
|
---|
5726 |
|
---|
5727 | // VirtualBox 3.2 adds NAT and boot priority to the NIC config in Main
|
---|
5728 | // VirtualBox 4.0 adds network bandwitdth
|
---|
5729 | if (m->sv < SettingsVersion_v1_11)
|
---|
5730 | {
|
---|
5731 | NetworkAdaptersList::const_iterator netit;
|
---|
5732 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
5733 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
5734 | ++netit)
|
---|
5735 | {
|
---|
5736 | if ( (m->sv < SettingsVersion_v1_12)
|
---|
5737 | && (netit->strBandwidthGroup.isNotEmpty())
|
---|
5738 | )
|
---|
5739 | {
|
---|
5740 | /* New in VirtualBox 4.1 */
|
---|
5741 | m->sv = SettingsVersion_v1_12;
|
---|
5742 | break;
|
---|
5743 | }
|
---|
5744 | else if ( (m->sv < SettingsVersion_v1_10)
|
---|
5745 | && (netit->fEnabled)
|
---|
5746 | && (netit->mode == NetworkAttachmentType_NAT)
|
---|
5747 | && ( netit->nat.u32Mtu != 0
|
---|
5748 | || netit->nat.u32SockRcv != 0
|
---|
5749 | || netit->nat.u32SockSnd != 0
|
---|
5750 | || netit->nat.u32TcpRcv != 0
|
---|
5751 | || netit->nat.u32TcpSnd != 0
|
---|
5752 | || !netit->nat.fDNSPassDomain
|
---|
5753 | || netit->nat.fDNSProxy
|
---|
5754 | || netit->nat.fDNSUseHostResolver
|
---|
5755 | || netit->nat.fAliasLog
|
---|
5756 | || netit->nat.fAliasProxyOnly
|
---|
5757 | || netit->nat.fAliasUseSamePorts
|
---|
5758 | || netit->nat.strTFTPPrefix.length()
|
---|
5759 | || netit->nat.strTFTPBootFile.length()
|
---|
5760 | || netit->nat.strTFTPNextServer.length()
|
---|
5761 | || netit->nat.llRules.size()
|
---|
5762 | )
|
---|
5763 | )
|
---|
5764 | {
|
---|
5765 | m->sv = SettingsVersion_v1_10;
|
---|
5766 | // no break because we still might need v1.11 above
|
---|
5767 | }
|
---|
5768 | else if ( (m->sv < SettingsVersion_v1_10)
|
---|
5769 | && (netit->fEnabled)
|
---|
5770 | && (netit->ulBootPriority != 0)
|
---|
5771 | )
|
---|
5772 | {
|
---|
5773 | m->sv = SettingsVersion_v1_10;
|
---|
5774 | // no break because we still might need v1.11 above
|
---|
5775 | }
|
---|
5776 | }
|
---|
5777 | }
|
---|
5778 |
|
---|
5779 | // all the following require settings version 1.9
|
---|
5780 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
5781 | && ( (hardwareMachine.firmwareType >= FirmwareType_EFI)
|
---|
5782 | || machineUserData.fTeleporterEnabled
|
---|
5783 | || machineUserData.uTeleporterPort
|
---|
5784 | || !machineUserData.strTeleporterAddress.isEmpty()
|
---|
5785 | || !machineUserData.strTeleporterPassword.isEmpty()
|
---|
5786 | || (!hardwareMachine.uuid.isZero() && hardwareMachine.uuid.isValid())
|
---|
5787 | )
|
---|
5788 | )
|
---|
5789 | m->sv = SettingsVersion_v1_9;
|
---|
5790 |
|
---|
5791 | // "accelerate 2d video" requires settings version 1.8
|
---|
5792 | if ( (m->sv < SettingsVersion_v1_8)
|
---|
5793 | && (hardwareMachine.fAccelerate2DVideo)
|
---|
5794 | )
|
---|
5795 | m->sv = SettingsVersion_v1_8;
|
---|
5796 |
|
---|
5797 | // The hardware versions other than "1" requires settings version 1.4 (2.1+).
|
---|
5798 | if ( m->sv < SettingsVersion_v1_4
|
---|
5799 | && hardwareMachine.strVersion != "1"
|
---|
5800 | )
|
---|
5801 | m->sv = SettingsVersion_v1_4;
|
---|
5802 | }
|
---|
5803 |
|
---|
5804 | /**
|
---|
5805 | * Called from Main code to write a machine config file to disk. This builds a DOM tree from
|
---|
5806 | * the member variables and then writes the XML file; it throws xml::Error instances on errors,
|
---|
5807 | * in particular if the file cannot be written.
|
---|
5808 | */
|
---|
5809 | void MachineConfigFile::write(const com::Utf8Str &strFilename)
|
---|
5810 | {
|
---|
5811 | try
|
---|
5812 | {
|
---|
5813 | // createStubDocument() sets the settings version to at least 1.7; however,
|
---|
5814 | // we might need to enfore a later settings version if incompatible settings
|
---|
5815 | // are present:
|
---|
5816 | bumpSettingsVersionIfNeeded();
|
---|
5817 |
|
---|
5818 | m->strFilename = strFilename;
|
---|
5819 | createStubDocument();
|
---|
5820 |
|
---|
5821 | xml::ElementNode *pelmMachine = m->pelmRoot->createChild("Machine");
|
---|
5822 | buildMachineXML(*pelmMachine,
|
---|
5823 | MachineConfigFile::BuildMachineXML_IncludeSnapshots
|
---|
5824 | | MachineConfigFile::BuildMachineXML_MediaRegistry,
|
---|
5825 | // but not BuildMachineXML_WriteVBoxVersionAttribute
|
---|
5826 | NULL); /* pllElementsWithUuidAttributes */
|
---|
5827 |
|
---|
5828 | // now go write the XML
|
---|
5829 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
5830 | writer.write(m->strFilename.c_str(), true /*fSafe*/);
|
---|
5831 |
|
---|
5832 | m->fFileExists = true;
|
---|
5833 | clearDocument();
|
---|
5834 | }
|
---|
5835 | catch (...)
|
---|
5836 | {
|
---|
5837 | clearDocument();
|
---|
5838 | throw;
|
---|
5839 | }
|
---|
5840 | }
|
---|