1 | /* $Id: Settings.cpp 98103 2023-01-17 14:15:46Z 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 > 19)
|
---|
433 | sv = SettingsVersion_Future;
|
---|
434 | }
|
---|
435 | else if (uMajor > 1)
|
---|
436 | sv = SettingsVersion_Future;
|
---|
437 |
|
---|
438 | Log(("Parsed settings version %d.%d to enum value %d\n", uMajor, uMinor, sv));
|
---|
439 | }
|
---|
440 |
|
---|
441 | if (sv == SettingsVersion_Null)
|
---|
442 | throw ConfigFileError(this, pElm, N_("Cannot handle settings version '%s'"), strVersion.c_str());
|
---|
443 |
|
---|
444 | return sv;
|
---|
445 | }
|
---|
446 |
|
---|
447 | /**
|
---|
448 | * Helper function that parses a UUID in string form into
|
---|
449 | * a com::Guid item. Accepts UUIDs both with and without
|
---|
450 | * "{}" brackets. Throws on errors.
|
---|
451 | * @param guid
|
---|
452 | * @param strUUID
|
---|
453 | * @param pElm
|
---|
454 | */
|
---|
455 | void ConfigFileBase::parseUUID(Guid &guid,
|
---|
456 | const Utf8Str &strUUID,
|
---|
457 | const xml::ElementNode *pElm) const
|
---|
458 | {
|
---|
459 | guid = strUUID.c_str();
|
---|
460 | if (guid.isZero())
|
---|
461 | throw ConfigFileError(this, pElm, N_("UUID \"%s\" has zero format"), strUUID.c_str());
|
---|
462 | else if (!guid.isValid())
|
---|
463 | throw ConfigFileError(this, pElm, N_("UUID \"%s\" has invalid format"), strUUID.c_str());
|
---|
464 | }
|
---|
465 |
|
---|
466 | /**
|
---|
467 | * Parses the given string in str and attempts to treat it as an ISO
|
---|
468 | * date/time stamp to put into timestamp. Throws on errors.
|
---|
469 | * @param timestamp
|
---|
470 | * @param str
|
---|
471 | * @param pElm
|
---|
472 | */
|
---|
473 | void ConfigFileBase::parseTimestamp(RTTIMESPEC ×tamp,
|
---|
474 | const com::Utf8Str &str,
|
---|
475 | const xml::ElementNode *pElm) const
|
---|
476 | {
|
---|
477 | const char *pcsz = str.c_str();
|
---|
478 | // yyyy-mm-ddThh:mm:ss
|
---|
479 | // "2009-07-10T11:54:03Z"
|
---|
480 | // 01234567890123456789
|
---|
481 | // 1
|
---|
482 | if (str.length() > 19)
|
---|
483 | {
|
---|
484 | // timezone must either be unspecified or 'Z' for UTC
|
---|
485 | if ( (pcsz[19])
|
---|
486 | && (pcsz[19] != 'Z')
|
---|
487 | )
|
---|
488 | throw ConfigFileError(this, pElm, N_("Cannot handle ISO timestamp '%s': is not UTC date"), str.c_str());
|
---|
489 |
|
---|
490 | int32_t yyyy;
|
---|
491 | uint32_t mm, dd, hh, min, secs;
|
---|
492 | if ( (pcsz[4] == '-')
|
---|
493 | && (pcsz[7] == '-')
|
---|
494 | && (pcsz[10] == 'T')
|
---|
495 | && (pcsz[13] == ':')
|
---|
496 | && (pcsz[16] == ':')
|
---|
497 | )
|
---|
498 | {
|
---|
499 | int rc;
|
---|
500 | if ( (RT_SUCCESS(rc = RTStrToInt32Ex(pcsz, NULL, 0, &yyyy)))
|
---|
501 | // could theoretically be negative but let's assume that nobody
|
---|
502 | // created virtual machines before the Christian era
|
---|
503 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 5, NULL, 0, &mm)))
|
---|
504 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 8, NULL, 0, &dd)))
|
---|
505 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 11, NULL, 0, &hh)))
|
---|
506 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 14, NULL, 0, &min)))
|
---|
507 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 17, NULL, 0, &secs)))
|
---|
508 | )
|
---|
509 | {
|
---|
510 | RTTIME time =
|
---|
511 | {
|
---|
512 | yyyy,
|
---|
513 | (uint8_t)mm,
|
---|
514 | 0,
|
---|
515 | 0,
|
---|
516 | (uint8_t)dd,
|
---|
517 | (uint8_t)hh,
|
---|
518 | (uint8_t)min,
|
---|
519 | (uint8_t)secs,
|
---|
520 | 0,
|
---|
521 | RTTIME_FLAGS_TYPE_UTC,
|
---|
522 | 0
|
---|
523 | };
|
---|
524 | if (RTTimeNormalize(&time))
|
---|
525 | if (RTTimeImplode(×tamp, &time))
|
---|
526 | return;
|
---|
527 | }
|
---|
528 |
|
---|
529 | throw ConfigFileError(this, pElm, N_("Cannot parse ISO timestamp '%s': runtime error, %Rra"), str.c_str(), rc);
|
---|
530 | }
|
---|
531 |
|
---|
532 | throw ConfigFileError(this, pElm, N_("Cannot parse ISO timestamp '%s': invalid format"), str.c_str());
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | /**
|
---|
537 | * Helper function that parses a Base64 formatted string into a binary blob.
|
---|
538 | * @param binary
|
---|
539 | * @param str
|
---|
540 | * @param pElm
|
---|
541 | */
|
---|
542 | void ConfigFileBase::parseBase64(IconBlob &binary,
|
---|
543 | const Utf8Str &str,
|
---|
544 | const xml::ElementNode *pElm) const
|
---|
545 | {
|
---|
546 | #define DECODE_STR_MAX _1M
|
---|
547 | const char* psz = str.c_str();
|
---|
548 | ssize_t cbOut = RTBase64DecodedSize(psz, NULL);
|
---|
549 | if (cbOut > DECODE_STR_MAX)
|
---|
550 | throw ConfigFileError(this, pElm, N_("Base64 encoded data too long (%d > %d)"), cbOut, DECODE_STR_MAX);
|
---|
551 | else if (cbOut < 0)
|
---|
552 | throw ConfigFileError(this, pElm, N_("Base64 encoded data '%s' invalid"), psz);
|
---|
553 | binary.resize((size_t)cbOut);
|
---|
554 | int vrc = VINF_SUCCESS;
|
---|
555 | if (cbOut)
|
---|
556 | vrc = RTBase64Decode(psz, &binary.front(), (size_t)cbOut, NULL, NULL);
|
---|
557 | if (RT_FAILURE(vrc))
|
---|
558 | {
|
---|
559 | binary.resize(0);
|
---|
560 | throw ConfigFileError(this, pElm, N_("Base64 encoded data could not be decoded (%Rrc)"), vrc);
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | /**
|
---|
565 | * Helper to create a string for a RTTIMESPEC for writing out ISO timestamps.
|
---|
566 | * @param stamp
|
---|
567 | * @return
|
---|
568 | */
|
---|
569 | com::Utf8Str ConfigFileBase::stringifyTimestamp(const RTTIMESPEC &stamp) const
|
---|
570 | {
|
---|
571 | RTTIME time;
|
---|
572 | if (!RTTimeExplode(&time, &stamp))
|
---|
573 | throw ConfigFileError(this, NULL, N_("Timespec %lld ms is invalid"), RTTimeSpecGetMilli(&stamp));
|
---|
574 |
|
---|
575 | return Utf8StrFmt("%04u-%02u-%02uT%02u:%02u:%02uZ",
|
---|
576 | time.i32Year, time.u8Month, time.u8MonthDay,
|
---|
577 | time.u8Hour, time.u8Minute, time.u8Second);
|
---|
578 | }
|
---|
579 |
|
---|
580 | /**
|
---|
581 | * Helper to create a base64 encoded string out of a binary blob.
|
---|
582 | * @param str
|
---|
583 | * @param binary
|
---|
584 | * @throws std::bad_alloc and ConfigFileError
|
---|
585 | */
|
---|
586 | void ConfigFileBase::toBase64(com::Utf8Str &str, const IconBlob &binary) const
|
---|
587 | {
|
---|
588 | size_t cb = binary.size();
|
---|
589 | if (cb > 0)
|
---|
590 | {
|
---|
591 | size_t cchOut = RTBase64EncodedLength(cb);
|
---|
592 | str.reserve(cchOut + 1);
|
---|
593 | int vrc = RTBase64Encode(&binary.front(), cb, str.mutableRaw(), str.capacity(), NULL);
|
---|
594 | if (RT_FAILURE(vrc))
|
---|
595 | throw ConfigFileError(this, NULL, N_("Failed to convert binary data to base64 format (%Rrc)"), vrc);
|
---|
596 | str.jolt();
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 | /**
|
---|
601 | * Helper method to read in an ExtraData subtree and stores its contents
|
---|
602 | * in the given map of extradata items. Used for both main and machine
|
---|
603 | * extradata (MainConfigFile and MachineConfigFile).
|
---|
604 | * @param elmExtraData
|
---|
605 | * @param map
|
---|
606 | */
|
---|
607 | void ConfigFileBase::readExtraData(const xml::ElementNode &elmExtraData,
|
---|
608 | StringsMap &map)
|
---|
609 | {
|
---|
610 | xml::NodesLoop nlLevel4(elmExtraData);
|
---|
611 | const xml::ElementNode *pelmExtraDataItem;
|
---|
612 | while ((pelmExtraDataItem = nlLevel4.forAllNodes()))
|
---|
613 | {
|
---|
614 | if (pelmExtraDataItem->nameEquals("ExtraDataItem"))
|
---|
615 | {
|
---|
616 | // <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/>
|
---|
617 | Utf8Str strName, strValue;
|
---|
618 | if ( pelmExtraDataItem->getAttributeValue("name", strName)
|
---|
619 | && pelmExtraDataItem->getAttributeValue("value", strValue) )
|
---|
620 | map[strName] = strValue;
|
---|
621 | else
|
---|
622 | throw ConfigFileError(this, pelmExtraDataItem, N_("Required ExtraDataItem/@name or @value attribute is missing"));
|
---|
623 | }
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | /**
|
---|
628 | * Reads \<USBDeviceFilter\> entries from under the given elmDeviceFilters node and
|
---|
629 | * stores them in the given linklist. This is in ConfigFileBase because it's used
|
---|
630 | * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
|
---|
631 | * filters).
|
---|
632 | * @param elmDeviceFilters
|
---|
633 | * @param ll
|
---|
634 | */
|
---|
635 | void ConfigFileBase::readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
|
---|
636 | USBDeviceFiltersList &ll)
|
---|
637 | {
|
---|
638 | xml::NodesLoop nl1(elmDeviceFilters, "DeviceFilter");
|
---|
639 | const xml::ElementNode *pelmLevel4Child;
|
---|
640 | while ((pelmLevel4Child = nl1.forAllNodes()))
|
---|
641 | {
|
---|
642 | USBDeviceFilter flt;
|
---|
643 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
644 | Utf8Str strAction;
|
---|
645 | if ( pelmLevel4Child->getAttributeValue("name", flt.strName)
|
---|
646 | && pelmLevel4Child->getAttributeValue("active", flt.fActive))
|
---|
647 | {
|
---|
648 | if (!pelmLevel4Child->getAttributeValue("vendorId", flt.strVendorId))
|
---|
649 | pelmLevel4Child->getAttributeValue("vendorid", flt.strVendorId); // used before 1.3
|
---|
650 | if (!pelmLevel4Child->getAttributeValue("productId", flt.strProductId))
|
---|
651 | pelmLevel4Child->getAttributeValue("productid", flt.strProductId); // used before 1.3
|
---|
652 | pelmLevel4Child->getAttributeValue("revision", flt.strRevision);
|
---|
653 | pelmLevel4Child->getAttributeValue("manufacturer", flt.strManufacturer);
|
---|
654 | pelmLevel4Child->getAttributeValue("product", flt.strProduct);
|
---|
655 | if (!pelmLevel4Child->getAttributeValue("serialNumber", flt.strSerialNumber))
|
---|
656 | pelmLevel4Child->getAttributeValue("serialnumber", flt.strSerialNumber); // used before 1.3
|
---|
657 | pelmLevel4Child->getAttributeValue("port", flt.strPort);
|
---|
658 |
|
---|
659 | // the next 2 are irrelevant for host USB objects
|
---|
660 | pelmLevel4Child->getAttributeValue("remote", flt.strRemote);
|
---|
661 | pelmLevel4Child->getAttributeValue("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
662 |
|
---|
663 | // action is only used with host USB objects
|
---|
664 | if (pelmLevel4Child->getAttributeValue("action", strAction))
|
---|
665 | {
|
---|
666 | if (strAction == "Ignore")
|
---|
667 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
668 | else if (strAction == "Hold")
|
---|
669 | flt.action = USBDeviceFilterAction_Hold;
|
---|
670 | else
|
---|
671 | throw ConfigFileError(this, pelmLevel4Child, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
|
---|
672 | }
|
---|
673 |
|
---|
674 | ll.push_back(flt);
|
---|
675 | }
|
---|
676 | }
|
---|
677 | }
|
---|
678 |
|
---|
679 | /**
|
---|
680 | * Reads a media registry entry from the main VirtualBox.xml file.
|
---|
681 | *
|
---|
682 | * Whereas the current media registry code is fairly straightforward, it was quite a mess
|
---|
683 | * with settings format before 1.4 (VirtualBox 2.0 used settings format 1.3). The elements
|
---|
684 | * in the media registry were much more inconsistent, and different elements were used
|
---|
685 | * depending on the type of device and image.
|
---|
686 | *
|
---|
687 | * @param t
|
---|
688 | * @param elmMedium
|
---|
689 | * @param med
|
---|
690 | */
|
---|
691 | void ConfigFileBase::readMediumOne(MediaType t,
|
---|
692 | const xml::ElementNode &elmMedium,
|
---|
693 | Medium &med)
|
---|
694 | {
|
---|
695 | // <HardDisk uuid="{5471ecdb-1ddb-4012-a801-6d98e226868b}" location="/mnt/innotek-unix/vdis/Windows XP.vdi" format="VDI" type="Normal">
|
---|
696 |
|
---|
697 | Utf8Str strUUID;
|
---|
698 | if (!elmMedium.getAttributeValue("uuid", strUUID))
|
---|
699 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName());
|
---|
700 |
|
---|
701 | parseUUID(med.uuid, strUUID, &elmMedium);
|
---|
702 |
|
---|
703 | bool fNeedsLocation = true;
|
---|
704 |
|
---|
705 | if (t == HardDisk)
|
---|
706 | {
|
---|
707 | if (m->sv < SettingsVersion_v1_4)
|
---|
708 | {
|
---|
709 | // here the system is:
|
---|
710 | // <HardDisk uuid="{....}" type="normal">
|
---|
711 | // <VirtualDiskImage filePath="/path/to/xxx.vdi"/>
|
---|
712 | // </HardDisk>
|
---|
713 |
|
---|
714 | fNeedsLocation = false;
|
---|
715 | bool fNeedsFilePath = true;
|
---|
716 | const xml::ElementNode *pelmImage;
|
---|
717 | if ((pelmImage = elmMedium.findChildElement("VirtualDiskImage")))
|
---|
718 | med.strFormat = "VDI";
|
---|
719 | else if ((pelmImage = elmMedium.findChildElement("VMDKImage")))
|
---|
720 | med.strFormat = "VMDK";
|
---|
721 | else if ((pelmImage = elmMedium.findChildElement("VHDImage")))
|
---|
722 | med.strFormat = "VHD";
|
---|
723 | else if ((pelmImage = elmMedium.findChildElement("ISCSIHardDisk")))
|
---|
724 | {
|
---|
725 | med.strFormat = "iSCSI";
|
---|
726 |
|
---|
727 | fNeedsFilePath = false;
|
---|
728 | // location is special here: current settings specify an "iscsi://user@server:port/target/lun"
|
---|
729 | // string for the location and also have several disk properties for these, whereas this used
|
---|
730 | // to be hidden in several sub-elements before 1.4, so compose a location string and set up
|
---|
731 | // the properties:
|
---|
732 | med.strLocation = "iscsi://";
|
---|
733 | Utf8Str strUser, strServer, strPort, strTarget, strLun;
|
---|
734 | if (pelmImage->getAttributeValue("userName", strUser))
|
---|
735 | {
|
---|
736 | med.strLocation.append(strUser);
|
---|
737 | med.strLocation.append("@");
|
---|
738 | }
|
---|
739 | Utf8Str strServerAndPort;
|
---|
740 | if (pelmImage->getAttributeValue("server", strServer))
|
---|
741 | {
|
---|
742 | strServerAndPort = strServer;
|
---|
743 | }
|
---|
744 | if (pelmImage->getAttributeValue("port", strPort))
|
---|
745 | {
|
---|
746 | if (strServerAndPort.length())
|
---|
747 | strServerAndPort.append(":");
|
---|
748 | strServerAndPort.append(strPort);
|
---|
749 | }
|
---|
750 | med.strLocation.append(strServerAndPort);
|
---|
751 | if (pelmImage->getAttributeValue("target", strTarget))
|
---|
752 | {
|
---|
753 | med.strLocation.append("/");
|
---|
754 | med.strLocation.append(strTarget);
|
---|
755 | }
|
---|
756 | if (pelmImage->getAttributeValue("lun", strLun))
|
---|
757 | {
|
---|
758 | med.strLocation.append("/");
|
---|
759 | med.strLocation.append(strLun);
|
---|
760 | }
|
---|
761 |
|
---|
762 | if (strServer.length() && strPort.length())
|
---|
763 | med.properties["TargetAddress"] = strServerAndPort;
|
---|
764 | if (strTarget.length())
|
---|
765 | med.properties["TargetName"] = strTarget;
|
---|
766 | if (strUser.length())
|
---|
767 | med.properties["InitiatorUsername"] = strUser;
|
---|
768 | Utf8Str strPassword;
|
---|
769 | if (pelmImage->getAttributeValue("password", strPassword))
|
---|
770 | med.properties["InitiatorSecret"] = strPassword;
|
---|
771 | if (strLun.length())
|
---|
772 | med.properties["LUN"] = strLun;
|
---|
773 | }
|
---|
774 | else if ((pelmImage = elmMedium.findChildElement("CustomHardDisk")))
|
---|
775 | {
|
---|
776 | fNeedsFilePath = false;
|
---|
777 | fNeedsLocation = true;
|
---|
778 | // also requires @format attribute, which will be queried below
|
---|
779 | }
|
---|
780 | else
|
---|
781 | throw ConfigFileError(this, &elmMedium, N_("Required %s/VirtualDiskImage element is missing"), elmMedium.getName());
|
---|
782 |
|
---|
783 | if (fNeedsFilePath)
|
---|
784 | {
|
---|
785 | if (!(pelmImage->getAttributeValuePath("filePath", med.strLocation)))
|
---|
786 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
|
---|
787 | }
|
---|
788 | }
|
---|
789 |
|
---|
790 | if (med.strFormat.isEmpty()) // not set with 1.4 format above, or 1.4 Custom format?
|
---|
791 | if (!elmMedium.getAttributeValue("format", med.strFormat))
|
---|
792 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName());
|
---|
793 |
|
---|
794 | if (!elmMedium.getAttributeValue("autoReset", med.fAutoReset))
|
---|
795 | med.fAutoReset = false;
|
---|
796 |
|
---|
797 | Utf8Str strType;
|
---|
798 | if (elmMedium.getAttributeValue("type", strType))
|
---|
799 | {
|
---|
800 | // pre-1.4 used lower case, so make this case-insensitive
|
---|
801 | strType.toUpper();
|
---|
802 | if (strType == "NORMAL")
|
---|
803 | med.hdType = MediumType_Normal;
|
---|
804 | else if (strType == "IMMUTABLE")
|
---|
805 | med.hdType = MediumType_Immutable;
|
---|
806 | else if (strType == "WRITETHROUGH")
|
---|
807 | med.hdType = MediumType_Writethrough;
|
---|
808 | else if (strType == "SHAREABLE")
|
---|
809 | med.hdType = MediumType_Shareable;
|
---|
810 | else if (strType == "READONLY")
|
---|
811 | med.hdType = MediumType_Readonly;
|
---|
812 | else if (strType == "MULTIATTACH")
|
---|
813 | med.hdType = MediumType_MultiAttach;
|
---|
814 | else
|
---|
815 | throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable, Writethrough, Shareable, Readonly or MultiAttach"));
|
---|
816 | }
|
---|
817 | }
|
---|
818 | else
|
---|
819 | {
|
---|
820 | if (m->sv < SettingsVersion_v1_4)
|
---|
821 | {
|
---|
822 | // DVD and floppy images before 1.4 had "src" attribute instead of "location"
|
---|
823 | if (!elmMedium.getAttributeValue("src", med.strLocation))
|
---|
824 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
|
---|
825 |
|
---|
826 | fNeedsLocation = false;
|
---|
827 | }
|
---|
828 |
|
---|
829 | if (!elmMedium.getAttributeValue("format", med.strFormat))
|
---|
830 | {
|
---|
831 | // DVD and floppy images before 1.11 had no format attribute. assign the default.
|
---|
832 | med.strFormat = "RAW";
|
---|
833 | }
|
---|
834 |
|
---|
835 | if (t == DVDImage)
|
---|
836 | med.hdType = MediumType_Readonly;
|
---|
837 | else if (t == FloppyImage)
|
---|
838 | med.hdType = MediumType_Writethrough;
|
---|
839 | }
|
---|
840 |
|
---|
841 | if (fNeedsLocation)
|
---|
842 | // current files and 1.4 CustomHardDisk elements must have a location attribute
|
---|
843 | if (!elmMedium.getAttributeValue("location", med.strLocation))
|
---|
844 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName());
|
---|
845 |
|
---|
846 | // 3.2 builds added Description as an attribute, read it silently
|
---|
847 | // and write it back as an element starting with 5.1.26
|
---|
848 | elmMedium.getAttributeValue("Description", med.strDescription);
|
---|
849 |
|
---|
850 | xml::NodesLoop nlMediumChildren(elmMedium);
|
---|
851 | const xml::ElementNode *pelmMediumChild;
|
---|
852 | while ((pelmMediumChild = nlMediumChildren.forAllNodes()))
|
---|
853 | {
|
---|
854 | if (pelmMediumChild->nameEquals("Description"))
|
---|
855 | med.strDescription = pelmMediumChild->getValue();
|
---|
856 | else if (pelmMediumChild->nameEquals("Property"))
|
---|
857 | {
|
---|
858 | // handle medium properties
|
---|
859 | Utf8Str strPropName, strPropValue;
|
---|
860 | if ( pelmMediumChild->getAttributeValue("name", strPropName)
|
---|
861 | && pelmMediumChild->getAttributeValue("value", strPropValue) )
|
---|
862 | med.properties[strPropName] = strPropValue;
|
---|
863 | else
|
---|
864 | throw ConfigFileError(this, pelmMediumChild, N_("Required HardDisk/Property/@name or @value attribute is missing"));
|
---|
865 | }
|
---|
866 | }
|
---|
867 | }
|
---|
868 |
|
---|
869 | /**
|
---|
870 | * Reads a media registry entry from the main VirtualBox.xml file and
|
---|
871 | * likewise for all children where applicable.
|
---|
872 | *
|
---|
873 | * @param t
|
---|
874 | * @param elmMedium
|
---|
875 | * @param med
|
---|
876 | */
|
---|
877 | void ConfigFileBase::readMedium(MediaType t,
|
---|
878 | const xml::ElementNode &elmMedium,
|
---|
879 | Medium &med)
|
---|
880 | {
|
---|
881 | std::list<const xml::ElementNode *> llElementsTodo;
|
---|
882 | llElementsTodo.push_back(&elmMedium);
|
---|
883 | std::list<Medium *> llSettingsTodo;
|
---|
884 | llSettingsTodo.push_back(&med);
|
---|
885 | std::list<uint32_t> llDepthsTodo;
|
---|
886 | llDepthsTodo.push_back(1);
|
---|
887 |
|
---|
888 | while (llElementsTodo.size() > 0)
|
---|
889 | {
|
---|
890 | const xml::ElementNode *pElement = llElementsTodo.front();
|
---|
891 | llElementsTodo.pop_front();
|
---|
892 | Medium *pMed = llSettingsTodo.front();
|
---|
893 | llSettingsTodo.pop_front();
|
---|
894 | uint32_t depth = llDepthsTodo.front();
|
---|
895 | llDepthsTodo.pop_front();
|
---|
896 |
|
---|
897 | if (depth > SETTINGS_MEDIUM_DEPTH_MAX)
|
---|
898 | throw ConfigFileError(this, pElement, N_("Maximum medium tree depth of %u exceeded"), SETTINGS_MEDIUM_DEPTH_MAX);
|
---|
899 |
|
---|
900 | readMediumOne(t, *pElement, *pMed);
|
---|
901 |
|
---|
902 | if (t != HardDisk)
|
---|
903 | return;
|
---|
904 |
|
---|
905 | // load all children
|
---|
906 | xml::NodesLoop nl2(*pElement, m->sv >= SettingsVersion_v1_4 ? "HardDisk" : "DiffHardDisk");
|
---|
907 | const xml::ElementNode *pelmHDChild;
|
---|
908 | while ((pelmHDChild = nl2.forAllNodes()))
|
---|
909 | {
|
---|
910 | llElementsTodo.push_back(pelmHDChild);
|
---|
911 | pMed->llChildren.push_back(Medium::Empty);
|
---|
912 | llSettingsTodo.push_back(&pMed->llChildren.back());
|
---|
913 | llDepthsTodo.push_back(depth + 1);
|
---|
914 | }
|
---|
915 | }
|
---|
916 | }
|
---|
917 |
|
---|
918 | /**
|
---|
919 | * Reads in the entire \<MediaRegistry\> chunk and stores its media in the lists
|
---|
920 | * of the given MediaRegistry structure.
|
---|
921 | *
|
---|
922 | * This is used in both MainConfigFile and MachineConfigFile since starting with
|
---|
923 | * VirtualBox 4.0, we can have media registries in both.
|
---|
924 | *
|
---|
925 | * For pre-1.4 files, this gets called with the \<DiskRegistry\> chunk instead.
|
---|
926 | *
|
---|
927 | * @param elmMediaRegistry
|
---|
928 | * @param mr
|
---|
929 | */
|
---|
930 | void ConfigFileBase::readMediaRegistry(const xml::ElementNode &elmMediaRegistry,
|
---|
931 | MediaRegistry &mr)
|
---|
932 | {
|
---|
933 | xml::NodesLoop nl1(elmMediaRegistry);
|
---|
934 | const xml::ElementNode *pelmChild1;
|
---|
935 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
936 | {
|
---|
937 | MediaType t = Error;
|
---|
938 | if (pelmChild1->nameEquals("HardDisks"))
|
---|
939 | t = HardDisk;
|
---|
940 | else if (pelmChild1->nameEquals("DVDImages"))
|
---|
941 | t = DVDImage;
|
---|
942 | else if (pelmChild1->nameEquals("FloppyImages"))
|
---|
943 | t = FloppyImage;
|
---|
944 | else
|
---|
945 | continue;
|
---|
946 |
|
---|
947 | xml::NodesLoop nl2(*pelmChild1);
|
---|
948 | const xml::ElementNode *pelmMedium;
|
---|
949 | while ((pelmMedium = nl2.forAllNodes()))
|
---|
950 | {
|
---|
951 | if ( t == HardDisk
|
---|
952 | && (pelmMedium->nameEquals("HardDisk")))
|
---|
953 | {
|
---|
954 | mr.llHardDisks.push_back(Medium::Empty);
|
---|
955 | readMedium(t, *pelmMedium, mr.llHardDisks.back());
|
---|
956 | }
|
---|
957 | else if ( t == DVDImage
|
---|
958 | && (pelmMedium->nameEquals("Image")))
|
---|
959 | {
|
---|
960 | mr.llDvdImages.push_back(Medium::Empty);
|
---|
961 | readMedium(t, *pelmMedium, mr.llDvdImages.back());
|
---|
962 | }
|
---|
963 | else if ( t == FloppyImage
|
---|
964 | && (pelmMedium->nameEquals("Image")))
|
---|
965 | {
|
---|
966 | mr.llFloppyImages.push_back(Medium::Empty);
|
---|
967 | readMedium(t, *pelmMedium, mr.llFloppyImages.back());
|
---|
968 | }
|
---|
969 | }
|
---|
970 | }
|
---|
971 | }
|
---|
972 |
|
---|
973 | /**
|
---|
974 | * This is common version for reading NAT port forward rule in per-_machine's_adapter_ and
|
---|
975 | * per-network approaches.
|
---|
976 | * Note: this function doesn't in fill given list from xml::ElementNodesList, because there is conflicting
|
---|
977 | * declaration in ovmfreader.h.
|
---|
978 | */
|
---|
979 | void ConfigFileBase::readNATForwardRulesMap(const xml::ElementNode &elmParent, NATRulesMap &mapRules)
|
---|
980 | {
|
---|
981 | xml::ElementNodesList plstRules;
|
---|
982 | elmParent.getChildElements(plstRules, "Forwarding");
|
---|
983 | for (xml::ElementNodesList::iterator pf = plstRules.begin(); pf != plstRules.end(); ++pf)
|
---|
984 | {
|
---|
985 | NATRule rule;
|
---|
986 | uint32_t port = 0;
|
---|
987 | (*pf)->getAttributeValue("name", rule.strName);
|
---|
988 | (*pf)->getAttributeValue("proto", (uint32_t&)rule.proto);
|
---|
989 | (*pf)->getAttributeValue("hostip", rule.strHostIP);
|
---|
990 | (*pf)->getAttributeValue("hostport", port);
|
---|
991 | rule.u16HostPort = (uint16_t)port;
|
---|
992 | (*pf)->getAttributeValue("guestip", rule.strGuestIP);
|
---|
993 | (*pf)->getAttributeValue("guestport", port);
|
---|
994 | rule.u16GuestPort = (uint16_t)port;
|
---|
995 | mapRules.insert(std::make_pair(rule.strName, rule));
|
---|
996 | }
|
---|
997 | }
|
---|
998 |
|
---|
999 | void ConfigFileBase::readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopbacks)
|
---|
1000 | {
|
---|
1001 | xml::ElementNodesList plstLoopbacks;
|
---|
1002 | elmParent.getChildElements(plstLoopbacks, "Loopback4");
|
---|
1003 | for (xml::ElementNodesList::iterator lo = plstLoopbacks.begin();
|
---|
1004 | lo != plstLoopbacks.end(); ++lo)
|
---|
1005 | {
|
---|
1006 | NATHostLoopbackOffset loopback;
|
---|
1007 | (*lo)->getAttributeValue("address", loopback.strLoopbackHostAddress);
|
---|
1008 | (*lo)->getAttributeValue("offset", (uint32_t&)loopback.u32Offset);
|
---|
1009 | llLoopbacks.push_back(loopback);
|
---|
1010 | }
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 |
|
---|
1014 | /**
|
---|
1015 | * Adds a "version" attribute to the given XML element with the
|
---|
1016 | * VirtualBox settings version (e.g. "1.10-linux"). Used by
|
---|
1017 | * the XML format for the root element and by the OVF export
|
---|
1018 | * for the vbox:Machine element.
|
---|
1019 | * @param elm
|
---|
1020 | */
|
---|
1021 | void ConfigFileBase::setVersionAttribute(xml::ElementNode &elm)
|
---|
1022 | {
|
---|
1023 | const char *pcszVersion = NULL;
|
---|
1024 | switch (m->sv)
|
---|
1025 | {
|
---|
1026 | case SettingsVersion_v1_8:
|
---|
1027 | pcszVersion = "1.8";
|
---|
1028 | break;
|
---|
1029 |
|
---|
1030 | case SettingsVersion_v1_9:
|
---|
1031 | pcszVersion = "1.9";
|
---|
1032 | break;
|
---|
1033 |
|
---|
1034 | case SettingsVersion_v1_10:
|
---|
1035 | pcszVersion = "1.10";
|
---|
1036 | break;
|
---|
1037 |
|
---|
1038 | case SettingsVersion_v1_11:
|
---|
1039 | pcszVersion = "1.11";
|
---|
1040 | break;
|
---|
1041 |
|
---|
1042 | case SettingsVersion_v1_12:
|
---|
1043 | pcszVersion = "1.12";
|
---|
1044 | break;
|
---|
1045 |
|
---|
1046 | case SettingsVersion_v1_13:
|
---|
1047 | pcszVersion = "1.13";
|
---|
1048 | break;
|
---|
1049 |
|
---|
1050 | case SettingsVersion_v1_14:
|
---|
1051 | pcszVersion = "1.14";
|
---|
1052 | break;
|
---|
1053 |
|
---|
1054 | case SettingsVersion_v1_15:
|
---|
1055 | pcszVersion = "1.15";
|
---|
1056 | break;
|
---|
1057 |
|
---|
1058 | case SettingsVersion_v1_16:
|
---|
1059 | pcszVersion = "1.16";
|
---|
1060 | break;
|
---|
1061 |
|
---|
1062 | case SettingsVersion_v1_17:
|
---|
1063 | pcszVersion = "1.17";
|
---|
1064 | break;
|
---|
1065 |
|
---|
1066 | case SettingsVersion_v1_18:
|
---|
1067 | pcszVersion = "1.18";
|
---|
1068 | break;
|
---|
1069 |
|
---|
1070 | case SettingsVersion_v1_19:
|
---|
1071 | pcszVersion = "1.19";
|
---|
1072 | break;
|
---|
1073 |
|
---|
1074 | default:
|
---|
1075 | // catch human error: the assertion below will trigger in debug
|
---|
1076 | // or dbgopt builds, so hopefully this will get noticed sooner in
|
---|
1077 | // the future, because it's easy to forget top update something.
|
---|
1078 | AssertMsg(m->sv <= SettingsVersion_v1_7, ("Settings.cpp: unexpected settings version %d, unhandled future version?\n", m->sv));
|
---|
1079 | // silently upgrade if this is less than 1.7 because that's the oldest we can write
|
---|
1080 | if (m->sv <= SettingsVersion_v1_7)
|
---|
1081 | {
|
---|
1082 | pcszVersion = "1.7";
|
---|
1083 | m->sv = SettingsVersion_v1_7;
|
---|
1084 | }
|
---|
1085 | else
|
---|
1086 | {
|
---|
1087 | // This is reached for SettingsVersion_Future and forgotten
|
---|
1088 | // settings version after SettingsVersion_v1_7, which should
|
---|
1089 | // not happen (see assertion above). Set the version to the
|
---|
1090 | // latest known version, to minimize loss of information, but
|
---|
1091 | // as we can't predict the future we have to use some format
|
---|
1092 | // we know, and latest should be the best choice. Note that
|
---|
1093 | // for "forgotten settings" this may not be the best choice,
|
---|
1094 | // but as it's an omission of someone who changed this file
|
---|
1095 | // it's the only generic possibility.
|
---|
1096 | pcszVersion = "1.19";
|
---|
1097 | m->sv = SettingsVersion_v1_19;
|
---|
1098 | }
|
---|
1099 | break;
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | m->strSettingsVersionFull = Utf8StrFmt("%s-%s",
|
---|
1103 | pcszVersion,
|
---|
1104 | VBOX_XML_PLATFORM); // e.g. "linux"
|
---|
1105 | elm.setAttribute("version", m->strSettingsVersionFull);
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 |
|
---|
1109 | /**
|
---|
1110 | * Creates a special backup file in case there is a version
|
---|
1111 | * bump, so that it is possible to go back to the previous
|
---|
1112 | * state. This is done only once (not for every settings
|
---|
1113 | * version bump), when the settings version is newer than
|
---|
1114 | * the version read from the config file. Must be called
|
---|
1115 | * before ConfigFileBase::createStubDocument, because that
|
---|
1116 | * method may alter information which this method needs.
|
---|
1117 | */
|
---|
1118 | void ConfigFileBase::specialBackupIfFirstBump()
|
---|
1119 | {
|
---|
1120 | // Since this gets called before the XML document is actually written out,
|
---|
1121 | // this is where we must check whether we're upgrading the settings version
|
---|
1122 | // and need to make a backup, so the user can go back to an earlier
|
---|
1123 | // VirtualBox version and recover his old settings files.
|
---|
1124 | if ( (m->svRead != SettingsVersion_Null) // old file exists?
|
---|
1125 | && (m->svRead < m->sv) // we're upgrading?
|
---|
1126 | )
|
---|
1127 | {
|
---|
1128 | // compose new filename: strip off trailing ".xml"/".vbox"
|
---|
1129 | Utf8Str strFilenameNew;
|
---|
1130 | Utf8Str strExt = ".xml";
|
---|
1131 | if (m->strFilename.endsWith(".xml"))
|
---|
1132 | strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
|
---|
1133 | else if (m->strFilename.endsWith(".vbox"))
|
---|
1134 | {
|
---|
1135 | strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 5);
|
---|
1136 | strExt = ".vbox";
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | // and append something like "-1.3-linux.xml"
|
---|
1140 | strFilenameNew.append("-");
|
---|
1141 | strFilenameNew.append(m->strSettingsVersionFull); // e.g. "1.3-linux"
|
---|
1142 | strFilenameNew.append(strExt); // .xml for main config, .vbox for machine config
|
---|
1143 |
|
---|
1144 | // Copying the file cannot be avoided, as doing tricks with renaming
|
---|
1145 | // causes trouble on OS X with aliases (which follow the rename), and
|
---|
1146 | // on all platforms there is a risk of "losing" the VM config when
|
---|
1147 | // running out of space, as a rename here couldn't be rolled back.
|
---|
1148 | // Ignoring all errors besides running out of space is intentional, as
|
---|
1149 | // we don't want to do anything if the file already exists.
|
---|
1150 | int vrc = RTFileCopy(m->strFilename.c_str(), strFilenameNew.c_str());
|
---|
1151 | if (RT_UNLIKELY(vrc == VERR_DISK_FULL))
|
---|
1152 | throw ConfigFileError(this, NULL, N_("Cannot create settings backup file when upgrading to a newer settings format"));
|
---|
1153 |
|
---|
1154 | // do this only once
|
---|
1155 | m->svRead = SettingsVersion_Null;
|
---|
1156 | }
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | /**
|
---|
1160 | * Creates a new stub xml::Document in the m->pDoc member with the
|
---|
1161 | * root "VirtualBox" element set up. This is used by both
|
---|
1162 | * MainConfigFile and MachineConfigFile at the beginning of writing
|
---|
1163 | * out their XML.
|
---|
1164 | *
|
---|
1165 | * Before calling this, it is the responsibility of the caller to
|
---|
1166 | * set the "sv" member to the required settings version that is to
|
---|
1167 | * be written. For newly created files, the settings version will be
|
---|
1168 | * recent (1.12 or later if necessary); for files read in from disk
|
---|
1169 | * earlier, it will be the settings version indicated in the file.
|
---|
1170 | * However, this method will silently make sure that the settings
|
---|
1171 | * version is always at least 1.7 and change it if necessary, since
|
---|
1172 | * there is no write support for earlier settings versions.
|
---|
1173 | */
|
---|
1174 | void ConfigFileBase::createStubDocument()
|
---|
1175 | {
|
---|
1176 | Assert(m->pDoc == NULL);
|
---|
1177 | m->pDoc = new xml::Document;
|
---|
1178 |
|
---|
1179 | m->pelmRoot = m->pDoc->createRootElement("VirtualBox",
|
---|
1180 | "\n"
|
---|
1181 | "** DO NOT EDIT THIS FILE.\n"
|
---|
1182 | "** If you make changes to this file while any VirtualBox related application\n"
|
---|
1183 | "** is running, your changes will be overwritten later, without taking effect.\n"
|
---|
1184 | "** Use VBoxManage or the VirtualBox Manager GUI to make changes.\n"
|
---|
1185 | );
|
---|
1186 | m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
|
---|
1187 | // Have the code for producing a proper schema reference. Not used by most
|
---|
1188 | // tools, so don't bother doing it. The schema is not on the server anyway.
|
---|
1189 | #ifdef VBOX_WITH_SETTINGS_SCHEMA
|
---|
1190 | m->pelmRoot->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
---|
1191 | m->pelmRoot->setAttribute("xsi:schemaLocation", VBOX_XML_NAMESPACE " " VBOX_XML_SCHEMA);
|
---|
1192 | #endif
|
---|
1193 |
|
---|
1194 | // add settings version attribute to root element, update m->strSettingsVersionFull
|
---|
1195 | setVersionAttribute(*m->pelmRoot);
|
---|
1196 |
|
---|
1197 | LogRel(("Saving settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | /**
|
---|
1201 | * Creates an \<ExtraData\> node under the given parent element with
|
---|
1202 | * \<ExtraDataItem\> childern according to the contents of the given
|
---|
1203 | * map.
|
---|
1204 | *
|
---|
1205 | * This is in ConfigFileBase because it's used in both MainConfigFile
|
---|
1206 | * and MachineConfigFile, which both can have extradata.
|
---|
1207 | *
|
---|
1208 | * @param elmParent
|
---|
1209 | * @param me
|
---|
1210 | */
|
---|
1211 | void ConfigFileBase::buildExtraData(xml::ElementNode &elmParent,
|
---|
1212 | const StringsMap &me)
|
---|
1213 | {
|
---|
1214 | if (me.size())
|
---|
1215 | {
|
---|
1216 | xml::ElementNode *pelmExtraData = elmParent.createChild("ExtraData");
|
---|
1217 | for (StringsMap::const_iterator it = me.begin();
|
---|
1218 | it != me.end();
|
---|
1219 | ++it)
|
---|
1220 | {
|
---|
1221 | const Utf8Str &strName = it->first;
|
---|
1222 | const Utf8Str &strValue = it->second;
|
---|
1223 | xml::ElementNode *pelmThis = pelmExtraData->createChild("ExtraDataItem");
|
---|
1224 | pelmThis->setAttribute("name", strName);
|
---|
1225 | pelmThis->setAttribute("value", strValue);
|
---|
1226 | }
|
---|
1227 | }
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | /**
|
---|
1231 | * Creates \<DeviceFilter\> nodes under the given parent element according to
|
---|
1232 | * the contents of the given USBDeviceFiltersList. This is in ConfigFileBase
|
---|
1233 | * because it's used in both MainConfigFile (for host filters) and
|
---|
1234 | * MachineConfigFile (for machine filters).
|
---|
1235 | *
|
---|
1236 | * If fHostMode is true, this means that we're supposed to write filters
|
---|
1237 | * for the IHost interface (respect "action", omit "strRemote" and
|
---|
1238 | * "ulMaskedInterfaces" in struct USBDeviceFilter).
|
---|
1239 | *
|
---|
1240 | * @param elmParent
|
---|
1241 | * @param ll
|
---|
1242 | * @param fHostMode
|
---|
1243 | */
|
---|
1244 | void ConfigFileBase::buildUSBDeviceFilters(xml::ElementNode &elmParent,
|
---|
1245 | const USBDeviceFiltersList &ll,
|
---|
1246 | bool fHostMode)
|
---|
1247 | {
|
---|
1248 | for (USBDeviceFiltersList::const_iterator it = ll.begin();
|
---|
1249 | it != ll.end();
|
---|
1250 | ++it)
|
---|
1251 | {
|
---|
1252 | const USBDeviceFilter &flt = *it;
|
---|
1253 | xml::ElementNode *pelmFilter = elmParent.createChild("DeviceFilter");
|
---|
1254 | pelmFilter->setAttribute("name", flt.strName);
|
---|
1255 | pelmFilter->setAttribute("active", flt.fActive);
|
---|
1256 | if (flt.strVendorId.length())
|
---|
1257 | pelmFilter->setAttribute("vendorId", flt.strVendorId);
|
---|
1258 | if (flt.strProductId.length())
|
---|
1259 | pelmFilter->setAttribute("productId", flt.strProductId);
|
---|
1260 | if (flt.strRevision.length())
|
---|
1261 | pelmFilter->setAttribute("revision", flt.strRevision);
|
---|
1262 | if (flt.strManufacturer.length())
|
---|
1263 | pelmFilter->setAttribute("manufacturer", flt.strManufacturer);
|
---|
1264 | if (flt.strProduct.length())
|
---|
1265 | pelmFilter->setAttribute("product", flt.strProduct);
|
---|
1266 | if (flt.strSerialNumber.length())
|
---|
1267 | pelmFilter->setAttribute("serialNumber", flt.strSerialNumber);
|
---|
1268 | if (flt.strPort.length())
|
---|
1269 | pelmFilter->setAttribute("port", flt.strPort);
|
---|
1270 |
|
---|
1271 | if (fHostMode)
|
---|
1272 | {
|
---|
1273 | const char *pcsz =
|
---|
1274 | (flt.action == USBDeviceFilterAction_Ignore) ? "Ignore"
|
---|
1275 | : /*(flt.action == USBDeviceFilterAction_Hold) ?*/ "Hold";
|
---|
1276 | pelmFilter->setAttribute("action", pcsz);
|
---|
1277 | }
|
---|
1278 | else
|
---|
1279 | {
|
---|
1280 | if (flt.strRemote.length())
|
---|
1281 | pelmFilter->setAttribute("remote", flt.strRemote);
|
---|
1282 | if (flt.ulMaskedInterfaces)
|
---|
1283 | pelmFilter->setAttribute("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
1284 | }
|
---|
1285 | }
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | /**
|
---|
1289 | * Creates a single \<HardDisk\> element for the given Medium structure
|
---|
1290 | * and all child hard disks underneath. Called from MainConfigFile::write().
|
---|
1291 | *
|
---|
1292 | * @param t
|
---|
1293 | * @param elmMedium
|
---|
1294 | * @param med
|
---|
1295 | */
|
---|
1296 | void ConfigFileBase::buildMedium(MediaType t,
|
---|
1297 | xml::ElementNode &elmMedium,
|
---|
1298 | const Medium &med)
|
---|
1299 | {
|
---|
1300 | std::list<const Medium *> llSettingsTodo;
|
---|
1301 | llSettingsTodo.push_back(&med);
|
---|
1302 | std::list<xml::ElementNode *> llElementsTodo;
|
---|
1303 | llElementsTodo.push_back(&elmMedium);
|
---|
1304 | std::list<uint32_t> llDepthsTodo;
|
---|
1305 | llDepthsTodo.push_back(1);
|
---|
1306 |
|
---|
1307 | while (llSettingsTodo.size() > 0)
|
---|
1308 | {
|
---|
1309 | const Medium *pMed = llSettingsTodo.front();
|
---|
1310 | llSettingsTodo.pop_front();
|
---|
1311 | xml::ElementNode *pElement = llElementsTodo.front();
|
---|
1312 | llElementsTodo.pop_front();
|
---|
1313 | uint32_t depth = llDepthsTodo.front();
|
---|
1314 | llDepthsTodo.pop_front();
|
---|
1315 |
|
---|
1316 | if (depth > SETTINGS_MEDIUM_DEPTH_MAX)
|
---|
1317 | throw ConfigFileError(this, pElement, N_("Maximum medium tree depth of %u exceeded"), SETTINGS_MEDIUM_DEPTH_MAX);
|
---|
1318 |
|
---|
1319 | xml::ElementNode *pelmMedium;
|
---|
1320 |
|
---|
1321 | if (t == HardDisk)
|
---|
1322 | pelmMedium = pElement->createChild("HardDisk");
|
---|
1323 | else
|
---|
1324 | pelmMedium = pElement->createChild("Image");
|
---|
1325 |
|
---|
1326 | pelmMedium->setAttribute("uuid", pMed->uuid.toStringCurly());
|
---|
1327 |
|
---|
1328 | pelmMedium->setAttributePath("location", pMed->strLocation);
|
---|
1329 |
|
---|
1330 | if (t == HardDisk || RTStrICmp(pMed->strFormat.c_str(), "RAW"))
|
---|
1331 | pelmMedium->setAttribute("format", pMed->strFormat);
|
---|
1332 | if ( t == HardDisk
|
---|
1333 | && pMed->fAutoReset)
|
---|
1334 | pelmMedium->setAttribute("autoReset", pMed->fAutoReset);
|
---|
1335 | if (pMed->strDescription.length())
|
---|
1336 | pelmMedium->createChild("Description")->addContent(pMed->strDescription);
|
---|
1337 |
|
---|
1338 | for (StringsMap::const_iterator it = pMed->properties.begin();
|
---|
1339 | it != pMed->properties.end();
|
---|
1340 | ++it)
|
---|
1341 | {
|
---|
1342 | xml::ElementNode *pelmProp = pelmMedium->createChild("Property");
|
---|
1343 | pelmProp->setAttribute("name", it->first);
|
---|
1344 | pelmProp->setAttribute("value", it->second);
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | // only for base hard disks, save the type
|
---|
1348 | if (depth == 1)
|
---|
1349 | {
|
---|
1350 | // no need to save the usual DVD/floppy medium types
|
---|
1351 | if ( ( t != DVDImage
|
---|
1352 | || ( pMed->hdType != MediumType_Writethrough // shouldn't happen
|
---|
1353 | && pMed->hdType != MediumType_Readonly))
|
---|
1354 | && ( t != FloppyImage
|
---|
1355 | || pMed->hdType != MediumType_Writethrough))
|
---|
1356 | {
|
---|
1357 | const char *pcszType =
|
---|
1358 | pMed->hdType == MediumType_Normal ? "Normal" :
|
---|
1359 | pMed->hdType == MediumType_Immutable ? "Immutable" :
|
---|
1360 | pMed->hdType == MediumType_Writethrough ? "Writethrough" :
|
---|
1361 | pMed->hdType == MediumType_Shareable ? "Shareable" :
|
---|
1362 | pMed->hdType == MediumType_Readonly ? "Readonly" :
|
---|
1363 | pMed->hdType == MediumType_MultiAttach ? "MultiAttach" :
|
---|
1364 | "INVALID";
|
---|
1365 | pelmMedium->setAttribute("type", pcszType);
|
---|
1366 | }
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | /* save all children */
|
---|
1370 | MediaList::const_iterator itBegin = pMed->llChildren.begin();
|
---|
1371 | MediaList::const_iterator itEnd = pMed->llChildren.end();
|
---|
1372 | for (MediaList::const_iterator it = itBegin; it != itEnd; ++it)
|
---|
1373 | {
|
---|
1374 | llSettingsTodo.push_back(&*it);
|
---|
1375 | llElementsTodo.push_back(pelmMedium);
|
---|
1376 | llDepthsTodo.push_back(depth + 1);
|
---|
1377 | }
|
---|
1378 | }
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | /**
|
---|
1382 | * Creates a \<MediaRegistry\> node under the given parent and writes out all
|
---|
1383 | * hard disks and DVD and floppy images from the lists in the given MediaRegistry
|
---|
1384 | * structure under it.
|
---|
1385 | *
|
---|
1386 | * This is used in both MainConfigFile and MachineConfigFile since starting with
|
---|
1387 | * VirtualBox 4.0, we can have media registries in both.
|
---|
1388 | *
|
---|
1389 | * @param elmParent
|
---|
1390 | * @param mr
|
---|
1391 | */
|
---|
1392 | void ConfigFileBase::buildMediaRegistry(xml::ElementNode &elmParent,
|
---|
1393 | const MediaRegistry &mr)
|
---|
1394 | {
|
---|
1395 | if (mr.llHardDisks.size() == 0 && mr.llDvdImages.size() == 0 && mr.llFloppyImages.size() == 0)
|
---|
1396 | return;
|
---|
1397 |
|
---|
1398 | xml::ElementNode *pelmMediaRegistry = elmParent.createChild("MediaRegistry");
|
---|
1399 |
|
---|
1400 | if (mr.llHardDisks.size())
|
---|
1401 | {
|
---|
1402 | xml::ElementNode *pelmHardDisks = pelmMediaRegistry->createChild("HardDisks");
|
---|
1403 | for (MediaList::const_iterator it = mr.llHardDisks.begin();
|
---|
1404 | it != mr.llHardDisks.end();
|
---|
1405 | ++it)
|
---|
1406 | {
|
---|
1407 | buildMedium(HardDisk, *pelmHardDisks, *it);
|
---|
1408 | }
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | if (mr.llDvdImages.size())
|
---|
1412 | {
|
---|
1413 | xml::ElementNode *pelmDVDImages = pelmMediaRegistry->createChild("DVDImages");
|
---|
1414 | for (MediaList::const_iterator it = mr.llDvdImages.begin();
|
---|
1415 | it != mr.llDvdImages.end();
|
---|
1416 | ++it)
|
---|
1417 | {
|
---|
1418 | buildMedium(DVDImage, *pelmDVDImages, *it);
|
---|
1419 | }
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | if (mr.llFloppyImages.size())
|
---|
1423 | {
|
---|
1424 | xml::ElementNode *pelmFloppyImages = pelmMediaRegistry->createChild("FloppyImages");
|
---|
1425 | for (MediaList::const_iterator it = mr.llFloppyImages.begin();
|
---|
1426 | it != mr.llFloppyImages.end();
|
---|
1427 | ++it)
|
---|
1428 | {
|
---|
1429 | buildMedium(FloppyImage, *pelmFloppyImages, *it);
|
---|
1430 | }
|
---|
1431 | }
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | /**
|
---|
1435 | * Serialize NAT port-forwarding rules in parent container.
|
---|
1436 | * Note: it's responsibility of caller to create parent of the list tag.
|
---|
1437 | * because this method used for serializing per-_mahine's_adapter_ and per-network approaches.
|
---|
1438 | */
|
---|
1439 | void ConfigFileBase::buildNATForwardRulesMap(xml::ElementNode &elmParent, const NATRulesMap &mapRules)
|
---|
1440 | {
|
---|
1441 | for (NATRulesMap::const_iterator r = mapRules.begin();
|
---|
1442 | r != mapRules.end(); ++r)
|
---|
1443 | {
|
---|
1444 | xml::ElementNode *pelmPF;
|
---|
1445 | pelmPF = elmParent.createChild("Forwarding");
|
---|
1446 | const NATRule &nr = r->second;
|
---|
1447 | if (nr.strName.length())
|
---|
1448 | pelmPF->setAttribute("name", nr.strName);
|
---|
1449 | pelmPF->setAttribute("proto", nr.proto);
|
---|
1450 | if (nr.strHostIP.length())
|
---|
1451 | pelmPF->setAttribute("hostip", nr.strHostIP);
|
---|
1452 | if (nr.u16HostPort)
|
---|
1453 | pelmPF->setAttribute("hostport", nr.u16HostPort);
|
---|
1454 | if (nr.strGuestIP.length())
|
---|
1455 | pelmPF->setAttribute("guestip", nr.strGuestIP);
|
---|
1456 | if (nr.u16GuestPort)
|
---|
1457 | pelmPF->setAttribute("guestport", nr.u16GuestPort);
|
---|
1458 | }
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 |
|
---|
1462 | void ConfigFileBase::buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackOffsetList)
|
---|
1463 | {
|
---|
1464 | for (NATLoopbackOffsetList::const_iterator lo = natLoopbackOffsetList.begin();
|
---|
1465 | lo != natLoopbackOffsetList.end(); ++lo)
|
---|
1466 | {
|
---|
1467 | xml::ElementNode *pelmLo;
|
---|
1468 | pelmLo = elmParent.createChild("Loopback4");
|
---|
1469 | pelmLo->setAttribute("address", (*lo).strLoopbackHostAddress);
|
---|
1470 | pelmLo->setAttribute("offset", (*lo).u32Offset);
|
---|
1471 | }
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | /**
|
---|
1475 | * Cleans up memory allocated by the internal XML parser. To be called by
|
---|
1476 | * descendant classes when they're done analyzing the DOM tree to discard it.
|
---|
1477 | */
|
---|
1478 | void ConfigFileBase::clearDocument()
|
---|
1479 | {
|
---|
1480 | m->cleanup();
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | /**
|
---|
1484 | * Returns true only if the underlying config file exists on disk;
|
---|
1485 | * either because the file has been loaded from disk, or it's been written
|
---|
1486 | * to disk, or both.
|
---|
1487 | * @return
|
---|
1488 | */
|
---|
1489 | bool ConfigFileBase::fileExists()
|
---|
1490 | {
|
---|
1491 | return m->fFileExists;
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 | /**
|
---|
1495 | * Returns the settings file version
|
---|
1496 | *
|
---|
1497 | * @returns Settings file version enum.
|
---|
1498 | */
|
---|
1499 | SettingsVersion_T ConfigFileBase::getSettingsVersion()
|
---|
1500 | {
|
---|
1501 | return m->sv;
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 |
|
---|
1505 | /**
|
---|
1506 | * Copies the base variables from another instance. Used by Machine::saveSettings
|
---|
1507 | * so that the settings version does not get lost when a copy of the Machine settings
|
---|
1508 | * file is made to see if settings have actually changed.
|
---|
1509 | * @param b
|
---|
1510 | */
|
---|
1511 | void ConfigFileBase::copyBaseFrom(const ConfigFileBase &b)
|
---|
1512 | {
|
---|
1513 | m->copyFrom(*b.m);
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1517 | //
|
---|
1518 | // Structures shared between Machine XML and VirtualBox.xml
|
---|
1519 | //
|
---|
1520 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1521 |
|
---|
1522 |
|
---|
1523 | /**
|
---|
1524 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1525 | */
|
---|
1526 | USBDeviceFilter::USBDeviceFilter() :
|
---|
1527 | fActive(false),
|
---|
1528 | action(USBDeviceFilterAction_Null),
|
---|
1529 | ulMaskedInterfaces(0)
|
---|
1530 | {
|
---|
1531 | }
|
---|
1532 |
|
---|
1533 | /**
|
---|
1534 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1535 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1536 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1537 | */
|
---|
1538 | bool USBDeviceFilter::operator==(const USBDeviceFilter &u) const
|
---|
1539 | {
|
---|
1540 | return (this == &u)
|
---|
1541 | || ( strName == u.strName
|
---|
1542 | && fActive == u.fActive
|
---|
1543 | && strVendorId == u.strVendorId
|
---|
1544 | && strProductId == u.strProductId
|
---|
1545 | && strRevision == u.strRevision
|
---|
1546 | && strManufacturer == u.strManufacturer
|
---|
1547 | && strProduct == u.strProduct
|
---|
1548 | && strSerialNumber == u.strSerialNumber
|
---|
1549 | && strPort == u.strPort
|
---|
1550 | && action == u.action
|
---|
1551 | && strRemote == u.strRemote
|
---|
1552 | && ulMaskedInterfaces == u.ulMaskedInterfaces);
|
---|
1553 | }
|
---|
1554 |
|
---|
1555 | /**
|
---|
1556 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1557 | */
|
---|
1558 | settings::Medium::Medium() :
|
---|
1559 | fAutoReset(false),
|
---|
1560 | hdType(MediumType_Normal)
|
---|
1561 | {
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 | /**
|
---|
1565 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1566 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1567 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1568 | */
|
---|
1569 | bool settings::Medium::operator==(const settings::Medium &m) const
|
---|
1570 | {
|
---|
1571 | return (this == &m)
|
---|
1572 | || ( uuid == m.uuid
|
---|
1573 | && strLocation == m.strLocation
|
---|
1574 | && strDescription == m.strDescription
|
---|
1575 | && strFormat == m.strFormat
|
---|
1576 | && fAutoReset == m.fAutoReset
|
---|
1577 | && properties == m.properties
|
---|
1578 | && hdType == m.hdType
|
---|
1579 | && llChildren == m.llChildren); // this is deep and recurses
|
---|
1580 | }
|
---|
1581 |
|
---|
1582 | const struct settings::Medium settings::Medium::Empty; /* default ctor is OK */
|
---|
1583 |
|
---|
1584 | /**
|
---|
1585 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1586 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1587 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1588 | */
|
---|
1589 | bool MediaRegistry::operator==(const MediaRegistry &m) const
|
---|
1590 | {
|
---|
1591 | return (this == &m)
|
---|
1592 | || ( llHardDisks == m.llHardDisks
|
---|
1593 | && llDvdImages == m.llDvdImages
|
---|
1594 | && llFloppyImages == m.llFloppyImages);
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | /**
|
---|
1598 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1599 | */
|
---|
1600 | NATRule::NATRule() :
|
---|
1601 | proto(NATProtocol_TCP),
|
---|
1602 | u16HostPort(0),
|
---|
1603 | u16GuestPort(0)
|
---|
1604 | {
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 | /**
|
---|
1608 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1609 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1610 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1611 | */
|
---|
1612 | bool NATRule::operator==(const NATRule &r) const
|
---|
1613 | {
|
---|
1614 | return (this == &r)
|
---|
1615 | || ( strName == r.strName
|
---|
1616 | && proto == r.proto
|
---|
1617 | && u16HostPort == r.u16HostPort
|
---|
1618 | && strHostIP == r.strHostIP
|
---|
1619 | && u16GuestPort == r.u16GuestPort
|
---|
1620 | && strGuestIP == r.strGuestIP);
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 | /**
|
---|
1624 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1625 | */
|
---|
1626 | NATHostLoopbackOffset::NATHostLoopbackOffset() :
|
---|
1627 | u32Offset(0)
|
---|
1628 | {
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | /**
|
---|
1632 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
1633 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
1634 | * machine settings have really changed and thus need to be written out to disk.
|
---|
1635 | */
|
---|
1636 | bool NATHostLoopbackOffset::operator==(const NATHostLoopbackOffset &o) const
|
---|
1637 | {
|
---|
1638 | return (this == &o)
|
---|
1639 | || ( strLoopbackHostAddress == o.strLoopbackHostAddress
|
---|
1640 | && u32Offset == o.u32Offset);
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 |
|
---|
1644 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1645 | //
|
---|
1646 | // VirtualBox.xml structures
|
---|
1647 | //
|
---|
1648 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1649 |
|
---|
1650 | /**
|
---|
1651 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1652 | */
|
---|
1653 | SystemProperties::SystemProperties()
|
---|
1654 | : uProxyMode(ProxyMode_System)
|
---|
1655 | , uLogHistoryCount(3)
|
---|
1656 | , fExclusiveHwVirt(true)
|
---|
1657 | {
|
---|
1658 | #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
|
---|
1659 | fExclusiveHwVirt = false;
|
---|
1660 | #endif
|
---|
1661 | }
|
---|
1662 |
|
---|
1663 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
1664 | UpdateAgent::UpdateAgent()
|
---|
1665 | : fEnabled(false)
|
---|
1666 | , enmChannel(UpdateChannel_Stable)
|
---|
1667 | , uCheckFreqSeconds(RT_SEC_1DAY)
|
---|
1668 | , uCheckCount(0)
|
---|
1669 | {
|
---|
1670 | }
|
---|
1671 | #endif /* VBOX_WITH_UPDATE_AGENT */
|
---|
1672 |
|
---|
1673 | /**
|
---|
1674 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1675 | */
|
---|
1676 | DhcpOptValue::DhcpOptValue()
|
---|
1677 | : strValue()
|
---|
1678 | , enmEncoding(DHCPOptionEncoding_Normal)
|
---|
1679 | {
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 | /**
|
---|
1683 | * Non-standard constructor.
|
---|
1684 | */
|
---|
1685 | DhcpOptValue::DhcpOptValue(const com::Utf8Str &aText, DHCPOptionEncoding_T aEncoding)
|
---|
1686 | : strValue(aText)
|
---|
1687 | , enmEncoding(aEncoding)
|
---|
1688 | {
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | /**
|
---|
1692 | * Default constructor.
|
---|
1693 | */
|
---|
1694 | DHCPGroupCondition::DHCPGroupCondition()
|
---|
1695 | : fInclusive(true)
|
---|
1696 | , enmType(DHCPGroupConditionType_MAC)
|
---|
1697 | , strValue()
|
---|
1698 | {
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | /**
|
---|
1702 | * Default constructor.
|
---|
1703 | */
|
---|
1704 | DHCPConfig::DHCPConfig()
|
---|
1705 | : mapOptions()
|
---|
1706 | , secMinLeaseTime(0)
|
---|
1707 | , secDefaultLeaseTime(0)
|
---|
1708 | , secMaxLeaseTime(0)
|
---|
1709 | {
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | /**
|
---|
1713 | * Default constructor.
|
---|
1714 | */
|
---|
1715 | DHCPGroupConfig::DHCPGroupConfig()
|
---|
1716 | : DHCPConfig()
|
---|
1717 | , strName()
|
---|
1718 | , vecConditions()
|
---|
1719 | {
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | /**
|
---|
1723 | * Default constructor.
|
---|
1724 | */
|
---|
1725 | DHCPIndividualConfig::DHCPIndividualConfig()
|
---|
1726 | : DHCPConfig()
|
---|
1727 | , strMACAddress()
|
---|
1728 | , strVMName()
|
---|
1729 | , uSlot(0)
|
---|
1730 | {
|
---|
1731 | }
|
---|
1732 |
|
---|
1733 | /**
|
---|
1734 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1735 | */
|
---|
1736 | DHCPServer::DHCPServer()
|
---|
1737 | : fEnabled(false)
|
---|
1738 | {
|
---|
1739 | }
|
---|
1740 |
|
---|
1741 | /**
|
---|
1742 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1743 | */
|
---|
1744 | NATNetwork::NATNetwork() :
|
---|
1745 | fEnabled(true),
|
---|
1746 | fIPv6Enabled(false),
|
---|
1747 | fAdvertiseDefaultIPv6Route(false),
|
---|
1748 | fNeedDhcpServer(true),
|
---|
1749 | u32HostLoopback6Offset(0)
|
---|
1750 | {
|
---|
1751 | }
|
---|
1752 |
|
---|
1753 | #ifdef VBOX_WITH_VMNET
|
---|
1754 | /**
|
---|
1755 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1756 | */
|
---|
1757 | HostOnlyNetwork::HostOnlyNetwork() :
|
---|
1758 | strNetworkMask("255.255.255.0"),
|
---|
1759 | strIPLower("192.168.56.1"),
|
---|
1760 | strIPUpper("192.168.56.199"),
|
---|
1761 | fEnabled(true)
|
---|
1762 | {
|
---|
1763 | uuid.create();
|
---|
1764 | }
|
---|
1765 | #endif /* VBOX_WITH_VMNET */
|
---|
1766 |
|
---|
1767 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
1768 | /**
|
---|
1769 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
1770 | */
|
---|
1771 | CloudNetwork::CloudNetwork() :
|
---|
1772 | strProviderShortName("OCI"),
|
---|
1773 | strProfileName("Default"),
|
---|
1774 | fEnabled(true)
|
---|
1775 | {
|
---|
1776 | }
|
---|
1777 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
1778 |
|
---|
1779 |
|
---|
1780 |
|
---|
1781 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1782 | //
|
---|
1783 | // MainConfigFile
|
---|
1784 | //
|
---|
1785 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1786 |
|
---|
1787 | /**
|
---|
1788 | * Reads one \<MachineEntry\> from the main VirtualBox.xml file.
|
---|
1789 | * @param elmMachineRegistry
|
---|
1790 | */
|
---|
1791 | void MainConfigFile::readMachineRegistry(const xml::ElementNode &elmMachineRegistry)
|
---|
1792 | {
|
---|
1793 | // <MachineEntry uuid="{ xxx }" src=" xxx "/>
|
---|
1794 | xml::NodesLoop nl1(elmMachineRegistry);
|
---|
1795 | const xml::ElementNode *pelmChild1;
|
---|
1796 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
1797 | {
|
---|
1798 | if (pelmChild1->nameEquals("MachineEntry"))
|
---|
1799 | {
|
---|
1800 | MachineRegistryEntry mre;
|
---|
1801 | Utf8Str strUUID;
|
---|
1802 | if ( pelmChild1->getAttributeValue("uuid", strUUID)
|
---|
1803 | && pelmChild1->getAttributeValue("src", mre.strSettingsFile) )
|
---|
1804 | {
|
---|
1805 | parseUUID(mre.uuid, strUUID, pelmChild1);
|
---|
1806 | llMachines.push_back(mre);
|
---|
1807 | }
|
---|
1808 | else
|
---|
1809 | throw ConfigFileError(this, pelmChild1, N_("Required MachineEntry/@uuid or @src attribute is missing"));
|
---|
1810 | }
|
---|
1811 | }
|
---|
1812 | }
|
---|
1813 |
|
---|
1814 | /**
|
---|
1815 | * Builds the XML tree for the DHCP servers.
|
---|
1816 | */
|
---|
1817 | void MainConfigFile::buildDHCPServers(xml::ElementNode &elmDHCPServers, DHCPServersList const &ll)
|
---|
1818 | {
|
---|
1819 | for (DHCPServersList::const_iterator it = ll.begin(); it != ll.end(); ++it)
|
---|
1820 | {
|
---|
1821 | const DHCPServer &srv = *it;
|
---|
1822 | xml::ElementNode *pElmThis = elmDHCPServers.createChild("DHCPServer");
|
---|
1823 |
|
---|
1824 | pElmThis->setAttribute("networkName", srv.strNetworkName);
|
---|
1825 | pElmThis->setAttribute("IPAddress", srv.strIPAddress);
|
---|
1826 | DhcpOptConstIterator itOpt = srv.globalConfig.mapOptions.find(DHCPOption_SubnetMask);
|
---|
1827 | if (itOpt != srv.globalConfig.mapOptions.end())
|
---|
1828 | pElmThis->setAttribute("networkMask", itOpt->second.strValue);
|
---|
1829 | pElmThis->setAttribute("lowerIP", srv.strIPLower);
|
---|
1830 | pElmThis->setAttribute("upperIP", srv.strIPUpper);
|
---|
1831 | pElmThis->setAttribute("enabled", (srv.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
1832 |
|
---|
1833 | /* We don't want duplicate validation check of networkMask here*/
|
---|
1834 | if (srv.globalConfig.mapOptions.size() > (itOpt != srv.globalConfig.mapOptions.end() ? 1U : 0U))
|
---|
1835 | {
|
---|
1836 | xml::ElementNode *pElmOptions = pElmThis->createChild("Options");
|
---|
1837 | buildDHCPOptions(*pElmOptions, srv.globalConfig, true);
|
---|
1838 | }
|
---|
1839 |
|
---|
1840 | for (DHCPGroupConfigVec::const_iterator itGroup = srv.vecGroupConfigs.begin();
|
---|
1841 | itGroup != srv.vecGroupConfigs.end(); ++itGroup)
|
---|
1842 | {
|
---|
1843 | DHCPGroupConfig const &rGroupConfig = *itGroup;
|
---|
1844 |
|
---|
1845 | xml::ElementNode *pElmGroup = pElmThis->createChild("Group");
|
---|
1846 | pElmGroup->setAttribute("name", rGroupConfig.strName);
|
---|
1847 | buildDHCPOptions(*pElmGroup, rGroupConfig, false);
|
---|
1848 |
|
---|
1849 | for (DHCPGroupConditionVec::const_iterator itCond = rGroupConfig.vecConditions.begin();
|
---|
1850 | itCond != rGroupConfig.vecConditions.end(); ++itCond)
|
---|
1851 | {
|
---|
1852 | xml::ElementNode *pElmCondition = pElmGroup->createChild("Condition");
|
---|
1853 | pElmCondition->setAttribute("inclusive", itCond->fInclusive);
|
---|
1854 | pElmCondition->setAttribute("type", (int32_t)itCond->enmType);
|
---|
1855 | pElmCondition->setAttribute("value", itCond->strValue);
|
---|
1856 | }
|
---|
1857 | }
|
---|
1858 |
|
---|
1859 | for (DHCPIndividualConfigMap::const_iterator itHost = srv.mapIndividualConfigs.begin();
|
---|
1860 | itHost != srv.mapIndividualConfigs.end(); ++itHost)
|
---|
1861 | {
|
---|
1862 | DHCPIndividualConfig const &rIndividualConfig = itHost->second;
|
---|
1863 |
|
---|
1864 | xml::ElementNode *pElmConfig = pElmThis->createChild("Config");
|
---|
1865 | if (rIndividualConfig.strMACAddress.isNotEmpty())
|
---|
1866 | pElmConfig->setAttribute("MACAddress", rIndividualConfig.strMACAddress);
|
---|
1867 | if (rIndividualConfig.strVMName.isNotEmpty())
|
---|
1868 | pElmConfig->setAttribute("vm-name", rIndividualConfig.strVMName);
|
---|
1869 | if (rIndividualConfig.uSlot != 0 || rIndividualConfig.strVMName.isNotEmpty())
|
---|
1870 | pElmConfig->setAttribute("slot", rIndividualConfig.uSlot);
|
---|
1871 | if (rIndividualConfig.strFixedAddress.isNotEmpty())
|
---|
1872 | pElmConfig->setAttribute("fixedAddress", rIndividualConfig.strFixedAddress);
|
---|
1873 | buildDHCPOptions(*pElmConfig, rIndividualConfig, false);
|
---|
1874 | }
|
---|
1875 | }
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | /**
|
---|
1879 | * Worker for buildDHCPServers() that builds Options or Config element trees.
|
---|
1880 | */
|
---|
1881 | void MainConfigFile::buildDHCPOptions(xml::ElementNode &elmOptions, DHCPConfig const &rConfig, bool fSkipSubnetMask)
|
---|
1882 | {
|
---|
1883 | /* Generic (and optional) attributes on the Options or Config element: */
|
---|
1884 | if (rConfig.secMinLeaseTime > 0)
|
---|
1885 | elmOptions.setAttribute("secMinLeaseTime", rConfig.secMinLeaseTime);
|
---|
1886 | if (rConfig.secDefaultLeaseTime > 0)
|
---|
1887 | elmOptions.setAttribute("secDefaultLeaseTime", rConfig.secDefaultLeaseTime);
|
---|
1888 | if (rConfig.secMaxLeaseTime > 0)
|
---|
1889 | elmOptions.setAttribute("secMaxLeaseTime", rConfig.secMaxLeaseTime);
|
---|
1890 | if (rConfig.strForcedOptions.isNotEmpty())
|
---|
1891 | elmOptions.setAttribute("forcedOptions", rConfig.strForcedOptions);
|
---|
1892 | if (rConfig.strSuppressedOptions.isNotEmpty())
|
---|
1893 | elmOptions.setAttribute("suppressedOptions", rConfig.strSuppressedOptions);
|
---|
1894 |
|
---|
1895 | /* The DHCP options are <Option> child elements: */
|
---|
1896 | for (DhcpOptConstIterator it = rConfig.mapOptions.begin(); it != rConfig.mapOptions.end(); ++it)
|
---|
1897 | if (it->first != DHCPOption_SubnetMask || !fSkipSubnetMask)
|
---|
1898 | {
|
---|
1899 | xml::ElementNode *pElmOption = elmOptions.createChild("Option");
|
---|
1900 | pElmOption->setAttribute("name", it->first);
|
---|
1901 | pElmOption->setAttribute("value", it->second.strValue);
|
---|
1902 | if (it->second.enmEncoding != DHCPOptionEncoding_Normal)
|
---|
1903 | pElmOption->setAttribute("encoding", (int32_t)it->second.enmEncoding);
|
---|
1904 | }
|
---|
1905 | }
|
---|
1906 |
|
---|
1907 | /**
|
---|
1908 | * Reads in the \<DHCPServers\> chunk.
|
---|
1909 | * @param elmDHCPServers
|
---|
1910 | */
|
---|
1911 | void MainConfigFile::readDHCPServers(const xml::ElementNode &elmDHCPServers)
|
---|
1912 | {
|
---|
1913 | xml::NodesLoop nl1(elmDHCPServers);
|
---|
1914 | const xml::ElementNode *pelmServer;
|
---|
1915 | while ((pelmServer = nl1.forAllNodes()))
|
---|
1916 | {
|
---|
1917 | if (pelmServer->nameEquals("DHCPServer"))
|
---|
1918 | {
|
---|
1919 | DHCPServer srv;
|
---|
1920 | if ( pelmServer->getAttributeValue("networkName", srv.strNetworkName)
|
---|
1921 | && pelmServer->getAttributeValue("IPAddress", srv.strIPAddress)
|
---|
1922 | && pelmServer->getAttributeValue("networkMask", srv.globalConfig.mapOptions[DHCPOption_SubnetMask].strValue)
|
---|
1923 | && pelmServer->getAttributeValue("lowerIP", srv.strIPLower)
|
---|
1924 | && pelmServer->getAttributeValue("upperIP", srv.strIPUpper)
|
---|
1925 | && pelmServer->getAttributeValue("enabled", srv.fEnabled) )
|
---|
1926 | {
|
---|
1927 | /* Global options: */
|
---|
1928 | const xml::ElementNode *pElmOptions;
|
---|
1929 | xml::NodesLoop nlOptions(*pelmServer, "Options");
|
---|
1930 | while ((pElmOptions = nlOptions.forAllNodes()) != NULL) /** @todo this loop makes no sense, there can only be one \<Options\> child. */
|
---|
1931 | readDHCPOptions(srv.globalConfig, *pElmOptions, true /*fIgnoreSubnetMask*/);
|
---|
1932 |
|
---|
1933 | /* Group configurations: */
|
---|
1934 | xml::NodesLoop nlGroup(*pelmServer, "Group");
|
---|
1935 | const xml::ElementNode *pElmGroup;
|
---|
1936 | size_t i = 0;
|
---|
1937 | while ((pElmGroup = nlGroup.forAllNodes()) != NULL)
|
---|
1938 | {
|
---|
1939 | srv.vecGroupConfigs.push_back(DHCPGroupConfig());
|
---|
1940 | DHCPGroupConfig &rGroupConfig = srv.vecGroupConfigs.back();
|
---|
1941 |
|
---|
1942 | if (!pElmGroup->getAttributeValue("name", rGroupConfig.strName))
|
---|
1943 | rGroupConfig.strName.printf("Unamed Group #%u", ++i);
|
---|
1944 |
|
---|
1945 | readDHCPOptions(rGroupConfig, *pElmGroup, false /*fIgnoreSubnetMask*/);
|
---|
1946 |
|
---|
1947 | xml::NodesLoop nlCondition(*pElmGroup, "Condition");
|
---|
1948 | const xml::ElementNode *pElmCondition;
|
---|
1949 | while ((pElmCondition = nlCondition.forAllNodes()) != NULL)
|
---|
1950 | {
|
---|
1951 | rGroupConfig.vecConditions.push_back(DHCPGroupCondition());
|
---|
1952 | DHCPGroupCondition &rGroupCondition = rGroupConfig.vecConditions.back();
|
---|
1953 |
|
---|
1954 | if (!pElmCondition->getAttributeValue("inclusive", rGroupCondition.fInclusive))
|
---|
1955 | rGroupCondition.fInclusive = true;
|
---|
1956 |
|
---|
1957 | int32_t iType;
|
---|
1958 | if (!pElmCondition->getAttributeValue("type", iType))
|
---|
1959 | iType = DHCPGroupConditionType_MAC;
|
---|
1960 | rGroupCondition.enmType = (DHCPGroupConditionType_T)iType;
|
---|
1961 |
|
---|
1962 | pElmCondition->getAttributeValue("value", rGroupCondition.strValue);
|
---|
1963 | }
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | /* host specific configuration: */
|
---|
1967 | xml::NodesLoop nlConfig(*pelmServer, "Config");
|
---|
1968 | const xml::ElementNode *pElmConfig;
|
---|
1969 | while ((pElmConfig = nlConfig.forAllNodes()) != NULL)
|
---|
1970 | {
|
---|
1971 | com::Utf8Str strMACAddress;
|
---|
1972 | if (!pElmConfig->getAttributeValue("MACAddress", strMACAddress))
|
---|
1973 | strMACAddress.setNull();
|
---|
1974 |
|
---|
1975 | com::Utf8Str strVMName;
|
---|
1976 | if (!pElmConfig->getAttributeValue("vm-name", strVMName))
|
---|
1977 | strVMName.setNull();
|
---|
1978 |
|
---|
1979 | uint32_t uSlot;
|
---|
1980 | if (!pElmConfig->getAttributeValue("slot", uSlot))
|
---|
1981 | uSlot = 0;
|
---|
1982 |
|
---|
1983 | com::Utf8Str strKey;
|
---|
1984 | if (strVMName.isNotEmpty())
|
---|
1985 | strKey.printf("%s/%u", strVMName.c_str(), uSlot);
|
---|
1986 | else
|
---|
1987 | strKey.printf("%s/%u", strMACAddress.c_str(), uSlot);
|
---|
1988 |
|
---|
1989 | DHCPIndividualConfig &rIndividualConfig = srv.mapIndividualConfigs[strKey];
|
---|
1990 | rIndividualConfig.strMACAddress = strMACAddress;
|
---|
1991 | rIndividualConfig.strVMName = strVMName;
|
---|
1992 | rIndividualConfig.uSlot = uSlot;
|
---|
1993 | pElmConfig->getAttributeValue("fixedAddress", rIndividualConfig.strFixedAddress);
|
---|
1994 |
|
---|
1995 | readDHCPOptions(rIndividualConfig, *pElmConfig, false /*fIgnoreSubnetMask*/);
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 | llDhcpServers.push_back(srv);
|
---|
1999 | }
|
---|
2000 | else
|
---|
2001 | throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
|
---|
2002 | }
|
---|
2003 | }
|
---|
2004 | }
|
---|
2005 |
|
---|
2006 | /**
|
---|
2007 | * Worker for readDHCPServers that reads a configuration, either global,
|
---|
2008 | * group or host (VM+NIC) specific.
|
---|
2009 | */
|
---|
2010 | void MainConfigFile::readDHCPOptions(DHCPConfig &rConfig, const xml::ElementNode &elmConfig, bool fIgnoreSubnetMask)
|
---|
2011 | {
|
---|
2012 | /* Generic (and optional) attributes on the Options or Config element: */
|
---|
2013 | if (!elmConfig.getAttributeValue("secMinLeaseTime", rConfig.secMinLeaseTime))
|
---|
2014 | rConfig.secMinLeaseTime = 0;
|
---|
2015 | if (!elmConfig.getAttributeValue("secDefaultLeaseTime", rConfig.secDefaultLeaseTime))
|
---|
2016 | rConfig.secDefaultLeaseTime = 0;
|
---|
2017 | if (!elmConfig.getAttributeValue("secMaxLeaseTime", rConfig.secMaxLeaseTime))
|
---|
2018 | rConfig.secMaxLeaseTime = 0;
|
---|
2019 | if (!elmConfig.getAttributeValue("forcedOptions", rConfig.strForcedOptions))
|
---|
2020 | rConfig.strSuppressedOptions.setNull();
|
---|
2021 | if (!elmConfig.getAttributeValue("suppressedOptions", rConfig.strSuppressedOptions))
|
---|
2022 | rConfig.strSuppressedOptions.setNull();
|
---|
2023 |
|
---|
2024 | /* The DHCP options are <Option> child elements: */
|
---|
2025 | xml::NodesLoop nl2(elmConfig, "Option");
|
---|
2026 | const xml::ElementNode *pElmOption;
|
---|
2027 | while ((pElmOption = nl2.forAllNodes()) != NULL)
|
---|
2028 | {
|
---|
2029 | int32_t iOptName;
|
---|
2030 | if (!pElmOption->getAttributeValue("name", iOptName))
|
---|
2031 | continue;
|
---|
2032 | DHCPOption_T OptName = (DHCPOption_T)iOptName;
|
---|
2033 | if (OptName == DHCPOption_SubnetMask && fIgnoreSubnetMask)
|
---|
2034 | continue;
|
---|
2035 |
|
---|
2036 | com::Utf8Str strValue;
|
---|
2037 | pElmOption->getAttributeValue("value", strValue);
|
---|
2038 |
|
---|
2039 | int32_t iOptEnc;
|
---|
2040 | if (!pElmOption->getAttributeValue("encoding", iOptEnc))
|
---|
2041 | iOptEnc = DHCPOptionEncoding_Normal;
|
---|
2042 |
|
---|
2043 | rConfig.mapOptions[OptName] = DhcpOptValue(strValue, (DHCPOptionEncoding_T)iOptEnc);
|
---|
2044 | } /* end of forall("Option") */
|
---|
2045 |
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | /**
|
---|
2049 | * Reads in the \<NATNetworks\> chunk.
|
---|
2050 | * @param elmNATNetworks
|
---|
2051 | */
|
---|
2052 | void MainConfigFile::readNATNetworks(const xml::ElementNode &elmNATNetworks)
|
---|
2053 | {
|
---|
2054 | xml::NodesLoop nl1(elmNATNetworks);
|
---|
2055 | const xml::ElementNode *pelmNet;
|
---|
2056 | while ((pelmNet = nl1.forAllNodes()))
|
---|
2057 | {
|
---|
2058 | if (pelmNet->nameEquals("NATNetwork"))
|
---|
2059 | {
|
---|
2060 | NATNetwork net;
|
---|
2061 | if ( pelmNet->getAttributeValue("networkName", net.strNetworkName)
|
---|
2062 | && pelmNet->getAttributeValue("enabled", net.fEnabled)
|
---|
2063 | && pelmNet->getAttributeValue("network", net.strIPv4NetworkCidr)
|
---|
2064 | && pelmNet->getAttributeValue("ipv6", net.fIPv6Enabled)
|
---|
2065 | && pelmNet->getAttributeValue("ipv6prefix", net.strIPv6Prefix)
|
---|
2066 | && pelmNet->getAttributeValue("advertiseDefaultIPv6Route", net.fAdvertiseDefaultIPv6Route)
|
---|
2067 | && pelmNet->getAttributeValue("needDhcp", net.fNeedDhcpServer) )
|
---|
2068 | {
|
---|
2069 | pelmNet->getAttributeValue("loopback6", net.u32HostLoopback6Offset);
|
---|
2070 | const xml::ElementNode *pelmMappings;
|
---|
2071 | if ((pelmMappings = pelmNet->findChildElement("Mappings")))
|
---|
2072 | readNATLoopbacks(*pelmMappings, net.llHostLoopbackOffsetList);
|
---|
2073 |
|
---|
2074 | const xml::ElementNode *pelmPortForwardRules4;
|
---|
2075 | if ((pelmPortForwardRules4 = pelmNet->findChildElement("PortForwarding4")))
|
---|
2076 | readNATForwardRulesMap(*pelmPortForwardRules4,
|
---|
2077 | net.mapPortForwardRules4);
|
---|
2078 |
|
---|
2079 | const xml::ElementNode *pelmPortForwardRules6;
|
---|
2080 | if ((pelmPortForwardRules6 = pelmNet->findChildElement("PortForwarding6")))
|
---|
2081 | readNATForwardRulesMap(*pelmPortForwardRules6,
|
---|
2082 | net.mapPortForwardRules6);
|
---|
2083 |
|
---|
2084 | llNATNetworks.push_back(net);
|
---|
2085 | }
|
---|
2086 | else
|
---|
2087 | throw ConfigFileError(this, pelmNet, N_("Required NATNetwork/@networkName, @gateway, @network,@advertiseDefaultIpv6Route , @needDhcp or @enabled attribute is missing"));
|
---|
2088 | }
|
---|
2089 | }
|
---|
2090 | }
|
---|
2091 |
|
---|
2092 | #ifdef VBOX_WITH_VMNET
|
---|
2093 | /**
|
---|
2094 | * Reads in the \<HostOnlyNetworks\> chunk.
|
---|
2095 | * @param elmHostOnlyNetworks
|
---|
2096 | */
|
---|
2097 | void MainConfigFile::readHostOnlyNetworks(const xml::ElementNode &elmHostOnlyNetworks)
|
---|
2098 | {
|
---|
2099 | xml::NodesLoop nl1(elmHostOnlyNetworks);
|
---|
2100 | const xml::ElementNode *pelmNet;
|
---|
2101 | while ((pelmNet = nl1.forAllNodes()))
|
---|
2102 | {
|
---|
2103 | if (pelmNet->nameEquals("HostOnlyNetwork"))
|
---|
2104 | {
|
---|
2105 | HostOnlyNetwork net;
|
---|
2106 | Utf8Str strID;
|
---|
2107 | if ( pelmNet->getAttributeValue("name", net.strNetworkName)
|
---|
2108 | && pelmNet->getAttributeValue("mask", net.strNetworkMask)
|
---|
2109 | && pelmNet->getAttributeValue("ipLower", net.strIPLower)
|
---|
2110 | && pelmNet->getAttributeValue("ipUpper", net.strIPUpper)
|
---|
2111 | && pelmNet->getAttributeValue("id", strID)
|
---|
2112 | && pelmNet->getAttributeValue("enabled", net.fEnabled) )
|
---|
2113 | {
|
---|
2114 | parseUUID(net.uuid, strID, pelmNet);
|
---|
2115 | llHostOnlyNetworks.push_back(net);
|
---|
2116 | }
|
---|
2117 | else
|
---|
2118 | throw ConfigFileError(this, pelmNet, N_("Required HostOnlyNetwork/@name, @mask, @ipLower, @ipUpper, @id or @enabled attribute is missing"));
|
---|
2119 | }
|
---|
2120 | }
|
---|
2121 | }
|
---|
2122 | #endif /* VBOX_WITH_VMNET */
|
---|
2123 |
|
---|
2124 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2125 | /**
|
---|
2126 | * Reads in the \<CloudNetworks\> chunk.
|
---|
2127 | * @param elmCloudNetworks
|
---|
2128 | */
|
---|
2129 | void MainConfigFile::readCloudNetworks(const xml::ElementNode &elmCloudNetworks)
|
---|
2130 | {
|
---|
2131 | xml::NodesLoop nl1(elmCloudNetworks);
|
---|
2132 | const xml::ElementNode *pelmNet;
|
---|
2133 | while ((pelmNet = nl1.forAllNodes()))
|
---|
2134 | {
|
---|
2135 | if (pelmNet->nameEquals("CloudNetwork"))
|
---|
2136 | {
|
---|
2137 | CloudNetwork net;
|
---|
2138 | if ( pelmNet->getAttributeValue("name", net.strNetworkName)
|
---|
2139 | && pelmNet->getAttributeValue("provider", net.strProviderShortName)
|
---|
2140 | && pelmNet->getAttributeValue("profile", net.strProfileName)
|
---|
2141 | && pelmNet->getAttributeValue("id", net.strNetworkId)
|
---|
2142 | && pelmNet->getAttributeValue("enabled", net.fEnabled) )
|
---|
2143 | {
|
---|
2144 | llCloudNetworks.push_back(net);
|
---|
2145 | }
|
---|
2146 | else
|
---|
2147 | throw ConfigFileError(this, pelmNet, N_("Required CloudNetwork/@name, @provider, @profile, @id or @enabled attribute is missing"));
|
---|
2148 | }
|
---|
2149 | }
|
---|
2150 | }
|
---|
2151 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2152 |
|
---|
2153 | /**
|
---|
2154 | * Creates \<USBDeviceSource\> nodes under the given parent element according to
|
---|
2155 | * the contents of the given USBDeviceSourcesList.
|
---|
2156 | *
|
---|
2157 | * @param elmParent
|
---|
2158 | * @param ll
|
---|
2159 | */
|
---|
2160 | void MainConfigFile::buildUSBDeviceSources(xml::ElementNode &elmParent,
|
---|
2161 | const USBDeviceSourcesList &ll)
|
---|
2162 | {
|
---|
2163 | for (USBDeviceSourcesList::const_iterator it = ll.begin();
|
---|
2164 | it != ll.end();
|
---|
2165 | ++it)
|
---|
2166 | {
|
---|
2167 | const USBDeviceSource &src = *it;
|
---|
2168 | xml::ElementNode *pelmSource = elmParent.createChild("USBDeviceSource");
|
---|
2169 | pelmSource->setAttribute("name", src.strName);
|
---|
2170 | pelmSource->setAttribute("backend", src.strBackend);
|
---|
2171 | pelmSource->setAttribute("address", src.strAddress);
|
---|
2172 |
|
---|
2173 | /* Write the properties. */
|
---|
2174 | for (StringsMap::const_iterator itProp = src.properties.begin();
|
---|
2175 | itProp != src.properties.end();
|
---|
2176 | ++itProp)
|
---|
2177 | {
|
---|
2178 | xml::ElementNode *pelmProp = pelmSource->createChild("Property");
|
---|
2179 | pelmProp->setAttribute("name", itProp->first);
|
---|
2180 | pelmProp->setAttribute("value", itProp->second);
|
---|
2181 | }
|
---|
2182 | }
|
---|
2183 | }
|
---|
2184 |
|
---|
2185 | /**
|
---|
2186 | * Reads \<USBDeviceFilter\> entries from under the given elmDeviceFilters node and
|
---|
2187 | * stores them in the given linklist. This is in ConfigFileBase because it's used
|
---|
2188 | * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
|
---|
2189 | * filters).
|
---|
2190 | * @param elmDeviceSources
|
---|
2191 | * @param ll
|
---|
2192 | */
|
---|
2193 | void MainConfigFile::readUSBDeviceSources(const xml::ElementNode &elmDeviceSources,
|
---|
2194 | USBDeviceSourcesList &ll)
|
---|
2195 | {
|
---|
2196 | xml::NodesLoop nl1(elmDeviceSources, "USBDeviceSource");
|
---|
2197 | const xml::ElementNode *pelmChild;
|
---|
2198 | while ((pelmChild = nl1.forAllNodes()))
|
---|
2199 | {
|
---|
2200 | USBDeviceSource src;
|
---|
2201 |
|
---|
2202 | if ( pelmChild->getAttributeValue("name", src.strName)
|
---|
2203 | && pelmChild->getAttributeValue("backend", src.strBackend)
|
---|
2204 | && pelmChild->getAttributeValue("address", src.strAddress))
|
---|
2205 | {
|
---|
2206 | // handle medium properties
|
---|
2207 | xml::NodesLoop nl2(*pelmChild, "Property");
|
---|
2208 | const xml::ElementNode *pelmSrcChild;
|
---|
2209 | while ((pelmSrcChild = nl2.forAllNodes()))
|
---|
2210 | {
|
---|
2211 | Utf8Str strPropName, strPropValue;
|
---|
2212 | if ( pelmSrcChild->getAttributeValue("name", strPropName)
|
---|
2213 | && pelmSrcChild->getAttributeValue("value", strPropValue) )
|
---|
2214 | src.properties[strPropName] = strPropValue;
|
---|
2215 | else
|
---|
2216 | throw ConfigFileError(this, pelmSrcChild, N_("Required USBDeviceSource/Property/@name or @value attribute is missing"));
|
---|
2217 | }
|
---|
2218 |
|
---|
2219 | ll.push_back(src);
|
---|
2220 | }
|
---|
2221 | }
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | /**
|
---|
2225 | * Converts old style Proxy settings from ExtraData/UI section.
|
---|
2226 | *
|
---|
2227 | * Saves proxy settings directly to systemProperties structure.
|
---|
2228 | *
|
---|
2229 | * @returns true if conversion was successfull, false if not.
|
---|
2230 | * @param strUIProxySettings The GUI settings string to convert.
|
---|
2231 | */
|
---|
2232 | bool MainConfigFile::convertGuiProxySettings(const com::Utf8Str &strUIProxySettings)
|
---|
2233 | {
|
---|
2234 | /*
|
---|
2235 | * Possible variants:
|
---|
2236 | * - "ProxyAuto,proxyserver.url,1080,authDisabled,,"
|
---|
2237 | * - "ProxyDisabled,proxyserver.url,1080,authDisabled,,"
|
---|
2238 | * - "ProxyEnabled,proxyserver.url,1080,authDisabled,,"
|
---|
2239 | *
|
---|
2240 | * Note! We only need to bother with the first three fields as the last
|
---|
2241 | * three was never really used or ever actually passed to the HTTP
|
---|
2242 | * client code.
|
---|
2243 | */
|
---|
2244 | /* First field: The proxy mode. */
|
---|
2245 | const char *psz = RTStrStripL(strUIProxySettings.c_str());
|
---|
2246 | static const struct { const char *psz; size_t cch; ProxyMode_T enmMode; } s_aModes[] =
|
---|
2247 | {
|
---|
2248 | { RT_STR_TUPLE("ProxyAuto"), ProxyMode_System },
|
---|
2249 | { RT_STR_TUPLE("ProxyDisabled"), ProxyMode_NoProxy },
|
---|
2250 | { RT_STR_TUPLE("ProxyEnabled"), ProxyMode_Manual },
|
---|
2251 | };
|
---|
2252 | for (size_t i = 0; i < RT_ELEMENTS(s_aModes); i++)
|
---|
2253 | if (RTStrNICmpAscii(psz, s_aModes[i].psz, s_aModes[i].cch) == 0)
|
---|
2254 | {
|
---|
2255 | systemProperties.uProxyMode = s_aModes[i].enmMode;
|
---|
2256 | psz = RTStrStripL(psz + s_aModes[i].cch);
|
---|
2257 | if (*psz == ',')
|
---|
2258 | {
|
---|
2259 | /* Second field: The proxy host, possibly fully fledged proxy URL. */
|
---|
2260 | psz = RTStrStripL(psz + 1);
|
---|
2261 | if (*psz != '\0' && *psz != ',')
|
---|
2262 | {
|
---|
2263 | const char *pszEnd = strchr(psz, ',');
|
---|
2264 | size_t cchHost = pszEnd ? (size_t)(pszEnd - psz) : strlen(psz);
|
---|
2265 | while (cchHost > 0 && RT_C_IS_SPACE(psz[cchHost - 1]))
|
---|
2266 | cchHost--;
|
---|
2267 | systemProperties.strProxyUrl.assign(psz, cchHost);
|
---|
2268 | if (systemProperties.strProxyUrl.find("://") == RTCString::npos)
|
---|
2269 | systemProperties.strProxyUrl.replace(0, 0, "http://");
|
---|
2270 |
|
---|
2271 | /* Third field: The proxy port. Defaulted to 1080 for all proxies.
|
---|
2272 | The new settings has type specific default ports. */
|
---|
2273 | uint16_t uPort = 1080;
|
---|
2274 | if (pszEnd)
|
---|
2275 | {
|
---|
2276 | int rc = RTStrToUInt16Ex(RTStrStripL(pszEnd + 1), NULL, 10, &uPort);
|
---|
2277 | if (RT_FAILURE(rc))
|
---|
2278 | uPort = 1080;
|
---|
2279 | }
|
---|
2280 | RTURIPARSED Parsed;
|
---|
2281 | int rc = RTUriParse(systemProperties.strProxyUrl.c_str(), &Parsed);
|
---|
2282 | if (RT_SUCCESS(rc))
|
---|
2283 | {
|
---|
2284 | if (Parsed.uAuthorityPort == UINT32_MAX)
|
---|
2285 | systemProperties.strProxyUrl.appendPrintf(systemProperties.strProxyUrl.endsWith(":")
|
---|
2286 | ? "%u" : ":%u", uPort);
|
---|
2287 | }
|
---|
2288 | else
|
---|
2289 | {
|
---|
2290 | LogRelFunc(("Dropping invalid proxy URL for %u: %s\n",
|
---|
2291 | systemProperties.uProxyMode, systemProperties.strProxyUrl.c_str()));
|
---|
2292 | systemProperties.strProxyUrl.setNull();
|
---|
2293 | }
|
---|
2294 | }
|
---|
2295 | /* else: don't bother with the rest if we haven't got a host. */
|
---|
2296 | }
|
---|
2297 | if ( systemProperties.strProxyUrl.isEmpty()
|
---|
2298 | && systemProperties.uProxyMode == ProxyMode_Manual)
|
---|
2299 | {
|
---|
2300 | systemProperties.uProxyMode = ProxyMode_System;
|
---|
2301 | return false;
|
---|
2302 | }
|
---|
2303 | return true;
|
---|
2304 | }
|
---|
2305 | LogRelFunc(("Unknown proxy type: %s\n", psz));
|
---|
2306 | return false;
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | /**
|
---|
2310 | * Constructor.
|
---|
2311 | *
|
---|
2312 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
2313 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
2314 | * are initialized with default values.
|
---|
2315 | *
|
---|
2316 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
2317 | * the caller should catch; if this constructor does not throw, then the member
|
---|
2318 | * variables contain meaningful values (either from the file or defaults).
|
---|
2319 | *
|
---|
2320 | * @param pstrFilename
|
---|
2321 | */
|
---|
2322 | MainConfigFile::MainConfigFile(const Utf8Str *pstrFilename)
|
---|
2323 | : ConfigFileBase(pstrFilename)
|
---|
2324 | {
|
---|
2325 | if (pstrFilename)
|
---|
2326 | {
|
---|
2327 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
2328 | // we need only analyze what is in there
|
---|
2329 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
2330 | const xml::ElementNode *pelmRootChild;
|
---|
2331 | bool fCopyProxySettingsFromExtraData = false;
|
---|
2332 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
2333 | {
|
---|
2334 | if (pelmRootChild->nameEquals("Global"))
|
---|
2335 | {
|
---|
2336 | xml::NodesLoop nlGlobalChildren(*pelmRootChild);
|
---|
2337 | const xml::ElementNode *pelmGlobalChild;
|
---|
2338 | while ((pelmGlobalChild = nlGlobalChildren.forAllNodes()))
|
---|
2339 | {
|
---|
2340 | if (pelmGlobalChild->nameEquals("SystemProperties"))
|
---|
2341 | {
|
---|
2342 | pelmGlobalChild->getAttributeValue("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
2343 | pelmGlobalChild->getAttributeValue("LoggingLevel", systemProperties.strLoggingLevel);
|
---|
2344 | pelmGlobalChild->getAttributeValue("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
2345 | if (!pelmGlobalChild->getAttributeValue("VRDEAuthLibrary", systemProperties.strVRDEAuthLibrary))
|
---|
2346 | // pre-1.11 used @remoteDisplayAuthLibrary instead
|
---|
2347 | pelmGlobalChild->getAttributeValue("remoteDisplayAuthLibrary", systemProperties.strVRDEAuthLibrary);
|
---|
2348 | pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
2349 | pelmGlobalChild->getAttributeValue("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
|
---|
2350 | pelmGlobalChild->getAttributeValue("defaultCryptoExtPack", systemProperties.strDefaultCryptoExtPack);
|
---|
2351 | pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.uLogHistoryCount);
|
---|
2352 | pelmGlobalChild->getAttributeValue("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
|
---|
2353 | pelmGlobalChild->getAttributeValue("defaultFrontend", systemProperties.strDefaultFrontend);
|
---|
2354 | pelmGlobalChild->getAttributeValue("exclusiveHwVirt", systemProperties.fExclusiveHwVirt);
|
---|
2355 | if (!pelmGlobalChild->getAttributeValue("proxyMode", systemProperties.uProxyMode))
|
---|
2356 | fCopyProxySettingsFromExtraData = true;
|
---|
2357 | pelmGlobalChild->getAttributeValue("proxyUrl", systemProperties.strProxyUrl);
|
---|
2358 | pelmGlobalChild->getAttributeValue("LanguageId", systemProperties.strLanguageId);
|
---|
2359 | }
|
---|
2360 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
2361 | else if (pelmGlobalChild->nameEquals("Updates"))
|
---|
2362 | {
|
---|
2363 | /* We keep the updates configuration as part of the host for now, as the API exposes the IHost::updateHost attribute,
|
---|
2364 | * but use an own "Updates" branch in the XML for better structurizing stuff in the future. */
|
---|
2365 | UpdateAgent &updateHost = host.updateHost;
|
---|
2366 |
|
---|
2367 | xml::NodesLoop nlLevel4(*pelmGlobalChild);
|
---|
2368 | const xml::ElementNode *pelmLevel4Child;
|
---|
2369 | while ((pelmLevel4Child = nlLevel4.forAllNodes()))
|
---|
2370 | {
|
---|
2371 | if (pelmLevel4Child->nameEquals("Host"))
|
---|
2372 | {
|
---|
2373 | pelmLevel4Child->getAttributeValue("enabled", updateHost.fEnabled);
|
---|
2374 | pelmLevel4Child->getAttributeValue("channel", (uint32_t&)updateHost.enmChannel);
|
---|
2375 | pelmLevel4Child->getAttributeValue("checkFreqSec", updateHost.uCheckFreqSeconds);
|
---|
2376 | pelmLevel4Child->getAttributeValue("repoUrl", updateHost.strRepoUrl);
|
---|
2377 | pelmLevel4Child->getAttributeValue("lastCheckDate", updateHost.strLastCheckDate);
|
---|
2378 | pelmLevel4Child->getAttributeValue("checkCount", updateHost.uCheckCount);
|
---|
2379 | }
|
---|
2380 | /** @todo Add update settings for ExtPack and Guest Additions here later. See @bugref{7983}. */
|
---|
2381 | }
|
---|
2382 |
|
---|
2383 | /* Global enabled switch for updates. Currently bound to host updates, as this is the only update we have so far. */
|
---|
2384 | pelmGlobalChild->getAttributeValue("enabled", updateHost.fEnabled);
|
---|
2385 | }
|
---|
2386 | #endif
|
---|
2387 | else if (pelmGlobalChild->nameEquals("ExtraData"))
|
---|
2388 | readExtraData(*pelmGlobalChild, mapExtraDataItems);
|
---|
2389 | else if (pelmGlobalChild->nameEquals("MachineRegistry"))
|
---|
2390 | readMachineRegistry(*pelmGlobalChild);
|
---|
2391 | else if ( (pelmGlobalChild->nameEquals("MediaRegistry"))
|
---|
2392 | || ( (m->sv < SettingsVersion_v1_4)
|
---|
2393 | && (pelmGlobalChild->nameEquals("DiskRegistry"))
|
---|
2394 | )
|
---|
2395 | )
|
---|
2396 | readMediaRegistry(*pelmGlobalChild, mediaRegistry);
|
---|
2397 | else if (pelmGlobalChild->nameEquals("NetserviceRegistry"))
|
---|
2398 | {
|
---|
2399 | xml::NodesLoop nlLevel4(*pelmGlobalChild);
|
---|
2400 | const xml::ElementNode *pelmLevel4Child;
|
---|
2401 | while ((pelmLevel4Child = nlLevel4.forAllNodes()))
|
---|
2402 | {
|
---|
2403 | if (pelmLevel4Child->nameEquals("DHCPServers"))
|
---|
2404 | readDHCPServers(*pelmLevel4Child);
|
---|
2405 | if (pelmLevel4Child->nameEquals("NATNetworks"))
|
---|
2406 | readNATNetworks(*pelmLevel4Child);
|
---|
2407 | #ifdef VBOX_WITH_VMNET
|
---|
2408 | if (pelmLevel4Child->nameEquals("HostOnlyNetworks"))
|
---|
2409 | readHostOnlyNetworks(*pelmLevel4Child);
|
---|
2410 | #endif /* VBOX_WITH_VMNET */
|
---|
2411 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2412 | if (pelmLevel4Child->nameEquals("CloudNetworks"))
|
---|
2413 | readCloudNetworks(*pelmLevel4Child);
|
---|
2414 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2415 | }
|
---|
2416 | }
|
---|
2417 | else if (pelmGlobalChild->nameEquals("USBDeviceFilters"))
|
---|
2418 | readUSBDeviceFilters(*pelmGlobalChild, host.llUSBDeviceFilters);
|
---|
2419 | else if (pelmGlobalChild->nameEquals("USBDeviceSources"))
|
---|
2420 | readUSBDeviceSources(*pelmGlobalChild, host.llUSBDeviceSources);
|
---|
2421 | }
|
---|
2422 | } // end if (pelmRootChild->nameEquals("Global"))
|
---|
2423 | }
|
---|
2424 |
|
---|
2425 | if (fCopyProxySettingsFromExtraData)
|
---|
2426 | for (StringsMap::const_iterator it = mapExtraDataItems.begin(); it != mapExtraDataItems.end(); ++it)
|
---|
2427 | if (it->first.equals("GUI/ProxySettings"))
|
---|
2428 | {
|
---|
2429 | convertGuiProxySettings(it->second);
|
---|
2430 | break;
|
---|
2431 | }
|
---|
2432 |
|
---|
2433 | clearDocument();
|
---|
2434 | }
|
---|
2435 |
|
---|
2436 | // DHCP servers were introduced with settings version 1.7; if we're loading
|
---|
2437 | // from an older version OR this is a fresh install, then add one DHCP server
|
---|
2438 | // with default settings
|
---|
2439 | if ( (!llDhcpServers.size())
|
---|
2440 | && ( (!pstrFilename) // empty VirtualBox.xml file
|
---|
2441 | || (m->sv < SettingsVersion_v1_7) // upgrading from before 1.7
|
---|
2442 | )
|
---|
2443 | )
|
---|
2444 | {
|
---|
2445 | DHCPServer srv;
|
---|
2446 | #ifdef RT_OS_WINDOWS
|
---|
2447 | srv.strNetworkName = "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter";
|
---|
2448 | #else
|
---|
2449 | srv.strNetworkName = "HostInterfaceNetworking-vboxnet0";
|
---|
2450 | #endif
|
---|
2451 | srv.strIPAddress = "192.168.56.100";
|
---|
2452 | srv.globalConfig.mapOptions[DHCPOption_SubnetMask] = DhcpOptValue("255.255.255.0");
|
---|
2453 | srv.strIPLower = "192.168.56.101";
|
---|
2454 | srv.strIPUpper = "192.168.56.254";
|
---|
2455 | srv.fEnabled = true;
|
---|
2456 | llDhcpServers.push_back(srv);
|
---|
2457 | }
|
---|
2458 | }
|
---|
2459 |
|
---|
2460 | void MainConfigFile::bumpSettingsVersionIfNeeded()
|
---|
2461 | {
|
---|
2462 | #ifdef VBOX_WITH_VMNET
|
---|
2463 | if (m->sv < SettingsVersion_v1_19)
|
---|
2464 | {
|
---|
2465 | // VirtualBox 7.0 adds support for host-only networks.
|
---|
2466 | if (!llHostOnlyNetworks.empty())
|
---|
2467 | m->sv = SettingsVersion_v1_19;
|
---|
2468 | }
|
---|
2469 | #endif /* VBOX_WITH_VMNET */
|
---|
2470 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2471 | if (m->sv < SettingsVersion_v1_18)
|
---|
2472 | {
|
---|
2473 | // VirtualBox 6.1 adds support for cloud networks.
|
---|
2474 | if (!llCloudNetworks.empty())
|
---|
2475 | m->sv = SettingsVersion_v1_18;
|
---|
2476 | }
|
---|
2477 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2478 |
|
---|
2479 | if (m->sv < SettingsVersion_v1_16)
|
---|
2480 | {
|
---|
2481 | // VirtualBox 5.1 add support for additional USB device sources.
|
---|
2482 | if (!host.llUSBDeviceSources.empty())
|
---|
2483 | m->sv = SettingsVersion_v1_16;
|
---|
2484 | }
|
---|
2485 |
|
---|
2486 | if (m->sv < SettingsVersion_v1_14)
|
---|
2487 | {
|
---|
2488 | // VirtualBox 4.3 adds NAT networks.
|
---|
2489 | if ( !llNATNetworks.empty())
|
---|
2490 | m->sv = SettingsVersion_v1_14;
|
---|
2491 | }
|
---|
2492 | }
|
---|
2493 |
|
---|
2494 |
|
---|
2495 | /**
|
---|
2496 | * Called from the IVirtualBox interface to write out VirtualBox.xml. This
|
---|
2497 | * builds an XML DOM tree and writes it out to disk.
|
---|
2498 | */
|
---|
2499 | void MainConfigFile::write(const com::Utf8Str strFilename)
|
---|
2500 | {
|
---|
2501 | bumpSettingsVersionIfNeeded();
|
---|
2502 |
|
---|
2503 | m->strFilename = strFilename;
|
---|
2504 | specialBackupIfFirstBump();
|
---|
2505 | createStubDocument();
|
---|
2506 |
|
---|
2507 | xml::ElementNode *pelmGlobal = m->pelmRoot->createChild("Global");
|
---|
2508 |
|
---|
2509 | buildExtraData(*pelmGlobal, mapExtraDataItems);
|
---|
2510 |
|
---|
2511 | xml::ElementNode *pelmMachineRegistry = pelmGlobal->createChild("MachineRegistry");
|
---|
2512 | for (MachinesRegistry::const_iterator it = llMachines.begin();
|
---|
2513 | it != llMachines.end();
|
---|
2514 | ++it)
|
---|
2515 | {
|
---|
2516 | // <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"/>
|
---|
2517 | const MachineRegistryEntry &mre = *it;
|
---|
2518 | xml::ElementNode *pelmMachineEntry = pelmMachineRegistry->createChild("MachineEntry");
|
---|
2519 | pelmMachineEntry->setAttribute("uuid", mre.uuid.toStringCurly());
|
---|
2520 | pelmMachineEntry->setAttribute("src", mre.strSettingsFile);
|
---|
2521 | }
|
---|
2522 |
|
---|
2523 | buildMediaRegistry(*pelmGlobal, mediaRegistry);
|
---|
2524 |
|
---|
2525 | xml::ElementNode *pelmNetServiceRegistry = pelmGlobal->createChild("NetserviceRegistry"); /** @todo r=bird: wrong capitalization of NetServiceRegistry. sigh. */
|
---|
2526 | buildDHCPServers(*pelmNetServiceRegistry->createChild("DHCPServers"), llDhcpServers);
|
---|
2527 |
|
---|
2528 | xml::ElementNode *pelmNATNetworks;
|
---|
2529 | /* don't create entry if no NAT networks are registered. */
|
---|
2530 | if (!llNATNetworks.empty())
|
---|
2531 | {
|
---|
2532 | pelmNATNetworks = pelmNetServiceRegistry->createChild("NATNetworks");
|
---|
2533 | for (NATNetworksList::const_iterator it = llNATNetworks.begin();
|
---|
2534 | it != llNATNetworks.end();
|
---|
2535 | ++it)
|
---|
2536 | {
|
---|
2537 | const NATNetwork &n = *it;
|
---|
2538 | xml::ElementNode *pelmThis = pelmNATNetworks->createChild("NATNetwork");
|
---|
2539 | pelmThis->setAttribute("networkName", n.strNetworkName);
|
---|
2540 | pelmThis->setAttribute("network", n.strIPv4NetworkCidr);
|
---|
2541 | pelmThis->setAttribute("ipv6", n.fIPv6Enabled ? 1 : 0);
|
---|
2542 | pelmThis->setAttribute("ipv6prefix", n.strIPv6Prefix);
|
---|
2543 | pelmThis->setAttribute("advertiseDefaultIPv6Route", (n.fAdvertiseDefaultIPv6Route)? 1 : 0);
|
---|
2544 | pelmThis->setAttribute("needDhcp", (n.fNeedDhcpServer) ? 1 : 0);
|
---|
2545 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
2546 | if (n.mapPortForwardRules4.size())
|
---|
2547 | {
|
---|
2548 | xml::ElementNode *pelmPf4 = pelmThis->createChild("PortForwarding4");
|
---|
2549 | buildNATForwardRulesMap(*pelmPf4, n.mapPortForwardRules4);
|
---|
2550 | }
|
---|
2551 | if (n.mapPortForwardRules6.size())
|
---|
2552 | {
|
---|
2553 | xml::ElementNode *pelmPf6 = pelmThis->createChild("PortForwarding6");
|
---|
2554 | buildNATForwardRulesMap(*pelmPf6, n.mapPortForwardRules6);
|
---|
2555 | }
|
---|
2556 |
|
---|
2557 | if (n.llHostLoopbackOffsetList.size())
|
---|
2558 | {
|
---|
2559 | xml::ElementNode *pelmMappings = pelmThis->createChild("Mappings");
|
---|
2560 | buildNATLoopbacks(*pelmMappings, n.llHostLoopbackOffsetList);
|
---|
2561 |
|
---|
2562 | }
|
---|
2563 | }
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 | #ifdef VBOX_WITH_VMNET
|
---|
2567 | xml::ElementNode *pelmHostOnlyNetworks;
|
---|
2568 | /* don't create entry if no HostOnly networks are registered. */
|
---|
2569 | if (!llHostOnlyNetworks.empty())
|
---|
2570 | {
|
---|
2571 | pelmHostOnlyNetworks = pelmNetServiceRegistry->createChild("HostOnlyNetworks");
|
---|
2572 | for (HostOnlyNetworksList::const_iterator it = llHostOnlyNetworks.begin();
|
---|
2573 | it != llHostOnlyNetworks.end();
|
---|
2574 | ++it)
|
---|
2575 | {
|
---|
2576 | const HostOnlyNetwork &n = *it;
|
---|
2577 | xml::ElementNode *pelmThis = pelmHostOnlyNetworks->createChild("HostOnlyNetwork");
|
---|
2578 | pelmThis->setAttribute("name", n.strNetworkName);
|
---|
2579 | pelmThis->setAttribute("mask", n.strNetworkMask);
|
---|
2580 | pelmThis->setAttribute("ipLower", n.strIPLower);
|
---|
2581 | pelmThis->setAttribute("ipUpper", n.strIPUpper);
|
---|
2582 | pelmThis->setAttribute("id", n.uuid.toStringCurly());
|
---|
2583 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
2584 | }
|
---|
2585 | }
|
---|
2586 | #endif /* VBOX_WITH_VMNET */
|
---|
2587 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
2588 | xml::ElementNode *pelmCloudNetworks;
|
---|
2589 | /* don't create entry if no cloud networks are registered. */
|
---|
2590 | if (!llCloudNetworks.empty())
|
---|
2591 | {
|
---|
2592 | pelmCloudNetworks = pelmNetServiceRegistry->createChild("CloudNetworks");
|
---|
2593 | for (CloudNetworksList::const_iterator it = llCloudNetworks.begin();
|
---|
2594 | it != llCloudNetworks.end();
|
---|
2595 | ++it)
|
---|
2596 | {
|
---|
2597 | const CloudNetwork &n = *it;
|
---|
2598 | xml::ElementNode *pelmThis = pelmCloudNetworks->createChild("CloudNetwork");
|
---|
2599 | pelmThis->setAttribute("name", n.strNetworkName);
|
---|
2600 | pelmThis->setAttribute("provider", n.strProviderShortName);
|
---|
2601 | pelmThis->setAttribute("profile", n.strProfileName);
|
---|
2602 | pelmThis->setAttribute("id", n.strNetworkId);
|
---|
2603 | pelmThis->setAttribute("enabled", (n.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
2604 | }
|
---|
2605 | }
|
---|
2606 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
2607 |
|
---|
2608 | #ifdef VBOX_WITH_UPDATE_AGENT
|
---|
2609 | /* We keep the updates configuration as part of the host for now, as the API exposes the IHost::updateHost attribute,
|
---|
2610 | * but use an own "Updates" branch in the XML for better structurizing stuff in the future. */
|
---|
2611 | UpdateAgent &updateHost = host.updateHost;
|
---|
2612 |
|
---|
2613 | xml::ElementNode *pelmUpdates = pelmGlobal->createChild("Updates");
|
---|
2614 | /* Global enabled switch for updates. Currently bound to host updates, as this is the only update we have so far. */
|
---|
2615 | pelmUpdates->setAttribute("enabled", updateHost.fEnabled);
|
---|
2616 |
|
---|
2617 | xml::ElementNode *pelmUpdateHost = pelmUpdates->createChild("Host");
|
---|
2618 | pelmUpdateHost->setAttribute("enabled", updateHost.fEnabled);
|
---|
2619 | pelmUpdateHost->setAttribute("channel", (int32_t)updateHost.enmChannel);
|
---|
2620 | pelmUpdateHost->setAttribute("checkFreqSec", updateHost.uCheckFreqSeconds);
|
---|
2621 | if (updateHost.strRepoUrl.length())
|
---|
2622 | pelmUpdateHost->setAttribute("repoUrl", updateHost.strRepoUrl);
|
---|
2623 | if (updateHost.strLastCheckDate.length())
|
---|
2624 | pelmUpdateHost->setAttribute("lastCheckDate", updateHost.strLastCheckDate);
|
---|
2625 | pelmUpdateHost->setAttribute("checkCount", updateHost.uCheckCount);
|
---|
2626 | /** @todo Add update settings for ExtPack and Guest Additions here later. See @bugref{7983}. */
|
---|
2627 | #endif
|
---|
2628 |
|
---|
2629 | xml::ElementNode *pelmSysProps = pelmGlobal->createChild("SystemProperties");
|
---|
2630 | if (systemProperties.strDefaultMachineFolder.length())
|
---|
2631 | pelmSysProps->setAttribute("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
2632 | if (systemProperties.strLoggingLevel.length())
|
---|
2633 | pelmSysProps->setAttribute("LoggingLevel", systemProperties.strLoggingLevel);
|
---|
2634 | if (systemProperties.strDefaultHardDiskFormat.length())
|
---|
2635 | pelmSysProps->setAttribute("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
2636 | if (systemProperties.strVRDEAuthLibrary.length())
|
---|
2637 | pelmSysProps->setAttribute("VRDEAuthLibrary", systemProperties.strVRDEAuthLibrary);
|
---|
2638 | if (systemProperties.strWebServiceAuthLibrary.length())
|
---|
2639 | pelmSysProps->setAttribute("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
2640 | if (systemProperties.strDefaultVRDEExtPack.length())
|
---|
2641 | pelmSysProps->setAttribute("defaultVRDEExtPack", systemProperties.strDefaultVRDEExtPack);
|
---|
2642 | if (systemProperties.strDefaultCryptoExtPack.length())
|
---|
2643 | pelmSysProps->setAttribute("defaultCryptoExtPack", systemProperties.strDefaultCryptoExtPack);
|
---|
2644 | pelmSysProps->setAttribute("LogHistoryCount", systemProperties.uLogHistoryCount);
|
---|
2645 | if (systemProperties.strAutostartDatabasePath.length())
|
---|
2646 | pelmSysProps->setAttribute("autostartDatabasePath", systemProperties.strAutostartDatabasePath);
|
---|
2647 | if (systemProperties.strDefaultFrontend.length())
|
---|
2648 | pelmSysProps->setAttribute("defaultFrontend", systemProperties.strDefaultFrontend);
|
---|
2649 | if (systemProperties.strProxyUrl.length())
|
---|
2650 | pelmSysProps->setAttribute("proxyUrl", systemProperties.strProxyUrl);
|
---|
2651 | pelmSysProps->setAttribute("proxyMode", systemProperties.uProxyMode);
|
---|
2652 | pelmSysProps->setAttribute("exclusiveHwVirt", systemProperties.fExclusiveHwVirt);
|
---|
2653 | if (systemProperties.strLanguageId.isNotEmpty())
|
---|
2654 | pelmSysProps->setAttribute("LanguageId", systemProperties.strLanguageId);
|
---|
2655 |
|
---|
2656 | buildUSBDeviceFilters(*pelmGlobal->createChild("USBDeviceFilters"),
|
---|
2657 | host.llUSBDeviceFilters,
|
---|
2658 | true); // fHostMode
|
---|
2659 |
|
---|
2660 | if (!host.llUSBDeviceSources.empty())
|
---|
2661 | buildUSBDeviceSources(*pelmGlobal->createChild("USBDeviceSources"),
|
---|
2662 | host.llUSBDeviceSources);
|
---|
2663 |
|
---|
2664 | // now go write the XML
|
---|
2665 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
2666 | writer.write(m->strFilename.c_str(), true /*fSafe*/);
|
---|
2667 |
|
---|
2668 | m->fFileExists = true;
|
---|
2669 |
|
---|
2670 | clearDocument();
|
---|
2671 | LogRel(("Finished saving settings file \"%s\"\n", m->strFilename.c_str()));
|
---|
2672 | }
|
---|
2673 |
|
---|
2674 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2675 | //
|
---|
2676 | // Machine XML structures
|
---|
2677 | //
|
---|
2678 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2679 |
|
---|
2680 | /**
|
---|
2681 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
2682 | */
|
---|
2683 | VRDESettings::VRDESettings() :
|
---|
2684 | fEnabled(true), // default for old VMs, for new ones it's false
|
---|
2685 | authType(AuthType_Null),
|
---|
2686 | ulAuthTimeout(5000),
|
---|
2687 | fAllowMultiConnection(false),
|
---|
2688 | fReuseSingleConnection(false)
|
---|
2689 | {
|
---|
2690 | }
|
---|
2691 |
|
---|
2692 | /**
|
---|
2693 | * Check if all settings have default values.
|
---|
2694 | */
|
---|
2695 | bool VRDESettings::areDefaultSettings(SettingsVersion_T sv) const
|
---|
2696 | {
|
---|
2697 | return (sv < SettingsVersion_v1_16 ? fEnabled : !fEnabled)
|
---|
2698 | && authType == AuthType_Null
|
---|
2699 | && (ulAuthTimeout == 5000 || ulAuthTimeout == 0)
|
---|
2700 | && strAuthLibrary.isEmpty()
|
---|
2701 | && !fAllowMultiConnection
|
---|
2702 | && !fReuseSingleConnection
|
---|
2703 | && strVrdeExtPack.isEmpty()
|
---|
2704 | && mapProperties.size() == 0;
|
---|
2705 | }
|
---|
2706 |
|
---|
2707 | /**
|
---|
2708 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2709 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2710 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2711 | */
|
---|
2712 | bool VRDESettings::operator==(const VRDESettings& v) const
|
---|
2713 | {
|
---|
2714 | return (this == &v)
|
---|
2715 | || ( fEnabled == v.fEnabled
|
---|
2716 | && authType == v.authType
|
---|
2717 | && ulAuthTimeout == v.ulAuthTimeout
|
---|
2718 | && strAuthLibrary == v.strAuthLibrary
|
---|
2719 | && fAllowMultiConnection == v.fAllowMultiConnection
|
---|
2720 | && fReuseSingleConnection == v.fReuseSingleConnection
|
---|
2721 | && strVrdeExtPack == v.strVrdeExtPack
|
---|
2722 | && mapProperties == v.mapProperties);
|
---|
2723 | }
|
---|
2724 |
|
---|
2725 | /**
|
---|
2726 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
2727 | */
|
---|
2728 | BIOSSettings::BIOSSettings() :
|
---|
2729 | fACPIEnabled(true),
|
---|
2730 | fIOAPICEnabled(false),
|
---|
2731 | fLogoFadeIn(true),
|
---|
2732 | fLogoFadeOut(true),
|
---|
2733 | fPXEDebugEnabled(false),
|
---|
2734 | fSmbiosUuidLittleEndian(true),
|
---|
2735 | ulLogoDisplayTime(0),
|
---|
2736 | biosBootMenuMode(BIOSBootMenuMode_MessageAndMenu),
|
---|
2737 | apicMode(APICMode_APIC),
|
---|
2738 | llTimeOffset(0)
|
---|
2739 | {
|
---|
2740 | }
|
---|
2741 |
|
---|
2742 | /**
|
---|
2743 | * Check if all settings have default values.
|
---|
2744 | */
|
---|
2745 | bool BIOSSettings::areDefaultSettings() const
|
---|
2746 | {
|
---|
2747 | return fACPIEnabled
|
---|
2748 | && !fIOAPICEnabled
|
---|
2749 | && fLogoFadeIn
|
---|
2750 | && fLogoFadeOut
|
---|
2751 | && !fPXEDebugEnabled
|
---|
2752 | && !fSmbiosUuidLittleEndian
|
---|
2753 | && ulLogoDisplayTime == 0
|
---|
2754 | && biosBootMenuMode == BIOSBootMenuMode_MessageAndMenu
|
---|
2755 | && apicMode == APICMode_APIC
|
---|
2756 | && llTimeOffset == 0
|
---|
2757 | && strLogoImagePath.isEmpty();
|
---|
2758 | }
|
---|
2759 |
|
---|
2760 | /**
|
---|
2761 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
2762 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
2763 | * machine settings have really changed and thus need to be written out to disk.
|
---|
2764 | */
|
---|
2765 | bool BIOSSettings::operator==(const BIOSSettings &d) const
|
---|
2766 | {
|
---|
2767 | return (this == &d)
|
---|
2768 | || ( fACPIEnabled == d.fACPIEnabled
|
---|
2769 | && fIOAPICEnabled == d.fIOAPICEnabled
|
---|
2770 | && fLogoFadeIn == d.fLogoFadeIn
|
---|
2771 | && fLogoFadeOut == d.fLogoFadeOut
|
---|
2772 | && fPXEDebugEnabled == d.fPXEDebugEnabled
|
---|
2773 | && fSmbiosUuidLittleEndian == d.fSmbiosUuidLittleEndian
|
---|
2774 | && ulLogoDisplayTime == d.ulLogoDisplayTime
|
---|
2775 | && biosBootMenuMode == d.biosBootMenuMode
|
---|
2776 | && apicMode == d.apicMode
|
---|
2777 | && llTimeOffset == d.llTimeOffset
|
---|
2778 | && strLogoImagePath == d.strLogoImagePath);
|
---|
2779 | }
|
---|
2780 |
|
---|
2781 | RecordingScreenSettings::RecordingScreenSettings(uint32_t a_idScreen /* = UINT32_MAX */)
|
---|
2782 | : idScreen(a_idScreen)
|
---|
2783 | {
|
---|
2784 | applyDefaults();
|
---|
2785 | }
|
---|
2786 |
|
---|
2787 | RecordingScreenSettings::~RecordingScreenSettings()
|
---|
2788 | {
|
---|
2789 |
|
---|
2790 | }
|
---|
2791 |
|
---|
2792 | /**
|
---|
2793 | * Returns the default options string for screen recording settings.
|
---|
2794 | *
|
---|
2795 | * @returns Default options string for a given screen.
|
---|
2796 | */
|
---|
2797 | /* static */
|
---|
2798 | const char *RecordingScreenSettings::getDefaultOptions(void)
|
---|
2799 | {
|
---|
2800 | /* Note: Needs to be kept in sync with FE/Qt's UIMachineSettingsDisplay::putToCache()! */
|
---|
2801 | return "vc_enabled=true,ac_enabled=false,ac_profile=med";
|
---|
2802 | }
|
---|
2803 |
|
---|
2804 | /**
|
---|
2805 | * Returns a recording settings feature map from a given string.
|
---|
2806 | *
|
---|
2807 | * @returns VBox status code.
|
---|
2808 | * @param strFeatures String of features to convert.
|
---|
2809 | * @param featureMap Where to return the converted features on success.
|
---|
2810 | */
|
---|
2811 | /* static */
|
---|
2812 | int RecordingScreenSettings::featuresFromString(const com::Utf8Str &strFeatures, RecordingFeatureMap &featureMap)
|
---|
2813 | {
|
---|
2814 | featureMap.clear();
|
---|
2815 |
|
---|
2816 | RTCList<RTCString> lstFeatures = strFeatures.split(" ");
|
---|
2817 | for (size_t i = 0; i < lstFeatures.size(); i++)
|
---|
2818 | {
|
---|
2819 | if (lstFeatures.at(i).compare("video", RTCString::CaseInsensitive) == 0)
|
---|
2820 | featureMap[RecordingFeature_Video] = true;
|
---|
2821 | else if (lstFeatures.at(i).compare("audio", RTCString::CaseInsensitive) == 0)
|
---|
2822 | featureMap[RecordingFeature_Audio] = true;
|
---|
2823 | /* ignore everything else */
|
---|
2824 | }
|
---|
2825 |
|
---|
2826 | return VINF_SUCCESS;
|
---|
2827 | }
|
---|
2828 |
|
---|
2829 | /**
|
---|
2830 | * Converts a feature map to a serializable string.
|
---|
2831 | *
|
---|
2832 | * @param featureMap Feature map to convert.
|
---|
2833 | * @param strFeatures Where to return the features converted as a string.
|
---|
2834 | */
|
---|
2835 | /* static */
|
---|
2836 | void RecordingScreenSettings::featuresToString(const RecordingFeatureMap &featureMap, com::Utf8Str &strFeatures)
|
---|
2837 | {
|
---|
2838 | strFeatures = "";
|
---|
2839 |
|
---|
2840 | RecordingFeatureMap::const_iterator itFeature = featureMap.begin();
|
---|
2841 | while (itFeature != featureMap.end())
|
---|
2842 | {
|
---|
2843 | if (itFeature->first == RecordingFeature_Video && itFeature->second)
|
---|
2844 | strFeatures += "video ";
|
---|
2845 | if (itFeature->first == RecordingFeature_Audio && itFeature->second)
|
---|
2846 | strFeatures += "audio ";
|
---|
2847 | ++itFeature;
|
---|
2848 | }
|
---|
2849 | strFeatures.strip();
|
---|
2850 | }
|
---|
2851 |
|
---|
2852 | /**
|
---|
2853 | * Returns a recording settings audio codec from a given string.
|
---|
2854 | *
|
---|
2855 | * @returns VBox status code.
|
---|
2856 | * @retval VERR_NOT_SUPPORTED if audio codec is invalid or not supported.
|
---|
2857 | * @param strCodec String that contains the codec name.
|
---|
2858 | * @param enmCodec Where to return the audio codec on success.
|
---|
2859 | *
|
---|
2860 | * @note An empty string will return "none" (no codec).
|
---|
2861 | */
|
---|
2862 | /* static */
|
---|
2863 | int RecordingScreenSettings::audioCodecFromString(const com::Utf8Str &strCodec, RecordingAudioCodec_T &enmCodec)
|
---|
2864 | {
|
---|
2865 | if ( RTStrIStr(strCodec.c_str(), "none")
|
---|
2866 | || strCodec.isEmpty())
|
---|
2867 | {
|
---|
2868 | enmCodec = RecordingAudioCodec_None;
|
---|
2869 | return VINF_SUCCESS;
|
---|
2870 | }
|
---|
2871 | else if (RTStrIStr(strCodec.c_str(), "wav"))
|
---|
2872 | {
|
---|
2873 | enmCodec = RecordingAudioCodec_WavPCM;
|
---|
2874 | return VINF_SUCCESS;
|
---|
2875 | }
|
---|
2876 | else if (RTStrIStr(strCodec.c_str(), "mp3"))
|
---|
2877 | {
|
---|
2878 | enmCodec = RecordingAudioCodec_MP3;
|
---|
2879 | return VINF_SUCCESS;
|
---|
2880 | }
|
---|
2881 | else if (RTStrIStr(strCodec.c_str(), "opus"))
|
---|
2882 | {
|
---|
2883 | enmCodec = RecordingAudioCodec_Opus;
|
---|
2884 | return VINF_SUCCESS;
|
---|
2885 | }
|
---|
2886 | else if (RTStrIStr(strCodec.c_str(), "vorbis"))
|
---|
2887 | {
|
---|
2888 | enmCodec = RecordingAudioCodec_OggVorbis;
|
---|
2889 | return VINF_SUCCESS;
|
---|
2890 | }
|
---|
2891 |
|
---|
2892 | AssertFailedReturn(VERR_NOT_SUPPORTED);
|
---|
2893 | }
|
---|
2894 |
|
---|
2895 | /**
|
---|
2896 | * Converts an audio codec to a serializable string.
|
---|
2897 | *
|
---|
2898 | * @param enmCodec Codec to convert to a string.
|
---|
2899 | * @param strCodec Where to return the audio codec converted as a string.
|
---|
2900 | */
|
---|
2901 | /* static */
|
---|
2902 | void RecordingScreenSettings::audioCodecToString(const RecordingAudioCodec_T &enmCodec, com::Utf8Str &strCodec)
|
---|
2903 | {
|
---|
2904 | switch (enmCodec)
|
---|
2905 | {
|
---|
2906 | case RecordingAudioCodec_None: strCodec = "none"; return;
|
---|
2907 | case RecordingAudioCodec_WavPCM: strCodec = "wav"; return;
|
---|
2908 | case RecordingAudioCodec_MP3: strCodec = "mp3"; return;
|
---|
2909 | case RecordingAudioCodec_Opus: strCodec = "opus"; return;
|
---|
2910 | case RecordingAudioCodec_OggVorbis: strCodec = "vorbis"; return;
|
---|
2911 | default: AssertFailedReturnVoid();
|
---|
2912 | }
|
---|
2913 | }
|
---|
2914 |
|
---|
2915 | /**
|
---|
2916 | * Returns a recording settings video codec from a given string.
|
---|
2917 | *
|
---|
2918 | * @returns VBox status code.
|
---|
2919 | * @retval VERR_NOT_SUPPORTED if video codec is invalid or not supported.
|
---|
2920 | * @param strCodec String that contains the codec name.
|
---|
2921 | * @param enmCodec Where to return the video codec on success.
|
---|
2922 | *
|
---|
2923 | * @note An empty string will return "none" (no codec).
|
---|
2924 | */
|
---|
2925 | /* static */
|
---|
2926 | int RecordingScreenSettings::videoCodecFromString(const com::Utf8Str &strCodec, RecordingVideoCodec_T &enmCodec)
|
---|
2927 | {
|
---|
2928 | if ( RTStrIStr(strCodec.c_str(), "none")
|
---|
2929 | || strCodec.isEmpty())
|
---|
2930 | {
|
---|
2931 | enmCodec = RecordingVideoCodec_None;
|
---|
2932 | return VINF_SUCCESS;
|
---|
2933 | }
|
---|
2934 | else if (RTStrIStr(strCodec.c_str(), "MJPEG"))
|
---|
2935 | {
|
---|
2936 | enmCodec = RecordingVideoCodec_MJPEG;
|
---|
2937 | return VINF_SUCCESS;
|
---|
2938 | }
|
---|
2939 | else if (RTStrIStr(strCodec.c_str(), "H262"))
|
---|
2940 | {
|
---|
2941 | enmCodec = RecordingVideoCodec_H262;
|
---|
2942 | return VINF_SUCCESS;
|
---|
2943 | }
|
---|
2944 | else if (RTStrIStr(strCodec.c_str(), "H264"))
|
---|
2945 | {
|
---|
2946 | enmCodec = RecordingVideoCodec_H264;
|
---|
2947 | return VINF_SUCCESS;
|
---|
2948 | }
|
---|
2949 | else if (RTStrIStr(strCodec.c_str(), "H265"))
|
---|
2950 | {
|
---|
2951 | enmCodec = RecordingVideoCodec_H265;
|
---|
2952 | return VINF_SUCCESS;
|
---|
2953 | }
|
---|
2954 | else if (RTStrIStr(strCodec.c_str(), "H266"))
|
---|
2955 | {
|
---|
2956 | enmCodec = RecordingVideoCodec_H266;
|
---|
2957 | return VINF_SUCCESS;
|
---|
2958 | }
|
---|
2959 | else if (RTStrIStr(strCodec.c_str(), "VP8"))
|
---|
2960 | {
|
---|
2961 | enmCodec = RecordingVideoCodec_VP8;
|
---|
2962 | return VINF_SUCCESS;
|
---|
2963 | }
|
---|
2964 | else if (RTStrIStr(strCodec.c_str(), "VP9"))
|
---|
2965 | {
|
---|
2966 | enmCodec = RecordingVideoCodec_VP9;
|
---|
2967 | return VINF_SUCCESS;
|
---|
2968 | }
|
---|
2969 | else if (RTStrIStr(strCodec.c_str(), "AV1"))
|
---|
2970 | {
|
---|
2971 | enmCodec = RecordingVideoCodec_AV1;
|
---|
2972 | return VINF_SUCCESS;
|
---|
2973 | }
|
---|
2974 | else if (RTStrIStr(strCodec.c_str(), "other"))
|
---|
2975 | {
|
---|
2976 | enmCodec = RecordingVideoCodec_Other;
|
---|
2977 | return VINF_SUCCESS;
|
---|
2978 | }
|
---|
2979 |
|
---|
2980 | AssertFailedReturn(VERR_NOT_SUPPORTED);
|
---|
2981 | }
|
---|
2982 |
|
---|
2983 | /**
|
---|
2984 | * Converts a video codec to a serializable string.
|
---|
2985 | *
|
---|
2986 | * @param enmCodec Codec to convert to a string.
|
---|
2987 | * @param strCodec Where to return the video codec converted as a string.
|
---|
2988 | */
|
---|
2989 | /* static */
|
---|
2990 | void RecordingScreenSettings::videoCodecToString(const RecordingVideoCodec_T &enmCodec, com::Utf8Str &strCodec)
|
---|
2991 | {
|
---|
2992 | switch (enmCodec)
|
---|
2993 | {
|
---|
2994 | case RecordingVideoCodec_None: strCodec = "none"; return;
|
---|
2995 | case RecordingVideoCodec_MJPEG: strCodec = "MJPEG"; return;
|
---|
2996 | case RecordingVideoCodec_H262: strCodec = "H262"; return;
|
---|
2997 | case RecordingVideoCodec_H264: strCodec = "H264"; return;
|
---|
2998 | case RecordingVideoCodec_H265: strCodec = "H265"; return;
|
---|
2999 | case RecordingVideoCodec_H266: strCodec = "H266"; return;
|
---|
3000 | case RecordingVideoCodec_VP8: strCodec = "VP8"; return;
|
---|
3001 | case RecordingVideoCodec_VP9: strCodec = "VP9"; return;
|
---|
3002 | case RecordingVideoCodec_AV1: strCodec = "AV1"; return;
|
---|
3003 | case RecordingVideoCodec_Other: strCodec = "other"; return;
|
---|
3004 | default: AssertFailedReturnVoid();
|
---|
3005 | }
|
---|
3006 | }
|
---|
3007 |
|
---|
3008 | /**
|
---|
3009 | * Applies the default settings.
|
---|
3010 | */
|
---|
3011 | void RecordingScreenSettings::applyDefaults(void)
|
---|
3012 | {
|
---|
3013 | /*
|
---|
3014 | * Set sensible defaults.
|
---|
3015 | */
|
---|
3016 |
|
---|
3017 | /*
|
---|
3018 | * Enable screen 0 by default.
|
---|
3019 | * Otherwise enabling recording without any screen enabled at all makes no sense.
|
---|
3020 | *
|
---|
3021 | * Note: When tweaking this, make sure to also alter RecordingScreenSettings::areDefaultSettings().
|
---|
3022 | */
|
---|
3023 | fEnabled = idScreen == 0 ? true : false;;
|
---|
3024 | enmDest = RecordingDestination_File;
|
---|
3025 | ulMaxTimeS = 0;
|
---|
3026 | strOptions = RecordingScreenSettings::getDefaultOptions();
|
---|
3027 | File.ulMaxSizeMB = 0;
|
---|
3028 | File.strName = "";
|
---|
3029 | Video.enmCodec = RecordingVideoCodec_VP8;
|
---|
3030 | Video.enmDeadline = RecordingCodecDeadline_Default;
|
---|
3031 | Video.enmRateCtlMode = RecordingRateControlMode_VBR;
|
---|
3032 | Video.enmScalingMode = RecordingVideoScalingMode_None;
|
---|
3033 | Video.ulWidth = 1024;
|
---|
3034 | Video.ulHeight = 768;
|
---|
3035 | Video.ulRate = 512;
|
---|
3036 | Video.ulFPS = 25;
|
---|
3037 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
3038 | # if defined(VBOX_WITH_LIBVORBIS)
|
---|
3039 | Audio.enmCodec = RecordingAudioCodec_OggVorbis;
|
---|
3040 | # else
|
---|
3041 | Audio.enmCodec = RecordingAudioCodec_None;
|
---|
3042 | # endif
|
---|
3043 | #else
|
---|
3044 | Audio.enmCodec = RecordingAudioCodec_None;
|
---|
3045 | #endif /* VBOX_WITH_RECORDING */
|
---|
3046 | Audio.enmDeadline = RecordingCodecDeadline_Default;
|
---|
3047 | Audio.enmRateCtlMode = RecordingRateControlMode_VBR;
|
---|
3048 | Audio.cBits = 16;
|
---|
3049 | Audio.cChannels = 2;
|
---|
3050 | Audio.uHz = 22050;
|
---|
3051 |
|
---|
3052 | featureMap[RecordingFeature_Video] = true;
|
---|
3053 | featureMap[RecordingFeature_Audio] = false; /** @todo Audio is not yet enabled by default. */
|
---|
3054 | }
|
---|
3055 |
|
---|
3056 | /**
|
---|
3057 | * Check if all settings have default values.
|
---|
3058 | *
|
---|
3059 | * @returns @c true if default, @c false if not.
|
---|
3060 | */
|
---|
3061 | bool RecordingScreenSettings::areDefaultSettings(void) const
|
---|
3062 | {
|
---|
3063 | return ( fEnabled == false
|
---|
3064 | /* Screen 0 is special: There we ALWAYS enable recording by default. */
|
---|
3065 | || ( idScreen == 0
|
---|
3066 | && fEnabled == true)
|
---|
3067 | )
|
---|
3068 | && enmDest == RecordingDestination_File
|
---|
3069 | && ulMaxTimeS == 0
|
---|
3070 | && strOptions == RecordingScreenSettings::getDefaultOptions()
|
---|
3071 | && File.ulMaxSizeMB == 0
|
---|
3072 | && File.strName == ""
|
---|
3073 | && Video.enmCodec == RecordingVideoCodec_VP8
|
---|
3074 | && Video.enmDeadline == RecordingCodecDeadline_Default
|
---|
3075 | && Video.enmRateCtlMode == RecordingRateControlMode_VBR
|
---|
3076 | && Video.enmScalingMode == RecordingVideoScalingMode_None
|
---|
3077 | && Video.ulWidth == 1024
|
---|
3078 | && Video.ulHeight == 768
|
---|
3079 | && Video.ulRate == 512
|
---|
3080 | && Video.ulFPS == 25
|
---|
3081 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
3082 | # if defined(VBOX_WITH_LIBVORBIS)
|
---|
3083 | && Audio.enmCodec == RecordingAudioCodec_OggVorbis
|
---|
3084 | # else
|
---|
3085 | && Audio.enmCodec == RecordingAudioCodec_None
|
---|
3086 | # endif
|
---|
3087 | #else
|
---|
3088 | && Audio.enmCodec == RecordingAudioCodec_None
|
---|
3089 | #endif /* VBOX_WITH_AUDIO_RECORDING */
|
---|
3090 | && Audio.enmDeadline == RecordingCodecDeadline_Default
|
---|
3091 | && Audio.enmRateCtlMode == RecordingRateControlMode_VBR
|
---|
3092 | && Audio.cBits == 16
|
---|
3093 | && Audio.cChannels == 2
|
---|
3094 | && Audio.uHz == 22050
|
---|
3095 | && featureMap.find(RecordingFeature_Video)->second == true
|
---|
3096 | && featureMap.find(RecordingFeature_Audio)->second == false;
|
---|
3097 | }
|
---|
3098 |
|
---|
3099 | /**
|
---|
3100 | * Returns if a certain recording feature is enabled or not.
|
---|
3101 | *
|
---|
3102 | * @returns @c true if the feature is enabled, @c false if not.
|
---|
3103 | * @param enmFeature Feature to check.
|
---|
3104 | */
|
---|
3105 | bool RecordingScreenSettings::isFeatureEnabled(RecordingFeature_T enmFeature) const
|
---|
3106 | {
|
---|
3107 | RecordingFeatureMap::const_iterator itFeature = featureMap.find(enmFeature);
|
---|
3108 | if (itFeature != featureMap.end())
|
---|
3109 | return itFeature->second;
|
---|
3110 |
|
---|
3111 | return false;
|
---|
3112 | }
|
---|
3113 |
|
---|
3114 | /**
|
---|
3115 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3116 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3117 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3118 | */
|
---|
3119 | bool RecordingScreenSettings::operator==(const RecordingScreenSettings &d) const
|
---|
3120 | {
|
---|
3121 | return fEnabled == d.fEnabled
|
---|
3122 | && enmDest == d.enmDest
|
---|
3123 | && featureMap == d.featureMap
|
---|
3124 | && ulMaxTimeS == d.ulMaxTimeS
|
---|
3125 | && strOptions == d.strOptions
|
---|
3126 | && File.strName == d.File.strName
|
---|
3127 | && File.ulMaxSizeMB == d.File.ulMaxSizeMB
|
---|
3128 | && Video.enmCodec == d.Video.enmCodec
|
---|
3129 | && Video.enmDeadline == d.Video.enmDeadline
|
---|
3130 | && Video.enmRateCtlMode == d.Video.enmRateCtlMode
|
---|
3131 | && Video.enmScalingMode == d.Video.enmScalingMode
|
---|
3132 | && Video.ulWidth == d.Video.ulWidth
|
---|
3133 | && Video.ulHeight == d.Video.ulHeight
|
---|
3134 | && Video.ulRate == d.Video.ulRate
|
---|
3135 | && Video.ulFPS == d.Video.ulFPS
|
---|
3136 | && Audio.enmCodec == d.Audio.enmCodec
|
---|
3137 | && Audio.enmDeadline == d.Audio.enmDeadline
|
---|
3138 | && Audio.enmRateCtlMode == d.Audio.enmRateCtlMode
|
---|
3139 | && Audio.cBits == d.Audio.cBits
|
---|
3140 | && Audio.cChannels == d.Audio.cChannels
|
---|
3141 | && Audio.uHz == d.Audio.uHz
|
---|
3142 | && featureMap == d.featureMap;
|
---|
3143 | }
|
---|
3144 |
|
---|
3145 | /**
|
---|
3146 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3147 | */
|
---|
3148 | RecordingCommonSettings::RecordingCommonSettings()
|
---|
3149 | {
|
---|
3150 | applyDefaults();
|
---|
3151 | }
|
---|
3152 |
|
---|
3153 | /**
|
---|
3154 | * Applies the default settings.
|
---|
3155 | */
|
---|
3156 | void RecordingCommonSettings::applyDefaults(void)
|
---|
3157 | {
|
---|
3158 | fEnabled = false;
|
---|
3159 | }
|
---|
3160 |
|
---|
3161 | /**
|
---|
3162 | * Check if all settings have default values.
|
---|
3163 | */
|
---|
3164 | bool RecordingCommonSettings::areDefaultSettings(void) const
|
---|
3165 | {
|
---|
3166 | return fEnabled == false;
|
---|
3167 | }
|
---|
3168 |
|
---|
3169 | /**
|
---|
3170 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3171 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3172 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3173 | */
|
---|
3174 | bool RecordingCommonSettings::operator==(const RecordingCommonSettings &d) const
|
---|
3175 | {
|
---|
3176 | if (this == &d)
|
---|
3177 | return true;
|
---|
3178 |
|
---|
3179 | return fEnabled == d.fEnabled;
|
---|
3180 | }
|
---|
3181 |
|
---|
3182 | /**
|
---|
3183 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3184 | */
|
---|
3185 | RecordingSettings::RecordingSettings()
|
---|
3186 | {
|
---|
3187 | applyDefaults();
|
---|
3188 | }
|
---|
3189 |
|
---|
3190 | /**
|
---|
3191 | * Applies the default settings.
|
---|
3192 | */
|
---|
3193 | void RecordingSettings::applyDefaults(void)
|
---|
3194 | {
|
---|
3195 | common.applyDefaults();
|
---|
3196 |
|
---|
3197 | mapScreens.clear();
|
---|
3198 |
|
---|
3199 | try
|
---|
3200 | {
|
---|
3201 | /* Always add screen 0 to the default configuration. */
|
---|
3202 | RecordingScreenSettings screenSettings(0 /* Screen ID */);
|
---|
3203 |
|
---|
3204 | mapScreens[0 /* Screen ID */] = screenSettings;
|
---|
3205 | }
|
---|
3206 | catch (std::bad_alloc &)
|
---|
3207 | {
|
---|
3208 | AssertFailed();
|
---|
3209 | }
|
---|
3210 | }
|
---|
3211 |
|
---|
3212 | /**
|
---|
3213 | * Check if all settings have default values.
|
---|
3214 | */
|
---|
3215 | bool RecordingSettings::areDefaultSettings(void) const
|
---|
3216 | {
|
---|
3217 | AssertReturn(mapScreens.size() >= 1, false); /* The first screen always must be present. */
|
---|
3218 |
|
---|
3219 | if (!common.areDefaultSettings())
|
---|
3220 | return false;
|
---|
3221 |
|
---|
3222 | RecordingScreenSettingsMap::const_iterator itScreen = mapScreens.begin();
|
---|
3223 | while (itScreen != mapScreens.end())
|
---|
3224 | {
|
---|
3225 | if (!itScreen->second.areDefaultSettings())
|
---|
3226 | return false;
|
---|
3227 | ++itScreen;
|
---|
3228 | }
|
---|
3229 |
|
---|
3230 | return true;
|
---|
3231 | }
|
---|
3232 |
|
---|
3233 | /**
|
---|
3234 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3235 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3236 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3237 | */
|
---|
3238 | bool RecordingSettings::operator==(const RecordingSettings &that) const
|
---|
3239 | {
|
---|
3240 | if (this == &that) /* If pointers match, take a shortcut. */
|
---|
3241 | return true;
|
---|
3242 |
|
---|
3243 | if (common == that.common)
|
---|
3244 | {
|
---|
3245 | /* Too lazy for a != operator. */
|
---|
3246 | }
|
---|
3247 | else
|
---|
3248 | return false;
|
---|
3249 |
|
---|
3250 | if (mapScreens.size() != that.mapScreens.size())
|
---|
3251 | return false;
|
---|
3252 |
|
---|
3253 | RecordingScreenSettingsMap::const_iterator itScreen = mapScreens.begin();
|
---|
3254 | RecordingScreenSettingsMap::const_iterator itScreenThat = that.mapScreens.begin();
|
---|
3255 | while ( itScreen != mapScreens.end()
|
---|
3256 | && itScreenThat != that.mapScreens.end())
|
---|
3257 | {
|
---|
3258 | if (itScreen->second == itScreenThat->second)
|
---|
3259 | {
|
---|
3260 | /* Nothing to do in here (yet). */
|
---|
3261 | }
|
---|
3262 | else
|
---|
3263 | return false;
|
---|
3264 |
|
---|
3265 | ++itScreen;
|
---|
3266 | ++itScreenThat;
|
---|
3267 | }
|
---|
3268 |
|
---|
3269 | return true;
|
---|
3270 | }
|
---|
3271 |
|
---|
3272 | /**
|
---|
3273 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3274 | */
|
---|
3275 | GraphicsAdapter::GraphicsAdapter() :
|
---|
3276 | graphicsControllerType(GraphicsControllerType_VBoxVGA),
|
---|
3277 | ulVRAMSizeMB(8),
|
---|
3278 | cMonitors(1),
|
---|
3279 | fAccelerate3D(false),
|
---|
3280 | fAccelerate2DVideo(false)
|
---|
3281 | {
|
---|
3282 | }
|
---|
3283 |
|
---|
3284 | /**
|
---|
3285 | * Check if all settings have default values.
|
---|
3286 | */
|
---|
3287 | bool GraphicsAdapter::areDefaultSettings() const
|
---|
3288 | {
|
---|
3289 | return graphicsControllerType == GraphicsControllerType_VBoxVGA
|
---|
3290 | && ulVRAMSizeMB == 8
|
---|
3291 | && cMonitors <= 1
|
---|
3292 | && !fAccelerate3D
|
---|
3293 | && !fAccelerate2DVideo;
|
---|
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 GraphicsAdapter::operator==(const GraphicsAdapter &g) const
|
---|
3302 | {
|
---|
3303 | return (this == &g)
|
---|
3304 | || ( graphicsControllerType == g.graphicsControllerType
|
---|
3305 | && ulVRAMSizeMB == g.ulVRAMSizeMB
|
---|
3306 | && cMonitors == g.cMonitors
|
---|
3307 | && fAccelerate3D == g.fAccelerate3D
|
---|
3308 | && fAccelerate2DVideo == g.fAccelerate2DVideo);
|
---|
3309 | }
|
---|
3310 |
|
---|
3311 | /**
|
---|
3312 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3313 | */
|
---|
3314 | TpmSettings::TpmSettings() :
|
---|
3315 | tpmType(TpmType_None)
|
---|
3316 | {
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | /**
|
---|
3320 | * Check if all settings have default values.
|
---|
3321 | */
|
---|
3322 | bool TpmSettings::areDefaultSettings() const
|
---|
3323 | {
|
---|
3324 | return tpmType == TpmType_None
|
---|
3325 | && strLocation.isEmpty();
|
---|
3326 | }
|
---|
3327 |
|
---|
3328 | /**
|
---|
3329 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3330 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3331 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3332 | */
|
---|
3333 | bool TpmSettings::operator==(const TpmSettings &g) const
|
---|
3334 | {
|
---|
3335 | return (this == &g)
|
---|
3336 | || ( tpmType == g.tpmType
|
---|
3337 | && strLocation == g.strLocation);
|
---|
3338 | }
|
---|
3339 |
|
---|
3340 | /**
|
---|
3341 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3342 | */
|
---|
3343 | NvramSettings::NvramSettings()
|
---|
3344 | {
|
---|
3345 | }
|
---|
3346 |
|
---|
3347 | /**
|
---|
3348 | * Check if all settings have default values.
|
---|
3349 | */
|
---|
3350 | bool NvramSettings::areDefaultSettings() const
|
---|
3351 | {
|
---|
3352 | return strNvramPath.isEmpty()
|
---|
3353 | && strKeyId.isEmpty()
|
---|
3354 | && strKeyStore.isEmpty();
|
---|
3355 | }
|
---|
3356 |
|
---|
3357 | /**
|
---|
3358 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3359 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3360 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3361 | */
|
---|
3362 | bool NvramSettings::operator==(const NvramSettings &g) const
|
---|
3363 | {
|
---|
3364 | return (this == &g)
|
---|
3365 | || (strNvramPath == g.strNvramPath)
|
---|
3366 | || (strKeyId == g.strKeyId)
|
---|
3367 | || (strKeyStore == g.strKeyStore);
|
---|
3368 | }
|
---|
3369 |
|
---|
3370 |
|
---|
3371 | /**
|
---|
3372 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3373 | */
|
---|
3374 | USBController::USBController() :
|
---|
3375 | enmType(USBControllerType_Null)
|
---|
3376 | {
|
---|
3377 | }
|
---|
3378 |
|
---|
3379 | /**
|
---|
3380 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3381 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3382 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3383 | */
|
---|
3384 | bool USBController::operator==(const USBController &u) const
|
---|
3385 | {
|
---|
3386 | return (this == &u)
|
---|
3387 | || ( strName == u.strName
|
---|
3388 | && enmType == u.enmType);
|
---|
3389 | }
|
---|
3390 |
|
---|
3391 | /**
|
---|
3392 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3393 | */
|
---|
3394 | USB::USB()
|
---|
3395 | {
|
---|
3396 | }
|
---|
3397 |
|
---|
3398 | /**
|
---|
3399 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3400 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3401 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3402 | */
|
---|
3403 | bool USB::operator==(const USB &u) const
|
---|
3404 | {
|
---|
3405 | return (this == &u)
|
---|
3406 | || ( llUSBControllers == u.llUSBControllers
|
---|
3407 | && llDeviceFilters == u.llDeviceFilters);
|
---|
3408 | }
|
---|
3409 |
|
---|
3410 | /**
|
---|
3411 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3412 | */
|
---|
3413 | NAT::NAT() :
|
---|
3414 | u32Mtu(0),
|
---|
3415 | u32SockRcv(0),
|
---|
3416 | u32SockSnd(0),
|
---|
3417 | u32TcpRcv(0),
|
---|
3418 | u32TcpSnd(0),
|
---|
3419 | fDNSPassDomain(true), /* historically this value is true */
|
---|
3420 | fDNSProxy(false),
|
---|
3421 | fDNSUseHostResolver(false),
|
---|
3422 | fAliasLog(false),
|
---|
3423 | fAliasProxyOnly(false),
|
---|
3424 | fAliasUseSamePorts(false),
|
---|
3425 | fLocalhostReachable(true) /* Historically this value is true. */
|
---|
3426 | {
|
---|
3427 | }
|
---|
3428 |
|
---|
3429 | /**
|
---|
3430 | * Check if all DNS settings have default values.
|
---|
3431 | */
|
---|
3432 | bool NAT::areDNSDefaultSettings() const
|
---|
3433 | {
|
---|
3434 | return fDNSPassDomain && !fDNSProxy && !fDNSUseHostResolver;
|
---|
3435 | }
|
---|
3436 |
|
---|
3437 | /**
|
---|
3438 | * Check if all Alias settings have default values.
|
---|
3439 | */
|
---|
3440 | bool NAT::areAliasDefaultSettings() const
|
---|
3441 | {
|
---|
3442 | return !fAliasLog && !fAliasProxyOnly && !fAliasUseSamePorts;
|
---|
3443 | }
|
---|
3444 |
|
---|
3445 | /**
|
---|
3446 | * Check if all TFTP settings have default values.
|
---|
3447 | */
|
---|
3448 | bool NAT::areTFTPDefaultSettings() const
|
---|
3449 | {
|
---|
3450 | return strTFTPPrefix.isEmpty()
|
---|
3451 | && strTFTPBootFile.isEmpty()
|
---|
3452 | && strTFTPNextServer.isEmpty();
|
---|
3453 | }
|
---|
3454 |
|
---|
3455 | /**
|
---|
3456 | * Check whether the localhost-reachable setting is the default for the given settings version.
|
---|
3457 | */
|
---|
3458 | bool NAT::areLocalhostReachableDefaultSettings(SettingsVersion_T sv) const
|
---|
3459 | {
|
---|
3460 | return ( fLocalhostReachable
|
---|
3461 | && sv < SettingsVersion_v1_19)
|
---|
3462 | || ( !fLocalhostReachable
|
---|
3463 | && sv >= SettingsVersion_v1_19);
|
---|
3464 | }
|
---|
3465 |
|
---|
3466 | /**
|
---|
3467 | * Check if all settings have default values.
|
---|
3468 | */
|
---|
3469 | bool NAT::areDefaultSettings(SettingsVersion_T sv) const
|
---|
3470 | {
|
---|
3471 | /*
|
---|
3472 | * Before settings version 1.19 localhost was reachable by default
|
---|
3473 | * when using NAT which was changed with version 1.19+, see @bugref{9896}
|
---|
3474 | * for more information.
|
---|
3475 | */
|
---|
3476 | return strNetwork.isEmpty()
|
---|
3477 | && strBindIP.isEmpty()
|
---|
3478 | && u32Mtu == 0
|
---|
3479 | && u32SockRcv == 0
|
---|
3480 | && u32SockSnd == 0
|
---|
3481 | && u32TcpRcv == 0
|
---|
3482 | && u32TcpSnd == 0
|
---|
3483 | && areDNSDefaultSettings()
|
---|
3484 | && areAliasDefaultSettings()
|
---|
3485 | && areTFTPDefaultSettings()
|
---|
3486 | && mapRules.size() == 0
|
---|
3487 | && areLocalhostReachableDefaultSettings(sv);
|
---|
3488 | }
|
---|
3489 |
|
---|
3490 | /**
|
---|
3491 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3492 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3493 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3494 | */
|
---|
3495 | bool NAT::operator==(const NAT &n) const
|
---|
3496 | {
|
---|
3497 | return (this == &n)
|
---|
3498 | || ( strNetwork == n.strNetwork
|
---|
3499 | && strBindIP == n.strBindIP
|
---|
3500 | && u32Mtu == n.u32Mtu
|
---|
3501 | && u32SockRcv == n.u32SockRcv
|
---|
3502 | && u32SockSnd == n.u32SockSnd
|
---|
3503 | && u32TcpSnd == n.u32TcpSnd
|
---|
3504 | && u32TcpRcv == n.u32TcpRcv
|
---|
3505 | && strTFTPPrefix == n.strTFTPPrefix
|
---|
3506 | && strTFTPBootFile == n.strTFTPBootFile
|
---|
3507 | && strTFTPNextServer == n.strTFTPNextServer
|
---|
3508 | && fDNSPassDomain == n.fDNSPassDomain
|
---|
3509 | && fDNSProxy == n.fDNSProxy
|
---|
3510 | && fDNSUseHostResolver == n.fDNSUseHostResolver
|
---|
3511 | && fAliasLog == n.fAliasLog
|
---|
3512 | && fAliasProxyOnly == n.fAliasProxyOnly
|
---|
3513 | && fAliasUseSamePorts == n.fAliasUseSamePorts
|
---|
3514 | && fLocalhostReachable == n.fLocalhostReachable
|
---|
3515 | && mapRules == n.mapRules);
|
---|
3516 | }
|
---|
3517 |
|
---|
3518 | /**
|
---|
3519 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3520 | */
|
---|
3521 | NetworkAdapter::NetworkAdapter() :
|
---|
3522 | ulSlot(0),
|
---|
3523 | type(NetworkAdapterType_Am79C970A), // default for old VMs, for new ones it's Am79C973
|
---|
3524 | fEnabled(false),
|
---|
3525 | fCableConnected(false), // default for old VMs, for new ones it's true
|
---|
3526 | ulLineSpeed(0),
|
---|
3527 | enmPromiscModePolicy(NetworkAdapterPromiscModePolicy_Deny),
|
---|
3528 | fTraceEnabled(false),
|
---|
3529 | mode(NetworkAttachmentType_Null),
|
---|
3530 | ulBootPriority(0)
|
---|
3531 | {
|
---|
3532 | }
|
---|
3533 |
|
---|
3534 | /**
|
---|
3535 | * Check if all Generic Driver settings have default values.
|
---|
3536 | */
|
---|
3537 | bool NetworkAdapter::areGenericDriverDefaultSettings() const
|
---|
3538 | {
|
---|
3539 | return strGenericDriver.isEmpty()
|
---|
3540 | && genericProperties.size() == 0;
|
---|
3541 | }
|
---|
3542 |
|
---|
3543 | /**
|
---|
3544 | * Check if all settings have default values.
|
---|
3545 | */
|
---|
3546 | bool NetworkAdapter::areDefaultSettings(SettingsVersion_T sv) const
|
---|
3547 | {
|
---|
3548 | // 5.0 and earlier had a default of fCableConnected=false, which doesn't
|
---|
3549 | // make a lot of sense (but it's a fact). Later versions don't save the
|
---|
3550 | // setting if it's at the default value and thus must get it right.
|
---|
3551 | return !fEnabled
|
---|
3552 | && strMACAddress.isEmpty()
|
---|
3553 | && ( (sv >= SettingsVersion_v1_16 && fCableConnected && type == NetworkAdapterType_Am79C973)
|
---|
3554 | || (sv < SettingsVersion_v1_16 && !fCableConnected && type == NetworkAdapterType_Am79C970A))
|
---|
3555 | && ulLineSpeed == 0
|
---|
3556 | && enmPromiscModePolicy == NetworkAdapterPromiscModePolicy_Deny
|
---|
3557 | && mode == NetworkAttachmentType_Null
|
---|
3558 | && nat.areDefaultSettings(sv)
|
---|
3559 | && strBridgedName.isEmpty()
|
---|
3560 | && strInternalNetworkName.isEmpty()
|
---|
3561 | #ifdef VBOX_WITH_VMNET
|
---|
3562 | && strHostOnlyNetworkName.isEmpty()
|
---|
3563 | #endif /* VBOX_WITH_VMNET */
|
---|
3564 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
3565 | && strCloudNetworkName.isEmpty()
|
---|
3566 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
3567 | && strHostOnlyName.isEmpty()
|
---|
3568 | && areGenericDriverDefaultSettings()
|
---|
3569 | && strNATNetworkName.isEmpty();
|
---|
3570 | }
|
---|
3571 |
|
---|
3572 | /**
|
---|
3573 | * Special check if settings of the non-current attachment type have default values.
|
---|
3574 | */
|
---|
3575 | bool NetworkAdapter::areDisabledDefaultSettings(SettingsVersion_T sv) const
|
---|
3576 | {
|
---|
3577 | return (mode != NetworkAttachmentType_NAT ? nat.areDefaultSettings(sv) : true)
|
---|
3578 | && (mode != NetworkAttachmentType_Bridged ? strBridgedName.isEmpty() : true)
|
---|
3579 | && (mode != NetworkAttachmentType_Internal ? strInternalNetworkName.isEmpty() : true)
|
---|
3580 | #ifdef VBOX_WITH_VMNET
|
---|
3581 | && (mode != NetworkAttachmentType_HostOnlyNetwork ? strHostOnlyNetworkName.isEmpty() : true)
|
---|
3582 | #endif /* VBOX_WITH_VMNET */
|
---|
3583 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
3584 | && (mode != NetworkAttachmentType_Cloud ? strCloudNetworkName.isEmpty() : true)
|
---|
3585 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
3586 | && (mode != NetworkAttachmentType_HostOnly ? strHostOnlyName.isEmpty() : true)
|
---|
3587 | && (mode != NetworkAttachmentType_Generic ? areGenericDriverDefaultSettings() : true)
|
---|
3588 | && (mode != NetworkAttachmentType_NATNetwork ? strNATNetworkName.isEmpty() : true);
|
---|
3589 | }
|
---|
3590 |
|
---|
3591 | /**
|
---|
3592 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3593 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3594 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3595 | */
|
---|
3596 | bool NetworkAdapter::operator==(const NetworkAdapter &n) const
|
---|
3597 | {
|
---|
3598 | return (this == &n)
|
---|
3599 | || ( ulSlot == n.ulSlot
|
---|
3600 | && type == n.type
|
---|
3601 | && fEnabled == n.fEnabled
|
---|
3602 | && strMACAddress == n.strMACAddress
|
---|
3603 | && fCableConnected == n.fCableConnected
|
---|
3604 | && ulLineSpeed == n.ulLineSpeed
|
---|
3605 | && enmPromiscModePolicy == n.enmPromiscModePolicy
|
---|
3606 | && fTraceEnabled == n.fTraceEnabled
|
---|
3607 | && strTraceFile == n.strTraceFile
|
---|
3608 | && mode == n.mode
|
---|
3609 | && nat == n.nat
|
---|
3610 | && strBridgedName == n.strBridgedName
|
---|
3611 | && strHostOnlyName == n.strHostOnlyName
|
---|
3612 | #ifdef VBOX_WITH_VMNET
|
---|
3613 | && strHostOnlyNetworkName == n.strHostOnlyNetworkName
|
---|
3614 | #endif /* VBOX_WITH_VMNET */
|
---|
3615 | && strInternalNetworkName == n.strInternalNetworkName
|
---|
3616 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
3617 | && strCloudNetworkName == n.strCloudNetworkName
|
---|
3618 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
3619 | && strGenericDriver == n.strGenericDriver
|
---|
3620 | && genericProperties == n.genericProperties
|
---|
3621 | && ulBootPriority == n.ulBootPriority
|
---|
3622 | && strBandwidthGroup == n.strBandwidthGroup);
|
---|
3623 | }
|
---|
3624 |
|
---|
3625 | /**
|
---|
3626 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3627 | */
|
---|
3628 | SerialPort::SerialPort() :
|
---|
3629 | ulSlot(0),
|
---|
3630 | fEnabled(false),
|
---|
3631 | ulIOBase(0x3f8),
|
---|
3632 | ulIRQ(4),
|
---|
3633 | portMode(PortMode_Disconnected),
|
---|
3634 | fServer(false),
|
---|
3635 | uartType(UartType_U16550A)
|
---|
3636 | {
|
---|
3637 | }
|
---|
3638 |
|
---|
3639 | /**
|
---|
3640 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3641 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3642 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3643 | */
|
---|
3644 | bool SerialPort::operator==(const SerialPort &s) const
|
---|
3645 | {
|
---|
3646 | return (this == &s)
|
---|
3647 | || ( ulSlot == s.ulSlot
|
---|
3648 | && fEnabled == s.fEnabled
|
---|
3649 | && ulIOBase == s.ulIOBase
|
---|
3650 | && ulIRQ == s.ulIRQ
|
---|
3651 | && portMode == s.portMode
|
---|
3652 | && strPath == s.strPath
|
---|
3653 | && fServer == s.fServer
|
---|
3654 | && uartType == s.uartType);
|
---|
3655 | }
|
---|
3656 |
|
---|
3657 | /**
|
---|
3658 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3659 | */
|
---|
3660 | ParallelPort::ParallelPort() :
|
---|
3661 | ulSlot(0),
|
---|
3662 | fEnabled(false),
|
---|
3663 | ulIOBase(0x378),
|
---|
3664 | ulIRQ(7)
|
---|
3665 | {
|
---|
3666 | }
|
---|
3667 |
|
---|
3668 | /**
|
---|
3669 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3670 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3671 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3672 | */
|
---|
3673 | bool ParallelPort::operator==(const ParallelPort &s) const
|
---|
3674 | {
|
---|
3675 | return (this == &s)
|
---|
3676 | || ( ulSlot == s.ulSlot
|
---|
3677 | && fEnabled == s.fEnabled
|
---|
3678 | && ulIOBase == s.ulIOBase
|
---|
3679 | && ulIRQ == s.ulIRQ
|
---|
3680 | && strPath == s.strPath);
|
---|
3681 | }
|
---|
3682 |
|
---|
3683 | /**
|
---|
3684 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3685 | */
|
---|
3686 | AudioAdapter::AudioAdapter() :
|
---|
3687 | fEnabled(true), // default for old VMs, for new ones it's false
|
---|
3688 | fEnabledIn(true), // default for old VMs, for new ones it's false
|
---|
3689 | fEnabledOut(true), // default for old VMs, for new ones it's false
|
---|
3690 | controllerType(AudioControllerType_AC97),
|
---|
3691 | codecType(AudioCodecType_STAC9700),
|
---|
3692 | driverType(AudioDriverType_Null)
|
---|
3693 | {
|
---|
3694 | }
|
---|
3695 |
|
---|
3696 | /**
|
---|
3697 | * Check if all settings have default values.
|
---|
3698 | */
|
---|
3699 | bool AudioAdapter::areDefaultSettings(SettingsVersion_T sv) const
|
---|
3700 | {
|
---|
3701 | return (sv < SettingsVersion_v1_16 ? false : !fEnabled)
|
---|
3702 | && (sv <= SettingsVersion_v1_16 ? fEnabledIn : !fEnabledIn)
|
---|
3703 | && (sv <= SettingsVersion_v1_16 ? fEnabledOut : !fEnabledOut)
|
---|
3704 | && fEnabledOut == true
|
---|
3705 | && controllerType == AudioControllerType_AC97
|
---|
3706 | && codecType == AudioCodecType_STAC9700
|
---|
3707 | && properties.size() == 0;
|
---|
3708 | }
|
---|
3709 |
|
---|
3710 | /**
|
---|
3711 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3712 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3713 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3714 | */
|
---|
3715 | bool AudioAdapter::operator==(const AudioAdapter &a) const
|
---|
3716 | {
|
---|
3717 | return (this == &a)
|
---|
3718 | || ( fEnabled == a.fEnabled
|
---|
3719 | && fEnabledIn == a.fEnabledIn
|
---|
3720 | && fEnabledOut == a.fEnabledOut
|
---|
3721 | && controllerType == a.controllerType
|
---|
3722 | && codecType == a.codecType
|
---|
3723 | && driverType == a.driverType
|
---|
3724 | && properties == a.properties);
|
---|
3725 | }
|
---|
3726 |
|
---|
3727 | /**
|
---|
3728 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3729 | */
|
---|
3730 | SharedFolder::SharedFolder() :
|
---|
3731 | fWritable(false),
|
---|
3732 | fAutoMount(false)
|
---|
3733 | {
|
---|
3734 | }
|
---|
3735 |
|
---|
3736 | /**
|
---|
3737 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3738 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3739 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3740 | */
|
---|
3741 | bool SharedFolder::operator==(const SharedFolder &g) const
|
---|
3742 | {
|
---|
3743 | return (this == &g)
|
---|
3744 | || ( strName == g.strName
|
---|
3745 | && strHostPath == g.strHostPath
|
---|
3746 | && fWritable == g.fWritable
|
---|
3747 | && fAutoMount == g.fAutoMount
|
---|
3748 | && strAutoMountPoint == g.strAutoMountPoint);
|
---|
3749 | }
|
---|
3750 |
|
---|
3751 | /**
|
---|
3752 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3753 | */
|
---|
3754 | GuestProperty::GuestProperty() :
|
---|
3755 | timestamp(0)
|
---|
3756 | {
|
---|
3757 | }
|
---|
3758 |
|
---|
3759 | /**
|
---|
3760 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3761 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3762 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3763 | */
|
---|
3764 | bool GuestProperty::operator==(const GuestProperty &g) const
|
---|
3765 | {
|
---|
3766 | return (this == &g)
|
---|
3767 | || ( strName == g.strName
|
---|
3768 | && strValue == g.strValue
|
---|
3769 | && timestamp == g.timestamp
|
---|
3770 | && strFlags == g.strFlags);
|
---|
3771 | }
|
---|
3772 |
|
---|
3773 | /**
|
---|
3774 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3775 | */
|
---|
3776 | CpuIdLeaf::CpuIdLeaf() :
|
---|
3777 | idx(UINT32_MAX),
|
---|
3778 | idxSub(0),
|
---|
3779 | uEax(0),
|
---|
3780 | uEbx(0),
|
---|
3781 | uEcx(0),
|
---|
3782 | uEdx(0)
|
---|
3783 | {
|
---|
3784 | }
|
---|
3785 |
|
---|
3786 | /**
|
---|
3787 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3788 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3789 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3790 | */
|
---|
3791 | bool CpuIdLeaf::operator==(const CpuIdLeaf &c) const
|
---|
3792 | {
|
---|
3793 | return (this == &c)
|
---|
3794 | || ( idx == c.idx
|
---|
3795 | && idxSub == c.idxSub
|
---|
3796 | && uEax == c.uEax
|
---|
3797 | && uEbx == c.uEbx
|
---|
3798 | && uEcx == c.uEcx
|
---|
3799 | && uEdx == c.uEdx);
|
---|
3800 | }
|
---|
3801 |
|
---|
3802 | /**
|
---|
3803 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3804 | */
|
---|
3805 | Cpu::Cpu() :
|
---|
3806 | ulId(UINT32_MAX)
|
---|
3807 | {
|
---|
3808 | }
|
---|
3809 |
|
---|
3810 | /**
|
---|
3811 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3812 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3813 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3814 | */
|
---|
3815 | bool Cpu::operator==(const Cpu &c) const
|
---|
3816 | {
|
---|
3817 | return (this == &c)
|
---|
3818 | || (ulId == c.ulId);
|
---|
3819 | }
|
---|
3820 |
|
---|
3821 | /**
|
---|
3822 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3823 | */
|
---|
3824 | BandwidthGroup::BandwidthGroup() :
|
---|
3825 | cMaxBytesPerSec(0),
|
---|
3826 | enmType(BandwidthGroupType_Null)
|
---|
3827 | {
|
---|
3828 | }
|
---|
3829 |
|
---|
3830 | /**
|
---|
3831 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3832 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3833 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3834 | */
|
---|
3835 | bool BandwidthGroup::operator==(const BandwidthGroup &i) const
|
---|
3836 | {
|
---|
3837 | return (this == &i)
|
---|
3838 | || ( strName == i.strName
|
---|
3839 | && cMaxBytesPerSec == i.cMaxBytesPerSec
|
---|
3840 | && enmType == i.enmType);
|
---|
3841 | }
|
---|
3842 |
|
---|
3843 | /**
|
---|
3844 | * IOSettings constructor.
|
---|
3845 | */
|
---|
3846 | IOSettings::IOSettings() :
|
---|
3847 | fIOCacheEnabled(true),
|
---|
3848 | ulIOCacheSize(5)
|
---|
3849 | {
|
---|
3850 | }
|
---|
3851 |
|
---|
3852 | /**
|
---|
3853 | * Check if all IO Cache settings have default values.
|
---|
3854 | */
|
---|
3855 | bool IOSettings::areIOCacheDefaultSettings() const
|
---|
3856 | {
|
---|
3857 | return fIOCacheEnabled
|
---|
3858 | && ulIOCacheSize == 5;
|
---|
3859 | }
|
---|
3860 |
|
---|
3861 | /**
|
---|
3862 | * Check if all settings have default values.
|
---|
3863 | */
|
---|
3864 | bool IOSettings::areDefaultSettings() const
|
---|
3865 | {
|
---|
3866 | return areIOCacheDefaultSettings()
|
---|
3867 | && llBandwidthGroups.size() == 0;
|
---|
3868 | }
|
---|
3869 |
|
---|
3870 | /**
|
---|
3871 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3872 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3873 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3874 | */
|
---|
3875 | bool IOSettings::operator==(const IOSettings &i) const
|
---|
3876 | {
|
---|
3877 | return (this == &i)
|
---|
3878 | || ( fIOCacheEnabled == i.fIOCacheEnabled
|
---|
3879 | && ulIOCacheSize == i.ulIOCacheSize
|
---|
3880 | && llBandwidthGroups == i.llBandwidthGroups);
|
---|
3881 | }
|
---|
3882 |
|
---|
3883 | /**
|
---|
3884 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3885 | */
|
---|
3886 | HostPCIDeviceAttachment::HostPCIDeviceAttachment() :
|
---|
3887 | uHostAddress(0),
|
---|
3888 | uGuestAddress(0)
|
---|
3889 | {
|
---|
3890 | }
|
---|
3891 |
|
---|
3892 | /**
|
---|
3893 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
3894 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
3895 | * machine settings have really changed and thus need to be written out to disk.
|
---|
3896 | */
|
---|
3897 | bool HostPCIDeviceAttachment::operator==(const HostPCIDeviceAttachment &a) const
|
---|
3898 | {
|
---|
3899 | return (this == &a)
|
---|
3900 | || ( uHostAddress == a.uHostAddress
|
---|
3901 | && uGuestAddress == a.uGuestAddress
|
---|
3902 | && strDeviceName == a.strDeviceName);
|
---|
3903 | }
|
---|
3904 |
|
---|
3905 |
|
---|
3906 | /**
|
---|
3907 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
3908 | */
|
---|
3909 | Hardware::Hardware() :
|
---|
3910 | strVersion("1"),
|
---|
3911 | fHardwareVirt(true),
|
---|
3912 | fNestedPaging(true),
|
---|
3913 | fVPID(true),
|
---|
3914 | fUnrestrictedExecution(true),
|
---|
3915 | fHardwareVirtForce(false),
|
---|
3916 | fUseNativeApi(false),
|
---|
3917 | fTripleFaultReset(false),
|
---|
3918 | fPAE(false),
|
---|
3919 | fAPIC(true),
|
---|
3920 | fX2APIC(false),
|
---|
3921 | fIBPBOnVMExit(false),
|
---|
3922 | fIBPBOnVMEntry(false),
|
---|
3923 | fSpecCtrl(false),
|
---|
3924 | fSpecCtrlByHost(false),
|
---|
3925 | fL1DFlushOnSched(true),
|
---|
3926 | fL1DFlushOnVMEntry(false),
|
---|
3927 | fMDSClearOnSched(true),
|
---|
3928 | fMDSClearOnVMEntry(false),
|
---|
3929 | fNestedHWVirt(false),
|
---|
3930 | fVirtVmsaveVmload(true),
|
---|
3931 | enmLongMode(HC_ARCH_BITS == 64 ? Hardware::LongMode_Enabled : Hardware::LongMode_Disabled),
|
---|
3932 | cCPUs(1),
|
---|
3933 | fCpuHotPlug(false),
|
---|
3934 | fHPETEnabled(false),
|
---|
3935 | ulCpuExecutionCap(100),
|
---|
3936 | uCpuIdPortabilityLevel(0),
|
---|
3937 | strCpuProfile("host"),
|
---|
3938 | ulMemorySizeMB((uint32_t)-1),
|
---|
3939 | firmwareType(FirmwareType_BIOS),
|
---|
3940 | pointingHIDType(PointingHIDType_PS2Mouse),
|
---|
3941 | keyboardHIDType(KeyboardHIDType_PS2Keyboard),
|
---|
3942 | chipsetType(ChipsetType_PIIX3),
|
---|
3943 | iommuType(IommuType_None),
|
---|
3944 | paravirtProvider(ParavirtProvider_Legacy), // default for old VMs, for new ones it's ParavirtProvider_Default
|
---|
3945 | strParavirtDebug(""),
|
---|
3946 | fEmulatedUSBCardReader(false),
|
---|
3947 | clipboardMode(ClipboardMode_Disabled),
|
---|
3948 | fClipboardFileTransfersEnabled(false),
|
---|
3949 | dndMode(DnDMode_Disabled),
|
---|
3950 | ulMemoryBalloonSize(0),
|
---|
3951 | fPageFusionEnabled(false)
|
---|
3952 | {
|
---|
3953 | mapBootOrder[0] = DeviceType_Floppy;
|
---|
3954 | mapBootOrder[1] = DeviceType_DVD;
|
---|
3955 | mapBootOrder[2] = DeviceType_HardDisk;
|
---|
3956 |
|
---|
3957 | /* The default value for PAE depends on the host:
|
---|
3958 | * - 64 bits host -> always true
|
---|
3959 | * - 32 bits host -> true for Windows & Darwin (masked off if the host cpu doesn't support it anyway)
|
---|
3960 | */
|
---|
3961 | #if HC_ARCH_BITS == 64 || defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN)
|
---|
3962 | fPAE = true;
|
---|
3963 | #endif
|
---|
3964 |
|
---|
3965 | /* The default value of large page supports depends on the host:
|
---|
3966 | * - 64 bits host -> true, unless it's Linux (pending further prediction work due to excessively expensive large page allocations)
|
---|
3967 | * - 32 bits host -> false
|
---|
3968 | */
|
---|
3969 | #if HC_ARCH_BITS == 64 && !defined(RT_OS_LINUX)
|
---|
3970 | fLargePages = true;
|
---|
3971 | #else
|
---|
3972 | /* Not supported on 32 bits hosts. */
|
---|
3973 | fLargePages = false;
|
---|
3974 | #endif
|
---|
3975 | }
|
---|
3976 |
|
---|
3977 | /**
|
---|
3978 | * Check if all Paravirt settings have default values.
|
---|
3979 | */
|
---|
3980 | bool Hardware::areParavirtDefaultSettings(SettingsVersion_T sv) const
|
---|
3981 | {
|
---|
3982 | // 5.0 didn't save the paravirt settings if it is ParavirtProvider_Legacy,
|
---|
3983 | // so this default must be kept. Later versions don't save the setting if
|
---|
3984 | // it's at the default value.
|
---|
3985 | return ( (sv >= SettingsVersion_v1_16 && paravirtProvider == ParavirtProvider_Default)
|
---|
3986 | || (sv < SettingsVersion_v1_16 && paravirtProvider == ParavirtProvider_Legacy))
|
---|
3987 | && strParavirtDebug.isEmpty();
|
---|
3988 | }
|
---|
3989 |
|
---|
3990 | /**
|
---|
3991 | * Check if all Boot Order settings have default values.
|
---|
3992 | */
|
---|
3993 | bool Hardware::areBootOrderDefaultSettings() const
|
---|
3994 | {
|
---|
3995 | BootOrderMap::const_iterator it0 = mapBootOrder.find(0);
|
---|
3996 | BootOrderMap::const_iterator it1 = mapBootOrder.find(1);
|
---|
3997 | BootOrderMap::const_iterator it2 = mapBootOrder.find(2);
|
---|
3998 | BootOrderMap::const_iterator it3 = mapBootOrder.find(3);
|
---|
3999 | return ( mapBootOrder.size() == 3
|
---|
4000 | || ( mapBootOrder.size() == 4
|
---|
4001 | && (it3 != mapBootOrder.end() && it3->second == DeviceType_Null)))
|
---|
4002 | && (it0 != mapBootOrder.end() && it0->second == DeviceType_Floppy)
|
---|
4003 | && (it1 != mapBootOrder.end() && it1->second == DeviceType_DVD)
|
---|
4004 | && (it2 != mapBootOrder.end() && it2->second == DeviceType_HardDisk);
|
---|
4005 | }
|
---|
4006 |
|
---|
4007 | /**
|
---|
4008 | * Check if all Network Adapter settings have default values.
|
---|
4009 | */
|
---|
4010 | bool Hardware::areAllNetworkAdaptersDefaultSettings(SettingsVersion_T sv) const
|
---|
4011 | {
|
---|
4012 | for (NetworkAdaptersList::const_iterator it = llNetworkAdapters.begin();
|
---|
4013 | it != llNetworkAdapters.end();
|
---|
4014 | ++it)
|
---|
4015 | {
|
---|
4016 | if (!it->areDefaultSettings(sv))
|
---|
4017 | return false;
|
---|
4018 | }
|
---|
4019 | return true;
|
---|
4020 | }
|
---|
4021 |
|
---|
4022 | /**
|
---|
4023 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4024 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4025 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4026 | */
|
---|
4027 | bool Hardware::operator==(const Hardware& h) const
|
---|
4028 | {
|
---|
4029 | return (this == &h)
|
---|
4030 | || ( strVersion == h.strVersion
|
---|
4031 | && uuid == h.uuid
|
---|
4032 | && fHardwareVirt == h.fHardwareVirt
|
---|
4033 | && fNestedPaging == h.fNestedPaging
|
---|
4034 | && fLargePages == h.fLargePages
|
---|
4035 | && fVPID == h.fVPID
|
---|
4036 | && fUnrestrictedExecution == h.fUnrestrictedExecution
|
---|
4037 | && fHardwareVirtForce == h.fHardwareVirtForce
|
---|
4038 | && fUseNativeApi == h.fUseNativeApi
|
---|
4039 | && fPAE == h.fPAE
|
---|
4040 | && enmLongMode == h.enmLongMode
|
---|
4041 | && fTripleFaultReset == h.fTripleFaultReset
|
---|
4042 | && fAPIC == h.fAPIC
|
---|
4043 | && fX2APIC == h.fX2APIC
|
---|
4044 | && fIBPBOnVMExit == h.fIBPBOnVMExit
|
---|
4045 | && fIBPBOnVMEntry == h.fIBPBOnVMEntry
|
---|
4046 | && fSpecCtrl == h.fSpecCtrl
|
---|
4047 | && fSpecCtrlByHost == h.fSpecCtrlByHost
|
---|
4048 | && fL1DFlushOnSched == h.fL1DFlushOnSched
|
---|
4049 | && fL1DFlushOnVMEntry == h.fL1DFlushOnVMEntry
|
---|
4050 | && fMDSClearOnSched == h.fMDSClearOnSched
|
---|
4051 | && fMDSClearOnVMEntry == h.fMDSClearOnVMEntry
|
---|
4052 | && fNestedHWVirt == h.fNestedHWVirt
|
---|
4053 | && fVirtVmsaveVmload == h.fVirtVmsaveVmload
|
---|
4054 | && cCPUs == h.cCPUs
|
---|
4055 | && fCpuHotPlug == h.fCpuHotPlug
|
---|
4056 | && ulCpuExecutionCap == h.ulCpuExecutionCap
|
---|
4057 | && uCpuIdPortabilityLevel == h.uCpuIdPortabilityLevel
|
---|
4058 | && strCpuProfile == h.strCpuProfile
|
---|
4059 | && fHPETEnabled == h.fHPETEnabled
|
---|
4060 | && llCpus == h.llCpus
|
---|
4061 | && llCpuIdLeafs == h.llCpuIdLeafs
|
---|
4062 | && ulMemorySizeMB == h.ulMemorySizeMB
|
---|
4063 | && mapBootOrder == h.mapBootOrder
|
---|
4064 | && firmwareType == h.firmwareType
|
---|
4065 | && pointingHIDType == h.pointingHIDType
|
---|
4066 | && keyboardHIDType == h.keyboardHIDType
|
---|
4067 | && chipsetType == h.chipsetType
|
---|
4068 | && iommuType == h.iommuType
|
---|
4069 | && paravirtProvider == h.paravirtProvider
|
---|
4070 | && strParavirtDebug == h.strParavirtDebug
|
---|
4071 | && fEmulatedUSBCardReader == h.fEmulatedUSBCardReader
|
---|
4072 | && vrdeSettings == h.vrdeSettings
|
---|
4073 | && biosSettings == h.biosSettings
|
---|
4074 | && nvramSettings == h.nvramSettings
|
---|
4075 | && graphicsAdapter == h.graphicsAdapter
|
---|
4076 | && usbSettings == h.usbSettings
|
---|
4077 | && tpmSettings == h.tpmSettings
|
---|
4078 | && llNetworkAdapters == h.llNetworkAdapters
|
---|
4079 | && llSerialPorts == h.llSerialPorts
|
---|
4080 | && llParallelPorts == h.llParallelPorts
|
---|
4081 | && audioAdapter == h.audioAdapter
|
---|
4082 | && storage == h.storage
|
---|
4083 | && llSharedFolders == h.llSharedFolders
|
---|
4084 | && clipboardMode == h.clipboardMode
|
---|
4085 | && fClipboardFileTransfersEnabled == h.fClipboardFileTransfersEnabled
|
---|
4086 | && dndMode == h.dndMode
|
---|
4087 | && ulMemoryBalloonSize == h.ulMemoryBalloonSize
|
---|
4088 | && fPageFusionEnabled == h.fPageFusionEnabled
|
---|
4089 | && llGuestProperties == h.llGuestProperties
|
---|
4090 | && ioSettings == h.ioSettings
|
---|
4091 | && pciAttachments == h.pciAttachments
|
---|
4092 | && strDefaultFrontend == h.strDefaultFrontend);
|
---|
4093 | }
|
---|
4094 |
|
---|
4095 | /**
|
---|
4096 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4097 | */
|
---|
4098 | AttachedDevice::AttachedDevice() :
|
---|
4099 | deviceType(DeviceType_Null),
|
---|
4100 | fPassThrough(false),
|
---|
4101 | fTempEject(false),
|
---|
4102 | fNonRotational(false),
|
---|
4103 | fDiscard(false),
|
---|
4104 | fHotPluggable(false),
|
---|
4105 | lPort(0),
|
---|
4106 | lDevice(0)
|
---|
4107 | {
|
---|
4108 | }
|
---|
4109 |
|
---|
4110 | /**
|
---|
4111 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4112 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4113 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4114 | */
|
---|
4115 | bool AttachedDevice::operator==(const AttachedDevice &a) const
|
---|
4116 | {
|
---|
4117 | return (this == &a)
|
---|
4118 | || ( deviceType == a.deviceType
|
---|
4119 | && fPassThrough == a.fPassThrough
|
---|
4120 | && fTempEject == a.fTempEject
|
---|
4121 | && fNonRotational == a.fNonRotational
|
---|
4122 | && fDiscard == a.fDiscard
|
---|
4123 | && fHotPluggable == a.fHotPluggable
|
---|
4124 | && lPort == a.lPort
|
---|
4125 | && lDevice == a.lDevice
|
---|
4126 | && uuid == a.uuid
|
---|
4127 | && strHostDriveSrc == a.strHostDriveSrc
|
---|
4128 | && strBwGroup == a.strBwGroup);
|
---|
4129 | }
|
---|
4130 |
|
---|
4131 | /**
|
---|
4132 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4133 | */
|
---|
4134 | StorageController::StorageController() :
|
---|
4135 | storageBus(StorageBus_IDE),
|
---|
4136 | controllerType(StorageControllerType_PIIX3),
|
---|
4137 | ulPortCount(2),
|
---|
4138 | ulInstance(0),
|
---|
4139 | fUseHostIOCache(true),
|
---|
4140 | fBootable(true)
|
---|
4141 | {
|
---|
4142 | }
|
---|
4143 |
|
---|
4144 | /**
|
---|
4145 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4146 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4147 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4148 | */
|
---|
4149 | bool StorageController::operator==(const StorageController &s) const
|
---|
4150 | {
|
---|
4151 | return (this == &s)
|
---|
4152 | || ( strName == s.strName
|
---|
4153 | && storageBus == s.storageBus
|
---|
4154 | && controllerType == s.controllerType
|
---|
4155 | && ulPortCount == s.ulPortCount
|
---|
4156 | && ulInstance == s.ulInstance
|
---|
4157 | && fUseHostIOCache == s.fUseHostIOCache
|
---|
4158 | && llAttachedDevices == s.llAttachedDevices);
|
---|
4159 | }
|
---|
4160 |
|
---|
4161 | /**
|
---|
4162 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4163 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4164 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4165 | */
|
---|
4166 | bool Storage::operator==(const Storage &s) const
|
---|
4167 | {
|
---|
4168 | return (this == &s)
|
---|
4169 | || (llStorageControllers == s.llStorageControllers); // deep compare
|
---|
4170 | }
|
---|
4171 |
|
---|
4172 | /**
|
---|
4173 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4174 | */
|
---|
4175 | Debugging::Debugging() :
|
---|
4176 | fTracingEnabled(false),
|
---|
4177 | fAllowTracingToAccessVM(false),
|
---|
4178 | strTracingConfig(),
|
---|
4179 | enmDbgProvider(GuestDebugProvider_None),
|
---|
4180 | enmIoProvider(GuestDebugIoProvider_None),
|
---|
4181 | strAddress(),
|
---|
4182 | ulPort(0)
|
---|
4183 | {
|
---|
4184 | }
|
---|
4185 |
|
---|
4186 | /**
|
---|
4187 | * Check if all settings have default values.
|
---|
4188 | */
|
---|
4189 | bool Debugging::areDefaultSettings() const
|
---|
4190 | {
|
---|
4191 | return !fTracingEnabled
|
---|
4192 | && !fAllowTracingToAccessVM
|
---|
4193 | && strTracingConfig.isEmpty()
|
---|
4194 | && enmDbgProvider == GuestDebugProvider_None
|
---|
4195 | && enmIoProvider == GuestDebugIoProvider_None
|
---|
4196 | && strAddress.isEmpty()
|
---|
4197 | && ulPort == 0;
|
---|
4198 | }
|
---|
4199 |
|
---|
4200 | /**
|
---|
4201 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4202 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4203 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4204 | */
|
---|
4205 | bool Debugging::operator==(const Debugging &d) const
|
---|
4206 | {
|
---|
4207 | return (this == &d)
|
---|
4208 | || ( fTracingEnabled == d.fTracingEnabled
|
---|
4209 | && fAllowTracingToAccessVM == d.fAllowTracingToAccessVM
|
---|
4210 | && strTracingConfig == d.strTracingConfig
|
---|
4211 | && enmDbgProvider == d.enmDbgProvider
|
---|
4212 | && enmIoProvider == d.enmIoProvider
|
---|
4213 | && strAddress == d.strAddress
|
---|
4214 | && ulPort == d.ulPort);
|
---|
4215 | }
|
---|
4216 |
|
---|
4217 | /**
|
---|
4218 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4219 | */
|
---|
4220 | Autostart::Autostart() :
|
---|
4221 | fAutostartEnabled(false),
|
---|
4222 | uAutostartDelay(0),
|
---|
4223 | enmAutostopType(AutostopType_Disabled)
|
---|
4224 | {
|
---|
4225 | }
|
---|
4226 |
|
---|
4227 | /**
|
---|
4228 | * Check if all settings have default values.
|
---|
4229 | */
|
---|
4230 | bool Autostart::areDefaultSettings() const
|
---|
4231 | {
|
---|
4232 | return !fAutostartEnabled
|
---|
4233 | && !uAutostartDelay
|
---|
4234 | && enmAutostopType == AutostopType_Disabled;
|
---|
4235 | }
|
---|
4236 |
|
---|
4237 | /**
|
---|
4238 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4239 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4240 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4241 | */
|
---|
4242 | bool Autostart::operator==(const Autostart &a) const
|
---|
4243 | {
|
---|
4244 | return (this == &a)
|
---|
4245 | || ( fAutostartEnabled == a.fAutostartEnabled
|
---|
4246 | && uAutostartDelay == a.uAutostartDelay
|
---|
4247 | && enmAutostopType == a.enmAutostopType);
|
---|
4248 | }
|
---|
4249 |
|
---|
4250 | /**
|
---|
4251 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4252 | */
|
---|
4253 | Snapshot::Snapshot()
|
---|
4254 | {
|
---|
4255 | RTTimeSpecSetNano(×tamp, 0);
|
---|
4256 | }
|
---|
4257 |
|
---|
4258 | /**
|
---|
4259 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4260 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4261 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4262 | */
|
---|
4263 | bool Snapshot::operator==(const Snapshot &s) const
|
---|
4264 | {
|
---|
4265 | return (this == &s)
|
---|
4266 | || ( uuid == s.uuid
|
---|
4267 | && strName == s.strName
|
---|
4268 | && strDescription == s.strDescription
|
---|
4269 | && RTTimeSpecIsEqual(×tamp, &s.timestamp)
|
---|
4270 | && strStateFile == s.strStateFile
|
---|
4271 | && hardware == s.hardware // deep compare
|
---|
4272 | && recordingSettings == s.recordingSettings // deep compare
|
---|
4273 | && llChildSnapshots == s.llChildSnapshots // deep compare
|
---|
4274 | && debugging == s.debugging
|
---|
4275 | && autostart == s.autostart);
|
---|
4276 | }
|
---|
4277 |
|
---|
4278 | const struct Snapshot settings::Snapshot::Empty; /* default ctor is OK */
|
---|
4279 |
|
---|
4280 | /**
|
---|
4281 | * Constructor. Needs to set sane defaults which stand the test of time.
|
---|
4282 | */
|
---|
4283 | MachineUserData::MachineUserData() :
|
---|
4284 | fDirectoryIncludesUUID(false),
|
---|
4285 | fNameSync(true),
|
---|
4286 | fTeleporterEnabled(false),
|
---|
4287 | uTeleporterPort(0),
|
---|
4288 | fRTCUseUTC(false),
|
---|
4289 | enmVMPriority(VMProcPriority_Default)
|
---|
4290 | {
|
---|
4291 | llGroups.push_back("/");
|
---|
4292 | }
|
---|
4293 |
|
---|
4294 | /**
|
---|
4295 | * Comparison operator. This gets called from MachineConfigFile::operator==,
|
---|
4296 | * which in turn gets called from Machine::saveSettings to figure out whether
|
---|
4297 | * machine settings have really changed and thus need to be written out to disk.
|
---|
4298 | */
|
---|
4299 | bool MachineUserData::operator==(const MachineUserData &c) const
|
---|
4300 | {
|
---|
4301 | return (this == &c)
|
---|
4302 | || ( strName == c.strName
|
---|
4303 | && fDirectoryIncludesUUID == c.fDirectoryIncludesUUID
|
---|
4304 | && fNameSync == c.fNameSync
|
---|
4305 | && strDescription == c.strDescription
|
---|
4306 | && llGroups == c.llGroups
|
---|
4307 | && strOsType == c.strOsType
|
---|
4308 | && strSnapshotFolder == c.strSnapshotFolder
|
---|
4309 | && fTeleporterEnabled == c.fTeleporterEnabled
|
---|
4310 | && uTeleporterPort == c.uTeleporterPort
|
---|
4311 | && strTeleporterAddress == c.strTeleporterAddress
|
---|
4312 | && strTeleporterPassword == c.strTeleporterPassword
|
---|
4313 | && fRTCUseUTC == c.fRTCUseUTC
|
---|
4314 | && ovIcon == c.ovIcon
|
---|
4315 | && enmVMPriority == c.enmVMPriority);
|
---|
4316 | }
|
---|
4317 |
|
---|
4318 |
|
---|
4319 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4320 | //
|
---|
4321 | // MachineConfigFile
|
---|
4322 | //
|
---|
4323 | ////////////////////////////////////////////////////////////////////////////////
|
---|
4324 |
|
---|
4325 | /**
|
---|
4326 | * Constructor.
|
---|
4327 | *
|
---|
4328 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
4329 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
4330 | * are initialized with default values.
|
---|
4331 | *
|
---|
4332 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
4333 | * the caller should catch; if this constructor does not throw, then the member
|
---|
4334 | * variables contain meaningful values (either from the file or defaults).
|
---|
4335 | *
|
---|
4336 | * @param pstrFilename
|
---|
4337 | * @param pCryptoIf Pointer to the cryptographic interface, required for an encrypted machine config.
|
---|
4338 | * @param pszPassword The password to use for an encrypted machine config.
|
---|
4339 | */
|
---|
4340 | MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename, PCVBOXCRYPTOIF pCryptoIf, const char *pszPassword)
|
---|
4341 | : ConfigFileBase(pstrFilename),
|
---|
4342 | enmParseState(ParseState_NotParsed),
|
---|
4343 | fCurrentStateModified(true),
|
---|
4344 | fAborted(false)
|
---|
4345 | {
|
---|
4346 | RTTimeNow(&timeLastStateChange);
|
---|
4347 |
|
---|
4348 | if (pstrFilename)
|
---|
4349 | {
|
---|
4350 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
4351 | // we need only analyze what is in there
|
---|
4352 |
|
---|
4353 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
4354 | const xml::ElementNode *pelmRootChild;
|
---|
4355 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
4356 | {
|
---|
4357 | if (pelmRootChild->nameEquals("MachineEncrypted"))
|
---|
4358 | readMachineEncrypted(*pelmRootChild, pCryptoIf, pszPassword);
|
---|
4359 | if (pelmRootChild->nameEquals("Machine"))
|
---|
4360 | readMachine(*pelmRootChild);
|
---|
4361 | }
|
---|
4362 |
|
---|
4363 | // clean up memory allocated by XML engine
|
---|
4364 | clearDocument();
|
---|
4365 |
|
---|
4366 | if (enmParseState == ParseState_NotParsed)
|
---|
4367 | enmParseState = ParseState_Parsed;
|
---|
4368 | }
|
---|
4369 | }
|
---|
4370 |
|
---|
4371 | /**
|
---|
4372 | * Public routine which returns true if this machine config file can have its
|
---|
4373 | * own media registry (which is true for settings version v1.11 and higher,
|
---|
4374 | * i.e. files created by VirtualBox 4.0 and higher).
|
---|
4375 | * @return
|
---|
4376 | */
|
---|
4377 | bool MachineConfigFile::canHaveOwnMediaRegistry() const
|
---|
4378 | {
|
---|
4379 | return (m->sv >= SettingsVersion_v1_11);
|
---|
4380 | }
|
---|
4381 |
|
---|
4382 | /**
|
---|
4383 | * Public routine which copies encryption settings. Used by Machine::saveSettings
|
---|
4384 | * so that the encryption settings do not get lost when a copy of the Machine settings
|
---|
4385 | * file is made to see if settings have actually changed.
|
---|
4386 | * @param other
|
---|
4387 | */
|
---|
4388 | void MachineConfigFile::copyEncryptionSettingsFrom(const MachineConfigFile &other)
|
---|
4389 | {
|
---|
4390 | strKeyId = other.strKeyId;
|
---|
4391 | strKeyStore = other.strKeyStore;
|
---|
4392 | }
|
---|
4393 |
|
---|
4394 | /**
|
---|
4395 | * Public routine which allows for importing machine XML from an external DOM tree.
|
---|
4396 | * Use this after having called the constructor with a NULL argument.
|
---|
4397 | *
|
---|
4398 | * This is used by the OVF code if a <vbox:Machine> element has been encountered
|
---|
4399 | * in an OVF VirtualSystem element.
|
---|
4400 | *
|
---|
4401 | * @param elmMachine
|
---|
4402 | */
|
---|
4403 | void MachineConfigFile::importMachineXML(const xml::ElementNode &elmMachine)
|
---|
4404 | {
|
---|
4405 | // Ideally the version should be mandatory, but since VirtualBox didn't
|
---|
4406 | // care about it until 5.1 came with different defaults, there are OVF
|
---|
4407 | // files created by magicians (not using VirtualBox, which always wrote it)
|
---|
4408 | // which lack this information. Let's hope that they learn to add the
|
---|
4409 | // version when they switch to the newer settings style/defaults of 5.1.
|
---|
4410 | if (!(elmMachine.getAttributeValue("version", m->strSettingsVersionFull)))
|
---|
4411 | m->strSettingsVersionFull = VBOX_XML_IMPORT_VERSION_FULL;
|
---|
4412 |
|
---|
4413 | LogRel(("Import settings with version \"%s\"\n", m->strSettingsVersionFull.c_str()));
|
---|
4414 |
|
---|
4415 | m->sv = parseVersion(m->strSettingsVersionFull, &elmMachine);
|
---|
4416 |
|
---|
4417 | // remember the settings version we read in case it gets upgraded later,
|
---|
4418 | // so we know when to make backups
|
---|
4419 | m->svRead = m->sv;
|
---|
4420 |
|
---|
4421 | readMachine(elmMachine);
|
---|
4422 | }
|
---|
4423 |
|
---|
4424 | /**
|
---|
4425 | * Comparison operator. This gets called from Machine::saveSettings to figure out
|
---|
4426 | * whether machine settings have really changed and thus need to be written out to disk.
|
---|
4427 | *
|
---|
4428 | * Even though this is called operator==, this does NOT compare all fields; the "equals"
|
---|
4429 | * should be understood as "has the same machine config as". The following fields are
|
---|
4430 | * NOT compared:
|
---|
4431 | * -- settings versions and file names inherited from ConfigFileBase;
|
---|
4432 | * -- fCurrentStateModified because that is considered separately in Machine::saveSettings!!
|
---|
4433 | *
|
---|
4434 | * The "deep" comparisons marked below will invoke the operator== functions of the
|
---|
4435 | * structs defined in this file, which may in turn go into comparing lists of
|
---|
4436 | * other structures. As a result, invoking this can be expensive, but it's
|
---|
4437 | * less expensive than writing out XML to disk.
|
---|
4438 | */
|
---|
4439 | bool MachineConfigFile::operator==(const MachineConfigFile &c) const
|
---|
4440 | {
|
---|
4441 | return (this == &c)
|
---|
4442 | || ( uuid == c.uuid
|
---|
4443 | && machineUserData == c.machineUserData
|
---|
4444 | && strStateFile == c.strStateFile
|
---|
4445 | && uuidCurrentSnapshot == c.uuidCurrentSnapshot
|
---|
4446 | // skip fCurrentStateModified!
|
---|
4447 | && RTTimeSpecIsEqual(&timeLastStateChange, &c.timeLastStateChange)
|
---|
4448 | && fAborted == c.fAborted
|
---|
4449 | && hardwareMachine == c.hardwareMachine // this one's deep
|
---|
4450 | && mediaRegistry == c.mediaRegistry // this one's deep
|
---|
4451 | // skip mapExtraDataItems! there is no old state available as it's always forced
|
---|
4452 | && llFirstSnapshot == c.llFirstSnapshot // this one's deep
|
---|
4453 | && recordingSettings == c.recordingSettings // this one's deep
|
---|
4454 | && strKeyId == c.strKeyId
|
---|
4455 | && strKeyStore == c.strKeyStore
|
---|
4456 | && strStateKeyId == c.strStateKeyId
|
---|
4457 | && strStateKeyStore == c.strStateKeyStore
|
---|
4458 | && strLogKeyId == c.strLogKeyId
|
---|
4459 | && strLogKeyStore == c.strLogKeyStore);
|
---|
4460 | }
|
---|
4461 |
|
---|
4462 | /**
|
---|
4463 | * Called from MachineConfigFile::readHardware() to read cpu information.
|
---|
4464 | * @param elmCpu
|
---|
4465 | * @param ll
|
---|
4466 | */
|
---|
4467 | void MachineConfigFile::readCpuTree(const xml::ElementNode &elmCpu,
|
---|
4468 | CpuList &ll)
|
---|
4469 | {
|
---|
4470 | xml::NodesLoop nl1(elmCpu, "Cpu");
|
---|
4471 | const xml::ElementNode *pelmCpu;
|
---|
4472 | while ((pelmCpu = nl1.forAllNodes()))
|
---|
4473 | {
|
---|
4474 | Cpu cpu;
|
---|
4475 |
|
---|
4476 | if (!pelmCpu->getAttributeValue("id", cpu.ulId))
|
---|
4477 | throw ConfigFileError(this, pelmCpu, N_("Required Cpu/@id attribute is missing"));
|
---|
4478 |
|
---|
4479 | ll.push_back(cpu);
|
---|
4480 | }
|
---|
4481 | }
|
---|
4482 |
|
---|
4483 | /**
|
---|
4484 | * Called from MachineConfigFile::readHardware() to cpuid information.
|
---|
4485 | * @param elmCpuid
|
---|
4486 | * @param ll
|
---|
4487 | */
|
---|
4488 | void MachineConfigFile::readCpuIdTree(const xml::ElementNode &elmCpuid,
|
---|
4489 | CpuIdLeafsList &ll)
|
---|
4490 | {
|
---|
4491 | xml::NodesLoop nl1(elmCpuid, "CpuIdLeaf");
|
---|
4492 | const xml::ElementNode *pelmCpuIdLeaf;
|
---|
4493 | while ((pelmCpuIdLeaf = nl1.forAllNodes()))
|
---|
4494 | {
|
---|
4495 | CpuIdLeaf leaf;
|
---|
4496 |
|
---|
4497 | if (!pelmCpuIdLeaf->getAttributeValue("id", leaf.idx))
|
---|
4498 | throw ConfigFileError(this, pelmCpuIdLeaf, N_("Required CpuId/@id attribute is missing"));
|
---|
4499 |
|
---|
4500 | if (!pelmCpuIdLeaf->getAttributeValue("subleaf", leaf.idxSub))
|
---|
4501 | leaf.idxSub = 0;
|
---|
4502 | pelmCpuIdLeaf->getAttributeValue("eax", leaf.uEax);
|
---|
4503 | pelmCpuIdLeaf->getAttributeValue("ebx", leaf.uEbx);
|
---|
4504 | pelmCpuIdLeaf->getAttributeValue("ecx", leaf.uEcx);
|
---|
4505 | pelmCpuIdLeaf->getAttributeValue("edx", leaf.uEdx);
|
---|
4506 |
|
---|
4507 | ll.push_back(leaf);
|
---|
4508 | }
|
---|
4509 | }
|
---|
4510 |
|
---|
4511 | /**
|
---|
4512 | * Called from MachineConfigFile::readHardware() to network information.
|
---|
4513 | * @param elmNetwork
|
---|
4514 | * @param ll
|
---|
4515 | */
|
---|
4516 | void MachineConfigFile::readNetworkAdapters(const xml::ElementNode &elmNetwork,
|
---|
4517 | NetworkAdaptersList &ll)
|
---|
4518 | {
|
---|
4519 | xml::NodesLoop nl1(elmNetwork, "Adapter");
|
---|
4520 | const xml::ElementNode *pelmAdapter;
|
---|
4521 | while ((pelmAdapter = nl1.forAllNodes()))
|
---|
4522 | {
|
---|
4523 | NetworkAdapter nic;
|
---|
4524 |
|
---|
4525 | if (m->sv >= SettingsVersion_v1_16)
|
---|
4526 | {
|
---|
4527 | /* Starting with VirtualBox 5.1 the default is cable connected and
|
---|
4528 | * PCnet-FAST III. Needs to match NetworkAdapter.areDefaultSettings(). */
|
---|
4529 | nic.fCableConnected = true;
|
---|
4530 | nic.type = NetworkAdapterType_Am79C973;
|
---|
4531 | }
|
---|
4532 |
|
---|
4533 | if (!pelmAdapter->getAttributeValue("slot", nic.ulSlot))
|
---|
4534 | throw ConfigFileError(this, pelmAdapter, N_("Required Adapter/@slot attribute is missing"));
|
---|
4535 |
|
---|
4536 | Utf8Str strTemp;
|
---|
4537 | if (pelmAdapter->getAttributeValue("type", strTemp))
|
---|
4538 | {
|
---|
4539 | if (strTemp == "Am79C970A")
|
---|
4540 | nic.type = NetworkAdapterType_Am79C970A;
|
---|
4541 | else if (strTemp == "Am79C973")
|
---|
4542 | nic.type = NetworkAdapterType_Am79C973;
|
---|
4543 | else if (strTemp == "Am79C960")
|
---|
4544 | nic.type = NetworkAdapterType_Am79C960;
|
---|
4545 | else if (strTemp == "82540EM")
|
---|
4546 | nic.type = NetworkAdapterType_I82540EM;
|
---|
4547 | else if (strTemp == "82543GC")
|
---|
4548 | nic.type = NetworkAdapterType_I82543GC;
|
---|
4549 | else if (strTemp == "82545EM")
|
---|
4550 | nic.type = NetworkAdapterType_I82545EM;
|
---|
4551 | else if (strTemp == "virtio")
|
---|
4552 | nic.type = NetworkAdapterType_Virtio;
|
---|
4553 | else if (strTemp == "NE1000")
|
---|
4554 | nic.type = NetworkAdapterType_NE1000;
|
---|
4555 | else if (strTemp == "NE2000")
|
---|
4556 | nic.type = NetworkAdapterType_NE2000;
|
---|
4557 | else if (strTemp == "WD8003")
|
---|
4558 | nic.type = NetworkAdapterType_WD8003;
|
---|
4559 | else if (strTemp == "WD8013")
|
---|
4560 | nic.type = NetworkAdapterType_WD8013;
|
---|
4561 | else if (strTemp == "3C503")
|
---|
4562 | nic.type = NetworkAdapterType_ELNK2;
|
---|
4563 | else if (strTemp == "3C501")
|
---|
4564 | nic.type = NetworkAdapterType_ELNK1;
|
---|
4565 | else
|
---|
4566 | throw ConfigFileError(this, pelmAdapter, N_("Invalid value '%s' in Adapter/@type attribute"), strTemp.c_str());
|
---|
4567 | }
|
---|
4568 |
|
---|
4569 | pelmAdapter->getAttributeValue("enabled", nic.fEnabled);
|
---|
4570 | pelmAdapter->getAttributeValue("MACAddress", nic.strMACAddress);
|
---|
4571 | pelmAdapter->getAttributeValue("cable", nic.fCableConnected);
|
---|
4572 | pelmAdapter->getAttributeValue("speed", nic.ulLineSpeed);
|
---|
4573 |
|
---|
4574 | if (pelmAdapter->getAttributeValue("promiscuousModePolicy", strTemp))
|
---|
4575 | {
|
---|
4576 | if (strTemp == "Deny")
|
---|
4577 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
|
---|
4578 | else if (strTemp == "AllowNetwork")
|
---|
4579 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
|
---|
4580 | else if (strTemp == "AllowAll")
|
---|
4581 | nic.enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
|
---|
4582 | else
|
---|
4583 | throw ConfigFileError(this, pelmAdapter,
|
---|
4584 | N_("Invalid value '%s' in Adapter/@promiscuousModePolicy attribute"), strTemp.c_str());
|
---|
4585 | }
|
---|
4586 |
|
---|
4587 | pelmAdapter->getAttributeValue("trace", nic.fTraceEnabled);
|
---|
4588 | pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
|
---|
4589 | pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority);
|
---|
4590 | pelmAdapter->getAttributeValue("bandwidthGroup", nic.strBandwidthGroup);
|
---|
4591 |
|
---|
4592 | xml::ElementNodesList llNetworkModes;
|
---|
4593 | pelmAdapter->getChildElements(llNetworkModes);
|
---|
4594 | xml::ElementNodesList::iterator it;
|
---|
4595 | /* We should have only active mode descriptor and disabled modes set */
|
---|
4596 | if (llNetworkModes.size() > 2)
|
---|
4597 | {
|
---|
4598 | throw ConfigFileError(this, pelmAdapter, N_("Invalid number of modes ('%d') attached to Adapter attribute"), llNetworkModes.size());
|
---|
4599 | }
|
---|
4600 | for (it = llNetworkModes.begin(); it != llNetworkModes.end(); ++it)
|
---|
4601 | {
|
---|
4602 | const xml::ElementNode *pelmNode = *it;
|
---|
4603 | if (pelmNode->nameEquals("DisabledModes"))
|
---|
4604 | {
|
---|
4605 | xml::ElementNodesList llDisabledNetworkModes;
|
---|
4606 | xml::ElementNodesList::iterator itDisabled;
|
---|
4607 | pelmNode->getChildElements(llDisabledNetworkModes);
|
---|
4608 | /* run over disabled list and load settings */
|
---|
4609 | for (itDisabled = llDisabledNetworkModes.begin();
|
---|
4610 | itDisabled != llDisabledNetworkModes.end(); ++itDisabled)
|
---|
4611 | {
|
---|
4612 | const xml::ElementNode *pelmDisabledNode = *itDisabled;
|
---|
4613 | readAttachedNetworkMode(*pelmDisabledNode, false, nic);
|
---|
4614 | }
|
---|
4615 | }
|
---|
4616 | else
|
---|
4617 | readAttachedNetworkMode(*pelmNode, true, nic);
|
---|
4618 | }
|
---|
4619 | // else: default is NetworkAttachmentType_Null
|
---|
4620 |
|
---|
4621 | ll.push_back(nic);
|
---|
4622 | }
|
---|
4623 | }
|
---|
4624 |
|
---|
4625 | void MachineConfigFile::readAttachedNetworkMode(const xml::ElementNode &elmMode, bool fEnabled, NetworkAdapter &nic)
|
---|
4626 | {
|
---|
4627 | NetworkAttachmentType_T enmAttachmentType = NetworkAttachmentType_Null;
|
---|
4628 |
|
---|
4629 | if (elmMode.nameEquals("NAT"))
|
---|
4630 | {
|
---|
4631 | enmAttachmentType = NetworkAttachmentType_NAT;
|
---|
4632 |
|
---|
4633 | elmMode.getAttributeValue("network", nic.nat.strNetwork);
|
---|
4634 | elmMode.getAttributeValue("hostip", nic.nat.strBindIP);
|
---|
4635 | elmMode.getAttributeValue("mtu", nic.nat.u32Mtu);
|
---|
4636 | elmMode.getAttributeValue("sockrcv", nic.nat.u32SockRcv);
|
---|
4637 | elmMode.getAttributeValue("socksnd", nic.nat.u32SockSnd);
|
---|
4638 | elmMode.getAttributeValue("tcprcv", nic.nat.u32TcpRcv);
|
---|
4639 | elmMode.getAttributeValue("tcpsnd", nic.nat.u32TcpSnd);
|
---|
4640 | elmMode.getAttributeValue("localhost-reachable", nic.nat.fLocalhostReachable);
|
---|
4641 | const xml::ElementNode *pelmDNS;
|
---|
4642 | if ((pelmDNS = elmMode.findChildElement("DNS")))
|
---|
4643 | {
|
---|
4644 | pelmDNS->getAttributeValue("pass-domain", nic.nat.fDNSPassDomain);
|
---|
4645 | pelmDNS->getAttributeValue("use-proxy", nic.nat.fDNSProxy);
|
---|
4646 | pelmDNS->getAttributeValue("use-host-resolver", nic.nat.fDNSUseHostResolver);
|
---|
4647 | }
|
---|
4648 | const xml::ElementNode *pelmAlias;
|
---|
4649 | if ((pelmAlias = elmMode.findChildElement("Alias")))
|
---|
4650 | {
|
---|
4651 | pelmAlias->getAttributeValue("logging", nic.nat.fAliasLog);
|
---|
4652 | pelmAlias->getAttributeValue("proxy-only", nic.nat.fAliasProxyOnly);
|
---|
4653 | pelmAlias->getAttributeValue("use-same-ports", nic.nat.fAliasUseSamePorts);
|
---|
4654 | }
|
---|
4655 | const xml::ElementNode *pelmTFTP;
|
---|
4656 | if ((pelmTFTP = elmMode.findChildElement("TFTP")))
|
---|
4657 | {
|
---|
4658 | pelmTFTP->getAttributeValue("prefix", nic.nat.strTFTPPrefix);
|
---|
4659 | pelmTFTP->getAttributeValue("boot-file", nic.nat.strTFTPBootFile);
|
---|
4660 | pelmTFTP->getAttributeValue("next-server", nic.nat.strTFTPNextServer);
|
---|
4661 | }
|
---|
4662 |
|
---|
4663 | readNATForwardRulesMap(elmMode, nic.nat.mapRules);
|
---|
4664 | }
|
---|
4665 | else if ( elmMode.nameEquals("HostInterface")
|
---|
4666 | || elmMode.nameEquals("BridgedInterface"))
|
---|
4667 | {
|
---|
4668 | enmAttachmentType = NetworkAttachmentType_Bridged;
|
---|
4669 |
|
---|
4670 | // optional network name, cannot be required or we have trouble with
|
---|
4671 | // settings which are saved before configuring the network name
|
---|
4672 | elmMode.getAttributeValue("name", nic.strBridgedName);
|
---|
4673 | }
|
---|
4674 | else if (elmMode.nameEquals("InternalNetwork"))
|
---|
4675 | {
|
---|
4676 | enmAttachmentType = NetworkAttachmentType_Internal;
|
---|
4677 |
|
---|
4678 | // optional network name, cannot be required or we have trouble with
|
---|
4679 | // settings which are saved before configuring the network name
|
---|
4680 | elmMode.getAttributeValue("name", nic.strInternalNetworkName);
|
---|
4681 | }
|
---|
4682 | else if (elmMode.nameEquals("HostOnlyInterface"))
|
---|
4683 | {
|
---|
4684 | enmAttachmentType = NetworkAttachmentType_HostOnly;
|
---|
4685 |
|
---|
4686 | // optional network name, cannot be required or we have trouble with
|
---|
4687 | // settings which are saved before configuring the network name
|
---|
4688 | elmMode.getAttributeValue("name", nic.strHostOnlyName);
|
---|
4689 | }
|
---|
4690 | #ifdef VBOX_WITH_VMNET
|
---|
4691 | else if (elmMode.nameEquals("HostOnlyNetwork"))
|
---|
4692 | {
|
---|
4693 | enmAttachmentType = NetworkAttachmentType_HostOnlyNetwork;
|
---|
4694 |
|
---|
4695 | // optional network name, cannot be required or we have trouble with
|
---|
4696 | // settings which are saved before configuring the network name
|
---|
4697 | elmMode.getAttributeValue("name", nic.strHostOnlyNetworkName);
|
---|
4698 | }
|
---|
4699 | #endif /* VBOX_WITH_VMNET */
|
---|
4700 | else if (elmMode.nameEquals("GenericInterface"))
|
---|
4701 | {
|
---|
4702 | enmAttachmentType = NetworkAttachmentType_Generic;
|
---|
4703 |
|
---|
4704 | elmMode.getAttributeValue("driver", nic.strGenericDriver); // optional network attachment driver
|
---|
4705 |
|
---|
4706 | // get all properties
|
---|
4707 | xml::NodesLoop nl(elmMode);
|
---|
4708 | const xml::ElementNode *pelmModeChild;
|
---|
4709 | while ((pelmModeChild = nl.forAllNodes()))
|
---|
4710 | {
|
---|
4711 | if (pelmModeChild->nameEquals("Property"))
|
---|
4712 | {
|
---|
4713 | Utf8Str strPropName, strPropValue;
|
---|
4714 | if ( pelmModeChild->getAttributeValue("name", strPropName)
|
---|
4715 | && pelmModeChild->getAttributeValue("value", strPropValue) )
|
---|
4716 | nic.genericProperties[strPropName] = strPropValue;
|
---|
4717 | else
|
---|
4718 | throw ConfigFileError(this, pelmModeChild, N_("Required GenericInterface/Property/@name or @value attribute is missing"));
|
---|
4719 | }
|
---|
4720 | }
|
---|
4721 | }
|
---|
4722 | else if (elmMode.nameEquals("NATNetwork"))
|
---|
4723 | {
|
---|
4724 | enmAttachmentType = NetworkAttachmentType_NATNetwork;
|
---|
4725 |
|
---|
4726 | // optional network name, cannot be required or we have trouble with
|
---|
4727 | // settings which are saved before configuring the network name
|
---|
4728 | elmMode.getAttributeValue("name", nic.strNATNetworkName);
|
---|
4729 | }
|
---|
4730 | else if (elmMode.nameEquals("VDE"))
|
---|
4731 | {
|
---|
4732 | // inofficial hack (VDE networking was never part of the official
|
---|
4733 | // settings, so it's not mentioned in VirtualBox-settings.xsd)
|
---|
4734 | enmAttachmentType = NetworkAttachmentType_Generic;
|
---|
4735 |
|
---|
4736 | com::Utf8Str strVDEName;
|
---|
4737 | elmMode.getAttributeValue("network", strVDEName); // optional network name
|
---|
4738 | nic.strGenericDriver = "VDE";
|
---|
4739 | nic.genericProperties["network"] = strVDEName;
|
---|
4740 | }
|
---|
4741 | #ifdef VBOX_WITH_VMNET
|
---|
4742 | else if (elmMode.nameEquals("HostOnlyNetwork"))
|
---|
4743 | {
|
---|
4744 | enmAttachmentType = NetworkAttachmentType_HostOnly;
|
---|
4745 |
|
---|
4746 | // optional network name, cannot be required or we have trouble with
|
---|
4747 | // settings which are saved before configuring the network name
|
---|
4748 | elmMode.getAttributeValue("name", nic.strHostOnlyNetworkName);
|
---|
4749 | }
|
---|
4750 | #endif /* VBOX_WITH_VMNET */
|
---|
4751 | #ifdef VBOX_WITH_CLOUD_NET
|
---|
4752 | else if (elmMode.nameEquals("CloudNetwork"))
|
---|
4753 | {
|
---|
4754 | enmAttachmentType = NetworkAttachmentType_Cloud;
|
---|
4755 |
|
---|
4756 | // optional network name, cannot be required or we have trouble with
|
---|
4757 | // settings which are saved before configuring the network name
|
---|
4758 | elmMode.getAttributeValue("name", nic.strCloudNetworkName);
|
---|
4759 | }
|
---|
4760 | #endif /* VBOX_WITH_CLOUD_NET */
|
---|
4761 |
|
---|
4762 | if (fEnabled && enmAttachmentType != NetworkAttachmentType_Null)
|
---|
4763 | nic.mode = enmAttachmentType;
|
---|
4764 | }
|
---|
4765 |
|
---|
4766 | /**
|
---|
4767 | * Called from MachineConfigFile::readHardware() to read serial port information.
|
---|
4768 | * @param elmUART
|
---|
4769 | * @param ll
|
---|
4770 | */
|
---|
4771 | void MachineConfigFile::readSerialPorts(const xml::ElementNode &elmUART,
|
---|
4772 | SerialPortsList &ll)
|
---|
4773 | {
|
---|
4774 | xml::NodesLoop nl1(elmUART, "Port");
|
---|
4775 | const xml::ElementNode *pelmPort;
|
---|
4776 | while ((pelmPort = nl1.forAllNodes()))
|
---|
4777 | {
|
---|
4778 | SerialPort port;
|
---|
4779 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
4780 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@slot attribute is missing"));
|
---|
4781 |
|
---|
4782 | // slot must be unique
|
---|
4783 | for (SerialPortsList::const_iterator it = ll.begin();
|
---|
4784 | it != ll.end();
|
---|
4785 | ++it)
|
---|
4786 | if ((*it).ulSlot == port.ulSlot)
|
---|
4787 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in UART/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
4788 |
|
---|
4789 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
4790 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@enabled attribute is missing"));
|
---|
4791 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
4792 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IOBase attribute is missing"));
|
---|
4793 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
4794 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IRQ attribute is missing"));
|
---|
4795 |
|
---|
4796 | Utf8Str strPortMode;
|
---|
4797 | if (!pelmPort->getAttributeValue("hostMode", strPortMode))
|
---|
4798 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@hostMode attribute is missing"));
|
---|
4799 | if (strPortMode == "RawFile")
|
---|
4800 | port.portMode = PortMode_RawFile;
|
---|
4801 | else if (strPortMode == "HostPipe")
|
---|
4802 | port.portMode = PortMode_HostPipe;
|
---|
4803 | else if (strPortMode == "HostDevice")
|
---|
4804 | port.portMode = PortMode_HostDevice;
|
---|
4805 | else if (strPortMode == "Disconnected")
|
---|
4806 | port.portMode = PortMode_Disconnected;
|
---|
4807 | else if (strPortMode == "TCP")
|
---|
4808 | port.portMode = PortMode_TCP;
|
---|
4809 | else
|
---|
4810 | throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
|
---|
4811 |
|
---|
4812 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
4813 | pelmPort->getAttributeValue("server", port.fServer);
|
---|
4814 |
|
---|
4815 | Utf8Str strUartType;
|
---|
4816 | if (pelmPort->getAttributeValue("uartType", strUartType))
|
---|
4817 | {
|
---|
4818 | if (strUartType == "16450")
|
---|
4819 | port.uartType = UartType_U16450;
|
---|
4820 | else if (strUartType == "16550A")
|
---|
4821 | port.uartType = UartType_U16550A;
|
---|
4822 | else if (strUartType == "16750")
|
---|
4823 | port.uartType = UartType_U16750;
|
---|
4824 | else
|
---|
4825 | throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@uartType attribute"), strUartType.c_str());
|
---|
4826 | }
|
---|
4827 |
|
---|
4828 | ll.push_back(port);
|
---|
4829 | }
|
---|
4830 | }
|
---|
4831 |
|
---|
4832 | /**
|
---|
4833 | * Called from MachineConfigFile::readHardware() to read parallel port information.
|
---|
4834 | * @param elmLPT
|
---|
4835 | * @param ll
|
---|
4836 | */
|
---|
4837 | void MachineConfigFile::readParallelPorts(const xml::ElementNode &elmLPT,
|
---|
4838 | ParallelPortsList &ll)
|
---|
4839 | {
|
---|
4840 | xml::NodesLoop nl1(elmLPT, "Port");
|
---|
4841 | const xml::ElementNode *pelmPort;
|
---|
4842 | while ((pelmPort = nl1.forAllNodes()))
|
---|
4843 | {
|
---|
4844 | ParallelPort port;
|
---|
4845 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
4846 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@slot attribute is missing"));
|
---|
4847 |
|
---|
4848 | // slot must be unique
|
---|
4849 | for (ParallelPortsList::const_iterator it = ll.begin();
|
---|
4850 | it != ll.end();
|
---|
4851 | ++it)
|
---|
4852 | if ((*it).ulSlot == port.ulSlot)
|
---|
4853 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in LPT/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
4854 |
|
---|
4855 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
4856 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@enabled attribute is missing"));
|
---|
4857 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
4858 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IOBase attribute is missing"));
|
---|
4859 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
4860 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IRQ attribute is missing"));
|
---|
4861 |
|
---|
4862 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
4863 |
|
---|
4864 | ll.push_back(port);
|
---|
4865 | }
|
---|
4866 | }
|
---|
4867 |
|
---|
4868 | /**
|
---|
4869 | * Called from MachineConfigFile::readHardware() to read audio adapter information
|
---|
4870 | * and maybe fix driver information depending on the current host hardware.
|
---|
4871 | *
|
---|
4872 | * @param elmAudioAdapter "AudioAdapter" XML element.
|
---|
4873 | * @param aa
|
---|
4874 | */
|
---|
4875 | void MachineConfigFile::readAudioAdapter(const xml::ElementNode &elmAudioAdapter,
|
---|
4876 | AudioAdapter &aa)
|
---|
4877 | {
|
---|
4878 | if (m->sv >= SettingsVersion_v1_15)
|
---|
4879 | {
|
---|
4880 | // get all properties
|
---|
4881 | xml::NodesLoop nl1(elmAudioAdapter, "Property");
|
---|
4882 | const xml::ElementNode *pelmModeChild;
|
---|
4883 | while ((pelmModeChild = nl1.forAllNodes()))
|
---|
4884 | {
|
---|
4885 | Utf8Str strPropName, strPropValue;
|
---|
4886 | if ( pelmModeChild->getAttributeValue("name", strPropName)
|
---|
4887 | && pelmModeChild->getAttributeValue("value", strPropValue) )
|
---|
4888 | aa.properties[strPropName] = strPropValue;
|
---|
4889 | else
|
---|
4890 | throw ConfigFileError(this, pelmModeChild, N_("Required AudioAdapter/Property/@name or @value attribute "
|
---|
4891 | "is missing"));
|
---|
4892 | }
|
---|
4893 | }
|
---|
4894 |
|
---|
4895 | elmAudioAdapter.getAttributeValue("enabled", aa.fEnabled);
|
---|
4896 | elmAudioAdapter.getAttributeValue("enabledIn", aa.fEnabledIn);
|
---|
4897 | elmAudioAdapter.getAttributeValue("enabledOut", aa.fEnabledOut);
|
---|
4898 |
|
---|
4899 | Utf8Str strTemp;
|
---|
4900 | if (elmAudioAdapter.getAttributeValue("controller", strTemp))
|
---|
4901 | {
|
---|
4902 | if (strTemp == "SB16")
|
---|
4903 | aa.controllerType = AudioControllerType_SB16;
|
---|
4904 | else if (strTemp == "AC97")
|
---|
4905 | aa.controllerType = AudioControllerType_AC97;
|
---|
4906 | else if (strTemp == "HDA")
|
---|
4907 | aa.controllerType = AudioControllerType_HDA;
|
---|
4908 | else
|
---|
4909 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
|
---|
4910 | }
|
---|
4911 |
|
---|
4912 | if (elmAudioAdapter.getAttributeValue("codec", strTemp))
|
---|
4913 | {
|
---|
4914 | if (strTemp == "SB16")
|
---|
4915 | aa.codecType = AudioCodecType_SB16;
|
---|
4916 | else if (strTemp == "STAC9700")
|
---|
4917 | aa.codecType = AudioCodecType_STAC9700;
|
---|
4918 | else if (strTemp == "AD1980")
|
---|
4919 | aa.codecType = AudioCodecType_AD1980;
|
---|
4920 | else if (strTemp == "STAC9221")
|
---|
4921 | aa.codecType = AudioCodecType_STAC9221;
|
---|
4922 | else
|
---|
4923 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@codec attribute"), strTemp.c_str());
|
---|
4924 | }
|
---|
4925 | else
|
---|
4926 | {
|
---|
4927 | /* No codec attribute provided; use defaults. */
|
---|
4928 | switch (aa.controllerType)
|
---|
4929 | {
|
---|
4930 | case AudioControllerType_AC97:
|
---|
4931 | aa.codecType = AudioCodecType_STAC9700;
|
---|
4932 | break;
|
---|
4933 | case AudioControllerType_SB16:
|
---|
4934 | aa.codecType = AudioCodecType_SB16;
|
---|
4935 | break;
|
---|
4936 | case AudioControllerType_HDA:
|
---|
4937 | aa.codecType = AudioCodecType_STAC9221;
|
---|
4938 | break;
|
---|
4939 | default:
|
---|
4940 | Assert(false); /* We just checked the controller type above. */
|
---|
4941 | }
|
---|
4942 | }
|
---|
4943 |
|
---|
4944 | if (elmAudioAdapter.getAttributeValue("driver", strTemp))
|
---|
4945 | {
|
---|
4946 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
4947 | strTemp.toUpper();
|
---|
4948 | if (strTemp == "DEFAULT") /* Keep this to be backwards compatible for settings < r152556. */
|
---|
4949 | aa.driverType = AudioDriverType_Default;
|
---|
4950 | else if (strTemp == "NULL")
|
---|
4951 | aa.driverType = AudioDriverType_Null;
|
---|
4952 | else if (strTemp == "WAS")
|
---|
4953 | aa.driverType = AudioDriverType_WAS;
|
---|
4954 | else if (strTemp == "WINMM")
|
---|
4955 | aa.driverType = AudioDriverType_WinMM;
|
---|
4956 | else if ( (strTemp == "DIRECTSOUND") || (strTemp == "DSOUND") )
|
---|
4957 | aa.driverType = AudioDriverType_DirectSound;
|
---|
4958 | else if (strTemp == "SOLAUDIO") /* Deprecated -- Solaris will use OSS by default now. */
|
---|
4959 | aa.driverType = AudioDriverType_SolAudio;
|
---|
4960 | else if (strTemp == "ALSA")
|
---|
4961 | aa.driverType = AudioDriverType_ALSA;
|
---|
4962 | else if (strTemp == "PULSE")
|
---|
4963 | aa.driverType = AudioDriverType_Pulse;
|
---|
4964 | else if (strTemp == "OSS")
|
---|
4965 | aa.driverType = AudioDriverType_OSS;
|
---|
4966 | else if (strTemp == "COREAUDIO")
|
---|
4967 | aa.driverType = AudioDriverType_CoreAudio;
|
---|
4968 | else if (strTemp == "MMPM") /* Deprecated; only kept for backwards compatibility. */
|
---|
4969 | aa.driverType = AudioDriverType_MMPM;
|
---|
4970 | else
|
---|
4971 | throw ConfigFileError(this, &elmAudioAdapter, N_("Invalid value '%s' in AudioAdapter/@driver attribute"), strTemp.c_str());
|
---|
4972 |
|
---|
4973 | /* When loading settings >= 1.19 (VBox 7.0), the attribute "useDefault" will determine if the VM should use
|
---|
4974 | * the OS' default audio driver or not. This additional attribute is necessary in order to be backwards compatible
|
---|
4975 | * with older VBox versions. */
|
---|
4976 | bool fUseDefault = false;
|
---|
4977 | if ( elmAudioAdapter.getAttributeValue("useDefault", &fUseDefault) /* Overrides "driver" above (if set). */
|
---|
4978 | && fUseDefault)
|
---|
4979 | aa.driverType = AudioDriverType_Default;
|
---|
4980 |
|
---|
4981 | // now check if this is actually supported on the current host platform;
|
---|
4982 | // people might be opening a file created on a Windows host, and that
|
---|
4983 | // VM should still start on a Linux host
|
---|
4984 | if (!isAudioDriverAllowedOnThisHost(aa.driverType))
|
---|
4985 | aa.driverType = getHostDefaultAudioDriver();
|
---|
4986 | }
|
---|
4987 | }
|
---|
4988 |
|
---|
4989 | /**
|
---|
4990 | * Called from MachineConfigFile::readHardware() to read guest property information.
|
---|
4991 | * @param elmGuestProperties
|
---|
4992 | * @param hw
|
---|
4993 | */
|
---|
4994 | void MachineConfigFile::readGuestProperties(const xml::ElementNode &elmGuestProperties,
|
---|
4995 | Hardware &hw)
|
---|
4996 | {
|
---|
4997 | xml::NodesLoop nl1(elmGuestProperties, "GuestProperty");
|
---|
4998 | const xml::ElementNode *pelmProp;
|
---|
4999 | while ((pelmProp = nl1.forAllNodes()))
|
---|
5000 | {
|
---|
5001 | GuestProperty prop;
|
---|
5002 |
|
---|
5003 | pelmProp->getAttributeValue("name", prop.strName);
|
---|
5004 | pelmProp->getAttributeValue("value", prop.strValue);
|
---|
5005 |
|
---|
5006 | pelmProp->getAttributeValue("timestamp", prop.timestamp);
|
---|
5007 | pelmProp->getAttributeValue("flags", prop.strFlags);
|
---|
5008 |
|
---|
5009 | /* Check guest property 'name' and 'value' for correctness before
|
---|
5010 | * placing it to local cache. */
|
---|
5011 |
|
---|
5012 | int rc = GuestPropValidateName(prop.strName.c_str(), prop.strName.length() + 1 /* '\0' */);
|
---|
5013 | if (RT_FAILURE(rc))
|
---|
5014 | {
|
---|
5015 | LogRel(("WARNING: Guest property with invalid name (%s) present in VM configuration file. Guest property will be dropped.\n",
|
---|
5016 | prop.strName.c_str()));
|
---|
5017 | continue;
|
---|
5018 | }
|
---|
5019 |
|
---|
5020 | rc = GuestPropValidateValue(prop.strValue.c_str(), prop.strValue.length() + 1 /* '\0' */);
|
---|
5021 | if (rc == VERR_TOO_MUCH_DATA)
|
---|
5022 | {
|
---|
5023 | LogRel(("WARNING: Guest property '%s' present in VM configuration file and has too long value. Guest property value will be truncated.\n",
|
---|
5024 | prop.strName.c_str()));
|
---|
5025 |
|
---|
5026 | /* In order to pass validation, guest property value length (including '\0') in bytes
|
---|
5027 | * should be less than GUEST_PROP_MAX_VALUE_LEN. Chop it down to an appropriate length. */
|
---|
5028 | prop.strValue.truncate(GUEST_PROP_MAX_VALUE_LEN - 1 /*terminator*/);
|
---|
5029 | }
|
---|
5030 | else if (RT_FAILURE(rc))
|
---|
5031 | {
|
---|
5032 | LogRel(("WARNING: Guest property '%s' present in VM configuration file and has invalid value. Guest property will be dropped.\n",
|
---|
5033 | prop.strName.c_str()));
|
---|
5034 | continue;
|
---|
5035 | }
|
---|
5036 |
|
---|
5037 | hw.llGuestProperties.push_back(prop);
|
---|
5038 | }
|
---|
5039 | }
|
---|
5040 |
|
---|
5041 | /**
|
---|
5042 | * Helper function to read attributes that are common to \<SATAController\> (pre-1.7)
|
---|
5043 | * and \<StorageController\>.
|
---|
5044 | * @param elmStorageController
|
---|
5045 | * @param sctl
|
---|
5046 | */
|
---|
5047 | void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
|
---|
5048 | StorageController &sctl)
|
---|
5049 | {
|
---|
5050 | elmStorageController.getAttributeValue("PortCount", sctl.ulPortCount);
|
---|
5051 | elmStorageController.getAttributeValue("useHostIOCache", sctl.fUseHostIOCache);
|
---|
5052 | }
|
---|
5053 |
|
---|
5054 | /**
|
---|
5055 | * Reads in a \<Hardware\> block and stores it in the given structure. Used
|
---|
5056 | * both directly from readMachine and from readSnapshot, since snapshots
|
---|
5057 | * have their own hardware sections.
|
---|
5058 | *
|
---|
5059 | * For legacy pre-1.7 settings we also need a storage structure because
|
---|
5060 | * the IDE and SATA controllers used to be defined under \<Hardware\>.
|
---|
5061 | *
|
---|
5062 | * @param elmHardware Hardware node to read from.
|
---|
5063 | * @param hw Where to store the hardware settings.
|
---|
5064 | */
|
---|
5065 | void MachineConfigFile::readHardware(const xml::ElementNode &elmHardware,
|
---|
5066 | Hardware &hw)
|
---|
5067 | {
|
---|
5068 | if (m->sv >= SettingsVersion_v1_16)
|
---|
5069 | {
|
---|
5070 | /* Starting with VirtualBox 5.1 the default is Default, before it was
|
---|
5071 | * Legacy. This needs to matched by areParavirtDefaultSettings(). */
|
---|
5072 | hw.paravirtProvider = ParavirtProvider_Default;
|
---|
5073 | /* The new default is disabled, before it was enabled by default. */
|
---|
5074 | hw.vrdeSettings.fEnabled = false;
|
---|
5075 | /* The new default is disabled, before it was enabled by default. */
|
---|
5076 | hw.audioAdapter.fEnabled = false;
|
---|
5077 | }
|
---|
5078 |
|
---|
5079 | if (m->sv >= SettingsVersion_v1_17)
|
---|
5080 | {
|
---|
5081 | /* Starting with VirtualBox 5.2 the default is disabled, before it was
|
---|
5082 | * enabled. This needs to matched by AudioAdapter::areDefaultSettings(). */
|
---|
5083 | hw.audioAdapter.fEnabledIn = false;
|
---|
5084 | /* The new default is disabled, before it was enabled by default. */
|
---|
5085 | hw.audioAdapter.fEnabledOut = false;
|
---|
5086 | }
|
---|
5087 |
|
---|
5088 | if (!elmHardware.getAttributeValue("version", hw.strVersion))
|
---|
5089 | {
|
---|
5090 | /* KLUDGE ALERT! For a while during the 3.1 development this was not
|
---|
5091 | written because it was thought to have a default value of "2". For
|
---|
5092 | sv <= 1.3 it defaults to "1" because the attribute didn't exist,
|
---|
5093 | while for 1.4+ it is sort of mandatory. Now, the buggy XML writer
|
---|
5094 | code only wrote 1.7 and later. So, if it's a 1.7+ XML file and it's
|
---|
5095 | missing the hardware version, then it probably should be "2" instead
|
---|
5096 | of "1". */
|
---|
5097 | if (m->sv < SettingsVersion_v1_7)
|
---|
5098 | hw.strVersion = "1";
|
---|
5099 | else
|
---|
5100 | hw.strVersion = "2";
|
---|
5101 | }
|
---|
5102 | Utf8Str strUUID;
|
---|
5103 | if (elmHardware.getAttributeValue("uuid", strUUID))
|
---|
5104 | parseUUID(hw.uuid, strUUID, &elmHardware);
|
---|
5105 |
|
---|
5106 | xml::NodesLoop nl1(elmHardware);
|
---|
5107 | const xml::ElementNode *pelmHwChild;
|
---|
5108 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
5109 | {
|
---|
5110 | if (pelmHwChild->nameEquals("CPU"))
|
---|
5111 | {
|
---|
5112 | if (!pelmHwChild->getAttributeValue("count", hw.cCPUs))
|
---|
5113 | {
|
---|
5114 | // pre-1.5 variant; not sure if this actually exists in the wild anywhere
|
---|
5115 | const xml::ElementNode *pelmCPUChild;
|
---|
5116 | if ((pelmCPUChild = pelmHwChild->findChildElement("CPUCount")))
|
---|
5117 | pelmCPUChild->getAttributeValue("count", hw.cCPUs);
|
---|
5118 | }
|
---|
5119 |
|
---|
5120 | pelmHwChild->getAttributeValue("hotplug", hw.fCpuHotPlug);
|
---|
5121 | pelmHwChild->getAttributeValue("executionCap", hw.ulCpuExecutionCap);
|
---|
5122 |
|
---|
5123 | const xml::ElementNode *pelmCPUChild;
|
---|
5124 | if (hw.fCpuHotPlug)
|
---|
5125 | {
|
---|
5126 | if ((pelmCPUChild = pelmHwChild->findChildElement("CpuTree")))
|
---|
5127 | readCpuTree(*pelmCPUChild, hw.llCpus);
|
---|
5128 | }
|
---|
5129 |
|
---|
5130 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtEx")))
|
---|
5131 | {
|
---|
5132 | pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirt);
|
---|
5133 | }
|
---|
5134 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExNestedPaging")))
|
---|
5135 | pelmCPUChild->getAttributeValue("enabled", hw.fNestedPaging);
|
---|
5136 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExLargePages")))
|
---|
5137 | pelmCPUChild->getAttributeValue("enabled", hw.fLargePages);
|
---|
5138 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExVPID")))
|
---|
5139 | pelmCPUChild->getAttributeValue("enabled", hw.fVPID);
|
---|
5140 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExUX")))
|
---|
5141 | pelmCPUChild->getAttributeValue("enabled", hw.fUnrestrictedExecution);
|
---|
5142 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtForce")))
|
---|
5143 | pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirtForce);
|
---|
5144 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExUseNativeApi")))
|
---|
5145 | pelmCPUChild->getAttributeValue("enabled", hw.fUseNativeApi);
|
---|
5146 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExVirtVmsaveVmload")))
|
---|
5147 | pelmCPUChild->getAttributeValue("enabled", hw.fVirtVmsaveVmload);
|
---|
5148 |
|
---|
5149 | if (!(pelmCPUChild = pelmHwChild->findChildElement("PAE")))
|
---|
5150 | {
|
---|
5151 | /* The default for pre 3.1 was false, so we must respect that. */
|
---|
5152 | if (m->sv < SettingsVersion_v1_9)
|
---|
5153 | hw.fPAE = false;
|
---|
5154 | }
|
---|
5155 | else
|
---|
5156 | pelmCPUChild->getAttributeValue("enabled", hw.fPAE);
|
---|
5157 |
|
---|
5158 | bool fLongMode;
|
---|
5159 | if ( (pelmCPUChild = pelmHwChild->findChildElement("LongMode"))
|
---|
5160 | && pelmCPUChild->getAttributeValue("enabled", fLongMode) )
|
---|
5161 | hw.enmLongMode = fLongMode ? Hardware::LongMode_Enabled : Hardware::LongMode_Disabled;
|
---|
5162 | else
|
---|
5163 | hw.enmLongMode = Hardware::LongMode_Legacy;
|
---|
5164 |
|
---|
5165 | if ((pelmCPUChild = pelmHwChild->findChildElement("SyntheticCpu")))
|
---|
5166 | {
|
---|
5167 | bool fSyntheticCpu = false;
|
---|
5168 | pelmCPUChild->getAttributeValue("enabled", fSyntheticCpu);
|
---|
5169 | hw.uCpuIdPortabilityLevel = fSyntheticCpu ? 1 : 0;
|
---|
5170 | }
|
---|
5171 | pelmHwChild->getAttributeValue("CpuIdPortabilityLevel", hw.uCpuIdPortabilityLevel);
|
---|
5172 | pelmHwChild->getAttributeValue("CpuProfile", hw.strCpuProfile);
|
---|
5173 |
|
---|
5174 | if ((pelmCPUChild = pelmHwChild->findChildElement("TripleFaultReset")))
|
---|
5175 | pelmCPUChild->getAttributeValue("enabled", hw.fTripleFaultReset);
|
---|
5176 |
|
---|
5177 | if ((pelmCPUChild = pelmHwChild->findChildElement("APIC")))
|
---|
5178 | pelmCPUChild->getAttributeValue("enabled", hw.fAPIC);
|
---|
5179 | if ((pelmCPUChild = pelmHwChild->findChildElement("X2APIC")))
|
---|
5180 | pelmCPUChild->getAttributeValue("enabled", hw.fX2APIC);
|
---|
5181 | if (hw.fX2APIC)
|
---|
5182 | hw.fAPIC = true;
|
---|
5183 | pelmCPUChild = pelmHwChild->findChildElement("IBPBOn");
|
---|
5184 | if (pelmCPUChild)
|
---|
5185 | {
|
---|
5186 | pelmCPUChild->getAttributeValue("vmexit", hw.fIBPBOnVMExit);
|
---|
5187 | pelmCPUChild->getAttributeValue("vmentry", hw.fIBPBOnVMEntry);
|
---|
5188 | }
|
---|
5189 | pelmCPUChild = pelmHwChild->findChildElement("SpecCtrl");
|
---|
5190 | if (pelmCPUChild)
|
---|
5191 | pelmCPUChild->getAttributeValue("enabled", hw.fSpecCtrl);
|
---|
5192 | pelmCPUChild = pelmHwChild->findChildElement("SpecCtrlByHost");
|
---|
5193 | if (pelmCPUChild)
|
---|