webservices/wsstar/wsstarplugin/src/wsstarregisterhandler.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 #include "wsstarregisterhandler.h"
       
    26 #include "wsstartrustclient.h"
       
    27 #include "sendebug.h"
       
    28 #include "senlogger.h"
       
    29 
       
    30 
       
    31 class CWSStarHandlerContext;
       
    32 // Create instance of concrete ECOM interface implementation
       
    33 CWSStarRegisterHandler* CWSStarRegisterHandler::NewL(TAny* aHandlerCtx)
       
    34     {
       
    35     
       
    36     MSenHandlerContext* handlerCtx =
       
    37         reinterpret_cast<MSenHandlerContext*>(aHandlerCtx);
       
    38     CWSStarRegisterHandler* self   = new (ELeave) CWSStarRegisterHandler(*handlerCtx);
       
    39     CleanupStack::PushL (self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop(self);
       
    42     return self;
       
    43     }
       
    44 
       
    45 // Constructor
       
    46 CWSStarRegisterHandler::CWSStarRegisterHandler(MSenHandlerContext& aCtx):CSenSessionHandler(aCtx)
       
    47     {
       
    48     
       
    49     }
       
    50 
       
    51 // Destructor
       
    52 CWSStarRegisterHandler::~CWSStarRegisterHandler()
       
    53     {
       
    54     }
       
    55 
       
    56 // Second phase construction.
       
    57 void CWSStarRegisterHandler::ConstructL()
       
    58     {
       
    59     }
       
    60     
       
    61 TInt CWSStarRegisterHandler::InvokeL(MSenSessionContext& aCtx)
       
    62     {
       
    63     MSenServiceDescription& pServiceDescription = *(MSenServiceDescription*)aCtx.GetSenWSDescriptionL(WSStarContextKeys::KServiceDescription());
       
    64     const TDesC8* action = aCtx.GetDesC8L(WSStarContextKeys::KRegisterAction());
       
    65     TInt result(KErrNone);
       
    66     if (*action == WSStarContextValues::KActionRegister())
       
    67         {
       
    68         result = RegisterServiceDescriptionL(pServiceDescription);
       
    69         }
       
    70     else if (*action == WSStarContextValues::KActionUnregister())
       
    71         {
       
    72         result = UnregisterServiceDescriptionL(pServiceDescription);
       
    73         };
       
    74     return result;  
       
    75     }
       
    76     
       
    77 SenHandler::THandlerDirection CWSStarRegisterHandler::Direction() const
       
    78     {
       
    79         return SenHandler::EBoth;
       
    80     };
       
    81 SenHandler::THandlerPhase CWSStarRegisterHandler::Phase()
       
    82     {
       
    83         return SenHandler::EDiscovery;
       
    84     };
       
    85 
       
    86 //---------------------------------------------------------------------------
       
    87 // Attempt to register the ServiceDescription to the ServiceManager 
       
    88 //---------------------------------------------------------------------------
       
    89 //
       
    90 TInt CWSStarRegisterHandler::RegisterServiceDescriptionL(MSenServiceDescription& aServiceDescription )
       
    91     {
       
    92     TInt retval(KErrNone);
       
    93     CWSStarServiceSession* pSession = NULL;
       
    94     TPtrC8 contract = aServiceDescription.Contract();
       
    95     TPtrC8 endpoint = aServiceDescription.Endpoint();
       
    96 
       
    97     if (contract == KNullDesC8) 
       
    98         {
       
    99         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarRegisterHandler::RegisterServiceDescriptionL failed - KErrSenNoContract");
       
   100         retval = KErrSenNoContract;
       
   101         }
       
   102     else if(endpoint == KNullDesC8)
       
   103         {
       
   104         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarRegisterHandler::RegisterServiceDescriptionL failed - KErrSenNoEndpoint");
       
   105         retval = KErrSenNoEndpoint;
       
   106         }
       
   107     else
       
   108         {
       
   109         if(contract == KWSStarSTSContract)
       
   110             {
       
   111             retval = RegisterSTSClientL(&aServiceDescription);
       
   112             }
       
   113         else if (aServiceDescription.DescriptionClassType() ==
       
   114                         MSenServiceDescription::EWSStarServiceSession)
       
   115             {
       
   116             //  description already is a session so we just add to core-DAO
       
   117             //  example:    when connection has been made, and service is registered 
       
   118             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarRegisterHandler::RegisterServiceDescriptionL - session is already so just adding")));
       
   119                 pSession = (CWSStarServiceSession*) &aServiceDescription;
       
   120                 retval = iHandlerContext.GetSenCoreServiceManager()->AddServiceDescriptionL(pSession);
       
   121             }
       
   122         else
       
   123             {
       
   124             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarRegisterHandler::RegisterServiceDescriptionL - Creating session from description...")));
       
   125             pSession = CWSStarServiceSession::NewLC(*(CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF()));	//codescannerwarnings
       
   126             //example:  when description has been read from db during bootup
       
   127             //          session has to be initialized (set validity time for example)
       
   128             retval = pSession->InitializeFromL(aServiceDescription);
       
   129             if (retval == KErrNone)
       
   130                 {
       
   131                 retval = iHandlerContext.GetSenCoreServiceManager()->AddServiceDescriptionL(pSession);
       
   132                 CleanupStack::Pop(pSession);
       
   133                 }
       
   134             else
       
   135                 {
       
   136                 CleanupStack::PopAndDestroy(pSession);
       
   137                 }
       
   138             }
       
   139         }
       
   140     return retval;
       
   141     }
       
   142     
       
   143     
       
   144 //---------------------------------------------------------------------------
       
   145 // Attempt to unregister the ServiceDescription from the ServiceManager 
       
   146 //---------------------------------------------------------------------------
       
   147 //
       
   148 TInt CWSStarRegisterHandler::UnregisterServiceDescriptionL(
       
   149     MSenServiceDescription& aServiceDescription)
       
   150     {
       
   151     TInt retval(KErrNone);
       
   152     CWSStarServiceSession *pSession = NULL;
       
   153     TPtrC8 contract = aServiceDescription.Contract();
       
   154 
       
   155     if(contract == KWSStarSTSContract)
       
   156         {
       
   157         retval = UnRegisterSTSClientL(&aServiceDescription);
       
   158         }
       
   159     else
       
   160         {
       
   161         if(aServiceDescription.DescriptionClassType() ==
       
   162                 MSenServiceDescription::EWSStarServiceSession)
       
   163             {
       
   164             pSession = (CWSStarServiceSession*) &aServiceDescription;
       
   165             retval = iHandlerContext.GetSenCoreServiceManager()->RemoveServiceDescriptionL(*pSession);
       
   166             }
       
   167         else
       
   168             {
       
   169 
       
   170             pSession = CWSStarServiceSession::NewLC(*(CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF()));	//codescannerwarnings
       
   171             retval = pSession->InitializeFromL(aServiceDescription);
       
   172             if (retval == KErrNone)
       
   173                 {
       
   174                 retval = iHandlerContext.GetSenCoreServiceManager()->RemoveServiceDescriptionL(*pSession);
       
   175                 }
       
   176             CleanupStack::PopAndDestroy(pSession);
       
   177             }
       
   178         }
       
   179 
       
   180     return retval;
       
   181     }    
       
   182 
       
   183 //---------------------------------------------------------------------------
       
   184 // Register specific description (STS contract)
       
   185 //---------------------------------------------------------------------------
       
   186 //    
       
   187 TInt CWSStarRegisterHandler::RegisterSTSClientL(
       
   188                                 MSenServiceDescription *aServiceDescription)
       
   189     {
       
   190     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarRegisterHandler::RegisterSTSClientL");
       
   191     
       
   192     TPtrC8 endpoint = aServiceDescription->Endpoint();
       
   193     TInt retval = KErrNone;
       
   194     CWSStarServiceSession* pSession = NULL;
       
   195     CWSStarTrustClient* pSTSClient = NULL;
       
   196 
       
   197     if(aServiceDescription->DescriptionClassType() ==
       
   198                 MSenServiceDescription::EWSStarSTSClient)
       
   199         {
       
   200         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarRegisterHandler::RegisterSTSClient - This ServiceDescription is already an STS Client")));
       
   201         pSTSClient = (CWSStarTrustClient*)aServiceDescription;
       
   202         retval = iHandlerContext.GetSenCoreServiceManager()->AddServiceDescriptionL(pSTSClient);
       
   203         }
       
   204     else
       
   205         {
       
   206         // Create new STS client and initialize
       
   207         // it from given description
       
   208         pSession = CWSStarServiceSession::NewLC(*(CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF()));	//codescannerwarnings
       
   209         retval = pSession->InitializeFromL(*aServiceDescription);
       
   210 
       
   211         if(retval != KErrNone)
       
   212             {
       
   213             TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("CWSStarRegisterHandler::RegisterSTSClientL failed %d"), retval));
       
   214             CleanupStack::PopAndDestroy(pSession);
       
   215             return retval;
       
   216             }
       
   217         TPtrC8 sessionEndpoint = pSession->Endpoint();
       
   218             TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMinLogLevel, _L8("CWSStarRegisterHandler::RegisterSTSClientL created STS using endpoint:'%S'"), &sessionEndpoint));
       
   219 
       
   220         pSTSClient = CWSStarTrustClient::NewLC(*(CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF()), *Log());	//codescannerwarnings
       
   221         pSTSClient->SetSTSSessionL(pSession);    // pSession will be owned by STSClient
       
   222         CleanupStack::Pop(pSTSClient);
       
   223         CleanupStack::Pop(pSession);
       
   224         CleanupStack::PushL(pSTSClient);
       
   225 
       
   226         retval = iHandlerContext.GetSenCoreServiceManager()->AddServiceDescriptionL(pSTSClient);
       
   227         if(retval != KErrNone)
       
   228             {
       
   229             delete pSTSClient;
       
   230             }
       
   231         CleanupStack::Pop(pSTSClient); 
       
   232         pSTSClient = NULL;
       
   233         }
       
   234     return retval;
       
   235     }
       
   236 
       
   237 //---------------------------------------------------------------------------
       
   238 // Unregister specific description (STS contract)
       
   239 //---------------------------------------------------------------------------
       
   240 //    
       
   241 
       
   242 TInt CWSStarRegisterHandler::UnRegisterSTSClientL(
       
   243                                 MSenServiceDescription *aServiceDescription)
       
   244     {
       
   245     TInt retval = KErrNone;
       
   246 
       
   247     CWSStarServiceSession *pSession = NULL;
       
   248     CWSStarTrustClient *pSTSClient = NULL;
       
   249 
       
   250     if(aServiceDescription->DescriptionClassType() ==
       
   251                 MSenServiceDescription::EWSStarSTSClient)
       
   252         {
       
   253         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarRegisterHandler::RegisterSTSClient - This ServiceDescription is already an STS Client")));
       
   254         pSTSClient = (CWSStarTrustClient*)aServiceDescription;
       
   255         retval = iHandlerContext.GetSenCoreServiceManager()->RemoveServiceDescriptionL(*pSTSClient);
       
   256         }
       
   257     else
       
   258         {
       
   259         
       
   260         pSession = CWSStarServiceSession::NewLC(*(CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF()));	//codescannerwarnings
       
   261         retval = pSession->InitializeFromL(*aServiceDescription);
       
   262         if(retval != KErrNone)
       
   263             {
       
   264             CleanupStack::PopAndDestroy(pSession);
       
   265             return retval;
       
   266             }
       
   267         pSTSClient = CWSStarTrustClient::NewLC(*(CSIF*)iHandlerContext.GetAnyL(HandlerContextKey::KSIF()), *Log());	//codescannerwarnings
       
   268         pSTSClient->SetSTSSessionL(pSession);    // pSession will be owned by STSClient
       
   269         CleanupStack::Pop(pSTSClient);
       
   270         CleanupStack::Pop(pSession);
       
   271         CleanupStack::PushL(pSTSClient);
       
   272 
       
   273         retval = iHandlerContext.GetSenCoreServiceManager()->RemoveServiceDescriptionL(*pSTSClient);
       
   274         CleanupStack::PopAndDestroy(pSTSClient);
       
   275         }
       
   276 
       
   277     return retval;
       
   278     }    
       
   279     
       
   280 //---------------------------------------------------------------------------
       
   281 // Logger using during DEBUG mode
       
   282 //---------------------------------------------------------------------------
       
   283 //    
       
   284 RFileLogger* CWSStarRegisterHandler::Log() const
       
   285     {
       
   286     RFileLogger* pLog = NULL;
       
   287     TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); )
       
   288     return pLog;
       
   289     }
       
   290 
       
   291 TInt CWSStarRegisterHandler::InitL(MSenHandlerContext& aCtx)
       
   292     {
       
   293     iHandlerContext = aCtx;
       
   294     return KErrNone;
       
   295     }
       
   296     
       
   297 // END OF FILE
       
   298