sipvoipprovider/src/svpuriparser.cpp
changeset 0 a4daefaec16c
child 10 ed1e38b404e5
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     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();
       
   158     
       
   159     // Trim ALL white space from URI, even if used as an user name
       
   160     uri->Des().TrimAll();
       
   161 
       
   162     if ( uri )
       
   163         {
       
   164         //First check is this tel-uri. Domain part is not allowed in tel-uri.
       
   165         if ( uri->Length() >= KTelPrefixLength &&
       
   166              KErrNotFound != uri->Des().Left( KTelPrefixLength ).Find( KTelPrefix ) &&
       
   167              KErrNotFound == uri->Des().Find( KSVPAt ) )
       
   168             {
       
   169             CleanupStack::Pop( uri );
       
   170             return uri;
       
   171             }
       
   172         
       
   173         // parse display name if exists
       
   174         while ( KErrNotFound != uri->Find( KSVPSipPrefix ) )
       
   175             {
       
   176             TInt index = uri->Find( KSVPSipPrefix );
       
   177             
       
   178             if ( 0 == index )
       
   179                 {
       
   180                 uri->Des().Delete( index, 4 );
       
   181                 }
       
   182             else
       
   183                 {
       
   184                 uri->Des().Delete( 0, index );
       
   185                 }
       
   186             }
       
   187         
       
   188         // Check "<" and remove it if exists
       
   189         if ( uri->Length() && CheckLeftBracket( *uri ) )
       
   190             {
       
   191             RemoveLeftBracket( uri );
       
   192             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   193             CleanupStack::PushL( uri );
       
   194             }
       
   195         
       
   196         // Check ">" and remove it if exists
       
   197         if ( uri->Length() && CheckRightBracket( *uri ) )
       
   198             {
       
   199             RemoveRightBracket( uri );
       
   200             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   201             CleanupStack::PushL( uri );
       
   202             }
       
   203         
       
   204         // Check "sips:" and remove it if exists
       
   205         if ( uri->Length() && CheckSipsPrefix( *uri ) )
       
   206             {
       
   207             RemoveSipsPrefixL( uri );
       
   208             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   209             CleanupStack::PushL( uri );
       
   210             }
       
   211         
       
   212         // Add "sip:" prefix, if it's missing.
       
   213         if ( !CheckSipPrefix( *uri ) )
       
   214             {
       
   215             AddSipPrefixL( uri );
       
   216             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   217             CleanupStack::PushL( uri );
       
   218             }
       
   219         
       
   220         // Add "@" character if it's missing
       
   221         if ( !CheckAt( *uri ) )
       
   222             {
       
   223             AddAtL( uri );
       
   224             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   225             CleanupStack::PushL( uri );
       
   226             }
       
   227         
       
   228         // Add domain, if it's missing
       
   229         if ( !CheckDomain( *uri ) )
       
   230             {
       
   231             AddDomainL( uri, aAOR );
       
   232             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   233             CleanupStack::PushL( uri );
       
   234             }
       
   235         
       
   236         EscapeEncodeSipUriL( uri, EscapeUtils::EEscapeNormal );
       
   237         CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   238         CleanupStack::PushL( uri );
       
   239         
       
   240         // Emergency call has no knowledge of the service ID, therefore
       
   241         // user=phone parameter is omitted
       
   242         if ( !aIsEmergency &&
       
   243              IsUriValidForUserEqualsPhoneL( *uri ) && 
       
   244              UserEqualsPhoneRequiredL() )
       
   245             {
       
   246             AddUserEqualsPhoneL( uri );
       
   247             }
       
   248         }
       
   249     else
       
   250         {
       
   251         SVPDEBUG1( "    CSVPUriParser::CompleteSipUriL uri null" )
       
   252         }
       
   253 
       
   254     CleanupStack::Pop( 1 ); // uri
       
   255     
       
   256     SVPDEBUG1( "CSVPUriParser::CompleteSipUriL Out" )
       
   257     return uri;
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CSVPUriParser::AddUserEqualsPhone
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CSVPUriParser::AddUserEqualsPhoneL( HBufC8*& aUri ) const
       
   265     {
       
   266     SVPDEBUG1( "CSVPUriParser::AddUserEqualsPhoneL In" )
       
   267    
       
   268     aUri = aUri->ReAllocL( aUri->Length() + 
       
   269                           KSVPUserEqualsPhoneLength + 
       
   270                           KSVPDoubleBracketLength ); 
       
   271     aUri->Des().Insert( 0, KSVPLeftBracketMark );
       
   272     aUri->Des().Append( KSVPUserEqualsPhone );
       
   273     aUri->Des().Append( KSVPRightBracketMark );
       
   274     
       
   275     SVPDEBUG1( "CSVPUriParser::AddUserEqualsPhoneL Out" )
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CSVPUriParser::CompleteSecureSipUriL
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 HBufC8* CSVPUriParser::CompleteSecureSipUriL(
       
   283     const TDesC8& aUri, const TDesC8& aAOR ) const
       
   284     {
       
   285     SVPDEBUG1( "CSVPUriParser::CompleteSecureSipUriL In" )
       
   286     
       
   287     // Copy the parameter to a new buffer.
       
   288     HBufC8* uri = aUri.AllocLC();
       
   289     
       
   290     // Trim ALL white space from URI, even if used as an user name 
       
   291     uri->Des().TrimAll();
       
   292 
       
   293     if ( uri )
       
   294         {
       
   295         //First check is this tel-uri. Domain part is not allowed in tel-uri.
       
   296         if ( uri->Length() >= KTelPrefixLength &&
       
   297              KErrNotFound != uri->Des().Left( KTelPrefixLength ).Find( KTelPrefix ) &&
       
   298              KErrNotFound == uri->Des().Find( KSVPAt ) )
       
   299             {
       
   300             CleanupStack::Pop( uri );
       
   301             return uri;
       
   302             }
       
   303         
       
   304         // Check "<" and remove it if exists
       
   305         if ( uri->Length() && CheckLeftBracket( *uri ) )
       
   306             {
       
   307             RemoveLeftBracket( uri );
       
   308             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   309             CleanupStack::PushL( uri );
       
   310             }
       
   311         
       
   312         // Check ">" and remove it if exists
       
   313         if ( uri->Length() && CheckRightBracket( *uri ) )
       
   314             {
       
   315             RemoveRightBracket( uri );
       
   316             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   317             CleanupStack::PushL( uri );
       
   318             }
       
   319         
       
   320         // Check "sip:" and remove it if exists
       
   321         if ( uri->Length() && CheckSipPrefix( *uri ) )
       
   322             {
       
   323             RemoveSipPrefixL( uri );
       
   324             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   325             CleanupStack::PushL( uri );
       
   326             }
       
   327         
       
   328         // Add "sips:" prefix, if it's missing.
       
   329         if ( !CheckSipsPrefix( *uri ) )
       
   330             {
       
   331             AddSipsPrefixL( uri );
       
   332             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   333             CleanupStack::PushL( uri );
       
   334             }
       
   335         
       
   336         // Add "@" character if it's missing
       
   337         if ( !CheckAt( *uri ) )
       
   338             {
       
   339             AddAtL( uri );
       
   340             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   341             CleanupStack::PushL( uri );
       
   342             }
       
   343         
       
   344         // Add domain, if it's missing
       
   345         if ( !CheckDomain( *uri ) )
       
   346             {
       
   347             AddDomainL( uri, aAOR );
       
   348             CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   349             CleanupStack::PushL( uri );
       
   350             }
       
   351         
       
   352         EscapeEncodeSipUriL( uri, EscapeUtils::EEscapeNormal );
       
   353         CleanupStack::Pop( 1 ); // uri, ReAlloc possible
       
   354         CleanupStack::PushL( uri );
       
   355         
       
   356         if ( UserEqualsPhoneRequiredL() &&
       
   357              IsUriValidForUserEqualsPhoneL( *uri ) )
       
   358             {
       
   359             AddUserEqualsPhoneL( uri );
       
   360             }
       
   361         }
       
   362     else
       
   363         {
       
   364         SVPDEBUG1( "    CSVPUriParser::CompleteSecureSipUriL uri null" )
       
   365         }
       
   366 
       
   367     CleanupStack::Pop( 1 ); // uri
       
   368     
       
   369     SVPDEBUG1( "CSVPUriParser::CompleteSecureSipUriL Out" )
       
   370     return uri;
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // CSVPUriParser::CompleteEventSipUriL
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 HBufC8* CSVPUriParser::CompleteEventSipUriL( const TDesC8& aUri ) const
       
   378     {
       
   379     SVPDEBUG1( "CSVPUriParser::CompleteEventSipUriL In" )
       
   380     
       
   381     // Copy the parameter to a new buffer.
       
   382     HBufC8* uri = aUri.AllocLC();
       
   383     
       
   384     // Add "sip:" prefix, if it's missing.
       
   385     if ( !CheckSipPrefix( *uri ) )
       
   386         {
       
   387         AddSipPrefixL( uri );
       
   388         }
       
   389     
       
   390     CleanupStack::Pop( 1 ); // uri
       
   391     
       
   392     SVPDEBUG1( "CSVPUriParser::CompleteEventSipUriL Out" )
       
   393     return uri;
       
   394     }
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // CSVPUriParser::CheckSipPrefix
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 TBool CSVPUriParser::CheckSipPrefix( const TDesC8& aUri ) const
       
   401     {
       
   402     SVPDEBUG1( "CSVPUriParser::CheckSipPrefix" )
       
   403     
       
   404     // The "sip:" prefix is expected to be at the beginning of the URI.
       
   405     if ( KErrNotFound == aUri.Find( KSVPSipPrefix ) )
       
   406         {
       
   407         return EFalse;
       
   408         }
       
   409     else
       
   410         {
       
   411         return ETrue;    
       
   412         }
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // CSVPUriParser::CheckSipsPrefix
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 TBool CSVPUriParser::CheckSipsPrefix( const TDesC8& aUri ) const
       
   420     {
       
   421     SVPDEBUG1( "CSVPUriParser::CheckSipsPrefix" )
       
   422     
       
   423     // The "sip:" prefix is expected to be at the beginning of the URI.
       
   424     return ( 0 == aUri.Find( KSVPSipsPrefix ) );
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CSVPUriParser::CheckAt
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 TBool CSVPUriParser::CheckAt( const TDesC8& aUri ) const
       
   432     {
       
   433     SVPDEBUG1( "CSVPUriParser::CheckAt" )
       
   434     
       
   435     // It is expected that there is atleast one character between 
       
   436     // "sip:" prefix and "@" character.
       
   437     return ( aUri.Find( KSVPAt ) >= KSVPSipPrefixLength );
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // CSVPUriParser::CheckDomain
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 TBool CSVPUriParser::CheckDomain( const TDesC8& aUri ) const
       
   445     {
       
   446     SVPDEBUG1( "CSVPUriParser::CheckDomain" )
       
   447     
       
   448     // Check whether the "@" chearacter is the last one.
       
   449     return ( aUri.Find( KSVPAt ) < aUri.Length() - 1 );
       
   450     }
       
   451 
       
   452 // ---------------------------------------------------------------------------
       
   453 // CSVPUriParser::DomainL
       
   454 // ---------------------------------------------------------------------------
       
   455 //
       
   456 HBufC8* CSVPUriParser::DomainL( const TDesC8& aUri )
       
   457     {
       
   458     SVPDEBUG1( "CSVPUriParser::DomainL In" )
       
   459     
       
   460     HBufC8* ptr = NULL;
       
   461     
       
   462     // Check that URI is complete; it has domain part:
       
   463     if ( aUri.Find( KSVPAt ) < aUri.Length() - 1 )
       
   464         {
       
   465         TInt uriLength = aUri.Length();
       
   466         TInt atPos = aUri.Find( KSVPAt );
       
   467         //__ASSERT_ALWAYS( atPos != KErrNotFound, User::Leave( KErrArgument ) );
       
   468         TPtrC8 domainPart = aUri.Right( uriLength - atPos - 1 );
       
   469         ptr = domainPart.AllocL();
       
   470         }
       
   471     
       
   472     SVPDEBUG1( "CSVPUriParser::DomainL Out" )
       
   473     return ptr;
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // CSVPUriParser::AddSipPrefixL
       
   478 // ---------------------------------------------------------------------------
       
   479 //
       
   480 void CSVPUriParser::AddSipPrefixL( HBufC8*& aUri ) const 
       
   481     {
       
   482     SVPDEBUG1( "CSVPUriParser::AddSipPrefixL In" )
       
   483     aUri = aUri->ReAllocL( aUri->Length() + KSVPSipPrefixLength );
       
   484     aUri->Des().Insert( 0, KSVPSipPrefix );
       
   485     
       
   486     SVPDEBUG1( "CSVPUriParser::AddSipPrefixL Out" )
       
   487     }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // CSVPUriParser::RemoveSipPrefixL
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 void CSVPUriParser::RemoveSipPrefixL( HBufC8*& aUri ) const 
       
   494     {
       
   495     SVPDEBUG1( "CSVPUriParser::RemoveSipPrefixL" )
       
   496     
       
   497     aUri->Des().Delete( 0, KSVPSipPrefixLength );
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // CSVPUriParser::AddSipsPrefixL
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void CSVPUriParser::AddSipsPrefixL( HBufC8*& aUri ) const 
       
   505     {
       
   506     SVPDEBUG1( "CSVPUriParser::AddSipsPrefixL In" )
       
   507     
       
   508     aUri = aUri->ReAllocL( aUri->Length() + KSVPSipsPrefixLength );
       
   509     aUri->Des().Insert( 0, KSVPSipsPrefix );
       
   510     
       
   511     SVPDEBUG1( "CSVPUriParser::AddSipsPrefixL Out" )
       
   512     }
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // CSVPUriParser::RemoveSipsPrefixL
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void CSVPUriParser::RemoveSipsPrefixL( HBufC8*& aUri ) const 
       
   519     {
       
   520     SVPDEBUG1( "CSVPUriParser::RemoveSipsPrefixL" )
       
   521     
       
   522     aUri->Des().Delete( 0, KSVPSipsPrefixLength );
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // CSVPUriParser::AddAtL
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CSVPUriParser::AddAtL( HBufC8*& aUri ) const
       
   530     {
       
   531     SVPDEBUG1( "CSVPUriParser::AddAtL In" )
       
   532     
       
   533     aUri = aUri->ReAllocL( aUri->Length() + KSVPAtLength );
       
   534     aUri->Des().Append( KSVPAt );
       
   535     
       
   536     SVPDEBUG1( "CSVPUriParser::AddAtL Out" )
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // CSVPUriParser::AddDomainL
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 void CSVPUriParser::AddDomainL( 
       
   544     HBufC8*& aUri, const TDesC8& aAOR ) const 
       
   545     {
       
   546     SVPDEBUG1( "CSVPUriParser::AddDomainL In" )
       
   547     
       
   548     // Parse the domain part from the AOR.
       
   549     HBufC8* domainBuf = HBufC8::NewLC( aAOR.Length() ); // CS : 1
       
   550     TInt atPos = aAOR.Find( KSVPAt );
       
   551     
       
   552     // Check, that the "@" character is in AOR.
       
   553     __ASSERT_ALWAYS( KErrNotFound != atPos, User::Leave( KErrArgument ) );
       
   554     // Check, that there is a domain part.
       
   555     __ASSERT_ALWAYS( atPos < aAOR.Length()-1, User::Leave( KErrArgument ) );
       
   556     
       
   557     // Copy the domain to the domain buffer.
       
   558     domainBuf->Des().Append( aAOR.Mid( atPos + 1 ) );
       
   559     
       
   560     // Re-allocate the URI
       
   561     aUri = aUri->ReAllocL( aUri->Length() + domainBuf->Length() );
       
   562     aUri->Des().Append( domainBuf->Des() ); // Append the domain.
       
   563     
       
   564     CleanupStack::PopAndDestroy( domainBuf ); // CS : 0
       
   565     
       
   566     SVPDEBUG1( "CSVPUriParser::AddDomainL Out" )
       
   567     }
       
   568 
       
   569 // ---------------------------------------------------------------------------
       
   570 // CSVPUriParser::CheckLeftBracket
       
   571 // ---------------------------------------------------------------------------
       
   572 //
       
   573 TBool CSVPUriParser::CheckLeftBracket( const TDesC8& aUri ) const
       
   574     {
       
   575     SVPDEBUG1( "CSVPUriParser::CheckLeftBracket" )
       
   576     
       
   577     // The "<" prefix is expected to be at the beginning of the URI.
       
   578     return ( 0 == aUri.Find( KSVPLeftBracketMark ) );
       
   579     }
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // CSVPUriParser::RemoveLeftBracket
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 void CSVPUriParser::RemoveLeftBracket( HBufC8*& aUri ) const 
       
   586     {
       
   587     SVPDEBUG1( "CSVPUriParser::RemoveLeftBracket" )
       
   588     
       
   589     aUri->Des().Delete( 0, KSVPSingleBracketLength );
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------------------------
       
   593 // CSVPUriParser::CheckRightBracket
       
   594 // ---------------------------------------------------------------------------
       
   595 //
       
   596 TBool CSVPUriParser::CheckRightBracket( const TDesC8& aUri ) const
       
   597     {
       
   598     SVPDEBUG1( "CSVPUriParser::CheckRightBracket" )
       
   599     
       
   600     // The ">" prefix is expected to be at the end of the URI.
       
   601     return ( aUri.Length() == ( aUri.Find( KSVPRightBracketMark )
       
   602                                 + KSVPSingleBracketLength ) );
       
   603     }
       
   604 
       
   605 // ---------------------------------------------------------------------------
       
   606 // CSVPUriParser::RemoveRightBracket
       
   607 // ---------------------------------------------------------------------------
       
   608 //
       
   609 void CSVPUriParser::RemoveRightBracket( HBufC8*& aUri ) const 
       
   610     {
       
   611     SVPDEBUG1( "CSVPUriParser::RemoveRightBracket" )
       
   612     
       
   613     aUri->Des().Delete( aUri->Length() - KSVPSingleBracketLength,
       
   614                         KSVPSingleBracketLength );
       
   615     }
       
   616 
       
   617 // ---------------------------------------------------------------------------
       
   618 // CSVPUriParser::EscapeEncodeSipUriL
       
   619 // ---------------------------------------------------------------------------
       
   620 //
       
   621 void CSVPUriParser::EscapeEncodeSipUriL( HBufC8*& aSipUri,
       
   622         EscapeUtils::TEscapeMode aMode )
       
   623     {
       
   624     SVPDEBUG1( "CSVPUriParser::EscapeEncodeSipUriL In" )
       
   625     
       
   626     HBufC8* temp = EscapeUtils::EscapeEncodeL( *aSipUri, aMode );
       
   627     CleanupStack::PushL( temp );
       
   628     aSipUri = aSipUri->ReAllocL( temp->Length() );
       
   629     *aSipUri = *temp;
       
   630     CleanupStack::PopAndDestroy( temp );
       
   631     
       
   632     SVPDEBUG1( "CSVPUriParser::EscapeEncodeSipUriL Out" )
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // CSVPUriParser::EscapeDecodeSipUriL
       
   637 // ---------------------------------------------------------------------------
       
   638 //
       
   639 void CSVPUriParser::EscapeDecodeSipUriL( HBufC8*& aSipUri )
       
   640     {
       
   641     SVPDEBUG1( "CSVPUriParser::EscapeDecodeSipUriL In" )
       
   642     
       
   643     HBufC8* temp = EscapeUtils::EscapeDecodeL( *aSipUri );
       
   644     CleanupStack::PushL( temp ); 
       
   645     
       
   646     if( temp->Length() > aSipUri->Length() )
       
   647         {
       
   648         aSipUri = aSipUri->ReAllocL( temp->Length() );
       
   649         }
       
   650     
       
   651     *aSipUri = *temp;
       
   652     
       
   653     CleanupStack::PopAndDestroy( temp );
       
   654     
       
   655     SVPDEBUG1( "CSVPUriParser::EscapeDecodeSipUriL Out" )
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // CSVPUriParser::ParseDisplayNameL
       
   660 // ---------------------------------------------------------------------------
       
   661 // 
       
   662 HBufC* CSVPUriParser::ParseDisplayNameL( const TDesC8& aRemoteParty )
       
   663     {
       
   664     SVPDEBUG1( "CSVPUriParser::ParseDisplayNameL()" )
       
   665         
       
   666     // Open SIP string pool 
       
   667     SIPStrings::OpenL();
       
   668 
       
   669     // Make a local copy
       
   670     HBufC8* utf8 = HBufC8::NewLC( aRemoteParty.Length() ); // CS:1
       
   671     ( utf8->Des() ).Copy( aRemoteParty );
       
   672     
       
   673     // Escape decode
       
   674     CSVPUriParser::EscapeDecodeSipUriL( utf8 );
       
   675     
       
   676     // Convert from UTF8 to unicode
       
   677     HBufC* unicode16 = EscapeUtils::ConvertToUnicodeFromUtf8L( *utf8 );
       
   678     CleanupStack::PopAndDestroy( utf8 ); // CS:0
       
   679     CleanupStack::PushL( unicode16 ); // CS:1
       
   680     HBufC8* unicode8 = HBufC8::NewL( unicode16->Length() );
       
   681     ( unicode8->Des() ).Copy( *unicode16 );
       
   682     CleanupStack::PopAndDestroy( unicode16 ); // CS:0
       
   683     CleanupStack::PushL( unicode8 ); // CS:1
       
   684     
       
   685     // Create SIP From header
       
   686     CSIPFromHeader* originatorHdr = CSIPFromHeader::DecodeL( *unicode8 );
       
   687     CleanupStack::PopAndDestroy( unicode8 ); // CS:0
       
   688     CleanupStack::PushL( originatorHdr ); // CS:1
       
   689     
       
   690     // Extract and parse display name, format is "..."
       
   691     HBufC8* displayName8 = originatorHdr->SIPAddress().DisplayName().AllocL();
       
   692     CleanupStack::PopAndDestroy( originatorHdr ); // CS:0
       
   693     CleanupStack::PushL( displayName8 ); // CS:1
       
   694 
       
   695     // Convert to 16-bit
       
   696     HBufC* displayName = HBufC::NewL( displayName8->Length() );
       
   697     ( displayName->Des() ).Copy( *displayName8 );
       
   698     CleanupStack::PopAndDestroy( displayName8 ); // CS:0
       
   699     
       
   700     // Close SIP string pool
       
   701     SIPStrings::Close();
       
   702 
       
   703     // Parse: remove quotation marks from both ends
       
   704     displayName->Des().Trim(); 
       
   705     if ( KSVPQuotationMark() == displayName->Left( 1 ) && 
       
   706          KSVPQuotationMark() == displayName->Right( 1 ) )
       
   707         {
       
   708         displayName->Des().Delete( 0, 1 );
       
   709         displayName->Des().Delete( displayName->Length() - 1, 1 );
       
   710         }
       
   711     
       
   712     // Parse: remove backslashes   
       
   713     TLex lex( *displayName );
       
   714     const TChar backslash = '\\';
       
   715     TBool chDeleted = EFalse;
       
   716     while ( !lex.Eos() )
       
   717         {
       
   718         if ( backslash == lex.Peek() && !chDeleted )
       
   719             {
       
   720             // Backslash found, delete it if not consecutive
       
   721             displayName->Des().Delete( lex.Offset() , 1 );
       
   722             lex.Inc();
       
   723             chDeleted = ETrue;
       
   724             }
       
   725         else
       
   726             {
       
   727             // Not a backslash
       
   728             lex.Inc();
       
   729             chDeleted = EFalse;
       
   730             }
       
   731         }
       
   732 
       
   733     // Handle anonymous
       
   734     if ( KErrNotFound != displayName->Des().FindF( KSVPAnonymous ) )
       
   735         {
       
   736         SVPDEBUG1( "CSVPUriParser::ParseDisplayNameL, anonymous case" )
       
   737         displayName->Des().Copy( KNullDesC );
       
   738         }
       
   739 
       
   740     SVPDEBUG2( "CSVPUriParser::ParseDisplayNameL, display name: %S", 
       
   741         displayName )
       
   742     return displayName;
       
   743     }
       
   744 
       
   745 // ---------------------------------------------------------------------------
       
   746 // CSVPUriParser::ParseRemotePartyUriL
       
   747 // ---------------------------------------------------------------------------
       
   748 // 
       
   749 HBufC* CSVPUriParser::ParseRemotePartyUriL( const TDesC8& aRemoteParty )
       
   750     {
       
   751     SVPDEBUG1( "CSVPUriParser::ParseRemotePartyUriL()" )
       
   752         
       
   753     // Open SIP string pool 
       
   754     SIPStrings::OpenL();
       
   755 
       
   756     // Make a local copy
       
   757     HBufC8* utf8 = HBufC8::NewLC( aRemoteParty.Length() ); // CS:1
       
   758     ( utf8->Des() ).Copy( aRemoteParty );
       
   759 
       
   760     // Escape decode
       
   761     CSVPUriParser::EscapeDecodeSipUriL( utf8 );
       
   762     
       
   763     // Convert from UTF8 to unicode
       
   764     HBufC* unicode16 = EscapeUtils::ConvertToUnicodeFromUtf8L( *utf8 );
       
   765     CleanupStack::PopAndDestroy( utf8 ); // CS:0
       
   766     CleanupStack::PushL( unicode16 ); // CS:1
       
   767     HBufC8* unicode8 = HBufC8::NewL( unicode16->Length() );
       
   768     ( unicode8->Des() ).Copy( *unicode16 );
       
   769     CleanupStack::PopAndDestroy( unicode16 ); // CS:0
       
   770     CleanupStack::PushL( unicode8 ); // CS:1
       
   771     
       
   772     // Create SIP From header
       
   773     CSIPFromHeader* originatorHdr = CSIPFromHeader::DecodeL( *unicode8 );
       
   774     CleanupStack::PopAndDestroy( unicode8 ); // CS:0
       
   775     CleanupStack::PushL( originatorHdr ); // CS:1
       
   776         
       
   777     // Extract URI, returned without angle brackets
       
   778     HBufC8* uri8 = originatorHdr->SIPAddress().Uri8().Uri().UriDes().AllocL();
       
   779     CleanupStack::PopAndDestroy( originatorHdr ); // CS:0
       
   780     CleanupStack::PushL( uri8 ); // CS:1
       
   781     
       
   782     // Parse: remove URI parameters
       
   783     TInt posSemiColon = uri8->FindF( KSVPSemiCln );
       
   784     if ( KErrNotFound != posSemiColon )
       
   785         {
       
   786         uri8->Des().Delete( posSemiColon, uri8->Length() - posSemiColon );
       
   787         }
       
   788 
       
   789     // Convert to 16-bit
       
   790     HBufC* uri = HBufC::NewL( uri8->Length() );
       
   791     ( uri->Des() ).Copy( *uri8 );
       
   792     CleanupStack::PopAndDestroy( uri8 ); // CS:0
       
   793 
       
   794     // Handle anonymous
       
   795     if ( KErrNotFound != uri->Des().FindF( KSVPAnonymous ) )
       
   796         {
       
   797         SVPDEBUG1( "CSVPUriParser::ParseRemotePartyUriL, anonymous case" )
       
   798         uri->Des().Copy( KNullDesC );
       
   799         }
       
   800 
       
   801     // Close SIP string pool
       
   802     SIPStrings::Close();
       
   803     
       
   804     SVPDEBUG2( "CSVPUriParser::ParseRemotePartyUriL, URI: %S", uri )
       
   805     return uri;
       
   806     }
       
   807 
       
   808 //  End of File