|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Implementation of policymanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "OperationParser.h" |
|
22 #include "PolicyParser.h" |
|
23 #include "OperationParserConstants.h" |
|
24 #include "PolicyManager.h" |
|
25 #include "PolicyStorage.h" |
|
26 #include "debug.h" |
|
27 #include "ErrorCodes.h" |
|
28 |
|
29 |
|
30 // CONSTANTS |
|
31 _LIT8( KCDataElement, "KCData"); |
|
32 const TChar KXMLElementEndMark = '>'; |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // COperationParser::COperationParser() |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 |
|
39 COperationParser::COperationParser() |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // COperationParser::~COperationParser() |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 |
|
48 COperationParser::~COperationParser() |
|
49 { |
|
50 ResetOperations(); |
|
51 delete iParser; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // COperationParser::NewL() |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 |
|
59 COperationParser * COperationParser::NewL( const TDesC8& aOperationDescription) |
|
60 { |
|
61 //2nd phase constructor |
|
62 COperationParser * self = new (ELeave) COperationParser(); |
|
63 |
|
64 CleanupStack::PushL( self); |
|
65 self->ConstructL( aOperationDescription); |
|
66 CleanupStack::Pop( self); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // COperationParser::ConstructL() |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 |
|
76 void COperationParser::ConstructL( const TDesC8& aOperationDescription) |
|
77 { |
|
78 //2nd phase constructor |
|
79 iParser = Xml::CParser::NewL( _L8( "text/xml"), *this ); |
|
80 iXMLContent.Set( aOperationDescription); |
|
81 } |
|
82 |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // COperationParser::ResetOperations() |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void COperationParser::ResetOperations() |
|
89 { |
|
90 for ( TInt i(0); i < iOperations.Count(); i++) |
|
91 { |
|
92 delete iOperations[i]; |
|
93 iOperations[i] = NULL; |
|
94 } |
|
95 |
|
96 iOperations.Close(); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // COperationParser::ConstructL() |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 |
|
104 void COperationParser::HandleErrorL( const TDesC8& aErrorTxt, const TDesC8& aElementName) |
|
105 { |
|
106 //parse error text |
|
107 iReturnText->Copy( _L8("(Line ")); |
|
108 iReturnText->AppendNum( iActiveLine); |
|
109 iReturnText->Append( _L8(") ")); |
|
110 iReturnText->Append( aErrorTxt); |
|
111 iReturnText->Append( _L8(": ")); |
|
112 iReturnText->Append( aElementName); |
|
113 |
|
114 RDEBUG_2("Operation parser error: %S", &iReturnText); |
|
115 |
|
116 User::Leave( KErrOpParser); |
|
117 } |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // COperationParser::ParseOperationsL() |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 |
|
127 void COperationParser::ParseOperationsL( TDes8& aReturnTxt) |
|
128 { |
|
129 //reset line counter and initialize XML-parser |
|
130 iActiveLine = 0; |
|
131 iReturnText = &aReturnTxt; |
|
132 iXMLStackPointer = 0; |
|
133 ResetOperations(); |
|
134 |
|
135 |
|
136 //initliaze symbian xml parser |
|
137 iParser->ParseBeginL(); |
|
138 |
|
139 //Max size of chunk (max text length, which go once to parser) |
|
140 const TInt KMaxChunkLength = 1000; |
|
141 |
|
142 TPtrC8 xml = iXMLContent; |
|
143 TPtrC8 chunk; |
|
144 TInt length = KMaxChunkLength < xml.Length() ? KMaxChunkLength : xml.Length(); |
|
145 |
|
146 do |
|
147 { |
|
148 //Find line feed mark (asciicode 10) |
|
149 TInt indexLineFeed = xml.Locate(10); |
|
150 TInt elementEndIndex = xml.Locate( KXMLElementEndMark ); |
|
151 |
|
152 if ( elementEndIndex != KErrNotFound && (elementEndIndex < indexLineFeed || indexLineFeed == KErrNotFound)) |
|
153 { |
|
154 length = elementEndIndex + 1; |
|
155 } |
|
156 else |
|
157 if ( indexLineFeed != KErrNotFound) |
|
158 { |
|
159 //max text, which go to parser is one line or KMaxChunkLength. Counter tracks line, where parsing is going |
|
160 iActiveLine++; |
|
161 |
|
162 length = indexLineFeed + 1; |
|
163 } |
|
164 |
|
165 //set chunk pointer |
|
166 chunk.Set( xml.Left(length)); |
|
167 |
|
168 |
|
169 if ( ParserUtility::ContainsCDataField( chunk)) |
|
170 { |
|
171 //cdata mark indicated in chunk, remove cdata area from chunk, |
|
172 TPtrC8 cdata; |
|
173 ParserUtility::ReadCDataAreaL( cdata, chunk, xml); |
|
174 |
|
175 //pointer to cdata content |
|
176 ParserUtility::RemoveCDataMarksL( cdata); |
|
177 |
|
178 if ( !iActiveOperation) |
|
179 { |
|
180 HandleErrorL( ParserErrors::UnexpectedElement, KCDataElement); |
|
181 } |
|
182 |
|
183 iActiveOperation->SetXACMLContentL( cdata); |
|
184 iActiveOperation->SetLineOffset( iActiveLine - 1); |
|
185 |
|
186 iActiveLine += ParserUtility::LineCounter( cdata); |
|
187 } |
|
188 else |
|
189 { |
|
190 //set remaining XACML description to xacmlDescription |
|
191 xml.Set( xml.Mid(length)); |
|
192 } |
|
193 |
|
194 //'|' and '~' are not allowed in policy system... |
|
195 if ( chunk.Locate('|') != KErrNotFound || chunk.Locate('~') != KErrNotFound) |
|
196 { |
|
197 HandleErrorL( ParserErrors::InvalidMark, ParserErrors::InvalidMarks); |
|
198 } |
|
199 |
|
200 //drive description to parser |
|
201 iParser->ParseL( chunk); |
|
202 |
|
203 length = KMaxChunkLength < xml.Length() ? KMaxChunkLength : xml.Length(); |
|
204 } while ( length); |
|
205 |
|
206 //close parser |
|
207 iParser->ParseEndL(); |
|
208 } |
|
209 |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // COperationParser::OnProcessingInstructionL() |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void COperationParser::ExecuteL( TInt aIndex, CPolicyManager *aManager) |
|
216 { |
|
217 iOperations[ aIndex]->ExecuteL( aManager); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // COperationParser::OperationCount() |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TInt COperationParser::OperationCount() |
|
225 { |
|
226 return iOperations.Count(); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // COperationParser::OnStartDocumentL() |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 |
|
234 |
|
235 void COperationParser::OnStartDocumentL(const Xml::RDocumentParameters& /*aDocParam*/, TInt /*aErrorCode*/) |
|
236 { |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // COperationParser::OnEndDocumentL() |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void COperationParser::OnEndDocumentL(TInt /*aErrorCode*/) |
|
244 { |
|
245 |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // COperationParser::OnStartElementL() |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void COperationParser::OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt /*aErrorCode*/) |
|
253 { |
|
254 using namespace OperationParserConstants; |
|
255 |
|
256 TPtrC8 elementName = aElement.LocalName().DesC(); |
|
257 CPolicyStorage* policyStorage = CPolicyStorage::PolicyStorage(); |
|
258 |
|
259 //package starts operation package |
|
260 if ( elementName != XMLStack[ iXMLStackPointer] ) |
|
261 { |
|
262 HandleErrorL( ParserErrors::UnexpectedElement, elementName); |
|
263 } |
|
264 |
|
265 if ( elementName == Operation ) |
|
266 { |
|
267 if ( !iActiveOperation ) |
|
268 { |
|
269 iActiveOperation = COperationInfo::NewL(); |
|
270 } |
|
271 else |
|
272 { |
|
273 HandleErrorL( ParserErrors::UnexpectedElement, elementName); |
|
274 } |
|
275 } |
|
276 |
|
277 //search element attributes |
|
278 for ( TInt i = 0; i < aAttributes.Count(); i++) |
|
279 { |
|
280 Xml::RAttribute attribute( aAttributes[i]); |
|
281 |
|
282 TPtrC8 attributeName = attribute.Attribute().LocalName().DesC(); |
|
283 TPtrC8 attributeValue = attribute.Value().DesC(); |
|
284 |
|
285 |
|
286 if ( iActiveOperation && elementName == Operation ) |
|
287 { |
|
288 if ( attributeName == ActionId ) |
|
289 { |
|
290 iActiveOperation->SetActionIdL( attributeValue ); |
|
291 } |
|
292 else if ( attributeName == TargetId) |
|
293 { |
|
294 iActiveOperation->SetTargetElementIdL( attributeValue ); |
|
295 } |
|
296 else if ( attributeName == UseBearerCert) |
|
297 { |
|
298 if ( attributeValue == True) |
|
299 { |
|
300 iActiveOperation->UseBearerCertificate( ETrue); |
|
301 } |
|
302 else |
|
303 { |
|
304 iActiveOperation->UseBearerCertificate( EFalse); |
|
305 } |
|
306 } |
|
307 else if ( attributeName == AddServerId) |
|
308 { |
|
309 if ( KErrNone != policyStorage->AddNewServerId( attributeValue)) |
|
310 { |
|
311 HandleErrorL( ManagementErrors::ServerIdManagementError, attributeName); |
|
312 } |
|
313 } |
|
314 else if ( attributeName == RemoveServerId) |
|
315 { |
|
316 if ( attributeValue == ResetAllTag) |
|
317 { |
|
318 if ( KErrNone != policyStorage->ResetServerIdList()) |
|
319 { |
|
320 HandleErrorL( ManagementErrors::ServerIdManagementError, attributeName); |
|
321 } |
|
322 } |
|
323 else |
|
324 { |
|
325 if ( KErrNone != policyStorage->RemoveServerId( attributeValue)) |
|
326 { |
|
327 HandleErrorL( ManagementErrors::ServerIdManagementError, attributeName); |
|
328 } |
|
329 } |
|
330 } |
|
331 else |
|
332 { |
|
333 HandleErrorL( ParserErrors::UnexpectedAttribute, attributeName); |
|
334 } |
|
335 } |
|
336 else |
|
337 { |
|
338 HandleErrorL( ParserErrors::UnexpectedAttribute, attributeName); |
|
339 } |
|
340 |
|
341 } |
|
342 |
|
343 iXMLStackPointer++; |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // COperationParser::OnEndElementL() |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 void COperationParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt /*aErrorCode*/) |
|
351 { |
|
352 using namespace OperationParserConstants; |
|
353 |
|
354 TPtrC8 elementName = aElement.LocalName().DesC(); |
|
355 |
|
356 //Add new operation operation list |
|
357 if ( elementName == Operation ) |
|
358 { |
|
359 iOperations.AppendL( iActiveOperation); |
|
360 iActiveOperation = NULL; |
|
361 } |
|
362 |
|
363 iXMLStackPointer--; |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // COperationParser::OnContentL() |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 void COperationParser::OnContentL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
371 { |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // COperationParser::OnStartPrefixMappingL() |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 void COperationParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/) |
|
379 { |
|
380 |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // COperationParser::OnEndPrefixMappingL() |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 |
|
388 void COperationParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
389 { |
|
390 |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // COperationParser::OnIgnorableWhiteSpaceL() |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void COperationParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
398 { |
|
399 |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // COperationParser::OnSkippedEntityL() |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 void COperationParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/) |
|
407 { |
|
408 |
|
409 } |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // COperationParser::OnProcessingInstructionL() |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 void COperationParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/) |
|
416 { |
|
417 |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // COperationParser::OnError() |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 void COperationParser::OnError(TInt /*aErrorCode*/) |
|
425 { |
|
426 //parse error text |
|
427 iReturnText->Copy( _L8("(Line ")); |
|
428 iReturnText->AppendNum( iActiveLine); |
|
429 iReturnText->Append( _L8(") ")); |
|
430 iReturnText->Append( ParserErrors::SyntaxError); |
|
431 |
|
432 RDEBUG_2("Operation parser error: %S", &iReturnText); |
|
433 |
|
434 // PolicyEngine expects this leave in error conditions -> prgram flow |
|
435 // goes to correct TRAP after this. Can not remove this Leave although |
|
436 // the function name does not have "L" |
|
437 User::Leave( KErrOpParser ); |
|
438 } |
|
439 |
|
440 // ----------------------------------------------------------------------------- |
|
441 // COperationParser::GetExtendedInterface() |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 TAny* COperationParser::GetExtendedInterface(const TInt32 /*aUid*/) |
|
445 { |
|
446 return NULL; |
|
447 } |
|
448 |
|
449 |
|
450 // ----------------------------------------------------------------------------- |
|
451 // COperationParser::GetExtendedInterface() |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 COperationInfo::COperationInfo() |
|
455 { |
|
456 } |
|
457 |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // COperationParser::~COperationInfo() |
|
461 // ----------------------------------------------------------------------------- |
|
462 // |
|
463 COperationInfo::~COperationInfo() |
|
464 { |
|
465 delete iActionId; |
|
466 delete iTargetElement; |
|
467 } |
|
468 |
|
469 // ----------------------------------------------------------------------------- |
|
470 // COperationParser::NewL() |
|
471 // ----------------------------------------------------------------------------- |
|
472 // |
|
473 |
|
474 COperationInfo* COperationInfo::NewL() |
|
475 { |
|
476 return new (ELeave) COperationInfo(); |
|
477 } |
|
478 |
|
479 // ----------------------------------------------------------------------------- |
|
480 // COperationInfo::UseBearerCertificate() |
|
481 // ----------------------------------------------------------------------------- |
|
482 // |
|
483 void COperationInfo::UseBearerCertificate( const TBool aUseBearerCertificate) |
|
484 { |
|
485 iUseBearerCertificate = aUseBearerCertificate; |
|
486 } |
|
487 |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // COperationParser::SetActionIdL() |
|
491 // ----------------------------------------------------------------------------- |
|
492 // |
|
493 |
|
494 void COperationInfo::SetActionIdL( const TDesC8& aActionId) |
|
495 { |
|
496 if ( iActionId ) |
|
497 { |
|
498 User::Leave( KErrOpParser); |
|
499 } |
|
500 |
|
501 iActionId = aActionId.AllocL(); |
|
502 } |
|
503 |
|
504 // ----------------------------------------------------------------------------- |
|
505 // COperationParser::SetTargetElementIdL() |
|
506 // ----------------------------------------------------------------------------- |
|
507 // |
|
508 |
|
509 void COperationInfo::SetTargetElementIdL( const TDesC8& aTargetElementId) |
|
510 { |
|
511 if ( iTargetElement ) |
|
512 { |
|
513 User::Leave( KErrOpParser); |
|
514 } |
|
515 |
|
516 iTargetElement = aTargetElementId.AllocL(); |
|
517 } |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // COperationParser::SetXACMLContentL() |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 |
|
524 void COperationInfo::SetXACMLContentL( const TPtrC8& aXACMLContent) |
|
525 { |
|
526 if ( iXACMLContent.Length()) |
|
527 { |
|
528 User::Leave( KErrOpParser); |
|
529 } |
|
530 |
|
531 iXACMLContent.Set( aXACMLContent); |
|
532 } |
|
533 |
|
534 |
|
535 // ----------------------------------------------------------------------------- |
|
536 // COperationParser::ExecuteL() |
|
537 // ----------------------------------------------------------------------------- |
|
538 // |
|
539 |
|
540 void COperationInfo::ExecuteL( CPolicyManager *iManager) |
|
541 { |
|
542 if ( *iActionId == OperationParserConstants::Add) |
|
543 { |
|
544 iManager->NewElementL( iLineOffset, *iTargetElement, iXACMLContent, iUseBearerCertificate); |
|
545 } |
|
546 else if ( *iActionId == OperationParserConstants::Remove) |
|
547 { |
|
548 iManager->RemoveElementL( *iTargetElement); |
|
549 } |
|
550 else if ( *iActionId == OperationParserConstants::Replace) |
|
551 { |
|
552 iManager->ReplaceElementL( iLineOffset, *iTargetElement, iXACMLContent); |
|
553 } |
|
554 else |
|
555 { |
|
556 User::Panic( Panics::OperationParserPanic, KErrGeneral); |
|
557 } |
|
558 } |
|
559 |
|
560 // ----------------------------------------------------------------------------- |
|
561 // COperationParser::SetLineOffset() |
|
562 // ----------------------------------------------------------------------------- |
|
563 // |
|
564 |
|
565 void COperationInfo::SetLineOffset( const TInt& aLineOffset) |
|
566 { |
|
567 iLineOffset = aLineOffset; |
|
568 } |
|
569 |
|
570 |