webservices/wscore/src/sencoreservicemanager.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:          
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 // INCLUDE FILES
       
    29 #include <mmtsy_names.h>
       
    30 #include <SenServiceConnection.h>   // error codes and framework ids
       
    31 #include <SenHostletConnection.h>   // error codes for hostlet connections
       
    32 #include <MSenServiceDescription.h>
       
    33 #include <MSenConsumerPolicy.h>
       
    34 #include <SenXmlUtils.h>
       
    35 #include "senwsdescription.h"
       
    36 #include "senwspattern.h"
       
    37 #include <MSenServicePolicy.h>
       
    38 
       
    39 #include "sencoreservicemanager.h"
       
    40 #include "senservicemanagerdefines.h"
       
    41 #include "senclientsession.h"
       
    42 #include "senxmldao.h"
       
    43 
       
    44 #include "sencoreshutdowntimer.h"
       
    45 
       
    46 #include "senserviceinvocationframework.h"  // internal Framework\inc
       
    47 #include "senservicesession.h"              // internal Framework\inc
       
    48 #include "sendebug.h"                       // internal Utils\inc
       
    49 #include "senlogger.h"                      // internal Utils\inc
       
    50 #include "senguidgen.h"                     // internal Utils\inc
       
    51 #include "senmultiuseridentitymanager.h"         // internal IdentityManager\inc
       
    52 #include "sencredentialmanager.h"           // internal CredentialManager\inc
       
    53 #include "seninternalcredential.h"
       
    54 
       
    55 // To be kept ONLY UNTIL there are real ECOM transport plug-ins available:
       
    56 #include "SenHttpTransportProperties.h"
       
    57 
       
    58 #include "sentransportcontext.h"
       
    59 
       
    60 #include "sentransport.h"
       
    61 
       
    62 #include "senservercontext.h"
       
    63 
       
    64 #include <RSenDocument.h>
       
    65 
       
    66 #include "senxmldebug.h"
       
    67 
       
    68 
       
    69 namespace
       
    70     {
       
    71     const TInt KBase64DecodeMultiplier  = 1;
       
    72     const TInt KBase64EncodeMultiplier  = 2;
       
    73 // Deleted to fix for compiler warning  #177-D
       
    74     _LIT(KSOAServerName,"SOAServer");
       
    75     const TInt KFlatBufSize            = 64;
       
    76     }
       
    77 
       
    78 
       
    79 
       
    80 CSenCoreServiceManager* CSenCoreServiceManager::NewL()
       
    81     {
       
    82     CSenCoreServiceManager* pNew = CSenCoreServiceManager::NewLC();
       
    83     CleanupStack::Pop();
       
    84     return pNew;
       
    85     }
       
    86 
       
    87 CSenCoreServiceManager* CSenCoreServiceManager::NewLC()
       
    88     {
       
    89     CSenCoreServiceManager* pNew =
       
    90         new (ELeave) CSenCoreServiceManager(EPriorityNormal);
       
    91     CleanupStack::PushL(pNew);
       
    92 
       
    93     pNew->ConstructL();
       
    94     return pNew;
       
    95     }
       
    96 
       
    97 CSenCoreServiceManager::CSenCoreServiceManager(TInt aPriority)
       
    98 
       
    99 #ifndef RD_SEN_SC_MSG_DISPATCHER_ENABLED // == FALSE, DISPATCHER IS DISABLED   
       
   100 #ifdef EKA2
       
   101 :   CPolicyServer(aPriority, coreServiceManagerPolicy, EUnsharableSessions),
       
   102   #else
       
   103 :   CServer2(aPriority, EUnsharableSessions), //IPC V2
       
   104   #endif //EKA2
       
   105 
       
   106 #else // RD_SEN_SC_MSG_DISPATCHER_ENABLED == TRUE, DISPATCHER IS ENABLED
       
   107   #ifdef EKA2
       
   108 :   CPolicyServer(aPriority, coreServiceManagerPolicy, ESharableSessions),
       
   109   #else
       
   110 :   CServer2(aPriority, ESharableSessions), //IPC V2
       
   111   #endif //EKA2
       
   112 #endif //RD_SEN_SC_MSG_DISPATCHER_ENABLED
       
   113     iDAO(NULL),
       
   114     iIdentityManager(NULL),
       
   115     //iTransport(NULL),
       
   116     iGuidGenerator(NULL),
       
   117     iReader(NULL),
       
   118     iNextTransactionId(0)
       
   119 //    ipActiveHostletEndpoints(NULL)
       
   120     {
       
   121     }
       
   122 
       
   123 void CSenCoreServiceManager::ConstructL()
       
   124     {
       
   125     iShutdownTimer = CSenCoreShutdownTimer::NewL();
       
   126     
       
   127     // Start by creating a GUID generator
       
   128     iGuidGenerator = CSenGuidGen::NewL();
       
   129 
       
   130 
       
   131 #ifdef _SENDEBUG
       
   132 
       
   133     // Open connection to the file logger server
       
   134     // Create a logger
       
   135     TLSLOG_OPEN_TO_MODE( KSenCoreServiceManagerLogChannelBase, KSenCoreServiceManagerLogLevel, KSenCoreServiceManagerLogDir, KSenCoreServiceManagerLogFile, EFileLoggingModeAppend );
       
   136     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::ConstructL - Log file opened [2008-11-12], WSF version 1.9 - build 48");
       
   137     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("- Core instance (memory address): 0x%X"), this));
       
   138 
       
   139 //    TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"Zapping filelogged messages (.xml)");
       
   140 
       
   141     TLSLOG_OPEN(KSenFaultsLogChannel, KSenFaultsLogLevel, KSenFaults, KSenFaultsLog);
       
   142     TLSLOG_OPEN(KSenUtilsLogChannel, KSenUtilsLogLevel, KSenUtils, KSenUtilsLog);
       
   143 
       
   144     // zap logged messages (.xml)
       
   145 //    RFs fss;
       
   146 //    User::LeaveIfError(fss.Connect() == NULL);
       
   147 //    CleanupClosePushL(fss);
       
   148 //
       
   149 //    fss.Delete(_L("c:\\logs\\WsLog\\AS_init_req.xml"));
       
   150 //    fss.Delete(_L("c:\\logs\\WsLog\\AS_init_rsp.xml"));
       
   151 //    fss.Delete(_L("c:\\logs\\WsLog\\AS_req.xml"));
       
   152 //    fss.Delete(_L("c:\\logs\\WsLog\\AS_rsp.xml"));
       
   153 //    fss.Delete(_L("c:\\logs\\WsLog\\DS_lookup_req.xml"));
       
   154 //    fss.Delete(_L("c:\\logs\\WsLog\\DS_lookup_rsp.xml"));
       
   155 //    fss.Delete(_L("c:\\logs\\WsLog\\service_body_req.xml"));
       
   156 //    fss.Delete(_L("c:\\logs\\WsLog\\service_body_rsp.xml"));
       
   157 //    fss.Delete(_L("c:\\logs\\WsLog\\service_env_req.xml"));
       
   158 //    fss.Delete(_L("c:\\logs\\WsLog\\service_env_rsp.xml"));
       
   159 //    CleanupStack::PopAndDestroy(); // fss.Close()
       
   160 #endif // _SENDEBUG
       
   161 #ifdef _RD_SEN_ENABLE_CREDLOG    
       
   162     CREDLOG_OPEN();
       
   163     
       
   164     CREDLOG_L(KSenCredsLogLevelMin,    "Creds.log level 1: MIN enabled.");
       
   165     CREDLOG_L(KSenCredsLogLevelNormal, "Creds.log level 2: NORMAL enabled.");
       
   166     CREDLOG_L(KSenCredsLogLevelMax,    "Creds.log level 3: MAX enabled.");
       
   167     
       
   168 
       
   169     _LIT8(KTestingCredsLogLine, "[min]: Logging level verification complete.");
       
   170     CREDLOG(KSenCredsLogLevelMin, KTestingCredsLogLine);
       
   171 
       
   172     _LIT8(KTestingCredsLongLogLine, "[normal] ------------------------------------------------------------------------------"); // could be more that 120 chars or so..
       
   173     CREDLOG_ALL(KSenCredsLogLevelNormal, KTestingCredsLongLogLine);
       
   174 
       
   175     _LIT8(KTestingCredsLogLineFormat, "[max] - Logging channel is: %d");
       
   176     CREDLOG_FORMAT((KSenCredsLogChannel, KSenCredsLogLevelMax, KTestingCredsLogLineFormat, KSenCredsLogChannel)); // on format lines you need to give channel (at the moment)
       
   177 #endif // _RD_SEN_ENABLE_CREDLOG    
       
   178 
       
   179     // Create THE common XML reader inside Serene
       
   180     iReader = CSenXmlReader::NewL(KXmlParserMimeType); // use libxml2 sax parser
       
   181 
       
   182     iIdentityManager = CSenMultiUserIdentityManager::NewL(*this);
       
   183 
       
   184     iCredentialManager = CSenCredentialManager::NewL(*this);
       
   185 
       
   186     iDAO = CSenXMLDAO::NewL(*(MSenCoreServiceManager*)this);
       
   187     	
       
   188 	CREDLOG_L(KSenCredsLogLevelMin,    "GetImsiImeiL Started");    	
       
   189     // Load the sessions from XML-file
       
   190     GetImsiImeiL();
       
   191 	CREDLOG_L(KSenCredsLogLevelMin,    "GetImsiImeiL Completed");    
       
   192     
       
   193     iDAO->Load();
       
   194 
       
   195     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"SenCoreServiceManager starting!");
       
   196 
       
   197     // Create server context for SEN.EXE (could be done in thread function as well)
       
   198     ipServerContext = CSenServerContext::NewL(*this);
       
   199    
       
   200     StartL(KSenServiceManager);
       
   201     NotifyFrameworksL(KSenEventWsfReady);
       
   202     }
       
   203 
       
   204 CSenCoreServiceManager::~CSenCoreServiceManager()
       
   205     {
       
   206 
       
   207     // Delete member variables
       
   208     CSenCoreServiceManager::SetShowPasswordDialog(EFalse);
       
   209     delete ipServerContext;
       
   210     delete iDAO;
       
   211     delete iCredentialManager;
       
   212     if(iIdentityManager != NULL) // Fix for codescanner warning
       
   213     {
       
   214     iIdentityManager->WriteDatabase();
       
   215     }
       
   216     delete iIdentityManager;
       
   217     delete iGuidGenerator;
       
   218     delete iShutdownTimer;
       
   219     delete iReader;
       
   220     delete ipVtcpTransport;
       
   221 //    delete ipVtcpEndpoint;
       
   222 //    if(ipActiveHostletEndpoints)
       
   223 //        {
       
   224 //        ipActiveHostletEndpoints->ResetAndDestroy();
       
   225 //        delete ipActiveHostletEndpoints;
       
   226 //        }
       
   227 
       
   228 #ifdef _SENDEBUG
       
   229     TLSLOG_CLOSE(KSenFaultsLogChannel);
       
   230     TLSLOG_CLOSE(KSenUtilsLogChannel);
       
   231     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"Log file closed.");
       
   232 
       
   233     TLSLOG_CLOSE(KSenCoreServiceManagerLogChannelBase);
       
   234 #endif // _SENDEBUG
       
   235 
       
   236     CREDLOG_CLOSE();
       
   237 
       
   238     iStringPool.Close();
       
   239 //    iLog.Close();
       
   240     }
       
   241 
       
   242 //////////////////////////////////////////////////////////////////////////
       
   243 // from MSenIdentityManager
       
   244 
       
   245 MSenIdentity& CSenCoreServiceManager::IdentityL()
       
   246     {
       
   247     return iIdentityManager->IdentityL();
       
   248     }
       
   249 
       
   250 TInt CSenCoreServiceManager::UserNameL(HBufC8*& aUserName)
       
   251     {
       
   252     return iIdentityManager->UserNameL(aUserName);
       
   253     }
       
   254 
       
   255 CSenIdentityProvider* CSenCoreServiceManager::IdentityProviderL(
       
   256                                                         const TDesC8& aURI )
       
   257     {
       
   258     if(iIdentityManager)
       
   259         return iIdentityManager->IdentityProviderL(aURI);
       
   260     else
       
   261         return NULL;
       
   262     }
       
   263 
       
   264 CSenIdentityProvider* CSenCoreServiceManager::IdentityProviderL(
       
   265                                                 const CDesC8Array& aIdpList,
       
   266                                                 TBool aStrict)
       
   267     {
       
   268     if(iIdentityManager)
       
   269         return iIdentityManager->IdentityProviderL(aIdpList,aStrict);
       
   270     else
       
   271         return NULL;
       
   272     }
       
   273 
       
   274 
       
   275 CSenIdentityProvider* CSenCoreServiceManager::IdentityProviderL(
       
   276                                 MSenServiceDescription& aServiceDescription )
       
   277     {
       
   278     if(iIdentityManager)
       
   279         return iIdentityManager->IdentityProviderL(aServiceDescription);
       
   280     else
       
   281         return NULL;
       
   282     }
       
   283 
       
   284 CSenIdentityProvider* CSenCoreServiceManager::IdentityProviderL(
       
   285                                             MSenServiceDescription& aService,
       
   286                                             const CDesC8Array& aIdpList,
       
   287                                             TBool aStrict)
       
   288     {
       
   289     if(iIdentityManager)
       
   290         return iIdentityManager->IdentityProviderL(aService, aIdpList, aStrict);
       
   291     else
       
   292         return NULL;
       
   293     }
       
   294 
       
   295 const RPointerArray<CSenIdentityProvider>& CSenCoreServiceManager::IdentityProvidersL()
       
   296     {
       
   297     if(!iIdentityManager) User::Leave(KErrNotFound);
       
   298     return iIdentityManager->IdentityProvidersL();
       
   299     }
       
   300 
       
   301 CSenIdentityProvider* CSenCoreServiceManager::IdentityProviderL()
       
   302     {
       
   303     if(iIdentityManager)
       
   304         return iIdentityManager->IdentityProviderL();
       
   305     else
       
   306         return NULL;
       
   307     }
       
   308 
       
   309 TInt CSenCoreServiceManager::RegisterIdentityProviderL(
       
   310                                                 CSenIdentityProvider* aIdp)
       
   311     {
       
   312     return iIdentityManager->RegisterIdentityProviderL(aIdp);
       
   313     }
       
   314 
       
   315 TInt CSenCoreServiceManager::UnregisterIdentityProviderL(
       
   316                                                 CSenIdentityProvider& aIdp)
       
   317     {
       
   318     return iIdentityManager->UnregisterIdentityProviderL(aIdp);
       
   319     }
       
   320 
       
   321 TBool CSenCoreServiceManager::AssociateServiceL(const TDesC8& aServiceID,
       
   322                                                 const TDesC8& aProviderID )
       
   323     {
       
   324     return iIdentityManager->AssociateServiceL(aServiceID, aProviderID);
       
   325     }
       
   326 
       
   327 TBool CSenCoreServiceManager::DissociateServiceL(const TDesC8& aServiceID,
       
   328                                                  const TDesC8& aProviderID )
       
   329     {
       
   330     return iIdentityManager->DissociateServiceL(aServiceID, aProviderID);
       
   331     }
       
   332 
       
   333 TInt CSenCoreServiceManager::IdentitiesL( CDesC8Array& aIdentitiesList )
       
   334     {
       
   335     return iIdentityManager->IdentitiesL( aIdentitiesList );
       
   336     }
       
   337 
       
   338 TInt CSenCoreServiceManager::AuthenticationForL(CSenIdentityProvider& aAccount, TPckgBuf<TSenAuthentication>& aResponse)
       
   339     {
       
   340     return iIdentityManager->AuthenticationForL( aAccount, aResponse );
       
   341     }
       
   342 
       
   343 //////////////////////////////////////////////////////////////////////////
       
   344 
       
   345 
       
   346 // getter
       
   347 MSIF* CSenCoreServiceManager::Framework(const TDesC8& aFrameworkID)
       
   348     {
       
   349     return(iDAO->Framework(aFrameworkID));
       
   350     }
       
   351 
       
   352 
       
   353 TInt CSenCoreServiceManager::InitServiceConnectionL(MSenRemoteServiceConsumer& aConsumer,
       
   354                                                     CSenWSDescription& aPattern,
       
   355                                                     HBufC8*& aErrorMsg)
       
   356     {
       
   357     CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL");
       
   358     TInt retVal(KErrNotFound);
       
   359 
       
   360 //    CSenWSDescription* pSD = iDAO->FindMatchingServiceDescription(aPattern);
       
   361         
       
   362     TInt bestScore;
       
   363     CSenWSDescription* pSD = 
       
   364         iDAO->FindMatchingSDAndBestScoreL(aPattern, bestScore);	//CodeScannerWarnings
       
   365 
       
   366     if(!pSD) // service NOT found
       
   367         {
       
   368          CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   369          CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ," - No matching service description in XML database.");
       
   370 
       
   371         // request frameworks to search for a matching service
       
   372         // as soon as a matching service is found retry the primary search
       
   373 
       
   374         TInt additions = iDAO->AddServiceDescriptionToFrameworksL( aPattern, aConsumer, aErrorMsg );
       
   375         CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   376         TInt error(KErrNone);
       
   377         if( additions < 0 )
       
   378             {
       
   379             error = additions;
       
   380             additions = 0;
       
   381             }
       
   382         CSLOG_FORMAT((aConsumer.ConnectionId(), KNormalLogLevel , _L8(" - Just added %d service description(s)."), additions));
       
   383         if ( error )
       
   384             {
       
   385             retVal = error;
       
   386             CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"/ / / / / / / / / / / / / / /");
       
   387             CSLOG_FORMAT((aConsumer.ConnectionId(), KMinLogLevel , _L8(" - Error occurred: (%d)."), error));
       
   388             if( aErrorMsg )
       
   389                 {
       
   390                 CSLOG_ALL(aConsumer.ConnectionId(),KMinLogLevel ,*aErrorMsg);
       
   391                 }
       
   392              CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"/ / / / / / / / / / / / / / /");
       
   393             }
       
   394 
       
   395         if( additions > 0 ) // at least one SD was added, and no error occurred
       
   396             {
       
   397 			/* We should now try the primary search again.
       
   398 			 * Note that we try to pick a service that matches 
       
   399 			 * at least as well as the best we had earlier
       
   400 			 * but at least the contract or endpoint should
       
   401 			 * match.
       
   402 			 */ 
       
   403             pSD = iDAO->FindScoreMatchingServiceDescriptionL(aPattern, bestScore+1);	//CodeScannerWarnings
       
   404 //            pSD = iDAO->FindMatchingServiceDescription(aPattern);
       
   405             }
       
   406         }
       
   407 
       
   408     if(pSD) // Service was found
       
   409         {
       
   410         // Update ProviderPolicy information
       
   411         pSD->RebuildFrom(aPattern);
       
   412         // Update ServicePolicy information
       
   413         MSenServicePolicy* servicePolicy = pSD->ServicePolicy();
       
   414         if(servicePolicy)
       
   415             {
       
   416             MSenServicePolicy* givenServicePolicy = aPattern.ServicePolicy();
       
   417             if(givenServicePolicy)
       
   418                 servicePolicy->RebuildServicePolicyFrom(*givenServicePolicy);
       
   419             }
       
   420 
       
   421 #ifdef _SENDEBUG
       
   422         TPtrC8 endpoint = pSD->Endpoint();
       
   423         if(endpoint.Length()>0)
       
   424             {
       
   425             CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   426            CSLOG_FORMAT((aConsumer.ConnectionId(), KMinLogLevel , _L8("- Matching service found, endpoint: %S"), &endpoint));
       
   427             }
       
   428         else
       
   429             {
       
   430             CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   431             CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"- Matching service found; it has no endpoint.");
       
   432             }
       
   433 #endif // _SENDEBUG
       
   434 
       
   435         TPtrC8 patternFrameworkID = pSD->FrameworkId();
       
   436         if(patternFrameworkID != KNullDesC8)
       
   437             {
       
   438             MSIF* pFramework = NULL;
       
   439             pFramework = iDAO->Framework( patternFrameworkID );
       
   440 
       
   441             if(pFramework)
       
   442                 {
       
   443                 CSenServiceSession* pSession = NULL;
       
   444 
       
   445                 TInt err = pFramework->CreateServiceSessionL(*pSD,
       
   446                                                             aPattern,
       
   447                                                             pSession,
       
   448                                                             aConsumer,
       
   449                                                             aErrorMsg);
       
   450                 CleanupStack::PushL(pSession);
       
   451                 if( err != KErrNone )
       
   452                     {
       
   453                     CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   454                     CSLOG_FORMAT((aConsumer.ConnectionId(), KMinLogLevel , _L8(" - CreateServiceSessionL failed, error: %d"), err));
       
   455 
       
   456                     if ( pSession && pSession != pSD )
       
   457                         {
       
   458                         // Since session creation failed, delete the returned orphan
       
   459                         // object. This should never occur; it is badly against the
       
   460                         // "framework design paradigms"):
       
   461                         CleanupStack::PopAndDestroy( pSession );
       
   462                         }
       
   463                     else
       
   464                         {
       
   465                         // NULL was returned
       
   466                         CleanupStack::Pop( pSession );
       
   467                         }
       
   468                     return err;
       
   469                     }
       
   470                 else
       
   471                     {
       
   472                     // Create service session OK
       
   473                     // Note: isReady in Symbian c == isValid in Java
       
   474                     if( pSession && pSession->IsReadyL() )
       
   475                         {
       
   476                         // bind consumer to the new session:
       
   477                         pSession->AddConsumerL(aConsumer);
       
   478                         aConsumer.SetSessionL(*pSession);
       
   479                         UpdateTouchL(pSession);
       
   480                         CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   481                         CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ," - CreateServiceSessionL OK!");
       
   482                         CleanupStack::Pop(); // pSession
       
   483                         return KErrNone;
       
   484                         }
       
   485                     else
       
   486                         {
       
   487                         CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"CSenCoreServiceManager::InitServiceConnectionL:");
       
   488                         CSLOG_L(aConsumer.ConnectionId(), KMinLogLevel ,"- Removing service description");
       
   489 
       
   490                         if(pSession)
       
   491                             {
       
   492                             iDAO->Remove(*pSession);
       
   493                             }
       
   494                         else
       
   495                             {
       
   496                             iDAO->Remove(*pSD);
       
   497                             }
       
   498                         CleanupStack::Pop(pSession);
       
   499                         return KErrNotReady;
       
   500                         }
       
   501                     }
       
   502                 }
       
   503             }
       
   504 
       
   505         }
       
   506     // else { // service was not found }
       
   507     return retVal;
       
   508     }
       
   509 
       
   510 TInt CSenCoreServiceManager::ServiceDescriptionsL( RWSDescriptionArray& aMatches, const TDesC8& aContract )
       
   511     {
       
   512     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::ServiceDescriptionsL(<contract>)");
       
   513     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8(" - Collecting existing service descriptions with contract: %S"), &aContract));
       
   514     return iDAO->FindAllMatchingServiceDescriptions(aMatches, aContract);
       
   515     }
       
   516 
       
   517 TInt CSenCoreServiceManager::ServiceDescriptionsL(RWSDescriptionArray& aMatches, MSenServiceDescription& aPattern)
       
   518     {
       
   519     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::ServiceDescriptionsL(<pattern>)");
       
   520     return iDAO->FindAllMatchingServiceDescriptions(aMatches, aPattern);
       
   521     }
       
   522 
       
   523 // Note that this method *always* takes the ownership of the SD
       
   524 TInt CSenCoreServiceManager::RegisterServiceDescriptionL( CSenWSDescription* apServiceDescription )
       
   525     {
       
   526     if(!apServiceDescription)
       
   527         {
       
   528         return KErrArgument;
       
   529         }
       
   530 
       
   531     TInt retVal(KErrNotFound);
       
   532     MSIF* framework = Framework(apServiceDescription->FrameworkId());
       
   533     if(framework)
       
   534         {
       
   535         retVal = framework->RegisterServiceDescriptionL(*apServiceDescription);
       
   536 
       
   537         if(!iDAO->Owns(apServiceDescription))
       
   538             {
       
   539             delete apServiceDescription;
       
   540             apServiceDescription = NULL;
       
   541             }
       
   542         }
       
   543     else
       
   544         {
       
   545         delete apServiceDescription;
       
   546         apServiceDescription = NULL;
       
   547         }
       
   548     return retVal;
       
   549     }
       
   550 
       
   551 
       
   552 TInt CSenCoreServiceManager::UnregisterServiceDescriptionL( MSenServiceDescription& aServiceDescription )
       
   553     {
       
   554     TInt retVal(KErrNotFound);
       
   555     MSIF* framework = Framework(aServiceDescription.FrameworkId());
       
   556     if(framework)
       
   557         {
       
   558         retVal = framework->UnregisterServiceDescriptionL(aServiceDescription);
       
   559         }
       
   560     return retVal;
       
   561     }
       
   562 
       
   563 
       
   564 CDesC8Array& CSenCoreServiceManager::SupportedFrameworksL()
       
   565     {
       
   566     return iDAO->SupportedFrameworksL();
       
   567     }
       
   568 
       
   569 RFileLogger* CSenCoreServiceManager::Log() const
       
   570     {
       
   571     return (RFileLogger*) &iLog;
       
   572     }
       
   573 
       
   574 void CSenCoreServiceManager::IncrementConnections()
       
   575     {
       
   576     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::IncrementConnections");
       
   577     if( iShutdownTimer && iShutdownTimer->IsActive() ) // iConnectionCount <= 0
       
   578         {
       
   579         iShutdownTimer->Deque(); // will prevent the active scheduler (of this server) from being stopped
       
   580         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Shutdown timer cancelled, serving emerged new client.");
       
   581         }
       
   582     iConnectionCount++;
       
   583     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("- Client count increased to: %d"),iConnectionCount));
       
   584     }
       
   585 
       
   586 void CSenCoreServiceManager::DecrementConnections()
       
   587     {
       
   588     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel,"CSenCoreServiceManager::DecrementConnections");
       
   589     iConnectionCount--;
       
   590     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("- Client count decreased to: %d"),iConnectionCount));
       
   591     if (iConnectionCount <= 0)
       
   592         {
       
   593         if( iShutdownTimer )
       
   594             {
       
   595             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Shutdown timer activated.");
       
   596             iShutdownTimer->ActivateShutdown(); // will stop the active scheduler (of this server) after N secs, unless cancelled
       
   597             }
       
   598         else
       
   599             {
       
   600             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Stopping active scheduler.");
       
   601             CActiveScheduler::Stop(); // in practice, not utilized anymore (with shutdown timer functionality)
       
   602             }
       
   603        }
       
   604     }
       
   605 
       
   606 // from MSenCoreServiceManager
       
   607 HBufC8* CSenCoreServiceManager::RandomGuidL()
       
   608     {
       
   609     HBufC8* pRandomGuid =  iGuidGenerator->GetRandomGuid8LC();
       
   610     CleanupStack::Pop();
       
   611     return pRandomGuid;
       
   612     }
       
   613 
       
   614 // NOTE(!): AddServiceDescriptionL() always takes the ownership of aServiceDescription
       
   615 TInt CSenCoreServiceManager::AddServiceDescriptionL( CSenWSDescription* apServiceDescription )
       
   616     {
       
   617     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   618 
       
   619     if(!apServiceDescription)
       
   620         {
       
   621         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel," - Illegal argument: Cannot add NULL as ServiceDescription!");
       
   622         return KErrArgument; 
       
   623         }
       
   624 
       
   625     TPtrC8 contract     = apServiceDescription->Contract();
       
   626     TPtrC8 endpoint     = apServiceDescription->Endpoint();
       
   627 
       
   628 #ifdef _SENDEBUG
       
   629     TPtrC8 frameworkID  = apServiceDescription->FrameworkId();
       
   630     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel, _L8(" - Framework ID: '%S'"),&frameworkID));
       
   631     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel, _L8(" - Endpoint: '%S'"),&endpoint));
       
   632     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel, _L8(" - Contract: '%S'"),&contract));
       
   633 #endif
       
   634 
       
   635     if ( contract.Length() == 0 && endpoint.Length() == 0 )
       
   636         {
       
   637         delete apServiceDescription;
       
   638         apServiceDescription = NULL;
       
   639         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   640         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - No endpoint & no contract: invalid SD NOT added!");
       
   641         return KErrSenNoContractNoEndPoint;
       
   642         }
       
   643 
       
   644     CSenWSDescription* pDuplicate =
       
   645         iDAO->FindExactServiceDescriptionL(*apServiceDescription);	//CodeScannerWarnings
       
   646 
       
   647     if(pDuplicate)
       
   648         {
       
   649         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   650         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - Duplicate found, going to unregister -> register!");
       
   651 
       
   652         // Signal the frameworks: the duplicate ownership is
       
   653         // theirs (it can be deleted, etc)
       
   654         if( iDAO->Remove( *pDuplicate ) ) // true if matching SD already exists
       
   655             {
       
   656             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   657             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - Removed duplicate, adding new SD.");
       
   658 
       
   659             TInt retVal = iDAO->Add(*apServiceDescription);
       
   660             if(retVal!=KErrNone)
       
   661                 {
       
   662                 // Failed to add new SD to XML DAO, must free the orphan
       
   663                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   664                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - Could NOT add as new SD. Deleting this orphan.");
       
   665                 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8(" - error code: %d"),retVal));
       
   666 
       
   667                 // delete the new instance and return error (to framework)
       
   668                 delete apServiceDescription;
       
   669                 apServiceDescription = NULL;
       
   670                 return retVal; 
       
   671                 }
       
   672 #ifdef _SENDEBUG
       
   673             else
       
   674                 {
       
   675                 // Successfully added new SD, XMLDAO now owns it
       
   676                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   677                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - Successfully added as new SD instance.");
       
   678                 }
       
   679 #endif
       
   680             }
       
   681         else
       
   682             {
       
   683             // Failed to remove duplicate SD from database
       
   684             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   685             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - Remove duplicate SD failed. Returning error.");
       
   686 
       
   687             // delete the new instance and return error (to framework)
       
   688             delete apServiceDescription;
       
   689             apServiceDescription = NULL;
       
   690             return KErrGeneral; 
       
   691             }
       
   692 
       
   693         }
       
   694     else
       
   695         {
       
   696         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::AddServiceDescriptionL()");
       
   697         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel," - Adding new service description.");
       
   698         iDAO->Add(*apServiceDescription);
       
   699         }
       
   700 
       
   701     return KErrNone;
       
   702     }
       
   703 
       
   704 TInt CSenCoreServiceManager::RemoveServiceDescriptionL( CSenWSDescription& aServiceDescription )
       
   705     {
       
   706     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CSenCoreServiceManager::RemoveServiceDescriptionL:")));
       
   707 
       
   708 #ifdef _SENDEBUG
       
   709     CBufFlat* pBuf = CBufFlat::NewL(KFlatBufSize);
       
   710     CleanupStack::PushL(pBuf);
       
   711     RBufWriteStream writeStream;
       
   712     writeStream.Open(*pBuf);
       
   713     CleanupClosePushL(writeStream);
       
   714     aServiceDescription.WriteAsXMLToL(writeStream);
       
   715     TPtr8 asXml = pBuf->Ptr(0);
       
   716     TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(asXml));
       
   717     CleanupStack::PopAndDestroy(2); // writeStream.Close(), pBuf
       
   718 #endif // _SENDEBUG
       
   719 
       
   720     if( iDAO->Remove( aServiceDescription ) )
       
   721         {
       
   722         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(_L("Removed matching SD!")));
       
   723         }
       
   724     else
       
   725         {
       
   726         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(_L("No matching SD found!")));
       
   727         return KErrNotFound;
       
   728         }
       
   729 
       
   730     return KErrNone;
       
   731     }
       
   732 
       
   733 // 2005-09-11: note that function leaves(!), if framework was
       
   734 // not successfully added to XML DAO
       
   735 CSenBaseFragment* CSenCoreServiceManager::InstallFrameworkL(const TDesC8& aCue)
       
   736     {
       
   737     TLSLOG(KSenCoreServiceManagerLogChannelBase, KMinLogLevel,(_L("CSenCoreServiceManager::InstallFrameworkL, cue:")));
       
   738     TLSLOG(KSenCoreServiceManagerLogChannelBase, KMinLogLevel,(aCue));
       
   739     CSIF* pFramework = CSIF::NewL(aCue, *this);
       
   740     CleanupStack::PushL(pFramework);
       
   741 
       
   742 #ifdef _SENDEBUG
       
   743         HBufC8* ptrBuf = pFramework->AsXmlL();
       
   744         if(ptrBuf)
       
   745             {
       
   746             CleanupStack::PushL(ptrBuf);
       
   747             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(*ptrBuf));
       
   748             CleanupStack::PopAndDestroy();
       
   749             }
       
   750 #endif // _SENDEBUG
       
   751 
       
   752 
       
   753     CSenBaseFragment* frameworkConfigParser = & pFramework->ConfigParser();
       
   754     TInt retCode(iDAO->Add(*pFramework));
       
   755     if(retCode==KErrNone)
       
   756         {
       
   757         CleanupStack::Pop(); //
       
   758         }
       
   759     else
       
   760         {
       
   761         // delete orpan SIF plug-in instance now
       
   762         CleanupStack::PopAndDestroy();
       
   763         }
       
   764 
       
   765     // leave, if add plug-in to DAO failed
       
   766     User::LeaveIfError(retCode);
       
   767 
       
   768 
       
   769     return frameworkConfigParser;
       
   770     }
       
   771 
       
   772 TInt CSenCoreServiceManager::SaveL(const CSenServiceSession& aServiceSession)
       
   773     {
       
   774     return iDAO->SaveL(aServiceSession);
       
   775     }
       
   776 
       
   777 TInt CSenCoreServiceManager::SaveL(const CSIF& aServiceInvocationFramework)
       
   778     {
       
   779     return iDAO->SaveL(aServiceInvocationFramework);
       
   780     }
       
   781 
       
   782 CSenXmlReader* CSenCoreServiceManager::XMLReader()
       
   783     {
       
   784     return iReader;
       
   785     }
       
   786 
       
   787 // notifies *ALL* framework plug-ins about certain event
       
   788 TInt CSenCoreServiceManager::NotifyFrameworksL(const TInt aEvent)
       
   789     {
       
   790     return NotifyFrameworksL(KNullDesC8, aEvent, NULL);
       
   791     }
       
   792 
       
   793 // same as above, with an additional pointer argument
       
   794 TInt CSenCoreServiceManager::NotifyFrameworksL(const TInt aEvent,
       
   795                                                TAny* aArgument)
       
   796     {
       
   797     return NotifyFrameworksL(KNullDesC8, aEvent, aArgument);
       
   798     }
       
   799 
       
   800 
       
   801 // notifies only those frameworks plug-ins, which match
       
   802 // with given framework ID (aFrameworkID)
       
   803 //
       
   804 // Note(!): if aFrameworkID == KNullDesC8 (zero-length),
       
   805 // then *all* known framework plug-ins are notified
       
   806 // about the event.
       
   807 TInt CSenCoreServiceManager::NotifyFrameworksL(const TDesC8& aFrameworkID,
       
   808                                              const TInt aEvent)
       
   809     {
       
   810     return NotifyFrameworksL(aFrameworkID, aEvent, NULL);
       
   811     }
       
   812 
       
   813 
       
   814 TInt CSenCoreServiceManager::NotifyFrameworksL(const TDesC8& aFrameworkID,
       
   815                                              const TInt aEvent,
       
   816                                              TAny* aArgument)
       
   817     {
       
   818     return iDAO->NotifyFrameworksL(aFrameworkID, aEvent, aArgument);
       
   819     }
       
   820 
       
   821 
       
   822 
       
   823 //MSenIdentityManager& CSenCoreServiceManager::IdentityManager()
       
   824 //    {
       
   825 //    return *(MSenIdentityManager*)this;
       
   826 //    }
       
   827 
       
   828 
       
   829 // CServer implementation:
       
   830 CSession2* CSenCoreServiceManager::NewSessionL( const TVersion &aVersion, const RMessage2& /*aMessage*/) const //IPC V2
       
   831     {
       
   832     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CSenCoreServiceManager::NewSessionL() start")));
       
   833 
       
   834     // Check we're the right version
       
   835     if ( !User::QueryVersionSupported(TVersion(KWsfServMajorVersionNumber,
       
   836          KWsfServMinorVersionNumber,
       
   837          KWsfServBuildVersionNumber),
       
   838          aVersion))
       
   839         {
       
   840         User::Leave(KErrNotSupported);
       
   841         }
       
   842     return CSenClientSession::NewL( *const_cast<CSenCoreServiceManager*> (this), *ipServerContext );
       
   843     }
       
   844 
       
   845 
       
   846 void CSenCoreServiceManager::ThreadFunctionL()
       
   847     {
       
   848     // Construct active scheduler
       
   849     CActiveScheduler* pActiveScheduler = new (ELeave) CActiveScheduler;
       
   850     CleanupStack::PushL(pActiveScheduler) ;
       
   851 
       
   852 
       
   853     // Install active scheduler
       
   854     // We don't need to check whether an active scheduler is already installed
       
   855     // as this is a new thread, so there won't be one
       
   856     CActiveScheduler::Install(pActiveScheduler);
       
   857 
       
   858     // Give a name to this thread
       
   859     User::LeaveIfError(User::RenameThread(KSOAServerName));
       
   860 
       
   861     RSenDocument::ManualXmlEngineTlsAttachL();
       
   862 
       
   863     // Construct our server
       
   864     CSenCoreServiceManager::NewLC(); 
       
   865 
       
   866     RSemaphore semaphore;
       
   867     CleanupClosePushL(semaphore);
       
   868     User::LeaveIfError(semaphore.OpenGlobal(KSenServiceManagerSemaphoreName));
       
   869 
       
   870     // Semaphore opened ok
       
   871     semaphore.Signal();
       
   872     CleanupStack::PopAndDestroy(); // close semaphore
       
   873 
       
   874     // Start handling requests
       
   875     CActiveScheduler::Start();
       
   876 
       
   877     CleanupStack::PopAndDestroy(); // CSenCoreServiceManager
       
   878     
       
   879     RSenDocument::ManualXmlEngineTlsCleanup();
       
   880 
       
   881     CleanupStack::PopAndDestroy(); // pActiveScheduler
       
   882     }
       
   883 
       
   884 void CSenCoreServiceManager::PanicClient(const RMessage2& aMessage,
       
   885                                          TWsfServPanic aPanic)
       
   886     {
       
   887     aMessage.Panic(KSenServiceManagerPanic, aPanic);
       
   888     }
       
   889 
       
   890 void CSenCoreServiceManager::PanicServer(TWsfServPanic aPanic)
       
   891     {
       
   892     User::Panic(KSenServiceManagerPanic, aPanic);
       
   893     }
       
   894 
       
   895 // @param aCommand is the 2nd argument given to RProcess::Create() method by the invoking client
       
   896 TInt CSenCoreServiceManager::ThreadFunction(TAny* /* aCommand */)
       
   897     {
       
   898 #ifdef _SENDEBUG
       
   899 #ifdef _DEBUG
       
   900 #ifndef _RD_SEN_DO_NOT_USE_UHEAP_MARKING
       
   901     __UHEAP_MARK;
       
   902 #endif // _RD_SEN_DO_NOT_USE_UHEAP_MARKING   
       
   903 #endif // _DEBUG
       
   904 #endif // _SENDEBUG
       
   905 
       
   906     CTrapCleanup* pCleanupStack = CTrapCleanup::New();
       
   907     if ( pCleanupStack == NULL )
       
   908         {
       
   909         PanicServer(ECreateTrapCleanup);
       
   910         }
       
   911 
       
   912     TRAPD( err, ThreadFunctionL(); )
       
   913     if (err != KErrNone)
       
   914         {
       
   915         PanicServer( ESrvCreateServer );
       
   916         }
       
   917 
       
   918     delete pCleanupStack;
       
   919     pCleanupStack = NULL;
       
   920     REComSession::FinalClose();
       
   921 #ifdef _SENDEBUG
       
   922 #ifdef _DEBUG
       
   923 #ifndef _RD_SEN_DO_NOT_USE_UHEAP_MARKING
       
   924     __UHEAP_MARKEND; // check memory leaks
       
   925 #endif // _RD_SEN_DO_NOT_USE_UHEAP_MARKING   
       
   926 #endif // _DEBUG
       
   927 #endif // _SENDEBUG
       
   928 
       
   929     return KErrNone;
       
   930     }
       
   931 
       
   932 
       
   933 // We come here, if CSenClientSessions's ServiceL has leaved:
       
   934 TInt CSenCoreServiceManager::RunError(TInt aError)
       
   935     {
       
   936     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("CSenCoreServiceManager::RunError( %d )"),aError));
       
   937     if (aError == KErrBadDescriptor)
       
   938         {
       
   939         // A bad descriptor error implies a badly programmed client,
       
   940         // so panic it..
       
   941         PanicClient(Message(), EBadDescriptor);
       
   942         }
       
   943     else
       
   944         {
       
   945         // .. otherwise report the error to the client
       
   946         Message().Complete(aError);
       
   947         }
       
   948 
       
   949     // The leave will result in an early return from CServer::RunL(), skipping
       
   950     // the call to request another message. So do that now in order to keep the
       
   951     // server running.
       
   952     ReStart();
       
   953 
       
   954     return KErrNone;    // handled the error fully
       
   955     }
       
   956 
       
   957 
       
   958 
       
   959 // Base64 encode/decode
       
   960 HBufC8* CSenCoreServiceManager::EncodeToBase64LC(const TDesC8& aSource)
       
   961     {
       
   962     HBufC8* pResult8 =
       
   963             HBufC8::NewLC(aSource.Length() * KBase64EncodeMultiplier);
       
   964     TPtr8 result8 = pResult8->Des();
       
   965     Base64Codec().Encode(aSource, result8);
       
   966     return pResult8;
       
   967     }
       
   968 
       
   969 HBufC8* CSenCoreServiceManager::DecodeFromBase64LC(const TDesC8& aSource)
       
   970     {
       
   971     HBufC8* pResult8 =
       
   972             HBufC8::NewLC(aSource.Length() * KBase64DecodeMultiplier);
       
   973     TPtr8 result8 = pResult8->Des();
       
   974     Base64Codec().Decode(aSource, result8);
       
   975     return pResult8;
       
   976     }
       
   977 
       
   978 // private getter, which always initializes the base64codec
       
   979 TImCodecB64& CSenCoreServiceManager::Base64Codec()
       
   980     {
       
   981     iBase64Codec.Initialise();
       
   982     return iBase64Codec;
       
   983     }
       
   984 
       
   985 TPtrC8 CSenCoreServiceManager::SenSecurityMechanismNames8L()
       
   986     {
       
   987     return iIdentityManager->SenSecurityMechanismNames8L();
       
   988     }
       
   989 
       
   990 CSenSecurityMechanism* CSenCoreServiceManager::MechanismNamedL(
       
   991                                                         const TDesC8& aName)
       
   992     {
       
   993     return iIdentityManager->MechanismNamedL(aName);
       
   994     }
       
   995 
       
   996 void CSenCoreServiceManager::SetShowPasswordDialog(const TBool aState)
       
   997     {
       
   998     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::SetShowPasswordDialog");
       
   999     iIdentityManager->SetShowPasswordDialog(aState);
       
  1000     }
       
  1001 
       
  1002 TInt CSenCoreServiceManager::ContainsServiceDescriptionL(TBool& aContains,
       
  1003                                                          CSenWSDescription& aPattern)
       
  1004     {
       
  1005     return iDAO->ContainsServiceDescriptionL(aContains, aPattern);
       
  1006     }
       
  1007 
       
  1008 TInt CSenCoreServiceManager::ContainsIdentityProviderL(TBool& aContains,
       
  1009                                                     CSenIdentityProvider& aIDP)
       
  1010     {
       
  1011     return iIdentityManager->ContainsIdentityProviderL(aContains, aIDP);
       
  1012     }
       
  1013 
       
  1014 
       
  1015 TInt CSenCoreServiceManager::SizeOfServiceDescriptionsL(RWSDescriptionArray& aArray)
       
  1016     {
       
  1017     TInt size(0);
       
  1018 
       
  1019     TInt count = aArray.Count();
       
  1020     CBufFlat* pBuf = NULL;
       
  1021     for(TInt i = 0; i < count; i++)
       
  1022         {
       
  1023         pBuf = CBufFlat::NewL(KFlatBufSize);
       
  1024         CleanupStack::PushL(pBuf);
       
  1025         RBufWriteStream bufWs(*pBuf);
       
  1026         CleanupClosePushL(bufWs);
       
  1027 
       
  1028         aArray[i]->WriteAsXMLToL(bufWs);
       
  1029         TPtr8 p8 = pBuf->Ptr(0);
       
  1030         size += p8.Length();
       
  1031         CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  1032         pBuf = NULL;
       
  1033         }
       
  1034     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("CSenCoreServiceManager::SizeOfServiceDescriptionsL: %d"),size));
       
  1035 
       
  1036 
       
  1037     return size;
       
  1038     }
       
  1039 TInt CSenCoreServiceManager::SizeOfIdentityProvidersL(const RPointerArray<CSenIdentityProvider>& aArray)
       
  1040     {
       
  1041     TInt size(0);
       
  1042 
       
  1043     TInt count = aArray.Count();
       
  1044     CBufFlat* pBuf = NULL;
       
  1045     for(TInt i = 0; i < count; i++)
       
  1046         {
       
  1047         pBuf = CBufFlat::NewL(KFlatBufSize);
       
  1048         CleanupStack::PushL(pBuf);
       
  1049         RBufWriteStream bufWs(*pBuf);
       
  1050         CleanupClosePushL(bufWs);
       
  1051 
       
  1052         aArray[i]->WriteAsXMLToL(bufWs);
       
  1053         TPtr8 p8 = pBuf->Ptr(0);
       
  1054         size += p8.Length();
       
  1055         CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  1056         pBuf = NULL;
       
  1057         }
       
  1058     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("CSenCoreServiceManager::SizeOfIdentityProvidersL: %d"),size));
       
  1059 
       
  1060     return size;
       
  1061     }
       
  1062 
       
  1063 TInt CSenCoreServiceManager::SizeOfCredentialsL(RSenCredentialArray& aArray)
       
  1064     {
       
  1065     _LIT8(KNoProperties, "-");
       
  1066     TInt size(0);
       
  1067 
       
  1068     TInt count = aArray.Count();
       
  1069     CBufFlat* pBuf = NULL;
       
  1070     for(TInt i = 0; i < count; i++)
       
  1071         {
       
  1072         pBuf = CBufFlat::NewL(KFlatBufSize);
       
  1073         CleanupStack::PushL(pBuf);
       
  1074         RBufWriteStream bufWs(*pBuf);
       
  1075         CleanupClosePushL(bufWs);
       
  1076 
       
  1077         aArray[i]->WriteAsXMLToL(bufWs);
       
  1078         if ( aArray[i]->HasProperties() )
       
  1079             {
       
  1080             aArray[i]->PropertiesL().WriteAsXMLToL(bufWs);	//codescannerwarnings            
       
  1081             }
       
  1082         else
       
  1083             {
       
  1084             bufWs.WriteL(KNoProperties);
       
  1085             }
       
  1086 
       
  1087         TPtr8 p8 = pBuf->Ptr(0);
       
  1088         size += p8.Length();
       
  1089         
       
  1090         CleanupStack::PopAndDestroy(2); // bufWs (close), pBuf
       
  1091         pBuf = NULL;
       
  1092         }
       
  1093     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("CSenCoreServiceManager::SizeOfCredentialsL: %d"),size));
       
  1094 
       
  1095 
       
  1096     return size;
       
  1097     }
       
  1098 
       
  1099 CSenTransportBase* CSenCoreServiceManager::CreateL( CSenWSDescription& aInitializer,
       
  1100                                                     CSenServiceSession* apSession)
       
  1101     {
       
  1102     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::CreateL:");
       
  1103     TInt leaveCode(KErrNone);
       
  1104 
       
  1105     CSenTransportBase* pTransport = NULL;
       
  1106 
       
  1107     TPtrC8 transportCue = aInitializer.TransportCue();
       
  1108     if( apSession && (apSession->TransportCue().Length()>0) )
       
  1109         {
       
  1110         transportCue.Set( apSession->TransportCue() );
       
  1111         } 
       
  1112 
       
  1113     TPtrC8 uriScheme;
       
  1114     if( transportCue.Length() == 0 )
       
  1115         {
       
  1116         // Next, attempt resolve the <scheme> from the endpoint
       
  1117 
       
  1118         TPtrC8 uri = aInitializer.Endpoint();
       
  1119         if(uri.Length()>0)
       
  1120             {
       
  1121             TInt index = uri.Locate(':');
       
  1122             if(index!=KErrNotFound)
       
  1123                 {
       
  1124                 uriScheme.Set( uri.Left(index) );
       
  1125                 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("- URI scheme is: '%S'"),&uriScheme));
       
  1126                 transportCue.Set(iDAO->TransportPluginCueBySchemeL(uriScheme));
       
  1127                 }
       
  1128             }
       
  1129         }
       
  1130         
       
  1131 /*
       
  1132     TBool isVtcp(EFalse);
       
  1133     if ( transportCue == KSenTransportCueVirtualTCP || uriScheme == KSenTransportSchemeTCP )
       
  1134         {
       
  1135         isVtcp = ETrue;
       
  1136         if ( ipVtcpTransport )
       
  1137             {
       
  1138             if( ipVtcpEndpoint && *ipVtcpEndpoint == aInitializer.Endpoint() )
       
  1139                 {
       
  1140                 return ipVtcpTransport;
       
  1141                 }
       
  1142             else
       
  1143                 {
       
  1144 //                delete ipVtcpTransport; // not owned!
       
  1145                 ipVtcpTransport = NULL;
       
  1146                 delete ipVtcpEndpoint;
       
  1147                 ipVtcpEndpoint = NULL;
       
  1148                 //ipVtcpEndpoint = aInitializer.Endpoint().AllocL();
       
  1149                 }
       
  1150             }
       
  1151 //        else { // we are creating a new transport instance }        
       
  1152         }
       
  1153 */    
       
  1154     
       
  1155     // TEST
       
  1156     CSenTransportContext* pCtx = NULL;
       
  1157     if(apSession)
       
  1158         {
       
  1159         pCtx = CSenTransportContext::NewLC( *this, aInitializer, *apSession );
       
  1160         }
       
  1161     else
       
  1162         {
       
  1163         pCtx = CSenTransportContext::NewLC( *this, aInitializer );
       
  1164         }
       
  1165         
       
  1166     if( transportCue.Length() > 0 )
       
  1167         {
       
  1168         // Utilize the cue:
       
  1169        if ( transportCue == KSenTransportCueVirtualTCP || uriScheme == KSenTransportSchemeTCP )       
       
  1170             {
       
  1171             if ( !ipVtcpTransport )
       
  1172                 {
       
  1173                 TLSLOG_FORMAT(( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, _L8("- About to instantiate new vTCP transport (args: cue: '%S', ctx)"), &transportCue ));
       
  1174                 TRAP( leaveCode, ipVtcpTransport = CSenTransport::NewL( transportCue, pCtx ); )
       
  1175                 if( leaveCode )
       
  1176                     {
       
  1177                     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("- Could not load vTCP transport plugin, leave: %d"),leaveCode));
       
  1178 				     CleanupStack::Pop(pCtx);					
       
  1179                     User::Leave( leaveCode ); // throw forward
       
  1180                     }
       
  1181                 CleanupStack::Pop(pCtx); // ownership is NOW safely transferred to newly created transport plug-in
       
  1182                 }
       
  1183             else
       
  1184                 {
       
  1185                 CleanupStack::PopAndDestroy(pCtx); 
       
  1186                 }
       
  1187             pTransport = ipVtcpTransport;
       
  1188             }
       
  1189         else
       
  1190             {
       
  1191             TLSLOG_FORMAT(( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, _L8("- About to instantiate new transport (args: cue: '%S', ctx)"), &transportCue ));
       
  1192             TRAP( leaveCode, pTransport = CSenTransport::NewL(transportCue, pCtx); )
       
  1193             if( leaveCode )
       
  1194                 {
       
  1195                 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("- Could not load new transport plugin, leave: %d"),leaveCode));
       
  1196 				CleanupStack::Pop(pCtx);				
       
  1197                 User::Leave( leaveCode ); // throw forward
       
  1198                 }
       
  1199             CleanupStack::Pop(pCtx); // ownership is NOW safely transferred to newly created transport plug-in
       
  1200             
       
  1201             }
       
  1202         }
       
  1203     else
       
  1204         {
       
  1205         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- About to instantiate new transport (arg: ctx)");
       
  1206         // default to HTTP Channel transport plug-in:
       
  1207         TRAP( leaveCode, pTransport = CSenTransport::NewL(pCtx); )
       
  1208         if( leaveCode )
       
  1209             {
       
  1210             TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("- Could not load new transport plugin, leave: %d"),leaveCode));
       
  1211 			CleanupStack::Pop(pCtx);
       
  1212             User::Leave( leaveCode ); // throw forward
       
  1213             }
       
  1214         CleanupStack::Pop(pCtx); // ownership is NOW safely transferred to newly created transport plug-in
       
  1215         }
       
  1216 
       
  1217     CleanupStack::PushL(pTransport);
       
  1218 
       
  1219     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8(" aInitializer.DescriptionClassType() == %d "),aInitializer.DescriptionClassType() )); 
       
  1220 
       
  1221     if( aInitializer.DescriptionClassType() == MSenServiceDescription::EWSDescription )
       
  1222         {
       
  1223         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"Class type is: MSenServiceDescription::EWSDescription.");
       
  1224         TUint32 desiredIapId(0);
       
  1225         TInt retVal = aInitializer.IapId(desiredIapId);
       
  1226         if(retVal==KErrNone)
       
  1227             {
       
  1228             CSenTransportProperties* pProperties = CSenTransportProperties::NewLC();
       
  1229             pProperties->SetIapIdL(desiredIapId);
       
  1230             HBufC8* pPropertiesAsXml = pProperties->AsUtf8LC();
       
  1231             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"- Consumer Policy -layer's Transport Properties as XML:");
       
  1232             TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(*pPropertiesAsXml));
       
  1233             pTransport->SetPropertiesL(*pPropertiesAsXml, MSenLayeredProperties::ESenProviderSessionLayer, NULL);
       
  1234             CleanupStack::PopAndDestroy(pPropertiesAsXml);
       
  1235             CleanupStack::PopAndDestroy(pProperties);
       
  1236             }
       
  1237         }
       
  1238     else if( aInitializer.DescriptionClassType() == MSenServiceDescription::EWSPattern )
       
  1239         {
       
  1240         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"Class type is: MSenServiceDescription::EWSPattern.");
       
  1241         CSenWSPattern* pConsumerPolicy = (CSenWSPattern*)&aInitializer;
       
  1242 
       
  1243         TUint32 desiredIapId(0);
       
  1244         TInt retVal = pConsumerPolicy->ConsumerIapId(desiredIapId);
       
  1245         if(retVal==KErrNone)
       
  1246             {
       
  1247             CSenTransportProperties* pProperties = CSenTransportProperties::NewLC();
       
  1248             pProperties->SetIapIdL(desiredIapId);
       
  1249             HBufC8* pPropertiesAsXml = pProperties->AsUtf8LC();
       
  1250             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Consumer Policy -layer's Transport Properties as XML:");
       
  1251             TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(*pPropertiesAsXml));
       
  1252             pTransport->SetPropertiesL(*pPropertiesAsXml, MSenLayeredProperties::ESenConsumerSessionLayer, NULL);
       
  1253             CleanupStack::PopAndDestroy(pPropertiesAsXml);
       
  1254             CleanupStack::PopAndDestroy(pProperties);
       
  1255             }
       
  1256         retVal = aInitializer.IapId(desiredIapId);
       
  1257         if(retVal==KErrNone)
       
  1258             {
       
  1259             CSenTransportProperties* pProperties = CSenTransportProperties::NewLC();
       
  1260             pProperties->SetIapIdL(desiredIapId);
       
  1261             HBufC8* pPropertiesAsXml = pProperties->AsUtf8LC();
       
  1262             TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"- Provider Policy -layer's Transport Properties as XML:");
       
  1263             TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(*pPropertiesAsXml));
       
  1264             pTransport->SetPropertiesL(*pPropertiesAsXml, MSenLayeredProperties::ESenProviderSessionLayer, NULL);
       
  1265             CleanupStack::PopAndDestroy(pPropertiesAsXml);
       
  1266             CleanupStack::PopAndDestroy(pProperties);
       
  1267             }
       
  1268         }
       
  1269 #ifdef _SENDEBUG
       
  1270     else
       
  1271         {
       
  1272         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"- Initializer SD's type is unknown!");
       
  1273         }
       
  1274 #endif // _SENDEBUG     
       
  1275 
       
  1276     // Check if Serene-wide proxy settings have been defined:
       
  1277     const TDesC8& proxyHost = iDAO->ProxyHost();
       
  1278     const TInt proxyPort = iDAO->ProxyPort();
       
  1279 
       
  1280     if ( proxyHost.Length() > 0 || proxyPort > 0 )
       
  1281         {
       
  1282         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"- Using proxy settings to get HTTP transport, but without policy info.");
       
  1283 
       
  1284         CSenTransportProperties* pProperties = CSenTransportProperties::NewLC();
       
  1285         pProperties->SetProxyHostL(proxyHost);
       
  1286         pProperties->SetProxyPortL(proxyPort);
       
  1287         HBufC8* pPropertiesAsXml = pProperties->AsUtf8LC();
       
  1288         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"- Serene-wide -layer's Transport Properties as XML:");
       
  1289         TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(*pPropertiesAsXml));
       
  1290         pTransport->SetPropertiesL(*pPropertiesAsXml, MSenLayeredProperties::ESenConsumerSessionLayer, NULL);
       
  1291         CleanupStack::PopAndDestroy(pPropertiesAsXml);
       
  1292         CleanupStack::PopAndDestroy(pProperties);
       
  1293         }
       
  1294 
       
  1295     // Set framework specific transport properties
       
  1296 
       
  1297     TPtrC8 frameworkID(aInitializer.FrameworkId());
       
  1298     if ( frameworkID.Length()== 0 && apSession)
       
  1299         {
       
  1300         frameworkID.Set(apSession->FrameworkId());
       
  1301         }
       
  1302     if ( frameworkID.Length() > 0 )
       
  1303         {
       
  1304         MSIF* pFramework = Framework(frameworkID);
       
  1305         if ( pFramework )
       
  1306             {
       
  1307             TInt setRetVal = pFramework->SetTransportPropertiesL(*pTransport);
       
  1308             TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("- pFramework->SetTransportPropertiesL returned: %d"), setRetVal )); 
       
  1309             }
       
  1310         }
       
  1311 #ifdef _SENDEBUG   
       
  1312     else
       
  1313         {     
       
  1314         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel," - Initializer SD's Framework ID is zero-length!");    
       
  1315         }
       
  1316 #endif // _SENDEBUG
       
  1317 #ifdef _SENDEBUG
       
  1318     HBufC8* pEffectiveProperties = NULL;
       
  1319     TInt effRetVal = pTransport->PropertiesL(pEffectiveProperties);
       
  1320     CleanupStack::PushL(pEffectiveProperties);
       
  1321     if( effRetVal == KErrNone && pEffectiveProperties )
       
  1322         {
       
  1323         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"- Effective Transport Properties (flattened) as XML:");    
       
  1324         TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,(*pEffectiveProperties));
       
  1325         }
       
  1326     CleanupStack::PopAndDestroy(pEffectiveProperties);
       
  1327 #endif // _SENDEBUG
       
  1328 
       
  1329     CleanupStack::Pop(pTransport);
       
  1330 /*    
       
  1331     if( isVtcp )
       
  1332         {
       
  1333         ipVtcpTransport = pTransport;
       
  1334         ipVtcpEndpoint = aInitializer.Endpoint().AllocL();
       
  1335         }
       
  1336 */
       
  1337     return pTransport;
       
  1338     }
       
  1339 
       
  1340 MSenProvider& CSenCoreServiceManager::LookupHostletForL(const TDesC8& aHostletEndpoint,
       
  1341                                                          const TDesC& aReqThreadId,
       
  1342                                                          const TDesC8& aReqConsumerId)
       
  1343     {
       
  1344     // LookupHostletForL() method needs to be wrapped inside critical section
       
  1345     // NOTE: do *NOT* file log before this line(!):
       
  1346     iDAO->iCriticalSection.Wait(); // will pass through only one thread at the time
       
  1347     MSenProvider& provider = iDAO->LookupHostletForL(aHostletEndpoint, aReqThreadId, aReqConsumerId);
       
  1348     iDAO->iCriticalSection.Signal(); // allow next, pending thread to proceed, if such exists
       
  1349     return provider;
       
  1350     }
       
  1351 
       
  1352 TInt CSenCoreServiceManager::ReleaseHostletL(const MSenProvider* aHostlet,
       
  1353                                              const TDesC& aReqThreadId,
       
  1354                                              const TDesC8& aReqConsumerId)
       
  1355     {
       
  1356     // LookupHostletForL() method needs to be wrapped inside critical section
       
  1357     // NOTE: do *NOT* file log before this line(!):
       
  1358     iDAO->iCriticalSection.Wait(); // will pass through only one thread at the time
       
  1359     TInt retVal = iDAO->ReleaseHostletL(aHostlet, aReqThreadId, aReqConsumerId);
       
  1360     iDAO->iCriticalSection.Signal(); // allow next, pending thread to proceed, if such exists
       
  1361     return retVal;
       
  1362     }
       
  1363 
       
  1364 RStringPool& CSenCoreServiceManager::StringPool()
       
  1365     {
       
  1366     return iStringPool;
       
  1367     }
       
  1368 
       
  1369 // Helper
       
  1370 /*
       
  1371 RPointerArray<HBufC8>& CSenCoreServiceManager::ActiveHostletEndpointsL()
       
  1372     {
       
  1373     if(!ipActiveHostletEndpoints)
       
  1374         {
       
  1375         ipActiveHostletEndpoints = new (ELeave) RPointerArray<HBufC8>;
       
  1376         }
       
  1377     return *ipActiveHostletEndpoints;
       
  1378     }
       
  1379 
       
  1380 
       
  1381 TInt CSenCoreServiceManager::AddActiveHostletConnectionEndpointL(const TDesC8& aEndpoint)
       
  1382     {
       
  1383     LOG_WRITEFORMAT((_L8("CSenCoreServiceManager::AddActiveHostletConnectionEndpointL(%S)"), &aEndpoint));
       
  1384     RPointerArray<HBufC8>& active = ActiveHostletEndpointsL();
       
  1385     TInt count(active.Count());
       
  1386     for(TInt i=0; i<count; i++)
       
  1387         {
       
  1388         HBufC8* pEndpoint = active[i];
       
  1389         if(pEndpoint && *pEndpoint == aEndpoint)
       
  1390             {
       
  1391             LOG_WRITE_L("- Endpoint already reserved.");
       
  1392             return KErrSenEndpointReserved; // from SenHostletConnection.h
       
  1393             }
       
  1394         }
       
  1395 
       
  1396     User::LeaveIfError(active.Append(aEndpoint.AllocL()));
       
  1397     return KErrNone;
       
  1398     }
       
  1399 
       
  1400 TInt CSenCoreServiceManager::RemoveActiveHostletConnectionEndpoint(const TDesC8& aEndpoint)
       
  1401     {
       
  1402     LOG_WRITEFORMAT((_L8("CSenCoreServiceManager::RemoveActiveHostletConnectionEndpoint(%S):"), &aEndpoint));
       
  1403     TInt retVal(KErrNotFound);
       
  1404     RPointerArray<HBufC8>& active = ActiveHostletEndpointsL();
       
  1405     TInt count(active.Count());
       
  1406     TInt i = 0;
       
  1407     for(; i<count; i++)
       
  1408         {
       
  1409         HBufC8* pEndpoint = active[i];
       
  1410         if(pEndpoint && *pEndpoint == aEndpoint)
       
  1411             {
       
  1412             LOG_WRITEFORMAT((_L8("- Match (%d) in the list of active endpoints found!"), i));
       
  1413             break; // match
       
  1414             }
       
  1415         }
       
  1416     if(i<count)
       
  1417         {
       
  1418         // match occured, remove the endpoint
       
  1419         LOG_WRITEFORMAT((_L8("- Removing (%d) the endpoint now."), i));
       
  1420         active.Remove(i);
       
  1421         retVal = KErrNone;
       
  1422         }
       
  1423     return retVal;
       
  1424     }
       
  1425 */
       
  1426 
       
  1427 TInt CSenCoreServiceManager::NextTransactionId()
       
  1428     {
       
  1429     iNextTransactionId++;
       
  1430     return iNextTransactionId;
       
  1431     }
       
  1432 
       
  1433 TInt CSenCoreServiceManager::SaveCredentialDB()
       
  1434     {
       
  1435     return iCredentialManager->SaveCredentialDB();
       
  1436     }
       
  1437 
       
  1438 TInt CSenCoreServiceManager::CredentialsL(const CSenWSDescription& aPattern,
       
  1439 								          RSenCredentialArray& aCredentials)
       
  1440     {
       
  1441     return iCredentialManager->CredentialsL(aPattern, aCredentials);
       
  1442     }
       
  1443 
       
  1444 TInt CSenCoreServiceManager::CredentialsL(const CSenWSDescription& aPattern,
       
  1445 					                      const CSenIdentityProvider& aIdP,
       
  1446 								          RSenCredentialArray& aCredentials)
       
  1447     {
       
  1448     return iCredentialManager->CredentialsL(aPattern, aIdP, aCredentials);
       
  1449     }
       
  1450 
       
  1451 TInt CSenCoreServiceManager::CredentialsL(const CSenWSDescription& aPattern,
       
  1452 								          RSenCredentialPtrArray& aCredentials)
       
  1453     {
       
  1454     return iCredentialManager->CredentialsL(aPattern, aCredentials);
       
  1455     }
       
  1456 
       
  1457 TInt CSenCoreServiceManager::CredentialsL(const CSenWSDescription& aPattern,
       
  1458 					                      const CSenIdentityProvider& aIdP,
       
  1459 								          RSenCredentialPtrArray& aCredentials)
       
  1460     {
       
  1461     return iCredentialManager->CredentialsL(aPattern, aIdP, aCredentials);
       
  1462     }
       
  1463 
       
  1464 RSenCredentialPtr CSenCoreServiceManager::AddCredentialL(CSenInternalCredential* apCredential,
       
  1465                                                           TInt& aErrorTo)
       
  1466     {
       
  1467     return iCredentialManager->AddCredentialL(apCredential, aErrorTo);
       
  1468     }
       
  1469 
       
  1470 RSenCredentialPtr CSenCoreServiceManager::AddCredentialL(CSenIdentityProvider* apIdP,
       
  1471                                                          CSenInternalCredential* apCredential,
       
  1472                                                          TInt& aErrorTo)
       
  1473     {
       
  1474     return iCredentialManager->AddCredentialL(apIdP, apCredential, aErrorTo);
       
  1475     }
       
  1476 
       
  1477 RSenCredentialPtr CSenCoreServiceManager::AddCredentialL(const TDesC8& aCredential,
       
  1478                                                          TInt& aErrorTo)
       
  1479     {
       
  1480     return iCredentialManager->AddCredentialL(aCredential, aErrorTo);
       
  1481     }
       
  1482 
       
  1483 RSenCredentialPtr CSenCoreServiceManager::AddCredentialL(CSenIdentityProvider* apIdP,
       
  1484 	        								              const TDesC8& aCredential,
       
  1485 			        						              TInt& aErrorTo)
       
  1486     {
       
  1487     return iCredentialManager->AddCredentialL(apIdP, aCredential, aErrorTo);
       
  1488     }
       
  1489 
       
  1490 TInt CSenCoreServiceManager::RemoveCredentialsL(const CSenWSDescription& aPattern)
       
  1491     {
       
  1492     return iCredentialManager->RemoveCredentialsL(aPattern);
       
  1493     }
       
  1494 
       
  1495 TInt CSenCoreServiceManager::RemoveCredentialsL(const CSenWSDescription& aPattern,
       
  1496 						                        const CSenIdentityProvider& aIdP)
       
  1497     {
       
  1498     return iCredentialManager->RemoveCredentialsL(aPattern, aIdP);
       
  1499     }
       
  1500 
       
  1501 TInt CSenCoreServiceManager::RemoveCredentialsL(const TDesC8& aProviderId)
       
  1502     {
       
  1503     return iCredentialManager->RemoveCredentialsL(aProviderId);
       
  1504     }
       
  1505 
       
  1506 TInt CSenCoreServiceManager::RemoveCredentialL(TInt aInternalCredentialId)	//codescannerwarnings
       
  1507     {
       
  1508     return iCredentialManager->RemoveCredentialL(aInternalCredentialId);	//codescannerwarnings
       
  1509     }
       
  1510 
       
  1511 RSenCredentialPtr CSenCoreServiceManager::CredentialL(TInt aInternalCredentialId,
       
  1512                                                       TInt& aErrorTo)
       
  1513     {
       
  1514     return iCredentialManager->CredentialL(aInternalCredentialId, aErrorTo);
       
  1515     }
       
  1516 
       
  1517 RSenCredentialPtr CSenCoreServiceManager::UpdateCredentialL(TInt aInternalCredentialId,
       
  1518                                                      CSenInternalCredential* apCredential,
       
  1519                                                      TInt& aErrorTo)
       
  1520     {
       
  1521     return iCredentialManager->UpdateCredentialL(aInternalCredentialId,
       
  1522                                                  apCredential,
       
  1523                                                  aErrorTo);
       
  1524     }
       
  1525 
       
  1526 RSenCredentialPtr CSenCoreServiceManager::UpdateCredentialL(TInt aInternalCredentialId,
       
  1527                                                             const TDesC8& aCredential,
       
  1528                                                             TInt& aErrorTo)
       
  1529     {
       
  1530     return iCredentialManager->UpdateCredentialL(aInternalCredentialId,
       
  1531                                                  aCredential,
       
  1532                                                  aErrorTo);
       
  1533     }
       
  1534 
       
  1535 TInt CSenCoreServiceManager::FindMatchingIdentityProviderL(CSenIdentityProvider &aIdP,
       
  1536                                                            CSenIdentityProvider*& apMatch)
       
  1537     {
       
  1538     return iIdentityManager->FindMatchingIdentityProviderL(aIdP, apMatch);
       
  1539     }
       
  1540 
       
  1541 TInt CSenCoreServiceManager::UpdateIdentityProviderL(CSenIdentityProvider& aIdp)
       
  1542     {
       
  1543     return iIdentityManager->UpdateIdentityProviderL(aIdp);
       
  1544     }
       
  1545 
       
  1546 TInt CSenCoreServiceManager::NextConnectionID()
       
  1547     {
       
  1548     return iConnectionID++;
       
  1549     }
       
  1550 void CSenCoreServiceManager::UpdateTouchL(CSenServiceSession* aSession)
       
  1551 	{
       
  1552 	MSenServiceDescription& sd = aSession->AsServiceDescription();
       
  1553 	
       
  1554 	iIdentityManager->UpdateTouchIdentityDBL(sd);
       
  1555 	iCredentialManager->UpdateTouchCredDBL(sd);
       
  1556 	iDAO->UpdateTouchSessionDBL(sd);
       
  1557 
       
  1558 	}
       
  1559 TPtrC8 CSenCoreServiceManager::IMSI()
       
  1560     {
       
  1561     return iIMSI;    
       
  1562     }
       
  1563 /*
       
  1564 void CSenCoreServiceManager::GetIMSIL()
       
  1565     {
       
  1566     TBuf<15> phoneImsi;
       
  1567     
       
  1568     RTelServer server;
       
  1569     User::LeaveIfError( server.Connect() );
       
  1570     CleanupClosePushL( server );
       
  1571 
       
  1572     RMobilePhone phone;
       
  1573     User::LeaveIfError( server.LoadPhoneModule( KMmTsyModuleName ) );
       
  1574     User::LeaveIfError( phone.Open( server, KMmTsyPhoneName ) );
       
  1575     CleanupClosePushL( phone );
       
  1576     User::LeaveIfError( phone.Initialise() );
       
  1577 
       
  1578     TRequestStatus status;    
       
  1579     phone.GetSubscriberId( status, phoneImsi );
       
  1580     User::WaitForRequest( status );
       
  1581     //User::LeaveIfError( status.Int() );
       
  1582     
       
  1583     iIMSI.Copy(phoneImsi);
       
  1584     
       
  1585     status = KErrNone;
       
  1586 
       
  1587     CleanupStack::PopAndDestroy( 2 ); // phone, server
       
  1588     }
       
  1589 */    
       
  1590 TPtrC8 CSenCoreServiceManager::IMEI()
       
  1591 	{
       
  1592     return iIMEI;		
       
  1593 	}
       
  1594 		
       
  1595 void CSenCoreServiceManager::GetImsiImeiL()
       
  1596     {
       
  1597 	CREDLOG_L(KSenCredsLogLevelMin,    "GetImsiImeiL Entered");    	
       
  1598     TBuf<15> phoneImsi;
       
  1599     TBuf<RMobilePhone::KPhoneSerialNumberSize> phoneImei;
       
  1600     RMobilePhone::TMobilePhoneIdentityV1 phoneIdV1;
       
  1601         
       
  1602     RTelServer server;
       
  1603     User::LeaveIfError( server.Connect() );
       
  1604     CleanupClosePushL( server );
       
  1605 
       
  1606     RMobilePhone phone;
       
  1607     User::LeaveIfError( server.LoadPhoneModule( KMmTsyModuleName ) );
       
  1608     User::LeaveIfError( phone.Open( server, KMmTsyPhoneName ) );
       
  1609     CleanupClosePushL( phone );
       
  1610     User::LeaveIfError( phone.Initialise() );
       
  1611 
       
  1612 	CREDLOG_L(KSenCredsLogLevelMin,    "GetImsiImeiL RMobilePhone Initialized");
       
  1613 
       
  1614     TRequestStatus status;
       
  1615     phone.GetSubscriberId( status, phoneImsi );    
       
  1616     User::WaitForRequest( status );
       
  1617 	status = KErrNone;
       
  1618 	CREDLOG_L(KSenCredsLogLevelMin,    "GetImsiImeiL GetSubscriberId Completed");		
       
  1619 		
       
  1620     phone.GetPhoneId( status, phoneIdV1 );
       
  1621     phoneImei = phoneIdV1.iSerialNumber;
       
  1622     User::WaitForRequest( status ); 
       
  1623 	status = KErrNone;          
       
  1624     //User::LeaveIfError( status.Int() );
       
  1625 	CREDLOG_L(KSenCredsLogLevelMin,    "GetImsiImeiL phoneIdV1 Completed");    
       
  1626     
       
  1627     iIMSI.Copy(phoneImsi);    
       
  1628     iIMEI.Copy(phoneImei);
       
  1629     
       
  1630     status = KErrNone;
       
  1631 
       
  1632     CleanupStack::PopAndDestroy( 2 ); // phone, server
       
  1633     }
       
  1634 //END OF FILE