sipvoipprovider/src/svpuriparser.cpp
branchRCL_3
changeset 22 d38647835c2e
child 23 755430a7d64b
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  provides uri parser methods for SVP 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <uri8.h>
       
    19 #include <sipstrings.h>    // For remote party data parsing
       
    20 #include <sipfromheader.h> // For remote party data parsing
       
    21 #include <sipaddress.h>    // For remote party data parsing
       
    22 
       
    23 #include "svplogger.h"
       
    24 #include "svpconsts.h"
       
    25 #include "svpuriparser.h"
       
    26 #include "svpcleanupresetanddestroy.h"
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CSVPUriParser::CSVPUriParser
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CSVPUriParser::CSVPUriParser()
       
    33     {
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CSVPUriParser::NewLC
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CSVPUriParser* CSVPUriParser::NewLC()
       
    41     {
       
    42     CSVPUriParser* self = new ( ELeave ) CSVPUriParser;
       
    43     CleanupStack::PushL( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CSVPUriParser::NewL
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CSVPUriParser* CSVPUriParser::NewL()
       
    52     {
       
    53     CSVPUriParser* self = CSVPUriParser::NewLC();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CSVPUriParser::~CSVPUriParser
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CSVPUriParser::~CSVPUriParser()
       
    63     {
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CSVPUriParser::SetUserEqualsPhoneRequiredL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CSVPUriParser::SetUserEqualsPhoneRequiredL( TBool aValue )
       
    71     {
       
    72     SVPDEBUG1( "CSVPUriParser::SetUserEqualsPhoneRequiredL" )
       
    73     iUserEqualsPhoneRequired = aValue;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CSVPUriParser::UserEqualsPhoneRequiredL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TBool CSVPUriParser::UserEqualsPhoneRequiredL() const
       
    81     {
       
    82     SVPDEBUG1( "CSVPUriParser::UserEqualsPhoneRequired In" )
       
    83     // check if user=phone is required
       
    84     SVPDEBUG2( "CSVPUriParser::UserEqualsPhoneRequired Out: %d",
       
    85            iUserEqualsPhoneRequired )
       
    86     return iUserEqualsPhoneRequired;    
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CSVPUriParser::IsUriValidForUserEqualsPhoneL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 TBool CSVPUriParser::IsUriValidForUserEqualsPhoneL( const TDesC8& aUri )
       
    94     {
       
    95     SVPDEBUG1( "CSVPUriParser::IsUriValidForUserEqualsPhoneL In" )
       
    96     
       
    97     /// flag to indicate if all checks are ok
       
    98     TBool userEqPhoneCheck = EFalse;    
       
    99     
       
   100     // Extract user info
       
   101     TUriParser8 uri8Parser;
       
   102     uri8Parser.Parse( aUri );
       
   103     CUri8* cUri8 = CUri8::NewLC( uri8Parser ); // CS:1
       
   104     
       
   105     const TUriC8& tempUri =  cUri8->Uri();
       
   106     const TDesC8& userInfo = tempUri.Extract( EUriUserinfo );
       
   107     
       
   108     TLex8 user( userInfo );
       
   109     TInt length = userInfo.Length();
       
   110     const TChar KSvpPlus( '+' );
       
   111     
       
   112     // Check if there is a preceeding plus
       
   113     if ( KSvpPlus == user.Peek() )
       
   114         {
       
   115         user.Inc();
       
   116         length--;
       
   117         }
       
   118     
       
   119     // Check the minimum length
       
   120     if ( KSVPMinUserInfoLength > length )
       
   121         {
       
   122         userEqPhoneCheck = EFalse;
       
   123         }
       
   124     else // Check that there is only digits
       
   125         {
       
   126         userEqPhoneCheck = ETrue;
       
   127         
       
   128         while ( !user.Eos() )
       
   129             {
       
   130             if ( !user.Peek().IsDigit() )
       
   131                 {
       
   132                 userEqPhoneCheck = EFalse;
       
   133                 break;
       
   134                 }
       
   135             
       
   136             user.Inc();
       
   137             }
       
   138         }
       
   139     
       
   140     CleanupStack::PopAndDestroy( cUri8 );
       
   141     
       
   142     SVPDEBUG2( "CSVPUriParser::IsUriValidForUserEqualsPhoneL Out: %d",
       
   143            userEqPhoneCheck )
       
   144     return userEqPhoneCheck;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CSVPUriParser::CompleteSipUriL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 HBufC8* CSVPUriParser::CompleteSipUriL( 
       
   152     const TDesC8& aUri, const TDesC8& aAOR, TBool aIsEmergency ) const
       
   153     {
       
   154     SVPDEBUG1( "CSVPUriParser::CompleteSipUriL In" )
       
   155     
       
   156     // Copy the parameter to a new buffer.
       
   157     HBufC8* uri = aUri.AllocLC();   // CS: 1
       
   158     
       
   159 #ifdef _DEBUG
       
   160     TBuf<KSvpMaxDebugBufferSize> tmpStr;
       
   161     tmpStr.Copy( aAOR );
       
   162     SVPDEBUG2( "CSVPUriParser::CompleteSipUriL IN aAOR: %S", &tmpStr )
       
   163     tmpStr.Copy( aUri );
       
   164     SVPDEBUG2( "CSVPUriParser::CompleteSipUriL IN aURI: %S", &tmpStr )
       
   165 #endif // _DEBUG
       
   166     
       
   167     // Trim ALL white space from URI, even if used as an user name
       
   168     uri->Des().TrimAll();
       
   169 
       
   170     if ( uri )
       
   171         {
       
   172         //First check is this tel-uri. Domain part is not allowed in tel-uri.
       
   173         if ( uri->Length() >= KTelPrefixLength &&
       
   174              KErrNotFound != uri->Des().Left( KTelPrefixLength ).Find( KTelPrefix ) &&
       
   175              KErrNotFound == uri->Des().Find( KSVPAt ) )
       
   176             {
       
   177             CleanupStack::Pop( uri );  // CS:0
       
   178             return uri;
       
   179             }
       
   180         
       
   181         // parse display name if exists
       
   182         while ( KErrNotFound != uri->Find( KSVPSipPrefix ) )
       
   183             {
       
   184             TInt index = uri->Find( KSVPSipPrefix );
       
   185             
       
   186             if ( 0 == index )
       
   187                 {
       
   188                 uri->Des().Delete( index, 4 );
       
   189                 }
       
   190             else
       
   191                 {
       
   192                 uri->Des().Delete( 0, index );
       
   193                 }
       
   194             }
       
   195         
       
   196         // Check "<" and remove it if exists
       
   197         if ( uri->Length() && CheckLeftBracket( *uri ) )
       
   198             {
       
   199             RemoveLeftBracket( uri );
       
   200             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   201             CleanupStack::PushL( uri );
       
   202             }
       
   203         
       
   204         // Check ">" and remove it if exists
       
   205         if ( uri->Length() && CheckRightBracket( *uri ) )
       
   206             {
       
   207             RemoveRightBracket( uri );
       
   208             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   209             CleanupStack::PushL( uri );
       
   210             }
       
   211         
       
   212         // Check "sips:" and remove it if exists
       
   213         if ( uri->Length() && CheckSipsPrefix( *uri ) )
       
   214             {
       
   215             RemoveSipsPrefixL( uri );
       
   216             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   217             CleanupStack::PushL( uri );
       
   218             }
       
   219         
       
   220         // Add "sip:" prefix, if it's missing.
       
   221         if ( !CheckSipPrefix( *uri ) )
       
   222             {
       
   223             AddSipPrefixL( uri );
       
   224             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   225             CleanupStack::PushL( uri );
       
   226             }
       
   227         
       
   228         // Add "@" character if it's missing
       
   229         if ( !CheckAt( *uri ) )
       
   230             {
       
   231             AddAtL( uri );
       
   232             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   233             CleanupStack::PushL( uri );
       
   234             }
       
   235         
       
   236         // Add domain, if it's missing
       
   237         if ( !CheckDomain( *uri ) )
       
   238             {
       
   239             AddDomainL( uri, aAOR );
       
   240             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   241             CleanupStack::PushL( uri );
       
   242             }
       
   243         
       
   244         EscapeEncodeSipUriL( uri, EscapeUtils::EEscapeNormal );
       
   245         CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   246         CleanupStack::PushL( uri );
       
   247         
       
   248         // Emergency call has no knowledge of the service ID, therefore
       
   249         // user=phone parameter is omitted
       
   250         if ( !aIsEmergency &&
       
   251              IsUriValidForUserEqualsPhoneL( *uri ) && 
       
   252              UserEqualsPhoneRequiredL() )
       
   253             {
       
   254             AddUserEqualsPhoneL( uri );
       
   255             }
       
   256         }
       
   257     else
       
   258         {
       
   259         SVPDEBUG1( "    CSVPUriParser::CompleteSipUriL uri null" )
       
   260         }
       
   261     
       
   262 #ifdef _DEBUG
       
   263     tmpStr.Copy( *uri );
       
   264     SVPDEBUG2( "CSVPUriParser::CompleteSipUriL OUT: %S", &tmpStr )
       
   265 #endif // _DEBUG
       
   266     
       
   267     CleanupStack::Pop( 1 ); // uri
       
   268     return uri;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // CSVPUriParser::AddUserEqualsPhone
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CSVPUriParser::AddUserEqualsPhoneL( HBufC8*& aUri ) const
       
   276     {
       
   277     SVPDEBUG1( "CSVPUriParser::AddUserEqualsPhoneL In" )
       
   278    
       
   279     aUri = aUri->ReAllocL( aUri->Length() + 
       
   280                           KSVPUserEqualsPhoneLength + 
       
   281                           KSVPDoubleBracketLength ); 
       
   282     aUri->Des().Insert( 0, KSVPLeftBracketMark );
       
   283     aUri->Des().Append( KSVPUserEqualsPhone );
       
   284     aUri->Des().Append( KSVPRightBracketMark );
       
   285     
       
   286     SVPDEBUG1( "CSVPUriParser::AddUserEqualsPhoneL Out" )
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CSVPUriParser::CompleteSecureSipUriL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 HBufC8* CSVPUriParser::CompleteSecureSipUriL(
       
   294     const TDesC8& aUri, const TDesC8& aAOR ) const
       
   295     {
       
   296     SVPDEBUG1( "CSVPUriParser::CompleteSecureSipUriL In" )
       
   297     
       
   298     // Copy the parameter to a new buffer.
       
   299     HBufC8* uri = aUri.AllocLC();
       
   300 
       
   301 #ifdef _DEBUG
       
   302     TBuf<KSvpMaxDebugBufferSize> tmpStr;
       
   303     tmpStr.Copy( aAOR );
       
   304     SVPDEBUG2( "CSVPUriParser::CompleteSecureSipUriL IN aAOR: %S", &tmpStr )
       
   305     tmpStr.Copy( aUri );
       
   306     SVPDEBUG2( "CSVPUriParser::CompleteSecureSipUriL IN aURI: %S", &tmpStr )
       
   307 #endif // _DEBUG
       
   308     
       
   309     // Trim ALL white space from URI, even if used as an user name 
       
   310     uri->Des().TrimAll();
       
   311 
       
   312     if ( uri )
       
   313         {
       
   314         //First check is this tel-uri. Domain part is not allowed in tel-uri.
       
   315         if ( uri->Length() >= KTelPrefixLength &&
       
   316              KErrNotFound != uri->Des().Left( KTelPrefixLength ).Find( KTelPrefix ) &&
       
   317              KErrNotFound == uri->Des().Find( KSVPAt ) )
       
   318             {
       
   319             CleanupStack::Pop( uri );
       
   320             return uri;
       
   321             }
       
   322         
       
   323         // Check "<" and remove it if exists
       
   324         if ( uri->Length() && CheckLeftBracket( *uri ) )
       
   325             {
       
   326             RemoveLeftBracket( uri );
       
   327             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   328             CleanupStack::PushL( uri );
       
   329             }
       
   330         
       
   331         // Check ">" and remove it if exists
       
   332         if ( uri->Length() && CheckRightBracket( *uri ) )
       
   333             {
       
   334             RemoveRightBracket( uri );
       
   335             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   336             CleanupStack::PushL( uri );
       
   337             }
       
   338         
       
   339         // Check "sip:" and remove it if exists
       
   340         if ( uri->Length() && CheckSipPrefix( *uri ) )
       
   341             {
       
   342             RemoveSipPrefixL( uri );
       
   343             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   344             CleanupStack::PushL( uri );
       
   345             }
       
   346         
       
   347         // Add "sips:" prefix, if it's missing.
       
   348         if ( !CheckSipsPrefix( *uri ) )
       
   349             {
       
   350             AddSipsPrefixL( uri );
       
   351             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   352             CleanupStack::PushL( uri );
       
   353             }
       
   354         
       
   355         // Add "@" character if it's missing
       
   356         if ( !CheckAt( *uri ) )
       
   357             {
       
   358             AddAtL( uri );
       
   359             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   360             CleanupStack::PushL( uri );
       
   361             }
       
   362         
       
   363         // Add domain, if it's missing
       
   364         if ( !CheckDomain( *uri ) )
       
   365             {
       
   366             AddDomainL( uri, aAOR );
       
   367             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   368             CleanupStack::PushL( uri );
       
   369             }
       
   370         
       
   371         EscapeEncodeSipUriL( uri, EscapeUtils::EEscapeNormal );
       
   372         CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   373         CleanupStack::PushL( uri );
       
   374         
       
   375         if ( UserEqualsPhoneRequiredL() &&
       
   376              IsUriValidForUserEqualsPhoneL( *uri ) )
       
   377             {
       
   378             AddUserEqualsPhoneL( uri );
       
   379             }
       
   380         }
       
   381     else
       
   382         {
       
   383         SVPDEBUG1( "    CSVPUriParser::CompleteSecureSipUriL uri null" )
       
   384         }
       
   385     
       
   386 #ifdef _DEBUG
       
   387     tmpStr.Copy( *uri );
       
   388     SVPDEBUG2( "CSVPUriParser::CompleteSecureSipUriL OUT: %S", &tmpStr )
       
   389 #endif // _DEBUG
       
   390     
       
   391     CleanupStack::Pop( 1 ); // uri
       
   392     return uri;
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // CSVPUriParser::CompleteEventSipUriL
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 HBufC8* CSVPUriParser::CompleteEventSipUriL( const TDesC8& aUri ) const
       
   400     {
       
   401     SVPDEBUG1( "CSVPUriParser::CompleteEventSipUriL In" )
       
   402     
       
   403     // Copy the parameter to a new buffer.
       
   404     HBufC8* uri = aUri.AllocLC();
       
   405     
       
   406     // Add "sip:" prefix, if it's missing.
       
   407     if ( !CheckSipPrefix( *uri ) )
       
   408         {
       
   409         AddSipPrefixL( uri );
       
   410         }
       
   411     
       
   412     CleanupStack::Pop( 1 ); // uri
       
   413     
       
   414     SVPDEBUG1( "CSVPUriParser::CompleteEventSipUriL Out" )
       
   415     return uri;
       
   416     }
       
   417 
       
   418 // ---------------------------------------------------------------------------
       
   419 // CSVPUriParser::CheckSipPrefix
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 TBool CSVPUriParser::CheckSipPrefix( const TDesC8& aUri ) const
       
   423     {
       
   424     SVPDEBUG1( "CSVPUriParser::CheckSipPrefix" )
       
   425     
       
   426     // The "sip:" prefix is expected to be at the beginning of the URI.
       
   427     if ( KErrNotFound == aUri.Find( KSVPSipPrefix ) )
       
   428         {
       
   429         return EFalse;
       
   430         }
       
   431     else
       
   432         {
       
   433         return ETrue;    
       
   434         }
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CSVPUriParser::CheckSipsPrefix
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 TBool CSVPUriParser::CheckSipsPrefix( const TDesC8& aUri ) const
       
   442     {
       
   443     SVPDEBUG1( "CSVPUriParser::CheckSipsPrefix" )
       
   444     
       
   445     // The "sips:" prefix is expected to be at the beginning of the URI.
       
   446     return ( 0 == aUri.Find( KSVPSipsPrefix ) );
       
   447     }
       
   448 
       
   449 // ---------------------------------------------------------------------------
       
   450 // CSVPUriParser::CheckAt
       
   451 // ---------------------------------------------------------------------------
       
   452 //
       
   453 TBool CSVPUriParser::CheckAt( const TDesC8& aUri ) const
       
   454     {
       
   455     SVPDEBUG1( "CSVPUriParser::CheckAt" )
       
   456     
       
   457     // It is expected that there is atleast one character between 
       
   458     // "sip:" prefix and "@" character.
       
   459     return ( aUri.Find( KSVPAt ) >= KSVPSipPrefixLength );
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // CSVPUriParser::CheckDomain
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 TBool CSVPUriParser::CheckDomain( const TDesC8& aUri ) const
       
   467     {
       
   468     SVPDEBUG1( "CSVPUriParser::CheckDomain" )
       
   469     
       
   470     // Check whether the "@" chearacter is the last one.
       
   471     return ( aUri.Find( KSVPAt ) < aUri.Length() - 1 );
       
   472     }
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // CSVPUriParser::DomainL
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 HBufC8* CSVPUriParser::DomainL( const TDesC8& aUri )
       
   479     {
       
   480     SVPDEBUG1( "CSVPUriParser::DomainL In" )
       
   481     
       
   482     HBufC8* ptr = NULL;
       
   483     
       
   484     // Check that URI is complete; it has domain part:
       
   485     if ( aUri.Find( KSVPAt ) < aUri.Length() - 1 )
       
   486         {
       
   487         TInt uriLength = aUri.Length();
       
   488         TInt atPos = aUri.Find( KSVPAt );
       
   489         //__ASSERT_ALWAYS( atPos != KErrNotFound, User::Leave( KErrArgument ) );
       
   490         TPtrC8 domainPart = aUri.Right( uriLength - atPos - 1 );
       
   491         ptr = domainPart.AllocL();
       
   492         }
       
   493     
       
   494     SVPDEBUG1( "CSVPUriParser::DomainL Out" )
       
   495     return ptr;
       
   496     }
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // CSVPUriParser::AddSipPrefixL
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 void CSVPUriParser::AddSipPrefixL( HBufC8*& aUri ) const 
       
   503     {
       
   504     SVPDEBUG1( "CSVPUriParser::AddSipPrefixL In" )
       
   505     aUri = aUri->ReAllocL( aUri->Length() + KSVPSipPrefixLength );
       
   506     aUri->Des().Insert( 0, KSVPSipPrefix );
       
   507     
       
   508     SVPDEBUG1( "CSVPUriParser::AddSipPrefixL Out" )
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------------------------
       
   512 // CSVPUriParser::RemoveSipPrefixL
       
   513 // ---------------------------------------------------------------------------
       
   514 //
       
   515 void CSVPUriParser::RemoveSipPrefixL( HBufC8*& aUri ) const 
       
   516     {
       
   517     SVPDEBUG1( "CSVPUriParser::RemoveSipPrefixL" )
       
   518     
       
   519     aUri->Des().Delete( 0, KSVPSipPrefixLength );
       
   520     }
       
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // CSVPUriParser::AddSipsPrefixL
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 void CSVPUriParser::AddSipsPrefixL( HBufC8*& aUri ) const 
       
   527     {
       
   528     SVPDEBUG1( "CSVPUriParser::AddSipsPrefixL In" )
       
   529     
       
   530     aUri = aUri->ReAllocL( aUri->Length() + KSVPSipsPrefixLength );
       
   531     aUri->Des().Insert( 0, KSVPSipsPrefix );
       
   532     
       
   533     SVPDEBUG1( "CSVPUriParser::AddSipsPrefixL Out" )
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // CSVPUriParser::RemoveSipsPrefixL
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 void CSVPUriParser::RemoveSipsPrefixL( HBufC8*& aUri ) const 
       
   541     {
       
   542     SVPDEBUG1( "CSVPUriParser::RemoveSipsPrefixL" )
       
   543     
       
   544     aUri->Des().Delete( 0, KSVPSipsPrefixLength );
       
   545     }
       
   546 
       
   547 // ---------------------------------------------------------------------------
       
   548 // CSVPUriParser::AddAtL
       
   549 // ---------------------------------------------------------------------------
       
   550 //
       
   551 void CSVPUriParser::AddAtL( HBufC8*& aUri ) const
       
   552     {
       
   553     SVPDEBUG1( "CSVPUriParser::AddAtL In" )
       
   554     
       
   555     aUri = aUri->ReAllocL( aUri->Length() + KSVPAtLength );
       
   556     aUri->Des().Append( KSVPAt );
       
   557     
       
   558     SVPDEBUG1( "CSVPUriParser::AddAtL Out" )
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // CSVPUriParser::AddDomainL
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 void CSVPUriParser::AddDomainL( 
       
   566     HBufC8*& aUri, const TDesC8& aAOR ) const 
       
   567     {
       
   568     SVPDEBUG1( "CSVPUriParser::AddDomainL In" )
       
   569     
       
   570     // Parse the domain part from the AOR.
       
   571     HBufC8* domainBuf = HBufC8::NewLC( aAOR.Length() ); // CS : 1
       
   572     TInt atPos = aAOR.Find( KSVPAt );
       
   573     
       
   574     // Check, that the "@" character is in AOR.
       
   575     __ASSERT_ALWAYS( KErrNotFound != atPos, User::Leave( KErrArgument ) );
       
   576     // Check, that there is a domain part.
       
   577     __ASSERT_ALWAYS( atPos < aAOR.Length()-1, User::Leave( KErrArgument ) );
       
   578     
       
   579     // Copy the domain to the domain buffer.
       
   580     domainBuf->Des().Append( aAOR.Mid( atPos + 1 ) );
       
   581     
       
   582     // Re-allocate the URI
       
   583     aUri = aUri->ReAllocL( aUri->Length() + domainBuf->Length() );
       
   584     aUri->Des().Append( *domainBuf ); // Append the domain.
       
   585     
       
   586     CleanupStack::PopAndDestroy( domainBuf ); // CS : 0
       
   587     
       
   588     SVPDEBUG1( "CSVPUriParser::AddDomainL Out" )
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // CSVPUriParser::CheckLeftBracket
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 TBool CSVPUriParser::CheckLeftBracket( const TDesC8& aUri ) const
       
   596     {
       
   597     SVPDEBUG1( "CSVPUriParser::CheckLeftBracket" )
       
   598     
       
   599     // The "<" prefix is expected to be at the beginning of the URI.
       
   600     return ( 0 == aUri.Find( KSVPLeftBracketMark ) );
       
   601     }
       
   602 
       
   603 // ---------------------------------------------------------------------------
       
   604 // CSVPUriParser::RemoveLeftBracket
       
   605 // ---------------------------------------------------------------------------
       
   606 //
       
   607 void CSVPUriParser::RemoveLeftBracket( HBufC8*& aUri ) const 
       
   608     {
       
   609     SVPDEBUG1( "CSVPUriParser::RemoveLeftBracket" )
       
   610     
       
   611     aUri->Des().Delete( 0, KSVPSingleBracketLength );
       
   612     }
       
   613 
       
   614 // ---------------------------------------------------------------------------
       
   615 // CSVPUriParser::CheckRightBracket
       
   616 // ---------------------------------------------------------------------------
       
   617 //
       
   618 TBool CSVPUriParser::CheckRightBracket( const TDesC8& aUri ) const
       
   619     {
       
   620     SVPDEBUG1( "CSVPUriParser::CheckRightBracket" )
       
   621     
       
   622     // The ">" prefix is expected to be at the end of the URI.
       
   623     return ( aUri.Length() == ( aUri.Find( KSVPRightBracketMark )
       
   624                                 + KSVPSingleBracketLength ) );
       
   625     }
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 // CSVPUriParser::RemoveRightBracket
       
   629 // ---------------------------------------------------------------------------
       
   630 //
       
   631 void CSVPUriParser::RemoveRightBracket( HBufC8*& aUri ) const 
       
   632     {
       
   633     SVPDEBUG1( "CSVPUriParser::RemoveRightBracket" )
       
   634     
       
   635     aUri->Des().Delete( aUri->Length() - KSVPSingleBracketLength,
       
   636                         KSVPSingleBracketLength );
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // CSVPUriParser::EscapeEncodeSipUriL
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 void CSVPUriParser::EscapeEncodeSipUriL( HBufC8*& aSipUri,
       
   644         EscapeUtils::TEscapeMode aMode )
       
   645     {
       
   646     SVPDEBUG1( "CSVPUriParser::EscapeEncodeSipUriL In" )
       
   647     
       
   648     HBufC8* temp = EscapeUtils::EscapeEncodeL( *aSipUri, aMode );
       
   649     CleanupStack::PushL( temp );
       
   650     aSipUri = aSipUri->ReAllocL( temp->Length() );
       
   651     *aSipUri = *temp;
       
   652     CleanupStack::PopAndDestroy( temp );
       
   653     
       
   654     SVPDEBUG1( "CSVPUriParser::EscapeEncodeSipUriL Out" )
       
   655     }
       
   656 
       
   657 // ---------------------------------------------------------------------------
       
   658 // CSVPUriParser::EscapeDecodeSipUriL
       
   659 // ---------------------------------------------------------------------------
       
   660 //
       
   661 void CSVPUriParser::EscapeDecodeSipUriL( HBufC8*& aSipUri )
       
   662     {
       
   663     SVPDEBUG1( "CSVPUriParser::EscapeDecodeSipUriL In" )
       
   664     
       
   665     HBufC8* temp = EscapeUtils::EscapeDecodeL( *aSipUri );
       
   666     CleanupStack::PushL( temp ); 
       
   667     
       
   668     if( temp->Length() > aSipUri->Length() )
       
   669         {
       
   670         aSipUri = aSipUri->ReAllocL( temp->Length() );
       
   671         }
       
   672     
       
   673     *aSipUri = *temp;
       
   674     
       
   675     CleanupStack::PopAndDestroy( temp );
       
   676     
       
   677     SVPDEBUG1( "CSVPUriParser::EscapeDecodeSipUriL Out" )
       
   678     }
       
   679 
       
   680 // ---------------------------------------------------------------------------
       
   681 // CSVPUriParser::ParseDisplayNameL
       
   682 // ---------------------------------------------------------------------------
       
   683 // 
       
   684 HBufC* CSVPUriParser::ParseDisplayNameL( const TDesC8& aRemoteParty )
       
   685     {
       
   686     SVPDEBUG1( "CSVPUriParser::ParseDisplayNameL()" )
       
   687         
       
   688     // Open SIP string pool 
       
   689     SIPStrings::OpenL();
       
   690 
       
   691     // Make a local copy
       
   692     HBufC8* utf8 = HBufC8::NewLC( aRemoteParty.Length() ); // CS:1
       
   693     ( utf8->Des() ).Copy( aRemoteParty );
       
   694     
       
   695     // Escape decode
       
   696     CSVPUriParser::EscapeDecodeSipUriL( utf8 );
       
   697     
       
   698     // Convert from UTF8 to unicode
       
   699     HBufC* unicode16 = EscapeUtils::ConvertToUnicodeFromUtf8L( *utf8 );
       
   700     CleanupStack::PopAndDestroy( utf8 ); // CS:0
       
   701     CleanupStack::PushL( unicode16 ); // CS:1
       
   702     HBufC8* unicode8 = HBufC8::NewL( unicode16->Length() );
       
   703     ( unicode8->Des() ).Copy( *unicode16 );
       
   704     CleanupStack::PopAndDestroy( unicode16 ); // CS:0
       
   705     CleanupStack::PushL( unicode8 ); // CS:1
       
   706     
       
   707     // Create SIP From header
       
   708     CSIPFromHeader* originatorHdr = CSIPFromHeader::DecodeL( *unicode8 );
       
   709     CleanupStack::PopAndDestroy( unicode8 ); // CS:0
       
   710     CleanupStack::PushL( originatorHdr ); // CS:1
       
   711     
       
   712     // Extract and parse display name, format is "..."
       
   713     HBufC8* displayName8 = originatorHdr->SIPAddress().DisplayName().AllocL();
       
   714     CleanupStack::PopAndDestroy( originatorHdr ); // CS:0
       
   715     CleanupStack::PushL( displayName8 ); // CS:1
       
   716 
       
   717     // Convert to 16-bit
       
   718     HBufC* displayName = HBufC::NewL( displayName8->Length() );
       
   719     ( displayName->Des() ).Copy( *displayName8 );
       
   720     CleanupStack::PopAndDestroy( displayName8 ); // CS:0
       
   721     
       
   722     // Close SIP string pool
       
   723     SIPStrings::Close();
       
   724 
       
   725     // Parse: remove quotation marks from both ends
       
   726     displayName->Des().Trim(); 
       
   727     if ( KSVPQuotationMark() == displayName->Left( 1 ) && 
       
   728          KSVPQuotationMark() == displayName->Right( 1 ) )
       
   729         {
       
   730         displayName->Des().Delete( 0, 1 );
       
   731         displayName->Des().Delete( displayName->Length() - 1, 1 );
       
   732         }
       
   733     
       
   734     // Parse: remove backslashes   
       
   735     TLex lex( *displayName );
       
   736     const TChar backslash = '\\';
       
   737     TBool chDeleted = EFalse;
       
   738     while ( !lex.Eos() )
       
   739         {
       
   740         if ( backslash == lex.Peek() && !chDeleted )
       
   741             {
       
   742             // Backslash found, delete it if not consecutive
       
   743             displayName->Des().Delete( lex.Offset() , 1 );
       
   744             lex.Inc();
       
   745             chDeleted = ETrue;
       
   746             }
       
   747         else
       
   748             {
       
   749             // Not a backslash
       
   750             lex.Inc();
       
   751             chDeleted = EFalse;
       
   752             }
       
   753         }
       
   754 
       
   755     // Handle anonymous
       
   756     if ( KErrNotFound != displayName->Des().FindF( KSVPAnonymous ) )
       
   757         {
       
   758         SVPDEBUG1( "CSVPUriParser::ParseDisplayNameL, anonymous case" )
       
   759         displayName->Des().Copy( KNullDesC );
       
   760         }
       
   761 
       
   762     SVPDEBUG2( "CSVPUriParser::ParseDisplayNameL, display name: %S", 
       
   763         displayName )
       
   764     return displayName;
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CSVPUriParser::ParseRemotePartyUriL
       
   769 // ---------------------------------------------------------------------------
       
   770 // 
       
   771 HBufC* CSVPUriParser::ParseRemotePartyUriL( const TDesC8& aRemoteParty )
       
   772     {
       
   773     SVPDEBUG1( "CSVPUriParser::ParseRemotePartyUriL()" )
       
   774         
       
   775     // Open SIP string pool 
       
   776     SIPStrings::OpenL();
       
   777 
       
   778     // Make a local copy
       
   779     HBufC8* utf8 = HBufC8::NewLC( aRemoteParty.Length() ); // CS:1
       
   780     ( utf8->Des() ).Copy( aRemoteParty );
       
   781 
       
   782     // Escape decode
       
   783     CSVPUriParser::EscapeDecodeSipUriL( utf8 );
       
   784     
       
   785     // Convert from UTF8 to unicode
       
   786     HBufC* unicode16 = EscapeUtils::ConvertToUnicodeFromUtf8L( *utf8 );
       
   787     CleanupStack::PopAndDestroy( utf8 ); // CS:0
       
   788     CleanupStack::PushL( unicode16 ); // CS:1
       
   789     HBufC8* unicode8 = HBufC8::NewL( unicode16->Length() );
       
   790     ( unicode8->Des() ).Copy( *unicode16 );
       
   791     CleanupStack::PopAndDestroy( unicode16 ); // CS:0
       
   792     CleanupStack::PushL( unicode8 ); // CS:1
       
   793     
       
   794     // Create SIP From header
       
   795     CSIPFromHeader* originatorHdr = CSIPFromHeader::DecodeL( *unicode8 );
       
   796     CleanupStack::PopAndDestroy( unicode8 ); // CS:0
       
   797     CleanupStack::PushL( originatorHdr ); // CS:1
       
   798         
       
   799     // Extract URI, returned without angle brackets
       
   800     HBufC8* uri8 = originatorHdr->SIPAddress().Uri8().Uri().UriDes().AllocL();
       
   801     CleanupStack::PopAndDestroy( originatorHdr ); // CS:0
       
   802     CleanupStack::PushL( uri8 ); // CS:1
       
   803     
       
   804     // Parse: remove URI parameters
       
   805     TInt posSemiColon = uri8->FindF( KSVPSemiCln );
       
   806     if ( KErrNotFound != posSemiColon )
       
   807         {
       
   808         uri8->Des().Delete( posSemiColon, uri8->Length() - posSemiColon );
       
   809         }
       
   810 
       
   811     // Convert to 16-bit
       
   812     HBufC* uri = HBufC::NewL( uri8->Length() );
       
   813     ( uri->Des() ).Copy( *uri8 );
       
   814     CleanupStack::PopAndDestroy( uri8 ); // CS:0
       
   815 
       
   816     // Handle anonymous
       
   817     if ( KErrNotFound != uri->Des().FindF( KSVPAnonymous ) )
       
   818         {
       
   819         SVPDEBUG1( "CSVPUriParser::ParseRemotePartyUriL, anonymous case" )
       
   820         uri->Des().Copy( KNullDesC );
       
   821         }
       
   822 
       
   823     // Close SIP string pool
       
   824     SIPStrings::Close();
       
   825     
       
   826     SVPDEBUG2( "CSVPUriParser::ParseRemotePartyUriL, URI: %S", uri )
       
   827     return uri;
       
   828     }
       
   829 
       
   830 //  End of File