webservices/wsconnectionagent/src/senconnagentsession.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2009 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 #ifdef __ENABLE_ALR__
       
    22 #include <comms-infras/cs_mobility_apiext.h>
       
    23 #endif //__ENABLE_ALR__
       
    24 
       
    25 
       
    26 #include "senconnagentsession.h"
       
    27 #include "senconnagentserver.h"
       
    28 #include "senservicemanagerdefines.h"
       
    29 #include "MSenServiceConsumer.h"
       
    30 
       
    31 #include "MSenAuthenticationProvider.h"
       
    32 #include "SenIdentityProvider.h"
       
    33 #include "msenservicemanager.h"
       
    34 
       
    35 #include "msencobrandinginterface.h"
       
    36 #include "senchunk.h"
       
    37 #include "senxmldebug.h"
       
    38 
       
    39 CSenConnAgentSession::~CSenConnAgentSession()
       
    40     {
       
    41     
       
    42     }
       
    43 
       
    44 void CSenConnAgentSession::ServiceL(const RMessage2& aMessage)
       
    45     {
       
    46     switch (aMessage.Function())
       
    47         {
       
    48         case ESenCliServInitialize:
       
    49             {
       
    50             iObserver = static_cast<MSenFilesObserver*>(
       
    51 					const_cast<TAny*>(aMessage.Ptr0()));
       
    52             aMessage.Complete(KErrNone);
       
    53             ((CActiveSchedulerWait*)aMessage.Ptr1())->AsyncStop();
       
    54             }
       
    55             break;
       
    56         case ESenCliServTransferProgress:
       
    57             {
       
    58             TTransferProgress transfer;
       
    59             TPckg<TTransferProgress> transferPckg(transfer);
       
    60             aMessage.ReadL(0, transferPckg);
       
    61             HBufC8* buf = HBufC8::NewLC(aMessage.GetDesLengthL(1));
       
    62             TPtr8 bufPtr = buf->Des();
       
    63             aMessage.ReadL(1, bufPtr);
       
    64             aMessage.Complete(KErrNone);
       
    65             if (transfer.iSoap)
       
    66                 {
       
    67                 iObserver->TransferProgress(transfer.iTxnId,
       
    68                         transfer.iIncoming, *buf, KNullDesC8, 0);
       
    69                 }
       
    70             else
       
    71                 {
       
    72                 iObserver->TransferProgress(transfer.iTxnId,
       
    73                         transfer.iIncoming, KNullDesC8, *buf, transfer.iProgress);
       
    74                 }
       
    75             CleanupStack::PopAndDestroy(buf);
       
    76           }
       
    77             break;
       
    78         case ESenCliServAuthInitialize:
       
    79             {
       
    80 	        iAuthObserver = static_cast<MSenAuthenticationProvider*>(
       
    81 					const_cast<TAny*>(aMessage.Ptr0()));
       
    82 	        ((CActiveSchedulerWait*)aMessage.Ptr1())->AsyncStop();
       
    83 	        aMessage.Complete(KErrNone);
       
    84             }
       
    85 	        break;
       
    86         case ESenCliServCoBrandingInitialize:
       
    87             {
       
    88 	        ipCoBrandingObserver = static_cast<MSenCoBrandingObserver*>(
       
    89 					const_cast<TAny*>(aMessage.Ptr0()));
       
    90 	        ((CActiveSchedulerWait*)aMessage.Ptr1())->AsyncStop();
       
    91 	        aMessage.Complete(KErrNone);
       
    92             }
       
    93             break;
       
    94 	    case ESenCliServReAuthNeeded:
       
    95 	        {
       
    96 	    	TInt retVal(KErrNone);
       
    97 	    	TRAPD(error, retVal = ReauthenticationNeededL(aMessage));
       
    98 	    	if(error)
       
    99 	    		{
       
   100 	    		retVal = error;
       
   101 	    		}
       
   102 	    	aMessage.Complete(retVal);
       
   103 	    	CActiveSchedulerWait* wait = static_cast<CActiveSchedulerWait*>(
       
   104 					const_cast<TAny*>(aMessage.Ptr1()));
       
   105 	    	if(wait && wait->IsStarted())
       
   106 	    		{
       
   107 	    		wait->AsyncStop();
       
   108 	    		}
       
   109 	    		}
       
   110         	break;
       
   111         case ESenCliServGoNoGo:
       
   112             {
       
   113 	    	TInt retValue(KErrNone);
       
   114 	    	TRAPD(CBerror, retValue = CoBrandingGoNoGoL(aMessage));
       
   115 	    	if(CBerror)
       
   116 	    		{
       
   117 	    		retValue = CBerror;
       
   118 	    		}
       
   119 	    	aMessage.Complete(retValue);
       
   120             }
       
   121         	break;
       
   122 
       
   123 #ifdef __ENABLE_ALR__
       
   124         case ESenCliServMobilityInitialize:
       
   125             {
       
   126             iMobiltyObserver = static_cast<MMobilityProtocolResp*>(
       
   127 					const_cast<TAny*>(aMessage.Ptr0()));
       
   128             aMessage.Complete(KErrNone);
       
   129             ((CActiveSchedulerWait*)aMessage.Ptr1())->AsyncStop();                
       
   130             }
       
   131             break;
       
   132         case ESenCliServPrefferedCarrierAvailable:
       
   133             {
       
   134             TInt oldap = aMessage.Int0();
       
   135             TInt newap= aMessage.Int1();
       
   136             
       
   137             TAccessPointInfo oldAPInfo ;
       
   138             oldAPInfo.SetAccessPoint( oldap );
       
   139             TAccessPointInfo newAPInfo ;
       
   140             newAPInfo.SetAccessPoint( newap );
       
   141 
       
   142             HBufC8* upgradeBuf = HBufC8::NewLC(10);
       
   143             TPtr8 upgradeBuffer = upgradeBuf->Des();
       
   144             aMessage.ReadL(2, upgradeBuffer); 
       
   145             TBool isUpgrade = (TBool)(*upgradeBuffer.Ptr()) ;
       
   146             CleanupStack::PopAndDestroy(upgradeBuf); 
       
   147             
       
   148             HBufC8* seemlessBuf = HBufC8::NewLC(10);
       
   149             TPtr8 seemlessBuffer = seemlessBuf->Des();
       
   150             aMessage.ReadL(3, seemlessBuffer); 
       
   151             TBool isSeamless = (TBool)(*seemlessBuffer.Ptr()) ;
       
   152             CleanupStack::PopAndDestroy(seemlessBuf); 
       
   153             
       
   154             aMessage.Complete(KErrNone);
       
   155             // check for mobility observer and forward the call to the observer (application)
       
   156             if(iMobiltyObserver)
       
   157                 {
       
   158                 iMobiltyObserver->PreferredCarrierAvailable(oldAPInfo, newAPInfo, isUpgrade, isSeamless) ;
       
   159                 }
       
   160             }
       
   161             break;
       
   162         case ESenCliServNewCarrierActive:
       
   163             {
       
   164             TInt newap = aMessage.Int0();
       
   165             TAccessPointInfo newAPInfo ;
       
   166             newAPInfo.SetAccessPoint( newap );
       
   167             HBufC8* inBuf = HBufC8::NewLC(10);
       
   168             TPtr8 inBuffer = inBuf->Des();
       
   169             aMessage.ReadL(1, inBuffer); 
       
   170             TBool isSeamless = (TBool)(*inBuffer.Ptr()) ;
       
   171             CleanupStack::PopAndDestroy(inBuf); 
       
   172             aMessage.Complete(KErrNone);
       
   173             // check for mobility observer and forward the call to the observer (application)
       
   174             if(iMobiltyObserver)
       
   175                 {
       
   176                 iMobiltyObserver->NewCarrierActive(newAPInfo, isSeamless) ;
       
   177                 }
       
   178             }
       
   179             break;
       
   180         case ESenCliServMobilityError:
       
   181             {
       
   182         	TInt mobilityError = aMessage.Int0();
       
   183             aMessage.Complete(KErrNone);
       
   184             // check for mobility observer and forward the call to the observer (application)
       
   185             if(iMobiltyObserver)
       
   186                 {
       
   187                 iMobiltyObserver->Error(mobilityError);
       
   188                 }
       
   189             }
       
   190             break;
       
   191 #endif //__ENABLE_ALR__
       
   192         default:
       
   193             {
       
   194             aMessage.Complete(KErrNotSupported);
       
   195             }
       
   196             break;
       
   197         }
       
   198     }
       
   199 
       
   200 void CSenConnAgentSession::Disconnect(const RMessage2& aMessage)
       
   201     {
       
   202     CSession2::Disconnect(aMessage);
       
   203     CSenConnAgentServer* server = reinterpret_cast<CSenConnAgentServer*>
       
   204             (Dll::Tls());
       
   205     ASSERT(server);
       
   206     server->DestroyIfInactive();
       
   207     }
       
   208 TInt CSenConnAgentSession::CoBrandingGoNoGoL(const RMessage2& aMessage)
       
   209     {
       
   210     TBool* goNoGo = static_cast<TBool*>(
       
   211 					const_cast<TAny*>(aMessage.Ptr0()));    
       
   212 
       
   213 	HBufC8* buf = HBufC8::NewLC(aMessage.GetDesLengthL(1));
       
   214 	TPtr8 bufPtr = buf->Des();
       
   215 	aMessage.ReadL(1, bufPtr);
       
   216     
       
   217     RBuf8* selectedbrandID = static_cast<RBuf8*>(
       
   218 					const_cast<TAny*>(aMessage.Ptr2()));
       
   219 
       
   220     if (ipCoBrandingObserver)
       
   221         {
       
   222         *goNoGo = ipCoBrandingObserver->OnGetBrandIdL(*buf,*selectedbrandID);  
       
   223 				CleanupStack::PopAndDestroy(buf);        
       
   224         return KErrNone;
       
   225         }
       
   226         
       
   227 		CleanupStack::PopAndDestroy(buf);        
       
   228     return KErrGeneral;
       
   229     }
       
   230 TInt CSenConnAgentSession::ReauthenticationNeededL(const RMessage2& aMessage)
       
   231 	{
       
   232 	TInt retVal = KErrNone;
       
   233 	TBool providerCreated = EFalse;
       
   234 	
       
   235 	if(iAuthObserver)
       
   236 		{
       
   237 		CSenChunk* pSenChunk = CSenChunk::NewLC(KNullDesC());
       
   238 		retVal = pSenChunk->OpenChunkFromRMsgL(aMessage,0);
       
   239 		
       
   240 		if(retVal == KErrNone)
       
   241 			{
       
   242 	    	CSenIdentityProvider* pIdP = 
       
   243 	    		(CSenIdentityProvider*)iAuthObserver->IdentityProviderL();
       
   244 	    	
       
   245 	    	if(!pIdP)
       
   246 	    		{
       
   247 	    		TPtrC8 identityProvider;
       
   248 	    		retVal = pSenChunk->DescFromChunk(identityProvider);
       
   249 	    		
       
   250 	    		if(retVal == KErrNone)
       
   251 	    			{
       
   252 			    	pIdP = CSenIdentityProvider::NewLC(KNullDesC8());
       
   253 			    	providerCreated = ETrue;
       
   254 			    	CSenXmlReader* pXmlReader = CSenXmlReader::NewLC(KXmlParserMimeType);
       
   255 			    	pXmlReader->SetContentHandler( *pIdP );
       
   256 			    	pIdP->SetReader(*pXmlReader);
       
   257 			    	
       
   258 			    	pIdP->ParseL( identityProvider );
       
   259 			    	CleanupStack::PopAndDestroy(pXmlReader);
       
   260 			    		
       
   261 			    	TPtrC8 userName = iAuthObserver->UsernameL();
       
   262 			        TPtrC8 password = iAuthObserver->PasswordL();
       
   263 			        if(pIdP && userName != KNullDesC8 && password != KNullDesC8 )
       
   264 			        	{
       
   265 				        retVal = pIdP->SetUserInfoL( userName ,
       
   266 											   		 userName ,
       
   267 											   		 password );
       
   268 			        	}
       
   269 	    			}
       
   270 	    		}
       
   271 	    	
       
   272 	    	if(pIdP)
       
   273 	    		{
       
   274 	    		// Identity provider data retrieved from callback, return it
       
   275 	    		HBufC8* desIdP = pIdP->AsXmlL();
       
   276 	    		CleanupStack::PushL(desIdP);
       
   277 	    		pSenChunk->DescToChunk(*desIdP);
       
   278 	    		CleanupStack::PopAndDestroy(desIdP);
       
   279 	    		}
       
   280 	    	else
       
   281 	    		{
       
   282 	    		// Identity provider was not passed
       
   283 	    		retVal = KErrNotFound;
       
   284 	    		}
       
   285 	    	
       
   286 	    	if(providerCreated)
       
   287 	    		{
       
   288 	    		CleanupStack::PopAndDestroy(pIdP);
       
   289 	    		}
       
   290 			}
       
   291 		CleanupStack::PopAndDestroy(pSenChunk);
       
   292 		}
       
   293 	else
       
   294 		{
       
   295 		retVal = KErrNotReady;
       
   296 		}
       
   297 	return retVal;
       
   298 	}