1 | /* $Id: Settings.cpp 105016 2024-06-25 10:28:21Z 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 | * 5) You _must_ update xml/VirtualBox-settings.xsd to contain the new tags and attributes.
|
---|
56 | * Check that settings file from before and after your change are validating properly.
|
---|
57 | * Use "kmk testvalidsettings", it should not find any files which don't validate.
|
---|
58 | */
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
62 | *
|
---|
63 | * This file is part of VirtualBox base platform packages, as
|
---|
64 | * available from https://www.virtualbox.org.
|
---|
65 | *
|
---|
66 | * This program is free software; you can redistribute it and/or
|
---|
67 | * modify it under the terms of the GNU General Public License
|
---|
68 | * as published by the Free Software Foundation, in version 3 of the
|
---|
69 | * License.
|
---|
70 | *
|
---|
71 | * This program is distributed in the hope that it will be useful, but
|
---|
72 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
73 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
74 | * General Public License for more details.
|
---|
75 | *
|
---|
76 | * You should have received a copy of the GNU General Public License
|
---|
77 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
78 | *
|
---|
79 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
80 | */
|
---|
81 |
|
---|
82 | #define LOG_GROUP LOG_GROUP_MAIN
|
---|
83 | #include "VBox/com/string.h"
|
---|
84 | #include "VBox/settings.h"
|
---|
85 | #include <iprt/base64.h>
|
---|
86 | #include <iprt/cpp/lock.h>
|
---|
87 | #include <iprt/cpp/utils.h>
|
---|
88 | #include <iprt/cpp/xml.h>
|
---|
89 | #include <iprt/ctype.h>
|
---|
90 | #include <iprt/err.h>
|
---|
91 | #include <iprt/file.h>
|
---|
92 | #include <iprt/ldr.h>
|
---|
93 | #include <iprt/process.h>
|
---|
94 | #include <iprt/stream.h>
|
---|
95 | #ifdef RT_OS_WINDOWS
|
---|
96 | # include <iprt/system.h> /* For RTSystemGetNtVersion() / RTSYSTEM_MAKE_NT_VERSION. */
|
---|
97 | #endif
|
---|
98 | #include <iprt/uri.h>
|
---|
99 |
|
---|
100 | // Guest Properties validation.
|
---|
101 | #include "VBox/HostServices/GuestPropertySvc.h"
|
---|
102 |
|
---|
103 | // generated header
|
---|
104 | #include "SchemaDefs.h"
|
---|
105 |
|
---|
106 | #include "HashedPw.h"
|
---|
107 | #include "LoggingNew.h"
|
---|
108 |
|
---|
109 | using namespace com;
|
---|
110 | using namespace settings;
|
---|
111 |
|
---|
112 | ////////////////////////////////////////////////////////////////////////////////
|
---|
113 | //
|
---|
114 | // Defines
|
---|
115 | //
|
---|
116 | ////////////////////////////////////////////////////////////////////////////////
|
---|
117 |
|
---|
118 | /** VirtualBox XML settings namespace */
|
---|
119 | #define VBOX_XML_NAMESPACE "http://www.virtualbox.org/"
|
---|
120 |
|
---|
121 | /** VirtualBox XML schema location (relative URI) */
|
---|
122 | #define VBOX_XML_SCHEMA "VirtualBox-settings.xsd"
|
---|
123 |
|
---|
124 | /** VirtualBox XML settings version number substring ("x.y") */
|
---|
125 | #define VBOX_XML_VERSION "1.12"
|
---|
126 |
|
---|
127 | /** VirtualBox OVF settings import default version number substring ("x.y").
|
---|
128 | *
|
---|
129 | * Think twice before changing this, as all VirtualBox versions before 5.1
|
---|
130 | * wrote the settings version when exporting, but totally ignored it on
|
---|
131 | * importing (while it should have been a mandatory attribute), so 3rd party
|
---|
132 | * software out there creates OVF files with the VirtualBox specific settings
|
---|
133 | * but lacking the version attribute. This shouldn't happen any more, but
|
---|
134 | * breaking existing OVF files isn't nice. */
|
---|
135 | #define VBOX_XML_IMPORT_VERSION "1.15"
|
---|
136 |
|
---|
137 | /** VirtualBox XML settings version platform substring */
|
---|
138 | #if defined (RT_OS_DARWIN)
|
---|
139 | # define VBOX_XML_PLATFORM "macosx"
|
---|
140 | #elif defined (RT_OS_FREEBSD)
|
---|
141 | # define VBOX_XML_PLATFORM "freebsd"
|
---|
142 | #elif defined (RT_OS_LINUX)
|
---|
143 | # define VBOX_XML_PLATFORM "linux"
|
---|
144 | #elif defined (RT_OS_NETBSD)
|
---|
145 | # define VBOX_XML_PLATFORM "netbsd"
|
---|
146 | #elif defined (RT_OS_OPENBSD)
|
---|
147 | # define VBOX_XML_PLATFORM "openbsd"
|
---|
148 | #elif defined (RT_OS_OS2)
|
---|
149 | # define VBOX_XML_PLATFORM "os2"
|
---|
150 | #elif defined (RT_OS_SOLARIS)
|
---|
151 | # define VBOX_XML_PLATFORM "solaris"
|
---|
152 | #elif defined (RT_OS_WINDOWS)
|
---|
153 | # define VBOX_XML_PLATFORM "windows"
|
---|
154 | #else
|
---|
155 | # error Unsupported platform!
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | /** VirtualBox XML settings full version string ("x.y-platform") */
|
---|
159 | #define VBOX_XML_VERSION_FULL VBOX_XML_VERSION "-" VBOX_XML_PLATFORM
|
---|
160 |
|
---|
161 | /** VirtualBox OVF import default settings full version string ("x.y-platform") */
|
---|
162 | #define VBOX_XML_IMPORT_VERSION_FULL VBOX_XML_IMPORT_VERSION "-" VBOX_XML_PLATFORM
|
---|
163 |
|
---|
164 | ////////////////////////////////////////////////////////////////////////////////
|
---|
165 | //
|
---|
166 | // Internal data
|
---|
167 | //
|
---|
168 | ////////////////////////////////////////////////////////////////////////////////
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Opaque data structore for ConfigFileBase (only declared
|
---|
172 | * in header, defined only here).
|
---|
173 | */
|
---|
174 |
|
---|
175 | struct ConfigFileBase::Data
|
---|
176 | {
|
---|
177 | Data()
|
---|
178 | : pDoc(NULL),
|
---|
179 | pelmRoot(NULL),
|
---|
180 | sv(SettingsVersion_Null),
|
---|
181 | svRead(SettingsVersion_Null)
|
---|
182 | {}
|
---|
183 |
|
---|
184 | ~Data()
|
---|
185 | {
|
---|
186 | cleanup();
|
---|
187 | }
|
---|
188 |
|
---|
189 | RTCString strFilename;
|
---|
190 | bool fFileExists;
|
---|
191 |
|
---|
192 | xml::Document *pDoc;
|
---|
193 | xml::ElementNode *pelmRoot;
|
---|
194 |
|
---|
195 | com::Utf8Str strSettingsVersionFull; // e.g. "1.7-linux"
|
---|
196 | SettingsVersion_T sv; // e.g. SettingsVersion_v1_7
|
---|
197 |
|
---|
198 | SettingsVersion_T svRead; // settings version that the original file had when it was read,
|
---|
199 | // or SettingsVersion_Null if none
|
---|
200 |
|
---|
201 | void copyFrom(const Data &d)
|
---|
202 | {
|
---|
203 | strFilename = d.strFilename;
|
---|
204 | fFileExists = d.fFileExists;
|
---|
205 | strSettingsVersionFull = d.strSettingsVersionFull;
|
---|
206 | sv = d.sv;
|
---|
207 | svRead = d.svRead;
|
---|
208 | }
|
---|
209 |
|
---|
210 | void cleanup()
|
---|
211 | {
|
---|
212 | if (pDoc)
|
---|
213 | {
|
---|
214 | delete pDoc;
|
---|
215 | pDoc = NULL;
|
---|
216 | pelmRoot = NULL;
|
---|
217 | }
|
---|
218 | }
|
---|
219 | };
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Private exception class (not in the header file) that makes
|
---|
223 | * throwing xml::LogicError instances easier. That class is public
|
---|
224 | * and should be caught by client code.
|
---|
225 | */
|
---|
226 | class settings::ConfigFileError : public xml::LogicError
|
---|
227 | {
|
---|
228 | public:
|
---|
229 | ConfigFileError(const ConfigFileBase *file,
|
---|
230 | const xml::Node *pNode,
|
---|
231 | const char *pcszFormat, ...)
|
---|
232 | : xml::LogicError()
|
---|
233 | {
|
---|
234 | va_list args;
|
---|
235 | va_start(args, pcszFormat);
|
---|
236 | Utf8Str strWhat(pcszFormat, args);
|
---|
237 | va_end(args);
|
---|
238 |
|
---|
239 | Utf8Str strLine;
|
---|
240 | if (pNode)
|
---|
241 | strLine = Utf8StrFmt(" (line %RU32)", pNode->getLineNumber());
|
---|
242 |
|
---|
243 | const char *pcsz = strLine.c_str();
|
---|
244 | Utf8StrFmt str(N_("Error in %s%s -- %s"),
|
---|
245 | file->m->strFilename.c_str(),
|
---|
246 | (pcsz) ? pcsz : "",
|
---|
247 | strWhat.c_str());
|
---|
248 |
|
---|
249 | setWhat(str.c_str());
|
---|
250 | }
|
---|
251 | };
|
---|
252 |
|
---|
253 | ////////////////////////////////////////////////////////////////////////////////
|
---|
254 | //
|
---|
255 | // ConfigFileBase
|
---|
256 | //
|
---|
257 | ////////////////////////////////////////////////////////////////////////////////
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Constructor. Allocates the XML internals, parses the XML file if
|
---|
261 | * pstrFilename is != NULL and reads the settings version from it.
|
---|
262 | * @param pstrFilename
|
---|
263 | */
|
---|
264 | ConfigFileBase::ConfigFileBase(const com::Utf8Str *pstrFilename)
|
---|
265 | : m(new Data)
|
---|
266 | {
|
---|
267 | m->fFileExists = false;
|
---|
268 |
|
---|
269 | if (pstrFilename)
|
---|
270 | {
|
---|
271 | try
|
---|
272 | {
|
---|
273 | // reading existing settings file:
|
---|
274 | m->strFilename = *pstrFilename;
|
---|
275 |
|
---|
276 | xml::XmlFileParser parser;
|
---|
277 | m->pDoc = new xml::Document;
|
---|
278 | parser.read(*pstrFilename,
|
---|
279 | *m->pDoc);
|
---|
280 |
|
---|
281 | m->fFileExists = true;
|
---|
282 |
|
---|
283 | m->pelmRoot = m->pDoc->getRootElement();
|
---|
284 | if (!m->pelmRoot || !m->pelmRoot->nameEquals("VirtualBox"))
|
---|
285 | throw ConfigFileError(this, m->pelmRoot, N_("Root element in VirtualBox settings files must be \"VirtualBox\""));
|
---|
286 |
|
---|
287 | if (!(m->pelmRoot->getAttributeValue("version", m->strSettingsVersionFull)))
|
---|
288 | throw ConfigFileError(this, m->pelmRoot, N_("Required VirtualBox/@version attribute is missing"));
|
---|
289 |
|
---|
290 | LogRel(("Loading settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
|
---|
291 |
|
---|
292 | m->sv = parseVersion(m->strSettingsVersionFull, m->pelmRoot);
|
---|
293 |
|
---|
294 | // remember the settings version we read in case it gets upgraded later,
|
---|
295 | // so we know when to make backups
|
---|
296 | m->svRead = m->sv;
|
---|
297 | }
|
---|
298 | catch(...)
|
---|
299 | {
|
---|
300 | /*
|
---|
301 | * The destructor is not called when an exception is thrown in the constructor,
|
---|
302 | * so we have to do the cleanup here.
|
---|
303 | */
|
---|
304 | delete m;
|
---|
305 | m = NULL;
|
---|
306 | throw;
|
---|
307 | }
|
---|
308 | }
|
---|
309 | else
|
---|
310 | {
|
---|
311 | // creating new settings file:
|
---|
312 | m->strSettingsVersionFull = VBOX_XML_VERSION_FULL;
|
---|
313 | m->sv = SettingsVersion_v1_12;
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | ConfigFileBase::ConfigFileBase(const ConfigFileBase &other)
|
---|
318 | : m(new Data)
|
---|
319 | {
|
---|
320 | copyBaseFrom(other);
|
---|
321 | m->strFilename = "";
|
---|
322 | m->fFileExists = false;
|
---|
323 | }
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Clean up.
|
---|
327 | */
|
---|
328 | ConfigFileBase::~ConfigFileBase()
|
---|
329 | {
|
---|
330 | if (m)
|
---|
331 | {
|
---|
332 | delete m;
|
---|
333 | m = NULL;
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Helper function to convert a MediaType enum value into string from.
|
---|
339 | * @param t
|
---|
340 | */
|
---|
341 | /*static*/
|
---|
342 | const char *ConfigFileBase::stringifyMediaType(MediaType t)
|
---|
343 | {
|
---|
344 | switch (t)
|
---|
345 | {
|
---|
346 | case HardDisk:
|
---|
347 | return "hard disk";
|
---|
348 | case DVDImage:
|
---|
349 | return "DVD";
|
---|
350 | case FloppyImage:
|
---|
351 | return "floppy";
|
---|
352 | default:
|
---|
353 | AssertMsgFailed(("media type %d\n", t));
|
---|
354 | return "UNKNOWN";
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | /**
|
---|
359 | * Helper function that parses a full version number.
|
---|
360 | *
|
---|
361 | * Allow future versions but fail if file is older than 1.6. Throws on errors.
|
---|
362 | * @returns settings version
|
---|
363 | * @param strVersion
|
---|
364 | * @param pElm
|
---|
365 | */
|
---|
366 | SettingsVersion_T ConfigFileBase::parseVersion(const Utf8Str &strVersion, const xml::ElementNode *pElm)
|
---|
367 | {
|
---|
368 | SettingsVersion_T sv = SettingsVersion_Null;
|
---|
369 | if (strVersion.length() > 3)
|
---|
370 | {
|
---|
371 | const char *pcsz = strVersion.c_str();
|
---|
372 |
|
---|
373 | uint32_t uMajor = 0;
|
---|
374 | char ch;
|
---|
375 | while ( (ch = *pcsz)
|
---|
376 | && RT_C_IS_DIGIT(ch) )
|
---|
377 | {
|
---|
378 | uMajor *= 10;
|
---|
379 | uMajor += (uint32_t)(ch - '0');
|
---|
380 | ++pcsz;
|
---|
381 | }
|
---|
382 |
|
---|
383 | uint32_t uMinor = 0;
|
---|
384 | if (ch == '.')
|
---|
385 | {
|
---|
386 | pcsz++;
|
---|
387 | while ( (ch = *pcsz)
|
---|
388 | && RT_C_IS_DIGIT(ch))
|
---|
389 | {
|
---|
390 | uMinor *= 10;
|
---|
391 | uMinor += (ULONG)(ch - '0');
|
---|
392 | ++pcsz;
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | if (uMajor == 1)
|
---|
397 | {
|
---|
398 | if (uMinor == 3)
|
---|
399 | sv = SettingsVersion_v1_3;
|
---|
400 | else if (uMinor == 4)
|
---|
401 | sv = SettingsVersion_v1_4;
|
---|
402 | else if (uMinor == 5)
|
---|
403 | sv = SettingsVersion_v1_5;
|
---|
404 | else if (uMinor == 6)
|
---|
405 | sv = SettingsVersion_v1_6;
|
---|
406 | else if (uMinor == 7)
|
---|
407 | sv = SettingsVersion_v1_7;
|
---|
408 | else if (uMinor == 8)
|
---|
409 | sv = SettingsVersion_v1_8;
|
---|
410 | else if (uMinor == 9)
|
---|
411 | sv = SettingsVersion_v1_9;
|
---|
412 | else if (uMinor == 10)
|
---|
413 | sv = SettingsVersion_v1_10;
|
---|
414 | else if (uMinor == 11)
|
---|
415 | sv = SettingsVersion_v1_11;
|
---|
416 | else if (uMinor == 12)
|
---|
417 | sv = SettingsVersion_v1_12;
|
---|
418 | else if (uMinor == 13)
|
---|
419 | sv = SettingsVersion_v1_13;
|
---|
420 | else if (uMinor == 14)
|
---|
421 | sv = SettingsVersion_v1_14;
|
---|
422 | else if (uMinor == 15)
|
---|
423 | sv = SettingsVersion_v1_15;
|
---|
424 | else if (uMinor == 16)
|
---|
425 | sv = SettingsVersion_v1_16;
|
---|
426 | else if (uMinor == 17)
|
---|
427 | sv = SettingsVersion_v1_17;
|
---|
428 | else if (uMinor == 18)
|
---|
429 | sv = SettingsVersion_v1_18;
|
---|
430 | else if (uMinor == 19)
|
---|
431 | sv = SettingsVersion_v1_19;
|
---|
432 | else if (uMinor == 20)
|
---|
433 | sv = SettingsVersion_v1_20;
|
---|
434 | else if (uMinor > 20)
|
---|
435 | sv = SettingsVersion_Future;
|
---|
436 | }
|
---|
437 | else if (uMajor > 1)
|
---|
438 | sv = SettingsVersion_Future;
|
---|
439 |
|
---|
440 | Log(("Parsed settings version %d.%d to enum value %d\n", uMajor, uMinor, sv));
|
---|
441 | }
|
---|
442 |
|
---|
443 | if (sv == SettingsVersion_Null)
|
---|
444 | throw ConfigFileError(this, pElm, N_("Cannot handle settings version '%s'"), strVersion.c_str());
|
---|
445 |
|
---|
446 | return sv;
|
---|
447 | }
|
---|
448 |
|
---|
449 | /**
|
---|
450 | * Helper function that parses a UUID in string form into
|
---|
451 | * a com::Guid item. Accepts UUIDs both with and without
|
---|
452 | * "{}" brackets. Throws on errors.
|
---|
453 | * @param guid
|
---|
454 | * @param strUUID
|
---|
455 | * @param pElm
|
---|
456 | */
|
---|
457 | void ConfigFileBase::parseUUID(Guid &guid,
|
---|
458 | const Utf8Str &strUUID,
|
---|
459 | const xml::ElementNode *pElm) const
|
---|
460 | {
|
---|
461 | guid = strUUID.c_str();
|
---|
462 | if (guid.isZero())
|
---|
463 | throw ConfigFileError(this, pElm, N_("UUID \"%s\" has zero format"), strUUID.c_str());
|
---|
464 | else if (!guid.isValid())
|
---|
465 | throw ConfigFileError(this, pElm, N_("UUID \"%s\" has invalid format"), strUUID.c_str());
|
---|
466 | }
|
---|
467 |
|
---|
468 | /**
|
---|
469 | * Parses the given string in str and attempts to treat it as an ISO
|
---|
470 | * date/time stamp to put into timestamp. Throws on errors.
|
---|
471 | * @param timestamp
|
---|
472 | * @param str
|
---|
473 | * @param pElm
|
---|
474 | */
|
---|
475 | void ConfigFileBase::parseTimestamp(RTTIMESPEC ×tamp,
|
---|
476 | const com::Utf8Str &str,
|
---|
477 | const xml::ElementNode *pElm) const
|
---|
478 | {
|
---|
479 | const char *pcsz = str.c_str();
|
---|
480 | // yyyy-mm-ddThh:mm:ss
|
---|
481 | // "2009-07-10T11:54:03Z"
|
---|
482 | // 01234567890123456789
|
---|
483 | // 1
|
---|
484 | if (str.length() > 19)
|
---|
485 | {
|
---|
486 | // timezone must either be unspecified or 'Z' for UTC
|
---|
487 | if ( (pcsz[19])
|
---|
488 | && (pcsz[19] != 'Z')
|
---|
489 | )
|
---|
490 | throw ConfigFileError(this, pElm, N_("Cannot handle ISO timestamp '%s': is not UTC date"), str.c_str());
|
---|
491 |
|
---|
492 | int32_t yyyy;
|
---|
493 | uint32_t mm, dd, hh, min, secs;
|
---|
494 | if ( (pcsz[4] == '-')
|
---|
495 | && (pcsz[7] == '-')
|
---|
496 | && (pcsz[10] == 'T')
|
---|
497 | && (pcsz[13] == ':')
|
---|
498 | && (pcsz[16] == ':')
|
---|
499 | )
|
---|
500 | {
|
---|
501 | int vrc;
|
---|
502 | if ( (RT_SUCCESS(vrc = RTStrToInt32Ex(pcsz, NULL, 0, &yyyy)))
|
---|
503 | // could theoretically be negative but let's assume that nobody
|
---|
504 | // created virtual machines before the Christian era
|
---|
505 | && (RT_SUCCESS(vrc = RTStrToUInt32Ex(pcsz + 5, NULL, 0, &mm)))
|
---|
506 | && (RT_SUCCESS(vrc = RTStrToUInt32Ex(pcsz + 8, NULL, 0, &dd)))
|
---|
507 | && (RT_SUCCESS(vrc = RTStrToUInt32Ex(pcsz + 11, NULL, 0, &hh)))
|
---|
508 | && (RT_SUCCESS(vrc = RTStrToUInt32Ex(pcsz + 14, NULL, 0, &min)))
|
---|
509 | && (RT_SUCCESS(vrc = RTStrToUInt32Ex(pcsz + 17, NULL, 0, &secs)))
|
---|
510 | )
|
---|
511 | {
|
---|
512 | RTTIME time =
|
---|
513 | {
|
---|
514 | yyyy,
|
---|
515 | (uint8_t)mm,
|
---|
516 | 0,
|
---|
517 | 0,
|
---|
518 | (uint8_t)dd,
|
---|
519 | (uint8_t)hh,
|
---|
520 | (uint8_t)min,
|
---|
521 | (uint8_t)secs,
|
---|
522 | 0,
|
---|
523 | RTTIME_FLAGS_TYPE_UTC,
|
---|
524 | 0
|
---|
525 | };
|
---|
526 | if (RTTimeNormalize(&time))
|
---|
527 | if (RTTimeImplode(×tamp, &time))
|
---|
528 | return;
|
---|
529 | }
|
---|
530 |
|
---|
531 | throw ConfigFileError(this, pElm, N_("Cannot parse ISO timestamp '%s': runtime error, %Rra"), str.c_str(), vrc);
|
---|
532 | }
|
---|
533 |
|
---|
534 | throw ConfigFileError(this, pElm, N_("Cannot parse ISO timestamp '%s': invalid format"), str.c_str());
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | /**
|
---|
539 | * Helper function that parses a Base64 formatted string into a binary blob.
|
---|
540 | * @param binary
|
---|
541 | * @param str
|
---|
542 | * @param pElm
|
---|
543 | */
|
---|
544 | void ConfigFileBase::parseBase64(IconBlob &binary,
|
---|
545 | const Utf8Str &str,
|
---|
546 | const xml::ElementNode *pElm) const
|
---|
547 | {
|
---|
548 | #define DECODE_STR_MAX _1M
|
---|
549 | const char* psz = str.c_str();
|
---|
550 | ssize_t cbOut = RTBase64DecodedSize(psz, NULL);
|
---|
551 | if (cbOut > DECODE_STR_MAX)
|
---|
552 | throw ConfigFileError(this, pElm, N_("Base64 encoded data too long (%d > %d)"), cbOut, DECODE_STR_MAX);
|
---|
553 | else if (cbOut < 0)
|
---|
554 | throw ConfigFileError(this, pElm, N_("Base64 encoded data '%s' invalid"), psz);
|
---|
555 | binary.resize((size_t)cbOut);
|
---|
556 | int vrc = VINF_SUCCESS;
|
---|
557 | if (cbOut)
|
---|
558 | vrc = RTBase64Decode(psz, &binary.front(), (size_t)cbOut, NULL, NULL);
|
---|
559 | if (RT_FAILURE(vrc))
|
---|
560 | {
|
---|
561 | binary.resize(0);
|
---|
562 | throw ConfigFileError(this, pElm, N_("Base64 encoded data could not be decoded (%Rrc)"), vrc);
|
---|
563 | }
|
---|
564 | }
|
---|
565 |
|
---|
566 | /**
|
---|
567 | * Helper to create a string for a RTTIMESPEC for writing out ISO timestamps.
|
---|
568 | * @param stamp
|
---|
569 | * @return
|
---|
570 | */
|
---|
571 | com::Utf8Str ConfigFileBase::stringifyTimestamp(const RTTIMESPEC &stamp) const
|
---|
572 | {
|
---|
573 | RTTIME time;
|
---|
574 | if (!RTTimeExplode(&time, &stamp))
|
---|
575 | throw ConfigFileError(this, NULL, N_("Timespec %lld ms is invalid"), RTTimeSpecGetMilli(&stamp));
|
---|
576 |
|
---|
577 | return Utf8StrFmt("%04u-%02u-%02uT%02u:%02u:%02uZ",
|
---|
578 | time.i32Year, time.u8Month, time.u8MonthDay,
|
---|
579 | time.u8Hour, time.u8Minute, time.u8Second);
|
---|
580 | }
|
---|
581 |
|
---|
582 | /**
|
---|
583 | * Helper to create a base64 encoded string out of a binary blob.
|
---|
584 | * @param str
|
---|
585 | * @param binary
|
---|
586 | * @throws std::bad_alloc and ConfigFileError
|
---|
587 | */
|
---|
588 | void ConfigFileBase::toBase64(com::Utf8Str &str, const IconBlob &binary) const
|
---|
589 | {
|
---|
590 | size_t cb = binary.size();
|
---|
591 | if (cb > 0)
|
---|
592 | {
|
---|
593 | size_t cchOut = RTBase64EncodedLength(cb);
|
---|
594 | str.reserve(cchOut + 1);
|
---|
595 | int vrc = RTBase64Encode(&binary.front(), cb, str.mutableRaw(), str.capacity(), NULL);
|
---|
596 | if (RT_FAILURE(vrc))
|
---|
597 | throw ConfigFileError(this, NULL, N_("Failed to convert binary data to base64 format (%Rrc)"), vrc);
|
---|
598 | str.jolt();
|
---|
599 | }
|
---|
600 | }
|
---|
601 |
|
---|
602 | /**
|
---|
603 | * Helper method to read in an ExtraData subtree and stores its contents
|
---|
604 | * in the given map of extradata items. Used for both main and machine
|
---|
605 | * extradata (MainConfigFile and MachineConfigFile).
|
---|
606 | * @param elmExtraData
|
---|
607 | * @param map
|
---|
608 | */
|
---|
609 | void ConfigFileBase::readExtraData(const xml::ElementNode &elmExtraData,
|
---|
610 | StringsMap &map)
|
---|
611 | {
|
---|
612 | xml::NodesLoop nlLevel4(elmExtraData);
|
---|
613 | const xml::ElementNode *pelmExtraDataItem;
|
---|
614 | while ((pelmExtraDataItem = nlLevel4.forAllNodes()))
|
---|
615 | {
|
---|
616 | if (pelmExtraDataItem->nameEquals("ExtraDataItem"))
|
---|
617 | {
|
---|
618 | // <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/>
|
---|
619 | Utf8Str strName, strValue;
|
---|
620 | if ( pelmExtraDataItem->getAttributeValue("name", strName)
|
---|
621 | && pelmExtraDataItem->getAttributeValue("value", strValue) )
|
---|
622 | map[strName] = strValue;
|
---|
623 | else
|
---|
624 | throw ConfigFileError(this, pelmExtraDataItem, N_("Required ExtraDataItem/@name or @value attribute is missing"));
|
---|
625 | }
|
---|
626 | }
|
---|
627 | }
|
---|
628 |
|
---|
629 | /**
|
---|
630 | * Reads \<USBDeviceFilter\> entries from under the given elmDeviceFilters node and
|
---|
631 | * stores them in the given linklist. This is in ConfigFileBase because it's used
|
---|
632 | * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
|
---|
633 | * filters).
|
---|
634 | * @param elmDeviceFilters
|
---|
635 | * @param ll
|
---|
636 | */
|
---|
637 | void ConfigFileBase::readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
|
---|
638 | USBDeviceFiltersList &ll)
|
---|
639 | {
|
---|
640 | xml::NodesLoop nl1(elmDeviceFilters, "DeviceFilter");
|
---|
641 | const xml::ElementNode *pelmLevel4Child;
|
---|
642 | while ((pelmLevel4Child = nl1.forAllNodes()))
|
---|
643 | {
|
---|
644 | USBDeviceFilter flt;
|
---|
645 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
646 | Utf8Str strAction;
|
---|
647 | if ( pelmLevel4Child->getAttributeValue("name", flt.strName)
|
---|
648 | && pelmLevel4Child->getAttributeValue("active", flt.fActive))
|
---|
649 | {
|
---|
650 | if (!pelmLevel4Child->getAttributeValue("vendorId", flt.strVendorId))
|
---|
651 | pelmLevel4Child->getAttributeValue("vendorid", flt.strVendorId); // used before 1.3
|
---|
652 | if (!pelmLevel4Child->getAttributeValue("productId", flt.strProductId))
|
---|
653 | pelmLevel4Child->getAttributeValue("productid", flt.strProductId); // used before 1.3
|
---|
654 | pelmLevel4Child->getAttributeValue("revision", flt.strRevision);
|
---|
655 | pelmLevel4Child->getAttributeValue("manufacturer", flt.strManufacturer);
|
---|
656 | pelmLevel4Child->getAttributeValue("product", flt.strProduct);
|
---|
657 | if (!pelmLevel4Child->getAttributeValue("serialNumber", flt.strSerialNumber))
|
---|
658 | pelmLevel4Child->getAttributeValue("serialnumber", flt.strSerialNumber); // used before 1.3
|
---|
659 | pelmLevel4Child->getAttributeValue("port", flt.strPort);
|
---|
660 |
|
---|
661 | // the next 2 are irrelevant for host USB objects
|
---|
662 | pelmLevel4Child->getAttributeValue("remote", flt.strRemote);
|
---|
663 | pelmLevel4Child->getAttributeValue("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
664 |
|
---|
665 | // action is only used with host USB objects
|
---|
666 | if (pelmLevel4Child->getAttributeValue("action", strAction))
|
---|
667 | {
|
---|
668 | if (strAction == "Ignore")
|
---|
669 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
670 | else if (strAction == "Hold")
|
---|
671 | flt.action = USBDeviceFilterAction_Hold;
|
---|
672 | else
|
---|
673 | throw ConfigFileError(this, pelmLevel4Child, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
|
---|
674 | }
|
---|
675 |
|
---|
676 | ll.push_back(flt);
|
---|
677 | }
|
---|
678 | }
|
---|
679 | }
|
---|
680 |
|
---|
681 | /**
|
---|
682 | * Reads a media registry entry from the main VirtualBox.xml file.
|
---|
683 | *
|
---|
684 | * Whereas the current media registry code is fairly straightforward, it was quite a mess
|
---|
685 | * with settings format before 1.4 (VirtualBox 2.0 used settings format 1.3). The elements
|
---|
686 | * in the media registry were much more inconsistent, and different elements were used
|
---|
687 | * depending on the type of device and image.
|
---|
688 | *
|
---|
689 | * @param t
|
---|
690 | * @param elmMedium
|
---|
691 | * @param med
|
---|
692 | */
|
---|
693 | void ConfigFileBase::readMediumOne(MediaType t,
|
---|
694 | const xml::ElementNode &elmMedium,
|
---|
695 | Medium &med)
|
---|
696 | {
|
---|
697 | // <HardDisk uuid="{5471ecdb-1ddb-4012-a801-6d98e226868b}" location="/mnt/innotek-unix/vdis/Windows XP.vdi" format="VDI" type="Normal">
|
---|
698 |
|
---|
699 | Utf8Str strUUID;
|
---|
700 | if (!elmMedium.getAttributeValue("uuid", strUUID))
|
---|
701 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName());
|
---|
702 |
|
---|
703 | parseUUID(med.uuid, strUUID, &elmMedium);
|
---|
704 |
|
---|
705 | bool fNeedsLocation = true;
|
---|
706 |
|
---|
707 | if (t == HardDisk)
|
---|
708 | {
|
---|
709 | if (m->sv < SettingsVersion_v1_4)
|
---|
710 | {
|
---|
711 | // here the system is:
|
---|
712 | // <HardDisk uuid="{....}" type="normal">
|
---|
713 | // <VirtualDiskImage filePath="/path/to/xxx.vdi"/>
|
---|
714 | // </HardDisk>
|
---|
715 |
|
---|
716 | fNeedsLocation = false;
|
---|
717 | bool fNeedsFilePath = true;
|
---|
718 | const xml::ElementNode *pelmImage;
|
---|
719 | if ((pelmImage = elmMedium.findChildElement("VirtualDiskImage")))
|
---|
720 | med.strFormat = "VDI";
|
---|
721 | else if ((pelmImage = elmMedium.findChildElement("VMDKImage")))
|
---|
722 | med.strFormat = "VMDK";
|
---|
723 | else if ((pelmImage = elmMedium.findChildElement("VHDImage")))
|
---|
724 | med.strFormat = "VHD";
|
---|
725 | else if ((pelmImage = elmMedium.findChildElement("ISCSIHardDisk")))
|
---|
726 | {
|
---|
727 | med.strFormat = "iSCSI";
|
---|
728 |
|
---|
729 | fNeedsFilePath = false;
|
---|
730 | // location is special here: current settings specify an "iscsi://user@server:port/target/lun"
|
---|
731 | // string for the location and also have several disk properties for these, whereas this used
|
---|
732 | // to be hidden in several sub-elements before 1.4, so compose a location string and set up
|
---|
733 | // the properties:
|
---|
734 | med.strLocation = "iscsi://";
|
---|
735 | Utf8Str strUser, strServer, strPort, strTarget, strLun;
|
---|
736 | if (pelmImage->getAttributeValue("userName", strUser))
|
---|
737 | {
|
---|
738 | med.strLocation.append(strUser);
|
---|
739 | med.strLocation.append("@");
|
---|
740 | }
|
---|
741 | Utf8Str strServerAndPort;
|
---|
742 | if (pelmImage->getAttributeValue("server", strServer))
|
---|
743 | {
|
---|
744 | strServerAndPort = strServer;
|
---|
745 | }
|
---|
746 | if (pelmImage->getAttributeValue("port", strPort))
|
---|
747 | {
|
---|
748 | if (strServerAndPort.length())
|
---|
749 | strServerAndPort.append(":");
|
---|
750 | strServerAndPort.append(strPort);
|
---|
751 | }
|
---|
752 | med.strLocation.append(strServerAndPort);
|
---|
753 | if (pelmImage->getAttributeValue("target", strTarget))
|
---|
754 | {
|
---|
755 | med.strLocation.append("/");
|
---|
756 | med.strLocation.append(strTarget);
|
---|
757 | }
|
---|
758 | if (pelmImage->getAttributeValue("lun", strLun))
|
---|
759 | {
|
---|
760 | med.strLocation.append("/");
|
---|
761 | med.strLocation.append(strLun);
|
---|
762 | }
|
---|
763 |
|
---|
764 | if (strServer.length() && strPort.length())
|
---|
765 | med.properties["TargetAddress"] = strServerAndPort;
|
---|
766 | if (strTarget.length())
|
---|
767 | med.properties["TargetName"] = strTarget;
|
---|
768 | if (strUser.length())
|
---|
769 | med.properties["InitiatorUsername"] = strUser;
|
---|
770 | Utf8Str strPassword;
|
---|
771 | if (pelmImage->getAttributeValue("password", strPassword))
|
---|
772 | med.properties["InitiatorSecret"] = strPassword;
|
---|
773 | if (strLun.length())
|
---|
774 | med.properties["LUN"] = strLun;
|
---|
775 | }
|
---|
776 | else if ((pelmImage = elmMedium.findChildElement("CustomHardDisk")))
|
---|
777 | {
|
---|
778 | fNeedsFilePath = false;
|
---|
779 | fNeedsLocation = true;
|
---|
780 | // also requires @format attribute, which will be queried below
|
---|
781 | }
|
---|
782 | else
|
---|
783 | throw ConfigFileError(this, &elmMedium, N_("Required %s/VirtualDiskImage element is missing"), elmMedium.getName());
|
---|
784 |
|
---|
785 | if (fNeedsFilePath)
|
---|
786 | {
|
---|
787 | if (!(pelmImage->getAttributeValuePath("filePath", med.strLocation)))
|
---|
788 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
|
---|
789 | }
|
---|
790 | }
|
---|
791 |
|
---|
792 | if (med.strFormat.isEmpty()) // not set with 1.4 format above, or 1.4 Custom format?
|
---|
793 | if (!elmMedium.getAttributeValue("format", med.strFormat))
|
---|
794 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName());
|
---|
795 |
|
---|
796 | if (!elmMedium.getAttributeValue("autoReset", med.fAutoReset))
|
---|
797 | med.fAutoReset = false;
|
---|
798 |
|
---|
799 | Utf8Str strType;
|
---|
800 | if (elmMedium.getAttributeValue("type", strType))
|
---|
801 | {
|
---|
802 | // pre-1.4 used lower case, so make this case-insensitive
|
---|
803 | strType.toUpper();
|
---|
804 | if (strType == "NORMAL")
|
---|
805 | med.hdType = MediumType_Normal;
|
---|
806 | else if (strType == "IMMUTABLE")
|
---|
807 | med.hdType = MediumType_Immutable;
|
---|
808 | else if (strType == "WRITETHROUGH")
|
---|
809 | med.hdType = MediumType_Writethrough;
|
---|
810 | else if (strType == "SHAREABLE")
|
---|
811 | med.hdType = MediumType_Shareable;
|
---|
812 | else if (strType == "READONLY")
|
---|
813 | med.hdType = MediumType_Readonly;
|
---|
814 | else if (strType == "MULTIATTACH")
|
---|
815 | med.hdType = MediumType_MultiAttach;
|
---|
816 | else
|
---|
817 | throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable, Writethrough, Shareable, Readonly or MultiAttach"));
|
---|
818 | }
|
---|
819 | }
|
---|
820 | else
|
---|
821 | {
|
---|
822 | if (m->sv < SettingsVersion_v1_4)
|
---|
823 | {
|
---|
824 | // DVD and floppy images before 1.4 had "src" attribute instead of "location"
|
---|
825 | if (!elmMedium.getAttributeValue("src", med.strLocation))
|
---|
826 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
|
---|
827 |
|
---|
828 | fNeedsLocation = false;
|
---|
829 | }
|
---|
830 |
|
---|
831 | if (!elmMedium.getAttributeValue("format", med.strFormat))
|
---|
832 | {
|
---|
833 | // DVD and floppy images before 1.11 had no format attribute. assign the default.
|
---|
834 | med.strFormat = "RAW";
|
---|
835 | }
|
---|
836 |
|
---|
837 | if (t == DVDImage)
|
---|
838 | med.hdType = MediumType_Readonly;
|
---|
839 | else if (t == FloppyImage)
|
---|
840 | med.hdType = MediumType_Writethrough;
|
---|
841 | }
|
---|
842 |
|
---|
843 | if (fNeedsLocation)
|
---|
844 | // current files and 1.4 CustomHardDisk elements must have a location attribute
|
---|
845 | if (!elmMedium.getAttributeValue("location", med.strLocation))
|
---|
846 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName());
|
---|
847 |
|
---|
848 | // 3.2 builds added Description as an attribute, read it silently
|
---|
849 | // and write it back as an element starting with 5.1.26
|
---|
850 | elmMedium.getAttributeValue("Description", med.strDescription);
|
---|
851 |
|
---|
852 | xml::NodesLoop nlMediumChildren(elmMedium);
|
---|
853 | const xml::ElementNode *pelmMediumChild;
|
---|
854 | while ((pelmMediumChild = nlMediumChildren.forAllNodes()))
|
---|
855 | {
|
---|
856 | if (pelmMediumChild->nameEquals("Description"))
|
---|
857 | med.strDescription = pelmMediumChild->getValue();
|
---|
858 | else if (pelmMediumChild->nameEquals("Property"))
|
---|
859 | {
|
---|
860 | // handle medium properties
|
---|
861 | Utf8Str strPropName, strPropValue;
|
---|
862 | if ( pelmMediumChild->getAttributeValue("name", strPropName)
|
---|
863 | && pelmMediumChild->getAttributeValue("value", strPropValue) )
|
---|
864 | med.properties[strPropName] = strPropValue;
|
---|
865 | else
|
---|
866 | throw ConfigFileError(this, pelmMediumChild, N_("Required HardDisk/Property/@name or @value attribute is missing"));
|
---|
867 | }
|
---|
868 | }
|
---|
869 | }
|
---|
870 |
|
---|
871 | /**
|
---|
872 | * Reads a media registry entry from the main VirtualBox.xml file and
|
---|
873 | * likewise for all children where applicable.
|
---|
874 | *
|
---|
875 | * @param t
|
---|
876 | * @param elmMedium
|
---|
877 | * @param med
|
---|
878 | */
|
---|
879 | void ConfigFileBase::readMedium(MediaType t,
|
---|
880 | const xml::ElementNode &elmMedium,
|
---|
881 | Medium &med)
|
---|
882 | {
|
---|
883 | std::list<const xml::ElementNode *> llElementsTodo;
|
---|
884 | llElementsTodo.push_back(&elmMedium);
|
---|
885 | std::list<Medium *> llSettingsTodo;
|
---|
886 | llSettingsTodo.push_back(&med);
|
---|
887 | std::list<uint32_t> llDepthsTodo;
|
---|
888 | llDepthsTodo.push_back(1);
|
---|
889 |
|
---|
890 | while (llElementsTodo.size() > 0)
|
---|
891 | {
|
---|
892 | const xml::ElementNode *pElement = llElementsTodo.front();
|
---|
893 | llElementsTodo.pop_front();
|
---|
894 | Medium *pMed = llSettingsTodo.front();
|
---|
895 | llSettingsTodo.pop_front();
|
---|
896 | uint32_t depth = llDepthsTodo.front();
|
---|
897 | llDepthsTodo.pop_front();
|
---|
898 |
|
---|
899 | if (depth > SETTINGS_MEDIUM_DEPTH_MAX)
|
---|
900 | throw ConfigFileError(this, pElement, N_("Maximum medium tree depth of %u exceeded"), SETTINGS_MEDIUM_DEPTH_MAX);
|
---|
901 |
|
---|
902 | readMediumOne(t, *pElement, *pMed);
|
---|
903 |
|
---|
904 | if (t != HardDisk)
|
---|
905 | return;
|
---|
906 |
|
---|
907 | // load all children
|
---|
908 | xml::NodesLoop nl2(*pElement, m->sv >= SettingsVersion_v1_4 ? "HardDisk" : "DiffHardDisk");
|
---|
909 | const xml::ElementNode *pelmHDChild;
|
---|
910 | while ((pelmHDChild = nl2.forAllNodes()))
|
---|
911 | {
|
---|
912 | llElementsTodo.push_back(pelmHDChild);
|
---|
913 | pMed->llChildren.push_back(Medium::Empty);
|
---|
914 | llSettingsTodo.push_back(&pMed->llChildren.back());
|
---|
915 | llDepthsTodo.push_back(depth + 1);
|
---|
916 | }
|
---|
917 | }
|
---|
918 | }
|
---|
919 |
|
---|
920 | /**
|
---|
921 | * Reads in the entire \<MediaRegistry\> chunk and stores its media in the lists
|
---|
922 | * of the given MediaRegistry structure.
|
---|
923 | *
|
---|
924 | * This is used in both MainConfigFile and MachineConfigFile since starting with
|
---|
925 | * VirtualBox 4.0, we can have media registries in both.
|
---|
926 | *
|
---|
927 | * For pre-1.4 files, this gets called with the \<DiskRegistry\> chunk instead.
|
---|
928 | *
|
---|
929 | * @param elmMediaRegistry
|
---|
930 | * @param mr
|
---|
931 | */
|
---|
932 | void ConfigFileBase::readMediaRegistry(const xml::ElementNode &elmMediaRegistry,
|
---|
933 | MediaRegistry &mr)
|
---|
934 | {
|
---|
935 | xml::NodesLoop nl1(elmMediaRegistry);
|
---|
936 | const xml::ElementNode *pelmChild1;
|
---|
937 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
938 | {
|
---|
939 | MediaType t = Error;
|
---|
940 | if (pelmChild1->nameEquals("HardDisks"))
|
---|
941 | t = HardDisk;
|
---|
942 | else if (pelmChild1->nameEquals("DVDImages"))
|
---|
943 | t = DVDImage;
|
---|
944 | else if (pelmChild1->nameEquals("FloppyImages"))
|
---|
945 | t = FloppyImage;
|
---|
946 | else
|
---|
947 | continue;
|
---|
948 |
|
---|
949 | xml::NodesLoop nl2(*pelmChild1);
|
---|
950 | const xml::ElementNode *pelmMedium;
|
---|
951 | while ((pelmMedium = nl2.forAllNodes()))
|
---|
952 | {
|
---|
953 | if ( t == HardDisk
|
---|
954 | && (pelmMedium->nameEquals("HardDisk")))
|
---|
955 | {
|
---|
956 | mr.llHardDisks.push_back(Medium::Empty);
|
---|
957 | readMedium(t, *pelmMedium, mr.llHardDisks.back());
|
---|
958 | }
|
---|
959 | else if ( t == DVDImage
|
---|
960 | && (pelmMedium->nameEquals("Image")))
|
---|
961 | {
|
---|
962 | mr.llDvdImages.push_back(Medium::Empty);
|
---|
963 | readMedium(t, *pelmMedium, mr.llDvdImages.back());
|
---|
964 | }
|
---|
965 | else if ( t == FloppyImage
|
---|
966 | && (pelmMedium->nameEquals("Image")))
|
---|
967 | {
|
---|
968 | mr.llFloppyImages.push_back(Medium::Empty);
|
---|
969 | readMedium(t, *pelmMedium, mr.llFloppyImages.back());
|
---|
970 | }
|
---|
971 | }
|
---|
972 | }
|
---|
973 | }
|
---|
974 |
|
---|
975 | /**
|
---|
976 | * This is common version for reading NAT port forward rule in per-_machine's_adapter_ and
|
---|
977 | * per-network approaches.
|
---|
978 | * Note: this function doesn't in fill given list from xml::ElementNodesList, because there is conflicting
|
---|
979 | * declaration in ovmfreader.h.
|
---|
980 | */
|
---|
981 | void ConfigFileBase::readNATForwardRulesMap(const xml::ElementNode &elmParent, NATRulesMap &mapRules)
|
---|
982 | {
|
---|
983 | xml::ElementNodesList plstRules;
|
---|
984 | elmParent.getChildElements(plstRules, "Forwarding");
|
---|
985 | for (xml::ElementNodesList::iterator pf = plstRules.begin(); pf != plstRules.end(); ++pf)
|
---|
986 | {
|
---|
987 | NATRule rule;
|
---|
988 | uint32_t port = 0;
|
---|
989 | (*pf)->getAttributeValue("name", rule.strName);
|
---|
990 | (*pf)->getAttributeValue("proto", (uint32_t&)rule.proto);
|
---|
991 | (*pf)->getAttributeValue("hostip", rule.strHostIP);
|
---|
992 | (*pf)->getAttributeValue("hostport", port);
|
---|
993 | rule.u16HostPort = (uint16_t)port;
|
---|
994 | (*pf)->getAttributeValue("guestip", rule.strGuestIP);
|
---|
995 | (*pf)->getAttributeValue("guestport", port);
|
---|
996 | rule.u16GuestPort = (uint16_t)port;
|
---|
997 | mapRules.insert(std::make_pair(rule.strName, rule));
|
---|
998 | }
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | void ConfigFileBase::readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopbacks)
|
---|
1002 | {
|
---|
1003 | xml::ElementNodesList plstLoopbacks;
|
---|
1004 | elmParent.getChildElements(plstLoopbacks, "Loopback4");
|
---|
1005 | for (xml::ElementNodesList::iterator lo = plstLoopbacks.begin();
|
---|
1006 | lo != plstLoopbacks.end(); ++lo)
|
---|
1007 | {
|
---|
1008 | NATHostLoopbackOffset loopback;
|
---|
1009 | (*lo)->getAttributeValue("address", loopback.strLoopbackHostAddress);
|
---|
1010 | (*lo)->getAttributeValue("offset", (uint32_t&)loopback.u32Offset);
|
---|
1011 | llLoopbacks.push_back(loopback);
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 |
|
---|
1016 | /**
|
---|
1017 | * Adds a "version" attribute to the given XML element with the
|
---|
1018 | * VirtualBox settings version (e.g. "1.10-linux"). Used by
|
---|
1019 | * the XML format for the root element and by the OVF export
|
---|
1020 | * for the vbox:Machine element.
|
---|
1021 | * @param elm
|
---|
1022 | */
|
---|
1023 | void ConfigFileBase::setVersionAttribute(xml::ElementNode &elm)
|
---|
1024 | {
|
---|
1025 | const char *pcszVersion = NULL;
|
---|
1026 | switch (m->sv)
|
---|
1027 | {
|
---|
1028 | case SettingsVersion_v1_8:
|
---|
1029 | pcszVersion = "1.8";
|
---|
1030 | break;
|
---|
1031 |
|
---|
1032 | case SettingsVersion_v1_9:
|
---|
1033 | pcszVersion = "1.9";
|
---|
1034 | break;
|
---|
1035 |
|
---|
1036 | case SettingsVersion_v1_10:
|
---|
1037 | pcszVersion = "1.10";
|
---|
1038 | break;
|
---|
1039 |
|
---|
1040 | case SettingsVersion_v1_11:
|
---|
1041 | pcszVersion = "1.11";
|
---|
1042 | break;
|
---|
1043 |
|
---|
1044 | case SettingsVersion_v1_12:
|
---|
1045 | pcszVersion = "1.12";
|
---|
1046 | break;
|
---|
1047 |
|
---|
1048 | case SettingsVersion_v1_13:
|
---|
1049 | pcszVersion = "1.13";
|
---|
1050 | break;
|
---|
1051 |
|
---|
1052 | case SettingsVersion_v1_14:
|
---|
1053 | pcszVersion = "1.14";
|
---|
1054 | break;
|
---|
1055 |
|
---|
1056 | case SettingsVersion_v1_15:
|
---|
1057 | pcszVersion = "1.15";
|
---|
1058 | break;
|
---|
1059 |
|
---|
1060 | case SettingsVersion_v1_16:
|
---|
1061 | pcszVersion = "1.16";
|
---|
1062 | break;
|
---|
1063 |
|
---|
1064 | case SettingsVersion_v1_17:
|
---|
1065 | pcszVersion = "1.17";
|
---|
1066 | break;
|
---|
1067 |
|
---|
1068 | case SettingsVersion_v1_18:
|
---|
1069 | pcszVersion = "1.18";
|
---|
1070 | break;
|
---|
1071 |
|
---|
1072 | case SettingsVersion_v1_19:
|
---|
1073 | pcszVersion = "1.19";
|
---|
1074 | break;
|
---|
1075 |
|
---|
1076 | case SettingsVersion_v1_20:
|
---|
1077 | pcszVersion = "1.20";
|
---|
1078 | break;
|
---|
1079 |
|
---|
1080 | default:
|
---|
1081 | // catch human error: the assertion below will trigger in debug
|
---|
1082 | // or dbgopt builds, so hopefully this will get noticed sooner in
|
---|
1083 | // the future, because it's easy to forget top update something.
|
---|
1084 | AssertMsg(m->sv <= SettingsVersion_v1_7, ("Settings.cpp: unexpected settings version %d, unhandled future version?\n", m->sv));
|
---|
1085 | // silently upgrade if this is less than 1.7 because that's the oldest we can write
|
---|
1086 | if (m->sv <= SettingsVersion_v1_7)
|
---|
1087 | {
|
---|
1088 | pcszVersion = "1.7";
|
---|
1089 | m->sv = SettingsVersion_v1_7;
|
---|
1090 | }
|
---|
1091 | else
|
---|
1092 | {
|
---|
1093 | // This is reached for SettingsVersion_Future and forgotten
|
---|
1094 | // settings version after SettingsVersion_v1_7, which should
|
---|
1095 | // not happen (see assertion above). Set the version to the
|
---|
1096 | // latest known version, to minimize loss of information, but
|
---|
1097 | // as we can't predict the future we have to use some format
|
---|
1098 | // we know, and latest should be the best choice. Note that
|
---|
1099 | // for "forgotten settings" this may not be the best choice,
|
---|
1100 | // but as it's an omission of someone who changed this file
|
---|
1101 | // it's the only generic possibility.
|
---|
1102 | pcszVersion = "1.20";
|
---|
1103 | m->sv = SettingsVersion_v1_20;
|
---|
1104 | }
|
---|
1105 | break;
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | m->strSettingsVersionFull = Utf8StrFmt("%s-%s",
|
---|
1109 | pcszVersion,
|
---|
1110 | VBOX_XML_PLATFORM); // e.g. "linux"
|
---|
1111 | elm.setAttribute("version", m->strSettingsVersionFull);
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 |
|
---|
1115 | /**
|
---|
1116 | * Creates a special backup file in case there is a version
|
---|
1117 | * bump, so that it is possible to go back to the previous
|
---|
1118 | * state. This is done only once (not for every settings
|
---|
1119 | * version bump), when the settings version is newer than
|
---|
1120 | * the version read from the config file. Must be called
|
---|
1121 | * before ConfigFileBase::createStubDocument, because that
|
---|
1122 | * method may alter information which this method needs.
|
---|
1123 | */
|
---|
1124 | void ConfigFileBase::specialBackupIfFirstBump()
|
---|
1125 | {
|
---|
1126 | // Since this gets called before the XML document is actually written out,
|
---|
1127 | // this is where we must check whether we're upgrading the settings version
|
---|
1128 | // and need to make a backup, so the user can go back to an earlier
|
---|
1129 | // VirtualBox version and recover his old settings files.
|
---|
1130 | if ( (m->svRead != SettingsVersion_Null) // old file exists?
|
---|
1131 | && (m->svRead < m->sv) // we're upgrading?
|
---|
1132 | )
|
---|
1133 | {
|
---|
1134 | // compose new filename: strip off trailing ".xml"/".vbox"
|
---|
1135 | Utf8Str strFilenameNew;
|
---|
1136 | Utf8Str strExt = ".xml";
|
---|
1137 | if (m->strFilename.endsWith(".xml"))
|
---|
1138 | strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
|
---|
1139 | else if (m->strFilename.endsWith(".vbox"))
|
---|
1140 | {
|
---|
1141 | strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 5);
|
---|
1142 | strExt = ".vbox";
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | // and append something like "-1.3-linux.xml"
|
---|
1146 | strFilenameNew.append("-");
|
---|
1147 | strFilenameNew.append(m->strSettingsVersionFull); // e.g. "1.3-linux"
|
---|
1148 | strFilenameNew.append(strExt); // .xml for main config, .vbox for machine config
|
---|
1149 |
|
---|
1150 | // Copying the file cannot be avoided, as doing tricks with renaming
|
---|
1151 | // causes trouble on OS X with aliases (which follow the rename), and
|
---|
1152 | // on all platforms there is a risk of "losing" the VM config when
|
---|
1153 | // running out of space, as a rename here couldn't be rolled back.
|
---|
1154 | // Ignoring all errors besides running out of space is intentional, as
|
---|
1155 | // we don't want to do anything if the file already exists.
|
---|
1156 | int vrc = RTFileCopy(m->strFilename.c_str(), strFilenameNew.c_str());
|
---|
1157 | if (RT_UNLIKELY(vrc == VERR_DISK_FULL))
|
---|
1158 | throw ConfigFileError(this, NULL, N_("Cannot create settings backup file when upgrading to a newer settings format"));
|
---|
1159 |
|
---|
1160 | // do this only once
|
---|
1161 | m->svRead = SettingsVersion_Null;
|
---|
1162 | }
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | /**
|
---|
1166 | * Creates a new stub xml::Document in the m->pDoc member with the
|
---|
1167 | * root "VirtualBox" element set up. This is used by both
|
---|
1168 | * MainConfigFile and MachineConfigFile at the beginning of writing
|
---|
1169 | * out their XML.
|
---|
1170 | *
|
---|
1171 | * Before calling this, it is the responsibility of the caller to
|
---|
1172 | * set the "sv" member to the required settings version that is to
|
---|
1173 | * be written. For newly created files, the settings version will be
|
---|
1174 | * recent (1.12 or later if necessary); for files read in from disk
|
---|
1175 | * earlier, it will be the settings version indicated in the file.
|
---|
1176 | * However, this method will silently make sure that the settings
|
---|
1177 | * version is always at least 1.7 and change it if necessary, since
|
---|
1178 | * there is no write support for earlier settings versions.
|
---|
1179 | */
|
---|
1180 | void ConfigFileBase::createStubDocument()
|
---|
1181 | {
|
---|
1182 | Assert(m->pDoc == NULL);
|
---|
1183 | m->pDoc = new xml::Document;
|
---|
1184 |
|
---|
1185 | m->pelmRoot = m->pDoc->createRootElement("VirtualBox",
|
---|
1186 | "\n"
|
---|
1187 | "** DO NOT EDIT THIS FILE.\n"
|
---|
1188 | "** If you make changes to this file while any VirtualBox related application\n"
|
---|
1189 | "** is running, your changes will be overwritten later, without taking effect.\n"
|
---|
1190 | "** Use VBoxManage or the VirtualBox Manager GUI to make changes.\n"
|
---|
1191 | );
|
---|
1192 | m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
|
---|
1193 | // Have the code for producing a proper schema reference. Not used by most
|
---|
1194 | // tools, so don't bother doing it. The schema is not on the server anyway.
|
---|
1195 | #ifdef VBOX_WITH_SETTINGS_SCHEMA
|
---|
1196 | m->pelmRoot->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
---|
1197 | m->pelmRoot->setAttribute("xsi:schemaLocation", VBOX_XML_NAMESPACE " " VBOX_XML_SCHEMA);
|
---|
1198 | #endif
|
---|
1199 |
|
---|
1200 | // add settings version attribute to root element, update m->strSettingsVersionFull
|
---|
1201 | setVersionAttribute(*m->pelmRoot);
|
---|
1202 |
|
---|
1203 | LogRel(("Saving settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | /**
|
---|
1207 | * Creates an \<ExtraData\> node under the given parent element with
|
---|
1208 | * \<ExtraDataItem\> childern according to the contents of the given
|
---|
1209 | * map.
|
---|
1210 | *
|
---|
1211 | * This is in ConfigFileBase because it's used in both MainConfigFile
|
---|
1212 | * and MachineConfigFile, which both can have extradata.
|
---|
1213 | *
|
---|
1214 | * @param elmParent
|
---|
1215 | * @param me
|
---|
1216 | */
|
---|
1217 | void ConfigFileBase::buildExtraData(xml::ElementNode &elmParent,
|
---|
1218 | const StringsMap &me)
|
---|
1219 | {
|
---|
1220 | if (me.size())
|
---|
1221 | {
|
---|
1222 | xml::ElementNode *pelmExtraData = elmParent.createChild("ExtraData");
|
---|
1223 | for (StringsMap::const_iterator it = me.begin();
|
---|
1224 | it != me.end();
|
---|
1225 | ++it)
|
---|
1226 | {
|
---|
1227 | const Utf8Str &strName = it->first;
|
---|
1228 | const Utf8Str &strValue = it->second;
|
---|
1229 | xml::ElementNode *pelmThis = pelmExtraData->createChild("ExtraDataItem");
|
---|
1230 | pelmThis->setAttribute("name", strName);
|
---|
1231 | pelmThis->setAttribute("value", strValue);
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | /**
|
---|
1237 | * Creates \<DeviceFilter\> nodes under the given parent element according to
|
---|
1238 | * the contents of the given USBDeviceFiltersList. This is in ConfigFileBase
|
---|
1239 | * because it's used in both MainConfigFile (for host filters) and
|
---|
1240 | * MachineConfigFile (for machine filters).
|
---|
1241 | *
|
---|
1242 | * If fHostMode is true, this means that we're supposed to write filters
|
---|
1243 | * for the IHost interface (respect "action", omit "strRemote" and
|
---|
1244 | * "ulMaskedInterfaces" in struct USBDeviceFilter).
|
---|
1245 | *
|
---|
1246 | * @param elmParent
|
---|
1247 | * @param ll
|
---|
1248 | * @param fHostMode
|
---|
1249 | */
|
---|
1250 | void ConfigFileBase::buildUSBDeviceFilters(xml::ElementNode &elmParent,
|
---|
1251 | const USBDeviceFiltersList &ll,
|
---|
1252 | bool fHostMode)
|
---|
1253 | {
|
---|
1254 | for (USBDeviceFiltersList::const_iterator it = ll.begin();
|
---|
1255 | it != ll.end();
|
---|
1256 | ++it)
|
---|
1257 | {
|
---|
1258 | const USBDeviceFilter &flt = *it;
|
---|
1259 | xml::ElementNode *pelmFilter = elmParent.createChild("DeviceFilter");
|
---|
1260 | pelmFilter->setAttribute("name", flt.strName);
|
---|
1261 | pelmFilter->setAttribute("active", flt.fActive);
|
---|
1262 | if (flt.strVendorId.length())
|
---|
1263 | pelmFilter->setAttribute("vendorId", flt.strVendorId);
|
---|
1264 | if (flt.strProductId.length())
|
---|
1265 | pelmFilter->setAttribute("productId", flt.strProductId);
|
---|
1266 | if (flt.strRevision.length())
|
---|
1267 | pelmFilter->setAttribute("revision", flt.strRevision);
|
---|
1268 | if (flt.strManufacturer.length())
|
---|
1269 | pelmFilter->setAttribute("manufacturer", flt.strManufacturer);
|
---|
1270 | if (flt.strProduct.length())
|
---|
1271 | pelmFilter->setAttribute("product", flt.strProduct);
|
---|
1272 | if (flt.strSerialNumber.length())
|
---|
1273 | pelmFilter->setAttribute("serialNumber", flt.strSerialNumber);
|
---|
1274 | if (flt.strPort.length())
|
---|
1275 | pelmFilter->setAttribute("port", flt.strPort);
|
---|
1276 |
|
---|
1277 | if (fHostMode)
|
---|
1278 | {
|
---|
1279 | const char *pcsz =
|
---|
1280 | (flt.action == USBDeviceFilterAction_Ignore) ? "Ignore"
|
---|
1281 | : /*(flt.action == USBDeviceFilterAction_Hold) ?*/ "Hold";
|
---|
1282 | pelmFilter->setAttribute("action", pcsz);
|
---|
1283 | }
|
---|
1284 | else
|
---|
1285 | {
|
---|
1286 | if (flt.strRemote.length())
|
---|
1287 | pelmFilter->setAttribute("remote", flt.strRemote);
|
---|
1288 | if (flt.ulMaskedInterfaces)
|
---|
1289 | pelmFilter->setAttribute("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
1290 | }
|
---|
1291 | }
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | /**
|
---|
1295 | * Creates a single \<HardDisk\> element for the given Medium structure
|
---|
1296 | * and all child hard disks underneath. Called from MainConfigFile::write().
|
---|
1297 | *
|
---|
1298 | * @param t
|
---|
1299 | * @param elmMedium
|
---|
1300 | * @param med
|
---|
1301 | */
|
---|
1302 | void ConfigFileBase::buildMedium(MediaType t,
|
---|
1303 | xml::ElementNode &elmMedium,
|
---|
1304 | const Medium &med)
|
---|
1305 | {
|
---|
1306 | std::list<const Medium *> llSettingsTodo;
|
---|
1307 | llSettingsTodo.push_back(&med);
|
---|
1308 | std::list<xml::ElementNode *> llElementsTodo;
|
---|
1309 | llElementsTodo.push_back(&elmMedium);
|
---|
1310 | std::list<uint32_t> llDepthsTodo;
|
---|
1311 | llDepthsTodo.push_back(1);
|
---|
1312 |
|
---|
1313 | while (llSettingsTodo.size() > 0)
|
---|
1314 | {
|
---|
1315 | const Medium *pMed = llSettingsTodo.front();
|
---|
1316 | llSettingsTodo.pop_front();
|
---|
1317 | xml::ElementNode *pElement = llElementsTodo.front();
|
---|
1318 | llElementsTodo.pop_front();
|
---|
1319 | uint32_t depth = llDepthsTodo.front();
|
---|
1320 | llDepthsTodo.pop_front();
|
---|
1321 |
|
---|
1322 | if (depth > SETTINGS_MEDIUM_DEPTH_MAX)
|
---|
1323 | throw ConfigFileError(this, pElement, N_("Maximum medium tree depth of %u exceeded"), SETTINGS_MEDIUM_DEPTH_MAX);
|
---|
1324 |
|
---|
1325 | xml::ElementNode *pelmMedium;
|
---|
1326 |
|
---|
1327 | if (t == HardDisk)
|
---|
1328 | pelmMedium = pElement->createChild("HardDisk");
|
---|
1329 | else
|
---|
1330 | pelmMedium = pElement->createChild("Image");
|
---|
1331 |
|
---|
1332 | pelmMedium->setAttribute("uuid", pMed->uuid.toStringCurly());
|
---|
1333 |
|
---|
1334 | pelmMedium->setAttributePath("location", pMed->strLocation);
|
---|
1335 |
|
---|
1336 | if (t == HardDisk || RTStrICmp(pMed->strFormat.c_str(), "RAW"))
|
---|
1337 | pelmMedium->setAttribute("format", pMed->strFormat);
|
---|
1338 | if ( t == HardDisk
|
---|
1339 | && pMed->fAutoReset)
|
---|
1340 | pelmMedium->setAttribute("autoReset", pMed->fAutoReset);
|
---|
1341 | if (pMed->strDescription.length())
|
---|
1342 | pelmMedium->createChild("Description")->addContent(pMed->strDescription);
|
---|
1343 |
|
---|
1344 | for (StringsMap::const_iterator it = pMed->properties.begin();
|
---|
1345 | it != pMed->properties.end();
|
---|
1346 | ++it)
|
---|
1347 | {
|
---|
1348 | xml::ElementNode *pelmProp = pelmMedium->createChild("Property");
|
---|
1349 | pelmProp->setAttribute("name", it->first);
|
---|
1350 | pelmProp->setAttribute("value", it->second);
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | // only for base hard disks, save the type
|
---|
1354 | if (depth == 1)
|
---|
1355 | {
|
---|
1356 | // no need to save the usual DVD/floppy medium types
|
---|
1357 | if ( ( t != DVDImage
|
---|
1358 | || ( pMed->hdType != MediumType_Writethrough // shouldn't happen
|
---|
1359 | && pMed->hdType != MediumType_Readonly))
|
---|
1360 | && ( t != FloppyImage
|
---|
1361 | || pMed->hdType != MediumType_Writethrough))
|
---|
1362 | {
|
---|
1363 | const char *pcszType =
|
---|
1364 | pMed->hdType == MediumType_Normal ? "Normal" :
|
---|
1365 | pMed->hdType == MediumType_Immutable ? "Immutable" :
|
---|
1366 | pMed->hdType == MediumType_Writethrough ? "Writethrough" :
|
---|
1367 | pMed->hdType == MediumType_Shareable ? "Shareable" :
|
---|
1368 | pMed->hdType == MediumType_Readonly ? "Readonly" :
|
---|
1369 | pMed->hdType == MediumType_MultiAttach ? "MultiAttach" :
|
---|
1370 | "INVALID";
|
---|
1371 | pelmMedium->setAttribute("type", pcszType);
|
---|
1372 | }
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | /* save all children */
|
---|
1376 | MediaList::const_iterator itBegin = pMed->llChildren.begin();
|
---|
1377 | MediaList::const_iterator itEnd = pMed->llChildren.end();
|
---|
1378 | for (MediaList::const_iterator it = itBegin; it != itEnd; ++it)
|
---|
1379 | {
|
---|
1380 | llSettingsTodo.push_back(&*it);
|
---|
1381 | llElementsTodo.push_back(pelmMedium);
|
---|
1382 | llDepthsTodo.push_back(depth + 1);
|
---|
1383 | }
|
---|
1384 | }
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | /**
|
---|
1388 | * Creates a \<MediaRegistry\> node under the given parent and writes out all
|
---|
1389 | * hard disks and DVD and floppy images from the lists in the given MediaRegistry
|
---|
1390 | * structure under it.
|
---|
1391 | *
|
---|
1392 | * This is used in both MainConfigFile and MachineConfigFile since starting with
|
---|
1393 | * VirtualBox 4.0, we can have media registries in both.
|
---|
1394 | *
|
---|
1395 | * @param elmParent
|
---|
1396 | * @param mr
|
---|
1397 | */
|
---|
1398 | void ConfigFileBase::buildMediaRegistry(xml::ElementNode &elmParent,
|
---|
1399 | const MediaRegistry &mr)
|
---|
1400 | {
|
---|
1401 | if (mr.llHardDisks.size() == 0 && mr.llDvdImages.size() == 0 && mr.llFloppyImages.size() == 0)
|
---|
1402 | return;
|
---|
1403 |
|
---|
1404 | xml::ElementNode *pelmMediaRegistry = elmParent.createChild("MediaRegistry");
|
---|
1405 |
|
---|
1406 | if (mr.llHardDisks.size())
|
---|
1407 | {
|
---|
1408 | xml::ElementNode *pelmHardDisks = pelmMediaRegistry->createChild("HardDisks");
|
---|
1409 | for (MediaList::const_iterator it = mr.llHardDisks.begin();
|
---|
1410 | it != mr.llHardDisks.end();
|
---|
1411 | ++it)
|
---|
1412 | {
|
---|
1413 | buildMedium(HardDisk, *pelmHardDisks, *it);
|
---|
1414 | }
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | if (mr.llDvdImages.size())
|
---|
1418 | {
|
---|
1419 | xml::ElementNode *pelmDVDImages = pelmMediaRegistry->createChild("DVDImages");
|
---|
1420 | for (MediaList::const_iterator it = mr.llDvdImages.begin();
|
---|
1421 | it != mr.llDvdImages.end();
|
---|
1422 | ++it)
|
---|
1423 | {
|
---|
1424 | buildMedium(DVDImage, *pelmDVDImages, *it);
|
---|
1425 | }
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 | if (mr.llFloppyImages.size())
|
---|
1429 | {
|
---|
1430 | xml::ElementNode *pelmFloppyImages = pelmMediaRegistry->createChild("FloppyImages");
|
---|
1431 | for (MediaList::const_iterator it = mr.llFloppyImages.begin();
|
---|
1432 | it != mr.llFloppyImages.end();
|
---|
1433 | ++it)
|
---|
1434 | {
|
---|
1435 | buildMedium(FloppyImage, *pelmFloppyImages, *it);
|
---|
1436 | }
|
---|
1437 | }
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | /**
|
---|
1441 | * Serialize NAT port-forwarding rules in parent container.
|
---|
1442 | * Note: it's responsibility of caller to create parent of the list tag.
|
---|
1443 | * because this method used for serializing per-_mahine's_adapter_ and per-network approaches.
|
---|
1444 | */
|
---|
1445 | void ConfigFileBase::buildNATForwardRulesMap(xml::ElementNode &elmParent, const NATRulesMap &mapRules)
|
---|
1446 | {
|
---|
1447 | for (NATRulesMap::const_iterator r = mapRules.begin();
|
---|
1448 | r != mapRules.end(); ++r)
|
---|
1449 | {
|
---|
1450 | xml::ElementNode *pelmPF;
|
---|
1451 | pelmPF = elmParent.createChild("Forwarding");
|
---|
1452 | const NATRule &nr = r->second;
|
---|
1453 | if (nr.strName.length())
|
---|
1454 | pelmPF->setAttribute("name", nr.strName);
|
---|
1455 | pelmPF->setAttribute("proto", nr.proto);
|
---|
1456 | if (nr.strHostIP.length())
|
---|
1457 | pelmPF->setAttribute("hostip", nr.strHostIP);
|
---|
1458 | if (nr.u16HostPort)
|
---|
1459 | pelmPF->setAttribute("hostport", nr.u16HostPort);
|
---|
1460 | if (nr.strGuestIP.length())
|
---|
1461 | pelmPF->setAttribute("guestip", nr.strGuestIP);
|
---|
1462 | if (nr.u16GuestPort)
|
---|
1463 | pelmPF->setAttribute("guestport", nr.u16GuestPort);
|
---|
1464 | }
|
---|
1465 | }
|
---|
1466 |
|
---|
1467 |
|
---|
1468 | void ConfigFileBase::buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackOffsetList)
|
---|
1469 | {
|
---|
1470 | for (NATLoopbackOffsetList::const_iterator lo = natLoopbackOffsetList.begin();
|
---|
1471 | lo != natLoopbackOffsetList.end(); ++lo)
|
---|
1472 | {
|
---|
1473 | xml::ElementNode *pelmLo;
|
---|
1474 | pelmLo = elmParent.createChild("Loopback4");
|
---|
1475 | pelmLo->setAttribute("address", (*lo).strLoopbackHostAddress);
|
---|
1476 | pelmLo->setAttribute("offset", (*lo).u32Offset);
|
---|
1477 | }
|
---|
1478 | }
|
---|
1479 |
|
---|
1480 | /**
|
---|
1481 | * Cleans up memory allocated by the internal XML parser. To be called by
|
---|
1482 | * descendant classes when they're done analyzing the DOM tree to discard it.
|
---|
1483 | */
|
---|
1484 | void ConfigFileBase::clearDocument()
|
---|
1485 | {
|
---|
1486 | m->cleanup();
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | /**
|
---|
1490 | * Returns true only if the underlying config file exists on disk;
|
---|
1491 | * either because the file has been loaded from disk, or it's been written
|
---|
1492 | * to disk, or both.
|
---|
1493 | * @return
|
---|
1494 | */
|
---|
1495 | bool ConfigFileBase::fileExists()
|
---|
1496 | {
|
---|
1497 | return m->fFileExists;
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | /**
|
---|
1501 | * Returns the settings file version
|
---|
1502 | *
|
---|
1503 | * @returns Settings file version enum.
|
---|
1504 | */
|
---|
1505 | SettingsVersion_T ConfigFileBase::getSettingsVersion()
|
---|
1506 | {
|
---|
1507 | return m->sv;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 |
|
---|
1511 | /**
|
---|
1512 | * Copies the base variables from another instance. Used by Machine::saveSettings
|
---|
1513 | * so that the settings version does not get lost when a copy of the Machine settings
|
---|
1514 | * file is made to see if settings have actually changed.
|
---|
1515 | * @param b
|
---|
1516 | */
|
---|
1517 | void ConfigFileBase::copyBaseFrom(const ConfigFileBase &b)
|
---|
1518 | {
|
---|
1519 | m->copyFrom(*b.m);
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1523 | //
|
---|
1524 | // Structures shared between Machine XML and VirtualBox.xml
|
---|
1525 | //
|
---|
1526 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1527 |
|
---|
1528 |
|
---|
1529 | /**
|
---|
1530 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1531 | */
|
---|
1532 | USBDeviceFilter::USBDeviceFilter() :
|
---|
1533 | fActive(false),
|
---|
1534 | action(USBDeviceFilterAction_Null),
|
---|
1535 | ulMaskedInterfaces(0)
|
---|
1536 | {
|
---|
1537 | }
|
---|
1538 |
|
---|
1539 | /**
|
---|
1540 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1541 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1542 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1543 | */
|
---|
1544 | bool USBDeviceFilter::operator==(const USBDeviceFilter &u) const
|
---|
1545 | {
|
---|
1546 | return (this == &u)
|
---|
1547 | || ( strName == u.strName
|
---|
1548 | && fActive == u.fActive
|
---|
1549 | && strVendorId == u.strVendorId
|
---|
1550 | && strProductId == u.strProductId
|
---|
1551 | && strRevision == u.strRevision
|
---|
1552 | && strManufacturer == u.strManufacturer
|
---|
1553 | && strProduct == u.strProduct
|
---|
1554 | && strSerialNumber == u.strSerialNumber
|
---|
1555 | && strPort == u.strPort
|
---|
1556 | && action == u.action
|
---|
1557 | && strRemote == u.strRemote
|
---|
1558 | && ulMaskedInterfaces == u.ulMaskedInterfaces);
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | /**
|
---|
1562 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1563 | */
|
---|
1564 | settings::Medium::Medium() :
|
---|
1565 | fAutoReset(false),
|
---|
1566 | hdType(MediumType_Normal)
|
---|
1567 | {
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 | /**
|
---|
1571 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1572 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1573 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1574 | */
|
---|
1575 | bool settings::Medium::operator==(const settings::Medium &m) const
|
---|
1576 | {
|
---|
1577 | return (this == &m)
|
---|
1578 | || ( uuid == m.uuid
|
---|
1579 | && strLocation == m.strLocation
|
---|
1580 | && strDescription == m.strDescription
|
---|
1581 | && strFormat == m.strFormat
|
---|
1582 | && fAutoReset == m.fAutoReset
|
---|
1583 | && properties == m.properties
|
---|
1584 | && hdType == m.hdType
|
---|
1585 | && llChildren == m.llChildren); // this is deep and recurses
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | const struct settings::Medium settings::Medium::Empty; /* default ctor is OK */
|
---|
1589 |
|
---|
1590 | /**
|
---|
1591 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1592 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1593 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1594 | */
|
---|
1595 | bool MediaRegistry::operator==(const MediaRegistry &m) const
|
---|
1596 | {
|
---|
1597 | return (this == &m)
|
---|
1598 | || ( llHardDisks == m.llHardDisks
|
---|
1599 | && llDvdImages == m.llDvdImages
|
---|
1600 | && llFloppyImages == m.llFloppyImages);
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | /**
|
---|
1604 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1605 | */
|
---|
1606 | NATRule::NATRule() :
|
---|
1607 | proto(NATProtocol_TCP),
|
---|
1608 | u16HostPort(0),
|
---|
1609 | u16GuestPort(0)
|
---|
1610 | {
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | /**
|
---|
1614 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1615 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1616 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1617 | */
|
---|
1618 | bool NATRule::operator==(const NATRule &r) const
|
---|
1619 | {
|
---|
1620 | return (this == &r)
|
---|
1621 | || ( strName == r.strName
|
---|
1622 | && proto == r.proto
|
---|
1623 | && u16HostPort == r.u16HostPort
|
---|
1624 | && strHostIP == r.strHostIP
|
---|
1625 | && u16GuestPort == r.u16GuestPort
|
---|
1626 | && strGuestIP == r.strGuestIP);
|
---|
1627 | }
|
---|
1628 |
|
---|
1629 | /**
|
---|
1630 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1631 | */
|
---|
1632 | NATHostLoopbackOffset::NATHostLoopbackOffset() :
|
---|
1633 | u32Offset(0)
|
---|
1634 | {
|
---|
1635 | }
|
---|
1636 |
|
---|
1637 | /**
|
---|
1638 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1639 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1640 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1641 | */
|
---|
1642 | bool NATHostLoopbackOffset::operator==(const NATHostLoopbackOffset &o) const
|
---|
1643 | {
|
---|
1644 | return (this == &o)
|
---|
1645 | || ( strLoopbackHostAddress == o.strLoopbackHostAddress
|
---|
1646 | && u32Offset == o.u32Offset);
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1651 | //
|
---|
1652 | // VirtualBox.xml structures
|
---|
1653 | //
|
---|
1654 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1655 |
|
---|
1656 | PlatformProperties::PlatformProperties()
|
---|
1657 | : fExclusiveHwVirt(true)
|
---|
1658 | {
|
---|
1659 | #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
|
---|
1660 | fExclusiveHwVirt = false; /** BUGBUG Does this apply to MacOS on ARM as well? */
|
---|
1661 | #endif
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | /**
|
---|
1665 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1666 | */
|
---|
1667 | SystemProperties::SystemProperties()
|
---|
1668 | : uProxyMode(ProxyMode_System)
|
---|
1669 | , uLogHistoryCount(3)
|
---|
1670 | {
|
---|
1671 | }
|
---|
1672 |
|
---|
1673 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
1674 | UpdateAgent::UpdateAgent()
|
---|
1675 | : fEnabled(false)
|
---|
1676 | , enmChannel(UpdateChannel_Stable)
|
---|
1677 | , uCheckFreqSeconds(RT_SEC_1DAY)
|
---|
1678 | , uCheckCount(0)
|
---|
1679 | {
|
---|
1680 | }
|
---|
1681 | #endif /* VBOX_WITH_UPDATE_AGENT */
|
---|
1682 |
|
---|
1683 | /**
|
---|
1684 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1685 | */
|
---|
1686 | DhcpOptValue::DhcpOptValue()
|
---|
1687 | : strValue()
|
---|
1688 | , enmEncoding(DHCPOptionEncoding_Normal)
|
---|
1689 | {
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 | /**
|
---|
1693 | * Non-standard constructor.
|
---|
1694 | */
|
---|
1695 | DhcpOptValue::DhcpOptValue(const com::Utf8Str &aText, DHCPOptionEncoding_T aEncoding)
|
---|
1696 | : strValue(aText)
|
---|
1697 | , enmEncoding(aEncoding)
|
---|
1698 | {
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | /**
|
---|
1702 | * Default constructor.
|
---|
1703 | */
|
---|
1704 | DHCPGroupCondition::DHCPGroupCondition()
|
---|
1705 | : fInclusive(true)
|
---|
1706 | , enmType(DHCPGroupConditionType_MAC)
|
---|
1707 | , strValue()
|
---|
1708 | {
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | /**
|
---|
1712 | * Default constructor.
|
---|
1713 | */
|
---|
1714 | DHCPConfig::DHCPConfig()
|
---|
1715 | : mapOptions()
|
---|
1716 | , secMinLeaseTime(0)
|
---|
1717 | , secDefaultLeaseTime(0)
|
---|
1718 | , secMaxLeaseTime(0)
|
---|
1719 | {
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | /**
|
---|
1723 | * Default constructor.
|
---|
1724 | */
|
---|
1725 | DHCPGroupConfig::DHCPGroupConfig()
|
---|
1726 | : DHCPConfig()
|
---|
1727 | , strName()
|
---|
1728 | , vecConditions()
|
---|
1729 | {
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 | /**
|
---|
1733 | * Default constructor.
|
---|
1734 | */
|
---|
1735 | DHCPIndividualConfig::DHCPIndividualConfig()
|
---|
1736 | : DHCPConfig()
|
---|
1737 | , strMACAddress()
|
---|
1738 | , strVMName()
|
---|
1739 | , uSlot(0)
|
---|
1740 | {
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | /**
|
---|
1744 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1745 | */
|
---|
1746 | DHCPServer::DHCPServer()
|
---|
1747 | : fEnabled(false)
|
---|
1748 | {
|
---|
1749 | }
|
---|
1750 |
|
---|
1751 | /**
|
---|
1752 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1753 | */
|
---|
1754 | NATNetwork::NATNetwork() :
|
---|
1755 | fEnabled(true),
|
---|
1756 | fIPv6Enabled(false),
|
---|
1757 | fAdvertiseDefaultIPv6Route(false),
|
---|
1758 | fNeedDhcpServer(true),
|
---|
1759 | u32HostLoopback6Offset(0)
|
---|
1760 | {
|
---|
1761 | }
|
---|
1762 |
|
---|
1763 | #ifdef VBOX_WITH_VMNET
|
---|
1764 | /**
|
---|
1765 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1766 | */
|
---|
1767 | HostOnlyNetwork::HostOnlyNetwork() :
|
---|
1768 | strNetworkMask("255.255.255.0"),
|
---|
1769 | strIPLower("192.168.56.1"),
|
---|
1770 | strIPUpper("192.168.56.199"),
|
---|
1771 | fEnabled(true)
|
---|
1772 | {
|
---|
1773 | uuid.create();
|
---|
1774 | }
|
---|
1775 | #endif /* VBOX_WITH_VMNET */
|
---|
1776 |
|
---|
1777 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
1778 | /**
|
---|
1779 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1780 | */
|
---|
1781 | CloudNetwork::CloudNetwork() :
|
---|
1782 | strProviderShortName("OCI"),
|
---|
1783 | strProfileName("Default"),
|
---|
1784 | fEnabled(true)
|
---|
1785 | {
|
---|
1786 | }
|
---|
1787 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
1788 |
|
---|
1789 |
|
---|
1790 |
|
---|
1791 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1792 | //
|
---|
1793 | // MainConfigFile
|
---|
1794 | //
|
---|
1795 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1796 |
|
---|
1797 | /**
|
---|
1798 | * Reads one \<MachineEntry\> from the main VirtualBox.xml file.
|
---|
1799 | * @param elmMachineRegistry
|
---|
1800 | */
|
---|
1801 | void MainConfigFile::readMachineRegistry(const xml::ElementNode &elmMachineRegistry)
|
---|
1802 | {
|
---|
1803 | // <MachineEntry uuid="{ xxx }" src=" xxx "/>
|
---|
1804 | xml::NodesLoop nl1(elmMachineRegistry);
|
---|
1805 | const xml::ElementNode *pelmChild1;
|
---|
1806 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
1807 | {
|
---|
1808 | if (pelmChild1->nameEquals("MachineEntry"))
|
---|
1809 | {
|
---|
1810 | MachineRegistryEntry mre;
|
---|
1811 | Utf8Str strUUID;
|
---|
1812 | if ( pelmChild1->getAttributeValue("uuid", strUUID)
|
---|
1813 | && pelmChild1->getAttributeValue("src", mre.strSettingsFile) )
|
---|
1814 | {
|
---|
1815 | parseUUID(mre.uuid, strUUID, pelmChild1);
|
---|
1816 | llMachines.push_back(mre);
|
---|
1817 | }
|
---|
1818 | else
|
---|
1819 | throw ConfigFileError(this, pelmChild1, N_("Required MachineEntry/@uuid or @src attribute is missing"));
|
---|
1820 | }
|
---|
1821 | }
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 | /**
|
---|
1825 | * Builds the XML tree for the DHCP servers.
|
---|
1826 | */
|
---|
1827 | void MainConfigFile::buildDHCPServers(xml::ElementNode &elmDHCPServers, DHCPServersList const &ll)
|
---|
1828 | {
|
---|
1829 | for (DHCPServersList::const_iterator it = ll.begin(); it != ll.end(); ++it)
|
---|
1830 | {
|
---|
1831 | const DHCPServer &srv = *it;
|
---|
1832 | xml::ElementNode *pElmThis = elmDHCPServers.createChild("DHCPServer");
|
---|
1833 |
|
---|
1834 | pElmThis->setAttribute("networkName", srv.strNetworkName);
|
---|
1835 | pElmThis->setAttribute("IPAddress", srv.strIPAddress);
|
---|
1836 | DhcpOptConstIterator itOpt = srv.globalConfig.mapOptions.find(DHCPOption_SubnetMask);
|
---|
1837 | if (itOpt != srv.globalConfig.mapOptions.end())
|
---|
1838 | pElmThis->setAttribute("networkMask", itOpt->second.strValue);
|
---|
1839 | pElmThis->setAttribute("lowerIP", srv.strIPLower);
|
---|
1840 | pElmThis->setAttribute("upperIP", srv.strIPUpper);
|
---|
1841 | pElmThis->setAttribute("enabled", (srv.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
1842 |
|
---|
1843 | /* We don't want duplicate validation check of networkMask here*/
|
---|
1844 | if (srv.globalConfig.mapOptions.size() > (itOpt != srv.globalConfig.mapOptions.end() ? 1U : 0U))
|
---|
1845 | {
|
---|
1846 | xml::ElementNode *pElmOptions = pElmThis->createChild("Options");
|
---|
1847 | buildDHCPOptions(*pElmOptions, srv.globalConfig, true);
|
---|
1848 | }
|
---|
1849 |
|
---|
1850 | for (DHCPGroupConfigVec::const_iterator itGroup = srv.vecGroupConfigs.begin();
|
---|
1851 | itGroup != srv.vecGroupConfigs.end(); ++itGroup)
|
---|
1852 | {
|
---|
1853 | DHCPGroupConfig const &rGroupConfig = *itGroup;
|
---|
1854 |
|
---|
1855 | xml::ElementNode *pElmGroup = pElmThis->createChild("Group");
|
---|
1856 | pElmGroup->setAttribute("name", rGroupConfig.strName);
|
---|
1857 | buildDHCPOptions(*pElmGroup, rGroupConfig, false);
|
---|
1858 |
|
---|
1859 | for (DHCPGroupConditionVec::const_iterator itCond = rGroupConfig.vecConditions.begin();
|
---|
1860 | itCond != rGroupConfig.vecConditions.end(); ++itCond)
|
---|
1861 | {
|
---|
1862 | xml::ElementNode *pElmCondition = pElmGroup->createChild("Condition");
|
---|
1863 | pElmCondition->setAttribute("inclusive", itCond->fInclusive);
|
---|
1864 | pElmCondition->setAttribute("type", (int32_t)itCond->enmType);
|
---|
1865 | pElmCondition->setAttribute("value", itCond->strValue);
|
---|
1866 | }
|
---|
1867 | }
|
---|
1868 |
|
---|
1869 | for (DHCPIndividualConfigMap::const_iterator itHost = srv.mapIndividualConfigs.begin();
|
---|
1870 | itHost != srv.mapIndividualConfigs.end(); ++itHost)
|
---|
1871 | {
|
---|
1872 | DHCPIndividualConfig const &rIndividualConfig = itHost->second;
|
---|
1873 |
|
---|
1874 | xml::ElementNode *pElmConfig = pElmThis->createChild("Config");
|
---|
1875 | if (rIndividualConfig.strMACAddress.isNotEmpty())
|
---|
1876 | pElmConfig->setAttribute("MACAddress", rIndividualConfig.strMACAddress);
|
---|
1877 | if (rIndividualConfig.strVMName.isNotEmpty())
|
---|
1878 | pElmConfig->setAttribute("vm-name", rIndividualConfig.strVMName);
|
---|
1879 | if (rIndividualConfig.uSlot != 0 || rIndividualConfig.strVMName.isNotEmpty())
|
---|
1880 | pElmConfig->setAttribute("slot", rIndividualConfig.uSlot);
|
---|
1881 | if (rIndividualConfig.strFixedAddress.isNotEmpty())
|
---|
1882 | pElmConfig->setAttribute("fixedAddress", rIndividualConfig.strFixedAddress);
|
---|
1883 | buildDHCPOptions(*pElmConfig, rIndividualConfig, false);
|
---|
1884 | }
|
---|
1885 | }
|
---|
1886 | }
|
---|
1887 |
|
---|
1888 | /**
|
---|
1889 | * Worker for buildDHCPServers() that builds Options or Config element trees.
|
---|
1890 | */
|
---|
1891 | void MainConfigFile::buildDHCPOptions(xml::ElementNode &elmOptions, DHCPConfig const &rConfig, bool fSkipSubnetMask)
|
---|
1892 | {
|
---|
1893 | /* Generic (and optional) attributes on the Options or Config element: */
|
---|
1894 | if (rConfig.secMinLeaseTime > 0)
|
---|
1895 | elmOptions.setAttribute("secMinLeaseTime", rConfig.secMinLeaseTime);
|
---|
1896 | if (rConfig.secDefaultLeaseTime > 0)
|
---|
1897 | elmOptions.setAttribute("secDefaultLeaseTime", rConfig.secDefaultLeaseTime);
|
---|
1898 | if (rConfig.secMaxLeaseTime > 0)
|
---|
1899 | elmOptions.setAttribute("secMaxLeaseTime", rConfig.secMaxLeaseTime);
|
---|
1900 | if (rConfig.strForcedOptions.isNotEmpty())
|
---|
1901 | elmOptions.setAttribute("forcedOptions", rConfig.strForcedOptions);
|
---|
1902 | if (rConfig.strSuppressedOptions.isNotEmpty())
|
---|
1903 | elmOptions.setAttribute("suppressedOptions", rConfig.strSuppressedOptions);
|
---|
1904 |
|
---|
1905 | /* The DHCP options are <Option> child elements: */
|
---|
1906 | for (DhcpOptConstIterator it = rConfig.mapOptions.begin(); it != rConfig.mapOptions.end(); ++it)
|
---|
1907 | if (it->first != DHCPOption_SubnetMask || !fSkipSubnetMask)
|
---|
1908 | {
|
---|
1909 | xml::ElementNode *pElmOption = elmOptions.createChild("Option");
|
---|
1910 | pElmOption->setAttribute("name", it->first);
|
---|
1911 | pElmOption->setAttribute("value", it->second.strValue);
|
---|
1912 | if (it->second.enmEncoding != DHCPOptionEncoding_Normal)
|
---|
1913 | pElmOption->setAttribute("encoding", (int32_t)it->second.enmEncoding);
|
---|
1914 | }
|
---|
1915 | }
|
---|
1916 |
|
---|
1917 | /**
|
---|
1918 | * Reads in the \<DHCPServers\> chunk.
|
---|
1919 | * @param elmDHCPServers
|
---|
1920 | */
|
---|
1921 | void MainConfigFile::readDHCPServers(const xml::ElementNode &elmDHCPServers)
|
---|
1922 | {
|
---|
1923 | xml::NodesLoop nl1(elmDHCPServers);
|
---|
1924 | const xml::ElementNode *pelmServer;
|
---|
1925 | while ((pelmServer = nl1.forAllNodes()))
|
---|
1926 | {
|
---|
1927 | if (pelmServer->nameEquals("DHCPServer"))
|
---|
1928 | {
|
---|
1929 | DHCPServer srv;
|
---|
1930 | if ( pelmServer->getAttributeValue("networkName", srv.strNetworkName)
|
---|
1931 | && pelmServer->getAttributeValue("IPAddress", srv.strIPAddress)
|
---|
1932 | && pelmServer->getAttributeValue("networkMask", srv.globalConfig.mapOptions[DHCPOption_SubnetMask].strValue)
|
---|
1933 | && pelmServer->getAttributeValue("lowerIP", srv.strIPLower)
|
---|
1934 | && pelmServer->getAttributeValue("upperIP", srv.strIPUpper)
|
---|
1935 | && pelmServer->getAttributeValue("enabled", srv.fEnabled) )
|
---|
1936 | {
|
---|
1937 | /* Global options: */
|
---|
1938 | const xml::ElementNode *pElmOptions;
|
---|
1939 | xml::NodesLoop nlOptions(*pelmServer, "Options");
|
---|
1940 | while ((pElmOptions = nlOptions.forAllNodes()) != NULL) /** @todo this loop makes no sense, there can only be one \<Options\> child. */
|
---|
1941 | readDHCPOptions(srv.globalConfig, *pElmOptions, true /*fIgnoreSubnetMask*/);
|
---|
1942 |
|
---|
1943 | /* Group configurations: */
|
---|
1944 | xml::NodesLoop nlGroup(*pelmServer, "Group");
|
---|
1945 | const xml::ElementNode *pElmGroup;
|
---|
1946 | size_t i = 0;
|
---|
1947 | while ((pElmGroup = nlGroup.forAllNodes()) != NULL)
|
---|
1948 | {
|
---|
1949 | srv.vecGroupConfigs.push_back(DHCPGroupConfig());
|
---|
1950 | DHCPGroupConfig &rGroupConfig = srv.vecGroupConfigs.back();
|
---|
1951 |
|
---|
1952 | if (!pElmGroup->getAttributeValue("name", rGroupConfig.strName))
|
---|
1953 | rGroupConfig.strName.printf("Unamed Group #%u", ++i);
|
---|
1954 |
|
---|
1955 | readDHCPOptions(rGroupConfig, *pElmGroup, false /*fIgnoreSubnetMask*/);
|
---|
1956 |
|
---|
1957 | xml::NodesLoop nlCondition(*pElmGroup, "Condition");
|
---|
1958 | const xml::ElementNode *pElmCondition;
|
---|
1959 | while ((pElmCondition = nlCondition.forAllNodes()) != NULL)
|
---|
1960 | {
|
---|
1961 | rGroupConfig.vecConditions.push_back(DHCPGroupCondition());
|
---|
1962 | DHCPGroupCondition &rGroupCondition = rGroupConfig.vecConditions.back();
|
---|
1963 |
|
---|
1964 | if (!pElmCondition->getAttributeValue("inclusive", rGroupCondition.fInclusive))
|
---|
1965 | rGroupCondition.fInclusive = true;
|
---|
1966 |
|
---|
1967 | int32_t iType;
|
---|
1968 | if (!pElmCondition->getAttributeValue("type", iType))
|
---|
1969 | iType = DHCPGroupConditionType_MAC;
|
---|
1970 | rGroupCondition.enmType = (DHCPGroupConditionType_T)iType;
|
---|
1971 |
|
---|
1972 | pElmCondition->getAttributeValue("value", rGroupCondition.strValue);
|
---|
1973 | }
|
---|
1974 | }
|
---|
1975 |
|
---|
1976 | /* host specific configuration: */
|
---|
1977 | xml::NodesLoop nlConfig(*pelmServer, "Config");
|
---|
1978 | const xml::ElementNode *pElmConfig;
|
---|
1979 | while ((pElmConfig = nlConfig.forAllNodes()) != NULL)
|
---|
1980 | {
|
---|
1981 | com::Utf8Str strMACAddress;
|
---|
1982 | if (!pElmConfig->getAttributeValue("MACAddress", strMACAddress))
|
---|
1983 | strMACAddress.setNull();
|
---|
1984 |
|
---|
1985 | com::Utf8Str strVMName;
|
---|
1986 | if (!pElmConfig->getAttributeValue("vm-name", strVMName))
|
---|
1987 | strVMName.setNull();
|
---|
1988 |
|
---|
1989 | uint32_t uSlot;
|
---|
1990 | if (!pElmConfig->getAttributeValue("slot", uSlot))
|
---|
1991 | uSlot = 0;
|
---|
1992 |
|
---|
1993 | com::Utf8Str strKey;
|
---|
1994 | if (strVMName.isNotEmpty())
|
---|
1995 | strKey.printf("%s/%u", strVMName.c_str(), uSlot);
|
---|
1996 | else
|
---|
1997 | strKey.printf("%s/%u", strMACAddress.c_str(), uSlot);
|
---|
1998 |
|
---|
1999 | DHCPIndividualConfig &rIndividualConfig = srv.mapIndividualConfigs[strKey];
|
---|
2000 | rIndividualConfig.strMACAddress = strMACAddress;
|
---|
2001 | rIndividualConfig.strVMName = strVMName;
|
---|
2002 | rIndividualConfig.uSlot = uSlot;
|
---|
2003 | pElmConfig->getAttributeValue("fixedAddress", rIndividualConfig.strFixedAddress);
|
---|
2004 |
|
---|
2005 | readDHCPOptions(rIndividualConfig, *pElmConfig, false /*fIgnoreSubnetMask*/);
|
---|
2006 | }
|
---|
2007 |
|
---|
2008 | llDhcpServers.push_back(srv);
|
---|
2009 | }
|
---|
2010 | else
|
---|
2011 | throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
|
---|
2012 | }
|
---|
2013 | }
|
---|
2014 | }
|
---|
2015 |
|
---|
2016 | /**
|
---|
2017 | * Worker for readDHCPServers that reads a configuration, either global,
|
---|
2018 | * group or host (VM+NIC) specific.
|
---|
2019 | */
|
---|
2020 | void MainConfigFile::readDHCPOptions(DHCPConfig &rConfig, const xml::ElementNode &elmConfig, bool fIgnoreSubnetMask)
|
---|
2021 | {
|
---|
2022 | /* Generic (and optional) attributes on the Options or Config element: */
|
---|
2023 | if (!elmConfig.getAttributeValue("secMinLeaseTime", rConfig.secMinLeaseTime))
|
---|
2024 | rConfig.secMinLeaseTime = 0;
|
---|
2025 | if (!elmConfig.getAttributeValue("secDefaultLeaseTime", rConfig.secDefaultLeaseTime))
|
---|
2026 | rConfig.secDefaultLeaseTime = 0;
|
---|
2027 | if (!elmConfig.getAttributeValue("secMaxLeaseTime", rConfig.secMaxLeaseTime))
|
---|
2028 | rConfig.secMaxLeaseTime = 0;
|
---|
2029 | if (!elmConfig.getAttributeValue("forcedOptions", rConfig.strForcedOptions))
|
---|
2030 | rConfig.strSuppressedOptions.setNull();
|
---|
2031 | if (!elmConfig.getAttributeValue("suppressedOptions", rConfig.strSuppressedOptions))
|
---|
2032 | rConfig.strSuppressedOptions.setNull();
|
---|
2033 |
|
---|
2034 | /* The DHCP options are <Option> child elements: */
|
---|
2035 | xml::NodesLoop nl2(elmConfig, "Option");
|
---|
2036 | const xml::ElementNode *pElmOption;
|
---|
2037 | while ((pElmOption = nl2.forAllNodes()) != NULL)
|
---|
2038 | {
|
---|
2039 | int32_t iOptName;
|
---|
2040 | if (!pElmOption->getAttributeValue("name", iOptName))
|
---|
2041 | continue;
|
---|
2042 | DHCPOption_T OptName = (DHCPOption_T)iOptName;
|
---|
2043 | if (OptName == DHCPOption_SubnetMask && fIgnoreSubnetMask)
|
---|
2044 | continue;
|
---|
2045 |
|
---|
2046 | com::Utf8Str strValue;
|
---|
2047 | pElmOption->getAttributeValue("value", strValue);
|
---|
2048 |
|
---|
2049 | int32_t iOptEnc;
|
---|
2050 | if (!pElmOption->getAttributeValue("encoding", iOptEnc))
|
---|
2051 | iOptEnc = DHCPOptionEncoding_Normal;
|
---|
2052 |
|
---|
2053 | rConfig.mapOptions[OptName] = DhcpOptValue(strValue, (DHCPOptionEncoding_T)iOptEnc);
|
---|
2054 | } /* end of forall("Option") */
|
---|
2055 |
|
---|
2056 | }
|
---|
2057 |
|
---|
2058 | /**
|
---|
2059 | * Reads in the \<NATNetworks\> chunk.
|
---|
2060 | * @param elmNATNetworks
|
---|
2061 | */
|
---|
2062 | void MainConfigFile::readNATNetworks(const xml::ElementNode &elmNATNetworks)
|
---|
2063 | {
|
---|
2064 | xml::NodesLoop nl1(elmNATNetworks);
|
---|
2065 | const xml::ElementNode *pelmNet;
|
---|
2066 | while ((pelmNet = nl1.forAllNodes()))
|
---|
2067 | {
|
---|
2068 | if (pelmNet->nameEquals("NATNetwork"))
|
---|
2069 | {
|
---|
2070 | NATNetwork net;
|
---|
2071 | if ( pelmNet->getAttributeValue("networkName", net.strNetworkName)
|
---|
2072 | && pelmNet->getAttributeValue("enabled", net.fEnabled)
|
---|
2073 | && pelmNet->getAttributeValue("network", net.strIPv4NetworkCidr)
|
---|
2074 | && pelmNet->getAttributeValue("ipv6", net.fIPv6Enabled)
|
---|
2075 | && pelmNet->getAttributeValue("ipv6prefix", net.strIPv6Prefix)
|
---|
2076 | && pelmNet->getAttributeValue("advertiseDefaultIPv6Route", net.fAdvertiseDefaultIPv6Route)
|
---|
2077 | && pelmNet->getAttributeValue("needDhcp", net.fNeedDhcpServer) )
|
---|
2078 | {
|
---|
2079 | pelmNet->getAttributeValue("loopback6", net.u32HostLoopback6Offset);
|
---|
2080 | const xml::ElementNode *pelmMappings;
|
---|
2081 | if ((pelmMappings = pelmNet->findChildElement("Mappings")))
|
---|
2082 | readNATLoopbacks(*pelmMappings, net.llHostLoopbackOffsetList);
|
---|
2083 |
|
---|
2084 | const xml::ElementNode *pelmPortForwardRules4;
|
---|
2085 | if ((pelmPortForwardRules4 = pelmNet->findChildElement("PortForwarding4")))
|
---|
2086 | readNATForwardRulesMap(*pelmPortForwardRules4,
|
---|
2087 | net.mapPortForwardRules4);
|
---|
2088 |
|
---|
2089 | const xml::ElementNode *pelmPortForwardRules6;
|
---|
2090 | if ((pelmPortForwardRules6 = pelmNet->findChildElement("PortForwarding6")))
|
---|
2091 | readNATForwardRulesMap(*pelmPortForwardRules6,
|
---|
2092 | net.mapPortForwardRules6);
|
---|
2093 |
|
---|
2094 | llNATNetworks.push_back(net);
|
---|
2095 | }
|
---|
2096 | else
|
---|
2097 | throw ConfigFileError(this, pelmNet, N_("Required NATNetwork/@networkName, @gateway, @network,@advertiseDefaultIpv6Route , @needDhcp or @enabled attribute is missing"));
|
---|
2098 | }
|
---|
2099 | }
|
---|
2100 | }
|
---|
2101 |
|
---|
2102 | #ifdef VBOX_WITH_VMNET
|
---|
2103 | /**
|
---|
2104 | * Reads in the \<HostOnlyNetworks\> chunk.
|
---|
2105 | * @param elmHostOnlyNetworks
|
---|
2106 | */
|
---|
2107 | void MainConfigFile::readHostOnlyNetworks(const xml::ElementNode &elmHostOnlyNetworks)
|
---|
2108 | {
|
---|
2109 | xml::NodesLoop nl1(elmHostOnlyNetworks);
|
---|
2110 | const xml::ElementNode *pelmNet;
|
---|
2111 | while ((pelmNet = nl1.forAllNodes()))
|
---|
2112 | {
|
---|
2113 | if (pelmNet->nameEquals("HostOnlyNetwork"))
|
---|
2114 | {
|
---|
2115 | HostOnlyNetwork net;
|
---|
2116 | Utf8Str strID;
|
---|
2117 | if ( pelmNet->getAttributeValue("name", net.strNetworkName)
|
---|
2118 | && pelmNet->getAttributeValue("mask", net.strNetworkMask)
|
---|
2119 | && pelmNet->getAttributeValue("ipLower", net.strIPLower)
|
---|
2120 | && pelmNet->getAttributeValue("ipUpper", net.strIPUpper)
|
---|
2121 | && pelmNet->getAttributeValue("id", strID)
|
---|
2122 | && pelmNet->getAttributeValue("enabled", net.fEnabled) )
|
---|
2123 | {
|
---|
2124 | parseUUID(net.uuid, strID, pelmNet);
|
---|
2125 | llHostOnlyNetworks.push_back(net);
|
---|
2126 | }
|
---|
2127 | else
|
---|
2128 | throw ConfigFileError(this, pelmNet, N_("Required HostOnlyNetwork/@name, @mask, @ipLower, @ipUpper, @id or @enabled attribute is missing"));
|
---|
2129 | }
|
---|
2130 | }
|
---|
2131 | }
|
---|
2132 | #endif /* VBOX_WITH_VMNET */
|
---|
2133 |
|
---|
2134 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2135 | /**
|
---|
2136 | * Reads in the \<CloudNetworks\> chunk.
|
---|
2137 | * @param elmCloudNetworks
|
---|
2138 | */
|
---|
2139 | void MainConfigFile::readCloudNetworks(const xml::ElementNode &elmCloudNetworks)
|
---|
2140 | {
|
---|
2141 | xml::NodesLoop nl1(elmCloudNetworks);
|
---|
2142 | const xml::ElementNode *pelmNet;
|
---|
2143 | while ((pelmNet = nl1.forAllNodes()))
|
---|
2144 | {
|
---|
2145 | if (pelmNet->nameEquals("CloudNetwork"))
|
---|
2146 | {
|
---|
2147 | CloudNetwork net;
|
---|
2148 | if ( pelmNet->getAttributeValue("name", net.strNetworkName)
|
---|
2149 | && pelmNet->getAttributeValue("provider", net.strProviderShortName)
|
---|
2150 | && pelmNet->getAttributeValue("profile", net.strProfileName)
|
---|
2151 | && pelmNet->getAttributeValue("id", net.strNetworkId)
|
---|
2152 | && pelmNet->getAttributeValue("enabled", net.fEnabled) )
|
---|
2153 | {
|
---|
2154 | llCloudNetworks.push_back(net);
|
---|
2155 | }
|
---|
2156 | else
|
---|
2157 | throw ConfigFileError(this, pelmNet, N_("Required CloudNetwork/@name, @provider, @profile, @id or @enabled attribute is missing"));
|
---|
2158 | }
|
---|
2159 | }
|
---|
2160 | }
|
---|
2161 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2162 |
|
---|
2163 | /**
|
---|
2164 | * Creates \<USBDeviceSource\> nodes under the given parent element according to
|
---|
2165 | * the contents of the given USBDeviceSourcesList.
|
---|
2166 | *
|
---|
2167 | * @param elmParent
|
---|
2168 | * @param ll
|
---|
2169 | */
|
---|
2170 | void MainConfigFile::buildUSBDeviceSources(xml::ElementNode &elmParent,
|
---|
2171 | const USBDeviceSourcesList &ll)
|
---|
2172 | {
|
---|
2173 | for (USBDeviceSourcesList::const_iterator it = ll.begin();
|
---|
2174 | it != ll.end();
|
---|
2175 | ++it)
|
---|
2176 | {
|
---|
2177 | const USBDeviceSource &src = *it;
|
---|
2178 | xml::ElementNode *pelmSource = elmParent.createChild("USBDeviceSource");
|
---|
2179 | pelmSource->setAttribute("name", src.strName);
|
---|
2180 | pelmSource->setAttribute("backend", src.strBackend);
|
---|
2181 | pelmSource->setAttribute("address", src.strAddress);
|
---|
2182 |
|
---|
2183 | /* Write the properties. */
|
---|
2184 | for (StringsMap::const_iterator itProp = src.properties.begin();
|
---|
2185 | itProp != src.properties.end();
|
---|
2186 | ++itProp)
|
---|
2187 | {
|
---|
2188 | xml::ElementNode *pelmProp = pelmSource->createChild("Property");
|
---|
2189 | pelmProp->setAttribute("name", itProp->first);
|
---|
2190 | pelmProp->setAttribute("value", itProp->second);
|
---|
2191 | }
|
---|
2192 | }
|
---|
2193 | }
|
---|
2194 |
|
---|
2195 | /**
|
---|
2196 | * Reads \<USBDeviceFilter\> entries from under the given elmDeviceFilters node and
|
---|
2197 | * stores them in the given linklist. This is in ConfigFileBase because it's used
|
---|
2198 | * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
|
---|
2199 | * filters).
|
---|
2200 | * @param elmDeviceSources
|
---|
2201 | * @param ll
|
---|
2202 | */
|
---|
2203 | void MainConfigFile::readUSBDeviceSources(const xml::ElementNode &elmDeviceSources,
|
---|
2204 | USBDeviceSourcesList &ll)
|
---|
2205 | {
|
---|
2206 | xml::NodesLoop nl1(elmDeviceSources, "USBDeviceSource");
|
---|
2207 | const xml::ElementNode *pelmChild;
|
---|
2208 | while ((pelmChild = nl1.forAllNodes()))
|
---|
2209 | {
|
---|
2210 | USBDeviceSource src;
|
---|
2211 |
|
---|
2212 | if ( pelmChild->getAttributeValue("name", src.strName)
|
---|
2213 | && pelmChild->getAttributeValue("backend", src.strBackend)
|
---|
2214 | && pelmChild->getAttributeValue("address", src.strAddress))
|
---|
2215 | {
|
---|
2216 | // handle medium properties
|
---|
2217 | xml::NodesLoop nl2(*pelmChild, "Property");
|
---|
2218 | const xml::ElementNode *pelmSrcChild;
|
---|
2219 | while ((pelmSrcChild = nl2.forAllNodes()))
|
---|
2220 | {
|
---|
2221 | Utf8Str strPropName, strPropValue;
|
---|
2222 | if ( pelmSrcChild->getAttributeValue("name", strPropName)
|
---|
2223 | && pelmSrcChild->getAttributeValue("value", strPropValue) )
|
---|
2224 | src.properties[strPropName] = strPropValue;
|
---|
2225 | else
|
---|
2226 | throw ConfigFileError(this, pelmSrcChild, N_("Required USBDeviceSource/Property/@name or @value attribute is missing"));
|
---|
2227 | }
|
---|
2228 |
|
---|
2229 | ll.push_back(src);
|
---|
2230 | }
|
---|
2231 | }
|
---|
2232 | }
|
---|
2233 |
|
---|
2234 | /**
|
---|
2235 | * Converts old style Proxy settings from ExtraData/UI section.
|
---|
2236 | *
|
---|
2237 | * Saves proxy settings directly to systemProperties structure.
|
---|
2238 | *
|
---|
2239 | * @returns true if conversion was successfull, false if not.
|
---|
2240 | * @param strUIProxySettings The GUI settings string to convert.
|
---|
2241 | */
|
---|
2242 | bool MainConfigFile::convertGuiProxySettings(const com::Utf8Str &strUIProxySettings)
|
---|
2243 | {
|
---|
2244 | /*
|
---|
2245 | * Possible variants:
|
---|
2246 | * - "ProxyAuto,proxyserver.url,1080,authDisabled,,"
|
---|
2247 | * - "ProxyDisabled,proxyserver.url,1080,authDisabled,,"
|
---|
2248 | * - "ProxyEnabled,proxyserver.url,1080,authDisabled,,"
|
---|
2249 | *
|
---|
2250 | * Note! We only need to bother with the first three fields as the last
|
---|
2251 | * three was never really used or ever actually passed to the HTTP
|
---|
2252 | * client code.
|
---|
2253 | */
|
---|
2254 | /* First field: The proxy mode. */
|
---|
2255 | const char *psz = RTStrStripL(strUIProxySettings.c_str());
|
---|
2256 | static const struct { const char *psz; size_t cch; ProxyMode_T enmMode; } s_aModes[] =
|
---|
2257 | {
|
---|
2258 | { RT_STR_TUPLE("ProxyAuto"), ProxyMode_System },
|
---|
2259 | { RT_STR_TUPLE("ProxyDisabled"), ProxyMode_NoProxy },
|
---|
2260 | { RT_STR_TUPLE("ProxyEnabled"), ProxyMode_Manual },
|
---|
2261 | };
|
---|
2262 | for (size_t i = 0; i < RT_ELEMENTS(s_aModes); i++)
|
---|
2263 | if (RTStrNICmpAscii(psz, s_aModes[i].psz, s_aModes[i].cch) == 0)
|
---|
2264 | {
|
---|
2265 | systemProperties.uProxyMode = s_aModes[i].enmMode;
|
---|
2266 | psz = RTStrStripL(psz + s_aModes[i].cch);
|
---|
2267 | if (*psz == ',')
|
---|
2268 | {
|
---|
2269 | /* Second field: The proxy host, possibly fully fledged proxy URL. */
|
---|
2270 | psz = RTStrStripL(psz + 1);
|
---|
2271 | if (*psz != '\0' && *psz != ',')
|
---|
2272 | {
|
---|
2273 | const char *pszEnd = strchr(psz, ',');
|
---|
2274 | size_t cchHost = pszEnd ? (size_t)(pszEnd - psz) : strlen(psz);
|
---|
2275 | while (cchHost > 0 && RT_C_IS_SPACE(psz[cchHost - 1]))
|
---|
2276 | cchHost--;
|
---|
2277 | systemProperties.strProxyUrl.assign(psz, cchHost);
|
---|
2278 | if (systemProperties.strProxyUrl.find("://") == RTCString::npos)
|
---|
2279 | systemProperties.strProxyUrl.replace(0, 0, "http://");
|
---|
2280 |
|
---|
2281 | /* Third field: The proxy port. Defaulted to 1080 for all proxies.
|
---|
2282 | The new settings has type specific default ports. */
|
---|
2283 | uint16_t uPort = 1080;
|
---|
2284 | if (pszEnd)
|
---|
2285 | {
|
---|
2286 | int vrc = RTStrToUInt16Ex(RTStrStripL(pszEnd + 1), NULL, 10, &uPort);
|
---|
2287 | if (RT_FAILURE(vrc))
|
---|
2288 | uPort = 1080;
|
---|
2289 | }
|
---|
2290 | RTURIPARSED Parsed;
|
---|
2291 | int vrc = RTUriParse(systemProperties.strProxyUrl.c_str(), &Parsed);
|
---|
2292 | if (RT_SUCCESS(vrc))
|
---|
2293 | {
|
---|
2294 | if (Parsed.uAuthorityPort == UINT32_MAX)
|
---|
2295 | systemProperties.strProxyUrl.appendPrintf(systemProperties.strProxyUrl.endsWith(":")
|
---|
2296 | ? "%u" : ":%u", uPort);
|
---|
2297 | }
|
---|
2298 | else
|
---|
2299 | {
|
---|
2300 | LogRelFunc(("Dropping invalid proxy URL for %u: %s\n",
|
---|
2301 | systemProperties.uProxyMode, systemProperties.strProxyUrl.c_str()));
|
---|
2302 | systemProperties.strProxyUrl.setNull();
|
---|
2303 | }
|
---|
2304 | }
|
---|
2305 | /* else: don't bother with the rest if we haven't got a host. */
|
---|
2306 | }
|
---|
2307 | if ( systemProperties.strProxyUrl.isEmpty()
|
---|
2308 | && systemProperties.uProxyMode == ProxyMode_Manual)
|
---|
2309 | {
|
---|
2310 | systemProperties.uProxyMode = ProxyMode_System;
|
---|
2311 | return false;
|
---|
2312 | }
|
---|
2313 | return true;
|
---|
2314 | }
|
---|
2315 | LogRelFunc(("Unknown proxy type: %s\n", psz));
|
---|
2316 | return false;
|
---|
2317 | }
|
---|
2318 |
|
---|
2319 | /**
|
---|
2320 | * Constructor.
|
---|
2321 | *
|
---|
2322 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
2323 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
2324 | * are initialized with default values.
|
---|
2325 | *
|
---|
2326 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
2327 | * the caller should catch; if this constructor does not throw, then the member
|
---|
2328 | * variables contain meaningful values (either from the file or defaults).
|
---|
2329 | *
|
---|
2330 | * @param pstrFilename
|
---|
2331 | */
|
---|
2332 | MainConfigFile::MainConfigFile(const Utf8Str *pstrFilename)
|
---|
2333 | : ConfigFileBase(pstrFilename)
|
---|
2334 | {
|
---|
2335 | if (pstrFilename)
|
---|
2336 | {
|
---|
2337 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
2338 | // we need only analyze what is in there
|
---|
2339 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
2340 | const xml::ElementNode *pelmRootChild;
|
---|
2341 | bool fCopyProxySettingsFromExtraData = false;
|
---|
2342 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
2343 | {
|
---|
2344 | if (pelmRootChild->nameEquals("Global"))
|
---|
2345 | {
|
---|
2346 | xml::NodesLoop nlGlobalChildren(*pelmRootChild);
|
---|
2347 | const xml::ElementNode *pelmGlobalChild;
|
---|
2348 | while ((pelmGlobalChild = nlGlobalChildren.forAllNodes()))
|
---|
2349 | {
|
---|
2350 | if (pelmGlobalChild->nameEquals("SystemProperties"))
|
---|
2351 | {
|
---|
2352 | pelmGlobalChild->getAttributeValue("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
2353 | pelmGlobalChild->getAttributeValue("LoggingLevel", systemProperties.strLoggingLevel);
|
---|
2354 | pelmGlobalChild->getAttributeValue("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
2355 | if (!pelmGlobalChild->getAttributeValue("VRDEAuthLibrary", systemProperties.strVRDEAuthLibrary))
|
---|
2356 | // pre-1.11 used @remoteDisplayAuthLibrary instead
|
---|
2357 | pelmGlobalChild->getAttributeValue("remoteDisplayAuthLibrary", systemProperties.strVRDEAuthLibrary);
|
---|
2358 | pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
2359 | pelmGlobalChild->getAttributeValue("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
|
---|
2360 | pelmGlobalChild->getAttributeValue("defaultCryptoExtPack", systemProperties.strDefaultCryptoExtPack);
|
---|
2361 | pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.uLogHistoryCount);
|
---|
2362 | pelmGlobalChild->getAttributeValue("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
|
---|
2363 | pelmGlobalChild->getAttributeValue("defaultFrontend", systemProperties.strDefaultFrontend);
|
---|
2364 | if (m->sv < SettingsVersion_v1_20) /* exclusiveHwVirt was part of SystemProperties for < v1.20. */
|
---|
2365 | pelmGlobalChild->getAttributeValue("exclusiveHwVirt", platformProperties.fExclusiveHwVirt);
|
---|
2366 | if (!pelmGlobalChild->getAttributeValue("proxyMode", systemProperties.uProxyMode))
|
---|
2367 | fCopyProxySettingsFromExtraData = true;
|
---|
2368 | pelmGlobalChild->getAttributeValue("proxyUrl", systemProperties.strProxyUrl);
|
---|
2369 | pelmGlobalChild->getAttributeValue("LanguageId", systemProperties.strLanguageId);
|
---|
2370 | }
|
---|
2371 | if ( pelmGlobalChild->nameEquals("PlatformProperties")
|
---|
2372 | && m->sv >= SettingsVersion_v1_20)
|
---|
2373 | {
|
---|
2374 | /* Since settings v1.20 exclusiveHwVirt is part of PlatformProperties. */
|
---|
2375 | pelmGlobalChild->getAttributeValue("exclusiveHwVirt", platformProperties.fExclusiveHwVirt);
|
---|
2376 | }
|
---|
2377 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
2378 | else if (pelmGlobalChild->nameEquals("Updates"))
|
---|
2379 | {
|
---|
2380 | /* We keep the updates configuration as part of the host for now, as the API exposes the IHost::updateHost attribute,
|
---|
2381 | * but use an own "Updates" branch in the XML for better structurizing stuff in the future. */
|
---|
2382 | UpdateAgent &updateHost = host.updateHost;
|
---|
2383 |
|
---|
2384 | xml::NodesLoop nlLevel4(*pelmGlobalChild);
|
---|
2385 | const xml::ElementNode *pelmLevel4Child;
|
---|
2386 | while ((pelmLevel4Child = nlLevel4.forAllNodes()))
|
---|
2387 | {
|
---|
2388 | if (pelmLevel4Child->nameEquals("Host"))
|
---|
2389 | {
|
---|
2390 | pelmLevel4Child->getAttributeValue("enabled", updateHost.fEnabled);
|
---|
2391 | pelmLevel4Child->getAttributeValue("channel", (uint32_t&)updateHost.enmChannel);
|
---|
2392 | pelmLevel4Child->getAttributeValue("checkFreqSec", updateHost.uCheckFreqSeconds);
|
---|
2393 | pelmLevel4Child->getAttributeValue("repoUrl", updateHost.strRepoUrl);
|
---|
2394 | pelmLevel4Child->getAttributeValue("lastCheckDate", updateHost.strLastCheckDate);
|
---|
2395 | pelmLevel4Child->getAttributeValue("checkCount", updateHost.uCheckCount);
|
---|
2396 | }
|
---|
2397 | /** @todo Add update settings for ExtPack and Guest Additions here later. See @bugref{7983}. */
|
---|
2398 | }
|
---|
2399 |
|
---|
2400 | /* Global enabled switch for updates. Currently bound to host updates, as this is the only update we have so far. */
|
---|
2401 | pelmGlobalChild->getAttributeValue("enabled", updateHost.fEnabled);
|
---|
2402 | }
|
---|
2403 | #endif
|
---|
2404 | else if (pelmGlobalChild->nameEquals("ExtraData"))
|
---|
2405 | readExtraData(*pelmGlobalChild, mapExtraDataItems);
|
---|
2406 | else if (pelmGlobalChild->nameEquals("MachineRegistry"))
|
---|
2407 | readMachineRegistry(*pelmGlobalChild);
|
---|
2408 | else if ( (pelmGlobalChild->nameEquals("MediaRegistry"))
|
---|
2409 | || ( (m->sv < SettingsVersion_v1_4)
|
---|
2410 | && (pelmGlobalChild->nameEquals("DiskRegistry"))
|
---|
2411 | )
|
---|
2412 | )
|
---|
2413 | readMediaRegistry(*pelmGlobalChild, mediaRegistry);
|
---|
2414 | else if (pelmGlobalChild->nameEquals("NetserviceRegistry"))
|
---|
2415 | {
|
---|
2416 | xml::NodesLoop nlLevel4(*pelmGlobalChild);
|
---|
2417 | const xml::ElementNode *pelmLevel4Child;
|
---|
2418 | while ((pelmLevel4Child = nlLevel4.forAllNodes()))
|
---|
2419 | {
|
---|
2420 | if (pelmLevel4Child->nameEquals("DHCPServers"))
|
---|
2421 | readDHCPServers(*pelmLevel4Child);
|
---|
2422 | if (pelmLevel4Child->nameEquals("NATNetworks"))
|
---|
2423 | readNATNetworks(*pelmLevel4Child);
|
---|
2424 | #ifdef VBOX_WITH_VMNET
|
---|
2425 | if (pelmLevel4Child->nameEquals("HostOnlyNetworks"))
|
---|
2426 | readHostOnlyNetworks(*pelmLevel4Child);
|
---|
2427 | #endif /* VBOX_WITH_VMNET */
|
---|
2428 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2429 | if (pelmLevel4Child->nameEquals("CloudNetworks"))
|
---|
2430 | readCloudNetworks(*pelmLevel4Child);
|
---|
2431 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2432 | }
|
---|
2433 | }
|
---|
2434 | else if (pelmGlobalChild->nameEquals("USBDeviceFilters"))
|
---|
2435 | readUSBDeviceFilters(*pelmGlobalChild, host.llUSBDeviceFilters);
|
---|
2436 | else if (pelmGlobalChild->nameEquals("USBDeviceSources"))
|
---|
2437 | readUSBDeviceSources(*pelmGlobalChild, host.llUSBDeviceSources);
|
---|
2438 | }
|
---|
2439 | } // end if (pelmRootChild->nameEquals("Global"))
|
---|
2440 | }
|
---|
2441 |
|
---|
2442 | if (fCopyProxySettingsFromExtraData)
|
---|
2443 | for (StringsMap::const_iterator it = mapExtraDataItems.begin(); it != mapExtraDataItems.end(); ++it)
|
---|
2444 | if (it->first.equals("GUI/ProxySettings"))
|
---|
2445 | {
|
---|
2446 | convertGuiProxySettings(it->second);
|
---|
2447 | break;
|
---|
2448 | }
|
---|
2449 |
|
---|
2450 | clearDocument();
|
---|
2451 | }
|
---|
2452 |
|
---|
2453 | // DHCP servers were introduced with settings version 1.7; if we're loading
|
---|
2454 | // from an older version OR this is a fresh install, then add one DHCP server
|
---|
2455 | // with default settings
|
---|
2456 | if ( (!llDhcpServers.size())
|
---|
2457 | && ( (!pstrFilename) // empty VirtualBox.xml file
|
---|
2458 | || (m->sv < SettingsVersion_v1_7) // upgrading from before 1.7
|
---|
2459 | )
|
---|
2460 | )
|
---|
2461 | {
|
---|
2462 | DHCPServer srv;
|
---|
2463 | #ifdef RT_OS_WINDOWS
|
---|
2464 | srv.strNetworkName = "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter";
|
---|
2465 | #else
|
---|
2466 | srv.strNetworkName = "HostInterfaceNetworking-vboxnet0";
|
---|
2467 | #endif
|
---|
2468 | srv.strIPAddress = "192.168.56.100";
|
---|
2469 | srv.globalConfig.mapOptions[DHCPOption_SubnetMask] = DhcpOptValue("255.255.255.0");
|
---|
2470 | srv.strIPLower = "192.168.56.101";
|
---|
2471 | srv.strIPUpper = "192.168.56.254";
|
---|
2472 | srv.fEnabled = true;
|
---|
2473 | llDhcpServers.push_back(srv);
|
---|
2474 | }
|
---|
2475 | }
|
---|
2476 |
|
---|
2477 | void MainConfigFile::bumpSettingsVersionIfNeeded()
|
---|
2478 | {
|
---|
2479 | #ifdef VBOX_WITH_VMNET
|
---|
2480 | if (m->sv < SettingsVersion_v1_19)
|
---|
2481 | {
|
---|
2482 | // VirtualBox 7.0 adds support for host-only networks.
|
---|
2483 | if (!llHostOnlyNetworks.empty())
|
---|
2484 | m->sv = SettingsVersion_v1_19;
|
---|
2485 | }
|
---|
2486 | #endif /* VBOX_WITH_VMNET */
|
---|
2487 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2488 | if (m->sv < SettingsVersion_v1_18)
|
---|
2489 | {
|
---|
2490 | // VirtualBox 6.1 adds support for cloud networks.
|
---|
2491 | if (!llCloudNetworks.empty())
|
---|
2492 | m->sv = SettingsVersion_v1_18;
|
---|
2493 | }
|
---|
2494 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2495 |
|
---|
2496 | if (m->sv < SettingsVersion_v1_16)
|
---|
2497 | {
|
---|
2498 | // VirtualBox 5.1 add support for additional USB device sources.
|
---|
2499 | if (!host.llUSBDeviceSources.empty())
|
---|
2500 | m->sv = SettingsVersion_v1_16;
|
---|
2501 | }
|
---|
2502 |
|
---|
2503 | if (m->sv < SettingsVersion_v1_14)
|
---|
2504 | {
|
---|
2505 | // VirtualBox 4.3 adds NAT networks.
|
---|
2506 | if ( !llNATNetworks.empty())
|
---|
2507 | m->sv = SettingsVersion_v1_14;
|
---|
2508 | }
|
---|
2509 | }
|
---|
2510 |
|
---|
2511 |
|
---|
2512 | /**
|
---|
2513 | * Called from the IVirtualBox interface to write out VirtualBox.xml. This
|
---|
2514 | * builds an XML DOM tree and writes it out to disk.
|
---|
2515 | */
|
---|
2516 | void MainConfigFile::write(const com::Utf8Str strFilename)
|
---|
2517 | {
|
---|
2518 | bumpSettingsVersionIfNeeded();
|
---|
2519 |
|
---|
2520 | m->strFilename = strFilename;
|
---|
2521 | specialBackupIfFirstBump();
|
---|
2522 | createStubDocument();
|
---|
2523 |
|
---|
2524 | xml::ElementNode *pelmGlobal = m->pelmRoot->createChild("Global");
|
---|
2525 |
|
---|
2526 | buildExtraData(*pelmGlobal, mapExtraDataItems);
|
---|
2527 |
|
---|
2528 | xml::ElementNode *pelmMachineRegistry = pelmGlobal->createChild("MachineRegistry");
|
---|
2529 | for (MachinesRegistry::const_iterator it = llMachines.begin();
|
---|
2530 | it != llMachines.end();
|
---|
2531 | ++it)
|
---|
2532 | {
|
---|
2533 | // <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"/>
|
---|
2534 | const MachineRegistryEntry &mre = *it;
|
---|
2535 | xml::ElementNode *pelmMachineEntry = pelmMachineRegistry->createChild("MachineEntry");
|
---|
2536 | pelmMachineEntry->setAttribute("uuid", mre.uuid.toStringCurly());
|
---|
2537 | pelmMachineEntry->setAttribute("src", mre.strSettingsFile);
|
---|
2538 | }
|
---|
2539 |
|
---|
2540 | buildMediaRegistry(*pelmGlobal, mediaRegistry);
|
---|
2541 |
|
---|
2542 | xml::ElementNode *pelmNetServiceRegistry = pelmGlobal->createChild("NetserviceRegistry"); /** @todo r=bird: wrong capitalization of NetServiceRegistry. sigh. */
|
---|
2543 | buildDHCPServers(*pelmNetServiceRegistry->createChild("DHCPServers"), llDhcpServers);
|
---|
2544 |
|
---|
2545 | xml::ElementNode *pelmNATNetworks;
|
---|
2546 | /* don't create entry if no NAT networks are registered. */
|
---|
2547 | if (!llNATNetworks.empty())
|
---|
2548 | {
|
---|
2549 | pelmNATNetworks = pelmNetServiceRegistry->createChild("NATNetworks");
|
---|
2550 | for (NATNetworksList::const_iterator it = llNATNetworks.begin();
|
---|
2551 | it != llNATNetworks.end();
|
---|
2552 | ++it)
|
---|
2553 | {
|
---|
2554 | const NATNetwork &n = *it;
|
---|
2555 | xml::ElementNode *pelmThis = pelmNATNetworks->createChild("NATNetwork");
|
---|
2556 | pelmThis->setAttribute("networkName", n.strNetworkName);
|
---|
2557 | pelmThis->setAttribute("network", n.strIPv4NetworkCidr);
|
---|
2558 | pelmThis->setAttribute("ipv6", n.fIPv6Enabled ? 1 : 0);
|
---|
2559 | pelmThis->setAttribute("ipv6prefix", n.strIPv6Prefix);
|
---|
2560 | pelmThis->setAttribute("advertiseDefaultIPv6Route", (n.fAdvertiseDefaultIPv6Route)? 1 : 0);
|
---|
2561 | pelmThis->setAttribute("needDhcp", (n.fNeedDhcpServer) ? 1 : 0);
|
---|
2562 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
2563 | if (n.mapPortForwardRules4.size())
|
---|
2564 | {
|
---|
2565 | xml::ElementNode *pelmPf4 = pelmThis->createChild("PortForwarding4");
|
---|
2566 | buildNATForwardRulesMap(*pelmPf4, n.mapPortForwardRules4);
|
---|
2567 | }
|
---|
2568 | if (n.mapPortForwardRules6.size())
|
---|
2569 | {
|
---|
2570 | xml::ElementNode *pelmPf6 = pelmThis->createChild("PortForwarding6");
|
---|
2571 | buildNATForwardRulesMap(*pelmPf6, n.mapPortForwardRules6);
|
---|
2572 | }
|
---|
2573 |
|
---|
2574 | if (n.llHostLoopbackOffsetList.size())
|
---|
2575 | {
|
---|
2576 | xml::ElementNode *pelmMappings = pelmThis->createChild("Mappings");
|
---|
2577 | buildNATLoopbacks(*pelmMappings, n.llHostLoopbackOffsetList);
|
---|
2578 |
|
---|
2579 | }
|
---|
2580 | }
|
---|
2581 | }
|
---|
2582 |
|
---|
2583 | #ifdef VBOX_WITH_VMNET
|
---|
2584 | xml::ElementNode *pelmHostOnlyNetworks;
|
---|
2585 | /* don't create entry if no HostOnly networks are registered. */
|
---|
2586 | if (!llHostOnlyNetworks.empty())
|
---|
2587 | {
|
---|
2588 | pelmHostOnlyNetworks = pelmNetServiceRegistry->createChild("HostOnlyNetworks");
|
---|
2589 | for (HostOnlyNetworksList::const_iterator it = llHostOnlyNetworks.begin();
|
---|
2590 | it != llHostOnlyNetworks.end();
|
---|
2591 | ++it)
|
---|
2592 | {
|
---|
2593 | const HostOnlyNetwork &n = *it;
|
---|
2594 | xml::ElementNode *pelmThis = pelmHostOnlyNetworks->createChild("HostOnlyNetwork");
|
---|
2595 | pelmThis->setAttribute("name", n.strNetworkName);
|
---|
2596 | pelmThis->setAttribute("mask", n.strNetworkMask);
|
---|
2597 | pelmThis->setAttribute("ipLower", n.strIPLower);
|
---|
2598 | pelmThis->setAttribute("ipUpper", n.strIPUpper);
|
---|
2599 | pelmThis->setAttribute("id", n.uuid.toStringCurly());
|
---|
2600 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
2601 | }
|
---|
2602 | }
|
---|
2603 | #endif /* VBOX_WITH_VMNET */
|
---|
2604 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2605 | xml::ElementNode *pelmCloudNetworks;
|
---|
2606 | /* don't create entry if no cloud networks are registered. */
|
---|
2607 | if (!llCloudNetworks.empty())
|
---|
2608 | {
|
---|
2609 | pelmCloudNetworks = pelmNetServiceRegistry->createChild("CloudNetworks");
|
---|
2610 | for (CloudNetworksList::const_iterator it = llCloudNetworks.begin();
|
---|
2611 | it != llCloudNetworks.end();
|
---|
2612 | ++it)
|
---|
2613 | {
|
---|
2614 | const CloudNetwork &n = *it;
|
---|
2615 | xml::ElementNode *pelmThis = pelmCloudNetworks->createChild("CloudNetwork");
|
---|
2616 | pelmThis->setAttribute("name", n.strNetworkName);
|
---|
2617 | pelmThis->setAttribute("provider", n.strProviderShortName);
|
---|
2618 | pelmThis->setAttribute("profile", n.strProfileName);
|
---|
2619 | pelmThis->setAttribute("id", n.strNetworkId);
|
---|
2620 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
2621 | }
|
---|
2622 | }
|
---|
2623 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2624 |
|
---|
2625 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
2626 | /* We keep the updates configuration as part of the host for now, as the API exposes the IHost::updateHost attribute,
|
---|
2627 | * but use an own "Updates" branch in the XML for better structurizing stuff in the future. */
|
---|
2628 | UpdateAgent &updateHost = host.updateHost;
|
---|
2629 |
|
---|
2630 | xml::ElementNode *pelmUpdates = pelmGlobal->createChild("Updates");
|
---|
2631 | /* Global enabled switch for updates. Currently bound to host updates, as this is the only update we have so far. */
|
---|
2632 | pelmUpdates->setAttribute("enabled", updateHost.fEnabled);
|
---|
2633 |
|
---|
2634 | xml::ElementNode *pelmUpdateHost = pelmUpdates->createChild("Host");
|
---|
2635 | pelmUpdateHost->setAttribute("enabled", updateHost.fEnabled);
|
---|
2636 | pelmUpdateHost->setAttribute("channel", (int32_t)updateHost.enmChannel);
|
---|
2637 | pelmUpdateHost->setAttribute("checkFreqSec", updateHost.uCheckFreqSeconds);
|
---|
2638 | if (updateHost.strRepoUrl.length())
|
---|
2639 | pelmUpdateHost->setAttribute("repoUrl", updateHost.strRepoUrl);
|
---|
2640 | if (updateHost.strLastCheckDate.length())
|
---|
2641 | pelmUpdateHost->setAttribute("lastCheckDate", updateHost.strLastCheckDate);
|
---|
2642 | pelmUpdateHost->setAttribute("checkCount", updateHost.uCheckCount);
|
---|
2643 | /** @todo Add update settings for ExtPack and Guest Additions here later. See @bugref{7983}. */
|
---|
2644 | #endif
|
---|
2645 |
|
---|
2646 | xml::ElementNode *pelmSysProps = pelmGlobal->createChild("SystemProperties");
|
---|
2647 | if (systemProperties.strDefaultMachineFolder.length())
|
---|
2648 | pelmSysProps->setAttribute("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
2649 | if (systemProperties.strLoggingLevel.length())
|
---|
2650 | pelmSysProps->setAttribute("LoggingLevel", systemProperties.strLoggingLevel);
|
---|
2651 | if (systemProperties.strDefaultHardDiskFormat.length())
|
---|
2652 | pelmSysProps->setAttribute("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
2653 | if (systemProperties.strVRDEAuthLibrary.length())
|
---|
2654 | pelmSysProps->setAttribute("VRDEAuthLibrary", systemProperties.strVRDEAuthLibrary);
|
---|
2655 | if (systemProperties.strWebServiceAuthLibrary.length())
|
---|
2656 | pelmSysProps->setAttribute("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
2657 | if (systemProperties.strDefaultVRDEExtPack.length())
|
---|
2658 | pelmSysProps->setAttribute("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
|
---|
2659 | if (systemProperties.strDefaultCryptoExtPack.length())
|
---|
2660 | pelmSysProps->setAttribute("defaultCryptoExtPack", systemProperties.strDefaultCryptoExtPack);
|
---|
2661 | pelmSysProps->setAttribute("LogHistoryCount", systemProperties.uLogHistoryCount);
|
---|
2662 | if (systemProperties.strAutostartDatabasePath.length())
|
---|
2663 | pelmSysProps->setAttribute("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
|
---|
2664 | if (systemProperties.strDefaultFrontend.length())
|
---|
2665 | pelmSysProps->setAttribute("defaultFrontend", systemProperties.strDefaultFrontend);
|
---|
2666 | if (systemProperties.strProxyUrl.length())
|
---|
2667 | pelmSysProps->setAttribute("proxyUrl", systemProperties.strProxyUrl);
|
---|
2668 | pelmSysProps->setAttribute("proxyMode", systemProperties.uProxyMode);
|
---|
2669 | if (m->sv >= SettingsVersion_v1_20) /* Since settings v1.20 exclusiveHwVirt is part of PlatformProperties. */
|
---|
2670 | {
|
---|
2671 | xml::ElementNode *pelmPlatProps = pelmGlobal->createChild("PlatformProperties");
|
---|
2672 | pelmPlatProps->setAttribute("exclusiveHwVirt", platformProperties.fExclusiveHwVirt);
|
---|
2673 | }
|
---|
2674 | else
|
---|
2675 | pelmSysProps->setAttribute("exclusiveHwVirt", platformProperties.fExclusiveHwVirt);
|
---|
2676 | if (systemProperties.strLanguageId.isNotEmpty())
|
---|
2677 | pelmSysProps->setAttribute("LanguageId", systemProperties.strLanguageId);
|
---|
2678 |
|
---|
2679 | buildUSBDeviceFilters(*pelmGlobal->createChild("USBDeviceFilters"),
|
---|
2680 | host.llUSBDeviceFilters,
|
---|
2681 | true); // fHostMode
|
---|
2682 |
|
---|
2683 | if (!host.llUSBDeviceSources.empty())
|
---|
2684 | buildUSBDeviceSources(*pelmGlobal->createChild("USBDeviceSources"),
|
---|
2685 | host.llUSBDeviceSources);
|
---|
2686 |
|
---|
2687 | // now go write the XML
|
---|
2688 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
2689 | writer.write(m->strFilename.c_str(), true /*fSafe*/);
|
---|
2690 |
|
---|
2691 | m->fFileExists = true;
|
---|
2692 |
|
---|
2693 | clearDocument();
|
---|
2694 | LogRel(("Finished saving settings file \"%s\"\n", m->strFilename.c_str()));
|
---|
2695 | }
|
---|
2696 |
|
---|
2697 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2698 | //
|
---|
2699 | // Machine XML structures
|
---|
2700 | //
|
---|
2701 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2702 |
|
---|
2703 | /**
|
---|
2704 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
2705 | */
|
---|
2706 | VRDESettings::VRDESettings() :
|
---|
2707 | fEnabled(true), // default for old VMs, for new ones it's false
|
---|
2708 | authType(AuthType_Null),
|
---|
2709 | ulAuthTimeout(5000),
|
---|
2710 | fAllowMultiConnection(false),
|
---|
2711 | fReuseSingleConnection(false)
|
---|
2712 | {
|
---|
2713 | }
|
---|
2714 |
|
---|
2715 | /**
|
---|
2716 | * Check if all settings have default values.
|
---|
2717 | */
|
---|
2718 | bool VRDESettings::areDefaultSettings(SettingsVersion_T sv) const
|
---|
2719 | {
|
---|
2720 | return (sv < SettingsVersion_v1_16 ? fEnabled : !fEnabled)
|
---|
2721 | && authType == AuthType_Null
|
---|
2722 | && (ulAuthTimeout == 5000 || ulAuthTimeout == 0)
|
---|
2723 | && strAuthLibrary.isEmpty()
|
---|
2724 | && !fAllowMultiConnection
|
---|
2725 | && !fReuseSingleConnection
|
---|
2726 | && strVrdeExtPack.isEmpty()
|
---|
2727 | && mapProperties.size() == 0;
|
---|
2728 | }
|
---|
2729 |
|
---|
2730 | /**
|
---|
2731 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2732 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2733 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2734 | */
|
---|
2735 | bool VRDESettings::operator==(const VRDESettings& v) const
|
---|
2736 | {
|
---|
2737 | return (this == &v)
|
---|
2738 | || ( fEnabled == v.fEnabled
|
---|
2739 | && authType == v.authType
|
---|
2740 | && ulAuthTimeout == v.ulAuthTimeout
|
---|
2741 | && strAuthLibrary == v.strAuthLibrary
|
---|
2742 | && fAllowMultiConnection == v.fAllowMultiConnection
|
---|
2743 | && fReuseSingleConnection == v.fReuseSingleConnection
|
---|
2744 | && strVrdeExtPack == v.strVrdeExtPack
|
---|
2745 | && mapProperties == v.mapProperties);
|
---|
2746 | }
|
---|
2747 |
|
---|
2748 | /**
|
---|
2749 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
2750 | */
|
---|
2751 | FirmwareSettings::FirmwareSettings() :
|
---|
2752 | firmwareType(FirmwareType_BIOS),
|
---|
2753 | fACPIEnabled(true),
|
---|
2754 | fIOAPICEnabled(false),
|
---|
2755 | fLogoFadeIn(true),
|
---|
2756 | fLogoFadeOut(true),
|
---|
2757 | fPXEDebugEnabled(false),
|
---|
2758 | fSmbiosUuidLittleEndian(true),
|
---|
2759 | fAutoSerialNumGen(true),
|
---|
2760 | ulLogoDisplayTime(0),
|
---|
2761 | enmBootMenuMode(FirmwareBootMenuMode_MessageAndMenu),
|
---|
2762 | apicMode(APICMode_APIC),
|
---|
2763 | llTimeOffset(0)
|
---|
2764 | {
|
---|
2765 | }
|
---|
2766 |
|
---|
2767 | /**
|
---|
2768 | * Returns if all settings have default values.
|
---|
2769 | *
|
---|
2770 | * @returns \c true if all settings have default values, \c false if not.
|
---|
2771 | * @param enmCPUArch CPU architecture to use for checking the default values for.
|
---|
2772 | */
|
---|
2773 | bool FirmwareSettings::areDefaultSettings(CPUArchitecture_T enmCPUArch) const
|
---|
2774 | {
|
---|
2775 | switch (enmCPUArch)
|
---|
2776 | {
|
---|
2777 | case CPUArchitecture_x86:
|
---|
2778 | RT_FALL_THROUGH();
|
---|
2779 | case CPUArchitecture_AMD64:
|
---|
2780 | return
|
---|
2781 | firmwareType == FirmwareType_BIOS
|
---|
2782 | && !fIOAPICEnabled
|
---|
2783 | && fLogoFadeIn
|
---|
2784 | && fLogoFadeOut
|
---|
2785 | && !fPXEDebugEnabled
|
---|
2786 | && !fSmbiosUuidLittleEndian
|
---|
2787 | && !fAutoSerialNumGen
|
---|
2788 | && ulLogoDisplayTime == 0
|
---|
2789 | && enmBootMenuMode == FirmwareBootMenuMode_MessageAndMenu
|
---|
2790 | && apicMode == APICMode_APIC
|
---|
2791 | && llTimeOffset == 0
|
---|
2792 | && strLogoImagePath.isEmpty();
|
---|
2793 |
|
---|
2794 | case CPUArchitecture_ARMv8_32:
|
---|
2795 | RT_FALL_THROUGH();
|
---|
2796 | case CPUArchitecture_ARMv8_64:
|
---|
2797 | return
|
---|
2798 | ( enmCPUArch == CPUArchitecture_ARMv8_32
|
---|
2799 | ? firmwareType == FirmwareType_EFI32
|
---|
2800 | : firmwareType == FirmwareType_EFI64)
|
---|
2801 | && !fIOAPICEnabled
|
---|
2802 | && fLogoFadeIn
|
---|
2803 | && fLogoFadeOut
|
---|
2804 | && !fPXEDebugEnabled
|
---|
2805 | && !fSmbiosUuidLittleEndian
|
---|
2806 | && !fAutoSerialNumGen
|
---|
2807 | && ulLogoDisplayTime == 0
|
---|
2808 | && enmBootMenuMode == FirmwareBootMenuMode_MessageAndMenu
|
---|
2809 | && apicMode == APICMode_APIC
|
---|
2810 | && llTimeOffset == 0
|
---|
2811 | && strLogoImagePath.isEmpty();
|
---|
2812 | break;
|
---|
2813 |
|
---|
2814 | default:
|
---|
2815 | break;
|
---|
2816 | }
|
---|
2817 |
|
---|
2818 | AssertFailedReturn(false);
|
---|
2819 | }
|
---|
2820 |
|
---|
2821 | /**
|
---|
2822 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2823 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2824 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2825 | */
|
---|
2826 | bool FirmwareSettings::operator==(const FirmwareSettings &d) const
|
---|
2827 | {
|
---|
2828 | return (this == &d)
|
---|
2829 | || ( firmwareType == d.firmwareType
|
---|
2830 | && fACPIEnabled == d.fACPIEnabled
|
---|
2831 | && fIOAPICEnabled == d.fIOAPICEnabled
|
---|
2832 | && fLogoFadeIn == d.fLogoFadeIn
|
---|
2833 | && fLogoFadeOut == d.fLogoFadeOut
|
---|
2834 | && fPXEDebugEnabled == d.fPXEDebugEnabled
|
---|
2835 | && fSmbiosUuidLittleEndian == d.fSmbiosUuidLittleEndian
|
---|
2836 | && fAutoSerialNumGen == d.fAutoSerialNumGen
|
---|
2837 | && ulLogoDisplayTime == d.ulLogoDisplayTime
|
---|
2838 | && enmBootMenuMode == d.enmBootMenuMode
|
---|
2839 | && apicMode == d.apicMode
|
---|
2840 | && llTimeOffset == d.llTimeOffset
|
---|
2841 | && strLogoImagePath == d.strLogoImagePath);
|
---|
2842 | }
|
---|
2843 |
|
---|
2844 | RecordingScreenSettings::RecordingScreenSettings(uint32_t a_idScreen /* = UINT32_MAX */)
|
---|
2845 | : idScreen(a_idScreen)
|
---|
2846 | {
|
---|
2847 | applyDefaults();
|
---|
2848 | }
|
---|
2849 |
|
---|
2850 | RecordingScreenSettings::~RecordingScreenSettings()
|
---|
2851 | {
|
---|
2852 |
|
---|
2853 | }
|
---|
2854 |
|
---|
2855 | /**
|
---|
2856 | * Returns the default options string for screen recording settings.
|
---|
2857 | *
|
---|
2858 | * @returns Default options string for a given screen.
|
---|
2859 | */
|
---|
2860 | /* static */
|
---|
2861 | const char *RecordingScreenSettings::getDefaultOptions(void)
|
---|
2862 | {
|
---|
2863 | /* Note: Needs to be kept in sync with FE/Qt's UIMachineSettingsDisplay::putToCache()! */
|
---|
2864 | return "vc_enabled=true,ac_enabled=false,ac_profile=med";
|
---|
2865 | }
|
---|
2866 |
|
---|
2867 | /**
|
---|
2868 | * Returns a recording settings feature map from a given string.
|
---|
2869 | *
|
---|
2870 | * @returns VBox status code.
|
---|
2871 | * @param strFeatures String of features to convert.
|
---|
2872 | * @param featureMap Where to return the converted features on success.
|
---|
2873 | */
|
---|
2874 | /* static */
|
---|
2875 | int RecordingScreenSettings::featuresFromString(const com::Utf8Str &strFeatures, RecordingFeatureMap &featureMap)
|
---|
2876 | {
|
---|
2877 | featureMap.clear();
|
---|
2878 |
|
---|
2879 | RTCList<RTCString> lstFeatures = strFeatures.split(" ");
|
---|
2880 | for (size_t i = 0; i < lstFeatures.size(); i++)
|
---|
2881 | {
|
---|
2882 | if (lstFeatures.at(i).compare("video", RTCString::CaseInsensitive) == 0)
|
---|
2883 | featureMap[RecordingFeature_Video] = true;
|
---|
2884 | else if (lstFeatures.at(i).compare("audio", RTCString::CaseInsensitive) == 0)
|
---|
2885 | featureMap[RecordingFeature_Audio] = true;
|
---|
2886 | /* ignore everything else */
|
---|
2887 | }
|
---|
2888 |
|
---|
2889 | return VINF_SUCCESS;
|
---|
2890 | }
|
---|
2891 |
|
---|
2892 | /**
|
---|
2893 | * Converts a feature map to a serializable string.
|
---|
2894 | *
|
---|
2895 | * @param featureMap Feature map to convert.
|
---|
2896 | * @param strFeatures Where to return the features converted as a string.
|
---|
2897 | */
|
---|
2898 | /* static */
|
---|
2899 | void RecordingScreenSettings::featuresToString(const RecordingFeatureMap &featureMap, com::Utf8Str &strFeatures)
|
---|
2900 | {
|
---|
2901 | strFeatures = "";
|
---|
2902 |
|
---|
2903 | RecordingFeatureMap::const_iterator itFeature = featureMap.begin();
|
---|
2904 | while (itFeature != featureMap.end())
|
---|
2905 | {
|
---|
2906 | if (itFeature->first == RecordingFeature_Video && itFeature->second)
|
---|
2907 | strFeatures += "video ";
|
---|
2908 | if (itFeature->first == RecordingFeature_Audio && itFeature->second)
|
---|
2909 | strFeatures += "audio ";
|
---|
2910 | ++itFeature;
|
---|
2911 | }
|
---|
2912 | strFeatures.strip();
|
---|
2913 | }
|
---|
2914 |
|
---|
2915 | /**
|
---|
2916 | * Returns a recording settings audio codec from a given string.
|
---|
2917 | *
|
---|
2918 | * @returns VBox status code.
|
---|
2919 | * @retval VERR_NOT_SUPPORTED if audio codec is invalid or not supported.
|
---|
2920 | * @param strCodec String that contains the codec name.
|
---|
2921 | * @param enmCodec Where to return the audio codec on success.
|
---|
2922 | *
|
---|
2923 | * @note An empty string will return "none" (no codec).
|
---|
2924 | */
|
---|
2925 | /* static */
|
---|
2926 | int RecordingScreenSettings::audioCodecFromString(const com::Utf8Str &strCodec, RecordingAudioCodec_T &enmCodec)
|
---|
2927 | {
|
---|
2928 | if ( RTStrIStr(strCodec.c_str(), "none")
|
---|
2929 | || strCodec.isEmpty())
|
---|
2930 | {
|
---|
2931 | enmCodec = RecordingAudioCodec_None;
|
---|
2932 | return VINF_SUCCESS;
|
---|
2933 | }
|
---|
2934 | else if (RTStrIStr(strCodec.c_str(), "wav"))
|
---|
2935 | {
|
---|
2936 | enmCodec = RecordingAudioCodec_WavPCM;
|
---|
2937 | return VINF_SUCCESS;
|
---|
2938 | }
|
---|
2939 | else if (RTStrIStr(strCodec.c_str(), "mp3"))
|
---|
2940 | {
|
---|
2941 | enmCodec = RecordingAudioCodec_MP3;
|
---|
2942 | return VINF_SUCCESS;
|
---|
2943 | }
|
---|
2944 | else if (RTStrIStr(strCodec.c_str(), "opus"))
|
---|
2945 | {
|
---|
2946 | enmCodec = RecordingAudioCodec_Opus;
|
---|
2947 | return VINF_SUCCESS;
|
---|
2948 | }
|
---|
2949 | else if (RTStrIStr(strCodec.c_str(), "vorbis"))
|
---|
2950 | {
|
---|
2951 | enmCodec = RecordingAudioCodec_OggVorbis;
|
---|
2952 | return VINF_SUCCESS;
|
---|
2953 | }
|
---|
2954 |
|
---|
2955 | AssertFailedReturn(VERR_NOT_SUPPORTED);
|
---|
2956 | }
|
---|
2957 |
|
---|
2958 | /**
|
---|
2959 | * Converts an audio codec to a serializable string.
|
---|
2960 | *
|
---|
2961 | * @param enmCodec Codec to convert to a string.
|
---|
2962 | * @param strCodec Where to return the audio codec converted as a string.
|
---|
2963 | */
|
---|
2964 | /* static */
|
---|
2965 | void RecordingScreenSettings::audioCodecToString(const RecordingAudioCodec_T &enmCodec, com::Utf8Str &strCodec)
|
---|
2966 | {
|
---|
2967 | switch (enmCodec)
|
---|
2968 | {
|
---|
2969 | case RecordingAudioCodec_None: strCodec = "none"; return;
|
---|
2970 | case RecordingAudioCodec_WavPCM: strCodec = "wav"; return;
|
---|
2971 | case RecordingAudioCodec_MP3: strCodec = "mp3"; return;
|
---|
2972 | case RecordingAudioCodec_Opus: strCodec = "opus"; return;
|
---|
2973 | case RecordingAudioCodec_OggVorbis: strCodec = "vorbis"; return;
|
---|
2974 | default: AssertFailedReturnVoid();
|
---|
2975 | }
|
---|
2976 | }
|
---|
2977 |
|
---|
2978 | /**
|
---|
2979 | * Returns a recording settings video codec from a given string.
|
---|
2980 | *
|
---|
2981 | * @returns VBox status code.
|
---|
2982 | * @retval VERR_NOT_SUPPORTED if video codec is invalid or not supported.
|
---|
2983 | * @param strCodec String that contains the codec name.
|
---|
2984 | * @param enmCodec Where to return the video codec on success.
|
---|
2985 | *
|
---|
2986 | * @note An empty string will return "none" (no codec).
|
---|
2987 | */
|
---|
2988 | /* static */
|
---|
2989 | int RecordingScreenSettings::videoCodecFromString(const com::Utf8Str &strCodec, RecordingVideoCodec_T &enmCodec)
|
---|
2990 | {
|
---|
2991 | if ( RTStrIStr(strCodec.c_str(), "none")
|
---|
2992 | || strCodec.isEmpty())
|
---|
2993 | {
|
---|
2994 | enmCodec = RecordingVideoCodec_None;
|
---|
2995 | return VINF_SUCCESS;
|
---|
2996 | }
|
---|
2997 | else if (RTStrIStr(strCodec.c_str(), "MJPEG"))
|
---|
2998 | {
|
---|
2999 | enmCodec = RecordingVideoCodec_MJPEG;
|
---|
3000 | return VINF_SUCCESS;
|
---|
3001 | }
|
---|
3002 | else if (RTStrIStr(strCodec.c_str(), "H262"))
|
---|
3003 | {
|
---|
3004 | enmCodec = RecordingVideoCodec_H262;
|
---|
3005 | return VINF_SUCCESS;
|
---|
3006 | }
|
---|
3007 | else if (RTStrIStr(strCodec.c_str(), "H264"))
|
---|
3008 | {
|
---|
3009 | enmCodec = RecordingVideoCodec_H264;
|
---|
3010 | return VINF_SUCCESS;
|
---|
3011 | }
|
---|
3012 | else if (RTStrIStr(strCodec.c_str(), "H265"))
|
---|
3013 | {
|
---|
3014 | enmCodec = RecordingVideoCodec_H265;
|
---|
3015 | return VINF_SUCCESS;
|
---|
3016 | }
|
---|
3017 | else if (RTStrIStr(strCodec.c_str(), "H266"))
|
---|
3018 | {
|
---|
3019 | enmCodec = RecordingVideoCodec_H266;
|
---|
3020 | return VINF_SUCCESS;
|
---|
3021 | }
|
---|
3022 | else if (RTStrIStr(strCodec.c_str(), "VP8"))
|
---|
3023 | {
|
---|
3024 | enmCodec = RecordingVideoCodec_VP8;
|
---|
3025 | return VINF_SUCCESS;
|
---|
3026 | }
|
---|
3027 | else if (RTStrIStr(strCodec.c_str(), "VP9"))
|
---|
3028 | {
|
---|
3029 | enmCodec = RecordingVideoCodec_VP9;
|
---|
3030 | return VINF_SUCCESS;
|
---|
3031 | }
|
---|
3032 | else if (RTStrIStr(strCodec.c_str(), "AV1"))
|
---|
3033 | {
|
---|
3034 | enmCodec = RecordingVideoCodec_AV1;
|
---|
3035 | return VINF_SUCCESS;
|
---|
3036 | }
|
---|
3037 | else if (RTStrIStr(strCodec.c_str(), "other"))
|
---|
3038 | {
|
---|
3039 | enmCodec = RecordingVideoCodec_Other;
|
---|
3040 | return VINF_SUCCESS;
|
---|
3041 | }
|
---|
3042 |
|
---|
3043 | AssertFailedReturn(VERR_NOT_SUPPORTED);
|
---|
3044 | }
|
---|
3045 |
|
---|
3046 | /**
|
---|
3047 | * Converts a video codec to a serializable string.
|
---|
3048 | *
|
---|
3049 | * @param enmCodec Codec to convert to a string.
|
---|
3050 | * @param strCodec Where to return the video codec converted as a string.
|
---|
3051 | */
|
---|
3052 | /* static */
|
---|
3053 | void RecordingScreenSettings::videoCodecToString(const RecordingVideoCodec_T &enmCodec, com::Utf8Str &strCodec)
|
---|
3054 | {
|
---|
3055 | switch (enmCodec)
|
---|
3056 | {
|
---|
3057 | case RecordingVideoCodec_None: strCodec = "none"; return;
|
---|
3058 | case RecordingVideoCodec_MJPEG: strCodec = "MJPEG"; return;
|
---|
3059 | case RecordingVideoCodec_H262: strCodec = "H262"; return;
|
---|
3060 | case RecordingVideoCodec_H264: strCodec = "H264"; return;
|
---|
3061 | case RecordingVideoCodec_H265: strCodec = "H265"; return;
|
---|
3062 | case RecordingVideoCodec_H266: strCodec = "H266"; return;
|
---|
3063 | case RecordingVideoCodec_VP8: strCodec = "VP8"; return;
|
---|
3064 | case RecordingVideoCodec_VP9: strCodec = "VP9"; return;
|
---|
3065 | case RecordingVideoCodec_AV1: strCodec = "AV1"; return;
|
---|
3066 | case RecordingVideoCodec_Other: strCodec = "other"; return;
|
---|
3067 | default: AssertFailedReturnVoid();
|
---|
3068 | }
|
---|
3069 | }
|
---|
3070 |
|
---|
3071 | /**
|
---|
3072 | * Applies the default settings.
|
---|
3073 | */
|
---|
3074 | void RecordingScreenSettings::applyDefaults(void)
|
---|
3075 | {
|
---|
3076 | /*
|
---|
3077 | * Set sensible defaults.
|
---|
3078 | */
|
---|
3079 |
|
---|
3080 | /*
|
---|
3081 | * Enable screen 0 by default.
|
---|
3082 | * Otherwise enabling recording without any screen enabled at all makes no sense.
|
---|
3083 | *
|
---|
3084 | * Note: When tweaking this, make sure to also alter RecordingScreenSettings::areDefaultSettings().
|
---|
3085 | */
|
---|
3086 | fEnabled = idScreen == 0 ? true : false;;
|
---|
3087 | enmDest = RecordingDestination_File;
|
---|
3088 | ulMaxTimeS = 0;
|
---|
3089 | strOptions = RecordingScreenSettings::getDefaultOptions();
|
---|
3090 | File.ulMaxSizeMB = 0;
|
---|
3091 | File.strName = "";
|
---|
3092 | Video.enmCodec = RecordingVideoCodec_VP8;
|
---|
3093 | Video.enmDeadline = RecordingCodecDeadline_Default;
|
---|
3094 | Video.enmRateCtlMode = RecordingRateControlMode_VBR;
|
---|
3095 | Video.enmScalingMode = RecordingVideoScalingMode_None;
|
---|
3096 | Video.ulWidth = 1024;
|
---|
3097 | Video.ulHeight = 768;
|
---|
3098 | Video.ulRate = 512;
|
---|
3099 | Video.ulFPS = 25;
|
---|
3100 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
3101 | # if defined(VBOX_WITH_LIBVORBIS)
|
---|
3102 | Audio.enmCodec = RecordingAudioCodec_OggVorbis;
|
---|
3103 | # else
|
---|
3104 | Audio.enmCodec = RecordingAudioCodec_None;
|
---|
3105 | # endif
|
---|
3106 | #else
|
---|
3107 | Audio.enmCodec = RecordingAudioCodec_None;
|
---|
3108 | #endif /* VBOX_WITH_RECORDING */
|
---|
3109 | Audio.enmDeadline = RecordingCodecDeadline_Default;
|
---|
3110 | Audio.enmRateCtlMode = RecordingRateControlMode_VBR;
|
---|
3111 | Audio.cBits = 16;
|
---|
3112 | Audio.cChannels = 2;
|
---|
3113 | Audio.uHz = 22050;
|
---|
3114 |
|
---|
3115 | featureMap[RecordingFeature_Video] = true;
|
---|
3116 | featureMap[RecordingFeature_Audio] = false; /** @todo Audio is not yet enabled by default. */
|
---|
3117 | }
|
---|
3118 |
|
---|
3119 | /**
|
---|
3120 | * Check if all settings have default values.
|
---|
3121 | *
|
---|
3122 | * @returns @c true if default, @c false if not.
|
---|
3123 | */
|
---|
3124 | bool RecordingScreenSettings::areDefaultSettings(void) const
|
---|
3125 | {
|
---|
3126 | return ( fEnabled == false
|
---|
3127 | /* Screen 0 is special: There we ALWAYS enable recording by default. */
|
---|
3128 | || ( idScreen == 0
|
---|
3129 | && fEnabled == true)
|
---|
3130 | )
|
---|
3131 | && enmDest == RecordingDestination_File
|
---|
3132 | && ulMaxTimeS == 0
|
---|
3133 | && strOptions == RecordingScreenSettings::getDefaultOptions()
|
---|
3134 | && File.ulMaxSizeMB == 0
|
---|
3135 | && File.strName == ""
|
---|
3136 | && Video.enmCodec == RecordingVideoCodec_VP8
|
---|
3137 | && Video.enmDeadline == RecordingCodecDeadline_Default
|
---|
3138 | && Video.enmRateCtlMode == RecordingRateControlMode_VBR
|
---|
3139 | && Video.enmScalingMode == RecordingVideoScalingMode_None
|
---|
3140 | && Video.ulWidth == 1024
|
---|
3141 | && Video.ulHeight == 768
|
---|
3142 | && Video.ulRate == 512
|
---|
3143 | && Video.ulFPS == 25
|
---|
3144 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
3145 | # if defined(VBOX_WITH_LIBVORBIS)
|
---|
3146 | && Audio.enmCodec == RecordingAudioCodec_OggVorbis
|
---|
3147 | # else
|
---|
3148 | && Audio.enmCodec == RecordingAudioCodec_None
|
---|
3149 | # endif
|
---|
3150 | #else
|
---|
3151 | && Audio.enmCodec == RecordingAudioCodec_None
|
---|
3152 | #endif /* VBOX_WITH_AUDIO_RECORDING */
|
---|
3153 | && Audio.enmDeadline == RecordingCodecDeadline_Default
|
---|
3154 | && Audio.enmRateCtlMode == RecordingRateControlMode_VBR
|
---|
3155 | && Audio.cBits == 16
|
---|
3156 | && Audio.cChannels == 2
|
---|
3157 | && Audio.uHz == 22050
|
---|
3158 | && featureMap.find(RecordingFeature_Video)->second == true
|
---|
3159 | && featureMap.find(RecordingFeature_Audio)->second == false;
|
---|
3160 | }
|
---|
3161 |
|
---|
3162 | /**
|
---|
3163 | * Returns if a certain recording feature is enabled or not.
|
---|
3164 | *
|
---|
3165 | * @returns @c true if the feature is enabled, @c false if not.
|
---|
3166 | * @param enmFeature Feature to check.
|
---|
3167 | */
|
---|
3168 | bool RecordingScreenSettings::isFeatureEnabled(RecordingFeature_T enmFeature) const
|
---|
3169 | {
|
---|
3170 | RecordingFeatureMap::const_iterator itFeature = featureMap.find(enmFeature);
|
---|
3171 | if (itFeature != featureMap.end())
|
---|
3172 | return itFeature->second;
|
---|
3173 |
|
---|
3174 | return false;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | /**
|
---|
3178 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3179 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3180 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3181 | */
|
---|
3182 | bool RecordingScreenSettings::operator==(const RecordingScreenSettings &d) const
|
---|
3183 | {
|
---|
3184 | return fEnabled == d.fEnabled
|
---|
3185 | && enmDest == d.enmDest
|
---|
3186 | && featureMap == d.featureMap
|
---|
3187 | && ulMaxTimeS == d.ulMaxTimeS
|
---|
3188 | && strOptions == d.strOptions
|
---|
3189 | && File.strName == d.File.strName
|
---|
3190 | && File.ulMaxSizeMB == d.File.ulMaxSizeMB
|
---|
3191 | && Video.enmCodec == d.Video.enmCodec
|
---|
3192 | && Video.enmDeadline == d.Video.enmDeadline
|
---|
3193 | && Video.enmRateCtlMode == d.Video.enmRateCtlMode
|
---|
3194 | && Video.enmScalingMode == d.Video.enmScalingMode
|
---|
3195 | && Video.ulWidth == d.Video.ulWidth
|
---|
3196 | && Video.ulHeight == d.Video.ulHeight
|
---|
3197 | && Video.ulRate == d.Video.ulRate
|
---|
3198 | && Video.ulFPS == d.Video.ulFPS
|
---|
3199 | && Audio.enmCodec == d.Audio.enmCodec
|
---|
3200 | && Audio.enmDeadline == d.Audio.enmDeadline
|
---|
3201 | && Audio.enmRateCtlMode == d.Audio.enmRateCtlMode
|
---|
3202 | && Audio.cBits == d.Audio.cBits
|
---|
3203 | && Audio.cChannels == d.Audio.cChannels
|
---|
3204 | && Audio.uHz == d.Audio.uHz
|
---|
3205 | && featureMap == d.featureMap;
|
---|
3206 | }
|
---|
3207 |
|
---|
3208 | /**
|
---|
3209 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3210 | */
|
---|
3211 | RecordingCommonSettings::RecordingCommonSettings()
|
---|
3212 | {
|
---|
3213 | applyDefaults();
|
---|
3214 | }
|
---|
3215 |
|
---|
3216 | /**
|
---|
3217 | * Applies the default settings.
|
---|
3218 | */
|
---|
3219 | void RecordingCommonSettings::applyDefaults(void)
|
---|
3220 | {
|
---|
3221 | fEnabled = false;
|
---|
3222 | }
|
---|
3223 |
|
---|
3224 | /**
|
---|
3225 | * Check if all settings have default values.
|
---|
3226 | */
|
---|
3227 | bool RecordingCommonSettings::areDefaultSettings(void) const
|
---|
3228 | {
|
---|
3229 | return fEnabled == false;
|
---|
3230 | }
|
---|
3231 |
|
---|
3232 | /**
|
---|
3233 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3234 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3235 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3236 | */
|
---|
3237 | bool RecordingCommonSettings::operator==(const RecordingCommonSettings &d) const
|
---|
3238 | {
|
---|
3239 | if (this == &d)
|
---|
3240 | return true;
|
---|
3241 |
|
---|
3242 | return fEnabled == d.fEnabled;
|
---|
3243 | }
|
---|
3244 |
|
---|
3245 | /**
|
---|
3246 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3247 | */
|
---|
3248 | RecordingSettings::RecordingSettings()
|
---|
3249 | {
|
---|
3250 | applyDefaults();
|
---|
3251 | }
|
---|
3252 |
|
---|
3253 | /**
|
---|
3254 | * Applies the default settings.
|
---|
3255 | */
|
---|
3256 | void RecordingSettings::applyDefaults(void)
|
---|
3257 | {
|
---|
3258 | common.applyDefaults();
|
---|
3259 |
|
---|
3260 | mapScreens.clear();
|
---|
3261 |
|
---|
3262 | try
|
---|
3263 | {
|
---|
3264 | /* Always add screen 0 to the default configuration. */
|
---|
3265 | RecordingScreenSettings screenSettings(0 /* Screen ID */);
|
---|
3266 |
|
---|
3267 | mapScreens[0 /* Screen ID */] = screenSettings;
|
---|
3268 | }
|
---|
3269 | catch (std::bad_alloc &)
|
---|
3270 | {
|
---|
3271 | AssertFailed();
|
---|
3272 | }
|
---|
3273 | }
|
---|
3274 |
|
---|
3275 | /**
|
---|
3276 | * Check if all settings have default values.
|
---|
3277 | */
|
---|
3278 | bool RecordingSettings::areDefaultSettings(void) const
|
---|
3279 | {
|
---|
3280 | AssertReturn(mapScreens.size() >= 1, false); /* The first screen always must be present. */
|
---|
3281 |
|
---|
3282 | if (!common.areDefaultSettings())
|
---|
3283 | return false;
|
---|
3284 |
|
---|
3285 | RecordingScreenSettingsMap::const_iterator itScreen = mapScreens.begin();
|
---|
3286 | while (itScreen != mapScreens.end())
|
---|
3287 | {
|
---|
3288 | if (!itScreen->second.areDefaultSettings())
|
---|
3289 | return false;
|
---|
3290 | ++itScreen;
|
---|
3291 | }
|
---|
3292 |
|
---|
3293 | return true;
|
---|
3294 | }
|
---|
3295 |
|
---|
3296 | /**
|
---|
3297 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3298 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3299 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3300 | */
|
---|
3301 | bool RecordingSettings::operator==(const RecordingSettings &that) const
|
---|
3302 | {
|
---|
3303 | if (this == &that) /* If pointers match, take a shortcut. */
|
---|
3304 | return true;
|
---|
3305 |
|
---|
3306 | if (common == that.common)
|
---|
3307 | {
|
---|
3308 | /* Too lazy for a != operator. */
|
---|
3309 | }
|
---|
3310 | else
|
---|
3311 | return false;
|
---|
3312 |
|
---|
3313 | if (mapScreens.size() != that.mapScreens.size())
|
---|
3314 | return false;
|
---|
3315 |
|
---|
3316 | RecordingScreenSettingsMap::const_iterator itScreen = mapScreens.begin();
|
---|
3317 | RecordingScreenSettingsMap::const_iterator itScreenThat = that.mapScreens.begin();
|
---|
3318 | while ( itScreen != mapScreens.end()
|
---|
3319 | && itScreenThat != that.mapScreens.end())
|
---|
3320 | {
|
---|
3321 | if (itScreen->second == itScreenThat->second)
|
---|
3322 | {
|
---|
3323 | /* Nothing to do in here (yet). */
|
---|
3324 | }
|
---|
3325 | else
|
---|
3326 | return false;
|
---|
3327 |
|
---|
3328 | ++itScreen;
|
---|
3329 | ++itScreenThat;
|
---|
3330 | }
|
---|
3331 |
|
---|
3332 | return true;
|
---|
3333 | }
|
---|
3334 |
|
---|
3335 | /**
|
---|
3336 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3337 | */
|
---|
3338 | GraphicsAdapter::GraphicsAdapter() :
|
---|
3339 | graphicsControllerType(GraphicsControllerType_VBoxVGA),
|
---|
3340 | ulVRAMSizeMB(8),
|
---|
3341 | cMonitors(1),
|
---|
3342 | fAccelerate3D(false),
|
---|
3343 | fAccelerate2DVideo(false)
|
---|
3344 | {
|
---|
3345 | }
|
---|
3346 |
|
---|
3347 | /**
|
---|
3348 | * Check if all settings have default values.
|
---|
3349 | */
|
---|
3350 | bool GraphicsAdapter::areDefaultSettings() const
|
---|
3351 | {
|
---|
3352 | return graphicsControllerType == GraphicsControllerType_VBoxVGA
|
---|
3353 | && ulVRAMSizeMB == 8
|
---|
3354 | && cMonitors <= 1
|
---|
3355 | && !fAccelerate3D
|
---|
3356 | && !fAccelerate2DVideo;
|
---|
3357 | }
|
---|
3358 |
|
---|
3359 | /**
|
---|
3360 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3361 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3362 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3363 | */
|
---|
3364 | bool GraphicsAdapter::operator==(const GraphicsAdapter &g) const
|
---|
3365 | {
|
---|
3366 | return (this == &g)
|
---|
3367 | || ( graphicsControllerType == g.graphicsControllerType
|
---|
3368 | && ulVRAMSizeMB == g.ulVRAMSizeMB
|
---|
3369 | && cMonitors == g.cMonitors
|
---|
3370 | && fAccelerate3D == g.fAccelerate3D
|
---|
3371 | && fAccelerate2DVideo == g.fAccelerate2DVideo);
|
---|
3372 | }
|
---|
3373 |
|
---|
3374 | /**
|
---|
3375 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3376 | */
|
---|
3377 | TpmSettings::TpmSettings() :
|
---|
3378 | tpmType(TpmType_None)
|
---|
3379 | {
|
---|
3380 | }
|
---|
3381 |
|
---|
3382 | /**
|
---|
3383 | * Check if all settings have default values.
|
---|
3384 | */
|
---|
3385 | bool TpmSettings::areDefaultSettings() const
|
---|
3386 | {
|
---|
3387 | return tpmType == TpmType_None
|
---|
3388 | && strLocation.isEmpty();
|
---|
3389 | }
|
---|
3390 |
|
---|
3391 | /**
|
---|
3392 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3393 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3394 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3395 | */
|
---|
3396 | bool TpmSettings::operator==(const TpmSettings &g) const
|
---|
3397 | {
|
---|
3398 | return (this == &g)
|
---|
3399 | || ( tpmType == g.tpmType
|
---|
3400 | && strLocation == g.strLocation);
|
---|
3401 | }
|
---|
3402 |
|
---|
3403 | /**
|
---|
3404 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3405 | */
|
---|
3406 | NvramSettings::NvramSettings()
|
---|
3407 | {
|
---|
3408 | }
|
---|
3409 |
|
---|
3410 | /**
|
---|
3411 | * Check if all settings have default values.
|
---|
3412 | */
|
---|
3413 | bool NvramSettings::areDefaultSettings() const
|
---|
3414 | {
|
---|
3415 | return strNvramPath.isEmpty()
|
---|
3416 | && strKeyId.isEmpty()
|
---|
3417 | && strKeyStore.isEmpty();
|
---|
3418 | }
|
---|
3419 |
|
---|
3420 | /**
|
---|
3421 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3422 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3423 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3424 | */
|
---|
3425 | bool NvramSettings::operator==(const NvramSettings &g) const
|
---|
3426 | {
|
---|
3427 | return (this == &g)
|
---|
3428 | || (strNvramPath == g.strNvramPath)
|
---|
3429 | || (strKeyId == g.strKeyId)
|
---|
3430 | || (strKeyStore == g.strKeyStore);
|
---|
3431 | }
|
---|
3432 |
|
---|
3433 |
|
---|
3434 | /**
|
---|
3435 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3436 | */
|
---|
3437 | USBController::USBController() :
|
---|
3438 | enmType(USBControllerType_Null)
|
---|
3439 | {
|
---|
3440 | }
|
---|
3441 |
|
---|
3442 | /**
|
---|
3443 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3444 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3445 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3446 | */
|
---|
3447 | bool USBController::operator==(const USBController &u) const
|
---|
3448 | {
|
---|
3449 | return (this == &u)
|
---|
3450 | || ( strName == u.strName
|
---|
3451 | && enmType == u.enmType);
|
---|
3452 | }
|
---|
3453 |
|
---|
3454 | /**
|
---|
3455 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3456 | */
|
---|
3457 | USB::USB()
|
---|
3458 | {
|
---|
3459 | }
|
---|
3460 |
|
---|
3461 | /**
|
---|
3462 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3463 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3464 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3465 | */
|
---|
3466 | bool USB::operator==(const USB &u) const
|
---|
3467 | {
|
---|
3468 | return (this == &u)
|
---|
3469 | || ( llUSBControllers == u.llUSBControllers
|
---|
3470 | && llDeviceFilters == u.llDeviceFilters);
|
---|
3471 | }
|
---|
3472 |
|
---|
3473 | /**
|
---|
3474 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3475 | */
|
---|
3476 | NAT::NAT() :
|
---|
3477 | u32Mtu(0),
|
---|
3478 | u32SockRcv(0),
|
---|
3479 | u32SockSnd(0),
|
---|
3480 | u32TcpRcv(0),
|
---|
3481 | u32TcpSnd(0),
|
---|
3482 | fDNSPassDomain(true), /* historically this value is true */
|
---|
3483 | fDNSProxy(false),
|
---|
3484 | fDNSUseHostResolver(false),
|
---|
3485 | fAliasLog(false),
|
---|
3486 | fAliasProxyOnly(false),
|
---|
3487 | fAliasUseSamePorts(false),
|
---|
3488 | fLocalhostReachable(true) /* Historically this value is true. */
|
---|
3489 | {
|
---|
3490 | }
|
---|
3491 |
|
---|
3492 | /**
|
---|
3493 | * Check if all DNS settings have default values.
|
---|
3494 | */
|
---|
3495 | bool NAT::areDNSDefaultSettings() const
|
---|
3496 | {
|
---|
3497 | return fDNSPassDomain && !fDNSProxy && !fDNSUseHostResolver;
|
---|
3498 | }
|
---|
3499 |
|
---|
3500 | /**
|
---|
3501 | * Check if all Alias settings have default values.
|
---|
3502 | */
|
---|
3503 | bool NAT::areAliasDefaultSettings() const
|
---|
3504 | {
|
---|
3505 | return !fAliasLog && !fAliasProxyOnly && !fAliasUseSamePorts;
|
---|
3506 | }
|
---|
3507 |
|
---|
3508 | /**
|
---|
3509 | * Check if all TFTP settings have default values.
|
---|
3510 | */
|
---|
3511 | bool NAT::areTFTPDefaultSettings() const
|
---|
3512 | {
|
---|
3513 | return strTFTPPrefix.isEmpty()
|
---|
3514 | && strTFTPBootFile.isEmpty()
|
---|
3515 | && strTFTPNextServer.isEmpty();
|
---|
3516 | }
|
---|
3517 |
|
---|
3518 | /**
|
---|
3519 | * Check whether the localhost-reachable setting is the default for the given settings version.
|
---|
3520 | */
|
---|
3521 | bool NAT::areLocalhostReachableDefaultSettings(SettingsVersion_T sv) const
|
---|
3522 | {
|
---|
3523 | return ( fLocalhostReachable
|
---|
3524 | && sv < SettingsVersion_v1_19)
|
---|
3525 | || ( !fLocalhostReachable
|
---|
3526 | && sv >= SettingsVersion_v1_19);
|
---|
3527 | }
|
---|
3528 |
|
---|
3529 | /**
|
---|
3530 | * Check if all settings have default values.
|
---|
3531 | */
|
---|
3532 | bool NAT::areDefaultSettings(SettingsVersion_T sv) const
|
---|
3533 | {
|
---|
3534 | /*
|
---|
3535 | * Before settings version 1.19 localhost was reachable by default
|
---|
3536 | * when using NAT which was changed with version 1.19+, see @bugref{9896}
|
---|
3537 | * for more information.
|
---|
3538 | */
|
---|
3539 | return strNetwork.isEmpty()
|
---|
3540 | && strBindIP.isEmpty()
|
---|
3541 | && u32Mtu == 0
|
---|
3542 | && u32SockRcv == 0
|
---|
3543 | && u32SockSnd == 0
|
---|
3544 | && u32TcpRcv == 0
|
---|
3545 | && u32TcpSnd == 0
|
---|
3546 | && areDNSDefaultSettings()
|
---|
3547 | && areAliasDefaultSettings()
|
---|
3548 | && areTFTPDefaultSettings()
|
---|
3549 | && mapRules.size() == 0
|
---|
3550 | && areLocalhostReachableDefaultSettings(sv);
|
---|
3551 | }
|
---|
3552 |
|
---|
3553 | /**
|
---|
3554 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3555 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3556 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3557 | */
|
---|
3558 | bool NAT::operator==(const NAT &n) const
|
---|
3559 | {
|
---|
3560 | return (this == &n)
|
---|
3561 | || ( strNetwork == n.strNetwork
|
---|
3562 | && strBindIP == n.strBindIP
|
---|
3563 | && u32Mtu == n.u32Mtu
|
---|
3564 | && u32SockRcv == n.u32SockRcv
|
---|
3565 | && u32SockSnd == n.u32SockSnd
|
---|
3566 | && u32TcpSnd == n.u32TcpSnd
|
---|
3567 | && u32TcpRcv == n.u32TcpRcv
|
---|
3568 | && strTFTPPrefix == n.strTFTPPrefix
|
---|
3569 | && strTFTPBootFile == n.strTFTPBootFile
|
---|
3570 | && strTFTPNextServer == n.strTFTPNextServer
|
---|
3571 | && fDNSPassDomain == n.fDNSPassDomain
|
---|
3572 | && fDNSProxy == n.fDNSProxy
|
---|
3573 | && fDNSUseHostResolver == n.fDNSUseHostResolver
|
---|
3574 | && fAliasLog == n.fAliasLog
|
---|
3575 | && fAliasProxyOnly == n.fAliasProxyOnly
|
---|
3576 | && fAliasUseSamePorts == n.fAliasUseSamePorts
|
---|
3577 | && fLocalhostReachable == n.fLocalhostReachable
|
---|
3578 | && mapRules == n.mapRules);
|
---|
3579 | }
|
---|
3580 |
|
---|
3581 | /**
|
---|
3582 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3583 | */
|
---|
3584 | NetworkAdapter::NetworkAdapter() :
|
---|
3585 | ulSlot(0),
|
---|
3586 | type(NetworkAdapterType_Am79C970A), // default for old VMs, for new ones it's Am79C973
|
---|
3587 | fEnabled(false),
|
---|
3588 | fCableConnected(false), // default for old VMs, for new ones it's true
|
---|
3589 | ulLineSpeed(0),
|
---|
3590 | enmPromiscModePolicy(NetworkAdapterPromiscModePolicy_Deny),
|
---|
3591 | fTraceEnabled(false),
|
---|
3592 | mode(NetworkAttachmentType_Null),
|
---|
3593 | ulBootPriority(0)
|
---|
3594 | {
|
---|
3595 | }
|
---|
3596 |
|
---|
3597 | /**
|
---|
3598 | * Check if all Generic Driver settings have default values.
|
---|
3599 | */
|
---|
3600 | bool NetworkAdapter::areGenericDriverDefaultSettings() const
|
---|
3601 | {
|
---|
3602 | return strGenericDriver.isEmpty()
|
---|
3603 | && genericProperties.size() == 0;
|
---|
3604 | }
|
---|
3605 |
|
---|
3606 | /**
|
---|
3607 | * Check if all settings have default values.
|
---|
3608 | */
|
---|
3609 | bool NetworkAdapter::areDefaultSettings(SettingsVersion_T sv) const
|
---|
3610 | {
|
---|
3611 | // 5.0 and earlier had a default of fCableConnected=false, which doesn't
|
---|
3612 | // make a lot of sense (but it's a fact). Later versions don't save the
|
---|
3613 | // setting if it's at the default value and thus must get it right.
|
---|
3614 | return !fEnabled
|
---|
3615 | && strMACAddress.isEmpty()
|
---|
3616 | && ( (sv >= SettingsVersion_v1_16 && fCableConnected && type == NetworkAdapterType_Am79C973)
|
---|
3617 | || (sv < SettingsVersion_v1_16 && !fCableConnected && type == NetworkAdapterType_Am79C970A))
|
---|
3618 | && ulLineSpeed == 0
|
---|
3619 | && enmPromiscModePolicy == NetworkAdapterPromiscModePolicy_Deny
|
---|
3620 | && mode == NetworkAttachmentType_Null
|
---|
3621 | && nat.areDefaultSettings(sv)
|
---|
3622 | && strBridgedName.isEmpty()
|
---|
3623 | && strInternalNetworkName.isEmpty()
|
---|
3624 | #ifdef VBOX_WITH_VMNET
|
---|
3625 | && strHostOnlyNetworkName.isEmpty()
|
---|
3626 | #endif /* VBOX_WITH_VMNET */
|
---|
3627 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
3628 | && strCloudNetworkName.isEmpty()
|
---|
3629 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
3630 | && strHostOnlyName.isEmpty()
|
---|
3631 | && areGenericDriverDefaultSettings()
|
---|
3632 | && strNATNetworkName.isEmpty();
|
---|
3633 | }
|
---|
3634 |
|
---|
3635 | /**
|
---|
3636 | * Special check if settings of the non-current attachment type have default values.
|
---|
3637 | */
|
---|
3638 | bool NetworkAdapter::areDisabledDefaultSettings(SettingsVersion_T sv) const
|
---|
3639 | {
|
---|
3640 | return (mode != NetworkAttachmentType_NAT ? nat.areDefaultSettings(sv) : true)
|
---|
3641 | && (mode != NetworkAttachmentType_Bridged ? strBridgedName.isEmpty() : true)
|
---|
3642 | && (mode != NetworkAttachmentType_Internal ? strInternalNetworkName.isEmpty() : true)
|
---|
3643 | #ifdef VBOX_WITH_VMNET
|
---|
3644 | && (mode != NetworkAttachmentType_HostOnlyNetwork ? strHostOnlyNetworkName.isEmpty() : true)
|
---|
3645 | #endif /* VBOX_WITH_VMNET */
|
---|
3646 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
3647 | && (mode != NetworkAttachmentType_Cloud ? strCloudNetworkName.isEmpty() : true)
|
---|
3648 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
3649 | && (mode != NetworkAttachmentType_HostOnly ? strHostOnlyName.isEmpty() : true)
|
---|
3650 | && (mode != NetworkAttachmentType_Generic ? areGenericDriverDefaultSettings() : true)
|
---|
3651 | && (mode != NetworkAttachmentType_NATNetwork ? strNATNetworkName.isEmpty() : true);
|
---|
3652 | }
|
---|
3653 |
|
---|
3654 | /**
|
---|
3655 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3656 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3657 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3658 | */
|
---|
3659 | bool NetworkAdapter::operator==(const NetworkAdapter &n) const
|
---|
3660 | {
|
---|
3661 | return (this == &n)
|
---|
3662 | || ( ulSlot == n.ulSlot
|
---|
3663 | && type == n.type
|
---|
3664 | && fEnabled == n.fEnabled
|
---|
3665 | && strMACAddress == n.strMACAddress
|
---|
3666 | && fCableConnected == n.fCableConnected
|
---|
3667 | && ulLineSpeed == n.ulLineSpeed
|
---|
3668 | && enmPromiscModePolicy == n.enmPromiscModePolicy
|
---|
3669 | && fTraceEnabled == n.fTraceEnabled
|
---|
3670 | && strTraceFile == n.strTraceFile
|
---|
3671 | && mode == n.mode
|
---|
3672 | && nat == n.nat
|
---|
3673 | && strBridgedName == n.strBridgedName
|
---|
3674 | && strHostOnlyName == n.strHostOnlyName
|
---|
3675 | #ifdef VBOX_WITH_VMNET
|
---|
3676 | && strHostOnlyNetworkName == n.strHostOnlyNetworkName
|
---|
3677 | #endif /* VBOX_WITH_VMNET */
|
---|
3678 | && strInternalNetworkName == n.strInternalNetworkName
|
---|
3679 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
3680 | && strCloudNetworkName == n.strCloudNetworkName
|
---|
3681 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
3682 | && strGenericDriver == n.strGenericDriver
|
---|
3683 | && genericProperties == n.genericProperties
|
---|
3684 | && ulBootPriority == n.ulBootPriority
|
---|
3685 | && strBandwidthGroup == n.strBandwidthGroup);
|
---|
3686 | }
|
---|
3687 |
|
---|
3688 | /**
|
---|
3689 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3690 | */
|
---|
3691 | SerialPort::SerialPort() :
|
---|
3692 | ulSlot(0),
|
---|
3693 | fEnabled(false),
|
---|
3694 | ulIOAddress(0x3f8),
|
---|
3695 | ulIRQ(4),
|
---|
3696 | portMode(PortMode_Disconnected),
|
---|
3697 | fServer(false),
|
---|
3698 | uartType(UartType_U16550A)
|
---|
3699 | {
|
---|
3700 | }
|
---|
3701 |
|
---|
3702 | /**
|
---|
3703 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3704 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3705 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3706 | */
|
---|
3707 | bool SerialPort::operator==(const SerialPort &s) const
|
---|
3708 | {
|
---|
3709 | return (this == &s)
|
---|
3710 | || ( ulSlot == s.ulSlot
|
---|
3711 | && fEnabled == s.fEnabled
|
---|
3712 | && ulIOAddress == s.ulIOAddress
|
---|
3713 | && ulIRQ == s.ulIRQ
|
---|
3714 | && portMode == s.portMode
|
---|
3715 | && strPath == s.strPath
|
---|
3716 | && fServer == s.fServer
|
---|
3717 | && uartType == s.uartType);
|
---|
3718 | }
|
---|
3719 |
|
---|
3720 | /**
|
---|
3721 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3722 | */
|
---|
3723 | ParallelPort::ParallelPort() :
|
---|
3724 | ulSlot(0),
|
---|
3725 | fEnabled(false),
|
---|
3726 | ulIOBase(0x378),
|
---|
3727 | ulIRQ(7)
|
---|
3728 | {
|
---|
3729 | }
|
---|
3730 |
|
---|
3731 | /**
|
---|
3732 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3733 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3734 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3735 | */
|
---|
3736 | bool ParallelPort::operator==(const ParallelPort &s) const
|
---|
3737 | {
|
---|
3738 | return (this == &s)
|
---|
3739 | || ( ulSlot == s.ulSlot
|
---|
3740 | && fEnabled == s.fEnabled
|
---|
3741 | && ulIOBase == s.ulIOBase
|
---|
3742 | && ulIRQ == s.ulIRQ
|
---|
3743 | && strPath == s.strPath);
|
---|
3744 | }
|
---|
3745 |
|
---|
3746 | /**
|
---|
3747 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3748 | */
|
---|
3749 | AudioAdapter::AudioAdapter() :
|
---|
3750 | fEnabled(true), // default for old VMs, for new ones it's false
|
---|
3751 | fEnabledIn(true), // default for old VMs, for new ones it's false
|
---|
3752 | fEnabledOut(true), // default for old VMs, for new ones it's false
|
---|
3753 | controllerType(AudioControllerType_AC97),
|
---|
3754 | codecType(AudioCodecType_STAC9700),
|
---|
3755 | driverType(AudioDriverType_Null)
|
---|
3756 | {
|
---|
3757 | }
|
---|
3758 |
|
---|
3759 | /**
|
---|
3760 | * Check if all settings have default values.
|
---|
3761 | */
|
---|
3762 | bool AudioAdapter::areDefaultSettings(SettingsVersion_T sv) const
|
---|
3763 | {
|
---|
3764 | return (sv < SettingsVersion_v1_16 ? false : !fEnabled)
|
---|
3765 | && (sv <= SettingsVersion_v1_16 ? fEnabledIn : !fEnabledIn)
|
---|
3766 | && (sv <= SettingsVersion_v1_16 ? fEnabledOut : !fEnabledOut)
|
---|
3767 | && fEnabledOut == true
|
---|
3768 | && controllerType == AudioControllerType_AC97
|
---|
3769 | && codecType == AudioCodecType_STAC9700
|
---|
3770 | && properties.size() == 0;
|
---|
3771 | }
|
---|
3772 |
|
---|
3773 | /**
|
---|
3774 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3775 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3776 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3777 | */
|
---|
3778 | bool AudioAdapter::operator==(const AudioAdapter &a) const
|
---|
3779 | {
|
---|
3780 | return (this == &a)
|
---|
3781 | || ( fEnabled == a.fEnabled
|
---|
3782 | && fEnabledIn == a.fEnabledIn
|
---|
3783 | && fEnabledOut == a.fEnabledOut
|
---|
3784 | && controllerType == a.controllerType
|
---|
3785 | && codecType == a.codecType
|
---|
3786 | && driverType == a.driverType
|
---|
3787 | && properties == a.properties);
|
---|
3788 | }
|
---|
3789 |
|
---|
3790 | /**
|
---|
3791 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3792 | */
|
---|
3793 | SharedFolder::SharedFolder() :
|
---|
3794 | fWritable(false),
|
---|
3795 | fAutoMount(false),
|
---|
3796 | enmSymlinkPolicy(SymlinkPolicy_None)
|
---|
3797 | {
|
---|
3798 | }
|
---|
3799 |
|
---|
3800 | /**
|
---|
3801 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3802 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3803 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3804 | */
|
---|
3805 | bool SharedFolder::operator==(const SharedFolder &g) const
|
---|
3806 | {
|
---|
3807 | return (this == &g)
|
---|
3808 | || ( strName == g.strName
|
---|
3809 | && strHostPath == g.strHostPath
|
---|
3810 | && fWritable == g.fWritable
|
---|
3811 | && fAutoMount == g.fAutoMount
|
---|
3812 | && strAutoMountPoint == g.strAutoMountPoint
|
---|
3813 | && enmSymlinkPolicy == g.enmSymlinkPolicy);
|
---|
3814 | }
|
---|
3815 |
|
---|
3816 | /**
|
---|
3817 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3818 | */
|
---|
3819 | GuestProperty::GuestProperty() :
|
---|
3820 | timestamp(0)
|
---|
3821 | {
|
---|
3822 | }
|
---|
3823 |
|
---|
3824 | /**
|
---|
3825 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3826 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3827 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3828 | */
|
---|
3829 | bool GuestProperty::operator==(const GuestProperty &g) const
|
---|
3830 | {
|
---|
3831 | return (this == &g)
|
---|
3832 | || ( strName == g.strName
|
---|
3833 | && strValue == g.strValue
|
---|
3834 | && timestamp == g.timestamp
|
---|
3835 | && strFlags == g.strFlags);
|
---|
3836 | }
|
---|
3837 |
|
---|
3838 | /**
|
---|
3839 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3840 | */
|
---|
3841 | CpuIdLeafX86::CpuIdLeafX86() :
|
---|
3842 | idx(UINT32_MAX),
|
---|
3843 | idxSub(0),
|
---|
3844 | uEax(0),
|
---|
3845 | uEbx(0),
|
---|
3846 | uEcx(0),
|
---|
3847 | uEdx(0)
|
---|
3848 | {
|
---|
3849 | }
|
---|
3850 |
|
---|
3851 | /**
|
---|
3852 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3853 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3854 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3855 | */
|
---|
3856 | bool CpuIdLeafX86::operator==(const CpuIdLeafX86 &c) const
|
---|
3857 | {
|
---|
3858 | return (this == &c)
|
---|
3859 | || ( idx == c.idx
|
---|
3860 | && idxSub == c.idxSub
|
---|
3861 | && uEax == c.uEax
|
---|
3862 | && uEbx == c.uEbx
|
---|
3863 | && uEcx == c.uEcx
|
---|
3864 | && uEdx == c.uEdx);
|
---|
3865 | }
|
---|
3866 |
|
---|
3867 | /**
|
---|
3868 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3869 | */
|
---|
3870 | Cpu::Cpu() :
|
---|
3871 | ulId(UINT32_MAX)
|
---|
3872 | {
|
---|
3873 | }
|
---|
3874 |
|
---|
3875 | /**
|
---|
3876 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3877 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3878 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3879 | */
|
---|
3880 | bool Cpu::operator==(const Cpu &c) const
|
---|
3881 | {
|
---|
3882 | return (this == &c)
|
---|
3883 | || (ulId == c.ulId);
|
---|
3884 | }
|
---|
3885 |
|
---|
3886 | /**
|
---|
3887 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3888 | */
|
---|
3889 | BandwidthGroup::BandwidthGroup() :
|
---|
3890 | cMaxBytesPerSec(0),
|
---|
3891 | enmType(BandwidthGroupType_Null)
|
---|
3892 | {
|
---|
3893 | }
|
---|
3894 |
|
---|
3895 | /**
|
---|
3896 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3897 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3898 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3899 | */
|
---|
3900 | bool BandwidthGroup::operator==(const BandwidthGroup &i) const
|
---|
3901 | {
|
---|
3902 | return (this == &i)
|
---|
3903 | || ( strName == i.strName
|
---|
3904 | && cMaxBytesPerSec == i.cMaxBytesPerSec
|
---|
3905 | && enmType == i.enmType);
|
---|
3906 | }
|
---|
3907 |
|
---|
3908 | /**
|
---|
3909 | * IOSettings constructor.
|
---|
3910 | */
|
---|
3911 | IOSettings::IOSettings() :
|
---|
3912 | fIOCacheEnabled(true),
|
---|
3913 | ulIOCacheSize(5)
|
---|
3914 | {
|
---|
3915 | }
|
---|
3916 |
|
---|
3917 | /**
|
---|
3918 | * Check if all IO Cache settings have default values.
|
---|
3919 | */
|
---|
3920 | bool IOSettings::areIOCacheDefaultSettings() const
|
---|
3921 | {
|
---|
3922 | return fIOCacheEnabled
|
---|
3923 | && ulIOCacheSize == 5;
|
---|
3924 | }
|
---|
3925 |
|
---|
3926 | /**
|
---|
3927 | * Check if all settings have default values.
|
---|
3928 | */
|
---|
3929 | bool IOSettings::areDefaultSettings() const
|
---|
3930 | {
|
---|
3931 | return areIOCacheDefaultSettings()
|
---|
3932 | && llBandwidthGroups.size() == 0;
|
---|
3933 | }
|
---|
3934 |
|
---|
3935 | /**
|
---|
3936 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3937 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3938 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3939 | */
|
---|
3940 | bool IOSettings::operator==(const IOSettings &i) const
|
---|
3941 | {
|
---|
3942 | return (this == &i)
|
---|
3943 | || ( fIOCacheEnabled == i.fIOCacheEnabled
|
---|
3944 | && ulIOCacheSize == i.ulIOCacheSize
|
---|
3945 | && llBandwidthGroups == i.llBandwidthGroups);
|
---|
3946 | }
|
---|
3947 |
|
---|
3948 | /**
|
---|
3949 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3950 | */
|
---|
3951 | HostPCIDeviceAttachment::HostPCIDeviceAttachment() :
|
---|
3952 | uHostAddress(0),
|
---|
3953 | uGuestAddress(0)
|
---|
3954 | {
|
---|
3955 | }
|
---|
3956 |
|
---|
3957 | /**
|
---|
3958 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3959 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3960 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3961 | */
|
---|
3962 | bool HostPCIDeviceAttachment::operator==(const HostPCIDeviceAttachment &a) const
|
---|
3963 | {
|
---|
3964 | return (this == &a)
|
---|
3965 | || ( uHostAddress == a.uHostAddress
|
---|
3966 | && uGuestAddress == a.uGuestAddress
|
---|
3967 | && strDeviceName == a.strDeviceName);
|
---|
3968 | }
|
---|
3969 |
|
---|
3970 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
3971 | PlatformARM::PlatformARM()
|
---|
3972 | {
|
---|
3973 | }
|
---|
3974 |
|
---|
3975 | bool PlatformARM::operator==(const PlatformARM& h) const
|
---|
3976 | {
|
---|
3977 | RT_NOREF(h);
|
---|
3978 | return true;
|
---|
3979 | }
|
---|
3980 | #endif /* VBOX_WITH_VIRT_ARMV8 */
|
---|
3981 |
|
---|
3982 | PlatformX86::PlatformX86() :
|
---|
3983 | fPAE(false),
|
---|
3984 | fAPIC(true),
|
---|
3985 | fX2APIC(false),
|
---|
3986 | fHPETEnabled(false),
|
---|
3987 | enmLongMode(HC_ARCH_BITS == 64 ? PlatformX86::LongMode_Enabled : PlatformX86::LongMode_Disabled),
|
---|
3988 | fTripleFaultReset(false),
|
---|
3989 | fIBPBOnVMExit(false),
|
---|
3990 | fIBPBOnVMEntry(false),
|
---|
3991 | fSpecCtrl(false),
|
---|
3992 | fSpecCtrlByHost(false),
|
---|
3993 | fL1DFlushOnSched(true),
|
---|
3994 | fL1DFlushOnVMEntry(false),
|
---|
3995 | fMDSClearOnSched(true),
|
---|
3996 | fMDSClearOnVMEntry(false),
|
---|
3997 | fHWVirtEx(true),
|
---|
3998 | fHWVirtExNestedPaging(true),
|
---|
3999 | fHWVirtExVPID(true),
|
---|
4000 | fHWVirtExUX(true),
|
---|
4001 | fHWVirtExForce(false),
|
---|
4002 | fHWVirtExUseNativeApi(false),
|
---|
4003 | fHWVirtExVirtVmsaveVmload(true),
|
---|
4004 | fNestedHWVirt(false)
|
---|
4005 | {
|
---|
4006 | /* The default value for PAE depends on the host:
|
---|
4007 | * - 64 bits host -> always true
|
---|
4008 | * - 32 bits host -> true for Windows & Darwin (masked off if the host cpu doesn't support it anyway)
|
---|
4009 | */
|
---|
4010 | #if HC_ARCH_BITS == 64 || defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN)
|
---|
4011 | fPAE = true;
|
---|
4012 | #endif
|
---|
4013 |
|
---|
4014 | /* The default value of large page supports depends on the host:
|
---|
4015 | * - 64 bits host -> true, unless it's Linux (pending further prediction work due to excessively expensive large page allocations)
|
---|
4016 | * - 32 bits host -> false
|
---|
4017 | */
|
---|
4018 | #if HC_ARCH_BITS == 64 && !defined(RT_OS_LINUX)
|
---|
4019 | fHWVirtExLargePages = true; /** @todo BUGBUG Does this apply for ARM as well? */
|
---|
4020 | #else
|
---|
4021 | /* Not supported on 32 bits hosts. */
|
---|
4022 | fHWVirtExLargePages = false;
|
---|
4023 | #endif
|
---|
4024 | }
|
---|
4025 |
|
---|
4026 | /**
|
---|
4027 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4028 | * which in turn gets called from Platform::saveSettings to figure out whether
|
---|
4029 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4030 | */
|
---|
4031 | bool PlatformX86::operator==(const PlatformX86& h) const
|
---|
4032 | {
|
---|
4033 | return (this == &h)
|
---|
4034 | || ( fPAE == h.fPAE
|
---|
4035 | && fAPIC == h.fAPIC
|
---|
4036 | && fX2APIC == h.fX2APIC
|
---|
4037 | && fHPETEnabled == h.fHPETEnabled
|
---|
4038 | && enmLongMode == h.enmLongMode
|
---|
4039 | && llCpuIdLeafs == h.llCpuIdLeafs
|
---|
4040 | && fTripleFaultReset == h.fTripleFaultReset
|
---|
4041 | && fIBPBOnVMExit == h.fIBPBOnVMExit
|
---|
4042 | && fIBPBOnVMEntry == h.fIBPBOnVMEntry
|
---|
4043 | && fSpecCtrl == h.fSpecCtrl
|
---|
4044 | && fSpecCtrlByHost == h.fSpecCtrlByHost
|
---|
4045 | && fL1DFlushOnSched == h.fL1DFlushOnSched
|
---|
4046 | && fL1DFlushOnVMEntry == h.fL1DFlushOnVMEntry
|
---|
4047 | && fMDSClearOnSched == h.fMDSClearOnSched
|
---|
4048 | && fMDSClearOnVMEntry == h.fMDSClearOnVMEntry
|
---|
4049 | && fHWVirtEx == h.fHWVirtEx
|
---|
4050 | && fHWVirtExNestedPaging == h.fHWVirtExNestedPaging
|
---|
4051 | && fHWVirtExLargePages == h.fHWVirtExLargePages
|
---|
4052 | && fHWVirtExVPID == h.fHWVirtExVPID
|
---|
4053 | && fHWVirtExUX == h.fHWVirtExUX
|
---|
4054 | && fHWVirtExForce == h.fHWVirtExForce
|
---|
4055 | && fHWVirtExUseNativeApi == h.fHWVirtExUseNativeApi
|
---|
4056 | && fHWVirtExVirtVmsaveVmload == h.fHWVirtExVirtVmsaveVmload
|
---|
4057 | && fNestedHWVirt == h.fNestedHWVirt);
|
---|
4058 | }
|
---|
4059 |
|
---|
4060 | /**
|
---|
4061 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4062 | */
|
---|
4063 | Platform::Platform() :
|
---|
4064 | architectureType(PlatformArchitecture_x86), /* We default to x86 here, as this is what we ever had so far. */
|
---|
4065 | chipsetType(ChipsetType_PIIX3),
|
---|
4066 | iommuType(IommuType_None),
|
---|
4067 | fRTCUseUTC(false)
|
---|
4068 | {
|
---|
4069 | }
|
---|
4070 |
|
---|
4071 | /**
|
---|
4072 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4073 | * which in turn gets called from Platform::saveSettings to figure out whether
|
---|
4074 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4075 | */
|
---|
4076 | bool Platform::operator==(const Platform& h) const
|
---|
4077 | {
|
---|
4078 | bool fRc = (this == &h)
|
---|
4079 | || ( architectureType == h.architectureType
|
---|
4080 | && chipsetType == h.chipsetType
|
---|
4081 | && iommuType == h.iommuType
|
---|
4082 | && fRTCUseUTC == h.fRTCUseUTC);
|
---|
4083 | if (fRc)
|
---|
4084 | {
|
---|
4085 | switch (architectureType)
|
---|
4086 | {
|
---|
4087 | case PlatformArchitecture_x86:
|
---|
4088 | return x86 == h.x86;
|
---|
4089 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
4090 | case PlatformArchitecture_ARM:
|
---|
4091 | return arm == h.arm;
|
---|
4092 | #endif
|
---|
4093 | default:
|
---|
4094 | AssertFailedReturn(false);
|
---|
4095 | }
|
---|
4096 | }
|
---|
4097 |
|
---|
4098 | return fRc;
|
---|
4099 | }
|
---|
4100 |
|
---|
4101 | /**
|
---|
4102 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4103 | */
|
---|
4104 | Hardware::Hardware() :
|
---|
4105 | strVersion("1"),
|
---|
4106 | cCPUs(1),
|
---|
4107 | fCpuHotPlug(false),
|
---|
4108 | ulCpuExecutionCap(100),
|
---|
4109 | uCpuIdPortabilityLevel(0),
|
---|
4110 | strCpuProfile("host"),
|
---|
4111 | ulMemorySizeMB((uint32_t)-1),
|
---|
4112 | pointingHIDType(PointingHIDType_PS2Mouse),
|
---|
4113 | keyboardHIDType(KeyboardHIDType_PS2Keyboard),
|
---|
4114 | paravirtProvider(ParavirtProvider_Legacy), // default for old VMs, for new ones it's ParavirtProvider_Default
|
---|
4115 | strParavirtDebug(""),
|
---|
4116 | fEmulatedUSBCardReader(false),
|
---|
4117 | clipboardMode(ClipboardMode_Disabled),
|
---|
4118 | fClipboardFileTransfersEnabled(false),
|
---|
4119 | dndMode(DnDMode_Disabled),
|
---|
4120 | ulMemoryBalloonSize(0),
|
---|
4121 | fPageFusionEnabled(false)
|
---|
4122 | {
|
---|
4123 | mapBootOrder[0] = DeviceType_Floppy;
|
---|
4124 | mapBootOrder[1] = DeviceType_DVD;
|
---|
4125 | mapBootOrder[2] = DeviceType_HardDisk;
|
---|
4126 | }
|
---|
4127 |
|
---|
4128 | /**
|
---|
4129 | * Check if all Paravirt settings have default values.
|
---|
4130 | */
|
---|
4131 | bool Hardware::areParavirtDefaultSettings(SettingsVersion_T sv) const
|
---|
4132 | {
|
---|
4133 | // 5.0 didn't save the paravirt settings if it is ParavirtProvider_Legacy,
|
---|
4134 | // so this default must be kept. Later versions don't save the setting if
|
---|
4135 | // it's at the default value.
|
---|
4136 | return ( (sv >= SettingsVersion_v1_16 && paravirtProvider == ParavirtProvider_Default)
|
---|
4137 | || (sv < SettingsVersion_v1_16 && paravirtProvider == ParavirtProvider_Legacy))
|
---|
4138 | && strParavirtDebug.isEmpty();
|
---|
4139 | }
|
---|
4140 |
|
---|
4141 | /**
|
---|
4142 | * Check if all Boot Order settings have default values.
|
---|
4143 | */
|
---|
4144 | bool Hardware::areBootOrderDefaultSettings() const
|
---|
4145 | {
|
---|
4146 | BootOrderMap::const_iterator it0 = mapBootOrder.find(0);
|
---|
4147 | BootOrderMap::const_iterator it1 = mapBootOrder.find(1);
|
---|
4148 | BootOrderMap::const_iterator it2 = mapBootOrder.find(2);
|
---|
4149 | BootOrderMap::const_iterator it3 = mapBootOrder.find(3);
|
---|
4150 | return ( mapBootOrder.size() == 3
|
---|
4151 | || ( mapBootOrder.size() == 4
|
---|
4152 | && (it3 != mapBootOrder.end() && it3->second == DeviceType_Null)))
|
---|
4153 | && (it0 != mapBootOrder.end() && it0->second == DeviceType_Floppy)
|
---|
4154 | && (it1 != mapBootOrder.end() && it1->second == DeviceType_DVD)
|
---|
4155 | && (it2 != mapBootOrder.end() && it2->second == DeviceType_HardDisk);
|
---|
4156 | }
|
---|
4157 |
|
---|
4158 | /**
|
---|
4159 | * Check if all Network Adapter settings have default values.
|
---|
4160 | */
|
---|
4161 | bool Hardware::areAllNetworkAdaptersDefaultSettings(SettingsVersion_T sv) const
|
---|
4162 | {
|
---|
4163 | for (NetworkAdaptersList::const_iterator it = llNetworkAdapters.begin();
|
---|
4164 | it != llNetworkAdapters.end();
|
---|
4165 | ++it)
|
---|
4166 | {
|
---|
4167 | if (!it->areDefaultSettings(sv))
|
---|
4168 | return false;
|
---|
4169 | }
|
---|
4170 | return true;
|
---|
4171 | }
|
---|
4172 |
|
---|
4173 | /**
|
---|
4174 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4175 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4176 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4177 | */
|
---|
4178 | bool Hardware::operator==(const Hardware& h) const
|
---|
4179 | {
|
---|
4180 | return (this == &h)
|
---|
4181 | || ( strVersion == h.strVersion
|
---|
4182 | && uuid == h.uuid
|
---|
4183 | && cCPUs == h.cCPUs
|
---|
4184 | && fCpuHotPlug == h.fCpuHotPlug
|
---|
4185 | && ulCpuExecutionCap == h.ulCpuExecutionCap
|
---|
4186 | && uCpuIdPortabilityLevel == h.uCpuIdPortabilityLevel
|
---|
4187 | && strCpuProfile == h.strCpuProfile
|
---|
4188 | && llCpus == h.llCpus
|
---|
4189 | && ulMemorySizeMB == h.ulMemorySizeMB
|
---|
4190 | && mapBootOrder == h.mapBootOrder
|
---|
4191 | && pointingHIDType == h.pointingHIDType
|
---|
4192 | && keyboardHIDType == h.keyboardHIDType
|
---|
4193 | && paravirtProvider == h.paravirtProvider
|
---|
4194 | && strParavirtDebug == h.strParavirtDebug
|
---|
4195 | && fEmulatedUSBCardReader == h.fEmulatedUSBCardReader
|
---|
4196 | && vrdeSettings == h.vrdeSettings
|
---|
4197 | && platformSettings == h.platformSettings
|
---|
4198 | && firmwareSettings == h.firmwareSettings
|
---|
4199 | && nvramSettings == h.nvramSettings
|
---|
4200 | && graphicsAdapter == h.graphicsAdapter
|
---|
4201 | && usbSettings == h.usbSettings
|
---|
4202 | && tpmSettings == h.tpmSettings
|
---|
4203 | && llNetworkAdapters == h.llNetworkAdapters
|
---|
4204 | && llSerialPorts == h.llSerialPorts
|
---|
4205 | && llParallelPorts == h.llParallelPorts
|
---|
4206 | && audioAdapter == h.audioAdapter
|
---|
4207 | && storage == h.storage
|
---|
4208 | && llSharedFolders == h.llSharedFolders
|
---|
4209 | && clipboardMode == h.clipboardMode
|
---|
4210 | && fClipboardFileTransfersEnabled == h.fClipboardFileTransfersEnabled
|
---|
4211 | && dndMode == h.dndMode
|
---|
4212 | && ulMemoryBalloonSize == h.ulMemoryBalloonSize
|
---|
4213 | && fPageFusionEnabled == h.fPageFusionEnabled
|
---|
4214 | && llGuestProperties == h.llGuestProperties
|
---|
4215 | && ioSettings == h.ioSettings
|
---|
4216 | && pciAttachments == h.pciAttachments
|
---|
4217 | && strDefaultFrontend == h.strDefaultFrontend);
|
---|
4218 | }
|
---|
4219 |
|
---|
4220 | /**
|
---|
4221 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4222 | */
|
---|
4223 | AttachedDevice::AttachedDevice() :
|
---|
4224 | deviceType(DeviceType_Null),
|
---|
4225 | fPassThrough(false),
|
---|
4226 | fTempEject(false),
|
---|
4227 | fNonRotational(false),
|
---|
4228 | fDiscard(false),
|
---|
4229 | fHotPluggable(false),
|
---|
4230 | lPort(0),
|
---|
4231 | lDevice(0)
|
---|
4232 | {
|
---|
4233 | }
|
---|
4234 |
|
---|
4235 | /**
|
---|
4236 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4237 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4238 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4239 | */
|
---|
4240 | bool AttachedDevice::operator==(const AttachedDevice &a) const
|
---|
4241 | {
|
---|
4242 | return (this == &a)
|
---|
4243 | || ( deviceType == a.deviceType
|
---|
4244 | && fPassThrough == a.fPassThrough
|
---|
4245 | && fTempEject == a.fTempEject
|
---|
4246 | && fNonRotational == a.fNonRotational
|
---|
4247 | && fDiscard == a.fDiscard
|
---|
4248 | && fHotPluggable == a.fHotPluggable
|
---|
4249 | && lPort == a.lPort
|
---|
4250 | && lDevice == a.lDevice
|
---|
4251 | && uuid == a.uuid
|
---|
4252 | && strHostDriveSrc == a.strHostDriveSrc
|
---|
4253 | && strBwGroup == a.strBwGroup);
|
---|
4254 | }
|
---|
4255 |
|
---|
4256 | /**
|
---|
4257 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4258 | */
|
---|
4259 | StorageController::StorageController() :
|
---|
4260 | storageBus(StorageBus_IDE),
|
---|
4261 | controllerType(StorageControllerType_PIIX3),
|
---|
4262 | ulPortCount(2),
|
---|
4263 | ulInstance(0),
|
---|
4264 | fUseHostIOCache(true),
|
---|
4265 | fBootable(true)
|
---|
4266 | {
|
---|
4267 | }
|
---|
4268 |
|
---|
4269 | /**
|
---|
4270 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4271 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4272 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4273 | */
|
---|
4274 | bool StorageController::operator==(const StorageController &s) const
|
---|
4275 | {
|
---|
4276 | return (this == &s)
|
---|
4277 | || ( strName == s.strName
|
---|
4278 | && storageBus == s.storageBus
|
---|
4279 | && controllerType == s.controllerType
|
---|
4280 | && ulPortCount == s.ulPortCount
|
---|
4281 | && ulInstance == s.ulInstance
|
---|
4282 | && fUseHostIOCache == s.fUseHostIOCache
|
---|
4283 | && llAttachedDevices == s.llAttachedDevices);
|
---|
4284 | }
|
---|
4285 |
|
---|
4286 | /**
|
---|
4287 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4288 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4289 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4290 | */
|
---|
4291 | bool Storage::operator==(const Storage &s) const
|
---|
4292 | {
|
---|
4293 | return (this == &s)
|
---|
4294 | || (llStorageControllers == s.llStorageControllers); // deep compare
|
---|
4295 | }
|
---|
4296 |
|
---|
4297 | /**
|
---|
4298 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4299 | */
|
---|
4300 | Debugging::Debugging() :
|
---|
4301 | fTracingEnabled(false),
|
---|
4302 | fAllowTracingToAccessVM(false),
|
---|
4303 | strTracingConfig(),
|
---|
4304 | enmDbgProvider(GuestDebugProvider_None),
|
---|
4305 | enmIoProvider(GuestDebugIoProvider_None),
|
---|
4306 | strAddress(),
|
---|
4307 | ulPort(0)
|
---|
4308 | {
|
---|
4309 | }
|
---|
4310 |
|
---|
4311 | /**
|
---|
4312 | * Check if all settings have default values.
|
---|
4313 | */
|
---|
4314 | bool Debugging::areDefaultSettings() const
|
---|
4315 | {
|
---|
4316 | return !fTracingEnabled
|
---|
4317 | && !fAllowTracingToAccessVM
|
---|
4318 | && strTracingConfig.isEmpty()
|
---|
4319 | && enmDbgProvider == GuestDebugProvider_None
|
---|
4320 | && enmIoProvider == GuestDebugIoProvider_None
|
---|
4321 | && strAddress.isEmpty()
|
---|
4322 | && ulPort == 0;
|
---|
4323 | }
|
---|
4324 |
|
---|
4325 | /**
|
---|
4326 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4327 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4328 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4329 | */
|
---|
4330 | bool Debugging::operator==(const Debugging &d) const
|
---|
4331 | {
|
---|
4332 | return (this == &d)
|
---|
4333 | || ( fTracingEnabled == d.fTracingEnabled
|
---|
4334 | && fAllowTracingToAccessVM == d.fAllowTracingToAccessVM
|
---|
4335 | && strTracingConfig == d.strTracingConfig
|
---|
4336 | && enmDbgProvider == d.enmDbgProvider
|
---|
4337 | && enmIoProvider == d.enmIoProvider
|
---|
4338 | && strAddress == d.strAddress
|
---|
4339 | && ulPort == d.ulPort);
|
---|
4340 | }
|
---|
4341 |
|
---|
4342 | /**
|
---|
4343 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4344 | */
|
---|
4345 | Autostart::Autostart() :
|
---|
4346 | fAutostartEnabled(false),
|
---|
4347 | uAutostartDelay(0),
|
---|
4348 | enmAutostopType(AutostopType_Disabled)
|
---|
4349 | {
|
---|
4350 | }
|
---|
4351 |
|
---|
4352 | /**
|
---|
4353 | * Check if all settings have default values.
|
---|
4354 | */
|
---|
4355 | bool Autostart::areDefaultSettings() const
|
---|
4356 | {
|
---|
4357 | return !fAutostartEnabled
|
---|
4358 | && !uAutostartDelay
|
---|
4359 | && enmAutostopType == AutostopType_Disabled;
|
---|
4360 | }
|
---|
4361 |
|
---|
4362 | /**
|
---|
4363 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4364 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4365 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4366 | */
|
---|
4367 | bool Autostart::operator==(const Autostart &a) const
|
---|
4368 | {
|
---|
4369 | return (this == &a)
|
---|
4370 | || ( fAutostartEnabled == a.fAutostartEnabled
|
---|
4371 | && uAutostartDelay == a.uAutostartDelay
|
---|
4372 | && enmAutostopType == a.enmAutostopType);
|
---|
4373 | }
|
---|
4374 |
|
---|
4375 | /**
|
---|
4376 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4377 | */
|
---|
4378 | Snapshot::Snapshot()
|
---|
4379 | {
|
---|
4380 | RTTimeSpecSetNano(×tamp, 0);
|
---|
4381 | }
|
---|
4382 |
|
---|
4383 | /**
|
---|
4384 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4385 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4386 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4387 | */
|
---|
4388 | bool Snapshot::operator==(const Snapshot &s) const
|
---|
4389 | {
|
---|
4390 | return (this == &s)
|
---|
4391 | || ( uuid == s.uuid
|
---|
4392 | && strName == s.strName
|
---|
4393 | && strDescription == s.strDescription
|
---|
4394 | && RTTimeSpecIsEqual(×tamp, &s.timestamp)
|
---|
4395 | && strStateFile == s.strStateFile
|
---|
4396 | && hardware == s.hardware // deep compare
|
---|
4397 | && recordingSettings == s.recordingSettings // deep compare
|
---|
4398 | && llChildSnapshots == s.llChildSnapshots // deep compare
|
---|
4399 | && debugging == s.debugging
|
---|
4400 | && autostart == s.autostart);
|
---|
4401 | }
|
---|
4402 |
|
---|
4403 | const struct Snapshot settings::Snapshot::Empty; /* default ctor is OK */
|
---|
4404 |
|
---|
4405 | /**
|
---|
4406 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4407 | */
|
---|
4408 | MachineUserData::MachineUserData() :
|
---|
4409 | fDirectoryIncludesUUID(false),
|
---|
4410 | fNameSync(true),
|
---|
4411 | fTeleporterEnabled(false),
|
---|
4412 | uTeleporterPort(0),
|
---|
4413 | enmVMPriority(VMProcPriority_Default),
|
---|
4414 | enmExecEngine(VMExecutionEngine_Default)
|
---|
4415 | {
|
---|
4416 | llGroups.push_back("/");
|
---|
4417 | }
|
---|
4418 |
|
---|
4419 | /**
|
---|
4420 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4421 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4422 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4423 | */
|
---|
4424 | bool MachineUserData::operator==(const MachineUserData &c) const
|
---|
4425 | {
|
---|
4426 | return (this == &c)
|
---|
4427 | || ( strName == c.strName
|
---|
4428 | && fDirectoryIncludesUUID == c.fDirectoryIncludesUUID
|
---|
4429 | && fNameSync == c.fNameSync
|
---|
4430 | && strDescription == c.strDescription
|
---|
4431 | && llGroups == c.llGroups
|
---|
4432 | && strOsType == c.strOsType
|
---|
4433 | && strSnapshotFolder == c.strSnapshotFolder
|
---|
4434 | && fTeleporterEnabled == c.fTeleporterEnabled
|
---|
4435 | && uTeleporterPort == c.uTeleporterPort
|
---|
4436 | && strTeleporterAddress == c.strTeleporterAddress
|
---|
4437 | && strTeleporterPassword == c.strTeleporterPassword
|
---|
4438 | && ovIcon == c.ovIcon
|
---|
4439 | && enmVMPriority == c.enmVMPriority
|
---|
4440 | && enmExecEngine == c.enmExecEngine);
|
---|
4441 | }
|
---|
4442 |
|
---|
4443 |
|
---|
4444 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4445 | //
|
---|
4446 | // MachineConfigFile
|
---|
4447 | //
|
---|
4448 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4449 |
|
---|
4450 | /**
|
---|
4451 | * Constructor.
|
---|
4452 | *
|
---|
4453 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
4454 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
4455 | * are initialized with default values.
|
---|
4456 | *
|
---|
4457 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
4458 | * the caller should catch; if this constructor does not throw, then the member
|
---|
4459 | * variables contain meaningful values (either from the file or defaults).
|
---|
4460 | *
|
---|
4461 | * @param pstrFilename
|
---|
4462 | * @param pCryptoIf Pointer to the cryptographic interface, required for an encrypted machine config.
|
---|
4463 | * @param pszPassword The password to use for an encrypted machine config.
|
---|
4464 | */
|
---|
4465 | MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename, PCVBOXCRYPTOIF pCryptoIf, const char *pszPassword)
|
---|
4466 | : ConfigFileBase(pstrFilename),
|
---|
4467 | enmParseState(ParseState_NotParsed),
|
---|
4468 | fCurrentStateModified(true),
|
---|
4469 | fAborted(false)
|
---|
4470 | {
|
---|
4471 | RTTimeNow(&timeLastStateChange);
|
---|
4472 |
|
---|
4473 | if (pstrFilename)
|
---|
4474 | {
|
---|
4475 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
4476 | // we need only analyze what is in there
|
---|
4477 |
|
---|
4478 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
4479 | const xml::ElementNode *pelmRootChild;
|
---|
4480 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
4481 | {
|
---|
4482 | if (pelmRootChild->nameEquals("MachineEncrypted"))
|
---|
4483 | readMachineEncrypted(*pelmRootChild, pCryptoIf, pszPassword);
|
---|
4484 | if (pelmRootChild->nameEquals("Machine"))
|
---|
4485 | readMachine(*pelmRootChild);
|
---|
4486 | }
|
---|
4487 |
|
---|
4488 | // clean up memory allocated by XML engine
|
---|
4489 | clearDocument();
|
---|
4490 |
|
---|
4491 | if (enmParseState == ParseState_NotParsed)
|
---|
4492 | enmParseState = ParseState_Parsed;
|
---|
4493 | }
|
---|
4494 | }
|
---|
4495 |
|
---|
4496 | /**
|
---|
4497 | * Public routine which returns true if this machine config file can have its
|
---|
4498 | * own media registry (which is true for settings version v1.11 and higher,
|
---|
4499 | * i.e. files created by VirtualBox 4.0 and higher).
|
---|
4500 | * @return
|
---|
4501 | */
|
---|
4502 | bool MachineConfigFile::canHaveOwnMediaRegistry() const
|
---|
4503 | {
|
---|
4504 | return (m->sv >= SettingsVersion_v1_11);
|
---|
4505 | }
|
---|
4506 |
|
---|
4507 | /**
|
---|
4508 | * Public routine which copies encryption settings. Used by Machine::saveSettings
|
---|
4509 | * so that the encryption settings do not get lost when a copy of the Machine settings
|
---|
4510 | * file is made to see if settings have actually changed.
|
---|
4511 | * @param other
|
---|
4512 | */
|
---|
4513 | void MachineConfigFile::copyEncryptionSettingsFrom(const MachineConfigFile &other)
|
---|
4514 | {
|
---|
4515 | strKeyId = other.strKeyId;
|
---|
4516 | strKeyStore = other.strKeyStore;
|
---|
4517 | }
|
---|
4518 |
|
---|
4519 | /**
|
---|
4520 | * Public routine which allows for importing machine XML from an external DOM tree.
|
---|
4521 | * Use this after having called the constructor with a NULL argument.
|
---|
4522 | *
|
---|
4523 | * This is used by the OVF code if a <vbox:Machine> element has been encountered
|
---|
4524 | * in an OVF VirtualSystem element.
|
---|
4525 | *
|
---|
4526 | * @param elmMachine
|
---|
4527 | */
|
---|
4528 | void MachineConfigFile::importMachineXML(const xml::ElementNode &elmMachine)
|
---|
4529 | {
|
---|
4530 | // Ideally the version should be mandatory, but since VirtualBox didn't
|
---|
4531 | // care about it until 5.1 came with different defaults, there are OVF
|
---|
4532 | // files created by magicians (not using VirtualBox, which always wrote it)
|
---|
4533 | // which lack this information. Let's hope that they learn to add the
|
---|
4534 | // version when they switch to the newer settings style/defaults of 5.1.
|
---|
4535 | if (!(elmMachine.getAttributeValue("version", m->strSettingsVersionFull)))
|
---|
4536 | m->strSettingsVersionFull = VBOX_XML_IMPORT_VERSION_FULL;
|
---|
4537 |
|
---|
4538 | LogRel(("Import settings with version \"%s\"\n", m->strSettingsVersionFull.c_str()));
|
---|
4539 |
|
---|
4540 | m->sv = parseVersion(m->strSettingsVersionFull, &elmMachine);
|
---|
4541 |
|
---|
4542 | // remember the settings version we read in case it gets upgraded later,
|
---|
4543 | // so we know when to make backups
|
---|
4544 | m->svRead = m->sv;
|
---|
4545 |
|
---|
4546 | readMachine(elmMachine);
|
---|
4547 | }
|
---|
4548 |
|
---|
4549 | /**
|
---|
4550 | * Comparison operator. This gets called from Machine::saveSettings to figure out
|
---|
4551 | * whether machine settings have really changed and thus need to be written out to disk.
|
---|
4552 | *
|
---|
4553 | * Even though this is called operator==, this does NOT compare all fields; the "equals"
|
---|
4554 | * should be understood as "has the same machine config as". The following fields are
|
---|
4555 | * NOT compared:
|
---|
4556 | * -- settings versions and file names inherited from ConfigFileBase;
|
---|
4557 | * -- fCurrentStateModified because that is considered separately in Machine::saveSettings!!
|
---|
4558 | *
|
---|
4559 | * The "deep" comparisons marked below will invoke the operator== functions of the
|
---|
4560 | * structs defined in this file, which may in turn go into comparing lists of
|
---|
4561 | * other structures. As a result, invoking this can be expensive, but it's
|
---|
4562 | * less expensive than writing out XML to disk.
|
---|
4563 | */
|
---|
4564 | bool MachineConfigFile::operator==(const MachineConfigFile &c) const
|
---|
4565 | {
|
---|
4566 | return (this == &c)
|
---|
4567 | || ( uuid == c.uuid
|
---|
4568 | && machineUserData == c.machineUserData
|
---|
4569 | && strStateFile == c.strStateFile
|
---|
4570 | && uuidCurrentSnapshot == c.uuidCurrentSnapshot
|
---|
4571 | // skip fCurrentStateModified!
|
---|
4572 | && RTTimeSpecIsEqual(&timeLastStateChange, &c.timeLastStateChange)
|
---|
4573 | && fAborted == c.fAborted
|
---|
4574 | && hardwareMachine == c.hardwareMachine // this one's deep
|
---|
4575 | && mediaRegistry == c.mediaRegistry // this one's deep
|
---|
4576 | // skip mapExtraDataItems! there is no old state available as it's always forced
|
---|
4577 | && llFirstSnapshot == c.llFirstSnapshot // this one's deep
|
---|
4578 | && recordingSettings == c.recordingSettings // this one's deep
|
---|
4579 | && strKeyId == c.strKeyId
|
---|
4580 | && strKeyStore == c.strKeyStore
|
---|
4581 | && strStateKeyId == c.strStateKeyId
|
---|
4582 | && strStateKeyStore == c.strStateKeyStore
|
---|
4583 | && strLogKeyId == c.strLogKeyId
|
---|
4584 | && strLogKeyStore == c.strLogKeyStore);
|
---|
4585 | }
|
---|
4586 |
|
---|
4587 | /**
|
---|
4588 | * Called from MachineConfigFile::readHardware() to read CPU information.
|
---|
4589 | *
|
---|
4590 | * @param elmCpu
|
---|
4591 | * @param ll
|
---|
4592 | */
|
---|
4593 | void MachineConfigFile::readCpuTree(const xml::ElementNode &elmCpu,
|
---|
4594 | CpuList &ll)
|
---|
4595 | {
|
---|
4596 | xml::NodesLoop nl1(elmCpu, "Cpu");
|
---|
4597 | const xml::ElementNode *pelmCpu;
|
---|
4598 | while ((pelmCpu = nl1.forAllNodes()))
|
---|
4599 | {
|
---|
4600 | Cpu cpu;
|
---|
4601 |
|
---|
4602 | if (!pelmCpu->getAttributeValue("id", cpu.ulId))
|
---|
4603 | throw ConfigFileError(this, pelmCpu, N_("Required Cpu/@id attribute is missing"));
|
---|
4604 |
|
---|
4605 | ll.push_back(cpu);
|
---|
4606 | }
|
---|
4607 | }
|
---|
4608 |
|
---|
4609 | /**
|
---|
4610 | * Called from MachineConfigFile::readPlatformX86() to read x86 CPUID information.
|
---|
4611 | *
|
---|
4612 | * @param elmCpuid
|
---|
4613 | * @param ll
|
---|
4614 | */
|
---|
4615 | void MachineConfigFile::readCpuIdTreeX86(const xml::ElementNode &elmCpuid,
|
---|
4616 | CpuIdLeafsX86List &ll)
|
---|
4617 | {
|
---|
4618 | xml::NodesLoop nl1(elmCpuid, "CpuIdLeaf");
|
---|
4619 | const xml::ElementNode *pelmCpuIdLeaf;
|
---|
4620 | while ((pelmCpuIdLeaf = nl1.forAllNodes()))
|
---|
4621 | {
|
---|
4622 | CpuIdLeafX86 leaf;
|
---|
4623 |
|
---|
4624 | if (!pelmCpuIdLeaf->getAttributeValue("id", leaf.idx))
|
---|
4625 | throw ConfigFileError(this, pelmCpuIdLeaf, N_("Required CpuIdLeaf/@id attribute is missing"));
|
---|
4626 |
|
---|
4627 | if (!pelmCpuIdLeaf->getAttributeValue("subleaf", leaf.idxSub))
|
---|
4628 | leaf.idxSub = 0;
|
---|
4629 | pelmCpuIdLeaf->getAttributeValue("eax", leaf.uEax);
|
---|
4630 | pelmCpuIdLeaf->getAttributeValue("ebx", leaf.uEbx);
|
---|
4631 | pelmCpuIdLeaf->getAttributeValue("ecx", leaf.uEcx);
|
---|
4632 | pelmCpuIdLeaf->getAttributeValue("edx", leaf.uEdx);
|
---|
4633 |
|
---|
4634 | ll.push_back(leaf);
|
---|
4635 | }
|
---|
4636 | }
|
---|
4637 |
|
---|
4638 | /**
|
---|
4639 | * Called from MachineConfigFile::readHardware() to network information.
|
---|
4640 | * @param elmNetwork
|
---|
4641 | * @param ll
|
---|
4642 | */
|
---|
4643 | void MachineConfigFile::readNetworkAdapters(const xml::ElementNode &elmNetwork,
|
---|
4644 | NetworkAdaptersList &ll)
|
---|
4645 | {
|
---|
4646 | xml::NodesLoop nl1(elmNetwork, "Adapter");
|
---|
4647 | const xml::ElementNode *pelmAdapter;
|
---|
4648 | while ((pelmAdapter = nl1.forAllNodes()))
|
---|
4649 | {
|
---|
4650 | NetworkAdapter nic;
|
---|
4651 |
|
---|
4652 | if (m->sv >= SettingsVersion_v1_16)
|
---|
4653 | {
|
---|
4654 | /* Starting with VirtualBox 5.1 the default is cable connected and
|
---|
4655 | * PCnet-FAST III. Needs to match NetworkAdapter.areDefaultSettings(). */
|
---|
4656 | nic.fCableConnected = true;
|
---|
4657 | nic.type = NetworkAdapterType_Am79C973;
|
---|
4658 | }
|
---|
4659 |
|
---|
4660 | if (!pelmAdapter->getAttributeValue("slot", nic.ulSlot))
|
---|
4661 | throw ConfigFileError(this, pelmAdapter, N_("Required Adapter/@slot attribute is missing"));
|
---|
4662 |
|
---|
4663 | Utf8Str strTemp;
|
---|
4664 | if (pelmAdapter->getAttributeValue("type", strTemp))
|
---|
4665 | {
|
---|
4666 | if (strTemp == "Am79C970A")
|
---|
4667 | nic.type = NetworkAdapterType_Am79C970A;
|
---|
4668 | else if (strTemp == "Am79C973")
|
---|
4669 | nic.type = NetworkAdapterType_Am79C973;
|
---|
4670 | else if (strTemp == "Am79C960")
|
---|
4671 | nic.type = NetworkAdapterType_Am79C960;
|
---|
4672 | else if (strTemp == "82540EM")
|
---|
4673 | nic.type = NetworkAdapterType_I82540EM;
|
---|
4674 | else if (strTemp == "82543GC")
|
---|
4675 | nic.type = NetworkAdapterType_I82543GC;
|
---|
4676 | else if (strTemp == "82545EM")
|
---|
4677 | nic.type = NetworkAdapterType_I82545EM;
|
---|
4678 | else if (strTemp == "virtio")
|
---|
4679 | nic.type = NetworkAdapterType_Virtio;
|
---|
4680 | else if (strTemp == "NE1000")
|
---|
4681 | nic.type = NetworkAdapterType_NE1000;
|
---|
4682 | else if (strTemp == "NE2000")
|
---|
4683 | nic.type = NetworkAdapterType_NE2000;
|
---|
4684 | else if (strTemp == "WD8003")
|
---|
4685 | nic.type = NetworkAdapterType_WD8003;
|
---|
4686 | else if (strTemp == "WD8013")
|
---|
4687 | nic.type = NetworkAdapterType_WD8013;
|
---|
4688 | else if (strTemp == "3C503")
|
---|
4689 | nic.type = NetworkAdapterType_ELNK2;
|
---|
4690 | else if (strTemp == "3C501")
|
---|
4691 | nic.type = NetworkAdapterType_ELNK1;
|
---|
4692 | else
|
---|
4693 | throw ConfigFileError(this, pelmAdapter, N_("Invalid value '%s' in Adapter/@type attribute"), strTemp.c_str());
|
---|
4694 | }
|
---|
4695 |
|
---|
4696 | pelmAdapter->getAttributeValue("enabled", nic.fEnabled);
|
---|
4697 | pelmAdapter->getAttributeValue("MACAddress", nic.strMACAddress);
|
---|
4698 | pelmAdapter->getAttributeValue("cable", nic.fCableConnected);
|
---|
4699 | pelmAdapter->getAttributeValue("speed", nic.ulLineSpeed);
|
---|
4700 |
|
---|
4701 | if (pelmAdapter->getAttributeValue("promiscuousModePolicy", strTemp))
|
---|
4702 | {
|
---|
4703 | if (strTemp == "Deny")
|
---|
4704 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
|
---|
4705 | else if (strTemp == "AllowNetwork")
|
---|
4706 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
|
---|
4707 | else if (strTemp == "AllowAll")
|
---|
4708 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
|
---|
4709 | else
|
---|
4710 | throw ConfigFileError(this, pelmAdapter,
|
---|
4711 | N_("Invalid value '%s' in Adapter/@promiscuousModePolicy attribute"), strTemp.c_str());
|
---|
4712 | }
|
---|
4713 |
|
---|
4714 | pelmAdapter->getAttributeValue("trace", nic.fTraceEnabled);
|
---|
4715 | pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
|
---|
4716 | pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority);
|
---|
4717 | pelmAdapter->getAttributeValue("bandwidthGroup", nic.strBandwidthGroup);
|
---|
4718 |
|
---|
4719 | xml::ElementNodesList llNetworkModes;
|
---|
4720 | pelmAdapter->getChildElements(llNetworkModes);
|
---|
4721 | xml::ElementNodesList::iterator it;
|
---|
4722 | /* We should have only active mode descriptor and disabled modes set */
|
---|
4723 | if (llNetworkModes.size() > 2)
|
---|
4724 | {
|
---|
4725 | throw ConfigFileError(this, pelmAdapter, N_("Invalid number of modes ('%d') attached to Adapter attribute"), llNetworkModes.size());
|
---|
4726 | }
|
---|
4727 | for (it = llNetworkModes.begin(); it != llNetworkModes.end(); ++it)
|
---|
4728 | {
|
---|
4729 | const xml::ElementNode *pelmNode = *it;
|
---|
4730 | if (pelmNode->nameEquals("DisabledModes"))
|
---|
4731 | {
|
---|
4732 | xml::ElementNodesList llDisabledNetworkModes;
|
---|
4733 | xml::ElementNodesList::iterator itDisabled;
|
---|
4734 | pelmNode->getChildElements(llDisabledNetworkModes);
|
---|
4735 | /* run over disabled list and load settings */
|
---|
4736 | for (itDisabled = llDisabledNetworkModes.begin();
|
---|
4737 | itDisabled != llDisabledNetworkModes.end(); ++itDisabled)
|
---|
4738 | {
|
---|
4739 | const xml::ElementNode *pelmDisabledNode = *itDisabled;
|
---|
4740 | readAttachedNetworkMode(*pelmDisabledNode, false, nic);
|
---|
4741 | }
|
---|
4742 | }
|
---|
4743 | else
|
---|
4744 | readAttachedNetworkMode(*pelmNode, true, nic);
|
---|
4745 | }
|
---|
4746 | // else: default is NetworkAttachmentType_Null
|
---|
4747 |
|
---|
4748 | ll.push_back(nic);
|
---|
4749 | }
|
---|
4750 | }
|
---|
4751 |
|
---|
4752 | void MachineConfigFile::readAttachedNetworkMode(const xml::ElementNode &elmMode, bool fEnabled, NetworkAdapter &nic)
|
---|
4753 | {
|
---|
4754 | NetworkAttachmentType_T enmAttachmentType = NetworkAttachmentType_Null;
|
---|
4755 |
|
---|
4756 | if (elmMode.nameEquals("NAT"))
|
---|
4757 | {
|
---|
4758 | enmAttachmentType = NetworkAttachmentType_NAT;
|
---|
4759 |
|
---|
4760 | elmMode.getAttributeValue("network", nic.nat.strNetwork);
|
---|
4761 | elmMode.getAttributeValue("hostip", nic.nat.strBindIP);
|
---|
4762 | elmMode.getAttributeValue("mtu", nic.nat.u32Mtu);
|
---|
4763 | elmMode.getAttributeValue("sockrcv", nic.nat.u32SockRcv);
|
---|
4764 | elmMode.getAttributeValue("socksnd", nic.nat.u32SockSnd);
|
---|
4765 | elmMode.getAttributeValue("tcprcv", nic.nat.u32TcpRcv);
|
---|
4766 | elmMode.getAttributeValue("tcpsnd", nic.nat.u32TcpSnd);
|
---|
4767 | elmMode.getAttributeValue("localhost-reachable", nic.nat.fLocalhostReachable);
|
---|
4768 | const xml::ElementNode *pelmDNS;
|
---|
4769 | if ((pelmDNS = elmMode.findChildElement("DNS")))
|
---|
4770 | {
|
---|
4771 | pelmDNS->getAttributeValue("pass-domain", nic.nat.fDNSPassDomain);
|
---|
4772 | pelmDNS->getAttributeValue("use-proxy", nic.nat.fDNSProxy);
|
---|
4773 | pelmDNS->getAttributeValue("use-host-resolver", nic.nat.fDNSUseHostResolver);
|
---|
4774 | }
|
---|
4775 | const xml::ElementNode *pelmAlias;
|
---|
4776 | if ((pelmAlias = elmMode.findChildElement("Alias")))
|
---|
4777 | {
|
---|
4778 | pelmAlias->getAttributeValue("logging", nic.nat.fAliasLog);
|
---|
4779 | pelmAlias->getAttributeValue("proxy-only", nic.nat.fAliasProxyOnly);
|
---|
4780 | pelmAlias->getAttributeValue("use-same-ports", nic.nat.fAliasUseSamePorts);
|
---|
4781 | }
|
---|
4782 | const xml::ElementNode *pelmTFTP;
|
---|
4783 | if ((pelmTFTP = elmMode.findChildElement("TFTP")))
|
---|
4784 | {
|
---|
4785 | pelmTFTP->getAttributeValue("prefix", nic.nat.strTFTPPrefix);
|
---|
4786 | pelmTFTP->getAttributeValue("boot-file", nic.nat.strTFTPBootFile);
|
---|
4787 | pelmTFTP->getAttributeValue("next-server", nic.nat.strTFTPNextServer);
|
---|
4788 | }
|
---|
4789 |
|
---|
4790 | readNATForwardRulesMap(elmMode, nic.nat.mapRules);
|
---|
4791 | }
|
---|
4792 | else if ( elmMode.nameEquals("HostInterface")
|
---|
4793 | || elmMode.nameEquals("BridgedInterface"))
|
---|
4794 | {
|
---|
4795 | enmAttachmentType = NetworkAttachmentType_Bridged;
|
---|
4796 |
|
---|
4797 | // optional network name, cannot be required or we have trouble with
|
---|
4798 | // settings which are saved before configuring the network name
|
---|
4799 | elmMode.getAttributeValue("name", nic.strBridgedName);
|
---|
4800 | }
|
---|
4801 | else if (elmMode.nameEquals("InternalNetwork"))
|
---|
4802 | {
|
---|
4803 | enmAttachmentType = NetworkAttachmentType_Internal;
|
---|
4804 |
|
---|
4805 | // optional network name, cannot be required or we have trouble with
|
---|
4806 | // settings which are saved before configuring the network name
|
---|
4807 | elmMode.getAttributeValue("name", nic.strInternalNetworkName);
|
---|
4808 | }
|
---|
4809 | else if (elmMode.nameEquals("HostOnlyInterface"))
|
---|
4810 | {
|
---|
4811 | enmAttachmentType = NetworkAttachmentType_HostOnly;
|
---|
4812 |
|
---|
4813 | // optional network name, cannot be required or we have trouble with
|
---|
4814 | // settings which are saved before configuring the network name
|
---|
4815 | elmMode.getAttributeValue("name", nic.strHostOnlyName);
|
---|
4816 | }
|
---|
4817 | #ifdef VBOX_WITH_VMNET
|
---|
4818 | else if (elmMode.nameEquals("HostOnlyNetwork"))
|
---|
4819 | {
|
---|
4820 | enmAttachmentType = NetworkAttachmentType_HostOnlyNetwork;
|
---|
4821 |
|
---|
4822 | // optional network name, cannot be required or we have trouble with
|
---|
4823 | // settings which are saved before configuring the network name
|
---|
4824 | elmMode.getAttributeValue("name", nic.strHostOnlyNetworkName);
|
---|
4825 | }
|
---|
4826 | #endif /* VBOX_WITH_VMNET */
|
---|
4827 | else if (elmMode.nameEquals("GenericInterface"))
|
---|
4828 | {
|
---|
4829 | enmAttachmentType = NetworkAttachmentType_Generic;
|
---|
4830 |
|
---|
4831 | elmMode.getAttributeValue("driver", nic.strGenericDriver); // optional network attachment driver
|
---|
4832 |
|
---|
4833 | // get all properties
|
---|
4834 | xml::NodesLoop nl(elmMode);
|
---|
4835 | const xml::ElementNode *pelmModeChild;
|
---|
4836 | while ((pelmModeChild = nl.forAllNodes()))
|
---|
4837 | {
|
---|
4838 | if (pelmModeChild->nameEquals("Property"))
|
---|
4839 | {
|
---|
4840 | Utf8Str strPropName, strPropValue;
|
---|
4841 | if ( pelmModeChild->getAttributeValue("name", strPropName)
|
---|
4842 | && pelmModeChild->getAttributeValue("value", strPropValue) )
|
---|
4843 | nic.genericProperties[strPropName] = strPropValue;
|
---|
4844 | else
|
---|
4845 | throw ConfigFileError(this, pelmModeChild, N_("Required GenericInterface/Property/@name or @value attribute is missing"));
|
---|
4846 | }
|
---|
4847 | }
|
---|
4848 | }
|
---|
4849 | else if (elmMode.nameEquals("NATNetwork"))
|
---|
4850 | {
|
---|
4851 | enmAttachmentType = NetworkAttachmentType_NATNetwork;
|
---|
4852 |
|
---|
4853 | // optional network name, cannot be required or we have trouble with
|
---|
4854 | // settings which are saved before configuring the network name
|
---|
4855 | elmMode.getAttributeValue("name", nic.strNATNetworkName);
|
---|
4856 | }
|
---|
4857 | else if (elmMode.nameEquals("VDE"))
|
---|
4858 | {
|
---|
4859 | // inofficial hack (VDE networking was never part of the official
|
---|
4860 | // settings, so it's not mentioned in VirtualBox-settings.xsd)
|
---|
4861 | enmAttachmentType = NetworkAttachmentType_Generic;
|
---|
4862 |
|
---|
4863 | com::Utf8Str strVDEName;
|
---|
4864 | elmMode.getAttributeValue("network", strVDEName); // optional network name
|
---|
4865 | nic.strGenericDriver = "VDE";
|
---|
4866 | nic.genericProperties["network"] = strVDEName;
|
---|
4867 | }
|
---|
4868 | #ifdef VBOX_WITH_VMNET
|
---|
4869 | else if (elmMode.nameEquals("HostOnlyNetwork"))
|
---|
4870 | {
|
---|
4871 | enmAttachmentType = NetworkAttachmentType_HostOnly;
|
---|
4872 |
|
---|
4873 | // optional network name, cannot be required or we have trouble with
|
---|
4874 | // settings which are saved before configuring the network name
|
---|
4875 | elmMode.getAttributeValue("name", nic.strHostOnlyNetworkName);
|
---|
4876 | }
|
---|
4877 | #endif /* VBOX_WITH_VMNET */
|
---|
4878 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
4879 | else if (elmMode.nameEquals("CloudNetwork"))
|
---|
4880 | {
|
---|
4881 | enmAttachmentType = NetworkAttachmentType_Cloud;
|
---|
4882 |
|
---|
4883 | // optional network name, cannot be required or we have trouble with
|
---|
4884 | // settings which are saved before configuring the network name
|
---|
4885 | elmMode.getAttributeValue("name", nic.strCloudNetworkName);
|
---|
4886 | }
|
---|
4887 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
4888 |
|
---|
4889 | if (fEnabled && enmAttachmentType != NetworkAttachmentType_Null)
|
---|
4890 | nic.mode = enmAttachmentType;
|
---|
4891 | }
|
---|
4892 |
|
---|
4893 | /**
|
---|
4894 | * Called from MachineConfigFile::readHardware() to read serial port information.
|
---|
4895 | * @param elmUART
|
---|
4896 | * @param ll
|
---|
4897 | */
|
---|
4898 | void MachineConfigFile::readSerialPorts(const xml::ElementNode &elmUART,
|
---|
4899 | SerialPortsList &ll)
|
---|
4900 | {
|
---|
4901 | xml::NodesLoop nl1(elmUART, "Port");
|
---|
4902 | const xml::ElementNode *pelmPort;
|
---|
4903 | while ((pelmPort = nl1.forAllNodes()))
|
---|
4904 | {
|
---|
4905 | SerialPort port;
|
---|
4906 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
4907 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@slot attribute is missing"));
|
---|
4908 |
|
---|
4909 | // slot must be unique
|
---|
4910 | for (SerialPortsList::const_iterator it = ll.begin();
|
---|
4911 | it != ll.end();
|
---|
4912 | ++it)
|
---|
4913 | if ((*it).ulSlot == port.ulSlot)
|
---|
4914 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in UART/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
4915 |
|
---|
4916 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
4917 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@enabled attribute is missing"));
|
---|
4918 | if (m->sv >= SettingsVersion_v1_20) /* IOBase was changed to IOAddress since settings v1.20. */
|
---|
4919 | {
|
---|
4920 | if (!pelmPort->getAttributeValue("IOAddress", port.ulIOAddress))
|
---|
4921 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IOAddress attribute is missing"));
|
---|
4922 | }
|
---|
4923 | else /* Settings < v1.20. */
|
---|
4924 | {
|
---|
4925 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOAddress))
|
---|
4926 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IOBase attribute is missing"));
|
---|
4927 | }
|
---|
4928 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
4929 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IRQ attribute is missing"));
|
---|
4930 |
|
---|
4931 | Utf8Str strPortMode;
|
---|
4932 | if (!pelmPort->getAttributeValue("hostMode", strPortMode))
|
---|
4933 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@hostMode attribute is missing"));
|
---|
4934 | if (strPortMode == "RawFile")
|
---|
4935 | port.portMode = PortMode_RawFile;
|
---|
4936 | else if (strPortMode == "HostPipe")
|
---|
4937 | port.portMode = PortMode_HostPipe;
|
---|
4938 | else if (strPortMode == "HostDevice")
|
---|
4939 | port.portMode = PortMode_HostDevice;
|
---|
4940 | else if (strPortMode == "Disconnected")
|
---|
4941 | port.portMode = PortMode_Disconnected;
|
---|
4942 | else if (strPortMode == "TCP")
|
---|
4943 | port.portMode = PortMode_TCP;
|
---|
4944 | else
|
---|
4945 | throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
|
---|
4946 |
|
---|
4947 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
4948 | pelmPort->getAttributeValue("server", port.fServer);
|
---|
4949 |
|
---|
4950 | Utf8Str strUartType;
|
---|
4951 | if (pelmPort->getAttributeValue("uartType", strUartType))
|
---|
4952 | {
|
---|
4953 | if (strUartType == "16450")
|
---|
4954 | port.uartType = UartType_U16450;
|
---|
4955 | else if (strUartType == "16550A")
|
---|
4956 | port.uartType = UartType_U16550A;
|
---|
4957 | else if (strUartType == "16750")
|
---|
4958 | port.uartType = UartType_U16750;
|
---|
4959 | else
|
---|
4960 | throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@uartType attribute"), strUartType.c_str());
|
---|
4961 | }
|
---|
4962 |
|
---|
4963 | ll.push_back(port);
|
---|
4964 | }
|
---|
4965 | }
|
---|
4966 |
|
---|
4967 | /**
|
---|
4968 | * Called from MachineConfigFile::readHardware() to read parallel port information.
|
---|
4969 | * @param elmLPT
|
---|
4970 | * @param ll
|
---|
4971 | */
|
---|
4972 | void MachineConfigFile::readParallelPorts(const xml::ElementNode &elmLPT,
|
---|
4973 | ParallelPortsList &ll)
|
---|
4974 | {
|
---|
4975 | xml::NodesLoop nl1(elmLPT, "Port");
|
---|
4976 | const xml::ElementNode *pelmPort;
|
---|
4977 | while ((pelmPort = nl1.forAllNodes()))
|
---|
4978 | {
|
---|
4979 | ParallelPort port;
|
---|
4980 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
4981 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@slot attribute is missing"));
|
---|
4982 |
|
---|
4983 | // slot must be unique
|
---|
4984 | for (ParallelPortsList::const_iterator it = ll.begin();
|
---|
4985 | it != ll.end();
|
---|
4986 | ++it)
|
---|
4987 | if ((*it).ulSlot == port.ulSlot)
|
---|
4988 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in LPT/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
4989 |
|
---|
4990 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
4991 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@enabled attribute is missing"));
|
---|
4992 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
4993 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IOBase attribute is missing"));
|
---|
4994 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
4995 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IRQ attribute is missing"));
|
---|
4996 |
|
---|
4997 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
4998 |
|
---|
4999 | ll.push_back(port);
|
---|
5000 | }
|
---|
5001 | }
|
---|
5002 |
|
---|
5003 | /**
|
---|
5004 | * Called from MachineConfigFile::readHardware() to read audio adapter information
|
---|
5005 | * and maybe fix driver information depending on the current host hardware.
|
---|
5006 | *
|
---|
5007 | * @param elmAudioAdapter "AudioAdapter" XML element.
|
---|
5008 | * @param aa
|
---|
5009 | */
|
---|
5010 | void MachineConfigFile::readAudioAdapter(const xml::ElementNode &elmAudioAdapter,
|
---|
5011 | AudioAdapter &aa)
|
---|
5012 | {
|
---|
5013 | if (m->sv >= SettingsVersion_v1_15)
|
---|
5014 | {
|
---|
5015 | // get all properties
|
---|
5016 | xml::NodesLoop nl1(elmAudioAdapter, "Property");
|
---|
5017 | const xml::ElementNode *pelmModeChild;
|
---|
5018 | while ((pelmModeChild = nl1.forAllNodes()))
|
---|
5019 | {
|
---|
5020 | Utf8Str strPropName, strPropValue;
|
---|
5021 | if ( pelmModeChild->getAttributeValue("name", strPropName)
|
---|
5022 | && pelmModeChild->getAttributeValue("value", strPropValue) )
|
---|
5023 | aa.properties[strPropName] = strPropValue;
|
---|
5024 | else
|
---|
5025 | throw ConfigFileError(this, pelmModeChild, N_("Required AudioAdapter/Property/@name or @value attribute "
|
---|
5026 | "is missing"));
|
---|
5027 | }
|
---|
5028 | }
|
---|
5029 |
|
---|
5030 | elmAudioAdapter.getAttributeValue("enabled", aa.fEnabled);
|
---|
5031 | elmAudioAdapter.getAttributeValue("enabledIn", aa.fEnabledIn);
|
---|
5032 | elmAudioAdapter.getAttributeValue("enabledOut", aa.fEnabledOut);
|
---|
5033 |
|
---|
5034 | Utf8Str strTemp;
|
---|
5035 | if (elmAudioAdapter.getAttributeValue("controller", strTemp))
|
---|
5036 | {
|
---|
5037 | if (strTemp == "SB16")
|
---|
5038 | aa.controllerType = AudioControllerType_SB16;
|
---|
5039 | else if (strTemp == "AC97")
|
---|
5040 | aa.controllerType = AudioControllerType_AC97;
|
---|
5041 | else if (strTemp == "HDA")
|
---|
5042 | aa.controllerType = AudioControllerType_HDA;
|
---|
5043 | else if (strTemp == "Virtio-Sound")
|
---|
5044 | aa.controllerType = AudioControllerType_VirtioSound;
|
---|
5045 | else
|
---|
5046 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
|
---|
5047 | }
|
---|
5048 |
|
---|
5049 | if (elmAudioAdapter.getAttributeValue("codec", strTemp))
|
---|
5050 | {
|
---|
5051 | if (strTemp == "SB16")
|
---|
5052 | aa.codecType = AudioCodecType_SB16;
|
---|
5053 | else if (strTemp == "STAC9700")
|
---|
5054 | aa.codecType = AudioCodecType_STAC9700;
|
---|
5055 | else if (strTemp == "AD1980")
|
---|
5056 | aa.codecType = AudioCodecType_AD1980;
|
---|
5057 | else if (strTemp == "STAC9221")
|
---|
5058 | aa.codecType = AudioCodecType_STAC9221;
|
---|
5059 | else
|
---|
5060 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@codec attribute"), strTemp.c_str());
|
---|
5061 | }
|
---|
5062 | else
|
---|
5063 | {
|
---|
5064 | /* No codec attribute provided; use defaults. */
|
---|
5065 | switch (aa.controllerType)
|
---|
5066 | {
|
---|
5067 | case AudioControllerType_AC97:
|
---|
5068 | aa.codecType = AudioCodecType_STAC9700;
|
---|
5069 | break;
|
---|
5070 | case AudioControllerType_SB16:
|
---|
5071 | aa.codecType = AudioCodecType_SB16;
|
---|
5072 | break;
|
---|
5073 | case AudioControllerType_HDA:
|
---|
5074 | aa.codecType = AudioCodecType_STAC9221;
|
---|
5075 | break;
|
---|
5076 | case AudioControllerType_VirtioSound:
|
---|
5077 | aa.codecType = AudioCodecType_Null;
|
---|
5078 | break;
|
---|
5079 | default:
|
---|
5080 | Assert(false); /* We just checked the controller type above. */
|
---|
5081 | }
|
---|
5082 | }
|
---|
5083 |
|
---|
5084 | if (elmAudioAdapter.getAttributeValue("driver", strTemp))
|
---|
5085 | {
|
---|
5086 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
5087 | strTemp.toUpper();
|
---|
5088 | if (strTemp == "DEFAULT") /* Keep this to be backwards compatible for settings < r152556. */
|
---|
5089 | aa.driverType = AudioDriverType_Default;
|
---|
5090 | else if (strTemp == "NULL")
|
---|
5091 | aa.driverType = AudioDriverType_Null;
|
---|
5092 | else if (strTemp == "WAS")
|
---|
5093 | aa.driverType = AudioDriverType_WAS;
|
---|
5094 | else if (strTemp == "WINMM")
|
---|
5095 | aa.driverType = AudioDriverType_WinMM;
|
---|
5096 | else if ( (strTemp == "DIRECTSOUND") || (strTemp == "DSOUND") )
|
---|
5097 | aa.driverType = AudioDriverType_DirectSound;
|
---|
5098 | else if (strTemp == "SOLAUDIO") /* Deprecated -- Solaris will use OSS by default now. */
|
---|
5099 | aa.driverType = AudioDriverType_SolAudio;
|
---|
5100 | else if (strTemp == "ALSA")
|
---|
5101 | aa.driverType = AudioDriverType_ALSA;
|
---|
5102 | else if (strTemp == "PULSE")
|
---|
5103 | aa.driverType = AudioDriverType_Pulse;
|
---|
5104 | else if (strTemp == "OSS")
|
---|
5105 | aa.driverType = AudioDriverType_OSS;
|
---|
5106 | else if (strTemp == "COREAUDIO")
|
---|
5107 | aa.driverType = AudioDriverType_CoreAudio;
|
---|
5108 | else if (strTemp == "MMPM") /* Deprecated; only kept for backwards compatibility. */
|
---|
5109 | aa.driverType = AudioDriverType_MMPM;
|
---|
5110 | else
|
---|
5111 | {
|
---|
5112 | /* Be nice when loading the settings on downgraded versions: In case the selected backend isn't available / known
|
---|
5113 | * to this version, fall back to the default backend, telling the user in the release log. See @bugref{10051c7}. */
|
---|
5114 | LogRel(("WARNING: Invalid value '%s' in AudioAdapter/@driver attribute found; falling back to default audio backend\n",
|
---|
5115 | strTemp.c_str()));
|
---|
5116 | aa.driverType = AudioDriverType_Default;
|
---|
5117 | }
|
---|
5118 |
|
---|
5119 | /* When loading settings >= 1.19 (VBox 7.0), the attribute "useDefault" will determine if the VM should use
|
---|
5120 | * the OS' default audio driver or not. This additional attribute is necessary in order to be backwards compatible
|
---|
5121 | * with older VBox versions. */
|
---|
5122 | bool fUseDefault = false;
|
---|
5123 | if ( elmAudioAdapter.getAttributeValue("useDefault", &fUseDefault) /* Overrides "driver" above (if set). */
|
---|
5124 | && fUseDefault)
|
---|
5125 | aa.driverType = AudioDriverType_Default;
|
---|
5126 |
|
---|
5127 | // now check if this is actually supported on the current host platform;
|
---|
5128 | // people might be opening a file created on a Windows host, and that
|
---|
5129 | // VM should still start on a Linux host
|
---|
5130 | if (!isAudioDriverAllowedOnThisHost(aa.driverType))
|
---|
5131 | aa.driverType = getHostDefaultAudioDriver();
|
---|
5132 | }
|
---|
5133 | }
|
---|
5134 |
|
---|
5135 | /**
|
---|
5136 | * Called from MachineConfigFile::readHardware() to read guest property information.
|
---|
5137 | * @param elmGuestProperties
|
---|
5138 | * @param hw
|
---|
5139 | */
|
---|
5140 | void MachineConfigFile::readGuestProperties(const xml::ElementNode &elmGuestProperties,
|
---|
5141 | Hardware &hw)
|
---|
5142 | {
|
---|
5143 | xml::NodesLoop nl1(elmGuestProperties, "GuestProperty");
|
---|
5144 | const xml::ElementNode *pelmProp;
|
---|
5145 | while ((pelmProp = nl1.forAllNodes()))
|
---|
5146 | {
|
---|
5147 | GuestProperty prop;
|
---|
5148 |
|
---|
5149 | pelmProp->getAttributeValue("name", prop.strName);
|
---|
5150 | pelmProp->getAttributeValue("value", prop.strValue);
|
---|
5151 |
|
---|
5152 | pelmProp->getAttributeValue("timestamp", prop.timestamp);
|
---|
5153 | pelmProp->getAttributeValue("flags", prop.strFlags);
|
---|
5154 |
|
---|
5155 | /* Check guest property 'name' and 'value' for correctness before
|
---|
5156 | * placing it to local cache. */
|
---|
5157 |
|
---|
5158 | int vrc = GuestPropValidateName(prop.strName.c_str(), prop.strName.length() + 1 /* '\0' */);
|
---|
5159 | if (RT_FAILURE(vrc))
|
---|
5160 | {
|
---|
5161 | LogRel(("WARNING: Guest property with invalid name (%s) present in VM configuration file. Guest property will be dropped.\n",
|
---|
5162 | prop.strName.c_str()));
|
---|
5163 | continue;
|
---|
5164 | }
|
---|
5165 |
|
---|
5166 | vrc = GuestPropValidateValue(prop.strValue.c_str(), prop.strValue.length() + 1 /* '\0' */);
|
---|
5167 | if (vrc == VERR_TOO_MUCH_DATA)
|
---|
5168 | {
|
---|
5169 | LogRel(("WARNING: Guest property '%s' present in VM configuration file and has too long value. Guest property value will be truncated.\n",
|
---|
5170 | prop.strName.c_str()));
|
---|
5171 |
|
---|
5172 | /* In order to pass validation, guest property value length (including '\0') in bytes
|
---|
5173 | * should be less than GUEST_PROP_MAX_VALUE_LEN. Chop it down to an appropriate length. */
|
---|
5174 | prop.strValue.truncate(GUEST_PROP_MAX_VALUE_LEN - 1 /*terminator*/);
|
---|
5175 | }
|
---|
5176 | else if (RT_FAILURE(vrc))
|
---|
5177 | {
|
---|
5178 | LogRel(("WARNING: Guest property '%s' present in VM configuration file and has invalid value. Guest property will be dropped.\n",
|
---|
5179 | prop.strName.c_str()));
|
---|
5180 | continue;
|
---|
5181 | }
|
---|
5182 |
|
---|
5183 | hw.llGuestProperties.push_back(prop);
|
---|
5184 | }
|
---|
5185 | }
|
---|
5186 |
|
---|
5187 | /**
|
---|
5188 | * Helper function to read attributes that are common to \<SATAController\> (pre-1.7)
|
---|
5189 | * and \<StorageController\>.
|
---|
5190 | * @param elmStorageController
|
---|
5191 | * @param sctl
|
---|
5192 | */
|
---|
5193 | void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
|
---|
5194 | StorageController &sctl)
|
---|
5195 | {
|
---|
5196 | elmStorageController.getAttributeValue("PortCount", sctl.ulPortCount);
|
---|
5197 | elmStorageController.getAttributeValue("useHostIOCache", sctl.fUseHostIOCache);
|
---|
5198 | }
|
---|
5199 |
|
---|
5200 | /**
|
---|
5201 | * Reads the x86 CPUID tree.
|
---|
5202 | *
|
---|
5203 | * For settings >= v1.20 these were stored under the "Platform/x86/CPU" node.
|
---|
5204 | * For settings < v1.20 these were stored under the "Hardware/CPU" node.
|
---|
5205 | *
|
---|
5206 | * @param elmPlatformOrHardware Platform or Hardware node to read from.
|
---|
5207 | * @param platX86 Where to store the platform settings.
|
---|
5208 | */
|
---|
5209 | void MachineConfigFile::readPlatformCPUIDTreeX86(const xml::ElementNode &elmPlatformOrHardware,
|
---|
5210 | PlatformX86 &platX86)
|
---|
5211 | {
|
---|
5212 | const xml::ElementNode *pelmCPUChild;
|
---|
5213 | if ((pelmCPUChild = elmPlatformOrHardware.findChildElement("CpuIdTree")))
|
---|
5214 | readCpuIdTreeX86(*pelmCPUChild, platX86.llCpuIdLeafs);
|
---|
5215 | }
|
---|
5216 |
|
---|
5217 | /**
|
---|
5218 | * Reads the x86 platform settings.
|
---|
5219 | *
|
---|
5220 | * For settings >= v1.20 these were stored under the "Platform/x86" node.
|
---|
5221 | * For settings < v1.20 these were stored under the "Hardware" node.
|
---|
5222 | *
|
---|
5223 | * @param elmPlatformX86OrHardware Platform/x86 or Hardware node to read from.
|
---|
5224 | * @param platX86 Where to store the x86 platform settings.
|
---|
5225 | */
|
---|
5226 | void MachineConfigFile::readPlatformX86(const xml::ElementNode &elmPlatformX86OrHardware,
|
---|
5227 | PlatformX86 &platX86)
|
---|
5228 | {
|
---|
5229 | xml::NodesLoop nl1(elmPlatformX86OrHardware);
|
---|
5230 |
|
---|
5231 | const xml::ElementNode *pelChild;
|
---|
5232 | while ((pelChild = nl1.forAllNodes()))
|
---|
5233 | {
|
---|
5234 | if (pelChild->nameEquals("HPET"))
|
---|
5235 | {
|
---|
5236 | pelChild->getAttributeValue("enabled", platX86.fHPETEnabled);
|
---|
5237 | }
|
---|
5238 | else if (pelChild->nameEquals("CPU"))
|
---|
5239 | {
|
---|
5240 | const xml::ElementNode *pelmCPUChild;
|
---|
5241 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtEx")))
|
---|
5242 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtEx);
|
---|
5243 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtExNestedPaging")))
|
---|
5244 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExNestedPaging);
|
---|
5245 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtExLargePages")))
|
---|
5246 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExLargePages);
|
---|
5247 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtExVPID")))
|
---|
5248 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExVPID);
|
---|
5249 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtExUX")))
|
---|
5250 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExUX);
|
---|
5251 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtForce")))
|
---|
5252 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExForce);
|
---|
5253 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtExUseNativeApi")))
|
---|
5254 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExUseNativeApi);
|
---|
5255 | if ((pelmCPUChild = pelChild->findChildElement("HardwareVirtExVirtVmsaveVmload")))
|
---|
5256 | pelmCPUChild->getAttributeValue("enabled", platX86.fHWVirtExVirtVmsaveVmload);
|
---|
5257 |
|
---|
5258 | if (!(pelmCPUChild = pelChild->findChildElement("PAE")))
|
---|
5259 | {
|
---|
5260 | /* The default for pre 3.1 was false, so we must respect that. */
|
---|
5261 | if (m->sv < SettingsVersion_v1_9)
|
---|
5262 | platX86.fPAE = false;
|
---|
5263 | }
|
---|
5264 | else
|
---|
5265 | pelmCPUChild->getAttributeValue("enabled", platX86.fPAE);
|
---|
5266 |
|
---|
5267 | bool fLongMode;
|
---|
5268 | if ( (pelmCPUChild = pelChild->findChildElement("LongMode"))
|
---|
5269 | && pelmCPUChild->getAttributeValue("enabled", fLongMode) )
|
---|
5270 | platX86.enmLongMode = fLongMode ? PlatformX86::LongMode_Enabled : PlatformX86::LongMode_Disabled;
|
---|
5271 | else
|
---|
5272 | platX86.enmLongMode = PlatformX86::LongMode_Legacy;
|
---|
5273 |
|
---|
5274 | if ((pelmCPUChild = pelChild->findChildElement("TripleFaultReset")))
|
---|
5275 | pelmCPUChild->getAttributeValue("enabled", platX86.fTripleFaultReset);
|
---|
5276 | if ((pelmCPUChild = pelChild->findChildElement("APIC")))
|
---|
5277 | pelmCPUChild->getAttributeValue("enabled", platX86.fAPIC);
|
---|
5278 | if ((pelmCPUChild = pelChild->findChildElement("X2APIC")))
|
---|
5279 | pelmCPUChild->getAttributeValue("enabled", platX86.fX2APIC);
|
---|
5280 |
|
---|
5281 | if ((pelmCPUChild = pelChild->findChildElement("IBPBOn")))
|
---|
5282 | {
|
---|
5283 | pelmCPUChild->getAttributeValue("vmexit", platX86.fIBPBOnVMExit);
|
---|
5284 | pelmCPUChild->getAttributeValue("vmentry", platX86.fIBPBOnVMEntry);
|
---|
5285 | }
|
---|
5286 | if ((pelmCPUChild = pelChild->findChildElement("SpecCtrl")))
|
---|
5287 | pelmCPUChild->getAttributeValue("enabled", platX86.fSpecCtrl);
|
---|
5288 | if ((pelmCPUChild = pelChild->findChildElement("SpecCtrlByHost")))
|
---|
5289 | pelmCPUChild->getAttributeValue("enabled", platX86.fSpecCtrlByHost);
|
---|
5290 | if ((pelmCPUChild = pelChild->findChildElement("L1DFlushOn")))
|
---|
5291 | {
|
---|
5292 | pelmCPUChild->getAttributeValue("scheduling", platX86.fL1DFlushOnSched);
|
---|
5293 | pelmCPUChild->getAttributeValue("vmentry", platX86.fL1DFlushOnVMEntry);
|
---|
5294 | }
|
---|
5295 | if ((pelmCPUChild = pelChild->findChildElement("MDSClearOn")))
|
---|
5296 | {
|
---|
5297 | pelmCPUChild->getAttributeValue("scheduling", platX86.fMDSClearOnSched);
|
---|
5298 | pelmCPUChild->getAttributeValue("vmentry", platX86.fMDSClearOnVMEntry);
|
---|
5299 | }
|
---|
5300 | if ((pelmCPUChild = pelChild->findChildElement("NestedHWVirt")))
|
---|
5301 | pelmCPUChild->getAttributeValue("enabled", platX86.fNestedHWVirt);
|
---|
5302 |
|
---|
5303 | readPlatformCPUIDTreeX86(*pelChild, platX86);
|
---|
5304 | }
|
---|
5305 | }
|
---|
5306 | }
|
---|
5307 |
|
---|
5308 | /**
|
---|
5309 | * Reads the platform settings.
|
---|
5310 | *
|
---|
5311 | * For settings >= v1.20 (>= VirtualBox 7.1) these were stored under the "Platform" node.
|
---|
5312 | * For settings < v1.20 (<= VirtualBox 7.0) these were stored under the "Hardware" node.
|
---|
5313 | *
|
---|
5314 | * @param elmPlatformOrHardware Platform or Hardware node to read from.
|
---|
5315 | * @param hw Where to store the hardware settings.
|
---|
5316 | * @param plat Where to store the platform settings.
|
---|
5317 | */
|
---|
5318 | void MachineConfigFile::readPlatform(const xml::ElementNode &elmPlatformOrHardware,
|
---|
5319 | Hardware &hw, Platform &plat)
|
---|
5320 | {
|
---|
5321 | /*
|
---|
5322 | * Platform-generic stuff.
|
---|
5323 | */
|
---|
5324 | xml::NodesLoop nl1(elmPlatformOrHardware);
|
---|
5325 | const xml::ElementNode *pelmChild;
|
---|
5326 | while ((pelmChild = nl1.forAllNodes()))
|
---|
5327 | {
|
---|
5328 | if (pelmChild->nameEquals("CPU"))
|
---|
5329 | {
|
---|
5330 | if (!pelmChild->getAttributeValue("count", hw.cCPUs))
|
---|
5331 | {
|
---|
5332 | // pre-1.5 variant; not sure if this actually exists in the wild anywhere
|
---|
5333 | const xml::ElementNode *pelmCPUChild;
|
---|
5334 | if ((pelmCPUChild = pelmChild->findChildElement("CPUCount")))
|
---|
5335 | pelmCPUChild->getAttributeValue("count", hw.cCPUs);
|
---|
5336 | }
|
---|
5337 |
|
---|
5338 | pelmChild->getAttributeValue("hotplug", hw.fCpuHotPlug);
|
---|
5339 | pelmChild->getAttributeValue("executionCap", hw.ulCpuExecutionCap);
|
---|
5340 |
|
---|
5341 | const xml::ElementNode *pelmCPUChild;
|
---|
5342 | if (hw.fCpuHotPlug)
|
---|
5343 | {
|
---|
5344 | if ((pelmCPUChild = pelmChild->findChildElement("CpuTree")))
|
---|
5345 | readCpuTree(*pelmCPUChild, hw.llCpus);
|
---|
5346 | }
|
---|
5347 |
|
---|
5348 | if ((pelmCPUChild = pelmChild->findChildElement("SyntheticCpu")))
|
---|
5349 | {
|
---|
5350 | bool fSyntheticCpu = false;
|
---|
5351 | pelmCPUChild->getAttributeValue("enabled", fSyntheticCpu);
|
---|
5352 | hw.uCpuIdPortabilityLevel = fSyntheticCpu ? 1 : 0;
|
---|
5353 | }
|
---|
5354 | pelmChild->getAttributeValue("CpuIdPortabilityLevel", hw.uCpuIdPortabilityLevel);
|
---|
5355 | pelmChild->getAttributeValue("CpuProfile", hw.strCpuProfile);
|
---|
5356 | }
|
---|
5357 | else if (pelmChild->nameEquals("Chipset"))
|
---|
5358 | {
|
---|
5359 | Utf8Str strChipsetType;
|
---|
5360 | if (pelmChild->getAttributeValue("type", strChipsetType))
|
---|
5361 | {
|
---|
5362 | if (strChipsetType == "PIIX3")
|
---|
5363 | plat.chipsetType = ChipsetType_PIIX3;
|
---|
5364 | else if (strChipsetType == "ICH9")
|
---|
5365 | plat.chipsetType = ChipsetType_ICH9;
|
---|
5366 | else if (strChipsetType == "ARMv8Virtual")
|
---|
5367 | plat.chipsetType = ChipsetType_ARMv8Virtual;
|
---|
5368 | else
|
---|
5369 | throw ConfigFileError(this,
|
---|
5370 | pelmChild,
|
---|
5371 | N_("Invalid value '%s' in Chipset/@type"),
|
---|
5372 | strChipsetType.c_str());
|
---|
5373 | }
|
---|
5374 | }
|
---|
5375 | else if (pelmChild->nameEquals("Iommu"))
|
---|
5376 | {
|
---|
5377 | Utf8Str strIommuType;
|
---|
5378 | if (pelmChild->getAttributeValue("type", strIommuType))
|
---|
5379 | {
|
---|
5380 | if (strIommuType == "None")
|
---|
5381 | plat.iommuType = IommuType_None;
|
---|
5382 | else if (strIommuType == "Automatic")
|
---|
5383 | plat.iommuType = IommuType_Automatic;
|
---|
5384 | else if (strIommuType == "AMD")
|
---|
5385 | plat.iommuType = IommuType_AMD;
|
---|
5386 | else if (strIommuType == "Intel")
|
---|
5387 | plat.iommuType = IommuType_Intel;
|
---|
5388 | else
|
---|
5389 | throw ConfigFileError(this,
|
---|
5390 | pelmChild,
|
---|
5391 | N_("Invalid value '%s' in Iommu/@type"),
|
---|
5392 | strIommuType.c_str());
|
---|
5393 | }
|
---|
5394 | }
|
---|
5395 | else if (pelmChild->nameEquals("RTC"))
|
---|
5396 | {
|
---|
5397 | Utf8Str strLocalOrUTC;
|
---|
5398 | plat.fRTCUseUTC = pelmChild->getAttributeValue("localOrUTC", strLocalOrUTC)
|
---|
5399 | && strLocalOrUTC == "UTC";
|
---|
5400 | }
|
---|
5401 | }
|
---|
5402 |
|
---|
5403 | if (m->sv >= SettingsVersion_v1_20) /* Settings v1.20 introduced platform architecture support. */
|
---|
5404 | {
|
---|
5405 | Utf8Str strArch;
|
---|
5406 | if (elmPlatformOrHardware.getAttributeValue("architecture", strArch))
|
---|
5407 | {
|
---|
5408 | if (strArch.equalsIgnoreCase("x86"))
|
---|
5409 | plat.architectureType = PlatformArchitecture_x86;
|
---|
5410 | else if (strArch.equalsIgnoreCase("ARM"))
|
---|
5411 | plat.architectureType = PlatformArchitecture_ARM;
|
---|
5412 | else
|
---|
5413 | throw ConfigFileError(this,
|
---|
5414 | &elmPlatformOrHardware,
|
---|
5415 | N_("Platform/@architecture '%s' invalid"), strArch.c_str());
|
---|
5416 | }
|
---|
5417 | else
|
---|
5418 | throw ConfigFileError(this, &elmPlatformOrHardware, N_("Platform/@architecture missing"));
|
---|
5419 | }
|
---|
5420 |
|
---|
5421 | /*
|
---|
5422 | * Platform-specific stuff.
|
---|
5423 | */
|
---|
5424 | switch (plat.architectureType)
|
---|
5425 | {
|
---|
5426 | case PlatformArchitecture_x86:
|
---|
5427 | {
|
---|
5428 | const xml::ElementNode *pelmPlatformX86OrHardware;
|
---|
5429 | if (m->sv >= SettingsVersion_v1_20) /* Settings v1.20 introduced platform support with a x86 sub node. */
|
---|
5430 | {
|
---|
5431 | pelmPlatformX86OrHardware = elmPlatformOrHardware.findChildElement("x86");
|
---|
5432 | if (!pelmPlatformX86OrHardware)
|
---|
5433 | throw ConfigFileError(this, &elmPlatformOrHardware, N_("Required Platform/@x86 element is missing"));
|
---|
5434 | }
|
---|
5435 | else /* For settings < v1.20 we stored everyhing in the Hardware node. */
|
---|
5436 | pelmPlatformX86OrHardware = &elmPlatformOrHardware;
|
---|
5437 |
|
---|
5438 | readPlatformX86(*pelmPlatformX86OrHardware, plat.x86);
|
---|
5439 | break;
|
---|
5440 | }
|
---|
5441 |
|
---|
5442 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
5443 | case PlatformArchitecture_ARM:
|
---|
5444 | {
|
---|
5445 | /* Nothing here yet -- add ARM-specific stuff as soon as we have it. */
|
---|
5446 | break;
|
---|
5447 | }
|
---|
5448 | #endif
|
---|
5449 | default:
|
---|
5450 | break;
|
---|
5451 | }
|
---|
5452 | }
|
---|
5453 |
|
---|
5454 | /**
|
---|
5455 | * Reads in a \<Hardware\> block and stores it in the given structure. Used
|
---|
5456 | * both directly from readMachine and from readSnapshot, since snapshots
|
---|
5457 | * have their own hardware sections.
|
---|
5458 | *
|
---|
5459 | * For legacy pre-1.7 settings we also need a storage structure because
|
---|
5460 | * the IDE and SATA controllers used to be defined under \<Hardware\>.
|
---|
5461 | *
|
---|
5462 | * @param elmHardware Hardware node to read from.
|
---|
5463 | * @param hw Where to store the hardware settings.
|
---|
5464 | */
|
---|
5465 | void MachineConfigFile::readHardware(const xml::ElementNode &elmHardware,
|
---|
5466 | Hardware &hw)
|
---|
5467 | {
|
---|
5468 | if (m->sv >= SettingsVersion_v1_16)
|
---|
5469 | {
|
---|
5470 | /* Starting with VirtualBox 5.1 the default is Default, before it was
|
---|
5471 | * Legacy. This needs to matched by areParavirtDefaultSettings(). */
|
---|
5472 | hw.paravirtProvider = ParavirtProvider_Default;
|
---|
5473 | /* The new default is disabled, before it was enabled by default. */
|
---|
5474 | hw.vrdeSettings.fEnabled = false;
|
---|
5475 | /* The new default is disabled, before it was enabled by default. */
|
---|
5476 | hw.audioAdapter.fEnabled = false;
|
---|
5477 | }
|
---|
5478 |
|
---|
5479 | if (m->sv >= SettingsVersion_v1_17)
|
---|
5480 | {
|
---|
5481 | /* Starting with VirtualBox 5.2 the default is disabled, before it was
|
---|
5482 | * enabled. This needs to matched by AudioAdapter::areDefaultSettings(). */
|
---|
5483 | hw.audioAdapter.fEnabledIn = false;
|
---|
5484 | /* The new default is disabled, before it was enabled by default. */
|
---|
5485 | hw.audioAdapter.fEnabledOut = false;
|
---|
5486 | }
|
---|
5487 |
|
---|
5488 | if (!elmHardware.getAttributeValue("version", hw.strVersion))
|
---|
5489 | {
|
---|
5490 | /* KLUDGE ALERT! For a while during the 3.1 development this was not
|
---|
5491 | written because it was thought to have a default value of "2". For
|
---|
5492 | sv <= 1.3 it defaults to "1" because the attribute didn't exist,
|
---|
5493 | while for 1.4+ it is sort of mandatory. Now, the buggy XML writer
|
---|
5494 | code only wrote 1.7 and later. So, if it's a 1.7+ XML file and it's
|
---|
5495 | missing the hardware version, then it probably should be "2" instead
|
---|
5496 | of "1". */
|
---|
5497 | if (m->sv < SettingsVersion_v1_7)
|
---|
5498 | hw.strVersion = "1";
|
---|
5499 | else
|
---|
5500 | hw.strVersion = "2";
|
---|
5501 | }
|
---|
5502 | Utf8Str strUUID;
|
---|
5503 | if (elmHardware.getAttributeValue("uuid", strUUID))
|
---|
5504 | parseUUID(hw.uuid, strUUID, &elmHardware);
|
---|
5505 |
|
---|
5506 | xml::NodesLoop nl1(elmHardware);
|
---|
5507 | const xml::ElementNode *pelmHwChild;
|
---|
5508 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
5509 | {
|
---|
5510 | if (pelmHwChild->nameEquals("Memory"))
|
---|
5511 | {
|
---|
5512 | pelmHwChild->getAttributeValue("RAMSize", hw.ulMemorySizeMB);
|
---|
5513 | pelmHwChild->getAttributeValue("PageFusion", hw.fPageFusionEnabled);
|
---|
5514 | }
|
---|
5515 | else if (pelmHwChild->nameEquals("HID"))
|
---|
5516 | {
|
---|
5517 | Utf8Str strHIDType;
|
---|
5518 | if (pelmHwChild->getAttributeValue("Keyboard", strHIDType))
|
---|
5519 | {
|
---|
5520 | if (strHIDType == "None")
|
---|
5521 | hw.keyboardHIDType = KeyboardHIDType_None;
|
---|
5522 | else if (strHIDType == "USBKeyboard")
|
---|
5523 | hw.keyboardHIDType = KeyboardHIDType_USBKeyboard;
|
---|
5524 | else if (strHIDType == "PS2Keyboard")
|
---|
5525 | hw.keyboardHIDType = KeyboardHIDType_PS2Keyboard;
|
---|
5526 | else if (strHIDType == "ComboKeyboard")
|
---|
5527 | hw.keyboardHIDType = KeyboardHIDType_ComboKeyboard;
|
---|
5528 | else
|
---|
5529 | throw ConfigFileError(this,
|
---|
5530 | pelmHwChild,
|
---|
5531 | N_("Invalid value '%s' in HID/Keyboard/@type"),
|
---|
5532 | strHIDType.c_str());
|
---|
5533 | }
|
---|
5534 | if (pelmHwChild->getAttributeValue("Pointing", strHIDType))
|
---|
5535 | {
|
---|
5536 | if (strHIDType == "None")
|
---|
5537 | hw.pointingHIDType = PointingHIDType_None;
|
---|
5538 | else if (strHIDType == "USBMouse")
|
---|
5539 | hw.pointingHIDType = PointingHIDType_USBMouse;
|
---|
5540 | else if (strHIDType == "USBTablet")
|
---|
5541 | hw.pointingHIDType = PointingHIDType_USBTablet;
|
---|
5542 | else if (strHIDType == "PS2Mouse")
|
---|
5543 | hw.pointingHIDType = PointingHIDType_PS2Mouse;
|
---|
5544 | else if (strHIDType == "ComboMouse")
|
---|
5545 | hw.pointingHIDType = PointingHIDType_ComboMouse;
|
---|
5546 | else if (strHIDType == "USBMultiTouch")
|
---|
5547 | hw.pointingHIDType = PointingHIDType_USBMultiTouch;
|
---|
5548 | else if (strHIDType == "USBMTScreenPlusPad")
|
---|
5549 | hw.pointingHIDType = PointingHIDType_USBMultiTouchScreenPlusPad;
|
---|
5550 | else
|
---|
5551 | throw ConfigFileError(this,
|
---|
5552 | pelmHwChild,
|
---|
5553 | N_("Invalid value '%s' in HID/Pointing/@type"),
|
---|
5554 | strHIDType.c_str());
|
---|
5555 | }
|
---|
5556 | }
|
---|
5557 | else if (pelmHwChild->nameEquals("Paravirt"))
|
---|
5558 | {
|
---|
5559 | Utf8Str strProvider;
|
---|
5560 | if (pelmHwChild->getAttributeValue("provider", strProvider))
|
---|
5561 | {
|
---|
5562 | if (strProvider == "None")
|
---|
5563 | hw.paravirtProvider = ParavirtProvider_None;
|
---|
5564 | else if (strProvider == "Default")
|
---|
5565 | hw.paravirtProvider = ParavirtProvider_Default;
|
---|
5566 | else if (strProvider == "Legacy")
|
---|
5567 | hw.paravirtProvider = ParavirtProvider_Legacy;
|
---|
5568 | else if (strProvider == "Minimal")
|
---|
5569 | hw.paravirtProvider = ParavirtProvider_Minimal;
|
---|
5570 | else if (strProvider == "HyperV")
|
---|
5571 | hw.paravirtProvider = ParavirtProvider_HyperV;
|
---|
5572 | else if (strProvider == "KVM")
|
---|
5573 | hw.paravirtProvider = ParavirtProvider_KVM;
|
---|
5574 | else
|
---|
5575 | throw ConfigFileError(this,
|
---|
5576 | pelmHwChild,
|
---|
5577 | N_("Invalid value '%s' in Paravirt/@provider attribute"),
|
---|
5578 | strProvider.c_str());
|
---|
5579 | }
|
---|
5580 |
|
---|
5581 | pelmHwChild->getAttributeValue("debug", hw.strParavirtDebug);
|
---|
5582 | }
|
---|
5583 | else if (pelmHwChild->nameEquals("Boot"))
|
---|
5584 | {
|
---|
5585 | hw.mapBootOrder.clear();
|
---|
5586 |
|
---|
5587 | xml::NodesLoop nl2(*pelmHwChild, "Order");
|
---|
5588 | const xml::ElementNode *pelmOrder;
|
---|
5589 | while ((pelmOrder = nl2.forAllNodes()))
|
---|
5590 | {
|
---|
5591 | uint32_t ulPos;
|
---|
5592 | Utf8Str strDevice;
|
---|
5593 | if (!pelmOrder->getAttributeValue("position", ulPos))
|
---|
5594 | throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@position attribute is missing"));
|
---|
5595 |
|
---|
5596 | if ( ulPos < 1
|
---|
5597 | || ulPos > SchemaDefs::MaxBootPosition
|
---|
5598 | )
|
---|
5599 | throw ConfigFileError(this,
|
---|
5600 | pelmOrder,
|
---|
5601 | N_("Invalid value '%RU32' in Boot/Order/@position: must be greater than 0 and less than %RU32"),
|
---|
5602 | ulPos,
|
---|
5603 | SchemaDefs::MaxBootPosition + 1);
|
---|
5604 | // XML is 1-based but internal data is 0-based
|
---|
5605 | --ulPos;
|
---|
5606 |
|
---|
5607 | if (hw.mapBootOrder.find(ulPos) != hw.mapBootOrder.end())
|
---|
5608 | throw ConfigFileError(this, pelmOrder, N_("Invalid value '%RU32' in Boot/Order/@position: value is not unique"), ulPos);
|
---|
5609 |
|
---|
5610 | if (!pelmOrder->getAttributeValue("device", strDevice))
|
---|
5611 | throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@device attribute is missing"));
|
---|
5612 |
|
---|
5613 | DeviceType_T type;
|
---|
5614 | if (strDevice == "None")
|
---|
5615 | type = DeviceType_Null;
|
---|
5616 | else if (strDevice == "Floppy")
|
---|
5617 | type = DeviceType_Floppy;
|
---|
5618 | else if (strDevice == "DVD")
|
---|
5619 | type = DeviceType_DVD;
|
---|
5620 | else if (strDevice == "HardDisk")
|
---|
5621 | type = DeviceType_HardDisk;
|
---|
5622 | else if (strDevice == "Network")
|
---|
5623 | type = DeviceType_Network;
|
---|
5624 | else
|
---|
5625 | throw ConfigFileError(this, pelmOrder, N_("Invalid value '%s' in Boot/Order/@device attribute"), strDevice.c_str());
|
---|
5626 | hw.mapBootOrder[ulPos] = type;
|
---|
5627 | }
|
---|
5628 | }
|
---|
5629 | else if (pelmHwChild->nameEquals("Display"))
|
---|
5630 | {
|
---|
5631 | Utf8Str strGraphicsControllerType;
|
---|
5632 | if (!pelmHwChild->getAttributeValue("controller", strGraphicsControllerType))
|
---|
5633 | hw.graphicsAdapter.graphicsControllerType = GraphicsControllerType_VBoxVGA;
|
---|
5634 | else
|
---|
5635 | {
|
---|
5636 | strGraphicsControllerType.toUpper();
|
---|
5637 | GraphicsControllerType_T type;
|
---|
5638 | if (strGraphicsControllerType == "VBOXVGA")
|
---|
5639 | type = GraphicsControllerType_VBoxVGA;
|
---|
5640 | else if (strGraphicsControllerType == "VMSVGA")
|
---|
5641 | type = GraphicsControllerType_VMSVGA;
|
---|
5642 | else if (strGraphicsControllerType == "VBOXSVGA")
|
---|
5643 | type = GraphicsControllerType_VBoxSVGA;
|
---|
5644 | else if (strGraphicsControllerType == "QEMURAMFB")
|
---|
5645 | type = GraphicsControllerType_QemuRamFB;
|
---|
5646 | else if (strGraphicsControllerType == "NONE")
|
---|
5647 | type = GraphicsControllerType_Null;
|
---|
5648 | else
|
---|
5649 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Display/@controller attribute"), strGraphicsControllerType.c_str());
|
---|
5650 | hw.graphicsAdapter.graphicsControllerType = type;
|
---|
5651 | }
|
---|
5652 | pelmHwChild->getAttributeValue("VRAMSize", hw.graphicsAdapter.ulVRAMSizeMB);
|
---|
5653 | if (!pelmHwChild->getAttributeValue("monitorCount", hw.graphicsAdapter.cMonitors))
|
---|
5654 | pelmHwChild->getAttributeValue("MonitorCount", hw.graphicsAdapter.cMonitors); // pre-v1.5 variant
|
---|
5655 | if (!pelmHwChild->getAttributeValue("accelerate3D", hw.graphicsAdapter.fAccelerate3D))
|
---|
5656 | pelmHwChild->getAttributeValue("Accelerate3D", hw.graphicsAdapter.fAccelerate3D); // pre-v1.5 variant
|
---|
5657 | pelmHwChild->getAttributeValue("accelerate2DVideo", hw.graphicsAdapter.fAccelerate2DVideo);
|
---|
5658 | }
|
---|
5659 | else if (pelmHwChild->nameEquals("RemoteDisplay"))
|
---|
5660 | {
|
---|
5661 | pelmHwChild->getAttributeValue("enabled", hw.vrdeSettings.fEnabled);
|
---|
5662 |
|
---|
5663 | Utf8Str str;
|
---|
5664 | if (pelmHwChild->getAttributeValue("port", str))
|
---|
5665 | hw.vrdeSettings.mapProperties["TCP/Ports"] = str;
|
---|
5666 | if (pelmHwChild->getAttributeValue("netAddress", str))
|
---|
5667 | hw.vrdeSettings.mapProperties["TCP/Address"] = str;
|
---|
5668 |
|
---|
5669 | Utf8Str strAuthType;
|
---|
5670 | if (pelmHwChild->getAttributeValue("authType", strAuthType))
|
---|
5671 | {
|
---|
5672 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
5673 | strAuthType.toUpper();
|
---|
5674 | if (strAuthType == "NULL")
|
---|
5675 | hw.vrdeSettings.authType = AuthType_Null;
|
---|
5676 | else if (strAuthType == "GUEST")
|
---|
5677 | hw.vrdeSettings.authType = AuthType_Guest;
|
---|
5678 | else if (strAuthType == "EXTERNAL")
|
---|
5679 | hw.vrdeSettings.authType = AuthType_External;
|
---|
5680 | else
|
---|
5681 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in RemoteDisplay/@authType attribute"), strAuthType.c_str());
|
---|
5682 | }
|
---|
5683 |
|
---|
5684 | pelmHwChild->getAttributeValue("authLibrary", hw.vrdeSettings.strAuthLibrary);
|
---|
5685 | pelmHwChild->getAttributeValue("authTimeout", hw.vrdeSettings.ulAuthTimeout);
|
---|
5686 | pelmHwChild->getAttributeValue("allowMultiConnection", hw.vrdeSettings.fAllowMultiConnection);
|
---|
5687 | pelmHwChild->getAttributeValue("reuseSingleConnection", hw.vrdeSettings.fReuseSingleConnection);
|
---|
5688 |
|
---|
5689 | /* 3.2 and 4.0 betas, 4.0 has this information in VRDEProperties. */
|
---|
5690 | const xml::ElementNode *pelmVideoChannel;
|
---|
5691 | if ((pelmVideoChannel = pelmHwChild->findChildElement("VideoChannel")))
|
---|
5692 | {
|
---|
5693 | bool fVideoChannel = false;
|
---|
5694 | pelmVideoChannel->getAttributeValue("enabled", fVideoChannel);
|
---|
5695 | hw.vrdeSettings.mapProperties["VideoChannel/Enabled"] = fVideoChannel? "true": "false";
|
---|
5696 |
|
---|
5697 | uint32_t ulVideoChannelQuality = 75;
|
---|
5698 | pelmVideoChannel->getAttributeValue("quality", ulVideoChannelQuality);
|
---|
5699 | ulVideoChannelQuality = RT_CLAMP(ulVideoChannelQuality, 10, 100);
|
---|
5700 | char *pszBuffer = NULL;
|
---|
5701 | if (RTStrAPrintf(&pszBuffer, "%d", ulVideoChannelQuality) >= 0)
|
---|
5702 | {
|
---|
5703 | hw.vrdeSettings.mapProperties["VideoChannel/Quality"] = pszBuffer;
|
---|
5704 | RTStrFree(pszBuffer);
|
---|
5705 | }
|
---|
5706 | else
|
---|
5707 | hw.vrdeSettings.mapProperties["VideoChannel/Quality"] = "75";
|
---|
5708 | }
|
---|
5709 | pelmHwChild->getAttributeValue("VRDEExtPack", hw.vrdeSettings.strVrdeExtPack);
|
---|
5710 |
|
---|
5711 | const xml::ElementNode *pelmProperties = pelmHwChild->findChildElement("VRDEProperties");
|
---|
5712 | if (pelmProperties != NULL)
|
---|
5713 | {
|
---|
5714 | xml::NodesLoop nl(*pelmProperties);
|
---|
5715 | const xml::ElementNode *pelmProperty;
|
---|
5716 | while ((pelmProperty = nl.forAllNodes()))
|
---|
5717 | {
|
---|
5718 | if (pelmProperty->nameEquals("Property"))
|
---|
5719 | {
|
---|
5720 | /* <Property name="TCP/Ports" value="3000-3002"/> */
|
---|
5721 | Utf8Str strName, strValue;
|
---|
5722 | if ( pelmProperty->getAttributeValue("name", strName)
|
---|
5723 | && pelmProperty->getAttributeValue("value", strValue))
|
---|
5724 | hw.vrdeSettings.mapProperties[strName] = strValue;
|
---|
5725 | else
|
---|
5726 | throw ConfigFileError(this, pelmProperty, N_("Required VRDE Property/@name or @value attribute is missing"));
|
---|
5727 | }
|
---|
5728 | }
|
---|
5729 | }
|
---|
5730 | }
|
---|
5731 | /* Since v1.20 (VBox 7.1) we store BIOS / UEFI settings inside the "Firmware" element.
|
---|
5732 | * Older versions (< v1.20) stored those settings in a "BIOS" element (see down below) for that. See also down below. */
|
---|
5733 | else if ( pelmHwChild->nameEquals("BIOS")
|
---|
5734 | || pelmHwChild->nameEquals("Firmware"))
|
---|
5735 | {
|
---|
5736 | /* For settings < v1.20 we already has an element "Firmware", which only contained the firmware type. The rest lived in the "BIOS" element.
|
---|
5737 | * For settings >= v1.20 we moved the "BIOS" element attributes also to "Firmware". */
|
---|
5738 | if (pelmHwChild->nameEquals("Firmware"))
|
---|
5739 | {
|
---|
5740 | Utf8Str strFirmwareType;
|
---|
5741 | if (pelmHwChild->getAttributeValue("type", strFirmwareType))
|
---|
5742 | {
|
---|
5743 | if ( (strFirmwareType == "BIOS")
|
---|
5744 | || (strFirmwareType == "1") // some trunk builds used the number here
|
---|
5745 | )
|
---|
5746 | hw.firmwareSettings.firmwareType = FirmwareType_BIOS;
|
---|
5747 | else if ( (strFirmwareType == "EFI")
|
---|
5748 | || (strFirmwareType == "2") // some trunk builds used the number here
|
---|
5749 | )
|
---|
5750 | hw.firmwareSettings.firmwareType = FirmwareType_EFI;
|
---|
5751 | else if ( strFirmwareType == "EFI32")
|
---|
5752 | hw.firmwareSettings.firmwareType = FirmwareType_EFI32;
|
---|
5753 | else if ( strFirmwareType == "EFI64")
|
---|
5754 | hw.firmwareSettings.firmwareType = FirmwareType_EFI64;
|
---|
5755 | else if ( strFirmwareType == "EFIDUAL")
|
---|
5756 | hw.firmwareSettings.firmwareType = FirmwareType_EFIDUAL;
|
---|
5757 | else
|
---|
5758 | throw ConfigFileError(this,
|
---|
5759 | pelmHwChild,
|
---|
5760 | N_("Invalid value '%s' in Firmware/@type"),
|
---|
5761 | strFirmwareType.c_str());
|
---|
5762 | }
|
---|
5763 | }
|
---|
5764 |
|
---|
5765 | /* Read the firmware settings either from the "Firmware" or "BIOS" elements, depending on the settings version. */
|
---|
5766 | if ( ( pelmHwChild->nameEquals("Firmware")
|
---|
5767 | && m->sv >= SettingsVersion_v1_20)
|
---|
5768 | || ( pelmHwChild->nameEquals("BIOS")
|
---|
5769 | && m->sv < SettingsVersion_v1_20)
|
---|
5770 | )
|
---|
5771 | {
|
---|
5772 | const xml::ElementNode *pelmFirmwareOrBIOSChild;
|
---|
5773 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("ACPI")))
|
---|
5774 | pelmFirmwareOrBIOSChild->getAttributeValue("enabled", hw.firmwareSettings.fACPIEnabled);
|
---|
5775 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("IOAPIC")))
|
---|
5776 | pelmFirmwareOrBIOSChild->getAttributeValue("enabled", hw.firmwareSettings.fIOAPICEnabled);
|
---|
5777 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("APIC")))
|
---|
5778 | {
|
---|
5779 | Utf8Str strAPIC;
|
---|
5780 | if (pelmFirmwareOrBIOSChild->getAttributeValue("mode", strAPIC))
|
---|
5781 | {
|
---|
5782 | strAPIC.toUpper();
|
---|
5783 | if (strAPIC == "DISABLED")
|
---|
5784 | hw.firmwareSettings.apicMode = APICMode_Disabled;
|
---|
5785 | else if (strAPIC == "APIC")
|
---|
5786 | hw.firmwareSettings.apicMode = APICMode_APIC;
|
---|
5787 | else if (strAPIC == "X2APIC")
|
---|
5788 | hw.firmwareSettings.apicMode = APICMode_X2APIC;
|
---|
5789 | else
|
---|
5790 | throw ConfigFileError(this, pelmFirmwareOrBIOSChild, N_("Invalid value '%s' in APIC/@mode attribute"), strAPIC.c_str());
|
---|
5791 | }
|
---|
5792 | }
|
---|
5793 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("Logo")))
|
---|
5794 | {
|
---|
5795 | pelmFirmwareOrBIOSChild->getAttributeValue("fadeIn", hw.firmwareSettings.fLogoFadeIn);
|
---|
5796 | pelmFirmwareOrBIOSChild->getAttributeValue("fadeOut", hw.firmwareSettings.fLogoFadeOut);
|
---|
5797 | pelmFirmwareOrBIOSChild->getAttributeValue("displayTime", hw.firmwareSettings.ulLogoDisplayTime);
|
---|
5798 | pelmFirmwareOrBIOSChild->getAttributeValue("imagePath", hw.firmwareSettings.strLogoImagePath);
|
---|
5799 | }
|
---|
5800 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("BootMenu")))
|
---|
5801 | {
|
---|
5802 | Utf8Str strBootMenuMode;
|
---|
5803 | if (pelmFirmwareOrBIOSChild->getAttributeValue("mode", strBootMenuMode))
|
---|
5804 | {
|
---|
5805 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
5806 | strBootMenuMode.toUpper();
|
---|
5807 | if (strBootMenuMode == "DISABLED")
|
---|
5808 | hw.firmwareSettings.enmBootMenuMode = FirmwareBootMenuMode_Disabled;
|
---|
5809 | else if (strBootMenuMode == "MENUONLY")
|
---|
5810 | hw.firmwareSettings.enmBootMenuMode = FirmwareBootMenuMode_MenuOnly;
|
---|
5811 | else if (strBootMenuMode == "MESSAGEANDMENU")
|
---|
5812 | hw.firmwareSettings.enmBootMenuMode = FirmwareBootMenuMode_MessageAndMenu;
|
---|
5813 | else
|
---|
5814 | throw ConfigFileError(this, pelmFirmwareOrBIOSChild, N_("Invalid value '%s' in BootMenu/@mode attribute"), strBootMenuMode.c_str());
|
---|
5815 | }
|
---|
5816 | }
|
---|
5817 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("PXEDebug")))
|
---|
5818 | pelmFirmwareOrBIOSChild->getAttributeValue("enabled", hw.firmwareSettings.fPXEDebugEnabled);
|
---|
5819 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("TimeOffset")))
|
---|
5820 | pelmFirmwareOrBIOSChild->getAttributeValue("value", hw.firmwareSettings.llTimeOffset);
|
---|
5821 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("NVRAM")))
|
---|
5822 | {
|
---|
5823 | pelmFirmwareOrBIOSChild->getAttributeValue("path", hw.nvramSettings.strNvramPath);
|
---|
5824 | if (m->sv >= SettingsVersion_v1_19)
|
---|
5825 | {
|
---|
5826 | pelmFirmwareOrBIOSChild->getAttributeValue("keyId", hw.nvramSettings.strKeyId);
|
---|
5827 | pelmFirmwareOrBIOSChild->getAttributeValue("keyStore", hw.nvramSettings.strKeyStore);
|
---|
5828 | }
|
---|
5829 | }
|
---|
5830 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("SmbiosUuidLittleEndian")))
|
---|
5831 | pelmFirmwareOrBIOSChild->getAttributeValue("enabled", hw.firmwareSettings.fSmbiosUuidLittleEndian);
|
---|
5832 | else
|
---|
5833 | hw.firmwareSettings.fSmbiosUuidLittleEndian = false; /* Default for existing VMs. */
|
---|
5834 |
|
---|
5835 | if ((pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("AutoSerialNumGen")))
|
---|
5836 | pelmFirmwareOrBIOSChild->getAttributeValue("enabled", hw.firmwareSettings.fAutoSerialNumGen);
|
---|
5837 | else
|
---|
5838 | hw.firmwareSettings.fAutoSerialNumGen = false; /* Default for existing VMs. */
|
---|
5839 |
|
---|
5840 | // legacy BIOS/IDEController (pre 1.7)
|
---|
5841 | if ( (m->sv < SettingsVersion_v1_7)
|
---|
5842 | && (pelmFirmwareOrBIOSChild = pelmHwChild->findChildElement("IDEController"))
|
---|
5843 | )
|
---|
5844 | {
|
---|
5845 | StorageController sctl;
|
---|
5846 | sctl.strName = "IDE Controller";
|
---|
5847 | sctl.storageBus = StorageBus_IDE;
|
---|
5848 |
|
---|
5849 | Utf8Str strType;
|
---|
5850 | if (pelmFirmwareOrBIOSChild->getAttributeValue("type", strType))
|
---|
5851 | {
|
---|
5852 | if (strType == "PIIX3")
|
---|
5853 | sctl.controllerType = StorageControllerType_PIIX3;
|
---|
5854 | else if (strType == "PIIX4")
|
---|
5855 | sctl.controllerType = StorageControllerType_PIIX4;
|
---|
5856 | else if (strType == "ICH6")
|
---|
5857 | sctl.controllerType = StorageControllerType_ICH6;
|
---|
5858 | else
|
---|
5859 | throw ConfigFileError(this, pelmFirmwareOrBIOSChild, N_("Invalid value '%s' for IDEController/@type attribute"), strType.c_str());
|
---|
5860 | }
|
---|
5861 | sctl.ulPortCount = 2;
|
---|
5862 | hw.storage.llStorageControllers.push_back(sctl);
|
---|
5863 | }
|
---|
5864 | }
|
---|
5865 | }
|
---|
5866 | else if (pelmHwChild->nameEquals("TrustedPlatformModule"))
|
---|
5867 | {
|
---|
5868 | Utf8Str strTpmType;
|
---|
5869 | if (pelmHwChild->getAttributeValue("type", strTpmType))
|
---|
5870 | {
|
---|
5871 | if (strTpmType == "None")
|
---|
5872 | hw.tpmSettings.tpmType = TpmType_None;
|
---|
5873 | else if (strTpmType == "v1_2")
|
---|
5874 | hw.tpmSettings.tpmType = TpmType_v1_2;
|
---|
5875 | else if (strTpmType == "v2_0")
|
---|
5876 | hw.tpmSettings.tpmType = TpmType_v2_0;
|
---|
5877 | else if (strTpmType == "Host")
|
---|
5878 | hw.tpmSettings.tpmType = TpmType_Host;
|
---|
5879 | else if (strTpmType == "Swtpm")
|
---|
5880 | hw.tpmSettings.tpmType = TpmType_Swtpm;
|
---|
5881 | else
|
---|
5882 | throw ConfigFileError(this,
|
---|
5883 | pelmHwChild,
|
---|
5884 | N_("Invalid value '%s' in TrustedPlatformModule/@type"),
|
---|
5885 | strTpmType.c_str());
|
---|
5886 | }
|
---|
5887 |
|
---|
5888 | pelmHwChild->getAttributeValue("location", hw.tpmSettings.strLocation);
|
---|
5889 | }
|
---|
5890 | else if ( (m->sv <= SettingsVersion_v1_14)
|
---|
5891 | && pelmHwChild->nameEquals("USBController"))
|
---|
5892 | {
|
---|
5893 | bool fEnabled = false;
|
---|
5894 |
|
---|
5895 | pelmHwChild->getAttributeValue("enabled", fEnabled);
|
---|
5896 | if (fEnabled)
|
---|
5897 | {
|
---|
5898 | /* Create OHCI controller with default name. */
|
---|
5899 | USBController ctrl;
|
---|
5900 |
|
---|
5901 | ctrl.strName = "OHCI";
|
---|
5902 | ctrl.enmType = USBControllerType_OHCI;
|
---|
5903 | hw.usbSettings.llUSBControllers.push_back(ctrl);
|
---|
5904 | }
|
---|
5905 |
|
---|
5906 | pelmHwChild->getAttributeValue("enabledEhci", fEnabled);
|
---|
5907 | if (fEnabled)
|
---|
5908 | {
|
---|
5909 | /* Create OHCI controller with default name. */
|
---|
5910 | USBController ctrl;
|
---|
5911 |
|
---|
5912 | ctrl.strName = "EHCI";
|
---|
5913 | ctrl.enmType = USBControllerType_EHCI;
|
---|
5914 | hw.usbSettings.llUSBControllers.push_back(ctrl);
|
---|
5915 | }
|
---|
5916 |
|
---|
5917 | readUSBDeviceFilters(*pelmHwChild,
|
---|
5918 | hw.usbSettings.llDeviceFilters);
|
---|
5919 | }
|
---|
5920 | else if (pelmHwChild->nameEquals("USB"))
|
---|
5921 | {
|
---|
5922 | const xml::ElementNode *pelmUSBChild;
|
---|
5923 |
|
---|
5924 | if ((pelmUSBChild = pelmHwChild->findChildElement("Controllers")))
|
---|
5925 | {
|
---|
5926 | xml::NodesLoop nl2(*pelmUSBChild, "Controller");
|
---|
5927 | const xml::ElementNode *pelmCtrl;
|
---|
5928 |
|
---|
5929 | while ((pelmCtrl = nl2.forAllNodes()))
|
---|
5930 | {
|
---|
5931 | USBController ctrl;
|
---|
5932 | com::Utf8Str strCtrlType;
|
---|
5933 |
|
---|
5934 | pelmCtrl->getAttributeValue("name", ctrl.strName);
|
---|
5935 |
|
---|
5936 | if (pelmCtrl->getAttributeValue("type", strCtrlType))
|
---|
5937 | {
|
---|
5938 | if (strCtrlType == "OHCI")
|
---|
5939 | ctrl.enmType = USBControllerType_OHCI;
|
---|
5940 | else if (strCtrlType == "EHCI")
|
---|
5941 | ctrl.enmType = USBControllerType_EHCI;
|
---|
5942 | else if (strCtrlType == "XHCI")
|
---|
5943 | ctrl.enmType = USBControllerType_XHCI;
|
---|
5944 | else
|
---|
5945 | throw ConfigFileError(this, pelmCtrl, N_("Invalid value '%s' for Controller/@type attribute"), strCtrlType.c_str());
|
---|
5946 | }
|
---|
5947 |
|
---|
5948 | hw.usbSettings.llUSBControllers.push_back(ctrl);
|
---|
5949 | }
|
---|
5950 | }
|
---|
5951 |
|
---|
5952 | if ((pelmUSBChild = pelmHwChild->findChildElement("DeviceFilters")))
|
---|
5953 | readUSBDeviceFilters(*pelmUSBChild, hw.usbSettings.llDeviceFilters);
|
---|
5954 | }
|
---|
5955 | else if ( m->sv < SettingsVersion_v1_7
|
---|
5956 | && pelmHwChild->nameEquals("SATAController"))
|
---|
5957 | {
|
---|
5958 | bool f;
|
---|
5959 | if ( pelmHwChild->getAttributeValue("enabled", f)
|
---|
5960 | && f)
|
---|
5961 | {
|
---|
5962 | StorageController sctl;
|
---|
5963 | sctl.strName = "SATA Controller";
|
---|
5964 | sctl.storageBus = StorageBus_SATA;
|
---|
5965 | sctl.controllerType = StorageControllerType_IntelAhci;
|
---|
5966 |
|
---|
5967 | readStorageControllerAttributes(*pelmHwChild, sctl);
|
---|
5968 |
|
---|
5969 | hw.storage.llStorageControllers.push_back(sctl);
|
---|
5970 | }
|
---|
5971 | }
|
---|
5972 | else if (pelmHwChild->nameEquals("Network"))
|
---|
5973 | readNetworkAdapters(*pelmHwChild, hw.llNetworkAdapters);
|
---|
5974 | else if ( pelmHwChild->nameEquals("UART")
|
---|
5975 | || pelmHwChild->nameEquals("Uart") // used before 1.3
|
---|
5976 | )
|
---|
5977 | readSerialPorts(*pelmHwChild, hw.llSerialPorts);
|
---|
5978 | else if ( pelmHwChild->nameEquals("LPT")
|
---|
5979 | || pelmHwChild->nameEquals("Lpt") // used before 1.3
|
---|
5980 | )
|
---|
5981 | readParallelPorts(*pelmHwChild, hw.llParallelPorts);
|
---|
5982 | else if (pelmHwChild->nameEquals("AudioAdapter"))
|
---|
5983 | readAudioAdapter(*pelmHwChild, hw.audioAdapter);
|
---|
5984 | else if (pelmHwChild->nameEquals("SharedFolders"))
|
---|
5985 | {
|
---|
5986 | xml::NodesLoop nl2(*pelmHwChild, "SharedFolder");
|
---|
5987 | const xml::ElementNode *pelmFolder;
|
---|
5988 | while ((pelmFolder = nl2.forAllNodes()))
|
---|
5989 | {
|
---|
5990 | SharedFolder sf;
|
---|
5991 | pelmFolder->getAttributeValue("name", sf.strName);
|
---|
5992 | pelmFolder->getAttributeValue("hostPath", sf.strHostPath);
|
---|
5993 | pelmFolder->getAttributeValue("writable", sf.fWritable);
|
---|
5994 | pelmFolder->getAttributeValue("autoMount", sf.fAutoMount);
|
---|
5995 | pelmFolder->getAttributeValue("autoMountPoint", sf.strAutoMountPoint);
|
---|
5996 |
|
---|
5997 | Utf8Str strTemp;
|
---|
5998 | if (pelmFolder->getAttributeValue("symlinkPolicy", strTemp))
|
---|
5999 | {
|
---|
6000 | if (strTemp == "forbidden")
|
---|
6001 | sf.enmSymlinkPolicy = SymlinkPolicy_Forbidden;
|
---|
6002 | else if (strTemp == "subtree")
|
---|
6003 | sf.enmSymlinkPolicy = SymlinkPolicy_AllowedInShareSubtree;
|
---|
6004 | else if (strTemp == "relative")
|
---|
6005 | sf.enmSymlinkPolicy = SymlinkPolicy_AllowedToRelativeTargets;
|
---|
6006 | else if (strTemp == "any")
|
---|
6007 | sf.enmSymlinkPolicy = SymlinkPolicy_AllowedToAnyTarget;
|
---|
6008 | else
|
---|
6009 | throw ConfigFileError(this,
|
---|
6010 | pelmHwChild,
|
---|
6011 | N_("Invalid value '%s' in SharedFolder/@symlinkPolicy attribute"),
|
---|
6012 | strTemp.c_str());
|
---|
6013 | }
|
---|
6014 | hw.llSharedFolders.push_back(sf);
|
---|
6015 | }
|
---|
6016 | }
|
---|
6017 | else if (pelmHwChild->nameEquals("Clipboard"))
|
---|
6018 | {
|
---|
6019 | Utf8Str strTemp;
|
---|
6020 | if (pelmHwChild->getAttributeValue("mode", strTemp))
|
---|
6021 | {
|
---|
6022 | if (strTemp == "Disabled")
|
---|
6023 | hw.clipboardMode = ClipboardMode_Disabled;
|
---|
6024 | else if (strTemp == "HostToGuest")
|
---|
6025 | hw.clipboardMode = ClipboardMode_HostToGuest;
|
---|
6026 | else if (strTemp == "GuestToHost")
|
---|
6027 | hw.clipboardMode = ClipboardMode_GuestToHost;
|
---|
6028 | else if (strTemp == "Bidirectional")
|
---|
6029 | hw.clipboardMode = ClipboardMode_Bidirectional;
|
---|
6030 | else
|
---|
6031 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Clipboard/@mode attribute"), strTemp.c_str());
|
---|
6032 | }
|
---|
6033 |
|
---|
6034 | pelmHwChild->getAttributeValue("fileTransfersEnabled", hw.fClipboardFileTransfersEnabled);
|
---|
6035 | }
|
---|
6036 | else if (pelmHwChild->nameEquals("DragAndDrop"))
|
---|
6037 | {
|
---|
6038 | Utf8Str strTemp;
|
---|
6039 | if (pelmHwChild->getAttributeValue("mode", strTemp))
|
---|
6040 | {
|
---|
6041 | if (strTemp == "Disabled")
|
---|
6042 | hw.dndMode = DnDMode_Disabled;
|
---|
6043 | else if (strTemp == "HostToGuest")
|
---|
6044 | hw.dndMode = DnDMode_HostToGuest;
|
---|
6045 | else if (strTemp == "GuestToHost")
|
---|
6046 | hw.dndMode = DnDMode_GuestToHost;
|
---|
6047 | else if (strTemp == "Bidirectional")
|
---|
6048 | hw.dndMode = DnDMode_Bidirectional;
|
---|
6049 | else
|
---|
6050 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in DragAndDrop/@mode attribute"), strTemp.c_str());
|
---|
6051 | }
|
---|
6052 | }
|
---|
6053 | else if (pelmHwChild->nameEquals("Guest"))
|
---|
6054 | {
|
---|
6055 | if (!pelmHwChild->getAttributeValue("memoryBalloonSize", hw.ulMemoryBalloonSize))
|
---|
6056 | pelmHwChild->getAttributeValue("MemoryBalloonSize", hw.ulMemoryBalloonSize); // used before 1.3
|
---|
6057 | }
|
---|
6058 | else if (pelmHwChild->nameEquals("GuestProperties"))
|
---|
6059 | readGuestProperties(*pelmHwChild, hw);
|
---|
6060 | else if (pelmHwChild->nameEquals("IO"))
|
---|
6061 | {
|
---|
6062 | const xml::ElementNode *pelmBwGroups;
|
---|
6063 | const xml::ElementNode *pelmIOChild;
|
---|
6064 |
|
---|
6065 | if ((pelmIOChild = pelmHwChild->findChildElement("IoCache")))
|
---|
6066 | {
|
---|
6067 | pelmIOChild->getAttributeValue("enabled", hw.ioSettings.fIOCacheEnabled);
|
---|
6068 | pelmIOChild->getAttributeValue("size", hw.ioSettings.ulIOCacheSize);
|
---|
6069 | }
|
---|
6070 |
|
---|
6071 | if ((pelmBwGroups = pelmHwChild->findChildElement("BandwidthGroups")))
|
---|
6072 | {
|
---|
6073 | xml::NodesLoop nl2(*pelmBwGroups, "BandwidthGroup");
|
---|
6074 | const xml::ElementNode *pelmBandwidthGroup;
|
---|
6075 | while ((pelmBandwidthGroup = nl2.forAllNodes()))
|
---|
6076 | {
|
---|
6077 | BandwidthGroup gr;
|
---|
6078 | Utf8Str strTemp;
|
---|
6079 |
|
---|
6080 | pelmBandwidthGroup->getAttributeValue("name", gr.strName);
|
---|
6081 |
|
---|
6082 | if (pelmBandwidthGroup->getAttributeValue("type", strTemp))
|
---|
6083 | {
|
---|
6084 | if (strTemp == "Disk")
|
---|
6085 | gr.enmType = BandwidthGroupType_Disk;
|
---|
6086 | else if (strTemp == "Network")
|
---|
6087 | gr.enmType = BandwidthGroupType_Network;
|
---|
6088 | else
|
---|
6089 | throw ConfigFileError(this, pelmBandwidthGroup, N_("Invalid value '%s' in BandwidthGroup/@type attribute"), strTemp.c_str());
|
---|
6090 | }
|
---|
6091 | else
|
---|
6092 | throw ConfigFileError(this, pelmBandwidthGroup, N_("Missing BandwidthGroup/@type attribute"));
|
---|
6093 |
|
---|
6094 | if (!pelmBandwidthGroup->getAttributeValue("maxBytesPerSec", gr.cMaxBytesPerSec))
|
---|
6095 | {
|
---|
6096 | pelmBandwidthGroup->getAttributeValue("maxMbPerSec", gr.cMaxBytesPerSec);
|
---|
6097 | gr.cMaxBytesPerSec *= _1M;
|
---|
6098 | }
|
---|
6099 | hw.ioSettings.llBandwidthGroups.push_back(gr);
|
---|
6100 | }
|
---|
6101 | }
|
---|
6102 | }
|
---|
6103 | else if (pelmHwChild->nameEquals("HostPci"))
|
---|
6104 | {
|
---|
6105 | const xml::ElementNode *pelmDevices;
|
---|
6106 |
|
---|
6107 | if ((pelmDevices = pelmHwChild->findChildElement("Devices")))
|
---|
6108 | {
|
---|
6109 | xml::NodesLoop nl2(*pelmDevices, "Device");
|
---|
6110 | const xml::ElementNode *pelmDevice;
|
---|
6111 | while ((pelmDevice = nl2.forAllNodes()))
|
---|
6112 | {
|
---|
6113 | HostPCIDeviceAttachment hpda;
|
---|
6114 |
|
---|
6115 | if (!pelmDevice->getAttributeValue("host", hpda.uHostAddress))
|
---|
6116 | throw ConfigFileError(this, pelmDevice, N_("Missing Device/@host attribute"));
|
---|
6117 |
|
---|
6118 | if (!pelmDevice->getAttributeValue("guest", hpda.uGuestAddress))
|
---|
6119 | throw ConfigFileError(this, pelmDevice, N_("Missing Device/@guest attribute"));
|
---|
6120 |
|
---|
6121 | /* name is optional */
|
---|
6122 | pelmDevice->getAttributeValue("name", hpda.strDeviceName);
|
---|
6123 |
|
---|
6124 | hw.pciAttachments.push_back(hpda);
|
---|
6125 | }
|
---|
6126 | }
|
---|
6127 | }
|
---|
6128 | else if (pelmHwChild->nameEquals("EmulatedUSB"))
|
---|
6129 | {
|
---|
6130 | const xml::ElementNode *pelmCardReader;
|
---|
6131 |
|
---|
6132 | if ((pelmCardReader = pelmHwChild->findChildElement("CardReader")))
|
---|
6133 | {
|
---|
6134 | pelmCardReader->getAttributeValue("enabled", hw.fEmulatedUSBCardReader);
|
---|
6135 | }
|
---|
6136 | }
|
---|
6137 | else if (pelmHwChild->nameEquals("Frontend"))
|
---|
6138 | {
|
---|
6139 | const xml::ElementNode *pelmDefault;
|
---|
6140 |
|
---|
6141 | if ((pelmDefault = pelmHwChild->findChildElement("Default")))
|
---|
6142 | {
|
---|
6143 | pelmDefault->getAttributeValue("type", hw.strDefaultFrontend);
|
---|
6144 | }
|
---|
6145 | }
|
---|
6146 | else if (pelmHwChild->nameEquals("StorageControllers"))
|
---|
6147 | readStorageControllers(*pelmHwChild, hw.storage);
|
---|
6148 | }
|
---|
6149 |
|
---|
6150 | /* We read the platform settings here, which were part of the "Hardware" node for settings < 1.2.0.
|
---|
6151 | * For newer settings (>= v1.20) we read the platform settings outside readHardware(). */
|
---|
6152 | if (m->sv < SettingsVersion_v1_20)
|
---|
6153 | readPlatform(elmHardware, hw, hw.platformSettings);
|
---|
6154 |
|
---|
6155 | if (hw.ulMemorySizeMB == (uint32_t)-1)
|
---|
6156 | throw ConfigFileError(this, &elmHardware, N_("Required Memory/@RAMSize element/attribute is missing"));
|
---|
6157 | }
|
---|
6158 |
|
---|
6159 | /**
|
---|
6160 | * This gets called instead of readStorageControllers() for legacy pre-1.7 settings
|
---|
6161 | * files which have a \<HardDiskAttachments\> node and storage controller settings
|
---|
6162 | * hidden in the \<Hardware\> settings. We set the StorageControllers fields just the
|
---|
6163 | * same, just from different sources.
|
---|
6164 | * @param elmHardDiskAttachments \<HardDiskAttachments\> XML node.
|
---|
6165 | * @param strg
|
---|
6166 | */
|
---|
6167 | void MachineConfigFile::readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments,
|
---|
6168 | Storage &strg)
|
---|
6169 | {
|
---|
6170 | StorageController *pIDEController = NULL;
|
---|
6171 | StorageController *pSATAController = NULL;
|
---|
6172 |
|
---|
6173 | for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
|
---|
6174 | it != strg.llStorageControllers.end();
|
---|
6175 | ++it)
|
---|
6176 | {
|
---|
6177 | StorageController &s = *it;
|
---|
6178 | if (s.storageBus == StorageBus_IDE)
|
---|
6179 | pIDEController = &s;
|
---|
6180 | else if (s.storageBus == StorageBus_SATA)
|
---|
6181 | pSATAController = &s;
|
---|
6182 | }
|
---|
6183 |
|
---|
6184 | xml::NodesLoop nl1(elmHardDiskAttachments, "HardDiskAttachment");
|
---|
6185 | const xml::ElementNode *pelmAttachment;
|
---|
6186 | while ((pelmAttachment = nl1.forAllNodes()))
|
---|
6187 | {
|
---|
6188 | AttachedDevice att;
|
---|
6189 | Utf8Str strUUID, strBus;
|
---|
6190 |
|
---|
6191 | if (!pelmAttachment->getAttributeValue("hardDisk", strUUID))
|
---|
6192 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@hardDisk attribute is missing"));
|
---|
6193 | parseUUID(att.uuid, strUUID, pelmAttachment);
|
---|
6194 |
|
---|
6195 | if (!pelmAttachment->getAttributeValue("bus", strBus))
|
---|
6196 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@bus attribute is missing"));
|
---|
6197 | // pre-1.7 'channel' is now port
|
---|
6198 | if (!pelmAttachment->getAttributeValue("channel", att.lPort))
|
---|
6199 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@channel attribute is missing"));
|
---|
6200 | // pre-1.7 'device' is still device
|
---|
6201 | if (!pelmAttachment->getAttributeValue("device", att.lDevice))
|
---|
6202 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@device attribute is missing"));
|
---|
6203 |
|
---|
6204 | att.deviceType = DeviceType_HardDisk;
|
---|
6205 |
|
---|
6206 | if (strBus == "IDE")
|
---|
6207 | {
|
---|
6208 | if (!pIDEController)
|
---|
6209 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'IDE' but cannot find IDE controller"));
|
---|
6210 | pIDEController->llAttachedDevices.push_back(att);
|
---|
6211 | }
|
---|
6212 | else if (strBus == "SATA")
|
---|
6213 | {
|
---|
6214 | if (!pSATAController)
|
---|
6215 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'SATA' but cannot find SATA controller"));
|
---|
6216 | pSATAController->llAttachedDevices.push_back(att);
|
---|
6217 | }
|
---|
6218 | else
|
---|
6219 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus attribute has illegal value '%s'"), strBus.c_str());
|
---|
6220 | }
|
---|
6221 | }
|
---|
6222 |
|
---|
6223 | /**
|
---|
6224 | * Reads in a \<StorageControllers\> block and stores it in the given Storage structure.
|
---|
6225 | * Used both directly from readMachine and from readSnapshot, since snapshots
|
---|
6226 | * have their own storage controllers sections.
|
---|
6227 | *
|
---|
6228 | * This is only called for settings version 1.7 and above; see readHardDiskAttachments_pre1_7()
|
---|
6229 | * for earlier versions.
|
---|
6230 | *
|
---|
6231 | * @param elmStorageControllers
|
---|
6232 | * @param strg
|
---|
6233 | */
|
---|
6234 | void MachineConfigFile::readStorageControllers(const xml::ElementNode &elmStorageControllers,
|
---|
6235 | Storage &strg)
|
---|
6236 | {
|
---|
6237 | xml::NodesLoop nlStorageControllers(elmStorageControllers, "StorageController");
|
---|
6238 | const xml::ElementNode *pelmController;
|
---|
6239 | while ((pelmController = nlStorageControllers.forAllNodes()))
|
---|
6240 | {
|
---|
6241 | StorageController sctl;
|
---|
6242 |
|
---|
6243 | if (!pelmController->getAttributeValue("name", sctl.strName))
|
---|
6244 | throw ConfigFileError(this, pelmController, N_("Required StorageController/@name attribute is missing"));
|
---|
6245 | // canonicalize storage controller names for configs in the switchover
|
---|
6246 | // period.
|
---|
6247 | if (m->sv < SettingsVersion_v1_9)
|
---|
6248 | {
|
---|
6249 | if (sctl.strName == "IDE")
|
---|
6250 | sctl.strName = "IDE Controller";
|
---|
6251 | else if (sctl.strName == "SATA")
|
---|
6252 | sctl.strName = "SATA Controller";
|
---|
6253 | else if (sctl.strName == "SCSI")
|
---|
6254 | sctl.strName = "SCSI Controller";
|
---|
6255 | }
|
---|
6256 |
|
---|
6257 | pelmController->getAttributeValue("Instance", sctl.ulInstance);
|
---|
6258 | // default from constructor is 0
|
---|
6259 |
|
---|
6260 | pelmController->getAttributeValue("Bootable", sctl.fBootable);
|
---|
6261 | // default from constructor is true which is true
|
---|
6262 | // for settings below version 1.11 because they allowed only
|
---|
6263 | // one controller per type.
|
---|
6264 |
|
---|
6265 | Utf8Str strType;
|
---|
6266 | if (!pelmController->getAttributeValue("type", strType))
|
---|
6267 | throw ConfigFileError(this, pelmController, N_("Required StorageController/@type attribute is missing"));
|
---|
6268 |
|
---|
6269 | if (strType == "AHCI")
|
---|
6270 | {
|
---|
6271 | sctl.storageBus = StorageBus_SATA;
|
---|
6272 | sctl.controllerType = StorageControllerType_IntelAhci;
|
---|
6273 | }
|
---|
6274 | else if (strType == "LsiLogic")
|
---|
6275 | {
|
---|
6276 | sctl.storageBus = StorageBus_SCSI;
|
---|
6277 | sctl.controllerType = StorageControllerType_LsiLogic;
|
---|
6278 | }
|
---|
6279 | else if (strType == "BusLogic")
|
---|
6280 | {
|
---|
6281 | sctl.storageBus = StorageBus_SCSI;
|
---|
6282 | sctl.controllerType = StorageControllerType_BusLogic;
|
---|
6283 | }
|
---|
6284 | else if (strType == "PIIX3")
|
---|
6285 | {
|
---|
6286 | sctl.storageBus = StorageBus_IDE;
|
---|
6287 | sctl.controllerType = StorageControllerType_PIIX3;
|
---|
6288 | }
|
---|
6289 | else if (strType == "PIIX4")
|
---|
6290 | {
|
---|
6291 | sctl.storageBus = StorageBus_IDE;
|
---|
6292 | sctl.controllerType = StorageControllerType_PIIX4;
|
---|
6293 | }
|
---|
6294 | else if (strType == "ICH6")
|
---|
6295 | {
|
---|
6296 | sctl.storageBus = StorageBus_IDE;
|
---|
6297 | sctl.controllerType = StorageControllerType_ICH6;
|
---|
6298 | }
|
---|
6299 | else if ( (m->sv >= SettingsVersion_v1_9)
|
---|
6300 | && (strType == "I82078")
|
---|
6301 | )
|
---|
6302 | {
|
---|
6303 | sctl.storageBus = StorageBus_Floppy;
|
---|
6304 | sctl.controllerType = StorageControllerType_I82078;
|
---|
6305 | }
|
---|
6306 | else if (strType == "LsiLogicSas")
|
---|
6307 | {
|
---|
6308 | sctl.storageBus = StorageBus_SAS;
|
---|
6309 | sctl.controllerType = StorageControllerType_LsiLogicSas;
|
---|
6310 | }
|
---|
6311 | else if (strType == "USB")
|
---|
6312 | {
|
---|
6313 | sctl.storageBus = StorageBus_USB;
|
---|
6314 | sctl.controllerType = StorageControllerType_USB;
|
---|
6315 | }
|
---|
6316 | else if (strType == "NVMe")
|
---|
6317 | {
|
---|
6318 | sctl.storageBus = StorageBus_PCIe;
|
---|
6319 | sctl.controllerType = StorageControllerType_NVMe;
|
---|
6320 | }
|
---|
6321 | else if (strType == "VirtioSCSI")
|
---|
6322 | {
|
---|
6323 | sctl.storageBus = StorageBus_VirtioSCSI;
|
---|
6324 | sctl.controllerType = StorageControllerType_VirtioSCSI;
|
---|
6325 | }
|
---|
6326 | else
|
---|
6327 | throw ConfigFileError(this, pelmController, N_("Invalid value '%s' for StorageController/@type attribute"), strType.c_str());
|
---|
6328 |
|
---|
6329 | readStorageControllerAttributes(*pelmController, sctl);
|
---|
6330 |
|
---|
6331 | xml::NodesLoop nlAttached(*pelmController, "AttachedDevice");
|
---|
6332 | const xml::ElementNode *pelmAttached;
|
---|
6333 | while ((pelmAttached = nlAttached.forAllNodes()))
|
---|
6334 | {
|
---|
6335 | AttachedDevice att;
|
---|
6336 | Utf8Str strTemp;
|
---|
6337 | pelmAttached->getAttributeValue("type", strTemp);
|
---|
6338 |
|
---|
6339 | att.fDiscard = false;
|
---|
6340 | att.fNonRotational = false;
|
---|
6341 | att.fHotPluggable = false;
|
---|
6342 | att.fPassThrough = false;
|
---|
6343 |
|
---|
6344 | if (strTemp == "HardDisk")
|
---|
6345 | {
|
---|
6346 | att.deviceType = DeviceType_HardDisk;
|
---|
6347 | pelmAttached->getAttributeValue("nonrotational", att.fNonRotational);
|
---|
6348 | pelmAttached->getAttributeValue("discard", att.fDiscard);
|
---|
6349 | }
|
---|
6350 | else if (m->sv >= SettingsVersion_v1_9)
|
---|
6351 | {
|
---|
6352 | // starting with 1.9 we list DVD and floppy drive info + attachments under <StorageControllers>
|
---|
6353 | if (strTemp == "DVD")
|
---|
6354 | {
|
---|
6355 | att.deviceType = DeviceType_DVD;
|
---|
6356 | pelmAttached->getAttributeValue("passthrough", att.fPassThrough);
|
---|
6357 | pelmAttached->getAttributeValue("tempeject", att.fTempEject);
|
---|
6358 | }
|
---|
6359 | else if (strTemp == "Floppy")
|
---|
6360 | att.deviceType = DeviceType_Floppy;
|
---|
6361 | }
|
---|
6362 |
|
---|
6363 | if (att.deviceType != DeviceType_Null)
|
---|
6364 | {
|
---|
6365 | const xml::ElementNode *pelmImage;
|
---|
6366 | // all types can have images attached, but for HardDisk it's required
|
---|
6367 | if (!(pelmImage = pelmAttached->findChildElement("Image")))
|
---|
6368 | {
|
---|
6369 | if (att.deviceType == DeviceType_HardDisk)
|
---|
6370 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image element is missing"));
|
---|
6371 | else
|
---|
6372 | {
|
---|
6373 | // DVDs and floppies can also have <HostDrive> instead of <Image>
|
---|
6374 | const xml::ElementNode *pelmHostDrive;
|
---|
6375 | if ((pelmHostDrive = pelmAttached->findChildElement("HostDrive")))
|
---|
6376 | if (!pelmHostDrive->getAttributeValue("src", att.strHostDriveSrc))
|
---|
6377 | throw ConfigFileError(this, pelmHostDrive, N_("Required AttachedDevice/HostDrive/@src attribute is missing"));
|
---|
6378 | }
|
---|
6379 | }
|
---|
6380 | else
|
---|
6381 | {
|
---|
6382 | if (!pelmImage->getAttributeValue("uuid", strTemp))
|
---|
6383 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image/@uuid attribute is missing"));
|
---|
6384 | parseUUID(att.uuid, strTemp, pelmImage);
|
---|
6385 | }
|
---|
6386 |
|
---|
6387 | if (!pelmAttached->getAttributeValue("port", att.lPort))
|
---|
6388 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@port attribute is missing"));
|
---|
6389 | if (!pelmAttached->getAttributeValue("device", att.lDevice))
|
---|
6390 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@device attribute is missing"));
|
---|
6391 |
|
---|
6392 | /* AHCI controller ports are hotpluggable by default, keep compatibility with existing settings. */
|
---|
6393 | if (m->sv >= SettingsVersion_v1_15)
|
---|
6394 | pelmAttached->getAttributeValue("hotpluggable", att.fHotPluggable);
|
---|
6395 | else if (sctl.controllerType == StorageControllerType_IntelAhci)
|
---|
6396 | att.fHotPluggable = true;
|
---|
6397 |
|
---|
6398 | pelmAttached->getAttributeValue("bandwidthGroup", att.strBwGroup);
|
---|
6399 | sctl.llAttachedDevices.push_back(att);
|
---|
6400 | }
|
---|
6401 | }
|
---|
6402 |
|
---|
6403 | strg.llStorageControllers.push_back(sctl);
|
---|
6404 | }
|
---|
6405 | }
|
---|
6406 |
|
---|
6407 | /**
|
---|
6408 | * This gets called for legacy pre-1.9 settings files after having parsed the
|
---|
6409 | * \<Hardware\> and \<StorageControllers\> sections to parse \<Hardware\> once more
|
---|
6410 | * for the \<DVDDrive\> and \<FloppyDrive\> sections.
|
---|
6411 | *
|
---|
6412 | * Before settings version 1.9, DVD and floppy drives were specified separately
|
---|
6413 | * under \<Hardware\>; we then need this extra loop to make sure the storage
|
---|
6414 | * controller structs are already set up so we can add stuff to them.
|
---|
6415 | *
|
---|
6416 | * @param elmHardware
|
---|
6417 | * @param strg
|
---|
6418 | */
|
---|
6419 | void MachineConfigFile::readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware,
|
---|
6420 | Storage &strg)
|
---|
6421 | {
|
---|
6422 | xml::NodesLoop nl1(elmHardware);
|
---|
6423 | const xml::ElementNode *pelmHwChild;
|
---|
6424 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
6425 | {
|
---|
6426 | if (pelmHwChild->nameEquals("DVDDrive"))
|
---|
6427 | {
|
---|
6428 | // create a DVD "attached device" and attach it to the existing IDE controller
|
---|
6429 | AttachedDevice att;
|
---|
6430 | att.deviceType = DeviceType_DVD;
|
---|
6431 | // legacy DVD drive is always secondary master (port 1, device 0)
|
---|
6432 | att.lPort = 1;
|
---|
6433 | att.lDevice = 0;
|
---|
6434 | pelmHwChild->getAttributeValue("passthrough", att.fPassThrough);
|
---|
6435 | pelmHwChild->getAttributeValue("tempeject", att.fTempEject);
|
---|
6436 |
|
---|
6437 | const xml::ElementNode *pDriveChild;
|
---|
6438 | Utf8Str strTmp;
|
---|
6439 | if ( (pDriveChild = pelmHwChild->findChildElement("Image")) != NULL
|
---|
6440 | && pDriveChild->getAttributeValue("uuid", strTmp))
|
---|
6441 | parseUUID(att.uuid, strTmp, pDriveChild);
|
---|
6442 | else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
|
---|
6443 | pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
|
---|
6444 |
|
---|
6445 | // find the IDE controller and attach the DVD drive
|
---|
6446 | bool fFound = false;
|
---|
6447 | for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
|
---|
6448 | it != strg.llStorageControllers.end();
|
---|
6449 | ++it)
|
---|
6450 | {
|
---|
6451 | StorageController &sctl = *it;
|
---|
6452 | if (sctl.storageBus == StorageBus_IDE)
|
---|
6453 | {
|
---|
6454 | sctl.llAttachedDevices.push_back(att);
|
---|
6455 | fFound = true;
|
---|
6456 | break;
|
---|
6457 | }
|
---|
6458 | }
|
---|
6459 |
|
---|
6460 | if (!fFound)
|
---|
6461 | throw ConfigFileError(this, pelmHwChild, N_("Internal error: found DVD drive but IDE controller does not exist"));
|
---|
6462 | // shouldn't happen because pre-1.9 settings files always had at least one IDE controller in the settings
|
---|
6463 | // which should have gotten parsed in <StorageControllers> before this got called
|
---|
6464 | }
|
---|
6465 | else if (pelmHwChild->nameEquals("FloppyDrive"))
|
---|
6466 | {
|
---|
6467 | bool fEnabled;
|
---|
6468 | if ( pelmHwChild->getAttributeValue("enabled", fEnabled)
|
---|
6469 | && fEnabled)
|
---|
6470 | {
|
---|
6471 | // create a new floppy controller and attach a floppy "attached device"
|
---|
6472 | StorageController sctl;
|
---|
6473 | sctl.strName = "Floppy Controller";
|
---|
6474 | sctl.storageBus = StorageBus_Floppy;
|
---|
6475 | sctl.controllerType = StorageControllerType_I82078;
|
---|
6476 | sctl.ulPortCount = 1;
|
---|
6477 |
|
---|
6478 | AttachedDevice att;
|
---|
6479 | att.deviceType = DeviceType_Floppy;
|
---|
6480 | att.lPort = 0;
|
---|
6481 | att.lDevice = 0;
|
---|
6482 |
|
---|
6483 | const xml::ElementNode *pDriveChild;
|
---|
6484 | Utf8Str strTmp;
|
---|
6485 | if ( (pDriveChild = pelmHwChild->findChildElement("Image"))
|
---|
6486 | && pDriveChild->getAttributeValue("uuid", strTmp) )
|
---|
6487 | parseUUID(att.uuid, strTmp, pDriveChild);
|
---|
6488 | else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
|
---|
6489 | pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
|
---|
6490 |
|
---|
6491 | // store attachment with controller
|
---|
6492 | sctl.llAttachedDevices.push_back(att);
|
---|
6493 | // store controller with storage
|
---|
6494 | strg.llStorageControllers.push_back(sctl);
|
---|
6495 | }
|
---|
6496 | }
|
---|
6497 | }
|
---|
6498 | }
|
---|
6499 |
|
---|
6500 | /**
|
---|
6501 | * Called for reading the \<Teleporter\> element under \<Machine\>.
|
---|
6502 | */
|
---|
6503 | void MachineConfigFile::readTeleporter(const xml::ElementNode &elmTeleporter,
|
---|
6504 | MachineUserData &userData)
|
---|
6505 | {
|
---|
6506 | elmTeleporter.getAttributeValue("enabled", userData.fTeleporterEnabled);
|
---|
6507 | elmTeleporter.getAttributeValue("port", userData.uTeleporterPort);
|
---|
6508 | elmTeleporter.getAttributeValue("address", userData.strTeleporterAddress);
|
---|
6509 | elmTeleporter.getAttributeValue("password", userData.strTeleporterPassword);
|
---|
6510 |
|
---|
6511 | if ( userData.strTeleporterPassword.isNotEmpty()
|
---|
6512 | && !VBoxIsPasswordHashed(&userData.strTeleporterPassword))
|
---|
6513 | VBoxHashPassword(&userData.strTeleporterPassword);
|
---|
6514 | }
|
---|
6515 |
|
---|
6516 | /**
|
---|
6517 | * Called for reading the \<Debugging\> element under \<Machine\> or \<Snapshot\>.
|
---|
6518 | */
|
---|
6519 | void MachineConfigFile::readDebugging(const xml::ElementNode &elmDebugging, Debugging &dbg)
|
---|
6520 | {
|
---|
6521 | if (m->sv < SettingsVersion_v1_13)
|
---|
6522 | return;
|
---|
6523 |
|
---|
6524 | const xml::ElementNode *pelmTracing = elmDebugging.findChildElement("Tracing");
|
---|
6525 | if (pelmTracing)
|
---|
6526 | {
|
---|
6527 | pelmTracing->getAttributeValue("enabled", dbg.fTracingEnabled);
|
---|
6528 | pelmTracing->getAttributeValue("allowTracingToAccessVM", dbg.fAllowTracingToAccessVM);
|
---|
6529 | pelmTracing->getAttributeValue("config", dbg.strTracingConfig);
|
---|
6530 | }
|
---|
6531 |
|
---|
6532 | const xml::ElementNode *pelmGuestDebug = elmDebugging.findChildElement("GuestDebug");
|
---|
6533 | if (pelmGuestDebug)
|
---|
6534 | {
|
---|
6535 | Utf8Str strTmp;
|
---|
6536 | pelmGuestDebug->getAttributeValue("provider", strTmp);
|
---|
6537 | if (strTmp == "None")
|
---|
6538 | dbg.enmDbgProvider = GuestDebugProvider_None;
|
---|
6539 | else if (strTmp == "GDB")
|
---|
6540 | dbg.enmDbgProvider = GuestDebugProvider_GDB;
|
---|
6541 | else if (strTmp == "KD")
|
---|
6542 | dbg.enmDbgProvider = GuestDebugProvider_KD;
|
---|
6543 | else
|
---|
6544 | throw ConfigFileError(this, pelmGuestDebug, N_("Invalid value '%s' for GuestDebug/@provider attribute"), strTmp.c_str());
|
---|
6545 |
|
---|
6546 | pelmGuestDebug->getAttributeValue("io", strTmp);
|
---|
6547 | if (strTmp == "None")
|
---|
6548 | dbg.enmIoProvider = GuestDebugIoProvider_None;
|
---|
6549 | else if (strTmp == "TCP")
|
---|
6550 | dbg.enmIoProvider = GuestDebugIoProvider_TCP;
|
---|
6551 | else if (strTmp == "UDP")
|
---|
6552 | dbg.enmIoProvider = GuestDebugIoProvider_UDP;
|
---|
6553 | else if (strTmp == "IPC")
|
---|
6554 | dbg.enmIoProvider = GuestDebugIoProvider_IPC;
|
---|
6555 | else
|
---|
6556 | throw ConfigFileError(this, pelmGuestDebug, N_("Invalid value '%s' for GuestDebug/@io attribute"), strTmp.c_str());
|
---|
6557 |
|
---|
6558 | pelmGuestDebug->getAttributeValue("address", dbg.strAddress);
|
---|
6559 | pelmGuestDebug->getAttributeValue("port", dbg.ulPort);
|
---|
6560 | }
|
---|
6561 | }
|
---|
6562 |
|
---|
6563 | /**
|
---|
6564 | * Called for reading the \<Autostart\> element under \<Machine\> or \<Snapshot\>.
|
---|
6565 | */
|
---|
6566 | void MachineConfigFile::readAutostart(const xml::ElementNode &elmAutostart, Autostart &autostrt)
|
---|
6567 | {
|
---|
6568 | Utf8Str strAutostop;
|
---|
6569 |
|
---|
6570 | if (m->sv < SettingsVersion_v1_13)
|
---|
6571 | return;
|
---|
6572 |
|
---|
6573 | elmAutostart.getAttributeValue("enabled", autostrt.fAutostartEnabled);
|
---|
6574 | elmAutostart.getAttributeValue("delay", autostrt.uAutostartDelay);
|
---|
6575 | elmAutostart.getAttributeValue("autostop", strAutostop);
|
---|
6576 | if (strAutostop == "Disabled")
|
---|
6577 | autostrt.enmAutostopType = AutostopType_Disabled;
|
---|
6578 | else if (strAutostop == "SaveState")
|
---|
6579 | autostrt.enmAutostopType = AutostopType_SaveState;
|
---|
6580 | else if (strAutostop == "PowerOff")
|
---|
6581 | autostrt.enmAutostopType = AutostopType_PowerOff;
|
---|
6582 | else if (strAutostop == "AcpiShutdown")
|
---|
6583 | autostrt.enmAutostopType = AutostopType_AcpiShutdown;
|
---|
6584 | else
|
---|
6585 | throw ConfigFileError(this, &elmAutostart, N_("Invalid value '%s' for Autostart/@autostop attribute"), strAutostop.c_str());
|
---|
6586 | }
|
---|
6587 |
|
---|
6588 | /**
|
---|
6589 | * Called for reading the \<VideoCapture\> element under \<Machine|Hardware\>,
|
---|
6590 | * or \<Recording\> under \<Machine\>,
|
---|
6591 | */
|
---|
6592 | void MachineConfigFile::readRecordingSettings(const xml::ElementNode &elmRecording, uint32_t cMonitors, RecordingSettings &recording)
|
---|
6593 | {
|
---|
6594 | if (cMonitors > 64)
|
---|
6595 | throw ConfigFileError(this, &elmRecording, N_("Invalid monitor count given"));
|
---|
6596 |
|
---|
6597 | elmRecording.getAttributeValue("enabled", recording.common.fEnabled);
|
---|
6598 |
|
---|
6599 | /* Note: Since settings 1.19 the recording settings have a dedicated XML branch "Recording" outside of "Hardware". */
|
---|
6600 | if (m->sv >= SettingsVersion_v1_19 /* VBox >= 7.0 */)
|
---|
6601 | {
|
---|
6602 | uint32_t cScreens = 0;
|
---|
6603 | elmRecording.getAttributeValue("screens", cScreens);
|
---|
6604 |
|
---|
6605 | xml::ElementNodesList plstScreens;
|
---|
6606 | elmRecording.getChildElements(plstScreens, "Screen");
|
---|
6607 |
|
---|
6608 | /* Sanity checks. */
|
---|
6609 | if (cScreens != plstScreens.size())
|
---|
6610 | throw ConfigFileError(this, &elmRecording, N_("Recording/@screens attribute does not match stored screen objects"));
|
---|
6611 | if (cScreens > 64)
|
---|
6612 | throw ConfigFileError(this, &elmRecording, N_("Recording/@screens attribute is invalid"));
|
---|
6613 |
|
---|
6614 | for (xml::ElementNodesList::iterator itScreen = plstScreens.begin();
|
---|
6615 | itScreen != plstScreens.end();
|
---|
6616 | ++itScreen)
|
---|
6617 | {
|
---|
6618 | /* The screen's stored ID is the monitor ID and also the key for the map. */
|
---|
6619 | uint32_t idxScreen;
|
---|
6620 | (*itScreen)->getAttributeValue("id", idxScreen);
|
---|
6621 |
|
---|
6622 | RecordingScreenSettings &screenSettings = recording.mapScreens[idxScreen];
|
---|
6623 |
|
---|
6624 | (*itScreen)->getAttributeValue("enabled", screenSettings.fEnabled);
|
---|
6625 | Utf8Str strTemp;
|
---|
6626 | (*itScreen)->getAttributeValue("featuresEnabled", strTemp);
|
---|
6627 | RecordingScreenSettings::featuresFromString(strTemp, screenSettings.featureMap);
|
---|
6628 | (*itScreen)->getAttributeValue("maxTimeS", screenSettings.ulMaxTimeS);
|
---|
6629 | (*itScreen)->getAttributeValue("options", screenSettings.strOptions);
|
---|
6630 | (*itScreen)->getAttributeValue("dest", (uint32_t &)screenSettings.enmDest);
|
---|
6631 | if (screenSettings.enmDest == RecordingDestination_File)
|
---|
6632 | (*itScreen)->getAttributeValuePath("file", screenSettings.File.strName);
|
---|
6633 | else
|
---|
6634 | throw ConfigFileError(this, (*itScreen),
|
---|
6635 | N_("Not supported Recording/@dest attribute '%#x'"), screenSettings.enmDest);
|
---|
6636 | (*itScreen)->getAttributeValue("maxSizeMB", screenSettings.File.ulMaxSizeMB);
|
---|
6637 | if ((*itScreen)->getAttributeValue("videoCodec", strTemp)) /* Stick with default if not set. */
|
---|
6638 | RecordingScreenSettings::videoCodecFromString(strTemp, screenSettings.Video.enmCodec);
|
---|
6639 | (*itScreen)->getAttributeValue("videoDeadline", (uint32_t &)screenSettings.Video.enmDeadline);
|
---|
6640 | (*itScreen)->getAttributeValue("videoRateCtlMode", (uint32_t &)screenSettings.Video.enmRateCtlMode);
|
---|
6641 | (*itScreen)->getAttributeValue("videoScalingMode", (uint32_t &)screenSettings.Video.enmScalingMode);
|
---|
6642 | (*itScreen)->getAttributeValue("horzRes", screenSettings.Video.ulWidth);
|
---|
6643 | (*itScreen)->getAttributeValue("vertRes", screenSettings.Video.ulHeight);
|
---|
6644 | (*itScreen)->getAttributeValue("rateKbps", screenSettings.Video.ulRate);
|
---|
6645 | (*itScreen)->getAttributeValue("fps", screenSettings.Video.ulFPS);
|
---|
6646 |
|
---|
6647 | if ((*itScreen)->getAttributeValue("audioCodec", strTemp)) /* Stick with default if not set. */
|
---|
6648 | RecordingScreenSettings::audioCodecFromString(strTemp, screenSettings.Audio.enmCodec);
|
---|
6649 | (*itScreen)->getAttributeValue("audioDeadline", (uint32_t &)screenSettings.Audio.enmDeadline);
|
---|
6650 | (*itScreen)->getAttributeValue("audioRateCtlMode", (uint32_t &)screenSettings.Audio.enmRateCtlMode);
|
---|
6651 | (*itScreen)->getAttributeValue("audioHz", (uint32_t &)screenSettings.Audio.uHz);
|
---|
6652 | (*itScreen)->getAttributeValue("audioBits", (uint32_t &)screenSettings.Audio.cBits);
|
---|
6653 | (*itScreen)->getAttributeValue("audioChannels", (uint32_t &)screenSettings.Audio.cChannels);
|
---|
6654 | }
|
---|
6655 | }
|
---|
6656 | else if ( m->sv >= SettingsVersion_v1_14
|
---|
6657 | && m->sv < SettingsVersion_v1_19 /* VBox < 7.0 */)
|
---|
6658 | {
|
---|
6659 | /* For settings < 1.19 (< VBox 7.0) we only support one recording configuration, that is,
|
---|
6660 | * all screens have the same configuration. So load/save to/from screen 0. */
|
---|
6661 | RecordingScreenSettings &screen0 = recording.mapScreens[0];
|
---|
6662 |
|
---|
6663 | elmRecording.getAttributeValue("maxTime", screen0.ulMaxTimeS);
|
---|
6664 | elmRecording.getAttributeValue("options", screen0.strOptions);
|
---|
6665 | elmRecording.getAttributeValuePath("file", screen0.File.strName);
|
---|
6666 | elmRecording.getAttributeValue("maxSize", screen0.File.ulMaxSizeMB);
|
---|
6667 | elmRecording.getAttributeValue("horzRes", screen0.Video.ulWidth);
|
---|
6668 | elmRecording.getAttributeValue("vertRes", screen0.Video.ulHeight);
|
---|
6669 | elmRecording.getAttributeValue("rate", screen0.Video.ulRate);
|
---|
6670 | elmRecording.getAttributeValue("fps", screen0.Video.ulFPS);
|
---|
6671 |
|
---|
6672 | /* Convert the enabled screens to the former uint64_t bit array and vice versa. */
|
---|
6673 | uint64_t uScreensBitmap = 0;
|
---|
6674 | elmRecording.getAttributeValue("screens", uScreensBitmap);
|
---|
6675 |
|
---|
6676 | /* Note: For settings < 1.19 the "screens" attribute is a bit field for all screens
|
---|
6677 | * which are ENABLED for recording. The settings for recording are for all the same though. */
|
---|
6678 | for (unsigned i = 0; i < cMonitors; i++)
|
---|
6679 | {
|
---|
6680 | /* Apply settings of screen 0 to screen i and enable it. */
|
---|
6681 | recording.mapScreens[i] = screen0;
|
---|
6682 |
|
---|
6683 | /* Screen i enabled? */
|
---|
6684 | recording.mapScreens[i].idScreen = i;
|
---|
6685 | recording.mapScreens[i].fEnabled = RT_BOOL(uScreensBitmap & RT_BIT_64(i));
|
---|
6686 | }
|
---|
6687 | }
|
---|
6688 | }
|
---|
6689 |
|
---|
6690 | /**
|
---|
6691 | * Called for reading the \<Groups\> element under \<Machine\>.
|
---|
6692 | */
|
---|
6693 | void MachineConfigFile::readGroups(const xml::ElementNode &elmGroups, StringsList &llGroups)
|
---|
6694 | {
|
---|
6695 | llGroups.clear();
|
---|
6696 | if (m->sv < SettingsVersion_v1_13)
|
---|
6697 | {
|
---|
6698 | llGroups.push_back("/");
|
---|
6699 | return;
|
---|
6700 | }
|
---|
6701 |
|
---|
6702 | xml::NodesLoop nlGroups(elmGroups);
|
---|
6703 | const xml::ElementNode *pelmGroup;
|
---|
6704 | while ((pelmGroup = nlGroups.forAllNodes()))
|
---|
6705 | {
|
---|
6706 | if (pelmGroup->nameEquals("Group"))
|
---|
6707 | {
|
---|
6708 | Utf8Str strGroup;
|
---|
6709 | if (!pelmGroup->getAttributeValue("name", strGroup))
|
---|
6710 | throw ConfigFileError(this, pelmGroup, N_("Required Group/@name attribute is missing"));
|
---|
6711 | llGroups.push_back(strGroup);
|
---|
6712 | }
|
---|
6713 | }
|
---|
6714 | }
|
---|
6715 |
|
---|
6716 | /**
|
---|
6717 | * Called initially for the \<Snapshot\> element under \<Machine\>, if present,
|
---|
6718 | * to store the snapshot's data into the given Snapshot structure (which is
|
---|
6719 | * then the one in the Machine struct). This might process further elements
|
---|
6720 | * of the snapshot tree if a \<Snapshots\> (plural) element is found in the
|
---|
6721 | * snapshot, which should contain a list of child snapshots; such lists are
|
---|
6722 | * maintained in the Snapshot structure.
|
---|
6723 | *
|
---|
6724 | * @param curSnapshotUuid
|
---|
6725 | * @param elmSnapshot
|
---|
6726 | * @param snap
|
---|
6727 | * @returns true if curSnapshotUuid is in this snapshot subtree, otherwise false
|
---|
6728 | */
|
---|
6729 | bool MachineConfigFile::readSnapshot(const Guid &curSnapshotUuid,
|
---|
6730 | const xml::ElementNode &elmSnapshot,
|
---|
6731 | Snapshot &snap)
|
---|
6732 | {
|
---|
6733 | std::list<const xml::ElementNode *> llElementsTodo;
|
---|
6734 | llElementsTodo.push_back(&elmSnapshot);
|
---|
6735 | std::list<Snapshot *> llSettingsTodo;
|
---|
6736 | llSettingsTodo.push_back(&snap);
|
---|
6737 | std::list<uint32_t> llDepthsTodo;
|
---|
6738 | llDepthsTodo.push_back(1);
|
---|
6739 |
|
---|
6740 | bool foundCurrentSnapshot = false;
|
---|
6741 |
|
---|
6742 | while (llElementsTodo.size() > 0)
|
---|
6743 | {
|
---|
6744 | const xml::ElementNode *pElement = llElementsTodo.front();
|
---|
6745 | llElementsTodo.pop_front();
|
---|
6746 | Snapshot *pSnap = llSettingsTodo.front();
|
---|
6747 | llSettingsTodo.pop_front();
|
---|
6748 | uint32_t depth = llDepthsTodo.front();
|
---|
6749 | llDepthsTodo.pop_front();
|
---|
6750 |
|
---|
6751 | if (depth > SETTINGS_SNAPSHOT_DEPTH_MAX)
|
---|
6752 | throw ConfigFileError(this, pElement, N_("Maximum snapshot tree depth of %u exceeded"), SETTINGS_SNAPSHOT_DEPTH_MAX);
|
---|
6753 |
|
---|
6754 | Utf8Str strTemp;
|
---|
6755 | if (!pElement->getAttributeValue("uuid", strTemp))
|
---|
6756 | throw ConfigFileError(this, pElement, N_("Required Snapshot/@uuid attribute is missing"));
|
---|
6757 | parseUUID(pSnap->uuid, strTemp, pElement);
|
---|
6758 | foundCurrentSnapshot |= (pSnap->uuid == curSnapshotUuid);
|
---|
6759 |
|
---|
6760 | if (!pElement->getAttributeValue("name", pSnap->strName))
|
---|
6761 | throw ConfigFileError(this, pElement, N_("Required Snapshot/@name attribute is missing"));
|
---|
6762 |
|
---|
6763 | // 3.1 dev builds added Description as an attribute, read it silently
|
---|
6764 | // and write it back as an element
|
---|
6765 | pElement->getAttributeValue("Description", pSnap->strDescription);
|
---|
6766 |
|
---|
6767 | if (!pElement->getAttributeValue("timeStamp", strTemp))
|
---|
6768 | throw ConfigFileError(this, pElement, N_("Required Snapshot/@timeStamp attribute is missing"));
|
---|
6769 | parseTimestamp(pSnap->timestamp, strTemp, pElement);
|
---|
6770 |
|
---|
6771 | pElement->getAttributeValuePath("stateFile", pSnap->strStateFile); // online snapshots only
|
---|
6772 |
|
---|
6773 | /* We read the platform settings here for newer settings (>= v1.20).
|
---|
6774 | * For older settings (< v1.20) we read the platform settings in readHardware(). */
|
---|
6775 | if (m->sv >= SettingsVersion_v1_20)
|
---|
6776 | {
|
---|
6777 | const xml::ElementNode *pelmPlatform;
|
---|
6778 | if (!(pelmPlatform = pElement->findChildElement("Platform")))
|
---|
6779 | throw ConfigFileError(this, pElement, N_("Required Snapshot/@Platform element is missing"));
|
---|
6780 | readPlatform(*pelmPlatform, pSnap->hardware, pSnap->hardware.platformSettings);
|
---|
6781 | }
|
---|
6782 |
|
---|
6783 | // parse Hardware before the other elements because other things depend on it
|
---|
6784 | const xml::ElementNode *pelmHardware;
|
---|
6785 | if (!(pelmHardware = pElement->findChildElement("Hardware")))
|
---|
6786 | throw ConfigFileError(this, pElement, N_("Required Snapshot/@Hardware element is missing"));
|
---|
6787 | readHardware(*pelmHardware, pSnap->hardware);
|
---|
6788 |
|
---|
6789 | const xml::ElementNode *pelmSnapshots = NULL;
|
---|
6790 |
|
---|
6791 | xml::NodesLoop nlSnapshotChildren(*pElement);
|
---|
6792 | const xml::ElementNode *pelmSnapshotChild;
|
---|
6793 | while ((pelmSnapshotChild = nlSnapshotChildren.forAllNodes()))
|
---|
6794 | {
|
---|
6795 | if (pelmSnapshotChild->nameEquals("Description"))
|
---|
6796 | pSnap->strDescription = pelmSnapshotChild->getValue();
|
---|
6797 | else if ( m->sv < SettingsVersion_v1_7
|
---|
6798 | && pelmSnapshotChild->nameEquals("HardDiskAttachments"))
|
---|
6799 | readHardDiskAttachments_pre1_7(*pelmSnapshotChild, pSnap->hardware.storage);
|
---|
6800 | else if ( m->sv >= SettingsVersion_v1_7
|
---|
6801 | && pelmSnapshotChild->nameEquals("StorageControllers"))
|
---|
6802 | readStorageControllers(*pelmSnapshotChild, pSnap->hardware.storage);
|
---|
6803 | else if (pelmSnapshotChild->nameEquals("Snapshots"))
|
---|
6804 | {
|
---|
6805 | if (pelmSnapshots)
|
---|
6806 | throw ConfigFileError(this, pelmSnapshotChild, N_("Just a single Snapshots element is allowed"));
|
---|
6807 | pelmSnapshots = pelmSnapshotChild;
|
---|
6808 | }
|
---|
6809 | }
|
---|
6810 |
|
---|
6811 | if (m->sv < SettingsVersion_v1_9)
|
---|
6812 | // go through Hardware once more to repair the settings controller structures
|
---|
6813 | // with data from old DVDDrive and FloppyDrive elements
|
---|
6814 | readDVDAndFloppies_pre1_9(*pelmHardware, pSnap->hardware.storage);
|
---|
6815 |
|
---|
6816 | const xml::ElementNode *pelmDebugging = elmSnapshot.findChildElement("Debugging"); /** @todo r=andy Shouldn't this be pElement instead of elmSnapshot? Re-visit this! */
|
---|
6817 | if (pelmDebugging)
|
---|
6818 | readDebugging(*pelmDebugging, pSnap->debugging);
|
---|
6819 | const xml::ElementNode *pelmAutostart = elmSnapshot.findChildElement("Autostart"); /** @todo r=andy Ditto. */
|
---|
6820 | if (pelmAutostart)
|
---|
6821 | readAutostart(*pelmAutostart, pSnap->autostart);
|
---|
6822 | if (m->sv < SettingsVersion_v1_19)
|
---|
6823 | {
|
---|
6824 | const xml::ElementNode *pelmVideoCapture = pElement->findChildElement("VideoCapture");
|
---|
6825 | if (pelmVideoCapture)
|
---|
6826 | readRecordingSettings(*pelmVideoCapture, pSnap->hardware.graphicsAdapter.cMonitors, pSnap->recordingSettings);
|
---|
6827 | }
|
---|
6828 | else /* >= VBox 7.0 */
|
---|
6829 | {
|
---|
6830 | const xml::ElementNode *pelmRecording = pElement->findChildElement("Recording");
|
---|
6831 | if (pelmRecording)
|
---|
6832 | readRecordingSettings(*pelmRecording, pSnap->hardware.graphicsAdapter.cMonitors, pSnap->recordingSettings);
|
---|
6833 | }
|
---|
6834 | // note: Groups exist only for Machine, not for Snapshot
|
---|
6835 |
|
---|
6836 | // process all child snapshots
|
---|
6837 | if (pelmSnapshots)
|
---|
6838 | {
|
---|
6839 | xml::NodesLoop nlChildSnapshots(*pelmSnapshots);
|
---|
6840 | const xml::ElementNode *pelmChildSnapshot;
|
---|
6841 | while ((pelmChildSnapshot = nlChildSnapshots.forAllNodes()))
|
---|
6842 | {
|
---|
6843 | if (pelmChildSnapshot->nameEquals("Snapshot"))
|
---|
6844 | {
|
---|
6845 | llElementsTodo.push_back(pelmChildSnapshot);
|
---|
6846 | pSnap->llChildSnapshots.push_back(Snapshot::Empty);
|
---|
6847 | llSettingsTodo.push_back(&pSnap->llChildSnapshots.back());
|
---|
6848 | llDepthsTodo.push_back(depth + 1);
|
---|
6849 | }
|
---|
6850 | }
|
---|
6851 | }
|
---|
6852 | }
|
---|
6853 |
|
---|
6854 | return foundCurrentSnapshot;
|
---|
6855 | }
|
---|
6856 |
|
---|
6857 | static struct
|
---|
6858 | {
|
---|
6859 | const char *pcszOld;
|
---|
6860 | const char *pcszNew;
|
---|
6861 | } const g_aConvertGuestOSTypesPre1_5[] =
|
---|
6862 | {
|
---|
6863 | { "unknown", GUEST_OS_ID_STR_X86("Other") },
|
---|
6864 | { "dos", GUEST_OS_ID_STR_X86("DOS") },
|
---|
6865 | { "win31", GUEST_OS_ID_STR_X86("Windows31") },
|
---|
6866 | { "win95", GUEST_OS_ID_STR_X86("Windows95") },
|
---|
6867 | { "win98", GUEST_OS_ID_STR_X86("Windows98") },
|
---|
6868 | { "winme", GUEST_OS_ID_STR_X86("WindowsMe") },
|
---|
6869 | { "winnt4", GUEST_OS_ID_STR_X86("WindowsNT4") },
|
---|
6870 | { "win2k", GUEST_OS_ID_STR_X86("Windows2000") },
|
---|
6871 | { "winxp", GUEST_OS_ID_STR_X86("WindowsXP") },
|
---|
6872 | { "win2k3", GUEST_OS_ID_STR_X86("Windows2003") },
|
---|
6873 | { "winvista", GUEST_OS_ID_STR_X86("WindowsVista") },
|
---|
6874 | { "win2k8", GUEST_OS_ID_STR_X86("Windows2008") },
|
---|
6875 | { "os2warp3", GUEST_OS_ID_STR_X86("OS2Warp3") },
|
---|
6876 | { "os2warp4", GUEST_OS_ID_STR_X86("OS2Warp4") },
|
---|
6877 | { "os2warp45", GUEST_OS_ID_STR_X86("OS2Warp45") },
|
---|
6878 | { "ecs", GUEST_OS_ID_STR_X86("OS2eCS") },
|
---|
6879 | { "linux22", GUEST_OS_ID_STR_X86("Linux22") },
|
---|
6880 | { "linux24", GUEST_OS_ID_STR_X86("Linux24") },
|
---|
6881 | { "linux26", GUEST_OS_ID_STR_X86("Linux26") },
|
---|
6882 | { "archlinux", GUEST_OS_ID_STR_X86("ArchLinux") },
|
---|
6883 | { "debian", GUEST_OS_ID_STR_X86("Debian") },
|
---|
6884 | { "opensuse", GUEST_OS_ID_STR_X86("OpenSUSE") },
|
---|
6885 | { "fedoracore", GUEST_OS_ID_STR_X86("Fedora") },
|
---|
6886 | { "gentoo", GUEST_OS_ID_STR_X86("Gentoo") },
|
---|
6887 | { "mandriva", GUEST_OS_ID_STR_X86("Mandriva") },
|
---|
6888 | { "redhat", GUEST_OS_ID_STR_X86("RedHat") },
|
---|
6889 | { "ubuntu", GUEST_OS_ID_STR_X86("Ubuntu") },
|
---|
6890 | { "xandros", GUEST_OS_ID_STR_X86("Xandros") },
|
---|
6891 | { "freebsd", GUEST_OS_ID_STR_X86("FreeBSD") },
|
---|
6892 | { "openbsd", GUEST_OS_ID_STR_X86("OpenBSD") },
|
---|
6893 | { "netbsd", GUEST_OS_ID_STR_X86("NetBSD") },
|
---|
6894 | { "netware", GUEST_OS_ID_STR_X86("Netware") },
|
---|
6895 | { "solaris", GUEST_OS_ID_STR_X86("Solaris") },
|
---|
6896 | { "opensolaris", GUEST_OS_ID_STR_X86("OpenSolaris") },
|
---|
6897 | { "l4", GUEST_OS_ID_STR_X86("L4") },
|
---|
6898 | };
|
---|
6899 |
|
---|
6900 | /* static */
|
---|
6901 | void MachineConfigFile::convertGuestOSTypeFromPre1_5(Utf8Str &str)
|
---|
6902 | {
|
---|
6903 | for (size_t idx = 0; idx < RT_ELEMENTS(g_aConvertGuestOSTypesPre1_5); ++idx)
|
---|
6904 | if (str == g_aConvertGuestOSTypesPre1_5[idx].pcszOld)
|
---|
6905 | {
|
---|
6906 | str = g_aConvertGuestOSTypesPre1_5[idx].pcszNew;
|
---|
6907 | break;
|
---|
6908 | }
|
---|
6909 | }
|
---|
6910 |
|
---|
6911 | /**
|
---|
6912 | * Worker function that converts the suffix of a guest OS type ID.
|
---|
6913 | *
|
---|
6914 | * @param a_rstrOsType Guest OS type ID to convert.
|
---|
6915 | * @param a_pszToReplace Suffix to replace.
|
---|
6916 | * @param a_pszReplacement What to replace the suffix with.
|
---|
6917 | */
|
---|
6918 | /* static */
|
---|
6919 | void MachineConfigFile::convertGuestOSTypeSuffix(com::Utf8Str &a_rstrOsType,
|
---|
6920 | const char *a_pszToReplace, const char *a_pszReplacement)
|
---|
6921 | {
|
---|
6922 | size_t const cchToReplace = strlen(a_pszToReplace);
|
---|
6923 | if (a_rstrOsType.endsWith(a_pszToReplace, cchToReplace))
|
---|
6924 | a_rstrOsType.replace(a_rstrOsType.length() - cchToReplace, cchToReplace, a_pszReplacement);
|
---|
6925 | }
|
---|
6926 |
|
---|
6927 | #ifdef GUEST_OS_ID_STYLE_PARTIAL_CLEANUP
|
---|
6928 |
|
---|
6929 | /**
|
---|
6930 | * Converts guest OS type IDs to be compatible with settings >= v1.20.
|
---|
6931 | *
|
---|
6932 | * @param str Guest OS type ID to convert.
|
---|
6933 | *
|
---|
6934 | * @note Settings < v1.20 require converting some guest OS type IDs, so that the rest of Main can recognize them.
|
---|
6935 | * We always work with the latest guest OS type ID internally.
|
---|
6936 | *
|
---|
6937 | * However, we never write back those modified guest OS type IDs for settings < v1.20, as this would break
|
---|
6938 | * compatibility with older VBox versions.
|
---|
6939 | */
|
---|
6940 | /* static */
|
---|
6941 | void MachineConfigFile::convertGuestOSTypeFromPre1_20(Utf8Str &str)
|
---|
6942 | {
|
---|
6943 | convertGuestOSTypeSuffix(str, "_64", "_x64");
|
---|
6944 | }
|
---|
6945 |
|
---|
6946 | /**
|
---|
6947 | * Converts guest OS type IDs to be compatible with settings < v1.20.
|
---|
6948 | *
|
---|
6949 | * @param str Guest OS type ID to convert.
|
---|
6950 | *
|
---|
6951 | * @note For settings < v1.20 we have to make sure that we replace the new guest OS type ID suffix "_x64"
|
---|
6952 | * with "_64" so that we don't break loading (valid) settings for old(er) VBox versions, which don't
|
---|
6953 | * know about the new suffix.
|
---|
6954 | */
|
---|
6955 | /* static */
|
---|
6956 | void MachineConfigFile::convertGuestOSTypeToPre1_20(Utf8Str &str)
|
---|
6957 | {
|
---|
6958 | convertGuestOSTypeSuffix(str, "_x64", "_64");
|
---|
6959 | }
|
---|
6960 |
|
---|
6961 | #else /* !GUEST_OS_ID_STYLE_PARTIAL_CLEANUP */
|
---|
6962 |
|
---|
6963 | /**
|
---|
6964 | * Undoes effects of the 'OSTYPEID_64' to 'OSTYPEID_x64' renaming attempt from
|
---|
6965 | * the VBox v7.1 development cycle on @a a_rstrOsType.
|
---|
6966 | *
|
---|
6967 | * @see @bugref{10384#c18}
|
---|
6968 | */
|
---|
6969 | /* static */
|
---|
6970 | void MachineConfigFile::convertGuestOSTypeFromDev1_20(Utf8Str &a_rstrOsType)
|
---|
6971 | {
|
---|
6972 | convertGuestOSTypeSuffix(a_rstrOsType, "_x64", "_64");
|
---|
6973 | }
|
---|
6974 |
|
---|
6975 | #endif /* !GUEST_OS_ID_STYLE_PARTIAL_CLEANUP */
|
---|
6976 |
|
---|
6977 |
|
---|
6978 | /**
|
---|
6979 | * Called from the constructor to actually read in the \<Machine\> element
|
---|
6980 | * of a machine config file.
|
---|
6981 | * @param elmMachine
|
---|
6982 | */
|
---|
6983 | void MachineConfigFile::readMachine(const xml::ElementNode &elmMachine)
|
---|
6984 | {
|
---|
6985 | Utf8Str strUUID;
|
---|
6986 | if ( elmMachine.getAttributeValue("uuid", strUUID)
|
---|
6987 | && elmMachine.getAttributeValue("name", machineUserData.strName))
|
---|
6988 | {
|
---|
6989 | parseUUID(uuid, strUUID, &elmMachine);
|
---|
6990 |
|
---|
6991 | elmMachine.getAttributeValue("directoryIncludesUUID", machineUserData.fDirectoryIncludesUUID);
|
---|
6992 | elmMachine.getAttributeValue("nameSync", machineUserData.fNameSync);
|
---|
6993 |
|
---|
6994 | Utf8Str str;
|
---|
6995 | elmMachine.getAttributeValue("Description", machineUserData.strDescription);
|
---|
6996 | elmMachine.getAttributeValue("OSType", machineUserData.strOsType);
|
---|
6997 | if (m->sv < SettingsVersion_v1_5)
|
---|
6998 | convertGuestOSTypeFromPre1_5(machineUserData.strOsType);
|
---|
6999 | #ifdef GUEST_OS_ID_STYLE_PARTIAL_CLEANUP
|
---|
7000 | if (m->sv <= SettingsVersion_v1_19)
|
---|
7001 | convertGuestOSTypeFromPre1_20(machineUserData.strOsType);
|
---|
7002 | #else
|
---|
7003 | if (m->sv == SettingsVersion_v1_20)
|
---|
7004 | convertGuestOSTypeFromDev1_20(machineUserData.strOsType);
|
---|
7005 | #endif
|
---|
7006 | elmMachine.getAttributeValue("stateKeyId", strStateKeyId);
|
---|
7007 | elmMachine.getAttributeValue("stateKeyStore", strStateKeyStore);
|
---|
7008 | elmMachine.getAttributeValuePath("stateFile", strStateFile);
|
---|
7009 |
|
---|
7010 | elmMachine.getAttributeValue("logKeyId", strLogKeyId);
|
---|
7011 | elmMachine.getAttributeValue("logKeyStore", strLogKeyStore);
|
---|
7012 |
|
---|
7013 | if (elmMachine.getAttributeValue("currentSnapshot", str))
|
---|
7014 | parseUUID(uuidCurrentSnapshot, str, &elmMachine);
|
---|
7015 |
|
---|
7016 | elmMachine.getAttributeValuePath("snapshotFolder", machineUserData.strSnapshotFolder);
|
---|
7017 |
|
---|
7018 | if (!elmMachine.getAttributeValue("currentStateModified", fCurrentStateModified))
|
---|
7019 | fCurrentStateModified = true;
|
---|
7020 | if (elmMachine.getAttributeValue("lastStateChange", str))
|
---|
7021 | parseTimestamp(timeLastStateChange, str, &elmMachine);
|
---|
7022 | // constructor has called RTTimeNow(&timeLastStateChange) before
|
---|
7023 | if (elmMachine.getAttributeValue("aborted", fAborted))
|
---|
7024 | fAborted = true;
|
---|
7025 |
|
---|
7026 | {
|
---|
7027 | Utf8Str strVMPriority;
|
---|
7028 | if (elmMachine.getAttributeValue("processPriority", strVMPriority))
|
---|
7029 | {
|
---|
7030 | if (strVMPriority == "Flat")
|
---|
7031 | machineUserData.enmVMPriority = VMProcPriority_Flat;
|
---|
7032 | else if (strVMPriority == "Low")
|
---|
7033 | machineUserData.enmVMPriority = VMProcPriority_Low;
|
---|
7034 | else if (strVMPriority == "Normal")
|
---|
7035 | machineUserData.enmVMPriority = VMProcPriority_Normal;
|
---|
7036 | else if (strVMPriority == "High")
|
---|
7037 | machineUserData.enmVMPriority = VMProcPriority_High;
|
---|
7038 | else
|
---|
7039 | machineUserData.enmVMPriority = VMProcPriority_Default;
|
---|
7040 | }
|
---|
7041 | }
|
---|
7042 |
|
---|
7043 | {
|
---|
7044 | Utf8Str strExecEngine;
|
---|
7045 | if (elmMachine.getAttributeValue("executionEngine", strExecEngine))
|
---|
7046 | {
|
---|
7047 | if (strExecEngine == "HwVirt")
|
---|
7048 | machineUserData.enmExecEngine = VMExecutionEngine_HwVirt;
|
---|
7049 | else if (strExecEngine == "NativeApi")
|
---|
7050 | machineUserData.enmExecEngine = VMExecutionEngine_NativeApi;
|
---|
7051 | else if (strExecEngine == "Interpreter")
|
---|
7052 | machineUserData.enmExecEngine = VMExecutionEngine_Interpreter;
|
---|
7053 | else if (strExecEngine == "Recompiler")
|
---|
7054 | machineUserData.enmExecEngine = VMExecutionEngine_Recompiler;
|
---|
7055 | else
|
---|
7056 | machineUserData.enmExecEngine = VMExecutionEngine_Default;
|
---|
7057 | }
|
---|
7058 | }
|
---|
7059 |
|
---|
7060 | str.setNull();
|
---|
7061 | elmMachine.getAttributeValue("icon", str);
|
---|
7062 | parseBase64(machineUserData.ovIcon, str, &elmMachine);
|
---|
7063 |
|
---|
7064 | /* We read the platform settings here for newer settings (>= v1.20).
|
---|
7065 | * For older settings (< v1.20) we read the platform settings in readHardware(). */
|
---|
7066 | if (m->sv >= SettingsVersion_v1_20)
|
---|
7067 | {
|
---|
7068 | const xml::ElementNode *pelmPlatform;
|
---|
7069 | if (!(pelmPlatform = elmMachine.findChildElement("Platform")))
|
---|
7070 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/@Platform element is missing"));
|
---|
7071 | readPlatform(*pelmPlatform, hardwareMachine, hardwareMachine.platformSettings);
|
---|
7072 | }
|
---|
7073 |
|
---|
7074 | // parse Hardware before the other elements because other things depend on it
|
---|
7075 | const xml::ElementNode *pelmHardware;
|
---|
7076 | if (!(pelmHardware = elmMachine.findChildElement("Hardware")))
|
---|
7077 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/@Hardware element is missing"));
|
---|
7078 | readHardware(*pelmHardware, hardwareMachine);
|
---|
7079 |
|
---|
7080 | xml::NodesLoop nlRootChildren(elmMachine);
|
---|
7081 | const xml::ElementNode *pelmMachineChild;
|
---|
7082 | while ((pelmMachineChild = nlRootChildren.forAllNodes()))
|
---|
7083 | {
|
---|
7084 | if (pelmMachineChild->nameEquals("ExtraData"))
|
---|
7085 | readExtraData(*pelmMachineChild,
|
---|
7086 | mapExtraDataItems);
|
---|
7087 | else if ( (m->sv < SettingsVersion_v1_7)
|
---|
7088 | && (pelmMachineChild->nameEquals("HardDiskAttachments"))
|
---|
7089 | )
|
---|
7090 | readHardDiskAttachments_pre1_7(*pelmMachineChild, hardwareMachine.storage);
|
---|
7091 | else if ( (m->sv >= SettingsVersion_v1_7)
|
---|
7092 | && (pelmMachineChild->nameEquals("StorageControllers"))
|
---|
7093 | )
|
---|
7094 | readStorageControllers(*pelmMachineChild, hardwareMachine.storage);
|
---|
7095 | else if (pelmMachineChild->nameEquals("Snapshot"))
|
---|
7096 | {
|
---|
7097 | if (uuidCurrentSnapshot.isZero())
|
---|
7098 | throw ConfigFileError(this, &elmMachine, N_("Snapshots present but required Machine/@currentSnapshot attribute is missing"));
|
---|
7099 | bool foundCurrentSnapshot = false;
|
---|
7100 | // Work directly with the target list, because otherwise
|
---|
7101 | // the entire snapshot settings tree will need to be copied,
|
---|
7102 | // and the usual STL implementation needs a lot of stack space.
|
---|
7103 | llFirstSnapshot.push_back(Snapshot::Empty);
|
---|
7104 | // this will also read all child snapshots
|
---|
7105 | foundCurrentSnapshot = readSnapshot(uuidCurrentSnapshot, *pelmMachineChild, llFirstSnapshot.back());
|
---|
7106 | if (!foundCurrentSnapshot)
|
---|
7107 | throw ConfigFileError(this, &elmMachine, N_("Snapshots present but none matches the UUID in the Machine/@currentSnapshot attribute"));
|
---|
7108 | }
|
---|
7109 | else if (pelmMachineChild->nameEquals("Description"))
|
---|
7110 | machineUserData.strDescription = pelmMachineChild->getValue();
|
---|
7111 | else if (pelmMachineChild->nameEquals("Teleporter"))
|
---|
7112 | readTeleporter(*pelmMachineChild, machineUserData);
|
---|
7113 | else if (pelmMachineChild->nameEquals("MediaRegistry"))
|
---|
7114 | readMediaRegistry(*pelmMachineChild, mediaRegistry);
|
---|
7115 | else if (pelmMachineChild->nameEquals("Debugging"))
|
---|
7116 | readDebugging(*pelmMachineChild, debugging);
|
---|
7117 | else if (pelmMachineChild->nameEquals("Autostart"))
|
---|
7118 | readAutostart(*pelmMachineChild, autostart);
|
---|
7119 | else if (pelmMachineChild->nameEquals("Groups"))
|
---|
7120 | readGroups(*pelmMachineChild, machineUserData.llGroups);
|
---|
7121 |
|
---|
7122 | if ( m->sv >= SettingsVersion_v1_14
|
---|
7123 | && m->sv < SettingsVersion_v1_19
|
---|
7124 | && pelmMachineChild->nameEquals("VideoCapture")) /* For settings >= 1.14 (< VBox 7.0). */
|
---|
7125 | readRecordingSettings(*pelmMachineChild, hardwareMachine.graphicsAdapter.cMonitors, recordingSettings);
|
---|
7126 | else if ( m->sv >= SettingsVersion_v1_19
|
---|
7127 | && pelmMachineChild->nameEquals("Recording")) /* Only exists for settings >= 1.19 (VBox 7.0). */
|
---|
7128 | readRecordingSettings(*pelmMachineChild, hardwareMachine.graphicsAdapter.cMonitors, recordingSettings);
|
---|
7129 | }
|
---|
7130 |
|
---|
7131 | if (m->sv < SettingsVersion_v1_9)
|
---|
7132 | // go through Hardware once more to repair the settings controller structures
|
---|
7133 | // with data from old DVDDrive and FloppyDrive elements
|
---|
7134 | readDVDAndFloppies_pre1_9(*pelmHardware, hardwareMachine.storage);
|
---|
7135 | }
|
---|
7136 | else
|
---|
7137 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/@uuid or @name attributes is missing"));
|
---|
7138 | }
|
---|
7139 |
|
---|
7140 | /**
|
---|
7141 | * Called from the constructor to decrypt the machine config and read
|
---|
7142 | * data from it.
|
---|
7143 | * @param elmMachine
|
---|
7144 | * @param pCryptoIf Pointer to the cryptographic interface.
|
---|
7145 | * @param pszPassword The password to decrypt the config with.
|
---|
7146 | */
|
---|
7147 | void MachineConfigFile::readMachineEncrypted(const xml::ElementNode &elmMachine,
|
---|
7148 | PCVBOXCRYPTOIF pCryptoIf = NULL,
|
---|
7149 | const char *pszPassword = NULL)
|
---|
7150 | {
|
---|
7151 | Utf8Str strUUID;
|
---|
7152 | if (elmMachine.getAttributeValue("uuid", strUUID))
|
---|
7153 | {
|
---|
7154 | parseUUID(uuid, strUUID, &elmMachine);
|
---|
7155 | if (!elmMachine.getAttributeValue("keyId", strKeyId))
|
---|
7156 | throw ConfigFileError(this, &elmMachine, N_("Required MachineEncrypted/@keyId attribute is missing"));
|
---|
7157 | if (!elmMachine.getAttributeValue("keyStore", strKeyStore))
|
---|
7158 | throw ConfigFileError(this, &elmMachine, N_("Required MachineEncrypted/@keyStore attribute is missing"));
|
---|
7159 |
|
---|
7160 | if (!pszPassword)
|
---|
7161 | {
|
---|
7162 | enmParseState = ParseState_PasswordError;
|
---|
7163 | return;
|
---|
7164 | }
|
---|
7165 |
|
---|
7166 | VBOXCRYPTOCTX hCryptoCtx = NULL;
|
---|
7167 | int vrc = pCryptoIf->pfnCryptoCtxLoad(strKeyStore.c_str(), pszPassword, &hCryptoCtx);
|
---|
7168 | if (RT_SUCCESS(vrc))
|
---|
7169 | {
|
---|
7170 | com::Utf8Str str = elmMachine.getValue();
|
---|
7171 | IconBlob abEncrypted; /** @todo Rename IconBlob because this is not about icons. */
|
---|
7172 | /** @todo This is not nice. */
|
---|
7173 | try
|
---|
7174 | {
|
---|
7175 | parseBase64(abEncrypted, str, &elmMachine);
|
---|
7176 | }
|
---|
7177 | catch (...)
|
---|
7178 | {
|
---|
7179 | int vrc2 = pCryptoIf->pfnCryptoCtxDestroy(hCryptoCtx);
|
---|
7180 | AssertRC(vrc2);
|
---|
7181 | throw;
|
---|
7182 | }
|
---|
7183 |
|
---|
7184 | IconBlob abDecrypted(abEncrypted.size());
|
---|
7185 | size_t cbDecrypted = 0;
|
---|
7186 | vrc = pCryptoIf->pfnCryptoCtxDecrypt(hCryptoCtx, false /*fPartial*/,
|
---|
7187 | &abEncrypted[0], abEncrypted.size(),
|
---|
7188 | uuid.raw(), sizeof(RTUUID),
|
---|
7189 | &abDecrypted[0], abDecrypted.size(), &cbDecrypted);
|
---|
7190 | int vrc2 = pCryptoIf->pfnCryptoCtxDestroy(hCryptoCtx);
|
---|
7191 | AssertRC(vrc2);
|
---|
7192 |
|
---|
7193 | if (RT_SUCCESS(vrc))
|
---|
7194 | {
|
---|
7195 | abDecrypted.resize(cbDecrypted);
|
---|
7196 | xml::XmlMemParser parser;
|
---|
7197 | xml::Document *pDoc = new xml::Document;
|
---|
7198 | parser.read(&abDecrypted[0], abDecrypted.size(), m->strFilename, *pDoc);
|
---|
7199 | xml::ElementNode *pelmRoot = pDoc->getRootElement();
|
---|
7200 | if (!pelmRoot || !pelmRoot->nameEquals("Machine"))
|
---|
7201 | throw ConfigFileError(this, pelmRoot, N_("Root element in Machine settings encrypted block must be \"Machine\""));
|
---|
7202 | readMachine(*pelmRoot);
|
---|
7203 | delete pDoc;
|
---|
7204 | }
|
---|
7205 | }
|
---|
7206 |
|
---|
7207 | if (RT_FAILURE(vrc))
|
---|
7208 | {
|
---|
7209 | if (vrc == VERR_ACCESS_DENIED)
|
---|
7210 | enmParseState = ParseState_PasswordError;
|
---|
7211 | else
|
---|
7212 | throw ConfigFileError(this, &elmMachine, N_("Parsing config failed. (%Rrc)"), vrc);
|
---|
7213 | }
|
---|
7214 | }
|
---|
7215 | else
|
---|
7216 | throw ConfigFileError(this, &elmMachine, N_("Required MachineEncrypted/@uuid attribute is missing"));
|
---|
7217 | }
|
---|
7218 |
|
---|
7219 | /**
|
---|
7220 | * Writes x86-specific platform settings out to the XML.
|
---|
7221 | *
|
---|
7222 | * For settings >= v1.20 this creates a \<x86\> node under elmParent.
|
---|
7223 | * keys under that. Called for both the \<Machine\> node and for snapshots.
|
---|
7224 | *
|
---|
7225 | * @param elmParent Parent element.
|
---|
7226 | * For settings >= v1.20 this is the \<Platform\> element.
|
---|
7227 | * For settings < v1.20 this is the \<Hardware\> element.
|
---|
7228 | * @param elmCPU CPU element platform-generic settings.
|
---|
7229 | * For settings >= v1.20 this is the \<Platform/CPU\> element.
|
---|
7230 | * For settings < v1.20 this is the \<Hardware/CPU\> element.
|
---|
7231 | * @param platX86 x86-specific platform settings to use for building the XML.
|
---|
7232 | */
|
---|
7233 | void MachineConfigFile::buildPlatformX86XML(xml::ElementNode &elmParent, xml::ElementNode &elmCPU, const PlatformX86 &platX86)
|
---|
7234 | {
|
---|
7235 | xml::ElementNode *pelmX86Root;
|
---|
7236 | xml::ElementNode *pelmX86CPU;
|
---|
7237 | if (m->sv >= SettingsVersion_v1_20)
|
---|
7238 | {
|
---|
7239 | pelmX86Root = elmParent.createChild("x86");
|
---|
7240 | pelmX86CPU = pelmX86Root->createChild("CPU");
|
---|
7241 |
|
---|
7242 | }
|
---|
7243 | else
|
---|
7244 | {
|
---|
7245 | pelmX86Root = &elmParent; /* Before settings v1.20 the x86-specifics were sprinkled across the Machine element. */
|
---|
7246 | pelmX86CPU = &elmCPU; /* Use the generic CPU element, even for x86-specific things. */
|
---|
7247 | }
|
---|
7248 |
|
---|
7249 | if ( (m->sv >= SettingsVersion_v1_10)
|
---|
7250 | && platX86.fHPETEnabled)
|
---|
7251 | {
|
---|
7252 | xml::ElementNode *pelmHPET = pelmX86Root->createChild("HPET");
|
---|
7253 | pelmHPET->setAttribute("enabled", platX86.fHPETEnabled);
|
---|
7254 | }
|
---|
7255 |
|
---|
7256 | // HardwareVirtExLargePages has too crazy default handling, must always save this setting.
|
---|
7257 | pelmX86CPU->createChild("HardwareVirtExLargePages")->setAttribute("enabled", platX86.fHWVirtExLargePages);
|
---|
7258 |
|
---|
7259 | if (m->sv >= SettingsVersion_v1_9)
|
---|
7260 | {
|
---|
7261 | if (platX86.fHWVirtExForce)
|
---|
7262 | pelmX86CPU->createChild("HardwareVirtForce")->setAttribute("enabled", platX86.fHWVirtExForce);
|
---|
7263 | }
|
---|
7264 |
|
---|
7265 | if (m->sv >= SettingsVersion_v1_9 && platX86.fHWVirtExUseNativeApi)
|
---|
7266 | pelmX86CPU->createChild("HardwareVirtExUseNativeApi")->setAttribute("enabled", platX86.fHWVirtExUseNativeApi);
|
---|
7267 |
|
---|
7268 | if (!platX86.fHWVirtEx)
|
---|
7269 | pelmX86CPU->createChild("HardwareVirtEx")->setAttribute("enabled", platX86.fHWVirtEx);
|
---|
7270 | if (!platX86.fHWVirtExNestedPaging)
|
---|
7271 | pelmX86CPU->createChild("HardwareVirtExNestedPaging")->setAttribute("enabled", platX86.fHWVirtExNestedPaging);
|
---|
7272 | if (!platX86.fHWVirtExVPID)
|
---|
7273 | pelmX86CPU->createChild("HardwareVirtExVPID")->setAttribute("enabled", platX86.fHWVirtExVPID);
|
---|
7274 | if (!platX86.fHWVirtExUX)
|
---|
7275 | pelmX86CPU->createChild("HardwareVirtExUX")->setAttribute("enabled", platX86.fHWVirtExUX);
|
---|
7276 | // PAE has too crazy default handling, must always save this setting.
|
---|
7277 | pelmX86CPU->createChild("PAE")->setAttribute("enabled", platX86.fPAE);
|
---|
7278 | if (m->sv >= SettingsVersion_v1_16)
|
---|
7279 | {
|
---|
7280 | if (platX86.fIBPBOnVMEntry || platX86.fIBPBOnVMExit)
|
---|
7281 | {
|
---|
7282 | xml::ElementNode *pelmChild = pelmX86CPU->createChild("IBPBOn");
|
---|
7283 | if (platX86.fIBPBOnVMExit)
|
---|
7284 | pelmChild->setAttribute("vmexit", platX86.fIBPBOnVMExit);
|
---|
7285 | if (platX86.fIBPBOnVMEntry)
|
---|
7286 | pelmChild->setAttribute("vmentry", platX86.fIBPBOnVMEntry);
|
---|
7287 | }
|
---|
7288 | if (platX86.fSpecCtrl)
|
---|
7289 | pelmX86CPU->createChild("SpecCtrl")->setAttribute("enabled", platX86.fSpecCtrl);
|
---|
7290 | if (platX86.fSpecCtrlByHost)
|
---|
7291 | pelmX86CPU->createChild("SpecCtrlByHost")->setAttribute("enabled", platX86.fSpecCtrlByHost);
|
---|
7292 | if (!platX86.fL1DFlushOnSched || platX86.fL1DFlushOnVMEntry)
|
---|
7293 | {
|
---|
7294 | xml::ElementNode *pelmChild = pelmX86CPU->createChild("L1DFlushOn");
|
---|
7295 | if (!platX86.fL1DFlushOnSched)
|
---|
7296 | pelmChild->setAttribute("scheduling", platX86.fL1DFlushOnSched);
|
---|
7297 | if (platX86.fL1DFlushOnVMEntry)
|
---|
7298 | pelmChild->setAttribute("vmentry", platX86.fL1DFlushOnVMEntry);
|
---|
7299 | }
|
---|
7300 | if (!platX86.fMDSClearOnSched || platX86.fMDSClearOnVMEntry)
|
---|
7301 | {
|
---|
7302 | xml::ElementNode *pelmChild = pelmX86CPU->createChild("MDSClearOn");
|
---|
7303 | if (!platX86.fMDSClearOnSched)
|
---|
7304 | pelmChild->setAttribute("scheduling", platX86.fMDSClearOnSched);
|
---|
7305 | if (platX86.fMDSClearOnVMEntry)
|
---|
7306 | pelmChild->setAttribute("vmentry", platX86.fMDSClearOnVMEntry);
|
---|
7307 | }
|
---|
7308 | }
|
---|
7309 | if (m->sv >= SettingsVersion_v1_17 && platX86.fNestedHWVirt)
|
---|
7310 | pelmX86CPU->createChild("NestedHWVirt")->setAttribute("enabled", platX86.fNestedHWVirt);
|
---|
7311 |
|
---|
7312 | if (m->sv >= SettingsVersion_v1_18 && !platX86.fHWVirtExVirtVmsaveVmload)
|
---|
7313 | pelmX86CPU->createChild("HardwareVirtExVirtVmsaveVmload")->setAttribute("enabled", platX86.fHWVirtExVirtVmsaveVmload);
|
---|
7314 |
|
---|
7315 | if (m->sv >= SettingsVersion_v1_14 && platX86.enmLongMode != PlatformX86::LongMode_Legacy)
|
---|
7316 | {
|
---|
7317 | // LongMode has too crazy default handling, must always save this setting.
|
---|
7318 | pelmX86CPU->createChild("LongMode")->setAttribute("enabled", platX86.enmLongMode == PlatformX86::LongMode_Enabled);
|
---|
7319 | }
|
---|
7320 |
|
---|
7321 | if (platX86.fTripleFaultReset)
|
---|
7322 | pelmX86CPU->createChild("TripleFaultReset")->setAttribute("enabled", platX86.fTripleFaultReset);
|
---|
7323 | if (m->sv >= SettingsVersion_v1_14)
|
---|
7324 | {
|
---|
7325 | if (platX86.fX2APIC)
|
---|
7326 | pelmX86CPU->createChild("X2APIC")->setAttribute("enabled", platX86.fX2APIC);
|
---|
7327 | else if (!platX86.fAPIC)
|
---|
7328 | pelmX86CPU->createChild("APIC")->setAttribute("enabled", platX86.fAPIC);
|
---|
7329 | }
|
---|
7330 |
|
---|
7331 | xml::ElementNode *pelmCpuIdTree = NULL;
|
---|
7332 | for (CpuIdLeafsX86List::const_iterator it = platX86.llCpuIdLeafs.begin();
|
---|
7333 | it != platX86.llCpuIdLeafs.end();
|
---|
7334 | ++it)
|
---|
7335 | {
|
---|
7336 | const CpuIdLeafX86 &leaf = *it;
|
---|
7337 |
|
---|
7338 | if (pelmCpuIdTree == NULL)
|
---|
7339 | pelmCpuIdTree = pelmX86CPU->createChild("CpuIdTree");
|
---|
7340 |
|
---|
7341 | xml::ElementNode *pelmCpuIdLeaf = pelmCpuIdTree->createChild("CpuIdLeaf");
|
---|
7342 | pelmCpuIdLeaf->setAttribute("id", leaf.idx);
|
---|
7343 | if (leaf.idxSub != 0)
|
---|
7344 | pelmCpuIdLeaf->setAttribute("subleaf", leaf.idxSub);
|
---|
7345 | pelmCpuIdLeaf->setAttribute("eax", leaf.uEax);
|
---|
7346 | pelmCpuIdLeaf->setAttribute("ebx", leaf.uEbx);
|
---|
7347 | pelmCpuIdLeaf->setAttribute("ecx", leaf.uEcx);
|
---|
7348 | pelmCpuIdLeaf->setAttribute("edx", leaf.uEdx);
|
---|
7349 | }
|
---|
7350 | }
|
---|
7351 |
|
---|
7352 | /**
|
---|
7353 | * Stores platform-generic and platform-specific data and then writes out the XML.
|
---|
7354 | *
|
---|
7355 | * For settings >= v.120 this creates a \<Platform\> node under elmParent.
|
---|
7356 | * For settings < v.120 this stores the data directly under elmParent.
|
---|
7357 | *
|
---|
7358 | * Called for both the \<Machine\> node and for snapshots.
|
---|
7359 | *
|
---|
7360 | * @param elmParent Parent element.
|
---|
7361 | * @param hw Hardware settings to use for building the XML.
|
---|
7362 | * For CPU stuff we don't have in Platform (yet).
|
---|
7363 | * @param plat Platform settings to use for building the XML.
|
---|
7364 | */
|
---|
7365 | void MachineConfigFile::buildPlatformXML(xml::ElementNode &elmParent,
|
---|
7366 | const Hardware &hw, const Platform &plat)
|
---|
7367 | {
|
---|
7368 | xml::ElementNode *pelmPlatformOrHardware;
|
---|
7369 | if (m->sv >= SettingsVersion_v1_20) /* Since settings v1.20 we have a dedicated Platform element. */
|
---|
7370 | {
|
---|
7371 | pelmPlatformOrHardware = elmParent.createChild("Platform");
|
---|
7372 |
|
---|
7373 | switch (plat.architectureType)
|
---|
7374 | {
|
---|
7375 | case PlatformArchitecture_x86:
|
---|
7376 | pelmPlatformOrHardware->setAttribute("architecture", "x86");
|
---|
7377 | break;
|
---|
7378 |
|
---|
7379 | case PlatformArchitecture_ARM:
|
---|
7380 | pelmPlatformOrHardware->setAttribute("architecture", "ARM");
|
---|
7381 | break;
|
---|
7382 |
|
---|
7383 | default:
|
---|
7384 | AssertFailed();
|
---|
7385 | break;
|
---|
7386 | }
|
---|
7387 | }
|
---|
7388 | else /* For settings < v1.20 we use the parent element (which is Hardware). */
|
---|
7389 | pelmPlatformOrHardware = &elmParent;
|
---|
7390 |
|
---|
7391 | if ( m->sv >= SettingsVersion_v1_10
|
---|
7392 | && plat.fRTCUseUTC)
|
---|
7393 | {
|
---|
7394 | xml::ElementNode *pelmRTC = pelmPlatformOrHardware->createChild("RTC");
|
---|
7395 | pelmRTC->setAttribute("localOrUTC", plat.fRTCUseUTC ? "UTC" : "local");
|
---|
7396 | }
|
---|
7397 |
|
---|
7398 | if (m->sv >= SettingsVersion_v1_11)
|
---|
7399 | {
|
---|
7400 | if (plat.chipsetType != ChipsetType_PIIX3)
|
---|
7401 | {
|
---|
7402 | xml::ElementNode *pelmChipset = pelmPlatformOrHardware->createChild("Chipset");
|
---|
7403 | const char *pcszChipset;
|
---|
7404 |
|
---|
7405 | switch (plat.chipsetType)
|
---|
7406 | {
|
---|
7407 | case ChipsetType_PIIX3: pcszChipset = "PIIX3"; break;
|
---|
7408 | case ChipsetType_ICH9: pcszChipset = "ICH9"; break;
|
---|
7409 | case ChipsetType_ARMv8Virtual: pcszChipset = "ARMv8Virtual"; break;
|
---|
7410 | default: Assert(false); pcszChipset = "PIIX3"; break;
|
---|
7411 | }
|
---|
7412 | pelmChipset->setAttribute("type", pcszChipset);
|
---|
7413 | }
|
---|
7414 | }
|
---|
7415 |
|
---|
7416 | if ( m->sv >= SettingsVersion_v1_19
|
---|
7417 | && plat.iommuType != IommuType_None)
|
---|
7418 | {
|
---|
7419 | const char *pcszIommuType;
|
---|
7420 | switch (plat.iommuType)
|
---|
7421 | {
|
---|
7422 | case IommuType_None: pcszIommuType = "None"; break;
|
---|
7423 | case IommuType_Automatic: pcszIommuType = "Automatic"; break;
|
---|
7424 | case IommuType_AMD: pcszIommuType = "AMD"; break;
|
---|
7425 | case IommuType_Intel: pcszIommuType = "Intel"; break;
|
---|
7426 | default: Assert(false); pcszIommuType = "None"; break;
|
---|
7427 | }
|
---|
7428 |
|
---|
7429 | xml::ElementNode *pelmIommu = pelmPlatformOrHardware->createChild("Iommu");
|
---|
7430 | pelmIommu->setAttribute("type", pcszIommuType);
|
---|
7431 | }
|
---|
7432 |
|
---|
7433 | xml::ElementNode *pelmCPU = pelmPlatformOrHardware->createChild("CPU");
|
---|
7434 |
|
---|
7435 | if (hw.cCPUs > 1)
|
---|
7436 | pelmCPU->setAttribute("count", hw.cCPUs);
|
---|
7437 | if (hw.ulCpuExecutionCap != 100)
|
---|
7438 | pelmCPU->setAttribute("executionCap", hw.ulCpuExecutionCap);
|
---|
7439 | if (hw.uCpuIdPortabilityLevel != 0)
|
---|
7440 | pelmCPU->setAttribute("CpuIdPortabilityLevel", hw.uCpuIdPortabilityLevel);
|
---|
7441 | if (!hw.strCpuProfile.equals("host") && hw.strCpuProfile.isNotEmpty())
|
---|
7442 | pelmCPU->setAttribute("CpuProfile", hw.strCpuProfile);
|
---|
7443 |
|
---|
7444 | if (m->sv >= SettingsVersion_v1_10)
|
---|
7445 | {
|
---|
7446 | if (hw.fCpuHotPlug)
|
---|
7447 | pelmCPU->setAttribute("hotplug", hw.fCpuHotPlug);
|
---|
7448 |
|
---|
7449 | xml::ElementNode *pelmCpuTree = NULL;
|
---|
7450 | for (CpuList::const_iterator it = hw.llCpus.begin();
|
---|
7451 | it != hw.llCpus.end();
|
---|
7452 | ++it)
|
---|
7453 | {
|
---|
7454 | const Cpu &cpu = *it;
|
---|
7455 |
|
---|
7456 | if (pelmCpuTree == NULL)
|
---|
7457 | pelmCpuTree = pelmCPU->createChild("CpuTree");
|
---|
7458 |
|
---|
7459 | xml::ElementNode *pelmCpu = pelmCpuTree->createChild("Cpu");
|
---|
7460 | pelmCpu->setAttribute("id", cpu.ulId);
|
---|
7461 | }
|
---|
7462 | }
|
---|
7463 |
|
---|
7464 | /* We only store specific stuff for the selected platform. */
|
---|
7465 | if (plat.architectureType == PlatformArchitecture_x86)
|
---|
7466 | buildPlatformX86XML(*pelmPlatformOrHardware, *pelmCPU, plat.x86);
|
---|
7467 | /** @todo Put ARM stuff here as soon as we have it. */
|
---|
7468 | }
|
---|
7469 |
|
---|
7470 | /**
|
---|
7471 | * Creates a \<Hardware\> node under elmParent and then writes out the XML
|
---|
7472 | * keys under that. Called for both the \<Machine\> node and for snapshots.
|
---|
7473 | *
|
---|
7474 | * @param elmParent Parent element.
|
---|
7475 | * @param hw Hardware settings to use for building the XML.
|
---|
7476 | * @param fl Flags.
|
---|
7477 | * @param pllElementsWithUuidAttributes Document me.
|
---|
7478 | */
|
---|
7479 | void MachineConfigFile::buildHardwareXML(xml::ElementNode &elmParent,
|
---|
7480 | const Hardware &hw,
|
---|
7481 | uint32_t fl,
|
---|
7482 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
|
---|
7483 | {
|
---|
7484 | xml::ElementNode *pelmHardware = elmParent.createChild("Hardware");
|
---|
7485 |
|
---|
7486 | if ( m->sv >= SettingsVersion_v1_4
|
---|
7487 | && (m->sv < SettingsVersion_v1_7 ? hw.strVersion != "1" : hw.strVersion != "2"))
|
---|
7488 | pelmHardware->setAttribute("version", hw.strVersion);
|
---|
7489 |
|
---|
7490 | if ((m->sv >= SettingsVersion_v1_9)
|
---|
7491 | && !hw.uuid.isZero()
|
---|
7492 | && hw.uuid.isValid()
|
---|
7493 | )
|
---|
7494 | pelmHardware->setAttribute("uuid", hw.uuid.toStringCurly());
|
---|
7495 |
|
---|
7496 | xml::ElementNode *pelmMemory = pelmHardware->createChild("Memory");
|
---|
7497 | pelmMemory->setAttribute("RAMSize", hw.ulMemorySizeMB);
|
---|
7498 | if (m->sv >= SettingsVersion_v1_10)
|
---|
7499 | {
|
---|
7500 | if (hw.fPageFusionEnabled)
|
---|
7501 | pelmMemory->setAttribute("PageFusion", hw.fPageFusionEnabled);
|
---|
7502 | }
|
---|
7503 |
|
---|
7504 | if ( m->sv >= SettingsVersion_v1_10
|
---|
7505 | && ( hw.pointingHIDType != PointingHIDType_PS2Mouse
|
---|
7506 | || hw.keyboardHIDType != KeyboardHIDType_PS2Keyboard))
|
---|
7507 | {
|
---|
7508 | xml::ElementNode *pelmHID = pelmHardware->createChild("HID");
|
---|
7509 | const char *pcszHID;
|
---|
7510 |
|
---|
7511 | if (hw.pointingHIDType != PointingHIDType_PS2Mouse)
|
---|
7512 | {
|
---|
7513 | switch (hw.pointingHIDType)
|
---|
7514 | {
|
---|
7515 | case PointingHIDType_USBMouse: pcszHID = "USBMouse"; break;
|
---|
7516 | case PointingHIDType_USBTablet: pcszHID = "USBTablet"; break;
|
---|
7517 | case PointingHIDType_PS2Mouse: pcszHID = "PS2Mouse"; break;
|
---|
7518 | case PointingHIDType_ComboMouse: pcszHID = "ComboMouse"; break;
|
---|
7519 | case PointingHIDType_USBMultiTouch: pcszHID = "USBMultiTouch";break;
|
---|
7520 | case PointingHIDType_USBMultiTouchScreenPlusPad: pcszHID = "USBMTScreenPlusPad";break;
|
---|
7521 | case PointingHIDType_None: pcszHID = "None"; break;
|
---|
7522 | default: Assert(false); pcszHID = "PS2Mouse"; break;
|
---|
7523 | }
|
---|
7524 | pelmHID->setAttribute("Pointing", pcszHID);
|
---|
7525 | }
|
---|
7526 |
|
---|
7527 | if (hw.keyboardHIDType != KeyboardHIDType_PS2Keyboard)
|
---|
7528 | {
|
---|
7529 | switch (hw.keyboardHIDType)
|
---|
7530 | {
|
---|
7531 | case KeyboardHIDType_USBKeyboard: pcszHID = "USBKeyboard"; break;
|
---|
7532 | case KeyboardHIDType_PS2Keyboard: pcszHID = "PS2Keyboard"; break;
|
---|
7533 | case KeyboardHIDType_ComboKeyboard: pcszHID = "ComboKeyboard"; break;
|
---|
7534 | case KeyboardHIDType_None: pcszHID = "None"; break;
|
---|
7535 | default: Assert(false); pcszHID = "PS2Keyboard"; break;
|
---|
7536 | }
|
---|
7537 | pelmHID->setAttribute("Keyboard", pcszHID);
|
---|
7538 | }
|
---|
7539 | }
|
---|
7540 |
|
---|
7541 |
|
---|
7542 |
|
---|
7543 | if ( (m->sv >= SettingsVersion_v1_15)
|
---|
7544 | && !hw.areParavirtDefaultSettings(m->sv)
|
---|
7545 | )
|
---|
7546 | {
|
---|
7547 | const char *pcszParavirtProvider;
|
---|
7548 | switch (hw.paravirtProvider)
|
---|
7549 | {
|
---|
7550 | case ParavirtProvider_None: pcszParavirtProvider = "None"; break;
|
---|
7551 | case ParavirtProvider_Default: pcszParavirtProvider = "Default"; break;
|
---|
7552 | case ParavirtProvider_Legacy: pcszParavirtProvider = "Legacy"; break;
|
---|
7553 | case ParavirtProvider_Minimal: pcszParavirtProvider = "Minimal"; break;
|
---|
7554 | case ParavirtProvider_HyperV: pcszParavirtProvider = "HyperV"; break;
|
---|
7555 | case ParavirtProvider_KVM: pcszParavirtProvider = "KVM"; break;
|
---|
7556 | default: Assert(false); pcszParavirtProvider = "None"; break;
|
---|
7557 | }
|
---|
7558 |
|
---|
7559 | xml::ElementNode *pelmParavirt = pelmHardware->createChild("Paravirt");
|
---|
7560 | pelmParavirt->setAttribute("provider", pcszParavirtProvider);
|
---|
7561 |
|
---|
7562 | if ( m->sv >= SettingsVersion_v1_16
|
---|
7563 | && hw.strParavirtDebug.isNotEmpty())
|
---|
7564 | pelmParavirt->setAttribute("debug", hw.strParavirtDebug);
|
---|
7565 | }
|
---|
7566 |
|
---|
7567 | if (!hw.areBootOrderDefaultSettings())
|
---|
7568 | {
|
---|
7569 | xml::ElementNode *pelmBoot = pelmHardware->createChild("Boot");
|
---|
7570 | for (BootOrderMap::const_iterator it = hw.mapBootOrder.begin();
|
---|
7571 | it != hw.mapBootOrder.end();
|
---|
7572 | ++it)
|
---|
7573 | {
|
---|
7574 | uint32_t i = it->first;
|
---|
7575 | DeviceType_T type = it->second;
|
---|
7576 | const char *pcszDevice;
|
---|
7577 |
|
---|
7578 | switch (type)
|
---|
7579 | {
|
---|
7580 | case DeviceType_Floppy: pcszDevice = "Floppy"; break;
|
---|
7581 | case DeviceType_DVD: pcszDevice = "DVD"; break;
|
---|
7582 | case DeviceType_HardDisk: pcszDevice = "HardDisk"; break;
|
---|
7583 | case DeviceType_Network: pcszDevice = "Network"; break;
|
---|
7584 | default: /*case DeviceType_Null:*/ pcszDevice = "None"; break;
|
---|
7585 | }
|
---|
7586 |
|
---|
7587 | xml::ElementNode *pelmOrder = pelmBoot->createChild("Order");
|
---|
7588 | pelmOrder->setAttribute("position",
|
---|
7589 | i + 1); // XML is 1-based but internal data is 0-based
|
---|
7590 | pelmOrder->setAttribute("device", pcszDevice);
|
---|
7591 | }
|
---|
7592 | }
|
---|
7593 |
|
---|
7594 | if (!hw.graphicsAdapter.areDefaultSettings())
|
---|
7595 | {
|
---|
7596 | xml::ElementNode *pelmDisplay = pelmHardware->createChild("Display");
|
---|
7597 | if (hw.graphicsAdapter.graphicsControllerType != GraphicsControllerType_VBoxVGA)
|
---|
7598 | {
|
---|
7599 | const char *pcszGraphics;
|
---|
7600 | switch (hw.graphicsAdapter.graphicsControllerType)
|
---|
7601 | {
|
---|
7602 | case GraphicsControllerType_VBoxVGA: pcszGraphics = "VBoxVGA"; break;
|
---|
7603 | case GraphicsControllerType_VMSVGA: pcszGraphics = "VMSVGA"; break;
|
---|
7604 | case GraphicsControllerType_VBoxSVGA: pcszGraphics = "VBoxSVGA"; break;
|
---|
7605 | case GraphicsControllerType_QemuRamFB: pcszGraphics = "QemuRamFB"; break;
|
---|
7606 | default: /*case GraphicsControllerType_Null:*/ pcszGraphics = "None"; break;
|
---|
7607 | }
|
---|
7608 | pelmDisplay->setAttribute("controller", pcszGraphics);
|
---|
7609 | }
|
---|
7610 | if (hw.graphicsAdapter.ulVRAMSizeMB != 8)
|
---|
7611 | pelmDisplay->setAttribute("VRAMSize", hw.graphicsAdapter.ulVRAMSizeMB);
|
---|
7612 | if (hw.graphicsAdapter.cMonitors > 1)
|
---|
7613 | pelmDisplay->setAttribute("monitorCount", hw.graphicsAdapter.cMonitors);
|
---|
7614 | if (hw.graphicsAdapter.fAccelerate3D)
|
---|
7615 | pelmDisplay->setAttribute("accelerate3D", hw.graphicsAdapter.fAccelerate3D);
|
---|
7616 |
|
---|
7617 | if (m->sv >= SettingsVersion_v1_8)
|
---|
7618 | {
|
---|
7619 | if (hw.graphicsAdapter.fAccelerate2DVideo)
|
---|
7620 | pelmDisplay->setAttribute("accelerate2DVideo", hw.graphicsAdapter.fAccelerate2DVideo);
|
---|
7621 | }
|
---|
7622 | }
|
---|
7623 |
|
---|
7624 | if (!hw.vrdeSettings.areDefaultSettings(m->sv))
|
---|
7625 | {
|
---|
7626 | xml::ElementNode *pelmVRDE = pelmHardware->createChild("RemoteDisplay");
|
---|
7627 | if (m->sv < SettingsVersion_v1_16 ? !hw.vrdeSettings.fEnabled : hw.vrdeSettings.fEnabled)
|
---|
7628 | pelmVRDE->setAttribute("enabled", hw.vrdeSettings.fEnabled);
|
---|
7629 | if (m->sv < SettingsVersion_v1_11)
|
---|
7630 | {
|
---|
7631 | /* In VBox 4.0 these attributes are replaced with "Properties". */
|
---|
7632 | Utf8Str strPort;
|
---|
7633 | StringsMap::const_iterator it = hw.vrdeSettings.mapProperties.find("TCP/Ports");
|
---|
7634 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
7635 | strPort = it->second;
|
---|
7636 | if (!strPort.length())
|
---|
7637 | strPort = "3389";
|
---|
7638 | pelmVRDE->setAttribute("port", strPort);
|
---|
7639 |
|
---|
7640 | Utf8Str strAddress;
|
---|
7641 | it = hw.vrdeSettings.mapProperties.find("TCP/Address");
|
---|
7642 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
7643 | strAddress = it->second;
|
---|
7644 | if (strAddress.length())
|
---|
7645 | pelmVRDE->setAttribute("netAddress", strAddress);
|
---|
7646 | }
|
---|
7647 | if (hw.vrdeSettings.authType != AuthType_Null)
|
---|
7648 | {
|
---|
7649 | const char *pcszAuthType;
|
---|
7650 | switch (hw.vrdeSettings.authType)
|
---|
7651 | {
|
---|
7652 | case AuthType_Guest: pcszAuthType = "Guest"; break;
|
---|
7653 | case AuthType_External: pcszAuthType = "External"; break;
|
---|
7654 | default: /*case AuthType_Null:*/ pcszAuthType = "Null"; break;
|
---|
7655 | }
|
---|
7656 | pelmVRDE->setAttribute("authType", pcszAuthType);
|
---|
7657 | }
|
---|
7658 |
|
---|
7659 | if (hw.vrdeSettings.ulAuthTimeout != 0 && hw.vrdeSettings.ulAuthTimeout != 5000)
|
---|
7660 | pelmVRDE->setAttribute("authTimeout", hw.vrdeSettings.ulAuthTimeout);
|
---|
7661 | if (hw.vrdeSettings.fAllowMultiConnection)
|
---|
7662 | pelmVRDE->setAttribute("allowMultiConnection", hw.vrdeSettings.fAllowMultiConnection);
|
---|
7663 | if (hw.vrdeSettings.fReuseSingleConnection)
|
---|
7664 | pelmVRDE->setAttribute("reuseSingleConnection", hw.vrdeSettings.fReuseSingleConnection);
|
---|
7665 |
|
---|
7666 | if (m->sv == SettingsVersion_v1_10)
|
---|
7667 | {
|
---|
7668 | xml::ElementNode *pelmVideoChannel = pelmVRDE->createChild("VideoChannel");
|
---|
7669 |
|
---|
7670 | /* In 4.0 videochannel settings were replaced with properties, so look at properties. */
|
---|
7671 | Utf8Str str;
|
---|
7672 | StringsMap::const_iterator it = hw.vrdeSettings.mapProperties.find("VideoChannel/Enabled");
|
---|
7673 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
7674 | str = it->second;
|
---|
7675 | bool fVideoChannel = RTStrICmp(str.c_str(), "true") == 0
|
---|
7676 | || RTStrCmp(str.c_str(), "1") == 0;
|
---|
7677 | pelmVideoChannel->setAttribute("enabled", fVideoChannel);
|
---|
7678 |
|
---|
7679 | it = hw.vrdeSettings.mapProperties.find("VideoChannel/Quality");
|
---|
7680 | if (it != hw.vrdeSettings.mapProperties.end())
|
---|
7681 | str = it->second;
|
---|
7682 | uint32_t ulVideoChannelQuality = RTStrToUInt32(str.c_str()); /* This returns 0 on invalid string which is ok. */
|
---|
7683 | if (ulVideoChannelQuality == 0)
|
---|
7684 | ulVideoChannelQuality = 75;
|
---|
7685 | else
|
---|
7686 | ulVideoChannelQuality = RT_CLAMP(ulVideoChannelQuality, 10, 100);
|
---|
7687 | pelmVideoChannel->setAttribute("quality", ulVideoChannelQuality);
|
---|
7688 | }
|
---|
7689 | if (m->sv >= SettingsVersion_v1_11)
|
---|
7690 | {
|
---|
7691 | if (hw.vrdeSettings.strAuthLibrary.length())
|
---|
7692 | pelmVRDE->setAttribute("authLibrary", hw.vrdeSettings.strAuthLibrary);
|
---|
7693 | if (hw.vrdeSettings.strVrdeExtPack.isNotEmpty())
|
---|
7694 | pelmVRDE->setAttribute("VRDEExtPack", hw.vrdeSettings.strVrdeExtPack);
|
---|
7695 | if (hw.vrdeSettings.mapProperties.size() > 0)
|
---|
7696 | {
|
---|
7697 | xml::ElementNode *pelmProperties = pelmVRDE->createChild("VRDEProperties");
|
---|
7698 | for (StringsMap::const_iterator it = hw.vrdeSettings.mapProperties.begin();
|
---|
7699 | it != hw.vrdeSettings.mapProperties.end();
|
---|
7700 | ++it)
|
---|
7701 | {
|
---|
7702 | const Utf8Str &strName = it->first;
|
---|
7703 | const Utf8Str &strValue = it->second;
|
---|
7704 | xml::ElementNode *pelm = pelmProperties->createChild("Property");
|
---|
7705 | pelm->setAttribute("name", strName);
|
---|
7706 | pelm->setAttribute("value", strValue);
|
---|
7707 | }
|
---|
7708 | }
|
---|
7709 | }
|
---|
7710 | }
|
---|
7711 |
|
---|
7712 | if ( !hw.firmwareSettings.areDefaultSettings( hw.platformSettings.architectureType == PlatformArchitecture_ARM
|
---|
7713 | /* Good enough for now (we don't support ARMv7). */
|
---|
7714 | ? CPUArchitecture_ARMv8_64 : CPUArchitecture_x86)
|
---|
7715 | || !hw.nvramSettings.areDefaultSettings())
|
---|
7716 | {
|
---|
7717 | /* Settings < v1.20 also had a "Firmware" element, but that only stored the firmware type. */
|
---|
7718 | xml::ElementNode *pelmFirmware = pelmHardware->createChild("Firmware");
|
---|
7719 |
|
---|
7720 | if ( (m->sv >= SettingsVersion_v1_9)
|
---|
7721 | && (hw.firmwareSettings.firmwareType >= FirmwareType_EFI)
|
---|
7722 | )
|
---|
7723 | {
|
---|
7724 | const char *pcszFirmware;
|
---|
7725 |
|
---|
7726 | switch (hw.firmwareSettings.firmwareType)
|
---|
7727 | {
|
---|
7728 | case FirmwareType_EFI: pcszFirmware = "EFI"; break;
|
---|
7729 | case FirmwareType_EFI32: pcszFirmware = "EFI32"; break;
|
---|
7730 | case FirmwareType_EFI64: pcszFirmware = "EFI64"; break;
|
---|
7731 | case FirmwareType_EFIDUAL: pcszFirmware = "EFIDUAL"; break;
|
---|
7732 | default: pcszFirmware = "None"; break;
|
---|
7733 | }
|
---|
7734 | pelmFirmware->setAttribute("type", pcszFirmware);
|
---|
7735 | }
|
---|
7736 |
|
---|
7737 | xml::ElementNode *pelmFirmwareOrBIOS;
|
---|
7738 | if (m->sv >= SettingsVersion_v1_20) /* Since settings v1.20 the rest also gets stored in "Firmware". */
|
---|
7739 | pelmFirmwareOrBIOS = pelmFirmware; /* Use the "Firmware" element from above. */
|
---|
7740 | else /* For settings < v1.20 the rest was stored in the "BIOS" element. */
|
---|
7741 | pelmFirmwareOrBIOS = pelmHardware->createChild("BIOS");
|
---|
7742 |
|
---|
7743 | if (!hw.firmwareSettings.fACPIEnabled)
|
---|
7744 | pelmFirmwareOrBIOS->createChild("ACPI")->setAttribute("enabled", hw.firmwareSettings.fACPIEnabled);
|
---|
7745 | if (hw.firmwareSettings.fIOAPICEnabled)
|
---|
7746 | pelmFirmwareOrBIOS->createChild("IOAPIC")->setAttribute("enabled", hw.firmwareSettings.fIOAPICEnabled);
|
---|
7747 | if (hw.firmwareSettings.apicMode != APICMode_APIC)
|
---|
7748 | {
|
---|
7749 | const char *pcszAPIC;
|
---|
7750 | switch (hw.firmwareSettings.apicMode)
|
---|
7751 | {
|
---|
7752 | case APICMode_Disabled:
|
---|
7753 | pcszAPIC = "Disabled";
|
---|
7754 | break;
|
---|
7755 | case APICMode_APIC:
|
---|
7756 | default:
|
---|
7757 | pcszAPIC = "APIC";
|
---|
7758 | break;
|
---|
7759 | case APICMode_X2APIC:
|
---|
7760 | pcszAPIC = "X2APIC";
|
---|
7761 | break;
|
---|
7762 | }
|
---|
7763 | pelmFirmwareOrBIOS->createChild("APIC")->setAttribute("mode", pcszAPIC);
|
---|
7764 | }
|
---|
7765 |
|
---|
7766 | if ( !hw.firmwareSettings.fLogoFadeIn
|
---|
7767 | || !hw.firmwareSettings.fLogoFadeOut
|
---|
7768 | || hw.firmwareSettings.ulLogoDisplayTime
|
---|
7769 | || !hw.firmwareSettings.strLogoImagePath.isEmpty())
|
---|
7770 | {
|
---|
7771 | xml::ElementNode *pelmLogo = pelmFirmwareOrBIOS->createChild("Logo");
|
---|
7772 | pelmLogo->setAttribute("fadeIn", hw.firmwareSettings.fLogoFadeIn);
|
---|
7773 | pelmLogo->setAttribute("fadeOut", hw.firmwareSettings.fLogoFadeOut);
|
---|
7774 | pelmLogo->setAttribute("displayTime", hw.firmwareSettings.ulLogoDisplayTime);
|
---|
7775 | if (!hw.firmwareSettings.strLogoImagePath.isEmpty())
|
---|
7776 | pelmLogo->setAttribute("imagePath", hw.firmwareSettings.strLogoImagePath);
|
---|
7777 | }
|
---|
7778 |
|
---|
7779 | if (hw.firmwareSettings.enmBootMenuMode != FirmwareBootMenuMode_MessageAndMenu)
|
---|
7780 | {
|
---|
7781 | const char *pcszBootMenu;
|
---|
7782 | switch (hw.firmwareSettings.enmBootMenuMode)
|
---|
7783 | {
|
---|
7784 | case FirmwareBootMenuMode_Disabled: pcszBootMenu = "Disabled"; break;
|
---|
7785 | case FirmwareBootMenuMode_MenuOnly: pcszBootMenu = "MenuOnly"; break;
|
---|
7786 | default: /*FirmwareBootMenuMode_MessageAndMenu*/ pcszBootMenu = "MessageAndMenu"; break;
|
---|
7787 | }
|
---|
7788 | pelmFirmwareOrBIOS->createChild("BootMenu")->setAttribute("mode", pcszBootMenu);
|
---|
7789 | }
|
---|
7790 | if (hw.firmwareSettings.llTimeOffset)
|
---|
7791 | pelmFirmwareOrBIOS->createChild("TimeOffset")->setAttribute("value", hw.firmwareSettings.llTimeOffset);
|
---|
7792 | if (hw.firmwareSettings.fPXEDebugEnabled)
|
---|
7793 | pelmFirmwareOrBIOS->createChild("PXEDebug")->setAttribute("enabled", hw.firmwareSettings.fPXEDebugEnabled);
|
---|
7794 | if (!hw.nvramSettings.areDefaultSettings())
|
---|
7795 | {
|
---|
7796 | xml::ElementNode *pelmNvram = pelmFirmwareOrBIOS->createChild("NVRAM");
|
---|
7797 | if (!hw.nvramSettings.strNvramPath.isEmpty())
|
---|
7798 | pelmNvram->setAttribute("path", hw.nvramSettings.strNvramPath);
|
---|
7799 | if (m->sv >= SettingsVersion_v1_9)
|
---|
7800 | {
|
---|
7801 | if (hw.nvramSettings.strKeyId.isNotEmpty())
|
---|
7802 | pelmNvram->setAttribute("keyId", hw.nvramSettings.strKeyId);
|
---|
7803 | if (hw.nvramSettings.strKeyStore.isNotEmpty())
|
---|
7804 | pelmNvram->setAttribute("keyStore", hw.nvramSettings.strKeyStore);
|
---|
7805 | }
|
---|
7806 | }
|
---|
7807 | if (hw.firmwareSettings.fSmbiosUuidLittleEndian)
|
---|
7808 | pelmFirmwareOrBIOS->createChild("SmbiosUuidLittleEndian")->setAttribute("enabled", hw.firmwareSettings.fSmbiosUuidLittleEndian);
|
---|
7809 | if (hw.firmwareSettings.fAutoSerialNumGen)
|
---|
7810 | pelmFirmwareOrBIOS->createChild("AutoSerialNumGen")->setAttribute("enabled", hw.firmwareSettings.fAutoSerialNumGen);
|
---|
7811 | }
|
---|
7812 |
|
---|
7813 | if (!hw.tpmSettings.areDefaultSettings())
|
---|
7814 | {
|
---|
7815 | xml::ElementNode *pelmTpm = pelmHardware->createChild("TrustedPlatformModule");
|
---|
7816 |
|
---|
7817 | const char *pcszTpm;
|
---|
7818 | switch (hw.tpmSettings.tpmType)
|
---|
7819 | {
|
---|
7820 | default:
|
---|
7821 | case TpmType_None:
|
---|
7822 | pcszTpm = "None";
|
---|
7823 | break;
|
---|
7824 | case TpmType_v1_2:
|
---|
7825 | pcszTpm = "v1_2";
|
---|
7826 | break;
|
---|
7827 | case TpmType_v2_0:
|
---|
7828 | pcszTpm = "v2_0";
|
---|
7829 | break;
|
---|
7830 | case TpmType_Host:
|
---|
7831 | pcszTpm = "Host";
|
---|
7832 | break;
|
---|
7833 | case TpmType_Swtpm:
|
---|
7834 | pcszTpm = "Swtpm";
|
---|
7835 | break;
|
---|
7836 | }
|
---|
7837 | pelmTpm->setAttribute("type", pcszTpm);
|
---|
7838 | pelmTpm->setAttribute("location", hw.tpmSettings.strLocation);
|
---|
7839 | }
|
---|
7840 |
|
---|
7841 | if (m->sv < SettingsVersion_v1_9)
|
---|
7842 | {
|
---|
7843 | // settings formats before 1.9 had separate DVDDrive and FloppyDrive items under Hardware;
|
---|
7844 | // run thru the storage controllers to see if we have a DVD or floppy drives
|
---|
7845 | size_t cDVDs = 0;
|
---|
7846 | size_t cFloppies = 0;
|
---|
7847 |
|
---|
7848 | xml::ElementNode *pelmDVD = pelmHardware->createChild("DVDDrive");
|
---|
7849 | xml::ElementNode *pelmFloppy = pelmHardware->createChild("FloppyDrive");
|
---|
7850 |
|
---|
7851 | for (StorageControllersList::const_iterator it = hw.storage.llStorageControllers.begin();
|
---|
7852 | it != hw.storage.llStorageControllers.end();
|
---|
7853 | ++it)
|
---|
7854 | {
|
---|
7855 | const StorageController &sctl = *it;
|
---|
7856 | // in old settings format, the DVD drive could only have been under the IDE controller
|
---|
7857 | if (sctl.storageBus == StorageBus_IDE)
|
---|
7858 | {
|
---|
7859 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
7860 | it2 != sctl.llAttachedDevices.end();
|
---|
7861 | ++it2)
|
---|
7862 | {
|
---|
7863 | const AttachedDevice &att = *it2;
|
---|
7864 | if (att.deviceType == DeviceType_DVD)
|
---|
7865 | {
|
---|
7866 | if (cDVDs > 0)
|
---|
7867 | throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one DVD drive with old settings format"));
|
---|
7868 |
|
---|
7869 | ++cDVDs;
|
---|
7870 |
|
---|
7871 | pelmDVD->setAttribute("passthrough", att.fPassThrough);
|
---|
7872 | if (att.fTempEject)
|
---|
7873 | pelmDVD->setAttribute("tempeject", att.fTempEject);
|
---|
7874 |
|
---|
7875 | if (!att.uuid.isZero() && att.uuid.isValid())
|
---|
7876 | pelmDVD->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
|
---|
7877 | else if (att.strHostDriveSrc.length())
|
---|
7878 | pelmDVD->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
7879 | }
|
---|
7880 | }
|
---|
7881 | }
|
---|
7882 | else if (sctl.storageBus == StorageBus_Floppy)
|
---|
7883 | {
|
---|
7884 | size_t cFloppiesHere = sctl.llAttachedDevices.size();
|
---|
7885 | if (cFloppiesHere > 1)
|
---|
7886 | throw ConfigFileError(this, NULL, N_("Internal error: floppy controller cannot have more than one device attachment"));
|
---|
7887 | if (cFloppiesHere)
|
---|
7888 | {
|
---|
7889 | const AttachedDevice &att = sctl.llAttachedDevices.front();
|
---|
7890 | pelmFloppy->setAttribute("enabled", true);
|
---|
7891 |
|
---|
7892 | if (!att.uuid.isZero() && att.uuid.isValid())
|
---|
7893 | pelmFloppy->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
|
---|
7894 | else if (att.strHostDriveSrc.length())
|
---|
7895 | pelmFloppy->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
7896 | }
|
---|
7897 |
|
---|
7898 | cFloppies += cFloppiesHere;
|
---|
7899 | }
|
---|
7900 | }
|
---|
7901 |
|
---|
7902 | if (cFloppies == 0)
|
---|
7903 | pelmFloppy->setAttribute("enabled", false);
|
---|
7904 | else if (cFloppies > 1)
|
---|
7905 | throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one floppy drive with old settings format"));
|
---|
7906 | }
|
---|
7907 |
|
---|
7908 | if (m->sv < SettingsVersion_v1_14)
|
---|
7909 | {
|
---|
7910 | bool fOhciEnabled = false;
|
---|
7911 | bool fEhciEnabled = false;
|
---|
7912 | xml::ElementNode *pelmUSB = pelmHardware->createChild("USBController");
|
---|
7913 |
|
---|
7914 | for (USBControllerList::const_iterator it = hw.usbSettings.llUSBControllers.begin();
|
---|
7915 | it != hw.usbSettings.llUSBControllers.end();
|
---|
7916 | ++it)
|
---|
7917 | {
|
---|
7918 | const USBController &ctrl = *it;
|
---|
7919 |
|
---|
7920 | switch (ctrl.enmType)
|
---|
7921 | {
|
---|
7922 | case USBControllerType_OHCI:
|
---|
7923 | fOhciEnabled = true;
|
---|
7924 | break;
|
---|
7925 | case USBControllerType_EHCI:
|
---|
7926 | fEhciEnabled = true;
|
---|
7927 | break;
|
---|
7928 | default:
|
---|
7929 | AssertMsgFailed(("Unknown USB controller type %d\n", ctrl.enmType));
|
---|
7930 | }
|
---|
7931 | }
|
---|
7932 |
|
---|
7933 | pelmUSB->setAttribute("enabled", fOhciEnabled);
|
---|
7934 | pelmUSB->setAttribute("enabledEhci", fEhciEnabled);
|
---|
7935 |
|
---|
7936 | buildUSBDeviceFilters(*pelmUSB, hw.usbSettings.llDeviceFilters, false /* fHostMode */);
|
---|
7937 | }
|
---|
7938 | else
|
---|
7939 | {
|
---|
7940 | if ( hw.usbSettings.llUSBControllers.size()
|
---|
7941 | || hw.usbSettings.llDeviceFilters.size())
|
---|
7942 | {
|
---|
7943 | xml::ElementNode *pelmUSB = pelmHardware->createChild("USB");
|
---|
7944 | if (hw.usbSettings.llUSBControllers.size())
|
---|
7945 | {
|
---|
7946 | xml::ElementNode *pelmCtrls = pelmUSB->createChild("Controllers");
|
---|
7947 |
|
---|
7948 | for (USBControllerList::const_iterator it = hw.usbSettings.llUSBControllers.begin();
|
---|
7949 | it != hw.usbSettings.llUSBControllers.end();
|
---|
7950 | ++it)
|
---|
7951 | {
|
---|
7952 | const USBController &ctrl = *it;
|
---|
7953 | com::Utf8Str strType;
|
---|
7954 | xml::ElementNode *pelmCtrl = pelmCtrls->createChild("Controller");
|
---|
7955 |
|
---|
7956 | switch (ctrl.enmType)
|
---|
7957 | {
|
---|
7958 | case USBControllerType_OHCI:
|
---|
7959 | strType = "OHCI";
|
---|
7960 | break;
|
---|
7961 | case USBControllerType_EHCI:
|
---|
7962 | strType = "EHCI";
|
---|
7963 | break;
|
---|
7964 | case USBControllerType_XHCI:
|
---|
7965 | strType = "XHCI";
|
---|
7966 | break;
|
---|
7967 | default:
|
---|
7968 | AssertMsgFailed(("Unknown USB controller type %d\n", ctrl.enmType));
|
---|
7969 | }
|
---|
7970 |
|
---|
7971 | pelmCtrl->setAttribute("name", ctrl.strName);
|
---|
7972 | pelmCtrl->setAttribute("type", strType);
|
---|
7973 | }
|
---|
7974 | }
|
---|
7975 |
|
---|
7976 | if (hw.usbSettings.llDeviceFilters.size())
|
---|
7977 | {
|
---|
7978 | xml::ElementNode *pelmFilters = pelmUSB->createChild("DeviceFilters");
|
---|
7979 | buildUSBDeviceFilters(*pelmFilters, hw.usbSettings.llDeviceFilters, false /* fHostMode */);
|
---|
7980 | }
|
---|
7981 | }
|
---|
7982 | }
|
---|
7983 |
|
---|
7984 | if ( hw.llNetworkAdapters.size()
|
---|
7985 | && !hw.areAllNetworkAdaptersDefaultSettings(m->sv))
|
---|
7986 | {
|
---|
7987 | xml::ElementNode *pelmNetwork = pelmHardware->createChild("Network");
|
---|
7988 | for (NetworkAdaptersList::const_iterator it = hw.llNetworkAdapters.begin();
|
---|
7989 | it != hw.llNetworkAdapters.end();
|
---|
7990 | ++it)
|
---|
7991 | {
|
---|
7992 | const NetworkAdapter &nic = *it;
|
---|
7993 |
|
---|
7994 | if (!nic.areDefaultSettings(m->sv))
|
---|
7995 | {
|
---|
7996 | xml::ElementNode *pelmAdapter = pelmNetwork->createChild("Adapter");
|
---|
7997 | pelmAdapter->setAttribute("slot", nic.ulSlot);
|
---|
7998 | if (nic.fEnabled)
|
---|
7999 | pelmAdapter->setAttribute("enabled", nic.fEnabled);
|
---|
8000 | if (!nic.strMACAddress.isEmpty())
|
---|
8001 | pelmAdapter->setAttribute("MACAddress", nic.strMACAddress);
|
---|
8002 | if ( (m->sv >= SettingsVersion_v1_16 && !nic.fCableConnected)
|
---|
8003 | || (m->sv < SettingsVersion_v1_16 && nic.fCableConnected))
|
---|
8004 | pelmAdapter->setAttribute("cable", nic.fCableConnected);
|
---|
8005 | if (nic.ulLineSpeed)
|
---|
8006 | pelmAdapter->setAttribute("speed", nic.ulLineSpeed);
|
---|
8007 | if (nic.ulBootPriority != 0)
|
---|
8008 | pelmAdapter->setAttribute("bootPriority", nic.ulBootPriority);
|
---|
8009 | if (nic.fTraceEnabled)
|
---|
8010 | {
|
---|
8011 | pelmAdapter->setAttribute("trace", nic.fTraceEnabled);
|
---|
8012 | pelmAdapter->setAttribute("tracefile", nic.strTraceFile);
|
---|
8013 | }
|
---|
8014 | if (nic.strBandwidthGroup.isNotEmpty())
|
---|
8015 | pelmAdapter->setAttribute("bandwidthGroup", nic.strBandwidthGroup);
|
---|
8016 |
|
---|
8017 | const char *pszPolicy;
|
---|
8018 | switch (nic.enmPromiscModePolicy)
|
---|
8019 | {
|
---|
8020 | case NetworkAdapterPromiscModePolicy_Deny: pszPolicy = NULL; break;
|
---|
8021 | case NetworkAdapterPromiscModePolicy_AllowNetwork: pszPolicy = "AllowNetwork"; break;
|
---|
8022 | case NetworkAdapterPromiscModePolicy_AllowAll: pszPolicy = "AllowAll"; break;
|
---|
8023 | default: pszPolicy = NULL; AssertFailed(); break;
|
---|
8024 | }
|
---|
8025 | if (pszPolicy)
|
---|
8026 | pelmAdapter->setAttribute("promiscuousModePolicy", pszPolicy);
|
---|
8027 |
|
---|
8028 | if ( (m->sv >= SettingsVersion_v1_16 && nic.type != NetworkAdapterType_Am79C973)
|
---|
8029 | || (m->sv < SettingsVersion_v1_16 && nic.type != NetworkAdapterType_Am79C970A))
|
---|
8030 | {
|
---|
8031 | const char *pcszType;
|
---|
8032 | switch (nic.type)
|
---|
8033 | {
|
---|
8034 | case NetworkAdapterType_Am79C973: pcszType = "Am79C973"; break;
|
---|
8035 | case NetworkAdapterType_Am79C960: pcszType = "Am79C960"; break;
|
---|
8036 | case NetworkAdapterType_I82540EM: pcszType = "82540EM"; break;
|
---|
8037 | case NetworkAdapterType_I82543GC: pcszType = "82543GC"; break;
|
---|
8038 | case NetworkAdapterType_I82545EM: pcszType = "82545EM"; break;
|
---|
8039 | case NetworkAdapterType_Virtio: pcszType = "virtio"; break;
|
---|
8040 | case NetworkAdapterType_NE1000: pcszType = "NE1000"; break;
|
---|
8041 | case NetworkAdapterType_NE2000: pcszType = "NE2000"; break;
|
---|
8042 | case NetworkAdapterType_WD8003: pcszType = "WD8003"; break;
|
---|
8043 | case NetworkAdapterType_WD8013: pcszType = "WD8013"; break;
|
---|
8044 | case NetworkAdapterType_ELNK2: pcszType = "3C503"; break;
|
---|
8045 | case NetworkAdapterType_ELNK1: pcszType = "3C501"; break;
|
---|
8046 | default: /*case NetworkAdapterType_Am79C970A:*/ pcszType = "Am79C970A"; break;
|
---|
8047 | }
|
---|
8048 | pelmAdapter->setAttribute("type", pcszType);
|
---|
8049 | }
|
---|
8050 |
|
---|
8051 | xml::ElementNode *pelmNAT;
|
---|
8052 | if (m->sv < SettingsVersion_v1_10)
|
---|
8053 | {
|
---|
8054 | switch (nic.mode)
|
---|
8055 | {
|
---|
8056 | case NetworkAttachmentType_NAT:
|
---|
8057 | pelmNAT = pelmAdapter->createChild("NAT");
|
---|
8058 | if (nic.nat.strNetwork.length())
|
---|
8059 | pelmNAT->setAttribute("network", nic.nat.strNetwork);
|
---|
8060 | break;
|
---|
8061 |
|
---|
8062 | case NetworkAttachmentType_Bridged:
|
---|
8063 | pelmAdapter->createChild("BridgedInterface")->setAttribute("name", nic.strBridgedName);
|
---|
8064 | break;
|
---|
8065 |
|
---|
8066 | case NetworkAttachmentType_Internal:
|
---|
8067 | pelmAdapter->createChild("InternalNetwork")->setAttribute("name", nic.strInternalNetworkName);
|
---|
8068 | break;
|
---|
8069 |
|
---|
8070 | case NetworkAttachmentType_HostOnly:
|
---|
8071 | pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strHostOnlyName);
|
---|
8072 | break;
|
---|
8073 |
|
---|
8074 | default: /*case NetworkAttachmentType_Null:*/
|
---|
8075 | break;
|
---|
8076 | }
|
---|
8077 | }
|
---|
8078 | else
|
---|
8079 | {
|
---|
8080 | /* m->sv >= SettingsVersion_v1_10 */
|
---|
8081 | if (!nic.areDisabledDefaultSettings(m->sv))
|
---|
8082 | {
|
---|
8083 | xml::ElementNode *pelmDisabledNode = pelmAdapter->createChild("DisabledModes");
|
---|
8084 | if (nic.mode != NetworkAttachmentType_NAT)
|
---|
8085 | buildNetworkXML(NetworkAttachmentType_NAT, false, *pelmDisabledNode, nic);
|
---|
8086 | if (nic.mode != NetworkAttachmentType_Bridged)
|
---|
8087 | buildNetworkXML(NetworkAttachmentType_Bridged, false, *pelmDisabledNode, nic);
|
---|
8088 | if (nic.mode != NetworkAttachmentType_Internal)
|
---|
8089 | buildNetworkXML(NetworkAttachmentType_Internal, false, *pelmDisabledNode, nic);
|
---|
8090 | if (nic.mode != NetworkAttachmentType_HostOnly)
|
---|
8091 | buildNetworkXML(NetworkAttachmentType_HostOnly, false, *pelmDisabledNode, nic);
|
---|
8092 | if (nic.mode != NetworkAttachmentType_Generic)
|
---|
8093 | buildNetworkXML(NetworkAttachmentType_Generic, false, *pelmDisabledNode, nic);
|
---|
8094 | if (nic.mode != NetworkAttachmentType_NATNetwork)
|
---|
8095 | buildNetworkXML(NetworkAttachmentType_NATNetwork, false, *pelmDisabledNode, nic);
|
---|
8096 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
8097 | /// @todo Bump settings version!
|
---|
8098 | if (nic.mode != NetworkAttachmentType_Cloud)
|
---|
8099 | buildNetworkXML(NetworkAttachmentType_Cloud, false, *pelmDisabledNode, nic);
|
---|
8100 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
8101 | #ifdef VBOX_WITH_VMNET
|
---|
8102 | if (nic.mode != NetworkAttachmentType_HostOnlyNetwork)
|
---|
8103 | buildNetworkXML(NetworkAttachmentType_HostOnlyNetwork, false, *pelmDisabledNode, nic);
|
---|
8104 | #endif /* VBOX_WITH_VMNET */
|
---|
8105 | }
|
---|
8106 | buildNetworkXML(nic.mode, true, *pelmAdapter, nic);
|
---|
8107 | }
|
---|
8108 | }
|
---|
8109 | }
|
---|
8110 | }
|
---|
8111 |
|
---|
8112 | if (hw.llSerialPorts.size())
|
---|
8113 | {
|
---|
8114 | xml::ElementNode *pelmPorts = pelmHardware->createChild("UART");
|
---|
8115 | for (SerialPortsList::const_iterator it = hw.llSerialPorts.begin();
|
---|
8116 | it != hw.llSerialPorts.end();
|
---|
8117 | ++it)
|
---|
8118 | {
|
---|
8119 | const SerialPort &port = *it;
|
---|
8120 | xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
|
---|
8121 | pelmPort->setAttribute("slot", port.ulSlot);
|
---|
8122 | pelmPort->setAttribute("enabled", port.fEnabled);
|
---|
8123 | if (m->sv >= SettingsVersion_v1_20) /* IOBase was renamed to IOAddress in v1.20. */
|
---|
8124 | pelmPort->setAttributeHex("IOAddress", port.ulIOAddress);
|
---|
8125 | else
|
---|
8126 | pelmPort->setAttributeHex("IOBase", port.ulIOAddress);
|
---|
8127 | pelmPort->setAttribute("IRQ", port.ulIRQ);
|
---|
8128 |
|
---|
8129 | const char *pcszHostMode;
|
---|
8130 | switch (port.portMode)
|
---|
8131 | {
|
---|
8132 | case PortMode_HostPipe: pcszHostMode = "HostPipe"; break;
|
---|
8133 | case PortMode_HostDevice: pcszHostMode = "HostDevice"; break;
|
---|
8134 | case PortMode_TCP: pcszHostMode = "TCP"; break;
|
---|
8135 | case PortMode_RawFile: pcszHostMode = "RawFile"; break;
|
---|
8136 | default: /*case PortMode_Disconnected:*/ pcszHostMode = "Disconnected"; break;
|
---|
8137 | }
|
---|
8138 | switch (port.portMode)
|
---|
8139 | {
|
---|
8140 | case PortMode_TCP:
|
---|
8141 | case PortMode_HostPipe:
|
---|
8142 | pelmPort->setAttribute("server", port.fServer);
|
---|
8143 | RT_FALL_THRU();
|
---|
8144 | case PortMode_HostDevice:
|
---|
8145 | case PortMode_RawFile:
|
---|
8146 | pelmPort->setAttribute("path", port.strPath);
|
---|
8147 | break;
|
---|
8148 |
|
---|
8149 | default:
|
---|
8150 | break;
|
---|
8151 | }
|
---|
8152 | pelmPort->setAttribute("hostMode", pcszHostMode);
|
---|
8153 |
|
---|
8154 | if ( m->sv >= SettingsVersion_v1_17
|
---|
8155 | && port.uartType != UartType_U16550A)
|
---|
8156 | {
|
---|
8157 | const char *pcszUartType;
|
---|
8158 |
|
---|
8159 | switch (port.uartType)
|
---|
8160 | {
|
---|
8161 | case UartType_U16450: pcszUartType = "16450"; break;
|
---|
8162 | case UartType_U16550A: pcszUartType = "16550A"; break;
|
---|
8163 | case UartType_U16750: pcszUartType = "16750"; break;
|
---|
8164 | default: pcszUartType = "16550A"; break;
|
---|
8165 | }
|
---|
8166 | pelmPort->setAttribute("uartType", pcszUartType);
|
---|
8167 | }
|
---|
8168 | }
|
---|
8169 | }
|
---|
8170 |
|
---|
8171 | if (hw.llParallelPorts.size())
|
---|
8172 | {
|
---|
8173 | xml::ElementNode *pelmPorts = pelmHardware->createChild("LPT");
|
---|
8174 | for (ParallelPortsList::const_iterator it = hw.llParallelPorts.begin();
|
---|
8175 | it != hw.llParallelPorts.end();
|
---|
8176 | ++it)
|
---|
8177 | {
|
---|
8178 | const ParallelPort &port = *it;
|
---|
8179 | xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
|
---|
8180 | pelmPort->setAttribute("slot", port.ulSlot);
|
---|
8181 | pelmPort->setAttribute("enabled", port.fEnabled);
|
---|
8182 | pelmPort->setAttributeHex("IOBase", port.ulIOBase);
|
---|
8183 | pelmPort->setAttribute("IRQ", port.ulIRQ);
|
---|
8184 | if (port.strPath.length())
|
---|
8185 | pelmPort->setAttribute("path", port.strPath);
|
---|
8186 | }
|
---|
8187 | }
|
---|
8188 |
|
---|
8189 | /* Always write the AudioAdapter config, intentionally not checking if
|
---|
8190 | * the settings are at the default, because that would be problematic
|
---|
8191 | * for the configured host driver type, which would automatically change
|
---|
8192 | * if the default host driver is detected differently. */
|
---|
8193 | {
|
---|
8194 | xml::ElementNode *pelmAudio = pelmHardware->createChild("AudioAdapter");
|
---|
8195 |
|
---|
8196 | const char *pcszController = NULL;
|
---|
8197 | switch (hw.audioAdapter.controllerType)
|
---|
8198 | {
|
---|
8199 | case AudioControllerType_VirtioSound:
|
---|
8200 | if (m->sv >= SettingsVersion_v1_20)
|
---|
8201 | {
|
---|
8202 | pcszController = "Virtio-Sound";
|
---|
8203 | break;
|
---|
8204 | }
|
---|
8205 | break;
|
---|
8206 | case AudioControllerType_SB16:
|
---|
8207 | pcszController = "SB16";
|
---|
8208 | break;
|
---|
8209 | case AudioControllerType_HDA:
|
---|
8210 | if (m->sv >= SettingsVersion_v1_11)
|
---|
8211 | {
|
---|
8212 | pcszController = "HDA";
|
---|
8213 | break;
|
---|
8214 | }
|
---|
8215 | RT_FALL_THRU();
|
---|
8216 | case AudioControllerType_AC97:
|
---|
8217 | default:
|
---|
8218 | pcszController = NULL;
|
---|
8219 | break;
|
---|
8220 | }
|
---|
8221 | if (pcszController)
|
---|
8222 | pelmAudio->setAttribute("controller", pcszController);
|
---|
8223 |
|
---|
8224 | const char *pcszCodec;
|
---|
8225 | switch (hw.audioAdapter.codecType)
|
---|
8226 | {
|
---|
8227 | /* Only write out the setting for non-default AC'97 codec
|
---|
8228 | * and leave the rest alone.
|
---|
8229 | */
|
---|
8230 | #if 0
|
---|
8231 | case AudioCodecType_SB16:
|
---|
8232 | pcszCodec = "SB16";
|
---|
8233 | break;
|
---|
8234 | case AudioCodecType_STAC9221:
|
---|
8235 | pcszCodec = "STAC9221";
|
---|
8236 | break;
|
---|
8237 | case AudioCodecType_STAC9700:
|
---|
8238 | pcszCodec = "STAC9700";
|
---|
8239 | break;
|
---|
8240 | #endif
|
---|
8241 | case AudioCodecType_AD1980:
|
---|
8242 | pcszCodec = "AD1980";
|
---|
8243 | break;
|
---|
8244 | default:
|
---|
8245 | /* Don't write out anything if unknown. */
|
---|
8246 | pcszCodec = NULL;
|
---|
8247 | }
|
---|
8248 | if (pcszCodec)
|
---|
8249 | pelmAudio->setAttribute("codec", pcszCodec);
|
---|
8250 |
|
---|
8251 | /*
|
---|
8252 | * Keep settings >= 1.19 compatible with older VBox versions (on a best effort basis, of course).
|
---|
8253 | * So use a dedicated attribute for the new "Default" audio driver type, which did not exist prior
|
---|
8254 | * settings 1.19 (VBox 7.0) and explicitly set the driver type to something older VBox versions
|
---|
8255 | * know about.
|
---|
8256 | */
|
---|
8257 | AudioDriverType_T driverType = hw.audioAdapter.driverType;
|
---|
8258 |
|
---|
8259 | if (driverType == AudioDriverType_Default)
|
---|
8260 | {
|
---|
8261 | /* Only recognized by VBox >= 7.0. */
|
---|
8262 | pelmAudio->setAttribute("useDefault", true);
|
---|
8263 |
|
---|
8264 | /* Make sure to set the actual driver type to the OS' default driver type.
|
---|
8265 | * This is required for VBox < 7.0. */
|
---|
8266 | driverType = getHostDefaultAudioDriver();
|
---|
8267 | }
|
---|
8268 |
|
---|
8269 | const char *pcszDriver = NULL;
|
---|
8270 | switch (driverType)
|
---|
8271 | {
|
---|
8272 | case AudioDriverType_Default: /* Handled above. */ break;
|
---|
8273 | case AudioDriverType_WinMM: pcszDriver = "WinMM"; break;
|
---|
8274 | case AudioDriverType_DirectSound: pcszDriver = "DirectSound"; break;
|
---|
8275 | case AudioDriverType_WAS: pcszDriver = "WAS"; break;
|
---|
8276 | case AudioDriverType_ALSA: pcszDriver = "ALSA"; break;
|
---|
8277 | case AudioDriverType_OSS: pcszDriver = "OSS"; break;
|
---|
8278 | case AudioDriverType_Pulse: pcszDriver = "Pulse"; break;
|
---|
8279 | case AudioDriverType_CoreAudio: pcszDriver = "CoreAudio"; break;
|
---|
8280 | case AudioDriverType_SolAudio: pcszDriver = "SolAudio"; break;
|
---|
8281 | case AudioDriverType_MMPM: pcszDriver = "MMPM"; break;
|
---|
8282 | default: /*case AudioDriverType_Null:*/ pcszDriver = "Null"; break;
|
---|
8283 | }
|
---|
8284 |
|
---|
8285 | /* Deliberately have the audio driver explicitly in the config file,
|
---|
8286 | * otherwise an unwritten default driver triggers auto-detection. */
|
---|
8287 | AssertStmt(pcszDriver != NULL, pcszDriver = "Null");
|
---|
8288 | pelmAudio->setAttribute("driver", pcszDriver);
|
---|
8289 |
|
---|
8290 | if (hw.audioAdapter.fEnabled || m->sv < SettingsVersion_v1_16)
|
---|
8291 | pelmAudio->setAttribute("enabled", hw.audioAdapter.fEnabled);
|
---|
8292 |
|
---|
8293 | if ( (m->sv <= SettingsVersion_v1_16 && !hw.audioAdapter.fEnabledIn)
|
---|
8294 | || (m->sv > SettingsVersion_v1_16 && hw.audioAdapter.fEnabledIn))
|
---|
8295 | pelmAudio->setAttribute("enabledIn", hw.audioAdapter.fEnabledIn);
|
---|
8296 |
|
---|
8297 | if ( (m->sv <= SettingsVersion_v1_16 && !hw.audioAdapter.fEnabledOut)
|
---|
8298 | || (m->sv > SettingsVersion_v1_16 && hw.audioAdapter.fEnabledOut))
|
---|
8299 | pelmAudio->setAttribute("enabledOut", hw.audioAdapter.fEnabledOut);
|
---|
8300 |
|
---|
8301 | if (m->sv >= SettingsVersion_v1_15 && hw.audioAdapter.properties.size() > 0)
|
---|
8302 | {
|
---|
8303 | for (StringsMap::const_iterator it = hw.audioAdapter.properties.begin();
|
---|
8304 | it != hw.audioAdapter.properties.end();
|
---|
8305 | ++it)
|
---|
8306 | {
|
---|
8307 | const Utf8Str &strName = it->first;
|
---|
8308 | const Utf8Str &strValue = it->second;
|
---|
8309 | xml::ElementNode *pelm = pelmAudio->createChild("Property");
|
---|
8310 | pelm->setAttribute("name", strName);
|
---|
8311 | pelm->setAttribute("value", strValue);
|
---|
8312 | }
|
---|
8313 | }
|
---|
8314 | }
|
---|
8315 |
|
---|
8316 | if (hw.llSharedFolders.size())
|
---|
8317 | {
|
---|
8318 | xml::ElementNode *pelmSharedFolders = pelmHardware->createChild("SharedFolders");
|
---|
8319 | for (SharedFoldersList::const_iterator it = hw.llSharedFolders.begin();
|
---|
8320 | it != hw.llSharedFolders.end();
|
---|
8321 | ++it)
|
---|
8322 | {
|
---|
8323 | const SharedFolder &sf = *it;
|
---|
8324 | xml::ElementNode *pelmThis = pelmSharedFolders->createChild("SharedFolder");
|
---|
8325 | pelmThis->setAttribute("name", sf.strName);
|
---|
8326 | pelmThis->setAttribute("hostPath", sf.strHostPath);
|
---|
8327 | pelmThis->setAttribute("writable", sf.fWritable);
|
---|
8328 | pelmThis->setAttribute("autoMount", sf.fAutoMount);
|
---|
8329 | if (sf.strAutoMountPoint.isNotEmpty())
|
---|
8330 | pelmThis->setAttribute("autoMountPoint", sf.strAutoMountPoint);
|
---|
8331 | const char *pcszSymlinkPolicy;
|
---|
8332 | if (sf.enmSymlinkPolicy != SymlinkPolicy_None)
|
---|
8333 | {
|
---|
8334 | switch (sf.enmSymlinkPolicy)
|
---|
8335 | {
|
---|
8336 | default: /*case SymlinkPolicy_Forbidden:*/ pcszSymlinkPolicy = "forbidden"; break;
|
---|
8337 | case SymlinkPolicy_AllowedInShareSubtree: pcszSymlinkPolicy = "subtree"; break;
|
---|
8338 | case SymlinkPolicy_AllowedToRelativeTargets: pcszSymlinkPolicy = "relative"; break;
|
---|
8339 | case SymlinkPolicy_AllowedToAnyTarget: pcszSymlinkPolicy = "any"; break;
|
---|
8340 | }
|
---|
8341 | pelmThis->setAttribute("symlinkPolicy", pcszSymlinkPolicy);
|
---|
8342 | }
|
---|
8343 | }
|
---|
8344 | }
|
---|
8345 |
|
---|
8346 | xml::ElementNode *pelmClip = pelmHardware->createChild("Clipboard");
|
---|
8347 | if (pelmClip)
|
---|
8348 | {
|
---|
8349 | if (hw.clipboardMode != ClipboardMode_Disabled)
|
---|
8350 | {
|
---|
8351 | const char *pcszClip;
|
---|
8352 | switch (hw.clipboardMode)
|
---|
8353 | {
|
---|
8354 | default: /*case ClipboardMode_Disabled:*/ pcszClip = "Disabled"; break;
|
---|
8355 | case ClipboardMode_HostToGuest: pcszClip = "HostToGuest"; break;
|
---|
8356 | case ClipboardMode_GuestToHost: pcszClip = "GuestToHost"; break;
|
---|
8357 | case ClipboardMode_Bidirectional: pcszClip = "Bidirectional"; break;
|
---|
8358 | }
|
---|
8359 | pelmClip->setAttribute("mode", pcszClip);
|
---|
8360 | }
|
---|
8361 |
|
---|
8362 | if (hw.fClipboardFileTransfersEnabled)
|
---|
8363 | pelmClip->setAttribute("fileTransfersEnabled", hw.fClipboardFileTransfersEnabled);
|
---|
8364 | }
|
---|
8365 |
|
---|
8366 | if (hw.dndMode != DnDMode_Disabled)
|
---|
8367 | {
|
---|
8368 | xml::ElementNode *pelmDragAndDrop = pelmHardware->createChild("DragAndDrop");
|
---|
8369 | const char *pcszDragAndDrop;
|
---|
8370 | switch (hw.dndMode)
|
---|
8371 | {
|
---|
8372 | default: /*case DnDMode_Disabled:*/ pcszDragAndDrop = "Disabled"; break;
|
---|
8373 | case DnDMode_HostToGuest: pcszDragAndDrop = "HostToGuest"; break;
|
---|
8374 | case DnDMode_GuestToHost: pcszDragAndDrop = "GuestToHost"; break;
|
---|
8375 | case DnDMode_Bidirectional: pcszDragAndDrop = "Bidirectional"; break;
|
---|
8376 | }
|
---|
8377 | pelmDragAndDrop->setAttribute("mode", pcszDragAndDrop);
|
---|
8378 | }
|
---|
8379 |
|
---|
8380 | if ( m->sv >= SettingsVersion_v1_10
|
---|
8381 | && !hw.ioSettings.areDefaultSettings())
|
---|
8382 | {
|
---|
8383 | xml::ElementNode *pelmIO = pelmHardware->createChild("IO");
|
---|
8384 | xml::ElementNode *pelmIOCache;
|
---|
8385 |
|
---|
8386 | if (!hw.ioSettings.areDefaultSettings())
|
---|
8387 | {
|
---|
8388 | pelmIOCache = pelmIO->createChild("IoCache");
|
---|
8389 | if (!hw.ioSettings.fIOCacheEnabled)
|
---|
8390 | pelmIOCache->setAttribute("enabled", hw.ioSettings.fIOCacheEnabled);
|
---|
8391 | if (hw.ioSettings.ulIOCacheSize != 5)
|
---|
8392 | pelmIOCache->setAttribute("size", hw.ioSettings.ulIOCacheSize);
|
---|
8393 | }
|
---|
8394 |
|
---|
8395 | if ( m->sv >= SettingsVersion_v1_11
|
---|
8396 | && hw.ioSettings.llBandwidthGroups.size())
|
---|
8397 | {
|
---|
8398 | xml::ElementNode *pelmBandwidthGroups = pelmIO->createChild("BandwidthGroups");
|
---|
8399 | for (BandwidthGroupList::const_iterator it = hw.ioSettings.llBandwidthGroups.begin();
|
---|
8400 | it != hw.ioSettings.llBandwidthGroups.end();
|
---|
8401 | ++it)
|
---|
8402 | {
|
---|
8403 | const BandwidthGroup &gr = *it;
|
---|
8404 | const char *pcszType;
|
---|
8405 | xml::ElementNode *pelmThis = pelmBandwidthGroups->createChild("BandwidthGroup");
|
---|
8406 | pelmThis->setAttribute("name", gr.strName);
|
---|
8407 | switch (gr.enmType)
|
---|
8408 | {
|
---|
8409 | case BandwidthGroupType_Network: pcszType = "Network"; break;
|
---|
8410 | default: /* BandwidthGrouptype_Disk */ pcszType = "Disk"; break;
|
---|
8411 | }
|
---|
8412 | pelmThis->setAttribute("type", pcszType);
|
---|
8413 | if (m->sv >= SettingsVersion_v1_13)
|
---|
8414 | pelmThis->setAttribute("maxBytesPerSec", gr.cMaxBytesPerSec);
|
---|
8415 | else
|
---|
8416 | pelmThis->setAttribute("maxMbPerSec", gr.cMaxBytesPerSec / _1M);
|
---|
8417 | }
|
---|
8418 | }
|
---|
8419 | }
|
---|
8420 |
|
---|
8421 | if ( m->sv >= SettingsVersion_v1_12
|
---|
8422 | && hw.pciAttachments.size())
|
---|
8423 | {
|
---|
8424 | xml::ElementNode *pelmPCI = pelmHardware->createChild("HostPci");
|
---|
8425 | xml::ElementNode *pelmPCIDevices = pelmPCI->createChild("Devices");
|
---|
8426 |
|
---|
8427 | for (HostPCIDeviceAttachmentList::const_iterator it = hw.pciAttachments.begin();
|
---|
8428 | it != hw.pciAttachments.end();
|
---|
8429 | ++it)
|
---|
8430 | {
|
---|
8431 | const HostPCIDeviceAttachment &hpda = *it;
|
---|
8432 |
|
---|
8433 | xml::ElementNode *pelmThis = pelmPCIDevices->createChild("Device");
|
---|
8434 |
|
---|
8435 | pelmThis->setAttribute("host", hpda.uHostAddress);
|
---|
8436 | pelmThis->setAttribute("guest", hpda.uGuestAddress);
|
---|
8437 | pelmThis->setAttribute("name", hpda.strDeviceName);
|
---|
8438 | }
|
---|
8439 | }
|
---|
8440 |
|
---|
8441 | if ( m->sv >= SettingsVersion_v1_12
|
---|
8442 | && hw.fEmulatedUSBCardReader)
|
---|
8443 | {
|
---|
8444 | xml::ElementNode *pelmEmulatedUSB = pelmHardware->createChild("EmulatedUSB");
|
---|
8445 |
|
---|
8446 | xml::ElementNode *pelmCardReader = pelmEmulatedUSB->createChild("CardReader");
|
---|
8447 | pelmCardReader->setAttribute("enabled", hw.fEmulatedUSBCardReader);
|
---|
8448 | }
|
---|
8449 |
|
---|
8450 | if ( m->sv >= SettingsVersion_v1_14
|
---|
8451 | && !hw.strDefaultFrontend.isEmpty())
|
---|
8452 | {
|
---|
8453 | xml::ElementNode *pelmFrontend = pelmHardware->createChild("Frontend");
|
---|
8454 | xml::ElementNode *pelmDefault = pelmFrontend->createChild("Default");
|
---|
8455 | pelmDefault->setAttribute("type", hw.strDefaultFrontend);
|
---|
8456 | }
|
---|
8457 |
|
---|
8458 | if (hw.ulMemoryBalloonSize)
|
---|
8459 | {
|
---|
8460 | xml::ElementNode *pelmGuest = pelmHardware->createChild("Guest");
|
---|
8461 | pelmGuest->setAttribute("memoryBalloonSize", hw.ulMemoryBalloonSize);
|
---|
8462 | }
|
---|
8463 |
|
---|
8464 | if (hw.llGuestProperties.size())
|
---|
8465 | {
|
---|
8466 | xml::ElementNode *pelmGuestProps = pelmHardware->createChild("GuestProperties");
|
---|
8467 | for (GuestPropertiesList::const_iterator it = hw.llGuestProperties.begin();
|
---|
8468 | it != hw.llGuestProperties.end();
|
---|
8469 | ++it)
|
---|
8470 | {
|
---|
8471 | const GuestProperty &prop = *it;
|
---|
8472 | xml::ElementNode *pelmProp = pelmGuestProps->createChild("GuestProperty");
|
---|
8473 | pelmProp->setAttribute("name", prop.strName);
|
---|
8474 | pelmProp->setAttribute("value", prop.strValue);
|
---|
8475 | pelmProp->setAttribute("timestamp", prop.timestamp);
|
---|
8476 | pelmProp->setAttribute("flags", prop.strFlags);
|
---|
8477 | }
|
---|
8478 | }
|
---|
8479 |
|
---|
8480 | /* Starting with settings version of 6.0 (and only 6.1 and later does this, while
|
---|
8481 | * 5.2 and 6.0 understand it), place storage controller settings under hardware,
|
---|
8482 | * where it always should've been. */
|
---|
8483 | xml::ElementNode &elmStorageParent = (m->sv >= SettingsVersion_v1_17) ? *pelmHardware : elmParent;
|
---|
8484 | buildStorageControllersXML(elmStorageParent,
|
---|
8485 | hw.storage,
|
---|
8486 | !!(fl & BuildMachineXML_SkipRemovableMedia),
|
---|
8487 | pllElementsWithUuidAttributes);
|
---|
8488 | }
|
---|
8489 |
|
---|
8490 | /**
|
---|
8491 | * Fill a \<Network\> node. Only relevant for XML version >= v1_10.
|
---|
8492 | * @param mode
|
---|
8493 | * @param fEnabled
|
---|
8494 | * @param elmParent
|
---|
8495 | * @param nic
|
---|
8496 | */
|
---|
8497 | void MachineConfigFile::buildNetworkXML(NetworkAttachmentType_T mode,
|
---|
8498 | bool fEnabled,
|
---|
8499 | xml::ElementNode &elmParent,
|
---|
8500 | const NetworkAdapter &nic)
|
---|
8501 | {
|
---|
8502 | switch (mode)
|
---|
8503 | {
|
---|
8504 | case NetworkAttachmentType_NAT:
|
---|
8505 | // For the currently active network attachment type we have to
|
---|
8506 | // generate the tag, otherwise the attachment type is lost.
|
---|
8507 | if (fEnabled || !nic.nat.areDefaultSettings(m->sv))
|
---|
8508 | {
|
---|
8509 | xml::ElementNode *pelmNAT = elmParent.createChild("NAT");
|
---|
8510 |
|
---|
8511 | if (!nic.nat.areDefaultSettings(m->sv))
|
---|
8512 | {
|
---|
8513 | if (nic.nat.strNetwork.length())
|
---|
8514 | pelmNAT->setAttribute("network", nic.nat.strNetwork);
|
---|
8515 | if (nic.nat.strBindIP.length())
|
---|
8516 | pelmNAT->setAttribute("hostip", nic.nat.strBindIP);
|
---|
8517 | if (nic.nat.u32Mtu)
|
---|
8518 | pelmNAT->setAttribute("mtu", nic.nat.u32Mtu);
|
---|
8519 | if (nic.nat.u32SockRcv)
|
---|
8520 | pelmNAT->setAttribute("sockrcv", nic.nat.u32SockRcv);
|
---|
8521 | if (nic.nat.u32SockSnd)
|
---|
8522 | pelmNAT->setAttribute("socksnd", nic.nat.u32SockSnd);
|
---|
8523 | if (nic.nat.u32TcpRcv)
|
---|
8524 | pelmNAT->setAttribute("tcprcv", nic.nat.u32TcpRcv);
|
---|
8525 | if (nic.nat.u32TcpSnd)
|
---|
8526 | pelmNAT->setAttribute("tcpsnd", nic.nat.u32TcpSnd);
|
---|
8527 | if (!nic.nat.areLocalhostReachableDefaultSettings(m->sv))
|
---|
8528 | pelmNAT->setAttribute("localhost-reachable", nic.nat.fLocalhostReachable);
|
---|
8529 | if (!nic.nat.areDNSDefaultSettings())
|
---|
8530 | {
|
---|
8531 | xml::ElementNode *pelmDNS = pelmNAT->createChild("DNS");
|
---|
8532 | if (!nic.nat.fDNSPassDomain)
|
---|
8533 | pelmDNS->setAttribute("pass-domain", nic.nat.fDNSPassDomain);
|
---|
8534 | if (nic.nat.fDNSProxy)
|
---|
8535 | pelmDNS->setAttribute("use-proxy", nic.nat.fDNSProxy);
|
---|
8536 | if (nic.nat.fDNSUseHostResolver)
|
---|
8537 | pelmDNS->setAttribute("use-host-resolver", nic.nat.fDNSUseHostResolver);
|
---|
8538 | }
|
---|
8539 |
|
---|
8540 | if (!nic.nat.areAliasDefaultSettings())
|
---|
8541 | {
|
---|
8542 | xml::ElementNode *pelmAlias = pelmNAT->createChild("Alias");
|
---|
8543 | if (nic.nat.fAliasLog)
|
---|
8544 | pelmAlias->setAttribute("logging", nic.nat.fAliasLog);
|
---|
8545 | if (nic.nat.fAliasProxyOnly)
|
---|
8546 | pelmAlias->setAttribute("proxy-only", nic.nat.fAliasProxyOnly);
|
---|
8547 | if (nic.nat.fAliasUseSamePorts)
|
---|
8548 | pelmAlias->setAttribute("use-same-ports", nic.nat.fAliasUseSamePorts);
|
---|
8549 | }
|
---|
8550 |
|
---|
8551 | if (!nic.nat.areTFTPDefaultSettings())
|
---|
8552 | {
|
---|
8553 | xml::ElementNode *pelmTFTP;
|
---|
8554 | pelmTFTP = pelmNAT->createChild("TFTP");
|
---|
8555 | if (nic.nat.strTFTPPrefix.length())
|
---|
8556 | pelmTFTP->setAttribute("prefix", nic.nat.strTFTPPrefix);
|
---|
8557 | if (nic.nat.strTFTPBootFile.length())
|
---|
8558 | pelmTFTP->setAttribute("boot-file", nic.nat.strTFTPBootFile);
|
---|
8559 | if (nic.nat.strTFTPNextServer.length())
|
---|
8560 | pelmTFTP->setAttribute("next-server", nic.nat.strTFTPNextServer);
|
---|
8561 | }
|
---|
8562 | buildNATForwardRulesMap(*pelmNAT, nic.nat.mapRules);
|
---|
8563 | }
|
---|
8564 | }
|
---|
8565 | break;
|
---|
8566 |
|
---|
8567 | case NetworkAttachmentType_Bridged:
|
---|
8568 | // For the currently active network attachment type we have to
|
---|
8569 | // generate the tag, otherwise the attachment type is lost.
|
---|
8570 | if (fEnabled || !nic.strBridgedName.isEmpty())
|
---|
8571 | {
|
---|
8572 | xml::ElementNode *pelmMode = elmParent.createChild("BridgedInterface");
|
---|
8573 | if (!nic.strBridgedName.isEmpty())
|
---|
8574 | pelmMode->setAttribute("name", nic.strBridgedName);
|
---|
8575 | }
|
---|
8576 | break;
|
---|
8577 |
|
---|
8578 | case NetworkAttachmentType_Internal:
|
---|
8579 | // For the currently active network attachment type we have to
|
---|
8580 | // generate the tag, otherwise the attachment type is lost.
|
---|
8581 | if (fEnabled || !nic.strInternalNetworkName.isEmpty())
|
---|
8582 | {
|
---|
8583 | xml::ElementNode *pelmMode = elmParent.createChild("InternalNetwork");
|
---|
8584 | if (!nic.strInternalNetworkName.isEmpty())
|
---|
8585 | pelmMode->setAttribute("name", nic.strInternalNetworkName);
|
---|
8586 | }
|
---|
8587 | break;
|
---|
8588 |
|
---|
8589 | case NetworkAttachmentType_HostOnly:
|
---|
8590 | // For the currently active network attachment type we have to
|
---|
8591 | // generate the tag, otherwise the attachment type is lost.
|
---|
8592 | if (fEnabled || !nic.strHostOnlyName.isEmpty())
|
---|
8593 | {
|
---|
8594 | xml::ElementNode *pelmMode = elmParent.createChild("HostOnlyInterface");
|
---|
8595 | if (!nic.strHostOnlyName.isEmpty())
|
---|
8596 | pelmMode->setAttribute("name", nic.strHostOnlyName);
|
---|
8597 | }
|
---|
8598 | break;
|
---|
8599 |
|
---|
8600 | #ifdef VBOX_WITH_VMNET
|
---|
8601 | case NetworkAttachmentType_HostOnlyNetwork:
|
---|
8602 | // For the currently active network attachment type we have to
|
---|
8603 | // generate the tag, otherwise the attachment type is lost.
|
---|
8604 | if (fEnabled || !nic.strHostOnlyNetworkName.isEmpty())
|
---|
8605 | {
|
---|
8606 | xml::ElementNode *pelmMode = elmParent.createChild("HostOnlyNetwork");
|
---|
8607 | if (!nic.strHostOnlyNetworkName.isEmpty())
|
---|
8608 | pelmMode->setAttribute("name", nic.strHostOnlyNetworkName);
|
---|
8609 | }
|
---|
8610 | break;
|
---|
8611 | #endif /* VBOX_WITH_VMNET */
|
---|
8612 |
|
---|
8613 | case NetworkAttachmentType_Generic:
|
---|
8614 | // For the currently active network attachment type we have to
|
---|
8615 | // generate the tag, otherwise the attachment type is lost.
|
---|
8616 | if (fEnabled || !nic.areGenericDriverDefaultSettings())
|
---|
8617 | {
|
---|
8618 | xml::ElementNode *pelmMode = elmParent.createChild("GenericInterface");
|
---|
8619 | if (!nic.areGenericDriverDefaultSettings())
|
---|
8620 | {
|
---|
8621 | pelmMode->setAttribute("driver", nic.strGenericDriver);
|
---|
8622 | for (StringsMap::const_iterator it = nic.genericProperties.begin();
|
---|
8623 | it != nic.genericProperties.end();
|
---|
8624 | ++it)
|
---|
8625 | {
|
---|
8626 | xml::ElementNode *pelmProp = pelmMode->createChild("Property");
|
---|
8627 | pelmProp->setAttribute("name", it->first);
|
---|
8628 | pelmProp->setAttribute("value", it->second);
|
---|
8629 | }
|
---|
8630 | }
|
---|
8631 | }
|
---|
8632 | break;
|
---|
8633 |
|
---|
8634 | case NetworkAttachmentType_NATNetwork:
|
---|
8635 | // For the currently active network attachment type we have to
|
---|
8636 | // generate the tag, otherwise the attachment type is lost.
|
---|
8637 | if (fEnabled || !nic.strNATNetworkName.isEmpty())
|
---|
8638 | {
|
---|
8639 | xml::ElementNode *pelmMode = elmParent.createChild("NATNetwork");
|
---|
8640 | if (!nic.strNATNetworkName.isEmpty())
|
---|
8641 | pelmMode->setAttribute("name", nic.strNATNetworkName);
|
---|
8642 | }
|
---|
8643 | break;
|
---|
8644 |
|
---|
8645 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
8646 | case NetworkAttachmentType_Cloud:
|
---|
8647 | // For the currently active network attachment type we have to
|
---|
8648 | // generate the tag, otherwise the attachment type is lost.
|
---|
8649 | if (fEnabled || !nic.strCloudNetworkName.isEmpty())
|
---|
8650 | {
|
---|
8651 | xml::ElementNode *pelmMode = elmParent.createChild("CloudNetwork");
|
---|
8652 | if (!nic.strCloudNetworkName.isEmpty())
|
---|
8653 | pelmMode->setAttribute("name", nic.strCloudNetworkName);
|
---|
8654 | }
|
---|
8655 | break;
|
---|
8656 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
8657 |
|
---|
8658 | default: /*case NetworkAttachmentType_Null:*/
|
---|
8659 | break;
|
---|
8660 | }
|
---|
8661 | }
|
---|
8662 |
|
---|
8663 | /**
|
---|
8664 | * Creates a \<StorageControllers\> node under elmParent and then writes out the XML
|
---|
8665 | * keys under that. Called for both the \<Machine\> node and for snapshots.
|
---|
8666 | * @param elmParent
|
---|
8667 | * @param st
|
---|
8668 | * @param fSkipRemovableMedia If true, DVD and floppy attachments are skipped and
|
---|
8669 | * an empty drive is always written instead. This is for the OVF export case.
|
---|
8670 | * This parameter is ignored unless the settings version is at least v1.9, which
|
---|
8671 | * is always the case when this gets called for OVF export.
|
---|
8672 | * @param pllElementsWithUuidAttributes If not NULL, must point to a list of element node
|
---|
8673 | * pointers to which we will append all elements that we created here that contain
|
---|
8674 | * UUID attributes. This allows the OVF export code to quickly replace the internal
|
---|
8675 | * media UUIDs with the UUIDs of the media that were exported.
|
---|
8676 | */
|
---|
8677 | void MachineConfigFile::buildStorageControllersXML(xml::ElementNode &elmParent,
|
---|
8678 | const Storage &st,
|
---|
8679 | bool fSkipRemovableMedia,
|
---|
8680 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
|
---|
8681 | {
|
---|
8682 | if (!st.llStorageControllers.size())
|
---|
8683 | return;
|
---|
8684 | xml::ElementNode *pelmStorageControllers = elmParent.createChild("StorageControllers");
|
---|
8685 |
|
---|
8686 | for (StorageControllersList::const_iterator it = st.llStorageControllers.begin();
|
---|
8687 | it != st.llStorageControllers.end();
|
---|
8688 | ++it)
|
---|
8689 | {
|
---|
8690 | const StorageController &sc = *it;
|
---|
8691 |
|
---|
8692 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
8693 | && (sc.controllerType == StorageControllerType_I82078)
|
---|
8694 | )
|
---|
8695 | // floppy controller already got written into <Hardware>/<FloppyController> in buildHardwareXML()
|
---|
8696 | // for pre-1.9 settings
|
---|
8697 | continue;
|
---|
8698 |
|
---|
8699 | xml::ElementNode *pelmController = pelmStorageControllers->createChild("StorageController");
|
---|
8700 | com::Utf8Str name = sc.strName;
|
---|
8701 | if (m->sv < SettingsVersion_v1_8)
|
---|
8702 | {
|
---|
8703 | // pre-1.8 settings use shorter controller names, they are
|
---|
8704 | // expanded when reading the settings
|
---|
8705 | if (name == "IDE Controller")
|
---|
8706 | name = "IDE";
|
---|
8707 | else if (name == "SATA Controller")
|
---|
8708 | name = "SATA";
|
---|
8709 | else if (name == "SCSI Controller")
|
---|
8710 | name = "SCSI";
|
---|
8711 | }
|
---|
8712 | pelmController->setAttribute("name", sc.strName);
|
---|
8713 |
|
---|
8714 | const char *pcszType;
|
---|
8715 | switch (sc.controllerType)
|
---|
8716 | {
|
---|
8717 | case StorageControllerType_IntelAhci: pcszType = "AHCI"; break;
|
---|
8718 | case StorageControllerType_LsiLogic: pcszType = "LsiLogic"; break;
|
---|
8719 | case StorageControllerType_BusLogic: pcszType = "BusLogic"; break;
|
---|
8720 | case StorageControllerType_PIIX4: pcszType = "PIIX4"; break;
|
---|
8721 | case StorageControllerType_ICH6: pcszType = "ICH6"; break;
|
---|
8722 | case StorageControllerType_I82078: pcszType = "I82078"; break;
|
---|
8723 | case StorageControllerType_LsiLogicSas: pcszType = "LsiLogicSas"; break;
|
---|
8724 | case StorageControllerType_USB: pcszType = "USB"; break;
|
---|
8725 | case StorageControllerType_NVMe: pcszType = "NVMe"; break;
|
---|
8726 | case StorageControllerType_VirtioSCSI: pcszType = "VirtioSCSI"; break;
|
---|
8727 | default: /*case StorageControllerType_PIIX3:*/ pcszType = "PIIX3"; break;
|
---|
8728 | }
|
---|
8729 | pelmController->setAttribute("type", pcszType);
|
---|
8730 |
|
---|
8731 | pelmController->setAttribute("PortCount", sc.ulPortCount);
|
---|
8732 |
|
---|
8733 | if (m->sv >= SettingsVersion_v1_9)
|
---|
8734 | if (sc.ulInstance)
|
---|
8735 | pelmController->setAttribute("Instance", sc.ulInstance);
|
---|
8736 |
|
---|
8737 | if (m->sv >= SettingsVersion_v1_10)
|
---|
8738 | pelmController->setAttribute("useHostIOCache", sc.fUseHostIOCache);
|
---|
8739 |
|
---|
8740 | if (m->sv >= SettingsVersion_v1_11)
|
---|
8741 | pelmController->setAttribute("Bootable", sc.fBootable);
|
---|
8742 |
|
---|
8743 | if (sc.controllerType == StorageControllerType_IntelAhci)
|
---|
8744 | {
|
---|
8745 | pelmController->setAttribute("IDE0MasterEmulationPort", 0);
|
---|
8746 | pelmController->setAttribute("IDE0SlaveEmulationPort", 1);
|
---|
8747 | pelmController->setAttribute("IDE1MasterEmulationPort", 2);
|
---|
8748 | pelmController->setAttribute("IDE1SlaveEmulationPort", 3);
|
---|
8749 | }
|
---|
8750 |
|
---|
8751 | for (AttachedDevicesList::const_iterator it2 = sc.llAttachedDevices.begin();
|
---|
8752 | it2 != sc.llAttachedDevices.end();
|
---|
8753 | ++it2)
|
---|
8754 | {
|
---|
8755 | const AttachedDevice &att = *it2;
|
---|
8756 |
|
---|
8757 | // For settings version before 1.9, DVDs and floppies are in hardware, not storage controllers,
|
---|
8758 | // so we shouldn't write them here; we only get here for DVDs though because we ruled out
|
---|
8759 | // the floppy controller at the top of the loop
|
---|
8760 | if ( att.deviceType == DeviceType_DVD
|
---|
8761 | && m->sv < SettingsVersion_v1_9
|
---|
8762 | )
|
---|
8763 | continue;
|
---|
8764 |
|
---|
8765 | xml::ElementNode *pelmDevice = pelmController->createChild("AttachedDevice");
|
---|
8766 |
|
---|
8767 | pcszType = NULL;
|
---|
8768 |
|
---|
8769 | switch (att.deviceType)
|
---|
8770 | {
|
---|
8771 | case DeviceType_HardDisk:
|
---|
8772 | pcszType = "HardDisk";
|
---|
8773 | if (att.fNonRotational)
|
---|
8774 | pelmDevice->setAttribute("nonrotational", att.fNonRotational);
|
---|
8775 | if (att.fDiscard)
|
---|
8776 | pelmDevice->setAttribute("discard", att.fDiscard);
|
---|
8777 | break;
|
---|
8778 |
|
---|
8779 | case DeviceType_DVD:
|
---|
8780 | pcszType = "DVD";
|
---|
8781 | pelmDevice->setAttribute("passthrough", att.fPassThrough);
|
---|
8782 | if (att.fTempEject)
|
---|
8783 | pelmDevice->setAttribute("tempeject", att.fTempEject);
|
---|
8784 | break;
|
---|
8785 |
|
---|
8786 | case DeviceType_Floppy:
|
---|
8787 | pcszType = "Floppy";
|
---|
8788 | break;
|
---|
8789 |
|
---|
8790 | default: break; /* Shut up MSC. */
|
---|
8791 | }
|
---|
8792 |
|
---|
8793 | pelmDevice->setAttribute("type", pcszType);
|
---|
8794 |
|
---|
8795 | if (m->sv >= SettingsVersion_v1_15)
|
---|
8796 | pelmDevice->setAttribute("hotpluggable", att.fHotPluggable);
|
---|
8797 |
|
---|
8798 | pelmDevice->setAttribute("port", att.lPort);
|
---|
8799 | pelmDevice->setAttribute("device", att.lDevice);
|
---|
8800 |
|
---|
8801 | if (att.strBwGroup.length())
|
---|
8802 | pelmDevice->setAttribute("bandwidthGroup", att.strBwGroup);
|
---|
8803 |
|
---|
8804 | // attached image, if any
|
---|
8805 | if (!att.uuid.isZero()
|
---|
8806 | && att.uuid.isValid()
|
---|
8807 | && (att.deviceType == DeviceType_HardDisk
|
---|
8808 | || !fSkipRemovableMedia
|
---|
8809 | )
|
---|
8810 | )
|
---|
8811 | {
|
---|
8812 | xml::ElementNode *pelmImage = pelmDevice->createChild("Image");
|
---|
8813 | pelmImage->setAttribute("uuid", att.uuid.toStringCurly());
|
---|
8814 |
|
---|
8815 | // if caller wants a list of UUID elements, give it to them
|
---|
8816 | if (pllElementsWithUuidAttributes)
|
---|
8817 | pllElementsWithUuidAttributes->push_back(pelmImage);
|
---|
8818 | }
|
---|
8819 | else if ( (m->sv >= SettingsVersion_v1_9)
|
---|
8820 | && (att.strHostDriveSrc.length())
|
---|
8821 | )
|
---|
8822 | pelmDevice->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
8823 | }
|
---|
8824 | }
|
---|
8825 | }
|
---|
8826 |
|
---|
8827 | /**
|
---|
8828 | * Creates a \<Debugging\> node under elmParent and then writes out the XML
|
---|
8829 | * keys under that. Called for both the \<Machine\> node and for snapshots.
|
---|
8830 | *
|
---|
8831 | * @param elmParent Parent element.
|
---|
8832 | * @param dbg Debugging settings.
|
---|
8833 | */
|
---|
8834 | void MachineConfigFile::buildDebuggingXML(xml::ElementNode &elmParent, const Debugging &dbg)
|
---|
8835 | {
|
---|
8836 | if (m->sv < SettingsVersion_v1_13 || dbg.areDefaultSettings())
|
---|
8837 | return;
|
---|
8838 |
|
---|
8839 | xml::ElementNode *pElmDebugging = elmParent.createChild("Debugging");
|
---|
8840 | xml::ElementNode *pElmTracing = pElmDebugging->createChild("Tracing");
|
---|
8841 | pElmTracing->setAttribute("enabled", dbg.fTracingEnabled);
|
---|
8842 | pElmTracing->setAttribute("allowTracingToAccessVM", dbg.fAllowTracingToAccessVM);
|
---|
8843 | pElmTracing->setAttribute("config", dbg.strTracingConfig);
|
---|
8844 |
|
---|
8845 | xml::ElementNode *pElmGuestDebug = pElmDebugging->createChild("GuestDebug");
|
---|
8846 | const char *pcszDebugProvider = NULL;
|
---|
8847 | const char *pcszIoProvider = NULL;
|
---|
8848 |
|
---|
8849 | switch (dbg.enmDbgProvider)
|
---|
8850 | {
|
---|
8851 | case GuestDebugProvider_None: pcszDebugProvider = "None"; break;
|
---|
8852 | case GuestDebugProvider_GDB: pcszDebugProvider = "GDB"; break;
|
---|
8853 | case GuestDebugProvider_KD: pcszDebugProvider = "KD"; break;
|
---|
8854 | default: AssertFailed(); pcszDebugProvider = "None"; break;
|
---|
8855 | }
|
---|
8856 |
|
---|
8857 | switch (dbg.enmIoProvider)
|
---|
8858 | {
|
---|
8859 | case GuestDebugIoProvider_None: pcszIoProvider = "None"; break;
|
---|
8860 | case GuestDebugIoProvider_TCP: pcszIoProvider = "TCP"; break;
|
---|
8861 | case GuestDebugIoProvider_UDP: pcszIoProvider = "UDP"; break;
|
---|
8862 | case GuestDebugIoProvider_IPC: pcszIoProvider = "IPC"; break;
|
---|
8863 | default: AssertFailed(); pcszIoProvider = "None"; break;
|
---|
8864 | }
|
---|
8865 |
|
---|
8866 | pElmGuestDebug->setAttribute("provider", pcszDebugProvider);
|
---|
8867 | pElmGuestDebug->setAttribute("io", pcszIoProvider);
|
---|
8868 | pElmGuestDebug->setAttribute("address", dbg.strAddress);
|
---|
8869 | pElmGuestDebug->setAttribute("port", dbg.ulPort);
|
---|
8870 | }
|
---|
8871 |
|
---|
8872 | /**
|
---|
8873 | * Creates a \<Autostart\> node under elmParent and then writes out the XML
|
---|
8874 | * keys under that. Called for both the \<Machine\> node and for snapshots.
|
---|
8875 | *
|
---|
8876 | * @param elmParent Parent element.
|
---|
8877 | * @param autostrt Autostart settings.
|
---|
8878 | */
|
---|
8879 | void MachineConfigFile::buildAutostartXML(xml::ElementNode &elmParent, const Autostart &autostrt)
|
---|
8880 | {
|
---|
8881 | const char *pcszAutostop = NULL;
|
---|
8882 |
|
---|
8883 | if (m->sv < SettingsVersion_v1_13 || autostrt.areDefaultSettings())
|
---|
8884 | return;
|
---|
8885 |
|
---|
8886 | xml::ElementNode *pElmAutostart = elmParent.createChild("Autostart");
|
---|
8887 | pElmAutostart->setAttribute("enabled", autostrt.fAutostartEnabled);
|
---|
8888 | pElmAutostart->setAttribute("delay", autostrt.uAutostartDelay);
|
---|
8889 |
|
---|
8890 | switch (autostrt.enmAutostopType)
|
---|
8891 | {
|
---|
8892 | case AutostopType_Disabled: pcszAutostop = "Disabled"; break;
|
---|
8893 | case AutostopType_SaveState: pcszAutostop = "SaveState"; break;
|
---|
8894 | case AutostopType_PowerOff: pcszAutostop = "PowerOff"; break;
|
---|
8895 | case AutostopType_AcpiShutdown: pcszAutostop = "AcpiShutdown"; break;
|
---|
8896 | default: Assert(false); pcszAutostop = "Disabled"; break;
|
---|
8897 | }
|
---|
8898 | pElmAutostart->setAttribute("autostop", pcszAutostop);
|
---|
8899 | }
|
---|
8900 |
|
---|
8901 | void MachineConfigFile::buildRecordingXML(xml::ElementNode &elmParent, const RecordingSettings &recording)
|
---|
8902 | {
|
---|
8903 | if (recording.areDefaultSettings()) /* Omit branch if we still have the default settings (i.e. nothing to save). */
|
---|
8904 | return;
|
---|
8905 |
|
---|
8906 | AssertReturnVoid(recording.mapScreens.size() <= 64); /* Make sure we never exceed the bitmap of 64 monitors. */
|
---|
8907 |
|
---|
8908 | /* Note: Since settings 1.19 the recording settings have a dedicated XML branch outside of Hardware. */
|
---|
8909 | if (m->sv >= SettingsVersion_v1_19 /* VBox >= 7.0 */)
|
---|
8910 | {
|
---|
8911 | /* Note: elmParent is Machine or Snapshot. */
|
---|
8912 | xml::ElementNode *pelmRecording = elmParent.createChild("Recording");
|
---|
8913 |
|
---|
8914 | if (!recordingSettings.common.areDefaultSettings())
|
---|
8915 | {
|
---|
8916 | pelmRecording->setAttribute("enabled", recording.common.fEnabled);
|
---|
8917 | }
|
---|
8918 |
|
---|
8919 | /* Only serialize screens which have non-default settings. */
|
---|
8920 | uint32_t cScreensToWrite = 0;
|
---|
8921 |
|
---|
8922 | RecordingScreenSettingsMap::const_iterator itScreen = recording.mapScreens.begin();
|
---|
8923 | while (itScreen != recording.mapScreens.end())
|
---|
8924 | {
|
---|
8925 | if (!itScreen->second.areDefaultSettings())
|
---|
8926 | cScreensToWrite++;
|
---|
8927 | ++itScreen;
|
---|
8928 | }
|
---|
8929 |
|
---|
8930 | if (cScreensToWrite)
|
---|
8931 | pelmRecording->setAttribute("screens", cScreensToWrite);
|
---|
8932 |
|
---|
8933 | itScreen = recording.mapScreens.begin();
|
---|
8934 | while (itScreen != recording.mapScreens.end())
|
---|
8935 | {
|
---|
8936 | if (!itScreen->second.areDefaultSettings()) /* Skip serializing screen settings which have default settings. */
|
---|
8937 | {
|
---|
8938 | xml::ElementNode *pelmScreen = pelmRecording->createChild("Screen");
|
---|
8939 |
|
---|
8940 | pelmScreen->setAttribute("id", itScreen->first); /* The key equals the monitor ID. */
|
---|
8941 | pelmScreen->setAttribute("enabled", itScreen->second.fEnabled);
|
---|
8942 | com::Utf8Str strTemp;
|
---|
8943 | RecordingScreenSettings::featuresToString(itScreen->second.featureMap, strTemp);
|
---|
8944 | pelmScreen->setAttribute("featuresEnabled", strTemp);
|
---|
8945 | if (itScreen->second.ulMaxTimeS)
|
---|
8946 | pelmScreen->setAttribute("maxTimeS", itScreen->second.ulMaxTimeS);
|
---|
8947 | if (itScreen->second.strOptions.isNotEmpty())
|
---|
8948 | pelmScreen->setAttributePath("options", itScreen->second.strOptions);
|
---|
8949 | pelmScreen->setAttribute("dest", itScreen->second.enmDest);
|
---|
8950 | if (!itScreen->second.File.strName.isEmpty())
|
---|
8951 | pelmScreen->setAttributePath("file", itScreen->second.File.strName);
|
---|
8952 | if (itScreen->second.File.ulMaxSizeMB)
|
---|
8953 | pelmScreen->setAttribute("maxSizeMB", itScreen->second.File.ulMaxSizeMB);
|
---|
8954 |
|
---|
8955 | RecordingScreenSettings::videoCodecToString(itScreen->second.Video.enmCodec, strTemp);
|
---|
8956 | pelmScreen->setAttribute("videoCodec", strTemp);
|
---|
8957 | if (itScreen->second.Video.enmDeadline != RecordingCodecDeadline_Default)
|
---|
8958 | pelmScreen->setAttribute("videoDeadline", itScreen->second.Video.enmDeadline);
|
---|
8959 | if (itScreen->second.Video.enmRateCtlMode != RecordingRateControlMode_VBR) /* Is default. */
|
---|
8960 | pelmScreen->setAttribute("videoRateCtlMode", itScreen->second.Video.enmRateCtlMode);
|
---|
8961 | if (itScreen->second.Video.enmScalingMode != RecordingVideoScalingMode_None)
|
---|
8962 | pelmScreen->setAttribute("videoScalingMode",itScreen->second.Video.enmScalingMode);
|
---|
8963 | if ( itScreen->second.Video.ulWidth != 1024
|
---|
8964 | || itScreen->second.Video.ulHeight != 768)
|
---|
8965 | {
|
---|
8966 | pelmScreen->setAttribute("horzRes", itScreen->second.Video.ulWidth);
|
---|
8967 | pelmScreen->setAttribute("vertRes", itScreen->second.Video.ulHeight);
|
---|
8968 | }
|
---|
8969 | if (itScreen->second.Video.ulRate != 512)
|
---|
8970 | pelmScreen->setAttribute("rateKbps", itScreen->second.Video.ulRate);
|
---|
8971 | if (itScreen->second.Video.ulFPS)
|
---|
8972 | pelmScreen->setAttribute("fps", itScreen->second.Video.ulFPS);
|
---|
8973 |
|
---|
8974 | RecordingScreenSettings::audioCodecToString(itScreen->second.Audio.enmCodec, strTemp);
|
---|
8975 | pelmScreen->setAttribute("audioCodec", strTemp);
|
---|
8976 | if (itScreen->second.Audio.enmDeadline != RecordingCodecDeadline_Default)
|
---|
8977 | pelmScreen->setAttribute("audioDeadline", itScreen->second.Audio.enmDeadline);
|
---|
8978 | if (itScreen->second.Audio.enmRateCtlMode != RecordingRateControlMode_VBR) /* Is default. */
|
---|
8979 | pelmScreen->setAttribute("audioRateCtlMode", itScreen->second.Audio.enmRateCtlMode);
|
---|
8980 | if (itScreen->second.Audio.uHz != 22050)
|
---|
8981 | pelmScreen->setAttribute("audioHz", itScreen->second.Audio.uHz);
|
---|
8982 | if (itScreen->second.Audio.cBits != 16)
|
---|
8983 | pelmScreen->setAttribute("audioBits", itScreen->second.Audio.cBits);
|
---|
8984 | if (itScreen->second.Audio.cChannels != 2)
|
---|
8985 | pelmScreen->setAttribute("audioChannels", itScreen->second.Audio.cChannels);
|
---|
8986 | }
|
---|
8987 | ++itScreen;
|
---|
8988 | }
|
---|
8989 | }
|
---|
8990 | else if ( m->sv >= SettingsVersion_v1_14
|
---|
8991 | && m->sv < SettingsVersion_v1_19 /* VBox < 7.0 */)
|
---|
8992 | {
|
---|
8993 | /* Note: elmParent is Hardware or Snapshot. */
|
---|
8994 | xml::ElementNode *pelmVideoCapture = elmParent.createChild("VideoCapture");
|
---|
8995 |
|
---|
8996 | if (!recordingSettings.common.areDefaultSettings())
|
---|
8997 | {
|
---|
8998 | pelmVideoCapture->setAttribute("enabled", recording.common.fEnabled);
|
---|
8999 | }
|
---|
9000 |
|
---|
9001 | /* Convert the enabled screens to the former uint64_t bit array and vice versa. */
|
---|
9002 | uint64_t uScreensBitmap = 0;
|
---|
9003 | RecordingScreenSettingsMap::const_iterator itScreen = recording.mapScreens.begin();
|
---|
9004 | while (itScreen != recording.mapScreens.end())
|
---|
9005 | {
|
---|
9006 | if (itScreen->second.fEnabled)
|
---|
9007 | uScreensBitmap |= RT_BIT_64(itScreen->first);
|
---|
9008 | ++itScreen;
|
---|
9009 | }
|
---|
9010 |
|
---|
9011 | if (uScreensBitmap)
|
---|
9012 | pelmVideoCapture->setAttribute("screens", uScreensBitmap);
|
---|
9013 |
|
---|
9014 | Assert(recording.mapScreens.size());
|
---|
9015 | const RecordingScreenSettingsMap::const_iterator itScreen0Settings = recording.mapScreens.find(0);
|
---|
9016 | Assert(itScreen0Settings != recording.mapScreens.end());
|
---|
9017 |
|
---|
9018 | if (itScreen0Settings->second.ulMaxTimeS)
|
---|
9019 | pelmVideoCapture->setAttribute("maxTime", itScreen0Settings->second.ulMaxTimeS);
|
---|
9020 | if (itScreen0Settings->second.strOptions.isNotEmpty())
|
---|
9021 | pelmVideoCapture->setAttributePath("options", itScreen0Settings->second.strOptions);
|
---|
9022 |
|
---|
9023 | if (!itScreen0Settings->second.File.strName.isEmpty())
|
---|
9024 | pelmVideoCapture->setAttributePath("file", itScreen0Settings->second.File.strName);
|
---|
9025 | if (itScreen0Settings->second.File.ulMaxSizeMB)
|
---|
9026 | pelmVideoCapture->setAttribute("maxSize", itScreen0Settings->second.File.ulMaxSizeMB);
|
---|
9027 |
|
---|
9028 | if ( itScreen0Settings->second.Video.ulWidth != 1024
|
---|
9029 | || itScreen0Settings->second.Video.ulHeight != 768)
|
---|
9030 | {
|
---|
9031 | pelmVideoCapture->setAttribute("horzRes", itScreen0Settings->second.Video.ulWidth);
|
---|
9032 | pelmVideoCapture->setAttribute("vertRes", itScreen0Settings->second.Video.ulHeight);
|
---|
9033 | }
|
---|
9034 | if (itScreen0Settings->second.Video.ulRate != 512)
|
---|
9035 | pelmVideoCapture->setAttribute("rate", itScreen0Settings->second.Video.ulRate);
|
---|
9036 | if (itScreen0Settings->second.Video.ulFPS)
|
---|
9037 | pelmVideoCapture->setAttribute("fps", itScreen0Settings->second.Video.ulFPS);
|
---|
9038 | }
|
---|
9039 | }
|
---|
9040 |
|
---|
9041 | /**
|
---|
9042 | * Creates a \<Groups\> node under elmParent and then writes out the XML
|
---|
9043 | * keys under that. Called for the \<Machine\> node only.
|
---|
9044 | *
|
---|
9045 | * @param elmParent Parent element.
|
---|
9046 | * @param llGroups Groups list.
|
---|
9047 | */
|
---|
9048 | void MachineConfigFile::buildGroupsXML(xml::ElementNode &elmParent, const StringsList &llGroups)
|
---|
9049 | {
|
---|
9050 | if ( m->sv < SettingsVersion_v1_13 || llGroups.size() == 0
|
---|
9051 | || (llGroups.size() == 1 && llGroups.front() == "/"))
|
---|
9052 | return;
|
---|
9053 |
|
---|
9054 | xml::ElementNode *pElmGroups = elmParent.createChild("Groups");
|
---|
9055 | for (StringsList::const_iterator it = llGroups.begin();
|
---|
9056 | it != llGroups.end();
|
---|
9057 | ++it)
|
---|
9058 | {
|
---|
9059 | const Utf8Str &group = *it;
|
---|
9060 | xml::ElementNode *pElmGroup = pElmGroups->createChild("Group");
|
---|
9061 | pElmGroup->setAttribute("name", group);
|
---|
9062 | }
|
---|
9063 | }
|
---|
9064 |
|
---|
9065 | /**
|
---|
9066 | * Writes a single snapshot into the DOM tree. Initially this gets called from
|
---|
9067 | * MachineConfigFile::write() for the root snapshot of a machine, if present;
|
---|
9068 | * elmParent then points to the \<Snapshots\> node under the \<Machine\> node
|
---|
9069 | * to which \<Snapshot\> must be added. This may then continue processing the
|
---|
9070 | * child snapshots.
|
---|
9071 | *
|
---|
9072 | * @param elmParent
|
---|
9073 | * @param snap
|
---|
9074 | */
|
---|
9075 | void MachineConfigFile::buildSnapshotXML(xml::ElementNode &elmParent,
|
---|
9076 | const Snapshot &snap)
|
---|
9077 | {
|
---|
9078 | std::list<const Snapshot *> llSettingsTodo;
|
---|
9079 | llSettingsTodo.push_back(&snap);
|
---|
9080 | std::list<xml::ElementNode *> llElementsTodo;
|
---|
9081 | llElementsTodo.push_back(&elmParent);
|
---|
9082 | std::list<uint32_t> llDepthsTodo;
|
---|
9083 | llDepthsTodo.push_back(1);
|
---|
9084 |
|
---|
9085 | while (llSettingsTodo.size() > 0)
|
---|
9086 | {
|
---|
9087 | const Snapshot *pSnap = llSettingsTodo.front();
|
---|
9088 | llSettingsTodo.pop_front();
|
---|
9089 | xml::ElementNode *pElement = llElementsTodo.front();
|
---|
9090 | llElementsTodo.pop_front();
|
---|
9091 | uint32_t depth = llDepthsTodo.front();
|
---|
9092 | llDepthsTodo.pop_front();
|
---|
9093 |
|
---|
9094 | if (depth > SETTINGS_SNAPSHOT_DEPTH_MAX)
|
---|
9095 | throw ConfigFileError(this, NULL, N_("Maximum snapshot tree depth of %u exceeded"), SETTINGS_SNAPSHOT_DEPTH_MAX);
|
---|
9096 |
|
---|
9097 | xml::ElementNode *pelmSnapshot = pElement->createChild("Snapshot");
|
---|
9098 |
|
---|
9099 | pelmSnapshot->setAttribute("uuid", pSnap->uuid.toStringCurly());
|
---|
9100 | pelmSnapshot->setAttribute("name", pSnap->strName);
|
---|
9101 | pelmSnapshot->setAttribute("timeStamp", stringifyTimestamp(pSnap->timestamp));
|
---|
9102 |
|
---|
9103 | if (pSnap->strStateFile.length())
|
---|
9104 | pelmSnapshot->setAttributePath("stateFile", pSnap->strStateFile);
|
---|
9105 |
|
---|
9106 | if (pSnap->strDescription.length())
|
---|
9107 | pelmSnapshot->createChild("Description")->addContent(pSnap->strDescription);
|
---|
9108 |
|
---|
9109 | // We only skip removable media for OVF, but OVF never includes snapshots.
|
---|
9110 | buildHardwareXML(*pelmSnapshot, pSnap->hardware, 0 /* fl */, NULL /* pllElementsWithUuidAttributes */);
|
---|
9111 | buildDebuggingXML(*pelmSnapshot, pSnap->debugging);
|
---|
9112 | buildAutostartXML(*pelmSnapshot, pSnap->autostart);
|
---|
9113 | buildRecordingXML(*pelmSnapshot, pSnap->recordingSettings);
|
---|
9114 | // note: Groups exist only for Machine, not for Snapshot
|
---|
9115 |
|
---|
9116 | if (m->sv < SettingsVersion_v1_20) /* Before settings v1.20 the platform stuff lived directly in the Hardware element. */
|
---|
9117 | {
|
---|
9118 | xml::ElementNode *pelHardware = unconst(pelmSnapshot->findChildElement("Hardware"));
|
---|
9119 | if (pelHardware)
|
---|
9120 | buildPlatformXML(*pelHardware, pSnap->hardware, pSnap->hardware.platformSettings);
|
---|
9121 | }
|
---|
9122 | else /* Now lives outside of "Hardware", in "Platform". */
|
---|
9123 | buildPlatformXML(*pelmSnapshot, pSnap->hardware, pSnap->hardware.platformSettings);
|
---|
9124 |
|
---|
9125 | if (pSnap->llChildSnapshots.size())
|
---|
9126 | {
|
---|
9127 | xml::ElementNode *pelmChildren = pelmSnapshot->createChild("Snapshots");
|
---|
9128 | for (SnapshotsList::const_iterator it = pSnap->llChildSnapshots.begin();
|
---|
9129 | it != pSnap->llChildSnapshots.end();
|
---|
9130 | ++it)
|
---|
9131 | {
|
---|
9132 | llSettingsTodo.push_back(&*it);
|
---|
9133 | llElementsTodo.push_back(pelmChildren);
|
---|
9134 | llDepthsTodo.push_back(depth + 1);
|
---|
9135 | }
|
---|
9136 | }
|
---|
9137 | }
|
---|
9138 | }
|
---|
9139 |
|
---|
9140 | /**
|
---|
9141 | * Builds the XML DOM tree for the machine config under the given XML element.
|
---|
9142 | *
|
---|
9143 | * This has been separated out from write() so it can be called from elsewhere,
|
---|
9144 | * such as the OVF code, to build machine XML in an existing XML tree.
|
---|
9145 | *
|
---|
9146 | * As a result, this gets called from two locations:
|
---|
9147 | *
|
---|
9148 | * -- MachineConfigFile::write();
|
---|
9149 | *
|
---|
9150 | * -- Appliance::buildXMLForOneVirtualSystem()
|
---|
9151 | *
|
---|
9152 | * In fl, the following flag bits are recognized:
|
---|
9153 | *
|
---|
9154 | * -- BuildMachineXML_MediaRegistry: If set, the machine's media registry will
|
---|
9155 | * be written, if present. This is not set when called from OVF because OVF
|
---|
9156 | * has its own variant of a media registry. This flag is ignored unless the
|
---|
9157 | * settings version is at least v1.11 (VirtualBox 4.0).
|
---|
9158 | *
|
---|
9159 | * -- BuildMachineXML_IncludeSnapshots: If set, descend into the snapshots tree
|
---|
9160 | * of the machine and write out \<Snapshot\> and possibly more snapshots under
|
---|
9161 | * that, if snapshots are present. Otherwise all snapshots are suppressed
|
---|
9162 | * (when called from OVF).
|
---|
9163 | *
|
---|
9164 | * -- BuildMachineXML_WriteVBoxVersionAttribute: If set, add a settingsVersion
|
---|
9165 | * attribute to the machine tag with the vbox settings version. This is for
|
---|
9166 | * the OVF export case in which we don't have the settings version set in
|
---|
9167 | * the root element.
|
---|
9168 | *
|
---|
9169 | * -- BuildMachineXML_SkipRemovableMedia: If set, removable media attachments
|
---|
9170 | * (DVDs, floppies) are silently skipped. This is for the OVF export case
|
---|
9171 | * until we support copying ISO and RAW media as well. This flag is ignored
|
---|
9172 | * unless the settings version is at least v1.9, which is always the case
|
---|
9173 | * when this gets called for OVF export.
|
---|
9174 | *
|
---|
9175 | * -- BuildMachineXML_SuppressSavedState: If set, the Machine/stateFile
|
---|
9176 | * attribute is never set. This is also for the OVF export case because we
|
---|
9177 | * cannot save states with OVF.
|
---|
9178 | *
|
---|
9179 | * @param elmMachine XML \<Machine\> element to add attributes and elements to.
|
---|
9180 | * @param fl Flags.
|
---|
9181 | * @param pllElementsWithUuidAttributes pointer to list that should receive UUID elements or NULL;
|
---|
9182 | * see buildStorageControllersXML() for details.
|
---|
9183 | */
|
---|
9184 | void MachineConfigFile::buildMachineXML(xml::ElementNode &elmMachine,
|
---|
9185 | uint32_t fl,
|
---|
9186 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes)
|
---|
9187 | {
|
---|
9188 | if (fl & BuildMachineXML_WriteVBoxVersionAttribute)
|
---|
9189 | {
|
---|
9190 | // add settings version attribute to machine element
|
---|
9191 | setVersionAttribute(elmMachine);
|
---|
9192 | LogRel(("Exporting settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
|
---|
9193 | }
|
---|
9194 |
|
---|
9195 | elmMachine.setAttribute("uuid", uuid.toStringCurly());
|
---|
9196 | elmMachine.setAttribute("name", machineUserData.strName);
|
---|
9197 | if (machineUserData.fDirectoryIncludesUUID)
|
---|
9198 | elmMachine.setAttribute("directoryIncludesUUID", machineUserData.fDirectoryIncludesUUID);
|
---|
9199 | if (!machineUserData.fNameSync)
|
---|
9200 | elmMachine.setAttribute("nameSync", machineUserData.fNameSync);
|
---|
9201 | if (machineUserData.strDescription.length())
|
---|
9202 | elmMachine.createChild("Description")->addContent(machineUserData.strDescription);
|
---|
9203 |
|
---|
9204 | #ifdef GUEST_OS_ID_STYLE_PARTIAL_CLEANUP
|
---|
9205 | com::Utf8Str strOsType = machineUserData.strOsType;
|
---|
9206 | if (m->sv < SettingsVersion_v1_20)
|
---|
9207 | convertGuestOSTypeToPre1_20(strOsType);
|
---|
9208 | elmMachine.setAttribute("OSType", strOsType);
|
---|
9209 | #else
|
---|
9210 | elmMachine.setAttribute("OSType", machineUserData.strOsType);
|
---|
9211 | #endif
|
---|
9212 |
|
---|
9213 | if (m->sv >= SettingsVersion_v1_19)
|
---|
9214 | {
|
---|
9215 | if (strStateKeyId.length())
|
---|
9216 | elmMachine.setAttribute("stateKeyId", strStateKeyId);
|
---|
9217 | if (strStateKeyStore.length())
|
---|
9218 | elmMachine.setAttribute("stateKeyStore", strStateKeyStore);
|
---|
9219 | if (strLogKeyId.length())
|
---|
9220 | elmMachine.setAttribute("logKeyId", strLogKeyId);
|
---|
9221 | if (strLogKeyStore.length())
|
---|
9222 | elmMachine.setAttribute("logKeyStore", strLogKeyStore);
|
---|
9223 | }
|
---|
9224 | if ( strStateFile.length()
|
---|
9225 | && !(fl & BuildMachineXML_SuppressSavedState)
|
---|
9226 | )
|
---|
9227 | elmMachine.setAttributePath("stateFile", strStateFile);
|
---|
9228 |
|
---|
9229 | if ((fl & BuildMachineXML_IncludeSnapshots)
|
---|
9230 | && !uuidCurrentSnapshot.isZero()
|
---|
9231 | && uuidCurrentSnapshot.isValid())
|
---|
9232 | elmMachine.setAttribute("currentSnapshot", uuidCurrentSnapshot.toStringCurly());
|
---|
9233 |
|
---|
9234 | if (machineUserData.strSnapshotFolder.length())
|
---|
9235 | elmMachine.setAttributePath("snapshotFolder", machineUserData.strSnapshotFolder);
|
---|
9236 | if (!fCurrentStateModified)
|
---|
9237 | elmMachine.setAttribute("currentStateModified", fCurrentStateModified);
|
---|
9238 | elmMachine.setAttribute("lastStateChange", stringifyTimestamp(timeLastStateChange));
|
---|
9239 | if (fAborted)
|
---|
9240 | elmMachine.setAttribute("aborted", fAborted);
|
---|
9241 |
|
---|
9242 | switch (machineUserData.enmVMPriority)
|
---|
9243 | {
|
---|
9244 | case VMProcPriority_Flat:
|
---|
9245 | elmMachine.setAttribute("processPriority", "Flat");
|
---|
9246 | break;
|
---|
9247 | case VMProcPriority_Low:
|
---|
9248 | elmMachine.setAttribute("processPriority", "Low");
|
---|
9249 | break;
|
---|
9250 | case VMProcPriority_Normal:
|
---|
9251 | elmMachine.setAttribute("processPriority", "Normal");
|
---|
9252 | break;
|
---|
9253 | case VMProcPriority_High:
|
---|
9254 | elmMachine.setAttribute("processPriority", "High");
|
---|
9255 | break;
|
---|
9256 | default:
|
---|
9257 | break;
|
---|
9258 | }
|
---|
9259 |
|
---|
9260 | switch (machineUserData.enmExecEngine)
|
---|
9261 | {
|
---|
9262 | case VMExecutionEngine_HwVirt:
|
---|
9263 | elmMachine.setAttribute("executionEngine", "HwVirt");
|
---|
9264 | break;
|
---|
9265 | case VMExecutionEngine_NativeApi:
|
---|
9266 | elmMachine.setAttribute("executionEngine", "NativeApi");
|
---|
9267 | break;
|
---|
9268 | case VMExecutionEngine_Interpreter:
|
---|
9269 | elmMachine.setAttribute("executionEngine", "Interpreter");
|
---|
9270 | break;
|
---|
9271 | case VMExecutionEngine_Recompiler:
|
---|
9272 | elmMachine.setAttribute("executionEngine", "Recompiler");
|
---|
9273 | break;
|
---|
9274 | case VMExecutionEngine_Default:
|
---|
9275 | default:
|
---|
9276 | break;
|
---|
9277 | }
|
---|
9278 |
|
---|
9279 | // Please keep the icon last so that one doesn't have to check if there
|
---|
9280 | // is anything in the line after this very long attribute in the XML.
|
---|
9281 | if (machineUserData.ovIcon.size())
|
---|
9282 | {
|
---|
9283 | Utf8Str strIcon;
|
---|
9284 | toBase64(strIcon, machineUserData.ovIcon);
|
---|
9285 | elmMachine.setAttribute("icon", strIcon);
|
---|
9286 | }
|
---|
9287 | if ( m->sv >= SettingsVersion_v1_9
|
---|
9288 | && ( machineUserData.fTeleporterEnabled
|
---|
9289 | || machineUserData.uTeleporterPort
|
---|
9290 | || !machineUserData.strTeleporterAddress.isEmpty()
|
---|
9291 | || !machineUserData.strTeleporterPassword.isEmpty()
|
---|
9292 | )
|
---|
9293 | )
|
---|
9294 | {
|
---|
9295 | xml::ElementNode *pelmTeleporter = elmMachine.createChild("Teleporter");
|
---|
9296 | pelmTeleporter->setAttribute("enabled", machineUserData.fTeleporterEnabled);
|
---|
9297 | pelmTeleporter->setAttribute("port", machineUserData.uTeleporterPort);
|
---|
9298 | pelmTeleporter->setAttribute("address", machineUserData.strTeleporterAddress);
|
---|
9299 | pelmTeleporter->setAttribute("password", machineUserData.strTeleporterPassword);
|
---|
9300 | }
|
---|
9301 |
|
---|
9302 | if ( (fl & BuildMachineXML_MediaRegistry)
|
---|
9303 | && (m->sv >= SettingsVersion_v1_11)
|
---|
9304 | )
|
---|
9305 | buildMediaRegistry(elmMachine, mediaRegistry);
|
---|
9306 |
|
---|
9307 | buildExtraData(elmMachine, mapExtraDataItems);
|
---|
9308 |
|
---|
9309 | if ( (fl & BuildMachineXML_IncludeSnapshots)
|
---|
9310 | && llFirstSnapshot.size())
|
---|
9311 | buildSnapshotXML(elmMachine, llFirstSnapshot.front());
|
---|
9312 |
|
---|
9313 | buildHardwareXML(elmMachine, hardwareMachine, fl, pllElementsWithUuidAttributes);
|
---|
9314 | buildDebuggingXML(elmMachine, debugging);
|
---|
9315 | buildAutostartXML(elmMachine, autostart);
|
---|
9316 |
|
---|
9317 | /* Note: Must come *after* buildHardwareXML(), as the "Hardware" branch is needed. */
|
---|
9318 | if ( m->sv >= SettingsVersion_v1_14
|
---|
9319 | && m->sv < SettingsVersion_v1_19) /* < VBox 7.0. */
|
---|
9320 | {
|
---|
9321 | xml::ElementNode *pelHardware = unconst(elmMachine.findChildElement("Hardware"));
|
---|
9322 | if (pelHardware)
|
---|
9323 | buildRecordingXML(*pelHardware, recordingSettings);
|
---|
9324 | }
|
---|
9325 | else if (m->sv >= SettingsVersion_v1_19) /* Now lives outside of "Hardware", in "Machine". */
|
---|
9326 | buildRecordingXML(elmMachine, recordingSettings);
|
---|
9327 |
|
---|
9328 | buildGroupsXML(elmMachine, machineUserData.llGroups);
|
---|
9329 |
|
---|
9330 | /* Note: Must come *after* buildHardwareXML(), as the "Hardware" branch is needed. */
|
---|
9331 | if (m->sv < SettingsVersion_v1_20)
|
---|
9332 | {
|
---|
9333 | xml::ElementNode *pelHardware = unconst(elmMachine.findChildElement("Hardware"));
|
---|
9334 | if (pelHardware)
|
---|
9335 | buildPlatformXML(*pelHardware, hardwareMachine, hardwareMachine.platformSettings);
|
---|
9336 | }
|
---|
9337 | else /* Now lives outside of "Hardware", in "Platform". */
|
---|
9338 | buildPlatformXML(elmMachine, hardwareMachine, hardwareMachine.platformSettings);
|
---|
9339 | }
|
---|
9340 |
|
---|
9341 | /**
|
---|
9342 | * Builds encrypted config.
|
---|
9343 | *
|
---|
9344 | * @sa MachineConfigFile::buildMachineXML
|
---|
9345 | */
|
---|
9346 | void MachineConfigFile::buildMachineEncryptedXML(xml::ElementNode &elmMachine,
|
---|
9347 | uint32_t fl,
|
---|
9348 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
|
---|
9349 | PCVBOXCRYPTOIF pCryptoIf,
|
---|
9350 | const char *pszPassword = NULL)
|
---|
9351 | {
|
---|
9352 | if ( !pszPassword
|
---|
9353 | || !pCryptoIf)
|
---|
9354 | throw ConfigFileError(this, &elmMachine, N_("Password is required"));
|
---|
9355 |
|
---|
9356 | xml::Document *pDoc = new xml::Document;
|
---|
9357 | xml::ElementNode *pelmRoot = pDoc->createRootElement("Machine");
|
---|
9358 | pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
|
---|
9359 | // Have the code for producing a proper schema reference. Not used by most
|
---|
9360 | // tools, so don't bother doing it. The schema is not on the server anyway.
|
---|
9361 | #ifdef VBOX_WITH_SETTINGS_SCHEMA
|
---|
9362 | pelmRoot->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
---|
9363 | pelmRoot->setAttribute("xsi:schemaLocation", VBOX_XML_NAMESPACE " " VBOX_XML_SCHEMA);
|
---|
9364 | #endif
|
---|
9365 |
|
---|
9366 | buildMachineXML(*pelmRoot, fl, pllElementsWithUuidAttributes);
|
---|
9367 | xml::XmlStringWriter writer;
|
---|
9368 | com::Utf8Str strMachineXml;
|
---|
9369 | int vrc = writer.write(*pDoc, &strMachineXml);
|
---|
9370 | delete pDoc;
|
---|
9371 | if (RT_SUCCESS(vrc))
|
---|
9372 | {
|
---|
9373 | VBOXCRYPTOCTX hCryptoCtx;
|
---|
9374 | if (strKeyStore.isEmpty())
|
---|
9375 | {
|
---|
9376 | vrc = pCryptoIf->pfnCryptoCtxCreate("AES-GCM256", pszPassword, &hCryptoCtx);
|
---|
9377 | if (RT_SUCCESS(vrc))
|
---|
9378 | {
|
---|
9379 | char *pszNewKeyStore;
|
---|
9380 | vrc = pCryptoIf->pfnCryptoCtxSave(hCryptoCtx, &pszNewKeyStore);
|
---|
9381 | if (RT_SUCCESS(vrc))
|
---|
9382 | {
|
---|
9383 | strKeyStore = pszNewKeyStore;
|
---|
9384 | RTStrFree(pszNewKeyStore);
|
---|
9385 | }
|
---|
9386 | else
|
---|
9387 | pCryptoIf->pfnCryptoCtxDestroy(hCryptoCtx);
|
---|
9388 | }
|
---|
9389 | }
|
---|
9390 | else
|
---|
9391 | vrc = pCryptoIf->pfnCryptoCtxLoad(strKeyStore.c_str(), pszPassword, &hCryptoCtx);
|
---|
9392 | if (RT_SUCCESS(vrc))
|
---|
9393 | {
|
---|
9394 | IconBlob abEncrypted;
|
---|
9395 | size_t cbEncrypted = 0;
|
---|
9396 | vrc = pCryptoIf->pfnCryptoCtxQueryEncryptedSize(hCryptoCtx, strMachineXml.length(), &cbEncrypted);
|
---|
9397 | if (RT_SUCCESS(vrc))
|
---|
9398 | {
|
---|
9399 | abEncrypted.resize(cbEncrypted);
|
---|
9400 | vrc = pCryptoIf->pfnCryptoCtxEncrypt(hCryptoCtx, false /*fPartial*/, NULL /*pvIV*/, 0 /*cbIV*/,
|
---|
9401 | strMachineXml.c_str(), strMachineXml.length(),
|
---|
9402 | uuid.raw(), sizeof(RTUUID),
|
---|
9403 | &abEncrypted[0], abEncrypted.size(), &cbEncrypted);
|
---|
9404 | int vrc2 = pCryptoIf->pfnCryptoCtxDestroy(hCryptoCtx);
|
---|
9405 | AssertRC(vrc2);
|
---|
9406 | if (RT_SUCCESS(vrc))
|
---|
9407 | {
|
---|
9408 | abEncrypted.resize(cbEncrypted);
|
---|
9409 | toBase64(strMachineXml, abEncrypted);
|
---|
9410 | elmMachine.setAttribute("uuid", uuid.toStringCurly());
|
---|
9411 | elmMachine.setAttribute("keyId", strKeyId);
|
---|
9412 | elmMachine.setAttribute("keyStore", strKeyStore);
|
---|
9413 | elmMachine.setContent(strMachineXml.c_str());
|
---|
9414 | }
|
---|
9415 | }
|
---|
9416 | }
|
---|
9417 |
|
---|
9418 | if (RT_FAILURE(vrc))
|
---|
9419 | throw ConfigFileError(this, &elmMachine, N_("Creating machine encrypted xml failed. (%Rrc)"), vrc);
|
---|
9420 | }
|
---|
9421 | else
|
---|
9422 | throw ConfigFileError(this, &elmMachine, N_("Creating machine xml failed. (%Rrc)"), vrc);
|
---|
9423 | }
|
---|
9424 |
|
---|
9425 | /**
|
---|
9426 | * Returns true only if the given AudioDriverType is supported on
|
---|
9427 | * the current host platform. For example, this would return false
|
---|
9428 | * for AudioDriverType_DirectSound when compiled on a Linux host.
|
---|
9429 | *
|
---|
9430 | * @return @c true if the current host supports the driver, @c false if not.
|
---|
9431 | * @param enmDrvType AudioDriverType_* enum to test.
|
---|
9432 | */
|
---|
9433 | /*static*/
|
---|
9434 | bool MachineConfigFile::isAudioDriverAllowedOnThisHost(AudioDriverType_T enmDrvType)
|
---|
9435 | {
|
---|
9436 | switch (enmDrvType)
|
---|
9437 | {
|
---|
9438 | case AudioDriverType_Default:
|
---|
9439 | RT_FALL_THROUGH();
|
---|
9440 | case AudioDriverType_Null:
|
---|
9441 | return true; /* Default and Null audio are always allowed. */
|
---|
9442 | #ifdef RT_OS_WINDOWS
|
---|
9443 | case AudioDriverType_WAS:
|
---|
9444 | /* We only support WAS on systems we tested so far (Vista+). */
|
---|
9445 | if (RTSystemGetNtVersion() < RTSYSTEM_MAKE_NT_VERSION(6,1,0))
|
---|
9446 | break;
|
---|
9447 | RT_FALL_THROUGH();
|
---|
9448 | case AudioDriverType_DirectSound:
|
---|
9449 | #endif
|
---|
9450 | #ifdef VBOX_WITH_AUDIO_OSS
|
---|
9451 | case AudioDriverType_OSS:
|
---|
9452 | #endif
|
---|
9453 | #ifdef VBOX_WITH_AUDIO_ALSA
|
---|
9454 | case AudioDriverType_ALSA:
|
---|
9455 | #endif
|
---|
9456 | #ifdef VBOX_WITH_AUDIO_PULSE
|
---|
9457 | case AudioDriverType_Pulse:
|
---|
9458 | #endif
|
---|
9459 | #ifdef RT_OS_DARWIN
|
---|
9460 | case AudioDriverType_CoreAudio:
|
---|
9461 | #endif
|
---|
9462 | #ifdef RT_OS_OS2
|
---|
9463 | case AudioDriverType_MMPM:
|
---|
9464 | #endif
|
---|
9465 | return true;
|
---|
9466 | default: break; /* Shut up MSC. */
|
---|
9467 | }
|
---|
9468 |
|
---|
9469 | return false;
|
---|
9470 | }
|
---|
9471 |
|
---|
9472 | /**
|
---|
9473 | * Returns the AudioDriverType_* which should be used by default on this
|
---|
9474 | * host platform. On Linux, this will check at runtime whether PulseAudio
|
---|
9475 | * or ALSA are actually supported on the first call.
|
---|
9476 | *
|
---|
9477 | * When more than one supported audio stack is available, choose the most suited
|
---|
9478 | * (probably newest in most cases) one.
|
---|
9479 | *
|
---|
9480 | * @return Default audio driver type for this host platform.
|
---|
9481 | */
|
---|
9482 | /*static*/
|
---|
9483 | AudioDriverType_T MachineConfigFile::getHostDefaultAudioDriver()
|
---|
9484 | {
|
---|
9485 | #if defined(RT_OS_WINDOWS)
|
---|
9486 | if (RTSystemGetNtVersion() >= RTSYSTEM_MAKE_NT_VERSION(6,1,0))
|
---|
9487 | return AudioDriverType_WAS;
|
---|
9488 | return AudioDriverType_DirectSound;
|
---|
9489 |
|
---|
9490 | #elif defined(RT_OS_LINUX)
|
---|
9491 | /* On Linux, we need to check at runtime what's actually supported.
|
---|
9492 | * Descending precedence. */
|
---|
9493 | static RTCLockMtx s_mtx;
|
---|
9494 | static AudioDriverType_T s_enmLinuxDriver = AudioDriverType_Null;
|
---|
9495 | RTCLock lock(s_mtx);
|
---|
9496 | if (s_enmLinuxDriver == AudioDriverType_Null) /* Already determined from a former run? */
|
---|
9497 | {
|
---|
9498 | # ifdef VBOX_WITH_AUDIO_PULSE
|
---|
9499 | /* Check for the pulse library & that the PulseAudio daemon is running. */
|
---|
9500 | if ( ( RTProcIsRunningByName("pulseaudio")
|
---|
9501 | /* We also use the PulseAudio backend when we find pipewire-pulse running, which
|
---|
9502 | * acts as a PulseAudio-compatible daemon for Pipewire-enabled applications. See @ticketref{21575} */
|
---|
9503 | || RTProcIsRunningByName("pipewire-pulse"))
|
---|
9504 | && RTLdrIsLoadable("libpulse.so.0"))
|
---|
9505 | {
|
---|
9506 | s_enmLinuxDriver = AudioDriverType_Pulse;
|
---|
9507 | }
|
---|
9508 | #endif /* VBOX_WITH_AUDIO_PULSE */
|
---|
9509 |
|
---|
9510 | # ifdef VBOX_WITH_AUDIO_ALSA
|
---|
9511 | if (s_enmLinuxDriver == AudioDriverType_Null)
|
---|
9512 | {
|
---|
9513 | /* Check if we can load the ALSA library */
|
---|
9514 | if (RTLdrIsLoadable("libasound.so.2"))
|
---|
9515 | s_enmLinuxDriver = AudioDriverType_ALSA;
|
---|
9516 | }
|
---|
9517 | # endif /* VBOX_WITH_AUDIO_ALSA */
|
---|
9518 |
|
---|
9519 | # ifdef VBOX_WITH_AUDIO_OSS
|
---|
9520 | if (s_enmLinuxDriver == AudioDriverType_Null)
|
---|
9521 | s_enmLinuxDriver = AudioDriverType_OSS;
|
---|
9522 | # endif /* VBOX_WITH_AUDIO_OSS */
|
---|
9523 | }
|
---|
9524 | return s_enmLinuxDriver;
|
---|
9525 |
|
---|
9526 | #elif defined(RT_OS_DARWIN)
|
---|
9527 | return AudioDriverType_CoreAudio;
|
---|
9528 |
|
---|
9529 | #elif defined(RT_OS_OS2)
|
---|
9530 | return AudioDriverType_MMPM;
|
---|
9531 |
|
---|
9532 | #else /* All other platforms. */
|
---|
9533 | # ifdef VBOX_WITH_AUDIO_OSS
|
---|
9534 | return AudioDriverType_OSS;
|
---|
9535 | # else
|
---|
9536 | /* Return NULL driver as a fallback if nothing of the above is available. */
|
---|
9537 | return AudioDriverType_Null;
|
---|
9538 | # endif
|
---|
9539 | #endif
|
---|
9540 | }
|
---|
9541 |
|
---|
9542 | /**
|
---|
9543 | * Called from write() before calling ConfigFileBase::createStubDocument().
|
---|
9544 | * This adjusts the settings version in m->sv if incompatible settings require
|
---|
9545 | * a settings bump, whereas otherwise we try to preserve the settings version
|
---|
9546 | * to avoid breaking compatibility with older versions.
|
---|
9547 | *
|
---|
9548 | * We do the checks in here in reverse order: newest first, oldest last, so
|
---|
9549 | * that we avoid unnecessary checks since some of these are expensive.
|
---|
9550 | */
|
---|
9551 | void MachineConfigFile::bumpSettingsVersionIfNeeded()
|
---|
9552 | {
|
---|
9553 | if (m->sv < SettingsVersion_v1_20)
|
---|
9554 | {
|
---|
9555 | // VirtualBox 7.1 (settings v1.20) adds support for different VM platforms and the QEMU RAM based framebuffer device.
|
---|
9556 | if ( ( hardwareMachine.platformSettings.architectureType != PlatformArchitecture_None
|
---|
9557 | && hardwareMachine.platformSettings.architectureType != PlatformArchitecture_x86)
|
---|
9558 | || hardwareMachine.graphicsAdapter.graphicsControllerType == GraphicsControllerType_QemuRamFB
|
---|
9559 | || machineUserData.enmExecEngine != VMExecutionEngine_Default)
|
---|
9560 | {
|
---|
9561 | /* Note: The new chipset type ARMv8Virtual implies setting the platform architecture type to ARM. */
|
---|
9562 | m->sv = SettingsVersion_v1_20;
|
---|
9563 | return;
|
---|
9564 | }
|
---|
9565 |
|
---|
9566 | // VirtualBox 7.1 (settings v1.20) adds support for customizable control over Shared Folders symlink creation.
|
---|
9567 | if (hardwareMachine.llSharedFolders.size())
|
---|
9568 | {
|
---|
9569 | for (SharedFoldersList::const_iterator it = hardwareMachine.llSharedFolders.begin();
|
---|
9570 | it != hardwareMachine.llSharedFolders.end();
|
---|
9571 | ++it)
|
---|
9572 | {
|
---|
9573 | if (it->enmSymlinkPolicy != SymlinkPolicy_None)
|
---|
9574 | {
|
---|
9575 | m->sv = SettingsVersion_v1_20;
|
---|
9576 | return;
|
---|
9577 | }
|
---|
9578 | }
|
---|
9579 | }
|
---|
9580 | }
|
---|
9581 |
|
---|
9582 | if (m->sv < SettingsVersion_v1_19)
|
---|
9583 | {
|
---|
9584 | // VirtualBox 7.0 adds iommu device and full VM encryption.
|
---|
9585 | if ( hardwareMachine.platformSettings.iommuType != IommuType_None
|
---|
9586 | || strKeyId.isNotEmpty()
|
---|
9587 | || strKeyStore.isNotEmpty()
|
---|
9588 | || strStateKeyId.isNotEmpty()
|
---|
9589 | || strStateKeyStore.isNotEmpty()
|
---|
9590 | || hardwareMachine.nvramSettings.strKeyId.isNotEmpty()
|
---|
9591 | || hardwareMachine.nvramSettings.strKeyStore.isNotEmpty()
|
---|
9592 | /* Default for newly created VMs in VBox 7.0.
|
---|
9593 | * Older VMs might have a specific audio driver set (also for VMs created with < VBox 7.0). */
|
---|
9594 | || hardwareMachine.audioAdapter.driverType == AudioDriverType_Default
|
---|
9595 | || recordingSettings.areDefaultSettings() == false
|
---|
9596 | || strLogKeyId.isNotEmpty()
|
---|
9597 | || strLogKeyStore.isEmpty())
|
---|
9598 | {
|
---|
9599 | m->sv = SettingsVersion_v1_19;
|
---|
9600 | return;
|
---|
9601 | }
|
---|
9602 |
|
---|
9603 | // VirtualBox 7.0 adds a Trusted Platform Module.
|
---|
9604 | if ( hardwareMachine.tpmSettings.tpmType != TpmType_None
|
---|
9605 | || hardwareMachine.tpmSettings.strLocation.isNotEmpty())
|
---|
9606 | {
|
---|
9607 | m->sv = SettingsVersion_v1_19;
|
---|
9608 | return;
|
---|
9609 | }
|
---|
9610 |
|
---|
9611 | NetworkAdaptersList::const_iterator netit;
|
---|
9612 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
9613 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
9614 | ++netit)
|
---|
9615 | {
|
---|
9616 | // VirtualBox 7.0 adds a flag if NAT can reach localhost.
|
---|
9617 | if ( netit->fEnabled
|
---|
9618 | && netit->mode == NetworkAttachmentType_NAT
|
---|
9619 | && !netit->nat.fLocalhostReachable)
|
---|
9620 | {
|
---|
9621 | m->sv = SettingsVersion_v1_19;
|
---|
9622 | break;
|
---|
9623 | }
|
---|
9624 |
|
---|
9625 | #ifdef VBOX_WITH_VMNET
|
---|
9626 | // VirtualBox 7.0 adds a host-only network attachment.
|
---|
9627 | if (netit->mode == NetworkAttachmentType_HostOnlyNetwork)
|
---|
9628 | {
|
---|
9629 | m->sv = SettingsVersion_v1_19;
|
---|
9630 | break;
|
---|
9631 | }
|
---|
9632 | #endif /* VBOX_WITH_VMNET */
|
---|
9633 | }
|
---|
9634 |
|
---|
9635 | // VirtualBox 7.0 adds guest debug settings.
|
---|
9636 | if ( debugging.enmDbgProvider != GuestDebugProvider_None
|
---|
9637 | || debugging.enmIoProvider != GuestDebugIoProvider_None
|
---|
9638 | || debugging.strAddress.isNotEmpty()
|
---|
9639 | || debugging.ulPort != 0)
|
---|
9640 | {
|
---|
9641 | m->sv = SettingsVersion_v1_19;
|
---|
9642 | return;
|
---|
9643 | }
|
---|
9644 | }
|
---|
9645 |
|
---|
9646 | if (m->sv < SettingsVersion_v1_18)
|
---|
9647 | {
|
---|
9648 | if (!hardwareMachine.nvramSettings.strNvramPath.isEmpty())
|
---|
9649 | {
|
---|
9650 | m->sv = SettingsVersion_v1_18;
|
---|
9651 | return;
|
---|
9652 | }
|
---|
9653 |
|
---|
9654 | // VirtualBox 6.1 adds AMD-V virtualized VMSAVE/VMLOAD setting.
|
---|
9655 | if (hardwareMachine.platformSettings.x86.fHWVirtExVirtVmsaveVmload == false)
|
---|
9656 | {
|
---|
9657 | m->sv = SettingsVersion_v1_18;
|
---|
9658 | return;
|
---|
9659 | }
|
---|
9660 |
|
---|
9661 | // VirtualBox 6.1 adds a virtio-scsi storage controller.
|
---|
9662 | for (StorageControllersList::const_iterator it = hardwareMachine.storage.llStorageControllers.begin();
|
---|
9663 | it != hardwareMachine.storage.llStorageControllers.end();
|
---|
9664 | ++it)
|
---|
9665 | {
|
---|
9666 | const StorageController &sctl = *it;
|
---|
9667 |
|
---|
9668 | if (sctl.controllerType == StorageControllerType_VirtioSCSI)
|
---|
9669 | {
|
---|
9670 | m->sv = SettingsVersion_v1_18;
|
---|
9671 | return;
|
---|
9672 | }
|
---|
9673 | }
|
---|
9674 |
|
---|
9675 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
9676 | NetworkAdaptersList::const_iterator netit;
|
---|
9677 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
9678 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
9679 | ++netit)
|
---|
9680 | {
|
---|
9681 | // VirtualBox 6.1 adds support for cloud networks.
|
---|
9682 | if ( netit->fEnabled
|
---|
9683 | && netit->mode == NetworkAttachmentType_Cloud)
|
---|
9684 | {
|
---|
9685 | m->sv = SettingsVersion_v1_18;
|
---|
9686 | break;
|
---|
9687 | }
|
---|
9688 |
|
---|
9689 | }
|
---|
9690 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
9691 | }
|
---|
9692 |
|
---|
9693 | if (m->sv < SettingsVersion_v1_17)
|
---|
9694 | {
|
---|
9695 | if (machineUserData.enmVMPriority != VMProcPriority_Default)
|
---|
9696 | {
|
---|
9697 | m->sv = SettingsVersion_v1_17;
|
---|
9698 | return;
|
---|
9699 | }
|
---|
9700 |
|
---|
9701 | // VirtualBox 6.0 adds nested hardware virtualization, using native API (NEM).
|
---|
9702 | if ( hardwareMachine.platformSettings.x86.fNestedHWVirt
|
---|
9703 | || hardwareMachine.platformSettings.x86.fHWVirtExUseNativeApi)
|
---|
9704 | {
|
---|
9705 | m->sv = SettingsVersion_v1_17;
|
---|
9706 | return;
|
---|
9707 | }
|
---|
9708 | if (hardwareMachine.llSharedFolders.size())
|
---|
9709 | for (SharedFoldersList::const_iterator it = hardwareMachine.llSharedFolders.begin();
|
---|
9710 | it != hardwareMachine.llSharedFolders.end();
|
---|
9711 | ++it)
|
---|
9712 | if (it->strAutoMountPoint.isNotEmpty())
|
---|
9713 | {
|
---|
9714 | m->sv = SettingsVersion_v1_17;
|
---|
9715 | return;
|
---|
9716 | }
|
---|
9717 |
|
---|
9718 | /*
|
---|
9719 | * Check if any serial port uses a non 16550A serial port.
|
---|
9720 | */
|
---|
9721 | for (SerialPortsList::const_iterator it = hardwareMachine.llSerialPorts.begin();
|
---|
9722 | it != hardwareMachine.llSerialPorts.end();
|
---|
9723 | ++it)
|
---|
9724 | {
|
---|
9725 | const SerialPort &port = *it;
|
---|
9726 | if (port.uartType != UartType_U16550A)
|
---|
9727 | {
|
---|
9728 | m->sv = SettingsVersion_v1_17;
|
---|
9729 | return;
|
---|
9730 | }
|
---|
9731 | }
|
---|
9732 | }
|
---|
9733 |
|
---|
9734 | if (m->sv < SettingsVersion_v1_16)
|
---|
9735 | {
|
---|
9736 | // VirtualBox 5.1 adds a NVMe storage controller, paravirt debug
|
---|
9737 | // options, cpu profile, APIC settings (CPU capability and BIOS).
|
---|
9738 |
|
---|
9739 | if ( hardwareMachine.strParavirtDebug.isNotEmpty()
|
---|
9740 | || (!hardwareMachine.strCpuProfile.equals("host") && hardwareMachine.strCpuProfile.isNotEmpty())
|
---|
9741 | || hardwareMachine.firmwareSettings.apicMode != APICMode_APIC
|
---|
9742 | || !hardwareMachine.platformSettings.x86.fAPIC
|
---|
9743 | || hardwareMachine.platformSettings.x86.fX2APIC
|
---|
9744 | || hardwareMachine.platformSettings.x86.fIBPBOnVMExit
|
---|
9745 | || hardwareMachine.platformSettings.x86.fIBPBOnVMEntry
|
---|
9746 | || hardwareMachine.platformSettings.x86.fSpecCtrl
|
---|
9747 | || hardwareMachine.platformSettings.x86.fSpecCtrlByHost
|
---|
9748 | || !hardwareMachine.platformSettings.x86.fL1DFlushOnSched
|
---|
9749 | || hardwareMachine.platformSettings.x86.fL1DFlushOnVMEntry
|
---|
9750 | || !hardwareMachine.platformSettings.x86.fMDSClearOnSched
|
---|
9751 | || hardwareMachine.platformSettings.x86.fMDSClearOnVMEntry)
|
---|
9752 | {
|
---|
9753 | m->sv = SettingsVersion_v1_16;
|
---|
9754 | return;
|
---|
9755 | }
|
---|
9756 |
|
---|
9757 | for (StorageControllersList::const_iterator it = hardwareMachine.storage.llStorageControllers.begin();
|
---|
9758 | it != hardwareMachine.storage.llStorageControllers.end();
|
---|
9759 | ++it)
|
---|
9760 | {
|
---|
9761 | const StorageController &sctl = *it;
|
---|
9762 |
|
---|
9763 | if (sctl.controllerType == StorageControllerType_NVMe)
|
---|
9764 | {
|
---|
9765 | m->sv = SettingsVersion_v1_16;
|
---|
9766 | return;
|
---|
9767 | }
|
---|
9768 | }
|
---|
9769 |
|
---|
9770 | for (CpuIdLeafsX86List::const_iterator it = hardwareMachine.platformSettings.x86.llCpuIdLeafs.begin();
|
---|
9771 | it != hardwareMachine.platformSettings.x86.llCpuIdLeafs.end();
|
---|
9772 | ++it)
|
---|
9773 | if (it->idxSub != 0)
|
---|
9774 | {
|
---|
9775 | m->sv = SettingsVersion_v1_16;
|
---|
9776 | return;
|
---|
9777 | }
|
---|
9778 | }
|
---|
9779 |
|
---|
9780 | if (m->sv < SettingsVersion_v1_15)
|
---|
9781 | {
|
---|
9782 | // VirtualBox 5.0 adds paravirt providers, explicit AHCI port hotplug
|
---|
9783 | // setting, USB storage controller, xHCI, serial port TCP backend
|
---|
9784 | // and VM process priority.
|
---|
9785 |
|
---|
9786 | /*
|
---|
9787 | * Check simple configuration bits first, loopy stuff afterwards.
|
---|
9788 | */
|
---|
9789 | if ( hardwareMachine.paravirtProvider != ParavirtProvider_Legacy
|
---|
9790 | || hardwareMachine.uCpuIdPortabilityLevel != 0)
|
---|
9791 | {
|
---|
9792 | m->sv = SettingsVersion_v1_15;
|
---|
9793 | return;
|
---|
9794 | }
|
---|
9795 |
|
---|
9796 | /*
|
---|
9797 | * Check whether the hotpluggable flag of all storage devices differs
|
---|
9798 | * from the default for old settings.
|
---|
9799 | * AHCI ports are hotpluggable by default every other device is not.
|
---|
9800 | * Also check if there are USB storage controllers.
|
---|
9801 | */
|
---|
9802 | for (StorageControllersList::const_iterator it = hardwareMachine.storage.llStorageControllers.begin();
|
---|
9803 | it != hardwareMachine.storage.llStorageControllers.end();
|
---|
9804 | ++it)
|
---|
9805 | {
|
---|
9806 | const StorageController &sctl = *it;
|
---|
9807 |
|
---|
9808 | if (sctl.controllerType == StorageControllerType_USB)
|
---|
9809 | {
|
---|
9810 | m->sv = SettingsVersion_v1_15;
|
---|
9811 | return;
|
---|
9812 | }
|
---|
9813 |
|
---|
9814 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
9815 | it2 != sctl.llAttachedDevices.end();
|
---|
9816 | ++it2)
|
---|
9817 | {
|
---|
9818 | const AttachedDevice &att = *it2;
|
---|
9819 |
|
---|
9820 | if ( ( att.fHotPluggable
|
---|
9821 | && sctl.controllerType != StorageControllerType_IntelAhci)
|
---|
9822 | || ( !att.fHotPluggable
|
---|
9823 | && sctl.controllerType == StorageControllerType_IntelAhci))
|
---|
9824 | {
|
---|
9825 | m->sv = SettingsVersion_v1_15;
|
---|
9826 | return;
|
---|
9827 | }
|
---|
9828 | }
|
---|
9829 | }
|
---|
9830 |
|
---|
9831 | /*
|
---|
9832 | * Check if there is an xHCI (USB3) USB controller.
|
---|
9833 | */
|
---|
9834 | for (USBControllerList::const_iterator it = hardwareMachine.usbSettings.llUSBControllers.begin();
|
---|
9835 | it != hardwareMachine.usbSettings.llUSBControllers.end();
|
---|
9836 | ++it)
|
---|
9837 | {
|
---|
9838 | const USBController &ctrl = *it;
|
---|
9839 | if (ctrl.enmType == USBControllerType_XHCI)
|
---|
9840 | {
|
---|
9841 | m->sv = SettingsVersion_v1_15;
|
---|
9842 | return;
|
---|
9843 | }
|
---|
9844 | }
|
---|
9845 |
|
---|
9846 | /*
|
---|
9847 | * Check if any serial port uses the TCP backend.
|
---|
9848 | */
|
---|
9849 | for (SerialPortsList::const_iterator it = hardwareMachine.llSerialPorts.begin();
|
---|
9850 | it != hardwareMachine.llSerialPorts.end();
|
---|
9851 | ++it)
|
---|
9852 | {
|
---|
9853 | const SerialPort &port = *it;
|
---|
9854 | if (port.portMode == PortMode_TCP)
|
---|
9855 | {
|
---|
9856 | m->sv = SettingsVersion_v1_15;
|
---|
9857 | return;
|
---|
9858 | }
|
---|
9859 | }
|
---|
9860 | }
|
---|
9861 |
|
---|
9862 | if (m->sv < SettingsVersion_v1_14)
|
---|
9863 | {
|
---|
9864 | // VirtualBox 4.3 adds default frontend setting, graphics controller
|
---|
9865 | // setting, explicit long mode setting, (video) capturing and NAT networking.
|
---|
9866 | if ( !hardwareMachine.strDefaultFrontend.isEmpty()
|
---|
9867 | || hardwareMachine.graphicsAdapter.graphicsControllerType != GraphicsControllerType_VBoxVGA
|
---|
9868 | || hardwareMachine.platformSettings.x86.enmLongMode != PlatformX86::LongMode_Legacy
|
---|
9869 | || machineUserData.ovIcon.size() > 0
|
---|
9870 | || recordingSettings.common.fEnabled)
|
---|
9871 | {
|
---|
9872 | m->sv = SettingsVersion_v1_14;
|
---|
9873 | return;
|
---|
9874 | }
|
---|
9875 | NetworkAdaptersList::const_iterator netit;
|
---|
9876 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
9877 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
9878 | ++netit)
|
---|
9879 | {
|
---|
9880 | if (netit->mode == NetworkAttachmentType_NATNetwork)
|
---|
9881 | {
|
---|
9882 | m->sv = SettingsVersion_v1_14;
|
---|
9883 | break;
|
---|
9884 | }
|
---|
9885 | }
|
---|
9886 | }
|
---|
9887 |
|
---|
9888 | if (m->sv < SettingsVersion_v1_14)
|
---|
9889 | {
|
---|
9890 | unsigned cOhciCtrls = 0;
|
---|
9891 | unsigned cEhciCtrls = 0;
|
---|
9892 | bool fNonStdName = false;
|
---|
9893 |
|
---|
9894 | for (USBControllerList::const_iterator it = hardwareMachine.usbSettings.llUSBControllers.begin();
|
---|
9895 | it != hardwareMachine.usbSettings.llUSBControllers.end();
|
---|
9896 | ++it)
|
---|
9897 | {
|
---|
9898 | const USBController &ctrl = *it;
|
---|
9899 |
|
---|
9900 | switch (ctrl.enmType)
|
---|
9901 | {
|
---|
9902 | case USBControllerType_OHCI:
|
---|
9903 | cOhciCtrls++;
|
---|
9904 | if (ctrl.strName != "OHCI")
|
---|
9905 | fNonStdName = true;
|
---|
9906 | break;
|
---|
9907 | case USBControllerType_EHCI:
|
---|
9908 | cEhciCtrls++;
|
---|
9909 | if (ctrl.strName != "EHCI")
|
---|
9910 | fNonStdName = true;
|
---|
9911 | break;
|
---|
9912 | default:
|
---|
9913 | /* Anything unknown forces a bump. */
|
---|
9914 | fNonStdName = true;
|
---|
9915 | }
|
---|
9916 |
|
---|
9917 | /* Skip checking other controllers if the settings bump is necessary. */
|
---|
9918 | if (cOhciCtrls > 1 || cEhciCtrls > 1 || fNonStdName)
|
---|
9919 | {
|
---|
9920 | m->sv = SettingsVersion_v1_14;
|
---|
9921 | break;
|
---|
9922 | }
|
---|
9923 | }
|
---|
9924 | }
|
---|
9925 |
|
---|
9926 | if (m->sv < SettingsVersion_v1_13)
|
---|
9927 | {
|
---|
9928 | // VirtualBox 4.2 adds tracing, autostart, UUID in directory and groups.
|
---|
9929 | if ( !debugging.areDefaultSettings()
|
---|
9930 | || !autostart.areDefaultSettings()
|
---|
9931 | || machineUserData.fDirectoryIncludesUUID
|
---|
9932 | || machineUserData.llGroups.size() > 1
|
---|
9933 | || machineUserData.llGroups.front() != "/")
|
---|
9934 | m->sv = SettingsVersion_v1_13;
|
---|
9935 | }
|
---|
9936 |
|
---|
9937 | if (m->sv < SettingsVersion_v1_13)
|
---|
9938 | {
|
---|
9939 | // VirtualBox 4.2 changes the units for bandwidth group limits.
|
---|
9940 | for (BandwidthGroupList::const_iterator it = hardwareMachine.ioSettings.llBandwidthGroups.begin();
|
---|
9941 | it != hardwareMachine.ioSettings.llBandwidthGroups.end();
|
---|
9942 | ++it)
|
---|
9943 | {
|
---|
9944 | const BandwidthGroup &gr = *it;
|
---|
9945 | if (gr.cMaxBytesPerSec % _1M)
|
---|
9946 | {
|
---|
9947 | // Bump version if a limit cannot be expressed in megabytes
|
---|
9948 | m->sv = SettingsVersion_v1_13;
|
---|
9949 | break;
|
---|
9950 | }
|
---|
9951 | }
|
---|
9952 | }
|
---|
9953 |
|
---|
9954 | if (m->sv < SettingsVersion_v1_12)
|
---|
9955 | {
|
---|
9956 | // VirtualBox 4.1 adds PCI passthrough and emulated USB Smart Card reader
|
---|
9957 | if ( hardwareMachine.pciAttachments.size()
|
---|
9958 | || hardwareMachine.fEmulatedUSBCardReader)
|
---|
9959 | m->sv = SettingsVersion_v1_12;
|
---|
9960 | }
|
---|
9961 |
|
---|
9962 | if (m->sv < SettingsVersion_v1_12)
|
---|
9963 | {
|
---|
9964 | // VirtualBox 4.1 adds a promiscuous mode policy to the network
|
---|
9965 | // adapters and a generic network driver transport.
|
---|
9966 | NetworkAdaptersList::const_iterator netit;
|
---|
9967 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
9968 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
9969 | ++netit)
|
---|
9970 | {
|
---|
9971 | if ( netit->enmPromiscModePolicy != NetworkAdapterPromiscModePolicy_Deny
|
---|
9972 | || netit->mode == NetworkAttachmentType_Generic
|
---|
9973 | || !netit->areGenericDriverDefaultSettings()
|
---|
9974 | )
|
---|
9975 | {
|
---|
9976 | m->sv = SettingsVersion_v1_12;
|
---|
9977 | break;
|
---|
9978 | }
|
---|
9979 | }
|
---|
9980 | }
|
---|
9981 |
|
---|
9982 | if (m->sv < SettingsVersion_v1_11)
|
---|
9983 | {
|
---|
9984 | // VirtualBox 4.0 adds HD audio, CPU priorities, ~fault tolerance~,
|
---|
9985 | // per-machine media registries, VRDE, JRockitVE, bandwidth groups,
|
---|
9986 | // ICH9 chipset
|
---|
9987 | if ( hardwareMachine.audioAdapter.controllerType == AudioControllerType_HDA
|
---|
9988 | || hardwareMachine.ulCpuExecutionCap != 100
|
---|
9989 | || mediaRegistry.llHardDisks.size()
|
---|
9990 | || mediaRegistry.llDvdImages.size()
|
---|
9991 | || mediaRegistry.llFloppyImages.size()
|
---|
9992 | || !hardwareMachine.vrdeSettings.strVrdeExtPack.isEmpty()
|
---|
9993 | || !hardwareMachine.vrdeSettings.strAuthLibrary.isEmpty()
|
---|
9994 | || machineUserData.strOsType == "JRockitVE"
|
---|
9995 | || hardwareMachine.ioSettings.llBandwidthGroups.size()
|
---|
9996 | || hardwareMachine.platformSettings.chipsetType == ChipsetType_ICH9
|
---|
9997 | )
|
---|
9998 | m->sv = SettingsVersion_v1_11;
|
---|
9999 | }
|
---|
10000 |
|
---|
10001 | if (m->sv < SettingsVersion_v1_10)
|
---|
10002 | {
|
---|
10003 | /* If the properties contain elements other than "TCP/Ports" and "TCP/Address",
|
---|
10004 | * then increase the version to at least VBox 3.2, which can have video channel properties.
|
---|
10005 | */
|
---|
10006 | unsigned cOldProperties = 0;
|
---|
10007 |
|
---|
10008 | StringsMap::const_iterator it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Ports");
|
---|
10009 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
10010 | cOldProperties++;
|
---|
10011 | it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Address");
|
---|
10012 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
10013 | cOldProperties++;
|
---|
10014 |
|
---|
10015 | if (hardwareMachine.vrdeSettings.mapProperties.size() != cOldProperties)
|
---|
10016 | m->sv = SettingsVersion_v1_10;
|
---|
10017 | }
|
---|
10018 |
|
---|
10019 | if (m->sv < SettingsVersion_v1_11)
|
---|
10020 | {
|
---|
10021 | /* If the properties contain elements other than "TCP/Ports", "TCP/Address",
|
---|
10022 | * "VideoChannel/Enabled" and "VideoChannel/Quality" then increase the version to VBox 4.0.
|
---|
10023 | */
|
---|
10024 | unsigned cOldProperties = 0;
|
---|
10025 |
|
---|
10026 | StringsMap::const_iterator it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Ports");
|
---|
10027 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
10028 | cOldProperties++;
|
---|
10029 | it = hardwareMachine.vrdeSettings.mapProperties.find("TCP/Address");
|
---|
10030 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
10031 | cOldProperties++;
|
---|
10032 | it = hardwareMachine.vrdeSettings.mapProperties.find("VideoChannel/Enabled");
|
---|
10033 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
10034 | cOldProperties++;
|
---|
10035 | it = hardwareMachine.vrdeSettings.mapProperties.find("VideoChannel/Quality");
|
---|
10036 | if (it != hardwareMachine.vrdeSettings.mapProperties.end())
|
---|
10037 | cOldProperties++;
|
---|
10038 |
|
---|
10039 | if (hardwareMachine.vrdeSettings.mapProperties.size() != cOldProperties)
|
---|
10040 | m->sv = SettingsVersion_v1_11;
|
---|
10041 | }
|
---|
10042 |
|
---|
10043 | // settings version 1.9 is required if there is not exactly one DVD
|
---|
10044 | // or more than one floppy drive present or the DVD is not at the secondary
|
---|
10045 | // master; this check is a bit more complicated
|
---|
10046 | //
|
---|
10047 | // settings version 1.10 is required if the host cache should be disabled
|
---|
10048 | //
|
---|
10049 | // settings version 1.11 is required for bandwidth limits and if more than
|
---|
10050 | // one controller of each type is present.
|
---|
10051 | if (m->sv < SettingsVersion_v1_11)
|
---|
10052 | {
|
---|
10053 | // count attached DVDs and floppies (only if < v1.9)
|
---|
10054 | size_t cDVDs = 0;
|
---|
10055 | size_t cFloppies = 0;
|
---|
10056 |
|
---|
10057 | // count storage controllers (if < v1.11)
|
---|
10058 | size_t cSata = 0;
|
---|
10059 | size_t cScsiLsi = 0;
|
---|
10060 | size_t cScsiBuslogic = 0;
|
---|
10061 | size_t cSas = 0;
|
---|
10062 | size_t cIde = 0;
|
---|
10063 | size_t cFloppy = 0;
|
---|
10064 |
|
---|
10065 | // need to run thru all the storage controllers and attached devices to figure this out
|
---|
10066 | for (StorageControllersList::const_iterator it = hardwareMachine.storage.llStorageControllers.begin();
|
---|
10067 | it != hardwareMachine.storage.llStorageControllers.end();
|
---|
10068 | ++it)
|
---|
10069 | {
|
---|
10070 | const StorageController &sctl = *it;
|
---|
10071 |
|
---|
10072 | // count storage controllers of each type; 1.11 is required if more than one
|
---|
10073 | // controller of one type is present
|
---|
10074 | switch (sctl.storageBus)
|
---|
10075 | {
|
---|
10076 | case StorageBus_IDE:
|
---|
10077 | cIde++;
|
---|
10078 | break;
|
---|
10079 | case StorageBus_SATA:
|
---|
10080 | cSata++;
|
---|
10081 | break;
|
---|
10082 | case StorageBus_SAS:
|
---|
10083 | cSas++;
|
---|
10084 | break;
|
---|
10085 | case StorageBus_SCSI:
|
---|
10086 | if (sctl.controllerType == StorageControllerType_LsiLogic)
|
---|
10087 | cScsiLsi++;
|
---|
10088 | else
|
---|
10089 | cScsiBuslogic++;
|
---|
10090 | break;
|
---|
10091 | case StorageBus_Floppy:
|
---|
10092 | cFloppy++;
|
---|
10093 | break;
|
---|
10094 | default:
|
---|
10095 | // Do nothing
|
---|
10096 | break;
|
---|
10097 | }
|
---|
10098 |
|
---|
10099 | if ( cSata > 1
|
---|
10100 | || cScsiLsi > 1
|
---|
10101 | || cScsiBuslogic > 1
|
---|
10102 | || cSas > 1
|
---|
10103 | || cIde > 1
|
---|
10104 | || cFloppy > 1)
|
---|
10105 | {
|
---|
10106 | m->sv = SettingsVersion_v1_11;
|
---|
10107 | break; // abort the loop -- we will not raise the version further
|
---|
10108 | }
|
---|
10109 |
|
---|
10110 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
10111 | it2 != sctl.llAttachedDevices.end();
|
---|
10112 | ++it2)
|
---|
10113 | {
|
---|
10114 | const AttachedDevice &att = *it2;
|
---|
10115 |
|
---|
10116 | // Bandwidth limitations are new in VirtualBox 4.0 (1.11)
|
---|
10117 | if (m->sv < SettingsVersion_v1_11)
|
---|
10118 | {
|
---|
10119 | if (att.strBwGroup.length() != 0)
|
---|
10120 | {
|
---|
10121 | m->sv = SettingsVersion_v1_11;
|
---|
10122 | break; // abort the loop -- we will not raise the version further
|
---|
10123 | }
|
---|
10124 | }
|
---|
10125 |
|
---|
10126 | // disabling the host IO cache requires settings version 1.10
|
---|
10127 | if ( (m->sv < SettingsVersion_v1_10)
|
---|
10128 | && (!sctl.fUseHostIOCache)
|
---|
10129 | )
|
---|
10130 | m->sv = SettingsVersion_v1_10;
|
---|
10131 |
|
---|
10132 | // we can only write the StorageController/@Instance attribute with v1.9
|
---|
10133 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
10134 | && (sctl.ulInstance != 0)
|
---|
10135 | )
|
---|
10136 | m->sv = SettingsVersion_v1_9;
|
---|
10137 |
|
---|
10138 | if (m->sv < SettingsVersion_v1_9)
|
---|
10139 | {
|
---|
10140 | if (att.deviceType == DeviceType_DVD)
|
---|
10141 | {
|
---|
10142 | if ( (sctl.storageBus != StorageBus_IDE) // DVD at bus other than DVD?
|
---|
10143 | || (att.lPort != 1) // DVDs not at secondary master?
|
---|
10144 | || (att.lDevice != 0)
|
---|
10145 | )
|
---|
10146 | m->sv = SettingsVersion_v1_9;
|
---|
10147 |
|
---|
10148 | ++cDVDs;
|
---|
10149 | }
|
---|
10150 | else if (att.deviceType == DeviceType_Floppy)
|
---|
10151 | ++cFloppies;
|
---|
10152 | }
|
---|
10153 | }
|
---|
10154 |
|
---|
10155 | if (m->sv >= SettingsVersion_v1_11)
|
---|
10156 | break; // abort the loop -- we will not raise the version further
|
---|
10157 | }
|
---|
10158 |
|
---|
10159 | // VirtualBox before 3.1 had zero or one floppy and exactly one DVD,
|
---|
10160 | // so any deviation from that will require settings version 1.9
|
---|
10161 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
10162 | && ( (cDVDs != 1)
|
---|
10163 | || (cFloppies > 1)
|
---|
10164 | )
|
---|
10165 | )
|
---|
10166 | m->sv = SettingsVersion_v1_9;
|
---|
10167 | }
|
---|
10168 |
|
---|
10169 | // VirtualBox 3.2: Check for non default I/O settings
|
---|
10170 | if (m->sv < SettingsVersion_v1_10)
|
---|
10171 | {
|
---|
10172 | if ( (hardwareMachine.ioSettings.fIOCacheEnabled != true)
|
---|
10173 | || (hardwareMachine.ioSettings.ulIOCacheSize != 5)
|
---|
10174 | // and page fusion
|
---|
10175 | || (hardwareMachine.fPageFusionEnabled)
|
---|
10176 | // and CPU hotplug, RTC timezone control, HID type and HPET
|
---|
10177 | || hardwareMachine.platformSettings.fRTCUseUTC
|
---|
10178 | || hardwareMachine.fCpuHotPlug
|
---|
10179 | || hardwareMachine.pointingHIDType != PointingHIDType_PS2Mouse
|
---|
10180 | || hardwareMachine.keyboardHIDType != KeyboardHIDType_PS2Keyboard
|
---|
10181 | || hardwareMachine.platformSettings.x86.fHPETEnabled
|
---|
10182 | )
|
---|
10183 | m->sv = SettingsVersion_v1_10;
|
---|
10184 | }
|
---|
10185 |
|
---|
10186 | // VirtualBox 3.2 adds NAT and boot priority to the NIC config in Main
|
---|
10187 | // VirtualBox 4.0 adds network bandwitdth
|
---|
10188 | if (m->sv < SettingsVersion_v1_11)
|
---|
10189 | {
|
---|
10190 | NetworkAdaptersList::const_iterator netit;
|
---|
10191 | for (netit = hardwareMachine.llNetworkAdapters.begin();
|
---|
10192 | netit != hardwareMachine.llNetworkAdapters.end();
|
---|
10193 | ++netit)
|
---|
10194 | {
|
---|
10195 | if ( (m->sv < SettingsVersion_v1_12)
|
---|
10196 | && (netit->strBandwidthGroup.isNotEmpty())
|
---|
10197 | )
|
---|
10198 | {
|
---|
10199 | /* New in VirtualBox 4.1 */
|
---|
10200 | m->sv = SettingsVersion_v1_12;
|
---|
10201 | break;
|
---|
10202 | }
|
---|
10203 | else if ( (m->sv < SettingsVersion_v1_10)
|
---|
10204 | && (netit->fEnabled)
|
---|
10205 | && (netit->mode == NetworkAttachmentType_NAT)
|
---|
10206 | && ( netit->nat.u32Mtu != 0
|
---|
10207 | || netit->nat.u32SockRcv != 0
|
---|
10208 | || netit->nat.u32SockSnd != 0
|
---|
10209 | || netit->nat.u32TcpRcv != 0
|
---|
10210 | || netit->nat.u32TcpSnd != 0
|
---|
10211 | || !netit->nat.fDNSPassDomain
|
---|
10212 | || netit->nat.fDNSProxy
|
---|
10213 | || netit->nat.fDNSUseHostResolver
|
---|
10214 | || netit->nat.fAliasLog
|
---|
10215 | || netit->nat.fAliasProxyOnly
|
---|
10216 | || netit->nat.fAliasUseSamePorts
|
---|
10217 | || netit->nat.strTFTPPrefix.length()
|
---|
10218 | || netit->nat.strTFTPBootFile.length()
|
---|
10219 | || netit->nat.strTFTPNextServer.length()
|
---|
10220 | || netit->nat.mapRules.size()
|
---|
10221 | )
|
---|
10222 | )
|
---|
10223 | {
|
---|
10224 | m->sv = SettingsVersion_v1_10;
|
---|
10225 | // no break because we still might need v1.11 above
|
---|
10226 | }
|
---|
10227 | else if ( (m->sv < SettingsVersion_v1_10)
|
---|
10228 | && (netit->fEnabled)
|
---|
10229 | && (netit->ulBootPriority != 0)
|
---|
10230 | )
|
---|
10231 | {
|
---|
10232 | m->sv = SettingsVersion_v1_10;
|
---|
10233 | // no break because we still might need v1.11 above
|
---|
10234 | }
|
---|
10235 | }
|
---|
10236 | }
|
---|
10237 |
|
---|
10238 | // all the following require settings version 1.9
|
---|
10239 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
10240 | && ( (hardwareMachine.firmwareSettings.firmwareType >= FirmwareType_EFI)
|
---|
10241 | || machineUserData.fTeleporterEnabled
|
---|
10242 | || machineUserData.uTeleporterPort
|
---|
10243 | || !machineUserData.strTeleporterAddress.isEmpty()
|
---|
10244 | || !machineUserData.strTeleporterPassword.isEmpty()
|
---|
10245 | || (!hardwareMachine.uuid.isZero() && hardwareMachine.uuid.isValid())
|
---|
10246 | )
|
---|
10247 | )
|
---|
10248 | m->sv = SettingsVersion_v1_9;
|
---|
10249 |
|
---|
10250 | // "accelerate 2d video" requires settings version 1.8
|
---|
10251 | if ( (m->sv < SettingsVersion_v1_8)
|
---|
10252 | && (hardwareMachine.graphicsAdapter.fAccelerate2DVideo)
|
---|
10253 | )
|
---|
10254 | m->sv = SettingsVersion_v1_8;
|
---|
10255 |
|
---|
10256 | // The hardware versions other than "1" requires settings version 1.4 (2.1+).
|
---|
10257 | if ( m->sv < SettingsVersion_v1_4
|
---|
10258 | && hardwareMachine.strVersion != "1"
|
---|
10259 | )
|
---|
10260 | m->sv = SettingsVersion_v1_4;
|
---|
10261 | }
|
---|
10262 |
|
---|
10263 | /**
|
---|
10264 | * Called from Main code to write a machine config file to disk. This builds a DOM tree from
|
---|
10265 | * the member variables and then writes the XML file; it throws xml::Error instances on errors,
|
---|
10266 | * in particular if the file cannot be written.
|
---|
10267 | */
|
---|
10268 | void MachineConfigFile::write(const com::Utf8Str &strFilename, PCVBOXCRYPTOIF pCryptoIf, const char *pszPassword)
|
---|
10269 | {
|
---|
10270 | try
|
---|
10271 | {
|
---|
10272 | // createStubDocument() sets the settings version to at least 1.7; however,
|
---|
10273 | // we might need to enfore a later settings version if incompatible settings
|
---|
10274 | // are present:
|
---|
10275 | bumpSettingsVersionIfNeeded();
|
---|
10276 |
|
---|
10277 | m->strFilename = strFilename;
|
---|
10278 | /*
|
---|
10279 | * Only create a backup if it is not encrypted.
|
---|
10280 | * Otherwise we get an unencrypted copy of the settings.
|
---|
10281 | */
|
---|
10282 | if (strKeyId.isEmpty() && strKeyStore.isEmpty())
|
---|
10283 | specialBackupIfFirstBump();
|
---|
10284 | createStubDocument();
|
---|
10285 |
|
---|
10286 | if (strKeyStore.isNotEmpty())
|
---|
10287 | {
|
---|
10288 | xml::ElementNode *pelmMachine = m->pelmRoot->createChild("MachineEncrypted");
|
---|
10289 | buildMachineEncryptedXML(*pelmMachine,
|
---|
10290 | MachineConfigFile::BuildMachineXML_IncludeSnapshots
|
---|
10291 | | MachineConfigFile::BuildMachineXML_MediaRegistry,
|
---|
10292 | // but not BuildMachineXML_WriteVBoxVersionAttribute
|
---|
10293 | NULL, /* pllElementsWithUuidAttributes */
|
---|
10294 | pCryptoIf,
|
---|
10295 | pszPassword);
|
---|
10296 | }
|
---|
10297 | else
|
---|
10298 | {
|
---|
10299 | xml::ElementNode *pelmMachine = m->pelmRoot->createChild("Machine");
|
---|
10300 | buildMachineXML(*pelmMachine,
|
---|
10301 | MachineConfigFile::BuildMachineXML_IncludeSnapshots
|
---|
10302 | | MachineConfigFile::BuildMachineXML_MediaRegistry,
|
---|
10303 | // but not BuildMachineXML_WriteVBoxVersionAttribute
|
---|
10304 | NULL); /* pllElementsWithUuidAttributes */
|
---|
10305 | }
|
---|
10306 |
|
---|
10307 | // now go write the XML
|
---|
10308 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
10309 | writer.write(m->strFilename.c_str(), true /*fSafe*/);
|
---|
10310 |
|
---|
10311 | m->fFileExists = true;
|
---|
10312 | clearDocument();
|
---|
10313 | LogRel(("Finished saving settings file \"%s\"\n", m->strFilename.c_str()));
|
---|
10314 | }
|
---|
10315 | catch (...)
|
---|
10316 | {
|
---|
10317 | clearDocument();
|
---|
10318 | LogRel(("Finished saving settings file \"%s\" with failure\n", m->strFilename.c_str()));
|
---|
10319 | throw;
|
---|
10320 | }
|
---|
10321 | }
|
---|