natplugins/natpnatfwsdpprovider/src/nspcontentparser.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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:  Class implementation for Sdp content parser.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32cmn.h>
       
    19 #include <in_sock.h>
       
    20 #include <sdpcodecstringpool.h>
       
    21 #include <sdpcodecstringconstants.h>
       
    22 #include <sdpdocument.h>
       
    23 #include <sdpconnectionfield.h>
       
    24 #include <sdpattributefield.h>
       
    25 #include <sdpmediafield.h>
       
    26 #include "natfwcandidate.h"
       
    27 #include "natfwcredentials.h"
       
    28 #include "nspcontentparser.h"
       
    29 #include "nspdefs.h"
       
    30 
       
    31 const TInt KAttributesNumber = 7;
       
    32 static const TText8* const AttributeArray[ KAttributesNumber ] =
       
    33     {
       
    34     _S8("candidate"),
       
    35     _S8("remote-candidates"),
       
    36     _S8("ice-lite"),
       
    37     _S8("ice-passive"),
       
    38     _S8("ice-ufrag"),
       
    39     _S8("ice-pwd"),
       
    40     _S8("ice-mismatch")
       
    41     };
       
    42 const TInt KIceAttrCandidateIndex = 0;
       
    43 const TInt KIceAttrRemoteCandidatesIndex = 1;
       
    44 const TInt KIceAttrLiteIndex = 2;
       
    45 const TInt KIceAttrPassiveIndex = 3;
       
    46 const TInt KIceAttrUfragIndex = 4;
       
    47 const TInt KIceAttrPwdIndex = 5;
       
    48 const TInt KIceAttrMismatchIndex = 6;
       
    49 
       
    50 _LIT8( KAttrRtcp, "rtcp" );
       
    51 _LIT8( KAttrEmpty, " " );
       
    52 _LIT8( KFieldSeparator, " " );
       
    53 
       
    54 const TInt KTypeAttrNumber = 9;
       
    55 static const TText8* const CandidateTypeArray[ KTypeAttrNumber ] = 
       
    56     {
       
    57     _S8( "typ" ),
       
    58     _S8( "host" ),
       
    59     _S8( "local" ),
       
    60     _S8( "srflx" ),
       
    61     _S8( "prflx" ),
       
    62     _S8( "relay" ),
       
    63     _S8( "tcp-so" ),
       
    64     _S8( "tcp-act" ),
       
    65     _S8( "tcp-pass" )
       
    66     };
       
    67 const TInt KTypeAttrIndexType = 0;
       
    68 const TInt KTypeAttrIndexHost = 1;
       
    69 const TInt KTypeAttrIndexLocal = 2;
       
    70 const TInt KTypeAttrIndexServerReflex = 3;
       
    71 const TInt KTypeAttrIndexPeerReflex = 4;
       
    72 const TInt KTypeAttrIndexRelay = 5;
       
    73 
       
    74 const TUint KRejecPort = 0;
       
    75 
       
    76 const TInt KMaxCandidateLength = 200;       // Max for candidate creation.
       
    77 const TInt KMaxLengthNumberConversion = 40; // Priority field max length.
       
    78 const TInt KMaxLengthTInetAddr = 40;        // Must support IPv4/IPv6
       
    79 const TInt KMaxLengthOfFQDN = 255;          // For FQDNs
       
    80 const TInt KMaxLengthRtcpField = 60;        // Max for rctp attr. value
       
    81 
       
    82 #define FINDFIELD_L( aField, aMediafield, aFieldarray ) \
       
    83     User::LeaveIfNull( aField = CNSPContentParser::FindMediaField( aMediafield, aFieldarray ) )
       
    84 
       
    85 // ======== MEMBER FUNCTIONS ========
       
    86 // ---------------------------------------------------------------------------
       
    87 // CNSPContentParser::CNSPContentParser
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CNSPContentParser::CNSPContentParser()
       
    91     {
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CNSPContentParser::ConstructL
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CNSPContentParser::ConstructL()
       
   100     {
       
   101     RStringPool pool = SdpCodecStringPool::StringPoolL();
       
   102     
       
   103     // ICE attributes
       
   104     iCandidate = pool.OpenFStringL( 
       
   105             TPtrC8( AttributeArray[ KIceAttrCandidateIndex ] ) );
       
   106     iRemoteCandidates = pool.OpenFStringL( 
       
   107             TPtrC8( AttributeArray[ KIceAttrRemoteCandidatesIndex ] ) );
       
   108     iLite = pool.OpenFStringL( 
       
   109             TPtrC8( AttributeArray[ KIceAttrLiteIndex ] ) );
       
   110     iPassive = pool.OpenFStringL( 
       
   111             TPtrC8( AttributeArray[ KIceAttrPassiveIndex ] ) );
       
   112     iUfrag = pool.OpenFStringL( 
       
   113             TPtrC8( AttributeArray[ KIceAttrUfragIndex ] ) );
       
   114     iPwd = pool.OpenFStringL( 
       
   115             TPtrC8( AttributeArray[ KIceAttrPwdIndex ] ) );
       
   116     iMismatch = pool.OpenFStringL( 
       
   117             TPtrC8( AttributeArray[ KIceAttrMismatchIndex ] ) );
       
   118     
       
   119     // Other
       
   120     iRTCP = pool.OpenFStringL( KAttrRtcp() );    
       
   121     iUdp = pool.StringF( SdpCodecStringConstants::EProtocolUdp,
       
   122                          SdpCodecStringPool::StringTableL() );
       
   123     iTcp = pool.StringF( SdpCodecStringConstants::EProtocolTcp,
       
   124                          SdpCodecStringPool::StringTableL() );
       
   125     iIN = pool.StringF( SdpCodecStringConstants::ENetType,
       
   126                          SdpCodecStringPool::StringTableL() );
       
   127     iIPv4 = pool.StringF( SdpCodecStringConstants::EAddressTypeIP4,
       
   128                          SdpCodecStringPool::StringTableL() );
       
   129     iIPv6 = pool.StringF( SdpCodecStringConstants::EAddressType,
       
   130                          SdpCodecStringPool::StringTableL() );
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CNSPContentParser::NewL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 CNSPContentParser* CNSPContentParser::NewL()
       
   139     {
       
   140     CNSPContentParser* self = CNSPContentParser::NewLC();
       
   141     CleanupStack::Pop( self );
       
   142     return self;
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CNSPContentParser::NewLC
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 CNSPContentParser* CNSPContentParser::NewLC()
       
   151     {
       
   152     CNSPContentParser* self = new( ELeave ) CNSPContentParser;
       
   153     CleanupStack::PushL( self );
       
   154     self->ConstructL();
       
   155     return self;
       
   156     }
       
   157 
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CNSPContentParser::CNSPContentParser
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 CNSPContentParser::~CNSPContentParser()
       
   164     {
       
   165     iCandidate.Close();
       
   166     iRemoteCandidates.Close();
       
   167     iLite.Close();
       
   168     iPassive.Close();
       
   169     iUfrag.Close();
       
   170     iPwd.Close();
       
   171     iMismatch.Close();
       
   172     iRTCP.Close();
       
   173     iUdp.Close();
       
   174     iTcp.Close();
       
   175     iIN.Close();
       
   176     iIPv4.Close();
       
   177     iIPv6.Close();
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CNSPContentParser::IsIceSupported
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TBool CNSPContentParser::IsIceSupported( CSdpDocument& aDocument ) const
       
   186     {
       
   187     RPointerArray<CSdpMediaField>& mediafields = aDocument.MediaFields();
       
   188     
       
   189     const TInt mediafieldcount( mediafields.Count() );
       
   190     for ( TInt index = 0; index < mediafieldcount; index++ )
       
   191         {
       
   192         RPointerArray<CSdpAttributeField>& attributes =
       
   193                 mediafields[index]->AttributeFields();
       
   194         
       
   195         const TInt attributecount( attributes.Count() );
       
   196         for ( TInt jndex = 0; jndex < attributecount; jndex++ )
       
   197             {
       
   198             if ( iCandidate == attributes[jndex]->Attribute() )
       
   199                 {
       
   200                 return ETrue;
       
   201                 }
       
   202             }
       
   203         }
       
   204     
       
   205     return EFalse;
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CNSPContentParser::IsMismatchL
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 TBool CNSPContentParser::IsMismatchL( CSdpDocument& aDocument ) const
       
   214     {
       
   215     const CSdpConnectionField* connField = aDocument.ConnectionField();
       
   216     const TDesC8& address = ( connField ? connField->Address() : KNullDesC8 );
       
   217     RPointerArray<CSdpMediaField>& mediafields = aDocument.MediaFields();
       
   218     
       
   219     TBool mismatch( EFalse );
       
   220     const TInt mediafieldcount( mediafields.Count() );
       
   221     for ( TInt index = 0; index < mediafieldcount && !mismatch; index++ )
       
   222         {
       
   223         const TDesC8& addr = CONN_ADDR( *mediafields[index], address );
       
   224         mismatch = IsMismatchAttribute( *mediafields[index] );
       
   225         
       
   226         if ( !mismatch && IsMismatchL( *mediafields[index], addr ) )
       
   227             {
       
   228             AddMismatchL( *mediafields[index] );
       
   229             mismatch = ETrue;
       
   230             }
       
   231         }
       
   232     
       
   233     return mismatch;
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CNSPContentParser::IsMismatchL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 TBool CNSPContentParser::IsMismatchL( CSdpMediaField& aMediaField,
       
   242         const TDesC8& aAddress ) const
       
   243     {
       
   244     const TDesC8& rtpAddr = CONN_ADDR( aMediaField, aAddress );
       
   245     const TUint rtpPort = aMediaField.Port();
       
   246     
       
   247     RBuf8 rtcpAddr;
       
   248     rtcpAddr.CreateL( KMaxLengthOfFQDN );
       
   249     rtcpAddr.CleanupClosePushL();
       
   250     rtcpAddr = rtpAddr;
       
   251     TUint rtcpPort = rtpPort;
       
   252     TBool isRtcp = FindRTCP( aMediaField, rtcpAddr, rtcpPort );
       
   253     
       
   254     RPointerArray<CNATFWCandidate> remotecand;
       
   255     CleanupStack::PushL( TCleanupItem(
       
   256             CNSPContentParser::CleanupArrayItem, &remotecand ) );
       
   257     
       
   258 	GetCandidatesL( aMediaField, remotecand );
       
   259     
       
   260     const TInt candidatecount( remotecand.Count() );
       
   261     TBool mismatch = ( candidatecount ? ETrue : EFalse );
       
   262     for ( TInt index = 0; index < candidatecount; index++ )
       
   263         {
       
   264         const TDesC8& addr = remotecand[index]->TransportDomainAddr();
       
   265         const TUint port = remotecand[index]->TransportDomainPort();
       
   266         
       
   267         if ( ( !rtpAddr.Compare( addr ) && port == rtpPort ) ||
       
   268              ( isRtcp && !rtcpAddr.Compare( addr ) && port == rtcpPort ) )
       
   269             {
       
   270             mismatch = EFalse;
       
   271             break;
       
   272             }
       
   273         }
       
   274     
       
   275     CleanupStack::PopAndDestroy( &remotecand );
       
   276     CleanupStack::PopAndDestroy( &rtcpAddr );
       
   277     
       
   278     NSPLOG_INT( "CNSPContentParser::IsMismatchL, ret:", mismatch )
       
   279     return mismatch;
       
   280     }
       
   281 
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CNSPContentParser::IsMismatchAttribute
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 TBool CNSPContentParser::IsMismatchAttribute( CSdpMediaField& aMediaField ) const
       
   288     {
       
   289     RPointerArray<CSdpAttributeField>& attributes = aMediaField.AttributeFields();
       
   290     
       
   291     const TInt attributecount( attributes.Count() );
       
   292     for ( TInt index = 0; index < attributecount; index++ )
       
   293         {
       
   294         if ( iMismatch == attributes[index]->Attribute() )
       
   295             {
       
   296             return ETrue;
       
   297             }
       
   298         }
       
   299     
       
   300     return EFalse;
       
   301     }
       
   302 
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CNSPContentParser::IsLiteAttribute
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 TBool CNSPContentParser::IsLiteAttribute( CSdpDocument& aDocument ) const
       
   309     {
       
   310     const RPointerArray<CSdpAttributeField>& attributes =
       
   311             aDocument.AttributeFields();
       
   312     
       
   313     const TInt attributecount( attributes.Count() );
       
   314     for ( TInt index = 0; index < attributecount; index++ )
       
   315         {
       
   316         if ( iLite == attributes[index]->Attribute() )
       
   317             {
       
   318             return ETrue;
       
   319             }
       
   320         }
       
   321     
       
   322     return EFalse;
       
   323     }
       
   324 
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CNSPContentParser::FindRTCP
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 TBool CNSPContentParser::FindRTCP( CSdpMediaField& aMediaField,
       
   331         TDes8& aAddress, TUint& aPort ) const
       
   332     {
       
   333     const RPointerArray<CSdpAttributeField>& attributes =
       
   334             aMediaField.AttributeFields();
       
   335     
       
   336     const TInt attributecount( attributes.Count() );
       
   337     for ( TInt index = 0; index < attributecount; index++ )
       
   338         {
       
   339         if ( iRTCP == attributes[index]->Attribute() )
       
   340             {
       
   341             TLex8 lexer( attributes[index]->Value() );
       
   342             
       
   343             TUint port( KRejecPort );
       
   344             TRAPD( error, LexTDesC8ToTUintL( lexer.NextToken(), port ) );
       
   345             aPort = ( KErrNone == error ? port : aPort );
       
   346             
       
   347             if ( KErrNone == error && !lexer.Eos() )
       
   348                 {
       
   349                 lexer.NextToken(); // nettype, not needed
       
   350                 lexer.NextToken(); // addresstype, not needed
       
   351                 aAddress = lexer.NextToken();
       
   352                 }
       
   353             
       
   354             return ETrue;
       
   355             }
       
   356         }
       
   357     
       
   358     return EFalse;
       
   359     }
       
   360 
       
   361 
       
   362 // ---------------------------------------------------------------------------
       
   363 // CNSPContentParser::ModifyRTCPL
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void CNSPContentParser::ModifyRTCPL( CSdpMediaField& aMediaField,
       
   367         const TDesC8& aAddress, TUint aPort ) const
       
   368     {
       
   369     TInetAddr address;
       
   370     CSdpAttributeField* attr = NULL;
       
   371     const RPointerArray<CSdpAttributeField>& attributes =
       
   372             aMediaField.AttributeFields();
       
   373     
       
   374     const TInt attributecount( attributes.Count() );
       
   375     for ( TInt index = 0; index < attributecount; index++ )
       
   376         {
       
   377         attr = attributes[index];
       
   378         
       
   379         if ( iRTCP == attr->Attribute() )
       
   380             {
       
   381             HBufC8* newattribute = HBufC8::NewLC( KMaxLengthRtcpField );
       
   382             TPtr8 ptr( newattribute->Des() );
       
   383             
       
   384             AppendNumToTDes8L( ptr, aPort );
       
   385             AppendTDesC8ToTDes8L( ptr, iIN.DesC() );
       
   386             InputTDesC8ToTInetAddrL( aAddress, address );
       
   387             AppendTDesC8ToTDes8L( ptr, KAfInet == address.Family() ?
       
   388                     iIPv4.DesC() : iIPv6.DesC() );
       
   389             AppendTDesC8ToTDes8L( ptr, aAddress, EFalse );
       
   390             
       
   391             attr->SetL( attr->Attribute(), newattribute->Des() );
       
   392             CleanupStack::PopAndDestroy( newattribute );
       
   393             break;
       
   394             }
       
   395         }
       
   396     }
       
   397 
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // CNSPContentParser::AddLiteL
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 void CNSPContentParser::AddLiteL( CSdpDocument& aDocument ) const
       
   404     {
       
   405     CSdpAttributeField* attr = CSdpAttributeField::NewLC( iLite, KNullDesC8 );
       
   406     User::LeaveIfError( aDocument.AttributeFields().Append( attr ) );
       
   407     CleanupStack::Pop( attr );
       
   408     }
       
   409 
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // CNSPContentParser::AddMismatchL
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void CNSPContentParser::AddMismatchL( CSdpDocument& aMismatch,
       
   416         CSdpDocument& aMismatched ) const
       
   417     {
       
   418     CSdpMediaField* field = NULL;
       
   419     RPointerArray<CSdpMediaField>& mismatchmedia = aMismatch.MediaFields();
       
   420     RPointerArray<CSdpMediaField>& mismatchedmedia = aMismatched.MediaFields();
       
   421     
       
   422     const TInt mediacount( mismatchmedia.Count() );
       
   423     for ( TInt index = 0; index < mediacount; index++ )
       
   424         {
       
   425         if ( IsMismatchAttribute( *mismatchmedia[index] ) )
       
   426             {
       
   427             FINDFIELD_L( field, *mismatchmedia[index], mismatchedmedia );
       
   428             AddMismatchL( *field );
       
   429             RemoveIceContent( *mismatchmedia[index] );
       
   430             }
       
   431         }
       
   432     }
       
   433 
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // CNSPContentParser::AddMismatchL
       
   437 // ---------------------------------------------------------------------------
       
   438 //
       
   439 void CNSPContentParser::AddMismatchL( CSdpMediaField& aMediaField ) const
       
   440     {
       
   441     CSdpAttributeField* attr = CSdpAttributeField::NewLC( iMismatch, KNullDesC8 );
       
   442     User::LeaveIfError( aMediaField.AttributeFields().Append( attr ) );
       
   443     CleanupStack::Pop( attr );
       
   444     }
       
   445 
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CNSPContentParser::AddCandidatesL
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 void CNSPContentParser::AddCandidatesL( CSdpMediaField& aMediaField,
       
   452         const RPointerArray<CNATFWCandidate>& aCandidates ) const
       
   453     {
       
   454     CSdpAttributeField* attr = NULL;
       
   455     RPointerArray<CSdpAttributeField>& attributeArray =
       
   456             aMediaField.AttributeFields();
       
   457     
       
   458     const TInt candidatecount( aCandidates.Count() );
       
   459     for ( TInt index = 0; index < candidatecount; index++ )
       
   460         {
       
   461         TRAPD( error, attr = EncodeCandidateLineL( *aCandidates[index] ) )
       
   462         User::LeaveIfError( KErrNone == error ?
       
   463                 attributeArray.Append( attr ) : error );
       
   464         }
       
   465     }
       
   466 
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 // CNSPContentParser::AddRemoteCandidatesL
       
   470 // ---------------------------------------------------------------------------
       
   471 //
       
   472 void CNSPContentParser::AddRemoteCandidatesL( CSdpMediaField& aMediaField,
       
   473         const RPointerArray<CNATFWCandidate>& aCandidates ) const
       
   474     {
       
   475     RPointerArray<CSdpAttributeField>& attributeArray =
       
   476             aMediaField.AttributeFields();
       
   477     
       
   478     CSdpAttributeField* attribute = EncodeRemoteCandidatesL( aCandidates );
       
   479     CleanupStack::PushL( attribute );
       
   480     User::LeaveIfError( attributeArray.Append( attribute ) );
       
   481     CleanupStack::Pop( attribute );
       
   482     }
       
   483 
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // CNSPContentParser::AddCredentialsL
       
   487 // ---------------------------------------------------------------------------
       
   488 //
       
   489 void CNSPContentParser::AddCredentialsL( CSdpMediaField& aMediaField,
       
   490         const CNATFWCredentials& aCredentials ) const
       
   491     {
       
   492     RPointerArray<CSdpAttributeField>& attributeArray =
       
   493             aMediaField.AttributeFields();
       
   494     
       
   495     CSdpAttributeField* user = EncodeUfragL( aCredentials );
       
   496     CleanupStack::PushL( user );
       
   497     User::LeaveIfError( attributeArray.Append( user ) );
       
   498     CleanupStack::Pop( user );
       
   499     
       
   500     CSdpAttributeField* pwd = EncodePwdL( aCredentials );
       
   501     CleanupStack::PushL( pwd );
       
   502     User::LeaveIfError( attributeArray.Append( pwd ) );
       
   503     CleanupStack::Pop( pwd );
       
   504     }
       
   505 
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // CNSPContentParser::AddCredentialsL
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 void CNSPContentParser::AddCredentialsL( CSdpDocument& aDocument,
       
   512         const CNATFWCredentials& aCredentials ) const
       
   513     {
       
   514     RPointerArray<CSdpAttributeField>& attributeArray =
       
   515             aDocument.AttributeFields();
       
   516     
       
   517     CSdpAttributeField* user = EncodeUfragL( aCredentials );
       
   518     CleanupStack::PushL( user );
       
   519     User::LeaveIfError( attributeArray.Append( user ) );
       
   520     CleanupStack::Pop( user );
       
   521     
       
   522     CSdpAttributeField* pwd = EncodePwdL( aCredentials );
       
   523     CleanupStack::PushL( pwd );
       
   524     User::LeaveIfError( attributeArray.Append( pwd ) );
       
   525     CleanupStack::Pop( pwd );
       
   526     }
       
   527 
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // CNSPContentParser::GetCandidatesL
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 TInt CNSPContentParser::GetCandidatesL( CSdpMediaField& aMediaField,
       
   534         RPointerArray<CNATFWCandidate>& aCandidates ) const
       
   535     {
       
   536     TInt warning = KErrNone;
       
   537     CNATFWCandidate* cand = NULL;
       
   538     const RPointerArray<CSdpAttributeField>& attrArray =
       
   539             aMediaField.AttributeFields();
       
   540     
       
   541     const TInt attributecount( attrArray.Count() );
       
   542     for ( TInt index = 0; index < attributecount; index++ )
       
   543         {
       
   544         if ( iCandidate == attrArray[index]->Attribute() )
       
   545             {
       
   546             cand = CNATFWCandidate::NewLC();
       
   547             
       
   548             TRAPD( error, DecodeCandidateLineL( *attrArray[index], *cand ) );
       
   549             
       
   550             if ( KErrNone == error )
       
   551                 {
       
   552                 User::LeaveIfError( aCandidates.Append( cand ) );
       
   553                 CleanupStack::Pop( cand );
       
   554                 }
       
   555             else if ( KErrNoMemory == error )
       
   556             	{
       
   557             	User::Leave( KErrNoMemory );
       
   558             	}
       
   559             else
       
   560                 {
       
   561                 warning = error;
       
   562                 CleanupStack::PopAndDestroy( cand );
       
   563                 }
       
   564             }
       
   565         }
       
   566     
       
   567     return warning;
       
   568     }
       
   569 
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // CNSPContentParser::GetRemoteCandidatesL
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 TInt CNSPContentParser::GetRemoteCandidatesL( CSdpDocument& aDocument,
       
   576         RPointerArray<CNATFWCandidate>& aRemoteCands ) const
       
   577     {
       
   578     const RPointerArray<CSdpMediaField>& mediafieldArray =
       
   579             aDocument.MediaFields();
       
   580     
       
   581     const TInt mediafieldcount( mediafieldArray.Count() );
       
   582     for ( TInt index = 0; index < mediafieldcount; index++ )
       
   583         {
       
   584         GetRemoteCandidatesL( *mediafieldArray[index], aRemoteCands );
       
   585         }
       
   586     
       
   587     return KErrNone;
       
   588     }
       
   589 
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // CNSPContentParser::GetRemoteCandidatesL
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 TInt CNSPContentParser::GetRemoteCandidatesL( CSdpMediaField& aMediaField,
       
   596         RPointerArray<CNATFWCandidate>& aRemoteCands ) const
       
   597     {
       
   598     const RPointerArray<CSdpAttributeField>& attributeArray =
       
   599             aMediaField.AttributeFields();
       
   600     
       
   601     const TInt attributecount( attributeArray.Count() );
       
   602     for ( TInt index = 0; index < attributecount; index++ )
       
   603         {
       
   604         if ( iRemoteCandidates == attributeArray[index]->Attribute() )
       
   605             {
       
   606             DecodeRemoteCandidatesL( attributeArray[index]->Value(),
       
   607                                      aRemoteCands );
       
   608             }
       
   609         }
       
   610     
       
   611     return KErrNone;
       
   612     }
       
   613 
       
   614 
       
   615 // ---------------------------------------------------------------------------
       
   616 // CNSPContentParser::GetCredentialsL
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 TInt CNSPContentParser::GetCredentialsL( CSdpMediaField& aMediaField,
       
   620         CNATFWCredentials& aCredentials ) const
       
   621     {
       
   622     const RPointerArray<CSdpAttributeField>& attributeArray =
       
   623             aMediaField.AttributeFields();
       
   624     
       
   625     const TInt attributecount( attributeArray.Count() );
       
   626     for ( TInt index = 0; index < attributecount; index++ )
       
   627         {
       
   628         if ( iUfrag == attributeArray[index]->Attribute() )
       
   629             {
       
   630             DecodeUfragL( *attributeArray[index], aCredentials );
       
   631             }
       
   632         else if ( iPwd == attributeArray[index]->Attribute() )
       
   633             {
       
   634             DecodePwdL( *attributeArray[index], aCredentials );
       
   635             }
       
   636         else
       
   637             {
       
   638             // Nothing to do here
       
   639             }
       
   640         }
       
   641     
       
   642     return KErrNone;
       
   643     }
       
   644 
       
   645 
       
   646 // ---------------------------------------------------------------------------
       
   647 // CNSPContentParser::GetCredentialsL
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 TInt CNSPContentParser::GetCredentialsL( CSdpDocument& aDocument,
       
   651         CNATFWCredentials& aCredentials ) const
       
   652     {
       
   653     const RPointerArray<CSdpAttributeField>& attributeArray =
       
   654             aDocument.AttributeFields();
       
   655     
       
   656     const TInt attributecount( attributeArray.Count() );
       
   657     for ( TInt index = 0; index < attributecount; index++ )
       
   658         {
       
   659         if ( iUfrag == attributeArray[index]->Attribute() )
       
   660             {
       
   661             DecodeUfragL( *attributeArray[index], aCredentials );
       
   662             }
       
   663         else if ( iPwd == attributeArray[index]->Attribute() )
       
   664             {
       
   665             DecodePwdL( *attributeArray[index], aCredentials );
       
   666             }
       
   667         else
       
   668             {
       
   669             // Nothing to do here
       
   670             }
       
   671         }
       
   672     
       
   673     return KErrNone;
       
   674     }
       
   675 
       
   676 
       
   677 // ---------------------------------------------------------------------------
       
   678 // CNSPContentParser::RemoveIceContent
       
   679 // ---------------------------------------------------------------------------
       
   680 //
       
   681 void CNSPContentParser::RemoveIceContent( CSdpDocument& aDocument ) const
       
   682     {
       
   683     RPointerArray<CSdpAttributeField>& attributes = aDocument.AttributeFields();
       
   684     
       
   685     for ( TInt index = 0; index < attributes.Count() ; )
       
   686         {
       
   687         RStringF attribute = attributes[index]->Attribute();
       
   688         
       
   689         if ( iCandidate == attribute ||
       
   690              iRemoteCandidates == attribute ||
       
   691              iLite == attribute ||
       
   692              iPassive == attribute ||
       
   693              iUfrag == attribute ||
       
   694              iPwd == attribute || 
       
   695              iMismatch == attribute )
       
   696             {
       
   697             delete ( attributes[index] );
       
   698             attributes.Remove( index );
       
   699             attributes.Compress();
       
   700             }
       
   701         else
       
   702             {
       
   703             index++;
       
   704             }
       
   705         }
       
   706     
       
   707     RPointerArray<CSdpMediaField>& mediafields = aDocument.MediaFields();
       
   708     
       
   709     const TInt mediafieldcount( mediafields.Count() );
       
   710     for ( TInt index = 0; index < mediafieldcount ; index++ )
       
   711         {
       
   712         RemoveIceContent( *mediafields[index] );
       
   713         }
       
   714     }
       
   715 
       
   716 
       
   717 // ---------------------------------------------------------------------------
       
   718 // CNSPContentParser::RemoveIceContent
       
   719 // ---------------------------------------------------------------------------
       
   720 //
       
   721 void CNSPContentParser::RemoveIceContent( CSdpMediaField& aMediaField ) const
       
   722     {
       
   723     RPointerArray<CSdpAttributeField>& attributes = aMediaField.AttributeFields();
       
   724     
       
   725     for ( TInt index = 0; index < attributes.Count() ; )
       
   726         {
       
   727         RStringF attribute = attributes[index]->Attribute();
       
   728         
       
   729         if ( iCandidate == attribute ||
       
   730              iRemoteCandidates == attribute ||
       
   731              iLite == attribute ||
       
   732              iPassive == attribute ||
       
   733              iUfrag == attribute ||
       
   734              iPwd == attribute ||
       
   735              iMismatch == attribute )
       
   736             {
       
   737             delete ( attributes[index] );
       
   738             attributes.Remove( index );
       
   739             attributes.Compress();
       
   740             }
       
   741         else
       
   742             {
       
   743             index++;
       
   744             }
       
   745         }
       
   746     }
       
   747 
       
   748 
       
   749 // ---------------------------------------------------------------------------
       
   750 // CNSPContentParser::EncodeCandidateLineL
       
   751 // ---------------------------------------------------------------------------
       
   752 //
       
   753 CSdpAttributeField* CNSPContentParser::EncodeCandidateLineL(
       
   754         const CNATFWCandidate& aCandidate ) const
       
   755     {
       
   756     HBufC8* content = HBufC8::NewLC( KMaxCandidateLength );
       
   757     TPtr8 ptr( content->Des() );
       
   758     
       
   759     // 1. Foundation
       
   760     AppendTDesC8ToTDes8L( ptr, aCandidate.Foundation() );
       
   761     
       
   762     // 2. Component Id
       
   763     AppendNumToTDes8L( ptr, aCandidate.ComponentId() );
       
   764     
       
   765     // 3. Protocol
       
   766     AppendProtocolToTDes8L( ptr, aCandidate.TransportProtocol() );
       
   767     
       
   768     // 4. Priority
       
   769     AppendNumToTDes8L( ptr, aCandidate.Priority() );
       
   770     
       
   771     // 5. IP address & Port
       
   772     AppendTDesC8ToTDes8L( ptr, aCandidate.TransportDomainAddr() );
       
   773     AppendNumToTDes8L( ptr, aCandidate.TransportDomainPort() );
       
   774     
       
   775     // 6. Type
       
   776     AppendTypeToTDes8L( ptr, aCandidate.Type(), EFalse );
       
   777     
       
   778     // 7. Optional information, i.e. related address and etc.
       
   779     
       
   780     CSdpAttributeField* attribute = CSdpAttributeField::NewL( iCandidate, *content );
       
   781     CleanupStack::PopAndDestroy( content );
       
   782     
       
   783     return attribute;
       
   784     }
       
   785 
       
   786 
       
   787 // ---------------------------------------------------------------------------
       
   788 // CNSPContentParser::DecodeCandidateLineL
       
   789 // ---------------------------------------------------------------------------
       
   790 //
       
   791 void CNSPContentParser::DecodeCandidateLineL(
       
   792         const CSdpAttributeField& aAttribute, CNATFWCandidate& aCandidate ) const
       
   793     {
       
   794     TLex8 lex( aAttribute.Value() );
       
   795     TUint unsignedInteger( 0 );
       
   796     
       
   797     // 1. Foundation( char(s) )
       
   798     aCandidate.SetFoundationL( lex.NextToken() );
       
   799     
       
   800     // 2. Component Id( single digit )
       
   801     LexTDesC8ToTUintL( lex.NextToken(), unsignedInteger );
       
   802     aCandidate.SetComponentId( unsignedInteger );
       
   803     
       
   804     // 3. Protocol( string: UDP, TCP )
       
   805     TUint protocol( KProtocolInetUdp );
       
   806     SolveTransportProtocolL( lex.NextToken(), protocol );
       
   807     aCandidate.SetTransportProtocol( protocol );
       
   808     
       
   809     // 4. Priority( multiple digits, positive large integer )
       
   810     LexTDesC8ToTUintL( lex.NextToken(), unsignedInteger );
       
   811     aCandidate.SetPriority( unsignedInteger );
       
   812     
       
   813     // 5. IP address & Port
       
   814     TPtrC8 address = lex.NextToken();
       
   815     LexTDesC8ToTUintL( lex.NextToken(), unsignedInteger );
       
   816     aCandidate.SetTransportDomainAddrL( address, unsignedInteger );
       
   817     
       
   818     // 6. Type( typ "value" )
       
   819     CNATFWCandidate::TCandidateType type;
       
   820     TPtrC8 typ = lex.NextToken();
       
   821     TPtrC8 value = lex.NextToken();
       
   822     SolveCandidateTypeL( typ, value, type );
       
   823     aCandidate.SetType( type );
       
   824     
       
   825     // 7. Optional information, i.e. related address and etc.
       
   826     }
       
   827 
       
   828 
       
   829 // ---------------------------------------------------------------------------
       
   830 // CNSPContentParser::EncodeRemoteCandidatesL
       
   831 // ---------------------------------------------------------------------------
       
   832 //
       
   833 CSdpAttributeField* CNSPContentParser::EncodeRemoteCandidatesL(
       
   834         const RPointerArray<CNATFWCandidate>& aCandidates ) const
       
   835     {
       
   836     HBufC8* content = HBufC8::NewLC( KMaxCandidateLength );
       
   837     TPtr8 ptr( content->Des() );
       
   838     
       
   839     const TInt remotecandidatecount( aCandidates.Count() );
       
   840     for ( TInt index = 0; index < remotecandidatecount; index++ )
       
   841         {
       
   842         EncodeRemoteCandidateL( ptr, *aCandidates[index] );
       
   843         }
       
   844 
       
   845     CSdpAttributeField* attribute = CSdpAttributeField::NewL(
       
   846             iRemoteCandidates, *content );
       
   847     CleanupStack::PopAndDestroy( content );
       
   848     return attribute;
       
   849     }
       
   850 
       
   851 
       
   852 // ---------------------------------------------------------------------------
       
   853 // CNSPContentParser::EncodeRemoteCandidatesL
       
   854 // ---------------------------------------------------------------------------
       
   855 //
       
   856 void CNSPContentParser::EncodeRemoteCandidateL( TDes8& aBuffer,
       
   857         const CNATFWCandidate& aCandidate ) const
       
   858     {
       
   859     // 1. Component Id( single digit )
       
   860     AppendNumToTDes8L( aBuffer, aCandidate.ComponentId() );
       
   861     
       
   862     // 2. IP address & Port
       
   863     AppendTDesC8ToTDes8L( aBuffer, aCandidate.TransportDomainAddr() );
       
   864     AppendNumToTDes8L( aBuffer, aCandidate.TransportDomainPort() );
       
   865     }
       
   866 
       
   867 
       
   868 // ---------------------------------------------------------------------------
       
   869 // CNSPContentParser::DecodeRemoteCandidatesL
       
   870 // ---------------------------------------------------------------------------
       
   871 //
       
   872 void CNSPContentParser::DecodeRemoteCandidatesL( const TDesC8& aValue,
       
   873         RPointerArray<CNATFWCandidate>& aCandidates ) const
       
   874     {
       
   875     TLex8 lex( aValue );
       
   876     TUint unsignedInteger( 0 );
       
   877     
       
   878     CNATFWCandidate* candidate = CNATFWCandidate::NewLC();
       
   879     
       
   880     // 1. Component Id( single digit )
       
   881     LexTDesC8ToTUintL( lex.NextToken(), unsignedInteger );
       
   882     candidate->SetComponentId( unsignedInteger );
       
   883     
       
   884     // 2. IP address & Port
       
   885     const TPtrC8 address = lex.NextToken();
       
   886     LexTDesC8ToTUintL( lex.NextToken(), unsignedInteger );
       
   887     candidate->SetTransportDomainAddrL( address, unsignedInteger );
       
   888     
       
   889     User::LeaveIfError( aCandidates.Append( candidate ) );
       
   890     CleanupStack::Pop( candidate );
       
   891     
       
   892     if ( !lex.Eos() )
       
   893         {
       
   894         DecodeRemoteCandidatesL( lex.Remainder(), aCandidates );
       
   895         }
       
   896     }
       
   897 
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 // CNSPContentParser::EncodeUfragL
       
   901 // ---------------------------------------------------------------------------
       
   902 //
       
   903 CSdpAttributeField* CNSPContentParser::EncodeUfragL(
       
   904         const CNATFWCredentials& aCredentials ) const
       
   905     {
       
   906     CSdpAttributeField* attribute = NULL;
       
   907     const TDesC8& username = aCredentials.Username();
       
   908     
       
   909     if ( !username.Length() )
       
   910         {
       
   911         attribute = CSdpAttributeField::NewL( iUfrag, KAttrEmpty );
       
   912         }
       
   913     else
       
   914         {
       
   915         attribute = CSdpAttributeField::NewL( iUfrag, username );
       
   916         }
       
   917     
       
   918     return attribute;
       
   919     }
       
   920 
       
   921 
       
   922 // ---------------------------------------------------------------------------
       
   923 // CNSPContentParser::DecodeUfragL
       
   924 // ---------------------------------------------------------------------------
       
   925 //
       
   926 void CNSPContentParser::DecodeUfragL( const CSdpAttributeField& aAttribute,
       
   927         CNATFWCredentials& aCredentials ) const
       
   928     {
       
   929     aCredentials.SetUsernameL( aAttribute.Value() );
       
   930     }
       
   931 
       
   932 
       
   933 // ---------------------------------------------------------------------------
       
   934 // CNSPContentParser::EncodePwdL
       
   935 // ---------------------------------------------------------------------------
       
   936 //
       
   937 CSdpAttributeField* CNSPContentParser::EncodePwdL(
       
   938         const CNATFWCredentials& aCredentials ) const
       
   939     {
       
   940     CSdpAttributeField* attribute = NULL;
       
   941     const TDesC8& password = aCredentials.Password();
       
   942     
       
   943     if ( !password.Length() )
       
   944         {
       
   945         attribute = CSdpAttributeField::NewL( iPwd, KAttrEmpty );
       
   946         }
       
   947     else
       
   948         {
       
   949         attribute = CSdpAttributeField::NewL( iPwd, password );
       
   950         }
       
   951     
       
   952     return attribute;
       
   953     }
       
   954 
       
   955 
       
   956 // ---------------------------------------------------------------------------
       
   957 // CNSPContentParser::DecodePwdL
       
   958 // ---------------------------------------------------------------------------
       
   959 //
       
   960 void CNSPContentParser::DecodePwdL( const CSdpAttributeField& aAttribute,
       
   961         CNATFWCredentials& aCredentials ) const
       
   962     {
       
   963     aCredentials.SetPasswordL( aAttribute.Value() );
       
   964     }
       
   965 
       
   966 
       
   967 // ---------------------------------------------------------------------------
       
   968 // CNSPContentParser::LexTDesC8ToTUintL
       
   969 // ---------------------------------------------------------------------------
       
   970 //
       
   971 void CNSPContentParser::LexTDesC8ToTUintL( const TDesC8& aDesC8,
       
   972         TUint& aUint ) const
       
   973     {
       
   974     TLex8 lex8( aDesC8 );
       
   975     User::LeaveIfError( lex8.Val( aUint, EDecimal ) );
       
   976     }
       
   977 
       
   978 
       
   979 // ---------------------------------------------------------------------------
       
   980 // CNSPContentParser::SolveTransportProtocolL
       
   981 // ---------------------------------------------------------------------------
       
   982 //
       
   983 void CNSPContentParser::SolveTransportProtocolL( const TDesC8& aDesC8,
       
   984         TUint& aProto ) const
       
   985     {
       
   986     if ( !aDesC8.CompareF( iUdp.DesC() ) )
       
   987         {
       
   988         aProto = KProtocolInetUdp;
       
   989         }
       
   990     else if ( !aDesC8.CompareF( iTcp.DesC() ) )
       
   991         {
       
   992         aProto = KProtocolInetTcp;
       
   993         }
       
   994     else
       
   995         {
       
   996         User::Leave( KErrArgument );
       
   997         }
       
   998     }
       
   999 
       
  1000 
       
  1001 // ---------------------------------------------------------------------------
       
  1002 // CNSPContentParser::InputTDesC8ToTInetAddrL
       
  1003 // ---------------------------------------------------------------------------
       
  1004 //
       
  1005 void CNSPContentParser::InputTDesC8ToTInetAddrL( const TDesC8& aDesC8,
       
  1006         TInetAddr& aAddress ) const
       
  1007     {
       
  1008     HBufC* buffer = HBufC::NewLC( aDesC8.Length() );
       
  1009     TPtr ptr( buffer->Des() );
       
  1010     ptr.Copy( aDesC8 );
       
  1011     User::LeaveIfError( aAddress.Input( buffer->Des() ) );
       
  1012     CleanupStack::PopAndDestroy( buffer );
       
  1013     }
       
  1014 
       
  1015 
       
  1016 // ---------------------------------------------------------------------------
       
  1017 // CNSPContentParser::SolveCandidateTypeL
       
  1018 // ---------------------------------------------------------------------------
       
  1019 //    
       
  1020 void CNSPContentParser::SolveCandidateTypeL( const TDesC8& aDesC8Typ,
       
  1021         const TDesC8& aDesC8Value, CNATFWCandidate::TCandidateType& aType ) const
       
  1022     {
       
  1023     TPtrC8 type( CandidateTypeArray[ KTypeAttrIndexType ] );
       
  1024     User::LeaveIfError( !aDesC8Typ.CompareF( type ) );
       
  1025     
       
  1026     const TInt candidatetypeindex = FindCandidateType( aDesC8Value );
       
  1027     
       
  1028     if ( KErrNotFound == candidatetypeindex )
       
  1029         {
       
  1030         NSPLOG_STR(
       
  1031         "CNSPContentParser::SolveCandidateTypeL(),KErrNotFound" )
       
  1032         User::Leave( KErrArgument );
       
  1033         }
       
  1034     
       
  1035     switch ( candidatetypeindex )
       
  1036         {
       
  1037         case KTypeAttrIndexHost:
       
  1038         case KTypeAttrIndexLocal:
       
  1039             {
       
  1040             aType = CNATFWCandidate::EHost;
       
  1041             break;
       
  1042             }
       
  1043         
       
  1044         case KTypeAttrIndexServerReflex:
       
  1045             {
       
  1046             aType = CNATFWCandidate::EServerReflexive;
       
  1047             break;
       
  1048             }
       
  1049         
       
  1050         case KTypeAttrIndexPeerReflex:
       
  1051             {
       
  1052             aType = CNATFWCandidate::EPeerReflexive;
       
  1053             break;
       
  1054             }
       
  1055         
       
  1056         case KTypeAttrIndexRelay:
       
  1057             {
       
  1058             aType = CNATFWCandidate::ERelay;
       
  1059             break;
       
  1060             }
       
  1061         
       
  1062         default:
       
  1063             {
       
  1064             NSPLOG_STR(
       
  1065             "CNSPContentParser::SolveCandidateTypeL(),default!" )
       
  1066             User::Leave( KErrArgument ); // should never come here
       
  1067             break;
       
  1068             }
       
  1069         }
       
  1070     }
       
  1071 
       
  1072 
       
  1073 // ---------------------------------------------------------------------------
       
  1074 // CNSPContentParser::FindCandidateType
       
  1075 // ---------------------------------------------------------------------------
       
  1076 //
       
  1077 TInt CNSPContentParser::FindCandidateType( const TDesC8& aDesC8Value ) const
       
  1078     {
       
  1079     for ( TInt index = 0; index < KTypeAttrNumber; index++ )
       
  1080         {
       
  1081         if ( !aDesC8Value.CompareF( TPtrC8( CandidateTypeArray[index] ) ) )
       
  1082             {
       
  1083             return index;
       
  1084             }
       
  1085         }
       
  1086     
       
  1087     return KErrNotFound;
       
  1088     }
       
  1089 
       
  1090 
       
  1091 // ---------------------------------------------------------------------------
       
  1092 // CNSPContentParser::FindCandidateType
       
  1093 // ---------------------------------------------------------------------------
       
  1094 //
       
  1095 TInt CNSPContentParser::FindCandidateTypeString(
       
  1096         const CNATFWCandidate::TCandidateType& aType ) const
       
  1097     {
       
  1098     switch ( aType )
       
  1099         {
       
  1100         case CNATFWCandidate::EHost:
       
  1101             {
       
  1102             return KTypeAttrIndexHost;
       
  1103             }
       
  1104         
       
  1105         case CNATFWCandidate::EServerReflexive:
       
  1106             {
       
  1107             return KTypeAttrIndexServerReflex;
       
  1108             }
       
  1109         
       
  1110         case CNATFWCandidate::EPeerReflexive:
       
  1111             {
       
  1112             return KTypeAttrIndexPeerReflex;
       
  1113             }
       
  1114         
       
  1115         case CNATFWCandidate::ERelay:
       
  1116             {
       
  1117             return KTypeAttrIndexRelay;
       
  1118             }
       
  1119         
       
  1120         default:
       
  1121             {
       
  1122             return KErrNotFound;
       
  1123             }
       
  1124         }
       
  1125     }
       
  1126 
       
  1127 
       
  1128 // ---------------------------------------------------------------------------
       
  1129 // CNSPContentParser::AppendTDesC8ToTDes8L
       
  1130 // ---------------------------------------------------------------------------
       
  1131 //
       
  1132 void CNSPContentParser::AppendTDesC8ToTDes8L( TDes8& aDes8,
       
  1133         const TDesC8& aDesC8, TBool aAddFieldSeparator ) const
       
  1134     {
       
  1135     LeaveIfTooLongL( aDes8, aDesC8.Length() );
       
  1136     aDes8.Append( aDesC8 );
       
  1137     
       
  1138     if ( aAddFieldSeparator )
       
  1139         {
       
  1140         LeaveIfTooLongL( aDes8, 1 );
       
  1141         aDes8.Append( KFieldSeparator );
       
  1142         }
       
  1143     }
       
  1144 
       
  1145 
       
  1146 // ---------------------------------------------------------------------------
       
  1147 // CNSPContentParser::AppendNumToTDes8L
       
  1148 // ---------------------------------------------------------------------------
       
  1149 //
       
  1150 void CNSPContentParser::AppendNumToTDes8L( TDes8& aDes8,
       
  1151         TUint aNumber, TBool aAddFieldSeparator ) const
       
  1152     {
       
  1153     TBuf< KMaxLengthNumberConversion > buffer;
       
  1154     buffer.AppendNum( aNumber, EDecimal );
       
  1155     LeaveIfTooLongL( aDes8, buffer.Length() );
       
  1156     aDes8.AppendNum( aNumber, EDecimal );
       
  1157     
       
  1158     if ( aAddFieldSeparator )
       
  1159         {
       
  1160         LeaveIfTooLongL( aDes8, 1 );
       
  1161         aDes8.Append( KFieldSeparator );
       
  1162         }
       
  1163     }
       
  1164 
       
  1165 
       
  1166 // ---------------------------------------------------------------------------
       
  1167 // CNSPContentParser::AppendProtocolToTDes8L
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //
       
  1170 void CNSPContentParser::AppendProtocolToTDes8L( TDes8& aDes8,
       
  1171         const TUint& aProtocol, TBool aAddFieldSeparator ) const
       
  1172     {
       
  1173     LeaveIfTooLongL( aDes8, Max( iUdp.DesC().Length(), iTcp.DesC().Length() ) );
       
  1174     
       
  1175     if ( KProtocolInetUdp == aProtocol )
       
  1176         {
       
  1177         aDes8.Append( iUdp.DesC() );
       
  1178         }
       
  1179     else if ( KProtocolInetTcp == aProtocol )
       
  1180         {
       
  1181         aDes8.Append( iTcp.DesC() );
       
  1182         }
       
  1183     else // EUndefined
       
  1184         {
       
  1185         User::Leave( KErrNotSupported );
       
  1186         }
       
  1187     
       
  1188     if ( aAddFieldSeparator )
       
  1189         {
       
  1190         LeaveIfTooLongL( aDes8, 1 );
       
  1191         aDes8.Append( KFieldSeparator );
       
  1192         }
       
  1193     }
       
  1194 
       
  1195 
       
  1196 // ---------------------------------------------------------------------------
       
  1197 // CNSPContentParser::AppendTInetAddrToTDes8L
       
  1198 // ---------------------------------------------------------------------------
       
  1199 //
       
  1200 void CNSPContentParser::AppendTInetAddrToTDes8L( TDes8& aDes8,
       
  1201         const TInetAddr& aAddress, TBool aAddFieldSeparator ) const
       
  1202     {
       
  1203     TBuf<KMaxLengthTInetAddr> buffer;
       
  1204     aAddress.Output( buffer );
       
  1205     LeaveIfTooLongL( aDes8, buffer.Length() );
       
  1206     aDes8.Append( buffer );
       
  1207     
       
  1208     if ( aAddFieldSeparator )
       
  1209         {
       
  1210         LeaveIfTooLongL( aDes8, 1 );
       
  1211         aDes8.Append( KFieldSeparator );
       
  1212         }
       
  1213     }
       
  1214 
       
  1215 
       
  1216 // ---------------------------------------------------------------------------
       
  1217 // CNSPContentParser::AppendTypeToTDes8L
       
  1218 // ---------------------------------------------------------------------------
       
  1219 //
       
  1220 void CNSPContentParser::AppendTypeToTDes8L( TDes8& aDes8,
       
  1221         const CNATFWCandidate::TCandidateType& aType,
       
  1222         TBool aAddFieldSeparator ) const
       
  1223     {
       
  1224     const TInt candidatetypeindex = FindCandidateTypeString( aType );
       
  1225     
       
  1226     if ( KErrNotFound != candidatetypeindex )
       
  1227         {
       
  1228         TPtrC8 type( CandidateTypeArray[ KTypeAttrIndexType ] );
       
  1229         TPtrC8 value( CandidateTypeArray[ candidatetypeindex ] );
       
  1230         
       
  1231         LeaveIfTooLongL( aDes8, type.Length() + 
       
  1232                 KFieldSeparator().Length() + value.Length() );
       
  1233         
       
  1234         aDes8.Append( type );
       
  1235         aDes8.Append( KFieldSeparator );
       
  1236         aDes8.Append( value );
       
  1237         
       
  1238         if ( aAddFieldSeparator )
       
  1239             {
       
  1240             LeaveIfTooLongL( aDes8, 1 );
       
  1241             aDes8.Append( KFieldSeparator );
       
  1242             }
       
  1243         }
       
  1244     else
       
  1245         {
       
  1246         NSPLOG_STR(
       
  1247         "CNSPContentParser::AppendTypeToTDes8L(),KErrNotFound!" )
       
  1248         User::Leave( KErrArgument );
       
  1249         }
       
  1250     }
       
  1251 
       
  1252 
       
  1253 // ---------------------------------------------------------------------------
       
  1254 // CNSPContentParser::LeaveIfTooLongL
       
  1255 // ---------------------------------------------------------------------------
       
  1256 //
       
  1257 void CNSPContentParser::LeaveIfTooLongL( const TDes8& aDes8,
       
  1258         const TInt aLength ) const
       
  1259     {
       
  1260     const TInt free = aDes8.MaxLength() - aDes8.Length();
       
  1261     
       
  1262     if ( free < aLength )
       
  1263         {
       
  1264         User::Leave( KErrTooBig );
       
  1265         }
       
  1266     }
       
  1267 
       
  1268 // ---------------------------------------------------------------------------
       
  1269 // CNSPContentParser::FindMediaField
       
  1270 // ---------------------------------------------------------------------------
       
  1271 //
       
  1272 CSdpMediaField* CNSPContentParser::FindMediaField( const CSdpMediaField& aMediaField,
       
  1273         const RPointerArray<CSdpMediaField>& aMediaFields ) const
       
  1274     {
       
  1275     const TInt mediafieldscount( aMediaFields.Count() );
       
  1276     for ( TInt index = 0; index < mediafieldscount; index++ )
       
  1277         {
       
  1278         if ( aMediaFields[index]->Media() == aMediaField.Media() )
       
  1279             {
       
  1280             return aMediaFields[index];
       
  1281             }
       
  1282         }
       
  1283     
       
  1284     return NULL;    
       
  1285     }
       
  1286 
       
  1287 // ---------------------------------------------------------------------------
       
  1288 // CNSPContentParser::CleanupArrayItem
       
  1289 // ---------------------------------------------------------------------------
       
  1290 //
       
  1291 void CNSPContentParser::CleanupArrayItem( TAny* anArray )
       
  1292     {
       
  1293     if ( anArray )
       
  1294         {
       
  1295         reinterpret_cast< RPointerArray<CNATFWCandidate>* >( anArray )->
       
  1296             ResetAndDestroy();
       
  1297         reinterpret_cast< RPointerArray<CNATFWCandidate>* >( anArray )->
       
  1298             Close();
       
  1299         }
       
  1300     }
       
  1301 
       
  1302 
       
  1303 // end of file