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