webservices/wsstar/wsstarplugin/src/wsstarsessionconsumer.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 FILES
       
    29 #include <SenXmlUtils.h>
       
    30 
       
    31 #include "wsstarsessionconsumer.h"
       
    32 #include "sendebug.h"
       
    33 #include <SenServiceConnection.h>
       
    34 #include "senlogger.h"
       
    35 #include "wsstarcons.h"
       
    36 
       
    37 CWSStarSessionConsumer* CWSStarSessionConsumer::NewL( MSenRemoteServiceConsumer& aServiceConsumer,
       
    38                                                       RFileLogger& aLogger )
       
    39     {
       
    40     CWSStarSessionConsumer* pSelf =
       
    41         CWSStarSessionConsumer::NewLC(aServiceConsumer, aLogger);
       
    42     CleanupStack::Pop(pSelf);
       
    43     return pSelf;
       
    44     }
       
    45 
       
    46 CWSStarSessionConsumer* CWSStarSessionConsumer::NewLC( MSenRemoteServiceConsumer& aServiceConsumer,
       
    47                                                        RFileLogger& aLogger )
       
    48     {
       
    49     CWSStarSessionConsumer* pSelf =
       
    50                         new (ELeave) CWSStarSessionConsumer( aServiceConsumer, aLogger );
       
    51     CleanupStack::PushL(pSelf);
       
    52     pSelf->ConstructL();
       
    53     return pSelf;
       
    54     }
       
    55 
       
    56 CWSStarSessionConsumer::~CWSStarSessionConsumer()
       
    57     {
       
    58     //delete iSentMessageId;
       
    59     //delete iReceivedMessageId;
       
    60     iSentMessages.Reset();
       
    61     iSendReplyTo.Reset();
       
    62     iTranspProp.Reset();
       
    63     }
       
    64 
       
    65 CWSStarSessionConsumer::CWSStarSessionConsumer( MSenRemoteServiceConsumer& aServiceConsumer,
       
    66                                                 RFileLogger& aLogger )
       
    67 :   iConsumer(aServiceConsumer),
       
    68     iLogger(aLogger),
       
    69     //iSentMessageId(NULL),
       
    70     //iReceivedMessageId(NULL),
       
    71     iSentMessages(ETrue, ETrue),
       
    72     iSendReplyTo(ETrue, ETrue),
       
    73     iTranspProp(ETrue, ETrue)
       
    74     {
       
    75     }
       
    76 
       
    77 
       
    78 const TDesC8& CWSStarSessionConsumer::Id() const
       
    79     {
       
    80     return iConsumer.Id();
       
    81     }
       
    82 
       
    83 TInt CWSStarSessionConsumer::SetSessionL(MSenRemoteServiceSession& aServiceSession)
       
    84     {
       
    85     iConsumer.SetSessionL(aServiceSession);
       
    86     return KErrNone;
       
    87     }
       
    88 
       
    89 void CWSStarSessionConsumer::HandleSoapMessageL( CSenSoapMessage* apMessage,
       
    90                                                  const TInt aTxnId,
       
    91                                                  MSenProperties* aResponseTransportProperties,
       
    92                                                  TBool aCompleteMessage )
       
    93     {
       
    94     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarSessionConsumer::HandleSoapMessageL(CSenSoapMessage*)");
       
    95     
       
    96     if ( apMessage )
       
    97         {
       
    98         CleanupStack::PushL( apMessage ); // this method has the ownership, until passed forward(!)
       
    99         
       
   100         // fix for the error HTUR-6XDABN : Start
       
   101         
       
   102     	// After sending the message to Remote consumer, Corresponding message is not 
       
   103     	// removed from the message queue. Due to this the message body sits in the 
       
   104     	// queue (memory) till the session consumer object gets destroyed. 
       
   105     	CSenElement& header = apMessage->HeaderL();
       
   106     	// Response RelatesTo content=MessageId of the request
       
   107         RPointerArray<CSenElement>& msgIdArray = header.ElementsL();
       
   108     
       
   109     	for(TInt i = 0; i < msgIdArray.Count(); i++)
       
   110     		{
       
   111     		CSenElement& idElement = *msgIdArray[i];
       
   112     		
       
   113     		if( idElement.LocalName() == WSStarContextKeys::KRelatesTo() )
       
   114     			{
       
   115             	// Remove the consumed message from the message queue 
       
   116             	iSentMessages.RemoveByKey( idElement.Content() );
       
   117             	iTranspProp.RemoveByKey( idElement.Content() ); 		
       
   118             	break;
       
   119     			}
       
   120     		}
       
   121     		
       
   122     	// msgIdArray.Close(); // Must be removed (now commented out) OR otherwise regression 
       
   123     	                       // (MMAA-6YFQ5V) will occur! The msgIdArray is a *reference*, 
       
   124     	                       // and any modification to this array will MODIFY the actual
       
   125     	                       // contents of that DOM tree(!). 
       
   126     	                         
       
   127     	// fix for the error HTUR-6XDABN : End
       
   128     	
       
   129         HBufC8* pMessageAsString = NULL;
       
   130         if (aCompleteMessage)
       
   131             {
       
   132             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Returning whole SOAP-ENV");
       
   133             pMessageAsString = apMessage->AsXmlL();
       
   134             }
       
   135         else
       
   136             {
       
   137             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Detaching SOAP body (calling BodyAsStringL).");
       
   138             pMessageAsString = apMessage->BodyAsStringL();
       
   139             }
       
   140         CleanupStack::PopAndDestroy( apMessage ); // object has been serialized into a descriptor => de-alloc it
       
   141         
       
   142         if (pMessageAsString)
       
   143             {
       
   144             iConsumer.HandleMessageL(pMessageAsString, aTxnId, aResponseTransportProperties);
       
   145             }
       
   146         else
       
   147             {
       
   148             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Fatal(!): pMessageAsString == NULL, invoking remote consumer's HandleErrorL.");
       
   149             iConsumer.HandleErrorL(NULL, KErrSenNoSoapBody, aTxnId, aResponseTransportProperties);
       
   150             }
       
   151         }
       
   152     else // apMessage == NULL
       
   153         {
       
   154         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel,"- Fatal(!): WSStarSessionConsumer::HandleSoapMessageL, apMessage == NULL, sending KErrSenInternal to remote consumer via HandleErrorL.");
       
   155         iConsumer.HandleErrorL(NULL, KErrSenInternal, aTxnId, aResponseTransportProperties);
       
   156         }           
       
   157     }
       
   158 
       
   159 TInt CWSStarSessionConsumer::HandleMessageL( HBufC8* apMessage,
       
   160                                              const TInt aTxnId,
       
   161                                              MSenProperties* aResponseTransportProperties )
       
   162     {
       
   163 #ifdef _SENDEBUG
       
   164     CleanupStack::PushL(apMessage);
       
   165     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarSessionConsumer::HandleMessageL");
       
   166     CleanupStack::Pop(apMessage);
       
   167 #endif // _SENDEBUG    
       
   168     return iConsumer.HandleMessageL(apMessage, aTxnId, aResponseTransportProperties);
       
   169     }
       
   170 
       
   171 TInt CWSStarSessionConsumer::HandleErrorL( HBufC8* apError,
       
   172                                            const TInt aErrorCode,
       
   173                                            const TInt aTxnId,
       
   174                                            MSenProperties* aResponseTransportProperties )
       
   175     {
       
   176 #ifdef _SENDEBUG
       
   177     CleanupStack::PushL(apError);
       
   178     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarSessionConsumer::HandleErrorL");
       
   179     CleanupStack::Pop(apError);
       
   180 #endif // _SENDEBUG    
       
   181     return iConsumer.HandleErrorL(apError, aErrorCode, aTxnId, aResponseTransportProperties);
       
   182     }
       
   183 
       
   184 void CWSStarSessionConsumer::SetStatusL(const TInt status)
       
   185     {
       
   186     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarSessionConsumer::SetStatusL");
       
   187     //we will not inform consumers about  fact that credential is expired, 
       
   188     // ws* has to obtain new ticket and keep connection valid
       
   189     if (status == KSenConnectionStatusExpired) 
       
   190         {
       
   191         iConsumer.SetStatusL(KSenConnectionStatusReady);    
       
   192         }
       
   193     else
       
   194         {
       
   195         iConsumer.SetStatusL(status);
       
   196         }
       
   197     }
       
   198 
       
   199 TInt CWSStarSessionConsumer::MessageForSendingL(const TDesC8& aBody,
       
   200                                            CWSStarMessageContext*& aCtx)
       
   201     {
       
   202     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarSessionConsumer::MessageForSendingL");
       
   203     
       
   204     //do nothing with message. Message is preapred by session and handlers
       
   205     //we need only set correlation id using context which travel with message
       
   206     //------------SCHarF ------- glue with addressing to get messageId. We will expect some answer
       
   207     const TDesC8* msgId = aCtx->GetDesC8L(WSStarContextKeys::KMessageID);
       
   208     const TDesC8* replyTo = aCtx->GetDesC8L(WSStarContextKeys::KReplyTo);
       
   209     if (msgId)
       
   210         {
       
   211         iSentMessages.Append(msgId->AllocL(), aBody.AllocL());    
       
   212         if(replyTo)
       
   213             {
       
   214             iSendReplyTo.Append(msgId->AllocL(), replyTo->AllocL());
       
   215             }
       
   216         const TDesC8* transpProp =
       
   217                 aCtx->GetDesC8L(WSStarContextKeys::KWSStarTranspProp);
       
   218         if (transpProp)
       
   219             {
       
   220             iTranspProp.Append(msgId->AllocL(), transpProp->AllocL());
       
   221             }
       
   222         }
       
   223     //------------end SCHarF ------- 
       
   224     
       
   225     return KErrNone;
       
   226     }
       
   227 
       
   228 void CWSStarSessionConsumer::ConstructL()
       
   229     {
       
   230     }
       
   231 
       
   232 /*void CWSStarSessionConsumer::SetSentMessageIdL(const TDesC8& aSentMessageId)
       
   233     {
       
   234     HBufC8* pNew = NULL;
       
   235     if(aSentMessageId.Length()>0)
       
   236         pNew = aSentMessageId.AllocL();
       
   237     delete iSentMessageId;
       
   238     iSentMessageId = pNew;
       
   239     }
       
   240 
       
   241 TPtrC8 CWSStarSessionConsumer::SentMessageId()
       
   242     {
       
   243     if(iSentMessageId)
       
   244         {
       
   245         return *iSentMessageId;
       
   246         }
       
   247     else
       
   248         {
       
   249         return KNullDesC8();
       
   250         }
       
   251     }
       
   252 
       
   253 void CWSStarSessionConsumer::SetReceivedMessageIdL(
       
   254                                             const TDesC8& aReceivedMessageId)
       
   255     {
       
   256     HBufC8* pNew =NULL;
       
   257     if(aReceivedMessageId.Length()>0)
       
   258         pNew = aReceivedMessageId.AllocL();
       
   259     delete iReceivedMessageId;
       
   260     iReceivedMessageId = pNew;
       
   261     }
       
   262 
       
   263 TPtrC8 CWSStarSessionConsumer::ReceivedMessageId()
       
   264     {
       
   265     if(iReceivedMessageId)
       
   266         return *iReceivedMessageId;
       
   267     else
       
   268         return KNullDesC8();
       
   269     }
       
   270 */
       
   271 TBool CWSStarSessionConsumer::Expects(const TDesC8& aRelatesTo, const TDesC8* aTo)
       
   272     {
       
   273     TInt index = iSentMessages.Find(aRelatesTo);
       
   274     TBool result(EFalse);
       
   275     TInt index2 = index; 
       
   276     if (aTo)
       
   277         index2 = iSendReplyTo.Find(aRelatesTo);
       
   278     
       
   279     if (index == index2 && index2 != KErrNotFound)
       
   280         {
       
   281         if (aTo)
       
   282             {
       
   283             const TDesC8* replyTo = iSendReplyTo.ValueAt(index);
       
   284             if (*replyTo == *aTo)
       
   285                 {
       
   286                 result = ETrue;
       
   287                 }
       
   288             else
       
   289                 {
       
   290                 TLSLOG(KSenFaultsLogChannel, KSenFaultsLogLevel, WSStarSessionConsumer::KFaultInvalidToTag);   
       
   291                 }
       
   292             }
       
   293         else
       
   294             {
       
   295             result = ETrue;
       
   296             }
       
   297         }
       
   298     else
       
   299         {
       
   300         TLSLOG(KSenFaultsLogChannel, KSenFaultsLogLevel, WSStarSessionConsumer::KFaultInvalidRelatesToTag);   
       
   301         }
       
   302 
       
   303     return result;
       
   304     }
       
   305 
       
   306 TDesC8* CWSStarSessionConsumer::BodyL(const TDesC8& aMessageID) const
       
   307     {
       
   308     HBufC8* pBody = NULL;
       
   309 
       
   310     TInt index = iSentMessages.Find(aMessageID);
       
   311     if (index != KErrNotFound)
       
   312         {
       
   313         pBody = (HBufC8*)iSentMessages.ValueAt(index);
       
   314         }
       
   315     return pBody;
       
   316     }
       
   317 
       
   318 const TDesC8& CWSStarSessionConsumer::TransportProperties(
       
   319         const TDesC8& aMessageID) const
       
   320     {
       
   321     TInt index = iTranspProp.Find(aMessageID);
       
   322     if (index != KErrNotFound)
       
   323         {
       
   324         const TDesC8* tp = iTranspProp.ValueAt(index);
       
   325         if (tp)
       
   326             {
       
   327             return *tp;
       
   328             }
       
   329         }
       
   330     return KNullDesC8;
       
   331     }
       
   332 
       
   333 MSenTransport& CWSStarSessionConsumer::TransportL()
       
   334     {
       
   335     return iConsumer.TransportL();
       
   336     }
       
   337     
       
   338 TInt CWSStarSessionConsumer::ChunkByTxnIdL(TInt aTxnId, CSenChunk*& aChunk)
       
   339     {
       
   340     return iConsumer.ChunkByTxnIdL(aTxnId, aChunk);
       
   341     }
       
   342 
       
   343 void CWSStarSessionConsumer::FileProgress(TInt /*aTxnId*/, TBool /*aIncoming*/, TBool /*aIsSoap*/,
       
   344                 const TDesC8& /*aSoapOrCid*/, TInt /*aProgress*/)
       
   345     {
       
   346     }
       
   347 
       
   348 CSenIdentifier& CWSStarSessionConsumer::Identifier() const
       
   349     {
       
   350     return iConsumer.Identifier();
       
   351     }
       
   352 
       
   353 
       
   354 // enable file logging (macros)
       
   355 RFileLogger* CWSStarSessionConsumer::Log() const
       
   356     {
       
   357     return (RFileLogger*) &iLogger;
       
   358     }
       
   359     
       
   360 TBool CWSStarSessionConsumer::HasAuthenticationCallback()
       
   361     {
       
   362     return iConsumer.HasAuthenticationCallback();
       
   363     }
       
   364 
       
   365 TInt CWSStarSessionConsumer::ReauthenticationNeededL(CSenIdentityProvider*& aIdp)
       
   366 	{
       
   367 	return iConsumer.ReauthenticationNeededL(aIdp);
       
   368 	}
       
   369 void CWSStarSessionConsumer::SetDataTrafficDetails( TSenDataTrafficDetails&  aDetails)  
       
   370 	{
       
   371 	iConsumer.SetDataTrafficDetails(aDetails);
       
   372 	}
       
   373 
       
   374 TBool CWSStarSessionConsumer::HasCoBrandingCallback()
       
   375     {
       
   376     return iConsumer.HasCoBrandingCallback();
       
   377     }
       
   378 
       
   379 TBool CWSStarSessionConsumer::OnGetBrandIdL(  const TDesC8& aBrandIdListAsXmlSnippet, RBuf8& aSelectedBrandId)
       
   380     {
       
   381     return iConsumer.OnGetBrandIdL(aBrandIdListAsXmlSnippet,aSelectedBrandId);
       
   382     }
       
   383 // End of file