webservices/wscore/src/senclientsession.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 <s32mem.h>                         // RChunk
       
    30 #include <e32property.h>                    // RProperty
       
    31 
       
    32 #include <SenServiceConnection.h>           // error codes and framework ids
       
    33 #include <SenHostletConnection.h>           // error code(s)
       
    34 #include "senwsdescription.h"
       
    35 #include "senwspattern.h"
       
    36 #include <SenIdentityProvider.h>
       
    37 #include <SenXmlUtils.h>
       
    38 #include <SenXmlProperties.h>
       
    39 
       
    40 #include <xmlengnodelist.h> 
       
    41 #include <defaultcaps.hrh>
       
    42 
       
    43 #include "senclientsession.h"
       
    44 #include "senservicemanagerdefines.h"       // IPC enumerations
       
    45 #include "msencoreservicemanager.h"
       
    46 
       
    47 #include "sendebug.h"                       // internal Utils\inc
       
    48 #include "sennotplugindlg.h"                // internal NotifierPlugin\inc
       
    49 #include "senidentifier.h"
       
    50 
       
    51 #include "senserviceinvocationframework.h"  // internal Framework\inc
       
    52 #include "msenremoteservicesession.h"       // internal Framework\inc
       
    53 #include "sentransport.h"                   // internal Framework\inc
       
    54 #include "sentransportcontext.h"            // internal Framework\inc
       
    55 //#include "SenServiceSession.h"              // internal Framework\inc
       
    56 #include "senwebservicesession.h"                // internal Framework\inc
       
    57 #include "senlayeredtransportproperties.h"  // internal Framework\inc
       
    58 #include "senmessagecontext.h"              // internal Framework\inc
       
    59 
       
    60 #include "SenSoapEnvelope2.h"
       
    61 #include "sensoapmessagedom2.h"
       
    62 #include "xmlengchunkcontainer.h"
       
    63 #include "xmlengfilecontainer.h"
       
    64 #include "xmlengdeserializer.h"
       
    65 #include "SenParser.h"
       
    66 #include "seninternalcredential.h"
       
    67 #include "senservercontext.h"
       
    68 #include "senapplicationcontext.h"
       
    69 #include "senclientcontext.h"
       
    70 #include "senxmldebug.h"
       
    71 #include "senlogger.h"
       
    72 #include "SenServiceConnection.h"  
       
    73 #include <SenTransportProperties.h>
       
    74 
       
    75 #ifdef __TEST_RETRY_TTL
       
    76 #include <SenVtcpTransportProperties.h>//internal for lonlived test
       
    77 #endif //__TEST_RETRY_TTL
       
    78 namespace
       
    79     {
       
    80     const TInt KFlatBufSize = 128;
       
    81 	const TInt KMaxAuthenticationRetries = 3;
       
    82     _LIT8(KTab, "\t");
       
    83     _LIT8(KNewline, "\n");
       
    84     _LIT8(KProviderPolicyLocalName,     "ProviderPolicy");
       
    85     _LIT8(KServicePolicyLocalName,      "ServicePolicy");
       
    86     _LIT8(KProviderIdLocalName,         "ProviderID");
       
    87     
       
    88     // _LIT8( KSenCidPostfix, "@example.org" );
       
    89     #ifdef RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS
       
    90     _LIT8( KSenCidPostfix, "@" );
       
    91     const TInt KSenMaxCidLength = 10;
       
    92     #endif //RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS
       
    93     
       
    94     }
       
    95 
       
    96 
       
    97 CSenMessageResourceHandler::CSenMessageResourceHandler(TInt aTxnId,
       
    98         TBool aIncoming, TBool aIsSoap, TInt aProgress,
       
    99         RSenConnectionServerSession* aOwner): CActive(EPriorityStandard),
       
   100         iOwner(aOwner)
       
   101     {
       
   102     TTransferProgress& data = iProgressData();
       
   103     data.iTxnId = aTxnId;
       
   104     data.iIncoming = aIncoming;
       
   105     data.iSoap = aIsSoap;
       
   106     data.iProgress = aProgress;
       
   107     }
       
   108 
       
   109 CSenMessageResourceHandler::~CSenMessageResourceHandler()
       
   110     {
       
   111     Cancel();
       
   112     delete iSoapOrCid;
       
   113     }
       
   114 
       
   115 void CSenMessageResourceHandler::DoCancel()
       
   116     {
       
   117     
       
   118     }
       
   119 
       
   120 void CSenMessageResourceHandler::RunL()
       
   121     {
       
   122     iOwner->Remove(this);
       
   123     delete this;
       
   124     }
       
   125 
       
   126 TInt CSenMessageResourceHandler::SetBuffer(const TDesC8& aSoapOrCid)
       
   127     {
       
   128     iSoapOrCid = aSoapOrCid.Alloc();
       
   129     if (iSoapOrCid)
       
   130         {
       
   131         return KErrNone;
       
   132         }
       
   133     return KErrNoMemory;
       
   134     }
       
   135 
       
   136 TInt RSenConnectionServerSession::CreateSession(const RMessage2& aMessage)
       
   137     {
       
   138     TFullName name;
       
   139     TInt err = aMessage.Read(0, name);
       
   140     if (err != KErrNone)
       
   141         {
       
   142         return err;
       
   143         }
       
   144     err = RSessionBase::CreateSession(name, TVersion(), KAsyncMessageSlots);
       
   145     return err;
       
   146     }
       
   147 
       
   148 void RSenConnectionServerSession::SendFileProgress(TInt aTxnId, TBool aIncoming,
       
   149         TBool aIsSoap, const TDesC8& aSoapOrCid, TInt aProgress)
       
   150     {
       
   151     CSenMessageResourceHandler* resHandler = new CSenMessageResourceHandler(
       
   152             aTxnId, aIncoming, aIsSoap, aProgress, this);
       
   153     if (!resHandler)
       
   154         {
       
   155         return;
       
   156         }
       
   157     if (resHandler->SetBuffer(aSoapOrCid) != KErrNone)
       
   158         {
       
   159         delete resHandler;
       
   160         return;
       
   161         }
       
   162 
       
   163     if (iFirst)
       
   164         {
       
   165         iFirst->iPrevious = resHandler;
       
   166         }
       
   167     resHandler->iNext = iFirst;
       
   168     iFirst = resHandler;
       
   169 
       
   170     CActiveScheduler::Add(resHandler);
       
   171     resHandler->SetActive();
       
   172     resHandler->iStatus = KRequestPending;
       
   173 
       
   174     TIpcArgs args(&resHandler->iProgressData, resHandler->iSoapOrCid);
       
   175     SendReceive(ESenCliServTransferProgress, args, resHandler->iStatus);
       
   176     }
       
   177 TBool RSenConnectionServerSession::OnGetBrandIdL(  const TDesC8& aBrandIdListAsXmlSnippet, RBuf8& aSelectedBrandId)
       
   178     {
       
   179     
       
   180     HBufC8* cbXmlSnippet = aBrandIdListAsXmlSnippet.Alloc();
       
   181     CleanupStack::PushL(cbXmlSnippet);    
       
   182 	TInt retVal(KErrNone);
       
   183 	TIpcArgs args;
       
   184 	TRequestStatus  status = KRequestPending; 	
       
   185 	TBool goNogo = EFalse;
       
   186 	args.Set(0, &goNogo);
       
   187 	args.Set(1, cbXmlSnippet);
       
   188 	args.Set(2, &aSelectedBrandId);
       
   189 	SendReceive(ESenCliServGoNoGo, args, status);
       
   190    	User::WaitForRequest(status);
       
   191    	retVal = status.Int();
       
   192     CleanupStack::PopAndDestroy(cbXmlSnippet);    
       
   193    
       
   194     if(retVal == KErrNone)
       
   195 	    return goNogo;        
       
   196 	else
       
   197 	    return EFalse;
       
   198 	    
       
   199     }
       
   200 void RSenConnectionServerSession::Remove(
       
   201         CSenMessageResourceHandler* aResourceHandler)
       
   202     {
       
   203     if (aResourceHandler == iFirst)
       
   204         {
       
   205         iFirst = aResourceHandler->iNext;
       
   206         if (iFirst)
       
   207             {
       
   208             iFirst->iPrevious = NULL;
       
   209             }
       
   210         }
       
   211     else
       
   212         {
       
   213         aResourceHandler->iPrevious->iNext = aResourceHandler->iNext;
       
   214         }
       
   215     }
       
   216 
       
   217 
       
   218 void RSenConnectionServerSession::Close()
       
   219     {
       
   220     CSenMessageResourceHandler* resHandler = iFirst;
       
   221     while (resHandler)
       
   222         {
       
   223         resHandler->Cancel();
       
   224         CSenMessageResourceHandler* tmp = resHandler;
       
   225         resHandler = resHandler->iNext;
       
   226         delete tmp;
       
   227         }
       
   228     RSessionBase::Close();
       
   229     }
       
   230 
       
   231 TInt RSenConnectionServerSession::InitProgressObserver(const RMessage2& aMessage)
       
   232 	{
       
   233 	TIpcArgs args(aMessage.Ptr1(), aMessage.Ptr2());
       
   234     TInt err = Send(ESenCliServInitialize, args);
       
   235     return err;
       
   236 	}
       
   237 #ifdef __ENABLE_ALR__
       
   238 TInt RSenConnectionServerSession::InitMobilityObserver(const RMessage2& aMessage)
       
   239 	{
       
   240 	TIpcArgs args(aMessage.Ptr1(), aMessage.Ptr2());
       
   241     TInt err = Send(ESenCliServMobilityInitialize, args);
       
   242     return err;
       
   243 	}
       
   244 
       
   245 TInt RSenConnectionServerSession::PreferredCarrierAvailable( TAccessPointInfo& aOldAPInfo,
       
   246                                         TAccessPointInfo& aNewAPInfo, TBool& aIsUpgrade, TBool& aIsSeemLess)
       
   247 	{
       
   248         // Note : Using TPtr8 since aIsSeamless is binary information
       
   249 	 TPtr8 upGradeDescriptor(reinterpret_cast<TUint8*>(&aIsUpgrade),sizeof(aIsUpgrade),
       
   250         sizeof(aIsUpgrade));
       
   251 	 TPtr8 seemLessdescriptor(reinterpret_cast<TUint8*>(&aIsSeemLess),sizeof(aIsSeemLess),
       
   252         sizeof(aIsSeemLess));
       
   253         
       
   254     TInt retVal(KErrNone);
       
   255     TIpcArgs args(aOldAPInfo.AccessPoint(), aNewAPInfo.AccessPoint(), &upGradeDescriptor, &seemLessdescriptor);    
       
   256 	CSenConnAgentSync* caSync = new CSenConnAgentSync();
       
   257 	if(caSync)
       
   258 		{
       
   259 		caSync->Start();
       
   260 		SendReceive(ESenCliServPrefferedCarrierAvailable, args, caSync->iStatus);
       
   261         retVal = caSync->iStatus.Int();
       
   262 		delete caSync;
       
   263 		}
       
   264 	return retVal;        
       
   265 	
       
   266 	}
       
   267 
       
   268 TInt RSenConnectionServerSession::NewCarrierActive( TAccessPointInfo& aNewAPInfo, TBool& aIsSeamless )
       
   269     {
       
   270     // Note : Using TPtr8 since aIsSeamless is binary information
       
   271     TPtr8 descriptor(reinterpret_cast<TUint8*>(&aIsSeamless),sizeof(aIsSeamless),
       
   272     sizeof(aIsSeamless));
       
   273     TInt retVal(KErrNone);
       
   274     TIpcArgs args(aNewAPInfo.AccessPoint(), &descriptor);    
       
   275     CSenConnAgentSync* caSync = new CSenConnAgentSync();
       
   276     if(caSync)
       
   277         {
       
   278         caSync->Start();		
       
   279         SendReceive(ESenCliServNewCarrierActive, args, caSync->iStatus);
       
   280         retVal = caSync->iStatus.Int();
       
   281         delete caSync;
       
   282         }
       
   283     return retVal;
       
   284     }
       
   285 
       
   286 TInt RSenConnectionServerSession::MobilityError( TInt& aError )
       
   287     {
       
   288     TInt retVal(KErrNone);
       
   289     TIpcArgs args(aError);
       
   290     CSenConnAgentSync* caSync = new CSenConnAgentSync();
       
   291     if(caSync)
       
   292         {
       
   293         caSync->Start();		
       
   294         SendReceive(ESenCliServMobilityError, args, caSync->iStatus);
       
   295         retVal = caSync->iStatus.Int();
       
   296         delete caSync;
       
   297         }
       
   298     return retVal;        
       
   299     }
       
   300 #endif //__ENABLE_ALR__
       
   301 
       
   302 
       
   303 TInt RSenConnectionServerSession::InitAuthObserver(const RMessage2& aMessage)
       
   304 	{
       
   305 	TIpcArgs args(aMessage.Ptr1(), aMessage.Ptr2());
       
   306     TInt err = Send(ESenCliServAuthInitialize, args);
       
   307     return err;
       
   308 	}
       
   309 TInt RSenConnectionServerSession::InitCoBrandingObserver(const RMessage2& aMessage)
       
   310 	{
       
   311 	TIpcArgs args(aMessage.Ptr1(), aMessage.Ptr2());
       
   312     TInt err = Send(ESenCliServCoBrandingInitialize, args);
       
   313     return err;
       
   314 	}
       
   315 TInt RSenConnectionServerSession::ReauthenticationNeeded(CSenChunk& aSenChunk)
       
   316 	{
       
   317 	TInt retVal(KErrNoMemory);
       
   318 	TIpcArgs args;
       
   319 	CActiveSchedulerWait asWait;
       
   320 	aSenChunk.ChunkToArgs(args, 0);
       
   321 	args.Set(1, &asWait);
       
   322 	CSenConnAgentSync* caSync = new CSenConnAgentSync();
       
   323 	if(caSync)
       
   324 		{
       
   325 		SendReceive(ESenCliServReAuthNeeded, args, caSync->iStatus);
       
   326 		caSync->Start();
       
   327 		Mem::FillZ(&asWait, sizeof(asWait));
       
   328 		asWait.Start();
       
   329 		retVal = caSync->iStatus.Int();
       
   330 		delete caSync;
       
   331 		}
       
   332 	return retVal;
       
   333 	}
       
   334 
       
   335 CSenConnAgentSync::CSenConnAgentSync(): CActive(EPriorityStandard)
       
   336 	{
       
   337 	CActiveScheduler::Add(this);
       
   338 	iStatus = KRequestPending;
       
   339 	}
       
   340 
       
   341 CSenConnAgentSync::~CSenConnAgentSync()
       
   342 	{
       
   343 	if(IsActive())
       
   344 		{
       
   345 		Cancel();
       
   346 		}
       
   347 	}
       
   348 
       
   349 void CSenConnAgentSync::DoCancel()
       
   350 	{	
       
   351 	}
       
   352 
       
   353 void CSenConnAgentSync::RunL()
       
   354 	{
       
   355 	}
       
   356 
       
   357 void CSenConnAgentSync::Start()
       
   358 	{
       
   359 	SetActive();
       
   360 	}
       
   361 
       
   362 CSenClientSession* CSenClientSession::NewL(MSenServiceManager& aServer, CSenServerContext& aCtx)
       
   363     {
       
   364     CSenClientSession* self = CSenClientSession::NewLC(aServer, aCtx);
       
   365     CleanupStack::Pop(self) ;
       
   366     return self ;
       
   367     }
       
   368 
       
   369 CSenClientSession* CSenClientSession::NewLC(MSenServiceManager& aServer, CSenServerContext& aCtx)
       
   370     {
       
   371     CSenClientSession* self = new (ELeave) CSenClientSession(aServer, aCtx);
       
   372     CleanupStack::PushL(self) ;
       
   373     self->ConstructL() ;
       
   374     return self;
       
   375     }
       
   376 
       
   377 
       
   378 CSenClientSession::CSenClientSession(MSenServiceManager& aServer, CSenServerContext& aCtx)
       
   379     : CSession2(),
       
   380     iManager(aServer),
       
   381     iStatus(0),
       
   382     iConsumerID(NULL),
       
   383     iSendBuf(NULL),
       
   384     iInitializer(NULL),
       
   385     iAllowWSDataReg(ENotChecked),
       
   386     iAllowWSDataUnReg(ENotChecked),
       
   387     ipTransport(NULL),
       
   388     ipIdentifier(NULL),
       
   389     ipHostletAwaitOp(NULL),
       
   390     iHostletRequests( ETrue, EFalse ),
       
   391     iAllowShowDialogCount(0),
       
   392     iConnectionID(KErrNotFound),
       
   393     iAuthenticationRetries(0),
       
   394     iServerContext( aCtx ),
       
   395     iConnectionHasCoBrandingCallback(EFalse),
       
   396     iReauthResendNeeded(EFalse)
       
   397 #ifdef __ENABLE_ALR__
       
   398     ,iMobiltyObserver(NULL),
       
   399     iALRObserver(NULL),
       
   400     iMobilityCallBackForwarded(EFalse),
       
   401     iMobilityChoice(EFalse)
       
   402 #endif
       
   403     {
       
   404     }
       
   405 
       
   406 void CSenClientSession::ConstructL()
       
   407     {
       
   408     iConnectionID = iManager.NextConnectionID();
       
   409     #ifdef _SENDEBUG
       
   410     
       
   411     
       
   412     TFileName logFile;
       
   413     logFile.Append( KSenCoreServiceManagerLogFile().Left(KSenCoreServiceManagerLogFile().Length()-4) ); // exclude ".log" file extension
       
   414     logFile.AppendNum( iConnectionID );
       
   415     logFile.Append( KSenUnderline );
       
   416     
       
   417     logFile.Append( KSenCoreServiceManagerLogFile().Right(4) ); // postfix with ".log" file extension
       
   418     TLSLOG_OPEN_TO_MODE(KSenClientSessionLogChannelBase+iConnectionID, KSenClientSessionLogLevel, KSenCoreServiceManagerLogDir, logFile, EFileLoggingModeAppend);
       
   419 #endif
       
   420     
       
   421     CSLOG_L(iConnectionID, KMinLogLevel ,"CSenClientSession::ConstructL");
       
   422     // Generate unique id for this consumer
       
   423     iConsumerID = iManager.RandomGuidL();
       
   424     ipIdentifier = CSenIdentifier::NewL(SenIdentifier::ESession, *iConsumerID);
       
   425     __ASSERT_ALWAYS(iConsumerID!=NULL, User::Leave(KErrConsumerIdIsNull));
       
   426     CSLOG(iConnectionID, KNormalLogLevel ,(iConsumerID->Des()));
       
   427     iInitializer = CSenWSDescription::NewL();
       
   428     iManager.IncrementConnections();
       
   429     }
       
   430 
       
   431 CSenClientSession::~CSenClientSession()
       
   432     {
       
   433     CSLOG_L(iConnectionID, KMinLogLevel ,"CSenClientSession::~CSenClientSession - START");
       
   434 #ifdef __ENABLE_ALR__    
       
   435     iMobiltyObserver = NULL ;
       
   436 #endif
       
   437     switch( iSessionType )
       
   438         {
       
   439         case ERemoteConsumer_SC:
       
   440             {
       
   441             CSLOG_L(iConnectionID, KMinLogLevel ,"- session type: ERemoteConsumer_SC");
       
   442             //TTL maangement
       
   443             if( iServiceSession )
       
   444                 {
       
   445                 MSenTransport* pTransport = iServiceSession->Transport();
       
   446                 if ( pTransport )
       
   447                     {
       
   448                     TRAP_IGNORE( pTransport->UnsubscribeEventListenerL(*this); )
       
   449                     }
       
   450 	                              
       
   451                 // Notify the framework plug-in about consumer being removed
       
   452                 if( iFwNotified )
       
   453                     {
       
   454                     TRAP_IGNORE( iManager.NotifyFrameworksL(
       
   455                             iServiceSession->FrameworkId(),
       
   456                             KSenEventConsumerRemoved,
       
   457                             this); )        
       
   458                     }
       
   459                 }
       
   460             }
       
   461         break;
       
   462         case ERemoteHostlet_HC:
       
   463             {
       
   464             CSLOG_L(iConnectionID, KMinLogLevel ,"- session type: ERemoteHostlet_HC");
       
   465             // Remove this hostlet from the session
       
   466             if( iServiceSession )
       
   467                 {
       
   468                 TRAP_IGNORE( iServiceSession->SetHostletL(NULL); )
       
   469                 }
       
   470             }
       
   471         break;
       
   472         case ENotInitialized:
       
   473             {
       
   474             CSLOG_L(iConnectionID, KMinLogLevel ,"- session type: ENotInitialized");
       
   475             }
       
   476         break;
       
   477         default:
       
   478             {
       
   479             CSLOG_L(iConnectionID, KMinLogLevel ,"- unknown session type.");
       
   480             }
       
   481         }
       
   482     
       
   483     //Loop and complete orphan RMessage2s
       
   484     CSLOG_L(iConnectionID, KMinLogLevel ,"- Loop and complete orphan RMessage2s");
       
   485 
       
   486     CSenClientSession::CompletePendingMessages();
       
   487 
       
   488     TInt count(iHostletRequests.Count());
       
   489     if( count > 0)
       
   490         {
       
   491         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d hostlet request(s) waiting. Completing due this host is freed."), count));
       
   492         for ( TInt hr=(count-1); hr>=0; hr-- )
       
   493             {
       
   494             CSenClientMessage* pMessage = (CSenClientMessage*)iHostletRequests.ValueAt( hr ); 
       
   495             TInt* pKey = iHostletRequests.KeyAt( hr );
       
   496 
       
   497             if( pMessage && pKey )
       
   498                 {
       
   499                 MSenRemoteServiceConsumer* pConsumer = pMessage->Consumer();
       
   500                 if( pConsumer )
       
   501                     {
       
   502                     // Notifying consumer
       
   503                     TPtrC8 id = pConsumer->Id();
       
   504                     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Notifying consumer (ID: '%S') that it's host is gone."), &id));
       
   505                     
       
   506                     TRAP_IGNORE( pConsumer->HandleErrorL(NULL, KErrSenCancelled, *pKey, NULL); ) 
       
   507                     }
       
   508                 }
       
   509             }
       
   510         iHostletRequests.Reset(); // de-allocates the keys (pKey -pointers)
       
   511         }
       
   512 
       
   513     iPendingTransactions.ResetAndDestroy();
       
   514     iPendingTxnIds.ResetAndDestroy();
       
   515 
       
   516     if(ipHostletAwaitOp)
       
   517         {
       
   518         RMessage2& await = ipHostletAwaitOp->RMessage();
       
   519         await.Complete(ESenServRequestCancelled);
       
   520         }
       
   521 
       
   522     if(iServiceSession)
       
   523         {
       
   524         // Notify responsible framework, so that it 
       
   525         // can do required cleanup for the session
       
   526         CSenClientSession::ReleaseServiceSession();
       
   527         }
       
   528     delete iSendBuf;
       
   529     delete iConsumerID;
       
   530     delete ipIdentifier;
       
   531     delete iInitializer;
       
   532 
       
   533     delete ipTransport;
       
   534     delete ipHostletAwaitOp;
       
   535     ipHostletAwaitOp = NULL;
       
   536     iConnectionSession.Close();
       
   537 
       
   538     /*    
       
   539     if( iSecureId > 0 )
       
   540         {
       
   541         CSenApplicationContext& appCtx = iServerContext.OpenApplicationContextL( iSecureId );
       
   542         if( iConnectionID > KErrNotFound )
       
   543             {
       
   544             CSenClientContext& clientCtx = appCtx.OpenClientContextL( iConnectionID );
       
   545             
       
   546             
       
   547             appCtx.CloseClientContext( clientCtx );
       
   548             iServerContext.CloseApplicationContext( appCtx );
       
   549             }
       
   550         }
       
   551     */
       
   552 #ifdef __ENABLE_ALR__    
       
   553     if (iSessionType == ERemoteConsumer_SC && iALRObserver != NULL)
       
   554         {
       
   555         delete iALRObserver ;
       
   556         CSLOG_L(iConnectionID, KMinLogLevel , "-iALRObserver deleted ");
       
   557         }       
       
   558 #endif        //__ENABLE_ALR__
       
   559 
       
   560     iManager.DecrementConnections();
       
   561     CSLOG_L(iConnectionID, KMinLogLevel ,"CSenClientSession::~CSenClientSession - END");
       
   562     #ifdef _SENDEBUG
       
   563     TLSLOG_CLOSE(KSenClientSessionLogChannelBase+iConnectionID);
       
   564     #endif
       
   565     }
       
   566 
       
   567 
       
   568 RTransactionArray& CSenClientSession::Transactions()
       
   569     {
       
   570     return iPendingTransactions;
       
   571     }
       
   572 
       
   573 RTransactionIdArray& CSenClientSession::TxnIds()
       
   574     {
       
   575     return iPendingTxnIds;
       
   576     }
       
   577     
       
   578 RHostletRequestMap& CSenClientSession::HostletRequestMap()
       
   579     {
       
   580     return iHostletRequests;
       
   581     }
       
   582         
       
   583 // All server side session objects have a ServiceL loop which
       
   584 // will be called from CS Framework
       
   585 void CSenClientSession::ServiceL(const RMessage2& aMessage)
       
   586     {
       
   587     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::ServiceL")));
       
   588     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- RMessage2.Handle(): %d"), aMessage.Handle()));
       
   589 
       
   590     switch (aMessage.Function())
       
   591         {
       
   592         case ESenServInitialize:
       
   593             {
       
   594            
       
   595             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServInitialize")));
       
   596             delete iSendBuf;
       
   597             iSendBuf = NULL;
       
   598             InitializeL(aMessage);
       
   599             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServInitialize Completed")));
       
   600             break;
       
   601             }
       
   602         case ESenServTransaction:
       
   603             {
       
   604             
       
   605             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServTransaction")));
       
   606             delete iSendBuf;
       
   607             iSendBuf = NULL;
       
   608             TransactionL(aMessage);
       
   609             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServTransaction Completed")));
       
   610             break;
       
   611             }
       
   612         case ESenServSendMsgAndGetTxnId:
       
   613             {
       
   614             
       
   615             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServSendMsgAndGetTxnId")));
       
   616             delete iSendBuf;
       
   617             iSendBuf = NULL;
       
   618             SendMsg(aMessage);
       
   619             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServSendMsgAndGetTxnId Completed")));
       
   620             break;
       
   621             }
       
   622         case ESenServInstallFramework:
       
   623             {
       
   624            
       
   625             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServInstallFramework")));
       
   626             delete iSendBuf;
       
   627             iSendBuf = NULL;
       
   628             InstallFrameworkL(aMessage);
       
   629             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServInstallFramework Completed")));
       
   630             break;
       
   631             }
       
   632         case ESenServAssociateService:
       
   633             {
       
   634             
       
   635             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServAssociateService")));
       
   636             delete iSendBuf;
       
   637             iSendBuf = NULL;
       
   638             AssociateServiceL(aMessage);
       
   639             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServAssociateService Completed")));
       
   640             break;
       
   641             }
       
   642         case ESenServDissociateService:
       
   643             {
       
   644             
       
   645             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServDissociateService")));
       
   646             delete iSendBuf;
       
   647             iSendBuf = NULL;
       
   648             DissociateServiceL(aMessage);
       
   649             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServDissociateService Completed")));
       
   650             break;
       
   651             }
       
   652         case ESenServRegisterIdentityProvider:
       
   653             {
       
   654            
       
   655             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRegisterIdentityProvider")));
       
   656             delete iSendBuf;
       
   657             iSendBuf = NULL;
       
   658             RegisterIdentityProviderL(aMessage);
       
   659             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRegisterIdentityProvider Completed")));
       
   660             break;
       
   661             }
       
   662         case ESenServUnregisterIdentityProvider:
       
   663             {
       
   664             
       
   665             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServUnregisterIdentityProvider")));
       
   666             delete iSendBuf;
       
   667             iSendBuf = NULL;
       
   668             UnregisterIdentityProviderL(aMessage);
       
   669             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServUnregisterIdentityProvider Completed")));
       
   670             break;
       
   671             }
       
   672         case ESenServRegisterServiceDescription:
       
   673             {
       
   674            
       
   675             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRegisterServiceDescription")));
       
   676             delete iSendBuf;
       
   677             iSendBuf = NULL;
       
   678             RegisterServiceDescriptionL(aMessage);
       
   679             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRegisterServiceDescription Completed")));
       
   680             break;
       
   681             }
       
   682         case ESenServUnregisterServiceDescription:
       
   683             {
       
   684             
       
   685             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServUnregisterServiceDescription")));
       
   686             delete iSendBuf;
       
   687             iSendBuf = NULL;
       
   688             UnregisterServiceDescriptionL(aMessage);
       
   689             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServUnregisterServiceDescription Completed")));
       
   690             break;
       
   691             }
       
   692         case ESenServGetServiceDescriptionsByPattern:
       
   693             {
       
   694             
       
   695             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetServiceDescriptionsByPattern")));
       
   696             ServiceDescriptionsByPatternL(aMessage);
       
   697             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetServiceDescriptionsByPattern Completed")));
       
   698             break;
       
   699             }
       
   700         case ESenServGetLengthOfServiceDescriptionByPattern:
       
   701             {
       
   702             
       
   703             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetLengthOfServiceDescriptionByPattern")));
       
   704             delete iSendBuf;
       
   705             iSendBuf = NULL;
       
   706             ServiceDescriptionsByPatternL(aMessage);
       
   707             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetLengthOfServiceDescriptionByPattern Completed")));
       
   708             break;
       
   709             }
       
   710         case ESenServGetServiceDescriptionsByUri:
       
   711             {
       
   712             
       
   713             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetServiceDescriptionsByUri")));
       
   714             ServiceDescriptionsByUriL(aMessage);
       
   715             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetServiceDescriptionsByUri Completed")));
       
   716             break;
       
   717             }
       
   718         case ESenServGetLengthOfServiceDescriptionByUri:
       
   719             {
       
   720            
       
   721             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetLengthOfServiceDescriptionByUri")));
       
   722             delete iSendBuf;
       
   723             iSendBuf = NULL;
       
   724             ServiceDescriptionsByUriL(aMessage);
       
   725             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetLengthOfServiceDescriptionByUri Completed")));
       
   726             break;
       
   727             }
       
   728         case ESenServIsReady:
       
   729             {
       
   730             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServIsReady")));
       
   731             
       
   732             delete iSendBuf;
       
   733             iSendBuf = NULL;
       
   734             IsReadyL(aMessage);
       
   735             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServIsReady Completed")));
       
   736             break;
       
   737             }
       
   738         case ESenServHasFacet:
       
   739             {
       
   740             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServHasFacet")));
       
   741             
       
   742             delete iSendBuf;
       
   743             iSendBuf = NULL;
       
   744             HasFacetL(aMessage);
       
   745             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServHasFacet Completed")));
       
   746             break;
       
   747             }
       
   748         case ESenServServerMessagesOnOff:
       
   749             {
       
   750             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServServerMessagesOnOff")));
       
   751             
       
   752             delete iSendBuf;
       
   753             iSendBuf = NULL;
       
   754             CompleteServerMessagesOnOffL(aMessage);
       
   755             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServServerMessagesOnOff Completed")));
       
   756             break;
       
   757             }
       
   758         case ESenServRequestServiceDescription:
       
   759             {
       
   760             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRequestServiceDescription")));
       
   761             
       
   762             delete iSendBuf;
       
   763             iSendBuf = NULL;
       
   764             RequestServiceDescriptionL(aMessage);
       
   765             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRequestServiceDescription Completed")));
       
   766             break;
       
   767             }
       
   768         case ESenServReceiveServiceDescription:
       
   769             {
       
   770             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServReceiveServiceDescription")));
       
   771             
       
   772             ReceiveServiceDescriptionL(aMessage);
       
   773             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServReceiveServiceDescription Completed")));
       
   774             break;
       
   775             }
       
   776         case ESenServStartTransaction:
       
   777             {
       
   778             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServStartTransaction")));
       
   779             
       
   780             delete iSendBuf;
       
   781             iSendBuf = NULL;
       
   782             StartTransactionL(aMessage);
       
   783             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServStartTransaction Completed")));
       
   784             break;
       
   785             }
       
   786         case ESenServTransactionCompleted:
       
   787             {
       
   788             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServTransactionCompleted")));
       
   789             
       
   790             delete iSendBuf;
       
   791             iSendBuf = NULL;
       
   792             TransactionCompletedL(aMessage);
       
   793             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServTransactionCompleted Completed")));
       
   794             break;
       
   795             }
       
   796         case ESenServCancelSession:
       
   797             {
       
   798             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServCancelSession")));
       
   799             
       
   800             CancelSessionL(aMessage);
       
   801             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServCancelSession Completed")));
       
   802             break;
       
   803             }
       
   804         case ESenServSetTransportProperties:
       
   805             {
       
   806             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServSetTransportProperties")));
       
   807             
       
   808             SetTransportPropertiesL(aMessage);
       
   809             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServSetTransportProperties Completed")));
       
   810             break;
       
   811             }
       
   812         case ESenServTransportProperties:
       
   813             {
       
   814             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServTransportProperties")));
       
   815             
       
   816             TransportPropertiesL(aMessage);
       
   817             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServTransportProperties Completed")));
       
   818             break;
       
   819             }
       
   820 
       
   821         // HOSTLET OPERATIONS
       
   822         case ESenServEstablishHostletConnection:
       
   823             {
       
   824             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServEstablishHostletConnection")));
       
   825             
       
   826             EstablishHostletConnectionL(aMessage);
       
   827             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServEstablishHostletConnection Completed")));
       
   828             break;
       
   829             }
       
   830         case ESenServAwaitHostletRequest:
       
   831             {
       
   832             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServAwaitHostletRequest")));
       
   833             
       
   834             AwaitHostletRequestL(aMessage);
       
   835             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServAwaitHostletRequest Completed")));
       
   836             break;
       
   837             }
       
   838 /*
       
   839         case ESenServAcquireRequestHandle:
       
   840             {
       
   841             LOG_WRITE_L("ESenServAcquireRequestHandle");
       
   842             //AcquireHostletRequestHandleL();
       
   843             break;
       
   844             }
       
   845 */
       
   846         case ESenServProvideHostletResponse:
       
   847             {
       
   848             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServHostletResponse")));
       
   849             
       
   850             ProvideHostletResponseL(aMessage);
       
   851             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServHostletResponse Completed")));
       
   852             break;
       
   853             }
       
   854         case ESenServMoveChunk:
       
   855             {
       
   856             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServMoveChunk")));
       
   857             
       
   858             MoveChunkL(aMessage);
       
   859             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServMoveChunk Completed")));
       
   860             break;
       
   861             }
       
   862         case ESenServMoveFile:
       
   863             {
       
   864             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServMoveFile")));
       
   865             
       
   866             MoveFileL(aMessage);
       
   867             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServMoveFile Completed")));
       
   868             break;
       
   869             }
       
   870 		case ESenServSendFileHandle:
       
   871             {
       
   872             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServSendFileHandle")));
       
   873             SendFileHandleL(aMessage);
       
   874 			CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServSendFileHandle Completed")));
       
   875             break;
       
   876             }            
       
   877         case ESenServGetGredentials:
       
   878             {
       
   879             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetGredentials")));
       
   880             
       
   881             CredentialsL(aMessage);
       
   882             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServGetGredentials Completed")));
       
   883             break;
       
   884             }
       
   885         case ESenServAddCredential:
       
   886             {
       
   887             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServAddCredential")));
       
   888             
       
   889             AddCredentialL(aMessage);
       
   890             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServAddCredential Completed")));
       
   891             break;
       
   892             }
       
   893         case ESenServRemoveCredential:
       
   894             {
       
   895             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRemoveCredential")));
       
   896             
       
   897             RemoveCredentialsL(aMessage);
       
   898             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServRemoveCredential Completed")));
       
   899             break;
       
   900             }
       
   901         case ESenServCancelRequest:
       
   902             {
       
   903             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServCancelRequest")));
       
   904             
       
   905             CancelRequestL(aMessage);
       
   906             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServCancelRequest Completed")));
       
   907             break;
       
   908             }
       
   909         case ESenServConnectionID:
       
   910             {
       
   911             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServConnectionID")));
       
   912             
       
   913             ConnectionID(aMessage);
       
   914             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServConnectionID Completed")));
       
   915             break;
       
   916             }
       
   917         case ESenServConnectionIdentityProvider:
       
   918             {
       
   919             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServConnectionIdentityProvider")));
       
   920             
       
   921             ConnectionIdentityProviderL(aMessage);
       
   922             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenServConnectionIdentityProvider Completed")));
       
   923             break;
       
   924             }
       
   925         case ESenObserveCoBranding:
       
   926             {
       
   927     		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenObserveCoBranding");
       
   928     		ObserveCoBranding(aMessage);
       
   929     		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenObserveCoBranding Completed");
       
   930             break;
       
   931             }
       
   932         case ESenObserveTransfer:
       
   933             {
       
   934     		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenObserveTransfer");
       
   935     		ObserveTransfer(aMessage);
       
   936     		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenObserveTransfer Completed");
       
   937             break;
       
   938             }
       
   939         case ESenObserveAuthCallback:
       
   940 		{
       
   941 		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenObserveAuthCallback");
       
   942 		ObserveAuthCallback(aMessage);
       
   943 		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenObserveAuthCallback Completed");
       
   944 		break;
       
   945 		}
       
   946 #ifdef __ENABLE_ALR__		
       
   947 		case ESenServRegisterMobiltyObserver:
       
   948 			{
       
   949 			CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServRegisterMobiltyObserver");
       
   950 			ObserveMobiltyService(aMessage);
       
   951 			CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServRegisterMobiltyObserver Completed");
       
   952 			break;
       
   953 			}
       
   954 		case ESenServMigrateToPreffredCarrier:
       
   955 			{
       
   956 			CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServMigrateToPreffredCarrier");
       
   957 			MigrateToPrefferedCarrierL(aMessage);
       
   958 			CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServMigrateToPreffredCarrier Completed");
       
   959 			break;
       
   960 			}		
       
   961 		case ESenServNewCarrierAccepted:
       
   962     	    {
       
   963     		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServNewCarrierAccepted");
       
   964     		NewCarrierAcceptedL(aMessage);
       
   965     		CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServNewCarrierAccepted Completed");
       
   966     	    break;
       
   967     	    }		
       
   968 #endif    	    
       
   969         case ESenTransferProgress:
       
   970             {
       
   971             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenTransferProgress")));
       
   972             aMessage.Complete(SendProgressToHostlet(aMessage));
       
   973             CSLOG(iConnectionID, KMinLogLevel ,(_L("ESenTransferProgress Completed")));
       
   974             break;
       
   975             }
       
   976         case ESenServSearchIdentityProvider:
       
   977         	{
       
   978         	CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServReauthenticationNeeded");
       
   979         	SearchIdentityProviderL(aMessage);
       
   980         	CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServReauthenticationNeeded Completed");
       
   981         	break;
       
   982         	}
       
   983         case ESenTrafficDetails: 	 
       
   984             {
       
   985         	CSLOG_L(iConnectionID,KMinLogLevel ,"ESenTrafficDetails");
       
   986             DataTrafficDetails(aMessage); 
       
   987             CSLOG_L(iConnectionID,KMinLogLevel ,"ESenTrafficDetails Completed");
       
   988             break;
       
   989             }
       
   990         case ESenServGetIdentityProviders:
       
   991         	{
       
   992         	CSLOG_L(iConnectionID,KMinLogLevel ,"ESenServGetIdentityProviders");
       
   993         	IdentityProviders(aMessage);
       
   994         	break;
       
   995         	}
       
   996         default:
       
   997             {
       
   998             CSLOG(iConnectionID, KMinLogLevel ,(_L("default")));
       
   999             
       
  1000             CSLOG(iConnectionID, KMinLogLevel ,(_L("Calling PanicClient( EBadRequest )")));
       
  1001             
       
  1002             PanicClient(aMessage, EBadRequest);
       
  1003             CSLOG(iConnectionID, KMinLogLevel ,(_L("default Completed")));
       
  1004             break;
       
  1005             }
       
  1006         }
       
  1007     }
       
  1008 
       
  1009 TInt CSenClientSession::ParseSessionInitializerL( CSenWSDescription*& apInitializer,
       
  1010                                                   const TDesC8& aSdAsXml,
       
  1011                                                   const TDesC8* apConsumerPolicy )
       
  1012     {
       
  1013     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ParseSessionInitializerL");
       
  1014     TInt retVal(KErrNone);
       
  1015     CSenWSDescription* pSD = NULL;
       
  1016     delete apInitializer;
       
  1017     apInitializer = NULL;
       
  1018     
       
  1019     if(apConsumerPolicy && apConsumerPolicy->Length()>0)
       
  1020         {
       
  1021         CSLOG_L(iConnectionID, KMinLogLevel, "- Service Pattern received");
       
  1022         pSD = CSenWSPattern::NewLC();
       
  1023         pSD->SetReader(*iManager.XMLReader());
       
  1024         TInt leaveCode(KErrNone);
       
  1025         TRAP(leaveCode, pSD->ParseL(aSdAsXml));
       
  1026         if(leaveCode!=KErrNone)
       
  1027             {
       
  1028             CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ParseSessionInitializerL:");
       
  1029             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- ParseL( SD_AS_XML ) leaved: %d"), leaveCode));
       
  1030 //            retVal = leaveCode; // known issue: leave code 991 from SAX framework
       
  1031             }
       
  1032         CSLOG_L(iConnectionID, KMinLogLevel ,"CSenClientSession::ParseSessionInitializerL - Consumer policy before parsing:");
       
  1033         CSLOG_ALL(iConnectionID, KMinLogLevel ,( *apConsumerPolicy ));
       
  1034 
       
  1035         // add the content into internal ConsumerPolicy member variable of SD..
       
  1036         leaveCode = KErrNone;
       
  1037         TRAP(leaveCode, pSD->ParseL(*apConsumerPolicy));
       
  1038         if(retVal == KErrNone && leaveCode!=KErrNone)
       
  1039             {
       
  1040             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- ParseL(policy) leaved: %d"), leaveCode));
       
  1041 //            retVal = leaveCode; // known issue: leave code 991 from SAX framework
       
  1042             }
       
  1043         }
       
  1044     else
       
  1045         {
       
  1046         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::ParseSessionInitializerL: parsing XML (%d bytes) into service description"), aSdAsXml.Length()));
       
  1047         pSD = CSenWSDescription::NewLC();
       
  1048         pSD->SetReader(*iManager.XMLReader());
       
  1049         TInt leaveCode(KErrNone);
       
  1050         TRAP(leaveCode, pSD->ParseL(aSdAsXml));
       
  1051         if(leaveCode!=KErrNone)
       
  1052             {
       
  1053             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::ParseSessionInitializerL - ParseL(SD) leaved: %d"), leaveCode));
       
  1054             retVal = leaveCode;
       
  1055             }
       
  1056         }
       
  1057 
       
  1058 #ifdef _SENDEBUG
       
  1059     HBufC8* pAsXml = pSD->AsXmlL();
       
  1060     if(pAsXml)
       
  1061         {
       
  1062         CleanupStack::PushL(pAsXml);
       
  1063         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ParseSessionInitializerL");
       
  1064         CSLOG_L(iConnectionID,KMinLogLevel ,"- Service description after parsing:");
       
  1065         CSLOG_ALL(iConnectionID,KMinLogLevel ,(*pAsXml));
       
  1066         CleanupStack::PopAndDestroy(); // pAsXml
       
  1067         }
       
  1068 #endif // _SENDEBUG
       
  1069 
       
  1070     apInitializer = pSD;
       
  1071     CleanupStack::Pop(); // pSD
       
  1072     return retVal;
       
  1073     }
       
  1074 
       
  1075 void CSenClientSession::InitializeL(const RMessage2& aMessage)
       
  1076     {
       
  1077     // To cache secure id of the client
       
  1078     // This secure id will be used to notify client in case RProperty updates
       
  1079     iClientSecureID = aMessage.SecureId();
       
  1080 	
       
  1081     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::InitializeL");
       
  1082     iSessionType = ERemoteConsumer_SC;
       
  1083 
       
  1084 	CSenChunk* pChunk = CSenChunk::NewLC(KNullDesC);
       
  1085 	TInt retVal = pChunk->OpenChunkFromRMsgL(aMessage, 2);
       
  1086 	
       
  1087 	TPckgBuf<TFourInts> fourInts;
       
  1088 	aMessage.ReadL( 3, fourInts );
       
  1089 	
       
  1090     TInt sdLength = fourInts().iInt1;
       
  1091     iConnectionHasAuthenticationCallback = fourInts().iInt2;
       
  1092 	TPtrC8 serviceDescriptionAsXml;
       
  1093     TPtrC8 consumerPolicyAsXml;
       
  1094 	if ( retVal == KErrNone )
       
  1095         {
       
  1096     	retVal = pChunk->DescFromChunk(serviceDescriptionAsXml, 0);
       
  1097     	
       
  1098     	if ( retVal == KErrNone )
       
  1099     	    {
       
  1100             TInt servDescFromChunkLength = serviceDescriptionAsXml.Length();
       
  1101             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- XML SD from chunk length: %d bytes"), servDescFromChunkLength));
       
  1102             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- XML SD from IPC args length: %d bytes"), sdLength));
       
  1103             if( sdLength != servDescFromChunkLength )
       
  1104                 {
       
  1105                 serviceDescriptionAsXml.Set( serviceDescriptionAsXml.Left( sdLength ) );
       
  1106                 // serviceDescriptionAsXml.SetLength( sdLength );
       
  1107                 }
       
  1108 
       
  1109     	    // Check if consumer policy was provided
       
  1110         	TInt getPolicyRetCode = pChunk->DescFromChunk(consumerPolicyAsXml, 1);
       
  1111                 	
       
  1112         	if( getPolicyRetCode != KErrNone )
       
  1113         	    {
       
  1114         	    CSLOG_L(iConnectionID,KMinLogLevel ,"- Consumer policy not used.");
       
  1115                 consumerPolicyAsXml.Set(KNullDesC8);
       
  1116         	    }
       
  1117             getPolicyRetCode = 0; // not used in release builds      	    
       
  1118 
       
  1119     	    }
       
  1120         }
       
  1121     if ( retVal == KErrNone )
       
  1122         {
       
  1123         // At least XML SD was read correctly from the chunk
       
  1124 
       
  1125         // Parse the XML string into a XML service description object
       
  1126         delete iInitializer;
       
  1127         iInitializer = NULL;
       
  1128         CSLOG_L(iConnectionID,KMaxLogLevel ,"- Service description as XML:");
       
  1129         CSLOG_ALL(iConnectionID,KMaxLogLevel ,( serviceDescriptionAsXml ));
       
  1130         CSLOG_L(iConnectionID,KMaxLogLevel ,"- Consumer policy as XML as XML:");
       
  1131         CSLOG_ALL(iConnectionID,KMaxLogLevel ,( consumerPolicyAsXml ));
       
  1132         
       
  1133         retVal = ParseSessionInitializerL(iInitializer, serviceDescriptionAsXml, &consumerPolicyAsXml);
       
  1134         // Attempt to initialize service session
       
  1135         if ( retVal == KErrNone )
       
  1136             {
       
  1137             // Sanity check
       
  1138             if( !iInitializer )
       
  1139                 {
       
  1140                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Fatal: initializer is NULL after succeeded parsing!");
       
  1141                 aMessage.Complete(ESenInternalError);
       
  1142                 return;
       
  1143                 }
       
  1144                 
       
  1145 
       
  1146             // Notify the framework plug-in about consumer being added
       
  1147             TPtrC8 frameworkID = iInitializer->FrameworkId();
       
  1148             if( frameworkID.Length() > 0 )
       
  1149                 {
       
  1150                 iFwNotified = ETrue;
       
  1151                 TRAP_IGNORE( iManager.NotifyFrameworksL(
       
  1152                         frameworkID,
       
  1153                         KSenEventConsumerAdded,
       
  1154                         this); )                 
       
  1155                 }
       
  1156 
       
  1157             // Initialize the service session
       
  1158             HBufC8* pErrorMsg = NULL;
       
  1159             retVal = InitializeServiceSessionL(*iInitializer, pErrorMsg);
       
  1160             CleanupStack::PushL( pErrorMsg );
       
  1161             if( pErrorMsg )
       
  1162                 {
       
  1163                 TPtrC8 error = pErrorMsg->Des();
       
  1164                 CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- InitializeL: retVal: (%d), error msg from InitializeServiceSessionL:"), retVal));
       
  1165                 CSLOG_ALL(iConnectionID,KMinLogLevel ,( error ));
       
  1166                 pChunk->DescsToChunk( error, KNullDesC8 );
       
  1167                 }
       
  1168             else
       
  1169                 {
       
  1170                 pChunk->DescsToChunk( KNullDesC8, KNullDesC8 );
       
  1171                 }
       
  1172             CleanupStack::PopAndDestroy( pErrorMsg );
       
  1173 
       
  1174             // Ensure that transport plug-in will be loaded:
       
  1175             if( retVal == KErrNone ) 
       
  1176                 {
       
  1177                 TRAP( retVal, TransportL(); ) 
       
  1178                 
       
  1179                 MSenTransport* pTransport = iServiceSession->Transport();
       
  1180                 if ( pTransport )
       
  1181                     {
       
  1182                     TInt ret = pTransport->SubscribeEventListenerL(*this);
       
  1183                     }
       
  1184                 }
       
  1185             }
       
  1186         }
       
  1187         
       
  1188     CleanupStack::PopAndDestroy( pChunk );
       
  1189 
       
  1190     // Write return value to pre-reserved client descriptor
       
  1191     TPtr8 returnValue(reinterpret_cast<TUint8*>(&retVal),
       
  1192                       sizeof(retVal), sizeof(retVal));
       
  1193 
       
  1194     TInt leaveCode(KErrNone);
       
  1195     TRAP(leaveCode, aMessage.WriteL(0, returnValue)); //IPC V2
       
  1196     if ( leaveCode != KErrNone )
       
  1197         {
       
  1198         aMessage.Complete(ESenInternalError);
       
  1199         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::InitializeL:");
       
  1200         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- RMessage2.WriteL(0, retVal) failed, leaveCode: %d. Completing with ESenInternalError"), leaveCode));
       
  1201         return;
       
  1202         }
       
  1203 
       
  1204     HBufC* pId16 = HBufC::NewLC(Id().Length());
       
  1205     TPtr16 id16 = pId16->Des();
       
  1206     id16.Copy(Id()); // Id does not containt UCS2 chars, so direct copying is ok!
       
  1207     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Writing id16: %S"), &id16));
       
  1208     TRAP(leaveCode, aMessage.WriteL(1, id16)); //IPC V2
       
  1209     CleanupStack::PopAndDestroy(); // pId16
       
  1210     if( leaveCode != KErrNone )
       
  1211         {
       
  1212         aMessage.Complete(ESenInternalError);
       
  1213         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::InitializeL:");
       
  1214         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- RMessage2.WriteL(1, sessionId) failed, leaveCode: %d. Completing with ESenInternalError"), leaveCode));
       
  1215         return;
       
  1216         }
       
  1217 
       
  1218     if (retVal == KErrSenFailedAuthentication && iAuthenticationRetries < KMaxAuthenticationRetries && iConnectionHasAuthenticationCallback)
       
  1219         {
       
  1220         // Authentication failed.
       
  1221         iAuthenticationRetries++;
       
  1222         
       
  1223         if ( iConnectionHasAuthenticationCallback )
       
  1224             {
       
  1225             // Ask authentication information from client
       
  1226             aMessage.Complete(ESenReAuthNeeded);
       
  1227         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("Completed with ESenReAuthNeeded iAuthenticationRetries = [%d]"), iAuthenticationRetries));		
       
  1228             }
       
  1229         else
       
  1230             {
       
  1231             retVal = KErrSenSoapFault;
       
  1232             }
       
  1233         }
       
  1234     else
       
  1235         {
       
  1236         // Complete. Either init was ok, or some error occurred; client now knows the result
       
  1237         iAuthenticationRetries = 0;
       
  1238         aMessage.Complete(ESenServInitialized);
       
  1239         CSLOG_L(iConnectionID,KMinLogLevel ,"Completed with ESenServInitialized");
       
  1240         }
       
  1241     }
       
  1242 
       
  1243 TInt CSenClientSession::InitializeServiceSessionL(CSenWSDescription& aInitializer, HBufC8*& aErrorMsg)
       
  1244     {
       
  1245     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::InitializeServiceSessionL");
       
  1246 
       
  1247     // Parsing was successful, perform the actual service connection lookup
       
  1248     iManager.SetShowPasswordDialog(ETrue);
       
  1249     TInt retVal = iManager.InitServiceConnectionL(*this, aInitializer, aErrorMsg);
       
  1250     iManager.SetShowPasswordDialog(EFalse);
       
  1251 
       
  1252     // Sanity check that connection is valid & ready
       
  1253     if(retVal == KErrNone && (!iServiceSession || iStatus != KSenConnectionStatusReady))
       
  1254         {
       
  1255         CSLOG_L(iConnectionID,KMinLogLevel ,"FATAL: InitServiceConnectionL() == KErrNone but ServiceSession is NOT ready!");
       
  1256         retVal = KErrSenInternal; 
       
  1257         }
       
  1258     return retVal;
       
  1259     }
       
  1260 
       
  1261 
       
  1262 
       
  1263 void CSenClientSession::TransactionL( const RMessage2& aMessage )
       
  1264     {
       
  1265     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::TransactionL");
       
  1266     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::TransactionL - RMessage2(%d)"), aMessage.Handle()));
       
  1267 
       
  1268     MSenTransport& transport = TransportL();
       
  1269 //    CSenClientMessage* pMessage = CSenClientMessage::NewLC( iManager.NextTransactionId(), aMessage, this, transport );
       
  1270     CSenClientMessage* pMessage = CSenClientMessage::NewLC( aMessage, this, transport );
       
  1271     pMessage->SetLogger( Log() );
       
  1272     MSenMessageContext& context = pMessage->MessageContext();
       
  1273     context.SetChunk(pMessage, EFalse);
       
  1274     
       
  1275     TInt retVal = pMessage->OpenChunkFromRMsgL( pMessage->RMessage(),2 );
       
  1276     if(retVal==KErrNone)
       
  1277         {
       
  1278 //        pMessage->ChunkHeader().SetContextId( pMessage->CtxId() );
       
  1279         
       
  1280         // Start waiting for HandleMessageL, HandleErrorL, cancel
       
  1281         // or destruction of this session...
       
  1282         retVal = Transactions().Append(pMessage);
       
  1283         if(retVal!=KErrNone)
       
  1284             {
       
  1285             CSLOG_L(iConnectionID,KMinLogLevel ,"- Transactions().Append failed (OOM)!");
       
  1286             }
       
  1287         }
       
  1288 #ifdef _SENDEBUG
       
  1289     else
       
  1290         {
       
  1291         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- pMessage->OpenChunkL(2) failed: %d"), retVal));
       
  1292         }
       
  1293 #endif
       
  1294 
       
  1295     if(retVal!=KErrNone)
       
  1296         {
       
  1297         CleanupStack::PopAndDestroy(); // pMessage
       
  1298         aMessage.Complete(ESenInternalError);
       
  1299         }
       
  1300     else
       
  1301         {
       
  1302         CleanupStack::Pop(); // pMessage
       
  1303         }
       
  1304     }
       
  1305     
       
  1306 TInt CSenClientSession::CompleteTransaction(TInt aErrorCode, CSenChunk& aChunk)
       
  1307     {
       
  1308     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CompleteTransaction");
       
  1309     TInt retVal(KErrNone);
       
  1310 	iReauthResendNeeded = EFalse ;
       
  1311 
       
  1312     TInt previousTxnId = aChunk.ChunkHeader().TransactionId();
       
  1313     aChunk.ChunkHeader().SetTransactionId(KErrNotFound);
       
  1314     TInt transactionIndex = TransactionIndex(KErrNotFound);
       
  1315     aChunk.ChunkHeader().SetTransactionId(previousTxnId);
       
  1316     
       
  1317     if ( transactionIndex != KErrNotFound )
       
  1318         {
       
  1319         retVal = CompleteTransactionByIndex(aErrorCode, transactionIndex);
       
  1320         }
       
  1321     else
       
  1322         {
       
  1323         retVal = KErrNotFound;
       
  1324         }
       
  1325     
       
  1326     return retVal;
       
  1327     }
       
  1328 
       
  1329 TInt CSenClientSession::CompleteTransactionByCtxId(TInt aErrorCode, TInt aCtxId)
       
  1330     {
       
  1331     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CompleteTransactionByCtxId");
       
  1332     TInt retVal(KErrNone);
       
  1333 
       
  1334     TInt transactionIndex = ContextIndex(aCtxId);
       
  1335     
       
  1336     if ( transactionIndex != KErrNotFound )
       
  1337         {
       
  1338         retVal = CompleteTransactionByIndex(aErrorCode, transactionIndex);
       
  1339         }
       
  1340     else
       
  1341         {
       
  1342         retVal = KErrNotFound;
       
  1343         }
       
  1344     
       
  1345     return retVal;
       
  1346     }
       
  1347 
       
  1348 TInt CSenClientSession::CompleteTransactionByIndex(TInt aErrorCode, TInt aTransactionIndex)
       
  1349     {
       
  1350     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CompleteTransactionByIndex");
       
  1351 
       
  1352     TInt retVal(KErrNone);
       
  1353     if ( aTransactionIndex == KErrNotFound ) 
       
  1354         {
       
  1355         return KErrNotFound;
       
  1356         }
       
  1357 
       
  1358     CSenClientMessage* pClientMessage = iPendingTransactions[aTransactionIndex];
       
  1359     RMessage2& message = pClientMessage->RMessage();
       
  1360     TPtr8 ptr(reinterpret_cast<TUint8*>(&aErrorCode), sizeof(aErrorCode), sizeof(aErrorCode));
       
  1361 
       
  1362     TInt leaveCode(KErrNone);
       
  1363     TRAP(leaveCode, message.WriteL(0, ptr)); //IPC V2
       
  1364     if ( leaveCode != KErrNone )
       
  1365         {
       
  1366         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Leave code: %d"), leaveCode));
       
  1367         message.Complete(ESenInternalError); 
       
  1368         CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - ErrorCode");
       
  1369         retVal = leaveCode;
       
  1370         }
       
  1371     else
       
  1372         {
       
  1373         TInt txnId = pClientMessage->ChunkHeader().TransactionId();
       
  1374         
       
  1375         TPtr8 ptr(reinterpret_cast<TUint8*>(&txnId), 
       
  1376                   sizeof(txnId), 
       
  1377                   sizeof(txnId)); 
       
  1378 
       
  1379         TInt leaveCode(KErrNone);
       
  1380         TRAP(leaveCode, message.WriteL(1, ptr)); //IPC V2
       
  1381         if ( leaveCode != KErrNone )
       
  1382             {
       
  1383             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Leave code: %d"), leaveCode));
       
  1384             message.Complete(ESenInternalError);
       
  1385             CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - TxnId");
       
  1386             retVal = leaveCode;
       
  1387             }
       
  1388         else
       
  1389             {
       
  1390             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- ErrCode: %d"), aErrorCode));
       
  1391             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- txnId  : %d"), txnId));
       
  1392             message.Complete(ESenServRequestResponsed);
       
  1393             CSLOG_L(iConnectionID,KMinLogLevel ,"Completed with ESenServRequestResponsed");
       
  1394             }
       
  1395         }
       
  1396 
       
  1397     iPendingTransactions.Remove( aTransactionIndex );
       
  1398     delete pClientMessage;
       
  1399 
       
  1400     return retVal;
       
  1401     }
       
  1402     
       
  1403 TInt CSenClientSession::TransactionIndex(TInt aTxnId)
       
  1404     {
       
  1405     TInt count = iPendingTransactions.Count();
       
  1406     TInt index(0);
       
  1407     for (; index < count; index++)
       
  1408         {
       
  1409         CSenClientMessage* pMsg = iPendingTransactions[index];
       
  1410         if (pMsg && pMsg->ChunkHeader().TransactionId() == aTxnId)
       
  1411             {
       
  1412             return index;    
       
  1413             }
       
  1414         }
       
  1415     return KErrNotFound;
       
  1416     }
       
  1417 
       
  1418 TInt CSenClientSession::ContextIndex(TInt aCtxId)
       
  1419     {
       
  1420     TInt count = iPendingTransactions.Count();
       
  1421     TInt index(0);
       
  1422     for (; index < count; index++)
       
  1423         {
       
  1424         CSenClientMessage* pContext = iPendingTransactions[index];
       
  1425         if (pContext && pContext->CtxId() == aCtxId)
       
  1426             {
       
  1427             return index;    
       
  1428             }
       
  1429         }
       
  1430     return KErrNotFound;
       
  1431     }
       
  1432 
       
  1433 
       
  1434 const TDesC8& CSenClientSession::Id() const
       
  1435     {
       
  1436     if(iConsumerID)
       
  1437         {
       
  1438         return *iConsumerID;
       
  1439         }
       
  1440     else
       
  1441         {
       
  1442         return KNullDesC8;
       
  1443         }
       
  1444     }
       
  1445 
       
  1446 CSenIdentifier& CSenClientSession::Identifier() const
       
  1447     {
       
  1448     return *ipIdentifier;
       
  1449     }
       
  1450 TInt CSenClientSession::ListBinaryElementsL(RArray<TXmlEngElement>& aElementArray,
       
  1451                                             TXmlEngElement& aElement)
       
  1452     {
       
  1453     CSLOG_L(iConnectionID, KMinLogLevel ,"CSenClientSession::ListBinaryElementsL");
       
  1454 	_LIT8(KInclude,         "Include");
       
  1455 	_LIT8(KXopIncludeUri,   "http://www.w3.org/2004/08/xop/include");
       
  1456 //	_LIT8(KHref,            "href");      // not in use atm
       
  1457 //	_LIT8(KHrefUriEmpty,    "");  // not in use atm
       
  1458 	
       
  1459 	TInt count(0);
       
  1460 	RXmlEngNodeList<TXmlEngElement> list;
       
  1461 	CleanupClosePushL(list);
       
  1462 	aElement.GetChildElements(list);
       
  1463 	TInt c = list.Count();
       
  1464 
       
  1465 #ifdef _SENDEBUG
       
  1466     TPtrC8 root = aElement.Name();
       
  1467     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Processing element: '%S', num of child elements: %d"), &root, c));
       
  1468     TPtrC8 content = aElement.Text();
       
  1469     CSLOG_L(iConnectionID, KMaxLogLevel , "----  Content START ----");
       
  1470     CSLOG_ALL(iConnectionID, KMaxLogLevel , (content));
       
  1471     CSLOG_L(iConnectionID, KMaxLogLevel , "----  Content END ----");
       
  1472 #endif // _SENDEBUG
       
  1473 
       
  1474 	
       
  1475 
       
  1476     while ( list.HasNext() )
       
  1477         {
       
  1478         TXmlEngElement element = list.Next();
       
  1479         
       
  1480         TPtrC8 tag = element.Name();
       
  1481         CSLOG_FORMAT((iConnectionID, KMaxLogLevel , _L8("- child: '%S'"), &tag));
       
  1482         if ( tag == KInclude )
       
  1483             {
       
  1484             CSLOG_L(iConnectionID, KMaxLogLevel , "- <xop:Include> element found.");
       
  1485             if ( element.NamespaceUri() == KXopIncludeUri )
       
  1486                 {
       
  1487                 CSLOG_L(iConnectionID, KMaxLogLevel , "- namespace == http://www.w3.org/2004/08/xop/include");
       
  1488                 aElementArray.AppendL(element);
       
  1489                 count = count + 1;
       
  1490                 }
       
  1491             }
       
  1492         count = count + ListBinaryElementsL(aElementArray, element);
       
  1493         }
       
  1494 
       
  1495     CleanupStack::PopAndDestroy(&list);
       
  1496     return count;
       
  1497     }
       
  1498 TInt CSenClientSession::ParseMessageL(TInt aTransactionId,
       
  1499                                       const TDesC8& aRequest,
       
  1500                                       CSenAtomEntry& aAtomEntry)
       
  1501     {
       
  1502 	CSLOG_L(iConnectionID, KMinLogLevel ,"CSenClientSession::ParseMessageL");
       
  1503     CSenParser* pParser = CSenParser::NewLC();
       
  1504     pParser->EnableFeature(EReportNamespaceMapping);
       
  1505 	pParser->ParseL(aRequest, aAtomEntry);
       
  1506 	
       
  1507 	// handle binary containers (BLOBs / attachments)
       
  1508     //TInt retVal = TransactionIndex(aTransactionId);
       
  1509     TInt retVal = ContextIndex(aTransactionId);
       
  1510     if ( retVal != KErrNotFound )
       
  1511         {
       
  1512         RTransactionArray& transactions = Transactions();   
       
  1513         CSenClientMessage* pClientMessage = transactions[retVal];
       
  1514     	
       
  1515 		RPointerArray<CSenBinaryData>& binaryDataArray = pClientMessage->BinaryDataArray();
       
  1516 
       
  1517         if ( binaryDataArray.Count() > 0 )
       
  1518             {
       
  1519         	TXmlEngElement messageRootElement = aAtomEntry.AsElementL();
       
  1520         	TInt count2 = binaryDataArray.Count();
       
  1521             RSenDocument document = aAtomEntry.AsDocumentL();
       
  1522         	
       
  1523         	TXmlEngElement element;
       
  1524         	CSenBinaryData* pBinaryData;
       
  1525 			for ( TInt j = 0; j < count2; j++ )
       
  1526 			    {
       
  1527 			    pBinaryData = binaryDataArray[j];
       
  1528             	if ( pBinaryData->Type() == CSenBinaryData::EChunk )
       
  1529         			{
       
  1530             	    TXmlEngChunkContainer binData =
       
  1531             	            document.CreateChunkContainerL(
       
  1532             	                        pBinaryData->Cid(),
       
  1533             	                        pBinaryData->Chunk(),
       
  1534             	                        pBinaryData->Offset(),
       
  1535             	                        pBinaryData->Size() );
       
  1536                     document.AsElement().AppendChildL(binData);
       
  1537         			}
       
  1538         		else if ( pBinaryData->Type() == CSenBinaryData::EFile )
       
  1539         			{
       
  1540             	    TXmlEngFileContainer binData = 
       
  1541             	            document.CreateFileContainerL(
       
  1542             	                        pBinaryData->Cid(),
       
  1543 	                                    pBinaryData->File() );
       
  1544         			
       
  1545                     document.AsElement().AppendChildL(binData);
       
  1546         			}
       
  1547 
       
  1548                 }
       
  1549             }
       
  1550         }
       
  1551 	
       
  1552     CleanupStack::PopAndDestroy(pParser);
       
  1553     return KErrNone;
       
  1554     }    
       
  1555 TInt CSenClientSession::ParseMessageL(TInt aTransactionId,
       
  1556                                       const TDesC8& aRequest,
       
  1557                                       CSenSoapEnvelope2& aSoapEnvelope)
       
  1558     {
       
  1559     CSLOG_L(iConnectionID, KMinLogLevel , "CSenClientSession::ParseMessageL");
       
  1560     CSenParser* pParser = CSenParser::NewLC();
       
  1561     pParser->EnableFeature(EReportNamespaceMapping);
       
  1562 	pParser->ParseL(aRequest, aSoapEnvelope);
       
  1563 
       
  1564 
       
  1565     // handle binary containers (BLOBs / attachments)
       
  1566     //TInt retVal = TransactionIndex(aTransactionId);
       
  1567     TInt retVal = ContextIndex(aTransactionId);
       
  1568     if ( retVal != KErrNotFound )
       
  1569         {
       
  1570         RTransactionArray& transactions = Transactions();   
       
  1571         CSenClientMessage* pClientMessage = transactions[retVal];
       
  1572     	
       
  1573 		RPointerArray<CSenBinaryData>& binaryDataArray = pClientMessage->BinaryDataArray();
       
  1574 
       
  1575         if ( binaryDataArray.Count() > 0 )
       
  1576             {
       
  1577     	
       
  1578         	_LIT8(KCidPrefix, "cid:*");
       
  1579         	TXmlEngElement messageRootElement = aSoapEnvelope.AsElementL();
       
  1580         	
       
  1581         	RArray<TXmlEngElement> elementArray;
       
  1582         	RXmlEngNodeList<TXmlEngAttr> attrArray;
       
  1583         	CleanupClosePushL(elementArray);
       
  1584             TInt binElementCount = ListBinaryElementsL(elementArray,messageRootElement);
       
  1585             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Count of <xop:Include elements> in DOM tree: %d"), binElementCount));
       
  1586             
       
  1587             TXmlEngAttr attr;
       
  1588             TPtrC8 cid;
       
  1589         	TInt count = elementArray.Count();
       
  1590         	TInt count2 = binaryDataArray.Count();
       
  1591             RSenDocument document = aSoapEnvelope.AsDocumentL();
       
  1592         	
       
  1593         	TXmlEngElement element;
       
  1594         	CSenBinaryData* pBinaryData;
       
  1595         	if ( count > 0 && count2 > 0 )
       
  1596         	    {
       
  1597         		for ( TInt i = 0; i < count; i++ )
       
  1598         		    {
       
  1599         			element = elementArray[i];
       
  1600         			element.GetAttributes(attrArray);
       
  1601         			while ( attrArray.HasNext() )
       
  1602         				{
       
  1603         				attr = attrArray.Next();
       
  1604         				TPtrC8 value = attr.Value();
       
  1605                     	TInt position = value.Match(KCidPrefix);
       
  1606                     	if ( position < 0 )
       
  1607                     		{
       
  1608                     		position = 0;
       
  1609                     		}
       
  1610                     	cid.Set(value.Mid( position + KCidPrefix().Size() - 1)); // minus star character (*)
       
  1611                     	if ( cid.Length() > 0 )
       
  1612                     	    {
       
  1613                     	    break;
       
  1614                     	    }
       
  1615         				}
       
  1616         		    attrArray.Close();
       
  1617         			
       
  1618         			for ( TInt j = 0; j < count2; j++ )
       
  1619         			    {
       
  1620         			    pBinaryData = binaryDataArray[j];
       
  1621         			    
       
  1622                         if ( pBinaryData->Cid() == cid )
       
  1623                             {
       
  1624                     		if ( pBinaryData->Type() == CSenBinaryData::EChunk )
       
  1625                     			{
       
  1626                         	    TXmlEngChunkContainer binData =
       
  1627                         	            document.CreateChunkContainerL(
       
  1628                         	                        pBinaryData->Cid(),
       
  1629                         	                        pBinaryData->Chunk(),
       
  1630                         	                        pBinaryData->Offset(),
       
  1631                         	                        pBinaryData->Size() );
       
  1632                                 element.ReplaceWith(binData);
       
  1633                     			}
       
  1634                     		else if ( pBinaryData->Type() == CSenBinaryData::EFile )
       
  1635                     			{
       
  1636                         	    TXmlEngFileContainer binData = 
       
  1637                         	            document.CreateFileContainerL(
       
  1638                         	                        pBinaryData->Cid(),
       
  1639             	                                    pBinaryData->File() );
       
  1640                     			
       
  1641                                 element.ReplaceWith(binData);
       
  1642                     			}
       
  1643 
       
  1644                             break;
       
  1645                             }
       
  1646         			    }
       
  1647         		    }
       
  1648         		}        
       
  1649             CleanupStack::PopAndDestroy(&elementArray);
       
  1650             }
       
  1651         }
       
  1652     CleanupStack::PopAndDestroy(pParser);
       
  1653     
       
  1654     return retVal;
       
  1655     }
       
  1656     
       
  1657 TInt CSenClientSession::SearchMsgChunk( const RMessage2& aMessage, CSenChunk*& aHit )
       
  1658     {
       
  1659     TInt ctxId = aMessage.Int1();
       
  1660     TInt ctxIndex = ContextIndex( ctxId );
       
  1661     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("SearchMsgChunk - using Context ID: %d"), ctxId));
       
  1662     if ( ctxIndex == KErrNotFound ) 
       
  1663         {
       
  1664         return ctxIndex;
       
  1665         }
       
  1666     aHit = iPendingTransactions[ctxIndex];
       
  1667     return KErrNone;
       
  1668     }
       
  1669     
       
  1670 void CSenClientSession::SendMsg( const RMessage2& aMessage )
       
  1671     {
       
  1672     CSLOG_L(iConnectionID, KMinLogLevel , "CSenClientSession::SendMsg");
       
  1673     CSenChunk* pSenChunk = NULL;
       
  1674     TInt err = SearchMsgChunk( aMessage, pSenChunk );
       
  1675     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- SearchMsgChunk returned: %d"), err));
       
  1676     
       
  1677     if ( err || !pSenChunk )
       
  1678         {
       
  1679         CSLOG_L(iConnectionID, KMinLogLevel , "CSenClientSession::SendMsg - FATAL(!): transaction not found by msg ctx ID!");
       
  1680         aMessage.Complete( KErrSenInternal );
       
  1681         }
       
  1682     else
       
  1683         {
       
  1684         TRAP( err, SendMsgL( aMessage, *pSenChunk );  )
       
  1685         
       
  1686         if ( err != KErrNone )
       
  1687             {
       
  1688             aMessage.Complete( err );
       
  1689             // Complete pending transaction, too
       
  1690             CompleteTransaction( err, *pSenChunk );
       
  1691             }
       
  1692         }
       
  1693     }
       
  1694 
       
  1695 void CSenClientSession::SendMsgL(const RMessage2& aMessage, CSenChunk& aSenChunk)
       
  1696     {
       
  1697    CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SendMsgL");
       
  1698     
       
  1699     TPtrC8 request;
       
  1700     TInt errorCode(KErrNone);
       
  1701     TPtrC8 transportProperties(KNullDesC8);
       
  1702 
       
  1703     HBufC8* pErrorMsg = NULL;
       
  1704 	TBool initReqd = EFalse ;
       
  1705 	TBool sessionValidityError = SessionValidity() ;	
       
  1706    if ( !aSenChunk.ChunkHeader().DoInitBeforeSending() )
       
  1707 	{
       
  1708 	if (KErrNone != sessionValidityError)
       
  1709 		{
       
  1710 		initReqd  = ETrue ;
       
  1711 		CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SendMsgL - init required ??? ");
       
  1712 		}
       
  1713    	}
       
  1714     if ( aSenChunk.ChunkHeader().DoInitBeforeSending() || initReqd)
       
  1715         {
       
  1716         iManager.SetShowPasswordDialog(ETrue);
       
  1717         errorCode = iManager.InitServiceConnectionL(*this, *iInitializer, pErrorMsg);
       
  1718         CleanupStack::PushL( pErrorMsg );
       
  1719         if ( errorCode )
       
  1720             {
       
  1721 			// Write error message to chunk only if there will be no more reauthentication loops
       
  1722             // otherwise resend after successful reauthentication will fail
       
  1723             if( errorCode != KErrSenFailedAuthentication || !(iAuthenticationRetries < KMaxAuthenticationRetries) )
       
  1724             	{
       
  1725 	            if( pErrorMsg )
       
  1726 	                {
       
  1727 	                TPtrC8 errorMsg = pErrorMsg->Des();
       
  1728                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- SendMsgL - re-auth error from InitializeL: retVal: (%d), error msg from InitializeServiceSessionL:"), errorCode));
       
  1729                     CSLOG_ALL(iConnectionID,KMinLogLevel ,( errorMsg ));
       
  1730 	                aSenChunk.DescToChunk( errorMsg ); // 2007-02-03: no longer silenced..
       
  1731 	                aSenChunk.ChunkHeader().SetPropertiesType(MSenProperties::ENotInUse);
       
  1732 	                }
       
  1733 	            else 
       
  1734 	                {
       
  1735 	                // Replace sent message (request) with error message
       
  1736 	                // (in this case there is no error message => return KNullDesC8)
       
  1737 	                // NOTE(!): do not zero-length the request if there was no error, 
       
  1738 	                // otherwise re-send will fail(!)
       
  1739 	                aSenChunk.DescToChunk( KNullDesC8 );
       
  1740 	                aSenChunk.ChunkHeader().SetPropertiesType(MSenProperties::ENotInUse);
       
  1741 	                }
       
  1742 				}
       
  1743             }
       
  1744         CleanupStack::PopAndDestroy( pErrorMsg );
       
  1745         pErrorMsg = NULL; // pointer is re-used
       
  1746         iManager.SetShowPasswordDialog(EFalse);                
       
  1747         
       
  1748         // Sanity check that connection is valid & ready
       
  1749         if ( errorCode == KErrNone && (!iServiceSession || iStatus != KSenConnectionStatusReady) )
       
  1750             {
       
  1751             CSLOG_L(iConnectionID,KMinLogLevel ,"FATAL: InitServiceConnectionL() == KErrNone but ServiceSession is NOT ready!");
       
  1752             errorCode = KErrSenInternal;
       
  1753             }
       
  1754         }
       
  1755         
       
  1756     if ( errorCode == KErrNone )
       
  1757         {
       
  1758 		if (!initReqd && !iReauthResendNeeded)
       
  1759 	    {
       
  1760 	    errorCode = sessionValidityError ;
       
  1761 	    }
       
  1762         if ( errorCode == KErrNone )
       
  1763             {
       
  1764             //if (aSenChunk.ChunkHeader().HasTransactionProperties() )
       
  1765                             
       
  1766             if ( aSenChunk.ChunkHeader().PropertiesType() != MSenProperties::ENotInUse )
       
  1767                 {
       
  1768                 errorCode = aSenChunk.DescsFromChunk(request, transportProperties);
       
  1769                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Has transport properties (%d bytes."), transportProperties.Length()));
       
  1770                 }
       
  1771             else
       
  1772                 {
       
  1773                 if (aSenChunk.RequestFileHandle().SubSessionHandle()) //request is null Now !!
       
  1774 	                {
       
  1775 	                errorCode = KErrNone ;	
       
  1776 	                }
       
  1777                 else
       
  1778 		            {
       
  1779                 	errorCode = aSenChunk.DescFromChunk(request);
       
  1780 					}
       
  1781                 }
       
  1782             }
       
  1783         }
       
  1784 
       
  1785     if ( errorCode != KErrNone )
       
  1786         {
       
  1787 	CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::SendMsgL() Fail with Error: = [%d], sessionValidityError = [%d]"), errorCode, sessionValidityError));
       
  1788         //when there is a soapfault and session is expired, it is auth-fault
       
  1789         if (KErrConnectionExpired == sessionValidityError && (KErrSenSoapFault == errorCode || KErrConnectionExpired == errorCode))
       
  1790 			{
       
  1791 			CSLOG_L(iConnectionID,KMaxLogLevel ,"-session is expired/soapfault, translating the error to  KErrSenAuthenticationFault");
       
  1792 			errorCode = KErrSenAuthenticationFault ;
       
  1793 			}
       
  1794 			
       
  1795     	aMessage.Complete(errorCode);
       
  1796     	CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Completed with errorCode: %d"), errorCode));
       
  1797         
       
  1798 	    if( (KErrSenAuthenticationFault == errorCode || KErrSenFailedAuthentication  == errorCode
       
  1799 	     || KErrConnectionExpired == errorCode) && iAuthenticationRetries < KMaxAuthenticationRetries)
       
  1800         	{
       
  1801         	iAuthenticationRetries++;
       
  1802 			CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::SendMsgL() iAuthenticationRetries = [%d]"), iAuthenticationRetries));
       
  1803         	CompleteReauthLoop(aSenChunk);
       
  1804         	return;
       
  1805         	}
       
  1806         else
       
  1807         	{
       
  1808         	iAuthenticationRetries = 0;
       
  1809 	        CompleteTransaction(errorCode, aSenChunk);
       
  1810 	        return;
       
  1811         	}
       
  1812         }
       
  1813 
       
  1814     iAuthenticationRetries = 0; // reauthentication loop ends
       
  1815 
       
  1816     delete pErrorMsg; // In all cases, pErrorMsg should always NULL in here..
       
  1817     pErrorMsg = NULL;
       
  1818 
       
  1819 
       
  1820 #ifdef _SENDEBUG
       
  1821     CSLOG_FORMAT((iConnectionID, KMaxLogLevel , _L8("=================== SendL(%d bytes):"), request.Length()));
       
  1822     CSLOG_ALL(iConnectionID, KMaxLogLevel ,(request));
       
  1823     if( transportProperties.Length()>0 )    
       
  1824         {
       
  1825         CSLOG_L(iConnectionID,KMaxLogLevel ,"- Message layer transport properties:");
       
  1826         CSLOG_ALL(iConnectionID, KMaxLogLevel ,(transportProperties));
       
  1827         }
       
  1828     else
       
  1829         {
       
  1830         CSLOG_L(iConnectionID,KMinLogLevel ,"- No message layer transport properties.");
       
  1831         }
       
  1832 //    FILELOGALL(_L("WsLog"), _L("service_body_req.xml"), request);
       
  1833 #endif
       
  1834 
       
  1835     if(iAllowShowDialogCount<1)
       
  1836         {
       
  1837         // flag will stay up as long as count > 0
       
  1838 
       
  1839         iManager.SetShowPasswordDialog(ETrue); 
       
  1840         }
       
  1841     iAllowShowDialogCount++;
       
  1842 	//Proxy URL CR
       
  1843 	CSenTransportProperties * pTransportProperties = CSenTransportProperties::NewL(transportProperties, *iManager.XMLReader());
       
  1844 	
       
  1845 	HBufC8* pTransportPropertiesProxyUrl = NULL ;	
       
  1846 	TPtrC8 aProxyUrl;
       
  1847 
       
  1848 	MSenTransport& transport = TransportL() ;
       
  1849 	MSenProperties& property = transport.PropertiesL() ;
       
  1850 	switch (property.PropertiesClassType())
       
  1851     	{
       
  1852 		case MSenProperties::ESenLayeredTransportProperties:
       
  1853 		case MSenProperties::ESenLayeredHttpTransportProperties:
       
  1854 		case MSenProperties::ESenLayeredVtcpTransportProperties:
       
  1855 			{
       
  1856 			CSenLayeredTransportProperties& layerdPropery = (CSenLayeredTransportProperties&)property ;
       
  1857 			TInt error = layerdPropery.PropertyL(KSenConnectionProxyUrl,aProxyUrl) ;
       
  1858 			if(!error) 
       
  1859     			{
       
  1860         		CSLOG_L(iConnectionID,KMinLogLevel ,"- Found New Proxy URL");
       
  1861             	CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- New proxy url('%S'."), &aProxyUrl));
       
  1862     			//pTransportProperties->SetProxyHostL(aProxyHost) ; 
       
  1863     			pTransportProperties->SetPropertyL(KSenConnectionProxyUrl,aProxyUrl);
       
  1864 		    	pTransportPropertiesProxyUrl = pTransportProperties->AsUtf8LC() ;    			
       
  1865     			}
       
  1866 			}    			
       
  1867     		break;
       
  1868     	}
       
  1869 		
       
  1870 		delete pTransportProperties;		    	
       
  1871 		pTransportProperties = NULL;			
       
  1872 		
       
  1873 	    if ( pTransportPropertiesProxyUrl )
       
  1874 	    	{
       
  1875         	CSLOG_L(iConnectionID,KMinLogLevel ,"- New Proxy URL has been set.");
       
  1876 	    	transportProperties.Set( pTransportPropertiesProxyUrl->Des() ) ;
       
  1877             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Transport properties with new proxy url(%d bytes."), transportProperties.Length()));
       
  1878  	    	
       
  1879 	    	}
       
  1880 
       
  1881 //    TInt transactionId( KErrNotFound );
       
  1882     
       
  1883     // Use the Core generated transaction ID when talking to transports
       
  1884     // Using this ID, the transports can find message context associated
       
  1885     // to this request / transaction.
       
  1886     TInt transactionId( aSenChunk.ChunkHeader().ContextId() );
       
  1887 #ifdef __ENABLE_ALR__	
       
  1888 	HBufC8* pNewTransportProperties = NULL ;
       
  1889 	if ( iSessionType != ERemoteHostlet_HC )
       
  1890 		{
       
  1891 		//Only real consumers will monitor Mobility service
       
  1892 		if ( !iALRObserver )
       
  1893 			{
       
  1894         	CSLOG_L(iConnectionID, KMinLogLevel , "SendMsgL - creating new ALR observer");
       
  1895 		  	iALRObserver = CALRObserver::NewL ( *this, *iManager.XMLReader() ) ;
       
  1896 		  	}	
       
  1897 		MSenTransport& transport = TransportL() ;
       
  1898 		//before opening connection we need to check the request is coming from Internal Consumers 
       
  1899 		//or real service consumer
       
  1900         CSLOG_L(iConnectionID, KMinLogLevel , "SendMsgL - calling OpenConnectionL");
       
  1901 	  	TInt error = iALRObserver->OpenConnectionL( transportProperties, transport, *iInitializer, pNewTransportProperties ) ;		
       
  1902 	    if ( pNewTransportProperties )
       
  1903 	    	{
       
  1904 	        CSLOG_L(iConnectionID, KMinLogLevel , "SendMsgL - OpenConnectionL new transport properties set");
       
  1905 	    	transportProperties.Set( pNewTransportProperties->Des() ) ;
       
  1906      	    CleanupStack::PushL( pNewTransportProperties );
       
  1907 	    	}
       
  1908 		if (error != KErrNone)
       
  1909 			{
       
  1910 			//ALR boot up failed , still iap can be collected in plugin 
       
  1911 	        CSLOG_FORMAT( (iConnectionID, KMinLogLevel , _L8("SendMsgL - OpenConnectionL returned, error: %d ALR boot up failed"), error) );
       
  1912 			}
       
  1913 		//else
       
  1914 		//	{	
       
  1915 		}
       
  1916 #endif	//__ENABLE_ALR__
       
  1917     TInt sendRetCode(KErrNone);
       
  1918     if ( aSenChunk.ChunkHeader().MessageType() == MSenMessage::ESoapMessage2 )
       
  1919         {
       
  1920         CSenSoapMessageDom2* pSoapMessage = CSenSoapMessageDom2::NewL(); 
       
  1921         CleanupStack::PushL(pSoapMessage);
       
  1922         ParseMessageL(transactionId, request, *pSoapMessage);
       
  1923         TInt ctxLookupErr(KErrNone);
       
  1924         MSenMessageContext* pCtx = MessageContextByTxnIdL( transactionId, ctxLookupErr );
       
  1925         if( ctxLookupErr == KErrNone && pCtx )
       
  1926             {
       
  1927             sendRetCode = pCtx->SetMessage( pSoapMessage, ETrue );
       
  1928             
       
  1929             if( sendRetCode == KErrNone )
       
  1930                 {
       
  1931                 // Ownerships successfully transferred to ctx:
       
  1932                 CleanupStack::Pop(pSoapMessage);
       
  1933 
       
  1934                 // Send like a "legacy SOAP message"
       
  1935                 sendRetCode = iServiceSession->SendSoapL( request,
       
  1936                                                           transportProperties,
       
  1937                                                           *this,
       
  1938                                                           transactionId,
       
  1939                                                           pErrorMsg );
       
  1940                 if ( pErrorMsg )
       
  1941                     {
       
  1942                     CleanupStack::PushL( pErrorMsg );
       
  1943                     }
       
  1944                 aSenChunk.ChunkHeader().SetContextId(transactionId); // temporary
       
  1945                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("SendMsgL - SetContextId: %d"), transactionId));
       
  1946                 }
       
  1947             else 
       
  1948                 {
       
  1949                 // "Add to ctx" -setter method failed, delete orphan msg:
       
  1950                 CleanupStack::PopAndDestroy(pSoapMessage);
       
  1951                 CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("SendMsgL - Add msg to ctx failed, error: %d"), sendRetCode));
       
  1952                 }
       
  1953             }
       
  1954         else 
       
  1955             {
       
  1956             // Message ctx not found, delete orphan msg:
       
  1957             CleanupStack::PopAndDestroy(pSoapMessage);
       
  1958 
       
  1959             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("SendMsgL - MsgCtx lookup failed, error: %d"), ctxLookupErr));
       
  1960             if( ctxLookupErr == KErrNone && pCtx == NULL)
       
  1961                 {
       
  1962                 // lookup retCode == OK, but pCtx == NULL
       
  1963                 ctxLookupErr = KErrSenInternal;
       
  1964                 }
       
  1965             sendRetCode = ctxLookupErr; // here one could generalize to: KErrSenInternal; 
       
  1966             }
       
  1967         }
       
  1968     else if ( aSenChunk.ChunkHeader().MessageType() == MSenMessage::EAtomMessage )
       
  1969         {
       
  1970         CSenAtomEntry* pAtomEntry = CSenAtomEntry::NewL(); 
       
  1971         CleanupStack::PushL(pAtomEntry);
       
  1972         ParseMessageL(transactionId, request, *pAtomEntry);
       
  1973         TInt ctxLookupErr(KErrNone);
       
  1974         MSenMessageContext* pCtx = MessageContextByTxnIdL( transactionId, ctxLookupErr );
       
  1975         if( ctxLookupErr == KErrNone && pCtx )
       
  1976             {
       
  1977             sendRetCode = pCtx->SetMessage( pAtomEntry, ETrue );
       
  1978             if( sendRetCode == KErrNone )
       
  1979                 {
       
  1980                 // Ownerships successfully transferred to ctx:
       
  1981                 CleanupStack::Pop(pAtomEntry);
       
  1982 
       
  1983                 // Send like a "legacy SOAP message"
       
  1984                 sendRetCode = iServiceSession->SendL( request,
       
  1985                                                           transportProperties,
       
  1986                                                           *this,
       
  1987                                                           transactionId,
       
  1988                                                           pErrorMsg );
       
  1989                 if ( pErrorMsg )
       
  1990                     {
       
  1991                     CleanupStack::PushL( pErrorMsg );
       
  1992                     }
       
  1993                 aSenChunk.ChunkHeader().SetContextId(transactionId); // temporary
       
  1994 				CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("SendMsgL - SetContextId: %d"), transactionId));
       
  1995                 }
       
  1996             else 
       
  1997                 {
       
  1998                 // "Add to ctx" -setter method failed, delete orphan msg:
       
  1999                 CleanupStack::PopAndDestroy(pAtomEntry);
       
  2000 				CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("SendMsgL - Add msg to ctx failed, error: %d"), sendRetCode));
       
  2001                 }
       
  2002             }
       
  2003         else 
       
  2004             {
       
  2005             // Message ctx not found, delete orphan msg:
       
  2006             CleanupStack::PopAndDestroy(pAtomEntry);
       
  2007 			CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("SendMsgL - MsgCtx lookup failed, error: %d"), ctxLookupErr));
       
  2008             if( ctxLookupErr == KErrNone && pCtx == NULL)
       
  2009                 {
       
  2010                 // lookup retCode == OK, but pCtx == NULL
       
  2011                 ctxLookupErr = KErrSenInternal;
       
  2012                 }
       
  2013             sendRetCode = ctxLookupErr; // here one could generalize to: KErrSenInternal; 
       
  2014             }
       
  2015         }
       
  2016     else if ( aSenChunk.ChunkHeader().MessageType() == MSenMessage::ESoapMessage )
       
  2017         {
       
  2018         sendRetCode = iServiceSession->SendSoapL( request,
       
  2019                                                   transportProperties,
       
  2020                                                   *this,
       
  2021                                                   transactionId,
       
  2022                                                   pErrorMsg );
       
  2023                                                   
       
  2024         if ( pErrorMsg )
       
  2025             {
       
  2026             CleanupStack::PushL( pErrorMsg );
       
  2027             }
       
  2028         aSenChunk.ChunkHeader().SetContextId(transactionId); // temporary
       
  2029         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("SendMsgL - SetContextId: %d"), transactionId));
       
  2030         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("SendMsgL - TxnId: %d, sendRetCode: %d"), transactionId, sendRetCode));
       
  2031         }
       
  2032     else
       
  2033         {
       
  2034         sendRetCode = iServiceSession->SendL( request, 
       
  2035                                               transportProperties, 
       
  2036                                               *this, 
       
  2037                                               transactionId,
       
  2038                                               pErrorMsg );
       
  2039                                               
       
  2040         if ( pErrorMsg )
       
  2041             {
       
  2042             CleanupStack::PushL( pErrorMsg );
       
  2043             }
       
  2044         aSenChunk.ChunkHeader().SetContextId(transactionId); // temporary
       
  2045         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("SendMsgL - SetContextId: %d"), transactionId));
       
  2046         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- TxnId from SendL: %d, sendRetCode: %d"), transactionId, sendRetCode));
       
  2047         }
       
  2048 
       
  2049     if ( sendRetCode == KErrNone )
       
  2050         {
       
  2051         if ( pErrorMsg )
       
  2052             {
       
  2053             CSLOG_L(iConnectionID,KMinLogLevel ,"- Minor (internal error): sendRetCode == KErrNone but pErrorMsg != NULL(!)");
       
  2054             CleanupStack::PopAndDestroy( pErrorMsg );
       
  2055             }
       
  2056         TInt* txnId = new (ELeave) TInt(transactionId);
       
  2057         CleanupStack::PushL(txnId);
       
  2058 
       
  2059         TInt appendRetCode = TxnIds().Append(txnId);
       
  2060         if(appendRetCode==KErrNone)
       
  2061             {
       
  2062             CleanupStack::Pop(txnId); // now owned by pointer array
       
  2063 
       
  2064             TInt previousTxnId = aSenChunk.ChunkHeader().TransactionId();
       
  2065             if (previousTxnId != 0)
       
  2066                 {
       
  2067                 TInt pendingTxnId = aSenChunk.ChunkHeader().PendingTransactionId();
       
  2068                 if (pendingTxnId == 0)
       
  2069                     {
       
  2070                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("*** PendingTransactionId: %d"), previousTxnId));
       
  2071                     aSenChunk.ChunkHeader().SetPendingTransactionId(previousTxnId);
       
  2072                     }
       
  2073                 }
       
  2074             aSenChunk.ChunkHeader().SetTransactionId( transactionId );
       
  2075             CSLOG_L(iConnectionID,KMinLogLevel ,"SendL() OK, attempt to complete with TxnID:");
       
  2076             
       
  2077             // OK! Complete with TxnID:
       
  2078             aMessage.Complete(transactionId); // OK!
       
  2079             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Completed with TxnId: %d"), transactionId));
       
  2080             // NOW TRANSACTION RMessage2 is pending and waiting for HandleMessageL
       
  2081             // or HandleErrorL callback, or Cancel() or destruction of this session!
       
  2082             }
       
  2083         else
       
  2084             {
       
  2085             CleanupStack::PopAndDestroy(txnId);
       
  2086             // OOM(?), Append failed
       
  2087             CSLOG_L(iConnectionID,KNormalLogLevel ," - TxnIds().Append(txnId)");
       
  2088             aMessage.Complete(appendRetCode);
       
  2089             // Complete on pending transaction, too
       
  2090             CompleteTransaction(appendRetCode, aSenChunk);
       
  2091             }
       
  2092         }
       
  2093     else // an error -- or signal about one-way message -- was received from transport
       
  2094         { 
       
  2095         if( pErrorMsg )
       
  2096             {
       
  2097             aSenChunk.DescToChunk( *pErrorMsg );
       
  2098             aSenChunk.ChunkHeader().SetPropertiesType(MSenProperties::ENotInUse);
       
  2099             CleanupStack::PopAndDestroy(pErrorMsg); // delete pErrorMsg;
       
  2100             }
       
  2101 
       
  2102         // SendL() failed, complete with error
       
  2103         CSLOG_L(iConnectionID,KMinLogLevel ,"SendL() failed, complete this plus TXN (second RMessage2) immediately:");
       
  2104         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Error code: %d"), sendRetCode));
       
  2105 
       
  2106         if ( sendRetCode == KErrSenTransactionComplete )
       
  2107             {
       
  2108             CSLOG_L(iConnectionID,KMinLogLevel ,"- Transport plug-in interprets sent request to be a ONE-WAY MESSAGE, completing with KErrNone & KNullDesC8");
       
  2109             aSenChunk.DescToChunk( KNullDesC8 );
       
  2110             aSenChunk.ChunkHeader().SetPropertiesType(MSenProperties::ENotInUse);
       
  2111             sendRetCode = KErrNone; // Consider: updating API documentation, 
       
  2112                                     // publishing KErrSenTransactionComplete,
       
  2113                                     //  returning it instead of KErrNone
       
  2114             }
       
  2115 
       
  2116         aMessage.Complete(sendRetCode);
       
  2117         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Completed with errorCode: %d"), sendRetCode));
       
  2118         // Complete one pending transaction, too
       
  2119         CompleteTransaction(sendRetCode, aSenChunk);
       
  2120         } 
       
  2121         //Proxy URL CR
       
  2122         if (pTransportPropertiesProxyUrl != NULL)
       
  2123             {
       
  2124     	        CleanupStack::PopAndDestroy(pTransportPropertiesProxyUrl);  
       
  2125             }
       
  2126             
       
  2127 #ifdef __ENABLE_ALR__	
       
  2128         if (pNewTransportProperties != NULL)
       
  2129             {
       
  2130     	        CleanupStack::PopAndDestroy(pNewTransportProperties);  
       
  2131             }
       
  2132 #endif	//__ENABLE_ALR__
       
  2133     }
       
  2134 
       
  2135 void CSenClientSession::InstallFrameworkL(const RMessage2& aMessage)
       
  2136     {
       
  2137     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::InstallFrameworkL")));
       
  2138     TInt retVal(KErrNone);
       
  2139     TInt length = aMessage.Int1();
       
  2140     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::InstallFrameworkL framework length %d"), length));
       
  2141     if (length < 1)
       
  2142         {
       
  2143         aMessage.Complete(KErrBadDescriptor);
       
  2144         return;
       
  2145         }
       
  2146 
       
  2147     HBufC8* inBuf = HBufC8::NewLC(length);
       
  2148     TPtr8 inBuffer = inBuf->Des();
       
  2149 
       
  2150     //get message data into buf (via ptr)
       
  2151     aMessage.ReadL(0, inBuffer);
       
  2152     TRAPD(err, iManager.InstallFrameworkL(inBuffer));
       
  2153     if (err != KErrNone)
       
  2154         {
       
  2155         retVal = KErrNotFound;
       
  2156         }
       
  2157     CleanupStack::PopAndDestroy(); // inBuf;
       
  2158     aMessage.Complete(retVal);
       
  2159     }
       
  2160 
       
  2161 void CSenClientSession::AssociateServiceL(const RMessage2& aMessage)
       
  2162     {
       
  2163     CSLOG(iConnectionID, KNormalLogLevel ,(_L("CSenClientSession::AssociateServiceL")));
       
  2164 
       
  2165     TInt servLength = aMessage.Int1();
       
  2166     TInt provLength = aMessage.Int3();
       
  2167 
       
  2168     if (servLength < 1 || provLength < 1)
       
  2169         {
       
  2170         aMessage.Complete(KErrBadDescriptor);
       
  2171         return;
       
  2172         }
       
  2173 
       
  2174     HBufC8* pServiceID = HBufC8::NewLC(servLength);
       
  2175     HBufC8* pProviderID = HBufC8::NewLC(provLength);
       
  2176     TPtr8 serviceID = pServiceID->Des();
       
  2177     TPtr8 providerID = pProviderID->Des();
       
  2178 
       
  2179     // Read IPC arguments from RMessage2:
       
  2180     aMessage.ReadL(0, serviceID);
       
  2181     aMessage.ReadL(2, providerID);
       
  2182 
       
  2183 
       
  2184     CSenIdentityProvider* pIdp = CSenIdentityProvider::NewLC(KNullDesC8);
       
  2185     pIdp->SetProviderID(providerID); // id for this IDP
       
  2186     pIdp->SetServiceID(serviceID);   // associated web service
       
  2187 
       
  2188     TInt error(KErrNone);
       
  2189     TBool idpAlreadyExists;
       
  2190     error = iManager.ContainsIdentityProviderL(idpAlreadyExists, *pIdp);
       
  2191     
       
  2192 
       
  2193     if (error == KErrNone && idpAlreadyExists)
       
  2194         {
       
  2195         CSLOG(iConnectionID, KMaxLogLevel ,(_L("     IDP data already existed")));
       
  2196         CleanupStack::PopAndDestroy(3); // pIdp, pProviderID, pServiceID 
       
  2197         aMessage.Complete(error);
       
  2198         return;
       
  2199         }
       
  2200 
       
  2201     if (!CheckAllowRegisterL(error, aMessage, pIdp->FrameworkId()))
       
  2202         {
       
  2203         CleanupStack::PopAndDestroy(3); // pIdp, pProviderID, pServiceID
       
  2204         aMessage.Complete(error);
       
  2205         return;
       
  2206         }
       
  2207     
       
  2208     TInt retVal(KErrNotFound);
       
  2209     if (iManager.AssociateServiceL(serviceID, providerID))
       
  2210         {
       
  2211         retVal = KErrNone;
       
  2212         }
       
  2213     CleanupStack::PopAndDestroy(3); // pIdp, pProviderID, pServiceID
       
  2214     aMessage.Complete(retVal);
       
  2215     }
       
  2216 
       
  2217 void CSenClientSession::DissociateServiceL(const RMessage2& aMessage)
       
  2218     {
       
  2219     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::DissociateServiceL")));
       
  2220     TInt servLength = aMessage.Int1();
       
  2221     TInt provLength = aMessage.Int3();
       
  2222 
       
  2223     if (servLength < 1 || provLength < 1)
       
  2224         {
       
  2225         aMessage.Complete(KErrBadDescriptor);
       
  2226         return;
       
  2227         }
       
  2228 
       
  2229     TInt error(KErrNone);
       
  2230     if (!CheckAllowUnRegisterL(error, aMessage))
       
  2231         {
       
  2232         aMessage.Complete(error);
       
  2233         return;
       
  2234         }
       
  2235 
       
  2236     HBufC8* serviceID = HBufC8::NewLC(servLength);
       
  2237     HBufC8* providerID = HBufC8::NewLC(provLength);
       
  2238     TPtr8 ptrServiceID = serviceID->Des();
       
  2239     TPtr8 ptrProviderID = providerID->Des();
       
  2240 
       
  2241     //get message data into buffers (via ptr)
       
  2242     aMessage.ReadL(0, ptrServiceID);
       
  2243     aMessage.ReadL(2, ptrProviderID);
       
  2244 
       
  2245     TInt retVal(KErrNotFound);
       
  2246     if (iManager.DissociateServiceL(ptrServiceID, ptrProviderID))
       
  2247         {
       
  2248         retVal = KErrNone;
       
  2249         }
       
  2250     CleanupStack::PopAndDestroy(2); // providerID, serviceID
       
  2251     aMessage.Complete(retVal);
       
  2252     }
       
  2253 
       
  2254 TBool CSenClientSession::CheckAllowRegisterL(TInt& aError, const RMessage2& aMessage, const TDesC8& aFrameworkId)
       
  2255     {
       
  2256     if(aFrameworkId == KDefaultOviFrameworkID)
       
  2257     	{
       
  2258     	if (!IsTrustedClient(aMessage))
       
  2259     	    {
       
  2260     	    aError = KErrPermissionDenied;
       
  2261     	    return EFalse;
       
  2262     	    }
       
  2263     	}
       
  2264 #if defined ( RD_SEN_DISABLE_USER_PERMISSION_DIALOGS )
       
  2265     iAllowWSDataReg = EAccepted;
       
  2266 #endif
       
  2267         
       
  2268     if (iAllowWSDataReg == ENotChecked)
       
  2269         {
       
  2270         aError = KErrNone;
       
  2271         RNotifier notifier;
       
  2272         User::LeaveIfError(notifier.Connect());
       
  2273         CleanupClosePushL(notifier);
       
  2274 
       
  2275         TRequestStatus reqStatus;
       
  2276         TPckgBuf<TAllowRegisterDlgRequest>* request = NULL;
       
  2277         TPckgBuf<TAllowRegisterDlgResponse>* response = NULL;
       
  2278 
       
  2279         request = new(ELeave)TPckgBuf<TAllowRegisterDlgRequest>();
       
  2280         CleanupStack::PushL(request);
       
  2281         response = new(ELeave)TPckgBuf<TAllowRegisterDlgResponse>();
       
  2282         CleanupStack::PushL(response);
       
  2283 
       
  2284         notifier.StartNotifierAndGetResponse(reqStatus, 
       
  2285             KSenNotifierPluginUID, *request, *response);
       
  2286 
       
  2287         User::WaitForRequest(reqStatus);
       
  2288 
       
  2289         
       
  2290         aError = reqStatus.Int();
       
  2291 
       
  2292         if(reqStatus.Int() == KErrNone)
       
  2293             {
       
  2294             if((*response)().OkButtonPressed())
       
  2295                 {
       
  2296                 iAllowWSDataReg = EAccepted;
       
  2297                 }
       
  2298             else
       
  2299                 {
       
  2300                 iAllowWSDataReg = ENotAccepted; 
       
  2301                 // Overwrite KErrNone to indicate
       
  2302                 // that end-user denies permission
       
  2303 
       
  2304                 aError = KErrSenNoEndUserPermission;
       
  2305                 }
       
  2306             }
       
  2307         else if(reqStatus.Int() == KErrNotFound)
       
  2308             {
       
  2309             CSLOG(iConnectionID, KMinLogLevel ,(_L("Plugin notifier impl. was not found.")));
       
  2310 
       
  2311 
       
  2312 #ifdef _SENDEBUG
       
  2313             // To allow console tests (debugging) to complete,
       
  2314             // always DO grant permission if plug-in is not found.
       
  2315             // THIS MUST BE USED ONLY IN DEBUG BUILDS, NEVER
       
  2316             // for RELEASE (UREL) BUILDS == H/W!
       
  2317             CleanupStack::PopAndDestroy(2); // request, response;
       
  2318             CleanupStack::PopAndDestroy(); // close the notifier
       
  2319             CSLOG(iConnectionID, KMinLogLevel ,(_L("** NOTE ** permission to manipulate WS data given!.")));
       
  2320 
       
  2321             aError = KErrNone; // for test driver compatibility
       
  2322             return ETrue; // we can now allow WS data manipulation
       
  2323                           // in debugging builds.
       
  2324 
       
  2325 #else
       
  2326     #ifndef EKA2 // EKA1 / S60 2nd edition devices -> temporary solution, since notifier plugin does not install!
       
  2327             CleanupStack::PopAndDestroy(2); // request, response;
       
  2328             CleanupStack::PopAndDestroy(); // close the notifier
       
  2329             CSLOG(iConnectionID, KMinLogLevel ,(_L("** NOTE ** permission to manipulate WS data given!.")));
       
  2330 
       
  2331             aError = KErrNone; 
       
  2332             return ETrue; 
       
  2333     #endif
       
  2334 #endif
       
  2335             }
       
  2336         else
       
  2337             {
       
  2338             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("NotifierPluginImpl error: (%d)"), reqStatus.Int()));
       
  2339             }
       
  2340 
       
  2341         CleanupStack::PopAndDestroy(2); // request, response;
       
  2342         CleanupStack::PopAndDestroy(); // close the notifier
       
  2343         }
       
  2344 
       
  2345     if (iAllowWSDataReg == EAccepted) 
       
  2346         {
       
  2347         return ETrue;
       
  2348         }
       
  2349     else 
       
  2350         {
       
  2351         return EFalse;
       
  2352         }
       
  2353     }
       
  2354 
       
  2355 TBool CSenClientSession::CheckAllowUnRegisterL(TInt& aError, const RMessage2& aMessage)
       
  2356 	{
       
  2357 	return CheckAllowUnRegisterL(aError, aMessage, KNullDesC8);
       
  2358 	}
       
  2359 TBool CSenClientSession::CheckAllowUnRegisterL(TInt& aError, const RMessage2& aMessage, const TDesC8& aFrameworkId)
       
  2360     {
       
  2361     if(aFrameworkId == KDefaultOviFrameworkID)
       
  2362     	{
       
  2363     	if (!IsTrustedClient(aMessage))
       
  2364     	    {
       
  2365     	    aError = KErrPermissionDenied;
       
  2366     	    return EFalse;
       
  2367     	    }
       
  2368     	}
       
  2369 #if defined ( RD_SEN_DISABLE_USER_PERMISSION_DIALOGS )
       
  2370     iAllowWSDataUnReg = EAccepted;
       
  2371 #endif
       
  2372 
       
  2373     if (iAllowWSDataUnReg == ENotChecked)
       
  2374         {
       
  2375         aError = KErrNone;
       
  2376         RNotifier notifier;
       
  2377         User::LeaveIfError(notifier.Connect());
       
  2378         CleanupClosePushL(notifier);
       
  2379 
       
  2380         TRequestStatus reqStatus;
       
  2381         TPckgBuf<TAllowUnRegisterDlgRequest>* request = NULL;
       
  2382         TPckgBuf<TAllowUnRegisterDlgResponse>* response = NULL; 
       
  2383 
       
  2384         request = new(ELeave)TPckgBuf<TAllowUnRegisterDlgRequest>();
       
  2385         CleanupStack::PushL(request);
       
  2386         response = new(ELeave)TPckgBuf<TAllowUnRegisterDlgResponse>();
       
  2387         CleanupStack::PushL(response);
       
  2388 
       
  2389         notifier.StartNotifierAndGetResponse(reqStatus, 
       
  2390             KSenNotifierPluginUID, *request, *response);
       
  2391 
       
  2392         User::WaitForRequest(reqStatus);
       
  2393 
       
  2394         aError = reqStatus.Int();
       
  2395 
       
  2396         
       
  2397         if(reqStatus.Int() == KErrNone)
       
  2398             {
       
  2399             if((*response)().OkButtonPressed())
       
  2400                 {
       
  2401                 iAllowWSDataUnReg = EAccepted;
       
  2402                 }
       
  2403             else
       
  2404                 {
       
  2405                 iAllowWSDataUnReg = ENotAccepted;
       
  2406                 // Overwrite KErrNone to indicate
       
  2407                 // that end-user denies permission
       
  2408 
       
  2409                 aError = KErrSenNoEndUserPermission;
       
  2410                 }
       
  2411             }
       
  2412         else if(reqStatus.Int() == KErrNotFound)
       
  2413             {
       
  2414             CSLOG(iConnectionID, KMinLogLevel ,(_L("Plugin notifier impl. was not found")));
       
  2415 
       
  2416 #ifdef _SENDEBUG
       
  2417             // To allow console tests (debugging) to complete,
       
  2418             // always DO grant permission if plugin is not found.
       
  2419             // THIS MUST BE USED ONLY IN DEBUG BUILDS, NEVER
       
  2420             // for RELEASE (UREL) BUILDS!
       
  2421             CleanupStack::PopAndDestroy(2); // request, response;
       
  2422             CleanupStack::PopAndDestroy(); // close the notifier
       
  2423             CSLOG(iConnectionID, KMinLogLevel ,(_L("** NOTE ** permission to manipulate WS data given!.")));
       
  2424 
       
  2425             aError = KErrNone; // for test driver compatibility
       
  2426             return ETrue; // we can now allow WS data manipulation
       
  2427                           // in debugging builds.
       
  2428             
       
  2429 #endif
       
  2430             }
       
  2431         else
       
  2432             {
       
  2433             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("Plugin notifier impl., Error: %d"), reqStatus.Int()));
       
  2434             }
       
  2435 
       
  2436         CleanupStack::PopAndDestroy(2); // request, response;
       
  2437         CleanupStack::PopAndDestroy(); // close the notifier
       
  2438         }
       
  2439 
       
  2440     if (iAllowWSDataUnReg == EAccepted) 
       
  2441         {
       
  2442         return ETrue;
       
  2443         }
       
  2444     else 
       
  2445         {
       
  2446         return EFalse;
       
  2447         }
       
  2448     }
       
  2449 
       
  2450 void CSenClientSession::RegisterIdentityProviderL(const RMessage2& aMessage)
       
  2451     {
       
  2452     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::RegisterIdentityProviderL")));
       
  2453 
       
  2454     TInt length = aMessage.Int1();
       
  2455     if (length < 1)
       
  2456         {
       
  2457         aMessage.Complete(KErrBadDescriptor);
       
  2458         return;
       
  2459         }
       
  2460 
       
  2461     HBufC8* inBuf = HBufC8::NewLC(length);
       
  2462     TPtr8 inBuffer = inBuf->Des();
       
  2463     aMessage.ReadL(0, inBuffer);
       
  2464 
       
  2465 #ifdef _SENDEBUG
       
  2466     if( inBuf )
       
  2467         {
       
  2468         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2469         CSLOG_L(iConnectionID,KMaxLogLevel ,"- IdentityProvider description (as XML):");
       
  2470         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(inBuffer));
       
  2471         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2472         }
       
  2473 #endif    
       
  2474 
       
  2475 
       
  2476     CSenIdentityProvider* pdp = CSenIdentityProvider::NewLC(KNullDesC8);
       
  2477 
       
  2478     // parse into XML object.
       
  2479     pdp->SetReader(*iManager.XMLReader());
       
  2480     pdp->ParseL(inBuffer);
       
  2481 
       
  2482     TInt error(KErrNone);
       
  2483     TBool idpAlreadyExists;
       
  2484     error = iManager.ContainsIdentityProviderL(idpAlreadyExists, *pdp);
       
  2485 
       
  2486     if (error == KErrNone && idpAlreadyExists)
       
  2487         {
       
  2488         CSLOG_L(iConnectionID,KMaxLogLevel ,"     IDP data already existed");
       
  2489         CleanupStack::PopAndDestroy(2); // pdp, inBuf
       
  2490         aMessage.Complete(error);
       
  2491         return;
       
  2492         }
       
  2493 
       
  2494     if (!CheckAllowRegisterL(error, aMessage, pdp->FrameworkId()))
       
  2495         {
       
  2496         CleanupStack::PopAndDestroy(2); // pdp, inBuf (fix from wk44)
       
  2497         aMessage.Complete(error);
       
  2498         return;
       
  2499         }
       
  2500 
       
  2501     // PLEASE NOTE(!): ownerships is always transferred to manager!
       
  2502     TInt retVal = iManager.RegisterIdentityProviderL(pdp);
       
  2503     CleanupStack::Pop(); //pdp -> ownership is now elsewhere...
       
  2504     CleanupStack::PopAndDestroy(); // inBuf
       
  2505     aMessage.Complete(retVal);
       
  2506     }
       
  2507 
       
  2508 void CSenClientSession::UnregisterIdentityProviderL(const RMessage2& aMessage)
       
  2509     {
       
  2510     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::UnregisterIdentityProviderL");
       
  2511     TInt length = aMessage.Int1();
       
  2512     if (length < 1)
       
  2513         {
       
  2514         aMessage.Complete(KErrBadDescriptor);
       
  2515         return;
       
  2516         }
       
  2517 
       
  2518     TInt error(KErrNone);
       
  2519     if (!CheckAllowUnRegisterL(error, aMessage))
       
  2520         {
       
  2521         aMessage.Complete(error);
       
  2522         return;
       
  2523         }
       
  2524 
       
  2525     HBufC8* inBuf = HBufC8::NewLC(length);
       
  2526     TPtr8 inBuffer = inBuf->Des();
       
  2527     aMessage.ReadL(0, inBuffer);
       
  2528 
       
  2529 #ifdef _SENDEBUG
       
  2530     if( inBuf )
       
  2531         {
       
  2532         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2533         CSLOG_L(iConnectionID,KMaxLogLevel ,"- IdentityProvider description (as XML):");
       
  2534         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(inBuffer));
       
  2535         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2536         }
       
  2537 #endif    
       
  2538     
       
  2539     CSenIdentityProvider* pdp = CSenIdentityProvider::NewLC(KNullDesC8);
       
  2540 
       
  2541     pdp->SetReader(*iManager.XMLReader());
       
  2542     pdp->ParseL(inBuffer);
       
  2543     if (!CheckAllowUnRegisterL(error, aMessage, pdp->FrameworkId()))
       
  2544         {
       
  2545         CleanupStack::PopAndDestroy(); // pdp
       
  2546         aMessage.Complete(error);
       
  2547         return;
       
  2548         }
       
  2549     TInt retVal(KErrNotFound);
       
  2550     retVal = iManager.UnregisterIdentityProviderL(*pdp);
       
  2551 
       
  2552 
       
  2553 // Note: after "protected credentials" -change => no need to remove credential(s) anymore, since they are protected by account details (userinfo from IDP)
       
  2554 //   if ( retVal == KErrNone )
       
  2555 //        {
       
  2556 //        iManager.RemoveCredentialsL(idp->ProviderID());
       
  2557 //        }
       
  2558 
       
  2559     CleanupStack::PopAndDestroy(); // pdp // in the future ownership will be
       
  2560                                           // transferred -> Pop is enough
       
  2561 
       
  2562     CleanupStack::PopAndDestroy(); // inBuf
       
  2563     aMessage.Complete(retVal);
       
  2564     }
       
  2565 
       
  2566 void CSenClientSession::RegisterServiceDescriptionL(const RMessage2& aMessage)
       
  2567     {
       
  2568     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::RegisterServiceDescriptionL");
       
  2569 
       
  2570     TInt length = aMessage.Int1();
       
  2571     if(length < 1)
       
  2572         {
       
  2573         CSLOG_L(iConnectionID,KMinLogLevel ,"Tried to register ZERO length SD.");
       
  2574         aMessage.Complete(KErrBadDescriptor);
       
  2575         return;
       
  2576         }
       
  2577 
       
  2578     HBufC8* inBuf = HBufC8::NewLC(length);
       
  2579     TPtr8 inBuffer = inBuf->Des();
       
  2580     aMessage.ReadL(0, inBuffer);
       
  2581 
       
  2582 #ifdef _SENDEBUG
       
  2583     if( inBuf )
       
  2584         {
       
  2585         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2586         CSLOG_L(iConnectionID,KMaxLogLevel ,"- XML SD description (as XML) before parsing:");
       
  2587         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*inBuf));
       
  2588         
       
  2589         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2590         }
       
  2591 #endif 
       
  2592 
       
  2593     CSenWSDescription* pSd = CSenWSDescription::NewLC();
       
  2594     pSd->SetReader(*iManager.XMLReader());
       
  2595     pSd->ParseL(inBuffer);
       
  2596 
       
  2597 #ifdef _SENDEBUG
       
  2598     HBufC8* pAsXml = NULL;
       
  2599     pAsXml = pSd->AsXmlL();
       
  2600     if(pAsXml)
       
  2601         {
       
  2602         CleanupStack::PushL(pAsXml);
       
  2603         CSLOG_L(iConnectionID,KMaxLogLevel ,"  SD after parsing:");
       
  2604         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*pAsXml));
       
  2605         CleanupStack::PopAndDestroy(); // pAsXml
       
  2606         }
       
  2607     else
       
  2608         {
       
  2609         CSLOG_L(iConnectionID,KMaxLogLevel ,"- SD as XML was NULL after parsing(!)");
       
  2610         }
       
  2611 #endif // _SENDEBUG
       
  2612 
       
  2613     TInt error(KErrNone);
       
  2614     TBool dataAlreadyExists;
       
  2615     error = iManager.ContainsServiceDescriptionL(dataAlreadyExists, *pSd);
       
  2616 
       
  2617     if (error == KErrNone && dataAlreadyExists)
       
  2618         {
       
  2619         CleanupStack::PopAndDestroy(2); // pSd, inBuf
       
  2620         aMessage.Complete(error);
       
  2621         CSLOG_L(iConnectionID,KMaxLogLevel ,"  SD was already found, no need to register.");
       
  2622         return;
       
  2623         }
       
  2624 
       
  2625     if (!CheckAllowRegisterL(error, aMessage, pSd->FrameworkId()))
       
  2626         {
       
  2627         CleanupStack::PopAndDestroy(2); // pSd, inBuf
       
  2628         aMessage.Complete(error);
       
  2629         return;
       
  2630         }
       
  2631 
       
  2632     // NOTE(!): RegisterServiceDescriptionL() always takes the ownership!
       
  2633     TInt retVal(iManager.RegisterServiceDescriptionL(pSd));
       
  2634     CleanupStack::Pop(); // pSd, ownership was transferred
       
  2635     CleanupStack::PopAndDestroy(); // inBuf
       
  2636     aMessage.Complete(retVal);
       
  2637     }
       
  2638 
       
  2639 void CSenClientSession::UnregisterServiceDescriptionL(const RMessage2& aMessage)
       
  2640     {
       
  2641     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::UnregisterServiceDescriptionL")));
       
  2642     TInt length = aMessage.Int1();
       
  2643     if(length < 1)
       
  2644         {
       
  2645         CSLOG(iConnectionID, KMaxLogLevel ,(_L("Tried to unregister ZERO length SD.")));
       
  2646         aMessage.Complete(KErrBadDescriptor);
       
  2647         return;
       
  2648         }
       
  2649 
       
  2650     TInt error(KErrNone);
       
  2651     if (!CheckAllowUnRegisterL(error, aMessage))
       
  2652         {
       
  2653         aMessage.Complete(error);
       
  2654         return;
       
  2655         }
       
  2656 
       
  2657     HBufC8* inBuf = HBufC8::NewLC(length);
       
  2658     TPtr8 inBuffer = inBuf->Des();
       
  2659     aMessage.ReadL(0, inBuffer);
       
  2660 
       
  2661 #ifdef _SENDEBUG
       
  2662     if( inBuf )
       
  2663         {
       
  2664         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2665         CSLOG_L(iConnectionID,KMaxLogLevel ,"- XML SD description (as XML) before parsing:");
       
  2666         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(inBuffer));
       
  2667         CSLOG_L(iConnectionID,KMaxLogLevel ,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
       
  2668         }
       
  2669 #endif 
       
  2670 
       
  2671     CSenWSDescription* sd = CSenWSDescription::NewLC();
       
  2672     sd->SetReader(*iManager.XMLReader());
       
  2673     sd->ParseL(inBuffer);
       
  2674     if (!CheckAllowUnRegisterL(error, aMessage, sd->FrameworkId()))
       
  2675         {
       
  2676         CleanupStack::PopAndDestroy(2); // sd, inBuf
       
  2677         aMessage.Complete(error);
       
  2678         return;
       
  2679         }
       
  2680 #ifdef _SENDEBUG
       
  2681         HBufC8* pAsXml = NULL;
       
  2682         pAsXml = sd->AsXmlL();
       
  2683         if(pAsXml)
       
  2684             {
       
  2685             CleanupStack::PushL(pAsXml);
       
  2686             CSLOG_L(iConnectionID,KMaxLogLevel ,"  SD after parsing:");
       
  2687             CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*pAsXml));
       
  2688             CleanupStack::PopAndDestroy(); // 1
       
  2689             }
       
  2690         else
       
  2691             {
       
  2692             CSLOG_L(iConnectionID,KMaxLogLevel ,"  SD as XML was NULL after parsing(!)");
       
  2693             }
       
  2694 #endif // _SENDEBUG
       
  2695 
       
  2696 
       
  2697     TInt retVal(iManager.UnregisterServiceDescriptionL(*sd));
       
  2698     CleanupStack::PopAndDestroy(2); // sd, inBuf
       
  2699     aMessage.Complete(retVal);
       
  2700     }
       
  2701 
       
  2702 void CSenClientSession::ServiceDescriptionsByPatternL(const RMessage2& aMessage)
       
  2703     {
       
  2704     TInt retVal(KErrNone);
       
  2705     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::ServiceDescriptionsByPatternL")));
       
  2706     
       
  2707     CSenChunk* pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  2708     pSenChunk->SetLogger(Log());
       
  2709     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  2710 
       
  2711     if(retVal != KErrNone)
       
  2712         {
       
  2713         CleanupStack::PopAndDestroy(pSenChunk);
       
  2714         aMessage.Complete(KErrBadDescriptor);
       
  2715         return;
       
  2716         }
       
  2717     
       
  2718     TPtrC8 pattern;
       
  2719     retVal = pSenChunk->DescFromChunk(pattern);
       
  2720     if(retVal != KErrNone)
       
  2721         {
       
  2722         CleanupStack::PopAndDestroy(pSenChunk);
       
  2723         aMessage.Complete(KErrBadDescriptor);
       
  2724         return;
       
  2725         }
       
  2726 
       
  2727     RWSDescriptionArray arr; // the elements will NOT be owned..
       
  2728 
       
  2729     CSenWSDescription* pSD = CSenWSDescription::NewLC();
       
  2730     pSD->SetReader(*iManager.XMLReader());
       
  2731     pSD->ParseL(pattern);
       
  2732 
       
  2733     retVal = iManager.ServiceDescriptionsL(arr, *pSD);
       
  2734     CleanupStack::PopAndDestroy(pSD); // pSD
       
  2735     CleanupClosePushL(arr);
       
  2736 
       
  2737     if (retVal != KErrNone)
       
  2738         {
       
  2739         CleanupStack::PopAndDestroy(); // arr.Close() is enough
       
  2740         CleanupStack::PopAndDestroy(pSenChunk);
       
  2741         aMessage.Complete(retVal);  
       
  2742         }
       
  2743 
       
  2744     TInt count = arr.Count();
       
  2745     
       
  2746     // Calculate required heap allocation size:
       
  2747     TInt size(0);
       
  2748     if(count>0)
       
  2749         {
       
  2750         size += (count-1) * KTab().Length();
       
  2751         }
       
  2752 
       
  2753     TInt leaveCode(KErrNone);
       
  2754     TRAP(leaveCode, size += iManager.SizeOfServiceDescriptionsL(arr); )
       
  2755     if(leaveCode!=KErrNone)
       
  2756         {
       
  2757         // the elements of array are not owned
       
  2758         CleanupStack::PopAndDestroy(); // arr.Close() is enough
       
  2759         CleanupStack::PopAndDestroy(pSenChunk);
       
  2760         aMessage.Complete(leaveCode); 
       
  2761         }
       
  2762         
       
  2763     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ServiceDescriptionsByPatternL");
       
  2764 
       
  2765     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Size of SD(s) + delimiter(s): %d bytes"), size));
       
  2766 
       
  2767     // Adjust RChunk to accomodate found SDs using known hnalde
       
  2768     TPtr8* pDescriptions = NULL;
       
  2769     retVal = pSenChunk->AllocDescToChunk(size, pDescriptions); 
       
  2770 
       
  2771     if(retVal==KErrNone && pDescriptions)
       
  2772         {
       
  2773         CBufFlat* pBuf = NULL;
       
  2774         if(count>0)
       
  2775             {
       
  2776             pBuf = CBufFlat::NewL(KFlatBufSize);
       
  2777             CleanupStack::PushL(pBuf);
       
  2778             RBufWriteStream bufWs(*pBuf);
       
  2779             CleanupClosePushL(bufWs);
       
  2780             arr[0]->WriteAsXMLToL(bufWs);
       
  2781             // Add this SD as XML into the "big heap buffer":
       
  2782             TPtr8 p8 = pBuf->Ptr(0);
       
  2783             pDescriptions->Append(p8); 
       
  2784             // Destroy the temporary, flat stream buffer
       
  2785             CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  2786             pBuf = NULL;
       
  2787             }
       
  2788         for(TInt x=1; x<count; x++)
       
  2789             {
       
  2790             // Add delimiter
       
  2791             pDescriptions->Append(KTab); 
       
  2792 
       
  2793             pBuf = CBufFlat::NewL(KFlatBufSize);
       
  2794             CleanupStack::PushL(pBuf);
       
  2795             RBufWriteStream bufWs(*pBuf);
       
  2796             CleanupClosePushL(bufWs);
       
  2797             arr[x]->WriteAsXMLToL(bufWs);
       
  2798             // Add this SD as XML into the "big heap buffer":
       
  2799             TPtr8 p8 = pBuf->Ptr(0);
       
  2800             pDescriptions->Append(p8); 
       
  2801             CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  2802             pBuf = NULL;
       
  2803             }
       
  2804         CSLOG_L(iConnectionID,KMaxLogLevel ,"- Requested descriptions:");
       
  2805         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*pDescriptions));
       
  2806         }
       
  2807 #ifdef _SENDEBUG
       
  2808     else
       
  2809         {
       
  2810         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- AllocDescToRMsgL failed: %d"), retVal));
       
  2811         }
       
  2812 #endif // _SENDEBUG
       
  2813 
       
  2814     CleanupStack::PopAndDestroy(); // arr.Close() is enough
       
  2815     CleanupStack::PopAndDestroy(pSenChunk); // Close SenChunk
       
  2816 
       
  2817     aMessage.Complete(retVal);
       
  2818     }
       
  2819 
       
  2820 void CSenClientSession::ServiceDescriptionsByUriL(const RMessage2& aMessage)
       
  2821     {
       
  2822     TInt retVal(KErrNone);
       
  2823     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ServiceDescriptionsByUriL (contract)");
       
  2824     
       
  2825     CSenChunk* pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  2826     pSenChunk->SetLogger(Log());
       
  2827     
       
  2828     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  2829     if(retVal != KErrNone)
       
  2830         {
       
  2831         CleanupStack::PopAndDestroy(pSenChunk);
       
  2832         aMessage.Complete(KErrBadDescriptor);
       
  2833         return;
       
  2834         }
       
  2835     
       
  2836     TPtrC8 pattern;
       
  2837     retVal = pSenChunk->DescFromChunk(pattern);
       
  2838     if(retVal != KErrNone)
       
  2839         {
       
  2840         CleanupStack::PopAndDestroy(pSenChunk);
       
  2841         aMessage.Complete(KErrBadDescriptor);
       
  2842         return;
       
  2843         }
       
  2844 
       
  2845     RWSDescriptionArray arr;
       
  2846     retVal = iManager.ServiceDescriptionsL(arr, pattern);
       
  2847     CleanupClosePushL(arr);
       
  2848 
       
  2849     if (retVal != KErrNone)
       
  2850         {
       
  2851         CleanupStack::PopAndDestroy(); // arr.Close() is enough
       
  2852         CleanupStack::PopAndDestroy(pSenChunk);
       
  2853         aMessage.Complete(retVal);
       
  2854         return;
       
  2855         }
       
  2856 
       
  2857 
       
  2858     TInt count = arr.Count();
       
  2859     
       
  2860     // Calculate required heap allocation size:
       
  2861     TInt size(0);
       
  2862     if(count>0)
       
  2863         {
       
  2864         size += (count-1) * KTab().Length();
       
  2865         }
       
  2866 
       
  2867     TInt leaveCode(KErrNone);
       
  2868     TRAP(leaveCode, size += iManager.SizeOfServiceDescriptionsL(arr); )
       
  2869     if(leaveCode!=KErrNone)
       
  2870         {
       
  2871         // the elements of array are not owned, reset is enough
       
  2872         //arr.Reset();
       
  2873         CleanupStack::PopAndDestroy(); // arr.Close() is enough
       
  2874         CleanupStack::PopAndDestroy(pSenChunk);
       
  2875         aMessage.Complete(leaveCode); 
       
  2876         }
       
  2877         
       
  2878     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ServiceDescriptionsByPatternL");
       
  2879 
       
  2880     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Size of SD(s) + delimiter(s): %d bytes"), size));
       
  2881 
       
  2882     TPtr8* pDescriptions = NULL;
       
  2883     retVal = pSenChunk->AllocDescToChunk(size, pDescriptions); 
       
  2884 
       
  2885     if(retVal==KErrNone && pDescriptions)
       
  2886         {
       
  2887 
       
  2888         CBufFlat* pBuf = NULL;
       
  2889         if(count>0)
       
  2890             {
       
  2891             pBuf = CBufFlat::NewL(KFlatBufSize);
       
  2892             CleanupStack::PushL(pBuf);
       
  2893             RBufWriteStream bufWs(*pBuf);
       
  2894             CleanupClosePushL(bufWs);
       
  2895             arr[0]->WriteAsXMLToL(bufWs);
       
  2896             // Add this SD as XML into the "big heap buffer":
       
  2897             TPtr8 p8 = pBuf->Ptr(0);
       
  2898             pDescriptions->Append(p8); 
       
  2899             // Destroy the temporary, flat stream buffer
       
  2900             CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  2901             pBuf = NULL;
       
  2902             }
       
  2903 
       
  2904         for(TInt x=1; x<count; x++)
       
  2905             {
       
  2906             // Add delimiter
       
  2907             pDescriptions->Append(KTab); 
       
  2908 
       
  2909             pBuf = CBufFlat::NewL(KFlatBufSize);
       
  2910             CleanupStack::PushL(pBuf);
       
  2911             RBufWriteStream bufWs(*pBuf);
       
  2912             CleanupClosePushL(bufWs);
       
  2913             arr[x]->WriteAsXMLToL(bufWs);
       
  2914             // Add this SD as XML into the "big heap buffer":
       
  2915             TPtr8 p8 = pBuf->Ptr(0);
       
  2916             pDescriptions->Append(p8); 
       
  2917             CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  2918             pBuf = NULL;
       
  2919             }
       
  2920             
       
  2921         CSLOG_L(iConnectionID,KMaxLogLevel ,"- Requested descriptions:");
       
  2922         CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*pDescriptions));
       
  2923         }
       
  2924 #ifdef _SENDEBUG
       
  2925     else
       
  2926         {
       
  2927         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- AllocDescToRMsgL failed: %d"), retVal));
       
  2928         }
       
  2929 #endif // _SENDEBUG
       
  2930     CleanupStack::PopAndDestroy(); // arr.Close() is enough
       
  2931     CleanupStack::PopAndDestroy(pSenChunk); // Close SenChunk
       
  2932     aMessage.Complete(retVal);
       
  2933     }
       
  2934 
       
  2935 void CSenClientSession::IsReadyL(const RMessage2& aMessage)
       
  2936     {
       
  2937     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::IsReadyL")));
       
  2938 
       
  2939     TBool isReady(EFalse);
       
  2940 
       
  2941     if (iStatus == KSenConnectionStatusReady)
       
  2942         isReady = ETrue;
       
  2943 
       
  2944     TPtr8 ptr(reinterpret_cast<TUint8*>(&isReady), sizeof(isReady),
       
  2945                 sizeof(isReady));
       
  2946     aMessage.WriteL(0, ptr); //IPC V2
       
  2947     aMessage.Complete(KErrNone);
       
  2948     }
       
  2949 
       
  2950 // note: currently this function does not leave
       
  2951 void CSenClientSession::StartTransactionL(const RMessage2& aMessage)
       
  2952     {
       
  2953     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::StartTransactionL")));
       
  2954 
       
  2955     if (!CheckValidity(aMessage))
       
  2956         {
       
  2957         return;
       
  2958         }
       
  2959     TInt retVal(KErrNone);
       
  2960     iServiceSession->StartTransaction();
       
  2961     aMessage.Complete(retVal);
       
  2962     }
       
  2963 
       
  2964 // note: currently this function does not leave
       
  2965 void CSenClientSession::TransactionCompletedL(const RMessage2& aMessage)
       
  2966     {
       
  2967     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::TransactionCompletedL")));
       
  2968 
       
  2969     if (!CheckValidity(aMessage))
       
  2970         {
       
  2971         return;
       
  2972         }
       
  2973     TInt retVal(KErrNone);
       
  2974     iServiceSession->TransactionCompleted();
       
  2975     aMessage.Complete(retVal);
       
  2976     }
       
  2977 
       
  2978 void CSenClientSession::CancelSessionL(const RMessage2& aMessage)
       
  2979     {
       
  2980     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::CancelSessionL")));
       
  2981     // Complete pending msgs via this call - or one could call non-leaving 
       
  2982     // version and complete with (possible) leavecode it returns..
       
  2983     CompletePendingMessagesL(); 
       
  2984     
       
  2985     // Check if this session is remote hostlet
       
  2986     if ( iSessionType == ERemoteHostlet_HC && ipHostletAwaitOp)
       
  2987         {
       
  2988         ipHostletAwaitOp->RMessage().Complete(KErrSenCancelled);
       
  2989         delete ipHostletAwaitOp;
       
  2990         ipHostletAwaitOp = NULL; 
       
  2991         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CancelSessionL - await op completed with KErrSenCancelled");
       
  2992         
       
  2993         }
       
  2994     
       
  2995     iManager.SetShowPasswordDialog(EFalse); // not mandatory
       
  2996     aMessage.Complete(KErrNone);
       
  2997     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CancelSessionL - operation complete.");
       
  2998     }
       
  2999 
       
  3000 void CSenClientSession::HasFacetL(const RMessage2& aMessage)
       
  3001     {
       
  3002     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::HasFacetL")));
       
  3003 
       
  3004     if (!CheckValidity(aMessage))
       
  3005         {
       
  3006         return;
       
  3007         }
       
  3008 
       
  3009     TInt length = aMessage.Int2();
       
  3010     if (length < 1)
       
  3011         {
       
  3012         aMessage.Complete(KErrBadDescriptor);
       
  3013         return;
       
  3014         }
       
  3015 
       
  3016     HBufC8* inBuf = HBufC8::NewLC(length);
       
  3017     TPtr8 inBuffer = inBuf->Des();
       
  3018     //inBuffer.Zero();
       
  3019 
       
  3020     TBool hasFacet;
       
  3021 
       
  3022     aMessage.ReadL(0, inBuffer); // URI
       
  3023 
       
  3024     TInt retVal = iServiceSession->HasFacetL(inBuffer, hasFacet);
       
  3025 
       
  3026     TPtr8 ptr(reinterpret_cast<TUint8*>(&hasFacet), sizeof(hasFacet),
       
  3027         sizeof(hasFacet));
       
  3028     aMessage.WriteL(1, ptr); //IPC V2
       
  3029     CleanupStack::PopAndDestroy(); // inBuf
       
  3030     aMessage.Complete(retVal);
       
  3031     }
       
  3032 
       
  3033 void CSenClientSession::CompleteServerMessagesOnOffL(const RMessage2& aMessage)
       
  3034     {
       
  3035     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::CompleteServerMessagesOnOffL")));
       
  3036 
       
  3037     if (!CheckValidity(aMessage))
       
  3038         {
       
  3039         return;
       
  3040         }
       
  3041 
       
  3042     HBufC8* inBuf = HBufC8::NewLC(10);
       
  3043     TPtr8 inBuffer = inBuf->Des();
       
  3044     aMessage.ReadL(0, inBuffer); // boolean
       
  3045     TBool onOrOff = (TBool)(*inBuffer.Ptr()) ;
       
  3046 
       
  3047     TInt retVal = iServiceSession->CompleteServerMessagesOnOffL(onOrOff);
       
  3048     CleanupStack::PopAndDestroy(); // inBuf
       
  3049     aMessage.Complete(retVal);
       
  3050     }
       
  3051 
       
  3052 void CSenClientSession::RequestServiceDescriptionL(const RMessage2& aMessage)
       
  3053     {
       
  3054     TInt retVal(KErrNone);
       
  3055     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::RequestServiceDescriptionL")));
       
  3056     if (!CheckValidity(aMessage))
       
  3057         {
       
  3058         return;
       
  3059         }
       
  3060 
       
  3061     iSendBuf = CBufFlat::NewL(KFlatBufSize);
       
  3062 
       
  3063     RBufWriteStream bufWs(*iSendBuf);
       
  3064     CleanupClosePushL(bufWs); // push
       
  3065     iServiceSession->AsServiceDescription().WriteAsXMLToL(bufWs);
       
  3066     //iServiceSession->WriteAsXMLToL(bufWs); 
       
  3067 
       
  3068 
       
  3069     // write the data length to client process descriptor..
       
  3070     TInt neededLength = iSendBuf->Ptr(0).Length();
       
  3071     TPtr8 ptr(reinterpret_cast<TUint8*>(&neededLength), sizeof(neededLength), sizeof(neededLength));
       
  3072     TRAP( retVal, aMessage.WriteL(0, ptr); ) //IPC V2
       
  3073 
       
  3074     CleanupStack::PopAndDestroy(); // close bufWs
       
  3075     aMessage.Complete(retVal);
       
  3076     }
       
  3077 
       
  3078 void CSenClientSession::ReceiveServiceDescriptionL(const RMessage2& aMessage)
       
  3079     {
       
  3080     TInt retVal(KErrNone);
       
  3081     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::ReceiveServiceDescriptionL")));
       
  3082     if (!CheckValidity(aMessage))
       
  3083         {
       
  3084         return;
       
  3085         }
       
  3086     if(iSendBuf)
       
  3087         {
       
  3088         TRAP( retVal, aMessage.WriteL(0, iSendBuf->Ptr(0)); )  //IPC V2
       
  3089         }
       
  3090     else 
       
  3091         {
       
  3092         retVal = KErrSenInternal; 
       
  3093         }
       
  3094 
       
  3095     aMessage.Complete(retVal);
       
  3096     }
       
  3097     
       
  3098 void CSenClientSession::SetTransportPropertiesL(const RMessage2& aMessage)
       
  3099     {
       
  3100     TInt retVal(KErrNone);
       
  3101     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::SetTransportPropertiesL")));
       
  3102 
       
  3103     if ( !CheckValidity(aMessage) )
       
  3104         {
       
  3105         return;
       
  3106         }
       
  3107     
       
  3108     CSenChunk* pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3109     pSenChunk->SetLogger(Log());
       
  3110     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3111 
       
  3112     if(retVal != KErrNone)
       
  3113         {
       
  3114         CleanupStack::PopAndDestroy(pSenChunk);
       
  3115         aMessage.Complete(KErrBadDescriptor);
       
  3116         return;
       
  3117         }
       
  3118     
       
  3119     TPtrC8 transportProperties;
       
  3120     retVal = pSenChunk->DescFromChunk(transportProperties);
       
  3121     if(retVal != KErrNone)
       
  3122         {
       
  3123         CleanupStack::PopAndDestroy(pSenChunk);
       
  3124         aMessage.Complete(KErrBadDescriptor);
       
  3125         return;
       
  3126         }
       
  3127     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Transport Properties (%d bytes):"), transportProperties.Length()));
       
  3128     CSLOG_ALL(iConnectionID, KMaxLogLevel ,(transportProperties));
       
  3129     if ( iServiceSession )
       
  3130         {
       
  3131 #ifdef __ENABLE_ALR__
       
  3132 #if  defined ( RD_SEN_ENABLE_VTCP_BY_TRANSPORTPROPERTIES )
       
  3133 	HBufC8* pNewTransportProperties = NULL ;
       
  3134 	    if (iSessionType != ERemoteHostlet_HC)
       
  3135             {
       
  3136             
       
  3137             //Only Real Consumer will monitor Mobility service
       
  3138             if (!iALRObserver)
       
  3139                 {
       
  3140 	            CSLOG_L(iConnectionID, KMinLogLevel , "SetTransportPropertiesL - creating new ALR observer");
       
  3141                 iALRObserver = CALRObserver::NewL (*this, *iManager.XMLReader()) ;
       
  3142                 }
       
  3143             MSenTransport& transport = TransportL() ;
       
  3144             MSenProperties& property = transport.PropertiesL() ;
       
  3145             //TPtrC8 transportCue = (*iInitializer).TransportCue();
       
  3146             if (property.PropertiesClassType() == MSenProperties::ESenLayeredVtcpTransportProperties)
       
  3147               	{
       
  3148             	if (iALRObserver->GetActiveIap() >= 0 )//&& (transportCue == KSenTransportCueVirtualTCP)
       
  3149             		{
       
  3150             		//VTCP start a connection while setting transport itself so lets start ALR mobility observer
       
  3151             		//collect the iap id and propagate it to VTCP
       
  3152       		        CSLOG_L(iConnectionID, KMinLogLevel , "-SetTransportPropertiesL calling OpenConnectionL ");
       
  3153             		TInt error = iALRObserver->OpenConnectionL(transportProperties, transport, *iInitializer, pNewTransportProperties) ;
       
  3154         		if (error != KErrNone)
       
  3155             			{
       
  3156             			//ALR boot up failed , still iap can be collected in plugin 
       
  3157             		    CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("SetTransportPropertiesL - OpenConnectionL returned, error: %d"), error));
       
  3158             		  	}
       
  3159             		if (pNewTransportProperties)
       
  3160             			{
       
  3161              		    CSLOG_L(iConnectionID, KMinLogLevel , "-SetTransportPropertiesL setting new transport properties from ALR observer");
       
  3162             			transportProperties.Set(pNewTransportProperties->Des()) ;
       
  3163                 		CleanupStack::PushL(pNewTransportProperties);                        
       
  3164             			}
       
  3165             		}
       
  3166               	}
       
  3167             }
       
  3168 #endif //RD_SEN_ENABLE_VTCP_BY_TRANSPORTPROPERTIES
       
  3169 #endif //__ENABLE_ALR__
       
  3170 #ifdef __TEST_RETRY_TTL
       
  3171 			HBufC8* pNewTranProp = NULL;
       
  3172 			CSenVtcpTransportProperties* pVtcpProperties=CSenVtcpTransportProperties::NewL(transportProperties, *iManager.XMLReader());
       
  3173 			pVtcpProperties->SetMaxRetryTTLL(240);
       
  3174 			pVtcpProperties->SetMinRetryTTLL(30);
       
  3175 			pVtcpProperties->SetRetryDeltaTimeoutL(30);
       
  3176 			pNewTranProp=pVtcpProperties->AsUtf8LC();
       
  3177 			transportProperties.Set(pNewTranProp->Des()) ;
       
  3178 			delete pVtcpProperties;
       
  3179 			pVtcpProperties = NULL;	
       
  3180 			
       
  3181 #endif //__TEST_RETRY_TTL
       
  3182 	        retVal = iServiceSession->SetTransportPropertiesL(transportProperties, *this);
       
  3183 #ifdef __TEST_RETRY_TTL	        
       
  3184 	       CleanupStack::PopAndDestroy(pNewTranProp);
       
  3185 #endif //__TEST_RETRY_TTL	       
       
  3186 #ifdef __ENABLE_ALR__
       
  3187 #if  defined ( RD_SEN_ENABLE_VTCP_BY_TRANSPORTPROPERTIES )
       
  3188                 if (pNewTransportProperties != NULL)
       
  3189                     {
       
  3190             	        CleanupStack::PopAndDestroy(pNewTransportProperties);  
       
  3191                     }
       
  3192 #endif //RD_SEN_ENABLE_VTCP_BY_TRANSPORTPROPERTIES	     	        
       
  3193 #endif //__ENABLE_ALR__
       
  3194         }
       
  3195     else
       
  3196         {
       
  3197         retVal = KErrSenNotInitialized;
       
  3198         }
       
  3199 
       
  3200     CleanupStack::PopAndDestroy(pSenChunk);
       
  3201     aMessage.Complete(retVal);
       
  3202     }
       
  3203 
       
  3204 void CSenClientSession::TransportPropertiesL(const RMessage2& aMessage)
       
  3205     {
       
  3206     TInt retVal(KErrNone);
       
  3207     CSLOG(iConnectionID, KMinLogLevel ,(_L("CSenClientSession::TransportPropertiesL")));
       
  3208     
       
  3209     if ( !CheckValidity(aMessage) )
       
  3210         {
       
  3211         return;
       
  3212         }
       
  3213 
       
  3214     CSenChunk* pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3215     pSenChunk->SetLogger(Log());
       
  3216     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3217 
       
  3218     if ( retVal != KErrNone )
       
  3219         {
       
  3220         CleanupStack::PopAndDestroy(pSenChunk);
       
  3221         aMessage.Complete(KErrBadDescriptor);
       
  3222         return;
       
  3223         }
       
  3224 
       
  3225     HBufC8* pTransportProperties = NULL;
       
  3226     iServiceSession->TransportPropertiesL(pTransportProperties, *this);
       
  3227     
       
  3228     retVal = pSenChunk->DescToChunk(*pTransportProperties);
       
  3229     delete pTransportProperties;
       
  3230     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- DescToRChunkL returned: %d"), retVal));
       
  3231     
       
  3232     if ( retVal != KErrNone )
       
  3233         {
       
  3234         aMessage.Complete(ESenInternalError);
       
  3235         CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - HandleBase");
       
  3236         }
       
  3237         
       
  3238     CleanupStack::PopAndDestroy(pSenChunk);
       
  3239     aMessage.Complete(retVal);
       
  3240     }
       
  3241 
       
  3242 void CSenClientSession::EstablishHostletConnectionL(const RMessage2& aMessage)
       
  3243     {
       
  3244     // To cache secure id of the client
       
  3245     // This secure id will be used to notify client in case RProperty updates
       
  3246     iClientSecureID = aMessage.SecureId();
       
  3247 
       
  3248     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::EstablishHostletConnectionL( %d )"), aMessage.Handle()));
       
  3249 
       
  3250     iSessionType = ERemoteHostlet_HC;
       
  3251     TInt retVal(KErrNone);
       
  3252     // Read hostlet connection properties from the rmessage
       
  3253 
       
  3254 
       
  3255     // Read service description buffer length
       
  3256     HBufC8* pServiceDescriptionBuf = NULL;
       
  3257     retVal = ReadBufferFromRMessageL(aMessage, 1, 0, pServiceDescriptionBuf);
       
  3258     CleanupStack::PushL( pServiceDescriptionBuf );
       
  3259 
       
  3260     if( retVal == KErrNone )
       
  3261         {
       
  3262         // Parse the XML string into a XML service description object
       
  3263         TPtr8 sdAsXml = pServiceDescriptionBuf->Des();
       
  3264         delete iInitializer;
       
  3265         iInitializer = NULL;
       
  3266         retVal = ParseSessionInitializerL(iInitializer, sdAsXml);
       
  3267 
       
  3268         // Attempt to initialize service session
       
  3269         if ( retVal == KErrNone )
       
  3270             {
       
  3271             // Sanity check
       
  3272             if( !iInitializer )
       
  3273                 {
       
  3274                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Fatal: initializer is NULL after succeeded parsing!");
       
  3275                 retVal = KErrSenInternal;
       
  3276                 }
       
  3277             else
       
  3278                 {
       
  3279                 // Initialize the service session
       
  3280                 HBufC8* pErrorMsg = NULL;
       
  3281                 retVal = InitializeServiceSessionL(*iInitializer, pErrorMsg);
       
  3282                 CleanupStack::PushL( pErrorMsg );
       
  3283                 if( pErrorMsg )
       
  3284                     {
       
  3285                     TPtrC8 error = pErrorMsg->Des();
       
  3286                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- EstablishHostletConnectionL: retVal: (%d), error msg from InitializeServiceSessionL:"), retVal));
       
  3287                     CSLOG_ALL(iConnectionID, KMinLogLevel ,( error ));
       
  3288                     }
       
  3289                 CleanupStack::PopAndDestroy( pErrorMsg );
       
  3290                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Hostlet session INIT returned: %d"), retVal));
       
  3291 
       
  3292 
       
  3293                 if( retVal == KErrNone && iServiceSession )
       
  3294                     {
       
  3295                     if( iServiceSession->Hostlet() )
       
  3296                         {
       
  3297                         // Some other HC is already serving this endpoint,
       
  3298                         // => return "endpoint reserved" code:
       
  3299                         retVal = KErrSenEndpointReserved;
       
  3300                         }
       
  3301                     else
       
  3302                         {
       
  3303                         RFacetArray hostFacets;
       
  3304                         iInitializer->FacetsL( hostFacets );
       
  3305                         CleanupClosePushL( hostFacets );
       
  3306                         TInt count(hostFacets.Count());
       
  3307                         for (TInt i=0; i<count; i++)
       
  3308                             {
       
  3309                             ((CSenServiceSession*)iServiceSession)->SetFacetL(*hostFacets[i]);
       
  3310                             }
       
  3311 
       
  3312                         hostFacets.ResetAndDestroy();
       
  3313                         CleanupStack::Pop();
       
  3314                         // Set this Remote Hostlet for the acquired session.
       
  3315                         iServiceSession->SetHostletL(this);
       
  3316 
       
  3317                         // Remove this client session from the list of session consumers:
       
  3318                         iServiceSession->RemoveConsumerL(*this);
       
  3319 
       
  3320                         // Create new hostlet connection transport plug-in instance:
       
  3321                         TransportL(); 
       
  3322                         
       
  3323                         }
       
  3324 
       
  3325                     }
       
  3326                 }
       
  3327             }
       
  3328         }
       
  3329         
       
  3330     CleanupStack::PopAndDestroy( pServiceDescriptionBuf );
       
  3331     // Complete with: KErrNone or KErrAlreadyExists, KErrSenNoEndpoint or KErrSenNoContract 
       
  3332     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- EstablishHostletConnectionL completes with: %d"), retVal));
       
  3333     aMessage.Complete(retVal); 
       
  3334     }
       
  3335 
       
  3336 // Helper
       
  3337 TInt CSenClientSession::ReadBufferFromRMessageL(const RMessage2& aMessage, 
       
  3338                                                 TInt aSdLengthIdx, 
       
  3339                                                 TInt aSdBufIdx,
       
  3340                                                 HBufC8*& aSdBuf)
       
  3341     {
       
  3342 
       
  3343     if(aSdBufIdx<0 || aSdBufIdx>3 || aSdLengthIdx<0 || aSdLengthIdx>3)
       
  3344         {
       
  3345         return KErrArgument;
       
  3346         }
       
  3347 
       
  3348     TInt retVal(KErrNone);
       
  3349 
       
  3350     // Read service description buffer length
       
  3351     TInt sdLength(KErrNotFound);
       
  3352 
       
  3353     switch(aSdLengthIdx)
       
  3354         {
       
  3355         case 0:
       
  3356             {
       
  3357             sdLength = aMessage.Int0(); // 1st argument
       
  3358             break;
       
  3359             }
       
  3360         case 1:
       
  3361             {
       
  3362             sdLength = aMessage.Int1(); // 2nd argument
       
  3363             break;
       
  3364             }
       
  3365         case 2:
       
  3366             {
       
  3367             sdLength = aMessage.Int2(); // 3rd argument
       
  3368             break;
       
  3369             }
       
  3370         case 3:
       
  3371             {
       
  3372             sdLength = aMessage.Int3(); // 4th argument
       
  3373             break;
       
  3374             }
       
  3375         default:
       
  3376             {
       
  3377             return KErrArgument;
       
  3378             }
       
  3379         }
       
  3380 
       
  3381     // Free and allocate buffer for service description    
       
  3382     delete aSdBuf;
       
  3383     aSdBuf = NULL;
       
  3384 
       
  3385     if(sdLength>0)
       
  3386         {
       
  3387         aSdBuf = HBufC8::NewL(sdLength);
       
  3388         TPtr8 sdBuffer = aSdBuf->Des();
       
  3389         // Read sd data into buf 
       
  3390         switch(aSdBufIdx)
       
  3391             {
       
  3392             case 0:
       
  3393                 {
       
  3394                 aMessage.ReadL(0, sdBuffer);
       
  3395                 break;
       
  3396                 }
       
  3397             case 1:
       
  3398                 {
       
  3399                 aMessage.ReadL(1, sdBuffer);
       
  3400                 break;
       
  3401                 }
       
  3402             case 2:
       
  3403                 {
       
  3404                 aMessage.ReadL(2, sdBuffer);
       
  3405                 break;
       
  3406                 }
       
  3407             case 3:
       
  3408                 {
       
  3409                 aMessage.ReadL(3, sdBuffer);
       
  3410                 break;
       
  3411                 }
       
  3412             default:
       
  3413                 {
       
  3414                 return KErrArgument;
       
  3415                 }
       
  3416             }
       
  3417         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8(" - ServiceDescription (%d bytes):"), sdBuffer.Length()));
       
  3418         CSLOG_ALL(iConnectionID, KMaxLogLevel ,(sdBuffer));
       
  3419         }
       
  3420     else
       
  3421         {
       
  3422         CSLOG_L(iConnectionID,KNormalLogLevel ," - error: SD length is zero!");
       
  3423         retVal = KErrArgument;
       
  3424         }
       
  3425     return retVal;
       
  3426     }
       
  3427 
       
  3428 void CSenClientSession::AwaitHostletRequestL(const RMessage2& aMessage)
       
  3429     {
       
  3430     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::AwaitHostletRequestL( %d )"), aMessage.Handle()));
       
  3431 
       
  3432     // ALWAYS first check, if there already is some pending request, in which 
       
  3433     // case aMessage can be completed immediately with request's chunk handle.
       
  3434     RHostletRequestMap& requests = HostletRequestMap();
       
  3435     TInt count(requests.Count());
       
  3436     if( count > 0 )
       
  3437         {
       
  3438         CSenClientMessage* pMessage = (CSenClientMessage*)requests.ValueAt( 0 );
       
  3439         const TInt* pKey = requests.KeyAt( 0 );
       
  3440         if( pMessage && pKey )
       
  3441             {
       
  3442             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d request(s) already waiting. Completing (serving) first in queue immediately."), count));
       
  3443             delete ipHostletAwaitOp;
       
  3444             ipHostletAwaitOp = NULL; // busy
       
  3445             RHandleBase& handle = pMessage->Chunk();
       
  3446 #ifdef EKA2
       
  3447             aMessage.Complete( handle );
       
  3448 #else // EKA1
       
  3449             aMessage.Complete( handle.Handle() );
       
  3450 #endif // EKA2:EKA1
       
  3451             // Queue is processed in simple, FIFO manner:
       
  3452             requests.RemoveByKey( *pKey ); // de-allocates the txn ID
       
  3453             }
       
  3454         }
       
  3455     else // start waiting for request..
       
  3456         {
       
  3457         // De-allocate last await op (wrapper)
       
  3458         delete ipHostletAwaitOp;
       
  3459         ipHostletAwaitOp = NULL;
       
  3460         // Create wrapper for wait operation (RMessage2)
       
  3461         ipHostletAwaitOp = CSenClientMessage::NewL( aMessage );
       
  3462         CSLOG_L(iConnectionID,KMinLogLevel ,"- Waiting for Hostlet request from consumer(s).");
       
  3463         }
       
  3464     }
       
  3465 
       
  3466 
       
  3467 
       
  3468 
       
  3469 void CSenClientSession::ProvideHostletResponseL( const RMessage2& aMessage )
       
  3470     {
       
  3471     TInt responseCode = aMessage.Int3();
       
  3472     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::ProvideHostletResponseL( handle: %d, responseCode: %d )"), aMessage.Handle(), responseCode));
       
  3473     TInt retVal(KErrNone);
       
  3474     
       
  3475     TInt txnId(KErrNotFound);
       
  3476     CSenChunk* pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3477     pSenChunk->SetLogger(Log());
       
  3478     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage, 2);
       
  3479     if ( retVal == KErrNone )
       
  3480         {
       
  3481         txnId = pSenChunk->ChunkHeader().TransactionId();
       
  3482         retVal = iServiceSession->ProvideHostletResponseL(*this, txnId, responseCode, KNullDesC8, *pSenChunk);
       
  3483         }
       
  3484     CleanupStack::PopAndDestroy( pSenChunk );
       
  3485         
       
  3486     if( retVal != KErrNone )  
       
  3487         {
       
  3488         // Some error occured, complete ASYNC "provide" -operation immediately
       
  3489         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::ProvideHostletResponseL - ERROR: Complete(%d)"), retVal));    
       
  3490         aMessage.Complete(retVal);
       
  3491         }
       
  3492     else
       
  3493         {
       
  3494         // OK, append this ASYNC op to array of pending REMOTE HOSTLET transactions         
       
  3495         // NOTE: TransactionL() method is quite similart to below code (re-factor later on)
       
  3496         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ProvideHostletResponseL - transport's CompleteTransaction() returned OK");
       
  3497             
       
  3498         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::ProvideHostletResponseL - RMessage2(%d)"), aMessage.Handle()));
       
  3499 
       
  3500         CSenClientMessage* pMessage = CSenClientMessage::NewLC( aMessage );
       
  3501         pMessage->SetLogger(Log());
       
  3502         TInt retVal = pMessage->OpenChunkFromRMsgL(pMessage->RMessage(),2);
       
  3503         
       
  3504         if ( retVal == KErrNone )
       
  3505             {
       
  3506             TInt* pTxnId = new (ELeave) TInt(txnId);
       
  3507             CleanupStack::PushL(pTxnId);
       
  3508 
       
  3509             retVal = TxnIds().Append(pTxnId);
       
  3510             if ( retVal == KErrNone )
       
  3511                 {
       
  3512                 CleanupStack::Pop(pTxnId); // now owned by pointer array
       
  3513             
       
  3514                 retVal = Transactions().Append(pMessage);
       
  3515                 if(retVal==KErrNone)
       
  3516                     {
       
  3517                     CleanupStack::Pop(pMessage); // now owned by transaction array of this Remote Hostlet
       
  3518                     // Respond operation (ASYNC) is now safely pending
       
  3519                     // Start waiting for MSenRemoteHostlet::OnServiceCompleteL OR cancel OR destruction 
       
  3520                     // of this client session (remote hostlet)...
       
  3521                     CSLOG_L(iConnectionID,KMinLogLevel ,"- ProvideResponse IPC operation now pending: OK.");
       
  3522                     }
       
  3523                 else
       
  3524                     {
       
  3525                     CleanupStack::PopAndDestroy(pMessage);
       
  3526                     }
       
  3527                 }
       
  3528             else
       
  3529                 {
       
  3530                 CleanupStack::PopAndDestroy(pTxnId);
       
  3531                 CleanupStack::PopAndDestroy(pMessage);
       
  3532                 }
       
  3533             }
       
  3534         else
       
  3535             {
       
  3536             CleanupStack::PopAndDestroy(pMessage);
       
  3537             }
       
  3538             
       
  3539         if ( retVal != KErrNone )
       
  3540             {
       
  3541             CSLOG_L(iConnectionID,KMinLogLevel ,"- Append failed (OOM): de-allocate client message:");
       
  3542             CSLOG_L(iConnectionID,KMinLogLevel ,"- Completeting this asynchronous IPC operation with ESenInternalError");
       
  3543             aMessage.Complete(retVal);
       
  3544             }
       
  3545         }
       
  3546     }
       
  3547 // Constantness on the TInt return type has no meaning since you are returning by value
       
  3548 TInt CSenClientSession::ConnectionId()
       
  3549     {
       
  3550     	return (iConnectionID);
       
  3551     }
       
  3552 
       
  3553 void CSenClientSession::MoveChunkL(const RMessage2& aMessage)
       
  3554     {
       
  3555     TInt retVal(KErrNone);
       
  3556     CSenChunk* pSenChunk = NULL;
       
  3557 
       
  3558     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3559     pSenChunk->SetLogger(Log());
       
  3560     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3561     
       
  3562     if ( retVal == KErrNone )
       
  3563         {
       
  3564         retVal = TransactionIndex(pSenChunk->ChunkHeader().TransactionId());
       
  3565         if ( retVal != KErrNotFound )
       
  3566             {
       
  3567             RTransactionArray& transactions = Transactions();   
       
  3568             CSenClientMessage* pClientMessage = transactions[retVal];
       
  3569     
       
  3570             TPtrC8 cid;
       
  3571             retVal = pSenChunk->DescFromChunk(cid,2);
       
  3572             if ( retVal == KErrNone )
       
  3573                 {
       
  3574                 RChunk chunk;
       
  3575                 CleanupClosePushL(chunk);
       
  3576                 retVal = chunk.Open(aMessage, 1, EOwnerProcess);
       
  3577                 if ( retVal == KErrNone )
       
  3578                     {
       
  3579                     CSenBinaryData* pBinaryData = CSenBinaryData::NewLC( chunk, cid, aMessage.Int2(), aMessage.Int3() );
       
  3580             		RPointerArray<CSenBinaryData>& bArray = pClientMessage->BinaryDataArray();
       
  3581             		bArray.AppendL(pBinaryData);
       
  3582             		CleanupStack::Pop(pBinaryData);
       
  3583                     }
       
  3584                 CleanupStack::Pop(&chunk);
       
  3585                 }
       
  3586             }
       
  3587         }
       
  3588         
       
  3589     CleanupStack::PopAndDestroy(pSenChunk);
       
  3590     
       
  3591     aMessage.Complete(retVal);
       
  3592     }
       
  3593 
       
  3594 void CSenClientSession::MoveFileL( const RMessage2& aMessage )
       
  3595     {
       
  3596     TInt retVal(KErrNone);
       
  3597     CSenChunk* pSenChunk = NULL;
       
  3598 
       
  3599     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3600     pSenChunk->SetLogger(Log());
       
  3601     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3602     
       
  3603     if ( retVal == KErrNone )
       
  3604         {
       
  3605         retVal = TransactionIndex(pSenChunk->ChunkHeader().TransactionId());
       
  3606         if ( retVal != KErrNotFound )
       
  3607             {
       
  3608             RTransactionArray& transactions = Transactions();   
       
  3609             CSenClientMessage* pClientMessage = transactions[retVal];
       
  3610 
       
  3611             TPtrC8 cid;
       
  3612             retVal = pSenChunk->DescFromChunk(cid,2);
       
  3613             if (retVal == KErrNone)
       
  3614                 {
       
  3615                 RFile binaryDataFile;
       
  3616                 CleanupClosePushL(binaryDataFile);
       
  3617                 retVal = binaryDataFile.AdoptFromClient(aMessage, 1, 2);
       
  3618                 if ( retVal == KErrNone )
       
  3619                     {
       
  3620                     RFs fs;
       
  3621             		// Get the Session handle
       
  3622             		User::LeaveIfError(fs.Open(aMessage, 1));
       
  3623             		CleanupClosePushL(fs);
       
  3624                     
       
  3625                     RFile file;
       
  3626             		// Adopt the File handle;
       
  3627             		User::LeaveIfError(file.Adopt(fs, binaryDataFile.SubSessionHandle()));
       
  3628             		CleanupClosePushL(file);
       
  3629             		
       
  3630             		CSenBinaryData* pBinaryData = CSenBinaryData::NewLC(fs, file, cid);
       
  3631             		RPointerArray<CSenBinaryData>& bArray = pClientMessage->BinaryDataArray();
       
  3632             		bArray.AppendL(pBinaryData);
       
  3633             		CleanupStack::Pop(pBinaryData);
       
  3634             		
       
  3635             		CleanupStack::Pop(&file);
       
  3636             		CleanupStack::Pop(&fs);
       
  3637                     }
       
  3638           	    CleanupStack::PopAndDestroy(&binaryDataFile);
       
  3639                 }
       
  3640             }
       
  3641         }
       
  3642 
       
  3643     CleanupStack::PopAndDestroy(pSenChunk);
       
  3644         
       
  3645     aMessage.Complete(retVal);
       
  3646     }
       
  3647     
       
  3648     
       
  3649 void CSenClientSession::SendFileHandleL( const RMessage2& aMessage )
       
  3650     {
       
  3651     TInt retVal(KErrNone);
       
  3652     TInt txnId(KErrNotFound);
       
  3653     CSenChunk* pSenChunk = NULL;
       
  3654     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3655     
       
  3656     pSenChunk->SetLogger(Log());
       
  3657     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3658 
       
  3659     if ( retVal == KErrNone )
       
  3660         {
       
  3661         txnId = pSenChunk->ChunkHeader().TransactionId();
       
  3662         if ( txnId != KErrNotFound )
       
  3663             { 
       
  3664             RFile fileHandle;
       
  3665             CleanupClosePushL(fileHandle);
       
  3666             retVal = fileHandle.AdoptFromClient(aMessage, 1, 2);
       
  3667             if ( retVal == KErrNone )
       
  3668                 {
       
  3669 		         if (fileHandle.SubSessionHandle())
       
  3670 			         { 
       
  3671 	                
       
  3672 		                TInt fileSize(0);
       
  3673 		                fileHandle.Size(fileSize);
       
  3674 		                
       
  3675 		                if (fileSize > 0)
       
  3676 		                {
       
  3677 			               CSenClientMessage* pContext = iPendingTransactions[txnId];
       
  3678 			                if (pContext)
       
  3679 			                {
       
  3680 			                	pContext->RequestFileHandle(fileHandle);		                
       
  3681 			                }			                
       
  3682 						    
       
  3683 		                }
       
  3684 		                else
       
  3685 		                {
       
  3686 		                	retVal = KErrArgument;		                	
       
  3687 		                }
       
  3688 		                
       
  3689 	                }
       
  3690 	                else
       
  3691 	                {
       
  3692 	                	retVal=KErrArgument; // NULL file handle;
       
  3693 	         
       
  3694 	                }
       
  3695                }
       
  3696             CleanupStack::Pop(&fileHandle);
       
  3697             }
       
  3698         }
       
  3699 
       
  3700     CleanupStack::PopAndDestroy(pSenChunk);
       
  3701 
       
  3702     aMessage.Complete(retVal);
       
  3703     }
       
  3704 TInt CSenClientSession::SendProgressToHostlet(const RMessage2& aMessage)
       
  3705     {
       
  3706     MSenRemoteHostlet* hostlet = iServiceSession->Hostlet();
       
  3707     if (!hostlet)
       
  3708         {
       
  3709         return KErrNotSupported;
       
  3710         }
       
  3711     TTransferProgress progressData;
       
  3712     TPckg<TTransferProgress> dataPtr = progressData;
       
  3713     TInt err = aMessage.Read(0, dataPtr);
       
  3714     if (err != KErrNone)
       
  3715         {
       
  3716         return err;
       
  3717         }
       
  3718     err = aMessage.GetDesLength(1);
       
  3719     if (err < 0)
       
  3720         {
       
  3721         return err;
       
  3722         }
       
  3723     HBufC8* msg = HBufC8::New(err);
       
  3724     if (!msg)
       
  3725         {
       
  3726         return KErrNoMemory;
       
  3727         }
       
  3728     TPtr8 msgPtr = msg->Des();
       
  3729     err = aMessage.Read(1, msgPtr);
       
  3730     if (err == KErrNone)
       
  3731         {
       
  3732         hostlet->TransferProgressForHostlet(progressData.iTxnId,
       
  3733                 progressData.iIncoming, progressData.iSoap, *msg,
       
  3734                 progressData.iProgress);
       
  3735         }
       
  3736     delete msg;
       
  3737     return err;
       
  3738     }
       
  3739 void CSenClientSession::AddCredentialL( const RMessage2& aMessage )
       
  3740     {
       
  3741     TInt retVal(KErrNone);
       
  3742     CSenChunk* pSenChunk = NULL;
       
  3743 
       
  3744     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3745     pSenChunk->SetLogger(Log());
       
  3746     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3747     
       
  3748     if ( retVal == KErrNone )
       
  3749         {
       
  3750         TPtrC8 patternAsXml;
       
  3751         TPtrC8 idpAsXml;
       
  3752         TPtrC8 credentialAsXml;
       
  3753         
       
  3754         retVal = pSenChunk->DescFromChunk(patternAsXml, 0);
       
  3755         if ( retVal == KErrNone )
       
  3756             {
       
  3757             retVal = pSenChunk->DescFromChunk(idpAsXml, 1);
       
  3758             if ( retVal == KErrNone )
       
  3759                 {
       
  3760                 retVal = pSenChunk->DescFromChunk(credentialAsXml, 2);
       
  3761                 if ( retVal == KErrNone )
       
  3762                     {
       
  3763                     CSenWSDescription* pSD = CSenWSDescription::NewLC();
       
  3764                     pSD->SetReader(*iManager.XMLReader());
       
  3765                     pSD->ParseL(patternAsXml);
       
  3766 
       
  3767                     CSenIdentityProvider* pIdP = CSenIdentityProvider::NewLC(KNullDesC8);
       
  3768                     pIdP->SetReader(*iManager.XMLReader());
       
  3769                     pIdP->ParseL(idpAsXml);
       
  3770                     
       
  3771                     CSenInternalCredential* pCredential = CSenInternalCredential::NewLC();
       
  3772                     CSenParser* pParser = CSenParser::NewLC();
       
  3773                 	pParser->ParseL(credentialAsXml, *pCredential);
       
  3774                 	
       
  3775                 	CSenElement& element = pSD->AsElement();
       
  3776                 	RPointerArray<CSenElement>& elements = element.ElementsL();
       
  3777                 	if ( elements.Count() > 0)
       
  3778                 	    {
       
  3779                 	    CSenCredentialIdentifier& identifier = pCredential->IdentifierL();	//codescannerwarnings
       
  3780                 	    
       
  3781                         TInt elementCount(elements.Count());
       
  3782                         for (TInt i=0; i<elementCount; i++)
       
  3783                             {
       
  3784                             if ( ( elements[i]->LocalName() != KProviderPolicyLocalName ) &&
       
  3785                                  ( elements[i]->LocalName() != KServicePolicyLocalName ) )
       
  3786                                 {
       
  3787                                 if ( elements[i]->LocalName() != KSenFacet )
       
  3788                                     {
       
  3789                                     identifier.SetPropertyL(elements[i]->LocalName(),
       
  3790                                                             elements[i]->Content());
       
  3791                                     }
       
  3792                                 }
       
  3793                             }
       
  3794                         RFacetArray facets;
       
  3795                         CleanupClosePushL(facets);
       
  3796                         pSD->FacetsL(facets);
       
  3797                             {
       
  3798                             TInt count(facets.Count());
       
  3799                             for (TInt i=0; i<count; i++)
       
  3800                                 {
       
  3801                                 identifier.SetFacetL(*facets[i]);
       
  3802                                 }
       
  3803                             }
       
  3804                         facets.ResetAndDestroy();
       
  3805                         CleanupStack::PopAndDestroy(&facets);
       
  3806                 	    }
       
  3807 
       
  3808                 	CSenCredentialIdentifier& identifier = pCredential->IdentifierL();
       
  3809                 	TPtrC8 username;
       
  3810                 	identifier.PropertyL(KSenIdpAuthzIDLocalname,username);
       
  3811                 	TPtrC8 password;
       
  3812                     identifier.PropertyL(KSenIdpPasswordLocalname,password);
       
  3813                     TPtrC8 usernameIdp = pIdP->UserName();
       
  3814                     TPtrC8 passwordIdp = pIdP->Password();
       
  3815                     if (!username.Length())
       
  3816                         {
       
  3817                         if (usernameIdp.Length())
       
  3818                             {
       
  3819                             identifier.SetPropertyL(KSenIdpAuthzIDLocalname,usernameIdp);
       
  3820                             }
       
  3821                         if (!password.Length() && passwordIdp.Length())
       
  3822                             {
       
  3823                             identifier.SetPropertyL(KSenIdpPasswordLocalname, passwordIdp);
       
  3824                             }
       
  3825                         }
       
  3826                     else
       
  3827                         {
       
  3828                         if (usernameIdp.Length() && username.Compare(usernameIdp) == 0)
       
  3829                             {
       
  3830                             if (!password.Length() && passwordIdp.Length())
       
  3831                                 {
       
  3832                                 identifier.SetPropertyL(KSenIdpPasswordLocalname, passwordIdp);
       
  3833                                 }
       
  3834                             }
       
  3835                         }
       
  3836                 	
       
  3837                     if ( pSenChunk->ChunkHeader().DescriptorCount() == 4 )
       
  3838                         {
       
  3839                         TPtrC8 credentialPropertiesAsXml;
       
  3840                         retVal = pSenChunk->DescFromChunk(credentialPropertiesAsXml, 3);
       
  3841                         if ( retVal == KErrNone )
       
  3842                             {
       
  3843                             CSenCredentialProperties& properties = pCredential->PropertiesL();	//codescannerwarnings
       
  3844                             pParser->ParseL(credentialPropertiesAsXml, properties);
       
  3845                             }
       
  3846                         }
       
  3847                 	CleanupStack::PopAndDestroy(pParser);
       
  3848                 	
       
  3849                 	// Following takes the ownership of pIdp and pCredential
       
  3850                     iManager.AddCredentialL(pIdP, pCredential, retVal);
       
  3851                     
       
  3852                   	RWSDescriptionArray aMatches;
       
  3853                     	iManager.ServiceDescriptionsL(aMatches,*pSD);
       
  3854                	CleanupClosePushL(aMatches);
       
  3855 
       
  3856                     	for(TInt i = 0; i < aMatches.Count(); i++)
       
  3857                     	{
       
  3858                     		((CSenWebServiceSession*)aMatches[i])->AddCredentialObserverL(*pCredential);
       
  3859                     	}
       
  3860 
       
  3861                      CleanupStack::PopAndDestroy(&aMatches);
       
  3862                     
       
  3863                     CleanupStack::Pop(pCredential);
       
  3864                     CleanupStack::Pop(pIdP);
       
  3865                                         
       
  3866                     CleanupStack::PopAndDestroy(pSD);
       
  3867                     }
       
  3868                 }
       
  3869             }
       
  3870         }
       
  3871 
       
  3872     CleanupStack::PopAndDestroy(pSenChunk);
       
  3873         
       
  3874     aMessage.Complete(retVal);
       
  3875     }
       
  3876 
       
  3877 void CSenClientSession::CredentialsL( const RMessage2& aMessage )
       
  3878     {
       
  3879     _LIT8(KNoProperties, "-");
       
  3880     
       
  3881     TInt retVal(KErrNone);
       
  3882     CSenChunk* pSenChunk = NULL;
       
  3883 
       
  3884     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  3885     pSenChunk->SetLogger(Log());
       
  3886     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  3887     
       
  3888     if ( retVal == KErrNone )
       
  3889         {
       
  3890         TPtrC8 patternAsXml;
       
  3891         TPtrC8 idpAsXml;
       
  3892         TPtrC8 credentialAsXml;
       
  3893         retVal = pSenChunk->DescFromChunk(patternAsXml, 0);
       
  3894         if ( retVal == KErrNone )
       
  3895             {
       
  3896             retVal = pSenChunk->DescFromChunk(idpAsXml, 1);
       
  3897             if ( retVal == KErrNone )
       
  3898                 {
       
  3899                 CSenWSDescription* pSD = CSenWSDescription::NewLC();
       
  3900                 pSD->SetReader(*iManager.XMLReader());
       
  3901                 pSD->ParseL(patternAsXml);
       
  3902 
       
  3903                 CSenIdentityProvider* pIdP = NULL;
       
  3904                 if ( idpAsXml != KNullDesC8 )
       
  3905                     {
       
  3906                     pIdP = CSenIdentityProvider::NewLC(KNullDesC8);
       
  3907                     pIdP->SetReader(*iManager.XMLReader());
       
  3908                     pIdP->ParseL(idpAsXml);
       
  3909                     }
       
  3910                 
       
  3911                 RSenCredentialArray credentialsArray;
       
  3912                 CleanupClosePushL(credentialsArray);
       
  3913                 if ( pIdP )
       
  3914                     {
       
  3915                     retVal = iManager.CredentialsL(*pSD, *pIdP, credentialsArray);
       
  3916                     }
       
  3917                 else
       
  3918                     {
       
  3919                     retVal = iManager.CredentialsL(*pSD, credentialsArray);
       
  3920                     }
       
  3921                     
       
  3922                 if ( retVal == KErrNone )
       
  3923                     {
       
  3924                     TInt count = credentialsArray.Count();
       
  3925                     
       
  3926                     // Calculate required heap allocation size:
       
  3927                     TInt size(0);
       
  3928                     if ( count > 0 )
       
  3929                         {
       
  3930                         size += (count-1) * KNewline().Length();
       
  3931                         }
       
  3932                     size += count * KTab().Length();
       
  3933 
       
  3934                     TInt leaveCode(KErrNone);
       
  3935                     TRAP( leaveCode, size += iManager.SizeOfCredentialsL(credentialsArray); )
       
  3936                     if ( leaveCode == KErrNone )
       
  3937                         {
       
  3938                         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Size of Credential(s) + delimiter(s): %d bytes"), size));
       
  3939 
       
  3940                         // Adjust RChunk to accomodate found Credentials using known handle
       
  3941                         TPtr8* pCredentials = NULL;
       
  3942                         retVal = pSenChunk->AllocDescToChunk(size, pCredentials); 
       
  3943 
       
  3944                         if(retVal==KErrNone && pCredentials)
       
  3945                             {
       
  3946                             CBufFlat* pBuf = NULL;
       
  3947                             if(count>0)
       
  3948                                 {
       
  3949                                 pBuf = CBufFlat::NewL(KFlatBufSize);
       
  3950                                 CleanupStack::PushL(pBuf);
       
  3951                                 RBufWriteStream bufWs(*pBuf);
       
  3952                                 CleanupClosePushL(bufWs);
       
  3953                                 credentialsArray[0]->WriteAsXMLToL(bufWs);
       
  3954                                 bufWs.WriteL(KTab);
       
  3955                                 if ( credentialsArray[0]->HasProperties() )
       
  3956                                     {
       
  3957                                     credentialsArray[0]->PropertiesL().WriteAsXMLToL(bufWs);	//codescannerwarnings
       
  3958                                     }
       
  3959                                 else
       
  3960                                     {
       
  3961                                     bufWs.WriteL(KNoProperties);
       
  3962                                     }
       
  3963                                 
       
  3964                                 // Add this Credential as XML into the "big heap buffer":
       
  3965                                 TPtr8 p8 = pBuf->Ptr(0);
       
  3966                                 
       
  3967                                 TInt p8size = p8.Length();
       
  3968                                 
       
  3969                                 pCredentials->Append(p8); 
       
  3970                                 // Destroy the temporary, flat stream buffer
       
  3971                                 CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  3972                                 pBuf = NULL;
       
  3973                                 }
       
  3974                             for(TInt x=1; x<count; x++)
       
  3975                                 {
       
  3976                                 // Add delimiter
       
  3977                                 pCredentials->Append(KNewline); 
       
  3978 
       
  3979                                 pBuf = CBufFlat::NewL(KFlatBufSize);
       
  3980                                 CleanupStack::PushL(pBuf);
       
  3981                                 RBufWriteStream bufWs(*pBuf);
       
  3982                                 CleanupClosePushL(bufWs);
       
  3983                                 credentialsArray[x]->WriteAsXMLToL(bufWs);
       
  3984                                 bufWs.WriteL(KTab);
       
  3985                                 if ( credentialsArray[x]->HasProperties() )
       
  3986                                     {
       
  3987                                     credentialsArray[x]->PropertiesL().WriteAsXMLToL(bufWs);	//codescannerwarnings
       
  3988                                     }
       
  3989                                 else
       
  3990                                     {
       
  3991                                     bufWs.WriteL(KNoProperties);
       
  3992                                     }
       
  3993                                 // Add this Credential as XML into the "big heap buffer":
       
  3994                                 TPtr8 p8 = pBuf->Ptr(0);
       
  3995                                 pCredentials->Append(p8); 
       
  3996                                 CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  3997                                 pBuf = NULL;
       
  3998                                 }
       
  3999                             CSLOG_L(iConnectionID,KMaxLogLevel ,"- Requested Credentials:");
       
  4000                             CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*pCredentials));
       
  4001                             }
       
  4002 #ifdef _SENDEBUG
       
  4003                         else
       
  4004                             {
       
  4005                             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- AllocDescToRMsgL failed: %d"), retVal));
       
  4006                             }
       
  4007 #endif // _SENDEBUG
       
  4008                         }
       
  4009                     }
       
  4010                     
       
  4011                 CleanupStack::PopAndDestroy(&credentialsArray); // Close() is enough
       
  4012                 if ( idpAsXml != KNullDesC8 )
       
  4013                     {
       
  4014                     CleanupStack::PopAndDestroy(pIdP);
       
  4015                     }
       
  4016                 CleanupStack::PopAndDestroy(pSD);
       
  4017                 }
       
  4018             }
       
  4019         }
       
  4020 
       
  4021     CleanupStack::PopAndDestroy(pSenChunk);
       
  4022         
       
  4023     aMessage.Complete(retVal);    
       
  4024     }
       
  4025 
       
  4026 void CSenClientSession::RemoveCredentialsL( const RMessage2& aMessage )
       
  4027     {
       
  4028     TInt retVal(KErrNone);
       
  4029     CSenChunk* pSenChunk = NULL;
       
  4030 
       
  4031     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  4032     pSenChunk->SetLogger(Log());
       
  4033     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  4034     
       
  4035     if ( retVal == KErrNone )
       
  4036         {
       
  4037         TPtrC8 patternAsXml;
       
  4038         TPtrC8 idpAsXml;
       
  4039         TPtrC8 credentialAsXml;
       
  4040         retVal = pSenChunk->DescFromChunk(patternAsXml, 0);
       
  4041         if ( retVal == KErrNone )
       
  4042             {
       
  4043             retVal = pSenChunk->DescFromChunk(idpAsXml, 1);
       
  4044             if ( retVal == KErrNone )
       
  4045                 {
       
  4046                 CSenWSDescription* pSD(NULL);
       
  4047                 if (patternAsXml.Length())
       
  4048                     {
       
  4049                     pSD = CSenWSDescription::NewLC();
       
  4050                     pSD->SetReader(*iManager.XMLReader());
       
  4051                     pSD->ParseL(patternAsXml);
       
  4052                     }
       
  4053                 
       
  4054                 CSenIdentityProvider* pIdP = CSenIdentityProvider::NewLC(KNullDesC8);
       
  4055                 pIdP->SetReader(*iManager.XMLReader());
       
  4056                 pIdP->ParseL(idpAsXml);
       
  4057                 
       
  4058                 if(pIdP->FrameworkId() == KDefaultOviFrameworkID && !IsTrustedClient(aMessage))
       
  4059                     {
       
  4060                     retVal = KErrPermissionDenied;
       
  4061                     }
       
  4062                 else
       
  4063                     {
       
  4064                     if (pSD)
       
  4065                         {
       
  4066                         retVal = iManager.RemoveCredentialsL(*pSD, *pIdP);
       
  4067                         }
       
  4068                     else
       
  4069                         {
       
  4070                         retVal = iManager.RemoveCredentialsL(pIdP->ProviderID());
       
  4071                         }
       
  4072                     }
       
  4073                 
       
  4074                 CleanupStack::PopAndDestroy(pIdP);
       
  4075                 if (pSD)
       
  4076                     {
       
  4077                     CleanupStack::PopAndDestroy(pSD);
       
  4078                     }
       
  4079                 }
       
  4080             }
       
  4081         }
       
  4082 
       
  4083     CleanupStack::PopAndDestroy(pSenChunk);
       
  4084         
       
  4085     aMessage.Complete(retVal);    
       
  4086     }
       
  4087 
       
  4088 void CSenClientSession::ConnectionID(const RMessage2& aMessage)
       
  4089     {
       
  4090     if ( iConnectionID == KErrNotFound )
       
  4091         {
       
  4092         iConnectionID = iManager.NextConnectionID();
       
  4093        // iSecureId = aMessage.SecureId();
       
  4094 
       
  4095         /*
       
  4096         iServerContext.OpenApplicationContextL(iSecureId);
       
  4097         CSenApplicationContext& appCtx = iServerContext.OpenApplicationContextL( aMessage.SecureId() );
       
  4098         appCtx.OpenClientContextL( iConnectionID );
       
  4099         */
       
  4100         }
       
  4101         iSecureId = aMessage.SecureId();
       
  4102         iVendorId = aMessage.VendorId();
       
  4103     aMessage.Complete(iConnectionID);
       
  4104     }
       
  4105     
       
  4106 void CSenClientSession::ConnectionIdentityProviderL(const RMessage2& aMessage)
       
  4107     {
       
  4108     TInt retVal(KErrNone);
       
  4109     CSenChunk* pSenChunk = NULL;
       
  4110 
       
  4111     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  4112     pSenChunk->SetLogger(Log());
       
  4113     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  4114     
       
  4115     if ( retVal == KErrNone )
       
  4116         {
       
  4117         CSenWSDescription* pDesc = CSenWSDescription::NewLC();
       
  4118         CBufFlat* pBuf = CBufFlat::NewL(KFlatBufSize);
       
  4119         CleanupStack::PushL(pBuf);
       
  4120         RBufWriteStream bufWs(*pBuf);
       
  4121         CleanupClosePushL(bufWs); // push
       
  4122         iServiceSession->AsServiceDescription().WriteAsXMLToL(bufWs);
       
  4123         
       
  4124         pDesc->SetReader(*iManager.XMLReader());
       
  4125         TInt leaveCode(KErrNone);
       
  4126         TRAP(leaveCode, pDesc->ParseL(pBuf->Ptr(0)));
       
  4127         if ( leaveCode == KErrNone )
       
  4128             {
       
  4129             CleanupStack::PopAndDestroy(&bufWs);
       
  4130             CleanupStack::PopAndDestroy(pBuf);
       
  4131             MSenElement& xmlSdAsElement = pDesc->AsElement();
       
  4132             MSenElement* pElement = xmlSdAsElement.Element(KProviderIdLocalName);
       
  4133             if ( pElement )
       
  4134                 {
       
  4135                 TPtrC8 providerId = pElement->Content();
       
  4136                 CSenWSDescription* pPattern = CSenWSDescription::NewLC();
       
  4137                 pPattern->SetEndPointL(providerId);
       
  4138                 CSenIdentityProvider* pIdp = ((MSenCoreServiceManager&)iManager).IdentityProviderL(*pPattern);
       
  4139                 CleanupStack::PopAndDestroy(pPattern);
       
  4140                 if ( pIdp )
       
  4141                     {
       
  4142                     HBufC8* pIdpAsXml = pIdp->AsXmlL();
       
  4143                     CleanupStack::PushL(pIdpAsXml);
       
  4144                     retVal = pSenChunk->DescToChunk(*pIdpAsXml);
       
  4145                     CleanupStack::PopAndDestroy(pIdpAsXml);
       
  4146                     }
       
  4147                 else
       
  4148                     {
       
  4149                     retVal = KErrNotFound;
       
  4150                     }
       
  4151                 }
       
  4152             }
       
  4153         else
       
  4154             {
       
  4155             CleanupStack::PopAndDestroy(&bufWs);
       
  4156             CleanupStack::PopAndDestroy(pBuf);
       
  4157             }
       
  4158         CleanupStack::PopAndDestroy(pDesc);
       
  4159         }
       
  4160 
       
  4161     CleanupStack::PopAndDestroy(pSenChunk);
       
  4162     
       
  4163     aMessage.Complete(retVal);
       
  4164     }
       
  4165 /*    
       
  4166 CSenIdentityProvider* CSenClientSession::ConnectionIdentityProviderL()
       
  4167     {
       
  4168     CSenIdentityProvider* pIdp = NULL;
       
  4169     
       
  4170     if ( iServiceSession )
       
  4171         {
       
  4172         CSenWSDescription* pDesc = CSenWSDescription::NewLC();
       
  4173         CBufFlat* pBuf = CBufFlat::NewL(KFlatBufSize);
       
  4174         CleanupStack::PushL(pBuf);
       
  4175         RBufWriteStream bufWs(*pBuf);
       
  4176         CleanupClosePushL(bufWs); // push
       
  4177         iServiceSession->AsServiceDescription().WriteAsXMLToL(bufWs);
       
  4178         
       
  4179         pDesc->SetReader(*iManager.XMLReader());
       
  4180         TInt leaveCode(KErrNone);
       
  4181         TRAP(leaveCode, pDesc->ParseL(pBuf->Ptr(0)));
       
  4182         if ( leaveCode == KErrNone )
       
  4183             {
       
  4184             CleanupStack::PopAndDestroy(&bufWs);
       
  4185             CleanupStack::PopAndDestroy(pBuf);
       
  4186             MSenElement& xmlSdAsElement = pDesc->AsElement();
       
  4187             MSenElement* pElement = xmlSdAsElement.Element(KProviderIdLocalName);
       
  4188             if ( pElement )
       
  4189                 {
       
  4190                 TPtrC8 providerId = pElement->Content();
       
  4191                 CSenWSDescription* pPattern = CSenWSDescription::NewLC();
       
  4192                 pPattern->SetEndPointL(providerId);
       
  4193                 CSenIdentityProvider* pIdp = ((MSenCoreServiceManager&)iManager).IdentityProviderL(*pPattern);
       
  4194                 CleanupStack::PopAndDestroy(pPattern);
       
  4195                 }
       
  4196             }
       
  4197         else
       
  4198             {
       
  4199             CleanupStack::PopAndDestroy(&bufWs);
       
  4200             CleanupStack::PopAndDestroy(pBuf);
       
  4201             }
       
  4202         CleanupStack::PopAndDestroy(pDesc);
       
  4203         }
       
  4204     
       
  4205     return pIdp;
       
  4206     }
       
  4207 */
       
  4208 void CSenClientSession::DataTrafficDetails(const RMessage2& aMessage) 
       
  4209 	{
       
  4210     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::DataTrafficDetails");
       
  4211 	TSenDataTrafficDetails trafficDetails; 
       
  4212 	TBool reset = aMessage.Int1();
       
  4213  	if(reset == 1)
       
  4214 		{
       
  4215 		iDetails.iTotalBytesSent = 0;
       
  4216 		iDetails.iTotalBytesRecieved = 0; 
       
  4217 		}
       
  4218 	trafficDetails = iDetails;
       
  4219 	TPtr8 trafficDetailsDesc(reinterpret_cast<TUint8*>(&trafficDetails),sizeof(trafficDetails),
       
  4220         					 sizeof(trafficDetails));
       
  4221 	TInt retVal(-1);     				
       
  4222 	TRAP(retVal,aMessage.WriteL(0,trafficDetailsDesc));
       
  4223 	CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Bytes send  : '%d')."), trafficDetails.iTotalBytesSent ));
       
  4224 	CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Bytes Received : '%d' ."), trafficDetails.iTotalBytesRecieved ));
       
  4225     aMessage.Complete(retVal);
       
  4226 	}
       
  4227 void CSenClientSession::CancelRequestL(const RMessage2& aMessage)
       
  4228     {
       
  4229     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CancelRequestL");
       
  4230     
       
  4231     TInt transactionIDtoCancel = aMessage.Int0();
       
  4232 
       
  4233     RTransactionIdArray& txnIds = TxnIds();
       
  4234 
       
  4235     TInt pendingCount(txnIds.Count());
       
  4236     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d txnIds(s) pending."), pendingCount));
       
  4237     for(TInt i=pendingCount-1; i>=0; i--)
       
  4238         {
       
  4239         if ( *txnIds[i] == transactionIDtoCancel )
       
  4240             {
       
  4241             TInt* pTxnId = txnIds[i];
       
  4242             TInt cancelledTxnId(*pTxnId);
       
  4243             txnIds.Remove(i);
       
  4244             delete pTxnId;
       
  4245             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Now processing txn with id %d"), cancelledTxnId));
       
  4246 
       
  4247 
       
  4248             // Attempt to cancel the actual activity on the transport layer.
       
  4249             // Note that even if transport will not cancel this transaction,
       
  4250             // the response from the transport (later on) won't anymore be 
       
  4251             // delivered to consumer, since this RMessage2 is removed from 
       
  4252             // iMessageMap few lines below. This means, that from the WS-stack
       
  4253             // client point-of-view, cancel works and no "stray" responses
       
  4254             // will follow (eventhough some data is received from transport 
       
  4255             // stack).
       
  4256             MSenTransport* pTransport = ipTransport;
       
  4257             if(iServiceSession)
       
  4258                 {
       
  4259                 CSLOG_L(iConnectionID,KNormalLogLevel ,"-- has session.");
       
  4260                 MSenTransport* pSessionTransport = iServiceSession->Transport();
       
  4261                 if(pSessionTransport)
       
  4262                     {
       
  4263                     CSLOG_L(iConnectionID,KNormalLogLevel ,"--- session has transport.");
       
  4264                     // If session owns a transport, always utilize that one
       
  4265                     pTransport = pSessionTransport;
       
  4266                     }
       
  4267                 }
       
  4268             // If session does not own a transport, check if this remote consumer does..
       
  4269 
       
  4270             if(pTransport)
       
  4271                 {
       
  4272                 CSLOG_L(iConnectionID,KMinLogLevel ,"---- About to call CancelTransaction");
       
  4273                 TInt retCode = pTransport->CancelTransaction(cancelledTxnId);
       
  4274                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Transport's  CancelTransaction(%d) returned: %d"), cancelledTxnId, retCode));
       
  4275                 retCode = 0; // not used in release builds atm. 
       
  4276                 }
       
  4277                 
       
  4278             break;
       
  4279             }
       
  4280         }
       
  4281         
       
  4282     RTransactionArray& txnMsgs = Transactions();
       
  4283     pendingCount = txnMsgs.Count();
       
  4284     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d RMessage2(s) pending."), pendingCount));
       
  4285     TInt transactionID;
       
  4286     TInt pendingTxnId;
       
  4287     for(TInt t=pendingCount-1; t>=0; t--)
       
  4288         {
       
  4289         if(txnMsgs[t])
       
  4290             {
       
  4291             CSenClientMessage* pClientMessage = Transactions()[t];
       
  4292             pendingTxnId = pClientMessage->ChunkHeader().PendingTransactionId();
       
  4293             transactionID = pClientMessage->ChunkHeader().TransactionId();
       
  4294 
       
  4295             if ( ( pendingTxnId && ( pendingTxnId == transactionIDtoCancel ) ) ||
       
  4296                  ( !pendingTxnId && ( transactionID == transactionIDtoCancel ) ) )
       
  4297                 {
       
  4298                 RMessage2& message = pClientMessage->RMessage();
       
  4299                 
       
  4300                 pendingTxnId = pClientMessage->ChunkHeader().PendingTransactionId();
       
  4301                 if (pendingTxnId)
       
  4302                     {
       
  4303                     transactionID = pendingTxnId;
       
  4304                     pClientMessage->ChunkHeader().SetPendingTransactionId(0);
       
  4305                     pClientMessage->ChunkHeader().SetTransactionId(pendingTxnId);
       
  4306                     }
       
  4307                 else
       
  4308                     {
       
  4309                     transactionID = pClientMessage->ChunkHeader().TransactionId();
       
  4310                     }
       
  4311                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Completing Txn ID: %d"),transactionID)); 
       
  4312                 
       
  4313                 TPtr8 ptr(reinterpret_cast<TUint8*>(&transactionID), 
       
  4314                           sizeof(transactionID), 
       
  4315                           sizeof(transactionID)); 
       
  4316 
       
  4317                 TInt leaveCode(KErrNone);
       
  4318                 TRAP(leaveCode, message.WriteL(1, ptr)); //IPC V2
       
  4319                 if(leaveCode!=KErrNone)
       
  4320                     {
       
  4321                     message.Complete(ESenInternalError);
       
  4322                     CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - TxnId");
       
  4323                     }
       
  4324                 else
       
  4325                     {
       
  4326                     message.Complete(ESenServRequestCancelled);
       
  4327                     CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenServRequestCancelled - TxnId");
       
  4328                     }
       
  4329 
       
  4330                 delete pClientMessage;
       
  4331                 txnMsgs.Remove(t);
       
  4332                 
       
  4333                 break;
       
  4334                 }
       
  4335             }
       
  4336         }
       
  4337         
       
  4338     aMessage.Complete(KErrNone);
       
  4339     }
       
  4340 
       
  4341 void CSenClientSession::PanicClient( const RMessagePtr2& aMessage, TInt aPanic ) const
       
  4342     {
       
  4343     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::PanicClient( %d )"), aPanic));
       
  4344     // Note: this panics the client thread, not server
       
  4345     aMessage.Panic(KSenServiceManagerPanic, aPanic) ; //IPC V2 
       
  4346     }
       
  4347 
       
  4348 RFileLogger* CSenClientSession::Log() const
       
  4349     {
       
  4350     return iManager.Log();
       
  4351     }
       
  4352 
       
  4353 TInt CSenClientSession::SetSessionL(MSenRemoteServiceSession& aServiceSession)
       
  4354     {
       
  4355     iServiceSession = &aServiceSession; // not owned
       
  4356     SetStatusL(iServiceSession->StatusL());
       
  4357     return KErrNone;
       
  4358     }
       
  4359 
       
  4360 
       
  4361 TInt CSenClientSession::HandleMessageL( HBufC8* apMessage,
       
  4362                                         const TInt aTxnId,
       
  4363                                         MSenProperties* aResponseTransportProperties )
       
  4364     {
       
  4365     iReauthResendNeeded = EFalse ; //resetting the flag if already true
       
  4366     if ( !apMessage )
       
  4367         {
       
  4368         apMessage = KNullDesC8().AllocL();
       
  4369         }
       
  4370     CleanupStack::PushL(apMessage);        
       
  4371     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::HandleMessageL");
       
  4372     
       
  4373     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Txn ID: %d, message length: %d bytes"),  aTxnId, apMessage->Length() ));
       
  4374     CSLOG_ALL(iConnectionID, KMaxLogLevel ,( *apMessage ));
       
  4375 
       
  4376     if( iAllowShowDialogCount>0 )
       
  4377         {
       
  4378         iAllowShowDialogCount--;
       
  4379         }
       
  4380 
       
  4381     if( iAllowShowDialogCount==0 )
       
  4382         {
       
  4383         iManager.SetShowPasswordDialog(EFalse); // turn the flag down
       
  4384         }
       
  4385 
       
  4386     TInt retCode(KErrNone);
       
  4387     TInt index = TransactionIndex(aTxnId);
       
  4388     if(index != KErrNotFound)
       
  4389         {
       
  4390         RTransactionArray& transactions = Transactions();   
       
  4391         CSenClientMessage* pClientMessage = transactions[index];
       
  4392         RMessage2& message = pClientMessage->RMessage();
       
  4393         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::HandleMessageL - RMessage2(%d)"),  message.Handle() ));
       
  4394 
       
  4395         // Remove the txnId from the list of pending ones:
       
  4396         TInt transactionIdCount(TxnIds().Count());
       
  4397         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Number of pending TxnIds: %d"), transactionIdCount));
       
  4398         
       
  4399         for(TInt tx=0; tx<transactionIdCount; tx++)
       
  4400             {
       
  4401             TInt* pTxnId = TxnIds()[tx];
       
  4402             if(*pTxnId == aTxnId)
       
  4403                 {
       
  4404                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Pending txnID(%d) found from index %d. Removing & deleting it."), *pTxnId,tx ));
       
  4405                 TxnIds().Remove(tx);
       
  4406                 delete pTxnId;
       
  4407                 break;
       
  4408                 }
       
  4409             }
       
  4410 
       
  4411         TInt transactionID(aTxnId);
       
  4412         TInt pendingTxnId = pClientMessage->ChunkHeader().PendingTransactionId();
       
  4413         if(pendingTxnId)
       
  4414             {
       
  4415             transactionID = pendingTxnId;
       
  4416             pClientMessage->ChunkHeader().SetPendingTransactionId(0);
       
  4417             pClientMessage->ChunkHeader().SetTransactionId(pendingTxnId);
       
  4418             }
       
  4419         
       
  4420         TPtr8 ptr(reinterpret_cast<TUint8*>(&transactionID), 
       
  4421                   sizeof(transactionID), 
       
  4422                   sizeof(transactionID)); 
       
  4423 
       
  4424         TInt leaveCode(KErrNone);
       
  4425         TRAP(leaveCode, message.WriteL(1, ptr)); //IPC V2
       
  4426         if(leaveCode!=KErrNone)
       
  4427             {
       
  4428             message.Complete(ESenInternalError);
       
  4429             CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - TxnId");
       
  4430             retCode = leaveCode;
       
  4431             }
       
  4432         else
       
  4433             {
       
  4434             // OK!
       
  4435             if( pClientMessage->ChunkHeader().MessageDirection() == MSenMessage::EOutbound )
       
  4436                 {
       
  4437                 // SetResponseL and SetRequestL to CSenChunk (or it's subclass)
       
  4438                 // Methods should always check that TP is set to correct when MSG
       
  4439                 // direction changes; for e.g. when copying response, the TP type
       
  4440                 // MUST be set to ENotInUse, or SC will fail(!). Furthermore, the
       
  4441                 // SetResponseL method could ignore message data (and not copy it),
       
  4442                 // if direction is already inbound, etc. And, methods should check
       
  4443                 // the PTR so that copy-to-self is ignored/skipped/avoided. Finally,
       
  4444                 // the methods SHOULD support DOUBLE ENDED chunks, so that descs 
       
  4445                 // could be nicely re-allocated separately (MSG first, TP by some
       
  4446                 // other component etc...)
       
  4447                 pClientMessage->ChunkHeader().SetMessageDirection( MSenMessage::EInbound ); 
       
  4448                 HBufC8* pSerializedProperties = NULL;
       
  4449                 if( aResponseTransportProperties )
       
  4450                     {
       
  4451                     pClientMessage->ChunkHeader().SetPropertiesType(aResponseTransportProperties->PropertiesClassType());
       
  4452                     pSerializedProperties = aResponseTransportProperties->AsUtf8LC();
       
  4453                     retCode = pClientMessage->DescsToChunk(*apMessage, *pSerializedProperties);
       
  4454                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- DescsToChunk return code: %d"), retCode));
       
  4455                     CleanupStack::PopAndDestroy(pSerializedProperties);
       
  4456                     }
       
  4457                 else
       
  4458                     {
       
  4459                     pClientMessage->ChunkHeader().SetPropertiesType(MSenProperties::ENotInUse);
       
  4460                     retCode = pClientMessage->DescToChunk(*apMessage);
       
  4461                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- DescToChunk return code: %d"), retCode));
       
  4462                     }
       
  4463                 }
       
  4464             else
       
  4465                 {
       
  4466                 CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Reply message (%d) direction is already MSenMessage::EInbound, and data is already copied to chunk."), aTxnId));
       
  4467                 apMessage = NULL; 
       
  4468                 }
       
  4469 
       
  4470             if ( retCode == KErrNone && leaveCode != KErrNone )
       
  4471                 {
       
  4472                 retCode = leaveCode;
       
  4473                 }
       
  4474             if( retCode != KErrNone)
       
  4475                 {
       
  4476                 message.Complete(ESenInternalError);
       
  4477                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - HandleBase");
       
  4478                 retCode = leaveCode;
       
  4479                 }
       
  4480             else // OK!
       
  4481                 {   
       
  4482                 message.Complete(ESenServRequestResponsed);
       
  4483                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenServRequestResponsed");
       
  4484                 }
       
  4485             }
       
  4486         transactions.Remove(index);
       
  4487         delete pClientMessage;
       
  4488         }
       
  4489     else // pending RMessage2 was not found
       
  4490         {   
       
  4491         CSLOG_L(iConnectionID,KMinLogLevel ,"- No pending RMessage2 found - cancelled?");
       
  4492         retCode = KErrNotFound; 
       
  4493         }
       
  4494     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::HandleMessageL returns: %d"), retCode));
       
  4495 
       
  4496     if( apMessage )
       
  4497         {
       
  4498         CleanupStack::PopAndDestroy(apMessage);        
       
  4499         }
       
  4500     else
       
  4501         {
       
  4502         CleanupStack::Pop(); // apMessage
       
  4503         }
       
  4504 
       
  4505     return retCode;
       
  4506     }
       
  4507 
       
  4508 TInt CSenClientSession::HandleErrorL( HBufC8* apError,
       
  4509                                       const TInt aErrorCode,
       
  4510                                       const TInt aTxnId,
       
  4511                                       MSenProperties* aResponseTransportProperties )
       
  4512     {
       
  4513     if ( !apError )
       
  4514         {
       
  4515         apError = KNullDesC8().AllocL();
       
  4516         }
       
  4517     CleanupStack::PushL(apError);        
       
  4518     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::HandleErrorL");
       
  4519     
       
  4520     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Txn ID: %d, error (%d) length: %d bytes"),  aTxnId, aErrorCode, apError->Length() ));
       
  4521 
       
  4522     if(iAllowShowDialogCount>0)
       
  4523         {
       
  4524         iAllowShowDialogCount--;
       
  4525         }
       
  4526 
       
  4527     if(iAllowShowDialogCount==0)
       
  4528         {
       
  4529         iManager.SetShowPasswordDialog(EFalse); // turn the flag down
       
  4530         }
       
  4531 
       
  4532     TInt retCode(KErrNone);
       
  4533     TInt index = TransactionIndex(aTxnId);
       
  4534     if(index != KErrNotFound)
       
  4535         {
       
  4536         RTransactionArray& transactions = Transactions();   
       
  4537         CSenClientMessage* pClientMessage = transactions[index];
       
  4538         RMessage2& message = pClientMessage->RMessage();
       
  4539         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::HandleErrorL - RMessage2(%d)"),  message.Handle() ));
       
  4540 
       
  4541         // Remove the txnId from the list of pending ones:
       
  4542         TInt transactionIdCount(TxnIds().Count());
       
  4543         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Number of pending TxnIds: %d"), transactionIdCount));
       
  4544         for(TInt tx=0; tx<transactionIdCount; tx++)
       
  4545             {
       
  4546             TInt* pTxnId = TxnIds()[tx];
       
  4547             if(*pTxnId == aTxnId)
       
  4548                 {
       
  4549                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Pending txnID(%d) found from index %d. Removing & deleting it."), *pTxnId, tx));
       
  4550                 TxnIds().Remove(tx);
       
  4551                 delete pTxnId;
       
  4552                 break;
       
  4553                 }
       
  4554             }
       
  4555 
       
  4556         TInt errorCode(aErrorCode);
       
  4557         TPtr8 ptrErr(reinterpret_cast<TUint8*>(&errorCode), 
       
  4558                      sizeof(errorCode), 
       
  4559                      sizeof(errorCode)); 
       
  4560 
       
  4561         TInt leaveCode(KErrNone);
       
  4562         TRAP(leaveCode, message.WriteL(0, ptrErr)); //IPC V2
       
  4563         if(leaveCode!=KErrNone)
       
  4564             {
       
  4565             message.Complete(ESenInternalError);
       
  4566             CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError");
       
  4567             retCode = leaveCode;
       
  4568             }
       
  4569         else // no internal error in writing error code
       
  4570             {
       
  4571             // Write back the transaction ID, so that client knows which
       
  4572             // request was responded (use slot 1, slot 0 is reserved for 
       
  4573             // errorcodes of handle error atm..)
       
  4574             TInt transactionID(aTxnId);
       
  4575             TInt pendingTxnId = pClientMessage->ChunkHeader().PendingTransactionId();
       
  4576             if (pendingTxnId)
       
  4577                 {
       
  4578                 transactionID = pendingTxnId;
       
  4579                 pClientMessage->ChunkHeader().SetPendingTransactionId(0);
       
  4580                 pClientMessage->ChunkHeader().SetTransactionId(pendingTxnId);
       
  4581                 }
       
  4582                 
       
  4583             TPtr8 ptr(reinterpret_cast<TUint8*>(&transactionID), 
       
  4584                       sizeof(transactionID), 
       
  4585                       sizeof(transactionID)); 
       
  4586 
       
  4587             TRAP(leaveCode, message.WriteL(1, ptr)); //IPC V2
       
  4588             if(leaveCode!=KErrNone)
       
  4589                 {
       
  4590                 message.Complete(ESenInternalError);
       
  4591                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError");
       
  4592                 retCode = leaveCode;
       
  4593                 }
       
  4594             else // no internal error in writing error message
       
  4595                 {
       
  4596                 switch(aErrorCode)
       
  4597                     {
       
  4598                     case KErrSenReinitRequired: // ESenReAuthAndResendNeeded
       
  4599                         {
       
  4600                         pClientMessage->ChunkHeader().SetMessageDirection( MSenMessage::EOutbound );
       
  4601                         iReauthResendNeeded = ETrue ;
       
  4602                         message.Complete(ESenReAuthAndResendNeeded);
       
  4603                         CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenReAuthAndResendNeeded");
       
  4604                         }
       
  4605                     break;
       
  4606                     case KErrSenResendRequired: // ESenResendNeeded
       
  4607                         {
       
  4608                         pClientMessage->ChunkHeader().SetMessageDirection( MSenMessage::EOutbound );
       
  4609                         iReauthResendNeeded = EFalse ;
       
  4610                         message.Complete(ESenResendNeeded);
       
  4611                         CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenResendNeeded");
       
  4612                         }
       
  4613                     break;
       
  4614                     default: // almost always: ESenServRequestResponsed 
       
  4615                         {
       
  4616                         iReauthResendNeeded = EFalse ;
       
  4617                         // Some other error, which can freely be propagated back to service consumer
       
  4618                         
       
  4619                         if( pClientMessage->ChunkHeader().MessageDirection() == MSenMessage::EOutbound )
       
  4620                             {
       
  4621                             // SetResponseL and SetRequestL to CSenChunk (or it's subclass)
       
  4622                             // Methods should always check that TP is set to correct when MSG
       
  4623                             // direction changes; for e.g. when copying response, the TP type
       
  4624                             // MUST be set to ENotInUse, or SC will fail(!). Furthermore, the
       
  4625                             // SetResponseL method could ignore message data (and not copy it),
       
  4626                             // if direction is already inbound, etc. And, methods should check
       
  4627                             // the PTR so that copy-to-self is ignored/skipped/avoided. Finally,
       
  4628                             // the methods SHOULD support DOUBLE ENDED chunks, so that descs 
       
  4629                             // could be nicely re-allocated separately (MSG first, TP by some
       
  4630                             // other component etc...)
       
  4631                             pClientMessage->ChunkHeader().SetMessageDirection( MSenMessage::EInbound ); 
       
  4632                             HBufC8* pSerializedProperties = NULL;
       
  4633                             if( aResponseTransportProperties )
       
  4634                                 {
       
  4635                                 pClientMessage->ChunkHeader().SetPropertiesType(aResponseTransportProperties->PropertiesClassType());
       
  4636                                 pSerializedProperties = aResponseTransportProperties->AsUtf8LC();
       
  4637                                 retCode = pClientMessage->DescsToChunk(*apError, *pSerializedProperties);
       
  4638                                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- DescsToChunk returned: %d"), retCode));
       
  4639                                 CleanupStack::PopAndDestroy(pSerializedProperties);
       
  4640                                 }
       
  4641                             else
       
  4642                                 {
       
  4643                                 pClientMessage->ChunkHeader().SetPropertiesType(MSenProperties::ENotInUse);
       
  4644                                 retCode = pClientMessage->DescToChunk(*apError);
       
  4645                                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- DescToChunk returned: %d"), retCode));
       
  4646                                 }
       
  4647                             }
       
  4648                         else
       
  4649                             {
       
  4650                             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Error message (%d) direction is already MSenMessage::EInbound, and data is already copied to chunk."), aTxnId));
       
  4651                             apError = NULL; // will NOT leak, since the pointer was pointing to global chunk!
       
  4652                             }
       
  4653                             
       
  4654                         if ( retCode == KErrNone && leaveCode != KErrNone )
       
  4655                             {
       
  4656                             retCode = leaveCode;
       
  4657                             }
       
  4658     
       
  4659                         if( retCode!=KErrNone )
       
  4660                             {
       
  4661                             message.Complete(ESenInternalError);
       
  4662                             CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - HandleBase");
       
  4663                             retCode = leaveCode;
       
  4664                             }
       
  4665                         else // OK!
       
  4666                             {   
       
  4667                             message.Complete(ESenServRequestResponsed);
       
  4668                             CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenServRequestResponsed");
       
  4669                             }
       
  4670                         }
       
  4671                     } // switch
       
  4672                 } // no internal error in writing error message
       
  4673             } // no internal error in writing error code
       
  4674             
       
  4675         transactions.Remove(index);
       
  4676         delete pClientMessage;
       
  4677         }
       
  4678     else // pending RMessage2 was not found
       
  4679         {   
       
  4680         CSLOG_L(iConnectionID,KMinLogLevel ,"- No pending RMessage2 found - cancelled?");
       
  4681         retCode = KErrNotFound; 
       
  4682         }
       
  4683     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("CSenClientSession::HandleErrorL returns: %d"), retCode));
       
  4684 
       
  4685     
       
  4686     if( apError )
       
  4687         {
       
  4688         CleanupStack::PopAndDestroy(apError);    
       
  4689         }
       
  4690     else
       
  4691         {
       
  4692         CleanupStack::Pop(); // apError
       
  4693         }
       
  4694     
       
  4695     return retCode;
       
  4696     }
       
  4697 
       
  4698 void CSenClientSession::SetStatusL(const TInt aStatus)
       
  4699     {
       
  4700     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::SetStatusL(%d)"), aStatus));
       
  4701     iStatus = aStatus;
       
  4702 
       
  4703     // Currently: publish ONLY "credentials expired" status.
       
  4704     // One MUST NOT publish "credentials ready" status,
       
  4705     // since publish&subscibe has higher priority
       
  4706     // than "Initialize" IPC op that is fied by SC constructor
       
  4707     // and this causes pre-mature SendL (internal boolean of SC
       
  4708     // impl about "readyness" is still false (=> this could be
       
  4709     // fixed, but it is better to wait for Async IPC "Initialize"
       
  4710     // to complete.
       
  4711     if( aStatus != KSenConnectionStatusReady )
       
  4712         {
       
  4713         // It is ok to "push" (==publish) "credentials expired" status
       
  4714         RProperty::Set(iClientSecureID,(KSenRPropertyKeyBaseNumber+iConnectionID), aStatus);
       
  4715         }
       
  4716     }
       
  4717 
       
  4718 void CSenClientSession::FileProgress( TInt aTxnId, TBool aIsIncoming, TBool aIsSoap, const TDesC8& aSoapOrCid, TInt aProgress ) 
       
  4719     {
       
  4720     CSenClientMessage* pTransaction = NULL;
       
  4721     
       
  4722     TInt index = TransactionIndex(aTxnId);
       
  4723     if( index > KErrNotFound )
       
  4724         {
       
  4725         RTransactionArray& transactions = Transactions();
       
  4726         if( index < transactions.Count() )
       
  4727             {
       
  4728             pTransaction = transactions[index];
       
  4729             }
       
  4730         }
       
  4731     
       
  4732     if( pTransaction ) ////// NOT needed  ( note about this code & TransferProgressForHostlet(): -> hostlet connection's client sessions does not have transaction in here..
       
  4733         {
       
  4734         if( !aIsIncoming && pTransaction->ChunkHeader().MessageDirection() != MSenMessage::EOutbound )
       
  4735             {
       
  4736             // the transaction has ALREADY been completed, so there is no need to inform about "file progress"
       
  4737             return;
       
  4738             }
       
  4739         } // end of 'if( pTransaction )'
       
  4740 #ifdef _SENDEBUG        
       
  4741         else
       
  4742             {
       
  4743         	CSLOG_FORMAT(( iConnectionID, KMinLogLevel, _L8("CSenClientSession::FileProgress() - ChunkByTxnIdL(%d) returned NULL"), aTxnId ));
       
  4744             }
       
  4745 #endif // _SENDEBUG
       
  4746 
       
  4747     TRAP_IGNORE ( DeliverProgressToClient( aTxnId, aIsIncoming, aIsSoap, aSoapOrCid, aProgress ); ) // should NOT leave!
       
  4748     }
       
  4749 void CSenClientSession::DeliverProgressToClient( TInt aTxnId, TBool aIsIncoming, TBool aIsSoap, const TDesC8& aSoapOrCid, TInt aProgress ) 
       
  4750     {
       
  4751     // NOTE: for OUTGOING messages with BLOBs (file attachements etc), aIncoming is EFalse, and aSoapOrCid is ALWAYS A CID(!)
       
  4752 	CSLOG_L( iConnectionID,KMinLogLevel,"" );
       
  4753 	CSLOG_FORMAT(( iConnectionID, KMinLogLevel, _L8("CSenClientSession::DeliverProgressToClient(txn: %d, progress: %d, incoming: %d, soap: %d) - begin"), aTxnId, aProgress, aIsIncoming, aIsSoap ));
       
  4754 	CSLOG_L( iConnectionID,KMinLogLevel, "- SOAP/CID:" );
       
  4755     CSLOG_ALL( iConnectionID, KMinLogLevel, (aSoapOrCid ));    
       
  4756 	
       
  4757 #ifndef RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS
       
  4758 
       
  4759     // THE "LEGACY CODE": START =>
       
  4760 	CSLOG_L( iConnectionID, KMinLogLevel,"CSenClientSession::DeliverProgressToClient() - RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == FALSE" );
       
  4761     if (iConnectionSession.Handle())
       
  4762         {
       
  4763         iConnectionSession.SendFileProgress( aTxnId, aIsIncoming, aIsSoap, aSoapOrCid, aProgress );
       
  4764         }
       
  4765         return;
       
  4766     // <= THE "LEGACY CODE": END
       
  4767     
       
  4768 #else // == RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == TRUE 
       
  4769 
       
  4770 	CSLOG_L( iConnectionID, KMinLogLevel, "CSenClientSession::DeliverProgressToClient() - RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == TRUE" );
       
  4771 	
       
  4772 	// CHECK IF CODE WAS COMPILED WITH "MIXED" MODE (conn agent for SOAP progress, pub&sub for outgoing BLOB progress):
       
  4773 	 
       
  4774   #ifdef RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS
       
  4775     // Use connection agent for any SOAP progress signalizing:
       
  4776 	CSLOG_L( iConnectionID, KMinLogLevel, "CSenClientSession::DeliverProgressToClient() - RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS == TRUE" );
       
  4777 	if( aIsSoap )
       
  4778 	    {
       
  4779     	CSLOG_L( iConnectionID, KMinLogLevel,"- aIsSoap == TRUE => try to use connection agent for SOAP progress.." );
       
  4780         if ( iConnectionSession.Handle() )
       
  4781             {
       
  4782         	CSLOG_L( iConnectionID, KMinLogLevel,"- iConnectionSession.Handle() is valid [OK]" );
       
  4783             iConnectionSession.SendFileProgress( aTxnId, aIsIncoming, aIsSoap, aSoapOrCid, aProgress );
       
  4784             return;
       
  4785             }
       
  4786   #ifdef _SENDEBUG            
       
  4787         else
       
  4788             {
       
  4789         	CSLOG_L( iConnectionID, KMinLogLevel,"DeliverProgressToClient(): - iConnectionSession.Handle() is _invalid_ [NOT OK]: cannot deliver SOAP progress" );
       
  4790             }
       
  4791   #endif // _SENDEBUG            
       
  4792 	    } // end of: if ( aIsSoap )
       
  4793 
       
  4794   #ifdef _SENDEBUG            
       
  4795     else
       
  4796         {
       
  4797         // the progress is not about SOAP
       
  4798     	CSLOG_L( iConnectionID, KMinLogLevel,"DeliverProgressToClient(): - aIsSoap == FALSE => Use pub&sub for BLOB related progress signalizing." );
       
  4799         }
       
  4800   #endif // _SENDEBUG            
       
  4801         
       
  4802   #endif // RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS END
       
  4803 	
       
  4804     // publish the new value from Serene Core server to the client (SC impl) 
       
  4805     
       
  4806     TInt cid(0);
       
  4807     TInt cid2( KErrNotFound );
       
  4808     
       
  4809     TBool hasCidPostfix( EFalse );
       
  4810     TInt lexingError(KErrNone);
       
  4811     if ( !aIsSoap ) // NOTE: WHEN RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS == TRUE, aIsSoap is ALWAYS FALSE when execution gets to this point(!)
       
  4812         {
       
  4813         // Current implementation "trusts" that CID is a numeric value!
       
  4814         TPtrC8 numericCid( aSoapOrCid );
       
  4815         
       
  4816         // Look for "@example.org" and rip if off, if found
       
  4817         TInt length = aSoapOrCid.Length();
       
  4818         if( length )
       
  4819             {
       
  4820             TInt index = aSoapOrCid.Find( KSenCidPostfix );
       
  4821             if( index != KErrNotFound )
       
  4822                 {
       
  4823                 hasCidPostfix = ETrue;
       
  4824                 numericCid.Set( aSoapOrCid.Left( index ) ); // take all the data prior the @ -char..
       
  4825                 CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("CSenClientSession::DeliverProgressToClient() - numeric cid: '%S', hasCidPostfix = ETrue"), &numericCid ));
       
  4826                 }
       
  4827                 
       
  4828             }
       
  4829         TPtrC8 numericCid2(KNullDesC8);
       
  4830         if ( numericCid.Length() > KSenMaxCidLength )
       
  4831             {
       
  4832             numericCid2.Set(numericCid.Right(KSenMaxCidLength));
       
  4833             numericCid.Set(numericCid.Left(KSenMaxCidLength-1));
       
  4834             }
       
  4835         TLex8 lex( numericCid );
       
  4836         lexingError = lex.Val( cid );
       
  4837         if( !lexingError && numericCid2.Length() )
       
  4838             {
       
  4839             TLex8 lex2( numericCid2 );
       
  4840             lexingError = lex2.Val( cid2 );
       
  4841             }
       
  4842             
       
  4843         if( !lexingError )
       
  4844             {
       
  4845             CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8(" - cid: '%S', cid2: '%S'"), &numericCid, &numericCid2 ));
       
  4846             TFileOutgoingTransferProgress progress( aTxnId, aIsIncoming, aProgress, hasCidPostfix, cid, cid2 ); // note(!): ELeave is NOT used here, instead KErrNoMemory is returned if this method fails!
       
  4847             TPckgBuf<TFileOutgoingTransferProgressBase> buffer( progress );
       
  4848             RProperty::Set( KSenInterfaceUidFilesObserver, iConnectionID, buffer ); // this is serializing the property, so it is ok to let the T-classes to go out of scope
       
  4849             }
       
  4850         else
       
  4851             {
       
  4852             CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("CSenClientSession::DeliverProgressToClient() - TLex:Val('cid') returned error: %d, cid: '%S', cid2: '%S'"), lexingError, &numericCid, &numericCid2 ));
       
  4853 #ifdef RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS
       
  4854         	CSLOG_L( iConnectionID, KMinLogLevel, "=> Going to UTILIZE Connection Agent for non-numeric CIDs!" );
       
  4855             if (iConnectionSession.Handle())
       
  4856                 {
       
  4857                 iConnectionSession.SendFileProgress( aTxnId, aIsIncoming, aIsSoap, aSoapOrCid, aProgress );
       
  4858                 }
       
  4859     
       
  4860 #endif // RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS
       
  4861             }
       
  4862         } // end of if ( !aIsSoap )
       
  4863 #ifdef _SENDEBUG        
       
  4864     else
       
  4865         {
       
  4866         // this callback is carrying a SOAP (should not, that happens only with "incoming" file progress callbacks, actually, not when sending a msg OUT
       
  4867         CSLOG_L( iConnectionID, KMinLogLevel, "CSenClientSession::DeliverProgressToClient() - SOAP of this 'progress' discarded (no ConnAgent session available)" );
       
  4868         }
       
  4869 #endif // _SENDEBUG
       
  4870 
       
  4871 
       
  4872 #endif // RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS  
       
  4873 
       
  4874     // The end of the method
       
  4875 	//CSLOG_L( iConnectionID,KMinLogLevel,"CSenClientSession::DeliverProgressToClient() - end" );
       
  4876     }
       
  4877 
       
  4878 TBool CSenClientSession::OnGetBrandIdL(  const TDesC8& aBrandIdListAsXmlSnippet, RBuf8& aSelectedBrandId)
       
  4879     {
       
  4880     if ( iConnectionSession.Handle() )
       
  4881         {
       
  4882         return iConnectionSession.OnGetBrandIdL( aBrandIdListAsXmlSnippet, aSelectedBrandId );
       
  4883         }
       
  4884     else
       
  4885         {
       
  4886         return EFalse;
       
  4887         }
       
  4888 		}       
       
  4889    
       
  4890 void CSenClientSession::TransferProgressForHostlet( TInt aTxnId, TBool aIsIncoming, TBool aIsSoap, const TDesC8& aSoapOrCid, TInt aProgress)
       
  4891     {
       
  4892 #ifndef RD_SEN_DISABLE_TRANSFER_PROGRESS_FOR_HC    
       
  4893     TRAP_IGNORE ( DeliverProgressToClient( aTxnId, aIsIncoming, aIsSoap, aSoapOrCid, aProgress ); ) // should NOT leave!
       
  4894 #else // RD_SEN_DISABLE_TRANSFER_PROGRESS_FOR_HC == TRUE
       
  4895     CSLOG_L( iConnectionID, KMinLogLevel, "CSenClientSession::TransferProgressForHostlet: RD_SEN_DISABLE_TRANSFER_PROGRESS_FOR_HC == ETrue" );
       
  4896 #endif // end of RD_SEN_DISABLE_TRANSFER_PROGRESS_FOR_HC    
       
  4897     }
       
  4898     
       
  4899 void CSenClientSession::SetDataTrafficDetails( TSenDataTrafficDetails& aDetails ) 	
       
  4900 	{
       
  4901 	CSLOG_L( iConnectionID, KSenCoreServiceManagerLogLevel, "CSenClientSession::SetDataTrafficDetails");
       
  4902 	iDetails += aDetails;
       
  4903 	}
       
  4904 
       
  4905 /**
       
  4906 * SessionValidity method checks the validity of this session
       
  4907 * @return KErrNone if session is ready and its credentials (if any) are valid
       
  4908 *         KErrSenNotInitialized if session is not yet set (iServiceSession is NULL)
       
  4909 *         KErrConnectionInitializing if session's state  is new 
       
  4910 *                                    (iStatus is KSenConnectionStatusNew)
       
  4911 *         KSenConnectionStatusExpired if session's state is initializing 
       
  4912 *                                    (iStatus is KSenConnectionStatusNew)
       
  4913 *         KSenConnectionStatusExpired if session's state is expired 
       
  4914 *                                    (iStatus is KSenConnectionStatusExpired)
       
  4915 */
       
  4916 TInt CSenClientSession::SessionValidity()
       
  4917     {
       
  4918     TInt errorCode(KErrNone);
       
  4919 
       
  4920     if( !iServiceSession )
       
  4921         {
       
  4922         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SessionValidity:");
       
  4923         CSLOG_L(iConnectionID,KMinLogLevel ," - KErrSenNotInitialized");
       
  4924         errorCode = KErrSenNotInitialized;
       
  4925         }
       
  4926     else if (iStatus == KSenConnectionStatusNew )
       
  4927         {
       
  4928         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SessionValidity:");
       
  4929         CSLOG_L(iConnectionID,KMinLogLevel ," - KErrConnectionInitializing");
       
  4930         errorCode = KErrConnectionInitializing;
       
  4931         }
       
  4932     else if(iStatus == KSenConnectionStatusExpired)
       
  4933         {
       
  4934         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SessionValidity:");
       
  4935         CSLOG_L(iConnectionID,KMinLogLevel ," - KErrConnectionExpired");
       
  4936         errorCode = KErrConnectionExpired;
       
  4937         }
       
  4938     else 
       
  4939         {
       
  4940         TBool sessionReady(EFalse);
       
  4941         TInt leaveCode(KErrNone);
       
  4942         TRAP( leaveCode, sessionReady = iServiceSession->IsReadyL(); )
       
  4943 
       
  4944         if(leaveCode!=KErrNone)
       
  4945             {
       
  4946             CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SessionValidity - FATAL:");
       
  4947             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8(" - IsReadyL() leaved: %d"), leaveCode));
       
  4948             // Specific error *could* be defined and passed to actual WSC, 
       
  4949             // but what it could possibly do with this info(?). Therefore,
       
  4950             // currently this method will just signal that "session has
       
  4951             // expired" by completing with KErrConnectionExpired.
       
  4952             
       
  4953             // Invalidate the session, since validity could not be determined
       
  4954             sessionReady = EFalse;
       
  4955             }
       
  4956 
       
  4957         if(!sessionReady)
       
  4958             {
       
  4959             // This session is not ready - its credentials are now invalid:
       
  4960             CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::SessionValidity session is not ready");
       
  4961             CSLOG_L(iConnectionID,KMinLogLevel ," - KErrConnectionExpired");
       
  4962             errorCode = KErrConnectionExpired;
       
  4963             }
       
  4964         }
       
  4965     return errorCode; // KErrNone if session (iServiceSession) is valid 
       
  4966     }
       
  4967 
       
  4968 // If this function returns EFalse, the caller should return
       
  4969 // because message has already been completed
       
  4970 TBool CSenClientSession::CheckValidity(const RMessage2& aMessage)
       
  4971     {
       
  4972     TInt errorCode(SessionValidity());
       
  4973     if(errorCode!=KErrNone)
       
  4974         {
       
  4975         // Signal the client by competing this RMessage2:
       
  4976         aMessage.Complete(errorCode);
       
  4977         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CheckValidity returns EFalse");
       
  4978         // Caller should return, since message was already completed
       
  4979         return EFalse;  
       
  4980         }
       
  4981     else
       
  4982         {
       
  4983         // Session is ready and credentials (if any) are valid.
       
  4984 		CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CheckValidity returns ETrue");        
       
  4985         return ETrue;
       
  4986         }
       
  4987     }
       
  4988 
       
  4989 
       
  4990 MSenTransport& CSenClientSession::TransportL()
       
  4991     {
       
  4992     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::TransportL()");
       
  4993 
       
  4994     // Check if session exists:
       
  4995     if(iServiceSession)
       
  4996         {
       
  4997         // Check if consumed session already owns a transport:
       
  4998         MSenTransport* pSessionTransport = iServiceSession->Transport();
       
  4999         if(pSessionTransport)
       
  5000             {
       
  5001             // Return the transport that is owned by the consumed session!
       
  5002             return *pSessionTransport;
       
  5003             }
       
  5004         }
       
  5005     // else, if NO session: utilize the transport owned by this consumer
       
  5006     //       OR: create new transport for the session
       
  5007 
       
  5008 
       
  5009 
       
  5010     // Core is capable of working as transport factory, too.
       
  5011     // The returned transport instancies may or may not be
       
  5012     // ECOM plugins:
       
  5013     MSenTransportFactory& transportFactory = iManager;
       
  5014     CSenTransportBase* pTransport = NULL;
       
  5015     
       
  5016     // Check if service session has been initilized
       
  5017     if(iServiceSession) // && iServiceSession.Transport() == NULL
       
  5018         {
       
  5019         // Session does not yet own any transport
       
  5020         // Check if this consumer owns some transport:
       
  5021         if(ipTransport)
       
  5022             {
       
  5023             // Transfer the ownership of current transport to the session
       
  5024             // (internal service consumers have initiated this transport)
       
  5025             CSLOG_L(iConnectionID,KMinLogLevel ,"- Transport's ownership transferred from consumer to session.");
       
  5026             pTransport = ipTransport;
       
  5027             ipTransport = NULL;
       
  5028             }
       
  5029         else // there is no transport
       
  5030             {
       
  5031             /*
       
  5032             // Figure out the XML SD to utilize FOR transport FACTORY:
       
  5033             CSenWSDescription* pDesc = NULL;
       
  5034             MSenServiceDescription& desc = iServiceSession->AsServiceDescription();
       
  5035             pDesc = (CSenWSDescription*)&desc;
       
  5036 
       
  5037             if(pDesc->Endpoint().Length()==0 && iInitializer && iInitializer->Endpoint().Length()>0)
       
  5038                 {
       
  5039                 LOG_WRITE_L("- Due session does not specify endpoint, initilizer is utilized instead.");
       
  5040                 // Only, and only if session does NOT know it's endpoint AND
       
  5041                 // initializer (SD) does specify endpoint, rely on initilizer SD
       
  5042                 pDesc = iInitializer;
       
  5043                 }
       
  5044             LOG_WRITE_L("- Instantiating new transport for the consumed service session.");
       
  5045             pTransport = transportFactory.CreateL(*pDesc);
       
  5046             */
       
  5047             CSLOG_L(iConnectionID,KMinLogLevel ,"- Instantiating new transport for the service session");
       
  5048             CSenWSDescription& description =  (CSenWSDescription&)iServiceSession->AsServiceDescription();
       
  5049 
       
  5050             if( description.HasSuperClass( MSenServiceDescription::EServiceSession ) )
       
  5051                 {
       
  5052                 CSenServiceSession& session = (CSenServiceSession&)description;
       
  5053                 pTransport = transportFactory.CreateL(*iInitializer, &session);
       
  5054                 }
       
  5055             else
       
  5056                 {
       
  5057                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Fatal: session does not derive from CSenServiceSession(!)");
       
  5058                 pTransport = transportFactory.CreateL(*iInitializer, NULL);
       
  5059                 }
       
  5060 
       
  5061             }
       
  5062         // Transfer the ownership of transport to the session
       
  5063         iServiceSession->SetTransportL(pTransport);
       
  5064         }
       
  5065     else // no service session
       
  5066         {
       
  5067         // Check if this consumer already owns a transport or not:
       
  5068         if(!ipTransport)
       
  5069             {
       
  5070             // Check if ther is initilizer 
       
  5071             if(!iInitializer)
       
  5072                 {
       
  5073                 // This should never happen:
       
  5074                 CSLOG_L(iConnectionID,KMinLogLevel ,"FATAL - CSenClientSession::TransportL():");
       
  5075                 CSLOG_L(iConnectionID,KMinLogLevel ," - iInitializer == NULL!");
       
  5076                 User::Leave(KErrNotFound);
       
  5077                 }
       
  5078             CSLOG_L(iConnectionID,KMinLogLevel ,"- Instantiating new transport for the service consumer (no session yet)");
       
  5079             pTransport = transportFactory.CreateL(*iInitializer, NULL);
       
  5080             ipTransport = pTransport;
       
  5081             }
       
  5082         else
       
  5083             {
       
  5084             // Utilize the transport owned by this consumer as long as session does not own one:
       
  5085             pTransport = ipTransport;
       
  5086             }
       
  5087         }
       
  5088     return *pTransport;
       
  5089     }
       
  5090 
       
  5091 
       
  5092 
       
  5093 TInt CSenClientSession::ReleaseServiceSession()
       
  5094     {
       
  5095     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ReleaseServiceSession");
       
  5096 
       
  5097     // Notify responsible framework, so that it 
       
  5098     // can do required cleanup for the session
       
  5099     TInt leaveCode(KErrNone);
       
  5100     if(iServiceSession)
       
  5101         {
       
  5102         // Cease to consumer this session:
       
  5103         TInt removeRetVal(KErrNone);
       
  5104         TRAP( leaveCode, removeRetVal = iServiceSession->RemoveConsumerL(*this); )
       
  5105 #ifdef _SENDEBUG
       
  5106         if(leaveCode!=KErrNone)
       
  5107             {
       
  5108             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- RemoveConsumerL leaved: %d"), leaveCode));
       
  5109             removeRetVal = leaveCode;
       
  5110             leaveCode=KErrNone;
       
  5111             }
       
  5112         else
       
  5113             {
       
  5114             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- RemoveConsumerL returned: %d"), removeRetVal));
       
  5115             }
       
  5116 #endif
       
  5117 
       
  5118         // Ask framework(s) to release this session: de-allocation is framework specific
       
  5119         TRAP( leaveCode, iManager.NotifyFrameworksL(
       
  5120                 iServiceSession->FrameworkId(),
       
  5121                 KSenEventConsumerReleasesSession,
       
  5122                 iServiceSession); )
       
  5123 #ifdef _SENDEBUG
       
  5124         if(leaveCode!=KErrNone)
       
  5125             {
       
  5126             CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- NotifyFrameworksL leaved %d"), leaveCode));
       
  5127             }
       
  5128         else
       
  5129             {
       
  5130             CSLOG_L(iConnectionID,KMinLogLevel ," - NotifyFrameworksL OK.");
       
  5131             }
       
  5132 #endif // _SENDEBUG
       
  5133 
       
  5134         if(leaveCode==KErrNone)
       
  5135             {
       
  5136             leaveCode=removeRetVal;
       
  5137             }
       
  5138         }
       
  5139 
       
  5140 
       
  5141     return leaveCode;
       
  5142     }
       
  5143 
       
  5144 TInt CSenClientSession::CompletePendingMessages()
       
  5145     {
       
  5146     TInt leaveCode(KErrNone);
       
  5147     TRAP( leaveCode, CompletePendingMessagesL(); )
       
  5148     return leaveCode;
       
  5149     }
       
  5150 
       
  5151 void CSenClientSession::CompletePendingMessagesL()
       
  5152     {
       
  5153     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::CompletePendingMessagesL");
       
  5154 
       
  5155     // New: first call cancel from transport using pending txnIds 
       
  5156 
       
  5157     RTransactionIdArray& txnIds = TxnIds();
       
  5158 
       
  5159     TInt pendingCount(txnIds.Count());
       
  5160     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d txnIds(s) pending."), pendingCount));
       
  5161     for(TInt i=pendingCount-1; i>=0; i--)
       
  5162         {
       
  5163         if(txnIds[i])
       
  5164             {
       
  5165             TInt* pTxnId = txnIds[i];
       
  5166             TInt cancelledTxnId(*pTxnId);
       
  5167             txnIds.Remove(i);
       
  5168             delete pTxnId;
       
  5169             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Now processing txn with id %d, after which %d are left.."), cancelledTxnId, i));
       
  5170 
       
  5171 
       
  5172             // Attempt to cancel the actual activity on the transport layer.
       
  5173             // Note that even if transport will not cancel this transaction,
       
  5174             // the response from the transport (later on) won't anymore be 
       
  5175             // delivered to consumer, since this RMessage2 is removed from 
       
  5176             // iMessageMap few lines below. This means, that from the WS-stack
       
  5177             // client point-of-view, cancel works and no "stray" responses
       
  5178             // will follow (eventhough some data is received from transport 
       
  5179             // stack).
       
  5180             MSenTransport* pTransport = ipTransport;
       
  5181             if(iServiceSession)
       
  5182                 {
       
  5183                 CSLOG_L(iConnectionID,KMaxLogLevel ,"-- has session.");
       
  5184                 MSenTransport* pSessionTransport = iServiceSession->Transport();
       
  5185                 if(pSessionTransport)
       
  5186                     {
       
  5187                     CSLOG_L(iConnectionID,KMaxLogLevel ,"--- session has transport.");
       
  5188                     // If session owns a transport, always utilize that one
       
  5189                     pTransport = pSessionTransport;
       
  5190                     }
       
  5191                 }
       
  5192             // If session does not own a transport, check if this remote consumer does..
       
  5193 
       
  5194             if(pTransport)
       
  5195                 {
       
  5196                 CSLOG_L(iConnectionID,KMinLogLevel ,"---- About to call CancelTransaction");
       
  5197                 TInt retCode = pTransport->CancelTransaction(cancelledTxnId);
       
  5198                 CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Transport's  CancelTransaction(%d) returned: %d"), cancelledTxnId, retCode));
       
  5199                 retCode = 0; // not used in release builds atm. 
       
  5200                 }
       
  5201             }
       
  5202         }
       
  5203     txnIds.ResetAndDestroy(); // deallocate TInt heap allocations
       
  5204 
       
  5205 
       
  5206     // New: complete pending transaction RMessage2 objects:
       
  5207     RTransactionArray& txnMsgs = Transactions();
       
  5208     pendingCount = txnMsgs.Count();
       
  5209     CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d RMessage2(s) pending."), pendingCount));
       
  5210     TInt transactionID;
       
  5211     TInt pendingTxnId;
       
  5212     for(TInt t=pendingCount-1; t>=0; t--)
       
  5213         {
       
  5214         if(txnMsgs[t])
       
  5215             {
       
  5216             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- %d left to complete."), t+1));
       
  5217             CSenClientMessage* pClientMessage = Transactions()[t];
       
  5218             RMessage2& message = pClientMessage->RMessage();
       
  5219             
       
  5220             pendingTxnId = pClientMessage->ChunkHeader().PendingTransactionId();
       
  5221             if (pendingTxnId)
       
  5222                 {
       
  5223                 transactionID = pendingTxnId;
       
  5224                 pClientMessage->ChunkHeader().SetPendingTransactionId(0);
       
  5225                 pClientMessage->ChunkHeader().SetTransactionId(pendingTxnId);
       
  5226                 }
       
  5227             else
       
  5228                 {
       
  5229                 transactionID = pClientMessage->ChunkHeader().TransactionId();
       
  5230                 }
       
  5231             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Completing Txn ID: %d"),transactionID)); 
       
  5232             
       
  5233             TPtr8 ptr(reinterpret_cast<TUint8*>(&transactionID), 
       
  5234                       sizeof(transactionID), 
       
  5235                       sizeof(transactionID)); 
       
  5236 
       
  5237             TInt leaveCode(KErrNone);
       
  5238             TRAP(leaveCode, message.WriteL(1, ptr)); //IPC V2
       
  5239             if(leaveCode!=KErrNone)
       
  5240                 {
       
  5241                 message.Complete(ESenInternalError);
       
  5242                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError - TxnId");
       
  5243                 }
       
  5244             else
       
  5245                 {
       
  5246                 message.Complete(ESenServRequestCancelled);
       
  5247                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenServRequestCancelled - TxnId");
       
  5248                 }
       
  5249 
       
  5250             delete pClientMessage;
       
  5251             txnMsgs.Remove(t);
       
  5252             }
       
  5253         }
       
  5254     txnMsgs.ResetAndDestroy(); // deallocate RMessage2 heap alloacations
       
  5255     }
       
  5256     
       
  5257 
       
  5258 TInt CSenClientSession::ProcessRequestFromConsumerL( const TDesC8& aMessage,
       
  5259                                                      const TInt aTxnId,
       
  5260                                                      MSenRemoteServiceConsumer& aConsumer )
       
  5261     {
       
  5262     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::ProcessRequestFromConsumerL");
       
  5263     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Consumer id: (%S)"), &aConsumer.Id() ));
       
  5264     CSLOG_L(iConnectionID,KMaxLogLevel ,"##############################################");
       
  5265     CSLOG_ALL(iConnectionID, KMaxLogLevel, ( aMessage ));
       
  5266     CSLOG_L(iConnectionID,KMaxLogLevel ,"##############################################");
       
  5267     CSenChunk* pChunk = NULL;
       
  5268     TInt retVal = aConsumer.ChunkByTxnIdL( aTxnId, pChunk );
       
  5269 
       
  5270     if( retVal == KErrNone ) 
       
  5271         {
       
  5272         CSenClientMessage* pMessage = (CSenClientMessage*) pChunk; // this holds all the data written by SC
       
  5273     
       
  5274         if( ipHostletAwaitOp )
       
  5275             {
       
  5276             RHandleBase& handle = pMessage->Chunk();
       
  5277 #ifdef EKA2
       
  5278             ipHostletAwaitOp->RMessage().Complete( handle );
       
  5279 #else // EKA1
       
  5280             ipHostletAwaitOp->RMessage().Complete( handle.Handle() );
       
  5281 #endif // EKA2:EKA1
       
  5282             delete ipHostletAwaitOp;
       
  5283             ipHostletAwaitOp = NULL;
       
  5284             }
       
  5285         else // await op is in-progress / model is "busy"
       
  5286             {
       
  5287             CSLOG_L(iConnectionID,KMaxLogLevel ,"- Request has to be queued, await operation is already in progress (busy)");
       
  5288             // 
       
  5289             TInt* pTxnId = new (ELeave) TInt(aTxnId); //CodeScannerWarnings
       
  5290             CleanupStack::PushL(pTxnId);
       
  5291             RHostletRequestMap& map = HostletRequestMap();
       
  5292             // Put this consumer request in queue and start waiting 
       
  5293             // for next "await hostlet request" -operation to come.
       
  5294             retVal = map.Append(pTxnId, pMessage);
       
  5295             if( retVal == KErrNone )
       
  5296                 {
       
  5297                 CleanupStack::Pop( pTxnId );
       
  5298                 }
       
  5299             else
       
  5300                 {
       
  5301                 CleanupStack::PopAndDestroy( pTxnId ); 
       
  5302                 }
       
  5303             }
       
  5304         }
       
  5305     return retVal;
       
  5306     }
       
  5307 
       
  5308 
       
  5309 // NOTE: closely similar to transactioncompletel(!) 
       
  5310 TInt CSenClientSession::OnServiceCompleteL( const TInt aTxnId, TInt aCompletionCode, const TDesC8& /* aDesc */ )
       
  5311     {
       
  5312     CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::OnServiceCompleteL (part of remote hostlet interface)");
       
  5313     TInt retVal(KErrNotFound);
       
  5314     RTransactionIdArray& ids = TxnIds();
       
  5315     TInt index(0);
       
  5316     TInt count(ids.Count());
       
  5317     TInt* pTxnId = NULL;
       
  5318     for(; index < count; index++)
       
  5319         {
       
  5320         pTxnId = ids[index];
       
  5321         if(pTxnId && *pTxnId == aTxnId)
       
  5322             {
       
  5323             break;
       
  5324             }
       
  5325         }
       
  5326         
       
  5327     if(index < count)
       
  5328         {
       
  5329         RTransactionArray& transactions = Transactions();
       
  5330         TInt count(transactions.Count());
       
  5331         if( index < count)
       
  5332             {
       
  5333             CSenClientMessage* pClientMessage = transactions[index];
       
  5334             RMessage2& message = pClientMessage->RMessage();
       
  5335 
       
  5336             TPtr8 ptr(reinterpret_cast<TUint8*>(&aCompletionCode),
       
  5337                         sizeof(aCompletionCode), sizeof(aCompletionCode));
       
  5338 
       
  5339             TInt leaveCode(KErrNone);
       
  5340             TRAP(leaveCode, message.WriteL(0, ptr)); //IPC V2
       
  5341             if(leaveCode!=KErrNone)
       
  5342                 {
       
  5343                 // LEAVE
       
  5344                 CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Leave code from RMessage2::WriteL(completionCode): %d"), leaveCode));
       
  5345                 message.Complete(ESenInternalError);
       
  5346                 retVal = leaveCode;
       
  5347                 CSLOG_L(iConnectionID,KMinLogLevel ,"Completed with ESenInternalError");
       
  5348                 }
       
  5349             else
       
  5350                 {
       
  5351                 // OK
       
  5352                 TInt transactionId(aTxnId);
       
  5353                 TPtr8 txnId(reinterpret_cast<TUint8*>(&transactionId),
       
  5354                             sizeof(transactionId), sizeof(transactionId));
       
  5355                 TRAP(leaveCode, message.WriteL(1, txnId)); //IPC V2
       
  5356                 if(leaveCode!=KErrNone)
       
  5357                     {
       
  5358                     // LEAVE
       
  5359                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Leave code from RMessage2::WriteL(txnID): %d"), leaveCode));
       
  5360                     message.Complete(ESenInternalError);
       
  5361                     retVal = leaveCode;
       
  5362                     CSLOG_L(iConnectionID,KMinLogLevel ,"Completed with ESenInternalError");
       
  5363                     }
       
  5364                 else
       
  5365                     {
       
  5366                     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- Completion code: %d"), aCompletionCode));
       
  5367                     message.Complete(ESenOnServiceComplete);
       
  5368                     CSLOG_L(iConnectionID,KMinLogLevel ,"Completed with ESenOnServiceComplete");
       
  5369                     }
       
  5370                 }
       
  5371             transactions.Remove(index);
       
  5372             delete pClientMessage;
       
  5373             retVal = KErrNone; // all went ok
       
  5374             }
       
  5375         else
       
  5376             {
       
  5377             retVal = KErrNotFound;
       
  5378             }
       
  5379         ids.Remove(index); // de-allocate TInt which was allocated from heap
       
  5380         delete pTxnId;
       
  5381         }
       
  5382     else
       
  5383         {
       
  5384         retVal = KErrNotFound;
       
  5385         }
       
  5386         
       
  5387     return retVal;    
       
  5388     }
       
  5389 
       
  5390 
       
  5391 TInt CSenClientSession::ChunkByTxnIdL( TInt aTxnId, CSenChunk*& aChunk )
       
  5392     {
       
  5393     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::ChunkByTxnIdL(%d)"), aTxnId));
       
  5394     aChunk = NULL;
       
  5395 
       
  5396     TInt retVal = TransactionIndex(aTxnId);
       
  5397     if(retVal > KErrNotFound)
       
  5398         {
       
  5399         RTransactionArray& transactions = Transactions();
       
  5400         if( retVal < transactions.Count() )
       
  5401             {
       
  5402             CSenClientMessage* pClientMessage = transactions[retVal];
       
  5403             aChunk = pClientMessage;
       
  5404             retVal = KErrNone;
       
  5405             }
       
  5406         else           
       
  5407             {
       
  5408             return KErrNotFound; // "KErrIndexOutOfBounds"
       
  5409             }
       
  5410         }
       
  5411      return retVal; // always KErrNone or KErrNotFound
       
  5412      }
       
  5413      
       
  5414 MSenMessageContext* CSenClientSession::MessageContextByTxnIdL( TInt aCtxId, TInt& aError )
       
  5415     {
       
  5416     CSenClientMessage* pClientMessage = NULL;
       
  5417     TInt retVal = ContextIndex(aCtxId); // retVal == "context index" or ERROR
       
  5418     if(retVal > KErrNotFound) 
       
  5419         {
       
  5420         RTransactionArray& transactions = Transactions();        
       
  5421         if( retVal < transactions.Count() )
       
  5422             {
       
  5423             pClientMessage = transactions[retVal];
       
  5424             if( pClientMessage )
       
  5425                 {
       
  5426                 aError = KErrNone;
       
  5427                 return &pClientMessage->MessageContext(); 
       
  5428                 }
       
  5429             }
       
  5430         else  
       
  5431             {
       
  5432             // "KErrIndexOutOfBounds"          
       
  5433             aError = KErrNotFound;
       
  5434             }
       
  5435         }
       
  5436     else        
       
  5437         {
       
  5438         aError = retVal;
       
  5439         }
       
  5440     return NULL;
       
  5441     }
       
  5442     
       
  5443 void CSenClientSession::StateChanged(TInt aState)
       
  5444     {
       
  5445     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("CSenClientSession::StateChanged(%d)"), aState));
       
  5446     RProperty::Set(iClientSecureID,(KSenRPropertyKeyBaseNumber+iConnectionID), aState);
       
  5447     }
       
  5448     
       
  5449 TBool CSenClientSession::HasAuthenticationCallback()
       
  5450     {
       
  5451     return iConnectionHasAuthenticationCallback;
       
  5452     }
       
  5453 TBool CSenClientSession::HasCoBrandingCallback()
       
  5454     {
       
  5455     return iConnectionHasCoBrandingCallback;
       
  5456     }
       
  5457 
       
  5458 void CSenClientSession::SearchIdentityProviderL(const RMessage2& aMessage)
       
  5459 	{
       
  5460 	TInt retVal(KErrNone);
       
  5461     CSenChunk* pSenChunk = NULL;
       
  5462 
       
  5463     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  5464     pSenChunk->SetLogger(Log());
       
  5465     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  5466     
       
  5467     if ( retVal == KErrNone )
       
  5468         {
       
  5469         TInt length = aMessage.Int2();
       
  5470         if(length < 1)
       
  5471             {
       
  5472             CSLOG_L(iConnectionID,KMaxLogLevel ,"- Tried search Identity Provide with null provider Id descriptor.");
       
  5473             aMessage.Complete(KErrBadDescriptor);
       
  5474             return;
       
  5475             }
       
  5476         
       
  5477         HBufC8* inBuf = HBufC8::NewLC(length);
       
  5478         TPtr8 providerId = inBuf->Des();
       
  5479         aMessage.ReadL(1, providerId);
       
  5480         
       
  5481 	    CSenWSDescription* pPattern = CSenWSDescription::NewLC();
       
  5482 	    pPattern->SetEndPointL(providerId);
       
  5483 	    CSenIdentityProvider* pIdp = ((MSenCoreServiceManager&)iManager).IdentityProviderL(*pPattern);
       
  5484 	    CleanupStack::PopAndDestroy(pPattern);
       
  5485 	    CleanupStack::PopAndDestroy(inBuf);
       
  5486 	    if ( pIdp )
       
  5487 	        {
       
  5488 	        HBufC8* pIdpAsXml = pIdp->AsXmlL();
       
  5489 	        CleanupStack::PushL(pIdpAsXml);
       
  5490 	        retVal = pSenChunk->DescToChunk(*pIdpAsXml);
       
  5491 	        CleanupStack::PopAndDestroy(pIdpAsXml);
       
  5492 	        }
       
  5493 	    else
       
  5494 	    	{
       
  5495 	        retVal = KErrNotFound;
       
  5496 	        }
       
  5497         }
       
  5498 
       
  5499     CleanupStack::PopAndDestroy(pSenChunk);
       
  5500     aMessage.Complete(retVal);
       
  5501 	
       
  5502 	}
       
  5503 TBool CSenClientSession::IsTrustedClient(const RMessage2& aMessage)
       
  5504     {
       
  5505     TVendorId vendor = aMessage.VendorId();
       
  5506 	_LIT_VENDOR_ID(trustedVendor,VID_DEFAULT);
       
  5507     
       
  5508     if (vendor.iId == trustedVendor.iId )
       
  5509         return ETrue;
       
  5510     else
       
  5511         return EFalse;
       
  5512 
       
  5513     }
       
  5514 TBool CSenClientSession::CleanPassword(const RMessage2& aMessage)
       
  5515 	{
       
  5516     TSecureId sid = aMessage.SecureId();
       
  5517     _LIT_SECURE_ID(nokia_chateventmonitorserver, 0x2001B2C5 );
       
  5518     _LIT_SECURE_ID(nokia_xmppnaui, 0x2001A95B);
       
  5519     if ((sid.iId == nokia_chateventmonitorserver.iId) || (sid.iId == nokia_xmppnaui.iId))
       
  5520         return EFalse;
       
  5521     else
       
  5522         return ETrue;
       
  5523     }
       
  5524 TSecureId CSenClientSession::SecureId()
       
  5525 	{
       
  5526 	return iSecureId;
       
  5527 	}
       
  5528 
       
  5529 TVendorId CSenClientSession::VendorId()
       
  5530 	{
       
  5531 	return iVendorId;
       
  5532 	}
       
  5533 void CSenClientSession::IdentityProviders(const RMessage2& aMessage)
       
  5534 	{
       
  5535 	
       
  5536 	TInt retVal(KErrNone);
       
  5537     CSenChunk* pSenChunk = NULL;
       
  5538     pSenChunk = CSenChunk::NewLC(KNullDesC);
       
  5539     retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
  5540     
       
  5541     if ( retVal == KErrNone )
       
  5542         {
       
  5543         const RPointerArray<CSenIdentityProvider> pIdps = ((MSenCoreServiceManager&)iManager).IdentityProvidersL();
       
  5544         
       
  5545         const TInt count = pIdps.Count();
       
  5546   
       
  5547         // Calculate required heap allocation size:
       
  5548         TInt size(0);
       
  5549         if(count>0)
       
  5550             {
       
  5551             size += (count-1) * KTab().Length();
       
  5552             }
       
  5553 
       
  5554         TInt leaveCode(KErrNone);
       
  5555         TRAP(leaveCode, size += iManager.SizeOfIdentityProvidersL(pIdps); )
       
  5556         if(leaveCode!=KErrNone)
       
  5557             {
       
  5558             CleanupStack::PopAndDestroy(pSenChunk);
       
  5559             aMessage.Complete(leaveCode);
       
  5560             }
       
  5561         CSLOG_L(iConnectionID,KMinLogLevel ,"CSenClientSession::IdentityProviders");
       
  5562         CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- Size of SD(s) + delimiter(s): %d bytes"), size));
       
  5563 
       
  5564         // Adjust RChunk to accomodate found IdP using known hnalde
       
  5565         TPtr8* pIdPrs = NULL;
       
  5566         retVal = pSenChunk->AllocDescToChunk(size, pIdPrs); 
       
  5567         const TBool trusted = IsTrustedClient( aMessage );
       
  5568         const TBool cleanPass = CleanPassword( aMessage );
       
  5569         if(retVal==KErrNone && pIdPrs)
       
  5570             {
       
  5571             for ( TInt i = 0; i < count; ++i )
       
  5572                 {
       
  5573                 if ( i >= 1 )
       
  5574                 	{
       
  5575                     pIdPrs->Append( KTab );
       
  5576                 	}
       
  5577                 
       
  5578                 CBufFlat* pBuf= CBufFlat::NewL( KFlatBufSize );
       
  5579                 CleanupStack::PushL( pBuf );
       
  5580                 
       
  5581                 RBufWriteStream bufWs( *pBuf );
       
  5582                 CleanupClosePushL( bufWs );
       
  5583                 
       
  5584                 HBufC8* passDec = SenXmlUtils::DecodeHttpCharactersLC( pIdps[i]->Password() );
       
  5585                 RBuf8 password;
       
  5586                 password.Create( *passDec );
       
  5587                 CleanupStack::PopAndDestroy( passDec );                
       
  5588                 
       
  5589                 if ( !trusted )
       
  5590                     {
       
  5591                     // Clean AutoSignIn
       
  5592                     TBool rollbackAutoMode = EFalse;
       
  5593                     CSenElement* autoSignInEl( NULL );
       
  5594                     
       
  5595                     if ( pIdps[i]->FrameworkId() == KDefaultOviFrameworkID )
       
  5596                         {
       
  5597                         CSenElement* el( NULL );
       
  5598                         pIdps[i]->AccountExtensions( el );
       
  5599                 
       
  5600                         if ( el )
       
  5601                             {
       
  5602                             autoSignInEl = el->Element( KSenAccAutoSignIn );
       
  5603                     
       
  5604                             if ( autoSignInEl && autoSignInEl->Content() == KSenPropertyTrue )
       
  5605                                 {
       
  5606                                 autoSignInEl->SetContentL( KSenPropertyFalse );
       
  5607                                 rollbackAutoMode = ETrue;
       
  5608                                 }
       
  5609                             }         
       
  5610                         }
       
  5611                     
       
  5612                     pIdps[i]->SetUserInfoL( pIdps[i]->AuthzID(),
       
  5613                                             pIdps[i]->AdvisoryAuthnID(),
       
  5614                                             KNullDesC8() );
       
  5615                     
       
  5616                     pIdps[i]->WriteAsXMLToL( bufWs );
       
  5617                     
       
  5618                     if ( rollbackAutoMode ) //autoSignInEl has to exists, otherwise rollbackAutoMode is false
       
  5619                     	{
       
  5620                     	autoSignInEl->SetContentL( KSenPropertyTrue );
       
  5621                     	}
       
  5622                     TRAPD(retVal,
       
  5623 			            	    HBufC8* encPassword = SenXmlUtils::EncodeHttpCharactersLC(password);
       
  5624 		                    pIdps[i]->SetUserInfoL( pIdps[i]->AuthzID(),
       
  5625 		                                            pIdps[i]->AdvisoryAuthnID(),
       
  5626 		                                            *encPassword );
       
  5627 		  	          	    CleanupStack::PopAndDestroy(encPassword);
       
  5628   	          	    		);
       
  5629                     }
       
  5630                 else//trusted application
       
  5631                     {
       
  5632                     if (cleanPass)//special case for Yukon
       
  5633                     	{
       
  5634                     	pIdps[i]->SetUserInfoL( pIdps[i]->AuthzID(),
       
  5635 	                                            pIdps[i]->AdvisoryAuthnID(),
       
  5636 	                                            KNullDesC8() );
       
  5637 	                    pIdps[i]->WriteAsXMLToL( bufWs );
       
  5638 	                    HBufC8* encPassword = SenXmlUtils::EncodeHttpCharactersLC(password);
       
  5639 	                    pIdps[i]->SetUserInfoL( pIdps[i]->AuthzID(),
       
  5640 	                                            pIdps[i]->AdvisoryAuthnID(),
       
  5641 	                                            *encPassword );
       
  5642 	            	    CleanupStack::PopAndDestroy(encPassword);
       
  5643                     	}
       
  5644                     else
       
  5645                     	{
       
  5646                     	pIdps[i]->WriteAsXMLToL( bufWs );
       
  5647                     	}
       
  5648                     }
       
  5649                 password.Close();
       
  5650                 // Add this SD as XML into the "big heap buffer":
       
  5651                 TPtr8 p8 = pBuf->Ptr(0);
       
  5652                 pIdPrs->Append(p8); 
       
  5653                 // Destroy the temporary, flat stream buffer
       
  5654                 CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  5655                 
       
  5656                 pBuf = NULL;
       
  5657                 }
       
  5658             CSLOG_L(iConnectionID,KMaxLogLevel ,"- Requested descriptions:");
       
  5659             CSLOG_ALL(iConnectionID,KMaxLogLevel ,(*pIdPrs));
       
  5660             }
       
  5661     #ifdef _SENDEBUG
       
  5662         else
       
  5663             {
       
  5664             CSLOG_FORMAT((iConnectionID, KNormalLogLevel , _L8("- AllocDescToRMsgL failed: %d"), retVal));
       
  5665             }
       
  5666     #endif // _SENDEBUG
       
  5667 
       
  5668         }
       
  5669     CleanupStack::PopAndDestroy(pSenChunk); // Close SenChunk
       
  5670 
       
  5671     aMessage.Complete(retVal);
       
  5672 	
       
  5673 	}
       
  5674 
       
  5675 void CSenClientSession::ObserveTransfer(const RMessage2& aMessage)
       
  5676 	{
       
  5677     CSLOG_L( iConnectionID,KMinLogLevel, "CSenClientSession::ObserveTransfer" );	
       
  5678 	TInt retVal(KErrNone);
       
  5679 	if(!iConnectionSession.Handle())
       
  5680 		{
       
  5681 		CSLOG_L( iConnectionID,KMinLogLevel, " iConnectionSession is not open. Creating it now." );	
       
  5682 		retVal = iConnectionSession.CreateSession(aMessage);
       
  5683 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- CreateSession returned: %d" ), retVal ));	
       
  5684 		}
       
  5685 	if(retVal == KErrNone)
       
  5686 		{
       
  5687 		CSLOG_L( iConnectionID,KMinLogLevel, " - Calling InitProgressObserver()." );	
       
  5688 		retVal = iConnectionSession.InitProgressObserver(aMessage);
       
  5689 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- InitProgressObserver() returned: %d" ), retVal ));	
       
  5690 		if(retVal != KErrNone)
       
  5691 			{
       
  5692     		CSLOG_L( iConnectionID,KMinLogLevel, " => Forced to close iConnectionSession." );	
       
  5693 			iConnectionSession.Close();
       
  5694 			}
       
  5695 		}
       
  5696 	aMessage.Complete(retVal);
       
  5697 	}
       
  5698 void CSenClientSession::ObserveCoBranding(const RMessage2& aMessage)
       
  5699 	{
       
  5700 	TInt retVal(KErrNone);
       
  5701 	if(!iConnectionSession.Handle())
       
  5702 		{
       
  5703 		CSLOG_L( iConnectionID,KMinLogLevel, " iConnectionSession is not open. Creating it now." );	
       
  5704 		retVal = iConnectionSession.CreateSession(aMessage);
       
  5705 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- CreateSession returned: %d" ), retVal ));	
       
  5706 		}
       
  5707 	if(retVal == KErrNone)
       
  5708 		{
       
  5709 		CSLOG_L( iConnectionID,KMinLogLevel, " - Calling InitCoBrandingObserver()." );	
       
  5710 		retVal = iConnectionSession.InitCoBrandingObserver(aMessage);
       
  5711 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- InitCoBrandingObserver() returned: %d" ), retVal ));	
       
  5712 		if(retVal != KErrNone)
       
  5713 			{
       
  5714     		CSLOG_L( iConnectionID,KMinLogLevel, " => Forced to close iConnectionSession." );	
       
  5715 			iConnectionSession.Close();
       
  5716 			}
       
  5717 		else
       
  5718     		{
       
  5719     		iConnectionHasCoBrandingCallback = ETrue;
       
  5720     		}
       
  5721 		}
       
  5722 	aMessage.Complete(retVal);
       
  5723 	}
       
  5724 void CSenClientSession::ObserveAuthCallback(const RMessage2& aMessage)
       
  5725 	{
       
  5726 	TInt retVal(KErrNone);
       
  5727 	if(!iConnectionSession.Handle())
       
  5728 		{
       
  5729 		CSLOG_L( iConnectionID,KMinLogLevel, " iConnectionSession is not open. Creating it now." );	
       
  5730 		retVal = iConnectionSession.CreateSession(aMessage);
       
  5731 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- CreateSession returned: %d" ), retVal ));	
       
  5732 		}
       
  5733 	if(retVal == KErrNone)
       
  5734 		{
       
  5735 		CSLOG_L( iConnectionID,KMinLogLevel, " - Calling InitAuthObserver()." );	
       
  5736 		retVal = iConnectionSession.InitAuthObserver(aMessage);
       
  5737 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- InitAuthObserver() returned: %d" ), retVal ));	
       
  5738 		if(retVal != KErrNone)
       
  5739 			{
       
  5740     		CSLOG_L( iConnectionID,KMinLogLevel, " => Forced to close iConnectionSession." );	
       
  5741 			iConnectionSession.Close();
       
  5742 			}
       
  5743 		}
       
  5744 	aMessage.Complete(retVal);
       
  5745 	}
       
  5746 
       
  5747 #ifdef __ENABLE_ALR__    
       
  5748 void CSenClientSession::ObserveMobiltyService(const RMessage2& aMessage)
       
  5749    {
       
  5750    CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::ObserveMobiltyService registered ");
       
  5751    TInt retVal(KErrNone);
       
  5752    if(!iConnectionSession.Handle())
       
  5753         {
       
  5754         CSLOG_L( iConnectionID,KMinLogLevel, " iConnectionSession is not open. Creating it now." );	
       
  5755         retVal = iConnectionSession.CreateSession(aMessage);
       
  5756 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- CreateSession returned: %d" ), retVal ));	
       
  5757         }
       
  5758    if(retVal == KErrNone)
       
  5759         {
       
  5760 		CSLOG_L( iConnectionID,KMinLogLevel, " - Calling InitMobilityObserver()." );	
       
  5761         retVal = iConnectionSession.InitMobilityObserver(aMessage);        
       
  5762 		CSLOG_FORMAT(( iConnectionID,KMinLogLevel, _L8("- InitMobilityObserver() returned: %d" ), retVal ));	
       
  5763         if(retVal != KErrNone)
       
  5764             {
       
  5765     		CSLOG_L( iConnectionID,KMinLogLevel, " => Forced to close iConnectionSession." );	
       
  5766             iConnectionSession.Close();
       
  5767             }
       
  5768         }
       
  5769    aMessage.Complete(retVal);
       
  5770    }
       
  5771 
       
  5772 void CSenClientSession::MigrateToPrefferedCarrierL(const RMessage2& aMessage)
       
  5773    {
       
  5774    CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::MigrateToPrefferedCarrier ");			
       
  5775    HBufC8* inBuf = HBufC8::NewLC(10);
       
  5776    TPtr8 inBuffer = inBuf->Des();
       
  5777    aMessage.ReadL(0, inBuffer); // boolean
       
  5778    TBool userChoice = (TBool)(*inBuffer.Ptr()) ;
       
  5779    CleanupStack::PopAndDestroy(); // inBuf			
       
  5780    aMessage.Complete(KErrNone);
       
  5781    iMobilityChoice = userChoice ;   
       
  5782    MigrateToPrefferedCarrier(userChoice) ;
       
  5783    }
       
  5784 
       
  5785 void CSenClientSession::MigrateToPrefferedCarrier(TBool aUserChoice)
       
  5786    {
       
  5787    CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::MigrateToPrefferedCarrier() ");
       
  5788     //if pending transaction are there we need to wait or cancel all transaction and then migrate //CompletePendingMessages()
       
  5789     RTransactionIdArray& txnIds = TxnIds();
       
  5790     TInt pendingCount(txnIds.Count());
       
  5791     if (pendingCount == 0)
       
  5792         {
       
  5793         if (aUserChoice != EFalse)
       
  5794             {
       
  5795             CSLOG_L(iConnectionID, KMinLogLevel , "-calling iALRObserver->MigrateToPreferredCarrier ");		
       
  5796             iALRObserver->MigrateToPreferredCarrier() ;
       
  5797             }
       
  5798         else
       
  5799             {
       
  5800             CSLOG_L(iConnectionID, KMinLogLevel , "-calling iALRObserver->IgnorePreferredCarrier ");		
       
  5801             iALRObserver->IgnorePreferredCarrier() ;				
       
  5802             }
       
  5803         }
       
  5804     else
       
  5805         {
       
  5806         CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("-call to iALRObserver->MigrateToPrefferedCarrier cant be performed as %d txnIds(s) pending."), pendingCount));
       
  5807         }    
       
  5808     }
       
  5809 
       
  5810 void CSenClientSession::NewCarrierAcceptedL(const RMessage2& aMessage)
       
  5811     {
       
  5812     CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::NewCarrierAccepted ");				
       
  5813     HBufC8* inBuf = HBufC8::NewLC(10);
       
  5814     TPtr8 inBuffer = inBuf->Des();
       
  5815     aMessage.ReadL(0, inBuffer); // boolean
       
  5816     TBool userChoice = (TBool)(*inBuffer.Ptr()) ;
       
  5817     CleanupStack::PopAndDestroy(); // inBuf	
       
  5818     aMessage.Complete(KErrNone);
       
  5819 
       
  5820     NewCarrierAcceptedL(userChoice) ;        
       
  5821     }
       
  5822 
       
  5823 void CSenClientSession::NewCarrierAcceptedL(TBool aUserChoice)
       
  5824    {
       
  5825    CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::NewCarrierAccepted() ");
       
  5826     if (aUserChoice != EFalse)
       
  5827         {
       
  5828         TInt retVal(KErrNone);
       
  5829         CSLOG_L(iConnectionID, KMinLogLevel , "-calling iALRObserver->NewCarrierAccepted ");
       
  5830         iALRObserver->NewCarrierAccepted() ;
       
  5831         //now we have new iap id and we can even propagate to transport plugin
       
  5832         //set transport properties
       
  5833         CSLOG_L(iConnectionID, KMinLogLevel , "-calling iALRObserver->GetNewIapAsTransportPropertyL ");
       
  5834         HBufC8* transportProperties = iALRObserver->GetNewIapAsTransportPropertyL() ;
       
  5835         if(transportProperties != NULL)
       
  5836             {
       
  5837             CleanupStack::PushL (transportProperties) ;
       
  5838             }
       
  5839         if ( iServiceSession && transportProperties )
       
  5840             {
       
  5841             CSLOG_L(iConnectionID, KMinLogLevel , "-setting up new transport properties with new iap id received from iALRObserver ");
       
  5842             retVal = iServiceSession->SetTransportPropertiesL(*transportProperties, *this);
       
  5843             }
       
  5844         else
       
  5845             {
       
  5846             retVal = KErrSenNotInitialized;
       
  5847                  CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("-CSenClientSession::NewCarrierActive SetTransportPropertiesL failed with %d "), retVal)) ;
       
  5848             //HandleErrorL(KErrSenNotInitialized, KNullDesC8) ;
       
  5849             }
       
  5850         if(transportProperties != NULL)
       
  5851             {
       
  5852              	CleanupStack::PopAndDestroy(transportProperties); // transportProperties	        
       
  5853             }
       
  5854         }
       
  5855     else
       
  5856         {
       
  5857         CSLOG_L(iConnectionID, KMinLogLevel , "-calling iALRObserver->NewCarrierRejected ");		
       
  5858         iALRObserver->NewCarrierRejected() ;			
       
  5859         }
       
  5860    }
       
  5861 
       
  5862 void CSenClientSession::PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
       
  5863                                         TAccessPointInfo aNewAPInfo,
       
  5864                                         TBool aIsUpgrade,
       
  5865                                         TBool aIsSeamless )
       
  5866 	{
       
  5867     CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::PreferredCarrierAvailable ");
       
  5868     
       
  5869     RTransactionIdArray& txnIds = TxnIds();
       
  5870     TInt pendingCount(txnIds.Count());
       
  5871       
       
  5872     if (iConnectionSession.Handle() && pendingCount == 0)
       
  5873         {
       
  5874         if (aIsSeamless)
       
  5875             {
       
  5876               // in S60 3.2, this situation cannot occur.
       
  5877             CSLOG_L(iConnectionID, KMinLogLevel , "-it is seemless in S60 3.2, this situation cannot occur. ");
       
  5878             }
       
  5879         else if (iMobilityCallBackForwarded == EFalse)
       
  5880             {
       
  5881             CSLOG_L(iConnectionID, KMinLogLevel , "-Calling iConnectionagentSession PreferredCarrierAvailable() ");
       
  5882     		iConnectionSession.PreferredCarrierAvailable(aOldAPInfo, aNewAPInfo, aIsUpgrade, aIsSeamless) ;
       
  5883             iMobilityCallBackForwarded = ETrue ;
       
  5884             }
       
  5885         else if(iMobilityCallBackForwarded != EFalse)
       
  5886             {
       
  5887             CSLOG_L(iConnectionID, KMinLogLevel , "-PreferredCarrierAvailable callback is already forwared to client ");
       
  5888             CSLOG_L(iConnectionID, KMinLogLevel , "-Client session has user choice by now and we can reuse it");
       
  5889             MigrateToPrefferedCarrier (iMobilityChoice) ;
       
  5890             }
       
  5891         }	
       
  5892 	else
       
  5893 		{
       
  5894         CSLOG_L(iConnectionID, KMinLogLevel , "MobiltyObserver is not registered ");
       
  5895         CSLOG_L(iConnectionID, KMinLogLevel , "switching to new carrier automaticaly");
       
  5896         MigrateToPrefferedCarrier (ETrue) ;
       
  5897 	    }
       
  5898     }
       
  5899 
       
  5900 void CSenClientSession::Error( TInt aError )
       
  5901 	{
       
  5902     CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("-CSenClientSession::Error aError = %d"), aError));
       
  5903     iMobilityCallBackForwarded = EFalse ; //reset the flag
       
  5904     iMobilityChoice = EFalse ;       
       
  5905     if (iConnectionSession.Handle())
       
  5906         {
       
  5907         CSLOG_L(iConnectionID, KMinLogLevel , "-Calling iConnectionagentSession MobilityError() ");
       
  5908         iConnectionSession.MobilityError(aError) ;        
       
  5909         }		
       
  5910     else
       
  5911         {
       
  5912         CSLOG_L(iConnectionID, KMinLogLevel , "MobiltyObserver is not registered ");
       
  5913         CSLOG_L(iConnectionID, KMinLogLevel , "-iMobiltyObserver->Error not called ");
       
  5914         }
       
  5915 	}
       
  5916 
       
  5917 void CSenClientSession::NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless )
       
  5918     {
       
  5919     CSLOG_L(iConnectionID, KMinLogLevel , "-CSenClientSession::NewCarrierActive ");
       
  5920     if (iConnectionSession.Handle())
       
  5921         {
       
  5922         CSLOG_L(iConnectionID, KMinLogLevel , "-Calling iConnectionagentSession NewCarrierActive() ");
       
  5923         iConnectionSession.NewCarrierActive(aNewAPInfo, aIsSeamless) ;
       
  5924         iMobilityCallBackForwarded = EFalse ; //reset the flag
       
  5925         iMobilityChoice = EFalse ;        
       
  5926         }	
       
  5927     else
       
  5928         {
       
  5929         CSLOG_L(iConnectionID, KMinLogLevel , "MobiltyObserver is not registered ");
       
  5930         CSLOG_L(iConnectionID, KMinLogLevel , "activating new carrier automaticaly");
       
  5931         TRAPD(retVal, NewCarrierAcceptedL(ETrue));
       
  5932         }
       
  5933     }
       
  5934 #endif // __ENABLE_ALR__    
       
  5935 
       
  5936 
       
  5937 
       
  5938 TInt CSenClientSession::CompleteReauthLoop(CSenChunk& aSenChunk) //also completes transaction
       
  5939 	{
       
  5940 	CSLOG_L(iConnectionID,KMinLogLevel ,"- CompleteReauthLoop");
       
  5941 	TInt retVal(KErrNone);
       
  5942 
       
  5943 	TInt previousTxnId = aSenChunk.ChunkHeader().TransactionId();
       
  5944 	aSenChunk.ChunkHeader().SetTransactionId(KErrNotFound);
       
  5945 	TInt transactionIndex = TransactionIndex(KErrNotFound);
       
  5946 	aSenChunk.ChunkHeader().SetTransactionId(previousTxnId);
       
  5947 	
       
  5948 	if ( transactionIndex != KErrNotFound )
       
  5949 		{
       
  5950 		CSenClientMessage* pClientMessage = iPendingTransactions[transactionIndex];
       
  5951 		RMessage2& message = pClientMessage->RMessage();
       
  5952 		
       
  5953 
       
  5954             TPtr8 ptr(reinterpret_cast<TUint8*>(&previousTxnId), 
       
  5955                       sizeof(previousTxnId), 
       
  5956                       sizeof(previousTxnId)); 
       
  5957 
       
  5958             TRAPD(leaveCode, message.WriteL(1, ptr)); //IPC V2
       
  5959             if(leaveCode!=KErrNone)
       
  5960                 {
       
  5961                 message.Complete(ESenInternalError);
       
  5962                 CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenInternalError");
       
  5963                 }
       
  5964             else // no internal error in writing error message
       
  5965                 {
       
  5966 		      	pClientMessage->ChunkHeader().SetPendingTransactionId(0);
       
  5967 		      	pClientMessage->ChunkHeader().SetTransactionId(previousTxnId);
       
  5968 			pClientMessage->ChunkHeader().SetMessageDirection( MSenMessage::EOutbound );
       
  5969             
       
  5970 			//CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- ErrCode: %d"), KErrSenFailedAuthentication));
       
  5971 			CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- ErrCode: %d"), KErrSenAuthenticationFault));
       
  5972 			CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- transactionIndex  : %d"), transactionIndex));
       
  5973 			CSLOG_FORMAT((iConnectionID, KMinLogLevel , _L8("- previousTxnId  : %d"), previousTxnId));
       
  5974 			iReauthResendNeeded = ETrue ;
       
  5975 			message.Complete(ESenReAuthAndResendNeeded);
       
  5976 			CSLOG_L(iConnectionID,KMinLogLevel ,"- Completed with ESenReAuthAndResendNeeded");
       
  5977 				
       
  5978 				iPendingTransactions.Remove( transactionIndex );
       
  5979 				delete pClientMessage;
       
  5980                 }
       
  5981 		}
       
  5982 	else
       
  5983 	    {
       
  5984 	    retVal = KErrNotFound;
       
  5985 	    }
       
  5986 	
       
  5987 	return retVal;
       
  5988 	}
       
  5989 
       
  5990 TInt CSenClientSession::ReauthenticationNeededL(CSenIdentityProvider*& aIdp)
       
  5991 	{
       
  5992 	_LIT(chunkNameLit, "caChunk"); // lenght = 7
       
  5993 	const TInt KMaxChunkNumDecimals = 64;
       
  5994 	const TInt maxChunkNameLen = KMaxChunkNumDecimals + 7;
       
  5995 	
       
  5996 	TInt retVal(KErrNotFound);
       
  5997 	if(aIdp)
       
  5998 		{
       
  5999 		HBufC* chunkNameDes = HBufC::NewLC(maxChunkNameLen);
       
  6000 		TPtr chunkName = chunkNameDes->Des();
       
  6001 		chunkName.Copy(chunkNameLit);
       
  6002 		chunkName.AppendNum(iConnectionID);
       
  6003 
       
  6004 		CSenChunk* pSenChunk = CSenChunk::NewLC(chunkName.Left(KMaxName));
       
  6005 		pSenChunk->SetLogger(Log());
       
  6006 		retVal = pSenChunk->CreateChunk();
       
  6007 		if(retVal == KErrNone)
       
  6008 			{
       
  6009 			// Write identity provider to chunk
       
  6010 			HBufC8* desIdp = aIdp->AsXmlL();
       
  6011 			CleanupStack::PushL(desIdp);
       
  6012 			retVal = pSenChunk->DescToChunk(*desIdp);
       
  6013 			CleanupStack::PopAndDestroy(desIdp);
       
  6014 			if(retVal == KErrNone)
       
  6015 				{
       
  6016 				if(iConnectionSession.Handle())
       
  6017 			    	{
       
  6018 			    	retVal = iConnectionSession.ReauthenticationNeeded(*pSenChunk);
       
  6019 			    	}
       
  6020 				else
       
  6021 					{
       
  6022 					retVal = KErrSenInternal;
       
  6023 					}
       
  6024 				
       
  6025 				if(retVal == KErrNone)
       
  6026 					{
       
  6027 					TPtrC8 identityProvider;
       
  6028 					retVal = pSenChunk->DescFromChunk(identityProvider);
       
  6029 					if(retVal == KErrNone)
       
  6030 						{
       
  6031 						CSenIdentityProvider* pIdentityProvider =
       
  6032 							CSenIdentityProvider::NewLC(KNullDesC8);
       
  6033 						CSenXmlReader* pXmlReader = CSenXmlReader::NewLC(KXmlParserMimeType);
       
  6034 						pXmlReader->SetContentHandler( *pIdentityProvider );
       
  6035 						pIdentityProvider->SetReader(*pXmlReader);
       
  6036 	
       
  6037 						TInt leaveCode(KErrNone);
       
  6038 						TRAP( leaveCode, pIdentityProvider->ParseL( identityProvider ); )
       
  6039 						                    
       
  6040 						CleanupStack::PopAndDestroy(pXmlReader);
       
  6041 						if ( leaveCode != KErrNone )
       
  6042 							{
       
  6043 							retVal = KErrSenInternal;
       
  6044 							CleanupStack::PopAndDestroy(pIdentityProvider);
       
  6045 							}
       
  6046 						else
       
  6047 							{
       
  6048 							// Store provider Id before registering new IDP (in case it gets deleted by manager)
       
  6049 							TPtrC8 providerId = pIdentityProvider->ProviderID();
       
  6050 							HBufC8* pProviderIdBuf = providerId.AllocLC();
       
  6051 							retVal = iManager.RegisterIdentityProviderL(pIdentityProvider);
       
  6052 							// Ownership transfered to manager
       
  6053 							CleanupStack::Pop(2); //pProviderIdBuf, pIdentityProvider
       
  6054 							CleanupStack::PushL(pProviderIdBuf);
       
  6055 							if(retVal == KErrNone)
       
  6056 								{
       
  6057 								// Retrieve new IDP and update reference
       
  6058 								CSenWSDescription* pPattern = CSenWSDescription::NewLC();
       
  6059 								pPattern->SetEndPointL(*pProviderIdBuf);
       
  6060 								CSenIdentityProvider* connIdp = ((MSenCoreServiceManager&)iManager).IdentityProviderL(*pPattern);
       
  6061 								CleanupStack::PopAndDestroy(pPattern);
       
  6062 								if(connIdp)
       
  6063 									{
       
  6064 									aIdp = connIdp;
       
  6065 									}
       
  6066 								}
       
  6067 							CleanupStack::PopAndDestroy(pProviderIdBuf);
       
  6068 							}
       
  6069 						}
       
  6070 					}
       
  6071 				}
       
  6072 			}
       
  6073 			CleanupStack::PopAndDestroy(pSenChunk);
       
  6074 			CleanupStack::PopAndDestroy(chunkNameDes);
       
  6075 		}
       
  6076 	return retVal;
       
  6077 	}
       
  6078 
       
  6079 CSenClientMessage* CSenClientMessage::NewL( const RMessage2& aMessage, MSenRemoteServiceConsumer* apConsumer )
       
  6080     {
       
  6081     CSenClientMessage* pOperation = NewLC(aMessage, apConsumer);
       
  6082     CleanupStack::Pop();
       
  6083     return pOperation;
       
  6084     }
       
  6085 
       
  6086 CSenClientMessage* CSenClientMessage::NewLC( const RMessage2& aMessage, MSenRemoteServiceConsumer* apConsumer )
       
  6087     {
       
  6088     CSenClientMessage* pOperation = new (ELeave) CSenClientMessage();
       
  6089     CleanupStack::PushL(pOperation);
       
  6090     pOperation->ConstructL(aMessage, apConsumer);
       
  6091     return pOperation;
       
  6092     }
       
  6093 
       
  6094 CSenClientMessage* CSenClientMessage::NewL( const RMessage2& aMessage, MSenRemoteServiceConsumer* apConsumer, MSenTransport& aTransport )
       
  6095     {
       
  6096     CSenClientMessage* pOperation = NewLC(aMessage, apConsumer, aTransport);
       
  6097     CleanupStack::Pop();
       
  6098     return pOperation;
       
  6099     }
       
  6100 
       
  6101 CSenClientMessage* CSenClientMessage::NewLC( const RMessage2& aMessage, MSenRemoteServiceConsumer* apConsumer, MSenTransport& aTransport )
       
  6102     {
       
  6103     CSenClientMessage* pOperation = new (ELeave) CSenClientMessage();
       
  6104     CleanupStack::PushL(pOperation);
       
  6105     pOperation->ConstructL(aMessage, apConsumer, aTransport);
       
  6106     return pOperation;
       
  6107     }
       
  6108 
       
  6109 
       
  6110 void CSenClientMessage::ConstructL(const RMessage2& aMessage, MSenRemoteServiceConsumer* apConsumer)
       
  6111     {
       
  6112     iMessage = aMessage;
       
  6113     ipConsumer = apConsumer;
       
  6114     ipChunkName = NULL;
       
  6115     }
       
  6116 
       
  6117 void CSenClientMessage::ConstructL(const RMessage2& aMessage, 
       
  6118                                    MSenRemoteServiceConsumer* apConsumer,
       
  6119                                    MSenTransport& aTransport)
       
  6120     {
       
  6121     ConstructL(aMessage, apConsumer);
       
  6122     MSenProperties& p = aTransport.PropertiesL();
       
  6123     /*
       
  6124     CSenLayeredTransportProperties* ctxProperties = NULL;
       
  6125     if( p.PropertiesClassType() == MSenProperties::ESenLayeredTransportProperties ||
       
  6126         p.PropertiesClassType() == MSenProperties::ESenLayeredHttpTransportProperties ||
       
  6127         p.PropertiesClassType() == MSenProperties::ESenLayeredVtcpTransportProperties)
       
  6128         {
       
  6129         CSenLayeredXmlProperties* properties = (CSenLayeredTransportProperties*)&p;
       
  6130         ctxProperties = (CSenLayeredTransportProperties*)properties->CloneL();
       
  6131         }
       
  6132     else
       
  6133         {        
       
  6134         ctxProperties = CSenLayeredTransportProperties::NewL();    
       
  6135         }
       
  6136     ipMessageContext = CSenMessageContext::NewL( SenContext::EOutgoing, ctxProperties );
       
  6137     */
       
  6138     TInt error(KErrNone);
       
  6139     ipMessageContext = CSenMessageContext::NewL( SenContext::EOutgoing, p.Clone(error) );
       
  6140     User::LeaveIfError(error);
       
  6141     }
       
  6142     
       
  6143 CSenClientMessage::CSenClientMessage()
       
  6144     {
       
  6145     }
       
  6146     
       
  6147 TInt CSenClientMessage::CtxId()
       
  6148     {
       
  6149     TInt ctxId = KErrNotFound;
       
  6150     if( ipMessageContext )  
       
  6151         {      
       
  6152         TInt leaveCode( KErrNone );   
       
  6153         CSenChunk* pChunk = NULL;
       
  6154         TRAP( leaveCode, pChunk = ipMessageContext->ChunkL(); )
       
  6155         if( !leaveCode && pChunk )
       
  6156             {
       
  6157             ctxId = pChunk->ChunkHeader().ContextId();                
       
  6158             }
       
  6159         }
       
  6160     return ctxId;        
       
  6161     }
       
  6162     
       
  6163 CSenClientMessage::~CSenClientMessage()
       
  6164     {
       
  6165     delete ipMessageContext;
       
  6166     ipMessageContext = NULL;
       
  6167     iBinaryDataArray.ResetAndDestroy();
       
  6168     }
       
  6169 
       
  6170 RMessage2& CSenClientMessage::RMessage()
       
  6171     {
       
  6172     return iMessage;
       
  6173     }
       
  6174     
       
  6175 MSenRemoteServiceConsumer* CSenClientMessage::Consumer()
       
  6176     {
       
  6177     return ipConsumer;
       
  6178     }
       
  6179     
       
  6180 MSenMessageContext& CSenClientMessage::MessageContext()
       
  6181     {
       
  6182     return *ipMessageContext;
       
  6183     }
       
  6184 
       
  6185 RPointerArray<CSenBinaryData>& CSenClientMessage::BinaryDataArray()
       
  6186     {
       
  6187     return iBinaryDataArray;
       
  6188     }
       
  6189 
       
  6190 CSenBinaryData* CSenBinaryData::NewL(RChunk& aChunk, TDesC8& aCid, TInt aOffset, TInt aSize)
       
  6191     {
       
  6192     CSenBinaryData* pSelf = CSenBinaryData::NewLC(aChunk, aCid, aOffset, aSize);
       
  6193     CleanupStack::Pop(pSelf);
       
  6194     return pSelf;
       
  6195     }
       
  6196     
       
  6197 CSenBinaryData* CSenBinaryData::NewLC(RChunk& aChunk, TDesC8& aCid, TInt aOffset, TInt aSize)
       
  6198     {
       
  6199     CSenBinaryData* pSelf = new (ELeave) CSenBinaryData(aOffset, aSize);
       
  6200     CleanupStack::PushL(pSelf);
       
  6201     pSelf->BaseConstructL(aChunk, aCid);
       
  6202     return pSelf;
       
  6203     }
       
  6204     
       
  6205 CSenBinaryData* CSenBinaryData::NewL(RFs& aFs, RFile& aFile, TDesC8& aCid, TInt aOffset, TInt aSize)
       
  6206     {
       
  6207     CSenBinaryData* pSelf = CSenBinaryData::NewLC(aFs, aFile, aCid, aOffset, aSize);
       
  6208     CleanupStack::Pop(pSelf);
       
  6209     return pSelf;
       
  6210     }
       
  6211     
       
  6212 CSenBinaryData* CSenBinaryData::NewLC(RFs& aFs, RFile& aFile, TDesC8& aCid, TInt aOffset, TInt aSize)
       
  6213     {
       
  6214     CSenBinaryData* pSelf = new (ELeave) CSenBinaryData(aOffset, aSize);
       
  6215     CleanupStack::PushL(pSelf);
       
  6216     pSelf->BaseConstructL(aFs, aFile, aCid);
       
  6217     return pSelf;
       
  6218     }
       
  6219     
       
  6220 CSenBinaryData::~CSenBinaryData()
       
  6221     {
       
  6222     iFs.Close();
       
  6223     iFile.Close();
       
  6224     iChunk.Close();
       
  6225     delete ipCid;
       
  6226     }
       
  6227         
       
  6228 RChunk& CSenBinaryData::Chunk()
       
  6229     {
       
  6230     return iChunk;
       
  6231     }
       
  6232     
       
  6233 RFile& CSenBinaryData::File()
       
  6234     {
       
  6235     return iFile;
       
  6236     }
       
  6237     
       
  6238 TDesC8& CSenBinaryData::Cid()
       
  6239     {
       
  6240     return *ipCid;
       
  6241     }
       
  6242     
       
  6243 TInt CSenBinaryData::Offset()
       
  6244     {
       
  6245     return iOffset;
       
  6246     }
       
  6247     
       
  6248 TInt CSenBinaryData::Size()
       
  6249     {
       
  6250     return iSize;
       
  6251     }
       
  6252 
       
  6253 CSenBinaryData::TSenBinaryDataType CSenBinaryData::Type()
       
  6254     {
       
  6255     return iType;
       
  6256     }
       
  6257 
       
  6258 CSenBinaryData::CSenBinaryData(TInt aOffset, TInt aSize)
       
  6259 :   iOffset(aOffset),
       
  6260     iSize(aSize)
       
  6261     {
       
  6262     }
       
  6263         
       
  6264 void CSenBinaryData::BaseConstructL(RChunk& aChunk, TDesC8& aCid)
       
  6265     {
       
  6266     iChunk  = aChunk;
       
  6267     ipCid    = aCid.AllocL();
       
  6268     iType = EChunk;
       
  6269     }
       
  6270 
       
  6271 void CSenBinaryData::BaseConstructL(RFs& aFs, RFile& aFile, TDesC8& aCid)
       
  6272     {
       
  6273     iFs     = aFs;
       
  6274     iFile   = aFile;
       
  6275     ipCid    = aCid.AllocL();
       
  6276     iType = EFile;
       
  6277     }
       
  6278 
       
  6279 TFileOutgoingTransferProgress::TFileOutgoingTransferProgress( TInt aTxnId, TBool aIsIncoming, TInt aProgress, TBool aHasCidPostfix, TInt aCid, TInt aCid2 )
       
  6280     {
       
  6281     iTxnId = aTxnId;
       
  6282     iIsIncoming = aIsIncoming;
       
  6283     iProgress = aProgress;
       
  6284     iCid = aCid;
       
  6285     iCid2 = aCid2;
       
  6286     iHasCidPostfix = aHasCidPostfix;
       
  6287     }
       
  6288 // END OF FILE
       
  6289