|
1 /* |
|
2 * Copyright (c) 2005 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 "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: Declaration of the OMA DRM rigths parser |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef DRMRIGHTSPARSER_H |
|
20 #define DRMRIGHTSPARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <Xml/Parser.h> |
|
24 #include <Xml/ContentHandler.h> |
|
25 #include <Xml/XmlParserErrors.h> |
|
26 |
|
27 using namespace Xml; |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CDRMRights; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 /** |
|
35 * Parser for OMA DRM rights objects (verion 1.0 and 2.0) |
|
36 * |
|
37 * @lib DrmParsers.dll |
|
38 * @since Series 60 3.0 |
|
39 */ |
|
40 NONSHARABLE_CLASS(CDrmRightsParser): public CBase, public MContentHandler |
|
41 { |
|
42 public: |
|
43 |
|
44 class CParsedRightsObject; |
|
45 class CParsedAsset; |
|
46 class CParsedPermission; |
|
47 |
|
48 enum TParserType |
|
49 { |
|
50 EXmlParser, |
|
51 EWbxmlParser |
|
52 }; |
|
53 |
|
54 enum TSoftwareSchemaType |
|
55 { |
|
56 ESymbianSid, |
|
57 ESymbianVid |
|
58 }; |
|
59 |
|
60 static const TInt KMaxElementCount = 40; |
|
61 static const TInt KMaxElementNesting = 16; |
|
62 |
|
63 public: // Constructors and destructor |
|
64 |
|
65 /** |
|
66 * Create a parser object |
|
67 * @since Series 60 3.0 |
|
68 * @param Type of the parser (XML or WBXML) |
|
69 * @return Allocated parser |
|
70 */ |
|
71 IMPORT_C static CDrmRightsParser* NewL( |
|
72 TParserType aType = EXmlParser); |
|
73 |
|
74 /** |
|
75 * Destructor. |
|
76 */ |
|
77 IMPORT_C ~CDrmRightsParser(); |
|
78 |
|
79 public: // New functions |
|
80 |
|
81 /** |
|
82 * Parse one rights object |
|
83 * @since Series 60 3.0 |
|
84 * @param aRightsObject XML or WBXML representation of the rights |
|
85 * @param aResultRigths Parsed rights |
|
86 */ |
|
87 IMPORT_C void ParseL( |
|
88 const TDesC8& aRightsObject, |
|
89 RPointerArray<CDRMRights>& aResultRights); |
|
90 |
|
91 /** |
|
92 * Parse one rights object and store it in the rights database |
|
93 * @since Series 60 3.0 |
|
94 * @param aRightsObject XML or WBXML representation of the rights |
|
95 * @param aResultRigths Parsed rights |
|
96 */ |
|
97 IMPORT_C void ParseAndStoreL( |
|
98 const TDesC8& aRightsObject, |
|
99 RPointerArray<CDRMRights>& aResultRights); |
|
100 |
|
101 protected: // Functions from base classes |
|
102 |
|
103 /** |
|
104 * From MContentHandler |
|
105 * @param aDocParam Specifies the various parameters of the document. |
|
106 * @arg aDocParam.iCharacterSetName The character encoding of the document. |
|
107 * @param aErrorCode is the error code. |
|
108 * If this is not KErrNone then special action may be required. |
|
109 */ |
|
110 void OnStartDocumentL( |
|
111 const RDocumentParameters& aDocParam, |
|
112 TInt aErrorCode); |
|
113 |
|
114 /** |
|
115 * From MContentHandler |
|
116 * @param aErrorCode is the error code. |
|
117 * If this is not KErrNone then special action may be required. |
|
118 */ |
|
119 void OnEndDocumentL( |
|
120 TInt aErrorCode); |
|
121 |
|
122 /** |
|
123 * From MContentHandler |
|
124 * @param aElement is a handle to the element's details. |
|
125 * @param aAttributes contains the attributes for the element. |
|
126 * @param aErrorCode is the error code. |
|
127 * If this is not KErrNone then special action may be required. |
|
128 */ |
|
129 void OnStartElementL( |
|
130 const RTagInfo& aElement, |
|
131 const RAttributeArray& aAttributes, |
|
132 TInt aErrorCode); |
|
133 |
|
134 /** |
|
135 * From MContentHandler |
|
136 * @param aElement is a handle to the element's details. |
|
137 * @param aErrorCode is the error code. |
|
138 * If this is not KErrNone then special action may be required. |
|
139 */ |
|
140 void OnEndElementL( |
|
141 const RTagInfo& aElement, |
|
142 TInt aErrorCode); |
|
143 |
|
144 /** |
|
145 * From MContentHandler |
|
146 * @param aBytes is the raw content data for the element. |
|
147 * The client is responsible for converting the data to the |
|
148 * required character set if necessary. |
|
149 * In some instances the content may be binary and must not be converted. |
|
150 * @param aErrorCode is the error code. |
|
151 * If this is not KErrNone then special action may be required. |
|
152 */ |
|
153 void OnContentL( |
|
154 const TDesC8& aBytes, |
|
155 TInt aErrorCode); |
|
156 |
|
157 /** |
|
158 * From MContentHandler |
|
159 * @param aPrefix is the Namespace prefix being declared. |
|
160 * @param aUri is the Namespace URI the prefix is mapped to. |
|
161 * @param aErrorCode is the error code. |
|
162 * If this is not KErrNone then special action may be required. |
|
163 */ |
|
164 void OnStartPrefixMappingL( |
|
165 const RString& aPrefix, |
|
166 const RString& aUri, |
|
167 TInt aErrorCode); |
|
168 |
|
169 /** |
|
170 * From MContentHandler |
|
171 * @param aPrefix is the Namespace prefix that was mapped. |
|
172 * @param aErrorCode is the error code. |
|
173 * If this is not KErrNone then special action may be required. |
|
174 */ |
|
175 void OnEndPrefixMappingL( |
|
176 const RString& aPrefix, |
|
177 TInt aErrorCode); |
|
178 |
|
179 /** |
|
180 * From MContentHandler |
|
181 * @param aBytes are the ignored bytes from the document being parsed. |
|
182 * @param aErrorCode is the error code. |
|
183 * If this is not KErrNone then special action may be required. |
|
184 */ |
|
185 void OnIgnorableWhiteSpaceL( |
|
186 const TDesC8& aBytes, |
|
187 TInt aErrorCode); |
|
188 |
|
189 /** |
|
190 * From MContentHandler |
|
191 * @param aName is the name of the skipped entity. |
|
192 * @param aErrorCode is the error code. |
|
193 * If this is not KErrNone then special action may be required. |
|
194 */ |
|
195 void OnSkippedEntityL( |
|
196 const RString& aName, |
|
197 TInt aErrorCode); |
|
198 |
|
199 /** |
|
200 * From MContentHandler |
|
201 * @param aTarget is the processing instruction target. |
|
202 * @param aData is the processing instruction data. If empty none was supplied. |
|
203 * @param aErrorCode is the error code. |
|
204 * If this is not KErrNone then special action may be required. |
|
205 */ |
|
206 void OnProcessingInstructionL( |
|
207 const TDesC8& aTarget, |
|
208 const TDesC8& aData, |
|
209 TInt aErrorCode); |
|
210 |
|
211 /** |
|
212 * From MContentHandler |
|
213 */ |
|
214 void OnOutOfData(); |
|
215 |
|
216 |
|
217 /** |
|
218 * From MContentHandler |
|
219 * @param aError is the error code |
|
220 */ |
|
221 void OnError( |
|
222 TInt aErrorCode); |
|
223 |
|
224 |
|
225 /** |
|
226 * From MContentHandler |
|
227 * @return 0 if no interface matching the uid is found. |
|
228 * Otherwise, the this pointer cast to that interface. |
|
229 * @param aUid the uid identifying the required interface. |
|
230 */ |
|
231 TAny* GetExtendedInterface( |
|
232 const TInt32 aUid); |
|
233 |
|
234 protected: // New functions |
|
235 |
|
236 /** |
|
237 * Match the state of the current stack to the predefined states |
|
238 * @since Series 60 3.0 |
|
239 * @return KErrNotFound if no state is matched, otherwise the number |
|
240 * of the state |
|
241 */ |
|
242 TInt MatchStackState(void); |
|
243 |
|
244 /** |
|
245 * Transform the result of the parsing into an API level rights object |
|
246 * @since Series 60 3.0 |
|
247 * @param aResult Out parameter for the resul |
|
248 */ |
|
249 void TransformRightsObjectL( |
|
250 RPointerArray<CDRMRights>& aResult); |
|
251 |
|
252 /** |
|
253 * Return the value of an attribute as a buffer |
|
254 * @since Series 60 3.0 |
|
255 * @param aAttrList Atrribute list |
|
256 * @param aAttrName Name of the attribute |
|
257 * @return value of the attribute or NULL |
|
258 */ |
|
259 HBufC8* GetAttributeValueL( |
|
260 const RAttributeArray& aAttrList, |
|
261 const TDesC8& aAttrName); |
|
262 |
|
263 private: |
|
264 |
|
265 /** |
|
266 * C++ default constructor. |
|
267 */ |
|
268 CDrmRightsParser(); |
|
269 |
|
270 void ConstructL( |
|
271 TParserType aType); |
|
272 |
|
273 |
|
274 /** |
|
275 * Parse the time string and return the TTime |
|
276 */ |
|
277 TTime ParseRelTimeL(TDesC8& aRelTimeString); |
|
278 |
|
279 /** |
|
280 * Parse the interval string and return the interval |
|
281 */ |
|
282 TTimeIntervalSeconds ParseRelInterval(TDesC8& aRelTimeString); |
|
283 |
|
284 |
|
285 /** |
|
286 * Validate time string variables |
|
287 */ |
|
288 TBool ValidTimeValues( TInt aYear, TMonth aMonth, TInt aDay, TInt aHour, |
|
289 TInt aMinute, TInt aSecond, TInt aMicrosecond ); |
|
290 |
|
291 /** |
|
292 * Validate day |
|
293 */ |
|
294 TBool ValidateDay( TInt aYear, TMonth aMonth, TInt aDay ); |
|
295 |
|
296 |
|
297 |
|
298 protected: // Data |
|
299 // XML Parser |
|
300 CParser* iParser; |
|
301 |
|
302 // Parsed rigths object |
|
303 CParsedRightsObject* iRights; |
|
304 |
|
305 // Predefined XML element names |
|
306 RString iElements[KMaxElementCount]; |
|
307 |
|
308 // Current parsing stack |
|
309 TInt iElementStack[KMaxElementNesting]; |
|
310 |
|
311 // Depth of the current parsing stack |
|
312 TInt iElementStackDepth; |
|
313 |
|
314 // Content between elements |
|
315 HBufC8* iContent; |
|
316 |
|
317 // Determines if the input is XML or WBXML |
|
318 TParserType iParserType; |
|
319 |
|
320 // Determines what kind of software constraint the RO contains |
|
321 TSoftwareSchemaType iSoftwareSchemeType; |
|
322 |
|
323 // In increments of +- 15 minutes |
|
324 TInt iTimeZone; |
|
325 |
|
326 // Tagname of unkown tag |
|
327 HBufC8* iUnknownTag; |
|
328 }; |
|
329 |
|
330 #endif // DRMRIGHTSPARSER_H |
|
331 |
|
332 // End of File |