syncmlfw/dm/provisioningadapter/src/NSmlDmProvisioningAdapter.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
child 27 5cc2995847ea
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
    21 #include <badesca.h>
    21 #include <badesca.h>
    22 #include <commdb.h>
    22 #include <commdb.h>
    23 #include <cdbcols.h>			 // CommsDB columname defs
    23 #include <cdbcols.h>			 // CommsDB columname defs
    24 #include <stringresourcereader.h>
    24 #include <stringresourcereader.h>
    25 #include <barsread.h>
    25 #include <barsread.h>
    26 #include <nsmldmprovisioningadapter.rsg>
    26 #include <NSmlDMProvisioningAdapter.rsg>
    27 #include <f32file.h>
    27 #include <f32file.h>
    28 #include <bautils.h>
    28 #include <bautils.h>
       
    29 #include <ApUtils.h>
    29 #include <utf.h>
    30 #include <utf.h>
    30 #include <featmgr.h>
    31 #include <featmgr.h>
    31 #include <barsc.h> 
    32 #include <barsc.h> 
    32 #include <cmconnectionmethoddef.h>
    33 
    33 #include <cmmanagerext.h>
       
    34 #include <nsmldebug.h>
    34 #include <nsmldebug.h>
    35 #include <CWPCharacteristic.h>
    35 #include <CWPCharacteristic.h>
    36 #include <CWPParameter.h>
    36 #include <CWPParameter.h>
    37 #include <CWPEngine.h>
    37 #include <CWPEngine.h>
    38 #include <NSmlPrivateAPI.h>
    38 #include <NSmlPrivateAPI.h>
    39 #include "NSmlDmProvisioningAdapter.h"
    39 #include "NSmlDmProvisioningAdapter.h"
    40 #include "NSmlTransportHandler.h"
    40 #include "NSmlTransportHandler.h"
    41 
    41 
    42 #include <data_caging_path_literals.hrh>
    42 #include <data_caging_path_literals.hrh>
    43 #define KMINPORT 0
       
    44 #define KMAXPORT 65536
       
    45 
    43 
    46 // ============================ MEMBER FUNCTIONS ===============================
    44 // ============================ MEMBER FUNCTIONS ===============================
    47 
    45 
    48 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    49 // CNSmlDmProvisioningAdapter::CNSmlDmProvisioningAdapter
    47 // CNSmlDmProvisioningAdapter::CNSmlDmProvisioningAdapter
    59 // CNSmlDmProvisioningAdapter::ConstructL
    57 // CNSmlDmProvisioningAdapter::ConstructL
    60 // Symbian 2nd phase constructor can leave.
    58 // Symbian 2nd phase constructor can leave.
    61 // -----------------------------------------------------------------------------
    59 // -----------------------------------------------------------------------------
    62 void CNSmlDmProvisioningAdapter::ConstructL()
    60 void CNSmlDmProvisioningAdapter::ConstructL()
    63 	{
    61 	{
       
    62     iLock = EFalse;
    64 	iSession.OpenL();
    63 	iSession.OpenL();
    65 	FeatureManager::InitializeLibL();
    64 	FeatureManager::InitializeLibL();
    66 	}
    65 	}
    67 
    66 
    68 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
   184 	if (iAuthSecretLimitIndicator)
   183 	if (iAuthSecretLimitIndicator)
   185 	{
   184 	{
   186 		iAuthSecretLimitIndicator = 0;
   185 		iAuthSecretLimitIndicator = 0;
   187 		User::Leave(KErrOverflow);
   186 		User::Leave(KErrOverflow);
   188 	}
   187 	}
   189 	
   188 
   190 	//check for incorrect port
       
   191 	//Only port address between 1 to 65536 is allowed. 
       
   192 	if( iProfiles[aItem]->iPort )
       
   193 		{
       
   194 			const TDesC& port = iProfiles[aItem]->iPort->Des();
       
   195 			TInt len = port.Length();
       
   196 			if(len > 0)
       
   197 			{
       
   198         HBufC* bufPort = port.AllocL();
       
   199         TLex aLex(*bufPort);
       
   200         TInt portNum ;
       
   201         TInt err = aLex.Val(portNum);
       
   202         if(bufPort)
       
   203         {
       
   204           delete bufPort;
       
   205           bufPort = NULL;
       
   206         }
       
   207 	    if(err != KErrNone)
       
   208 	    {
       
   209           User::Leave(KErrGeneral);
       
   210 	    }
       
   211 	    if(!((portNum > KMINPORT) && (portNum < KMAXPORT)))
       
   212 	    {
       
   213 	      User::Leave(KErrGeneral);       
       
   214 	    }
       
   215 		}
       
   216 	}
       
   217 	
       
   218 	TPckgBuf<TUint32> uid;
   189 	TPckgBuf<TUint32> uid;
   219 	
   190 	
   220 	RSyncMLDevManProfile profile,ProfileToSearch;
   191 	RSyncMLDevManProfile profile,ProfileToSearch;
   221 	RArray<TSmlProfileId> arr;
   192 	RArray<TSmlProfileId> arr;
   222   iSession.ListProfilesL( arr, ESmlDevMan );
   193   iSession.ListProfilesL( arr, ESmlDevMan );
   245 		{
   216 		{
   246 		profile.OpenL(iSession, ProfileId , ESmlOpenReadWrite );	
   217 		profile.OpenL(iSession, ProfileId , ESmlOpenReadWrite );	
   247 		TInt isprofilelocked=profile.ProfileLocked(EFalse, EFalse);
   218 		TInt isprofilelocked=profile.ProfileLocked(EFalse, EFalse);
   248 		if (isprofilelocked == 1)
   219 		if (isprofilelocked == 1)
   249 		 {
   220 		 {
   250 		  
   221             profile.ProfileLocked(ETrue, EFalse);
   251       profile.Close(); 
   222             iLock = ETrue;	 	
   252       User::Leave(KErrAccessDenied); 	 	
       
   253 		 }
   223 		 }
   254 		
   224 		
   255 		}
   225 		}
   256 	else
   226 	else
   257 		{
   227 		{
   287 	    {	    
   257 	    {	    
   288 	    profile.SetPasswordL( iProfiles[aItem]->iPassword->Des() );    
   258 	    profile.SetPasswordL( iProfiles[aItem]->iPassword->Des() );    
   289 	    }
   259 	    }
   290 		    
   260 		    
   291 	// creates profile -> must be done before opening the connection
   261 	// creates profile -> must be done before opening the connection
       
   262 
       
   263 	
       
   264 	if(iLock)
       
   265 	    {
       
   266       profile.ProfileLocked(ETrue, ETrue);
       
   267       iLock = EFalse;
       
   268 	    }
       
   269 	    
   292 	profile.UpdateL();
   270 	profile.UpdateL();
   293 	
   271 	
   294 	RSyncMLConnection connection;
   272 	RSyncMLConnection connection;
   295 	connection.OpenL( profile, KUidNSmlMediumTypeInternet.iUid );
   273 	connection.OpenL( profile, KUidNSmlMediumTypeInternet.iUid );
   296 	CleanupClosePushL( connection );
   274 	CleanupClosePushL( connection );
   297 		
   275 		
   298 	if( iProfiles[aItem]->iVisitParameter && iProfiles[aItem]->iVisitParameter->Data().Length() == uid.MaxLength() )
   276 	if( iProfiles[aItem]->iVisitParameter && iProfiles[aItem]->iVisitParameter->Data().Length() == uid.MaxLength() )
   299 		{
   277 		{
   300 		uid.Copy( iProfiles[aItem]->iVisitParameter->Data() );
   278 		uid.Copy( iProfiles[aItem]->iVisitParameter->Data() );
   301 		
   279 
   302 		RCmManagerExt  cmmanagerExt;
   280 		CCommsDatabase* commDb = CCommsDatabase::NewL();
   303 		cmmanagerExt.OpenL();
   281 		CleanupStack::PushL( commDb );
   304 		CleanupClosePushL(cmmanagerExt);
   282 		CApUtils* aputils = CApUtils::NewLC( *commDb );
   305 		RCmConnectionMethodExt cm;
       
   306 		cm = cmmanagerExt.ConnectionMethodL( uid());
       
   307 		CleanupClosePushL( cm );
       
   308 
   283 
   309 		TUint apId = 0;
   284 		TUint apId = 0;
   310 		TRAPD( ERROR, apId = cm.GetIntAttributeL(CMManager::ECmIapId) );
   285 		TRAPD( ERROR, apId = aputils->IapIdFromWapIdL( uid() ) );
   311 		if( ERROR != KErrNone )
   286 		if( ERROR != KErrNone )
   312 			{
   287 			{
   313 			apId = GetDefaultIAPL();
   288 			apId = GetDefaultIAPL();
   314 			}
   289 			}
   315 				
   290 				
   317 		TPtr8 ptrBuf = iapBuf->Des();
   292 		TPtr8 ptrBuf = iapBuf->Des();
   318 		ptrBuf.Num( apId );
   293 		ptrBuf.Num( apId );
   319 
   294 
   320 		connection.SetPropertyL( KNSmlIAPId, *iapBuf );
   295 		connection.SetPropertyL( KNSmlIAPId, *iapBuf );
   321 		
   296 		
   322 		CleanupStack::PopAndDestroy( 3 ); //cmmanager,cm, iapBuf
   297 		CleanupStack::PopAndDestroy( 3 ); //commdb, aputils, iapBuf		
   323 		}
   298 		}
   324 		
   299 		
   325 	if( iProfiles[aItem]->iHostAddress )
   300 	if( iProfiles[aItem]->iHostAddress )
   326 		{
   301 		{
   327 		// see if address contains also port
   302 		// see if address contains also port
   457 		}
   432 		}
   458 	    CleanupStack::PopAndDestroy(); //privateApi
   433 	    CleanupStack::PopAndDestroy(); //privateApi
   459 	    
   434 	    
   460 	    CleanupStack::PopAndDestroy(alertMessage);	    
   435 	    CleanupStack::PopAndDestroy(alertMessage);	    
   461 	    }
   436 	    }
   462 
   437 	    
   463 	CleanupStack::PopAndDestroy( &profile );
   438 	CleanupStack::PopAndDestroy( &profile );
   464 
   439 
   465 	_DBG_FILE("CNSmlDmProvisioningAdapter::SaveL(): end");
   440 	_DBG_FILE("CNSmlDmProvisioningAdapter::SaveL(): end");
   466 	}
   441 	}
   467 
   442