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 "gsmubuf.h"
|
|
17 |
#include "gsmuset.h"
|
|
18 |
#include "Gsmuelem.h"
|
|
19 |
#include "Gsmumsg.h"
|
|
20 |
#include "gsmusar.h"
|
|
21 |
#include "gsmupdu.h"
|
|
22 |
#include "WAPDGRM.H"
|
|
23 |
#include "ws_main.h"
|
|
24 |
#include "smsstackutils.h"
|
|
25 |
|
|
26 |
//
|
|
27 |
// For incoming short message
|
|
28 |
//
|
|
29 |
CWapDatagram* CWapDatagram::NewL(const CSmsMessage& aSms)
|
|
30 |
{
|
|
31 |
LOGWAPPROT2("CWapDatagram::NewL(): aSms=0x%08x", (TInt) &aSms);
|
|
32 |
|
|
33 |
CWapDatagram* datagram = new (ELeave)CWapDatagram();
|
|
34 |
|
|
35 |
CleanupStack::PushL(datagram);
|
|
36 |
datagram->ConstructL(aSms);
|
|
37 |
CleanupStack::Pop();
|
|
38 |
|
|
39 |
LOGWAPPROT2("CWapDatagram::NewL(): iFromPort: %d", datagram->iFromPort);
|
|
40 |
LOGWAPPROT2("CWapDatagram::NewL(): iToPort: %d", datagram->iToPort);
|
|
41 |
LOGWAPPROT2("CWapDatagram::NewL(): iReference: %d", datagram->iReference);
|
|
42 |
LOGWAPPROT2("CWapDatagram::NewL(): iTotalSegments: %d", datagram->iTotalSegments);
|
|
43 |
LOGWAPPROT2("CWapDatagram::NewL(): iSegmentNumber: %d", datagram->iSegmentNumber);
|
|
44 |
LOGWAPPROT2("CWapDatagram::NewL(): iIsComplete: %d", datagram->iIsComplete);
|
|
45 |
LOGWAPPROT2("CWapDatagram::NewL(): iReference: %d", datagram->iReference);
|
|
46 |
LOGWAPPROT2("CWapDatagram::NewL(): iIsTextHeader: %d", datagram->iIsTextHeader);
|
|
47 |
LOGWAPPROT2("CWapDatagram::NewL(): iLogServerId: %d", datagram->iLogServerId);
|
|
48 |
LOGWAPPROT2("CWapDatagram::NewL(): i16BitPorts: %d", datagram->i16BitPorts);
|
|
49 |
|
|
50 |
// assert destination port
|
|
51 |
if (datagram->i16BitPorts)
|
|
52 |
{
|
|
53 |
if (datagram->iToPort>=0 && datagram->iToPort<=65535)
|
|
54 |
{
|
|
55 |
LOGWAPPROT1("iToPort OK");
|
|
56 |
}
|
|
57 |
else
|
|
58 |
{
|
|
59 |
LOGWAPPROT1("iToPort FAILED");
|
|
60 |
}
|
|
61 |
}
|
|
62 |
else
|
|
63 |
{
|
|
64 |
if (datagram->iToPort>=0 && datagram->iToPort<=255)
|
|
65 |
{
|
|
66 |
LOGWAPPROT1("iToPort OK");
|
|
67 |
}
|
|
68 |
else
|
|
69 |
{
|
|
70 |
LOGWAPPROT1("iToPort FAILED");
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
if (datagram->i16BitPorts)
|
|
75 |
{
|
|
76 |
if (datagram->iFromPort>=0 && datagram->iFromPort<=65535)
|
|
77 |
{
|
|
78 |
LOGWAPPROT1("iFromPort OK");
|
|
79 |
}
|
|
80 |
else
|
|
81 |
{
|
|
82 |
LOGWAPPROT1("iFromPort FAILED");
|
|
83 |
}
|
|
84 |
}
|
|
85 |
else
|
|
86 |
{
|
|
87 |
if (datagram->iFromPort>=0 && datagram->iFromPort<=255)
|
|
88 |
{
|
|
89 |
LOGWAPPROT1("iFromPort OK");
|
|
90 |
}
|
|
91 |
else
|
|
92 |
{
|
|
93 |
LOGWAPPROT1("iFromPort FAILED");
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
return datagram;
|
|
98 |
} // CWapDatagram::NewL
|
|
99 |
|
|
100 |
|
|
101 |
//
|
|
102 |
// For outgoing short messages
|
|
103 |
//
|
|
104 |
CWapDatagram* CWapDatagram::NewL(const TDesC8& aSendBuffer)
|
|
105 |
{
|
|
106 |
LOGWAPPROT2("CWapDatagram::NewL(): aSendBuffer=0x%08x", (TInt) &aSendBuffer);
|
|
107 |
|
|
108 |
CWapDatagram* datagram = new (ELeave)CWapDatagram();
|
|
109 |
|
|
110 |
CleanupStack::PushL(datagram);
|
|
111 |
datagram->Construct(aSendBuffer);
|
|
112 |
CleanupStack::Pop();
|
|
113 |
|
|
114 |
return datagram;
|
|
115 |
} // CWapDatagram::NewL
|
|
116 |
|
|
117 |
|
|
118 |
CWapDatagram::~CWapDatagram()
|
|
119 |
{
|
|
120 |
LOGWAPPROT1("CWapDatagram::~CWapDatagram()");
|
|
121 |
|
|
122 |
delete iRecvbuf;
|
|
123 |
delete iBuffer;
|
|
124 |
delete iSegment;
|
|
125 |
} // CWapDatagram::~CWapDatagram
|
|
126 |
|
|
127 |
|
|
128 |
//
|
|
129 |
// What about service centre address ?
|
|
130 |
// aSmsMessageArray contains CSmsMessage objects
|
|
131 |
//
|
|
132 |
void CWapDatagram::EncodeConcatenatedMessagesL(RFs& aFs, CArrayPtr<CSmsMessage>& aSmsMessageArray)
|
|
133 |
{
|
|
134 |
LOGWAPPROT2("CWapDatagram::EncodeConcatenatedMessagesL(): %d messages", aSmsMessageArray.Count());
|
|
135 |
|
|
136 |
// Couple of checkings makes sense
|
|
137 |
__ASSERT_DEBUG(iToPort >=0 && iToAddress.Length()>=0
|
|
138 |
&& (iUserDataSettings.Alphabet()==TSmsDataCodingScheme::ESmsAlphabet8Bit
|
|
139 |
|| iUserDataSettings.Alphabet()==TSmsDataCodingScheme::ESmsAlphabet7Bit),
|
|
140 |
Panic(KPanicUsageError));
|
|
141 |
|
|
142 |
// Determine CSmsMessage encoding by character width
|
|
143 |
if (iUserDataSettings.Alphabet() == TSmsDataCodingScheme::ESmsAlphabet8Bit)
|
|
144 |
{
|
|
145 |
CSmsBufferBase* SmsBuffer = CSmsBuffer::NewL();
|
|
146 |
|
|
147 |
CleanupStack::PushL(SmsBuffer);
|
|
148 |
ConvertL(iSendBuffer,*SmsBuffer);
|
|
149 |
CleanupStack::Pop(); // SmsBuffer, popped here since it is pushed again in the following NewL call
|
|
150 |
CSmsMessage* SmsMessage = CSmsMessage::NewL(aFs, CSmsPDU::ESmsSubmit,SmsBuffer,EFalse);
|
|
151 |
CleanupStack::PushL(SmsMessage);
|
|
152 |
// one and only object
|
|
153 |
aSmsMessageArray.AppendL(SmsMessage);
|
|
154 |
CleanupStack::Pop(); // SmsMessage
|
|
155 |
|
|
156 |
SetSmsMessageSettingsL(*SmsMessage,ETrue);
|
|
157 |
}
|
|
158 |
else
|
|
159 |
{
|
|
160 |
// contruct TWapTextMessage object
|
|
161 |
TWapTextMessage* Segment = new (ELeave) TWapTextMessage(KNullDesC8);
|
|
162 |
CleanupStack::PushL(Segment);
|
|
163 |
CArrayPtrFlat<HBufC8>* SegmentArray = new (ELeave) CArrayPtrFlat<HBufC8> (8);
|
|
164 |
CleanupStack::PushL(SegmentArray);
|
|
165 |
// coverity[double_push]
|
|
166 |
CleanupResetAndDestroyPushL(*SegmentArray);
|
|
167 |
|
|
168 |
Segment->SetDestinationPort(iToPort,i16BitPorts);
|
|
169 |
Segment->SetSourcePort(iFromPort,i16BitPorts);
|
|
170 |
Segment->SetReferenceNumber(iReference);
|
|
171 |
Segment->SetUserData(iSendBuffer);
|
|
172 |
Segment->SetOtherHeader(iOtherHeader);
|
|
173 |
Segment->EncodeSegmentsL(*SegmentArray);
|
|
174 |
|
|
175 |
// contruct array of CSmsMessages
|
|
176 |
TInt Count = SegmentArray->Count();
|
|
177 |
for (TInt i=0; i<Count; i++)
|
|
178 |
{
|
|
179 |
CSmsBufferBase* SmsBuffer = CSmsBuffer::NewL();
|
|
180 |
|
|
181 |
CleanupStack::PushL(SmsBuffer);
|
|
182 |
ConvertL(*(SegmentArray->At(i)),*SmsBuffer);
|
|
183 |
CleanupStack::Pop(); // SmsBuffer, popped here since it is pushed again in the following NewL call
|
|
184 |
CSmsMessage* SmsMessage=CSmsMessage::NewL(aFs, CSmsPDU::ESmsSubmit,SmsBuffer,EFalse);
|
|
185 |
CleanupStack::PushL(SmsMessage);
|
|
186 |
aSmsMessageArray.AppendL(SmsMessage);
|
|
187 |
CleanupStack::Pop(); // SmsMessage
|
|
188 |
|
|
189 |
SetSmsMessageSettingsL(*SmsMessage,EFalse);
|
|
190 |
}
|
|
191 |
CleanupStack::PopAndDestroy(3, Segment); // SegmentArray elements (Reset and Destroy), SegmentArray, Segment
|
|
192 |
|
|
193 |
}
|
|
194 |
} // CWapDatagram::EncodeConcatenatedMessagesL
|
|
195 |
|
|
196 |
void CWapDatagram::DecodeConcatenatedMessagesL(CArrayPtr<TSegmentData>& aSmsMessageArray)
|
|
197 |
{
|
|
198 |
LOGWAPPROT1("CWapDatagram::DecodeConcatenatedMessagesL()");
|
|
199 |
|
|
200 |
// The TSegmentData elements are in the random order in the array
|
|
201 |
TInt Count = aSmsMessageArray.Count();
|
|
202 |
TInt i=0;
|
|
203 |
|
|
204 |
if (Count > 0)
|
|
205 |
{
|
|
206 |
TInt DataLength = 0; // total length of data
|
|
207 |
TInt TempLength = 0;
|
|
208 |
|
|
209 |
// Every TSegmentData should be equal length except last segment
|
|
210 |
// Use that 'constant' segment length as indexes
|
|
211 |
// Count the actual data length
|
|
212 |
for(i=0; i<Count; i++)
|
|
213 |
{
|
|
214 |
TempLength = aSmsMessageArray.At(i)->iData.Length();
|
|
215 |
DataLength += TempLength;
|
|
216 |
}
|
|
217 |
|
|
218 |
TSegmentData* Segment = NULL;
|
|
219 |
|
|
220 |
if (iBuffer)
|
|
221 |
{
|
|
222 |
delete iBuffer;
|
|
223 |
iBuffer = NULL;
|
|
224 |
}
|
|
225 |
iBuffer = HBufC8::NewL(DataLength );
|
|
226 |
|
|
227 |
TPtr8 BufferPtr(iBuffer->Des());
|
|
228 |
BufferPtr.SetLength(DataLength );
|
|
229 |
|
|
230 |
TInt segmentStartPosition=0;
|
|
231 |
|
|
232 |
for(i=0; i<Count; i++)
|
|
233 |
{
|
|
234 |
if (segmentStartPosition >= DataLength)
|
|
235 |
{
|
|
236 |
// Once the start position is out of range,
|
|
237 |
// there is no point in continuing reconstructing the
|
|
238 |
// wapdatagram.
|
|
239 |
break;
|
|
240 |
}
|
|
241 |
|
|
242 |
Segment = aSmsMessageArray.At(i);
|
|
243 |
TPtr8 CopyBufferPtr(&(BufferPtr[segmentStartPosition]),0,160);
|
|
244 |
CopyBufferPtr.Copy(Segment->iData);
|
|
245 |
segmentStartPosition+=Segment->iData.Length();
|
|
246 |
}
|
|
247 |
}
|
|
248 |
iIsComplete = ETrue;
|
|
249 |
} // CWapDatagram::DecodeConcatenatedMessagesL
|
|
250 |
|
|
251 |
|
|
252 |
void CWapDatagram::InternalizeL(RReadStream& aStream)
|
|
253 |
{
|
|
254 |
aStream >> iUserDataSettings;
|
|
255 |
aStream >> iToAddress;
|
|
256 |
iToPort = aStream.ReadInt32L();
|
|
257 |
aStream >> iFromAddress;
|
|
258 |
iFromPort = aStream.ReadInt32L();
|
|
259 |
TInt64 time;
|
|
260 |
aStream >> time;
|
|
261 |
iTime = time;
|
|
262 |
iUTCOffset = aStream.ReadInt32L();
|
|
263 |
iIsTextHeader = aStream.ReadInt32L();
|
|
264 |
iReference = aStream.ReadInt32L();
|
|
265 |
iTotalSegments = aStream.ReadInt32L();
|
|
266 |
iSegmentNumber = aStream.ReadInt32L();
|
|
267 |
iLogServerId = aStream.ReadInt32L();
|
|
268 |
iVersionNumber = aStream.ReadInt32L();
|
|
269 |
iSpare1 = aStream.ReadInt32L();
|
|
270 |
iSpare2 = aStream.ReadInt32L();
|
|
271 |
iSpare3 = aStream.ReadInt32L();
|
|
272 |
|
|
273 |
// Required for version 1, which is reading and internalizing extra SMS parameters from stream
|
|
274 |
if(iVersionNumber == EFirstVersion)
|
|
275 |
{
|
|
276 |
TInt length = aStream.ReadInt32L();
|
|
277 |
if(length>0)
|
|
278 |
{
|
|
279 |
HBufC8* smsBuffer=HBufC8::NewMaxLC(length);
|
|
280 |
TPtr8 recvbuftmp = smsBuffer->Des();
|
|
281 |
aStream >> recvbuftmp;
|
|
282 |
if(!iRecvbuf)
|
|
283 |
{
|
|
284 |
iRecvbuf = CBufFlat::NewL(KSmsBufferExpansion);
|
|
285 |
}
|
|
286 |
iRecvbuf->ResizeL(recvbuftmp.Size());
|
|
287 |
iRecvbuf->Write(0, recvbuftmp);
|
|
288 |
CleanupStack::PopAndDestroy(smsBuffer);
|
|
289 |
}
|
|
290 |
}
|
|
291 |
|
|
292 |
} // CWapDatagram::InternalizeL
|
|
293 |
|
|
294 |
|
|
295 |
//
|
|
296 |
// Reads iBuffer from stream (for 8Bit messages)
|
|
297 |
//
|
|
298 |
void CWapDatagram::InternalizeBufferL(RReadStream& aStream)
|
|
299 |
{
|
|
300 |
TInt length;
|
|
301 |
length=aStream.ReadInt32L();
|
|
302 |
iBuffer=HBufC8::NewMaxL(length);
|
|
303 |
TPtr8 tmp = iBuffer->Des();
|
|
304 |
aStream >> tmp;
|
|
305 |
iIsComplete = ETrue;
|
|
306 |
}
|
|
307 |
|
|
308 |
|
|
309 |
void CWapDatagram::ExternalizeL(RWriteStream& aStream) const
|
|
310 |
{
|
|
311 |
aStream << iUserDataSettings;
|
|
312 |
aStream << iToAddress;
|
|
313 |
aStream.WriteInt32L(iToPort);
|
|
314 |
|
|
315 |
aStream << iFromAddress;
|
|
316 |
aStream.WriteInt32L(iFromPort);
|
|
317 |
aStream << iTime.Int64();
|
|
318 |
aStream.WriteInt32L(iUTCOffset.Int());
|
|
319 |
|
|
320 |
aStream.WriteInt32L(iIsTextHeader);
|
|
321 |
aStream.WriteInt32L(iReference);
|
|
322 |
aStream.WriteInt32L(iTotalSegments);
|
|
323 |
aStream.WriteInt32L(iSegmentNumber);
|
|
324 |
|
|
325 |
aStream.WriteInt32L(iLogServerId);
|
|
326 |
|
|
327 |
aStream.WriteInt32L(iVersionNumber);
|
|
328 |
aStream.WriteInt32L(iSpare1);
|
|
329 |
aStream.WriteInt32L(iSpare2);
|
|
330 |
aStream.WriteInt32L(iSpare3);
|
|
331 |
|
|
332 |
// Externalizing the SMS params if exists
|
|
333 |
if(iRecvbuf)
|
|
334 |
{
|
|
335 |
TPtr8 recvbuftmp = iRecvbuf->Ptr(0);
|
|
336 |
aStream.WriteInt32L(recvbuftmp.Length());
|
|
337 |
aStream << recvbuftmp;
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
aStream.WriteInt32L(0);
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
|
|
346 |
//
|
|
347 |
// writes iBuffer to writeStream for 8-bit incomming messages
|
|
348 |
//
|
|
349 |
void CWapDatagram::ExternalizeBufferL(RWriteStream& aStream) const
|
|
350 |
{
|
|
351 |
TInt length= WapDatagramLength();
|
|
352 |
aStream.WriteInt32L(length);
|
|
353 |
TPtr8 tmp= iBuffer->Des();
|
|
354 |
aStream << tmp;
|
|
355 |
|
|
356 |
} // CWapDatagram::ExternalizeBufferL
|
|
357 |
|
|
358 |
|
|
359 |
//
|
|
360 |
// Outgoing
|
|
361 |
//
|
|
362 |
void CWapDatagram::Construct(const TDesC8& aSendBuffer)
|
|
363 |
{
|
|
364 |
LOGWAPPROT1("CWapDatagram::Construct()");
|
|
365 |
|
|
366 |
// Set version number to 1, as we have had to make
|
|
367 |
// changes to CWapDatagram for CR0929
|
|
368 |
iVersionNumber = EFirstVersion;
|
|
369 |
|
|
370 |
iSendBuffer.Set(aSendBuffer);
|
|
371 |
} // CWapDatagram::Construct
|
|
372 |
|
|
373 |
|
|
374 |
//
|
|
375 |
// Incoming
|
|
376 |
// code actualy supports 7-bit characters and port numbers
|
|
377 |
// encoded in information elements (IE) although it is not
|
|
378 |
// a requirement
|
|
379 |
//
|
|
380 |
void CWapDatagram::ConstructL(const CSmsMessage& aSms)
|
|
381 |
{
|
|
382 |
LOGWAPPROT1("CWapDatagram::ConstructL()");
|
|
383 |
|
|
384 |
// Set version number to 1, as we have had to make
|
|
385 |
// changes to CWapDatagram for CR0929
|
|
386 |
iVersionNumber = EFirstVersion;
|
|
387 |
|
|
388 |
iRecvbuf = CBufFlat::NewL(KSmsBufferExpansion);
|
|
389 |
|
|
390 |
RBufWriteStream writestream(*iRecvbuf);
|
|
391 |
writestream.Open(*iRecvbuf);
|
|
392 |
CleanupClosePushL(writestream);
|
|
393 |
|
|
394 |
// Externalizing everything within CSMSMessage except buffer
|
|
395 |
aSms.ExternalizeWithoutBufferL(writestream);
|
|
396 |
|
|
397 |
CleanupStack::PopAndDestroy(); // writestream
|
|
398 |
|
|
399 |
iRecvbuf->Compress();
|
|
400 |
|
|
401 |
const CSmsBufferBase& SmsBufferBase = aSms.Buffer();
|
|
402 |
|
|
403 |
GetDatagramSettings(aSms);
|
|
404 |
|
|
405 |
// Get the data from CSmsMessage and convert
|
|
406 |
// SmsBuffer store Unicode short message from CSmsMessage
|
|
407 |
ConvertL(SmsBufferBase,&iBuffer);
|
|
408 |
GetDatagramSettingsL();
|
|
409 |
|
|
410 |
iIsComplete = ETrue;
|
|
411 |
if (iUserDataSettings.Alphabet() == TSmsDataCodingScheme::ESmsAlphabet7Bit)
|
|
412 |
{
|
|
413 |
// this is a good candidate to include a text header.
|
|
414 |
if (iIsTextHeader)
|
|
415 |
{
|
|
416 |
// there is still a minor chance that message is complete:
|
|
417 |
// one fragment long datagram
|
|
418 |
if (iTotalSegments == 1)
|
|
419 |
{
|
|
420 |
// Get the segment data
|
|
421 |
TPtr8 PtrNarrow = iBuffer->Des();
|
|
422 |
PtrNarrow.Zero();
|
|
423 |
iSegment->UserData(PtrNarrow);
|
|
424 |
}
|
|
425 |
else
|
|
426 |
{
|
|
427 |
iIsComplete = EFalse;
|
|
428 |
// delete incomplete message from iBuffer;
|
|
429 |
delete iBuffer;
|
|
430 |
iBuffer = 0;
|
|
431 |
}
|
|
432 |
}
|
|
433 |
else
|
|
434 |
// This means that IEs with 7-bits are used
|
|
435 |
// Happily we support it
|
|
436 |
iIsComplete = ETrue;
|
|
437 |
|
|
438 |
}
|
|
439 |
} // CWapDatagram::ConstructL
|
|
440 |
|
|
441 |
|
|
442 |
//
|
|
443 |
// Set WAP datagram private members from a text based concatenated message
|
|
444 |
// Copies contents of iBuffer to iSmsBuffer
|
|
445 |
// Allocates iSegment object
|
|
446 |
//
|
|
447 |
void CWapDatagram::GetDatagramSettingsL()
|
|
448 |
{
|
|
449 |
LOGWAPPROT1("CWapDatagram::GetDatagramSettingsL()");
|
|
450 |
|
|
451 |
/* The WAP stack always receives 8 bit WAP datagrams from the SMS Stack as a single CSmsMessage.
|
|
452 |
This is because 8 bit WAP messages which cannot be encoded into a single PDU are sent in a segmented SMS
|
|
453 |
message which is reassembled inside the SMS Stack; the SMS Stack always passes the WAP stack
|
|
454 |
a single CSmsMessage containing a single WAP message regardless of the message length.
|
|
455 |
The WAP stack can receive 7 Bit WAP datagrams either as a single CSmsMessage or as a number of CSmsMessages
|
|
456 |
which need to be reassembled into a single WAP message by the WAP stack. The latter method is provided to maintain backward
|
|
457 |
compatibility with early versions of the WAP stack which were implemented before the concatenation function was
|
|
458 |
available in the SMS stack.*/
|
|
459 |
|
|
460 |
/* 160 is the maximum number of character that can be fitted in a single PDU using 7 bit encoding */
|
|
461 |
if((iUserDataSettings.Alphabet()== TSmsDataCodingScheme::ESmsAlphabet8Bit) ||
|
|
462 |
(iUserDataSettings.Alphabet()== TSmsDataCodingScheme::ESmsAlphabet7Bit && iBuffer->Length()>160 ))
|
|
463 |
{
|
|
464 |
iSegment = new (ELeave)TWapTextMessage(*iBuffer);
|
|
465 |
}
|
|
466 |
else if (iBuffer->Length()<=160)
|
|
467 |
{
|
|
468 |
iSmsBuffer = *iBuffer;
|
|
469 |
iSegment = new (ELeave)TWapTextMessage(iSmsBuffer);
|
|
470 |
iIsTextHeader = iSegment->Parse();
|
|
471 |
|
|
472 |
if (iIsTextHeader)
|
|
473 |
{
|
|
474 |
iFromPort = iSegment->SourcePort(&i16BitPorts);
|
|
475 |
iToPort = iSegment->DestinationPort(&i16BitPorts);
|
|
476 |
iReference = iSegment->ReferenceNumber();
|
|
477 |
iTotalSegments = iSegment->TotalSegments();
|
|
478 |
iSegmentNumber = iSegment->SegmentNumber();
|
|
479 |
}
|
|
480 |
}
|
|
481 |
else
|
|
482 |
{
|
|
483 |
delete iSegment;
|
|
484 |
iSegment = 0;
|
|
485 |
}
|
|
486 |
} // CWapDatagram::GetDatagramSettingsL
|
|
487 |
|
|
488 |
|
|
489 |
//
|
|
490 |
// Set WAP datagram private members from information element structures
|
|
491 |
//
|
|
492 |
void CWapDatagram::GetDatagramSettings(const CSmsMessage& aSms)
|
|
493 |
{
|
|
494 |
LOGWAPPROT1("CWapDatagram::GetDatagramSettings()");
|
|
495 |
|
|
496 |
const CSmsPDU& Pdu = aSms.SmsPDU();
|
|
497 |
|
|
498 |
__ASSERT_DEBUG(Pdu.Type()==CSmsPDU::ESmsDeliver || Pdu.Type()==CSmsPDU::ESmsSubmit, // this line is testing purposes only
|
|
499 |
Panic(KPanicUsageError));
|
|
500 |
|
|
501 |
aSms.UserDataSettings(iUserDataSettings);
|
|
502 |
|
|
503 |
Pdu.ApplicationPortAddressing(iToPort,iFromPort,&i16BitPorts);
|
|
504 |
if (iFromPort == (-1))
|
|
505 |
iFromPort = iToPort;
|
|
506 |
|
|
507 |
// From WAP datagram point of view following numbers are applicable
|
|
508 |
iReference = 0;
|
|
509 |
iTotalSegments = 1;
|
|
510 |
iSegmentNumber = 1;
|
|
511 |
|
|
512 |
iFromAddress = aSms.ToFromAddress();
|
|
513 |
iToAddress = KNullDesC;
|
|
514 |
iTime = aSms.Time();
|
|
515 |
|
|
516 |
TBool result = SetUTCOffset(aSms.UTCOffset());
|
|
517 |
__ASSERT_DEBUG(result, Panic(KPanicSmsMsgTimeZoneOutOfRange));
|
|
518 |
} // CWapDatagram::GetDatagramSettings
|
|
519 |
|
|
520 |
|
|
521 |
//
|
|
522 |
// Set Alphabet information of iUserDataSettings before calling the method
|
|
523 |
// Converts from 7/8-bit to UNICODE
|
|
524 |
//
|
|
525 |
void CWapDatagram::ConvertL(const TDesC8& aNarrowChars,CSmsBufferBase& aSmsBuffer) const
|
|
526 |
{
|
|
527 |
LOGWAPPROT1("CWapDatagram::ConvertL()");
|
|
528 |
|
|
529 |
// Convert the data in segments of specified max size
|
|
530 |
const TInt KMaxSegmentSize=CSmsBufferBase::EMaxBufLength;
|
|
531 |
|
|
532 |
// Create converter and reassembler
|
|
533 |
RFs fs;
|
|
534 |
CCnvCharacterSetConverter* charConv=CCnvCharacterSetConverter::NewLC();
|
|
535 |
CSmsAlphabetConverter* converter=CSmsAlphabetConverter::NewLC(*charConv,fs,iUserDataSettings.Alphabet(),ETrue);
|
|
536 |
TSmsBufferReassembler reassembler(*converter,aSmsBuffer);
|
|
537 |
|
|
538 |
// Rassemble
|
|
539 |
TInt elementsRemaining=aNarrowChars.Length();
|
|
540 |
while (elementsRemaining)
|
|
541 |
{
|
|
542 |
TInt segmentLength=Min(KMaxSegmentSize,elementsRemaining);
|
|
543 |
TPtrC8 ptr(aNarrowChars.Ptr()+aNarrowChars.Length()-elementsRemaining,segmentLength);
|
|
544 |
reassembler.ReassembleNextL(ptr, ESmsEncodingNone,
|
|
545 |
elementsRemaining==segmentLength);
|
|
546 |
elementsRemaining-=segmentLength;
|
|
547 |
}
|
|
548 |
|
|
549 |
CleanupStack::PopAndDestroy(2); // charConv,
|
|
550 |
} // CWapDatagram::ConvertL
|
|
551 |
|
|
552 |
|
|
553 |
//
|
|
554 |
// Converts from UNICODE to 7/8-bit
|
|
555 |
//
|
|
556 |
void CWapDatagram::ConvertL(const CSmsBufferBase& aSmsBuffer,HBufC8** aNarrowChars) const
|
|
557 |
{
|
|
558 |
LOGWAPPROT1("CWapDatagram::ConvertL()");
|
|
559 |
|
|
560 |
// Convert the data in segments of specified max size
|
|
561 |
const TInt KMaxSegmentSize=CSmsBufferBase::EMaxBufLength;
|
|
562 |
|
|
563 |
// Delete the existing buffer
|
|
564 |
if (*aNarrowChars)
|
|
565 |
{
|
|
566 |
delete *aNarrowChars;
|
|
567 |
*aNarrowChars=NULL;
|
|
568 |
}
|
|
569 |
|
|
570 |
// Create converter and segmenter
|
|
571 |
RFs fs;
|
|
572 |
CCnvCharacterSetConverter* charConv=CCnvCharacterSetConverter::NewLC();
|
|
573 |
CSmsAlphabetConverter* converter=CSmsAlphabetConverter::NewLC(*charConv,fs,iUserDataSettings.Alphabet(),ETrue);
|
|
574 |
CSmsBufferSegmenter* segmenter=CSmsBufferSegmenter::NewLC(*converter,aSmsBuffer,KMaxSegmentSize);
|
|
575 |
|
|
576 |
// Create a new buffer based on converted length
|
|
577 |
TInt convertedLength=segmenter->TotalConvertedLengthL(ESmsEncodingNone);
|
|
578 |
*aNarrowChars=HBufC8::NewMaxL(((convertedLength+KMaxSegmentSize-1)/KMaxSegmentSize)*KMaxSegmentSize);
|
|
579 |
TPtr8 narrowPtr=(*aNarrowChars)->Des();
|
|
580 |
|
|
581 |
// Now do the conversion
|
|
582 |
TInt elementsConverted=0;
|
|
583 |
TInt unconvertedChars=0;
|
|
584 |
TInt downgradedChars=0;
|
|
585 |
TBool complete=EFalse;
|
|
586 |
while (elementsConverted<convertedLength)
|
|
587 |
{
|
|
588 |
__ASSERT_DEBUG(elementsConverted<convertedLength,Panic(KPanicTooLongData));
|
|
589 |
TPtr8 ptr((TUint8*)narrowPtr.Ptr()+elementsConverted,0,KMaxSegmentSize);
|
|
590 |
complete=segmenter->SegmentNextL(ptr, unconvertedChars, downgradedChars, ESmsEncodingNone);
|
|
591 |
elementsConverted+=ptr.Length();
|
|
592 |
}
|
|
593 |
if((!complete || (convertedLength!=elementsConverted)) && convertedLength)
|
|
594 |
User::Leave( KErrCorrupt );
|
|
595 |
narrowPtr.SetLength(convertedLength);
|
|
596 |
|
|
597 |
CleanupStack::PopAndDestroy(3); // charConv,converter,segmenter
|
|
598 |
} // CWapDatagram::ConvertL
|
|
599 |
|
|
600 |
|
|
601 |
void CWapDatagram::SetSmsMessageSettingsL(CSmsMessage& aSmsMessage, TBool aSetPorts)
|
|
602 |
{
|
|
603 |
LOGWAPPROT1("CWapDatagram::SetSmsMessageSettingsL()");
|
|
604 |
|
|
605 |
CSmsPDU& Pdu = aSmsMessage.SmsPDU();
|
|
606 |
|
|
607 |
aSmsMessage.SetToFromAddressL(iToAddress);
|
|
608 |
aSmsMessage.SetUserDataSettingsL(iUserDataSettings);
|
|
609 |
aSmsMessage.SetTime(iTime);
|
|
610 |
|
|
611 |
TBool result = aSmsMessage.SetUTCOffset(iUTCOffset);
|
|
612 |
__ASSERT_DEBUG(result, Panic(KPanicWapDgrmTimeZoneOutOfRange));
|
|
613 |
|
|
614 |
if (aSetPorts)
|
|
615 |
{
|
|
616 |
if (iFromPort == (-1))
|
|
617 |
iFromPort = iToPort;
|
|
618 |
|
|
619 |
// Determine whether long or short form is used
|
|
620 |
if (iFromPort > 255 || iToPort>255)
|
|
621 |
i16BitPorts = ETrue;
|
|
622 |
|
|
623 |
Pdu.SetApplicationPortAddressingL(ETrue,iToPort,iFromPort,i16BitPorts);
|
|
624 |
// WAP implementation guidelines recommend DCS of 0x15, however
|
|
625 |
// some gateways / SCs will only accept DCS 0xf5
|
|
626 |
Pdu.SetBits7To4(TSmsDataCodingScheme::ESmsDCSTextUncompressed7BitOr8Bit);
|
|
627 |
Pdu.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabet8Bit);
|
|
628 |
Pdu.SetClass(ETrue,TSmsDataCodingScheme::ESmsClass1);
|
|
629 |
}
|
|
630 |
} // CWapDatagram::SetSmsMessageSettingsL
|
|
631 |
|
|
632 |
|
|
633 |
CWapDatagram::CWapDatagram():
|
|
634 |
iUserDataSettings(),
|
|
635 |
iToAddress(KNullDesC),
|
|
636 |
iFromAddress(KNullDesC),
|
|
637 |
i16BitPorts(EFalse),
|
|
638 |
iFromPort(-1),
|
|
639 |
iToPort(-1),
|
|
640 |
iTime(),
|
|
641 |
iUTCOffset(0),
|
|
642 |
iIsComplete(EFalse),
|
|
643 |
iReference(0),
|
|
644 |
iTotalSegments(0),
|
|
645 |
iSegmentNumber(0),
|
|
646 |
iIsTextHeader(EFalse),
|
|
647 |
iSegment(NULL),
|
|
648 |
iSmsBuffer(KNullDesC8),
|
|
649 |
iBuffer(NULL),
|
|
650 |
iSendBuffer(KNullDesC8),
|
|
651 |
iOtherHeader(KNullDesC8),
|
|
652 |
iLogServerId(0),
|
|
653 |
iVersionNumber(EBaseVersion),// Set version number to EBaseVersion by default.
|
|
654 |
iSpare1(0),
|
|
655 |
iSpare2(0),
|
|
656 |
iSpare3(0),
|
|
657 |
iRecvbuf(NULL)
|
|
658 |
{
|
|
659 |
iTime.UniversalTime();
|
|
660 |
|
|
661 |
TBool result = SetUTCOffset(User::UTCOffset());
|
|
662 |
__ASSERT_DEBUG(result, Panic(KPanicUserSuppliedTimeZoneOutOfRange));
|
|
663 |
|
|
664 |
iUserDataSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabet8Bit);
|
|
665 |
__DECLARE_NAME(_S("CWapDatagram"));
|
|
666 |
} // CWapDatagram::CWapDatagram
|
|
667 |
|
|
668 |
|
|
669 |
//
|
|
670 |
// Return the location of the link
|
|
671 |
//
|
|
672 |
TInt CWapDatagram::LinkOffset()
|
|
673 |
{
|
|
674 |
LOGWAPPROT1("CWapDatagram::LinkOffset()");
|
|
675 |
|
|
676 |
|
|
677 |
return _FOFF(CWapDatagram,iLink);
|
|
678 |
} // CWapDatagram::LinkOffset
|
|
679 |
|
|
680 |
|
|
681 |
TBool CWapDatagram::SetUTCOffset(const TTimeIntervalSeconds& aUTCOffset)
|
|
682 |
{
|
|
683 |
LOGWAPPROT1("CWapDatagram::SetUTCOffset()");
|
|
684 |
|
|
685 |
TBool rc = ETrue;
|
|
686 |
TInt utcOffset = aUTCOffset.Int();
|
|
687 |
|
|
688 |
if ((utcOffset <= CSmsMessage::EMaximumSeconds) &&
|
|
689 |
(utcOffset >= -CSmsMessage::EMaximumSeconds))
|
|
690 |
{
|
|
691 |
iUTCOffset = utcOffset;
|
|
692 |
}
|
|
693 |
else
|
|
694 |
{
|
|
695 |
LOGWAPPROT2("CWapDatagram:SetUTCOffset offset [out of range] = %d",utcOffset);
|
|
696 |
rc = EFalse;
|
|
697 |
}
|
|
698 |
|
|
699 |
return rc;
|
|
700 |
} // CWapDatagram::SetUTCOffset
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
CBufFlat* CWapDatagram::SmsExternalisedStream() const
|
|
705 |
{
|
|
706 |
return iRecvbuf;
|
|
707 |
}
|