author | hgs |
Tue, 22 Jun 2010 11:02:32 +0100 | |
changeset 44 | 8b72faa1200f |
parent 0 | 3553901f7fa8 |
child 66 | 07a122eea281 |
permissions | -rw-r--r-- |
44 | 1 |
// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
// All rights reserved. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
// This component and the accompanying materials are made available |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
// under the terms of "Eclipse Public License v1.0" |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
// which accompanies this distribution, and is available |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
// |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
// Initial Contributors: |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
// Nokia Corporation - initial contribution. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
// |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
// Contributors: |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
// |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
// Description: |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
// This file contains the implementation of the TWapTextMessage. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
// TWapTextMessage encodes and decodes 7-bit WAP text headers |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
// |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
// |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
@file |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
|
44 | 23 |
|
24 |
#include "OstTraceDefinitions.h" |
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
26 |
#include "wapthdrTraces.h" |
|
27 |
#endif |
|
28 |
||
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
#include <e32std.h> |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
#include "wapthdr.h" |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
#include "ws_main.h" |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
const TInt TWapTextMessage::KHeaderCount = 6; |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
_LIT8(KSCKHeaderLong, "//SCKL"); // standard NBS header for 16-bit adresses |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
_LIT8(KSCKHeaderShort,"//SCK"); // standard NBS header for 8-bit adresses |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
* Indices into different types header for each of the header elements |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
* (dest port, source port, reference, total segments, current segment) |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
const TWapTextMessage::TIndexInfo TWapTextMessage::KElemIndexes[TWapTextMessage::KHeaderCount] = |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
{ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
// Long header ("//SCKL") indices |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
// destination port (, other header) |
44 | 47 |
{ 1,{ 6, 10, 0, 0, 0, 0} }, |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
// destination port, source port (, other header) |
44 | 49 |
{ 2,{ 6, 10, 14, 0, 0, 0} }, |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
// destination port, source port, |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
51 |
// reference, total segments, current segment(, other header) |
44 | 52 |
{ 5,{ 6, 10, 14, 16, 18, 20}}, |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
54 |
// Short header ("//SCK") indices |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
// destination port (, other header) |
44 | 56 |
{ 1, { 5, 7, 0, 0, 0, 0}}, |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
// destination port, source port (, other header) |
44 | 58 |
{ 2, { 5, 7, 9, 0, 0, 0}}, |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
// destination port, source port, |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
// reference, total segments, current segment(, other header) |
44 | 61 |
{ 5,{ 5, 7, 9, 11, 13, 15}}, |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
}; |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
* C'tor |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
* |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
* @param aWapMessage WAP message to decode/encode |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
* @note simply use KNullDesC8, if you are going to encode. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
71 |
TWapTextMessage::TWapTextMessage(const TDesC8& aWapMessage) |
44 | 72 |
:iIsWapTextMessage(EFalse) |
73 |
,iWAPMessage(aWapMessage) |
|
74 |
,iIs16Bit(EFalse) |
|
75 |
,iDestinationPort(-1) |
|
76 |
,iSourcePort(-1) |
|
77 |
,iReference(0) |
|
78 |
,iTotalSegments(0) |
|
79 |
,iSegmentNumber(0) |
|
80 |
,iOtherHeader(0) |
|
81 |
,iOtherHeaderLength(0) |
|
82 |
,iData(0) |
|
83 |
,iDataLength(0) |
|
84 |
,iRefOtherHeader(KNullDesC8) |
|
85 |
,iRefData(KNullDesC8) |
|
86 |
{ |
|
87 |
} // TWapTextMessage::TWapTextMessage |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
* Panic is raised, if the header with other header and terminating |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
* ' ' is > 159 characters. Then 1 byte is left for payload ! |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
* what will be the array element type ? |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
95 |
void TWapTextMessage::EncodeSegmentsL(CArrayPtr<HBufC8>& aSegmentArray) |
44 | 96 |
{ |
97 |
TBuf8<KMaxSmsChars> header; // buffer for a modifiable header |
|
98 |
TInt headerLength = 0; |
|
99 |
TInt segmentNumberIndex = 0; // index of segment number field in the header |
|
100 |
TBuf8<2> hexSegmentNumber; |
|
101 |
TInt dataSegmented = 0; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
102 |
|
44 | 103 |
OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_ENCODESEGMENTSL_1, "TWapTextMessage::EncodeSegmentsL()"); |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
104 |
|
44 | 105 |
iSegmentNumber = 0; |
106 |
do |
|
107 |
{ |
|
108 |
// |
|
109 |
// Create the segment and add it to the array... |
|
110 |
// |
|
111 |
HBufC8* segment = HBufC8::NewL(KMaxSmsChars); // 160 characters |
|
112 |
CleanupStack::PushL(segment); |
|
113 |
TPtr8 ptr(segment->Des()); |
|
114 |
aSegmentArray.AppendL(segment); |
|
115 |
CleanupStack::Pop(); // segment |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
116 |
|
44 | 117 |
// |
118 |
// Calculate length of header and copy it... |
|
119 |
// |
|
120 |
if (iSegmentNumber==0) |
|
121 |
{ |
|
122 |
headerLength = CreateHeader(header, segmentNumberIndex); |
|
123 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
124 |
|
44 | 125 |
ptr.Copy(header); |
126 |
if (iTotalSegments>255) |
|
127 |
{ |
|
128 |
User::Leave(KErrOverflow); |
|
129 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
130 |
|
44 | 131 |
// |
132 |
// Set segment number... |
|
133 |
// |
|
134 |
if (segmentNumberIndex != 0) |
|
135 |
{ |
|
136 |
hexSegmentNumber.NumFixedWidthUC(iSegmentNumber+1, EHex, 2); // two bytes wide |
|
137 |
ptr.Insert(segmentNumberIndex, hexSegmentNumber); |
|
138 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
139 |
|
44 | 140 |
// |
141 |
// Count any escaped characters we can be sure that the converted data |
|
142 |
// size fits inside the remaining length (e.g. so that non-7bit characters |
|
143 |
// when converted by the SMS Stack will still fit). |
|
144 |
// |
|
145 |
TInt segmentSize = iRefData.Length() - dataSegmented; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
146 |
|
44 | 147 |
if (segmentSize > KMaxSmsChars - headerLength) |
148 |
{ |
|
149 |
segmentSize = KMaxSmsChars - headerLength; |
|
150 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
151 |
|
44 | 152 |
while (segmentSize > 1) |
153 |
{ |
|
154 |
TPtrC8 segmentData(iRefData.Mid(dataSegmented, segmentSize)); |
|
155 |
TInt non7bitCharEscapes = 0; |
|
156 |
||
157 |
// |
|
158 |
// Count all non-7bit characters that will be escaped (many non-7bit |
|
159 |
// characters are not escaped, but converted to "?"). The ones |
|
160 |
// that are known to be escaped are list below: |
|
161 |
// |
|
162 |
// 12 [Form Feed]. |
|
163 |
// 91 "[" |
|
164 |
// 92 "\" |
|
165 |
// 93 "]" |
|
166 |
// 94 "^" |
|
167 |
// 123 "{" |
|
168 |
// 124 "|" |
|
169 |
// 125 "}" |
|
170 |
// 126 "~" |
|
171 |
// |
|
172 |
for (TInt ch = 0; ch < segmentSize; ch++) |
|
173 |
{ |
|
174 |
if (segmentData[ch] == 12 || |
|
175 |
(segmentData[ch] >= 91 && segmentData[ch] <= 94) || |
|
176 |
(segmentData[ch] >= 123 && segmentData[ch] <= 126)) |
|
177 |
{ |
|
178 |
non7bitCharEscapes++; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
// |
|
183 |
// Can it fit? If so store it, otherwise reduce the size... |
|
184 |
// |
|
185 |
if (segmentData.Length() + non7bitCharEscapes <= KMaxSmsChars - headerLength) |
|
186 |
{ |
|
187 |
ptr.Append(segmentData); |
|
188 |
break; |
|
189 |
} |
|
190 |
||
191 |
segmentSize--; |
|
192 |
} |
|
193 |
||
194 |
dataSegmented += segmentSize; |
|
195 |
iSegmentNumber++; |
|
196 |
} |
|
197 |
while (dataSegmented < iRefData.Length()); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
198 |
|
44 | 199 |
__ASSERT_DEBUG(iTotalSegments == aSegmentArray.Count(), Panic(KPanicEncodingError)); |
200 |
} // TWapTextMessage::EncodeSegmentsL |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
201 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
202 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
203 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
204 |
* Returns true, if the short message starts with |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
205 |
* WAP text message header set by SetWapTextMessage. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
206 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
207 |
TBool TWapTextMessage::Parse() |
44 | 208 |
{ |
209 |
TInt waplength = iWAPMessage.Length(); |
|
210 |
OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSE_1, "TWapTextMessage::Parse [%d bytes]", waplength); |
|
211 |
if(waplength != 0) |
|
212 |
{ |
|
213 |
// check whether long or short header |
|
214 |
TInt iBaseIndex = -1; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
215 |
|
44 | 216 |
// minimum length is 8 "//SCKxx " |
217 |
if(waplength >= 8) |
|
218 |
{ |
|
219 |
TPtrC8 HeaderIdPart(iWAPMessage.Left(6)); |
|
220 |
if(!HeaderIdPart.Compare(KSCKHeaderLong)) |
|
221 |
{ |
|
222 |
iBaseIndex = 0; |
|
223 |
iIs16Bit = ETrue; // Yes, the ports are 16 bit wide |
|
224 |
} |
|
225 |
else |
|
226 |
HeaderIdPart.Set(iWAPMessage.Left(5)); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
227 |
|
44 | 228 |
if(iBaseIndex == (-1) && !HeaderIdPart.Compare(KSCKHeaderShort) ) |
229 |
iBaseIndex = 3; |
|
230 |
// else no match |
|
231 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
232 |
|
44 | 233 |
if(iBaseIndex >= 0) |
234 |
{ |
|
235 |
// check which of the TIndexInfos match |
|
236 |
for(TInt i=iBaseIndex; i<iBaseIndex+3; i++) |
|
237 |
{ |
|
238 |
// Get length (index) of text header variant |
|
239 |
TInt lastIndex = KElemIndexes[i].iIndexes[KElemIndexes[i].iLastIndex]; |
|
240 |
if (iWAPMessage.Length() <= lastIndex) |
|
241 |
{ |
|
242 |
// no hope about match, because other variants are longer |
|
243 |
iIsWapTextMessage = EFalse; |
|
244 |
break; |
|
245 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
246 |
|
44 | 247 |
TInt LastChar = iWAPMessage[lastIndex]; |
248 |
if (LastChar == '/' || LastChar == ' ' || LastChar == '\n') |
|
249 |
{ |
|
250 |
// reinitialize, because following maybe absent |
|
251 |
iTotalSegments = 1; |
|
252 |
iSegmentNumber = 1; |
|
253 |
iIsWapTextMessage = ParseWapTextHeader(KElemIndexes[i]); |
|
254 |
break; |
|
255 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
256 |
|
44 | 257 |
} |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
258 |
|
44 | 259 |
if (!iIsWapTextMessage) |
260 |
{ |
|
261 |
OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSE_2, "WARNING! illegal incoming WAP message"); |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
265 |
|
44 | 266 |
return iIsWapTextMessage; |
267 |
} // TWapTextMessage::Parse |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
268 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
269 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
270 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
271 |
* Parses a string of hex characters representing a number |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
272 |
* |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
273 |
* @param aInValue descriptor containing the number |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
274 |
* @param aBigEndian true if number is big endian |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
275 |
* @param aRadix Radixbase; 16, 10 etc |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
276 |
* @return TInt the parsed number |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
277 |
* @leave Panics with KPanicInvalidParseNumber error code, if not a |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
278 |
* number. Maximum width of the hex value can be 4. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
279 |
* |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
280 |
* TODO use TLex instead |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
281 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
282 |
TInt TWapTextMessage::ParseNumber(const TDesC8& aInValue, |
44 | 283 |
TBool aBigEndian, |
284 |
TInt aRadix) |
|
285 |
{ |
|
286 |
OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSENUMBER_1, "TWapTextMessage::ParseNumber [%s]", aInValue); |
|
287 |
// least significant byte first |
|
288 |
TInt Values[4] = {0,0,0,0}; |
|
289 |
TInt Temp = 0; |
|
290 |
TInt length = aInValue.Length(); |
|
291 |
TInt i = 0; |
|
292 |
TInt Value = 0; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
293 |
|
44 | 294 |
__ASSERT_DEBUG(length<5,Panic(KPanicInvalidParseNumber)); |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
295 |
if( length >= 5 ) |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
296 |
return KErrNotFound; |
44 | 297 |
for(i=0; i<length; i++) |
298 |
{ |
|
299 |
Temp = aInValue[i]; |
|
300 |
if (Temp>='0' && Temp<='9') |
|
301 |
Temp-='0'; |
|
302 |
else if (Temp>='A' && Temp<='Z') |
|
303 |
Temp = Temp - 'A'+10; |
|
304 |
else if (Temp>='a' && Temp<='z') |
|
305 |
Temp = Temp - 'a'+10; |
|
306 |
else |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
307 |
return KErrNotFound; |
44 | 308 |
if (aBigEndian) |
309 |
Values[(length-1)-i]=Temp; |
|
310 |
else |
|
311 |
Values[i]=Temp; |
|
312 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
313 |
|
44 | 314 |
// build the value |
315 |
Value=Values[0]; |
|
316 |
TInt Base=1; |
|
317 |
for(i=1; i<length; i++) |
|
318 |
{ |
|
319 |
Base*=aRadix; |
|
320 |
Value+=(Base)*Values[i]; |
|
321 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
322 |
|
44 | 323 |
return Value; |
324 |
} // TWapTextMessage::ParseNumber |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
325 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
326 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
327 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
328 |
* parse the WAP text header |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
329 |
* |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
330 |
* use ElemIndexes to retrieve the index |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
331 |
* an starting position of an element in iWapMessage |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
332 |
* Length of element is calculated by |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
333 |
* subtracting current index value from the next one |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
334 |
* except for KOtherHeader and user data, of course |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
335 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
336 |
TBool TWapTextMessage::ParseWapTextHeader(const TIndexInfo& aIndexArray) |
44 | 337 |
{ |
338 |
OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSEWAPTEXTHEADER_1, "TWapTextMessage::ParseWapTextHeader: %s", iWAPMessage ); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
339 |
|
44 | 340 |
TInt ParsedNumber = 0; |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
341 |
|
44 | 342 |
// parse the header |
343 |
TInt ElemIndexCount=aIndexArray.iLastIndex+1; |
|
344 |
for(TInt i=0; i<ElemIndexCount; i++) |
|
345 |
{ |
|
346 |
if (i<ElemIndexCount-1) |
|
347 |
{ |
|
348 |
// all the elems have a length defined in advance |
|
349 |
if (iWAPMessage.Length() >= aIndexArray.iIndexes[i+1]) |
|
350 |
{ |
|
351 |
// the header fits into the wap datagram |
|
352 |
TPtrC8 Elem(iWAPMessage.Mid(aIndexArray.iIndexes[i], |
|
353 |
aIndexArray.iIndexes[i+1]- |
|
354 |
aIndexArray.iIndexes[i])); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
355 |
|
44 | 356 |
ParsedNumber = ParseNumber(Elem,ETrue,16); |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
357 |
if( ParsedNumber == KErrNotFound ) |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
358 |
return EFalse; |
44 | 359 |
switch(i) |
360 |
{ |
|
361 |
case KIndexDestinationPort: |
|
362 |
iDestinationPort = ParsedNumber; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
363 |
|
44 | 364 |
break; |
365 |
case KIndexSourcePort: |
|
366 |
iSourcePort = ParsedNumber; |
|
367 |
break; |
|
368 |
case KIndexReferenceNumber: |
|
369 |
iReference = ParsedNumber; |
|
370 |
break; |
|
371 |
case KIndexTotalSegments: |
|
372 |
iTotalSegments = ParsedNumber; |
|
373 |
break; |
|
374 |
case KIndexSegmentNumber: |
|
375 |
iSegmentNumber = ParsedNumber; |
|
376 |
break; |
|
377 |
default: |
|
378 |
OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSEWAPTEXTHEADER_2, "Hm. unhandled WAP index [%d]", i ); |
|
379 |
break; |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
else |
|
384 |
{ |
|
385 |
// elems have not a length defined in advance |
|
386 |
iOtherHeader = 0; |
|
387 |
iOtherHeaderLength = 0; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
388 |
|
44 | 389 |
// Search the terminating character ' ' |
390 |
iData = iWAPMessage.Locate(' '); |
|
391 |
TInt dataTmp = iWAPMessage.Locate('\n'); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
392 |
|
44 | 393 |
if (iData == KErrNotFound) |
394 |
{ |
|
395 |
if (dataTmp == KErrNotFound) |
|
396 |
return EFalse; |
|
397 |
else |
|
398 |
iData = dataTmp; |
|
399 |
} |
|
400 |
else if (dataTmp != KErrNotFound) |
|
401 |
iData = Min(iData, dataTmp); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
402 |
|
44 | 403 |
// check the existence of other header |
404 |
// at least "// " should be there |
|
405 |
if ( iWAPMessage.Length() > aIndexArray.iIndexes[i]+2 |
|
406 |
&& iWAPMessage[aIndexArray.iIndexes[i]] == '/' |
|
407 |
&& iWAPMessage[aIndexArray.iIndexes[i]+1] == '/') |
|
408 |
{ |
|
409 |
iOtherHeader = aIndexArray.iIndexes[i]; |
|
410 |
iOtherHeaderLength=iData-iOtherHeader; |
|
411 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
412 |
|
44 | 413 |
// data: check if any characters after ' ' |
414 |
iDataLength = 0; |
|
415 |
iData++; |
|
416 |
if (iWAPMessage.Length() > iData) |
|
417 |
{ |
|
418 |
iDataLength = iWAPMessage.Length() - iData; |
|
419 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
420 |
|
44 | 421 |
// That's it |
422 |
} // end of other header and data |
|
423 |
}// end of for loop |
|
424 |
return ETrue; |
|
425 |
} // TWapTextMessage::ParseWapTextHeader |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
426 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
427 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
428 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
429 |
* Length of header is returned |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
430 |
* Sets internally the iTotalSegments |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
431 |
* Does not set the segment number into the aFixedHeader |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
432 |
* |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
433 |
* Length of complete header is returned. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
434 |
* On return the header is not complete, if SAR is needed, because the segment |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
435 |
* number is not set. Thus aFixedHeader.Length() != (return value of this function) is true. |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
436 |
* The segment number can be set by inserting it into aSegmentNumberIndex position |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
437 |
* If SAR is not needed aSegmentNumberIndex = 0 and |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
438 |
* aFixedHeader.Length() == (return value of this function) is true |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
439 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
440 |
TInt TWapTextMessage::CreateHeader(TDes8& aFixedHeader, TInt& aSegmentNumberIndex) |
44 | 441 |
{ |
442 |
OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_CREATEHEADER_1, "TWapTextMessage::CreateHeader"); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
443 |
|
44 | 444 |
// Index into KElemIndexes indicating which header elements are present |
445 |
TInt elemIndex; |
|
446 |
// Index into Indexes, for current header element |
|
447 |
TInt minorIndex=KIndexDestinationPort; |
|
448 |
TBuf8<4> hexNumber; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
449 |
|
44 | 450 |
// Segment number length is set, if SAR is needed |
451 |
TInt segmentNumberLength = 0; |
|
452 |
aSegmentNumberIndex = 0; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
453 |
|
44 | 454 |
// Determine whether long or short form is used |
455 |
if (iIs16Bit || iSourcePort > 255 || iDestinationPort>255) |
|
456 |
{ |
|
457 |
elemIndex = 0; |
|
458 |
aFixedHeader.Copy(KSCKHeaderLong); |
|
459 |
} |
|
460 |
else |
|
461 |
{ |
|
462 |
elemIndex = 3; |
|
463 |
aFixedHeader.Copy(KSCKHeaderShort); |
|
464 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
465 |
|
44 | 466 |
// Set destination port |
467 |
hexNumber.NumFixedWidthUC(iDestinationPort,EHex, |
|
468 |
KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]); |
|
469 |
aFixedHeader.Append(hexNumber); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
470 |
|
44 | 471 |
// Don't set the source port, |
472 |
// 1) if it is not set or it same as destination port and |
|
473 |
// 2) data (and other header) fits in one segment |
|
474 |
if (!((iSourcePort==-1 || iDestinationPort==iSourcePort) |
|
475 |
&& CalculateTotalSegments(KElemIndexes[elemIndex].iIndexes[minorIndex+1])==1)) |
|
476 |
{ |
|
477 |
// Source port is present |
|
478 |
elemIndex++; |
|
479 |
minorIndex++; |
|
480 |
if (iSourcePort==-1) |
|
481 |
iSourcePort = iDestinationPort; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
482 |
|
44 | 483 |
// Set source port |
484 |
hexNumber.NumFixedWidthUC(iSourcePort,EHex, |
|
485 |
KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]); |
|
486 |
aFixedHeader.Append(hexNumber); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
487 |
|
44 | 488 |
// Add the SAR info when source port is set |
489 |
elemIndex++; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
490 |
|
44 | 491 |
// Set reference |
492 |
minorIndex++; |
|
493 |
hexNumber.NumFixedWidthUC(iReference,EHex, |
|
494 |
KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]); |
|
495 |
aFixedHeader.Append(hexNumber); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
496 |
|
44 | 497 |
// Set fragment count |
498 |
minorIndex++; |
|
499 |
CalculateTotalSegments(KElemIndexes[elemIndex].iIndexes[KElemIndexes[elemIndex].iLastIndex]); |
|
500 |
hexNumber.NumFixedWidthUC(iTotalSegments,EHex, |
|
501 |
KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]); |
|
502 |
aFixedHeader.Append(hexNumber); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
503 |
|
44 | 504 |
// Return the index for segment number in the header |
505 |
minorIndex++; |
|
506 |
aSegmentNumberIndex = KElemIndexes[elemIndex].iIndexes[minorIndex]; |
|
507 |
segmentNumberLength = 2; |
|
508 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
509 |
|
44 | 510 |
aFixedHeader.Append(iRefOtherHeader); |
511 |
aFixedHeader.Append(_L(" ")); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
512 |
|
44 | 513 |
return aFixedHeader.Length()+segmentNumberLength; |
514 |
} // TWapTextMessage::CreateHeader |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
515 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
516 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
517 |
/** |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
518 |
* Calculates count of segments to send a used data (based on iRefData) |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
519 |
* The values is assigned to iTotalSegments |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
520 |
* The affect of terminating ' ' is taken into inside the method |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
521 |
*/ |
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
522 |
TInt TWapTextMessage::CalculateTotalSegments(TInt aFixedLength) |
44 | 523 |
{ |
524 |
OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_CALCULATETOTALSEGMENTS_1, "TWapTextMessage::CalculateTotalSegments [aFixedLength=%d]", aFixedLength); |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
525 |
|
44 | 526 |
// '+1': length of terminating ' ' |
527 |
TInt length = aFixedLength + iRefOtherHeader.Length() + 1; |
|
528 |
TInt remain = KMaxSmsChars - length; |
|
529 |
TInt dataSegmented = 0; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
530 |
|
44 | 531 |
__ASSERT_DEBUG(remain > 0, Panic(KPanicTextHeaderTooLong)); |
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
532 |
|
44 | 533 |
iTotalSegments = 0; |
534 |
do |
|
535 |
{ |
|
536 |
iTotalSegments++; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
537 |
|
44 | 538 |
// |
539 |
// Count any escaped characters we can be sure that the converted data |
|
540 |
// size fits inside the remaining length (e.g. so that non-7bit characters |
|
541 |
// when converted by the SMS Stack will still fit). |
|
542 |
// |
|
543 |
TInt segmentSize = iRefData.Length() - dataSegmented; |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
544 |
|
44 | 545 |
if (segmentSize > remain) |
546 |
{ |
|
547 |
segmentSize = remain; |
|
548 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
549 |
|
44 | 550 |
while (segmentSize > 1) |
551 |
{ |
|
552 |
TPtrC8 segmentData(iRefData.Mid(dataSegmented, segmentSize)); |
|
553 |
TInt non7bitCharEscapes = 0; |
|
554 |
||
555 |
// |
|
556 |
// Count all non-7bit characters that will be escaped (many non-7bit |
|
557 |
// characters are not escaped, but converted to "?"). The ones |
|
558 |
// that are known to be escaped are list below: |
|
559 |
// |
|
560 |
// 12 [Form Feed]. |
|
561 |
// 91 "[" |
|
562 |
// 92 "\" |
|
563 |
// 93 "]" |
|
564 |
// 94 "^" |
|
565 |
// 123 "{" |
|
566 |
// 124 "|" |
|
567 |
// 125 "}" |
|
568 |
// 126 "~" |
|
569 |
// |
|
570 |
for (TInt ch = 0; ch < segmentSize; ch++) |
|
571 |
{ |
|
572 |
if (segmentData[ch] == 12 || |
|
573 |
(segmentData[ch] >= 91 && segmentData[ch] <= 94) || |
|
574 |
(segmentData[ch] >= 123 && segmentData[ch] <= 126)) |
|
575 |
{ |
|
576 |
non7bitCharEscapes++; |
|
577 |
} |
|
578 |
} |
|
579 |
||
580 |
// |
|
581 |
// Can it fit? If so store it, otherwise reduce the size... |
|
582 |
// |
|
583 |
if (segmentData.Length() + non7bitCharEscapes <= remain) |
|
584 |
{ |
|
585 |
break; |
|
586 |
} |
|
587 |
||
588 |
segmentSize--; |
|
589 |
} |
|
590 |
||
591 |
dataSegmented += segmentSize; |
|
592 |
} |
|
593 |
while (dataSegmented < iRefData.Length()); |
|
594 |
||
595 |
// |
|
596 |
// At least one fragment is needed... |
|
597 |
// |
|
598 |
if (iTotalSegments == 0) |
|
599 |
{ |
|
600 |
iTotalSegments = 1; |
|
601 |
} |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
602 |
|
44 | 603 |
return iTotalSegments; |
604 |
} // TWapTextMessage::CalculateTotalSegments |
|
0
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
605 |
|
3553901f7fa8
Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
606 |
// EOF - WAPTHDR.CPP |