convergedcallengine/csplugin/src/tcspskypeidparser.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Parses Skype id from UUI message.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tcspskypeidparser.h"
       
    20 
       
    21 const TInt KMinSkypeIdUUILength = 3;
       
    22 const TInt KMaxSkypeIdUUILength = 33;
       
    23 const TInt KMaxSkypeIdLength = 32;
       
    24 const TInt KStartOf31To32EncodingByte = 26;
       
    25 const TInt KUUIMTDicriminator = 0x44;
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Constructor
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 TCSPSkypeIdParser::TCSPSkypeIdParser() 
       
    34     {
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Creates buffer to be used by client with parse method.
       
    39 // ---------------------------------------------------------------------------
       
    40 //  
       
    41 HBufC* TCSPSkypeIdParser::CreateSkypeIdBufferL()
       
    42     {
       
    43     return HBufC::NewL( KMaxSkypeIdLength );
       
    44     }
       
    45     
       
    46 // ---------------------------------------------------------------------------
       
    47 // Parses skype id.
       
    48 // SkypeID format:
       
    49 // byte 0: Protocol discriminator: Always 0x00
       
    50 // byte 1: User-User Information Discriminator.
       
    51 //         For MT call this has to be 0x44
       
    52 // Byte 2: First skype id character a.k.a payload. MSB bit is zero.
       
    53 // Byte 26-33 May have MSB bit set, which are bits of the last character.
       
    54 // The 26 byte's MSB is the last characters MSB bit.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TInt TCSPSkypeIdParser::Parse( 
       
    58     const TDesC& aUUIMessage, 
       
    59     TDes& aSkypeId )
       
    60     {
       
    61     const TInt messageLength( aUUIMessage.Length() );
       
    62     TInt error = KErrNone;
       
    63     
       
    64     const TBool messageSizeOk = (messageLength >= KMinSkypeIdUUILength &&
       
    65     							 messageLength <= KMaxSkypeIdUUILength);
       
    66     							 
       
    67     if( messageSizeOk &&
       
    68        ( aUUIMessage[1] ) == KUUIMTDicriminator ) // address type
       
    69         {
       
    70         
       
    71         TUint lastChar = 0;
       
    72         
       
    73         // skypeId payload starts from the second byte.
       
    74         TInt i = 2;
       
    75         for( ; i < messageLength; i++ )
       
    76             {
       
    77             TUint byte = aUUIMessage[i];
       
    78             if( i >= KStartOf31To32EncodingByte )
       
    79                 {
       
    80                 // 31 to 32 encoding: last character is build from
       
    81                 // 7 last bytes.
       
    82                 lastChar = lastChar << 1;
       
    83                 lastChar |= (byte>>7)&0x01;
       
    84                 }
       
    85             // MSB bit is not part of the character.
       
    86             aSkypeId.Append( byte & 0x7F ); 
       
    87                 
       
    88             
       
    89             }
       
    90             
       
    91         // Append the last char only if the aUUIMessage size was the maximum and there
       
    92         // is content in the last char.
       
    93         if( messageLength == KMaxSkypeIdUUILength && lastChar != 0 )
       
    94             {
       
    95             aSkypeId.Append(lastChar);
       
    96             }
       
    97 
       
    98         }
       
    99     else
       
   100         {
       
   101         error = KErrNotSupported;
       
   102         }
       
   103         
       
   104     return error;
       
   105     }