VirtualBox

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

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

Main/Settings: Implemented support for settings file auto-conversion at VBoxSVC startup (#2705).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 4.1 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.virtualbox.org. 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. The
78 * implementation must return a string representing the old version
79 * (before conversion) in the @c aOldVersion argument -- this string is
80 * used by XmlTreeBackend::oldVersion() and must be non-NULL to indicate
81 * that the conversion has been performed on the tree. The returned
82 * string must be allocated using RTStrDup or such.
83 *
84 * @param aRoot Root settings key.
85 * @param aOldVersionString Old version string (allocated by
86 * RTStrDup or such).
87 */
88bool VirtualBox::SettingsTreeHelper::
89needsConversion (const settings::Key &aRoot, char *&aOldVersion) const
90{
91 if (strcmp (aRoot.name(), "VirtualBox") == 0)
92 {
93 const char *version = aRoot.stringValue ("version");
94 const char *dash = strchr (version, '-');
95 if (dash != NULL && strcmp (dash + 1, VBOX_XML_PLATFORM) == 0)
96 {
97 if (strcmp (version, VBOX_XML_VERSION_FULL) != 0)
98 {
99 /* version mismatch */
100 aOldVersion = RTStrDup (version);
101 return true;
102 }
103 }
104 }
105
106 /* either the tree is invalid, or it's the other platform, or it's the same
107 * version */
108 return false;
109}
110
111/**
112 * Returns the URI of the XSLT template to perform the conversion.
113 * This template will be applied to the tree if #needsConversion()
114 * returns @c true for this tree.
115 */
116const char *VirtualBox::SettingsTreeHelper::templateUri() const
117{
118 return VBOX_XML_SETTINGS_CONVERTER;
119}
120
Note: See TracBrowser for help on using the repository browser.

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