sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#ifndef REMOVE_CAF1
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <caf/caftypes.h>
|
sl@0
|
22 |
#include <s32strm.h>
|
sl@0
|
23 |
#include <caf/cafmimeheader.h>
|
sl@0
|
24 |
#include "mimefieldanddata.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
using namespace ContentAccess;
|
sl@0
|
27 |
|
sl@0
|
28 |
EXPORT_C CCafMimeHeader* CCafMimeHeader::NewL(const TDesC8 &aContentType)
|
sl@0
|
29 |
{
|
sl@0
|
30 |
CCafMimeHeader *self = new (ELeave) CCafMimeHeader();
|
sl@0
|
31 |
CleanupStack::PushL(self);
|
sl@0
|
32 |
self->ConstructL(aContentType);
|
sl@0
|
33 |
CleanupStack::Pop(self);
|
sl@0
|
34 |
return self;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CCafMimeHeader::CCafMimeHeader()
|
sl@0
|
38 |
{
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
void CCafMimeHeader::ConstructL(const TDesC8 &aContentType)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
SetStandardMimeDataL(EContentType, aContentType);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
EXPORT_C CCafMimeHeader::~CCafMimeHeader()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
TInt i=0;
|
sl@0
|
49 |
iNonStandardMimeHeaders.ResetAndDestroy();
|
sl@0
|
50 |
iNonStandardMimeHeaders.Close();
|
sl@0
|
51 |
|
sl@0
|
52 |
for(i = 0; i < EMimeMax; i++)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
delete iStandardMimeHeader[i];
|
sl@0
|
55 |
}
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
EXPORT_C void CCafMimeHeader::SetStandardMimeDataL(const TMimeFields &aIndex, const TDesC8& aData)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
HBufC8 *data = aData.AllocLC();
|
sl@0
|
61 |
|
sl@0
|
62 |
// make sure mime types are lower case
|
sl@0
|
63 |
if(aIndex == EContentType)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
data->Des().LowerCase();
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
// replace whatever value was there before
|
sl@0
|
69 |
delete iStandardMimeHeader[aIndex];
|
sl@0
|
70 |
iStandardMimeHeader[aIndex] = data;
|
sl@0
|
71 |
|
sl@0
|
72 |
CleanupStack::Pop(data);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
EXPORT_C TPtrC8 CCafMimeHeader::StandardMimeData(const TMimeFields &aIndex) const
|
sl@0
|
76 |
{
|
sl@0
|
77 |
// If the field value has not been set, return a null string
|
sl@0
|
78 |
if(iStandardMimeHeader[aIndex] == NULL)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
return KNullDesC8();
|
sl@0
|
81 |
}
|
sl@0
|
82 |
return TPtrC8(iStandardMimeHeader[aIndex]->Des());
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
|
sl@0
|
86 |
EXPORT_C TInt CCafMimeHeader::NonStandardMimeCount() const
|
sl@0
|
87 |
{
|
sl@0
|
88 |
return iNonStandardMimeHeaders.Count();
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
EXPORT_C void CCafMimeHeader::AddNonStandardMimeL(const TDesC8& aFieldName, const TDesC8& aData)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
CMimeFieldAndData *mimeData = CMimeFieldAndData::NewL(aFieldName, aData);
|
sl@0
|
94 |
CleanupStack::PushL(mimeData);
|
sl@0
|
95 |
iNonStandardMimeHeaders.Append(mimeData);
|
sl@0
|
96 |
CleanupStack::Pop(mimeData);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
EXPORT_C TPtrC8 CCafMimeHeader::NonStandardMimeField(TInt aIndex) const
|
sl@0
|
100 |
{
|
sl@0
|
101 |
return iNonStandardMimeHeaders[aIndex]->FieldName();
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
EXPORT_C TPtrC8 CCafMimeHeader::NonStandardMimeData(TInt aIndex) const
|
sl@0
|
105 |
{
|
sl@0
|
106 |
return iNonStandardMimeHeaders[aIndex]->Data();
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
EXPORT_C void CCafMimeHeader::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
110 |
{
|
sl@0
|
111 |
TInt i=0;
|
sl@0
|
112 |
|
sl@0
|
113 |
// Write the contents of this class out to a stream
|
sl@0
|
114 |
|
sl@0
|
115 |
// Write the number of standard mime headers
|
sl@0
|
116 |
aStream.WriteInt32L(EMimeMax);
|
sl@0
|
117 |
|
sl@0
|
118 |
// Write out the standard mime data, each one preceeded by it's length
|
sl@0
|
119 |
for(i = 0; i < EMimeMax; i++)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
TInt length=0;
|
sl@0
|
122 |
|
sl@0
|
123 |
// Length is zero if the mime field has not been set,
|
sl@0
|
124 |
if(iStandardMimeHeader[i] == NULL)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
length = 0;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
else
|
sl@0
|
129 |
{
|
sl@0
|
130 |
length = iStandardMimeHeader[i]->Length();
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
// write the field length
|
sl@0
|
134 |
aStream.WriteInt16L(length);
|
sl@0
|
135 |
if(length > 0)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
// write the field value if length > 0
|
sl@0
|
138 |
aStream.WriteL(*iStandardMimeHeader[i]);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
aStream.WriteInt32L(iNonStandardMimeHeaders.Count());
|
sl@0
|
143 |
|
sl@0
|
144 |
// Write out non standard mime headers and data, each Des preceeded by it's length
|
sl@0
|
145 |
for(i = 0; i < iNonStandardMimeHeaders.Count(); i++)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
aStream.WriteInt16L(iNonStandardMimeHeaders[i]->FieldName().Length());
|
sl@0
|
148 |
if(iNonStandardMimeHeaders[i]->FieldName().Length() > 0)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
aStream.WriteL(iNonStandardMimeHeaders[i]->FieldName());
|
sl@0
|
151 |
}
|
sl@0
|
152 |
aStream.WriteInt16L(iNonStandardMimeHeaders[i]->Data().Length());
|
sl@0
|
153 |
if(iNonStandardMimeHeaders[i]->Data().Length() > 0)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
aStream.WriteL(iNonStandardMimeHeaders[i]->Data());
|
sl@0
|
156 |
}
|
sl@0
|
157 |
}
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
EXPORT_C void CCafMimeHeader::InternalizeL(RReadStream& aStream)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
TInt i=0;
|
sl@0
|
163 |
TInt fieldCount=0;
|
sl@0
|
164 |
TInt16 length=0;
|
sl@0
|
165 |
HBufC8 *field=NULL;
|
sl@0
|
166 |
HBufC8 *data=NULL;
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
// clear any existing headers
|
sl@0
|
170 |
iNonStandardMimeHeaders.ResetAndDestroy();
|
sl@0
|
171 |
for(i = 0; i < EMimeMax; i++)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
// delete the existing data for the mime field
|
sl@0
|
174 |
delete iStandardMimeHeader[i];
|
sl@0
|
175 |
iStandardMimeHeader[i] = NULL;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
|
sl@0
|
179 |
fieldCount= aStream.ReadInt32L();
|
sl@0
|
180 |
if(fieldCount != EMimeMax)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
// something is seriously wrong, should always be EMimeMax standard headers
|
sl@0
|
183 |
User::Leave(KErrGeneral);
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
for(i = 0; i < EMimeMax; i++)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
// read the length from the stream
|
sl@0
|
189 |
length = aStream.ReadInt16L();
|
sl@0
|
190 |
if(length > 0)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
// read in non zero fields, others will remain NULL
|
sl@0
|
193 |
data = HBufC8::NewLC(length);
|
sl@0
|
194 |
TPtr8 dataPtr = data->Des();
|
sl@0
|
195 |
aStream.ReadL(dataPtr,length);
|
sl@0
|
196 |
SetStandardMimeDataL(static_cast <TMimeFields>(i), dataPtr);
|
sl@0
|
197 |
CleanupStack::PopAndDestroy(data);
|
sl@0
|
198 |
}
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
fieldCount= aStream.ReadInt32L();
|
sl@0
|
202 |
|
sl@0
|
203 |
for(i = 0; i < fieldCount; i++)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
// Read mime field name
|
sl@0
|
206 |
length = aStream.ReadInt16L();
|
sl@0
|
207 |
if(length < 0)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
User::Leave(KErrCorrupt);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
field = HBufC8::NewLC(length);
|
sl@0
|
213 |
TPtr8 fieldPtr = field->Des();
|
sl@0
|
214 |
if(length > 0)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
aStream.ReadL(fieldPtr,length);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
// Read data
|
sl@0
|
220 |
length = aStream.ReadInt16L();
|
sl@0
|
221 |
if(length < 0)
|
sl@0
|
222 |
{
|
sl@0
|
223 |
User::Leave(KErrCorrupt);
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
data = HBufC8::NewLC(length);
|
sl@0
|
227 |
TPtr8 dataPtr = data->Des();
|
sl@0
|
228 |
if(length > 0)
|
sl@0
|
229 |
{
|
sl@0
|
230 |
aStream.ReadL(dataPtr,length);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
// Add a new mime field and data to our array
|
sl@0
|
234 |
AddNonStandardMimeL(fieldPtr, dataPtr);
|
sl@0
|
235 |
|
sl@0
|
236 |
// free memory allocated
|
sl@0
|
237 |
CleanupStack::PopAndDestroy(data);
|
sl@0
|
238 |
CleanupStack::PopAndDestroy(field);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
|
sl@0
|
243 |
#endif // #ifndef REMOVE_CAF1
|