|
1 /* |
|
2 * Copyright (c) 2006 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 plugin info |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <mpxuser.h> |
|
22 #include <mpxlog.h> |
|
23 #include <mpxplugininfo.h> |
|
24 |
|
25 |
|
26 // CONSTANTS |
|
27 _LIT8(KMPXTagMatch, "*<?>*"); |
|
28 _LIT8(KMPXTagEnd,"*<*?>*"); |
|
29 |
|
30 _LIT8(KMPXSupportUidsTag, "<p>"); |
|
31 _LIT8(KMPXPluginTypeTag, "<t>" ); |
|
32 _LIT8(KMPXPluginFlagTag, "<f>" ); |
|
33 _LIT8(KMPXPluginPriorityTag, "<i>" ); |
|
34 _LIT8(KMPXSupportSchemasTag,"<s>"); |
|
35 _LIT8(KMPXSupportExtensionsTag,"<e>"); |
|
36 |
|
37 _LIT8(KMPXSupportAppUidTag, "<a>"); |
|
38 _LIT8(KMPX0x, "0x"); |
|
39 _LIT8(KMPX0X, "0X"); |
|
40 const TUint8 KMPXSemicolon = ';'; |
|
41 const TInt KMPXTagLength = 3; |
|
42 |
|
43 |
|
44 // ============================ INTERNAL CLASSES ============================== |
|
45 |
|
46 /** |
|
47 Utility class used to parse data separated by xml-style tags. |
|
48 */ |
|
49 class TaggedDataParser |
|
50 { |
|
51 public: |
|
52 |
|
53 /** |
|
54 *Splits aData into xml-style tags and values, and gets aClient to process |
|
55 *each tag/value pair. |
|
56 */ |
|
57 static void ParseTaggedDataL(const TDesC8& aData, |
|
58 MTaggedDataParserClient& aClient); |
|
59 |
|
60 /** |
|
61 * Converts a string to a Tint. The string may contain hex value or decimal value |
|
62 */ |
|
63 static void ConvertText8ToTIntL(const TDesC8& aData, TInt& aInt); |
|
64 |
|
65 /** |
|
66 * Extracts elemements separated by semicolon into array descriptor |
|
67 * |
|
68 * @param aText original content to extract elements from |
|
69 * @param aArray the array to add the extracted elements to |
|
70 */ |
|
71 static void ExtractIntoArrayL(const TDesC8& aText, CDesCArray*& aArray); |
|
72 |
|
73 /** |
|
74 * Add an item into descriptor array |
|
75 * |
|
76 * @param aItem the item to be added to the descriptor array |
|
77 * @param aArray the array to add the item to |
|
78 */ |
|
79 static void AddItemIntoArrayL(TPtrC8& aItem, CDesCArray*& aArray); |
|
80 }; |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // Parser xml-styled data |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 void TaggedDataParser::ParseTaggedDataL( |
|
87 const TDesC8& aData, |
|
88 MTaggedDataParserClient& aClient) |
|
89 { |
|
90 TPtrC8 data(aData); |
|
91 TInt readPosition = 0; |
|
92 TBool moreData = data.Length() ? ETrue : EFalse; |
|
93 while (moreData) |
|
94 { |
|
95 // Assumes that this segment will begin with a tag |
|
96 TPtrC8 restOfData = data.Mid(readPosition); |
|
97 |
|
98 TInt endPos = restOfData.MatchF(KMPXTagMatch); |
|
99 if (endPos == KErrNotFound) |
|
100 User::Leave(KErrCorrupt); |
|
101 |
|
102 // extract the tag |
|
103 TPtrC8 tag = restOfData.Left(KMPXTagLength); |
|
104 readPosition += KMPXTagLength; |
|
105 // Find the next tag |
|
106 restOfData.Set(data.Mid(readPosition)); |
|
107 endPos = restOfData.MatchF(KMPXTagMatch); |
|
108 |
|
109 TPtrC8 tagData; |
|
110 if (endPos == KErrNotFound) |
|
111 { // no more tag available |
|
112 endPos = restOfData.MatchF(KMPXTagEnd); |
|
113 if (endPos == KErrNotFound) |
|
114 { // If we didn't find a tag ender, we must be at the end of |
|
115 // the data |
|
116 tagData.Set(restOfData); |
|
117 readPosition = restOfData.Length(); |
|
118 } |
|
119 else |
|
120 { |
|
121 tagData.Set(restOfData.Left(endPos)); |
|
122 } |
|
123 moreData = EFalse; |
|
124 } |
|
125 else |
|
126 { |
|
127 // strip the end tag from data if found |
|
128 TInt stripEndPos = restOfData.MatchF(KMPXTagEnd); |
|
129 if ( stripEndPos != KErrNotFound ) |
|
130 { |
|
131 tagData.Set(restOfData.Left(stripEndPos)); |
|
132 } |
|
133 else |
|
134 { |
|
135 tagData.Set(restOfData.Left(endPos)); |
|
136 } |
|
137 readPosition += endPos; |
|
138 } |
|
139 aClient.ProcessTaggedDataL(tag, tagData); |
|
140 } |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // Convert text into a integer |
|
145 // ---------------------------------------------------------------------------- |
|
146 // |
|
147 void TaggedDataParser::ConvertText8ToTIntL( |
|
148 const TDesC8& aData, |
|
149 TInt& aInt) |
|
150 { |
|
151 // Determine whether hex or decimal then parse as such |
|
152 if (((aData.FindF(KMPX0x) == 0) || (aData.FindF(KMPX0X) == 0)) && |
|
153 (aData.Length() >= KMPXTagLength)) |
|
154 { |
|
155 // only take the characters after "0x" |
|
156 TLex8 lex(aData.Right(aData.Length()-2)); |
|
157 TUint value( 0 ); |
|
158 User::LeaveIfError(lex.Val(value, EHex)); |
|
159 aInt = value; |
|
160 } |
|
161 else if (aData.Length() > 0) |
|
162 { |
|
163 TLex8 lex(aData); |
|
164 TInt32 value(0); |
|
165 User::LeaveIfError(lex.Val(value)); |
|
166 aInt = value; |
|
167 } |
|
168 else |
|
169 { |
|
170 User::Leave(KErrCorrupt); |
|
171 } |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // Extracts elemements separated by semicolon into array descriptor |
|
176 // ---------------------------------------------------------------------------- |
|
177 // |
|
178 void TaggedDataParser::ExtractIntoArrayL( |
|
179 const TDesC8& aText, |
|
180 CDesCArray*& aArray) |
|
181 { |
|
182 const TUint8* p = aText.Ptr(); |
|
183 TInt startPos(0); |
|
184 TInt pos(0); |
|
185 TInt len=aText.Length(); |
|
186 TPtrC8 element; |
|
187 |
|
188 while (pos < len) |
|
189 { |
|
190 if (*(p+pos) == KMPXSemicolon) |
|
191 { |
|
192 if (pos-startPos > 0) |
|
193 { |
|
194 element.Set(p+startPos, pos - startPos); |
|
195 AddItemIntoArrayL(element, aArray); |
|
196 } |
|
197 startPos = pos + 1; |
|
198 } |
|
199 ++pos; |
|
200 } |
|
201 if (startPos < len && pos - startPos > 0) |
|
202 {// last item |
|
203 element.Set(p+startPos, pos - startPos); |
|
204 AddItemIntoArrayL(element, aArray); |
|
205 } |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Add an item into descriptor |
|
210 // ---------------------------------------------------------------------------- |
|
211 // |
|
212 void TaggedDataParser::AddItemIntoArrayL(TPtrC8& aItem, CDesCArray*& aArray) |
|
213 { |
|
214 HBufC* item = MPXUser::AllocL(aItem); |
|
215 CleanupStack::PushL(item); |
|
216 //ignore leave when insert the same item |
|
217 TRAP_IGNORE(aArray->InsertIsqL(*item)); |
|
218 CleanupStack::PopAndDestroy(item); |
|
219 } |
|
220 |
|
221 |
|
222 // ============================ MEMBER FUNCTIONS ============================== |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // C++ default constructor can NOT contain any code, that |
|
226 // might leave. |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C CMPXPluginInfo::CMPXPluginInfo() |
|
230 { |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // By default Symbian 2nd phase constructor is private. |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C void CMPXPluginInfo::ConstructL( |
|
238 const CImplementationInformation& aData ) |
|
239 { |
|
240 iPluginName = aData.DisplayName().AllocL(); |
|
241 iPluginUid = aData.ImplementationUid(); |
|
242 iVersion = aData.Version(); |
|
243 |
|
244 iSupportedSchemas = new(ELeave)CDesCArrayFlat(KMPXArrayGranularity); |
|
245 iSupportedMimeTypes = new(ELeave)CDesCArrayFlat(KMPXArrayGranularity); |
|
246 iSupportedExtensions = new(ELeave)CDesCArrayFlat(KMPXArrayGranularity); |
|
247 |
|
248 TaggedDataParser::ExtractIntoArrayL(aData.DataType(), iSupportedMimeTypes); |
|
249 // Parse the opaque data... |
|
250 TaggedDataParser::ParseTaggedDataL(aData.OpaqueData(), *this); |
|
251 // Add plugin type into supported ids array |
|
252 TInt err=iSupportedUids.InsertInOrder(iPluginTypeUid,MPXUser::CompareUids); |
|
253 if (KErrNone!=err && KErrAlreadyExists!=err) |
|
254 { // ignore duplicated items |
|
255 User::Leave(err); |
|
256 } |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // Two-phased constructor. |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 CMPXPluginInfo* CMPXPluginInfo::NewL( |
|
264 const CImplementationInformation& aData ) |
|
265 { |
|
266 CMPXPluginInfo* self = CMPXPluginInfo::NewLC( aData ); |
|
267 CleanupStack::Pop( self ); |
|
268 |
|
269 return self; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // Two-phased constructor. |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 CMPXPluginInfo* CMPXPluginInfo::NewLC( |
|
277 const CImplementationInformation& aData ) |
|
278 { |
|
279 CMPXPluginInfo* self = new ( ELeave ) CMPXPluginInfo(); |
|
280 CleanupStack::PushL( self ); |
|
281 self->ConstructL( aData ); |
|
282 |
|
283 return self; |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // Destructor |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 EXPORT_C CMPXPluginInfo::~CMPXPluginInfo() |
|
291 { |
|
292 delete iPluginName; |
|
293 iSupportedUids.Close(); |
|
294 delete iSupportedSchemas; |
|
295 delete iSupportedMimeTypes; |
|
296 delete iSupportedExtensions; |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // Process a tagged data |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 EXPORT_C void CMPXPluginInfo::ProcessTaggedDataL(const TDesC8& aTag, const TDesC8& aData) |
|
304 { |
|
305 if (aTag==KMPXSupportUidsTag) |
|
306 { |
|
307 ExtractSupportedUidsL(aData); |
|
308 } |
|
309 else if (aTag==KMPXSupportAppUidTag) |
|
310 { |
|
311 TInt type(0); |
|
312 TaggedDataParser::ConvertText8ToTIntL(aData, type); |
|
313 iSupportedAppUid = TUid::Uid(type); |
|
314 MPX_DEBUG2("Plugin supported App Uid = %d", iSupportedAppUid); |
|
315 } |
|
316 else if (aTag==KMPXPluginTypeTag) |
|
317 { |
|
318 TInt type(0); |
|
319 TaggedDataParser::ConvertText8ToTIntL(aData, type); |
|
320 iPluginTypeUid = TUid::Uid(type); |
|
321 } |
|
322 else if (aTag==KMPXPluginFlagTag) |
|
323 { |
|
324 TInt value(0); |
|
325 TaggedDataParser::ConvertText8ToTIntL(aData, value); |
|
326 iFlags = (TUint)value; |
|
327 } |
|
328 else if (aTag==KMPXPluginPriorityTag) |
|
329 { |
|
330 iPriority = 0; |
|
331 TaggedDataParser::ConvertText8ToTIntL(aData, iPriority); |
|
332 } |
|
333 else if (aTag==KMPXSupportSchemasTag) |
|
334 { |
|
335 iSupportedSchemas->Reset(); |
|
336 TaggedDataParser::ExtractIntoArrayL(aData, iSupportedSchemas); |
|
337 } |
|
338 else if (aTag==KMPXSupportExtensionsTag) |
|
339 { |
|
340 iSupportedExtensions->Reset(); |
|
341 TaggedDataParser::ExtractIntoArrayL(aData, iSupportedExtensions); |
|
342 } |
|
343 else // let derived class to process the data |
|
344 { |
|
345 ProcessTaggedDataExL(aTag, aData); |
|
346 } |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // Default implementation of a extended tagged data |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 EXPORT_C void CMPXPluginInfo::ProcessTaggedDataExL( |
|
354 const TDesC8& /*aTag*/, |
|
355 const TDesC8& /*aData*/) |
|
356 { |
|
357 // Do nothing; derived class can add extended tags |
|
358 } |
|
359 // --------------------------------------------------------------------------- |
|
360 // Returns plugin's display name. |
|
361 // --------------------------------------------------------------------------- |
|
362 // |
|
363 const TDesC& CMPXPluginInfo::DisplayName() const |
|
364 { |
|
365 return iPluginName ? static_cast<const TDesC&>( *iPluginName ) : KNullDesC; |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // Returns plugin's implementation uid. |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 EXPORT_C const TUid& CMPXPluginInfo::ImplementationUid() const |
|
373 { |
|
374 return iPluginUid; |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // Returns plugin's supported uids. |
|
379 // --------------------------------------------------------------------------- |
|
380 // |
|
381 const TArray<TUid> CMPXPluginInfo::SupportedUids() const |
|
382 { |
|
383 return iSupportedUids.Array(); |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------------------------- |
|
387 // Returns plugin's plugin type. |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 const TUid& CMPXPluginInfo::PluginType() const |
|
391 { |
|
392 return iPluginTypeUid; |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // Returns Plugin's supported App Uid. |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 const TUid& CMPXPluginInfo::SupportedAppUid() const |
|
400 { |
|
401 return iSupportedAppUid; |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // Returns plugin's view priority. |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 TInt CMPXPluginInfo::Priority() const |
|
409 { |
|
410 return iPriority; |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // Extracts plugin supported Uids from data. |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 void CMPXPluginInfo::ExtractSupportedUidsL(const TDesC8& aData) |
|
418 { |
|
419 iSupportedUids.Reset(); |
|
420 ExtractUidsFromTextL( aData, iSupportedUids ); |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------------------------- |
|
424 // Parse a text string to extract a list of UIDs |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 EXPORT_C void CMPXPluginInfo::ExtractUidsFromTextL( const TDesC8& aData, |
|
428 RArray<TUid>& aArray ) |
|
429 { |
|
430 aArray.Reset(); |
|
431 const TUint8* p = aData.Ptr(); |
|
432 TInt startPos(0); |
|
433 TInt pos(0); |
|
434 TInt len=aData.Length(); |
|
435 TPtrC8 element; |
|
436 TInt err(KErrNone); |
|
437 while (pos < len) |
|
438 { |
|
439 if (*(p+pos) == KMPXSemicolon) |
|
440 { |
|
441 if (pos-startPos > 0) |
|
442 { |
|
443 element.Set(p+startPos, pos - startPos); |
|
444 TInt val(0); |
|
445 TaggedDataParser::ConvertText8ToTIntL(element, val); |
|
446 err = aArray.InsertInOrder(TUid::Uid(val), |
|
447 MPXUser::CompareUids); |
|
448 if (KErrNone!=err && KErrAlreadyExists!=err) |
|
449 { // ignore duplicated items |
|
450 User::Leave(err); |
|
451 } |
|
452 } |
|
453 startPos = pos + 1; |
|
454 } |
|
455 ++pos; |
|
456 } |
|
457 if (startPos < len && pos - startPos > 0) |
|
458 {// last item |
|
459 element.Set(p+startPos, pos - startPos); |
|
460 TInt val(0); |
|
461 TaggedDataParser::ConvertText8ToTIntL(element, val); |
|
462 aArray.AppendL(TUid::Uid(val)); |
|
463 } |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // Return supported mime types |
|
468 // --------------------------------------------------------------------------- |
|
469 // |
|
470 const CDesCArray& CMPXPluginInfo::SupportedMimeTypes() const |
|
471 { |
|
472 return *iSupportedMimeTypes; |
|
473 } |
|
474 |
|
475 // --------------------------------------------------------------------------- |
|
476 // Return supported extensions |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 |
|
480 const CDesCArray& CMPXPluginInfo::SupportedExtensions() const |
|
481 { |
|
482 return *iSupportedExtensions; |
|
483 } |
|
484 |
|
485 // --------------------------------------------------------------------------- |
|
486 // Return supported schemas |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 const CDesCArray& CMPXPluginInfo::SupportedSchemas() const |
|
490 { |
|
491 return *iSupportedSchemas; |
|
492 } |
|
493 |
|
494 // ---------------------------------------------------------------------------- |
|
495 // CMPXPluginInfo::SupportUids |
|
496 // ---------------------------------------------------------------------------- |
|
497 // |
|
498 TBool CMPXPluginInfo::SupportUids(const TArray<TUid>& aUids) const |
|
499 { |
|
500 return MPXUser::CompareOrderedUidArrays(iSupportedUids.Array(), aUids)>=0; |
|
501 } |
|
502 |
|
503 // ---------------------------------------------------------------------------- |
|
504 // CMPXPluginInfo::Flags |
|
505 // ---------------------------------------------------------------------------- |
|
506 // |
|
507 EXPORT_C TUint CMPXPluginInfo::Flags() const |
|
508 { |
|
509 return iFlags; |
|
510 } |
|
511 |
|
512 // ---------------------------------------------------------------------------- |
|
513 // CMPXPluginInfo::Flags |
|
514 // ---------------------------------------------------------------------------- |
|
515 // |
|
516 TInt CMPXPluginInfo::Version() const |
|
517 { |
|
518 return iVersion; |
|
519 } |
|
520 |
|
521 // ---------------------------------------------------------------------------- |
|
522 // CMPXPluginInfo::ReferenceCount |
|
523 // ---------------------------------------------------------------------------- |
|
524 // |
|
525 TInt& CMPXPluginInfo::ReferenceCount() |
|
526 { |
|
527 return iReferenceCount; |
|
528 } |
|
529 |
|
530 // ---------------------------------------------------------------------------- |
|
531 // CMPXPluginInfo::ComparePluginInfoByPriority |
|
532 // ---------------------------------------------------------------------------- |
|
533 // |
|
534 TInt CMPXPluginInfo::ComparePluginInfoByPriority( |
|
535 const CMPXPluginInfo& aPluginInfo1, |
|
536 const CMPXPluginInfo& aPluginInfo2) |
|
537 { |
|
538 TInt ret(0); |
|
539 if (aPluginInfo1.Priority() > aPluginInfo2.Priority()) |
|
540 { |
|
541 ret=-1; |
|
542 } |
|
543 else if (aPluginInfo1.Priority() < aPluginInfo2.Priority()) |
|
544 { |
|
545 ret=1; |
|
546 } |
|
547 return ret; |
|
548 } |
|
549 |
|
550 // --------------------------------------------------------------------------- |
|
551 // Extracts elemements separated by semicolon into array descriptor |
|
552 // ---------------------------------------------------------------------------- |
|
553 // |
|
554 EXPORT_C void CMPXPluginInfo::ExtractIntoArrayL(const TDesC8& aText, |
|
555 CDesCArray*& aArray) |
|
556 { |
|
557 TaggedDataParser::ExtractIntoArrayL(aText, aArray); |
|
558 } |
|
559 |
|
560 // End of File |