VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedScript.h@ 99739

Last change on this file since 99739 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: UnattendedScript.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Classes for reading/parsing/saving scripts for unattended installation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_UnattendedScript_h
29#define MAIN_INCLUDED_UnattendedScript_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include "TextScript.h"
35#include "iprt/expreval.h"
36
37using namespace xml;
38
39class Unattended;
40
41
42/**
43 * Generic unattended text script template editor.
44 *
45 * This just perform variable replacements, no other editing possible.
46 *
47 * Everything happens during saveToString, parse is a noop.
48 */
49class UnattendedScriptTemplate : public BaseTextScript
50{
51protected:
52 /** Where to get the replacement strings from. */
53 Unattended *mpUnattended;
54
55public:
56 DECLARE_TRANSLATE_METHODS(UnattendedScriptTemplate)
57
58 UnattendedScriptTemplate(Unattended *pUnattended, const char *pszDefaultTemplateFilename, const char *pszDefaultFilename);
59 virtual ~UnattendedScriptTemplate() {}
60
61 HRESULT parse() { return S_OK; }
62 HRESULT saveToString(Utf8Str &rStrDst);
63
64protected:
65 typedef enum
66 {
67 kValueEscaping_None,
68 kValueEscaping_Bourne,
69 kValueEscaping_XML_Element,
70 kValueEscaping_XML_Attribute_Double_Quotes
71 } kEvalEscaping_T;
72
73 /**
74 * Gets the replacement value for the given placeholder.
75 *
76 * @returns COM status code.
77 * @param pachPlaceholder The placholder string. Not zero terminated.
78 * @param cchPlaceholder The length of the placeholder.
79 * @param fOutputting Indicates whether we actually need the correct value
80 * or is just syntax checking excluded template parts.
81 * @param rValue Where to return the value.
82 */
83 HRESULT getReplacement(const char *pachPlaceholder, size_t cchPlaceholder, bool fOutputting, RTCString &rValue);
84
85 /**
86 * Gets the replacement value for the given expression placeholder
87 * (@@VBOX_INSERT[expr]@@ and friends).
88 *
89 * @returns COM status code.
90 * @param hEvaluator The evaluator to use for the expression.
91 * @param pachPlaceholder The placholder string. Not zero terminated.
92 * @param cchPlaceholder The length of the placeholder.
93 * @param fOutputting Indicates whether we actually need the correct value
94 * or is just syntax checking excluded template parts.
95 * @param ppszValue Where to return the value. Free by calling
96 * RTStrFree. Set to NULL for empty string.
97 */
98 HRESULT getReplacementForExpr(RTEXPREVAL hEvaluator, const char *pachPlaceholder, size_t cchPlaceholder,
99 bool fOutputting, char **ppszValue) RT_NOEXCEPT;
100
101 /**
102 * Resolves a conditional expression.
103 *
104 * @returns COM status code.
105 * @param hEvaluator The evaluator to use for the expression.
106 * @param pachPlaceholder The placholder string. Not zero terminated.
107 * @param cchPlaceholder The length of the placeholder.
108 * @param pfOutputting Where to return the result of the conditional. This
109 * holds the current outputting state on input in case
110 * someone want to sanity check anything.
111 */
112 HRESULT resolveConditionalExpr(RTEXPREVAL hEvaluator, const char *pachPlaceholder, size_t cchPlaceholder,
113 bool *pfOutputting) RT_NOEXCEPT;
114
115 /** @callback_method_impl{FNRTEXPREVALQUERYVARIABLE} */
116 static DECLCALLBACK(int) queryVariableForExpr(const char *pchName, size_t cchName, void *pvUser,
117 char **ppszValue) RT_NOEXCEPT;
118
119 /**
120 * Gets a variable.
121 *
122 * This is used both for getting replacements (@@VBOX_INSERT_XXX@@) and in
123 * expressions (@@VBOX_INSERT[expr]@@, @@VBOX_COND[expr]@@).
124 *
125 * @returns VBox status code.
126 * @retval VERR_NOT_FOUND if variable does not exist.
127 *
128 * @param pchName The variable name. Not zero terminated.
129 * @param cchName The length of the name.
130 * @param rstrTmp String object that can be used for keeping the
131 * value returned via @a *ppszValue.
132 * @param ppszValue If a value is desired, this is where to return
133 * it. This points to a string that should be
134 * accessible for a little while after the function
135 * returns. Use @a rstrTmp for storage if
136 * necessary.
137 *
138 * This will be NULL when called from the 'defined'
139 * operator. In which case no errors should be
140 * set.
141 * @throws std::bad_alloc
142 * @see FNRTEXPREVALQUERYVARIABLE
143 */
144 virtual int queryVariable(const char *pchName, size_t cchName, Utf8Str &rstrTmp, const char **ppszValue);
145
146 /**
147 * Get the result of a conditional.
148 *
149 * @returns COM status code.
150 * @param pachPlaceholder The placholder string. Not zero terminated.
151 * @param cchPlaceholder The length of the placeholder.
152 * @param pfOutputting Where to return the result of the conditional.
153 * This holds the current outputting state on input
154 * in case someone want to sanity check anything.
155 */
156 virtual HRESULT getConditional(const char *pachPlaceholder, size_t cchPlaceholder, bool *pfOutputting);
157};
158
159#if 0 /* convert when we fix SUSE */
160/**
161 * SUSE unattended XML file editor.
162 */
163class UnattendedSUSEXMLScript : public UnattendedXMLScript
164{
165public:
166 DECLARE_TRANSLATE_METHODS(UnattendedSUSEXMLScript)
167
168 UnattendedSUSEXMLScript(VirtualBoxBase *pSetError, const char *pszDefaultFilename = "autoinst.xml")
169 : UnattendedXMLScript(pSetError, pszDefaultFilename) {}
170 ~UnattendedSUSEXMLScript() {}
171
172 HRESULT parse();
173
174protected:
175 HRESULT setFieldInElement(xml::ElementNode *pElement, const DataId enmDataId, const Utf8Str &rStrValue);
176
177private:
178 //////////////////New functions//////////////////////////////
179 /** @throws std::bad_alloc */
180 HRESULT LoopThruSections(const xml::ElementNode *pelmRoot);
181 /** @throws std::bad_alloc */
182 HRESULT HandleUserAccountsSection(const xml::ElementNode *pelmSection);
183 /** @throws std::bad_alloc */
184 Utf8Str createProbableValue(const DataId enmDataId, const xml::ElementNode *pCurElem);
185 /** @throws std::bad_alloc */
186 Utf8Str createProbableUserHomeDir(const xml::ElementNode *pCurElem);
187 //////////////////New functions//////////////////////////////
188};
189#endif
190
191
192#endif /* !MAIN_INCLUDED_UnattendedScript_h */
193
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