24
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include "wappstor.h"
|
|
17 |
#include "ws_main.h"
|
|
18 |
#include "smsstackutils.h"
|
|
19 |
|
|
20 |
|
|
21 |
_LIT(KStoreName,"wapreast.dat");
|
|
22 |
|
|
23 |
const TInt KWapReassemblyStoreUidValue=0x100008CB;
|
|
24 |
const TUid KWapReassemblyStoreUid={KWapReassemblyStoreUidValue}; // Used for second uid of SAR stores
|
|
25 |
|
|
26 |
|
|
27 |
CWapReassemblyStore* CWapReassemblyStore::NewL(RFs& aFs)
|
|
28 |
{
|
|
29 |
LOGWAPPROT1("CWapReassemblyStore::NewL()");
|
|
30 |
|
|
31 |
CWapReassemblyStore* reassembly=new (ELeave)CWapReassemblyStore(aFs);
|
|
32 |
CleanupStack::PushL(reassembly);
|
|
33 |
reassembly->ConstructL();
|
|
34 |
CleanupStack::Pop(reassembly);
|
|
35 |
return reassembly;
|
|
36 |
} // CWapReassemblyStore::NewL
|
|
37 |
|
|
38 |
|
|
39 |
CWapReassemblyStore::~CWapReassemblyStore()
|
|
40 |
{
|
|
41 |
this->Close();
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
TBool CWapReassemblyStore::AddMessageL( TInt& aIndex, const CWapDatagram& aDatagram)
|
|
46 |
{
|
|
47 |
LOGWAPPROT1("CWapReassemblyStore::AddMessageL()");
|
|
48 |
|
|
49 |
CArrayPtrFlat<CWapDatagram::TSegmentData>* segmentArray = new
|
|
50 |
(ELeave) CArrayPtrFlat<CWapDatagram::TSegmentData> (8);
|
|
51 |
|
|
52 |
CleanupStack::PushL(segmentArray);
|
|
53 |
// coverity[double_push]
|
|
54 |
CleanupResetAndDestroyPushL(*segmentArray);
|
|
55 |
|
|
56 |
TBool isComplete = aDatagram.IsComplete();
|
|
57 |
|
|
58 |
// count of incomplete WAP short messages
|
|
59 |
TInt Count = Entries().Count();
|
|
60 |
if (!isComplete)
|
|
61 |
{
|
|
62 |
TWapReassemblyEntry Entry;
|
|
63 |
TBool isFound = EFalse;
|
|
64 |
|
|
65 |
// go through all entries in the reassembly store
|
|
66 |
// and find the short message entry,
|
|
67 |
// which matches with the given entry
|
|
68 |
for(aIndex=0;aIndex<Count; aIndex++)
|
|
69 |
{
|
|
70 |
TInt ToPort = 0;
|
|
71 |
TInt FromPort = 0;
|
|
72 |
aDatagram.Ports(FromPort,ToPort);
|
|
73 |
Entry = (TWapReassemblyEntry&)Entries()[aIndex];
|
|
74 |
isFound = ((Entry.Reference() ==
|
|
75 |
aDatagram.ConcatenatedMessageReference())
|
|
76 |
&& (Entry.Total() ==
|
|
77 |
aDatagram.NumConcatenatedMessages())
|
|
78 |
&& (Entry.ToPort() == ToPort)
|
|
79 |
&& (Entry.Description1() ==
|
|
80 |
aDatagram.FromAddress()));
|
|
81 |
if (isFound)
|
|
82 |
break;
|
|
83 |
}
|
|
84 |
if (isFound)
|
|
85 |
{
|
|
86 |
isFound = EFalse;
|
|
87 |
|
|
88 |
// new short message fragment received for an existing
|
|
89 |
// incomplete WAP datagram
|
|
90 |
TStreamId StreamdId = Entry.DataStreamId();
|
|
91 |
CWapDatagram* tempDatagram = CWapDatagram::NewL(KNullDesC8);
|
|
92 |
CleanupStack::PushL(tempDatagram);
|
|
93 |
|
|
94 |
TRAPD(ret, InternalizeEntryL(StreamdId,*tempDatagram,*segmentArray));
|
|
95 |
if(ret == KErrCorrupt)
|
|
96 |
{
|
|
97 |
Close();
|
|
98 |
User::LeaveIfError(iFs.Delete(iFullPathBuf));
|
|
99 |
DoOpenL(); //create a new file
|
|
100 |
}
|
|
101 |
else
|
|
102 |
User::LeaveIfError(ret);
|
|
103 |
|
|
104 |
// For the first: discard duplicates
|
|
105 |
// It takes place by comparing indexes of TSegmentDatas
|
|
106 |
CWapDatagram::TSegmentData *segmentData = new (ELeave)CWapDatagram::TSegmentData;
|
|
107 |
CleanupStack::PushL(segmentData);
|
|
108 |
aDatagram.SegmentData(*segmentData);
|
|
109 |
|
|
110 |
if(aDatagram.NumConcatenatedMessages() < segmentData->iSegmentNumber)
|
|
111 |
{
|
|
112 |
isFound = ETrue; // out of range discard
|
|
113 |
CleanupStack::PopAndDestroy(segmentData);
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
Count=segmentArray->Count();
|
|
118 |
for (TInt i=0; i<Count; i++)
|
|
119 |
{
|
|
120 |
CWapDatagram::TSegmentData* thisSegmentData =
|
|
121 |
segmentArray->At(i);
|
|
122 |
if (thisSegmentData->iSegmentNumber
|
|
123 |
== segmentData->iSegmentNumber)
|
|
124 |
{
|
|
125 |
// duplicate found. It is not saved.
|
|
126 |
isFound = ETrue;
|
|
127 |
CleanupStack::PopAndDestroy(segmentData);
|
|
128 |
break;
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|
|
132 |
if (!isFound)
|
|
133 |
{
|
|
134 |
TInt j=0;
|
|
135 |
for (; (j<segmentArray->Count()) && (segmentData->iSegmentNumber>(*segmentArray)[j]->iSegmentNumber); j++)
|
|
136 |
{
|
|
137 |
}
|
|
138 |
segmentArray->InsertL(j,segmentData);
|
|
139 |
CleanupStack::Pop(segmentData);
|
|
140 |
if (segmentArray->Count() ==
|
|
141 |
aDatagram.NumConcatenatedMessages())
|
|
142 |
// all fragments of a datagram are available
|
|
143 |
isComplete = ETrue;
|
|
144 |
|
|
145 |
BeginTransactionLC();
|
|
146 |
ExternalizeEntryL(StreamdId,*tempDatagram,*segmentArray);
|
|
147 |
PopulateEntry(Entry,*tempDatagram,segmentArray->Count());
|
|
148 |
ChangeEntryL(aIndex,Entry);
|
|
149 |
CommitTransactionL();
|
|
150 |
}
|
|
151 |
CleanupStack::PopAndDestroy(tempDatagram);
|
|
152 |
}
|
|
153 |
// else - a duplicate was found. Ignored.
|
|
154 |
else
|
|
155 |
{
|
|
156 |
// a first short message fragment received for a
|
|
157 |
// non-existing WAP datagram
|
|
158 |
CWapDatagram::TSegmentData *segmentData = new (ELeave)CWapDatagram::TSegmentData;
|
|
159 |
CleanupStack::PushL(segmentData);
|
|
160 |
aDatagram.SegmentData(*segmentData);
|
|
161 |
if(aDatagram.NumConcatenatedMessages() < segmentData->iSegmentNumber)
|
|
162 |
{
|
|
163 |
CleanupStack::PopAndDestroy(segmentData);
|
|
164 |
isComplete=EFalse;
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
|
168 |
segmentArray->AppendL(segmentData);
|
|
169 |
CleanupStack::Pop(segmentData);
|
|
170 |
aIndex = Count;
|
|
171 |
CreateEntryL(aDatagram,*segmentArray);
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
175 |
else // the datagram is complete
|
|
176 |
{
|
|
177 |
CWapDatagram::TSegmentData *segmentData = new (ELeave)CWapDatagram::TSegmentData;
|
|
178 |
CleanupStack::PushL(segmentData);
|
|
179 |
aDatagram.SegmentData(*segmentData);
|
|
180 |
if(aDatagram.NumConcatenatedMessages() < segmentData->iSegmentNumber)
|
|
181 |
{
|
|
182 |
CleanupStack::PopAndDestroy(segmentData);
|
|
183 |
isComplete=EFalse;
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
segmentArray->AppendL(segmentData);
|
|
188 |
CleanupStack::Pop(segmentData);
|
|
189 |
aIndex = Count;
|
|
190 |
CreateEntryL(aDatagram,*segmentArray);
|
|
191 |
}
|
|
192 |
}
|
|
193 |
|
|
194 |
CleanupStack::PopAndDestroy(2, segmentArray); // segmentArray elements (Reset and Destroy), segmentArray
|
|
195 |
return isComplete;
|
|
196 |
} // CWapReassemblyStore::AddMessageL
|
|
197 |
|
|
198 |
void CWapReassemblyStore::GetDatagramL( TInt aIndex,
|
|
199 |
CWapDatagram& aDatagram)
|
|
200 |
{
|
|
201 |
LOGWAPPROT1("CWapReassemblyStore::GetDatagramL()");
|
|
202 |
|
|
203 |
CArrayPtrFlat<CWapDatagram::TSegmentData>* segmentArray = new
|
|
204 |
(ELeave) CArrayPtrFlat<CWapDatagram::TSegmentData> (8);
|
|
205 |
|
|
206 |
// here we need to push 'segmentArray' pointer to the cleanup stack, since it's a heap allocation (pointer must be deleted)
|
|
207 |
// CleanupResetAndDestroyPushL() just trigers ResetAndDestroy() to be called on CleanupStack::PopAndDestroy()
|
|
208 |
CleanupStack::PushL(segmentArray);
|
|
209 |
// coverity[double_push]
|
|
210 |
CleanupResetAndDestroyPushL(*segmentArray);
|
|
211 |
|
|
212 |
// defect fix for EDNJJUN-4WYJGP
|
|
213 |
// Unable to send sms cause sms*.dat is corrupted
|
|
214 |
TRAPD(ret, InternalizeEntryL(Entries()[aIndex].DataStreamId(), aDatagram,*segmentArray));
|
|
215 |
if(ret == KErrCorrupt)
|
|
216 |
{
|
|
217 |
Close(); //because the file is in use
|
|
218 |
User::LeaveIfError(iFs.Delete(iFullPathBuf));
|
|
219 |
DoOpenL(); //create a new file
|
|
220 |
}
|
|
221 |
else
|
|
222 |
User::LeaveIfError(ret);
|
|
223 |
|
|
224 |
if(aDatagram.Alphabet() == TSmsDataCodingScheme::ESmsAlphabet7Bit)
|
|
225 |
{
|
|
226 |
aDatagram.DecodeConcatenatedMessagesL(*segmentArray);
|
|
227 |
}
|
|
228 |
|
|
229 |
CleanupStack::PopAndDestroy(2, segmentArray); // segmentArray elements (Reset and Destroy), segmentArray
|
|
230 |
} // CWapReassemblyStore::GetDatagramL
|
|
231 |
|
|
232 |
TBool CWapReassemblyStore::FindAndDeleteDatagramL( CWapDatagram& aDatagram)
|
|
233 |
{
|
|
234 |
LOGWAPPROT1("CWapReassemblyStore::FindAndDeleteDatagramL()");
|
|
235 |
|
|
236 |
TInt index;
|
|
237 |
TBool isFound = EFalse;
|
|
238 |
TWapReassemblyEntry entry;
|
|
239 |
TInt toPort = 0;
|
|
240 |
TInt fromPort = 0;
|
|
241 |
aDatagram.Ports(fromPort,toPort);
|
|
242 |
|
|
243 |
TInt Count = Entries().Count();
|
|
244 |
for(index=0;index<Count; index++)
|
|
245 |
{
|
|
246 |
entry = (TWapReassemblyEntry&)Entries()[index];
|
|
247 |
isFound = ((entry.Reference() ==
|
|
248 |
aDatagram.ConcatenatedMessageReference())
|
|
249 |
&& (entry.ToPort() == toPort)
|
|
250 |
&&(entry.Total() ==
|
|
251 |
aDatagram.NumConcatenatedMessages()));
|
|
252 |
if (isFound)
|
|
253 |
{
|
|
254 |
BeginTransactionLC();
|
|
255 |
DeleteEntryL(index);
|
|
256 |
CommitTransactionL();
|
|
257 |
return isFound;
|
|
258 |
}
|
|
259 |
}
|
|
260 |
return isFound;
|
|
261 |
} // CWapReassemblyStore::FindAndDeleteDatagramL
|
|
262 |
|
|
263 |
|
|
264 |
void CWapReassemblyStore::ConstructL()
|
|
265 |
{
|
|
266 |
LOGWAPPROT1("CWapReassemblyStore::ConstructL()");
|
|
267 |
|
|
268 |
//get full path of reassembly store
|
|
269 |
PrivatePath(iFullPathBuf);
|
|
270 |
//append store name
|
|
271 |
iFullPathBuf.Append(KStoreName);
|
|
272 |
OpenStoreL();
|
|
273 |
} // CWapReassemblyStore::ConstructL
|
|
274 |
|
|
275 |
|
|
276 |
/**
|
|
277 |
* internalize all the entries from the permanent file store to internal memory
|
|
278 |
*
|
|
279 |
* @note You have to call CSARStore::OpenFileLC() before calling this function
|
|
280 |
* @param aStreamId, unique id associated with the stream
|
|
281 |
* @param aDatagram, the datagram which will be internalized
|
|
282 |
* @param aSegmentArray, the array of segments for the datagram
|
|
283 |
*/
|
|
284 |
void CWapReassemblyStore::InternalizeEntryL(
|
|
285 |
TStreamId aStreamId,
|
|
286 |
CWapDatagram& aDatagram,
|
|
287 |
CArrayPtr<CWapDatagram::TSegmentData>& aSegmentArray)
|
|
288 |
{
|
|
289 |
LOGWAPPROT1("CWapReassemblyStore::InternalizeEntryL Start");
|
|
290 |
|
|
291 |
BeginTransactionLC();
|
|
292 |
RStoreReadStream ReadStream;
|
|
293 |
TInt32 Count;
|
|
294 |
|
|
295 |
ReadStream.OpenLC(FileStore(),aStreamId);
|
|
296 |
ReadStream >> aDatagram;
|
|
297 |
|
|
298 |
if(aDatagram.Alphabet() == TSmsDataCodingScheme::ESmsAlphabet8Bit)
|
|
299 |
{
|
|
300 |
aDatagram.InternalizeBufferL(ReadStream);
|
|
301 |
}
|
|
302 |
else
|
|
303 |
{
|
|
304 |
Count=ReadStream.ReadInt32L();
|
|
305 |
|
|
306 |
aSegmentArray.Reset();
|
|
307 |
for (TInt i=0; i<Count; i++)
|
|
308 |
{
|
|
309 |
CWapDatagram::TSegmentData* Segment = new (ELeave) CWapDatagram::TSegmentData;
|
|
310 |
CleanupStack::PushL(Segment);
|
|
311 |
aSegmentArray.AppendL(Segment);
|
|
312 |
CleanupStack::Pop();
|
|
313 |
|
|
314 |
Segment->iSegmentNumber = ReadStream.ReadInt32L();
|
|
315 |
ReadStream >> Segment->iData;
|
|
316 |
}
|
|
317 |
}
|
|
318 |
// Closes the ReadStream
|
|
319 |
CleanupStack::PopAndDestroy();
|
|
320 |
CommitTransactionL();
|
|
321 |
LOGWAPPROT1("CWapReassemblyStore::InternalizeEntryL End");
|
|
322 |
} // CWapReassemblyStore::InternalizeEntryL
|
|
323 |
|
|
324 |
|
|
325 |
/**
|
|
326 |
* externalizes all the entries from the internal memory to the permanent file store
|
|
327 |
*
|
|
328 |
* @note You have to call CSARStore::OpenFileLC() before calling this function
|
|
329 |
* @param aStreamId, unique id associated with the stream
|
|
330 |
* @param aDatagram, the datagram which should be externalized
|
|
331 |
* @param aSegmentArray, the array of segments for the datagram
|
|
332 |
*/
|
|
333 |
void CWapReassemblyStore::ExternalizeEntryL(
|
|
334 |
TStreamId& aStreamId,
|
|
335 |
const CWapDatagram& aDatagram,
|
|
336 |
const CArrayPtr<CWapDatagram::TSegmentData>& aSegmentArray)
|
|
337 |
{
|
|
338 |
LOGWAPPROT1("CWapReassemblyStore::ExternalizeEntryL Start");
|
|
339 |
|
|
340 |
TInt32 Count = aSegmentArray.Count();
|
|
341 |
RStoreWriteStream WriteStream;
|
|
342 |
|
|
343 |
if (aStreamId==KNullStreamId)
|
|
344 |
aStreamId=WriteStream.CreateLC(FileStore());
|
|
345 |
else
|
|
346 |
WriteStream.ReplaceLC(FileStore(),aStreamId);
|
|
347 |
WriteStream<<aDatagram;
|
|
348 |
|
|
349 |
if(aDatagram.Alphabet() == TSmsDataCodingScheme::ESmsAlphabet8Bit)
|
|
350 |
{
|
|
351 |
aDatagram.ExternalizeBufferL(WriteStream);
|
|
352 |
}
|
|
353 |
else
|
|
354 |
{
|
|
355 |
WriteStream.WriteInt32L(Count);
|
|
356 |
for(TInt i=0; i<Count; i++)
|
|
357 |
{
|
|
358 |
WriteStream.WriteInt32L(aSegmentArray[i]->iSegmentNumber);
|
|
359 |
WriteStream<<aSegmentArray[i]->iData;
|
|
360 |
}
|
|
361 |
|
|
362 |
}
|
|
363 |
// Closes the ReadStream
|
|
364 |
WriteStream.CommitL();
|
|
365 |
CleanupStack::PopAndDestroy();
|
|
366 |
} // CWapReassemblyStore::ExternalizeEntryL
|
|
367 |
|
|
368 |
|
|
369 |
void CWapReassemblyStore::PopulateEntry(TWapReassemblyEntry& aEntry,
|
|
370 |
const CWapDatagram& aDatagram,
|
|
371 |
TInt aNumDatagrams)
|
|
372 |
{
|
|
373 |
LOGWAPPROT1("CWapReassemblyStore::PopulateEntry()");
|
|
374 |
|
|
375 |
TInt ToPort = 0;
|
|
376 |
TInt FromPort = 0;
|
|
377 |
|
|
378 |
aDatagram.Ports(FromPort,ToPort);
|
|
379 |
// complete or not complete
|
|
380 |
if (!aDatagram.IsComplete())
|
|
381 |
{
|
|
382 |
aEntry.SetReference(aDatagram.ConcatenatedMessageReference());
|
|
383 |
aEntry.SetTotal(aDatagram.NumConcatenatedMessages());
|
|
384 |
aEntry.SetCount(aNumDatagrams);
|
|
385 |
}
|
|
386 |
else
|
|
387 |
{
|
|
388 |
//Wap Datagram might contain reference number which will be
|
|
389 |
//needed at the time of deleting the datagram from permanent store file
|
|
390 |
//Refer To Defect Fix: PDEF114607.
|
|
391 |
aEntry.SetReference(aDatagram.ConcatenatedMessageReference());
|
|
392 |
aEntry.SetTotal(1);
|
|
393 |
aEntry.SetCount(1);
|
|
394 |
}
|
|
395 |
|
|
396 |
aEntry.SetToPort(ToPort);
|
|
397 |
aEntry.SetDescription1(aDatagram.FromAddress());
|
|
398 |
aEntry.SetTime(aDatagram.Time());
|
|
399 |
} // CWapReassemblyStore::PopulateEntry
|
|
400 |
|
|
401 |
|
|
402 |
void CWapReassemblyStore::CreateEntryL(const CWapDatagram& aDatagram,
|
|
403 |
const CArrayPtr<CWapDatagram::TSegmentData>& aSegmentArray)
|
|
404 |
{
|
|
405 |
LOGWAPPROT1("CWapReassemblyStore::CreateEntryL");
|
|
406 |
|
|
407 |
TWapReassemblyEntry Entry;
|
|
408 |
TStreamId WriteStream = KNullStreamId;
|
|
409 |
BeginTransactionLC();
|
|
410 |
ExternalizeEntryL(WriteStream,aDatagram,aSegmentArray);
|
|
411 |
Entry.SetDataStreamId(WriteStream);
|
|
412 |
PopulateEntry(Entry,aDatagram,aDatagram.NumConcatenatedMessages());
|
|
413 |
AddEntryL(Entry);
|
|
414 |
CommitTransactionL();
|
|
415 |
} // CWapReassemblyStore::CreateEntryL
|
|
416 |
|
|
417 |
|
|
418 |
CWapReassemblyStore::CWapReassemblyStore(RFs& aFs)
|
|
419 |
:CSARStore(aFs)
|
|
420 |
{
|
|
421 |
} // CWapReassemblyStore::CWapReassemblyStore
|
|
422 |
|
|
423 |
|
|
424 |
/**
|
|
425 |
* Open the wap reassembly store.
|
|
426 |
* Use RFs::PrivatePath to generate private path.
|
|
427 |
*/
|
|
428 |
void CWapReassemblyStore::OpenStoreL()
|
|
429 |
{
|
|
430 |
LOGWAPPROT1("CWapReassemblyStore::OpenStoreL()");
|
|
431 |
|
|
432 |
OpenL(iFullPathBuf,KWapReassemblyStoreUid);
|
|
433 |
} // CWapReassemblyStore::OpenStoreL
|
|
434 |
|
|
435 |
// EOF - WAPPSTOR.CPP
|