smsprotocols/smsstack/wapprot/Src/wapthdr.cpp
author hgs
Tue, 22 Jun 2010 11:02:32 +0100
changeset 44 8b72faa1200f
parent 0 3553901f7fa8
child 66 07a122eea281
permissions -rw-r--r--
201024_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
     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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    23
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    24
#include "OstTraceDefinitions.h"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    25
#ifdef OST_TRACE_COMPILER_IN_USE
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    26
#include "wapthdrTraces.h"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    27
#endif
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    72
    :iIsWapTextMessage(EFalse)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    73
    ,iWAPMessage(aWapMessage)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    74
    ,iIs16Bit(EFalse)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    75
    ,iDestinationPort(-1)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    76
    ,iSourcePort(-1)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    77
    ,iReference(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    78
    ,iTotalSegments(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    79
    ,iSegmentNumber(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    80
    ,iOtherHeader(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    81
    ,iOtherHeaderLength(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    82
    ,iData(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    83
    ,iDataLength(0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    84
    ,iRefOtherHeader(KNullDesC8)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    85
    ,iRefData(KNullDesC8)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    86
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    96
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    97
    TBuf8<KMaxSmsChars>  header;        // buffer for a modifiable header
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    98
    TInt        headerLength = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
    99
    TInt        segmentNumberIndex = 0; // index of segment number field in the header
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   100
    TBuf8<2>    hexSegmentNumber;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   101
    TInt        dataSegmented = 0;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   105
    iSegmentNumber = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   106
    do
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   107
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   108
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   109
        // Create the segment and add it to the array...
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   110
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   111
        HBufC8*  segment = HBufC8::NewL(KMaxSmsChars); // 160 characters
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   112
        CleanupStack::PushL(segment);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   113
        TPtr8  ptr(segment->Des());
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   114
        aSegmentArray.AppendL(segment);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   115
        CleanupStack::Pop(); // segment
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   116
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   117
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   118
        // Calculate length of header and copy it...
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   119
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   120
        if (iSegmentNumber==0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   121
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   122
            headerLength = CreateHeader(header, segmentNumberIndex);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   123
            }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   125
        ptr.Copy(header);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   126
        if (iTotalSegments>255)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   127
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   128
            User::Leave(KErrOverflow);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   129
            }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   131
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   132
        // Set segment number...
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   133
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   134
        if (segmentNumberIndex != 0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   135
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   136
            hexSegmentNumber.NumFixedWidthUC(iSegmentNumber+1, EHex, 2); // two bytes wide
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   137
            ptr.Insert(segmentNumberIndex, hexSegmentNumber);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   138
            }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   140
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   141
        // Count any escaped characters we can be sure that the converted data
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   142
        // size fits inside the remaining length (e.g. so that non-7bit characters
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   143
        // when converted by the SMS Stack will still fit).
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   144
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   147
        if (segmentSize > KMaxSmsChars - headerLength)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   148
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   149
            segmentSize = KMaxSmsChars - headerLength;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   150
            }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   152
        while (segmentSize > 1)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   153
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   154
            TPtrC8  segmentData(iRefData.Mid(dataSegmented, segmentSize));
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   155
            TInt  non7bitCharEscapes = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   156
            
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   157
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   158
            // Count all non-7bit characters that will be escaped (many non-7bit
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   159
            // characters are not escaped, but converted to "?"). The ones
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   160
            // that are known to be escaped are list below:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   161
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   162
            //    12  [Form Feed].
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   163
            //    91  "["
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   164
            //    92  "\"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   165
            //    93  "]"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   166
            //    94  "^"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   167
            //   123  "{"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   168
            //   124  "|"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   169
            //   125  "}"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   170
            //   126  "~"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   171
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   172
            for (TInt  ch = 0;  ch < segmentSize;  ch++)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   173
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   174
                if (segmentData[ch] == 12  ||
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   175
                    (segmentData[ch] >= 91  &&  segmentData[ch] <= 94)  ||
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   176
                    (segmentData[ch] >= 123  &&  segmentData[ch] <= 126))
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   177
                    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   178
                    non7bitCharEscapes++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   179
                    }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   180
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   181
            
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   182
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   183
            // Can it fit? If so store it, otherwise reduce the size...
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   184
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   185
            if (segmentData.Length() + non7bitCharEscapes <= KMaxSmsChars - headerLength)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   186
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   187
                ptr.Append(segmentData);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   188
                break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   189
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   190
            
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   191
            segmentSize--;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   192
            }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   193
        
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   194
            dataSegmented += segmentSize;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   195
            iSegmentNumber++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   196
        }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   197
    while (dataSegmented < iRefData.Length());
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   199
    __ASSERT_DEBUG(iTotalSegments == aSegmentArray.Count(), Panic(KPanicEncodingError));
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   208
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   209
    TInt waplength = iWAPMessage.Length();
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   210
    OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSE_1, "TWapTextMessage::Parse [%d bytes]", waplength);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   211
    if(waplength != 0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   212
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   213
        // check whether long or short header
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   214
        TInt iBaseIndex = -1;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   216
        // minimum length is 8 "//SCKxx "
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   217
        if(waplength >= 8)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   218
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   219
            TPtrC8 HeaderIdPart(iWAPMessage.Left(6));
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   220
            if(!HeaderIdPart.Compare(KSCKHeaderLong))
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   221
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   222
                iBaseIndex = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   223
                iIs16Bit = ETrue; // Yes, the ports are 16 bit wide
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   224
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   225
            else
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   228
            if(iBaseIndex == (-1) && !HeaderIdPart.Compare(KSCKHeaderShort) )
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   229
                iBaseIndex = 3;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   230
            // else  no match
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   231
            }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   233
        if(iBaseIndex >= 0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   234
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   235
            // check which of the TIndexInfos match
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   236
            for(TInt i=iBaseIndex; i<iBaseIndex+3; i++)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   237
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   238
                // Get length (index) of text header variant
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   239
                TInt lastIndex = KElemIndexes[i].iIndexes[KElemIndexes[i].iLastIndex];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   240
                if (iWAPMessage.Length() <= lastIndex)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   241
                    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   242
                    // no hope about match, because other variants are longer
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   243
                    iIsWapTextMessage = EFalse;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   244
                    break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   245
                    }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   246
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   247
                TInt LastChar = iWAPMessage[lastIndex];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   248
                if (LastChar == '/' || LastChar == ' ' || LastChar == '\n')
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   249
                    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   250
                    // reinitialize, because following maybe absent
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   251
                    iTotalSegments = 1;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   252
                    iSegmentNumber = 1;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   253
                    iIsWapTextMessage = ParseWapTextHeader(KElemIndexes[i]);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   254
                    break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   255
                    }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   256
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   257
                }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   258
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   259
            if (!iIsWapTextMessage)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   260
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   261
                OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSE_2, "WARNING! illegal incoming WAP message");
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   262
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   263
            }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   264
        }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   265
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   266
    return iIsWapTextMessage;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   283
                                  TBool   aBigEndian,
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   284
                                  TInt    aRadix)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   285
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   286
    OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSENUMBER_1, "TWapTextMessage::ParseNumber [%s]", aInValue);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   287
    // least significant byte first
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   288
    TInt Values[4] = {0,0,0,0};
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   289
    TInt Temp = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   290
    TInt length = aInValue.Length();
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   291
    TInt i = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   292
    TInt Value = 0;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   293
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   297
    for(i=0; i<length; i++)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   298
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   299
        Temp = aInValue[i];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   300
        if (Temp>='0' && Temp<='9')
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   301
            Temp-='0';
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   302
        else if (Temp>='A' && Temp<='Z')
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   303
            Temp = Temp - 'A'+10;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   304
        else if (Temp>='a' && Temp<='z')
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   305
            Temp = Temp - 'a'+10;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   306
        else
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   307
            return KErrNotFound;
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   308
        if (aBigEndian)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   309
            Values[(length-1)-i]=Temp;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   310
        else
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   311
            Values[i]=Temp;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   312
        }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   314
    // build the value
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   315
    Value=Values[0];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   316
    TInt Base=1;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   317
    for(i=1; i<length; i++)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   318
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   319
        Base*=aRadix;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   320
        Value+=(Base)*Values[i];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   321
        }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   322
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   323
    return Value;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   337
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   340
    TInt ParsedNumber = 0;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   342
    // parse the header
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   343
    TInt ElemIndexCount=aIndexArray.iLastIndex+1;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   344
    for(TInt i=0; i<ElemIndexCount; i++)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   345
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   346
        if (i<ElemIndexCount-1)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   347
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   348
            // all the elems have a length defined in advance
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   349
            if (iWAPMessage.Length() >= aIndexArray.iIndexes[i+1])
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   350
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   351
                // the header fits into the wap datagram
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   352
                TPtrC8 Elem(iWAPMessage.Mid(aIndexArray.iIndexes[i],
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   353
                                            aIndexArray.iIndexes[i+1]-
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   354
                                            aIndexArray.iIndexes[i]));
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   355
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   359
                switch(i)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   360
                    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   361
                  case KIndexDestinationPort:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   362
                      iDestinationPort = ParsedNumber;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   363
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   364
                      break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   365
                  case KIndexSourcePort:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   366
                      iSourcePort = ParsedNumber;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   367
                      break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   368
                  case KIndexReferenceNumber:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   369
                      iReference = ParsedNumber;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   370
                      break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   371
                  case KIndexTotalSegments:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   372
                      iTotalSegments = ParsedNumber;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   373
                      break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   374
                  case KIndexSegmentNumber:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   375
                      iSegmentNumber = ParsedNumber;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   376
                      break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   377
                  default:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   378
                      OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSEWAPTEXTHEADER_2, "Hm. unhandled WAP index [%d]", i );
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   379
                      break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   380
                    }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   381
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   382
            }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   383
        else
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   384
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   385
            // elems have not a length defined in advance
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   386
            iOtherHeader = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   387
            iOtherHeaderLength = 0;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   388
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   389
            // Search the terminating character ' '
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   390
            iData = iWAPMessage.Locate(' ');
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   393
            if (iData == KErrNotFound)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   394
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   395
                if (dataTmp == KErrNotFound)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   396
                    return EFalse;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   397
                else
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   398
                    iData = dataTmp;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   399
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   400
            else if (dataTmp != KErrNotFound)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   401
                iData = Min(iData, dataTmp);
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   402
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   403
            // check the existence of other header
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   404
            // at least "// " should be there
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   405
            if (   iWAPMessage.Length() > aIndexArray.iIndexes[i]+2
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   406
                   && iWAPMessage[aIndexArray.iIndexes[i]] == '/'
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   407
                   && iWAPMessage[aIndexArray.iIndexes[i]+1] == '/')
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   408
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   409
                iOtherHeader = aIndexArray.iIndexes[i];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   410
                iOtherHeaderLength=iData-iOtherHeader;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   411
                }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   412
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   413
            // data: check if any characters after ' '
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   414
            iDataLength = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   415
            iData++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   416
            if (iWAPMessage.Length() > iData)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   417
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   418
                iDataLength = iWAPMessage.Length() - iData;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   419
                }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   420
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   421
            // That's it
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   422
            } // end of other header and data
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   423
        }// end of for loop
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   424
    return ETrue;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   441
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   444
    // Index into KElemIndexes indicating which header elements are present
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   445
    TInt elemIndex;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   446
    // Index into Indexes, for current header element
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   447
    TInt minorIndex=KIndexDestinationPort;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   448
    TBuf8<4> hexNumber;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   449
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   450
    // Segment number length is set, if SAR is needed
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   451
    TInt segmentNumberLength = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   452
    aSegmentNumberIndex = 0;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   453
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   454
    // Determine whether long or short form is used
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   455
    if (iIs16Bit || iSourcePort > 255 || iDestinationPort>255)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   456
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   457
        elemIndex = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   458
        aFixedHeader.Copy(KSCKHeaderLong);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   459
        }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   460
    else
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   461
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   462
        elemIndex = 3;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   463
        aFixedHeader.Copy(KSCKHeaderShort);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   464
        }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   465
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   466
    // Set destination port
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   467
    hexNumber.NumFixedWidthUC(iDestinationPort,EHex,
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   468
                              KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   469
    aFixedHeader.Append(hexNumber);
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   470
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   471
    // Don't set the source port,
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   472
    // 1) if it is not set or it same as destination port and
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   473
    // 2) data (and other header) fits in one segment
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   474
    if (!((iSourcePort==-1 || iDestinationPort==iSourcePort)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   475
          && CalculateTotalSegments(KElemIndexes[elemIndex].iIndexes[minorIndex+1])==1))
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   476
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   477
        // Source port is present
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   478
        elemIndex++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   479
        minorIndex++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   480
        if (iSourcePort==-1)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   481
            iSourcePort = iDestinationPort;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   482
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   483
        // Set source port
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   484
        hexNumber.NumFixedWidthUC(iSourcePort,EHex,
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   485
                                  KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   486
        aFixedHeader.Append(hexNumber);
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   487
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   488
        // Add the SAR info when source port is set
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   489
        elemIndex++;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   490
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   491
        // Set reference
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   492
        minorIndex++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   493
        hexNumber.NumFixedWidthUC(iReference,EHex,
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   494
                                  KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   495
        aFixedHeader.Append(hexNumber);
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   496
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   497
        // Set fragment count
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   498
        minorIndex++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   499
        CalculateTotalSegments(KElemIndexes[elemIndex].iIndexes[KElemIndexes[elemIndex].iLastIndex]);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   500
        hexNumber.NumFixedWidthUC(iTotalSegments,EHex,
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   501
                                  KElemIndexes[elemIndex].iIndexes[minorIndex+1]-KElemIndexes[elemIndex].iIndexes[minorIndex]);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   502
        aFixedHeader.Append(hexNumber);
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   503
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   504
        // Return the index for segment number in the header
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   505
        minorIndex++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   506
        aSegmentNumberIndex = KElemIndexes[elemIndex].iIndexes[minorIndex];
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   507
        segmentNumberLength = 2;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   508
        }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   509
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   510
    aFixedHeader.Append(iRefOtherHeader);
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   511
    aFixedHeader.Append(_L(" "));
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   512
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   513
    return aFixedHeader.Length()+segmentNumberLength;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   523
    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   526
    // '+1': length of terminating ' '
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   527
    TInt  length        = aFixedLength + iRefOtherHeader.Length() + 1;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   528
    TInt  remain        = KMaxSmsChars - length;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   529
    TInt  dataSegmented = 0;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   530
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   533
    iTotalSegments = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   534
    do
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   535
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   536
        iTotalSegments++;
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   537
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   538
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   539
        // Count any escaped characters we can be sure that the converted data
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   540
        // size fits inside the remaining length (e.g. so that non-7bit characters
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   541
        // when converted by the SMS Stack will still fit).
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   542
        //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   545
        if (segmentSize > remain)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   546
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   547
            segmentSize = remain;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   548
            }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   549
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   550
        while (segmentSize > 1)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   551
            {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   552
            TPtrC8  segmentData(iRefData.Mid(dataSegmented, segmentSize));
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   553
            TInt  non7bitCharEscapes = 0;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   554
            
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   555
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   556
            // Count all non-7bit characters that will be escaped (many non-7bit
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   557
            // characters are not escaped, but converted to "?"). The ones
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   558
            // that are known to be escaped are list below:
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   559
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   560
            //    12  [Form Feed].
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   561
            //    91  "["
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   562
            //    92  "\"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   563
            //    93  "]"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   564
            //    94  "^"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   565
            //   123  "{"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   566
            //   124  "|"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   567
            //   125  "}"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   568
            //   126  "~"
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   569
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   570
            for (TInt  ch = 0;  ch < segmentSize;  ch++)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   571
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   572
                if (segmentData[ch] == 12  ||
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   573
                    (segmentData[ch] >= 91  &&  segmentData[ch] <= 94)  ||
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   574
                    (segmentData[ch] >= 123  &&  segmentData[ch] <= 126))
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   575
                    {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   576
                    non7bitCharEscapes++;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   577
                    }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   578
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   579
            
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   580
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   581
            // Can it fit? If so store it, otherwise reduce the size...
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   582
            //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   583
            if (segmentData.Length() + non7bitCharEscapes <= remain)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   584
                {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   585
                break;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   586
                }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   587
            
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   588
            segmentSize--;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   589
            }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   590
        
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   591
            dataSegmented += segmentSize;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   592
        }
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   593
    while (dataSegmented < iRefData.Length());
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   594
    
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   595
    //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   596
    // At least one fragment is needed...
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   597
    //
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   598
    if (iTotalSegments == 0)
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   599
        {
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   600
        iTotalSegments = 1;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   601
        }
0
3553901f7fa8 Revision: 201005
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   602
44
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   603
    return iTotalSegments;
8b72faa1200f 201024_02
hgs
parents: 0
diff changeset
   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