|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * handles parsing of PKG file |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @publishedPartner |
|
23 @released |
|
24 */ |
|
25 |
|
26 #ifndef __PACKAGE_PARSER_H_ |
|
27 #define __PACKAGE_PARSER_H_ |
|
28 |
|
29 // =========================================================================== |
|
30 // INCLUDES |
|
31 // =========================================================================== |
|
32 #include <iostream> |
|
33 #include <string> |
|
34 #include <map> |
|
35 |
|
36 #include "utils.h" |
|
37 #include "utility_interface.h" |
|
38 #include "sisexpression.h" |
|
39 #include "sisinstallblock.h" |
|
40 #include "basetype.h" |
|
41 #include "siswrite.h" |
|
42 #include "sislanguage.h" |
|
43 |
|
44 // =========================================================================== |
|
45 // CONSTANTS |
|
46 // =========================================================================== |
|
47 |
|
48 // maximum length of strings used in condition expressions |
|
49 #define MAX_STRING 255 |
|
50 |
|
51 #define MAX_FUNC_ARGS 2 |
|
52 |
|
53 // Error codes for possible parser failures |
|
54 enum TParseException |
|
55 { |
|
56 ErrUnknownLine, |
|
57 ErrHeaderAlreadyDefined, |
|
58 ErrLanguagesAlreadyDefined, |
|
59 ErrLanguagesNotDefined, |
|
60 ErrUnknownLanguagesId, |
|
61 ErrHeaderNotDefined, |
|
62 ErrNoMainDependency, |
|
63 ErrFileNotFound, |
|
64 ErrPackageNotASISFile, |
|
65 ErrBadCondFormat, |
|
66 ErrReadFailed, |
|
67 ErrBadOption, |
|
68 ErrBadString, |
|
69 ErrUnexpectedToken, |
|
70 ErrInvalidEscape, |
|
71 ErrNumberOutOfRange, |
|
72 ErrUnknownVariable, |
|
73 ErrUninstallNeedsWaitEnd, |
|
74 ErrUIDMismatch, |
|
75 ErrCannotGetFullPath, |
|
76 ErrBadDestinationPath, |
|
77 ErrDuplicateUID, |
|
78 ErrExceedVersionNumber, |
|
79 ErrUnBalancedParenthesis, |
|
80 ErrHeaderRejectPreInstalledNonRemovable, |
|
81 ErrInvalidInstallFlagOption, |
|
82 ErrVersionInvalidRelationalOperator, |
|
83 ErrVersionWildcardsNotSupported, |
|
84 ErrVersionNegativesNotSupported, |
|
85 ErrBadIntegerToStringConversion |
|
86 }; |
|
87 |
|
88 /** |
|
89 * Error codes for possible interpret SIS failures. |
|
90 */ |
|
91 enum TInterpretSisException |
|
92 { |
|
93 ErrInvalidAppType, |
|
94 ErrEmbeddedSisNotSupported, |
|
95 ErrInvalidInstallOptions, |
|
96 ErrUserOptionsNotSupported, |
|
97 ErrHalValuesNotSupported |
|
98 }; |
|
99 |
|
100 typedef int TOKEN; |
|
101 |
|
102 // =========================================================================== |
|
103 // INTERNAL DATA STRUCTURES CONSTRUCTED WHEN PARSING PKG FILE |
|
104 // =========================================================================== |
|
105 /** |
|
106 * @internalComponent |
|
107 * @released |
|
108 */ |
|
109 union VARIANTVAL |
|
110 // a variant, i.e. either a number or string value |
|
111 { |
|
112 LONG dwNumber; // numeric value, e.g. 100 |
|
113 WCHAR pszString[MAX_STRING]; // string value, e.g. "crystal" |
|
114 }; |
|
115 |
|
116 #define MAXOPTLEN 20 |
|
117 |
|
118 struct SParseOpt |
|
119 { |
|
120 wchar_t pszOpt[MAXOPTLEN]; |
|
121 DWORD dwOpt; |
|
122 }; |
|
123 |
|
124 // =========================================================================== |
|
125 // CLASS DEFINITIONS |
|
126 // =========================================================================== |
|
127 |
|
128 class MParserObserver |
|
129 // Callback mixin - allows disemination of progress data |
|
130 { |
|
131 public: |
|
132 /** |
|
133 * Output message |
|
134 * @param aText Message to display |
|
135 */ |
|
136 virtual void DoMsg(const wchar_t* aText) const = 0; |
|
137 /** |
|
138 * Output 'verbose' messages |
|
139 * @param Message to display |
|
140 */ |
|
141 virtual void DoVerbage(const wchar_t* aText) const = 0; |
|
142 /** |
|
143 * Output error messages |
|
144 * @param Message to display |
|
145 */ |
|
146 virtual void DoErrMsg(const wchar_t* aText) const = 0; |
|
147 /** |
|
148 * Is verbose output required? |
|
149 * @return true if verbose output required else false. |
|
150 */ |
|
151 virtual bool Verbose() const = 0; |
|
152 /** |
|
153 * Reset the verbosity status |
|
154 * @param aVerbose true to which on verbose or else false. |
|
155 */ |
|
156 virtual bool SetVerbose(bool aVerbose) = 0; |
|
157 /** |
|
158 * Set the Line number which is being processed |
|
159 * @param aLineNumber new line number |
|
160 */ |
|
161 virtual void SetLineNumber(int aLineNumber) = 0; |
|
162 /** |
|
163 * Add error message for use later on |
|
164 * @param aError Error code |
|
165 */ |
|
166 virtual void AddInterpretSisError(TInterpretSisException aError) = 0; |
|
167 }; |
|
168 |
|
169 class CInterpretSisHelper; |
|
170 |
|
171 class CSISFileDescription; |
|
172 typedef std::map<const std::wstring, CSISFileDescription> TDuplicates; |
|
173 typedef TDuplicates::const_iterator TDuplicatesConstIter; |
|
174 |
|
175 class CPackageParser |
|
176 { |
|
177 public: |
|
178 /** |
|
179 * Constructor |
|
180 * @param aObserver - observer to parsing messages. UI implementor needs |
|
181 * to implement this to get the parsing details. |
|
182 */ |
|
183 CPackageParser(MParserObserver& aObserver); |
|
184 /** |
|
185 * The function parses the package file and creates a sis file. |
|
186 * In case of invalid package file the function throws exception. |
|
187 * See TParseException for details. |
|
188 * If aReportInterpretSisError variable it true then this function |
|
189 * will Report whether the interpretsis would not be able to provision |
|
190 * this file. For details about errors refer TInterpretSisException. |
|
191 * |
|
192 * @param aPkgFileName pkg file name |
|
193 * @param aSisFileName output sis file name |
|
194 * @param aMakeStub boolean which tells whether to create stub or not. |
|
195 * @param aReportInterpretSisError whether to report interpretsis failure or not. |
|
196 */ |
|
197 void MakeSis(const wchar_t* aPkgFileName, const wchar_t* aSisFileName, bool aMakeStub, bool aReportInterpretSisError); |
|
198 |
|
199 /** |
|
200 * This function will parse the package file. In case of any error it will |
|
201 * throw exception (TParseException). |
|
202 */ |
|
203 void ParseL (const wchar_t* aPkgFileName); |
|
204 /** |
|
205 * Set the directory to search for files. The package file and all the files referenced |
|
206 * by the package is searched in this path. |
|
207 */ |
|
208 void SetSearchDirectory(const wchar_t* aPath); |
|
209 /** |
|
210 * Create a hex dump of the created sis file. |
|
211 */ |
|
212 inline void Dump(std::ostream& aStream); |
|
213 |
|
214 private: |
|
215 HANDLE OpenPackageFile(const wchar_t* aPkgFileName); |
|
216 void ParseEmbeddedBlockL (CSISInstallBlock& aInstall); |
|
217 void ParseLanguagesL(); |
|
218 void ParseHeaderL(); |
|
219 void ParseVendorNameL (); |
|
220 void ParseLogoL (); |
|
221 void ParseFileL (CSISInstallBlock& aInstall); |
|
222 void ParsePackageL (CSISInstallBlock& aInstall); |
|
223 void ParseOptionsBlockL (); |
|
224 void ParseLanguageBlockL (CSISInstallBlock& aInstall); |
|
225 void ParseIfBlockL (CSISInstallBlock& aInstall); |
|
226 void ParseDependencyL(); |
|
227 void ParseTargetDeviceL(); |
|
228 void ParseSignatureL(); |
|
229 void ParsePropertyL (); |
|
230 void ParseCommentL (); |
|
231 void ParseVendorUniqueNameL (); |
|
232 void ParseLogicalOp (CSISExpression& aExpression); |
|
233 void ParseRelation(CSISExpression& aExpression); |
|
234 void ParseUnary(CSISExpression& aExpression); |
|
235 void ParseFactor(CSISExpression& aExpression); |
|
236 std::wstring ParseVersionArgs(); |
|
237 |
|
238 DWORD ParseOption(const SParseOpt* options, DWORD dwNumOptions, DWORD* pdwOptions); |
|
239 TVersion CPackageParser::ParseVersion(); |
|
240 std::wstring ConvertToString(const TInt32 aValue, std::ios_base& (*aBase)(std::ios_base&)); |
|
241 |
|
242 //Function added for supporting supported language option |
|
243 // in package file format. |
|
244 std::wstring ParseSupportedLangArgs(); |
|
245 |
|
246 void ExpectToken(TOKEN aToken); |
|
247 void GetNextToken(const TBool aDisablePkgKeywordCheck = 0); |
|
248 bool GetStringToken(); |
|
249 WORD ParseEscapeChars(); |
|
250 void GetAlphaNumericToken(); |
|
251 void GetNumericToken(); |
|
252 bool IsNumericToken(); |
|
253 void GetNextChar(); |
|
254 |
|
255 // validate the major , minor and build version. |
|
256 void ValidateVersion(TInt32& aMajor, TInt32& aMinor, TInt32& aBuild); |
|
257 |
|
258 const _TCHAR* GetTokenText(TOKEN aToken); |
|
259 |
|
260 // changed wstring to wchar_t for suite to prepend the path before filename. |
|
261 static TUint32 Find(wchar_t *aWhat, CSISFileDescription& aFileDesciption); |
|
262 static void Set(std::wstring& aWhat, CSISFileDescription& aData); |
|
263 |
|
264 inline bool InterpretSis() const; |
|
265 |
|
266 bool DoesExist(LPWSTR pszFile, DWORD *pdwSize); // Does the component file exist, how big is it |
|
267 bool DoesFileExist (std::wstring& aFileName, TUint64& aSize); |
|
268 |
|
269 void ReportInterpretSisError(TInterpretSisException aException); |
|
270 |
|
271 void ComputeAndSetHash(CSISFileDescription& aFileDesc); |
|
272 |
|
273 private: // Private Member variables |
|
274 bool iValidSISFile; |
|
275 bool iMakeStub; |
|
276 bool iReportInterpretSisError; |
|
277 bool iEnoughForStub; |
|
278 bool iIsHeaderDefined; |
|
279 bool iUniqueVendorName; |
|
280 bool iLocalisedVendorNames; |
|
281 wchar_t iPkgChar; |
|
282 int iLineNo; // The line we are currently on |
|
283 int iCurrentLang; // If we are in a lang/lang file block - which lang are we processing |
|
284 TOKEN iToken; |
|
285 HANDLE iFileHandle; |
|
286 MParserObserver& iObserver; // The obseverer object |
|
287 CSISXWriter iSISXWriter; // Stuff all our intermediate data in here |
|
288 VARIANTVAL iTokenValue; |
|
289 wchar_t iSearchDir[PATHMAX]; // Directory to search for component files |
|
290 |
|
291 static TDuplicates iSrcFiles; |
|
292 }; |
|
293 |
|
294 // Inline member functions |
|
295 inline bool CPackageParser::InterpretSis() const |
|
296 { |
|
297 return iReportInterpretSisError; |
|
298 } |
|
299 |
|
300 inline void CPackageParser::Dump(std::ostream& aStream) |
|
301 { |
|
302 iSISXWriter.Dump(aStream); |
|
303 } |
|
304 #endif // __PACKAGE_PARSER_H_ |
|
305 |