24
|
1 |
// Copyright (c) 2003-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 |
|
|
17 |
#include "smspdudb.h"
|
|
18 |
#include <testconfigfileparser.h>
|
|
19 |
#include "Gsmumsg.h"
|
|
20 |
#include "gsmubuf.h"
|
|
21 |
|
|
22 |
const TInt KSmsPduDbMaxReadWriteChunk = 0x200;
|
|
23 |
|
|
24 |
EXPORT_C CSmsPduDatabase* CSmsPduDatabase::NewL(RFs& aFs)
|
|
25 |
/**
|
|
26 |
* CSmsPduDatabase default factory function
|
|
27 |
*
|
|
28 |
* Calls the other overload of NewL with the default section, filename and component.
|
|
29 |
*/
|
|
30 |
{
|
|
31 |
return NewL(aFs, KSmsPduDbDefaultSection, KSmsPduDbDefaultFilename, KSmsPduDbDefaultComponent);
|
|
32 |
}
|
|
33 |
|
|
34 |
EXPORT_C CSmsPduDatabase* CSmsPduDatabase::NewL(RFs& aFs, const TDesC8& aSection, const TDesC& aFileName, const TDesC& aComponent)
|
|
35 |
{
|
|
36 |
CSmsPduDatabase* self = new (ELeave) CSmsPduDatabase(aFs);
|
|
37 |
CleanupStack::PushL(self);
|
|
38 |
|
|
39 |
//Construct iConfigFile and set iSection to aSection
|
|
40 |
CTestConfig* testConfig = CTestConfig::NewLC(aFs, aComponent, aFileName);
|
|
41 |
CleanupStack::Pop(testConfig);
|
|
42 |
|
|
43 |
self->iConfigFile = testConfig;
|
|
44 |
self->SetSectionL(aSection);
|
|
45 |
|
|
46 |
CleanupStack::Pop(self);
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
|
|
50 |
EXPORT_C CSmsPduDatabase* CSmsPduDatabase::NewL(RFs& aFs, const CTestConfigSection& aSection)
|
|
51 |
/**
|
|
52 |
* Constructs a CSmsPduDatabase and sets iSection to aSection.
|
|
53 |
* @note iConfigFile is not constructed and should remain NULL
|
|
54 |
*/
|
|
55 |
{
|
|
56 |
CSmsPduDatabase* self = new (ELeave) CSmsPduDatabase(aFs);
|
|
57 |
self->SetSection(aSection);
|
|
58 |
return self;
|
|
59 |
}
|
|
60 |
|
|
61 |
EXPORT_C CSmsPduDatabase::~CSmsPduDatabase()
|
|
62 |
{
|
|
63 |
delete iConfigFile;
|
|
64 |
// @note Don't delete iSection because it is either owned by iConfigFile or by another config file
|
|
65 |
}
|
|
66 |
|
|
67 |
TPtrC8 CSmsPduDatabase::GetTypeL(CSmsPDU::TSmsPDUType aType) const
|
|
68 |
{
|
|
69 |
TPtrC8 type;
|
|
70 |
|
|
71 |
switch (aType)
|
|
72 |
{
|
|
73 |
case CSmsPDU::ESmsSubmit:
|
|
74 |
|
|
75 |
type.Set(KSmsPduDbSubmit);
|
|
76 |
break;
|
|
77 |
|
|
78 |
case CSmsPDU::ESmsDeliver:
|
|
79 |
|
|
80 |
type.Set(KSmsPduDbDeliver);
|
|
81 |
break;
|
|
82 |
|
|
83 |
case CSmsPDU::ESmsCommand:
|
|
84 |
|
|
85 |
type.Set(KSmsPduDbCommand);
|
|
86 |
break;
|
|
87 |
|
|
88 |
case CSmsPDU::ESmsStatusReport:
|
|
89 |
|
|
90 |
type.Set(KSmsPduDbStatusReport);
|
|
91 |
break;
|
|
92 |
|
|
93 |
case CSmsPDU::ESmsSubmitReport:
|
|
94 |
|
|
95 |
type.Set(KSmsPduDbSubmitReport);
|
|
96 |
break;
|
|
97 |
|
|
98 |
case CSmsPDU::ESmsDeliverReport:
|
|
99 |
|
|
100 |
type.Set(KSmsPduDbDeliverReport);
|
|
101 |
break;
|
|
102 |
|
|
103 |
default:
|
|
104 |
|
|
105 |
User::Leave(KErrNotSupported);
|
|
106 |
break;
|
|
107 |
}
|
|
108 |
|
|
109 |
return type;
|
|
110 |
}
|
|
111 |
|
|
112 |
TPtrC8 CSmsPduDatabase::GetConcatTypeL(CSmsPDU::TSmsPDUType aType) const
|
|
113 |
{
|
|
114 |
TPtrC8 type;
|
|
115 |
|
|
116 |
switch (aType)
|
|
117 |
{
|
|
118 |
case CSmsPDU::ESmsSubmit:
|
|
119 |
|
|
120 |
type.Set(KSmsPduDbSubmitConcat);
|
|
121 |
break;
|
|
122 |
|
|
123 |
case CSmsPDU::ESmsDeliver:
|
|
124 |
|
|
125 |
type.Set(KSmsPduDbDeliverConcat);
|
|
126 |
break;
|
|
127 |
|
|
128 |
default:
|
|
129 |
|
|
130 |
User::Leave(KErrNotSupported);
|
|
131 |
break;
|
|
132 |
}
|
|
133 |
|
|
134 |
return type;
|
|
135 |
}
|
|
136 |
|
|
137 |
|
|
138 |
EXPORT_C CSmsPduDbPdu* CSmsPduDatabase::GetPduLC(CSmsPDU::TSmsPDUType aType, TInt aId) const
|
|
139 |
{
|
|
140 |
const TPtrC8 type(GetTypeL(aType));
|
|
141 |
RSmsPduDbIdArray array(type);
|
|
142 |
CleanupClosePushL(array);
|
|
143 |
GetIdsL(array, aId);
|
|
144 |
|
|
145 |
const CTestConfigItem& item = *array[0].iItem;
|
|
146 |
|
|
147 |
CSmsPduDbPdu* pdu = CSmsPduDbPdu::NewL(iFs, item, aType);
|
|
148 |
CleanupStack::PopAndDestroy(&array);
|
|
149 |
CleanupStack::PushL(pdu);
|
|
150 |
return pdu;
|
|
151 |
}
|
|
152 |
|
|
153 |
EXPORT_C void CSmsPduDatabase::GetPduL(RPointerArray<CSmsPduDbPdu>& aArray, CSmsPDU::TSmsPDUType aType) const
|
|
154 |
{
|
|
155 |
const TPtrC8 type(GetTypeL(aType));
|
|
156 |
RSmsPduDbIdArray array(type);
|
|
157 |
CleanupClosePushL(array);
|
|
158 |
|
|
159 |
GetIdsL(array);
|
|
160 |
const TInt count = array.Count();
|
|
161 |
|
|
162 |
for (TInt i = 0; i < count; i++)
|
|
163 |
{
|
|
164 |
CSmsPduDbPdu* pdu = CSmsPduDbPdu::NewL(iFs, *array[i].iItem, aType);
|
|
165 |
CleanupStack::PushL(pdu);
|
|
166 |
User::LeaveIfError(aArray.Append(pdu));
|
|
167 |
CleanupStack::Pop(pdu);
|
|
168 |
}
|
|
169 |
|
|
170 |
CleanupStack::PopAndDestroy(&array);
|
|
171 |
}
|
|
172 |
|
|
173 |
EXPORT_C CSmsPduDbConcatSegment* CSmsPduDatabase::GetConcatSegmentLC(CSmsPDU::TSmsPDUType aType, TInt aId, TInt aSegment) const
|
|
174 |
{
|
|
175 |
const TPtrC8 type(GetConcatTypeL(aType));
|
|
176 |
RSmsPduDbIdArray array(type, ETrue);
|
|
177 |
CleanupClosePushL(array);
|
|
178 |
GetIdsL(array, aId);
|
|
179 |
|
|
180 |
CSmsPduDbConcatSegment* concat = GetConcatSegmentL(array, aType, aId, aSegment);
|
|
181 |
|
|
182 |
CleanupStack::PopAndDestroy(&array);
|
|
183 |
CleanupStack::PushL(concat);
|
|
184 |
return concat;
|
|
185 |
}
|
|
186 |
|
|
187 |
CSmsPduDbConcatSegment* CSmsPduDatabase::GetConcatSegmentL(const RSmsPduDbIdArray& aIdArray, CSmsPDU::TSmsPDUType aType, TInt aId, TInt aSegment) const
|
|
188 |
{
|
|
189 |
const TInt count = aIdArray.Count();
|
|
190 |
CSmsPduDbConcatSegment* concat = NULL;
|
|
191 |
|
|
192 |
for (TInt i = 0; i < count; i++) //order important
|
|
193 |
{
|
|
194 |
const TSmsPduDbId& id = aIdArray[i];
|
|
195 |
|
|
196 |
if (id.iId == aId)
|
|
197 |
{
|
|
198 |
const TDesC8& val = id.iItem->Value();
|
|
199 |
TInt segment = KErrNotFound;
|
|
200 |
const TInt err = CTestConfig::GetElement(val, KSmsPduDbDelimiter, CSmsPduDbConcatSegment::EConcatSegment, segment);
|
|
201 |
|
|
202 |
if (err == KErrNone && segment == aSegment)
|
|
203 |
{
|
|
204 |
concat = CSmsPduDbConcatSegment::NewL(iFs, *id.iItem, aType);
|
|
205 |
break;
|
|
206 |
}
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
if (concat == NULL)
|
|
211 |
User::Leave(KErrNotFound);
|
|
212 |
|
|
213 |
return concat;
|
|
214 |
}
|
|
215 |
|
|
216 |
EXPORT_C CSmsPduDbConcat* CSmsPduDatabase::GetConcatLC(CSmsPDU::TSmsPDUType aType, TInt aId) const
|
|
217 |
{
|
|
218 |
const TPtrC8 type(GetConcatTypeL(aType));
|
|
219 |
RSmsPduDbIdArray array(type, ETrue);
|
|
220 |
CleanupClosePushL(array);
|
|
221 |
GetIdsL(array, aId);
|
|
222 |
|
|
223 |
CSmsPduDbConcat* concat = new (ELeave) CSmsPduDbConcat();
|
|
224 |
CleanupStack::PushL(concat);
|
|
225 |
|
|
226 |
const TInt count = array.Count();
|
|
227 |
|
|
228 |
for (TInt i=0; i<count; i++)
|
|
229 |
{
|
|
230 |
const TSmsPduDbId& id = array[i];
|
|
231 |
CSmsPduDbConcatSegment* concatSegment = CSmsPduDbConcatSegment::NewL(iFs, *id.iItem, aType);
|
|
232 |
CleanupStack::PushL(concatSegment);
|
|
233 |
User::LeaveIfError(concat->iSegments.Append(concatSegment));
|
|
234 |
}
|
|
235 |
|
|
236 |
concat->DecodeL(iFs);
|
|
237 |
|
|
238 |
CleanupStack::PopAndDestroy(&array);
|
|
239 |
return concat;
|
|
240 |
}
|
|
241 |
|
|
242 |
EXPORT_C void CSmsPduDatabase::GetConcatL(RPointerArray<CSmsPduDbConcat>& aArray, CSmsPDU::TSmsPDUType aType) const
|
|
243 |
{
|
|
244 |
const TPtrC8 type(GetConcatTypeL(aType));
|
|
245 |
RSmsPduDbIdArray array(type, ETrue);
|
|
246 |
CleanupClosePushL(array);
|
|
247 |
GetIdsL(array);
|
|
248 |
|
|
249 |
const TInt count = array.Count();
|
|
250 |
TInt lastId = KErrNotFound;
|
|
251 |
CSmsPduDbConcat* concat = NULL;
|
|
252 |
|
|
253 |
for (TInt i=0; i<count; i++)
|
|
254 |
{
|
|
255 |
const CTestConfigItem& item = *array[i].iItem;
|
|
256 |
const TInt id = array[i].iId;
|
|
257 |
|
|
258 |
if (id != lastId || concat == NULL)
|
|
259 |
{
|
|
260 |
if (concat != NULL)
|
|
261 |
concat->DecodeL(iFs);
|
|
262 |
|
|
263 |
concat = new (ELeave) CSmsPduDbConcat();
|
|
264 |
CleanupStack::PushL(concat);
|
|
265 |
User::LeaveIfError(aArray.Append(concat));
|
|
266 |
CleanupStack::Pop(concat);
|
|
267 |
lastId = id;
|
|
268 |
}
|
|
269 |
|
|
270 |
CSmsPduDbConcatSegment* segment = CSmsPduDbConcatSegment::NewL(iFs, item, aType);
|
|
271 |
CleanupStack::PushL(segment);
|
|
272 |
User::LeaveIfError(concat->iSegments.Append(segment));
|
|
273 |
CleanupStack::Pop(segment);
|
|
274 |
}
|
|
275 |
|
|
276 |
if (concat != NULL)
|
|
277 |
concat->DecodeL(iFs);
|
|
278 |
|
|
279 |
CleanupStack::PopAndDestroy(&array);
|
|
280 |
}
|
|
281 |
|
|
282 |
EXPORT_C CSmsPduDbMessage* CSmsPduDatabase::GetMessageLC(CSmsPDU::TSmsPDUType aType, TInt aId) const
|
|
283 |
{
|
|
284 |
RSmsPduDbIdArray array(KSmsPduDbMessage);
|
|
285 |
CleanupClosePushL(array);
|
|
286 |
GetIdsL(array, aId);
|
|
287 |
|
|
288 |
const CTestConfigItem& item = *array[0].iItem;
|
|
289 |
CSmsPduDbMessage* pdu = CSmsPduDbMessage::NewL(iFs, item, aType);
|
|
290 |
CleanupStack::PushL(pdu);
|
|
291 |
|
|
292 |
|
|
293 |
CleanupStack::PopAndDestroy(&array);
|
|
294 |
return pdu;
|
|
295 |
}
|
|
296 |
|
|
297 |
EXPORT_C void CSmsPduDatabase::GetMessageL(RPointerArray<CSmsPduDbMessage>& aArray, CSmsPDU::TSmsPDUType aType) const
|
|
298 |
{
|
|
299 |
RSmsPduDbIdArray array(KSmsPduDbMessage);
|
|
300 |
CleanupClosePushL(array);
|
|
301 |
GetIdsL(array);
|
|
302 |
|
|
303 |
const TInt count = array.Count();
|
|
304 |
|
|
305 |
for (TInt i=0; i<count; i++)
|
|
306 |
{
|
|
307 |
const CTestConfigItem& item = *array[i].iItem;
|
|
308 |
CSmsPduDbMessage* pdu = CSmsPduDbMessage::NewL(iFs, item, aType);
|
|
309 |
CleanupStack::PushL(pdu);
|
|
310 |
User::LeaveIfError(aArray.Append(pdu));
|
|
311 |
CleanupStack::Pop(pdu);
|
|
312 |
}
|
|
313 |
|
|
314 |
CleanupStack::PopAndDestroy(&array);
|
|
315 |
}
|
|
316 |
|
|
317 |
CSmsPduDatabase::CSmsPduDatabase(RFs& aFs)
|
|
318 |
: iFs(aFs)
|
|
319 |
{
|
|
320 |
}
|
|
321 |
|
|
322 |
void CSmsPduDatabase::GetIdsL(RSmsPduDbIdArray& aIds) const
|
|
323 |
{
|
|
324 |
RPointerArray<const CTestConfigItem> array;
|
|
325 |
CleanupClosePushL(array);
|
|
326 |
|
|
327 |
iSection->ItemsL(array, aIds.Type());
|
|
328 |
|
|
329 |
const TInt count = array.Count();
|
|
330 |
|
|
331 |
for (TInt i=0; i<count; i++)
|
|
332 |
{
|
|
333 |
TSmsPduDbId item(array[i]);
|
|
334 |
const TInt err = CTestConfig::GetElement(item.iItem->Value(), KSmsPduDbDelimiter, CSmsPduDbBase::ESmsPduDbId, item.iId);
|
|
335 |
if (err == KErrNone)
|
|
336 |
{
|
|
337 |
aIds.InsertL(item);
|
|
338 |
}
|
|
339 |
}
|
|
340 |
|
|
341 |
CleanupStack::PopAndDestroy(&array);
|
|
342 |
}
|
|
343 |
|
|
344 |
void CSmsPduDatabase::GetIdsL(RSmsPduDbIdArray& aIds, TInt aId) const
|
|
345 |
{
|
|
346 |
RSmsPduDbIdArray tempArray(aIds.Type(), ETrue);
|
|
347 |
CleanupClosePushL(tempArray);
|
|
348 |
|
|
349 |
GetIdsL(tempArray);
|
|
350 |
|
|
351 |
TInt find = KErrNotFound;
|
|
352 |
|
|
353 |
while ((find = tempArray.Find(aId)) != KErrNotFound)
|
|
354 |
{
|
|
355 |
User::LeaveIfError(aIds.Append(tempArray[find]));
|
|
356 |
tempArray.Remove(find);
|
|
357 |
}
|
|
358 |
|
|
359 |
CleanupStack::PopAndDestroy(&tempArray);
|
|
360 |
if (aIds.Count() == 0)
|
|
361 |
User::Leave(KErrNotFound);
|
|
362 |
}
|
|
363 |
|
|
364 |
void CSmsPduDatabase::ReadFileL(const TDesC& aInputFileName, const TDesC& aInputComponent, CBufFlat& aData) const
|
|
365 |
{
|
|
366 |
TParse parse;
|
|
367 |
User::LeaveIfError(CTestConfig::ResolveFile(iFs, aInputComponent, aInputFileName, parse));
|
|
368 |
|
|
369 |
RFile file;
|
|
370 |
User::LeaveIfError(file.Open(iFs, parse.FullName(), EFileRead));
|
|
371 |
CleanupClosePushL(file);
|
|
372 |
|
|
373 |
TInt size(0);
|
|
374 |
User::LeaveIfError(file.Size(size));
|
|
375 |
|
|
376 |
for (TInt i = 0; i < size; i += KSmsPduDbMaxReadWriteChunk)
|
|
377 |
{
|
|
378 |
const TInt readSize = Min(KSmsPduDbMaxReadWriteChunk, size - i);
|
|
379 |
TBuf8<KSmsPduDbMaxReadWriteChunk> read;
|
|
380 |
User::LeaveIfError(file.Read(read, readSize));
|
|
381 |
const TInt pos = aData.Size();
|
|
382 |
aData.InsertL(pos, read);
|
|
383 |
}
|
|
384 |
|
|
385 |
CleanupStack::PopAndDestroy(&file);
|
|
386 |
}
|
|
387 |
|
|
388 |
void CSmsPduDatabase::WriteFileL(const TDesC& aOutputFileName, const CBufFlat& aData) const
|
|
389 |
{
|
|
390 |
RFile file;
|
|
391 |
User::LeaveIfError(file.Replace(iFs, aOutputFileName, EFileWrite));
|
|
392 |
CleanupClosePushL(file);
|
|
393 |
|
|
394 |
const TInt size = aData.Size();
|
|
395 |
|
|
396 |
for (TInt i = 0; i < size; i += KSmsPduDbMaxReadWriteChunk)
|
|
397 |
{
|
|
398 |
const TInt readSize = Min(KSmsPduDbMaxReadWriteChunk, size - i);
|
|
399 |
TBuf8<KSmsPduDbMaxReadWriteChunk> read;
|
|
400 |
aData.Read(i, read, readSize);
|
|
401 |
User::LeaveIfError(file.Write(read));
|
|
402 |
}
|
|
403 |
|
|
404 |
User::LeaveIfError(file.Flush());
|
|
405 |
|
|
406 |
CleanupStack::PopAndDestroy(&file);
|
|
407 |
}
|
|
408 |
|
|
409 |
EXPORT_C void CSmsPduDatabase::RewriteFileL(const TDesC& aInputFileName, const TDesC& aInputComponent, const TDesC& aOutputFileName) const
|
|
410 |
{
|
|
411 |
CBufFlat* buffer = CBufFlat::NewL(0x100); //< TODO Remove this magic number
|
|
412 |
CleanupStack::PushL(buffer);
|
|
413 |
|
|
414 |
ReadFileL(aInputFileName, aInputComponent, *buffer);
|
|
415 |
|
|
416 |
ParseFileL(*buffer);
|
|
417 |
|
|
418 |
WriteFileL(aOutputFileName, *buffer);
|
|
419 |
|
|
420 |
CleanupStack::PopAndDestroy(buffer);
|
|
421 |
}
|
|
422 |
|
|
423 |
void CSmsPduDatabase::ParseFileL(CBufFlat& aData) const
|
|
424 |
{
|
|
425 |
TPtrC8 ptr(aData.Ptr(0));
|
|
426 |
TLex8 lex(ptr);
|
|
427 |
lex.Mark();
|
|
428 |
|
|
429 |
while (!lex.Eos())
|
|
430 |
{
|
|
431 |
if (lex.Peek() == KSmsPduDbTagStart)
|
|
432 |
{
|
|
433 |
ParseTagL(aData, ptr, lex);
|
|
434 |
}
|
|
435 |
else
|
|
436 |
{
|
|
437 |
lex.Inc();
|
|
438 |
}
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
|
442 |
void CSmsPduDatabase::ParseTagL(CBufFlat& aData, TPtrC8& aPtr, TLex8& aLex) const
|
|
443 |
{
|
|
444 |
const TInt startingPos = aLex.Offset();
|
|
445 |
|
|
446 |
const TPtrC8 remainder(aLex.Remainder());
|
|
447 |
const TInt locate = remainder.Locate(KSmsPduDbTagEnd);
|
|
448 |
TInt err = locate;
|
|
449 |
|
|
450 |
if (locate != KErrNotFound)
|
|
451 |
{
|
|
452 |
aLex.Mark();
|
|
453 |
aLex.Inc(locate+1);
|
|
454 |
|
|
455 |
const TPtrC8 marked(aLex.MarkedToken());
|
|
456 |
CSmsPduDbPdu* pdu = NULL;
|
|
457 |
|
|
458 |
TRAP(err, pdu = PduFactoryL(marked));
|
|
459 |
|
|
460 |
if (err == KErrNone)
|
|
461 |
{
|
|
462 |
CleanupStack::PushL(pdu);
|
|
463 |
TBuf8<RMobileSmsMessaging::KGsmTpduSize*2> hexPdu;
|
|
464 |
pdu->GetHexPdu(hexPdu);
|
|
465 |
aData.Delete(startingPos, marked.Length());
|
|
466 |
aData.InsertL(startingPos, hexPdu);
|
|
467 |
aPtr.Set(aData.Ptr(0));
|
|
468 |
aLex = aPtr;
|
|
469 |
aLex.Inc(startingPos + pdu->iPdu.Length());
|
|
470 |
CleanupStack::PopAndDestroy(pdu);
|
|
471 |
}
|
|
472 |
}
|
|
473 |
|
|
474 |
if (err != KErrNone)
|
|
475 |
{
|
|
476 |
aLex.Inc();
|
|
477 |
}
|
|
478 |
}
|
|
479 |
|
|
480 |
TBool CSmsPduDatabase::IsPdu(const TDesC8& aTag, CSmsPDU::TSmsPDUType& aType) const
|
|
481 |
{
|
|
482 |
TBool ret = EFalse;
|
|
483 |
|
|
484 |
if (aTag.CompareF(KSmsPduDbSubmit) == KErrNone)
|
|
485 |
{
|
|
486 |
ret = ETrue;
|
|
487 |
aType = CSmsPDU::ESmsSubmit;
|
|
488 |
}
|
|
489 |
else if (aTag.CompareF(KSmsPduDbDeliver) == KErrNone)
|
|
490 |
{
|
|
491 |
ret = ETrue;
|
|
492 |
aType = CSmsPDU::ESmsDeliver;
|
|
493 |
}
|
|
494 |
else if (aTag.CompareF(KSmsPduDbStatusReport) == KErrNone)
|
|
495 |
{
|
|
496 |
ret = ETrue;
|
|
497 |
aType = CSmsPDU::ESmsStatusReport;
|
|
498 |
}
|
|
499 |
else if (aTag.CompareF(KSmsPduDbCommand) == KErrNone)
|
|
500 |
{
|
|
501 |
ret = ETrue;
|
|
502 |
aType = CSmsPDU::ESmsCommand;
|
|
503 |
}
|
|
504 |
else if (aTag.CompareF(KSmsPduDbSubmitReport) == KErrNone)
|
|
505 |
{
|
|
506 |
ret = ETrue;
|
|
507 |
aType = CSmsPDU::ESmsSubmitReport;
|
|
508 |
}
|
|
509 |
else if (aTag.CompareF(KSmsPduDbDeliverReport) == KErrNone)
|
|
510 |
{
|
|
511 |
ret = ETrue;
|
|
512 |
aType = CSmsPDU::ESmsDeliverReport;
|
|
513 |
}
|
|
514 |
|
|
515 |
return ret;
|
|
516 |
}
|
|
517 |
|
|
518 |
TBool CSmsPduDatabase::IsConcatSegment(const TDesC8& aTag, CSmsPDU::TSmsPDUType& aType) const
|
|
519 |
{
|
|
520 |
TBool ret = EFalse;
|
|
521 |
|
|
522 |
if (aTag.CompareF(KSmsPduDbSubmitConcat) == KErrNone)
|
|
523 |
{
|
|
524 |
ret = ETrue;
|
|
525 |
aType = CSmsPDU::ESmsSubmit;
|
|
526 |
}
|
|
527 |
else if (aTag.CompareF(KSmsPduDbDeliverConcat) == KErrNone)
|
|
528 |
{
|
|
529 |
ret = ETrue;
|
|
530 |
aType = CSmsPDU::ESmsDeliver;
|
|
531 |
}
|
|
532 |
|
|
533 |
return ret;
|
|
534 |
}
|
|
535 |
|
|
536 |
EXPORT_C CSmsPduDbPdu* CSmsPduDatabase::PduFactoryL(const CTestConfigItem& aItem, CSmsPDU::TSmsPDUType aTypeForMessageTags) const
|
|
537 |
{
|
|
538 |
const TDesC8& type = aItem.Item();
|
|
539 |
CSmsPduDbPdu* pdu = NULL;
|
|
540 |
CSmsPDU::TSmsPDUType pduType;
|
|
541 |
|
|
542 |
if (IsPdu(type, pduType))
|
|
543 |
{
|
|
544 |
pdu = CSmsPduDbPdu::NewL(iFs, aItem, pduType);
|
|
545 |
}
|
|
546 |
else if (IsConcatSegment(type, pduType))
|
|
547 |
{
|
|
548 |
pdu = CSmsPduDbConcatSegment::NewL(iFs, aItem, pduType);
|
|
549 |
}
|
|
550 |
else if (IsMessage(type))
|
|
551 |
{
|
|
552 |
pdu = CSmsPduDbMessage::NewL(iFs, aItem, aTypeForMessageTags);
|
|
553 |
}
|
|
554 |
else
|
|
555 |
{
|
|
556 |
//Attempt to parse aItem.Value() using the other overload of PduFactoryL()
|
|
557 |
pdu = PduFactoryL(aItem.Value(), aTypeForMessageTags);
|
|
558 |
}
|
|
559 |
|
|
560 |
__ASSERT_DEBUG(pdu != NULL, PduDbPanic(EPduDbPanicPduNotConstructed));
|
|
561 |
return pdu;
|
|
562 |
}
|
|
563 |
|
|
564 |
EXPORT_C CSmsPduDbPdu* CSmsPduDatabase::PduFactoryL(const TDesC8& aTag, CSmsPDU::TSmsPDUType aTypeForMessageTags) const
|
|
565 |
/**
|
|
566 |
* Parses tags of the form <MESSAGE_TYPE; ID; {SEGMENT}>, e.g. <SUBMIT,21> or <MESSAGE,2> or <SUBMITCONCAT; 32; 2>
|
|
567 |
* If the MESSAGE_TYPE and ID combination if found in the PDU database then a CSmsPduDbPdu-derived object is created.
|
|
568 |
* SEGMENT is only compulsory if MESSAGE_TYPE is a concatenated message.
|
|
569 |
*
|
|
570 |
* @param aTag Tag of the form <MESSAGE_TYPE; ID; {SEGMENT}>. MESSAGE_TYPE and ID are compulsory and must be delimited by a semicolon (;)
|
|
571 |
* @param aTypeForMessageTags PDU Type used when creating a CSmsPduDbMessage. This occurs if MESSAGE_TYPE == "message"
|
|
572 |
*/
|
|
573 |
{
|
|
574 |
TPtrC8 tag(CTestConfig::Trim(aTag));
|
|
575 |
const TInt len = tag.Length();
|
|
576 |
|
|
577 |
if (len < 4)
|
|
578 |
User::Leave(KErrBadName);
|
|
579 |
|
|
580 |
TInt midStart = 0;
|
|
581 |
TInt midLen = len;
|
|
582 |
if (tag[0] == KSmsPduDbTagStart)
|
|
583 |
{
|
|
584 |
midStart++;
|
|
585 |
midLen--;
|
|
586 |
}
|
|
587 |
|
|
588 |
if (tag[len-1] == KSmsPduDbTagEnd)
|
|
589 |
midLen--;
|
|
590 |
|
|
591 |
tag.Set(tag.Mid(midStart, midLen));
|
|
592 |
|
|
593 |
TPtrC8 type;
|
|
594 |
TInt id(0);
|
|
595 |
|
|
596 |
User::LeaveIfError(CTestConfig::GetElement(tag, KSmsPduDbTagDelimitier, ETagType, type));
|
|
597 |
User::LeaveIfError(CTestConfig::GetElement(tag, KSmsPduDbTagDelimitier, ETagId, id));
|
|
598 |
|
|
599 |
CSmsPduDbPdu* pdu = NULL;
|
|
600 |
CSmsPDU::TSmsPDUType pduType;
|
|
601 |
|
|
602 |
if (IsPdu(type, pduType))
|
|
603 |
{
|
|
604 |
pdu = GetPduLC(pduType, id);
|
|
605 |
}
|
|
606 |
else if (IsConcatSegment(type, pduType))
|
|
607 |
{
|
|
608 |
TInt segment;
|
|
609 |
User::LeaveIfError(CTestConfig::GetElement(tag, KSmsPduDbTagDelimitier, ETagSegment, segment));
|
|
610 |
pdu = GetConcatSegmentLC(pduType, id, segment);
|
|
611 |
}
|
|
612 |
else if (IsMessage(type))
|
|
613 |
{
|
|
614 |
pdu = GetMessageLC(aTypeForMessageTags, id);
|
|
615 |
}
|
|
616 |
else
|
|
617 |
{
|
|
618 |
User::Leave(KErrBadName);
|
|
619 |
}
|
|
620 |
|
|
621 |
__ASSERT_DEBUG(pdu != NULL, PduDbPanic(EPduDbPanicPduNotConstructed));
|
|
622 |
CleanupStack::Pop(pdu);
|
|
623 |
return pdu;
|
|
624 |
}
|
|
625 |
|
|
626 |
EXPORT_C CSmsPduDbPdu* CSmsPduDatabase::PduFactory(const TDesC8& aTag, CSmsPDU::TSmsPDUType aTypeForMessageTags) const
|
|
627 |
{
|
|
628 |
CSmsPduDbPdu* pdu = NULL;
|
|
629 |
TRAPD(err, (pdu = PduFactoryL(aTag, aTypeForMessageTags)));
|
|
630 |
return ((err == KErrNone) ? pdu : NULL);
|
|
631 |
}
|
|
632 |
|
|
633 |
EXPORT_C CSmsPduDbPdu* CSmsPduDatabase::PduFactory(const CTestConfigItem& aItem, CSmsPDU::TSmsPDUType aTypeForMessageTags) const
|
|
634 |
{
|
|
635 |
CSmsPduDbPdu* pdu = NULL;
|
|
636 |
TRAPD(err, (pdu = PduFactoryL(aItem, aTypeForMessageTags)));
|
|
637 |
return ((err == KErrNone) ? pdu : NULL);
|
|
638 |
}
|
|
639 |
|
|
640 |
TInt CSmsPduDatabase::RSmsPduDbIdArray::Compare(const TSmsPduDbId& aLeft, const TSmsPduDbId& aRight)
|
|
641 |
{
|
|
642 |
return aLeft.iId - aRight.iId;
|
|
643 |
}
|
|
644 |
|
|
645 |
TInt CSmsPduDatabase::RSmsPduDbIdArray::Find(TInt aId) const
|
|
646 |
{
|
|
647 |
TLinearOrder<TSmsPduDbId> order(Compare);
|
|
648 |
const TSmsPduDbId tempId(NULL, aId);
|
|
649 |
return FindInOrder(tempId, order);
|
|
650 |
}
|
|
651 |
|
|
652 |
void CSmsPduDatabase::RSmsPduDbIdArray::InsertL(const TSmsPduDbId& aId)
|
|
653 |
{
|
|
654 |
TLinearOrder<TSmsPduDbId> order(Compare);
|
|
655 |
|
|
656 |
if (iAllowDuplicates)
|
|
657 |
User::LeaveIfError(InsertInOrderAllowRepeats(aId, order));
|
|
658 |
else
|
|
659 |
User::LeaveIfError(InsertInOrder(aId, order));
|
|
660 |
}
|