sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef REMOVE_CAF1 sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "mimefieldanddata.h" sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: EXPORT_C CCafMimeHeader* CCafMimeHeader::NewL(const TDesC8 &aContentType) sl@0: { sl@0: CCafMimeHeader *self = new (ELeave) CCafMimeHeader(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aContentType); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CCafMimeHeader::CCafMimeHeader() sl@0: { sl@0: } sl@0: sl@0: void CCafMimeHeader::ConstructL(const TDesC8 &aContentType) sl@0: { sl@0: SetStandardMimeDataL(EContentType, aContentType); sl@0: } sl@0: sl@0: EXPORT_C CCafMimeHeader::~CCafMimeHeader() sl@0: { sl@0: TInt i=0; sl@0: iNonStandardMimeHeaders.ResetAndDestroy(); sl@0: iNonStandardMimeHeaders.Close(); sl@0: sl@0: for(i = 0; i < EMimeMax; i++) sl@0: { sl@0: delete iStandardMimeHeader[i]; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCafMimeHeader::SetStandardMimeDataL(const TMimeFields &aIndex, const TDesC8& aData) sl@0: { sl@0: HBufC8 *data = aData.AllocLC(); sl@0: sl@0: // make sure mime types are lower case sl@0: if(aIndex == EContentType) sl@0: { sl@0: data->Des().LowerCase(); sl@0: } sl@0: sl@0: // replace whatever value was there before sl@0: delete iStandardMimeHeader[aIndex]; sl@0: iStandardMimeHeader[aIndex] = data; sl@0: sl@0: CleanupStack::Pop(data); sl@0: } sl@0: sl@0: EXPORT_C TPtrC8 CCafMimeHeader::StandardMimeData(const TMimeFields &aIndex) const sl@0: { sl@0: // If the field value has not been set, return a null string sl@0: if(iStandardMimeHeader[aIndex] == NULL) sl@0: { sl@0: return KNullDesC8(); sl@0: } sl@0: return TPtrC8(iStandardMimeHeader[aIndex]->Des()); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt CCafMimeHeader::NonStandardMimeCount() const sl@0: { sl@0: return iNonStandardMimeHeaders.Count(); sl@0: } sl@0: sl@0: EXPORT_C void CCafMimeHeader::AddNonStandardMimeL(const TDesC8& aFieldName, const TDesC8& aData) sl@0: { sl@0: CMimeFieldAndData *mimeData = CMimeFieldAndData::NewL(aFieldName, aData); sl@0: CleanupStack::PushL(mimeData); sl@0: iNonStandardMimeHeaders.Append(mimeData); sl@0: CleanupStack::Pop(mimeData); sl@0: } sl@0: sl@0: EXPORT_C TPtrC8 CCafMimeHeader::NonStandardMimeField(TInt aIndex) const sl@0: { sl@0: return iNonStandardMimeHeaders[aIndex]->FieldName(); sl@0: } sl@0: sl@0: EXPORT_C TPtrC8 CCafMimeHeader::NonStandardMimeData(TInt aIndex) const sl@0: { sl@0: return iNonStandardMimeHeaders[aIndex]->Data(); sl@0: } sl@0: sl@0: EXPORT_C void CCafMimeHeader::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: TInt i=0; sl@0: sl@0: // Write the contents of this class out to a stream sl@0: sl@0: // Write the number of standard mime headers sl@0: aStream.WriteInt32L(EMimeMax); sl@0: sl@0: // Write out the standard mime data, each one preceeded by it's length sl@0: for(i = 0; i < EMimeMax; i++) sl@0: { sl@0: TInt length=0; sl@0: sl@0: // Length is zero if the mime field has not been set, sl@0: if(iStandardMimeHeader[i] == NULL) sl@0: { sl@0: length = 0; sl@0: } sl@0: else sl@0: { sl@0: length = iStandardMimeHeader[i]->Length(); sl@0: } sl@0: sl@0: // write the field length sl@0: aStream.WriteInt16L(length); sl@0: if(length > 0) sl@0: { sl@0: // write the field value if length > 0 sl@0: aStream.WriteL(*iStandardMimeHeader[i]); sl@0: } sl@0: } sl@0: sl@0: aStream.WriteInt32L(iNonStandardMimeHeaders.Count()); sl@0: sl@0: // Write out non standard mime headers and data, each Des preceeded by it's length sl@0: for(i = 0; i < iNonStandardMimeHeaders.Count(); i++) sl@0: { sl@0: aStream.WriteInt16L(iNonStandardMimeHeaders[i]->FieldName().Length()); sl@0: if(iNonStandardMimeHeaders[i]->FieldName().Length() > 0) sl@0: { sl@0: aStream.WriteL(iNonStandardMimeHeaders[i]->FieldName()); sl@0: } sl@0: aStream.WriteInt16L(iNonStandardMimeHeaders[i]->Data().Length()); sl@0: if(iNonStandardMimeHeaders[i]->Data().Length() > 0) sl@0: { sl@0: aStream.WriteL(iNonStandardMimeHeaders[i]->Data()); sl@0: } sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCafMimeHeader::InternalizeL(RReadStream& aStream) sl@0: { sl@0: TInt i=0; sl@0: TInt fieldCount=0; sl@0: TInt16 length=0; sl@0: HBufC8 *field=NULL; sl@0: HBufC8 *data=NULL; sl@0: sl@0: sl@0: // clear any existing headers sl@0: iNonStandardMimeHeaders.ResetAndDestroy(); sl@0: for(i = 0; i < EMimeMax; i++) sl@0: { sl@0: // delete the existing data for the mime field sl@0: delete iStandardMimeHeader[i]; sl@0: iStandardMimeHeader[i] = NULL; sl@0: } sl@0: sl@0: sl@0: fieldCount= aStream.ReadInt32L(); sl@0: if(fieldCount != EMimeMax) sl@0: { sl@0: // something is seriously wrong, should always be EMimeMax standard headers sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: for(i = 0; i < EMimeMax; i++) sl@0: { sl@0: // read the length from the stream sl@0: length = aStream.ReadInt16L(); sl@0: if(length > 0) sl@0: { sl@0: // read in non zero fields, others will remain NULL sl@0: data = HBufC8::NewLC(length); sl@0: TPtr8 dataPtr = data->Des(); sl@0: aStream.ReadL(dataPtr,length); sl@0: SetStandardMimeDataL(static_cast (i), dataPtr); sl@0: CleanupStack::PopAndDestroy(data); sl@0: } sl@0: } sl@0: sl@0: fieldCount= aStream.ReadInt32L(); sl@0: sl@0: for(i = 0; i < fieldCount; i++) sl@0: { sl@0: // Read mime field name sl@0: length = aStream.ReadInt16L(); sl@0: if(length < 0) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: sl@0: field = HBufC8::NewLC(length); sl@0: TPtr8 fieldPtr = field->Des(); sl@0: if(length > 0) sl@0: { sl@0: aStream.ReadL(fieldPtr,length); sl@0: } sl@0: sl@0: // Read data sl@0: length = aStream.ReadInt16L(); sl@0: if(length < 0) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: sl@0: data = HBufC8::NewLC(length); sl@0: TPtr8 dataPtr = data->Des(); sl@0: if(length > 0) sl@0: { sl@0: aStream.ReadL(dataPtr,length); sl@0: } sl@0: sl@0: // Add a new mime field and data to our array sl@0: AddNonStandardMimeL(fieldPtr, dataPtr); sl@0: sl@0: // free memory allocated sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(field); sl@0: } sl@0: } sl@0: sl@0: sl@0: #endif // #ifndef REMOVE_CAF1