webservices/wsstar/wsstarplugin/src/wsstarplugin.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:           
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 #include "wsstarplugin.h"
       
    30 #include "SenServiceConnection.h" // framework IDs, error codes
       
    31 #include "sendebug.h"
       
    32 #include "senlogger.h"
       
    33 #include "MSenServiceDescription.h"
       
    34 #include "wsstarservicesession.h"
       
    35 #include "SenXmlUtils.h"
       
    36 #include "wsstarpolicy.h"
       
    37 #include "senguidgen.h"
       
    38 
       
    39 #include "wsstarpolicyhandler.h"
       
    40 using namespace WSStarConfig;
       
    41 
       
    42 // Local CONSTANTS
       
    43 const TInt KMaxLengthXml  = 1280; 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Create instance of concrete ECOM interface implementation
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CWSStarPlugin* CWSStarPlugin::NewL(TAny* aManager)
       
    50     {
       
    51     MSenCoreServiceManager* manager =
       
    52         reinterpret_cast<MSenCoreServiceManager*>(aManager);
       
    53 
       
    54     CWSStarPlugin* self = new (ELeave) CWSStarPlugin(*manager);
       
    55     CleanupStack::PushL (self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop(self);
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Constructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CWSStarPlugin::CWSStarPlugin(MSenCoreServiceManager& aManager)
       
    66     : iManager(aManager),
       
    67       iVersions(ETrue, ETrue),
       
    68       iDbReadDone(EFalse)
       
    69     {
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Destructor
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CWSStarPlugin::~CWSStarPlugin()
       
    77     {
       
    78     iMsgHandlers.ResetAndDestroy();
       
    79     iSessionHandlers.ResetAndDestroy();
       
    80     iHandlerContexts.ResetAndDestroy();
       
    81     iVersions.Reset();
       
    82     delete iDeviceId;
       
    83     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::~CWSStarPlugin()")));
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Second phase construction.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CWSStarPlugin::ConstructL()
       
    91     {
       
    92     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ConstructL")));
       
    93 
       
    94     BaseConstructL(KFrameworkXMLNS, KFrameworkLocalName);
       
    95     GenerateDeviceIdL();
       
    96     //load default setup of handlers
       
    97     AddHandlerL(KValidateValue, KNullDesC8, SenHandler::ESessionHandler);//old http://schemas.xmlsoap.org/ws/2004/04/trust
       
    98     AddHandlerL(KRegisterValue, KNullDesC8, SenHandler::ESessionHandler);
       
    99     AddHandlerL(KServiceUpdateValue, KNullDesC8, SenHandler::ESessionHandler);//new http://schemas.xmlsoap.org/ws/2004/08/addressing
       
   100     
       
   101     AddHandlerL(KEnveloperValue, KNullDesC8, SenHandler::EMessageHandler);//old http://schemas.xmlsoap.org/soap/envelope
       
   102     AddHandlerL(KCredentialCollectorValue, KNullDesC8, SenHandler::EMessageHandler);
       
   103     AddHandlerL(KAddressingValue, KNullDesC8, SenHandler::EMessageHandler);//new http://schemas.xmlsoap.org/ws/2004/08/addressing
       
   104     AddHandlerL(KPassportValue, KNullDesC8, SenHandler::EMessageHandler);
       
   105     AddHandlerL(KSecurityValue, KNullDesC8, SenHandler::EMessageHandler);
       
   106     AddHandlerL(KPolicyValue, KNullDesC8, SenHandler::ESessionHandler); //Initalize policy
       
   107 #ifdef RD_SEN_VTCP_SUPPORT        
       
   108     AddHandlerL(KCoBrandingValue, KNullDesC8, SenHandler::ESessionHandler); //Initalize co-branding
       
   109 #endif//RD_SEN_VTCP_SUPPORT	
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Getter for logger. Works only in debug mode.
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 /*RFileLogger* CWSStarPlugin::Log() const
       
   117     {
       
   118     return iManager.Log();
       
   119     }
       
   120 */
       
   121 
       
   122 //========================================================
       
   123 //                MSIF SPecific
       
   124 //========================================================
       
   125 
       
   126 //---------------------------------------------------------------------------
       
   127 // Attempt to register the ServiceDescription to the ServiceManager 
       
   128 //---------------------------------------------------------------------------
       
   129 //
       
   130 TInt CWSStarPlugin::RegisterServiceDescriptionL(
       
   131     MSenServiceDescription& aServiceDescription )
       
   132     {
       
   133     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::RegisterServiceDescriptionL(.)")));
       
   134     TInt error(KErrNone);
       
   135 
       
   136     CWSStarPolicyHandler* pPolicyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);    
       
   137     CWSStarSessionContext* pSessionRegisterCtx = CWSStarSessionContext::NewLC(Manager().XMLReader(), &aServiceDescription, pPolicyHandler);
       
   138     pSessionRegisterCtx->Add(WSStarContextKeys::KServiceDescription(),
       
   139             (CSenWSDescription*)&aServiceDescription);
       
   140     pSessionRegisterCtx->Add(WSStarContextKeys::KRegisterAction(),
       
   141             WSStarContextValues::KActionRegister());
       
   142 //policy initalization    
       
   143     TPtrC8 contract = aServiceDescription.Contract();
       
   144     TRAPD(policyError, pPolicyHandler->InvokeL(contract));
       
   145     if (policyError!=KErrNone)
       
   146         {
       
   147         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::RegisterServiceDescriptionL() !!!!leave from PolicyHandler")));
       
   148         }
       
   149 
       
   150 //SOA for S60 Composable Handler Framework v0.1 - 7.5.3.1 point 1)            
       
   151     CSenSessionHandler* pregisterHandler = 
       
   152                 (CSenSessionHandler*)Handler(KRegisterValue());
       
   153         
       
   154     TRAPD(errorL,error= pregisterHandler->InvokeL(*pSessionRegisterCtx));
       
   155     if (errorL!=KErrNone)
       
   156         {
       
   157         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::RegisterServiceDescriptionL() !!!!leave from RegisterHandler")));
       
   158         error = errorL;
       
   159         }
       
   160     CleanupStack::PopAndDestroy(pSessionRegisterCtx);
       
   161     return error;
       
   162     }
       
   163 
       
   164 //---------------------------------------------------------------------------
       
   165 // Attempt to unregister the ServiceDescription from the ServiceManager 
       
   166 //---------------------------------------------------------------------------
       
   167 //
       
   168 TInt CWSStarPlugin::UnregisterServiceDescriptionL(
       
   169     MSenServiceDescription& aServiceDescription)
       
   170     {
       
   171     
       
   172     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::UnRegisterServiceDescriptionL(.)")));
       
   173 //SOA for S60 Composable Handler Framework v0.1  - 7.5.3.1 point 1)            
       
   174     TInt error(KErrNone);
       
   175     CSenSessionHandler* pregisterHandler = 
       
   176                 (CSenSessionHandler*)Handler(KRegisterValue());
       
   177         
       
   178     CWSStarSessionContext* pSessionRegisterCtx = CWSStarSessionContext::NewLC(Manager().XMLReader(), &aServiceDescription);
       
   179     pSessionRegisterCtx->Add(WSStarContextKeys::KServiceDescription(),
       
   180             (CSenWSDescription*)&aServiceDescription);
       
   181     pSessionRegisterCtx->Add(WSStarContextKeys::KRegisterAction(),
       
   182             WSStarContextValues::KActionUnregister());
       
   183     CWSStarPolicyHandler* pPolicyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);    
       
   184     TRAPD(policyError, pPolicyHandler->UnRegisterWsPolicyL(aServiceDescription));
       
   185     if (policyError!=KErrNone)
       
   186         {
       
   187         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::UnRegisterServiceDescriptionL() !!!!leave from PolicyHandler")));
       
   188         }
       
   189         
       
   190     TRAPD(errorL,error = pregisterHandler->InvokeL(*pSessionRegisterCtx));
       
   191     if (errorL!=KErrNone)
       
   192         {
       
   193         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::UnregisterServiceDescriptionL() !!!!leave from RegisterHandler")));
       
   194         error = errorL;
       
   195         }
       
   196     CleanupStack::PopAndDestroy(pSessionRegisterCtx);
       
   197     return error;
       
   198     }
       
   199 
       
   200 //---------------------------------------------------------------------------
       
   201 // Getter of framework (like "WS-STAR")
       
   202 //---------------------------------------------------------------------------
       
   203 //
       
   204 const TDesC8& CWSStarPlugin::Id()
       
   205     {
       
   206     return KDefaultWSStarFrameworkID();
       
   207     }
       
   208 
       
   209 //---------------------------------------------------------------------------
       
   210 // Try to find one or more services that match the given ServiceDescription.
       
   211 //    Adding is only invoked if NO! session in cache. 
       
   212 //    Its mean that we have create new one.
       
   213 //---------------------------------------------------------------------------
       
   214 //
       
   215 TInt CWSStarPlugin::AddServiceDescriptionL( MSenServiceDescription& aPattern,
       
   216                                             MSenRemoteServiceConsumer& aRemoteConsumer,
       
   217                                             HBufC8*& aErrorMessage )
       
   218     {
       
   219     TInt addedSD(0);
       
   220     //-----1.no disco phase
       
   221     //-----2.establish credential and put to session
       
   222     //-----3.set validator. Enables re-auth for cases when credential is expired between init and send
       
   223     if(aPattern.FrameworkId() != KDefaultWSStarFrameworkID)
       
   224         {
       
   225         CSLOG_L(aRemoteConsumer.ConnectionId(),KNormalLogLevel ,"CWSStarPlugin::AddServiceDescriptionL - this is not KDefaultWSStarFrameworkID");
       
   226         addedSD = 0; // zero added
       
   227         }
       
   228     else if( aPattern.Endpoint().Length() > 0 && aPattern.Contract().Length() > 0 )
       
   229         {
       
   230         CWSStarServiceSession* pNewSession = CWSStarServiceSession::NewL(*this);
       
   231         CleanupStack::PushL(pNewSession);
       
   232 
       
   233         // InitializeFromL copies the contract and endpoint of concrete service
       
   234         //  also context will be set
       
   235         CWSStarPolicyHandler* policyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);
       
   236         pNewSession->InitializeFromL(aPattern, policyHandler);
       
   237         pNewSession->AddConsumerL(aRemoteConsumer);
       
   238         TSenDataTrafficDetails policyDetails; 
       
   239         policyHandler->DataTrafficDetails(policyDetails);
       
   240         aRemoteConsumer.SetDataTrafficDetails(policyDetails);
       
   241         pNewSession->SessionContext()->Update(WSStarContextKeys::KOnlySharing, EFalse);
       
   242 //SOA for S60 Composable Handler Framework v0.1  - 7.5.3.1 point 3)        
       
   243         TInt error = ProcessOutboundValidationL( aPattern, 
       
   244                                                 (MSenRemoteServiceSession*)pNewSession,
       
   245                                                 aErrorMessage );
       
   246         CSLOG_FORMAT((aRemoteConsumer.ConnectionId(), KMinLogLevel , _L8("CWSStarPlugin::AddServiceDescriptionL - ProcessOutboundValidation returned: %d"), error));
       
   247         if ( !error )
       
   248             {
       
   249             CWSStarSessionContext* pSessionRegisterCtx = pNewSession->SessionContext();            
       
   250             TPtrC8 cont = aPattern.Contract();
       
   251             TInt policyLeaveCode(KErrNone);
       
   252             TRAP( policyLeaveCode, error = policyHandler->InvokeL(cont); )
       
   253             if ( policyLeaveCode )
       
   254                 {
       
   255                 CSLOG_FORMAT((aRemoteConsumer.ConnectionId(), KMinLogLevel , _L8("CWSStarPlugin::AddServiceDescriptionL - PolicyHandler->Invoke() leaved: %d"), policyLeaveCode));
       
   256                 CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::AddServiceDescriptionL() - FATAL: leave from PolicyHandler->Invoke()");
       
   257                 error = policyLeaveCode;
       
   258                 }
       
   259 #ifdef _SENDEBUG
       
   260             else
       
   261                 {
       
   262                 CSLOG_FORMAT((aRemoteConsumer.ConnectionId(), KMinLogLevel , _L8("CWSStarPlugin::AddServiceDescriptionL - PolicyHandler->Invoke() returned: %d"), error));
       
   263                 }
       
   264 #endif // _SENDEBUG
       
   265             }
       
   266         if ( error )
       
   267             {
       
   268             addedSD = error;
       
   269             CleanupStack::PopAndDestroy(pNewSession);
       
   270             }
       
   271         else // BOTH outbound validation and policy handler invokation OK(!):
       
   272             {
       
   273             Manager().AddServiceDescriptionL((CSenWSDescription*)pNewSession);
       
   274             addedSD = 1;
       
   275             CleanupStack::Pop(pNewSession); //now session is owned by Core / XML DAO
       
   276             }
       
   277         }
       
   278     else
       
   279         {
       
   280         CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::AddServiceDescriptionL - No endpoint AND no contract; new session could not be added.");
       
   281         addedSD = 0; // zero added
       
   282         }
       
   283     return addedSD;
       
   284     }
       
   285 
       
   286 //---------------------------------------------------------------------------
       
   287 // Create a ServiceSession based upon the given ServiceDescription.
       
   288 //---------------------------------------------------------------------------
       
   289 //
       
   290 TInt CWSStarPlugin::CreateServiceSessionL( MSenServiceDescription& aServiceDescription,
       
   291                                            MSenServiceDescription& aPattern,
       
   292                                            CSenServiceSession*& aNewSession,
       
   293                                            MSenRemoteServiceConsumer& aRemoteConsumer,
       
   294                                            HBufC8*& aErrorMessage )
       
   295     {
       
   296     TInt error(KErrNone);
       
   297     if( aServiceDescription.DescriptionClassType() == MSenServiceDescription::EWSStarServiceSession )
       
   298         {
       
   299         //example:  when init connection with not registered description, nothing in db
       
   300         //example:  when bootup and description was already in db (registered during parsing db.file)
       
   301         aNewSession = (CWSStarServiceSession*) &aServiceDescription;
       
   302         CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::ServiceDescription is already a ServiceSession");
       
   303         }
       
   304     else
       
   305         {
       
   306         aNewSession = (CWSStarServiceSession*) NewServiceDescriptionL();
       
   307         error = ((CWSStarServiceSession*)aNewSession)->InitializeFromL( aServiceDescription );
       
   308         CSLOG_FORMAT((aRemoteConsumer.ConnectionId(), KMinLogLevel , _L8("CWSStarPlugin::ServiceDescription is not a ServiceSession, creating new one returned: %d"), error));
       
   309         }
       
   310     if(aNewSession && !error)//if session was just created, its possible that its not validate
       
   311         {
       
   312         //((CWSStarServiceSession*)aNewSession)->DetachCredentialsL() ; //invalidating session to recompute the status
       
   313         TBool isHostlet = ((CWSStarServiceSession*)aNewSession)->AmIHostletSession() ;
       
   314 		TInt credentialValidityError = KErrNone ;
       
   315 		TBool delegateToSTS = EFalse ;
       
   316         if (!isHostlet)
       
   317             {
       
   318 			credentialValidityError = ((CWSStarServiceSession*)aNewSession)->TryToSearchValidCredentialL() ;
       
   319 			if (KErrNone == credentialValidityError)
       
   320 				{
       
   321 				CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::CreateServiceSessionL() Valid credential found");
       
   322 				}
       
   323 			else
       
   324 				{
       
   325 				delegateToSTS = ETrue ;
       
   326 				CSLOG_FORMAT((aRemoteConsumer.ConnectionId(), KMinLogLevel , _L8("CWSStarPlugin::CreateServiceSessionL() No Valid credential found credentialValidityError = [%d]"), credentialValidityError));
       
   327 				}
       
   328 			}      
       
   329 		if(!aNewSession->IsReadyL())
       
   330 			{
       
   331 			delegateToSTS = ETrue ;
       
   332 			CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::CreateServiceSessionL() ServiceSession is not ready !!");
       
   333 			}
       
   334 		else
       
   335 			{
       
   336 			CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::CreateServiceSessionL() ServiceSession is ready");
       
   337 			}
       
   338 
       
   339 //        if(!aNewSession->IsReadyL())
       
   340         if(delegateToSTS)
       
   341             {
       
   342 //            CSLOG_L(aRemoteConsumer.ConnectionId(),KMinLogLevel ,"CWSStarPlugin::ServiceSession is not ready");
       
   343             //example: when credentail was parsed(exist) and additionally expired.
       
   344             //         We dont need revalidate if credentials doesnt exist at all
       
   345             
       
   346             
       
   347             CWSStarSessionContext* pSessionValidateCtx = ((CWSStarServiceSession*)aNewSession)->SessionContext();
       
   348             if (!pSessionValidateCtx) //sessionCts exist if revalidation is processing
       
   349                 {
       
   350                 CWSStarPolicyHandler* policyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);
       
   351                 pSessionValidateCtx = CWSStarSessionContext::NewLC(Manager().XMLReader(), &aPattern, policyHandler);
       
   352                 pSessionValidateCtx->Add(WSStarContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aNewSession);
       
   353                 ((CWSStarServiceSession*)aNewSession)->SetSessionContext(pSessionValidateCtx);
       
   354                 CleanupStack::Pop(pSessionValidateCtx);
       
   355                 }
       
   356                 
       
   357             pSessionValidateCtx->Update(WSStarContextKeys::KRemoteConsumer(),
       
   358                                         &aRemoteConsumer);
       
   359             aNewSession->AddConsumerL(aRemoteConsumer);
       
   360             pSessionValidateCtx->Update(WSStarContextKeys::KOnlySharing, EFalse);    
       
   361             error = ProcessOutboundValidationL( aPattern, 
       
   362                                                (MSenRemoteServiceSession*)aNewSession,
       
   363                                                aErrorMessage );
       
   364             if (error) aNewSession->RemoveConsumerL(aRemoteConsumer);
       
   365             }
       
   366         }
       
   367     return error;
       
   368     }
       
   369 
       
   370 TInt CWSStarPlugin::IssuePolicyDownloadL( CSenWSDescription* apSession )
       
   371     {
       
   372     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::IssuePolicyDownloadL");
       
   373     TInt retCode(KErrNone);
       
   374     CWSStarPolicyHandler* pPolicyHandler =  (CWSStarPolicyHandler*)Handler(KPolicyValue());
       
   375     TInt policyLeave(KErrNone);
       
   376     TRAP(policyLeave, retCode = pPolicyHandler->DownloadPolicyL( apSession ));
       
   377     if (policyLeave!=KErrNone)
       
   378         {
       
   379         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::IssuePolicyDownloadL - FATAL: leave from PolicyHandler");
       
   380         retCode = policyLeave;
       
   381         }
       
   382     retCode = pPolicyHandler->UpdatePolicyL(); 
       
   383     return retCode;
       
   384     }
       
   385 
       
   386 //---------------------------------------------------------------------------
       
   387 //---------------------------------------------------------------------------
       
   388 //
       
   389 TInt CWSStarPlugin::OnEvent( const TInt aEvent, TAny* apArgument )
       
   390     {
       
   391     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::OnEvent");
       
   392     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("  -event code: %d"), aEvent));
       
   393     TInt retCode(KErrNone);
       
   394     TInt leaveCode( KErrNone );
       
   395     
       
   396     switch( aEvent)
       
   397         {
       
   398         
       
   399         case KSenEventConsumerAdded:
       
   400             {
       
   401             ++iConsumerCount;
       
   402             CSenWSDescription* pSD = NULL; // not required
       
   403             TRAP( leaveCode, retCode = IssuePolicyDownloadL( pSD ); )
       
   404             if( leaveCode )
       
   405                 {
       
   406                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::OnEvent( KSenEventConsumerAdded ) - leave from IssuePolicyDownloadL");
       
   407                 if( !retCode )
       
   408                     {
       
   409                     retCode = leaveCode;
       
   410                     }
       
   411                 }
       
   412             break;
       
   413             }
       
   414             
       
   415         case KSenEventConsumerRemoved:
       
   416             {
       
   417             --iConsumerCount;
       
   418             break;
       
   419             }
       
   420         
       
   421         case KSenEventWsfReady:
       
   422             {
       
   423             iDbReadDone = ETrue;
       
   424             }
       
   425             break;
       
   426             
       
   427         case KSenEventRegisterNewServiceDescription:
       
   428             {
       
   429             if( iDbReadDone/* && iConsumerCount > 0*/ )
       
   430                 {
       
   431                 CSenWSDescription* pSD = (CSenWSDescription*)apArgument;
       
   432                 TInt policyLeave(KErrNone);
       
   433                 TRAP(policyLeave, retCode = IssuePolicyDownloadL( pSD ); )
       
   434                 if ( policyLeave & !retCode )
       
   435                     {
       
   436                     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::OnEvent( KSenEventSessionsDbReadComplete ) - leave from IssuePolicyDownloadL");
       
   437                     retCode = policyLeave;
       
   438                     }
       
   439                 }
       
   440             }        
       
   441             break;
       
   442             
       
   443         case KSenEventSessionsDbReadComplete:
       
   444             {
       
   445             // Current implementation downloads policy independent of (whether or not)
       
   446             // the session database has been read or not
       
   447             if( iConsumerCount > 0 )
       
   448                {
       
   449             CSenWSDescription* pSD = (CSenWSDescription*)apArgument;
       
   450             TInt policyLeave(KErrNone);
       
   451             TRAP(policyLeave, retCode = IssuePolicyDownloadL( pSD ); )
       
   452             if ( policyLeave & !retCode )
       
   453                 {
       
   454                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::OnEvent( KSenEventSessionsDbReadComplete ) - leave from IssuePolicyDownloadL");
       
   455                     if( !retCode )
       
   456                         {
       
   457                 retCode = policyLeave;
       
   458                         }
       
   459                  }
       
   460                }
       
   461             }
       
   462             break;
       
   463             
       
   464         case KSenEventRegisterIdentityProvider:
       
   465         case KSenEventUnregisterIdentityProvider:
       
   466             {
       
   467             TInt policyLeave(KErrNone);
       
   468             TRAP(policyLeave, VerifyPermissionOnEachSessionL(); )
       
   469             if ( policyLeave & !retCode )
       
   470                 {
       
   471                 TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarPlugin::OnEvent( KSenEventSessionsDbReadComplete ) - leave from VerifyPermissionOnEachSessionL");
       
   472                 if( !retCode )
       
   473                     {
       
   474                 retCode = policyLeave;
       
   475                     }
       
   476                 }
       
   477             }
       
   478             break;
       
   479             
       
   480         default:
       
   481             {
       
   482             // do nothing
       
   483             }
       
   484         }
       
   485     return retCode;
       
   486     }
       
   487 
       
   488 
       
   489 void CWSStarPlugin::VerifyPermissionOnEachSessionL()
       
   490     {
       
   491 //--    LOG_WRITE_L("CWSStarPlugin::VerifyPermissionOnEachSessionL");
       
   492 
       
   493     CSenWSDescription* pOpenMask = CSenWSDescription::NewLC( KNullDesC8, KNullDesC8 ); // this matches with *any* ServDescription
       
   494     pOpenMask->SetFrameworkIdL(KDefaultWSStarFrameworkID); // now it matches with any WS-* session
       
   495     
       
   496     RWSDescriptionArray all;
       
   497     iManager.ServiceDescriptionsL(all, *pOpenMask);
       
   498     CleanupStack::PopAndDestroy(pOpenMask);
       
   499     CleanupClosePushL(all);
       
   500 
       
   501     TInt count(all.Count());
       
   502     
       
   503 //--    LOG_WRITEFORMAT((_L("- %d WS-* service session(s) found."), count));
       
   504 
       
   505 #ifdef _SENDEBUG
       
   506 //--    TInt verified = 0;
       
   507 #endif // _SENDEBUG    
       
   508 
       
   509     for(TInt i=0; i<count; i++)
       
   510         {   
       
   511         CSenWSDescription* pSD = (CSenWSDescription*)all[i];
       
   512 
       
   513         if(pSD->DescriptionClassType() == MSenServiceDescription::EWSStarServiceSession)
       
   514             {
       
   515             CWSStarServiceSession* pSession = (CWSStarServiceSession*)pSD;
       
   516             pSession->VerifyPermissionL(); // accessible through friendship
       
   517 #ifdef _SENDEBUG            
       
   518 //--            verified++;
       
   519 //--            LOG_WRITEFORMAT((_L("- Verified a session (#%d)"), verified));
       
   520 #endif // _SENDEBUG              
       
   521             }
       
   522         }
       
   523     CleanupStack::PopAndDestroy(&all);
       
   524     }
       
   525 
       
   526 //---------------------------------------------------------------------------
       
   527 // There is no extended interface in WSStar framework at the moment.
       
   528 //---------------------------------------------------------------------------
       
   529 //
       
   530 TAny* CWSStarPlugin::ExtendedInterface()
       
   531     {
       
   532     return NULL;
       
   533     }
       
   534 
       
   535 //---------------------------------------------------------------------------
       
   536 // Return a new instance of a framework specific class that
       
   537 //     implements the ServiceDesccription interface.
       
   538 //---------------------------------------------------------------------------
       
   539 //
       
   540 CSenWSDescription* CWSStarPlugin::NewServiceDescriptionL()
       
   541     {
       
   542     CWSStarServiceSession* pSD =
       
   543         CWSStarServiceSession::NewL(*this);
       
   544     CleanupStack::PushL(pSD);    
       
   545     pSD->SetFrameworkIdL(KDefaultWSStarFrameworkID);
       
   546     CleanupStack::Pop(pSD);
       
   547     return pSD;
       
   548     }
       
   549 
       
   550 //---------------------------------------------------------------------------
       
   551 // Getter for manager
       
   552 //---------------------------------------------------------------------------
       
   553 //
       
   554 MSenCoreServiceManager& CWSStarPlugin::Manager()
       
   555     {
       
   556     return iManager;
       
   557     }
       
   558 //---------------------------------------------------------------------------
       
   559 // Setter for manager
       
   560 //---------------------------------------------------------------------------
       
   561 //
       
   562 void CWSStarPlugin::SetManager(MSenCoreServiceManager& aServiceManager)
       
   563     {
       
   564     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::SetManager(.)")));
       
   565     iManager = aServiceManager;
       
   566     }
       
   567 //---------------------------------------------------------------------------
       
   568 // Getter for configParser
       
   569 //---------------------------------------------------------------------------
       
   570 //
       
   571 CSenBaseFragment& CWSStarPlugin::ConfigParser()
       
   572     {
       
   573     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ConfigParser()")));
       
   574     return *this;
       
   575     //return callbacks which will be invoked during parsing rest of config
       
   576     //this callbacks will be responsible for loading features
       
   577     }
       
   578 
       
   579 //---------------------------------------------------------------------------
       
   580 // UCS2 serializer
       
   581 //---------------------------------------------------------------------------
       
   582 HBufC* CWSStarPlugin::AsXmlUnicodeL()
       
   583     {
       
   584     HBufC8* pUtf8 = AsXmlL();
       
   585     CleanupStack::PushL(pUtf8);
       
   586     HBufC* pAsAxlInUnicode = SenXmlUtils::ToUnicodeLC(*pUtf8);
       
   587     CleanupStack::Pop(pAsAxlInUnicode);
       
   588     CleanupStack::PopAndDestroy(pUtf8); 
       
   589     return pAsAxlInUnicode;
       
   590     }
       
   591 
       
   592 //---------------------------------------------------------------------------
       
   593 // UTF8 serializer
       
   594 //---------------------------------------------------------------------------
       
   595 HBufC8* CWSStarPlugin::AsXmlL()
       
   596     {
       
   597     HBufC8* retVal = HBufC8::NewLC(KMaxLengthXml);
       
   598     TPtr8 ptr = retVal->Des();
       
   599     ptr.Append(KSenLessThan);
       
   600     ptr.Append(KFrameworkLocalName);
       
   601     ptr.Append(KSenSpace);
       
   602     ptr.Append(KSenSpaceXmlns);
       
   603     ptr.Append(KSenEqualsDblQuot);
       
   604     ptr.Append(KFrameworkXMLNS);
       
   605     ptr.Append(KSenDblQuot);
       
   606     
       
   607     ptr.Append(KSenSpace);
       
   608     ptr.Append(KClassAttr);
       
   609     ptr.Append(KSenEqualsDblQuot);
       
   610     ptr.Append(KFrameworkCue);
       
   611     ptr.Append(KSenDblQuot);
       
   612     ptr.Append(KSenGreaterThan);
       
   613 
       
   614    
       
   615 //deviceId
       
   616     ptr.Append(KSenLessThan);
       
   617     ptr.Append(KDeviceIdLocalName);
       
   618     ptr.Append(KSenGreaterThan);
       
   619     if (iDeviceId)
       
   620         {
       
   621         ptr.Append(*iDeviceId);
       
   622         }
       
   623     ptr.Append(KSenLessThanSlash);	
       
   624     ptr.Append(KDeviceIdLocalName);
       
   625     ptr.Append(KSenGreaterThan);
       
   626     
       
   627 //--message handlers    
       
   628     for (TInt i=0; i < iMsgHandlers.Count(); i++)
       
   629         {
       
   630         AddHandlerTag(ptr, iMsgHandlers[i]->Name());
       
   631         }
       
   632 //--session handlers    
       
   633    for (TInt i=0; i < iSessionHandlers.Count(); i++)
       
   634         {
       
   635         AddHandlerTag(ptr, iSessionHandlers[i]->Name());
       
   636         }  
       
   637 
       
   638     ptr.Append(KSenLessThanSlash);
       
   639     ptr.Append(KFrameworkLocalName);
       
   640     ptr.Append(KSenGreaterThan);
       
   641     CleanupStack::Pop(retVal);
       
   642     return retVal;
       
   643     }
       
   644 
       
   645 
       
   646 
       
   647 //---------------------------------------------------------------------------
       
   648 //  used during reading configuration of WSStar framework in order to load 
       
   649 //  proper handlers.
       
   650 //---------------------------------------------------------------------------
       
   651 //
       
   652 void CWSStarPlugin::StartElementL(const TDesC8& /*aNsUri*/,
       
   653                                     const TDesC8& aLocalName,
       
   654                                     const TDesC8& /*aQName*/,
       
   655                                     const RAttributeArray& aAttrs)
       
   656     {
       
   657     if(aLocalName.Compare(KDeviceIdLocalName)==0)
       
   658         {
       
   659             ResetContentL();
       
   660             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::Found deviceId tag")));
       
   661         }
       
   662     else if(aLocalName.Compare(KHandlerLocalName) == 0)
       
   663         {
       
   664         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::Found handler")));
       
   665         TPtrC8 pClass = SenXmlUtils::AttrValue(aAttrs, KClassAttr);
       
   666         TPtrC8 pVersion = SenXmlUtils::AttrValue(aAttrs, KVersionAttr);
       
   667         
       
   668         //message handlers
       
   669         if ((pClass == KAddressingValue) ||
       
   670             (pClass == KEnveloperValue) ||
       
   671             (pClass == KCredentialCollectorValue )||
       
   672             (pClass == KSecurityValue) ||
       
   673             (pClass == KPassportValue))
       
   674             {
       
   675             AddHandlerL(pClass, pVersion, SenHandler::EMessageHandler);
       
   676             }
       
   677         //session handlers
       
   678         else if((pClass == KValidateValue) ||
       
   679                 (pClass == KServiceUpdateValue) ||
       
   680                 (pClass == KRegisterValue) || 
       
   681                 (pClass == KPolicyValue) )
       
   682             {
       
   683             AddHandlerL(pClass, pVersion, SenHandler::ESessionHandler);
       
   684             }
       
   685         else
       
   686             {
       
   687             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin but can not load it")));
       
   688             }
       
   689              
       
   690         }
       
   691     }
       
   692 //---------------------------------------------------------------------------
       
   693 //  used during reading configuration of WSStar framework 
       
   694 //---------------------------------------------------------------------------
       
   695 //
       
   696 void CWSStarPlugin::EndElementL(const TDesC8& aNsUri,
       
   697                                     const TDesC8& aLocalName,
       
   698                                     const TDesC8& aQName)
       
   699     {
       
   700     if(aLocalName.Compare(KDeviceIdLocalName)==0)
       
   701         {
       
   702         TPtrC8 content = Content();
       
   703         if (content.Length()>0)
       
   704             {
       
   705             delete iDeviceId;
       
   706             iDeviceId = NULL;
       
   707             iDeviceId = HBufC8::NewL(content.Length());
       
   708             TPtr8 deviceIdDes = iDeviceId->Des();
       
   709             deviceIdDes.Copy(content);
       
   710             }
       
   711         else
       
   712             {
       
   713             GenerateDeviceIdL();
       
   714             }
       
   715         }
       
   716     else
       
   717         {
       
   718         CSenBaseFragment::EndElementL(aNsUri,aLocalName,aQName);
       
   719         }
       
   720     }
       
   721     
       
   722 //---------------------------------------------------------------------------
       
   723 // getter of handler, using its cue
       
   724 //---------------------------------------------------------------------------
       
   725 //    
       
   726 
       
   727 MSenHandler* CWSStarPlugin::Handler(const TDesC8& aCue)
       
   728     {
       
   729     TInt count = iMsgHandlers.Count();
       
   730     for(TInt i=0;i<count; i++)
       
   731         {
       
   732         if (iMsgHandlers[i]->Name() == aCue)
       
   733             {
       
   734             return iMsgHandlers[i];
       
   735             }
       
   736         }
       
   737     count = iSessionHandlers.Count();
       
   738     for(TInt i=0;i<count; i++)
       
   739         {
       
   740         if (iSessionHandlers[i]->Name() == aCue)
       
   741             {
       
   742             return iSessionHandlers[i];
       
   743             }
       
   744         }
       
   745     return NULL;
       
   746     }
       
   747 //---------------------------------------------------------------------------
       
   748 // remove handler by cue, used during reloading (another version of handler is 
       
   749 //      used than deafault setup)
       
   750 //---------------------------------------------------------------------------
       
   751 //    
       
   752 void CWSStarPlugin::RemoveHandler(const TDesC8& aCue)
       
   753     {
       
   754     TInt count = iMsgHandlers.Count();
       
   755     for(TInt i=0;i<count; i++)
       
   756         {
       
   757         if (iMsgHandlers[i]->Name() == aCue)
       
   758             {
       
   759             delete iMsgHandlers[i];
       
   760             iMsgHandlers.Remove(i);
       
   761             return;
       
   762             }
       
   763         }
       
   764     count = iSessionHandlers.Count();
       
   765     for(TInt i=0;i<count; i++)
       
   766         {
       
   767         if (iSessionHandlers[i]->Name() == aCue)
       
   768             {
       
   769             delete iSessionHandlers[i];
       
   770             iSessionHandlers.Remove(i);
       
   771             return;
       
   772             }
       
   773         }
       
   774     }
       
   775 
       
   776 
       
   777 
       
   778 //---------------------------------------------------------------------------
       
   779 // Process Outbound validation phase
       
   780 //---------------------------------------------------------------------------
       
   781 //     
       
   782 TInt CWSStarPlugin::ProcessOutboundValidationL( MSenServiceDescription& aPattern, 
       
   783                                                 MSenRemoteServiceSession* aRemoteServiceSession,
       
   784                                                 HBufC8*& aErrorMessage )
       
   785     {
       
   786     CSenSessionHandler* pSTShandler = (CSenSessionHandler*)Handler(KValidateValue);
       
   787     CWSStarSessionContext* pSessionValidateCtx = ((CWSStarServiceSession*)aRemoteServiceSession)->SessionContext();
       
   788     if (!pSessionValidateCtx) //sessionCts exist if revalidation is processing
       
   789         {
       
   790         CWSStarPolicyHandler* policyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);
       
   791         pSessionValidateCtx = CWSStarSessionContext::NewLC(Manager().XMLReader(), &aPattern, policyHandler);
       
   792         pSessionValidateCtx->Add(WSStarContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   793         ((CWSStarServiceSession*)aRemoteServiceSession)->SetSessionContext(pSessionValidateCtx);
       
   794         CleanupStack::Pop(pSessionValidateCtx);
       
   795         }
       
   796     else
       
   797         {
       
   798         pSessionValidateCtx->Update(WSStarContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   799         }
       
   800     TInt error(KErrNone);
       
   801     TRAPD(errorL, error = pSTShandler->InvokeL(*pSessionValidateCtx));
       
   802     if ( error )
       
   803         {
       
   804         const TDesC8* pNotOwnedErrorMsg = pSessionValidateCtx->GetDesC8L(WSStarContextKeys::KErrMessage);
       
   805         if ( pNotOwnedErrorMsg )
       
   806             {
       
   807             aErrorMessage = pNotOwnedErrorMsg->AllocL();
       
   808             }
       
   809         }
       
   810     if (errorL!=KErrNone)
       
   811         {
       
   812         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundValidationL() !!!!leave from validate handler")));
       
   813         error = errorL;
       
   814         }
       
   815 #ifdef RD_SEN_VTCP_SUPPORT		
       
   816 	if(error)         
       
   817        {
       
   818         return error;        
       
   819        }
       
   820     CSenSessionHandler* pCoBrandinghandler = (CSenSessionHandler*)Handler(KCoBrandingValue);
       
   821     CWSStarSessionContext* pSessionCoBrandingCtx = ((CWSStarServiceSession*)aRemoteServiceSession)->SessionContext();
       
   822     if (!pSessionCoBrandingCtx) //sessionCts exist if revalidation is processing
       
   823         {
       
   824         CWSStarPolicyHandler* policyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);
       
   825         pSessionCoBrandingCtx = CWSStarSessionContext::NewLC(Manager().XMLReader(), &aPattern, policyHandler);
       
   826         pSessionCoBrandingCtx->Add(WSStarContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   827         ((CWSStarServiceSession*)aRemoteServiceSession)->SetSessionContext(pSessionCoBrandingCtx);
       
   828         CleanupStack::Pop(pSessionCoBrandingCtx);
       
   829         }
       
   830     else
       
   831         {
       
   832         pSessionCoBrandingCtx->Update(WSStarContextKeys::KServiceSession(), *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
   833         }
       
   834 
       
   835     TRAPD(cberrorL, error = pCoBrandinghandler->InvokeL(*pSessionCoBrandingCtx));
       
   836     if ( error )
       
   837         {
       
   838         const TDesC8* pNotOwnedErrorMsg = pSessionCoBrandingCtx->GetDesC8L(WSStarContextKeys::KErrMessage);
       
   839         if ( pNotOwnedErrorMsg )
       
   840             {
       
   841             aErrorMessage = pNotOwnedErrorMsg->AllocL();
       
   842             }
       
   843         }
       
   844     
       
   845     
       
   846     
       
   847     if (cberrorL!=KErrNone)
       
   848         {
       
   849         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundValidationL() !!!!leave from validate handler")));
       
   850         error = cberrorL;
       
   851         }
       
   852 #endif//RD_SEN_VTCP_SUPPORT		
       
   853     return error;
       
   854     }
       
   855     
       
   856     
       
   857     
       
   858 //---------------------------------------------------------------------------
       
   859 // Process Outbound message phase
       
   860 //---------------------------------------------------------------------------
       
   861 //                                          
       
   862 TInt CWSStarPlugin::ProcessOutboundMessageL( CWSStarMessageContext*& aMsgCtx,
       
   863                                              const TDesC8* aBody,
       
   864                                              CSenSoapMessage*& aReadyMsg )
       
   865     {
       
   866 //----------------enveloper
       
   867     TInt error(KErrNone);
       
   868     CSenMessageHandler* pHandler = NULL;
       
   869     aMsgCtx->Update(WSStarContextKeys::KBody, *aBody);
       
   870     if (aReadyMsg)
       
   871         {
       
   872         aMsgCtx->Update(SenContext::KSenCurrentSoapMessageCtxKey, aReadyMsg);
       
   873         }
       
   874     else
       
   875         {
       
   876         pHandler = (CSenMessageHandler*)Handler(KEnveloperValue);
       
   877         if (pHandler)
       
   878             {
       
   879             TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   880             if (errorL!=KErrNone)
       
   881                 {
       
   882                 TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundMessageL() !!!!leave from enveloper handler")));
       
   883                 error = errorL;
       
   884                 }
       
   885             }
       
   886         aReadyMsg = aMsgCtx->GetCurrentSoapMessage();
       
   887         }
       
   888 
       
   889 //----------------passport
       
   890     if (error) return error;
       
   891     pHandler = (CSenMessageHandler*)Handler(KPassportValue);
       
   892     if (pHandler)
       
   893         {
       
   894         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   895         if (errorL!=KErrNone)
       
   896             {
       
   897             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundMessageL() !!!!leave from passport handler")));
       
   898             error = errorL;
       
   899             }
       
   900         }
       
   901     if (error) return error;
       
   902 //----------------addresing 
       
   903 //some  logic which will load oall hanlders and in iteration will produce whole messge
       
   904 //      see axis2\axis2-M2-src\modules\core\src\org\apache\axis\engine\Phase.java
       
   905 //      now just addressing
       
   906     pHandler = (CSenMessageHandler*)Handler(KAddressingValue);
       
   907     if (pHandler)
       
   908         {
       
   909         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   910         if (errorL!=KErrNone)
       
   911             {
       
   912             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundMessageL() !!!!leave from addressing handler")));
       
   913             error = errorL;
       
   914             }
       
   915         }
       
   916     if (error) return error;
       
   917 //--------------------credential collector handler
       
   918 //adding credentials
       
   919     pHandler = (CSenMessageHandler*)Handler(KCredentialCollectorValue);
       
   920     if (pHandler)
       
   921         {
       
   922         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   923         if (errorL!=KErrNone)
       
   924             {
       
   925             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundMessageL() !!!!leave from credentail collector handler")));
       
   926             error = errorL;
       
   927             }
       
   928         }
       
   929     if (error) return error;
       
   930  
       
   931 //--------------------signatureContext handler
       
   932 //getting pop and sign
       
   933     pHandler = (CSenMessageHandler*)Handler(KSecurityValue);
       
   934     if (pHandler)
       
   935         {
       
   936         TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   937         if (errorL!=KErrNone)
       
   938             {
       
   939             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessOutboundMessageL() !!!!leave from security handler")));
       
   940             error = errorL;
       
   941             }
       
   942         }
       
   943     return error;
       
   944     }
       
   945 
       
   946 
       
   947 
       
   948 
       
   949 //---------------------------------------------------------------------------
       
   950 // Process Ibound message phase (body as element)
       
   951 //---------------------------------------------------------------------------
       
   952 //   
       
   953 TInt CWSStarPlugin::ProcessInboundMessageL(CWSStarMessageContext*& aMsgCtx,
       
   954                              CSenSoapMessage*& aMsg)
       
   955     {
       
   956         TInt error(KErrNone);
       
   957         aMsgCtx->Add(SenContext::KSenCurrentSoapMessageCtxKey, aMsg);
       
   958         CSenMessageHandler* pHandler(NULL);
       
   959         
       
   960 //----------------addresing 
       
   961 //some  logic which will load oall hanlders and in iteration will produce whole messge
       
   962 //      see axis2\axis2-M2-src\modules\core\src\org\apache\axis\engine\Phase.java
       
   963 //      now just addressing
       
   964         pHandler = (CSenMessageHandler*)Handler(KAddressingValue);
       
   965         if (pHandler)
       
   966             {
       
   967             TRAPD(errorL, error = pHandler ->InvokeL(*aMsgCtx));            
       
   968             if (errorL!=KErrNone)
       
   969                 {
       
   970                 TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessInboundMessageL() !!!!leave from addressing handler")));
       
   971                 error = errorL;
       
   972                 }
       
   973             }
       
   974         //----------------passport
       
   975         if (error) return error;
       
   976         pHandler = (CSenMessageHandler*)Handler(KPassportValue);
       
   977         if (pHandler)
       
   978             {
       
   979             TRAPD(errorL, error = pHandler->InvokeL(*aMsgCtx));
       
   980             if (errorL!=KErrNone)
       
   981                 {
       
   982                 TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessInboundMessageL() !!!!leave from passport handler")));
       
   983                 error = errorL;
       
   984                 }
       
   985             }
       
   986         return error;
       
   987     }
       
   988         
       
   989         
       
   990 //---------------------------------------------------------------------------
       
   991 // Process Ibound dispatch phase (in fact updatinf session)
       
   992 //---------------------------------------------------------------------------
       
   993 //        
       
   994 TInt CWSStarPlugin::ProcessInboundDispatchL(MSenRemoteServiceSession* aRemoteServiceSession,
       
   995                                            CSenSoapMessage*& aMsg)
       
   996     {
       
   997     CSenSessionHandler* pServiceUpdate = 
       
   998                     (CSenSessionHandler*)Handler(KServiceUpdateValue);
       
   999     CWSStarSessionContext* pSessionCtx = ((CWSStarServiceSession*)aRemoteServiceSession)->SessionContext();
       
  1000     if (pSessionCtx)
       
  1001         {
       
  1002         if (!pSessionCtx->GetSenRemoteServiceSessionL(WSStarContextKeys::KServiceSession))
       
  1003             {
       
  1004             pSessionCtx->Add(WSStarContextKeys::KServiceSession, *(MSenRemoteServiceSession*)aRemoteServiceSession);
       
  1005             }
       
  1006         pSessionCtx->Update(SenContext::KSenCurrentSoapMessageCtxKey, aMsg);
       
  1007         TInt error(KErrNone);
       
  1008         TRAPD(errorL, error = pServiceUpdate->InvokeL(*pSessionCtx));
       
  1009         if (errorL!=KErrNone)
       
  1010             {
       
  1011             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarPlugin::ProcessInboundDispatchL() !!!!leave from Servide Update handler")));
       
  1012             error = errorL;
       
  1013             }
       
  1014         return error;
       
  1015         }
       
  1016     else
       
  1017         {
       
  1018         //in STS session , sessionContext is not set, no dispatching yet in STS session
       
  1019         return KErrNotFound;
       
  1020         }
       
  1021     /*
       
  1022     handle error will know after that revalidateNeeded=ETrue and make ValidateOutboud again
       
  1023         this call Create session in WS*Plugin which checking credential*/
       
  1024 
       
  1025     }
       
  1026 
       
  1027 
       
  1028 //---------------------------------------------------------------------------
       
  1029 // Getter for Device Id.
       
  1030 //---------------------------------------------------------------------------
       
  1031 //        
       
  1032 TInt CWSStarPlugin::DeviceId(TPtrC8& aValue)
       
  1033     {
       
  1034     if (iDeviceId)
       
  1035 	    {
       
  1036         aValue.Set(*iDeviceId);
       
  1037         return KErrNone;
       
  1038         }
       
  1039     else
       
  1040         {
       
  1041         return KErrNotFound;
       
  1042         }
       
  1043     }
       
  1044 
       
  1045 //---------------------------------------------------------------------------
       
  1046 // Generate Device Id
       
  1047 //---------------------------------------------------------------------------
       
  1048 //        
       
  1049 void CWSStarPlugin::GenerateDeviceIdL()
       
  1050     {
       
  1051     CSenGuidGen* pGuidGenerator = CSenGuidGen::NewLC();
       
  1052     delete iDeviceId;
       
  1053     iDeviceId = NULL;
       
  1054     iDeviceId = pGuidGenerator->GetRandomGuid8LC();
       
  1055     TPtr8 deviceIdDes = iDeviceId->Des();
       
  1056     deviceIdDes.LowerCase();
       
  1057     CleanupStack::Pop(iDeviceId);
       
  1058     CleanupStack::PopAndDestroy(pGuidGenerator);
       
  1059     }
       
  1060 //---------------------------------------------------------------------------
       
  1061 // Add handler tag into session.xml
       
  1062 //---------------------------------------------------------------------------
       
  1063 //        
       
  1064 void CWSStarPlugin::AddHandlerTag(TPtr8& aXml, const TDesC8& aHandlerClassName)
       
  1065     {
       
  1066     aXml.Append(KSenLessThan);
       
  1067     aXml.Append(KHandlerLocalName);
       
  1068     aXml.Append(KSenSpace);
       
  1069     //class attr
       
  1070     aXml.Append(KClassAttr);
       
  1071     aXml.Append(KSenEqualsDblQuot);
       
  1072     aXml.Append(aHandlerClassName);
       
  1073     aXml.Append(KSenDblQuot);
       
  1074     TInt index = iVersions.Find(aHandlerClassName);
       
  1075     if (index != KErrNotFound)
       
  1076         {
       
  1077         HBufC8* value = (HBufC8*)iVersions.ValueAt(index);
       
  1078         if (value->Length())
       
  1079             {
       
  1080             aXml.Append(KSenSpace);
       
  1081             aXml.Append(KVersionAttr);
       
  1082             aXml.Append(KSenEqualsDblQuot);
       
  1083             aXml.Append(*value);
       
  1084             aXml.Append(KSenDblQuot);    
       
  1085             }
       
  1086         }   
       
  1087     aXml.Append(KSenSlashGreaterThan);
       
  1088     }
       
  1089     
       
  1090 //---------------------------------------------------------------------------
       
  1091 // Add handler into array, WS* SIF implementation keep handlers after loading
       
  1092 //---------------------------------------------------------------------------
       
  1093 //        
       
  1094 void CWSStarPlugin::AddHandlerL(const TDesC8& aHandlerClassName, const TDesC8& aVersion, SenHandler::THandlerType aType)
       
  1095     {
       
  1096     TInt index = iVersions.Find(aHandlerClassName);
       
  1097     if (index == KErrNotFound)
       
  1098         {
       
  1099         MSenHandler* handler  = NULL;
       
  1100         CWSStarHandlerContext* ctx = NULL;
       
  1101         ctx = CWSStarHandlerContext::NewL();
       
  1102         CleanupStack::PushL(ctx);
       
  1103         //ctx->Add(HandlerContextKey::KLogger, Log());
       
  1104         ctx->Add(iManager);
       
  1105         ctx->Update(HandlerContextKey::KVersion, aVersion);
       
  1106         iVersions.Append(aHandlerClassName.AllocL(), aVersion.AllocL());
       
  1107         if(aType == SenHandler::EMessageHandler)
       
  1108             {
       
  1109             TRAPD(loadError, handler = CSenMessageHandler::NewL(aHandlerClassName, *ctx));    
       
  1110             if (loadError != KErrNone)
       
  1111                 {
       
  1112                 User::Leave(loadError);
       
  1113                 }
       
  1114             else
       
  1115                 {
       
  1116                 iMsgHandlers.Append((CSenMessageHandler*)handler);    
       
  1117                 }    
       
  1118             }
       
  1119         else if (aType == SenHandler::ESessionHandler)
       
  1120             {
       
  1121             ctx->Add(HandlerContextKey::KSIF, this);
       
  1122             TRAPD(loadError, handler = CSenSessionHandler::NewL(aHandlerClassName, *ctx));
       
  1123             if (loadError != KErrNone)
       
  1124                 {
       
  1125                 User::Leave(loadError);
       
  1126                 }
       
  1127             else
       
  1128                 {
       
  1129                 iSessionHandlers.Append((CSenSessionHandler*)handler);
       
  1130                 }        
       
  1131             }
       
  1132         CleanupStack::Pop(ctx);
       
  1133         iHandlerContexts.Append(ctx);
       
  1134         }
       
  1135     else
       
  1136     //reload handler.
       
  1137     //user info from session.xml (in fact this is only for testing , nobody can have access to session.xml)
       
  1138         {
       
  1139         HBufC8* value = (HBufC8*)iVersions.ValueAt(index);
       
  1140         if (*value != aVersion)
       
  1141             {//reload
       
  1142             iVersions.RemoveByKey(aHandlerClassName);
       
  1143             RemoveHandler(aHandlerClassName);
       
  1144             //potentail infinitve reccurence!
       
  1145             AddHandlerL(aHandlerClassName, aVersion, aType);    
       
  1146             }
       
  1147         }
       
  1148     }
       
  1149 
       
  1150 //---------------------------------------------------------------------------
       
  1151 // SetTransportPropertiesL
       
  1152 //---------------------------------------------------------------------------
       
  1153 //        
       
  1154 TInt CWSStarPlugin::SetTransportPropertiesL(MSenTransport& /* aTransport */)
       
  1155     {
       
  1156     return KErrNotSupported; 
       
  1157     }
       
  1158     
       
  1159 MSenHandler* CWSStarPlugin::PolicyHandler()
       
  1160 {
       
  1161     MSenHandler* pPolicyHandler =  Handler(KPolicyValue());
       
  1162     if(pPolicyHandler)
       
  1163     return pPolicyHandler;
       
  1164     else
       
  1165     return NULL;
       
  1166 }
       
  1167 TInt CWSStarPlugin::PolicyConsumerAddedL(CSenServiceSession* aNewSession, MSenRemoteServiceConsumer& aRemoteConsumer)
       
  1168 {
       
  1169     CWSStarPolicyHandler* policyHandler = (CWSStarPolicyHandler*)Handler(WSStarConfig::KPolicyValue);
       
  1170     return policyHandler->PolicyConsumerAddedL(aNewSession,aRemoteConsumer);
       
  1171     
       
  1172 }
       
  1173 // END OF FILE
       
  1174