85 CRepository* repository( NULL ); |
84 CRepository* repository( NULL ); |
86 RBuf bOmaBasedMimeType; |
85 RBuf bOmaBasedMimeType; |
87 HBufC8* mimetype = NULL; |
86 HBufC8* mimetype = NULL; |
88 |
87 |
89 CleanupClosePushL(bOmaBasedMimeType); |
88 CleanupClosePushL(bOmaBasedMimeType); |
90 bOmaBasedMimeType.CreateL( KCenRepDataLength ); |
89 bOmaBasedMimeType.CreateL( KCenRepDataLength ); |
91 |
90 |
92 repository = CRepository::NewL( KCRUidOmaBased ); |
91 repository = CRepository::NewL( KCRUidOmaBased ); |
93 |
92 |
94 CleanupStack::PushL( repository ); |
93 CleanupStack::PushL( repository ); |
95 |
94 |
96 User::LeaveIfError(repository->Get( KOmaBasedMimeType, bOmaBasedMimeType )); |
95 User::LeaveIfError(repository->Get( KOmaBasedMimeType, bOmaBasedMimeType )); |
97 mimetype = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bOmaBasedMimeType ); |
96 mimetype = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bOmaBasedMimeType ); |
98 CleanupStack::PopAndDestroy( repository ); |
97 CleanupStack::PopAndDestroy( repository ); |
99 |
98 |
100 CleanupStack::PopAndDestroy(); |
99 CleanupStack::PopAndDestroy(); |
101 |
100 |
102 return mimetype; |
101 return mimetype; |
103 |
102 |
104 } |
103 } |
105 |
104 |
106 // ----------------------------------------------------------------------------- |
105 // ----------------------------------------------------------------------------- |
107 // COma1Dcf::NewL |
106 // COma1Dcf::NewL |
108 // Two-phased constructor. |
107 // Two-phased constructor. |
109 // ----------------------------------------------------------------------------- |
108 // ----------------------------------------------------------------------------- |
110 // |
109 // |
111 EXPORT_C COma1Dcf* COma1Dcf::NewL(const RFile& aFile) |
110 EXPORT_C COma1Dcf* COma1Dcf::NewL(const RFile& aFile) |
112 { |
111 { |
113 COma1Dcf* self = new(ELeave) COma1Dcf; |
112 COma1Dcf* self = new(ELeave) COma1Dcf; |
114 |
113 |
115 CleanupStack::PushL(self); |
114 CleanupStack::PushL(self); |
116 self->ConstructL(aFile); |
115 self->ConstructL(aFile); |
117 CleanupStack::Pop(); |
116 CleanupStack::Pop(); |
118 |
117 |
119 return self; |
118 return self; |
120 } |
119 } |
121 |
120 |
122 // ----------------------------------------------------------------------------- |
121 // ----------------------------------------------------------------------------- |
123 // COma1Dcf:: |
122 // COma1Dcf:: |
124 // |
123 // |
125 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
126 // |
125 // |
127 EXPORT_C COma1Dcf* COma1Dcf::NewL(const TDesC8& aMemoryBlock) |
126 EXPORT_C COma1Dcf* COma1Dcf::NewL(const TDesC8& aMemoryBlock) |
128 { |
127 { |
129 COma1Dcf* self = new(ELeave) COma1Dcf; |
128 COma1Dcf* self = new(ELeave) COma1Dcf; |
130 |
129 |
131 CleanupStack::PushL(self); |
130 CleanupStack::PushL(self); |
132 self->ConstructL(aMemoryBlock); |
131 self->ConstructL(aMemoryBlock); |
133 CleanupStack::Pop(); |
132 CleanupStack::Pop(); |
134 |
133 |
135 return self; |
134 return self; |
136 } |
135 } |
137 |
136 |
138 // ----------------------------------------------------------------------------- |
137 // ----------------------------------------------------------------------------- |
139 // COma1Dcf:: |
138 // COma1Dcf:: |
140 // |
139 // |
141 // ----------------------------------------------------------------------------- |
140 // ----------------------------------------------------------------------------- |
142 // |
141 // |
143 EXPORT_C COma1Dcf::~COma1Dcf() |
142 EXPORT_C COma1Dcf::~COma1Dcf() |
144 { |
143 { |
145 delete iHeaders; |
144 delete iHeaders; |
146 } |
145 } |
147 |
146 |
148 // ----------------------------------------------------------------------------- |
147 // ----------------------------------------------------------------------------- |
149 // COma1Dcf:: |
148 // COma1Dcf:: |
150 // |
149 // |
151 // ----------------------------------------------------------------------------- |
150 // ----------------------------------------------------------------------------- |
152 // |
151 // |
153 TInt COma1Dcf::ReadHeaderL(const TDesC8& aMemoryBlock) |
152 TInt COma1Dcf::ReadHeaderL(const TDesC8& aMemoryBlock) |
154 { |
153 { |
155 TInt r = KErrNone; |
154 TInt r = KErrNone; |
157 TInt mimeLength = 0; |
156 TInt mimeLength = 0; |
158 TInt fieldLength = 0; |
157 TInt fieldLength = 0; |
159 TBuf8<10> lengthFields; |
158 TBuf8<10> lengthFields; |
160 TUint32 length; |
159 TUint32 length; |
161 TPtr8 ptr(NULL,0,0); |
160 TPtr8 ptr(NULL,0,0); |
162 |
161 |
163 if (aMemoryBlock.Length()<3) |
162 if (aMemoryBlock.Length()<3) |
164 { |
163 { |
165 User::Leave(KErrArgument); |
164 User::Leave(KErrArgument); |
166 } |
165 } |
167 |
166 |
168 iVersion = aMemoryBlock[0]; |
167 iVersion = aMemoryBlock[0]; |
169 |
168 |
170 if (iVersion!=1) |
169 if (iVersion!=1) |
171 { |
170 { |
172 // for OMA Version 1, DCF version must be 1 |
171 // for OMA Version 1, DCF version must be 1 |
173 User::Leave(KErrArgument); |
172 User::Leave(KErrArgument); |
174 } |
173 } |
175 |
174 |
176 mimeLength = aMemoryBlock[1]; |
175 mimeLength = aMemoryBlock[1]; |
177 cidLength = aMemoryBlock[2]; |
176 cidLength = aMemoryBlock[2]; |
178 |
177 |
179 if (mimeLength + cidLength + 3 + 5 + 5 > aMemoryBlock.Length()) |
178 if (mimeLength + cidLength + 3 + 5 + 5 > aMemoryBlock.Length()) |
180 { |
179 { |
181 User::Leave(KErrArgument); |
180 User::Leave(KErrArgument); |
182 } |
181 } |
183 |
182 |
184 |
183 |
185 if (mimeLength!=0) |
184 if (mimeLength!=0) |
186 { |
185 { |
187 iMimeType = aMemoryBlock.Mid(3, mimeLength).AllocL(); |
186 iMimeType = aMemoryBlock.Mid(3, mimeLength).AllocL(); |
188 ptr.Set(iMimeType->Des()); |
187 ptr.Set(iMimeType->Des()); |
189 r = ptr.FindF(_L8("/")); |
188 r = ptr.FindF(_L8("/")); |
194 } |
193 } |
195 else |
194 else |
196 { |
195 { |
197 User::Leave(KErrArgument); |
196 User::Leave(KErrArgument); |
198 } |
197 } |
199 |
198 |
200 |
199 |
201 if (cidLength!=0) |
200 if (cidLength!=0) |
202 { |
201 { |
203 iContentID = aMemoryBlock.Mid(3 + mimeLength, cidLength).AllocL(); |
202 iContentID = aMemoryBlock.Mid(3 + mimeLength, cidLength).AllocL(); |
204 } |
203 } |
205 else |
204 else |
206 { |
205 { |
207 User::Leave(KErrArgument); |
206 User::Leave(KErrArgument); |
208 } |
207 } |
209 |
208 |
210 |
209 |
211 lengthFields.Copy(aMemoryBlock.Mid(3 + mimeLength + cidLength, 10)); |
210 lengthFields.Copy(aMemoryBlock.Mid(3 + mimeLength + cidLength, 10)); |
212 TWspPrimitiveDecoder decoder(lengthFields); |
211 TWspPrimitiveDecoder decoder(lengthFields); |
213 fieldLength = decoder.UintVar(length); |
212 fieldLength = decoder.UintVar(length); |
214 if( fieldLength < 0 ) |
213 if( fieldLength < 0 ) |
215 { |
214 { |
216 User::Leave(KErrArgument); |
215 User::Leave(KErrArgument); |
217 } |
216 } |
218 iHeaderLength = length; |
217 iHeaderLength = length; |
219 fieldLength += decoder.UintVar(length); |
218 fieldLength += decoder.UintVar(length); |
220 if( fieldLength < 0 ) |
219 if( fieldLength < 0 ) |
221 { |
220 { |
222 User::Leave(KErrArgument); |
221 User::Leave(KErrArgument); |
223 } |
222 } |
224 |
223 |
225 iDataLength = length; |
224 iDataLength = length; |
226 iOffset = 3 + mimeLength + cidLength + fieldLength + iHeaderLength; |
225 iOffset = 3 + mimeLength + cidLength + fieldLength + iHeaderLength; |
227 if (iDataLength == 0) |
226 if (iDataLength == 0) |
228 { |
227 { |
229 iDataLength = aMemoryBlock.Length() - iOffset; |
228 iDataLength = aMemoryBlock.Length() - iOffset; |
260 } |
259 } |
261 iRightsIssuerURL = ptr.AllocL(); |
260 iRightsIssuerURL = ptr.AllocL(); |
262 } |
261 } |
263 if (GetHeaderL(KContentName, ptr) == KErrNone) |
262 if (GetHeaderL(KContentName, ptr) == KErrNone) |
264 { |
263 { |
265 if( iTitle ) |
264 if( iTitle ) |
266 { |
265 { |
267 delete iTitle; |
266 delete iTitle; |
268 iTitle = NULL; |
267 iTitle = NULL; |
269 } |
268 } |
270 iTitle = ptr.AllocL(); |
269 iTitle = ptr.AllocL(); |
271 } |
270 } |
272 if (GetHeaderL(KContentDescription, ptr) == KErrNone) |
271 if (GetHeaderL(KContentDescription, ptr) == KErrNone) |
273 { |
272 { |
274 if( iDescription ) |
273 if( iDescription ) |
275 { |
274 { |
276 delete iDescription; |
275 delete iDescription; |
277 iDescription = NULL; |
276 iDescription = NULL; |
278 } |
277 } |
279 iDescription = ptr.AllocL(); |
278 iDescription = ptr.AllocL(); |
280 } |
279 } |
281 if (GetHeaderL(KIconURI, ptr) == KErrNone) |
280 if (GetHeaderL(KIconURI, ptr) == KErrNone) |
282 { |
281 { |
283 if( iIconUri ) |
282 if( iIconUri ) |
284 { |
283 { |
285 delete iIconUri; |
284 delete iIconUri; |
286 iIconUri = NULL; |
285 iIconUri = NULL; |
287 } |
286 } |
288 iIconUri = ptr.AllocL(); |
287 iIconUri = ptr.AllocL(); |
289 } |
288 } |
290 } |
289 } |
291 |
290 |
292 // ----------------------------------------------------------------------------- |
291 // ----------------------------------------------------------------------------- |
293 // COma1Dcf:: |
292 // COma1Dcf:: |
294 // |
293 // |
295 // ----------------------------------------------------------------------------- |
294 // ----------------------------------------------------------------------------- |
296 // |
295 // |
297 TInt COma1Dcf::ReadHeaderL(void) |
296 TInt COma1Dcf::ReadHeaderL(void) |
298 { |
297 { |
299 TInt r = KErrNone; |
298 TInt r = KErrNone; |
440 return r; |
439 return r; |
441 } |
440 } |
442 |
441 |
443 // ----------------------------------------------------------------------------- |
442 // ----------------------------------------------------------------------------- |
444 // COma1Dcf:: |
443 // COma1Dcf:: |
445 // |
444 // |
446 // ----------------------------------------------------------------------------- |
445 // ----------------------------------------------------------------------------- |
447 // |
446 // |
448 TInt COma1Dcf::CheckUniqueId(const TDesC& aUniqueId) |
447 TInt COma1Dcf::CheckUniqueId(const TDesC& aUniqueId) |
449 { |
448 { |
450 TInt r = CDcfCommon::CheckUniqueId(aUniqueId); |
449 TInt r = CDcfCommon::CheckUniqueId(aUniqueId); |
451 |
450 |
452 if (r == KErrNotFound) |
451 if (r == KErrNotFound) |
453 { |
452 { |
454 HBufC8* id = NULL; |
453 HBufC8* id = NULL; |
455 TRAPD(err, id = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aUniqueId)); |
454 TRAPD(err, id = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aUniqueId)); |
456 if (err == KErrNone) |
455 if (err == KErrNone) |
457 { |
456 { |
458 if (iContentID->Compare(*id) == 0) |
457 if (iContentID->Compare(*id) == 0) |
459 { |
458 { |
460 r = 0; |
459 r = 0; |
461 } |
460 } |
462 } |
461 } |
463 else |
462 else |
464 { |
463 { |
465 r = err; |
464 r = err; |
466 } |
465 } |
467 delete id; |
466 delete id; |
468 } |
467 } |
469 return r; |
468 return r; |
470 } |
469 } |
471 |
470 |
472 // ----------------------------------------------------------------------------- |
471 // ----------------------------------------------------------------------------- |
473 // COma1Dcf:: |
472 // COma1Dcf:: |
474 // |
473 // |
475 // ----------------------------------------------------------------------------- |
474 // ----------------------------------------------------------------------------- |
476 // |
475 // |
477 TInt COma1Dcf::OpenPart(const TDesC& aUniqueId) |
476 TInt COma1Dcf::OpenPart(const TDesC& aUniqueId) |
478 { |
477 { |
479 return OpenPart(CheckUniqueId(aUniqueId)); |
478 return OpenPart(CheckUniqueId(aUniqueId)); |
480 } |
479 } |
481 |
480 |
482 // ----------------------------------------------------------------------------- |
481 // ----------------------------------------------------------------------------- |
483 // COma1Dcf:: |
482 // COma1Dcf:: |
484 // |
483 // |
485 // ----------------------------------------------------------------------------- |
484 // ----------------------------------------------------------------------------- |
486 // |
485 // |
487 TInt COma1Dcf::OpenPart(TInt aPart) |
486 TInt COma1Dcf::OpenPart(TInt aPart) |
488 { |
487 { |
489 if (aPart == 0) |
488 if (aPart == 0) |
490 { |
489 { |
491 return KErrNone; |
490 return KErrNone; |
492 } |
491 } |
493 else |
492 else |
494 { |
493 { |
495 return KErrNotFound; |
494 return KErrNotFound; |
496 } |
495 } |
497 } |
496 } |
498 |
497 |
499 // ----------------------------------------------------------------------------- |
498 // ----------------------------------------------------------------------------- |
500 // COma1Dcf:: |
499 // COma1Dcf:: |
501 // |
500 // |
502 // ----------------------------------------------------------------------------- |
501 // ----------------------------------------------------------------------------- |
503 // |
502 // |
504 void COma1Dcf::GetPartIdsL(RPointerArray<HBufC8>& aPartList) |
503 void COma1Dcf::GetPartIdsL(RPointerArray<HBufC8>& aPartList) |
505 { |
504 { |
506 aPartList.ResetAndDestroy(); |
505 aPartList.ResetAndDestroy(); |
507 aPartList.AppendL(iContentID->Des().AllocL()); |
506 aPartList.AppendL(iContentID->Des().AllocL()); |
508 } |
507 } |
509 |
508 |
510 // ----------------------------------------------------------------------------- |
509 // ----------------------------------------------------------------------------- |
511 // COma1Dcf::GetHeaderL |
510 // COma1Dcf::GetHeaderL |
512 // |
511 // |
513 // ----------------------------------------------------------------------------- |
512 // ----------------------------------------------------------------------------- |
514 // |
513 // |
515 EXPORT_C TInt COma1Dcf::GetHeaderL( |
514 EXPORT_C TInt COma1Dcf::GetHeaderL( |
516 const TDesC8& aHeaderName, |
515 const TDesC8& aHeaderName, |
517 TPtrC8& aHeaderValue) |
516 TPtrC8& aHeaderValue) |
518 { |
517 { |
519 TInt i; |
518 TInt i; |
520 TInt j; |
519 TInt j; |
521 TPtrC8 ptr( iHeaders->Des() ); |
520 TPtrC8 ptr( iHeaders->Des() ); |
522 |
521 |
523 // Add Room for CRLF and Semicolon: |
522 // Add Room for CRLF and Semicolon: |
524 HBufC8* buffer = HBufC8::NewMaxLC( aHeaderName.Length() + 3 ); |
523 HBufC8* buffer = HBufC8::NewMaxLC( aHeaderName.Length() + 3 ); |
525 TPtr8 searchBuf( const_cast<TUint8*>(buffer->Ptr()), 0, buffer->Des().MaxSize() ); |
524 TPtr8 searchBuf( const_cast<TUint8*>(buffer->Ptr()), 0, buffer->Des().MaxSize() ); |
526 |
525 |
527 searchBuf.Copy(aHeaderName); |
526 searchBuf.Copy(aHeaderName); |
528 searchBuf.Append(KColon); |
527 searchBuf.Append(KColon); |
529 |
528 |
530 // First see if the |
529 // First see if the |
531 i = ptr.Find(searchBuf); |
530 i = ptr.Find(searchBuf); |
532 if( i < 0 ) |
531 if( i < 0 ) |
533 { |
532 { |
534 CleanupStack::PopAndDestroy(); // buffer |
533 CleanupStack::PopAndDestroy(); // buffer |
535 return KErrNotFound; |
534 return KErrNotFound; |
536 } |
535 } |
537 |
536 |
538 if( i > 0 ) |
537 if( i > 0 ) |
539 { |
538 { |
540 // if it's not the first one, use the search buffer: |
539 // if it's not the first one, use the search buffer: |
541 // Create the search buffer |
540 // Create the search buffer |
542 searchBuf.Copy(KEndLine); |
541 searchBuf.Copy(KEndLine); |
543 searchBuf.Append(aHeaderName); |
542 searchBuf.Append(aHeaderName); |
544 searchBuf.Append(KColon); |
543 searchBuf.Append(KColon); |
545 |
544 |
546 // First see if the |
545 // First see if the |
547 i = ptr.Find(searchBuf); |
546 i = ptr.Find(searchBuf); |
548 if ( i < 0 ) |
547 if ( i < 0 ) |
549 { |
548 { |
550 CleanupStack::PopAndDestroy(); // buffer |
549 CleanupStack::PopAndDestroy(); // buffer |
551 return KErrNotFound; |
550 return KErrNotFound; |
552 } |
551 } |
553 } |
552 } |
554 // Move search buffer |
553 // Move search buffer |
555 i += searchBuf.Length(); |
554 i += searchBuf.Length(); |
556 |
555 |
557 j = ptr.Mid(i).Find(KEndLine); |
556 j = ptr.Mid(i).Find(KEndLine); |
558 if( j < 0 ) |
557 if( j < 0 ) |
559 { |
558 { |
560 CleanupStack::PopAndDestroy(); // buffer |
559 CleanupStack::PopAndDestroy(); // buffer |
561 return KErrNotFound; |
560 return KErrNotFound; |
562 } |
561 } |
563 |
562 |
564 aHeaderValue.Set( ptr.Mid(i, j) ); |
563 aHeaderValue.Set( ptr.Mid(i, j) ); |
565 |
564 |
566 CleanupStack::PopAndDestroy(); // buffer |
565 CleanupStack::PopAndDestroy(); // buffer |
567 return KErrNone; |
566 return KErrNone; |
568 } |
567 } |
569 |
568 |
570 // End of File |
569 // End of File |