VirtualBox

source: vbox/trunk/src/VBox/Main/VirtualBoxImplExtra.cpp@ 7387

Last change on this file since 7387 was 7387, checked in by vboxsync, 17 years ago

Main/Settings: Perform conversion in a loop to allow for multi-step version to version updates (e.g. v1.0->v1.1->v1.2) which saves from patching all previous transformation rules when on every version change but still makes it possible to update from too old versions to the most recent one.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 5.0 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation extra definitions
4 *
5 * This file pulls in generated entities that may be rather big but rarely
6 * changed. Separating them from VirtualBoxImpl.cpp should speed up
7 * compilation a bit.
8 */
9
10/*
11 * Copyright (C) 2006-2007 innotek GmbH
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.215389.xyz. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License as published by the Free Software Foundation,
17 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
18 * distribution. VirtualBox OSE is distributed in the hope that it will
19 * be useful, but WITHOUT ANY WARRANTY of any kind.
20 */
21
22#include "VirtualBoxImpl.h"
23
24#include "VirtualBoxXMLUtil.h"
25
26/* embedded XML Schema documents for validating XML settings files */
27#include "xml_VirtualBox_settings_xsd.h"
28#include "xml_VirtualBox_settings_common_xsd.h"
29
30/* embedded settings converter template for updating settings files */
31#include "xml_SettingsConverter_xsl.h"
32
33/**
34 * Resolves external entities while parting and validating XML settings files.
35 *
36 * @param aURI URI of the external entity.
37 * @param aID ID of the external entity (may be NULL).
38 *
39 * @return Input stream created using @c new or NULL to indicate
40 * a wrong URI/ID pair.
41 */
42settings::Input *
43VirtualBox::SettingsTreeHelper::resolveEntity (const char *aURI, const char *aID)
44{
45 if (strcmp (aURI, VBOX_XML_SCHEMA_COMMON) == 0)
46 {
47 return new settings::
48 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_common_xsd,
49 g_cb_xml_VirtualBox_settings_common_xsd, aURI);
50 }
51
52 if (strcmp (aURI, VBOX_XML_SCHEMA) == 0)
53 {
54 return new settings::
55 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_xsd,
56 g_cb_xml_VirtualBox_settings_xsd, aURI);
57 }
58
59 if (strcmp (aURI, VBOX_XML_SETTINGS_CONVERTER) == 0)
60 {
61 return new settings::
62 MemoryBuf ((const char *) g_ab_xml_SettingsConverter_xsl,
63 g_cb_xml_SettingsConverter_xsl, aURI);
64 }
65
66 AssertMsgFailed (("Unexpected entity: '%s' - knows: '%s' and '%s'\n", aURI,
67 VBOX_XML_SCHEMA_COMMON, VBOX_XML_SCHEMA));
68 return NULL;
69}
70
71/**
72 * Returns @true if the given tree needs to be converted using the XSLT
73 * template identified by #templateUri(), or @false if no conversion is
74 * required.
75 *
76 * The implementation normally checks for the "version" value of the
77 * root key to determine if the conversion is necessary. When the
78 * @a aOldVersion argument is not NULL, the implementation must return a
79 * non-NULL non-empty string representing the old version (before
80 * conversion) in it this string is used by XmlTreeBackend::oldVersion()
81 * and must be non-NULL to indicate that the conversion has been
82 * performed on the tree. The returned string must be allocated using
83 * RTStrDup() or such.
84 *
85 * This method is called again after the successful transformation to
86 * let the implementation retry the version check and request another
87 * transformation if necessary. This may be used to perform multi-step
88 * conversion like this: 1.1 => 1.2, 1.2 => 1.3 (instead of 1.1 => 1.3)
89 * which saves from the need to update all previous conversion
90 * templates to make each of them convert directly to the recent
91 * version.
92 *
93 * @note Multi-step transformations are performed in a loop that exits
94 * only when this method returns @false. It's up to the
95 * implementation to detect cycling (repeated requests to convert
96 * from the same version) wrong version order, etc. and throw an
97 * EConversionCycle exception to break the loop without returning
98 * @false (which means the transformation succeeded).
99 *
100 * @param aRoot Root settings key.
101 * @param aOldVersionString Where to store old version string
102 * pointer. May be NULL.
103 */
104bool VirtualBox::SettingsTreeHelper::
105needsConversion (const settings::Key &aRoot, char **aOldVersion) const
106{
107 if (strcmp (aRoot.name(), "VirtualBox") == 0)
108 {
109 const char *version = aRoot.stringValue ("version");
110 const char *dash = strchr (version, '-');
111 if (dash != NULL && strcmp (dash + 1, VBOX_XML_PLATFORM) == 0)
112 {
113 if (strcmp (version, VBOX_XML_VERSION_FULL) != 0)
114 {
115 /* version mismatch */
116 if (aOldVersion != NULL)
117 *aOldVersion = RTStrDup (version);
118
119 return true;
120 }
121 }
122 }
123
124 /* either the tree is invalid, or it's the other platform, or it's the same
125 * version */
126 return false;
127}
128
129/**
130 * Returns the URI of the XSLT template to perform the conversion.
131 * This template will be applied to the tree if #needsConversion()
132 * returns @c true for this tree.
133 */
134const char *VirtualBox::SettingsTreeHelper::templateUri() const
135{
136 return VBOX_XML_SETTINGS_CONVERTER;
137}
138
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette