webservices/wsconnection/src/senserviceconnectionimpl.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 #include <s32strm.h>
       
    21 #include <f32file.h>
       
    22 #include <e32property.h>
       
    23 
       
    24 #include "senserviceconnectionimpl.h"
       
    25 
       
    26 #include "sendebug.h"                 // internal Utils\inc - logging MACROs
       
    27 #include "senlogger.h"
       
    28 #include "senservicemanagerdefines.h" // internal Core\inc  - IPC enumerations, plus 
       
    29                                       // to include KServerUid3 for SEN.EXE SecureID 
       
    30                                       // (UID3) that can be nicely used as Property 
       
    31                                       // Category UID
       
    32 
       
    33 #include <SenServicePattern.h>
       
    34 #include <SenXmlServiceDescription.h>
       
    35 #include <SenXmlUtils.h>
       
    36 #include "SenHttpTransportProperties.h"
       
    37 #include <SenIdentityProvider.h>
       
    38 
       
    39 #include "senguidgen.h"  // internal: Utils\inc - the prefix length constant for WSF GUIDs
       
    40 #include "senchunk.h"
       
    41 #include "senmessagebase.h"
       
    42 
       
    43 #include "SenSoapEnvelope2.h"
       
    44 #include "SenParser.h"
       
    45 
       
    46 #include "senservicemanagerdefines.h"
       
    47 #include "SenBaseAttribute.h"
       
    48 #include <xmlengchunkcontainer.h>
       
    49 #include <xmlengfilecontainer.h>
       
    50 #include <xmlengserializer.h>
       
    51 #include "senconnagentserver.h"
       
    52 #include "senxmldebug.h"
       
    53 #include "senatomentry.h"
       
    54 
       
    55 
       
    56 namespace
       
    57     {
       
    58     const TInt KMaxChunkNumDecimals = 64;
       
    59     _LIT8(KIdentityProviderName, "IdentityProvider");
       
    60     _LIT8( KSenCidPostfix, "@example.org" );
       
    61     const TInt KMaxCidLength = 512;
       
    62     }
       
    63 
       
    64 #ifdef RD_SEN_ENABLE_USE_OF_WSD_IN_SC_FOR_HW_TARGET
       
    65 // in hardware, we can use static variable
       
    66 TInt CSenConnectionChunk::iServOpenChunkCount;   
       
    67 #endif    
       
    68 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewL(MSenServiceConsumer& aObserver,
       
    69                                                            const TDesC8& aContract)
       
    70     {
       
    71     CSenServiceConnectionImpl* pNew = NewLC(aObserver, aContract);
       
    72     CleanupStack::Pop();
       
    73     return(pNew) ;
       
    74     }
       
    75 
       
    76 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewLC(MSenServiceConsumer& aObserver,
       
    77                                                             const TDesC8& aContract)
       
    78     {
       
    79 
       
    80     CSenServiceConnectionImpl* pNew = new (ELeave) CSenServiceConnectionImpl(aObserver, NULL);
       
    81 
       
    82     CleanupStack::PushL(pNew);
       
    83 
       
    84 
       
    85     CSenXmlServiceDescription* pSD =
       
    86             CSenXmlServiceDescription::NewLC(KNullDesC8, aContract);
       
    87     pNew->ConstructL(*pSD);
       
    88     CleanupStack::PopAndDestroy(); // pServicePattern
       
    89     return pNew;
       
    90     }
       
    91 
       
    92 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewL(MSenServiceConsumer& aObserver,
       
    93                                                            MSenServiceDescription& aPattern)
       
    94     {
       
    95     CSenServiceConnectionImpl* pNew = NewLC(aObserver, aPattern);
       
    96     CleanupStack::Pop();
       
    97     return(pNew) ;
       
    98     }
       
    99 
       
   100 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewLC(MSenServiceConsumer& aObserver,
       
   101                                                             MSenServiceDescription& aPattern)
       
   102     {
       
   103     CSenServiceConnectionImpl* pNew =
       
   104                             new (ELeave) CSenServiceConnectionImpl(aObserver, NULL);
       
   105     CleanupStack::PushL(pNew);
       
   106     pNew->ConstructL(aPattern);
       
   107     return pNew;
       
   108     }
       
   109 
       
   110 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewL(MSenServiceConsumer& aObserver,
       
   111                                                            CSenServicePattern& aServicePattern)
       
   112     {
       
   113     CSenServiceConnectionImpl* pNew = NewLC(aObserver, aServicePattern);
       
   114     CleanupStack::Pop();
       
   115     return(pNew) ;
       
   116     }
       
   117 
       
   118 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewLC(MSenServiceConsumer& aObserver,
       
   119                                                             CSenServicePattern& aServicePattern)
       
   120     {
       
   121     CSenServiceConnectionImpl* pNew = new (ELeave) CSenServiceConnectionImpl(aObserver, NULL);
       
   122     CleanupStack::PushL(pNew);
       
   123     pNew->ConstructL(aServicePattern);
       
   124     return pNew;
       
   125     }
       
   126 
       
   127 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewL(MSenServiceConsumer& aConsumer,
       
   128                                                            const TDesC8& aContract,
       
   129                                                            MSenExtendedConsumerInterface& aExtendedConsumer)
       
   130     {
       
   131     CSenServiceConnectionImpl* pNew = NewLC(aConsumer, aContract, aExtendedConsumer);
       
   132     CleanupStack::Pop();
       
   133     return(pNew) ;
       
   134     }
       
   135 
       
   136 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewLC(MSenServiceConsumer& aConsumer,
       
   137                                                             const TDesC8& aContract,
       
   138                                                             MSenExtendedConsumerInterface& aExtendedConsumer)
       
   139     {
       
   140 
       
   141     CSenServiceConnectionImpl* pNew = new (ELeave) CSenServiceConnectionImpl(aConsumer, &aExtendedConsumer);
       
   142 
       
   143     CleanupStack::PushL(pNew);
       
   144 
       
   145 
       
   146     CSenXmlServiceDescription* pSD =
       
   147             CSenXmlServiceDescription::NewLC(KNullDesC8, aContract);
       
   148     pNew->ConstructL(*pSD);
       
   149     CleanupStack::PopAndDestroy(); // pServicePattern
       
   150     return pNew;
       
   151     }
       
   152 
       
   153 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewL(MSenServiceConsumer& aConsumer,
       
   154                                                                 MSenServiceDescription& aServiceDescription,
       
   155                                                            MSenExtendedConsumerInterface& aExtendedConsumer)
       
   156     {
       
   157 
       
   158     CSenServiceConnectionImpl* pNew = NewLC(aConsumer, aServiceDescription, aExtendedConsumer);
       
   159     CleanupStack::Pop();
       
   160     return(pNew) ;
       
   161     }
       
   162 
       
   163 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewLC(MSenServiceConsumer& aConsumer,
       
   164                                                                 MSenServiceDescription& aServiceDescription,
       
   165                                                                 MSenExtendedConsumerInterface& aExtendedConsumer)
       
   166     {
       
   167     CSenServiceConnectionImpl* pNew =
       
   168                             new (ELeave) CSenServiceConnectionImpl(aConsumer,&aExtendedConsumer);
       
   169     CleanupStack::PushL(pNew);
       
   170     pNew->ConstructL(aServiceDescription);
       
   171     return pNew;        
       
   172     }
       
   173 
       
   174 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewL(MSenServiceConsumer& aConsumer,
       
   175                                                            CSenServicePattern& aServicePattern,
       
   176                                                            MSenExtendedConsumerInterface& aExtendedConsumer)
       
   177     {
       
   178     CSenServiceConnectionImpl* pNew = NewLC(aConsumer, aServicePattern, aExtendedConsumer);
       
   179     CleanupStack::Pop();
       
   180     return(pNew) ;
       
   181     }
       
   182 
       
   183 CSenServiceConnectionImpl* CSenServiceConnectionImpl::NewLC(MSenServiceConsumer& aConsumer,
       
   184                                                             CSenServicePattern& aServicePattern,
       
   185                                                             MSenExtendedConsumerInterface& aExtendedConsumer)
       
   186     {
       
   187     CSenServiceConnectionImpl* pNew = new (ELeave) CSenServiceConnectionImpl(aConsumer,&aExtendedConsumer);
       
   188     CleanupStack::PushL(pNew);
       
   189     pNew->ConstructL(aServicePattern);
       
   190     return pNew;
       
   191     }
       
   192 
       
   193 void CSenServiceConnectionImpl::ConstructL(MSenServiceDescription& aSD)
       
   194     {
       
   195 
       
   196     CSenElement& sdAsElement = ((CSenXmlServiceDescription&)aSD).AsElement();
       
   197 
       
   198     // Check if this is an internal service connection:
       
   199     const TDesC8* pInternal = sdAsElement.AttrValue( KSenAttrInternalSC );
       
   200     if( pInternal )
       
   201         {
       
   202         iIsInternalSC = ETrue;
       
   203         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"This is 'internal SC' => Will NOT create CSenConnectionStatusObserver.");
       
   204         delete SenXmlUtils::RemoveAttributeL(sdAsElement, KSenAttrInternalSC);
       
   205         iDispatcherEnabled = EFalse;
       
   206         }
       
   207     else // not internal, but starndard SC
       
   208         {
       
   209         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"This is normal SC => Creating CSenConnectionStatusObserver.");
       
   210 #ifdef RD_SEN_SC_MSG_DISPATCHER_ENABLED
       
   211         // Dispatcher is enabled ONLY IF the feature is NOT DISABLED AT COMPILER LEVEL:
       
   212         iDispatcherEnabled = ETrue; // ==> Default to using the dispatcher with any "normal" SC
       
   213 #endif // RD_SEN_SC_MSG_DISPATCHER_ENABLED
       
   214         }
       
   215 
       
   216     // Check if dispatcher is EXPLICITELY DISABLED (no matter if this is internal or not)
       
   217     const TDesC8* pDispatcherDisabled = sdAsElement.AttrValue( KSenAttrDisableDispatcherSC );
       
   218     if( pDispatcherDisabled )
       
   219         {
       
   220         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"Dispatcher is EXPLICITELY DISABLED for this SC.");
       
   221         delete SenXmlUtils::RemoveAttributeL(sdAsElement, KSenAttrDisableDispatcherSC );
       
   222         // Dispatcher is NOW EXPLICITELY DISABLED
       
   223         iDispatcherEnabled = EFalse; 
       
   224         }
       
   225 
       
   226     ipInitPatternAsXml = aSD.AsXmlL();
       
   227     if( aSD.DescriptionClassType() == MSenServiceDescription::EServicePattern )
       
   228         {
       
   229         CSenServicePattern* pServicePattern = (CSenServicePattern*)&aSD;
       
   230         ipInitConsumerPolicyAsXml = pServicePattern->ConsumerPolicyAsXmlL();
       
   231         }
       
   232         
       
   233         
       
   234     ipRegistrationTimer = CSenRegistrationTimer::NewL( *this );        
       
   235 /*    
       
   236 #ifdef _SENDEBUG
       
   237     TPtrC8 frameworkID = aSD.FrameworkId();
       
   238     TPtrC8 endpoint    = aSD.Endpoint();
       
   239     TPtrC8 contract    = aSD.Contract();
       
   240     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
       
   241     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel , _L8("- FrameworkID: %S"), &frameworkID ));
       
   242     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel , _L8("- Endpoint:    %S"), &endpoint ));
       
   243     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel , _L8("- Contract:    %S"), &contract ));
       
   244     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
       
   245 #endif //_SENDEBUG           
       
   246 */
       
   247 #ifndef RD_SEN_SC_PROXY_ENABLED_BY_DEFAULT
       
   248     ConnectL(); 
       
   249 // #else // ConnectL occurs on  "proxy" / factory  -level
       
   250 #endif    
       
   251     }
       
   252 
       
   253 
       
   254 void CSenServiceConnectionImpl::ConnectL()
       
   255     {
       
   256     ipSessionId = HBufC::NewL(KSenUuidMaxLength); 
       
   257     ipChunkName = HBufC::NewL(KSenUuidMaxLength+KMaxChunkNumDecimals);
       
   258 
       
   259     iSessionIdBuffer.Set(ipSessionId->Des());
       
   260 
       
   261     TLSLOG_OPEN(KSenServiceConnectionLogChannel, KSenServiceConnectionLogLevel, KSenServiceConnectionLogDir, KSenServiceConnectionLogFile);
       
   262     TInt connErr = iConnection.Connect();
       
   263     TInt connAttemp(0); // max 5 attempts are allowed (KMaxConnectionOpeningAttempts)
       
   264     while ( (connErr == KErrServerTerminated
       
   265                      ||
       
   266              connErr == KErrServerBusy)
       
   267                      &&
       
   268              connAttemp < KSenMaxClientConnectionOpeningAttempts )
       
   269         {
       
   270 //        TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel," - Server terminated/busy/max_conns => waiting.");
       
   271         User::After(1000000); // wait for a second if server has been shut down  
       
   272 //        TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel," - Wait is over.");
       
   273         connErr = iConnection.Connect();
       
   274         connAttemp++;
       
   275         }
       
   276     if ( connErr != KErrNone )
       
   277         {
       
   278         User::Leave( connErr );
       
   279         }
       
   280     
       
   281     if( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
   282         {
       
   283         TInt iShareAuto = iConnection.ShareAuto();
       
   284         if(iShareAuto != KErrNone )
       
   285             {
       
   286             User::Leave( iShareAuto );
       
   287             }
       
   288         }
       
   289         
       
   290     iConnectionID = iConnection.ConnectionID();
       
   291     iConnection.SetChannel(KSenServiceConnectionLogChannelBase+iConnectionID);   
       
   292     iTlsLogStatusChannel = KSenServiceConnectionStatusLogChannelBase + iConnectionID;
       
   293 
       
   294 #ifdef _SENDEBUG   
       
   295     RProcess process; 
       
   296     RThread thread;
       
   297     TFileName logFile;
       
   298     logFile.Append( KSenServiceConnectionLogFile().Left(KSenServiceConnectionLogFile().Length()-4) ); // exclude ".log" file extension
       
   299     logFile.AppendNum( iConnectionID );
       
   300     logFile.Append( KSenUnderline );
       
   301     logFile.Append( process.Name().Left(32));
       
   302     logFile.Append( KSenUnderline );
       
   303     logFile.Append( thread.Name().Left(20));
       
   304     logFile.Append( KSenServiceConnectionLogFile().Right(4) ); // postfix with ".log" file extension
       
   305     
       
   306     
       
   307 //    KSenServiceConnectionChannelBase
       
   308     TLSLOG_OPEN(KSenServiceConnectionLogChannelBase+iConnectionID, KSenServiceConnectionLogLevel, KSenServiceConnectionLogDir, logFile);
       
   309     // Open connection to the file logger server
       
   310     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,"CSenServiceConnection::ConstructL - Log file opened");
       
   311     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- About to initialize service connection");
       
   312     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- Connection ID: (%d)"), iConnectionID));
       
   313 
       
   314     logFile.Zero();
       
   315     logFile.Append( KSenServiceConnectionStatusLogFile().Left(KSenServiceConnectionStatusLogFile().Length()-4) ); // exclude ".log" file extension
       
   316     logFile.AppendNum( iConnectionID );
       
   317     logFile.Append( KSenUnderline );
       
   318     logFile.Append( process.Name().Left(32));
       
   319     logFile.Append( KSenUnderline );
       
   320     logFile.Append( thread.Name().Left(20));
       
   321     logFile.Append( KSenServiceConnectionStatusLogFile().Right(4) ); // postfix with ".log" file extension
       
   322     TLSLOG_OPEN( iTlsLogStatusChannel, KSenServiceConnectionStatusLogLevel, KSenServiceConnectionLogDir, logFile );
       
   323 
       
   324 
       
   325     TLSLOG_OPEN(KSenMessagesLogChannel, KSenMessagesLogLevel, KSenMessages, KSenMessagesLog);
       
   326 #endif // _SENDEBUG    
       
   327 
       
   328     iFragment = CSenBaseFragment::NewL(KServiceConnectionElementLocalName);
       
   329      
       
   330     InitializeL( /*aSD*/ );
       
   331 
       
   332     if( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
   333         {
       
   334         RThread aThread;
       
   335         iOwnerThreadId = aThread.Id();
       
   336         ipSenServiceDispatcher = CSenServiceDispatcher::NewL(iConnection,iConnectionID);
       
   337         ipSenServiceDispatcher->SetOwnerThreadId(iOwnerThreadId);
       
   338         TInt dispatcherThreadID = ipSenServiceDispatcher->GetDispactherThreadId();
       
   339         //    ipSenUnderTakerWaiter = CSenUnderTakerWaiter::NewL(this,dispatcherThreadID);
       
   340         //    ipSenUnderTakerWaiter->StartWaiter();
       
   341         }
       
   342     }
       
   343 
       
   344 void CSenServiceConnectionImpl::SetConsumer( MSenServiceConsumer& aConsumer, MSenExtendedConsumerInterface* apExtConsumer )
       
   345     {
       
   346     iObserver = &aConsumer;
       
   347     ipExtendedConsumerInterface = apExtConsumer;
       
   348     }
       
   349    
       
   350 void CSenServiceConnectionImpl::Consumer( MSenServiceConsumer*& aConsumer, MSenExtendedConsumerInterface*& apExtConsumer )
       
   351     {
       
   352     aConsumer = iObserver;
       
   353     apExtConsumer = ipExtendedConsumerInterface;
       
   354     }   
       
   355 
       
   356 TPtrC8 CSenServiceConnectionImpl::InitDescription()
       
   357     {
       
   358     return *ipInitPatternAsXml;
       
   359     }
       
   360 CSenServiceConnectionImpl::CSenServiceConnectionImpl(MSenServiceConsumer& aObserver,
       
   361                                                      MSenExtendedConsumerInterface* aExtendedConsumerInteface)
       
   362  :  iConnection(&iLog),
       
   363     iObserver(&aObserver),
       
   364     iInBuf(NULL),
       
   365     iInBuffer(NULL,0),
       
   366     iOutBuf(NULL),
       
   367     iOutBuffer(NULL,0),
       
   368     iInitialized(EFalse),
       
   369     iFragment(NULL),
       
   370     iResponseLength(0),
       
   371     iErrorNumber(0),
       
   372     iErrorNumberBuffer(NULL, 0),
       
   373     iTxnId(0),
       
   374     iTxnIdBuffer(NULL, 0),
       
   375     iChunkMap(NULL),
       
   376     ipSessionId(NULL),
       
   377     iSessionIdBuffer(NULL, 0),
       
   378     iChunkNameNumber(0),
       
   379     ipChunkName(NULL),
       
   380     iResponse(NULL),
       
   381     ipInitChunk(NULL),
       
   382     ipCompleteServerMsgsOnOff(NULL),
       
   383     iConnectionID( KErrNotReady ),
       
   384     //iTlsLogChannel( KSenServiceConnectionLogChannelBase )
       
   385     iTlsLogStatusChannel( KSenServiceConnectionStatusLogChannelBase ),
       
   386     iConnectionAgentCallbackInitialized(EFalse),
       
   387     iRegisterFileObserverDone(EFalse),
       
   388     iRegisterMobilityObserverDone(EFalse),
       
   389     iRegisterAuthObserverDone(EFalse),
       
   390     iRegisterCoBrandingObserverDone(EFalse),
       
   391     iReauthenticationNeeded(EFalse),
       
   392     ipExtendedConsumerInterface(aExtendedConsumerInteface),
       
   393 #ifdef __ENABLE_ALR__
       
   394     iMobiltyObserver(NULL),
       
   395 #endif
       
   396     iCancelSession(EFalse),
       
   397     iIsInternalSC(EFalse),
       
   398     iDispatcherEnabled(EFalse),
       
   399     ipRegistrationTimer(NULL)
       
   400     {
       
   401     CActiveScheduler::Add(this);
       
   402     }
       
   403 
       
   404 CSenServiceConnectionImpl::~CSenServiceConnectionImpl()
       
   405     {
       
   406     delete ipRegistrationTimer;
       
   407     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::~CSenServiceConnectionImpl")));
       
   408     CSenServiceConnectionImpl::Cancel(); // Causes call to DoCancel()
       
   409 
       
   410 #if !defined (RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS) && !defined( RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS ) // pub&sub is not in use for outgoing file progress
       
   411     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::~CSenServiceConnectionImpl(): RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == FALSE")));
       
   412     if (ipAuthProvider || iFilesObserver || ipCoBrandingObserver)
       
   413 #else // RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == TRUE
       
   414     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::~CSenServiceConnectionImpl(): RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == TRUE")));
       
   415     if (ipAuthProvider || ipCoBrandingObserver) // iFilesObserver is not used
       
   416 #endif // RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS end
       
   417         {
       
   418         CSenConnAgentServer::Close();
       
   419         iConnectionAgentCallbackInitialized = EFalse;
       
   420         }
       
   421 
       
   422 #ifdef __ENABLE_ALR__        
       
   423     if (iMobiltyObserver)
       
   424         {
       
   425         CSenConnAgentServer::Close();
       
   426         iRegisterMobilityObserverDone = EFalse;
       
   427         }
       
   428 #endif //__ENABLE_ALR__
       
   429 
       
   430 //    delete ipSenUnderTakerWaiter;
       
   431     delete ipSenServiceDispatcher;
       
   432 
       
   433     if ( iAsyncOpsArray )
       
   434         {
       
   435         TInt count(iAsyncOpsArray->Count());
       
   436         for ( TInt i = 0; i < count; i++ )
       
   437             {
       
   438             CSenAsyncOperation* pOp = (*iAsyncOpsArray)[i];
       
   439             if ( pOp )
       
   440                 {
       
   441                 pOp->iActive = NULL;
       
   442                 pOp->Deque();
       
   443                 delete pOp;
       
   444                 }
       
   445             }
       
   446         iAsyncOpsArray->Close();
       
   447         delete iAsyncOpsArray;
       
   448         }
       
   449 
       
   450     if(iChunkMap)
       
   451         {
       
   452         iChunkMap->Reset();
       
   453         delete iChunkMap;
       
   454         }
       
   455 
       
   456     delete iInBuf;
       
   457     delete iOutBuf;
       
   458     delete iFragment;
       
   459     delete ipSessionId;
       
   460     delete ipChunkName;
       
   461     delete ipInitPatternAsXml;
       
   462     delete ipInitConsumerPolicyAsXml;
       
   463     delete ipInitChunk;
       
   464     delete ipCompleteServerMsgsOnOff;
       
   465     
       
   466     // Close the log file and the connection to the server.
       
   467     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("Log file closed.")));
       
   468     TLSLOG_CLOSE (KSenServiceConnectionLogChannelBase+iConnectionID);
       
   469     TLSLOG_CLOSE(KSenServiceConnectionLogChannel);
       
   470     TLSLOG_CLOSE( iTlsLogStatusChannel );
       
   471     TLSLOG_CLOSE( KSenMessagesLogChannel );
       
   472 
       
   473     iConnection.Close();
       
   474     delete ipConnectionStatusObserver;
       
   475     delete ipFileProgressObserver;
       
   476     }
       
   477 
       
   478 
       
   479 TPtrC CSenServiceConnectionImpl::SessionID()
       
   480     {
       
   481     if(ipSessionId)
       
   482         {
       
   483         return *ipSessionId;
       
   484         }
       
   485     else
       
   486         {
       
   487         return KNullDesC();
       
   488         }
       
   489     }
       
   490 
       
   491 
       
   492 TInt CSenServiceConnectionImpl::RegisterAndSubscribeFileProgressObserversL()
       
   493     {
       
   494     TInt retCode( KErrNone );
       
   495     if(iFilesObserver && !iRegisterFileObserverDone)
       
   496     	{
       
   497     	
       
   498 #ifndef RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS // pub&sub not in use for outgoing file progress
       
   499         TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::RegisterAndSubscribeFileProgressObserversL: RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == FALSE")));
       
   500     	retCode = RegisterFilesObserver();
       
   501 #else // RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == TRUE
       
   502         TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::RegisterAndSubscribeFileProgressObserversL: RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS == TRUE")));
       
   503     	ipFileProgressObserver = CSenFileProgressObserver::NewL( *iFilesObserver, iConnectionID, iDispatcherEnabled, ipSenServiceDispatcher, ChunkMapL() );
       
   504 
       
   505     #ifdef RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS
       
   506         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel, "CSenServiceConnectionImpl::RegisterAndSubscribeFileProgressObserversL: RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS == TRUE");
       
   507         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel, "=> calling RegisterFilesObserver()");
       
   508         retCode = RegisterFilesObserver(); // MIXED MODE, using conn agent for SOAP progress..
       
   509     #else // RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS == FALSE
       
   510         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel, "CSenServiceConnectionImpl::RegisterAndSubscribeFileProgressObserversL: RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS == FALSE");
       
   511     #endif // RD_SEN_USE_CONNAGENT_FOR_SOAP_PROGRESS
       
   512 
       
   513 #endif // RD_SEN_USE_PUBSUB_FOR_OUTGOING_FILE_PROGRESS end 	
       
   514     	iRegisterFileObserverDone = ETrue; // register only once
       
   515     	}
       
   516     return retCode;
       
   517     }
       
   518     
       
   519 TInt CSenServiceConnectionImpl::SubmitL(CSenConnectionChunk& aClientOp)
       
   520     {
       
   521     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::SubmitL(CSenChunk)")));
       
   522     TInt retVal(KErrNone);
       
   523     
       
   524     iErrorNumber = 0;
       
   525     iErrorNumberBuffer.Set(reinterpret_cast<TUint8*>(&iErrorNumber),
       
   526                            sizeof(TInt),
       
   527                            sizeof(TInt));
       
   528 
       
   529     iTxnId = 0;
       
   530     iTxnIdBuffer.Set(reinterpret_cast<TUint8*>(&iTxnId),
       
   531                      sizeof(TInt),
       
   532                      sizeof(TInt));
       
   533 
       
   534     TRequestStatus status;
       
   535 
       
   536     iAsyncOpsCount++;
       
   537     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("CSenServiceConnectionImpl::SubmitL(CSenChunk) - iAsyncOpsCount: %d"), iAsyncOpsCount));
       
   538     iConnection.Transaction(status, iErrorNumberBuffer, iTxnIdBuffer, aClientOp);
       
   539     
       
   540     if ( aClientOp.HasBinaryDataArray() )
       
   541         {
       
   542         RegisterAndSubscribeFileProgressObserversL();
       
   543         retVal = MoveBinaryContainersToServer(aClientOp, aClientOp.BinaryDataArrayL());		//codescannerwarnings
       
   544         }
       
   545     else if (aClientOp.HasSharedFileHandle())
       
   546        {
       
   547        	retVal = MoveFileChunkHandleToServer(aClientOp) ;
       
   548        }
       
   549 
       
   550     // Pass handle to SendMsgAndReceiveTxnId, so that RHandleBase can be re-used:
       
   551     retVal = iConnection.SendMsgAndReceiveTxnId( aClientOp );
       
   552     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Waiting for response.)");
       
   553 
       
   554     User::WaitForRequest(status);   // Wait here until response is received (TXN == COMPLETE)
       
   555     iAsyncOpsCount--;
       
   556 
       
   557     switch(status.Int())
       
   558         {
       
   559         case ESenServRequestResponsed:
       
   560             {
       
   561             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL - ESenServRequestResponsed");
       
   562             retVal = iErrorNumber;
       
   563             }
       
   564             break;
       
   565 
       
   566         case ESenReAuthAndResendNeeded:
       
   567             {
       
   568             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL: ESenReAuthAndResendNeeded");
       
   569             
       
   570             if ( iAsyncOpsCount >= KAsyncMessageSlots)
       
   571                 {
       
   572                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Cannot re-init, max simultaneous async ops on-going: KErrSenServiceConnectionBusy");
       
   573                 retVal = KErrSenServiceConnectionBusy;
       
   574                 }
       
   575             else
       
   576                 {
       
   577                 aClientOp.ChunkHeader().SetDoInitBeforeSending(ETrue);
       
   578                 if(ipAuthProvider)
       
   579                 	{
       
   580                 	if(iReauthenticationNeeded)
       
   581                 		{
       
   582                 		TInt lerror(KErrNone);
       
   583                 		TRAP(lerror, ReauthNeededL(KNullDesC8)); // ignore errors
       
   584                 		}
       
   585                 	else
       
   586                 		{
       
   587                 		iReauthenticationNeeded = ETrue;
       
   588                 		}
       
   589                 	}
       
   590                 retVal = SubmitL(aClientOp); 
       
   591                 iReauthenticationNeeded = EFalse;
       
   592                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL: ESenReAuthAndResendNeeded Completed");
       
   593                 return retVal;
       
   594                 }
       
   595             }
       
   596             break;
       
   597 
       
   598         case ESenResendNeeded:
       
   599             {
       
   600             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL: ESenResendNeeded");
       
   601             
       
   602             if ( iAsyncOpsCount >= KAsyncMessageSlots)
       
   603                 {
       
   604                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Cannot re-send, max simultaneous async ops on-going: KErrSenServiceConnectionBusy");
       
   605                 retVal = KErrSenServiceConnectionBusy;
       
   606                 }
       
   607             else
       
   608                 {
       
   609                 return SubmitL(aClientOp);
       
   610                 }
       
   611             }
       
   612             break;
       
   613 
       
   614         case ESenInternalError:
       
   615             {
       
   616             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL - ESenInternalError");
       
   617             retVal = KErrSenInternal;
       
   618             }
       
   619         default:
       
   620             {
       
   621             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL - default");
       
   622 #ifdef _SENDEBUG                
       
   623             if(status.Int() == KErrPermissionDenied)
       
   624                 {
       
   625                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL: default - KErrPermissionDenied");
       
   626                 }
       
   627             else
       
   628                 {
       
   629                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"SubmitL: default - unexpected error.");
       
   630                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("Last received error from server: (%d)"), iErrorNumber));
       
   631                 }
       
   632             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("SubmitL, request status.Int(): (%d)"), status.Int()));
       
   633             
       
   634 #endif // _SENDEBUG             
       
   635             // WSF does not generalize errors:
       
   636             retVal = status.Int();
       
   637             }
       
   638             break;
       
   639         }
       
   640     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::SubmitL(CSenChunk) Completed")));
       
   641     return retVal;
       
   642     }
       
   643 
       
   644 TInt CSenServiceConnectionImpl::ResponseFromChunk(CSenChunk& aClientOp,
       
   645                                                   HBufC8*& aResponseTo)
       
   646     {
       
   647     TInt leaveCode(KErrNone); // handle OOM case:
       
   648     // Read response message, SOAP fault OR error
       
   649     TPtrC8 response;
       
   650     TInt retVal = aClientOp.DescFromChunk(response); // if handle is closed, this will panic.
       
   651     if(retVal==KErrNone)
       
   652         {
       
   653         // It is *mandatory* tor TRAP AllocL(), since HandleBase MUST be closed(!):
       
   654         TRAP( leaveCode, aResponseTo = response.AllocL(); )
       
   655         }
       
   656     
       
   657     if(leaveCode!=KErrNone)
       
   658         {
       
   659         // OOM occured
       
   660         retVal = leaveCode;
       
   661         }
       
   662         
       
   663     return retVal;
       
   664     }
       
   665 
       
   666 TInt CSenServiceConnectionImpl::SubmitL(const TDesC8& aRequest,
       
   667                                         HBufC8*& aResponseTo )
       
   668     {
       
   669     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL");
       
   670 
       
   671     TInt retVal = CheckConnection();
       
   672     
       
   673     if(retVal == KErrNone)
       
   674         {
       
   675         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
   676         if( pOperation )
       
   677         	{
       
   678 	        CleanupStack::PushL( pOperation );        	    
       
   679 #ifdef _SENDEBUG
       
   680 	        pOperation->SetLogger( &iLog );
       
   681 #endif //_SENDEBUG  
       
   682 	        retVal = pOperation->CreateChunk();
       
   683 	        if (retVal == KErrNone)
       
   684 	            {
       
   685 	            retVal = pOperation->DescToChunk(aRequest);
       
   686 	            if (retVal == KErrNone)
       
   687 	                {
       
   688 	                retVal = SubmitL(*pOperation);
       
   689 	                if (retVal != KErrNone && retVal != KErrSenSoapFault)
       
   690 	                    {
       
   691 	                    aResponseTo = NULL;
       
   692 	                    }
       
   693 	                else
       
   694 	                    {
       
   695 	                    retVal = ResponseFromChunk(*pOperation, aResponseTo);
       
   696 	                    }
       
   697 	                }
       
   698 	            }
       
   699 	        CleanupStack::PopAndDestroy(pOperation);
       
   700         	}
       
   701         	
       
   702 	     else
       
   703 	     	{
       
   704 #ifdef _SENDEBUG        
       
   705 				TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL - KErrServerBusy");
       
   706 #endif // _SENDEBUG
       
   707 			return KErrServerBusy;    	
       
   708 	     	}
       
   709 
       
   710         }
       
   711 #ifdef _SENDEBUG        
       
   712     else
       
   713     	{
       
   714         // error occured in CheckConnection()  	
       
   715         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("CSenServiceConnectionImpl::SubmitL - CheckConnection failed, error(%d)"), retVal ));
       
   716     	}	 
       
   717 #endif // _SENDEBUG    	
       
   718         
       
   719 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL Completed");
       
   720     return retVal;
       
   721     }
       
   722 
       
   723 TInt  CSenServiceConnectionImpl::SubmitL(RFile& aFile, HBufC8*& aResponse)
       
   724     {
       
   725     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL");
       
   726 
       
   727     TInt retVal = CheckConnection();
       
   728     
       
   729     if(retVal == KErrNone)
       
   730         {
       
   731         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName() ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
   732         if( pOperation )
       
   733         	{
       
   734 	        CleanupStack::PushL( pOperation );        	    
       
   735 	        pOperation->SetLogger(&iLog);
       
   736 	        retVal = pOperation->CreateChunk();
       
   737 	        if (retVal == KErrNone)
       
   738 	            {
       
   739 	            pOperation->HasSharedFileHandle(ETrue);
       
   740 	        	iSharedFileHandle = aFile;
       
   741 	          	retVal = SubmitL(*pOperation);
       
   742                 if (retVal != KErrNone && retVal != KErrSenSoapFault)
       
   743                     {
       
   744                     aResponse = NULL;
       
   745                     }
       
   746                 else
       
   747                     {
       
   748                     retVal = ResponseFromChunk(*pOperation, aResponse);
       
   749                     }
       
   750 	            }
       
   751 	        CleanupStack::PopAndDestroy(pOperation);
       
   752         	}
       
   753         	
       
   754 	     else
       
   755 	     	{
       
   756 #ifdef _SENDEBUG        
       
   757 				TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL - KErrServerBusy");
       
   758 #endif // _SENDEBUG
       
   759 			return KErrServerBusy;    	
       
   760 	     	}
       
   761 
       
   762         }
       
   763 #ifdef _SENDEBUG        
       
   764     else
       
   765     	{
       
   766         // error occured in CheckConnection()  	
       
   767         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("CSenServiceConnectionImpl::SubmitL - CheckConnection failed, error(%d)"), retVal ));
       
   768     	}	 
       
   769 #endif // _SENDEBUG    	
       
   770         
       
   771 
       
   772     return retVal;
       
   773     }
       
   774 	
       
   775 // Setter
       
   776 TInt CSenServiceConnectionImpl::CompleteServerMessagesOnOff( const TBool& aCompleteOnOff )
       
   777     {
       
   778     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::CompleteServerMessagesOnOff");
       
   779     if( !iInitialized )
       
   780         {
       
   781         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- SC is not yet initialized; saving facet value for post CTR use.");
       
   782         //TInt leaveCode(KErrNone);
       
   783         delete ipCompleteServerMsgsOnOff; // to prevent memory leaks in sequal calls
       
   784         ipCompleteServerMsgsOnOff = NULL;
       
   785         //TRAP( leaveCode, ipCompleteServerMsgsOnOff = new (ELeave) TBool(aCompleteOnOff); )
       
   786         // if ( leaveCode )
       
   787         ipCompleteServerMsgsOnOff = new TBool(aCompleteOnOff); // it is better to make NULL check than trap new (ELeave)
       
   788         if ( !ipCompleteServerMsgsOnOff )
       
   789             {
       
   790             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- FATAL: OOM occurred!");
       
   791             //return leaveCode;
       
   792             return KErrNoMemory;
       
   793             }
       
   794         //return KErrSenNotInitialized;
       
   795 #ifdef _SENDEBUG        
       
   796         if( *ipCompleteServerMsgsOnOff )
       
   797             {
       
   798             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- CompleteServerMessagesOnOff mode: ON (TRUE) saved.");
       
   799             }
       
   800         else
       
   801             {
       
   802             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- CompleteServerMessagesOnOff mode: OFF (FALSE) saved.");
       
   803             }
       
   804 #endif // _SENDEBUG            
       
   805         return KErrNone;
       
   806         }
       
   807     
       
   808     TInt retVal = iConnection.CompleteServerMessagesOnOff((TBool&)aCompleteOnOff);
       
   809 
       
   810     if (retVal == KErrConnectionInitializing)
       
   811         {
       
   812         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8(" CSenServiceConnectionImpl::CompleteServerMessagesOnOff - Calling SetStatus(%d)"), 
       
   813             KSenConnectionStatusNew ));
       
   814         DeliverStatus( KSenConnectionStatusNew );
       
   815         }
       
   816     else if (retVal == KErrConnectionExpired)
       
   817         {
       
   818         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8(" CSenServiceConnectionImpl::CompleteServerMessagesOnOff - Calling SetStatus(%d)"), 
       
   819             KErrConnectionExpired ));
       
   820         DeliverStatus( KSenConnectionStatusExpired );
       
   821         }
       
   822     return retVal;
       
   823     }
       
   824 
       
   825 // Getter
       
   826 TInt CSenServiceConnectionImpl::HasFacetL(const TDesC8& aURI, TBool& aHasFacet)
       
   827     {
       
   828     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::HasFacetL");
       
   829     TInt retVal(iConnection.HasFacet((TDesC8&)aURI, aHasFacet));
       
   830 
       
   831     if (retVal == KErrConnectionInitializing)
       
   832         {
       
   833         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8(" CSenServiceConnectionImpl::HasFacetL - Calling SetStatus(%d)"), 
       
   834             KSenConnectionStatusNew ));
       
   835         DeliverStatus( KSenConnectionStatusNew );
       
   836         }
       
   837     else if (retVal == KErrConnectionExpired)
       
   838         {
       
   839         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8(" CSenServiceConnectionImpl::HasFacetL - Calling SetStatus(%d)"), 
       
   840             KSenConnectionStatusExpired ));
       
   841         DeliverStatus( KSenConnectionStatusExpired );
       
   842         }
       
   843 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::HasFacetL Completed");
       
   844     return retVal;
       
   845     }
       
   846 
       
   847 // Getter
       
   848 TInt CSenServiceConnectionImpl::IsReady(TBool& aReady)
       
   849     {
       
   850 //     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::IsReady"); // DO NOT ADD LOGGING IN HERE
       
   851     if( !iInitialized && iIsInternalSC )
       
   852         {
       
   853         aReady = EFalse;
       
   854         return KErrNone;
       
   855         }	
       
   856     TInt retVal(iConnection.IsReady(aReady));
       
   857 //    TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::IsReady Completed"); // DO NOT ADD LOGGING IN HERE
       
   858     return retVal;
       
   859     }
       
   860 
       
   861 TInt CSenServiceConnectionImpl::CheckConnection()
       
   862     {
       
   863     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::CheckConnection")));
       
   864     TInt retVal(KErrNone);
       
   865     
       
   866     if(!iInitialized)
       
   867         {
       
   868         TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::CheckConnection - KErrSenNotInitialized")));
       
   869         retVal = KErrSenNotInitialized;
       
   870         }
       
   871      else if (iAsyncOpsCount > KAsyncMessageSlots-1)
       
   872         {
       
   873         TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::CheckConnection - KErrServerBusy (not enough message slots)")));
       
   874         retVal = KErrServerBusy;
       
   875         }
       
   876     else if (!IsActive())
       
   877         {
       
   878         SetActive();
       
   879         iStatus = KRequestPending;
       
   880         }
       
   881 	TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::CheckConnection Completed")));
       
   882     return retVal;
       
   883     }
       
   884 
       
   885 TInt CSenServiceConnectionImpl::SendL(CSenConnectionChunk* apClientOp)
       
   886     {
       
   887     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::SendL(CSenChunk)")));
       
   888     TInt retVal( KErrNone );
       
   889     CleanupStack::PushL( apClientOp );
       
   890     
       
   891     iErrorNumber = 0;
       
   892     iTxnId = 0;
       
   893     
       
   894     iAsyncOpsCount++;
       
   895     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("iAsyncOpsCount: %d"), iAsyncOpsCount));
       
   896     
       
   897     CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
   898     iConnection.Transaction(pSenAO->iStatus, pSenAO->iErrorNumberBuffer, pSenAO->iTxnIdBuffer, *apClientOp);
       
   899     
       
   900     if ( apClientOp->HasBinaryDataArray() )
       
   901         {
       
   902         RegisterAndSubscribeFileProgressObserversL();
       
   903         retVal = MoveBinaryContainersToServer(*apClientOp, apClientOp->BinaryDataArrayL());
       
   904         }
       
   905 	    else if (apClientOp->HasSharedFileHandle())
       
   906 	    {
       
   907 	    retVal = MoveFileChunkHandleToServer(*apClientOp) ;
       
   908 	    }
       
   909 
       
   910 
       
   911     if( iDispatcherEnabled )  // DISPATCHER IS ENABLED
       
   912         {
       
   913         //iTxnId = retVal;
       
   914         TInt* pTxnId = new (ELeave) TInt(++iVirtualTransactionCounter);
       
   915         CleanupStack::PushL(pTxnId);
       
   916 
       
   917         TInt appendRetVal(KErrNone);
       
   918         appendRetVal = ChunkMapL().Append( pTxnId, apClientOp );
       
   919         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- ChunkMapL().Append(%d, %d) returned: %d"), *pTxnId, apClientOp->Chunk().Handle(), appendRetVal));
       
   920         if( appendRetVal == KErrNone )
       
   921             {
       
   922             TMessage msg;
       
   923             msg.iSenConnectionChunk = apClientOp;
       
   924             msg.iSenAsyncOperation = pSenAO;
       
   925 
       
   926             TThreadMessage thrMsg = { msg, iVirtualTransactionCounter };
       
   927     		
       
   928     		// INSTEAD OF DOING ANY IPC OPERATION WITH WSF (Core), THE REQUEST IS ADDED TO THE QUEUE!
       
   929             appendRetVal = ipSenServiceDispatcher->AddToTheQueue( thrMsg ); //NOTE THAT CHUNK MAP IS NOT USED IN HERE (!)
       
   930             if( appendRetVal==KErrNone )
       
   931                 {
       
   932                 //Required transaction id to respond back to the client
       
   933                 iTxnId = *pTxnId;
       
   934                 // OK, pTxnId, was appended successfully to the dispatchers map                
       
   935                 CleanupStack::Pop( pTxnId ); // now owned by the map
       
   936                 CleanupStack::Pop( apClientOp ); // now owned by the map
       
   937                 retVal = iVirtualTransactionCounter;
       
   938                 }
       
   939             else
       
   940                 {
       
   941                 CleanupStack::PopAndDestroy( pTxnId ); // orphanized
       
   942                 CleanupStack::PopAndDestroy( apClientOp ); // orphanized
       
   943                 retVal = appendRetVal;
       
   944                 }
       
   945             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- ipSenServiceDispatcher->AddToTheQueue() returned: %d"), appendRetVal));
       
   946                 
       
   947             }
       
   948         else
       
   949             {
       
   950             CleanupStack::PopAndDestroy( pTxnId ); // orphanized
       
   951             CleanupStack::PopAndDestroy( apClientOp ); // orphanized
       
   952             }
       
   953         }
       
   954     else // DISPATCHER IS DISABLED
       
   955         {
       
   956         // This is EXPECTED TO BE "quick" synchronous operation and returns the TxnId:        
       
   957         retVal = iConnection.SendMsgAndReceiveTxnId(*apClientOp);
       
   958         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher NOT used]: SendMsgAndReceiveTxnId returned: %d"), retVal));
       
   959         if ( retVal > KErrNone )
       
   960             {
       
   961             iTxnId = retVal;
       
   962             TInt* pTxnId = new (ELeave) TInt( iTxnId );
       
   963             CleanupStack::PushL(pTxnId);
       
   964 
       
   965             TInt appendRetVal(KErrNone);
       
   966             appendRetVal = ChunkMapL().Append( pTxnId, apClientOp );
       
   967             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- ChunkMapL().Append(%d, %d) returned: %d"), *pTxnId, apClientOp->Chunk().Handle(), appendRetVal));
       
   968             if(appendRetVal==KErrNone)
       
   969                 {
       
   970                 // OK, pTxnId, was appended successfully to iChunkMap
       
   971                 CleanupStack::Pop( pTxnId ); // now owned by the map
       
   972                 CleanupStack::Pop( apClientOp ); // now owned by the map
       
   973                 }
       
   974             else
       
   975                 {
       
   976                 CleanupStack::PopAndDestroy( pTxnId ); // orphanized
       
   977                 CleanupStack::PopAndDestroy( apClientOp ); // orphanized
       
   978                 retVal = appendRetVal;
       
   979                 }
       
   980             }
       
   981         else
       
   982             {
       
   983             CleanupStack::PopAndDestroy( apClientOp ); // orphanized
       
   984             }
       
   985         }
       
   986 	TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::SendL(CSenChunk) Completed")));        
       
   987     return retVal;
       
   988     }
       
   989 
       
   990 TInt CSenServiceConnectionImpl::SendL(const TDesC8& aRequest)
       
   991     {
       
   992     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(TDesC8)");
       
   993 
       
   994     TInt retVal = CheckConnection();
       
   995     
       
   996     if(retVal == KErrNone)
       
   997         {
       
   998         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
   999 		if( pOperation )
       
  1000 			{
       
  1001 #ifdef _SENDEBUG
       
  1002 	        pOperation->SetLogger( &iLog );
       
  1003 #endif //_SENDEBUG  
       
  1004 	        retVal = pOperation->CreateChunk();
       
  1005 	        if (retVal == KErrNone)
       
  1006 	            {
       
  1007 	            retVal = pOperation->DescToChunk(aRequest);
       
  1008 	            if (retVal == KErrNone)
       
  1009 	                {
       
  1010 	                retVal = SendL(pOperation);
       
  1011 	                }
       
  1012 	            }
       
  1013     	    }
       
  1014 		else
       
  1015 			{
       
  1016 #ifdef _SENDEBUG        
       
  1017 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL - KErrServerBusy");
       
  1018 #endif // _SENDEBUG
       
  1019 			return KErrServerBusy;    	
       
  1020 			}
       
  1021         }
       
  1022 #ifdef _SENDEBUG        
       
  1023     else
       
  1024     	{
       
  1025         // error occured in CheckConnection()  	
       
  1026         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("CSenServiceConnectionImpl::SendL - CheckConnection failed, error(%d)"), retVal ));
       
  1027     	}	 
       
  1028 #endif // _SENDEBUG
       
  1029 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(TDesC8) Completed");    	
       
  1030     return retVal;
       
  1031     }
       
  1032 
       
  1033 // This method is executed when one of the static constructors of service connection (NewL or NewLC) is called.
       
  1034 void CSenServiceConnectionImpl::InitializeL( /* MSenServiceDescription& aSD */ )
       
  1035     {
       
  1036     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::InitializeL");
       
  1037     if (!IsActive())
       
  1038         {
       
  1039         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Opening a new chunk for connection initialization descriptors");
       
  1040         delete ipInitChunk; // added
       
  1041         ipInitChunk = NULL; // added
       
  1042         TInt error( KErrConnectionInitializing );
       
  1043 
       
  1044         if( iIsInternalSC )
       
  1045             {
       
  1046             ipInitChunk = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); 
       
  1047             if( !ipInitChunk )
       
  1048                 {
       
  1049                 error = KErrConnectionInitializing;
       
  1050                 //User::Leave( error );
       
  1051                 }
       
  1052             }
       
  1053         else
       
  1054             {
       
  1055             ipInitChunk = CSenChunk::NewL(NextChunkName()); // added
       
  1056             }
       
  1057         
       
  1058         
       
  1059         if( /* !error && */ ipInitChunk ) 
       
  1060             {
       
  1061             ipInitChunk->SetLogger(&iLog);
       
  1062             error = ipInitChunk->CreateChunk();
       
  1063             }
       
  1064 
       
  1065         TInt serviceDescriptionLength(0);
       
  1066         TInt consumerPolicyLength(0);
       
  1067 
       
  1068         // => ipInitPatternAsXml & ipInitConsumerPolicyAsXml  allocated now in ConstructL, old ConstructL moved to ConnectL
       
  1069         if( !error )
       
  1070             {
       
  1071             TPtrC8 serviceDescPtr = ipInitPatternAsXml->Des();
       
  1072             serviceDescriptionLength = serviceDescPtr.Length();
       
  1073             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
       
  1074             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- SD as XML:");
       
  1075             TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,( serviceDescPtr ));
       
  1076             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|");
       
  1077 /*
       
  1078             if( aSD.DescriptionClassType() == MSenServiceDescription::EServicePattern )
       
  1079                 {
       
  1080                 CSenServicePattern* pServicePattern = (CSenServicePattern*)&aSD;
       
  1081 */                
       
  1082             if( ipInitConsumerPolicyAsXml )
       
  1083                 {
       
  1084     	        TPtrC8 consumerPolicyPtr(ipInitConsumerPolicyAsXml->Des());
       
  1085     	        TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::InitializeL - ConsumerPolicy:");
       
  1086     	        TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(*ipInitConsumerPolicyAsXml));
       
  1087             	error = ipInitChunk->DescsToChunk(serviceDescPtr, consumerPolicyPtr);
       
  1088                 consumerPolicyLength = consumerPolicyPtr.Length();
       
  1089                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- DescsToChunk returned: %d"), error));
       
  1090                 }
       
  1091             else
       
  1092             	{
       
  1093             	// No consumer policy provided by the service consumer application
       
  1094             	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::InitializeL - No consumer policy is used.");
       
  1095             	error = ipInitChunk->DescToChunk(serviceDescPtr);
       
  1096             	TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- DescToChunk returned: %d"), error));
       
  1097             	}
       
  1098             }
       
  1099 
       
  1100         if( error )
       
  1101             {
       
  1102             // At the moment, pass through the original error code. 
       
  1103             // error code constant ("KErrSenDescToChunkFailed") 
       
  1104             TInt leaveCode(KErrNone);
       
  1105             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::InitializeL");
       
  1106 
       
  1107             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- Since the SC is NOT ready, pass KSenConnectionStatusCreateFailed to SetStatus. Error: (%d)"), error ));
       
  1108             DeliverStatus( KSenConnectionStatusCreateFailed );
       
  1109             TRAP( leaveCode, iObserver->HandleErrorL( error, KNullDesC8 ); )
       
  1110             if(leaveCode)
       
  1111                 {
       
  1112                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("MSenServiceConsumer::HandleErrorL leaved: %d"), leaveCode));
       
  1113                 }
       
  1114             }
       
  1115         else // no errors
       
  1116             {
       
  1117             iErrorNumber = 0;
       
  1118             iErrorNumberBuffer.Set(reinterpret_cast<TUint8*>(&iErrorNumber), sizeof(TInt), sizeof(TInt));
       
  1119             iAsyncOpsCount++;
       
  1120             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1121             CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  1122 
       
  1123             if( !iIsInternalSC )
       
  1124                 {
       
  1125                 ipConnectionStatusObserver = CSenConnectionStatusObserver::NewL(*iObserver, iConnectionID);
       
  1126                 }
       
  1127             
       
  1128             if( ipExtendedConsumerInterface )
       
  1129                 {
       
  1130                 ipInterface = NULL;
       
  1131                 ipInterface = ipExtendedConsumerInterface->GetInterfaceByUid( KSenInterfaceUidAuthenticationProvider );
       
  1132                 if(ipInterface)
       
  1133                     {
       
  1134                     ipAuthProvider = (MSenAuthenticationProvider*) ipInterface;
       
  1135                     // Register authentication observer
       
  1136 					
       
  1137                     error = RegisterAuthenticationObserver();
       
  1138 #ifdef _SENDEBUG                    
       
  1139                     if( error )
       
  1140                         {
       
  1141                         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- RegisterAuthenticationObserver() failed!");                            
       
  1142                         }
       
  1143 #endif // _SENDEBUG                        
       
  1144                     }
       
  1145                 TInt retCode( KErrNone );
       
  1146                 ipInterface = NULL;
       
  1147                 ipInterface = ipExtendedConsumerInterface->GetInterfaceByUid( KSenInterfaceUidCoBrandingObserver );
       
  1148                 if(ipInterface)
       
  1149                     {
       
  1150                     ipCoBrandingObserver = (MSenCoBrandingObserver*) ipInterface;
       
  1151                     
       
  1152                     // Register CoBranding observer
       
  1153                     retCode = RegisterCoBrandingObserver();
       
  1154               
       
  1155                     if( retCode )
       
  1156                         {
       
  1157                         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- RegisterCoBrandingObserver() failed!");
       
  1158                         if( !error )
       
  1159                             {
       
  1160                             // none of the previous "register" IPC operations have failed so far:
       
  1161                             error = retCode;  // ok to assign this as the error
       
  1162                             }
       
  1163                         }
       
  1164                     }
       
  1165                 ipInterface = NULL;
       
  1166                 ipInterface = ipExtendedConsumerInterface->GetInterfaceByUid( KSenInterfaceUidFilesObserver );
       
  1167                 if( ipInterface )
       
  1168                     {
       
  1169                     iFilesObserver = (MSenFilesObserver*) ipInterface;
       
  1170                     // Register Files observer
       
  1171 
       
  1172                     //retCode = RegisterFilesObserver();// Moved to SendL and SubmitL to avoid unnecessary calls of RegisterFilesObserver
       
  1173 									 					// and making the constructor light weight
       
  1174  					
       
  1175  					// ==> 2008-11-05 mmattola: 
       
  1176  					// commenting RegisterFilesObserver() OUT would be OK otherwise,
       
  1177  					//  BUT(!): that would mean that that the client CANNOT receive any "progress" info BEFORE / PRIOR sending something out(!) => not good!
       
  1178 						
       
  1179 				    
       
  1180                     
       
  1181                     if ( !iRegisterFileObserverDone )
       
  1182                         {
       
  1183                         TLSLOG_L( KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel, "InitializeL(): - Calling IssueRegistrations()");
       
  1184                         //ipRegistrationTimer->IssueRegistrations( ETrue );
       
  1185                         
       
  1186                         /*
       
  1187                         retCode = RegisterAndSubscribeFileProgressObserversL(); // returning this in here, to ENABLE early reception
       
  1188                         if( retCode )
       
  1189                             {
       
  1190                             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- RegisterFilesObserver() failed!");
       
  1191                             if( !error )
       
  1192                                 {
       
  1193                                 // none of the previous "register" IPC operations have failed so far:
       
  1194                                 error = retCode; // ok to assign this as the error
       
  1195                                 }
       
  1196                             }
       
  1197                         */
       
  1198                         } // end of if ( !iRegisterFileObserverDone )
       
  1199                     }
       
  1200                 ipInterface = NULL;
       
  1201                 ipInterface = ipExtendedConsumerInterface->GetInterfaceByUid( KSenInterfaceUidHostletConsumer );
       
  1202                 if(ipInterface)
       
  1203                     {
       
  1204                     ipHostletConsumer = (MSenHostletConsumer*) ipInterface;
       
  1205                     }
       
  1206                     
       
  1207                 ipInterface = NULL;
       
  1208                 ipInterface = ipExtendedConsumerInterface->GetInterfaceByUid( KSenInterfaceUidUserinfoProvider );
       
  1209                 //if(ipInterface)
       
  1210                 //    {
       
  1211                 //    iUserinfoProvider = (MSenUserinfoProvider*) ipInterface;
       
  1212                 //    }
       
  1213                 
       
  1214                 ipInterface = NULL;
       
  1215                 ipInterface = ipExtendedConsumerInterface->GetInterfaceByUid( KSenInterfaceUidAlrObserver );
       
  1216 
       
  1217 #ifdef __ENABLE_ALR__
       
  1218                 if(ipInterface)
       
  1219                     {
       
  1220                     iMobiltyObserver = (MMobilityProtocolResp*) ipInterface;
       
  1221                     
       
  1222                     // Register mobility observer
       
  1223                     retCode = RegisterMobilityObserverL();
       
  1224 
       
  1225                     if( retCode )
       
  1226                         {
       
  1227                         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- RegisterMobilityObserver() failed!");
       
  1228                         if( !error )
       
  1229                             {
       
  1230                             // none of the previous "register" IPC operations have failed so far:
       
  1231                             error = retCode; // ok to assign this as the error
       
  1232                             }
       
  1233                         }
       
  1234                     }
       
  1235 #endif //__ENABLE_ALR__
       
  1236 
       
  1237                 if( !error )
       
  1238                 	{
       
  1239                 	if(ipAuthProvider)
       
  1240                     	{
       
  1241                     	iConnection.Initialize( pSenAO->iStatus,
       
  1242                                             	pSenAO->iErrorNumberBuffer,
       
  1243                                             	iSessionIdBuffer,
       
  1244                                             	*ipInitChunk,
       
  1245                                             	serviceDescriptionLength,
       
  1246                                             	consumerPolicyLength,
       
  1247                                             	ETrue );
       
  1248                     	}
       
  1249                     	else
       
  1250                     	{
       
  1251                     	iConnection.Initialize( pSenAO->iStatus,
       
  1252                                             	pSenAO->iErrorNumberBuffer,
       
  1253                                             	iSessionIdBuffer,
       
  1254                                             	*ipInitChunk,
       
  1255                                             	serviceDescriptionLength,
       
  1256                                             	consumerPolicyLength,
       
  1257                                             	EFalse );
       
  1258                     	}
       
  1259                 	}
       
  1260                 else // occured
       
  1261                 	{
       
  1262                 	// Initialization of connection agent / some of the "register" -alike IPC ops failed 
       
  1263                 	TInt leaveCode(KErrNone);
       
  1264                 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::InitializeL");
       
  1265 
       
  1266                 	TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- Since the SC is NOT ready, pass KSenConnectionStatusCreateFailed to SetStatus. Error: (%d)"), error ));
       
  1267                 	DeliverStatus( KSenConnectionStatusCreateFailed );
       
  1268                 	TRAP( leaveCode, iObserver->HandleErrorL( error, KNullDesC8 ); )
       
  1269                 	if(leaveCode)
       
  1270                 		{
       
  1271                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("MSenServiceConsumer::HandleErrorL leaved: %d"), leaveCode));
       
  1272                 	    }
       
  1273                 	}
       
  1274                                     
       
  1275                 
       
  1276             }
       
  1277             else
       
  1278                 {
       
  1279                 iConnection.Initialize( pSenAO->iStatus,
       
  1280                                         pSenAO->iErrorNumberBuffer,
       
  1281                                         iSessionIdBuffer,
       
  1282                                         *ipInitChunk,
       
  1283                                         serviceDescriptionLength,
       
  1284                                         consumerPolicyLength,
       
  1285                                         EFalse );
       
  1286                 }
       
  1287             }
       
  1288         }
       
  1289     else
       
  1290         {
       
  1291         // Error occurred!
       
  1292         TInt leaveCode(KErrNone);
       
  1293         // This is actually AO "busy" case, but due sequential calls to SC's ConstructL()
       
  1294         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::InitializeL");
       
  1295         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Since the SC is NOT ready (AO is busy), pass KSenConnectionStatusCreateFailed to SetStatus.");
       
  1296         DeliverStatus( KSenConnectionStatusCreateFailed );
       
  1297 
       
  1298         TRAP( leaveCode, iObserver->HandleErrorL(KErrConnectionInitializing, KNullDesC8); )
       
  1299         if(leaveCode)
       
  1300             {
       
  1301             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("MSenServiceConsumer::HandleErrorL leaved: %d"), leaveCode ));
       
  1302             }
       
  1303         }
       
  1304 		        
       
  1305     }
       
  1306 
       
  1307 TPtrC CSenServiceConnectionImpl::NextChunkName()
       
  1308     {
       
  1309     if(ipChunkName)
       
  1310         {
       
  1311         iChunkNameNumber++;
       
  1312         TPtr chunkname = ipChunkName->Des();
       
  1313         chunkname.Zero();
       
  1314         TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,(iSessionIdBuffer));
       
  1315 
       
  1316         if(iSessionIdBuffer.Length()>KSenUuidPrefixLength)
       
  1317             {
       
  1318             chunkname.Append(iSessionIdBuffer.Right(iSessionIdBuffer.Length()-KSenUuidPrefixLength));
       
  1319             }
       
  1320         chunkname.AppendNum(iChunkNameNumber);
       
  1321 
       
  1322         // Remove dashes
       
  1323          _LIT(KDash, "-");
       
  1324         TInt pos = chunkname.Find(KDash);
       
  1325         while (pos != KErrNotFound)
       
  1326             {
       
  1327             chunkname.Replace(pos, KDash().Length(), KNullDesC);
       
  1328             pos = chunkname.Find(KDash);
       
  1329             }
       
  1330         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L("CSenServiceConnectionImpl::NextChunkName(): %S"), &chunkname));
       
  1331         return chunkname.Left(KMaxName); // max length of TName
       
  1332         }
       
  1333     else
       
  1334         {
       
  1335         return KNullDesC();
       
  1336         }  
       
  1337     }
       
  1338 void CSenServiceConnectionImpl::RunL()
       
  1339     {
       
  1340     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::RunL( %d )"),
       
  1341                                             iStatus.Int()));
       
  1342     }
       
  1343 void CSenServiceConnectionImpl::HandleMessageFromChildAOL(TInt aStatus)
       
  1344     {
       
  1345     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::HandleMessageFromChildAOL( %d )"),
       
  1346                                             aStatus));
       
  1347     iAsyncOpsCount--;
       
  1348     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- One async op completed. Pending iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1349                                             
       
  1350     switch (aStatus)
       
  1351         {
       
  1352         case ESenServInitialized:
       
  1353             {
       
  1354             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: ESenServInitialized");
       
  1355 
       
  1356             TInt leaveCode(KErrNone);
       
  1357             if ( iErrorNumber == KErrNone )
       
  1358                 {
       
  1359                 iInitialized = ETrue;
       
  1360 
       
  1361                 if ( ipCompleteServerMsgsOnOff )
       
  1362                     {
       
  1363                     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Performing ctr-implicit call to pending CompleteServerMessagesOnOff" );
       
  1364                     TBool complete = *ipCompleteServerMsgsOnOff;
       
  1365                     TInt errorCode = CompleteServerMessagesOnOff( complete );
       
  1366 #ifdef _SENDEBUG                        
       
  1367                     if ( errorCode )
       
  1368                         {
       
  1369                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8( "´- Ctr-implicit call to CompleteServerMessagesOnOff failed: (%d)!"), errorCode));
       
  1370                         }
       
  1371                     else
       
  1372                         {
       
  1373                         if( complete )
       
  1374                             {
       
  1375                             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , "- Ctr-implicit call ok. Complete msgs mode: ON (true)" );
       
  1376                             }
       
  1377                         else
       
  1378                             {
       
  1379                             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , "- Ctr-implicit call ok. Complete msgs mode: OFF (false)" );
       
  1380                             }
       
  1381                         }                        
       
  1382 #endif // _SENDEBUG                    
       
  1383 
       
  1384 
       
  1385                     }
       
  1386                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::HandleMessageFromChildAOL - Calling SetStatus(%d)"), KSenConnectionStatusReady ));
       
  1387                 DeliverStatus( KSenConnectionStatusReady ); // Service session is valid and ready to be used!
       
  1388                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- Session ID (%d bytes):"), iSessionIdBuffer.Length()));
       
  1389                 TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel ,( iSessionIdBuffer.Right(iSessionIdBuffer.Length()-5) ));
       
  1390                 }
       
  1391             else
       
  1392                 {
       
  1393                 // Error occurred   
       
  1394                 DeliverStatus( KSenConnectionStatusCreateFailed );
       
  1395                 
       
  1396                 TPtrC8 errorDescription;
       
  1397                 TInt retVal = ipInitChunk->DescFromChunk(errorDescription);
       
  1398 
       
  1399                 TInt error = iErrorNumber;
       
  1400                 if ( error == KErrSenSoapFault && !iInitialized ) // China DC
       
  1401                     {
       
  1402                     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Since the SC is NOT ready, pass KErrSenAuthenticationFault to HandleErrorL instead of KErrSenSoapFault");
       
  1403                     error = KErrSenAuthenticationFault;
       
  1404                     }
       
  1405                     
       
  1406                 if ( retVal == KErrNone )
       
  1407                     {
       
  1408                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("HandleMessageFromChildAOL: ESenServInitialize failed: %d"), error ));
       
  1409                     TRAP( leaveCode, iObserver->HandleErrorL(error, errorDescription); )
       
  1410                     if( leaveCode )
       
  1411                         {
       
  1412                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("MSenServiceConsumer::HandleMessageFromChildAOL - HandleErrorL leaves with %d"), leaveCode));
       
  1413                         }
       
  1414                     }
       
  1415                 else
       
  1416                     {
       
  1417                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- DescFromChunk failed: %d - callback will provide err code (%d) only."), retVal, error));
       
  1418                     DeliverResponseL( error );
       
  1419                     }
       
  1420                 }
       
  1421             delete ipInitChunk;
       
  1422             ipInitChunk = NULL;
       
  1423             delete ipInitPatternAsXml;
       
  1424             ipInitPatternAsXml = NULL;
       
  1425             delete ipInitConsumerPolicyAsXml;
       
  1426             ipInitConsumerPolicyAsXml = NULL;
       
  1427 
       
  1428             break;
       
  1429             }
       
  1430 
       
  1431         case ESenServRequestResponsed:       
       
  1432             {
       
  1433             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: ESenServRequestResponsed");
       
  1434             if ( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
  1435                 {
       
  1436                 TInt keyAt = ipSenServiceDispatcher->GetVirtualTransactionID( &iTxnId );
       
  1437                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: Looking for virtual transaction ID");
       
  1438                 if( keyAt != KErrNotFound )
       
  1439                     {
       
  1440                     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: Found virtual transaction ID");
       
  1441                     TInt index = ChunkMapL().Find(keyAt);
       
  1442                     if ( index != KErrNotFound )
       
  1443                         {
       
  1444                         CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1445                         TPtrC8 response;
       
  1446                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher is enabled]: HandleMessageFromChildAOL - mapped RChunk's handle: %d"), pOperation->Chunk().Handle()));
       
  1447 
       
  1448                         TInt retVal = pOperation->DescFromChunk(response);
       
  1449                         if ( retVal == KErrNone )
       
  1450                             {
       
  1451                             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- [dispatcher is enabled]: DescFromChunk ok");
       
  1452                             DeliverResponseL(iErrorNumber, pOperation);
       
  1453                             }
       
  1454                         else
       
  1455                             {
       
  1456                             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is enabled]: DescFromChunk failed: %d"), retVal));
       
  1457                             DeliverResponseL(retVal);
       
  1458                             }
       
  1459                         // Delete TxnId and CSenClientOp
       
  1460                         retVal = ChunkMapL().Remove(*pOperation);
       
  1461                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is enabled]: ChunkMap().Remove() returned: %d"), retVal));
       
  1462                         retVal = ipSenServiceDispatcher->RemoveFromTransMap(&keyAt);
       
  1463                         }
       
  1464                     else
       
  1465                         {
       
  1466                         LOG_WRITEFORMAT((_L("- Closing the transaction due SendL has failed: %d"), iErrorNumber));
       
  1467                         }
       
  1468                     }
       
  1469                 else
       
  1470                     {
       
  1471                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher is enabled]: Closing the transaction due SendL has failed: %d"), iErrorNumber));
       
  1472                     }
       
  1473                 }
       
  1474             else // DISPATCHER IS DISABLED
       
  1475                 {
       
  1476                 TInt index = ChunkMapL().Find(iTxnId);
       
  1477                 if ( index != KErrNotFound )
       
  1478                     {
       
  1479                     CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1480                     TPtrC8 response;
       
  1481                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher is disabled]: HandleMessageFromChildAOL - mapped RChunk's handle: %d"), pOperation->Chunk().Handle()));
       
  1482 
       
  1483                     TInt retVal = pOperation->DescFromChunk(response);
       
  1484                     if ( retVal == KErrNone )
       
  1485                         {
       
  1486                         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- [dispatcher is disabled]: DescFromChunk ok");
       
  1487                         DeliverResponseL(iErrorNumber, pOperation);
       
  1488                         }
       
  1489                     else
       
  1490                         {
       
  1491                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is disabled]: DescFromChunk failed: %d"), retVal));
       
  1492                         DeliverResponseL(retVal);
       
  1493                         }
       
  1494 
       
  1495                     // Delete TxnId and CSenClientOp
       
  1496                     retVal = ChunkMapL().Remove(*pOperation);
       
  1497                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is disabled]: ChunkMap().Remove() returned: %d"), retVal));
       
  1498                     retVal = 0; // not used in release builds
       
  1499                     }
       
  1500                 else
       
  1501                     {
       
  1502                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher is disabled]: Closing the transaction due SendL has failed: %d"), iErrorNumber));
       
  1503                     }
       
  1504                 }
       
  1505             break;
       
  1506             }
       
  1507 
       
  1508         case ESenInternalError:
       
  1509             {
       
  1510             delete ipInitChunk; // added, pre-emptive de-alloc in case of errors..
       
  1511             ipInitChunk = NULL; // added
       
  1512             delete ipInitPatternAsXml;
       
  1513             ipInitPatternAsXml = NULL;
       
  1514             delete ipInitConsumerPolicyAsXml;
       
  1515             ipInitConsumerPolicyAsXml = NULL;
       
  1516             
       
  1517             // we could have someting in iErrorNumber in some cases
       
  1518             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: ESenInternalError");
       
  1519             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- Last received error from server: (%d)"),
       
  1520                     iErrorNumber));
       
  1521 
       
  1522             DeliverResponseL(KErrSenInternal);
       
  1523             }
       
  1524             break;
       
  1525 
       
  1526         case ESenServRequestCancelled:
       
  1527             {
       
  1528             DeliverResponseL( KErrSenCancelled);
       
  1529             }
       
  1530             break;
       
  1531 
       
  1532         case ESenReAuthAndResendNeeded:
       
  1533             {
       
  1534             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: ESenReAuthAndResendNeeded");
       
  1535             
       
  1536             TInt retVal(KErrNone);
       
  1537             if ( iAsyncOpsCount >= KAsyncMessageSlots)
       
  1538                 {
       
  1539                 retVal = KErrSenServiceConnectionBusy;
       
  1540                 }
       
  1541                 
       
  1542             if ( retVal == KErrNone )
       
  1543                 {
       
  1544                 if ( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
  1545                     {
       
  1546                     TInt keyAt = ipSenServiceDispatcher->GetVirtualTransactionID(&iTxnId);
       
  1547                     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: Looking for virtual transaction ID");
       
  1548                     if(keyAt != KErrNotFound)
       
  1549                         {
       
  1550                         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: Found virtual transaction ID");
       
  1551                         TInt index = ChunkMapL().Find(keyAt);
       
  1552                         if ( index != KErrNotFound )
       
  1553                             {
       
  1554                             CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1555                             
       
  1556                             pOperation->ChunkHeader().SetDoInitBeforeSending(ETrue);
       
  1557                             
       
  1558                             iAsyncOpsCount++;
       
  1559                             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher enabled]: iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1560                             CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  1561                             iConnection.Transaction(pSenAO->iStatus, pSenAO->iErrorNumberBuffer, pSenAO->iTxnIdBuffer, *pOperation);
       
  1562 
       
  1563                             if ( pOperation->HasBinaryDataArray() )
       
  1564                                 {
       
  1565                                 retVal = MoveBinaryContainersToServer(*pOperation, pOperation->BinaryDataArrayL());
       
  1566                                 }
       
  1567                             // Reauthentication
       
  1568                             if(ipAuthProvider)
       
  1569                             	{
       
  1570                             	pSenAO->iReauthTxnId = iTxnId;
       
  1571                             	if(iReauthenticationNeeded)
       
  1572                             		{
       
  1573                             		iReauthenticationNeeded = EFalse; // unmark reauthentication flag
       
  1574         	                    	TInt lerror(KErrNone);
       
  1575         	                    	TRAP(lerror, ReauthNeededL(KNullDesC8));
       
  1576         	                    	}
       
  1577                             	}
       
  1578                             // This is quick and returns the TxnId:
       
  1579                             retVal = iConnection.SendMsgAndReceiveTxnId(*pOperation);
       
  1580                             //iTxnId = retVal;
       
  1581                             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher enabled]: SendMsgAndReceiveTxnId returned: %d"), retVal));
       
  1582                         	TInt* pActlTxnId = new (ELeave) TInt(0);
       
  1583     			            *pActlTxnId = iTxnId /*retVal*/;
       
  1584     				        CleanupStack::PushL(pActlTxnId);
       
  1585     				
       
  1586                             retVal = ipSenServiceDispatcher->UpdateTransMap(&keyAt,pActlTxnId);
       
  1587                             if(retVal == KErrNone)
       
  1588                                 {
       
  1589                                 CleanupStack::Pop(pActlTxnId);
       
  1590                                 }
       
  1591                             else
       
  1592                                 {
       
  1593     			    	        CleanupStack::PopAndDestroy(pActlTxnId);
       
  1594                                 }
       
  1595                             }
       
  1596                         else
       
  1597                             {
       
  1598                             retVal = KErrSenInternal;
       
  1599                             }
       
  1600                         }
       
  1601                     else
       
  1602                         {
       
  1603                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher enabled]: ChunkMap().FindKey(%d) failed!"), iTxnId));
       
  1604                         retVal = KErrSenInternal;
       
  1605                         }
       
  1606                         
       
  1607                     }
       
  1608                 else // DISPATCHER IS DISABLED
       
  1609                     {
       
  1610                     TInt index = ChunkMapL().Find(iTxnId);
       
  1611                     if ( index != KErrNotFound )
       
  1612                         {
       
  1613                         CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1614                         
       
  1615                         pOperation->ChunkHeader().SetDoInitBeforeSending(ETrue);
       
  1616                         
       
  1617                         iAsyncOpsCount++;
       
  1618                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher disabled]: iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1619                         CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  1620                         iConnection.Transaction(pSenAO->iStatus, pSenAO->iErrorNumberBuffer,
       
  1621                                                 pSenAO->iTxnIdBuffer, *pOperation);
       
  1622 
       
  1623                         if ( pOperation->HasBinaryDataArray() )
       
  1624                             {
       
  1625                             retVal = MoveBinaryContainersToServer(*pOperation,
       
  1626                                                                   pOperation->BinaryDataArrayL());
       
  1627                             }
       
  1628                         // Reauthentication
       
  1629                         if(ipAuthProvider)
       
  1630                         	{
       
  1631                         	pSenAO->iReauthTxnId = iTxnId;
       
  1632                         	if(iReauthenticationNeeded)
       
  1633                         		{
       
  1634                         		iReauthenticationNeeded = EFalse; //unmark reauthentication flag
       
  1635     	                    	TInt lerror(KErrNone);
       
  1636     	                    	TRAP(lerror, ReauthNeededL(KNullDesC8));
       
  1637     	                    	}
       
  1638                         	}
       
  1639                         // This is quick and returns the TxnId:
       
  1640                         retVal = iConnection.SendMsgAndReceiveTxnId(*pOperation);
       
  1641                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher disabled]: SendMsgAndReceiveTxnId returned: %d"), retVal));
       
  1642                         }
       
  1643                     else
       
  1644                         {
       
  1645                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher disabled]: ChunkMap().FindKey(%d) failed!"), iTxnId));
       
  1646                         retVal = KErrSenInternal;
       
  1647                         }
       
  1648                     }
       
  1649                 }
       
  1650                 
       
  1651             if ( retVal < KErrNone )
       
  1652                 {
       
  1653                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher disabled]:  Resend failed: %d"), retVal));
       
  1654                 // Note: do NOT return anything to consumer here (never call DeliverResponseL(retVal) here!)
       
  1655                 }
       
  1656             }
       
  1657             break;
       
  1658 
       
  1659         case ESenResendNeeded:
       
  1660             {
       
  1661             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: ESenResendNeeded");
       
  1662 
       
  1663             TInt retVal(KErrNone);
       
  1664             if ( iAsyncOpsCount >= KAsyncMessageSlots )
       
  1665                 {
       
  1666                 retVal = KErrSenServiceConnectionBusy;
       
  1667                 }
       
  1668                 
       
  1669             if ( retVal == KErrNone )
       
  1670                 {
       
  1671                 if( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
  1672                     {
       
  1673                     TInt keyAt = ipSenServiceDispatcher->GetVirtualTransactionID( &iTxnId );
       
  1674                     
       
  1675                     if(keyAt != KErrNotFound)
       
  1676                         {
       
  1677                         TInt index = ChunkMapL().Find(keyAt);
       
  1678                         if(index != KErrNotFound)
       
  1679                             {
       
  1680                             CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1681                             
       
  1682                             iAsyncOpsCount++;
       
  1683                             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is enabled]: iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1684                             CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL( this );
       
  1685                             iConnection.Transaction(pSenAO->iStatus, pSenAO->iErrorNumberBuffer, pSenAO->iTxnIdBuffer, *pOperation);
       
  1686                                 
       
  1687                             if ( pOperation->HasBinaryDataArray() )
       
  1688                                 {
       
  1689                                 retVal = MoveBinaryContainersToServer(*pOperation, pOperation->BinaryDataArrayL());
       
  1690                                 }
       
  1691 
       
  1692                             // This is EXPECTED TO BE "quick" SYNC IPC OPERATION THAT "just" returns the TxnId:
       
  1693                             
       
  1694                             // shouldn't this potentially "slow" IPC be performed 
       
  1695                             // by dispatcher(?) => resending is not handled by "dispatcher thread" now..
       
  1696                             retVal = iConnection.SendMsgAndReceiveTxnId(*pOperation); 
       
  1697                             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is enabled]: SendMsgAndReceiveTxnId returned: %d"), retVal));
       
  1698                             }
       
  1699                         else
       
  1700                             {
       
  1701                             retVal = KErrSenInternal;
       
  1702                             }
       
  1703                         }
       
  1704                     else
       
  1705                         {
       
  1706                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher is enabled]: ChunkMap().FindKey(%d) failed!"), iTxnId));                    
       
  1707                         retVal = KErrSenInternal;
       
  1708                         }
       
  1709                     }
       
  1710                 else // DISPATCHER IS DISABLED
       
  1711                     {
       
  1712                     TInt index = ChunkMapL().Find(iTxnId);
       
  1713                     if(index != KErrNotFound)
       
  1714                         {
       
  1715                         CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1716                         
       
  1717                         iAsyncOpsCount++;
       
  1718                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is disabled]: iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1719                         CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  1720                         iConnection.Transaction(pSenAO->iStatus, pSenAO->iErrorNumberBuffer,
       
  1721                                                 pSenAO->iTxnIdBuffer, *pOperation);
       
  1722                             
       
  1723                         if ( pOperation->HasBinaryDataArray() )
       
  1724                             {
       
  1725                             retVal = MoveBinaryContainersToServer(*pOperation,
       
  1726                                                                   pOperation->BinaryDataArrayL());
       
  1727                             }
       
  1728 
       
  1729                         // This is quick and returns the TxnId:
       
  1730                         retVal = iConnection.SendMsgAndReceiveTxnId(*pOperation);
       
  1731                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- [dispatcher is disabled]:  SendMsgAndReceiveTxnId returned: %d"), retVal));
       
  1732                         }
       
  1733                     else
       
  1734                         {
       
  1735                         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- [dispatcher is disabled]: ChunkMap().FindKey(%d) failed!"), iTxnId));                    
       
  1736                         retVal = KErrSenInternal;
       
  1737                         }
       
  1738                     }
       
  1739                 
       
  1740                 }
       
  1741                 
       
  1742             if ( retVal < KErrNone )
       
  1743                 {
       
  1744                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("=> Resend failed: %d"), retVal));
       
  1745                 // Note: do NOT return anything to consumer here (never call DeliverResponseL(retVal) here!)
       
  1746                 }
       
  1747             }
       
  1748             break;
       
  1749             
       
  1750         case ESenReAuthNeeded:
       
  1751             {
       
  1752             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: ESenReAuthNeeded");
       
  1753 
       
  1754             TInt retVal(KErrNone);
       
  1755             if ( iAsyncOpsCount >= KAsyncMessageSlots )
       
  1756                 {
       
  1757                 retVal = KErrSenServiceConnectionBusy;
       
  1758                 }
       
  1759                 
       
  1760             if ( retVal == KErrNone )
       
  1761                 {
       
  1762                 iErrorNumber = 0;
       
  1763                 iErrorNumberBuffer.Set(reinterpret_cast<TUint8*>(&iErrorNumber), sizeof(TInt), sizeof(TInt));
       
  1764                 iAsyncOpsCount++;
       
  1765                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- iAsyncOpsCount: %d"), iAsyncOpsCount));
       
  1766                 CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  1767                 
       
  1768                 TInt serviceDescriptionLength(0);
       
  1769                 TInt consumerPolicyLength(0);
       
  1770                 
       
  1771                 TPtrC8 serviceDescPtr = ipInitPatternAsXml->Des();
       
  1772                 serviceDescriptionLength = serviceDescPtr.Length();
       
  1773                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"- SD as XML:");
       
  1774                 TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,( serviceDescPtr ));
       
  1775                 
       
  1776                 if( ipInitConsumerPolicyAsXml )
       
  1777                     {
       
  1778         	        TPtrC8 consumerPolicyPtr(ipInitConsumerPolicyAsXml->Des());
       
  1779         	        TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"CSenServiceConnectionImpl::Reauthentication - ConsumerPolicy:");
       
  1780         	        TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,(*ipInitConsumerPolicyAsXml));
       
  1781                 	retVal = ipInitChunk->DescsToChunk(serviceDescPtr, consumerPolicyPtr);
       
  1782                     consumerPolicyLength = consumerPolicyPtr.Length();
       
  1783                     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- DescsToChunk returned: %d"), retVal));
       
  1784                     }
       
  1785                 else
       
  1786                 	{
       
  1787                 	// No consumer policy provided by the service consumer application
       
  1788                 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - No consumer policy is used.");
       
  1789                 	retVal = ipInitChunk->DescToChunk(serviceDescPtr);
       
  1790                 	TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- DescToChunk returned: %d"), retVal));
       
  1791                 	}
       
  1792                 	
       
  1793     	        if ( retVal == KErrNone )
       
  1794     	            {
       
  1795                     if ( ipAuthProvider )
       
  1796                         {
       
  1797                         CSenXmlServiceDescription* pServDesc =
       
  1798                       	CSenXmlServiceDescription::NewLC();
       
  1799 	                    CSenXmlReader* pXmlReader =
       
  1800 	                       	CSenXmlReader::NewLC(KXmlParserMimeType);
       
  1801 	                    pXmlReader->SetContentHandler(*pServDesc);
       
  1802 	                    pServDesc->SetReader(*pXmlReader);
       
  1803 	                    TInt retVal = pServDesc->BuildFrom(serviceDescPtr);
       
  1804 	                    CleanupStack::PopAndDestroy(pXmlReader);
       
  1805 	                    
       
  1806 	                    if(retVal == KErrNone)
       
  1807 	                       	{
       
  1808 	                        TPtrC8 providerId = pServDesc->ProviderId();
       
  1809 	                        TInt lerror(KErrNone);
       
  1810 	                        TRAP(lerror, retVal = ReauthNeededL(providerId));
       
  1811 	                        if(lerror != KErrNone)
       
  1812 	                        	{
       
  1813 	                        	// Leave occured, most probably because of callback function
       
  1814 	                        	retVal = lerror;
       
  1815 	                        	}
       
  1816 	                      	CleanupStack::PopAndDestroy(pServDesc);
       
  1817 	                       	}
       
  1818 	                    else
       
  1819 	                    	{
       
  1820 	                    	CleanupStack::PopAndDestroy(pServDesc);
       
  1821 	                    	}
       
  1822 
       
  1823                         // Call the asynchronous connection initilizer
       
  1824 	                    if(retVal == KErrNone)
       
  1825 	                    	{
       
  1826 	                    if ( ipAuthProvider )
       
  1827 	                        {
       
  1828 	                        iConnection.Initialize( pSenAO->iStatus,
       
  1829 	                                                pSenAO->iErrorNumberBuffer,
       
  1830 	                                                iSessionIdBuffer,
       
  1831 	                                                *ipInitChunk,
       
  1832 	                                                serviceDescriptionLength,
       
  1833 	                                                consumerPolicyLength,
       
  1834 	                                                ETrue );
       
  1835 	                        }
       
  1836 	                    else
       
  1837 	                        {
       
  1838 	                        iConnection.Initialize( pSenAO->iStatus,
       
  1839 	                                                pSenAO->iErrorNumberBuffer,
       
  1840 	                                                iSessionIdBuffer,
       
  1841 	                                                *ipInitChunk,
       
  1842 	                                                serviceDescriptionLength,
       
  1843 	                                                consumerPolicyLength,
       
  1844 	                                                EFalse );
       
  1845 	                         }
       
  1846                         }
       
  1847                         }
       
  1848                     else
       
  1849                         {
       
  1850                         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - authentication provider not found!");
       
  1851                         retVal = KErrGeneral;
       
  1852                         }
       
  1853     	            }
       
  1854                 }
       
  1855                 
       
  1856             if ( retVal < KErrNone )
       
  1857                 {
       
  1858                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- ReAuth failed: %d"), retVal));
       
  1859                 // Note: do NOT return anything to consumer here (never call DeliverResponseL(retVal) here!)
       
  1860                 // Error occurred   
       
  1861                 //TRAP( leaveCode, iObserver->SetStatus( KSenConnectionStatusCreateFailed ); )
       
  1862                 DeliverStatus( KSenConnectionStatusCreateFailed );
       
  1863                 
       
  1864                 TPtrC8 errorDescription;
       
  1865                 TInt retVal = ipInitChunk->DescFromChunk(errorDescription);
       
  1866 
       
  1867                 TInt error = KErrSenSoapFault;
       
  1868                 if ( error == KErrSenSoapFault && !iInitialized ) // China DC
       
  1869                     {
       
  1870                     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Since the SC is NOT ready, pass KErrSenAuthenticationFault to HandleErrorL instead of KErrSenSoapFault");
       
  1871                     error = KErrSenAuthenticationFault;
       
  1872                     }
       
  1873 
       
  1874                 if ( retVal == KErrNone )
       
  1875                 	{
       
  1876                      TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("HandleMessageFromChildAOL: ESenServInitialize failed: %d"), error ));
       
  1877                      TInt leaveCode(KErrNone);
       
  1878                      TRAP( leaveCode, iObserver->HandleErrorL(error, errorDescription); )
       
  1879                      if( leaveCode )
       
  1880                     	 {
       
  1881                          TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("MSenServiceConsumer::HandleMessageFromChildAOL - HandleErrorL leaves with %d"), leaveCode));
       
  1882                          }
       
  1883                      }
       
  1884                 else
       
  1885                      {
       
  1886                      TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- DescFromChunk failed: %d - callback will provide err code (%d) only."), retVal, error));
       
  1887                      //DeliverResponseL(retVal);
       
  1888                      DeliverResponseL( error );
       
  1889                      }
       
  1890                 
       
  1891                 delete ipInitChunk;
       
  1892                 ipInitChunk = NULL;
       
  1893                 delete ipInitPatternAsXml;
       
  1894                 ipInitPatternAsXml = NULL;
       
  1895                 delete ipInitConsumerPolicyAsXml;
       
  1896                 ipInitConsumerPolicyAsXml = NULL;
       
  1897                 }
       
  1898             }
       
  1899             break;
       
  1900 
       
  1901         default:
       
  1902             {
       
  1903             delete ipInitChunk; // added, pre-emptive de-alloc in case of errors..
       
  1904             ipInitChunk = NULL; // added
       
  1905             
       
  1906 #ifdef _SENDEBUG                
       
  1907             if ( aStatus == KErrPermissionDenied )
       
  1908                 {
       
  1909                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"HandleMessageFromChildAOL: default - KErrPermissionDenied");
       
  1910                 }
       
  1911             else
       
  1912                 {
       
  1913                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"RunL: default - unexpected error.");
       
  1914                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("Last received error from server: (%d)"), iErrorNumber));
       
  1915                 }
       
  1916             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("RunL, iStatus.Int(): (%d)"), iStatus.Int()));
       
  1917             
       
  1918 #endif // _SENDEBUG             
       
  1919             // WSF does not generalize errors:
       
  1920             if( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
  1921                 {
       
  1922                 TInt index = ChunkMapL().Find(iVirtualTransactionCounter);
       
  1923                 if ( index != KErrNotFound )
       
  1924                     {
       
  1925                     CSenConnectionChunk* pOperation = (CSenConnectionChunk*)ChunkMapL().ValueAt(index);
       
  1926                     DeliverResponseL(aStatus);
       
  1927                     ChunkMapL().Remove(*pOperation);
       
  1928                     }
       
  1929                 }
       
  1930             else // DISPATCHER IS DISABLED
       
  1931                 {
       
  1932                 DeliverResponseL(aStatus);
       
  1933                 }
       
  1934             break ;
       
  1935             }
       
  1936         }
       
  1937     }
       
  1938 
       
  1939 // Helper function, which delivers response to Service Consumer 
       
  1940 void CSenServiceConnectionImpl::DeliverResponseL(const TInt aErrorCode, CSenChunk* apOperation)
       
  1941     {
       
  1942     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::DeliverResponseL");
       
  1943     iTransactionIdKnown = ETrue;
       
  1944     
       
  1945     TInt statusCode(aErrorCode);
       
  1946     TPtrC8 response(KNullDesC8);
       
  1947     CSenMessageBase* pMessage = NULL;
       
  1948     if( apOperation )
       
  1949         {
       
  1950         pMessage = CSenMessageBase::NewLC(*apOperation);
       
  1951         iResponse = pMessage;
       
  1952 
       
  1953         TInt retVal = apOperation->DescFromChunk(response);
       
  1954         if( retVal == KErrNone )
       
  1955             {
       
  1956             TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- DescFromChunk ok");
       
  1957             // If data was read ok from chunk, then the status code is in 
       
  1958             // the IPC arg that was written by Core over process boundary:
       
  1959             statusCode = iErrorNumber; 
       
  1960             }
       
  1961         else
       
  1962             {
       
  1963             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- DescFromChunk failed: %d"), retVal));
       
  1964             statusCode = retVal;
       
  1965             response.Set(KNullDesC8);
       
  1966             }
       
  1967         }
       
  1968 
       
  1969 
       
  1970     if( ipHostletConsumer )
       
  1971         {
       
  1972         ipHostletConsumer->SetConnectionId( iConnectionID );
       
  1973         }        
       
  1974 
       
  1975         
       
  1976     if( statusCode == KErrNone )
       
  1977         {
       
  1978         // STANDARD, "OK" RESPONSE
       
  1979         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- response, (%d bytes):"), response.Length()));
       
  1980         TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,(response));
       
  1981         TRAPD( err, iObserver->HandleMessageL( response ); )
       
  1982         if(err)
       
  1983             {
       
  1984             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("DeliverResponseL: HandleMessageL() leaved: %d"), err));
       
  1985             }
       
  1986         }
       
  1987     else  // SOAP FAULT or ERROR
       
  1988         {
       
  1989         if( statusCode == KErrSenSoapFault)
       
  1990             {
       
  1991             TInt error = statusCode;   
       
  1992                 
       
  1993             // SOAP FAULT
       
  1994             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KNormalLogLevel , _L8("- SOAP fault (%d bytes):"), response.Length()));
       
  1995             TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,(response));
       
  1996 
       
  1997             if ( error == KErrSenSoapFault && !iInitialized ) // China DC
       
  1998                 {
       
  1999                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::DeliverResponseL:");
       
  2000                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- Since the SC is NOT ready, pass KErrSenAuthenticationFault to HandleErrorL instead of KErrSenSoapFault");
       
  2001                 error = KErrSenAuthenticationFault;
       
  2002                 }
       
  2003             TRAPD(err, iObserver->HandleErrorL( error, response ));
       
  2004             if(err)
       
  2005                 {
       
  2006                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("DeliverResponseL: HandleErrorL() leaved: %d"), err));
       
  2007                 }
       
  2008             }
       
  2009         else // some other ERROR, not a SOAPFault
       
  2010             {
       
  2011             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- error code (%d), error data (%d bytes):"), statusCode, response.Length()));
       
  2012             TLSLOG_ALL(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,(response));
       
  2013 
       
  2014             TRAPD(err, iObserver->HandleErrorL(statusCode, response));
       
  2015             if(err)
       
  2016                 {
       
  2017                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("DeliverResponseL: HandleErrorL() leaved: %d"), err));
       
  2018                 }
       
  2019             }
       
  2020         }
       
  2021     if( apOperation )
       
  2022         {
       
  2023         iResponse = NULL;
       
  2024         CleanupStack::PopAndDestroy( pMessage );
       
  2025         }
       
  2026     iTransactionIdKnown = EFalse;
       
  2027     }
       
  2028 
       
  2029 void CSenServiceConnectionImpl::DoCancel()
       
  2030     {
       
  2031     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::DoCancel")));
       
  2032 	if (iCancelSession == EFalse)
       
  2033 	{
       
  2034 	    if( iDispatcherEnabled )
       
  2035 	        {
       
  2036 	        ipSenServiceDispatcher->ResetQueue();
       
  2037 	        }
       
  2038 
       
  2039 	    TInt cancelLeaveCode(KErrNone);
       
  2040 	    CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  2041 	    TRAP(cancelLeaveCode, iConnection.CancelSession(pSenAO->iStatus));
       
  2042 #ifdef _SENDEBUG
       
  2043 	    if(cancelLeaveCode!=KErrNone)
       
  2044 	        {
       
  2045 	        TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- CancelSession leaved: %d)"), 
       
  2046 	            cancelLeaveCode));
       
  2047 	        }
       
  2048 #endif //_SENDEBUG  
       
  2049 	    cancelLeaveCode=0;
       
  2050 	    TRequestStatus* status = &iStatus;
       
  2051 	    User::RequestComplete( status, KErrCancel );
       
  2052   		//iCancelSession = ETrue;
       
  2053 	}
       
  2054     TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel,(_L("CSenServiceConnectionImpl::DoCancel Completed")));
       
  2055     }
       
  2056 
       
  2057 RFileLogger* CSenServiceConnectionImpl::Log() const
       
  2058     {
       
  2059     return (RFileLogger*) &iLog;
       
  2060     }
       
  2061 
       
  2062 
       
  2063 TInt CSenServiceConnectionImpl::SendL(CSenSoapEnvelope& aMessage )
       
  2064     {
       
  2065     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP)");
       
  2066 
       
  2067     TInt retVal = CheckConnection();
       
  2068     
       
  2069     if(retVal == KErrNone)
       
  2070         {
       
  2071         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  2072         if( pOperation )
       
  2073         	{
       
  2074 #ifdef _SENDEBUG
       
  2075 	        pOperation->SetLogger( &iLog );
       
  2076 #endif // _SENDEBUG
       
  2077 	        retVal = pOperation->CreateChunk();
       
  2078 	        if (retVal == KErrNone)
       
  2079 	            {
       
  2080 	            retVal = AssignPropertiesToChunkL(*pOperation, aMessage);	//codescannerwarnings
       
  2081 	            if (retVal == KErrNone)
       
  2082 	                {
       
  2083 	                pOperation->ChunkHeader().SetMessageType(MSenMessage::ESoapMessage);
       
  2084 	                retVal = SendL(pOperation);
       
  2085 	                }
       
  2086 	            }
       
  2087         	}
       
  2088 		else
       
  2089 			{
       
  2090 #ifdef _SENDEBUG        
       
  2091 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP) - KErrServerBusy");
       
  2092 #endif // _SENDEBUG
       
  2093 			return KErrServerBusy;    	
       
  2094 			}
       
  2095         }
       
  2096 #ifdef _SENDEBUG        
       
  2097     else
       
  2098     	{
       
  2099         // error occured in CheckConnection()  	
       
  2100         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SendL(SOAP) - CheckConnection failed, error(%d)"), retVal ));
       
  2101     	}	 
       
  2102 #endif // _SENDEBUG    	
       
  2103 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP) Completed");
       
  2104     return retVal;
       
  2105     }
       
  2106 
       
  2107 TInt CSenServiceConnectionImpl::SubmitL(CSenSoapEnvelope& aMessage, 
       
  2108                                         HBufC8*& aResponseTo)
       
  2109     {
       
  2110     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL(SOAP)");
       
  2111 
       
  2112     TInt retVal = CheckConnection();
       
  2113     
       
  2114     if(retVal == KErrNone)
       
  2115         {
       
  2116         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  2117         if( pOperation )
       
  2118         	{
       
  2119 	        CleanupStack::PushL( pOperation );
       
  2120 #ifdef _SENDEBUG
       
  2121 	        pOperation->SetLogger( &iLog );
       
  2122 #endif // _SENDEBUG
       
  2123 	        retVal = pOperation->CreateChunk();
       
  2124 	        if (retVal == KErrNone)
       
  2125 	            {
       
  2126 	            retVal = AssignPropertiesToChunkL(*pOperation, aMessage);	//codescannerwarnings
       
  2127 	            if (retVal == KErrNone)
       
  2128 	                {
       
  2129 	                pOperation->ChunkHeader().SetMessageType(MSenMessage::ESoapMessage);
       
  2130 	                retVal = SubmitL(*pOperation);
       
  2131 	                if (retVal != KErrNone && retVal != KErrSenSoapFault)
       
  2132 	                    {
       
  2133 	                    aResponseTo = NULL;
       
  2134 	                    }
       
  2135 	                else
       
  2136 	                    {
       
  2137 	                    retVal = ResponseFromChunk(*pOperation, aResponseTo);
       
  2138 	                    }
       
  2139 	                }
       
  2140 	            }
       
  2141 	        CleanupStack::PopAndDestroy(pOperation);
       
  2142         	}
       
  2143 		else
       
  2144 			{
       
  2145 #ifdef _SENDEBUG        
       
  2146 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL(SOAP) - KErrServerBusy");
       
  2147 #endif // _SENDEBUG
       
  2148 			return KErrServerBusy;    	
       
  2149 			}
       
  2150         }
       
  2151 #ifdef _SENDEBUG        
       
  2152     else
       
  2153     	{
       
  2154         // error occured in CheckConnection()  	
       
  2155         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SubmitL(SOAP) - CheckConnection failed, error(%d)"), retVal ));
       
  2156     	}	 
       
  2157 #endif // _SENDEBUG    	
       
  2158 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL(SOAP) Completed");
       
  2159     return retVal;
       
  2160     }
       
  2161     
       
  2162 
       
  2163 CSenElement& CSenServiceConnectionImpl::AsElement()
       
  2164     {
       
  2165     return iFragment->AsElement();
       
  2166     }
       
  2167 
       
  2168     /**
       
  2169     *  @return the current object as element. May return NULL.
       
  2170     *          Caller takes ownership.
       
  2171 */
       
  2172 CSenElement* CSenServiceConnectionImpl::ExtractElement()
       
  2173     {
       
  2174     return iFragment->ExtractElement();
       
  2175     }
       
  2176 
       
  2177 void CSenServiceConnectionImpl::SetReader(CSenXmlReader& aReader)
       
  2178     {
       
  2179     iFragment->SetReader(aReader);
       
  2180     }
       
  2181 
       
  2182 CSenXmlReader* CSenServiceConnectionImpl::Reader()
       
  2183     {
       
  2184     return iFragment->Reader();
       
  2185     }
       
  2186 
       
  2187 void CSenServiceConnectionImpl::ParseL(const TDesC8& aBuf)
       
  2188     {
       
  2189     iFragment->ParseL(aBuf);
       
  2190     }
       
  2191 
       
  2192 TInt CSenServiceConnectionImpl::BuildFrom(const TDesC8& aBuf)
       
  2193     {
       
  2194     return iFragment->BuildFrom(aBuf);
       
  2195     }
       
  2196 
       
  2197 void CSenServiceConnectionImpl::DelegateParsingL(MSenFragment& aDelegate)
       
  2198     {
       
  2199     iFragment->DelegateParsingL(aDelegate);
       
  2200     }
       
  2201 
       
  2202 void CSenServiceConnectionImpl::DelegateParsingL(
       
  2203                                          const TDesC8& aNsUri,
       
  2204                                          const TDesC8& aLocalName,
       
  2205                                          const TDesC8& aQName,
       
  2206                                          const RAttributeArray& aAttributes)
       
  2207     {
       
  2208     iFragment->DelegateParsingL(aNsUri, aLocalName, aQName, aAttributes);
       
  2209     }
       
  2210 
       
  2211 void CSenServiceConnectionImpl::ParseWithL(CSenXmlReader& aReader)
       
  2212     {
       
  2213     iFragment->ParseWithL(aReader);
       
  2214     }
       
  2215 
       
  2216 void CSenServiceConnectionImpl::SetOwner(MSenFragment& aFragment)
       
  2217     {
       
  2218     iFragment->SetOwner(aFragment);
       
  2219     }
       
  2220 
       
  2221 void CSenServiceConnectionImpl::ResumeParsingFromL( const TDesC8& aNsUri,
       
  2222                                                     const TDesC8& aLocalName,
       
  2223                                                     const TDesC8& aQName)
       
  2224     {
       
  2225     iFragment->ResumeParsingFromL(aNsUri, aLocalName, aQName);
       
  2226     }
       
  2227 
       
  2228 void CSenServiceConnectionImpl::SetAttributesL(
       
  2229                                             const RAttributeArray& aAttributes)
       
  2230     {
       
  2231     iFragment->SetAttributesL(aAttributes);
       
  2232     }
       
  2233 
       
  2234 
       
  2235 void CSenServiceConnectionImpl::WriteStartElementL(
       
  2236                                 const TDesC8& aNsUri,
       
  2237                                 const TDesC8& aLocalName,
       
  2238                                 const TDesC8& aQName,
       
  2239                                 const RAttributeArray& aAttributes
       
  2240                                 )
       
  2241     {
       
  2242     iFragment->WriteStartElementL(aNsUri, aLocalName, aQName, aAttributes);
       
  2243     }
       
  2244 
       
  2245 void CSenServiceConnectionImpl::WriteEndElementL(
       
  2246                               const TDesC8& aNsUri,
       
  2247                               const TDesC8& aLocalName,
       
  2248                               const TDesC8& aQName
       
  2249                               )
       
  2250     {
       
  2251     iFragment->WriteEndElementL(aNsUri, aLocalName, aQName);
       
  2252     }
       
  2253 
       
  2254 
       
  2255 TInt CSenServiceConnectionImpl::ServiceDescriptionL(HBufC8*& aServiceDescription)
       
  2256     {
       
  2257     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::ServiceDescriptionL");
       
  2258 
       
  2259     TInt retVal(KErrSenNotInitialized);
       
  2260     
       
  2261     if(iInitialized)
       
  2262         {
       
  2263         iResponseLength = 0;
       
  2264         iInBuffer.Set(reinterpret_cast<TUint8*>(&iResponseLength),
       
  2265             sizeof(TInt),
       
  2266             sizeof(TInt));
       
  2267 
       
  2268         retVal = iConnection.RequestServiceDescription(iInBuffer);
       
  2269         if(retVal==KErrNone)
       
  2270             {
       
  2271             if(iResponseLength<1)
       
  2272                 {
       
  2273                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"- FATAL error in RequestServiceDescription:");
       
  2274                 TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"  return code OK, response size <= 0 bytes!");
       
  2275                 aServiceDescription = NULL;
       
  2276                 return KErrUnderflow;
       
  2277                 }
       
  2278 
       
  2279             aServiceDescription = HBufC8::NewL(iResponseLength);
       
  2280             TPtr8 buf = aServiceDescription->Des();
       
  2281             retVal = iConnection.ReceiveServiceDescription(buf);
       
  2282             }
       
  2283         }
       
  2284     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::ServiceDescriptionL Completed");
       
  2285     return retVal;
       
  2286     }
       
  2287 
       
  2288 
       
  2289 const TDesC8& CSenServiceConnectionImpl::LocalName() const
       
  2290     {
       
  2291     if(iFragment)
       
  2292         return iFragment->LocalName();
       
  2293     else
       
  2294         return KNullDesC8;
       
  2295     }
       
  2296 
       
  2297 const TDesC8& CSenServiceConnectionImpl::NsUri() const
       
  2298     {
       
  2299     if(iFragment)
       
  2300         return iFragment->NsUri();
       
  2301     else
       
  2302         return KNullDesC8;
       
  2303     }
       
  2304 
       
  2305 const TDesC8& CSenServiceConnectionImpl::NsPrefix() const
       
  2306     {
       
  2307     if(iFragment)
       
  2308         return iFragment->NsPrefix();
       
  2309     else
       
  2310         return KNullDesC8;
       
  2311     }
       
  2312 
       
  2313 void CSenServiceConnectionImpl::WriteAsXMLToL(RWriteStream& aWriteStream)
       
  2314     {
       
  2315     if(iFragment)
       
  2316         {
       
  2317         iFragment->WriteAsXMLToL(aWriteStream);
       
  2318         }
       
  2319     }
       
  2320 
       
  2321 HBufC* CSenServiceConnectionImpl::AsXmlUnicodeL()
       
  2322     {
       
  2323     if(iFragment)
       
  2324         {
       
  2325         return iFragment->AsXmlUnicodeL();
       
  2326         }
       
  2327     else
       
  2328         {
       
  2329         return KNullDesC().AllocL();
       
  2330         }
       
  2331     }
       
  2332 
       
  2333 HBufC8* CSenServiceConnectionImpl::AsXmlL()
       
  2334     {
       
  2335     if(iFragment)
       
  2336         {
       
  2337         return iFragment->AsXmlL();
       
  2338         }
       
  2339     else
       
  2340         {
       
  2341         return KNullDesC8().AllocL();
       
  2342         }
       
  2343     }
       
  2344 
       
  2345 TInt CSenServiceConnectionImpl::StartTransaction()
       
  2346     {
       
  2347     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::StartTransaction");
       
  2348     
       
  2349     TInt retVal = CheckConnection();
       
  2350     
       
  2351     if(retVal == KErrNone)
       
  2352         {
       
  2353         	retVal = iConnection.StartTransaction();	
       
  2354         	
       
  2355         }    
       
  2356     else if(retVal == KErrSenNotInitialized)
       
  2357     	{  	
       
  2358     	 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8(" CSenServiceConnectionImpl::StartTransaction - Error(%d)"), 
       
  2359             KErrSenNotInitialized ));
       
  2360     	}	 
       
  2361     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::StartTransaction Completed");
       
  2362     return retVal;
       
  2363     }
       
  2364 
       
  2365 TInt CSenServiceConnectionImpl::TransactionCompleted()
       
  2366     {
       
  2367     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::TransactionCompleted");
       
  2368     TInt retVal = CheckConnection();
       
  2369     
       
  2370     if(retVal == KErrNone)
       
  2371         {
       
  2372         	retVal = iConnection.TransactionCompleted();	
       
  2373         }    
       
  2374     else if(retVal == KErrSenNotInitialized)
       
  2375     	{
       
  2376     	 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8(" CSenServiceConnectionImpl::TransactionCompleted - Error(%d)"), 
       
  2377             KErrSenNotInitialized )); 		
       
  2378     	}
       
  2379     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::TransactionCompleted Completed");
       
  2380     return retVal;    
       
  2381     }
       
  2382 
       
  2383 TBool CSenServiceConnectionImpl::ConsistsOfL(MSenFragment& aCandidate)
       
  2384     {
       
  2385     if (iFragment)
       
  2386         {
       
  2387         return iFragment->ConsistsOfL(aCandidate);
       
  2388         }
       
  2389     else
       
  2390         {
       
  2391         return EFalse;
       
  2392         }
       
  2393     }
       
  2394 
       
  2395 
       
  2396 TInt CSenServiceConnectionImpl::CancelAllRequests()
       
  2397     {
       
  2398     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::CancelAllRequests(sync)");
       
  2399     if ( iDispatcherEnabled )
       
  2400         {
       
  2401         ipSenServiceDispatcher->ResetQueue();
       
  2402         }
       
  2403     TInt cancelLeaveCode(KErrNone);
       
  2404     TInt retVal(KErrNone);
       
  2405     CSenAsyncOperation* pSenAO = CSenAsyncOperation::NewL(this);
       
  2406     TRAP( cancelLeaveCode, iConnection.CancelSession(pSenAO->iStatus); )
       
  2407 
       
  2408     if(cancelLeaveCode!=KErrNone)
       
  2409         {
       
  2410         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CancelSession() leaved with (code: %d)"), cancelLeaveCode));
       
  2411         if(retVal==KErrNone)
       
  2412             {
       
  2413             retVal = cancelLeaveCode;
       
  2414             }
       
  2415         }
       
  2416 
       
  2417 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::CancelAllRequests(sync) Completed");
       
  2418     return retVal;
       
  2419     }
       
  2420 
       
  2421 TInt CSenServiceConnectionImpl::TxnId()
       
  2422     {
       
  2423     if( iTransactionIdKnown )
       
  2424         {
       
  2425         if( iTxnId>KErrNone )
       
  2426             {
       
  2427             if( iDispatcherEnabled )
       
  2428                 {
       
  2429                 TInt virtualTransactionId = ipSenServiceDispatcher->GetVirtualTransactionID( &iTxnId );
       
  2430                 return virtualTransactionId;
       
  2431                 }
       
  2432             else
       
  2433                 {
       
  2434                 return iTxnId;
       
  2435                 }
       
  2436             }
       
  2437         else
       
  2438             {
       
  2439             return KErrNotFound;
       
  2440             }
       
  2441         }
       
  2442     else
       
  2443         {
       
  2444         return KErrNotFound;
       
  2445         }
       
  2446     }
       
  2447     
       
  2448 MSenMessage* CSenServiceConnectionImpl::Response()
       
  2449     {
       
  2450     return iResponse;
       
  2451     }
       
  2452     
       
  2453 TInt CSenServiceConnectionImpl::SetTransportPropertiesL(const TDesC8& aProperties)
       
  2454     {
       
  2455     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SetTransportProperties");
       
  2456 
       
  2457     TInt retVal(KErrSenNotInitialized);
       
  2458     
       
  2459     if(iInitialized)
       
  2460         {
       
  2461         CSenChunk* pSenChunk = CSenChunk::NewLC(NextChunkName());
       
  2462         pSenChunk->SetLogger(Log());
       
  2463         retVal = pSenChunk->CreateChunk();
       
  2464         if (retVal == KErrNone)
       
  2465             {
       
  2466             retVal = pSenChunk->DescToChunk(aProperties);
       
  2467             if (retVal == KErrNone)
       
  2468                 {
       
  2469                 retVal = iConnection.SetTransportPropertiesL(*pSenChunk);
       
  2470                 }
       
  2471             }
       
  2472         CleanupStack::PopAndDestroy(pSenChunk);
       
  2473         }
       
  2474     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SetTransportProperties Completed");
       
  2475     return retVal;
       
  2476     }
       
  2477     
       
  2478 TInt CSenServiceConnectionImpl::CancelTransaction(TInt aTransactionID)
       
  2479     {
       
  2480     if ( iDispatcherEnabled ) // DISPATCHER IS ENABLED
       
  2481         {
       
  2482         TInt actualTransID = ipSenServiceDispatcher->GetActualTransactionID(&aTransactionID);
       
  2483         
       
  2484     	if( actualTransID != KErrNotFound )
       
  2485     		{
       
  2486         	iConnection.CancelRequest(actualTransID);
       
  2487     		}
       
  2488     	else
       
  2489         	{
       
  2490     	TMessage message = ipSenServiceDispatcher->GetMessageFromQueue(aTransactionID);
       
  2491     	CSenAsyncOperation* pAsyncOp = message.iSenAsyncOperation;
       
  2492     	if (pAsyncOp)
       
  2493     	    {
       
  2494             TInt idx = AsyncOpsArrayL().Find(pAsyncOp);    
       
  2495             if (idx >= 0)
       
  2496                 {
       
  2497                 AsyncOpsArrayL().Remove(idx);
       
  2498                 }
       
  2499     	    pAsyncOp->iActive = NULL;
       
  2500     	    
       
  2501     	    pAsyncOp->Cancel();
       
  2502             delete pAsyncOp;
       
  2503             pAsyncOp = NULL;
       
  2504             }
       
  2505     	ipSenServiceDispatcher->RemoveFromQueue(aTransactionID);
       
  2506     	DeliverResponseL(KErrSenCancelled,NULL);
       
  2507     	}  
       
  2508         }
       
  2509     else // DISPATCHER IS DISABLED
       
  2510         {
       
  2511         iConnection.CancelRequest(aTransactionID);
       
  2512         }
       
  2513     return KErrNone;
       
  2514     }
       
  2515         
       
  2516 TInt CSenServiceConnectionImpl::TransportPropertiesL(HBufC8*& aProperties)
       
  2517     {
       
  2518     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::TransportPropertiesL");
       
  2519 
       
  2520     TInt retVal(KErrSenNotInitialized);
       
  2521     
       
  2522     if(iInitialized)
       
  2523         {
       
  2524         CSenChunk* pSenChunk = CSenChunk::NewLC(NextChunkName());
       
  2525         pSenChunk->SetLogger(Log());
       
  2526         retVal = pSenChunk->CreateChunk();
       
  2527         if (retVal == KErrNone)
       
  2528             {
       
  2529             retVal = iConnection.TransportPropertiesL(*pSenChunk);
       
  2530             if(retVal == KErrNone)
       
  2531                 {
       
  2532                 TPtrC8 transportProperties;
       
  2533                 retVal = pSenChunk->DescFromChunk(transportProperties);
       
  2534                 if(retVal == KErrNone)
       
  2535                     {
       
  2536                     aProperties = transportProperties.AllocL();
       
  2537                     }
       
  2538                 }
       
  2539             }
       
  2540         CleanupStack::PopAndDestroy(pSenChunk);
       
  2541         }
       
  2542     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::TransportPropertiesL Completed");
       
  2543     return retVal;
       
  2544     }
       
  2545 
       
  2546 RChunkMap& CSenServiceConnectionImpl::ChunkMapL()
       
  2547     {
       
  2548     if(!iChunkMap)
       
  2549         {
       
  2550         iChunkMap = new (ELeave) RChunkMap(ETrue, ETrue);
       
  2551         }
       
  2552     return *iChunkMap;
       
  2553     }
       
  2554     
       
  2555 RPointerArray<CSenAsyncOperation>& CSenServiceConnectionImpl::AsyncOpsArrayL() //codescannerwarnings
       
  2556     {
       
  2557     if(!iAsyncOpsArray)
       
  2558         {
       
  2559         iAsyncOpsArray = new (ELeave) RPointerArray<CSenAsyncOperation>;
       
  2560         }
       
  2561     return *iAsyncOpsArray;
       
  2562     }
       
  2563 
       
  2564 TInt CSenServiceConnectionImpl::SendL( const TDesC8& aRequest,
       
  2565                                        const TDesC8& aProperties )
       
  2566     {
       
  2567     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL");
       
  2568 
       
  2569     TInt retVal = CheckConnection();
       
  2570     
       
  2571     if(retVal == KErrNone)
       
  2572         {
       
  2573         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  2574         if( pOperation )
       
  2575 	        {
       
  2576 #ifdef _SENDEBUG
       
  2577 	        pOperation->SetLogger( &iLog );
       
  2578 #endif // _SENDEBUG
       
  2579 	        retVal = pOperation->CreateChunk();
       
  2580 	        if (retVal == KErrNone)
       
  2581 	            {
       
  2582 	            retVal = pOperation->DescsToChunk(aRequest, aProperties);
       
  2583 	            if (retVal == KErrNone)
       
  2584 	                {
       
  2585 	                pOperation->ChunkHeader().SetPropertiesType(MSenProperties::ESenTransportProperties);
       
  2586 	                retVal = SendL(pOperation);
       
  2587 	                }
       
  2588 	            }
       
  2589 	        }
       
  2590 		else
       
  2591 			{
       
  2592 #ifdef _SENDEBUG 
       
  2593 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(TDesC8& aRequest,TDesC8& aProrperties)- KErrServerBusy");
       
  2594 #endif // _SENDEBUG
       
  2595 			return KErrServerBusy;    	
       
  2596             }
       
  2597         }
       
  2598 #ifdef _SENDEBUG        
       
  2599     else
       
  2600     	{
       
  2601         // error occured in CheckConnection()  	
       
  2602         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SendL - CheckConnection failed, error(%d)"), retVal ));
       
  2603     	}	 
       
  2604 #endif // _SENDEBUG    	
       
  2605 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL Completed");
       
  2606     return retVal;
       
  2607     }
       
  2608 
       
  2609 TInt CSenServiceConnectionImpl::SubmitL( const TDesC8& aRequest,
       
  2610                                          const TDesC8& aProperties,
       
  2611                                          HBufC8*& aResponse )
       
  2612     {
       
  2613     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL");
       
  2614     TInt retVal = CheckConnection();
       
  2615     if(retVal == KErrNone)
       
  2616         {
       
  2617         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL(NextChunkName(), iIsInternalSC ); // this will return NULL in H/W targets if no chunks available (uses WSD)
       
  2618 		if( pOperation )
       
  2619 			{
       
  2620 	        CleanupStack::PushL( pOperation );
       
  2621 #ifdef _SENDEBUG
       
  2622 	        pOperation->SetLogger( &iLog );
       
  2623 #endif // _SENDEBUG
       
  2624 	        retVal = pOperation->CreateChunk();
       
  2625 	        if (retVal == KErrNone)
       
  2626 	            {
       
  2627 	            retVal = pOperation->DescsToChunk(aRequest, aProperties);
       
  2628 	            if (retVal == KErrNone)
       
  2629 	                {
       
  2630 	                pOperation->ChunkHeader().SetPropertiesType(MSenProperties::ESenTransportProperties);
       
  2631 	                retVal = SubmitL(*pOperation);
       
  2632 	                if (retVal != KErrNone && retVal != KErrSenSoapFault)
       
  2633 	                    {
       
  2634 	                    aResponse = NULL;
       
  2635 	                    }
       
  2636 	                else
       
  2637 	                    {
       
  2638 	                    retVal = ResponseFromChunk(*pOperation, aResponse);
       
  2639 	                    }
       
  2640 	                }
       
  2641 	            }
       
  2642 	        CleanupStack::PopAndDestroy(pOperation);
       
  2643 			}
       
  2644 		else
       
  2645 			{
       
  2646 #ifdef _SENDEBUG        
       
  2647 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL - KErrServerBusy");
       
  2648 #endif // _SENDEBUG
       
  2649 			return KErrServerBusy;    	
       
  2650 			}
       
  2651         }
       
  2652 #ifdef _SENDEBUG        
       
  2653     else
       
  2654     	{
       
  2655         // error occured in CheckConnection()  	
       
  2656         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SubmitL - CheckConnection failed, error(%d)"), retVal ));
       
  2657     	}	 
       
  2658 #endif // _SENDEBUG    	
       
  2659 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL Completed");
       
  2660     return retVal;
       
  2661     }
       
  2662 
       
  2663  TInt CSenServiceConnectionImpl::HttpMethodFromPropertiesL( const TDesC8& aProperties,
       
  2664                                                             CSenHttpTransportProperties::TSenHttpMethod& aMethod )
       
  2665     {
       
  2666     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::HttpMethodFromPropertiesL");
       
  2667     TInt retVal(KErrNotFound);
       
  2668     if ( aProperties.Length() > 0 && aProperties.Find(KHttpMethodLocalName)!= KErrNotFound && 
       
  2669         (aProperties.Find(KHttpGet)!= KErrNotFound || aProperties.Find(KHttpDelete)!= KErrNotFound) ) 
       
  2670         {
       
  2671         // Properties strings are found, now use CSenHttpProperties instance to validate that HTTP
       
  2672         // method really is either HTTP GET or HTTP DELETE:
       
  2673         CSenHttpTransportProperties* pHttpProperties = CSenHttpTransportProperties::NewLC(); // push tp
       
  2674         
       
  2675         // Parse aProperties into HTTP transport properties object:
       
  2676         TInt leaveCode( KErrNone );
       
  2677         TRAP( leaveCode, pHttpProperties->ReadFromL( aProperties ); )
       
  2678         if ( leaveCode == KErrNone )
       
  2679             {
       
  2680             CSenHttpTransportProperties::TSenHttpMethod method;
       
  2681             retVal = pHttpProperties->HttpMethodL( method );
       
  2682             if ( retVal == KErrNone )
       
  2683                 {
       
  2684                 aMethod = method;
       
  2685                 }
       
  2686 #ifdef _SENDEBUG            
       
  2687             else 
       
  2688                 {
       
  2689                 // HttpMethodL failed:
       
  2690                 TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- HttpMethodL call failed. Error code: (%d)"), retVal));
       
  2691                 }
       
  2692 #endif // _SENDEBUG            
       
  2693             }
       
  2694 #ifdef _SENDEBUG            
       
  2695         else 
       
  2696             {
       
  2697             // ReadFromL leaved:
       
  2698             TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- Reading (parsing) of HTTP properties failed. Leave code: (%d)"), leaveCode));
       
  2699             
       
  2700             }
       
  2701 #endif // _SENDEBUG            
       
  2702         CleanupStack::PopAndDestroy( pHttpProperties ); // de-alloc tp
       
  2703         }
       
  2704     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::HttpMethodFromPropertiesL Completed");
       
  2705     return retVal;
       
  2706     }
       
  2707 
       
  2708 TInt CSenServiceConnectionImpl::SendL( CSenSoapEnvelope& aMessage, const TDesC8& aProperties )
       
  2709     {
       
  2710     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP)");
       
  2711 
       
  2712     CSenHttpTransportProperties::TSenHttpMethod httpMethod;
       
  2713     TInt readHttpMethodRetVal = HttpMethodFromPropertiesL( aProperties, httpMethod );
       
  2714 
       
  2715     if ( readHttpMethodRetVal == KErrNone && 
       
  2716          (httpMethod == CSenHttpTransportProperties::ESenHttpGet ||
       
  2717          httpMethod == CSenHttpTransportProperties::ESenHttpDelete ))
       
  2718         {
       
  2719         // At the moment, Service Connection does not support sending 
       
  2720         // of SOAP-ENVs via HTTP headers for GET/DELETE requests:
       
  2721         return KErrNotSupported; // documented in public header(s)
       
  2722         }
       
  2723 
       
  2724     TInt retVal = CheckConnection();
       
  2725     
       
  2726     if(retVal == KErrNone)
       
  2727         {
       
  2728         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  2729 		if( pOperation )
       
  2730 			{
       
  2731 #ifdef _SENDEBUG
       
  2732 	        pOperation->SetLogger( &iLog );
       
  2733 #endif // _SENDEBUG
       
  2734 	        retVal = pOperation->CreateChunk();
       
  2735 	        if (retVal == KErrNone)
       
  2736 	            {
       
  2737 	            retVal = AssignPropertiesToChunkL( *pOperation, aMessage, aProperties );	//codescannerwarnings
       
  2738 	            if (retVal == KErrNone)
       
  2739 	                {
       
  2740 	                pOperation->ChunkHeader().SetMessageType(MSenMessage::ESoapMessage);
       
  2741 	                retVal = SendL(pOperation);
       
  2742 	                }
       
  2743 	            }
       
  2744 			}
       
  2745 		else
       
  2746 			{
       
  2747 #ifdef _SENDEBUG        
       
  2748 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP) - KErrServerBusy");
       
  2749 #endif // _SENDEBUG
       
  2750 			return KErrServerBusy;    	
       
  2751             }
       
  2752         }
       
  2753 #ifdef _SENDEBUG        
       
  2754     else
       
  2755     	{
       
  2756         // error occured in CheckConnection()  	
       
  2757         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SendL(SOAP) - CheckConnection failed, error(%d)"), retVal ));
       
  2758     	}	 
       
  2759 #endif // _SENDEBUG    	
       
  2760 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP) Completed");
       
  2761     return retVal;
       
  2762     }
       
  2763 
       
  2764 TInt CSenServiceConnectionImpl::SubmitL( CSenSoapEnvelope& aMessage, const TDesC8& aProperties, HBufC8*& aResponseTo)
       
  2765     {
       
  2766     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL");
       
  2767 
       
  2768     CSenHttpTransportProperties::TSenHttpMethod httpMethod;
       
  2769     TInt readHttpMethodRetVal = HttpMethodFromPropertiesL( aProperties, httpMethod );
       
  2770 
       
  2771     if ( readHttpMethodRetVal == KErrNone && 
       
  2772          (httpMethod == CSenHttpTransportProperties::ESenHttpGet ||
       
  2773          httpMethod == CSenHttpTransportProperties::ESenHttpDelete ))
       
  2774         {
       
  2775         // At the moment, Service Connection does not support sending 
       
  2776         // of SOAP-ENVs via HTTP headers for GET/DELETE requests:
       
  2777         return KErrNotSupported; // documented in public header(s)
       
  2778         }
       
  2779 
       
  2780     TInt retVal = CheckConnection();
       
  2781     
       
  2782     if(retVal == KErrNone)
       
  2783         {
       
  2784         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  2785     	if( pOperation )
       
  2786 			{
       
  2787 			CleanupStack::PushL( pOperation );
       
  2788 #ifdef _SENDEBUG
       
  2789 	        pOperation->SetLogger( &iLog );
       
  2790 #endif // _SENDEBUG
       
  2791 	        retVal = pOperation->CreateChunk();
       
  2792 	        if (retVal == KErrNone)
       
  2793 	            {
       
  2794 	            retVal = AssignPropertiesToChunkL(*pOperation, aMessage, aProperties);	//codescannerwarnings
       
  2795 	            if (retVal == KErrNone)
       
  2796 	                {
       
  2797 	                pOperation->ChunkHeader().SetMessageType(MSenMessage::ESoapMessage);
       
  2798 	                retVal = SubmitL(*pOperation);
       
  2799 	                if (retVal != KErrNone && retVal != KErrSenSoapFault)
       
  2800 	                    {
       
  2801 	                    aResponseTo = NULL;
       
  2802 	                    }
       
  2803 	                else
       
  2804 	                    {
       
  2805 	                    retVal = ResponseFromChunk(*pOperation, aResponseTo);
       
  2806 	                    }
       
  2807 	                }
       
  2808 	            }
       
  2809 	        CleanupStack::PopAndDestroy(pOperation);
       
  2810 			}
       
  2811 		else
       
  2812 			{
       
  2813 #ifdef _SENDEBUG        
       
  2814 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL( CSenSoapEnvelope&, const TDesC8&, HBufC8*&) - KErrServerBusy");
       
  2815 #endif // _SENDEBUG
       
  2816 			return KErrServerBusy;    	
       
  2817 			}
       
  2818         }
       
  2819 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL Completed");
       
  2820     return retVal;
       
  2821     }
       
  2822 
       
  2823 TInt CSenServiceConnectionImpl::AssignPropertiesToChunkL(CSenChunk& aChunk,
       
  2824                                                         CSenSoapEnvelope& aMessage,
       
  2825                                                         const TDesC8& aProperties)	//codescannerwarnings
       
  2826     {
       
  2827     TInt retVal(KErrNone);
       
  2828     
       
  2829     if ( aMessage.SoapAction2().Length() > 0 )
       
  2830         {
       
  2831         CSenTransportProperties* pProps = CSenTransportProperties::NewLC();
       
  2832         if ( aProperties.Length() > 0 )
       
  2833             {
       
  2834             pProps->ReadFromL(aProperties);
       
  2835             }
       
  2836         // This is performed to achieve two things:
       
  2837         // 1) define HTTP header for SOAP 1.1 binding
       
  2838         // 2) perform step (1) without using HTTP TP, so that each transport plug-in can still parse this value..
       
  2839         pProps->SetPropertyL(KSenSoapActionHeaderName, aMessage.SoapAction2(), KHttpHeaderType);
       
  2840 
       
  2841         HBufC8* pPropsAsXml = pProps->AsUtf8LC();
       
  2842         HBufC8* pSoapMsg = aMessage.AsXmlL();
       
  2843         retVal = aChunk.DescsToChunk(*pSoapMsg, *pPropsAsXml);
       
  2844         aChunk.ChunkHeader().SetPropertiesType(MSenProperties::ESenTransportProperties);
       
  2845         delete pSoapMsg;
       
  2846         CleanupStack::PopAndDestroy(pPropsAsXml);
       
  2847         CleanupStack::PopAndDestroy(pProps);
       
  2848         }
       
  2849     else
       
  2850         {
       
  2851         HBufC8* pSoapMsg = aMessage.AsXmlL();
       
  2852         if ( aProperties.Length() > 0 )
       
  2853             {
       
  2854             retVal = aChunk.DescsToChunk(*pSoapMsg, aProperties);
       
  2855             aChunk.ChunkHeader().SetPropertiesType(MSenProperties::ESenTransportProperties);
       
  2856             }
       
  2857         else
       
  2858             {
       
  2859             retVal = aChunk.DescToChunk(*pSoapMsg);
       
  2860             }
       
  2861         delete pSoapMsg;
       
  2862         }    
       
  2863     
       
  2864     return retVal;
       
  2865     }
       
  2866     
       
  2867 TInt CSenServiceConnectionImpl::AssignMessageToChunkL( CSenChunk& aChunk,
       
  2868                                                       MSenMessage& aMessage ) //codescannerwarnings
       
  2869     {
       
  2870     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::AssignMessageToChunk");
       
  2871     TInt retVal(KErrNone);
       
  2872     
       
  2873     CSenTransportProperties* pTempTransportProperties = NULL;
       
  2874     
       
  2875     MSenProperties* pProperties = aMessage.Properties();
       
  2876     if( !pProperties )
       
  2877         {
       
  2878         // use transport properties in order to serialize SOAP action
       
  2879         pTempTransportProperties = CSenTransportProperties::NewLC();
       
  2880         pProperties = pTempTransportProperties;
       
  2881         }
       
  2882 
       
  2883     if ( aMessage.IsSafeToCast( MSenMessage::ESoapEnvelope2 ) )
       
  2884         {
       
  2885         CSenSoapEnvelope2& message = (CSenSoapEnvelope2&)aMessage;
       
  2886         if ( message.SoapAction().Length() > 0 )
       
  2887             {
       
  2888             if( pProperties->IsSafeToCast( MSenProperties::ESenXmlProperties ) )
       
  2889                 {
       
  2890                 CSenXmlProperties* pConcreteProps = (CSenXmlProperties*)pProperties;
       
  2891                 pConcreteProps->SetPropertyL(KSenSoapActionHeaderName, message.SoapAction(), KHttpHeaderType);
       
  2892                 }
       
  2893             }
       
  2894         }
       
  2895 
       
  2896     HBufC8* pPropsAsXml = pProperties->AsUtf8L();
       
  2897     
       
  2898     if( pTempTransportProperties )
       
  2899         {
       
  2900         CleanupStack::PopAndDestroy( pTempTransportProperties );
       
  2901         }
       
  2902     CleanupStack::PushL(pPropsAsXml);
       
  2903 
       
  2904     RBuf8 buffer;
       
  2905     CleanupClosePushL( buffer );        
       
  2906 	CXmlEngSerializer* pSerializer(NULL);
       
  2907 	if ( aMessage.IsSafeToCast( MSenMessage::ESoapEnvelope2 ) )
       
  2908 	    {
       
  2909 	    pSerializer = CXmlEngSerializer::NewL(ESerializerXOPInfoset);
       
  2910 	    }
       
  2911 	else
       
  2912 	    {
       
  2913 	    pSerializer = CXmlEngSerializer::NewL(ESerializerDefault);
       
  2914 	    }
       
  2915 	CleanupStack::PushL( pSerializer );
       
  2916 	
       
  2917     TUint optionFlags = 0;
       
  2918     // Omit following declarations from the beginning of XML Document:
       
  2919     // <?xml version=\"1.0\...
       
  2920     //   encoding="..."
       
  2921     //   standalone="..."
       
  2922     // ?>
       
  2923     optionFlags = optionFlags | TXmlEngSerializationOptions::KOptionOmitXMLDeclaration;
       
  2924     
       
  2925     // Allow encoding declaration (if KOptionOmitXMLDeclaration is _not_ set)
       
  2926     //optionFlags = optionFlags | TSerializationOptions::KOptionEncoding;
       
  2927     
       
  2928     // Allow standalone declaration (if KOptionOmitXMLDeclaration is _not_ set)
       
  2929     //optionFlags = optionFlags | TSerializationOptions::KOptionStandalone;
       
  2930 
       
  2931     TXmlEngSerializationOptions options(optionFlags);
       
  2932 
       
  2933 	pSerializer->SetOutput(buffer);
       
  2934 	pSerializer->SetSerializationOptions(options);
       
  2935 	
       
  2936     RSenDocument document;
       
  2937     if (aMessage.IsSafeToCast( MSenMessage::ESoapEnvelope2))
       
  2938         {
       
  2939         CSenSoapEnvelope2& message = (CSenSoapEnvelope2&)aMessage;
       
  2940         document = message.AsDocumentL();
       
  2941         }
       
  2942     else if(aMessage.IsSafeToCast( MSenMessage::EAtomMessage))
       
  2943         {
       
  2944         CSenAtomMessage& message = (CSenAtomMessage&)aMessage;
       
  2945         document = message.AsDocumentL();
       
  2946         }
       
  2947     else
       
  2948         {
       
  2949         return KErrNotSupported;
       
  2950         }
       
  2951 	TInt leaveCode(KErrNone);
       
  2952 	
       
  2953 	TRAP( leaveCode, pSerializer->SerializeL(document); )
       
  2954 
       
  2955     if( leaveCode != KErrNone )
       
  2956         {
       
  2957         retVal = leaveCode;
       
  2958         }
       
  2959             
       
  2960     if( retVal == KErrNone )
       
  2961         {
       
  2962 
       
  2963 #ifdef _SENDEBUG
       
  2964         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"-----------------------------------------------------------------------------------");
       
  2965         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"- OK. Message about to send:");
       
  2966         TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,( buffer.Right(100) ));
       
  2967         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
       
  2968         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"- Transport properties:");
       
  2969         if( pPropsAsXml )
       
  2970             {
       
  2971             TPtrC8 properties = pPropsAsXml->Des();
       
  2972             TLSLOG(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,( properties.Right(100) ));
       
  2973             //LOG_WRITEALL(( properties ));
       
  2974             }
       
  2975         TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMaxLogLevel ,"-----------------------------------------------------------------------------------");
       
  2976 #endif // _SENDEBUG        
       
  2977 
       
  2978         retVal = aChunk.DescsToChunk( buffer, *pPropsAsXml );
       
  2979         aChunk.ChunkHeader().SetPropertiesType(MSenProperties::ESenTransportProperties);
       
  2980         }
       
  2981 #ifdef _SENDEBUG
       
  2982     else
       
  2983         {
       
  2984         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- Failed, error code: %d"), retVal ));
       
  2985         }
       
  2986 #endif // _SENDEBUG        
       
  2987         
       
  2988 
       
  2989     CleanupStack::PopAndDestroy(pSerializer);
       
  2990     CleanupStack::PopAndDestroy(&buffer);
       
  2991     CleanupStack::PopAndDestroy(pPropsAsXml);
       
  2992     
       
  2993     return retVal;
       
  2994     }
       
  2995     
       
  2996 // THIS IS THE SECOND, __MUCH IMPROVED__ VARIANT, WHICH SUPPORTS BOTH CHUNK AND FILE ATTACHEMENTS,
       
  2997 // plus multiple BLOBs PER ONE MESSAGE AND multiple simultaneous transfers
       
  2998 TInt CSenServiceConnectionImpl::MoveBinaryContainersToServer( CSenConnectionChunk& aOperation, RArray<TXmlEngDataContainer>& aList )
       
  2999     {
       
  3000     TInt retVal(KErrNone);
       
  3001     
       
  3002     TPtrC8 cid8;
       
  3003     TBuf8<100> cid(KNullDesC8);
       
  3004     TInt size;
       
  3005     TInt offset;
       
  3006 
       
  3007     // First check if we are resending this operation (message). If so, operation has already "parsed" the blob
       
  3008     // Proper solution that allows sending of multiple BLOBS, of various types:
       
  3009     
       
  3010     TInt containerCount( aOperation.ContainerCount() );
       
  3011     if ( containerCount > 0 )
       
  3012 		{
       
  3013 		RBinaryMap& map = aOperation.ContainerMap();
       
  3014 		TBool noError(ETrue);
       
  3015 		for (TInt i = 0; i < containerCount && noError; i++)
       
  3016 		    {
       
  3017 		    TDesC8* pCid = map.KeyAt(i);
       
  3018 		    const CSenBinaryContainer* pContainer = map.ValueAt(i);
       
  3019 		    if( pCid && pContainer )
       
  3020 		        {
       
  3021 		        TPtrC8 cid = pContainer->Cid();
       
  3022 		        CSenBinaryContainer::TDataType type = pContainer->Type();
       
  3023 		        switch( type )
       
  3024 		            {
       
  3025 	                case CSenBinaryContainer::EFile:
       
  3026 	                    {
       
  3027 	                    RFile file = pContainer->File();
       
  3028                         retVal = iConnection.MoveFile( aOperation, cid, file );
       
  3029                         if ( retVal != KErrNone )
       
  3030                             {
       
  3031                             noError = EFalse;
       
  3032                             break;
       
  3033                             }                        
       
  3034 	                    }
       
  3035 	                break;
       
  3036 	                
       
  3037 	                case CSenBinaryContainer::EChunk:
       
  3038 	                    {
       
  3039 	                    RChunk chunk = pContainer->Chunk();
       
  3040 	                    TInt size = pContainer->ChunkSize();
       
  3041 	                    TInt offset = pContainer->ChunkOffset();
       
  3042                         retVal = iConnection.MoveChunk( aOperation, cid, chunk, size, offset );
       
  3043                         if ( retVal != KErrNone )
       
  3044                             {
       
  3045                             noError = EFalse;
       
  3046                             break;
       
  3047                             }                        
       
  3048 	                    }
       
  3049 	                break;
       
  3050 	                default:
       
  3051 	                // do nothing
       
  3052 	                break;
       
  3053 		            }
       
  3054 		        }
       
  3055 		    }
       
  3056 		}
       
  3057     else
       
  3058         {
       
  3059         // this is the first time that we are movign binary containers to the server(!)
       
  3060     	TInt count = aList.Count();	
       
  3061     	for(TInt i = 0; i < count /* && retVal == KErrNone*/; i++)
       
  3062     		{
       
  3063     		if ( aList[i].NodeType() == TXmlEngNode::EChunkContainer )
       
  3064     			{
       
  3065     			cid = aList[i].Cid();
       
  3066     			size = aList[i].Size();
       
  3067     			offset = aList[i].AsChunkContainer().ChunkOffset();
       
  3068     			RChunk& chunk = aList[i].AsChunkContainer().Chunk();
       
  3069     			aOperation.AddChunkToContainerMap( cid, chunk, size, offset );
       
  3070     			cid8.Set(cid.Ptr(), cid.Length());
       
  3071                 retVal = iConnection.MoveChunk( aOperation, cid8, chunk, offset, size );
       
  3072                 
       
  3073                 if ( retVal != KErrNone )
       
  3074                     {
       
  3075                     break;
       
  3076                     }
       
  3077     			}
       
  3078     		else if( aList[i].NodeType() == TXmlEngNode::EFileContainer )
       
  3079     			{
       
  3080     			cid = aList[i].Cid();
       
  3081     			RFile& file = aList[i].AsFileContainer().File();
       
  3082     			
       
  3083     			// Real solution that supports sending of multiple files / BLOBs
       
  3084     			aOperation.AddFileToContainerMap( cid, file );
       
  3085     			cid8.Set(cid.Ptr(), cid.Length());
       
  3086                 retVal = iConnection.MoveFile( aOperation, cid8, file );
       
  3087 
       
  3088                 if ( retVal != KErrNone )
       
  3089                     {
       
  3090                     break;
       
  3091                     }
       
  3092     			}
       
  3093     		}
       
  3094         }
       
  3095     return retVal;
       
  3096     }
       
  3097     
       
  3098 TInt CSenServiceConnectionImpl::MoveFileChunkHandleToServer(CSenConnectionChunk& aOperation)
       
  3099     {
       
  3100     TInt retVal(KErrNone);
       
  3101     retVal = iConnection.SendFileHandle(aOperation,iSharedFileHandle);
       
  3102     return retVal;
       
  3103     }
       
  3104     
       
  3105     //Sending  Large File Throught RFile handle 
       
  3106 TInt CSenServiceConnectionImpl::SendL(RFile& aFile)
       
  3107     {
       
  3108   	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(RFile)");
       
  3109 
       
  3110 	TInt retVal(KErrNone);
       
  3111   	retVal = CheckConnection();
       
  3112   	 if(retVal == KErrNone)
       
  3113 	    {
       
  3114          if (aFile.SubSessionHandle() )
       
  3115          {
       
  3116         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL(NextChunkName()); 
       
  3117         
       
  3118         if( pOperation )
       
  3119         	{
       
  3120 			#ifdef _SENDEBUG
       
  3121 			        pOperation->SetLogger(&iLog);
       
  3122 			#endif
       
  3123 			        retVal = pOperation->CreateChunk();
       
  3124 			        pOperation->HasSharedFileHandle(ETrue);
       
  3125 			        iSharedFileHandle = aFile;
       
  3126 			        if (retVal == KErrNone)	            
       
  3127 			        	{
       
  3128 						retVal = SendL(pOperation);	
       
  3129 			            }
       
  3130         	}
       
  3131 		else
       
  3132 			{
       
  3133 #ifdef _SENDEBUG        
       
  3134 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP) - KErrServerBusy");
       
  3135 #endif // _SENDEBUG
       
  3136 			return KErrServerBusy;    	
       
  3137 			}
       
  3138 			
       
  3139         }
       
  3140         else
       
  3141         {
       
  3142         	
       
  3143 			TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("MSenServiceConsumer::HandleMessageFromChildAOL - HandleErrorL leaves with %d"), retVal));
       
  3144             retVal=KErrArgument;
       
  3145         	}
       
  3146          
       
  3147         }
       
  3148     
       
  3149     
       
  3150 #ifdef _SENDEBUG        
       
  3151     else
       
  3152     	{
       
  3153         // error occured in CheckConnection()  	
       
  3154         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SendL(SOAP) - CheckConnection failed, error(%d)"), retVal ));
       
  3155     	}	 
       
  3156 #endif // _SENDEBUG    	
       
  3157 
       
  3158     return retVal;
       
  3159       
       
  3160     }
       
  3161     
       
  3162 TInt CSenServiceConnectionImpl::SendL( MSenMessage& aMessage )
       
  3163     {
       
  3164     if ( aMessage.IsSafeToCast( MSenMessage::ESoapEnvelope2 ) )
       
  3165         {
       
  3166         CSenSoapEnvelope2& message = (CSenSoapEnvelope2&)aMessage;
       
  3167         return SendL(message);
       
  3168         }
       
  3169     else
       
  3170         {
       
  3171         return KErrNotSupported;
       
  3172         }
       
  3173     }
       
  3174 
       
  3175     
       
  3176 TInt CSenServiceConnectionImpl::SendL( CSenSoapEnvelope2& aMessage )
       
  3177     {
       
  3178     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(CSenSoapEnvelope2)");
       
  3179 
       
  3180     MSenProperties* pProperties = aMessage.Properties();
       
  3181     if( pProperties && pProperties->IsSafeToCast( MSenProperties::ESenHttpTransportProperties ) )
       
  3182         {
       
  3183         CSenHttpTransportProperties& properties = (CSenHttpTransportProperties&)*pProperties;
       
  3184         CSenHttpTransportProperties::TSenHttpMethod httpMethod;
       
  3185         TInt readHttpMethodRetVal = properties.HttpMethodL( httpMethod );
       
  3186 
       
  3187         if ( readHttpMethodRetVal == KErrNone && 
       
  3188              (httpMethod == CSenHttpTransportProperties::ESenHttpGet ||
       
  3189              httpMethod == CSenHttpTransportProperties::ESenHttpDelete ))
       
  3190             {
       
  3191             // At the moment, Service Connection does not support sending 
       
  3192             // of SOAP-ENVs via HTTP headers for GET/DELETE requests:
       
  3193             return KErrNotSupported; // documented in public header(s)
       
  3194             }
       
  3195         }
       
  3196 
       
  3197     TInt retVal = CheckConnection();
       
  3198     
       
  3199     if(retVal == KErrNone)
       
  3200         {
       
  3201         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  3202 	    if( pOperation )
       
  3203 	        {
       
  3204 #ifdef _SENDEBUG
       
  3205         pOperation->SetLogger(&iLog);
       
  3206 #endif
       
  3207 
       
  3208         retVal = pOperation->CreateChunk();
       
  3209         if (retVal == KErrNone)
       
  3210             {
       
  3211             pOperation->ChunkHeader().SetMessageType(aMessage.Type());
       
  3212             
       
  3213             // we can cast, condition is checked at the begin of that method
       
  3214             RSenDocument document;
       
  3215             if (aMessage.IsSafeToCast( MSenMessage::ESoapEnvelope2))
       
  3216                 {
       
  3217                 CSenSoapEnvelope2& message = (CSenSoapEnvelope2&)aMessage;
       
  3218                 document = message.AsDocumentL();
       
  3219                 }
       
  3220             else if(aMessage.IsSafeToCast( MSenMessage::EAtomMessage))
       
  3221                 {
       
  3222                 CSenAtomMessage& message = (CSenAtomMessage&)aMessage;
       
  3223                 document = message.AsDocumentL();
       
  3224                 }
       
  3225 	        document.GetDataContainerList(pOperation->BinaryDataArrayL());	//codescannerwarnings
       
  3226 	        pOperation->RemoveBinaryDataArrayIfEmpty();
       
  3227             
       
  3228             retVal = AssignMessageToChunkL(*pOperation, aMessage);	//codescannerwarnings
       
  3229             if (retVal == KErrNone)
       
  3230                 {
       
  3231                 retVal = SendL(pOperation);
       
  3232                 }
       
  3233             }
       
  3234 #ifdef _SENDEBUG
       
  3235 			else
       
  3236 				{
       
  3237 			        TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("-pOperation->CreateChunk Failed, error code: %d"), retVal ));
       
  3238 				}
       
  3239 #endif // _SENDEBUG
       
  3240 	        }
       
  3241 		else
       
  3242 			{
       
  3243 #ifdef _SENDEBUG        
       
  3244 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(SOAP-MSG2) - KErrServerBusy");
       
  3245 #endif // _SENDEBUG
       
  3246 			return KErrServerBusy;    	
       
  3247 			}
       
  3248         }
       
  3249 #ifdef _SENDEBUG        
       
  3250     else
       
  3251     	{
       
  3252         // error occured in CheckConnection()  	
       
  3253         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SendL(SOAP-MSG2) - CheckConnection failed, error(%d)"), retVal ));
       
  3254     	}	 
       
  3255 #endif // _SENDEBUG    	
       
  3256 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SendL(CSenSoapEnvelope2) Completed");
       
  3257     return retVal;
       
  3258     }
       
  3259 
       
  3260 TInt CSenServiceConnectionImpl::SubmitL( MSenMessage& aMessage,
       
  3261                                          CSenSoapEnvelope2*& aResponseTo )
       
  3262     {
       
  3263     if ( aMessage.IsSafeToCast( MSenMessage::ESoapEnvelope2) )
       
  3264         {
       
  3265         CSenSoapEnvelope2& message = (CSenSoapEnvelope2&)aMessage;
       
  3266         
       
  3267         return SubmitL(message, aResponseTo);
       
  3268         }
       
  3269     else
       
  3270         {
       
  3271         return KErrNotSupported; 
       
  3272         }
       
  3273     }
       
  3274 
       
  3275 TInt CSenServiceConnectionImpl::SubmitL( CSenSoapEnvelope2& aMessage, CSenSoapEnvelope2*& aResponseTo )
       
  3276     {
       
  3277     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL(CSenSoapEnvelope2)");
       
  3278 
       
  3279     MSenProperties* pProperties = aMessage.Properties();
       
  3280     if( pProperties && pProperties->IsSafeToCast( MSenProperties::ESenHttpTransportProperties ) )
       
  3281         {
       
  3282         CSenHttpTransportProperties& properties = (CSenHttpTransportProperties&)*pProperties;
       
  3283         CSenHttpTransportProperties::TSenHttpMethod httpMethod;
       
  3284         TInt getHttpMethodRetVal = properties.HttpMethodL( httpMethod );
       
  3285 
       
  3286         if ( getHttpMethodRetVal == KErrNone && 
       
  3287              httpMethod == CSenHttpTransportProperties::ESenHttpGet || 
       
  3288              httpMethod == CSenHttpTransportProperties::ESenHttpDelete )
       
  3289             {
       
  3290             // At the moment, Service Connection does not support sending 
       
  3291             // of SOAP-ENVs via HTTP headers for GET/DELETE requests:
       
  3292             return KErrNotSupported; // documented in public header(s)
       
  3293             }
       
  3294         }
       
  3295 
       
  3296     TInt retVal = CheckConnection();
       
  3297     
       
  3298     if(retVal == KErrNone)
       
  3299         {
       
  3300         CSenConnectionChunk* pOperation = CSenConnectionChunk::NewL( NextChunkName(), iIsInternalSC ); // returns NULL in hardware env (uses WSD in h/w, too), if no server chunk slot available
       
  3301         if( pOperation )
       
  3302         	{
       
  3303 	        CleanupStack::PushL( pOperation );
       
  3304 	        
       
  3305 	#ifdef _SENDEBUG
       
  3306 	        pOperation->SetLogger(&iLog);
       
  3307 #endif // _SENDEBUG
       
  3308 
       
  3309 	        retVal = pOperation->CreateChunk();
       
  3310 	        if (retVal == KErrNone)
       
  3311 	            {
       
  3312 	            pOperation->ChunkHeader().SetMessageType(aMessage.Type());
       
  3313 	            
       
  3314 	            RSenDocument document = aMessage.AsDocumentL();
       
  3315 		        document.GetDataContainerList(pOperation->BinaryDataArrayL());	//codescannerwarnings
       
  3316 		        pOperation->RemoveBinaryDataArrayIfEmpty();
       
  3317 	            
       
  3318 	            retVal = AssignMessageToChunkL(*pOperation, aMessage);	//codescannerwarnings
       
  3319 	            if (retVal == KErrNone)
       
  3320 	                {
       
  3321 	                retVal = SubmitL(*pOperation);
       
  3322 	                
       
  3323 	                if (retVal != KErrNone && retVal != KErrSenSoapFault)
       
  3324 	                    {
       
  3325 	                    aResponseTo = NULL;
       
  3326 	                    }
       
  3327 	                else
       
  3328 	                    {
       
  3329 	                    HBufC8* pResponseBuf = NULL;
       
  3330 	                    retVal = ResponseFromChunk(*pOperation, pResponseBuf);
       
  3331 	                    if( retVal == KErrNone && pResponseBuf && pResponseBuf->Length()>0)
       
  3332 	                        {
       
  3333 	                        CleanupStack::PushL(pResponseBuf);
       
  3334 	                        CSenSoapEnvelope2* pResponseSoapEnv2 = CSenSoapEnvelope2::NewL();
       
  3335 	                        CleanupStack::PushL(pResponseSoapEnv2);
       
  3336 	                        
       
  3337 	                        CSenParser* pParser = CSenParser::NewLC();
       
  3338 	                    	TRAP( retVal, pParser->ParseL(*pResponseBuf, *pResponseSoapEnv2); )
       
  3339 	                    	CleanupStack::PopAndDestroy(pParser);
       
  3340 
       
  3341 	                        if( retVal == KErrNone )
       
  3342 	                            {
       
  3343 	                            aResponseTo = pResponseSoapEnv2;
       
  3344 	                            // ownership was safely transferred to caller; remove pointer from cleanup stack:
       
  3345 	                            CleanupStack::Pop(pResponseSoapEnv2);
       
  3346 	                            }
       
  3347 	                        else
       
  3348 	                            {
       
  3349 	                            CleanupStack::PopAndDestroy(pResponseSoapEnv2);
       
  3350 	                            }
       
  3351 	                        
       
  3352 	                        CleanupStack::PopAndDestroy(pResponseBuf);
       
  3353 	                        }
       
  3354 	                    }
       
  3355 	                
       
  3356 	                }
       
  3357 	            }
       
  3358 	        CleanupStack::PopAndDestroy(pOperation);
       
  3359         	}
       
  3360 		else
       
  3361 			{
       
  3362 #ifdef _SENDEBUG
       
  3363 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL(SOAP-MSG2) - KErrServerBusy");
       
  3364 #endif // _SENDEBUG
       
  3365 			return KErrServerBusy;    	
       
  3366 			}
       
  3367         }
       
  3368 #ifdef _SENDEBUG        
       
  3369     else
       
  3370     	{
       
  3371         // error occured in CheckConnection()  	
       
  3372         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::SubmitL(SOAP-MSG2) - CheckConnection failed, error(%d)"), retVal ));
       
  3373     	}	 
       
  3374 #endif // _SENDEBUG    	
       
  3375 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::SubmitL(CSenSoapEnvelope2) Completed");
       
  3376     return retVal;
       
  3377     }
       
  3378     
       
  3379 TInt CSenServiceConnectionImpl::Identifier()
       
  3380     {
       
  3381     return iConnectionID;
       
  3382     }
       
  3383     
       
  3384 TInt CSenServiceConnectionImpl::RegisterFilesObserver()
       
  3385     {
       
  3386     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterFilesObserver");
       
  3387     TInt retVal(KErrNone);
       
  3388     if(!HasConnectionAgentCallbackInitialized())
       
  3389     	{
       
  3390 	    const TDesC& name = CSenConnAgentServer::Open();
       
  3391 	    if (name == KNullDesC)
       
  3392 	        {
       
  3393 	        return KErrGeneral;
       
  3394 	        }
       
  3395 	    retVal = iConnection.RegisterTransferObserver(&name, iFilesObserver);
       
  3396 	    iConnectionAgentCallbackInitialized = ETrue;
       
  3397     	}
       
  3398     else
       
  3399     	{
       
  3400     	retVal = iConnection.RegisterTransferObserver(&KNullDesC(), iFilesObserver);
       
  3401     	}
       
  3402     iRegisterFileObserverDone = ETrue;
       
  3403     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterFilesObserver Completed");
       
  3404     return retVal; 
       
  3405     }
       
  3406 #ifdef __ENABLE_ALR__
       
  3407 
       
  3408 TInt CSenServiceConnectionImpl::RegisterMobilityObserverL()
       
  3409     {
       
  3410     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterMobilityObserverL");
       
  3411     TInt retVal(KErrNone);
       
  3412     if(!HasConnectionAgentCallbackInitialized())
       
  3413     	{
       
  3414 	    const TDesC& name = CSenConnAgentServer::Open();
       
  3415 	    if (name == KNullDesC)
       
  3416 	        {
       
  3417 	        User::Leave(KErrGeneral);
       
  3418 	        }
       
  3419 	    iConnection.RegisterMobilityObserverL(&name, iMobiltyObserver);
       
  3420 	    iConnectionAgentCallbackInitialized = ETrue;
       
  3421     	}
       
  3422     else
       
  3423     	{
       
  3424     	iConnection.RegisterMobilityObserverL(&KNullDesC(), iMobiltyObserver);
       
  3425     	}    	
       
  3426     iRegisterMobilityObserverDone = ETrue;
       
  3427     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterMobilityObserverL Completed");
       
  3428     return retVal; 
       
  3429     }
       
  3430 
       
  3431 
       
  3432 void CSenServiceConnectionImpl::MigrateToPrefferedCarrierL(TBool &aUserChoice)
       
  3433     {
       
  3434     if (iMobiltyObserver)
       
  3435         {
       
  3436         User::LeaveIfError(iConnection.MigrateToPrefferedCarrierL(aUserChoice));    	
       
  3437         }
       
  3438 	else
       
  3439 	    {
       
  3440         User::Leave(KErrNotFound);
       
  3441 	    }	 
       
  3442     }
       
  3443 
       
  3444 void CSenServiceConnectionImpl::NewCarrierAcceptedL(TBool &aUserChoice)
       
  3445     {
       
  3446     if (iMobiltyObserver)
       
  3447         {
       
  3448         User::LeaveIfError(iConnection.NewCarrierAcceptedL(aUserChoice));    	
       
  3449         }
       
  3450 	else
       
  3451 	    {
       
  3452         User::Leave(KErrNotFound);
       
  3453 	    }	 
       
  3454     }
       
  3455 #endif
       
  3456 
       
  3457 
       
  3458 TInt CSenServiceConnectionImpl::SendProgressToHostlet(TInt aTxnId,
       
  3459         TBool aIncoming, const TDesC8& aMessage, const TDesC8& aCid,
       
  3460         TInt aProgress)
       
  3461     {
       
  3462     TBool isSoap = (aMessage != KNullDesC8);
       
  3463     TPtrC8 ptr;
       
  3464     if (isSoap)
       
  3465         {
       
  3466         ptr.Set(aMessage);
       
  3467         }
       
  3468     else
       
  3469         {
       
  3470         ptr.Set(aCid);
       
  3471         }
       
  3472     return iConnection.SendFileProgress(aTxnId, aIncoming, isSoap,ptr, aProgress);
       
  3473     }
       
  3474 
       
  3475 void CSenServiceConnectionImpl::DeliverStatus(TInt aStatus)
       
  3476     {
       
  3477     TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("Invoking SetStatus(%d) callback."), aStatus ));
       
  3478     TLSLOG_FORMAT(( iTlsLogStatusChannel, KSenServiceConnectionStatusLogLevel, _L8("CSenServiceConnectionImpl::DeliverStatus [legacy status update] - Invoking SetStatus(%d)"), aStatus ));
       
  3479     
       
  3480     TInt leaveCode(KErrNone);
       
  3481 
       
  3482     if( ipHostletConsumer )
       
  3483         {
       
  3484         ipHostletConsumer->SetConnectionId( iConnectionID );
       
  3485         }
       
  3486     
       
  3487     TRAP( leaveCode, iObserver->SetStatus(aStatus); )
       
  3488     if( leaveCode )
       
  3489         {
       
  3490         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("Fatal(!) -- CSenServiceConnectionImpl::DeliverStatus(): MSenServiceConsumer::SetStatus - leaves with %d"), leaveCode));
       
  3491         TLSLOG_FORMAT(( iTlsLogStatusChannel, KSenServiceConnectionStatusLogLevel, _L("Fatal(!) -- CSenServiceConnectionImpl::DeliverStatus(): MSenServiceConsumer::SetStatus - leaves with %d"), leaveCode));
       
  3492         leaveCode = KErrNone;
       
  3493         }
       
  3494     }
       
  3495     
       
  3496     
       
  3497  TInt CSenServiceConnectionImpl::IdentityProviderL( CSenIdentityProvider*& apIdentityProvider )
       
  3498     {
       
  3499     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::IdentityProviderL");
       
  3500     
       
  3501     delete apIdentityProvider;
       
  3502     apIdentityProvider = NULL;
       
  3503 
       
  3504     TInt retVal = CheckConnection();
       
  3505     if(retVal == KErrNone)
       
  3506         {
       
  3507         TInt retVal(KErrNone);
       
  3508         
       
  3509         CSenChunk* pSenChunk = CSenChunk::NewLC(NextChunkName());
       
  3510         pSenChunk->SetLogger(Log());
       
  3511         retVal = pSenChunk->CreateChunk();
       
  3512         
       
  3513         if (retVal == KErrNone)
       
  3514             {
       
  3515             retVal = iConnection.IdentityProviderL(*pSenChunk);
       
  3516             if(retVal == KErrNone)
       
  3517                 {
       
  3518                 TPtrC8 identityProvider;
       
  3519                 retVal = pSenChunk->DescFromChunk(identityProvider);
       
  3520                 if(retVal == KErrNone)
       
  3521                     {
       
  3522                     apIdentityProvider = CSenIdentityProvider::NewLC(KNullDesC8);
       
  3523                     CSenXmlReader* pXmlReader = CSenXmlReader::NewLC(KXmlParserMimeType); // use libxml2 sax parser
       
  3524                     pXmlReader->SetContentHandler( *apIdentityProvider );
       
  3525                     apIdentityProvider->SetReader(*pXmlReader);
       
  3526     
       
  3527                     TInt leaveCode(KErrNone);
       
  3528                     TRAP( leaveCode, apIdentityProvider->ParseL( identityProvider ); )
       
  3529                     
       
  3530                     CleanupStack::PopAndDestroy(pXmlReader);
       
  3531                     
       
  3532                     if ( leaveCode != KErrNone )
       
  3533                         {
       
  3534                         CleanupStack::PopAndDestroy( apIdentityProvider );
       
  3535                         apIdentityProvider = NULL;
       
  3536                         }
       
  3537                     else
       
  3538                         {
       
  3539                         CleanupStack::Pop( apIdentityProvider );
       
  3540                         }
       
  3541                     }
       
  3542                 }
       
  3543             }
       
  3544         CleanupStack::PopAndDestroy(pSenChunk);
       
  3545         }    
       
  3546 #ifdef _SENDEBUG        
       
  3547     else
       
  3548     	{
       
  3549         // error occured in CheckConnection()  	
       
  3550         TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::IdentityProviderL - CheckConnection failed, error(%d)"), retVal ));
       
  3551     	}	 
       
  3552 #endif // _SENDEBUG 
       
  3553 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::IdentityProviderL Completed");   	
       
  3554     return retVal;    
       
  3555     }
       
  3556 
       
  3557 TInt CSenServiceConnectionImpl::SearchIdentityProviderL( CSenIdentityProvider*& apIdentityProvider, const TDesC8& aProviderId )
       
  3558 		{
       
  3559 	    TInt retVal(KErrNone);
       
  3560 	    
       
  3561 	    CSenChunk* pSenChunk = CSenChunk::NewLC(NextChunkName());
       
  3562 	    pSenChunk->SetLogger(Log());
       
  3563 	    retVal = pSenChunk->CreateChunk();
       
  3564 	    
       
  3565 	    if (retVal == KErrNone)
       
  3566 	        {
       
  3567 	        retVal = iConnection.SearchIdentityProviderL(*pSenChunk, aProviderId);
       
  3568 	        if(retVal == KErrNone)
       
  3569 	            {
       
  3570 	            TPtrC8 identityProvider;
       
  3571 	            retVal = pSenChunk->DescFromChunk(identityProvider);
       
  3572 	            if(retVal == KErrNone)
       
  3573 	                {
       
  3574 	                apIdentityProvider = CSenIdentityProvider::NewLC(KNullDesC8);
       
  3575 	                CSenXmlReader* pXmlReader = CSenXmlReader::NewLC(KXmlParserMimeType); // use libxml2 sax parser
       
  3576 	                pXmlReader->SetContentHandler( *apIdentityProvider );
       
  3577 	                apIdentityProvider->SetReader(*pXmlReader);
       
  3578 
       
  3579 	                TInt leaveCode(KErrNone);
       
  3580 	                TRAP( leaveCode, apIdentityProvider->ParseL( identityProvider ); )
       
  3581 	                
       
  3582 	                CleanupStack::PopAndDestroy(pXmlReader);
       
  3583 	                
       
  3584 	                if ( leaveCode != KErrNone )
       
  3585 	                    {
       
  3586 	                    CleanupStack::PopAndDestroy( apIdentityProvider );
       
  3587 	                    apIdentityProvider = NULL;
       
  3588 	                    }
       
  3589 	                else
       
  3590 	                    {
       
  3591 	                    CleanupStack::Pop( apIdentityProvider );
       
  3592 	                    }
       
  3593 	                }
       
  3594 	            }
       
  3595 	        }
       
  3596 	    CleanupStack::PopAndDestroy(pSenChunk);
       
  3597 
       
  3598 	    return retVal; 
       
  3599 		}
       
  3600  
       
  3601 TInt CSenServiceConnectionImpl::RegisterAuthenticationObserver()
       
  3602 	{
       
  3603 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterAuthenticationObserver");
       
  3604 	TInt retVal(KErrNone);
       
  3605     if(!HasConnectionAgentCallbackInitialized())
       
  3606       	{
       
  3607 	    const TDesC& name = CSenConnAgentServer::Open();
       
  3608 	    if (name == KNullDesC)
       
  3609 	        {
       
  3610 	        return KErrGeneral;
       
  3611 	        }
       
  3612 	    retVal = iConnection.RegisterAuthenticationObserver(&name, ipAuthProvider);
       
  3613 	    iConnectionAgentCallbackInitialized = ETrue;
       
  3614        	}
       
  3615     else
       
  3616        	{
       
  3617        	retVal = iConnection.RegisterAuthenticationObserver(&KNullDesC(), ipAuthProvider);
       
  3618        	}
       
  3619        iRegisterAuthObserverDone = ETrue;
       
  3620     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterAuthenticationObserver Completed");
       
  3621     return retVal;
       
  3622 	}
       
  3623 TInt CSenServiceConnectionImpl::RegisterCoBrandingObserver()
       
  3624 {
       
  3625 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterCoBrandingObserver");
       
  3626 	TInt retVal(KErrNone);
       
  3627     if(!HasConnectionAgentCallbackInitialized())
       
  3628     	{
       
  3629 	    const TDesC& name = CSenConnAgentServer::Open();
       
  3630 	    if (name == KNullDesC)
       
  3631 	        {
       
  3632 	        return KErrGeneral;
       
  3633 	        }
       
  3634 	    retVal = iConnection.RegisterCoBrandingObserver(&name, ipCoBrandingObserver);
       
  3635 	    iConnectionAgentCallbackInitialized = ETrue;
       
  3636     	}
       
  3637     else
       
  3638     	{
       
  3639     	retVal = iConnection.RegisterCoBrandingObserver(&KNullDesC(), ipCoBrandingObserver);
       
  3640     	}
       
  3641     iRegisterCoBrandingObserverDone = ETrue;
       
  3642     TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::RegisterCoBrandingObserver Completed");
       
  3643     return retVal;    
       
  3644 }
       
  3645 
       
  3646 TBool CSenServiceConnectionImpl::HasConnectionAgentCallbackInitialized()
       
  3647 	{
       
  3648 #ifdef __ENABLE_ALR__
       
  3649 	if((ipAuthProvider || iFilesObserver || iMobiltyObserver || ipCoBrandingObserver) && iConnectionAgentCallbackInitialized)
       
  3650 #else
       
  3651 	if((ipAuthProvider || iFilesObserver || ipCoBrandingObserver) && iConnectionAgentCallbackInitialized)
       
  3652 #endif //__ENABLE_ALR__
       
  3653 		{
       
  3654 		return ETrue;
       
  3655 		}
       
  3656 	return EFalse;
       
  3657 	}
       
  3658 
       
  3659 TInt CSenServiceConnectionImpl::ReauthNeededL(const TDesC8& aProviderId)
       
  3660 	{
       
  3661 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::ReauthNeededL");
       
  3662 	TInt retVal(KErrNotFound);
       
  3663 	if(ipAuthProvider)
       
  3664 		{
       
  3665 		TBool identityProviderCreated = EFalse;
       
  3666 		// Get identity from authentication callback
       
  3667 	    CSenIdentityProvider* pIdP =
       
  3668 	            (CSenIdentityProvider*)ipAuthProvider->IdentityProviderL();
       
  3669 	    
       
  3670 	    if ( !pIdP )
       
  3671 	        {
       
  3672 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - IdentityProviderL() from authentication provider returned NULL.");
       
  3673 	        const TPtrC8 userName = ipAuthProvider->UsernameL();
       
  3674 	        const TPtrC8 password = ipAuthProvider->PasswordL();
       
  3675 	        if ( userName != KNullDesC8 &&
       
  3676 	             password != KNullDesC8 )
       
  3677 	        	{
       
  3678 		        if ( &aProviderId != NULL && aProviderId.Length() > 0 )
       
  3679 		        	{
       
  3680 		        	TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::Reauthentication - trying to search identity provider with the given id: %S"), &aProviderId ));
       
  3681 		            retVal = SearchIdentityProviderL(pIdP, aProviderId);
       
  3682 		            if(retVal == KErrNone && pIdP)
       
  3683 		               	{
       
  3684 		               	CleanupStack::PushL(pIdP);
       
  3685 		               	identityProviderCreated = ETrue;
       
  3686 		               	pIdP->SetUserInfoL( userName ,
       
  3687 		               						userName ,
       
  3688 		               						password );
       
  3689 		                }
       
  3690 		        	}
       
  3691 		        else
       
  3692 		        	{
       
  3693 					TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - provider id not found, trying to retrieve connection identity provider.");
       
  3694 		        	// Try to retrieve IdentityProvider
       
  3695 		        	IdentityProviderL(pIdP);
       
  3696 		        	if(pIdP)
       
  3697 		        		{
       
  3698 		        		CleanupStack::PushL(pIdP);
       
  3699 		        		identityProviderCreated = ETrue;
       
  3700 		        		}
       
  3701 		        	else
       
  3702 		        		{
       
  3703 						TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - identity provider not found, creating one with default parameters.");
       
  3704 		        		// Create IdentityProvider with default parameters
       
  3705 		        		pIdP = CSenIdentityProvider::NewLC(KIdentityProviderName);
       
  3706 		        		identityProviderCreated = ETrue;
       
  3707 		        		}
       
  3708 		        	
       
  3709 			        if(pIdP)
       
  3710 			        	{
       
  3711 			        	pIdP->SetUserInfoL( userName ,
       
  3712 	   										userName ,
       
  3713 	   										password );
       
  3714 		        		}
       
  3715 		        	}
       
  3716 	            } // if(userName != KNull...)
       
  3717 	        else
       
  3718 	        	{
       
  3719 				TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - UserNameL() and/or PasswordL() from authentiction provider returned NULL.");
       
  3720 	        	retVal = KErrGeneral;
       
  3721 	        	}
       
  3722 	        } // if(!pIdP)
       
  3723 	    
       
  3724 	    if ( pIdP )
       
  3725 	        {
       
  3726 			TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::Reauthentication - CSenServiceConnectionImpl::Reauthentication - identity provider ready to register.");
       
  3727 	        HBufC8* pIdPAsXml = pIdP->AsXmlL();
       
  3728 	        CleanupStack::PushL(pIdPAsXml);
       
  3729 	
       
  3730 	        // Update IdentityProvider into DB
       
  3731 	        TPtr8 ptr = pIdPAsXml->Des();
       
  3732 	        retVal = iConnection.RegisterIdentityProvider(ptr);
       
  3733 	        
       
  3734 	        CleanupStack::PopAndDestroy(pIdPAsXml);
       
  3735 	        if ( identityProviderCreated )
       
  3736 	            {
       
  3737 	            CleanupStack::PopAndDestroy(pIdP);
       
  3738 	            }
       
  3739 	        }
       
  3740 		}
       
  3741 	TLSLOG_L(KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel ,"CSenServiceConnectionImpl::ReauthNeededL Completed");
       
  3742 	return retVal;
       
  3743 	}
       
  3744 	
       
  3745 void CSenServiceConnectionImpl::DataTrafficDetails(TSenDataTrafficDetails& aDetails,
       
  3746 												   TSenDataTrafficOperations& aOperations) 
       
  3747 	{
       
  3748 	iConnection.DataTrafficDetails(aDetails, aOperations);
       
  3749 	}	
       
  3750 	
       
  3751 
       
  3752 TAny* CSenServiceConnectionImpl::InterfaceByUid( TUid aUID )
       
  3753     {
       
  3754     if ( aUID == KSenInterfaceUidInternalServiceConnection )
       
  3755 			{
       
  3756 			TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::InterfaceByUid(%d) == KSenInterfaceUidInternalServiceConnection" ), aUID.iUid ));
       
  3757 			// Must be cast to M-class  (as the same C-class implements multiple M-classes):
       
  3758 			MSenInternalServiceConnection* connection = (MSenInternalServiceConnection*) this;
       
  3759 			return connection; 
       
  3760 			}
       
  3761 	#ifdef __ENABLE_ALR__			
       
  3762     else if ( aUID == KSenInterfaceUidAlrServiceConnection )
       
  3763     	{
       
  3764 			TLSLOG_FORMAT((KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("CSenServiceConnectionImpl::InterfaceByUid(%d) == KSenInterfaceUidInternalServiceConnection" ), aUID.iUid ));
       
  3765 			MSenAlrServiceConnection* connection = NULL;
       
  3766 			// Must be cast to M-class  (as the same C-class implements multiple M-classes):
       
  3767 			connection = (MSenAlrServiceConnection*) this; // (mobility observer) is only available since S60 3.2 
       
  3768 			return connection; 
       
  3769     	}
       
  3770 	#endif // __ENABLE_ALR__		
       
  3771     return NULL;
       
  3772     }
       
  3773 
       
  3774 TInt CSenServiceConnectionImpl::PendingTrasanctionsCount()
       
  3775 	{
       
  3776 	return iAsyncOpsArray->Count();
       
  3777 	}										
       
  3778 
       
  3779 CSenAsyncOperation* CSenAsyncOperation::NewL(CSenServiceConnectionImpl* aActive)
       
  3780     {
       
  3781     CSenAsyncOperation* pNew = NewLC(aActive);
       
  3782     CleanupStack::Pop();
       
  3783     return(pNew);
       
  3784     }
       
  3785 
       
  3786 CSenAsyncOperation* CSenAsyncOperation::NewLC(CSenServiceConnectionImpl* aActive)
       
  3787     {
       
  3788     CSenAsyncOperation* pNew = new (ELeave) CSenAsyncOperation(aActive);
       
  3789     CleanupStack::PushL(pNew);
       
  3790     pNew->ConstructL();
       
  3791     return pNew;
       
  3792     }
       
  3793     
       
  3794 CSenAsyncOperation::CSenAsyncOperation(CSenServiceConnectionImpl* aActive)
       
  3795 :   CActive(EPriorityNormal),
       
  3796     iActive(aActive),
       
  3797     iErrorNumber(0),
       
  3798     iErrorNumberBuffer(NULL, 0),
       
  3799     iTxnId(0),
       
  3800     iTxnIdBuffer(NULL, 0),
       
  3801     iReauthTxnId(0)
       
  3802     {
       
  3803     CActiveScheduler::Add(this);
       
  3804     }
       
  3805 
       
  3806 void CSenAsyncOperation::ConstructL()
       
  3807     {
       
  3808     iErrorNumberBuffer.Set(reinterpret_cast<TUint8*>(&iErrorNumber),
       
  3809                            sizeof(TInt),
       
  3810                            sizeof(TInt));
       
  3811                            
       
  3812     iTxnIdBuffer.Set(reinterpret_cast<TUint8*>(&iTxnId),
       
  3813                      sizeof(TInt),
       
  3814                      sizeof(TInt));
       
  3815                      
       
  3816     SetActive();
       
  3817 	iStatus = KRequestPending;
       
  3818 #ifdef EKA2
       
  3819     iActive->AsyncOpsArrayL().AppendL(this);	//codescannerwarnings
       
  3820 #else
       
  3821     User::LeaveIfError(iActive->AsyncOpsArrayL().Append(this));	//codescannerwarnings
       
  3822 #endif
       
  3823     }
       
  3824     
       
  3825 CSenAsyncOperation::~CSenAsyncOperation()
       
  3826     {
       
  3827     if ( IsActive() )
       
  3828         {
       
  3829         Cancel(); // calls CSenAsyncOperation::DoCancel()
       
  3830         }
       
  3831     }
       
  3832 
       
  3833 void CSenAsyncOperation::RunL()
       
  3834     {
       
  3835     if ( iActive )
       
  3836         {
       
  3837         iActive->iErrorNumber = iErrorNumber;
       
  3838         if( iReauthTxnId != 0 && iTxnId == 0 )
       
  3839         	{
       
  3840         	iActive->iTxnId = iReauthTxnId;
       
  3841         	iActive->iReauthenticationNeeded = ETrue;
       
  3842         	}
       
  3843         else
       
  3844         	{
       
  3845         	iActive->iTxnId = iTxnId;
       
  3846         	}  
       
  3847         iActive->HandleMessageFromChildAOL(iStatus.Int());
       
  3848             
       
  3849         TInt idx = iActive->AsyncOpsArrayL().Find(this);	//codescannerwarnings
       
  3850         if (idx >= 0)
       
  3851             {
       
  3852             iActive->AsyncOpsArrayL().Remove(idx);	//codescannerwarnings
       
  3853             }
       
  3854         }
       
  3855     
       
  3856     delete this;
       
  3857     }
       
  3858         
       
  3859 void CSenAsyncOperation::DoCancel()
       
  3860     {
       
  3861     }
       
  3862 
       
  3863 
       
  3864 CSenConnectionStatusObserver* CSenConnectionStatusObserver::NewL(MSenServiceConsumer& aObserver,
       
  3865                                                                  TInt aConnectionID)
       
  3866     {
       
  3867     CSenConnectionStatusObserver* pNew = NewLC(aObserver, aConnectionID);
       
  3868     CleanupStack::Pop();
       
  3869     return(pNew);
       
  3870     }
       
  3871 
       
  3872 CSenConnectionStatusObserver* CSenConnectionStatusObserver::NewLC(MSenServiceConsumer& aObserver,
       
  3873                                                                   TInt aConnectionID)
       
  3874     {
       
  3875     CSenConnectionStatusObserver* pNew = new (ELeave) CSenConnectionStatusObserver(aObserver,
       
  3876                                                                                    aConnectionID);
       
  3877     CleanupStack::PushL(pNew);
       
  3878     pNew->ConstructL();
       
  3879     return pNew;
       
  3880     }
       
  3881     
       
  3882 CSenConnectionStatusObserver::CSenConnectionStatusObserver(MSenServiceConsumer& aObserver,
       
  3883                                                            TInt aConnectionID)
       
  3884 :   CActive(EPriorityMore),
       
  3885     iObserver(&aObserver),
       
  3886     iConnectionID(aConnectionID)
       
  3887     {}
       
  3888 
       
  3889 void CSenConnectionStatusObserver::ConstructL()
       
  3890     {
       
  3891     RThread thread;
       
  3892     TSecureId secureID = thread.SecureId();
       
  3893     
       
  3894 
       
  3895     _LIT_SECURITY_POLICY_PASS(KReadPropPassAll);
       
  3896     _LIT_SECURITY_POLICY_S0(KWritePropSenCoreSidOnlyPolicy, KServerUid3.iUid);
       
  3897     
       
  3898     // Default category value is the secure id of the loading process 
       
  3899     // Define the property
       
  3900     TInt err = RProperty::Define( // Secureid of the process will be used
       
  3901                                   iConnectionID,
       
  3902                                   RProperty::EInt,
       
  3903                                   KReadPropPassAll,
       
  3904 //                                  KReadPropThisSidOnlyPolicy,
       
  3905                                   KWritePropSenCoreSidOnlyPolicy);
       
  3906 
       
  3907 	// Use secure id of the loading process instead of server process (ws client process secure id)
       
  3908 	User::LeaveIfError(iConnectionStatusProperty.Attach(secureID, iConnectionID)); // secureid of the process will be category
       
  3909     CActiveScheduler::Add(this);
       
  3910     // Initial subscription
       
  3911     iConnectionStatusProperty.Subscribe(iStatus);
       
  3912     SetActive();
       
  3913 	iStatus = KRequestPending;
       
  3914     }
       
  3915 
       
  3916 CSenConnectionStatusObserver::~CSenConnectionStatusObserver()
       
  3917     {
       
  3918     Cancel();
       
  3919     iConnectionStatusProperty.Close();
       
  3920     // Use secure id of the loading process instead of server process (ws client process secure id) 
       
  3921     RThread thread;
       
  3922     TSecureId secureID = thread.SecureId();    
       
  3923     TInt err = RProperty::Delete( secureID, iConnectionID );
       
  3924     }
       
  3925 
       
  3926 void CSenConnectionStatusObserver::DoCancel()
       
  3927     {
       
  3928     iConnectionStatusProperty.Cancel();
       
  3929     }
       
  3930 
       
  3931 void CSenConnectionStatusObserver::RunL()
       
  3932     {
       
  3933         
       
  3934     TLSLOG_L( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, "CSenConnectionStatusObserver::RunL" );
       
  3935     iConnectionStatusProperty.Subscribe(iStatus);
       
  3936     SetActive();
       
  3937 	iStatus = KRequestPending;
       
  3938    
       
  3939     TInt propertyValue(KErrNotFound);
       
  3940     TInt getPropertyCode = iConnectionStatusProperty.Get(propertyValue);
       
  3941     if ( getPropertyCode == KErrNone)
       
  3942         {
       
  3943 #if !defined ( RD_SEN_DISABLE_TRANSPORT_STATUS_CODE_CALLBACK )
       
  3944         TLSLOG_FORMAT(( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, _L8("CSenConnectionStatusObserver::RunL [new value published] - Calling SetStatus(%d)"), propertyValue ));
       
  3945         iObserver->SetStatus( propertyValue ); // Note: client drop 2007-01-12 cannot handle foreign status codes 
       
  3946 #endif        
       
  3947         }
       
  3948 #ifdef _SENDEBUG
       
  3949     else
       
  3950         {
       
  3951         TLSLOG_FORMAT(( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, _L8("- MAJOR: iConnectionStatusProperty.Get(propertyValue) failed: %d"), getPropertyCode ));
       
  3952         }
       
  3953 #endif // _SENDEBUG        
       
  3954     }
       
  3955    
       
  3956 // ------------------------------------------------------------------------------------------------------------
       
  3957 
       
  3958 CSenFileProgressObserver* CSenFileProgressObserver::NewL( MSenFilesObserver& aObserver,
       
  3959                                                           TInt aConnectionID, 
       
  3960                                                           TBool aIsDispatcherEnabled,
       
  3961                                                           CSenServiceDispatcher* apSenServiceDispatcher, 
       
  3962                                                           RChunkMap& aChunkMap )
       
  3963     {
       
  3964     CSenFileProgressObserver* pNew = NewLC( aObserver, aConnectionID, aIsDispatcherEnabled, apSenServiceDispatcher,aChunkMap );
       
  3965     CleanupStack::Pop();
       
  3966     return(pNew);
       
  3967     }
       
  3968 
       
  3969 CSenFileProgressObserver* CSenFileProgressObserver::NewLC( MSenFilesObserver& aObserver,
       
  3970                                                            TInt aConnectionID,
       
  3971                                                            TBool aIsDispatcherEnabled,
       
  3972                                                            CSenServiceDispatcher* apSenServiceDispatcher, 
       
  3973                                                            RChunkMap& aChunkMap )
       
  3974     {
       
  3975     CSenFileProgressObserver* pNew = new (ELeave) CSenFileProgressObserver( aObserver, aConnectionID, aIsDispatcherEnabled, apSenServiceDispatcher, aChunkMap );
       
  3976     CleanupStack::PushL(pNew);
       
  3977     pNew->ConstructL();
       
  3978     return pNew;
       
  3979     }
       
  3980     
       
  3981     
       
  3982 
       
  3983 CSenFileProgressObserver::CSenFileProgressObserver( MSenFilesObserver& aObserver,
       
  3984                                                     TInt aConnectionID,
       
  3985                                                     TBool aIsDispatcherEnabled,
       
  3986                                                     CSenServiceDispatcher* apSenServiceDispatcher, 
       
  3987                                                     RChunkMap& aChunkMap )
       
  3988 //:    CActive(EPriorityNormal),
       
  3989 :   CActive(EPriorityMore),
       
  3990     iFileProgressObserver(&aObserver),
       
  3991     iConnectionID(aConnectionID),
       
  3992     iIsDispatcherEnabled(aIsDispatcherEnabled),
       
  3993     ipSenServiceDispatcher(apSenServiceDispatcher),
       
  3994     iChunkMap(aChunkMap)
       
  3995     {}
       
  3996 
       
  3997 void CSenFileProgressObserver::ConstructL()
       
  3998     {
       
  3999     _LIT_SECURITY_POLICY_PASS(KReadPropPassAll);
       
  4000     _LIT_SECURITY_POLICY_S0(KWritePropSenCoreSidOnlyPolicy, KServerUid3.iUid);
       
  4001     
       
  4002     // Define the property
       
  4003     TInt err = RProperty::Define( KSenInterfaceUidFilesObserver,
       
  4004                                   iConnectionID,
       
  4005                                   RProperty::ELargeByteArray, 
       
  4006                                   KReadPropPassAll,
       
  4007                                   KWritePropSenCoreSidOnlyPolicy,
       
  4008                                   512 );
       
  4009 	// Use KSenInterfaceUidFilesObserver extended consumer interface UID
       
  4010 	User::LeaveIfError(iFileProgressProperty.Attach(KSenInterfaceUidFilesObserver,  iConnectionID)); // KSenInterfaceUidFilesObserver UID will be category
       
  4011     CActiveScheduler::Add(this);
       
  4012     // Initial subscription
       
  4013     iFileProgressProperty.Subscribe(iStatus);
       
  4014     SetActive();
       
  4015     iStatus = KRequestPending;
       
  4016     }
       
  4017 
       
  4018 CSenFileProgressObserver::~CSenFileProgressObserver()
       
  4019     {
       
  4020     Cancel();
       
  4021     iFileProgressProperty.Close();
       
  4022     
       
  4023     TInt err = RProperty::Delete( KSenInterfaceUidFilesObserver, iConnectionID );
       
  4024     
       
  4025     }
       
  4026 
       
  4027 void CSenFileProgressObserver::DoCancel()
       
  4028     {
       
  4029     iFileProgressProperty.Cancel();
       
  4030     }
       
  4031 
       
  4032 void CSenFileProgressObserver::RunL()
       
  4033     {
       
  4034     // Resubscribe before processing new value to prevent missing updates(!):
       
  4035 	iFileProgressProperty.Subscribe(iStatus);
       
  4036     SetActive();
       
  4037     iStatus = KRequestPending;
       
  4038 
       
  4039     TLSLOG_L( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, "CSenFileProgressObserver::RunL" );
       
  4040        
       
  4041     TPckgBuf<TFileOutgoingTransferProgressBase> progress;
       
  4042     TInt getPropertyCode = iFileProgressProperty.Get( progress );
       
  4043     if ( getPropertyCode == KErrNone )
       
  4044         {
       
  4045         TLSLOG_L(KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, "CSenFileProgressObserver::RunL [new value published] - Calling TransferProgress");
       
  4046         TFileOutgoingTransferProgressBase data = progress();
       
  4047 
       
  4048         TInt index(KErrNotFound);
       
  4049         if ( iIsDispatcherEnabled ) // DISPATCHER IS ENABLED
       
  4050             {
       
  4051             TLSLOG_L(KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, "CSenFileProgressObserver::RunL : SC's message dispatcher is +enabled+.");
       
  4052             TInt keyAt = ipSenServiceDispatcher->GetVirtualTransactionID( &data.iTxnId );
       
  4053             if( keyAt != KErrNotFound )
       
  4054                 {
       
  4055                 TInt index = iChunkMap.Find( keyAt );
       
  4056                 }
       
  4057             }
       
  4058         else // DISPATCHER IS DISABLED
       
  4059             {
       
  4060             TLSLOG_L(KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, "CSenFileProgressObserver::RunL : SC's message dispatcher is -disabled-.");
       
  4061             index = iChunkMap.Find( data.iTxnId );
       
  4062             }
       
  4063 
       
  4064         // Check from the chunk (allocated by the service connection implemenation in first place),
       
  4065         // WHETHER THIS TRANSACTION HAS ALREADY BEEN COMPLETED(!). There is no need to report on
       
  4066         // "file progress" if the the transaction is already completed / over.
       
  4067         if ( index != KErrNotFound )
       
  4068             {
       
  4069             CSenConnectionChunk* pOperation = (CSenConnectionChunk*)iChunkMap.ValueAt(index);
       
  4070             TLSLOG_FORMAT(( KSenServiceConnectionLogChannelBase+iConnectionID, KMinLogLevel , _L8("- RChunk's handle: %d"), pOperation->Chunk().Handle() ));
       
  4071 
       
  4072             if( !data.iIsIncoming && pOperation->ChunkHeader().MessageDirection() != MSenMessage::EOutbound )
       
  4073                 {
       
  4074                 TLSLOG_FORMAT(( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, _L8("CSenFileProgressObserver::RunL : the transaction (txnID: %d) is already completed, no need to signalize 'progress'"), data.iTxnId ));
       
  4075                 return; 
       
  4076                 }
       
  4077             }
       
  4078             
       
  4079         //TBuf8<128> cid;
       
  4080         HBufC8* pCid = HBufC8::NewLC( KMaxCidLength );
       
  4081         TPtr8 cid = pCid->Des();
       
  4082         //cid.Format( KSenNumericCidFmt, data.iCid );
       
  4083         cid.Num( data.iCid );
       
  4084         if( data.iCid2 != KErrNotFound )
       
  4085             {
       
  4086             cid.AppendNum( data.iCid2 );
       
  4087             }
       
  4088         if( data.iHasCidPostfix )
       
  4089             {
       
  4090             cid.Append( KSenCidPostfix );
       
  4091             }
       
  4092         TLSLOG_FORMAT(( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, _L8("CSenFileProgressObserver::RunL: txn '%d', progress '%d', isIncoming '%d', cid '%S',  '"), data.iTxnId, data.iProgress, data.iIsIncoming, &cid ));
       
  4093         TRAP_IGNORE( iFileProgressObserver->TransferProgress( data.iTxnId, data.iIsIncoming, KNullDesC8, cid, data.iProgress );	)
       
  4094         CleanupStack::PopAndDestroy( pCid );
       
  4095         }
       
  4096 #ifdef _SENDEBUG
       
  4097     else
       
  4098         {
       
  4099         TLSLOG_FORMAT(( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, _L8("- MAJOR: iFileProgressProperty.Get(propertyValue) failed: %d"), getPropertyCode ));
       
  4100         }
       
  4101 #endif // _SENDEBUG 
       
  4102     }
       
  4103     
       
  4104 TInt CSenFileProgressObserver::RunError(TInt aError)
       
  4105 	{
       
  4106 	TLSLOG_FORMAT(( KSenServiceConnectionStatusLogChannelBase+iConnectionID, KSenServiceConnectionStatusLogLevel, _L8("CSenFileProgressObserver::RunError:[%d]"), aError ));
       
  4107 	// return aError;
       
  4108 	return KErrNone; // ignore the error, this is conscious decision.
       
  4109 	}
       
  4110 
       
  4111 
       
  4112 // ------------------------------------------------------------------------------------------------------------
       
  4113 
       
  4114 CSenConnectionChunk* CSenConnectionChunk::NewL(const TDesC& aChunkName, TBool aInternal )
       
  4115     {
       
  4116     CSenConnectionChunk* pChunk = CSenConnectionChunk::NewLC(aChunkName, aInternal);
       
  4117     CleanupStack::Pop();
       
  4118     return pChunk;
       
  4119     }
       
  4120 
       
  4121 CSenConnectionChunk* CSenConnectionChunk::NewLC(const TDesC& aChunkName, TBool aInternal)
       
  4122     {
       
  4123     CSenConnectionChunk* pChunk = new (ELeave) CSenConnectionChunk();
       
  4124 
       
  4125     
       
  4126     if ( pChunk->ServOpenChunkCount() >= (aInternal?(KMaxServMessageSlots+2):KMaxServMessageSlots ) )
       
  4127         {
       
  4128         delete pChunk;
       
  4129         pChunk = NULL;
       
  4130         }
       
  4131     CleanupStack::PushL(pChunk); // push even NULL, since client expects an item in cleanupstack
       
  4132     if ( pChunk )
       
  4133         {
       
  4134         pChunk->ConstructL( aChunkName );
       
  4135         }
       
  4136     return pChunk;
       
  4137     }
       
  4138 
       
  4139 void CSenConnectionChunk::ConstructL(const TDesC& aChunkName)
       
  4140     {
       
  4141     if (aChunkName.Length() > 0)
       
  4142         {
       
  4143         ipChunkName = aChunkName.AllocL();
       
  4144         }
       
  4145     else
       
  4146         {
       
  4147         ipChunkName = NULL;
       
  4148         }
       
  4149     iServOpenChunkCount++;
       
  4150     }
       
  4151     
       
  4152 CSenConnectionChunk::CSenConnectionChunk()
       
  4153 :   ipDataContainerArray(NULL), 
       
  4154     iMap( EFalse, ETrue )
       
  4155     {
       
  4156     }
       
  4157     
       
  4158 CSenConnectionChunk::~CSenConnectionChunk()
       
  4159     {
       
  4160     if ( ipDataContainerArray )
       
  4161         {
       
  4162         ipDataContainerArray->Close();
       
  4163         delete ipDataContainerArray;
       
  4164         }
       
  4165     iMap.Reset(); // will de-allocate the CSenBinaryContainers, if any
       
  4166 
       
  4167     iServOpenChunkCount--;
       
  4168     }
       
  4169 
       
  4170 RArray<TXmlEngDataContainer>& CSenConnectionChunk::BinaryDataArrayL()	//codescannerwarnings
       
  4171     {
       
  4172     if ( !ipDataContainerArray )
       
  4173         {
       
  4174         ipDataContainerArray = new (ELeave) RArray<TXmlEngDataContainer>;
       
  4175         }
       
  4176         
       
  4177     return *ipDataContainerArray;
       
  4178     }
       
  4179 
       
  4180 TBool CSenConnectionChunk::HasBinaryDataArray()
       
  4181     {
       
  4182     if ( ipDataContainerArray )
       
  4183         {
       
  4184         return ETrue;
       
  4185         }
       
  4186     else
       
  4187         {
       
  4188         return EFalse;
       
  4189         }
       
  4190     }
       
  4191 
       
  4192 TBool CSenConnectionChunk::HasSharedFileHandle()
       
  4193 {
       
  4194 return iHasSharedFileHandle ;
       
  4195 	
       
  4196 
       
  4197 }
       
  4198 
       
  4199 void CSenConnectionChunk::HasSharedFileHandle(TBool aHasSharedFileHandle)
       
  4200 {
       
  4201 	iHasSharedFileHandle = aHasSharedFileHandle;
       
  4202 }
       
  4203 
       
  4204 void CSenConnectionChunk::RemoveBinaryDataArrayIfEmpty()
       
  4205     {
       
  4206     if ( ipDataContainerArray )
       
  4207         {
       
  4208         if ( ipDataContainerArray->Count() == 0 )
       
  4209             {
       
  4210             ipDataContainerArray->Close();
       
  4211             delete ipDataContainerArray;
       
  4212             ipDataContainerArray = NULL;
       
  4213             }
       
  4214         }
       
  4215     }
       
  4216 TInt CSenConnectionChunk::ServOpenChunkCount()
       
  4217     {
       
  4218     TInt retCode( iServOpenChunkCount );
       
  4219 #if defined( RD_SEN_ENABLE_USE_OF_WSD_IN_SC_FOR_HW_TARGET )
       
  4220     retCode = iServOpenChunkCount;
       
  4221 #endif // WINS || RD_SEN_ENABLE_USE_OF_WSD_IN_SC_FOR_HW_TARGET
       
  4222     return retCode;
       
  4223     }
       
  4224     
       
  4225 TInt CSenConnectionChunk::AddFileToContainerMap( const TDesC8& aCid, RFile aFile )
       
  4226     {
       
  4227     TInt retVal(0);
       
  4228     TInt error ( KErrSenInternal );
       
  4229     
       
  4230     // First, check for duplicates
       
  4231     TInt index = iMap.Find( aCid );
       
  4232     if ( index != KErrNotFound )
       
  4233         {
       
  4234         return KErrAlreadyExists;
       
  4235         }
       
  4236 
       
  4237     // Otherwise, it is "safe" to add a binary container under this CID
       
  4238     TRAP( retVal, 
       
  4239     		CSenBinaryContainer* pContainer = CSenBinaryContainer::NewL( aCid, aFile );
       
  4240     		CleanupStack::PushL(pContainer);
       
  4241     		
       
  4242 		    if( retVal == KErrNone)
       
  4243 		    	{
       
  4244 		    	const HBufC8* pCid = pContainer->CidPtr();
       
  4245 					
       
  4246 					if( pCid )
       
  4247 					    {
       
  4248 					    error = iMap.Append( pCid, pContainer );        
       
  4249 					    }
       
  4250 					
       
  4251 					if( error )
       
  4252 					    {
       
  4253 					    CleanupStack::PopAndDestroy( pContainer );    
       
  4254 					    }
       
  4255 					else
       
  4256 					    {
       
  4257 					    CleanupStack::Pop( pContainer );
       
  4258 					    }
       
  4259 					}
       
  4260 				);			    
       
  4261     return error;
       
  4262     }
       
  4263     
       
  4264 TInt CSenConnectionChunk::AddChunkToContainerMap( const TDesC8& aCid, RChunk aChunk, TInt aChunkSize, TInt aChunkOffset )
       
  4265     {
       
  4266     TInt retVal(0);
       
  4267     TInt error ( KErrSenInternal );
       
  4268     // First, check for duplicates
       
  4269     TInt index = iMap.Find( aCid );
       
  4270     if ( index != KErrNotFound )
       
  4271 			{
       
  4272       return KErrAlreadyExists;
       
  4273       }
       
  4274 
       
  4275     // Otherwise, it is "safe" to add a binary container under this CID
       
  4276     TRAP( retVal, 
       
  4277     		CSenBinaryContainer* pContainer = CSenBinaryContainer::NewL( aCid, aChunk, aChunkSize, aChunkOffset );
       
  4278     		CleanupStack::PushL(pContainer);
       
  4279     		
       
  4280 		    if( retVal == KErrNone)
       
  4281 		  		{
       
  4282 			    const HBufC8* pCid = pContainer->CidPtr();
       
  4283 			    
       
  4284 			    if( pCid )
       
  4285 			        {
       
  4286 			        error = iMap.Append( pCid, pContainer );        
       
  4287 			        }
       
  4288 			    
       
  4289 			    if( error )
       
  4290 			        {
       
  4291 			        CleanupStack::PopAndDestroy( pContainer );    
       
  4292 			        }
       
  4293 			    else
       
  4294 			        {
       
  4295 			        CleanupStack::Pop( pContainer );
       
  4296 			        }
       
  4297 			    }
       
  4298 	    	);
       
  4299 	  return error;  
       
  4300   	}
       
  4301     
       
  4302 RBinaryMap& CSenConnectionChunk::ContainerMap()
       
  4303     {
       
  4304     return iMap;
       
  4305     }
       
  4306 
       
  4307 TInt CSenConnectionChunk::ContainerCount()
       
  4308     {
       
  4309     return iMap.Count();
       
  4310     }
       
  4311     
       
  4312 CSenBinaryContainer::CSenBinaryContainer( TDataType aType )
       
  4313 : iType(aType)
       
  4314     {
       
  4315     }
       
  4316 
       
  4317 CSenBinaryContainer::~CSenBinaryContainer()
       
  4318     {
       
  4319     delete ipCid;
       
  4320     ipCid = NULL;
       
  4321     iFile.Close();  
       
  4322     iChunk.Close(); 
       
  4323     }
       
  4324     
       
  4325 void CSenBinaryContainer::ConstructL( const TDesC8& aCid, RFile aFile )
       
  4326     {
       
  4327     ipCid = aCid.AllocL();
       
  4328     iFile.Duplicate( aFile );
       
  4329     }
       
  4330 
       
  4331 void CSenBinaryContainer::ConstructL( const TDesC8& aCid, RChunk aChunk, TInt aChunkSize, TInt aChunkOffset )
       
  4332     {
       
  4333     ipCid = aCid.AllocL();
       
  4334     iChunk = aChunk; // MOST LIKELY CODE SHOULD OPEN THE CHUNK IN HERE. 
       
  4335     iChunkSize = aChunkSize;
       
  4336     iChunkOffset = aChunkOffset;
       
  4337     }
       
  4338     
       
  4339 
       
  4340 CSenBinaryContainer* CSenBinaryContainer::NewL( const TDesC8& aCid, RFile aFile )
       
  4341     {
       
  4342     CSenBinaryContainer* pNew = CSenBinaryContainer::NewLC( aCid, aFile );
       
  4343     CleanupStack::Pop();
       
  4344     return pNew;        
       
  4345     }
       
  4346     
       
  4347 CSenBinaryContainer* CSenBinaryContainer::NewLC( const TDesC8& aCid, RFile aFile )
       
  4348     {
       
  4349     CSenBinaryContainer* pNew = new (ELeave) CSenBinaryContainer( CSenBinaryContainer::EFile );  
       
  4350     CleanupStack::PushL( pNew );
       
  4351     pNew->ConstructL( aCid, aFile );
       
  4352     return pNew;
       
  4353     }
       
  4354 
       
  4355 CSenBinaryContainer* CSenBinaryContainer::NewL( const TDesC8& aCid, RChunk aChunk, TInt aChunkSize, TInt aChunkOffset )
       
  4356     {
       
  4357     CSenBinaryContainer* pNew = CSenBinaryContainer::NewLC( aCid, aChunk, aChunkSize, aChunkOffset );
       
  4358     CleanupStack::Pop();
       
  4359     return pNew;        
       
  4360     }
       
  4361     
       
  4362 CSenBinaryContainer* CSenBinaryContainer::NewLC( const TDesC8& aCid, RChunk aChunk, TInt aChunkSize, TInt aChunkOffset )
       
  4363     {
       
  4364     CSenBinaryContainer* pNew = new (ELeave) CSenBinaryContainer( CSenBinaryContainer::EChunk );  
       
  4365     CleanupStack::PushL( pNew );
       
  4366     pNew->ConstructL( aCid, aChunk, aChunkSize, aChunkOffset );
       
  4367     return pNew;
       
  4368     }
       
  4369 
       
  4370 TBool CSenBinaryContainer::IsFile() const
       
  4371     {
       
  4372     // checks iType (TDataType)
       
  4373     TBool isFile( iType == CSenBinaryContainer::EFile );
       
  4374     return isFile;
       
  4375     }
       
  4376     
       
  4377     
       
  4378 TBool CSenBinaryContainer::IsChunk() const
       
  4379     {
       
  4380     // checks iType (TDataType)
       
  4381     TBool isChunk( iType == CSenBinaryContainer::EChunk );
       
  4382     return isChunk;
       
  4383     }
       
  4384     
       
  4385 CSenBinaryContainer::TDataType CSenBinaryContainer::Type() const
       
  4386     {
       
  4387     return iType;
       
  4388     }
       
  4389 
       
  4390 TPtrC8 CSenBinaryContainer::Cid() const
       
  4391     {
       
  4392     TPtrC8 cid(KNullDesC8);
       
  4393     if( ipCid )
       
  4394         {
       
  4395         cid.Set( *ipCid );
       
  4396         }
       
  4397     return cid;
       
  4398     }
       
  4399 
       
  4400 const HBufC8* CSenBinaryContainer::CidPtr() const
       
  4401     {
       
  4402     return ipCid;
       
  4403     }
       
  4404     
       
  4405 RFile CSenBinaryContainer::File() const
       
  4406     {
       
  4407     return iFile;
       
  4408     }
       
  4409 RChunk CSenBinaryContainer::Chunk() const
       
  4410     {
       
  4411     return iChunk;
       
  4412     }
       
  4413     
       
  4414 TInt CSenBinaryContainer::ChunkSize() const
       
  4415     {
       
  4416     return iChunkSize;   
       
  4417     }
       
  4418     
       
  4419 TInt CSenBinaryContainer::ChunkOffset() const
       
  4420     {
       
  4421     return iChunkSize;
       
  4422     }
       
  4423     
       
  4424 // End of file
       
  4425 
       
  4426