phoneengine/PhoneCntFinder/ContactService/src/tphcntsipuri.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2006 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:  SIP URI descriptor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tphcntsipuri.h"
       
    20 
       
    21 const TInt KSipPrefixLength = 4;
       
    22 _LIT( KPhCntSipUriAt, "@" );
       
    23 _LIT( KPhCntSipPrefix, "sip:" );
       
    24 _LIT( KPhCntSipUriSeparatorBegin, "<" );
       
    25 _LIT( KPhCntSipUriSeparatorEnd, ">" );
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Constructor
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 TPhCntSipURI::TPhCntSipURI( 
       
    35     const TDesC& aSipURI,
       
    36     TInt aDigitsForMatching ) : 
       
    37     iSipURI( aSipURI ),
       
    38     iDigitsForMatching( aDigitsForMatching )
       
    39     {
       
    40     RemoveUnusedChars();
       
    41     const TInt sipUriAtPos( iSipURIStripped.Find( KPhCntSipUriAt ) );
       
    42     if( sipUriAtPos > 0 ) 
       
    43         {
       
    44         iUserNamePart.Set( iSipURIStripped.Left( sipUriAtPos ) );
       
    45     	}
       
    46     else
       
    47         {
       
    48         iUserNamePart.Set( iSipURIStripped );
       
    49         }
       
    50 
       
    51     if ( iDigitsForMatching )
       
    52         {
       
    53         // Match is done with username part if iDigitsForMatching is given.
       
    54         // E.g. If username part contains valid cs number (sip:0401234567@domain.com)
       
    55         // and iDigitsForMatching is 7 match is done with string 1234567. 
       
    56         TInt length( 0 );
       
    57                                 
       
    58         if( sipUriAtPos > 0 )
       
    59             {
       
    60             length = iUserNamePart.Length() > aDigitsForMatching ? 
       
    61                         aDigitsForMatching :
       
    62                         iUserNamePart.Length();
       
    63                                 
       
    64             iFixedUserNamePart.Set( iUserNamePart.Right( length ) );
       
    65             }
       
    66         else
       
    67             {
       
    68             length = iSipURIStripped.Length() > aDigitsForMatching ? 
       
    69                         aDigitsForMatching :
       
    70                         iSipURIStripped.Length();
       
    71             
       
    72             iFixedUserNamePart.Set( iSipURIStripped.Right( length ) );
       
    73             }
       
    74         }
       
    75     
       
    76     }
       
    77     
       
    78 // ---------------------------------------------------------------------------
       
    79 // Gives the username part of sip uri.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 const TDesC& TPhCntSipURI::UserNamePart() const
       
    83     {
       
    84     return iUserNamePart;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Gives the whole sip uri.
       
    89 // ---------------------------------------------------------------------------
       
    90 //    
       
    91 const TDesC& TPhCntSipURI::SipURI() const
       
    92     {
       
    93     return iSipURIStripped;
       
    94     }
       
    95     
       
    96 // ---------------------------------------------------------------------------
       
    97 // Gives the fixed username part of sip uri.
       
    98 // ---------------------------------------------------------------------------
       
    99 //    
       
   100 const TDesC& TPhCntSipURI::FixedUserNamePart() const
       
   101     {
       
   102     return iFixedUserNamePart;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Removes possible < and > marks and sip: prefix from sip uri.
       
   107 // ---------------------------------------------------------------------------
       
   108 //    
       
   109 void TPhCntSipURI::RemoveUnusedChars()
       
   110     {
       
   111     TPtrC sipuri( iSipURI );
       
   112     
       
   113     // Remove begin mark
       
   114     const TInt startMarkPos( sipuri.Find( KPhCntSipUriSeparatorBegin ) );
       
   115     if( startMarkPos >= 0 ) 
       
   116         {
       
   117         // Extract the part after "<" mark ie take the part from end of 
       
   118         // the sip uri to "<" mark.
       
   119         sipuri.Set( sipuri.Right( iSipURI.Length() - ( startMarkPos + 1 ) ) );
       
   120         }
       
   121     
       
   122     // Remove end mark
       
   123     const TInt endMarkPos( sipuri.Find( KPhCntSipUriSeparatorEnd ) );
       
   124     if( endMarkPos >= 0 )
       
   125         {
       
   126         sipuri.Set( sipuri.Left( endMarkPos ) );
       
   127         }
       
   128         
       
   129     // "sip:" is not used when comparing addresses. 
       
   130     if ( sipuri.Length() > KSipPrefixLength )
       
   131         {
       
   132         TBuf<KSipPrefixLength> possibleSipPrefix;
       
   133         possibleSipPrefix.Copy( sipuri.Left( KSipPrefixLength ) );
       
   134         possibleSipPrefix.LowerCase();
       
   135                
       
   136         if ( possibleSipPrefix.Compare( KPhCntSipPrefix ) == KErrNone )
       
   137             {
       
   138             sipuri.Set( sipuri.Right( sipuri.Length() - KSipPrefixLength ) );
       
   139             }
       
   140         }
       
   141     
       
   142     iSipURIStripped.Set( sipuri );
       
   143     }
       
   144 
       
   145 // End of File