1 | /* $Id: UnattendedScript.h 76167 2018-12-11 17:03:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Classes for reading/parsing/saving scripts for unattended installation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 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 ____H_UNATTENDEDSCRIPT
|
---|
19 | #define ____H_UNATTENDEDSCRIPT
|
---|
20 |
|
---|
21 | #include "TextScript.h"
|
---|
22 |
|
---|
23 | using namespace xml;
|
---|
24 |
|
---|
25 | class Unattended;
|
---|
26 |
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Generic unattended text script template editor.
|
---|
30 | *
|
---|
31 | * This just perform variable replacements, no other editing possible.
|
---|
32 | *
|
---|
33 | * Everything happens during saveToString, parse is a noop.
|
---|
34 | */
|
---|
35 | class UnattendedScriptTemplate : public BaseTextScript
|
---|
36 | {
|
---|
37 | protected:
|
---|
38 | /** Where to get the replacement strings from. */
|
---|
39 | Unattended *mpUnattended;
|
---|
40 |
|
---|
41 | public:
|
---|
42 | UnattendedScriptTemplate(Unattended *pUnattended, const char *pszDefaultTemplateFilename, const char *pszDefaultFilename);
|
---|
43 | virtual ~UnattendedScriptTemplate() {}
|
---|
44 |
|
---|
45 | HRESULT parse() { return S_OK; }
|
---|
46 | HRESULT saveToString(Utf8Str &rStrDst);
|
---|
47 |
|
---|
48 | protected:
|
---|
49 | /**
|
---|
50 | * Gets the replacement value for the given placeholder.
|
---|
51 | *
|
---|
52 | * @returns COM status code.
|
---|
53 | * @param pachPlaceholder The placholder string. Not zero terminated.
|
---|
54 | * @param cchPlaceholder The length of the placeholder.
|
---|
55 | * @param fOutputting Indicates whether we actually need the correct value
|
---|
56 | * or is just syntax checking excluded template parts.
|
---|
57 | * @param rValue Where to return the value.
|
---|
58 | */
|
---|
59 | HRESULT getReplacement(const char *pachPlaceholder, size_t cchPlaceholder, bool fOutputting, RTCString &rValue);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Overridable worker for getReplacement.
|
---|
63 | *
|
---|
64 | * @returns COM status code.
|
---|
65 | * @param pachPlaceholder The placholder string. Not zero terminated.
|
---|
66 | * @param cchPlaceholder The length of the placeholder.
|
---|
67 | * @param cchFullPlaceholder The full placeholder length, including suffixes
|
---|
68 | * indicating how it should be escaped (for error
|
---|
69 | * messages).
|
---|
70 | * @param fOutputting Indicates whether we actually need the correct
|
---|
71 | * value or is just syntax checking excluded
|
---|
72 | * template parts. Intended for voiding triggering
|
---|
73 | * sanity checks regarding which replacements
|
---|
74 | * should be used and not (e.g. no guest additions
|
---|
75 | * path when installing GAs aren't enabled).
|
---|
76 | * @param rValue Where to return the value.
|
---|
77 | * @throws std::bad_alloc
|
---|
78 | */
|
---|
79 | virtual HRESULT getUnescapedReplacement(const char *pachPlaceholder, size_t cchPlaceholder,
|
---|
80 | size_t cchFullPlaceholder, bool fOutputting, RTCString &rValue);
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Get the result of a conditional.
|
---|
85 | *
|
---|
86 | * @returns COM status code.
|
---|
87 | * @param pachPlaceholder The placholder string. Not zero terminated.
|
---|
88 | * @param cchPlaceholder The length of the placeholder.
|
---|
89 | * @param pfOutputting Where to return the result of the conditional.
|
---|
90 | * This holds the current outputting state on input
|
---|
91 | * in case someone want to sanity check anything.
|
---|
92 | */
|
---|
93 | virtual HRESULT getConditional(const char *pachPlaceholder, size_t cchPlaceholder, bool *pfOutputting);
|
---|
94 | };
|
---|
95 |
|
---|
96 | #if 0 /* convert when we fix SUSE */
|
---|
97 | /**
|
---|
98 | * SUSE unattended XML file editor.
|
---|
99 | */
|
---|
100 | class UnattendedSUSEXMLScript : public UnattendedXMLScript
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | UnattendedSUSEXMLScript(VirtualBoxBase *pSetError, const char *pszDefaultFilename = "autoinst.xml")
|
---|
104 | : UnattendedXMLScript(pSetError, pszDefaultFilename) {}
|
---|
105 | ~UnattendedSUSEXMLScript() {}
|
---|
106 |
|
---|
107 | HRESULT parse();
|
---|
108 |
|
---|
109 | protected:
|
---|
110 | HRESULT setFieldInElement(xml::ElementNode *pElement, const DataId enmDataId, const Utf8Str &rStrValue);
|
---|
111 |
|
---|
112 | private:
|
---|
113 | //////////////////New functions//////////////////////////////
|
---|
114 | /** @throws std::bad_alloc */
|
---|
115 | HRESULT LoopThruSections(const xml::ElementNode *pelmRoot);
|
---|
116 | /** @throws std::bad_alloc */
|
---|
117 | HRESULT HandleUserAccountsSection(const xml::ElementNode *pelmSection);
|
---|
118 | /** @throws std::bad_alloc */
|
---|
119 | Utf8Str createProbableValue(const DataId enmDataId, const xml::ElementNode *pCurElem);
|
---|
120 | /** @throws std::bad_alloc */
|
---|
121 | Utf8Str createProbableUserHomeDir(const xml::ElementNode *pCurElem);
|
---|
122 | //////////////////New functions//////////////////////////////
|
---|
123 | };
|
---|
124 | #endif
|
---|
125 |
|
---|
126 |
|
---|
127 | #endif // !____H_UNATTENDEDSCRIPT
|
---|
128 |
|
---|