webservices/wsstar/wsstarplugin/src/wsstarsessioncontext.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:           
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 #include "wsstarrstresponse.h"
       
    29 #include "wsstarsessioncontext.h"
       
    30 #include "senwsdescription.h"
       
    31 #include <SenServiceConnection.h>
       
    32 #include <SenDateUtils.h>
       
    33 #include "sencryptoutils.h"
       
    34 #include "wsstarpolicy.h"
       
    35 #include "senlogger.h"
       
    36 #include "wsstarservicesession.h"
       
    37 #include "msenremoteservicesession.h"  // internal Framework\inc
       
    38 
       
    39 using namespace WSStarContextKeys;
       
    40 using namespace WSStarContextValues;
       
    41 
       
    42 CWSStarSessionContext* CWSStarSessionContext::NewL(CSenXmlReader* aParser, MSenServiceDescription* aSD, CWSStarPolicyHandler* aPolicyHandler)
       
    43     {
       
    44     CWSStarSessionContext* self = NewLC(aParser, aSD, aPolicyHandler);
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 CWSStarSessionContext* CWSStarSessionContext::NewLC(CSenXmlReader* aParser, MSenServiceDescription* aSD, CWSStarPolicyHandler* aPolicyHandler)
       
    49     {
       
    50     CWSStarSessionContext* self = new (ELeave) CWSStarSessionContext(aParser);
       
    51     CleanupStack::PushL (self);
       
    52     self->ConstructL(aSD, aPolicyHandler);
       
    53     return self;
       
    54     }
       
    55 
       
    56 // Constructor
       
    57 CWSStarSessionContext::CWSStarSessionContext(CSenXmlReader* aParser):
       
    58     iDescriptions(EFalse,EFalse),
       
    59     iInts(EFalse,ETrue),
       
    60     iDescs(EFalse,ETrue),
       
    61     iParser(aParser)
       
    62     {
       
    63     }
       
    64 
       
    65 // Constructor
       
    66 void CWSStarSessionContext::ConstructL(MSenServiceDescription* aSD, CWSStarPolicyHandler* /*aPolicyHandler*/)
       
    67     {
       
    68     if (CWSStarPolicy::CheckPolicyValueL(WSPolicy::KSoap12, aSD))
       
    69         {
       
    70         Update(KSoapVersion, ESOAP12);
       
    71         }
       
    72     else
       
    73         {
       
    74         Update(KSoapVersion, ESOAP11);
       
    75         }   
       
    76     HBufC8* addrVer = CWSStarPolicy::GetPolicyValueL(WSPolicy::KAddressing, aSD);
       
    77     if (addrVer)
       
    78         {
       
    79         Update(KAddressingVersion, *addrVer);
       
    80         delete addrVer;
       
    81         addrVer = NULL;
       
    82         }  
       
    83             
       
    84     }
       
    85 
       
    86 // Destructor
       
    87 CWSStarSessionContext::~CWSStarSessionContext()
       
    88     {
       
    89     iDescriptions.Reset();
       
    90     iInts.Reset();
       
    91     iDescs.Reset();
       
    92     if( ipSignedParts )
       
    93         {
       
    94         ipSignedParts->ResetAndDestroy();
       
    95         delete ipSignedParts;
       
    96         ipSignedParts = NULL;
       
    97         }
       
    98     delete iBody;
       
    99     iBody = NULL;
       
   100     }
       
   101     
       
   102 TInt CWSStarSessionContext::UpdatePolicyL(CWSStarPolicyHandler* aPolicyHandler, MSenServiceDescription* aSD)
       
   103     {
       
   104     CWSStarPolicyHandler* pPolicyHandler = (CWSStarPolicyHandler*)aPolicyHandler;
       
   105     if (pPolicyHandler)
       
   106         {
       
   107         RPointerArray<HBufC8>* pElements = new (ELeave) RPointerArray<HBufC8>();
       
   108         CleanupStack::PushL( pElements );
       
   109         CWSStarPolicy::GetPolicyValueL( WSPolicy::KSignedParts, KNullDesC8, pPolicyHandler, aSD, *pElements );
       
   110         if ( ipSignedParts )
       
   111             {
       
   112             ipSignedParts->ResetAndDestroy();
       
   113             delete ipSignedParts;
       
   114             ipSignedParts = NULL;
       
   115             }
       
   116         ipSignedParts = pElements; // takes the ownership of the elements array
       
   117         CleanupStack::Pop( pElements );
       
   118         }
       
   119     return KErrNone;
       
   120     }
       
   121 // -----------------------------------------------------------------------------
       
   122 // Sets token context keys based on RST response.
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TInt CWSStarSessionContext::SetTokenKeysL(CWSStarRSTResponse& aRSTResponse,
       
   126         HBufC8* aClientEntropy, TBool aSignalConsumers, TBool aSCT)
       
   127     {
       
   128 
       
   129 //1)TOKEN
       
   130     CWSStarServiceSession* session = (CWSStarServiceSession*)
       
   131                 GetSenRemoteServiceSessionL(KServiceSession);
       
   132     CSenCredential* credential = aRSTResponse.Credential();
       
   133     if (credential)
       
   134         {
       
   135         if (!aSCT)
       
   136             {
       
   137             if (aRSTResponse.CredentialExpires().Length())
       
   138                 {
       
   139                 User::LeaveIfError(Update(KTimestampExpires, aRSTResponse.CredentialExpires()));    
       
   140                 }
       
   141 
       
   142             User::LeaveIfError(Update(KMTIsReplacedBySCT, EFalse));
       
   143             TTime clientTime;
       
   144             clientTime.UniversalTime();
       
   145             TBuf8<SenDateUtils::KXmlDateTimeMaxLength> ts;
       
   146             TInt leaveCode(KErrNone);
       
   147             TRAP(leaveCode, SenDateUtils::ToXmlDateTimeUtf82L(ts, clientTime);)
       
   148             if (!leaveCode)
       
   149                 {
       
   150                 User::LeaveIfError(Update(KPhoneTimeWhenMTResolved, ts));                        
       
   151                 }
       
   152 
       
   153             if (aRSTResponse.CredentialCreated().Length())
       
   154                 {
       
   155                 User::LeaveIfError(Update(KTimestampCreated, aRSTResponse.CredentialCreated()));
       
   156 
       
   157                 TTime serverTime = SenDateUtils::FromXmlDateTimeL(aRSTResponse.CredentialCreated());
       
   158                 if (serverTime != Time::NullTTime())
       
   159                     {
       
   160                     TTimeIntervalMicroSeconds interval = serverTime.MicroSecondsFrom(clientTime);
       
   161                     ((CSenWebServiceSession*)session)->SetClientServerIntervalL(interval);	//codescannerwarnings
       
   162                     }
       
   163                 }
       
   164 
       
   165             //adding credential also calculate new status
       
   166             ((CSenWebServiceSession*)session)->AddCredentialL(*credential);
       
   167             session->AddPropertiesFromSessionContextToCredentialL();
       
   168             }
       
   169          else
       
   170             {
       
   171             User::LeaveIfError(Update(KMTIsReplacedBySCT, ETrue));    
       
   172             }
       
   173             
       
   174         //Co-Branding CR
       
   175         if(aSignalConsumers)
       
   176             {
       
   177             session->SetStatusL();
       
   178             if (((CSenServiceSession*)session)->StatusL() == KSenConnectionStatusExpired)
       
   179                 {
       
   180                 return KErrNotReady;
       
   181                 }
       
   182             }
       
   183             
       
   184         HBufC8* securityToken = credential->AsXmlL();
       
   185         if (securityToken)
       
   186             {
       
   187             if (!aSCT)
       
   188                 {
       
   189                 CleanupStack::PushL(securityToken);
       
   190                 User::LeaveIfError(Update(KTokenType, aRSTResponse.TokenType()));
       
   191                 HBufC8* binarySecurityToken =
       
   192                         SenCryptoUtils::CreateEncodedBinarySecretL(*securityToken, aRSTResponse.TokenType());
       
   193                 CleanupStack::PushL(binarySecurityToken);
       
   194                 User::LeaveIfError(Update(WSStarContextKeys::KSecurityToken,
       
   195                         *binarySecurityToken));
       
   196                 User::LeaveIfError(Update(WSStarContextKeys::KSecurityTokenBackup,
       
   197                         *binarySecurityToken));
       
   198                 CleanupStack::PopAndDestroy(binarySecurityToken);                
       
   199                 CleanupStack::PopAndDestroy(securityToken);                
       
   200                 }
       
   201             else
       
   202                 {//SCT is not encoded
       
   203                 CleanupStack::PushL(securityToken);
       
   204                 User::LeaveIfError(Update(WSStarContextKeys::KSecurityToken,
       
   205                         *securityToken));
       
   206                 CleanupStack::PopAndDestroy(securityToken);
       
   207                 }
       
   208             }    
       
   209         }
       
   210     else
       
   211         {
       
   212         return KErrNotFound;
       
   213         }
       
   214 //2)KEY TOKEN
       
   215     if (!aSCT)//if SCT comes, we still use old pop
       
   216         {
       
   217         const TInt KByteSize = 8;
       
   218         TPtrC8 popBase64 = aRSTResponse.POPBase64();
       
   219         HBufC8* newPOPBase64 = NULL;
       
   220         //if no (POP/BinarySecret) from server
       
   221         if (!popBase64.Length())
       
   222             {
       
   223 
       
   224             if (
       
   225                 //IOP 2007 improve, determine by ComputedKey tag instead optional nonce value.
       
   226                 //binaryType is optional attribute so it doesn't determine flow, better is checking ComputedKey tag
       
   227                 /*(aRSTResponse.BinaryType() == WSTrust::KBinaryTypeNonceValue)*/
       
   228                 aRSTResponse.ComputedKey().Length()
       
   229                 &&
       
   230                 aRSTResponse.EntropySTS().Length())
       
   231                     {
       
   232                     if (aClientEntropy)
       
   233                         {
       
   234                         //calcualte new POP using algorithm
       
   235                         TPtrC8 computedKey = aRSTResponse.ComputedKey();
       
   236                         if (computedKey == WSTrust::KComputedKeyPSHA1Value)
       
   237                             {
       
   238                             HBufC8* clientBin = SenCryptoUtils::DecodeBase64L(
       
   239                                     *aClientEntropy);
       
   240                             CleanupStack::PushL(clientBin);
       
   241                             HBufC8* STSBin = SenCryptoUtils::DecodeBase64L(
       
   242                                     aRSTResponse.EntropySTS());
       
   243                             CleanupStack::PushL(STSBin);
       
   244                             TInt keySize = aRSTResponse.KeySize();
       
   245                             if (!keySize)
       
   246                                 {
       
   247                                 TLSLOG(KSenFaultsLogChannel, KSenFaultsLogLevel, WSStarTrustFault::KBadKeySize());
       
   248                                 keySize = WSTrust::KSizeOfComputedKey;
       
   249                                 }
       
   250                             if (keySize % KByteSize)
       
   251                                 {
       
   252                                 TLSLOG(KSenFaultsLogChannel, KSenFaultsLogLevel, WSStarTrustFault::KBadKeySize());
       
   253                                 }
       
   254                             keySize = keySize / KByteSize; //byte = 8 bits
       
   255                             HBufC8* newEntropy = 
       
   256                                 SenCryptoUtils::GetPSHA1HashL( *clientBin, *STSBin, keySize);
       
   257                                 
       
   258                             CleanupStack::PopAndDestroy(2, clientBin);
       
   259                             CleanupStack::PushL(newEntropy);
       
   260                             newPOPBase64 = SenCryptoUtils::EncodeBase64L(
       
   261                                     *newEntropy);
       
   262                             CleanupStack::PopAndDestroy(newEntropy);
       
   263                             CleanupStack::PushL(newPOPBase64);
       
   264                             newEntropy = NULL;
       
   265                             popBase64.Set(*newPOPBase64);
       
   266                             }
       
   267                         else
       
   268                         //http://schemas.xmlsoap.org/ws/2005/02/trust/CK/HASH not supported
       
   269                             {
       
   270                             //still possible to talk with service without POP (we just will not sign anything)
       
   271                             //return KErrNotFound;
       
   272                             }
       
   273                         }
       
   274                        else
       
   275                         {
       
   276                         //server response with cmupting key but client doesnt provide entropy. wrong scenario
       
   277                         //still possible to talk with service without POP (we just will not sign anything)
       
   278                         }
       
   279                     }
       
   280         //no from server nor calculated so last chance that
       
   281         //6.2.3 If the requestor provides entropy and the responder doesn't 
       
   282         //(issuer uses the requestor's key),
       
   283         //then a proof-of-possession token need not be returned.
       
   284                 else if (aClientEntropy)
       
   285                     {
       
   286                     popBase64.Set(*aClientEntropy);
       
   287                     }
       
   288                 else
       
   289                     {
       
   290                     //still possible to talk with service without POP (we just will not sign anything)
       
   291                     //return KErrNotFound;
       
   292                     }
       
   293             }
       
   294         if (popBase64.Length())
       
   295             {
       
   296             User::LeaveIfError(Update(KPOPBase64, popBase64));
       
   297             if (newPOPBase64) CleanupStack::PopAndDestroy(newPOPBase64);
       
   298             
       
   299             //binary type always will be (default simmetric)
       
   300             if (aRSTResponse.BinaryType()== WSTrust::KBinaryTypeSimmetricValue)
       
   301                 {
       
   302                 User::LeaveIfError(Update(KBinaryType,   KPOPTypeSimmetric()));
       
   303                 }
       
   304             else if (aRSTResponse.BinaryType()== WSTrust::KBinaryTypeAsimmetricValue)
       
   305                 {
       
   306                 User::LeaveIfError(Update(KBinaryType, KPOPTypeAsimmetric()));
       
   307                 }
       
   308             else if (aRSTResponse.BinaryType()== WSTrust::KBinaryTypeNonceValue)
       
   309                 {
       
   310                 User::LeaveIfError(Update(KBinaryType, KPOPTypeNonce()));
       
   311                 }
       
   312             //adding KeyInfo (its identifier)
       
   313             TPtrC8 str = aRSTResponse.STR();
       
   314             if (str.Length())
       
   315                 {
       
   316                 User::LeaveIfError(Update(KSTR, str));
       
   317                 }
       
   318             }
       
   319         }
       
   320     session->AddPropertiesFromSessionContextToCredentialL();
       
   321     return KErrNone;
       
   322     }
       
   323 
       
   324 //-----------------------------------------------------
       
   325 //              from MSessionContext
       
   326 //-----------------------------------------------------
       
   327 const CSenWSDescription* CWSStarSessionContext::GetSession()
       
   328     {
       
   329     return NULL;
       
   330     };
       
   331 const CSenWSDescription* CWSStarSessionContext::GetInitializer()
       
   332     {
       
   333     return NULL;
       
   334     };
       
   335 
       
   336 //descriptions    
       
   337 TInt CWSStarSessionContext::Add(const TDesC8& aKey, CSenWSDescription* aValue)
       
   338     {
       
   339     return iDescriptions.Append(&aKey,aValue);
       
   340     };
       
   341 
       
   342 TInt CWSStarSessionContext::Update(const TDesC8& aKey, CSenWSDescription* aValue)
       
   343     {
       
   344     iDescriptions.RemoveByKey(aKey);
       
   345     return iDescriptions.Append(&aKey,aValue);
       
   346     };
       
   347 
       
   348 const CSenWSDescription* CWSStarSessionContext::GetSenWSDescriptionL(const TDesC8& aKey)
       
   349     {
       
   350     TInt index = iDescriptions.Find(aKey);
       
   351     if (index!=KErrNotFound)
       
   352         {
       
   353         return iDescriptions.ValueAt(index);
       
   354         }
       
   355     else
       
   356         {
       
   357         return NULL;
       
   358         };        
       
   359     };
       
   360 
       
   361 
       
   362 //sessions    
       
   363 TInt CWSStarSessionContext::Add(const TDesC8& aKey, MSenRemoteServiceSession& aValue)
       
   364     {
       
   365     return Update(aKey, aValue);
       
   366     };
       
   367 TInt CWSStarSessionContext::Update(const TDesC8& /*aKey*/, MSenRemoteServiceSession& aValue)
       
   368     {
       
   369     iSession = &aValue;
       
   370     return KErrNone;
       
   371     };
       
   372 const MSenRemoteServiceSession* CWSStarSessionContext::GetSenRemoteServiceSessionL(const TDesC8& /*aKey*/)
       
   373     {
       
   374     return iSession;
       
   375     };    
       
   376 
       
   377 
       
   378 
       
   379 //-----------------------------------------------------
       
   380 //              from MContext
       
   381 //-----------------------------------------------------
       
   382 
       
   383 SenContext::TContextType CWSStarSessionContext::Type() const  
       
   384     {
       
   385     return SenContext::ESessionContext;
       
   386     }
       
   387 
       
   388 SenContext::TContextDirection CWSStarSessionContext::Direction() const 
       
   389     {
       
   390     return SenContext::EBoth;
       
   391     }
       
   392 
       
   393 
       
   394 
       
   395 //-----------------descs
       
   396 TInt CWSStarSessionContext::Add(const TDesC8& aKey, const TDesC8& aValue)
       
   397     {   
       
   398         //version without copy
       
   399         //return iDescs.Append(&aKey,&aValue);
       
   400         
       
   401         //version with making of copy
       
   402         if (!aValue.Length()) return KErrUnderflow;
       
   403         HBufC8* newValue = NULL;
       
   404         TInt error(KErrNone);
       
   405         TRAP(error, newValue = aValue.AllocL());
       
   406         if (!error)
       
   407             {
       
   408             error = iDescs.Append(&aKey,newValue);
       
   409             }
       
   410         return 
       
   411             error;
       
   412     }
       
   413 TInt CWSStarSessionContext::Update(const TDesC8& aKey, const TDesC8& aValue)
       
   414     {
       
   415         //return iDescs.UpdateValue(&aKey,&aValue);
       
   416         
       
   417         //version with makeing of copy
       
   418         TInt error(KErrNone);
       
   419         if (!aValue.Length())
       
   420             {
       
   421             error = Remove(aKey);
       
   422             if (error == KErrNotFound)
       
   423                 return KErrNone;
       
   424             else
       
   425                 return error;
       
   426             }
       
   427         HBufC8* newValue = NULL;
       
   428         
       
   429         TRAP(error, newValue = aValue.AllocL());
       
   430         
       
   431         if (!error)
       
   432             {
       
   433             error = iDescs.UpdateValue(&aKey,newValue);
       
   434             }
       
   435         return 
       
   436             error;
       
   437     }
       
   438 const TDesC8* CWSStarSessionContext::GetDesC8L(const TDesC8& aKey)
       
   439     {
       
   440     TInt index = iDescs.Find(aKey);
       
   441     if (index != KErrNotFound)
       
   442         {
       
   443         return iDescs.ValueAt(index);
       
   444         }
       
   445     else
       
   446         {
       
   447         return NULL;
       
   448         };        
       
   449     }
       
   450 TInt CWSStarSessionContext::Remove(const TDesC8& aKey)
       
   451     {
       
   452     return iDescs.RemoveByKey(aKey);
       
   453     }
       
   454 
       
   455 
       
   456 //-----------------TInts
       
   457 TInt CWSStarSessionContext::Add(const TDesC8& aKey, TInt aValue)
       
   458     {
       
   459     TInt* a = NULL;
       
   460     a = new TInt(aValue);
       
   461     if (a) 
       
   462         {
       
   463         return iInts.Append(&aKey, a);
       
   464         }
       
   465     else
       
   466         {
       
   467         return KErrNoMemory;
       
   468         }
       
   469         
       
   470     }
       
   471 TInt CWSStarSessionContext::Update(const TDesC8& aKey, TInt aValue)
       
   472     {
       
   473     TInt* a = NULL;
       
   474     a = new TInt(aValue);
       
   475     if (a) 
       
   476         {
       
   477         return iInts.UpdateValue(&aKey, a);
       
   478         }
       
   479     else
       
   480         {
       
   481         return KErrNoMemory;
       
   482         }
       
   483     }
       
   484 const TInt* CWSStarSessionContext::GetIntL(const TDesC8& aKey)
       
   485     {
       
   486     TInt index = iInts.Find(aKey);
       
   487     if (index!=KErrNotFound)
       
   488         {
       
   489         return iInts.ValueAt(index);
       
   490         }
       
   491     else
       
   492         {
       
   493         return NULL;
       
   494         }
       
   495     }
       
   496 
       
   497 //-----------------elements
       
   498 TInt CWSStarSessionContext::Add(const TDesC8& aKey, CSenElement* aValue)
       
   499     {
       
   500     return Update(aKey,aValue);
       
   501     }
       
   502 TInt CWSStarSessionContext::Update(const TDesC8& aKey, CSenElement* aValue)
       
   503     {
       
   504     if (aKey == KBodyElement)
       
   505         {
       
   506         delete iBody;
       
   507         iBody = NULL;
       
   508         iBody = aValue;
       
   509         return KErrNone;
       
   510         }
       
   511     return KErrNotFound;
       
   512     }
       
   513 const CSenElement* CWSStarSessionContext::GetSenElementL(const TDesC8& aKey)
       
   514     {
       
   515     if (aKey == KBodyElement)
       
   516         {
       
   517         return iBody;
       
   518         }
       
   519     return NULL;
       
   520     }
       
   521 
       
   522 //-----------------TAnys
       
   523 TInt CWSStarSessionContext::Add(const TDesC8& aKey, TAny* aValue)
       
   524     {
       
   525     TInt err(KErrNone);
       
   526     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   527         {
       
   528         if (!iCurrentEnvelope)
       
   529             {
       
   530             iCurrentEnvelope = (CSenSoapEnvelope*)aValue;
       
   531             }
       
   532         else
       
   533             {
       
   534             err = KErrAlreadyExists;
       
   535             }
       
   536         }
       
   537     else if ( aKey == SenContext::KRemoteConsumer() )
       
   538         {
       
   539         if ( !ipConsumer )
       
   540             {
       
   541             ipConsumer = aValue;
       
   542             }
       
   543          else
       
   544             {
       
   545             err = KErrAlreadyExists;
       
   546             }
       
   547         }
       
   548     else 
       
   549         {
       
   550         err = KErrNotFound;
       
   551         }        
       
   552     return err;
       
   553     }
       
   554 TInt CWSStarSessionContext::Update(const TDesC8& aKey, TAny* aValue)
       
   555     {
       
   556     TInt err(KErrNone);
       
   557     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   558         {
       
   559         iCurrentEnvelope = (CSenSoapEnvelope*)aValue;
       
   560         }
       
   561     else if ( aKey == SenContext::KRemoteConsumer() )
       
   562         {
       
   563         ipConsumer = aValue;
       
   564         }
       
   565     else
       
   566         {
       
   567         err = KErrNotFound;
       
   568         }
       
   569     return err;
       
   570     }
       
   571 TAny* CWSStarSessionContext::GetAnyL(const TDesC8& aKey)	//codescannerwarnings
       
   572     {
       
   573     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey)
       
   574         {
       
   575         return iCurrentEnvelope;
       
   576         }
       
   577     else if ( aKey == WSStarContextKeys::KRemoteConsumer )
       
   578         {
       
   579         return ipConsumer;
       
   580         }
       
   581     else if(aKey == WSStarContextKeys::KSignedPartsArray)
       
   582         {
       
   583         return ipSignedParts;
       
   584         }
       
   585     else
       
   586         {
       
   587         return NULL;
       
   588         }
       
   589     }
       
   590 
       
   591 
       
   592 //-----------------Rest
       
   593 const CSenXmlReader* CWSStarSessionContext::GetParser()
       
   594     {
       
   595     return iParser;
       
   596     }
       
   597 TInt CWSStarSessionContext::Count() const
       
   598     { 
       
   599     return 0;
       
   600     }
       
   601 TPtrC8 CWSStarSessionContext::KeyAtL(TInt /*aIndex*/)
       
   602     { 
       
   603     return KNullDesC8();
       
   604     }        
       
   605 void CWSStarSessionContext::Reset()
       
   606     {
       
   607     }
       
   608 //-----------------------new    
       
   609 void CWSStarSessionContext::UpdateDesC8L(CWSStarMessageContext& aMessageContext, const TDesC8& aKey)
       
   610     {
       
   611     const TDesC8* ptr =
       
   612             aMessageContext.GetDesC8L(aKey);
       
   613     if (ptr)
       
   614         {
       
   615         User::LeaveIfError(Update(aKey, *ptr));
       
   616         }
       
   617     else
       
   618         {
       
   619         Remove(aKey);
       
   620         }
       
   621     
       
   622     }
       
   623     
       
   624 void CWSStarSessionContext::UpdateFromMessageInContextL(
       
   625         CWSStarMessageContext& aMessageContext)
       
   626     {
       
   627     const TDesC8* ptr =
       
   628             aMessageContext.GetDesC8L(KAction);
       
   629     if (ptr)
       
   630         {
       
   631         User::LeaveIfError(Update(KResponseAction, *ptr));
       
   632         }
       
   633     else
       
   634         {
       
   635         Remove(KResponseAction);
       
   636         }
       
   637     
       
   638     UpdateDesC8L(aMessageContext, KAddressingNsHolder);
       
   639     UpdateDesC8L(aMessageContext, KAddressingEndpointTagHolder);
       
   640     const TInt* ptrInt =
       
   641             aMessageContext.GetIntL(KReAuthNeeded);
       
   642     if (ptrInt)
       
   643         {
       
   644         User::LeaveIfError(Update(KReAuthNeeded, *ptrInt));
       
   645         }
       
   646     const TDesC8* ptrBrandID =
       
   647         aMessageContext.GetDesC8L(KMainBrandID);
       
   648     if (ptrBrandID)
       
   649         {
       
   650         User::LeaveIfError(Update(KMainBrandID, *ptrBrandID));
       
   651         }
       
   652     const TDesC8* ptrBrandIDList =
       
   653         aMessageContext.GetDesC8L(KBrandIDList);
       
   654     if (ptrBrandIDList)
       
   655         {
       
   656         User::LeaveIfError(Update(KBrandIDList, *ptrBrandIDList));
       
   657         }
       
   658     }
       
   659 
       
   660 void CWSStarSessionContext::UpdateFromMessageOutContextL(
       
   661         CWSStarMessageContext& aMessageContext)
       
   662     {
       
   663     if (!aMessageContext.GetSenElementL(KBodyElement))
       
   664         {
       
   665         iBody = NULL;    
       
   666         }
       
   667     UpdateDesC8L(aMessageContext, KSTR);
       
   668     UpdateDesC8L(aMessageContext, KBody);
       
   669     UpdateDesC8L(aMessageContext, KMessageID);
       
   670     }
       
   671 
       
   672 TInt CWSStarSessionContext::ShareTokenWithL(CWSStarSessionContext* aWSStarSessionCtxDst, TBool& aMTwasReplaceBySCT)
       
   673     {
       
   674     //first check SCT
       
   675     const TBool* isreplaced = NULL;
       
   676     const TDesC8* desc = NULL;
       
   677     isreplaced = GetIntL(KMTIsReplacedBySCT);
       
   678     if (isreplaced && *isreplaced == TRUE)
       
   679         {
       
   680         aMTwasReplaceBySCT = ETrue;
       
   681         }
       
   682     else
       
   683         {
       
   684         aMTwasReplaceBySCT = EFalse;
       
   685         }
       
   686     TInt error = KErrNone;
       
   687     desc = GetDesC8L(KTimestampExpires);
       
   688     if (desc)
       
   689         {
       
   690         error = aWSStarSessionCtxDst->Update(KTimestampExpires, *desc);
       
   691         if (error) return error;
       
   692         }
       
   693     desc = GetDesC8L(KTimestampCreated);
       
   694     if (desc)
       
   695         {
       
   696         error = aWSStarSessionCtxDst->Update(KTimestampCreated, *desc);    
       
   697         if (error) return error;
       
   698         }    
       
   699     desc = GetDesC8L(KPhoneTimeWhenMTResolved);
       
   700     if (desc)
       
   701         {
       
   702         error = aWSStarSessionCtxDst->Update(KPhoneTimeWhenMTResolved, *desc);    
       
   703         if (error) return error;
       
   704         }
       
   705     if (aMTwasReplaceBySCT)
       
   706         {
       
   707         CREDLOG_L(KSenCredsLogLevelNormal,"....this session has SCT so share it also");
       
   708         error = aWSStarSessionCtxDst->Update(KMTIsReplacedBySCT, aMTwasReplaceBySCT);    
       
   709         if (error) return error; 
       
   710         }
       
   711     desc = GetDesC8L(KSecurityToken);
       
   712     if (desc)//here we possible copy SCT, flag KMTIsReplacedBySCT determine
       
   713         {
       
   714         //some MS email "...1 SCT to access all WL for mobile services) but is not likely to remain that way..."
       
   715         //in future SCT will be not copied
       
   716         error = aWSStarSessionCtxDst->Update(KSecurityToken, *desc);    
       
   717         if (error) return error;
       
   718         }
       
   719     desc = GetDesC8L(KSecurityTokenBackup);
       
   720     if (desc)
       
   721         {
       
   722         error = aWSStarSessionCtxDst->Update(KSecurityTokenBackup, *desc);    
       
   723         if (error) return error;
       
   724         }
       
   725     //POP
       
   726     desc = GetDesC8L(KPOPBase64);
       
   727     if (desc)
       
   728         {
       
   729         error = aWSStarSessionCtxDst->Update(KPOPBase64, *desc);    
       
   730         if (error) return error;
       
   731         }  
       
   732     desc = GetDesC8L(KTokenType);
       
   733     if (desc)
       
   734         {
       
   735         error = aWSStarSessionCtxDst->Update(KTokenType, *desc);    
       
   736         if (error) return error;
       
   737         }  
       
   738     desc = GetDesC8L(KBinaryType);
       
   739     if (desc)
       
   740         {
       
   741         error = aWSStarSessionCtxDst->Update(KBinaryType, *desc);    
       
   742         if (error) return error;
       
   743         } 
       
   744     desc = GetDesC8L(KBinaryType);
       
   745     if (desc)
       
   746         {
       
   747         error = aWSStarSessionCtxDst->Update(KSTR, *desc);    
       
   748         if (error) return error;
       
   749         }                        
       
   750     return error;    
       
   751     }
       
   752 // END OF FILE
       
   753