webservices/wsoviplugin/src/wsoviplugin.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    29 #include "wsoviplugin.h"
       
    30 #include "SenServiceConnection.h" // framework IDs, error codes
       
    31 #include "sendebug.h"
       
    32 #include "senlogger.h"
       
    33 #include "MSenServiceDescription.h"
       
    34 #include "wsoviservicesession.h"
       
    35 #include "SenXmlUtils.h"
       
    36 #include "senguidgen.h"
       
    37 #include "wsovitokencreationresponse.h"
       
    38 #include <SenHttpTransportProperties.h>
       
    39 #include "sencryptoutils.h"
       
    40 #include "wsoviserviceupdatehandler.h"
       
    41 #include "wsovivalidatehandler.h"
       
    42 using namespace WSOviConfig;
       
    43 using namespace OAuth;
       
    44 // Local CONSTANTS
       
    45 const TInt KMaxLengthXml  = 1280; 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Create instance of concrete ECOM interface implementation
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CWSOviPlugin* CWSOviPlugin::NewL(TAny* aManager)
       
    52     {
       
    53     MSenCoreServiceManager* manager =
       
    54         reinterpret_cast<MSenCoreServiceManager*>(aManager);
       
    55 
       
    56     CWSOviPlugin* self = new (ELeave) CWSOviPlugin(*manager);
       
    57     CleanupStack::PushL (self);
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop(self);
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Constructor
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CWSOviPlugin::CWSOviPlugin(MSenCoreServiceManager& aManager)
       
    68     : iManager(aManager),
       
    69       iVersions(ETrue, ETrue)
       
    70     {
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Destructor
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CWSOviPlugin::~CWSOviPlugin()
       
    78     {
       
    79     iMsgHandlers.ResetAndDestroy();
       
    80     iSessionHandlers.ResetAndDestroy();
       
    81     iHandlerContexts.ResetAndDestroy();
       
    82     iVersions.Reset();
       
    83     iIMSI.Close();
       
    84     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::~CWSOviPlugin()")));
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Second phase construction.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CWSOviPlugin::ConstructL()
       
    92     {
       
    93     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ConstructL")));
       
    94 
       
    95     BaseConstructL(KFrameworkXMLNS, KFrameworkLocalName);
       
    96     //load default setup of handlers
       
    97     AddHandlerL(KValidateValue, KValidateHandlerVersion, SenHandler::ESessionHandler);
       
    98     AddHandlerL(KRegisterValue, KNullDesC8, SenHandler::ESessionHandler);
       
    99     
       
   100     AddHandlerL(KCredentialCollectorValue, KNullDesC8, SenHandler::EMessageHandler);
       
   101     AddHandlerL(KDeviceValue, KNullDesC8, SenHandler::EMessageHandler);
       
   102     AddHandlerL(KSecurityValue, KNullDesC8, SenHandler::EMessageHandler);
       
   103     AddHandlerL(KEncoderValue, KNullDesC8, SenHandler::EMessageHandler);
       
   104     AddHandlerL(KServiceUpdateValue, KNullDesC8, SenHandler::ESessionHandler);
       
   105     }
       
   106 
       
   107 //========================================================
       
   108 //                MSIF SPecific
       
   109 //========================================================
       
   110 
       
   111 //---------------------------------------------------------------------------
       
   112 // Attempt to register the ServiceDescription to the ServiceManager 
       
   113 //---------------------------------------------------------------------------
       
   114 //
       
   115 TInt CWSOviPlugin::RegisterServiceDescriptionL(
       
   116     MSenServiceDescription& aServiceDescription )
       
   117     {
       
   118     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::RegisterServiceDescriptionL(.)")));
       
   119     TInt error(KErrNone);
       
   120 
       
   121     CWSOviSessionContext* pSessionRegisterCtx = CWSOviSessionContext::NewLC();
       
   122     pSessionRegisterCtx->Add(WSOviContextKeys::KServiceDescription(),
       
   123             (CSenWSDescription*)&aServiceDescription);
       
   124     pSessionRegisterCtx->Add(WSOviContextKeys::KRegisterAction(),
       
   125             WSOviContextValues::KActionRegister());
       
   126 
       
   127 //SOA for S60 Composable Handler Framework v0.1 - 7.5.3.1 point 1)            
       
   128     CSenSessionHandler* pregisterHandler = 
       
   129                 (CSenSessionHandler*)Handler(KRegisterValue());
       
   130         
       
   131     TRAPD(errorL,error= pregisterHandler->InvokeL(*pSessionRegisterCtx));
       
   132     if (errorL!=KErrNone)
       
   133         {
       
   134         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::RegisterServiceDescriptionL() !!!!leave from RegisterHandler")));
       
   135         error = errorL;
       
   136         }
       
   137     CleanupStack::PopAndDestroy(pSessionRegisterCtx);
       
   138     return error;
       
   139     }
       
   140 
       
   141 //---------------------------------------------------------------------------
       
   142 // Attempt to unregister the ServiceDescription from the ServiceManager 
       
   143 //---------------------------------------------------------------------------
       
   144 //
       
   145 TInt CWSOviPlugin::UnregisterServiceDescriptionL(
       
   146     MSenServiceDescription& aServiceDescription)
       
   147     {
       
   148     
       
   149     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::UnRegisterServiceDescriptionL(.)")));
       
   150 //SOA for S60 Composable Handler Framework v0.1  - 7.5.3.1 point 1)            
       
   151     TInt error(KErrNone);
       
   152     CSenSessionHandler* pregisterHandler = 
       
   153                 (CSenSessionHandler*)Handler(KRegisterValue());
       
   154         
       
   155     CWSOviSessionContext* pSessionRegisterCtx = CWSOviSessionContext::NewLC();
       
   156     pSessionRegisterCtx->Add(WSOviContextKeys::KServiceDescription(),
       
   157             (CSenWSDescription*)&aServiceDescription);
       
   158     pSessionRegisterCtx->Add(WSOviContextKeys::KRegisterAction(),
       
   159             WSOviContextValues::KActionUnregister());
       
   160     TRAPD(errorL,error = pregisterHandler->InvokeL(*pSessionRegisterCtx));
       
   161     if (errorL!=KErrNone)
       
   162         {
       
   163         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::UnregisterServiceDescriptionL() !!!!leave from RegisterHandler")));
       
   164         error = errorL;
       
   165         }
       
   166     CleanupStack::PopAndDestroy(pSessionRegisterCtx);
       
   167     return error;
       
   168     }
       
   169 
       
   170 //---------------------------------------------------------------------------
       
   171 // Getter of framework ("WS-Ovi")
       
   172 //---------------------------------------------------------------------------
       
   173 //
       
   174 const TDesC8& CWSOviPlugin::Id()
       
   175     {
       
   176     return KDefaultOviFrameworkID();
       
   177     }
       
   178 
       
   179 //---------------------------------------------------------------------------
       
   180 // Try to find one or more services that match the given ServiceDescription.
       
   181 //    Adding is only invoked if NO! session in cache. 
       
   182 //    Its mean that we have create new one.
       
   183 //---------------------------------------------------------------------------
       
   184 //
       
   185 TInt CWSOviPlugin::AddServiceDescriptionL( MSenServiceDescription& aPattern,
       
   186                                             MSenRemoteServiceConsumer& aRemoteConsumer,
       
   187                                             HBufC8*& aErrorMessage )
       
   188     {
       
   189     TInt addedSD(0);
       
   190     //-----1.no disco phase
       
   191     //-----2.establish credential and put to session
       
   192     //-----3.set validator. Enables re-auth for cases when credential is expired between init and send
       
   193     if(aPattern.FrameworkId() != KDefaultOviFrameworkID)
       
   194         {
       
   195         TLSLOG_L(KSenClientSessionLogChannelBase+aRemoteConsumer.ConnectionId(),KNormalLogLevel ,"CWSOviPlugin::AddServiceDescriptionL - this is not KDefaultWSOviFrameworkID");
       
   196         addedSD = 0; // zero added
       
   197         }
       
   198     else if( aPattern.Endpoint().Length() > 0 && aPattern.Contract().Length() > 0 )
       
   199         {
       
   200         CWSOviServiceSession* pNewSession = CWSOviServiceSession::NewL(*this);
       
   201         CleanupStack::PushL(pNewSession);
       
   202 
       
   203         // InitializeFromL copies the contract and endpoint of concrete service
       
   204         //  also context will be set
       
   205         pNewSession->InitializeFromL(aPattern);
       
   206         pNewSession->AddConsumerL(aRemoteConsumer);
       
   207         pNewSession->SessionContext()->Update(WSOviContextKeys::KOnlySharing, EFalse);
       
   208 //SOA for S60 Composable Handler Framework v0.1  - 7.5.3.1 point 3)        
       
   209         TInt error = ProcessOutboundValidationL( aPattern, 
       
   210                                                 (MSenRemoteServiceSession*)pNewSession,
       
   211                                                 aErrorMessage );
       
   212         TLSLOG_FORMAT((KSenClientSessionLogChannelBase+aRemoteConsumer.ConnectionId(), KMinLogLevel , _L8("CWSOviPlugin::AddServiceDescriptionL - ProcessOutboundValidation returned: %d"), error));
       
   213 
       
   214         if ( error )
       
   215             {
       
   216             if (error>KErrNone)
       
   217                 {
       
   218                 addedSD = KErrSenAuthenticationFault;
       
   219                 }
       
   220             else
       
   221                 {
       
   222                 addedSD = error;
       
   223                 }
       
   224             CleanupStack::PopAndDestroy(pNewSession);
       
   225             }
       
   226         else // BOTH outbound validation and policy handler invokation OK(!):
       
   227             {
       
   228             Manager().AddServiceDescriptionL((CSenWSDescription*)pNewSession);
       
   229             addedSD = 1;
       
   230             CleanupStack::Pop(pNewSession); //now session is owned by Core / XML DAO
       
   231             }
       
   232         }
       
   233     else
       
   234         {
       
   235         TLSLOG_L(KSenClientSessionLogChannelBase+aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSOviPlugin::AddServiceDescriptionL - No endpoint AND no contract; new session could not be added.");
       
   236         addedSD = 0; // zero added
       
   237         }
       
   238     return addedSD;
       
   239     }
       
   240 
       
   241 TBool CWSOviPlugin::IsTrustedClient(MSenRemoteServiceConsumer& aRemoteConsumer)
       
   242     {
       
   243     TSecureId sid = aRemoteConsumer.SecureId();    
       
   244     //_LIT_SECURE_ID(nokia_chateventmonitorserver, 0x2001B2C5 );
       
   245     
       
   246     TVendorId vendor = aRemoteConsumer.VendorId();
       
   247 	_LIT_VENDOR_ID(trustedVendor,VID_DEFAULT);
       
   248     
       
   249     if (vendor.iId == trustedVendor.iId )
       
   250         return ETrue;
       
   251     else
       
   252         return EFalse;
       
   253     }
       
   254 
       
   255 //---------------------------------------------------------------------------
       
   256 // Create a ServiceSession based upon the given ServiceDescription.
       
   257 //---------------------------------------------------------------------------
       
   258 //
       
   259 TInt CWSOviPlugin::CreateServiceSessionL( MSenServiceDescription& aServiceDescription,
       
   260                                            MSenServiceDescription& aPattern,
       
   261                                            CSenServiceSession*& aNewSession,
       
   262                                            MSenRemoteServiceConsumer& aRemoteConsumer,
       
   263                                            HBufC8*& aErrorMessage )
       
   264     {
       
   265     if (!IsTrustedClient(aRemoteConsumer)) return KErrPermissionDenied;
       
   266     TInt error(KErrNone);
       
   267     if( aServiceDescription.DescriptionClassType() == MSenServiceDescription::EOviServiceSession )
       
   268         {
       
   269         //usecase:  when init connection with not registered description, nothing in db
       
   270         //usecase:  when bootup and description was already in db (registered during parsing db.file)
       
   271         aNewSession = (CWSOviServiceSession*) &aServiceDescription;
       
   272         aNewSession->SetStatusL();
       
   273         TLSLOG_L(KSenClientSessionLogChannelBase+aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSOviPlugin::ServiceDescription is already a ServiceSession");
       
   274         }
       
   275     else
       
   276         {
       
   277         aNewSession = (CWSOviServiceSession*) NewServiceDescriptionL();
       
   278         error = ((CWSOviServiceSession*)aNewSession)->InitializeFromL( aServiceDescription );
       
   279         }
       
   280     if(aNewSession && !error)//if session was just created, its possible that its not validate
       
   281         {
       
   282         if(!aNewSession->IsReadyL())
       
   283             {
       
   284             TLSLOG_L(KSenClientSessionLogChannelBase+aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSOviPlugin::ServiceSession is not ready");
       
   285             //usecase: when credential was parsed(exiNAUTH) and additionally expired.
       
   286             //         We don't need revalidate if credentials doesnt exist at all
       
   287             
       
   288             
       
   289             CWSOviSessionContext* pSessionValidateCtx = ((CWSOviServiceSession*)aNewSession)->SessionContext();
       
   290             if (!pSessionValidateCtx) //sessionCts exist if revalidation is processing
       
   291                 {
       
   292                 pSessionValidateCtx = CWSOviSessionContext::NewLC();
       
   293                 pSessionValidateCtx->Add(WSOviContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aNewSession);
       
   294                 ((CWSOviServiceSession*)aNewSession)->SetSessionContext(pSessionValidateCtx);
       
   295                 CleanupStack::Pop(pSessionValidateCtx);
       
   296                 }
       
   297                 
       
   298             pSessionValidateCtx->Update(WSOviContextKeys::KRemoteConsumer(),
       
   299                                         &aRemoteConsumer);
       
   300             aNewSession->AddConsumerL(aRemoteConsumer);
       
   301             pSessionValidateCtx->Update(WSOviContextKeys::KOnlySharing, EFalse);   
       
   302             error = ProcessOutboundValidationL( aPattern, 
       
   303                                                (MSenRemoteServiceSession*)aNewSession,
       
   304                                                aErrorMessage );
       
   305             if (error) aNewSession->RemoveConsumerL(aRemoteConsumer);
       
   306             if (error>KErrNone)
       
   307                 {
       
   308                 error = KErrSenAuthenticationFault;
       
   309                 }
       
   310             }
       
   311         else
       
   312             {
       
   313             //usecase: when credential was parsed(exiNAUTH) and credential is valid.
       
   314             // We start credential monitor and revalidation is start when credential expired. 
       
   315             TLSLOG_L(KSenClientSessionLogChannelBase+aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSOviPlugin::Call ActiveTicketObserverL()");
       
   316             ((CWSOviServiceSession*)aNewSession)->ActiveTicketObserverL();
       
   317             }
       
   318         }
       
   319     return error;
       
   320     }
       
   321 
       
   322 //---------------------------------------------------------------------------
       
   323 //---------------------------------------------------------------------------
       
   324 //
       
   325 TInt CWSOviPlugin::OnEvent( const TInt aEvent, TAny* apArgument )
       
   326     {
       
   327     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSOviPlugin::OnEvent");
       
   328     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("  -event code: %d"), aEvent));
       
   329     TInt retCode( KErrNone );
       
   330 
       
   331     switch( aEvent)
       
   332         {
       
   333         
       
   334         case KSenEventWsfReady:
       
   335             {
       
   336             TPtrC8 imsi = iManager.IMSI();
       
   337             if (iIMSI.Compare(imsi))
       
   338             	{
       
   339             	const RPointerArray<CSenIdentityProvider> list = iManager.IdentityProvidersL();
       
   340         	    for (TInt i = 0; i<list.Count(); i++)
       
   341     	            {
       
   342     	            CSenElement* el(NULL);
       
   343     	            list[i]->AccountExtensions(el);
       
   344     	            if (el)
       
   345     	            	{
       
   346     	            	delete (el->RemoveElement(KSenAccAutoSignIn));
       
   347     	            	((MSenCredentialManager&)iManager).RemoveCredentialsL(list[i]->ProviderID());
       
   348     	            	}
       
   349     	            //((MSenCredentialManager&)iManager).RemoveCredentialsL(list[i]->ProviderID());
       
   350     	            }
       
   351         	    iIMSI.Close();
       
   352         	    iIMSI.Create(imsi);
       
   353         	    }
       
   354             }
       
   355             break;
       
   356         case KSenEventRegisterIdentityProvider:
       
   357         case KSenEventUnregisterIdentityProvider:
       
   358             {
       
   359             TInt policyLeave(KErrNone);
       
   360             TRAP(policyLeave, VerifyPermissionOnEachSessionL(); )
       
   361             if ( policyLeave & !retCode )
       
   362                 {
       
   363                 retCode = policyLeave;
       
   364                 }
       
   365             }
       
   366             break;
       
   367             
       
   368         default:
       
   369             {
       
   370             // do nothing
       
   371             }
       
   372         }
       
   373     return retCode;
       
   374     }
       
   375 
       
   376 
       
   377 void CWSOviPlugin::VerifyPermissionOnEachSessionL()
       
   378     {
       
   379 
       
   380     CSenWSDescription* pOpenMask = CSenWSDescription::NewLC( KNullDesC8, KNullDesC8 );
       
   381     pOpenMask->SetFrameworkIdL(KDefaultOviFrameworkID); // now it matches with any WS-Ovi session
       
   382     
       
   383     RWSDescriptionArray all;
       
   384     iManager.ServiceDescriptionsL(all, *pOpenMask);
       
   385     CleanupStack::PopAndDestroy(pOpenMask);
       
   386     CleanupClosePushL(all);
       
   387 
       
   388     TInt count(all.Count());
       
   389 
       
   390     for(TInt i=0; i<count; i++)
       
   391         {   
       
   392         CSenWSDescription* pSD = (CSenWSDescription*)all[i];
       
   393 
       
   394         if(pSD->DescriptionClassType() == MSenServiceDescription::EOviServiceSession)
       
   395             {
       
   396             CWSOviServiceSession* pSession = (CWSOviServiceSession*)pSD;
       
   397             pSession->VerifyPermissionL(); // accessible through friendship
       
   398             }
       
   399         }
       
   400     CleanupStack::PopAndDestroy(&all);
       
   401     }
       
   402 
       
   403 //---------------------------------------------------------------------------
       
   404 // There is no extended interface in WSOvi framework at the moment.
       
   405 //---------------------------------------------------------------------------
       
   406 //
       
   407 TAny* CWSOviPlugin::ExtendedInterface()
       
   408     {
       
   409     return NULL;
       
   410     }
       
   411 
       
   412 //---------------------------------------------------------------------------
       
   413 // Return a new instance of a framework specific class that
       
   414 //     implements the ServiceDesccription interface.
       
   415 //---------------------------------------------------------------------------
       
   416 //
       
   417 CSenWSDescription* CWSOviPlugin::NewServiceDescriptionL()
       
   418     {
       
   419     CWSOviServiceSession* pSD =
       
   420         CWSOviServiceSession::NewL(*this);
       
   421     CleanupStack::PushL(pSD);    
       
   422     pSD->SetFrameworkIdL(KDefaultOviFrameworkID);
       
   423     CleanupStack::Pop(pSD);
       
   424     return pSD;
       
   425     }
       
   426 
       
   427 //---------------------------------------------------------------------------
       
   428 // Getter for manager
       
   429 //---------------------------------------------------------------------------
       
   430 //
       
   431 MSenCoreServiceManager& CWSOviPlugin::Manager()
       
   432     {
       
   433     return iManager;
       
   434     }
       
   435 //---------------------------------------------------------------------------
       
   436 // Setter for manager
       
   437 //---------------------------------------------------------------------------
       
   438 //
       
   439 void CWSOviPlugin::SetManager(MSenCoreServiceManager& aServiceManager)
       
   440     {
       
   441     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::SetManager(.)")));
       
   442     iManager = aServiceManager;
       
   443     }
       
   444 //---------------------------------------------------------------------------
       
   445 // Getter for configParser
       
   446 //---------------------------------------------------------------------------
       
   447 //
       
   448 CSenBaseFragment& CWSOviPlugin::ConfigParser()
       
   449     {
       
   450     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ConfigParser()")));
       
   451     return *this;
       
   452     //return callbacks which will be invoked during parsing rest of config
       
   453     //this callbacks will be responsible for loading features
       
   454     }
       
   455 
       
   456 //---------------------------------------------------------------------------
       
   457 // UCS2 serializer
       
   458 //---------------------------------------------------------------------------
       
   459 HBufC* CWSOviPlugin::AsXmlUnicodeL()
       
   460     {
       
   461     HBufC8* pUtf8 = AsXmlL();
       
   462     CleanupStack::PushL(pUtf8);
       
   463     HBufC* pAsAxlInUnicode = SenXmlUtils::ToUnicodeLC(*pUtf8);
       
   464     CleanupStack::Pop(pAsAxlInUnicode);
       
   465     CleanupStack::PopAndDestroy(pUtf8); 
       
   466     return pAsAxlInUnicode;
       
   467     }
       
   468 
       
   469 //---------------------------------------------------------------------------
       
   470 // UTF8 serializer
       
   471 //---------------------------------------------------------------------------
       
   472 HBufC8* CWSOviPlugin::AsXmlL()
       
   473     {
       
   474     HBufC8* retVal = HBufC8::NewLC(KMaxLengthXml);
       
   475     TPtr8 ptr = retVal->Des();
       
   476     ptr.Append(KSenLessThan);
       
   477     ptr.Append(KFrameworkLocalName);
       
   478     ptr.Append(KSenSpace);
       
   479     ptr.Append(KSenSpaceXmlns);
       
   480     ptr.Append(KSenEqualsDblQuot);
       
   481     ptr.Append(KFrameworkXMLNS);
       
   482     ptr.Append(KSenDblQuot);
       
   483     
       
   484     ptr.Append(KSenSpace);
       
   485     ptr.Append(KClassAttr);
       
   486     ptr.Append(KSenEqualsDblQuot);
       
   487     ptr.Append(KFrameworkCue);
       
   488     ptr.Append(KSenDblQuot);
       
   489     ptr.Append(KSenGreaterThan);
       
   490     
       
   491 //--message handlers    
       
   492     for (TInt i=0; i < iMsgHandlers.Count(); i++)
       
   493         {
       
   494         AddHandlerTag(ptr, iMsgHandlers[i]->Name());
       
   495         }
       
   496 //--session handlers    
       
   497    for (TInt i=0; i < iSessionHandlers.Count(); i++)
       
   498         {
       
   499         AddHandlerTag(ptr, iSessionHandlers[i]->Name());
       
   500         }  
       
   501 //add IMIS digest
       
   502    	ptr.Append(KSenLessThan);
       
   503    	ptr.Append(KIMSILocalName);
       
   504    	ptr.Append(KSenSpace);
       
   505       //class attr
       
   506    	ptr.Append(KIMSIDigestAttr);
       
   507    	ptr.Append(KSenEqualsDblQuot);
       
   508    	ptr.Append(iIMSI);
       
   509    	ptr.Append(KSenDblQuot);
       
   510    	ptr.Append(KSenSlashGreaterThan);
       
   511     
       
   512    
       
   513    
       
   514     ptr.Append(KSenLessThanSlash);
       
   515     ptr.Append(KFrameworkLocalName);
       
   516     ptr.Append(KSenGreaterThan);
       
   517     CleanupStack::Pop(retVal);
       
   518     return retVal;
       
   519     }
       
   520 
       
   521 
       
   522 
       
   523 //---------------------------------------------------------------------------
       
   524 //  used during reading configuration of WSOvi framework in order to load 
       
   525 //  proper handlers.
       
   526 //---------------------------------------------------------------------------
       
   527 //
       
   528 void CWSOviPlugin::StartElementL(const TDesC8& /*aNsUri*/,
       
   529                                     const TDesC8& aLocalName,
       
   530                                     const TDesC8& /*aQName*/,
       
   531                                     const RAttributeArray& aAttrs)
       
   532     {
       
   533     if(aLocalName.Compare(KHandlerLocalName) == 0)
       
   534         {
       
   535         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::Found handler")));
       
   536         TPtrC8 pClass = SenXmlUtils::AttrValue(aAttrs, KClassAttr);
       
   537         TPtrC8 pVersion = SenXmlUtils::AttrValue(aAttrs, KVersionAttr);
       
   538         
       
   539         //message handlers
       
   540         if ((pClass == KDeviceValue ) || 
       
   541             (pClass == KSecurityValue ))
       
   542             {
       
   543             AddHandlerL(pClass, pVersion, SenHandler::EMessageHandler);
       
   544             }
       
   545         //session handlers
       
   546         else if((pClass == KValidateValue) ||
       
   547                 (pClass == KRegisterValue)
       
   548                 )
       
   549             {
       
   550             AddHandlerL(pClass, pVersion, SenHandler::ESessionHandler);
       
   551             }
       
   552         else
       
   553             {
       
   554             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("Found unknown handler!")));
       
   555             }
       
   556              
       
   557         }
       
   558     else if (! aLocalName.Compare(KIMSILocalName))
       
   559     	{
       
   560     	iIMSI.Close();
       
   561     	iIMSI.Create(SenXmlUtils::AttrValue(aAttrs, KIMSIDigestAttr));
       
   562     	}
       
   563     }
       
   564 //---------------------------------------------------------------------------
       
   565 //  used during reading configuration of WSOvi framework 
       
   566 //---------------------------------------------------------------------------
       
   567 //
       
   568 void CWSOviPlugin::EndElementL(const TDesC8& aNsUri,
       
   569                                     const TDesC8& aLocalName,
       
   570                                     const TDesC8& aQName)
       
   571     {
       
   572     CSenBaseFragment::EndElementL(aNsUri,aLocalName,aQName);
       
   573     }
       
   574     
       
   575 //---------------------------------------------------------------------------
       
   576 // getter of handler, using its cue
       
   577 //---------------------------------------------------------------------------
       
   578 //    
       
   579 
       
   580 MSenHandler* CWSOviPlugin::Handler(const TDesC8& aCue)
       
   581     {
       
   582     TInt count = iMsgHandlers.Count();
       
   583     for(TInt i=0;i<count; i++)
       
   584         {
       
   585         if (iMsgHandlers[i]->Name() == aCue)
       
   586             {
       
   587             return iMsgHandlers[i];
       
   588             }
       
   589         }
       
   590     count = iSessionHandlers.Count();
       
   591     for(TInt i=0;i<count; i++)
       
   592         {
       
   593         if (iSessionHandlers[i]->Name() == aCue)
       
   594             {
       
   595             return iSessionHandlers[i];
       
   596             }
       
   597         }
       
   598     return NULL;
       
   599     }
       
   600 //---------------------------------------------------------------------------
       
   601 // remove handler by cue, used during reloading (another version of handler is 
       
   602 //      used than deafault setup)
       
   603 //---------------------------------------------------------------------------
       
   604 //    
       
   605 void CWSOviPlugin::RemoveHandler(const TDesC8& aCue)
       
   606     {
       
   607     TInt count = iMsgHandlers.Count();
       
   608     for(TInt i=0;i<count; i++)
       
   609         {
       
   610         if (iMsgHandlers[i]->Name() == aCue)
       
   611             {
       
   612             delete iMsgHandlers[i];
       
   613             iMsgHandlers.Remove(i);
       
   614             return;
       
   615             }
       
   616         }
       
   617     count = iSessionHandlers.Count();
       
   618     for(TInt i=0;i<count; i++)
       
   619         {
       
   620         if (iSessionHandlers[i]->Name() == aCue)
       
   621             {
       
   622             delete iSessionHandlers[i];
       
   623             iSessionHandlers.Remove(i);
       
   624             return;
       
   625             }
       
   626         }
       
   627     }
       
   628 
       
   629 
       
   630 
       
   631 //---------------------------------------------------------------------------
       
   632 // Process Outbound validation phase
       
   633 //---------------------------------------------------------------------------
       
   634 //     
       
   635 TInt CWSOviPlugin::ProcessOutboundValidationL( MSenServiceDescription& /*aPattern*/, 
       
   636                                                 MSenRemoteServiceSession* aRemoteServiceSession,
       
   637                                                 HBufC8*& aErrorMessage )
       
   638     {
       
   639     TInt error(KErrNone);
       
   640     CSenSessionHandler* pValidatehandler = (CSenSessionHandler*)Handler(KValidateValue);
       
   641     CWSOviSessionContext* pSessionValidateCtx = ((CWSOviServiceSession*)aRemoteServiceSession)->SessionContext();
       
   642     if (!pSessionValidateCtx) //sessionCts exist if revalidation is processing
       
   643         {
       
   644         pSessionValidateCtx = CWSOviSessionContext::NewLC();
       
   645         pSessionValidateCtx->Add(WSOviContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   646         ((CWSOviServiceSession*)aRemoteServiceSession)->SetSessionContext(pSessionValidateCtx);
       
   647         CleanupStack::Pop(pSessionValidateCtx);
       
   648         }
       
   649     else
       
   650         {
       
   651         pSessionValidateCtx->Update(WSOviContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   652         }
       
   653     TRAPD(errorL, error = pValidatehandler->InvokeL(*pSessionValidateCtx));
       
   654     if ( error )
       
   655         {
       
   656         const TDesC8* pNotOwnedErrorMsg = pSessionValidateCtx->GetDesC8L(WSOviContextKeys::KErrMessage);
       
   657         if ( pNotOwnedErrorMsg )
       
   658             {
       
   659             aErrorMessage = pNotOwnedErrorMsg->AllocL();
       
   660             }
       
   661         }
       
   662     if (errorL!=KErrNone)
       
   663         {
       
   664         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ProcessOutboundValidationL() !!!!leave from validate handler")));
       
   665         error = errorL;
       
   666         }
       
   667     return error;
       
   668     }
       
   669     
       
   670     
       
   671     
       
   672 //---------------------------------------------------------------------------
       
   673 // Process Outbound message phase
       
   674 //---------------------------------------------------------------------------
       
   675 //                                          
       
   676 TInt CWSOviPlugin::ProcessOutboundMessageL( CWSOviMessageContext*& aMsgCtx)
       
   677     {
       
   678 
       
   679 //--------------------device handler
       
   680     TInt error(KErrNone);
       
   681     CSenMessageHandler* pHandler = NULL;
       
   682     pHandler = (CSenMessageHandler*)Handler(KDeviceValue);
       
   683     if (pHandler)
       
   684         {
       
   685         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   686         if (errorL!=KErrNone)
       
   687             {
       
   688             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ProcessOutboundMessageL() !!!!leave from device handler")));
       
   689             error = errorL;
       
   690             }
       
   691         }
       
   692 
       
   693 
       
   694 //--------------------security handler
       
   695     pHandler = (CSenMessageHandler*)Handler(KSecurityValue);
       
   696     if (pHandler)
       
   697         {
       
   698         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   699         if (errorL!=KErrNone)
       
   700             {
       
   701             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ProcessOutboundMessageL() !!!!leave from security handler")));
       
   702             error = errorL;
       
   703             }
       
   704         }
       
   705 
       
   706 //--------------------credential collector handler
       
   707     pHandler = (CSenMessageHandler*)Handler(KCredentialCollectorValue);
       
   708     if (pHandler)
       
   709         {
       
   710         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   711         if (errorL!=KErrNone)
       
   712             {
       
   713             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ProcessOutboundMessageL() !!!!leave from Credential Collector handler")));
       
   714             error = errorL;
       
   715             }
       
   716         }
       
   717 
       
   718     //--------------------encoder handler
       
   719         pHandler = (CSenMessageHandler*)Handler(KEncoderValue);
       
   720         if (pHandler)
       
   721             {
       
   722             TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   723             if (errorL!=KErrNone)
       
   724                 {
       
   725                 TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ProcessOutboundMessageL() !!!!leave from Encoder handler")));
       
   726                 error = errorL;
       
   727                 }
       
   728             }
       
   729 
       
   730     return error;
       
   731     }
       
   732 
       
   733 
       
   734 
       
   735 
       
   736 //---------------------------------------------------------------------------
       
   737 // Process Ibound message phase (body as element)
       
   738 //---------------------------------------------------------------------------
       
   739 //   
       
   740 TInt CWSOviPlugin::ProcessInboundMessageL()
       
   741     {
       
   742     return KErrNotSupported;
       
   743     }
       
   744         
       
   745         
       
   746 //---------------------------------------------------------------------------
       
   747 // Process Ibound dispatch phase (in fact updatinf session)
       
   748 //---------------------------------------------------------------------------
       
   749 //        
       
   750 TInt CWSOviPlugin::ProcessInboundDispatchL( MSenRemoteServiceSession* aRemoteServiceSession,
       
   751                                                const TInt aErrorCode,
       
   752                                                HBufC8* aMessage,
       
   753                                                MSenProperties* aResponseTransportProperties)
       
   754     {
       
   755     TInt error(KErrNone);
       
   756     CSenSessionHandler* pHandler = NULL;
       
   757     CWSOviSessionContext* pSessionCtx = ((CWSOviServiceSession*)aRemoteServiceSession)->SessionContext();
       
   758     pSessionCtx->Update(WSOviContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   759     TLSLOG_FORMAT((KSenClientSessionLogChannelBase, KMinLogLevel , _L8("CWSOviPlugin::ProcessInboundDispatchL - aErrorCode: %d"), aErrorCode));
       
   760     if ( aMessage ) 
       
   761         {
       
   762         pSessionCtx->Update( WSOviContextKeys::KMessageBody, *aMessage );
       
   763         TLSLOG_ALL(KSenClientSessionLogChannelBase, KMinLogLevel , *aMessage);
       
   764         }
       
   765     if ( aResponseTransportProperties ) 
       
   766         {
       
   767         pSessionCtx->Update( WSOviContextKeys::KTP, (TAny*)aResponseTransportProperties );
       
   768         }
       
   769         
       
   770     pSessionCtx->Update(WSOviContextKeys::KErrCode, aErrorCode);
       
   771     
       
   772     //--------------------encoder handler
       
   773     pHandler = (CSenSessionHandler*)Handler(KServiceUpdateValue);
       
   774     if (pHandler)
       
   775         {
       
   776         TRAPD(errorL, error = pHandler->InvokeL(*pSessionCtx));
       
   777         if (errorL!=KErrNone)
       
   778             {
       
   779             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::ProcessOutboundMessageL() !!!!leave from Service Update handler")));
       
   780             error = errorL;
       
   781             }
       
   782         const TInt* diff = pSessionCtx->GetIntL(WSOviContextKeys::KRetryNeeded);
       
   783         if (diff && *diff > 0)
       
   784         	{
       
   785         	CWSOviValidateHandler* validateHandler = (CWSOviValidateHandler*)Handler(KValidateValue);
       
   786         	validateHandler->HandlerContext().Update(HandlerContextKey::KDiff, *diff);
       
   787         	}
       
   788         }
       
   789     return error;
       
   790     }
       
   791 
       
   792 
       
   793 //---------------------------------------------------------------------------
       
   794 // Add handler tag into session.xml
       
   795 //---------------------------------------------------------------------------
       
   796 //        
       
   797 void CWSOviPlugin::AddHandlerTag(TPtr8& aXml, const TDesC8& aHandlerClassName)
       
   798     {
       
   799     aXml.Append(KSenLessThan);
       
   800     aXml.Append(KHandlerLocalName);
       
   801     aXml.Append(KSenSpace);
       
   802     //class attr
       
   803     aXml.Append(KClassAttr);
       
   804     aXml.Append(KSenEqualsDblQuot);
       
   805     aXml.Append(aHandlerClassName);
       
   806     aXml.Append(KSenDblQuot);
       
   807     TInt index = iVersions.Find(aHandlerClassName);
       
   808     if (index != KErrNotFound)
       
   809         {
       
   810         HBufC8* value = (HBufC8*)iVersions.ValueAt(index);
       
   811         if (value->Length())
       
   812             {
       
   813             aXml.Append(KSenSpace);
       
   814             aXml.Append(KVersionAttr);
       
   815             aXml.Append(KSenEqualsDblQuot);
       
   816             aXml.Append(*value);
       
   817             aXml.Append(KSenDblQuot);    
       
   818             }
       
   819         }   
       
   820     aXml.Append(KSenSlashGreaterThan);
       
   821     }
       
   822     
       
   823 //---------------------------------------------------------------------------
       
   824 // Add handler into array, WSOvi SIF implementation keep handlers after loading
       
   825 //---------------------------------------------------------------------------
       
   826 //        
       
   827 void CWSOviPlugin::AddHandlerL(const TDesC8& aHandlerClassName, const TDesC8& aVersion, SenHandler::THandlerType aType)
       
   828     {
       
   829     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSOviPlugin::AddHandlerL")));
       
   830     TInt index = iVersions.Find(aHandlerClassName);
       
   831     if (index == KErrNotFound)
       
   832         {
       
   833         MSenHandler* handler  = NULL;
       
   834         CWSOviHandlerContext* ctx = NULL;
       
   835         ctx = CWSOviHandlerContext::NewL();
       
   836         CleanupStack::PushL(ctx);
       
   837         ctx->Add(iManager);
       
   838         ctx->Update(HandlerContextKey::KVersion, aVersion);
       
   839         iVersions.Append(aHandlerClassName.AllocL(), aVersion.AllocL());
       
   840         if(aType == SenHandler::EMessageHandler)
       
   841             {
       
   842             TRAPD(loadError, handler = CSenMessageHandler::NewL(aHandlerClassName, *ctx));    
       
   843             if (loadError != KErrNone)
       
   844                 {
       
   845                 User::Leave(loadError);
       
   846                 }
       
   847             else
       
   848                 {
       
   849                 iMsgHandlers.Append((CSenMessageHandler*)handler);    
       
   850                 }    
       
   851             }
       
   852         else if (aType == SenHandler::ESessionHandler)
       
   853             {
       
   854             ctx->Add(HandlerContextKey::KSIF, this);
       
   855             TRAPD(loadError, handler = CSenSessionHandler::NewL(aHandlerClassName, *ctx));
       
   856             if (loadError != KErrNone)
       
   857                 {
       
   858                 User::Leave(loadError);
       
   859                 }
       
   860             else
       
   861                 {
       
   862                 iSessionHandlers.Append((CSenSessionHandler*)handler);
       
   863                 }        
       
   864             }
       
   865         CleanupStack::Pop(ctx);
       
   866         iHandlerContexts.Append(ctx);
       
   867         }
       
   868     else
       
   869     //reload handler.
       
   870     //user info from session.xml (in fact this is only for testing , nobody can have access to session.xml)
       
   871         {
       
   872         HBufC8* value = (HBufC8*)iVersions.ValueAt(index);
       
   873         if (*value != aVersion)
       
   874             {//reload
       
   875             iVersions.RemoveByKey(aHandlerClassName);
       
   876             RemoveHandler(aHandlerClassName);
       
   877             //potentail infinitve reccurence!
       
   878             AddHandlerL(aHandlerClassName, aVersion, aType);    
       
   879             }
       
   880         }
       
   881     }
       
   882 //---------------------------------------------------------------------------
       
   883 // SetTransportPropertiesL
       
   884 //---------------------------------------------------------------------------
       
   885 //        
       
   886 TInt CWSOviPlugin::SetTransportPropertiesL(MSenTransport& /* aTransport */)
       
   887     {
       
   888     return KErrNotSupported;
       
   889     }
       
   890     
       
   891 // END OF FILE
       
   892