creator/engine/src/creator_accesspoint.cpp
branchRCL_3
changeset 21 b3cee849fa46
equal deleted inserted replaced
20:48060abbbeaf 21:b3cee849fa46
       
     1 /*
       
     2 * Copyright (c) 2010 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 //#include "creator_accesspoint.h" 
       
    22 #include "creator_traces.h"
       
    23 #include <ApListItemList.h>
       
    24 #include <ApListItem.h> 
       
    25 #include "enginewrapper.h"
       
    26 
       
    27 static const TInt KAccessPointsFieldLength = 128;
       
    28 
       
    29 _LIT(KCreatorAccessPointsPrefixName, "CR_");
       
    30 _LIT(KZeroIP, "0.0.0.0");
       
    31 
       
    32 //----------------------------------------------------------------------------
       
    33 
       
    34 CAccessPointsParameters::CAccessPointsParameters()
       
    35     {
       
    36     LOGSTRING("Creator: CAccessPointsParameters::CAccessPointsParameters");
       
    37 
       
    38     iConnectionName = HBufC::New(KAccessPointsFieldLength);
       
    39     iWapStartPage = HBufC::New(KAccessPointsFieldLength);
       
    40     iGprsAcessPointName = HBufC::New(KAccessPointsFieldLength);
       
    41     iIspLoginName = HBufC::New(KAccessPointsFieldLength);
       
    42     iIspLoginPass = HBufC::New(KAccessPointsFieldLength);
       
    43     iWapGatewayAddress = HBufC::New(KAccessPointsFieldLength);
       
    44     iIspIPAddr = HBufC::New(KAccessPointsFieldLength);
       
    45     iIspIPNameServer1 = HBufC::New(KAccessPointsFieldLength);
       
    46     iIspIPNameServer2 = HBufC::New(KAccessPointsFieldLength);
       
    47     iIspDefaultTelNumber = HBufC::New(KAccessPointsFieldLength);
       
    48     iProxyServerAddress = HBufC::New(KAccessPointsFieldLength);
       
    49     }
       
    50 
       
    51 CAccessPointsParameters::~CAccessPointsParameters()
       
    52     {
       
    53     LOGSTRING("Creator: CAccessPointsParameters::~CAccessPointsParameters");
       
    54 
       
    55     delete iProxyServerAddress;
       
    56     delete iIspDefaultTelNumber;
       
    57     delete iIspIPNameServer2;
       
    58     delete iIspIPNameServer1;
       
    59     delete iIspIPAddr;
       
    60     delete iWapGatewayAddress;
       
    61     delete iIspLoginPass;
       
    62     delete iIspLoginName;
       
    63     delete iGprsAcessPointName;
       
    64     delete iWapStartPage;
       
    65     delete iConnectionName;
       
    66     }
       
    67 
       
    68 void CAccessPointsParameters::SetRandomCMNameL(CCreatorEngine& aEngine)
       
    69 	{
       
    70 	TInt num = aEngine.RandomNumber(1, 3);
       
    71 	TBuf<10> apType;
       
    72 
       
    73 	if (num==1)
       
    74 		apType = _L("mms");
       
    75 	else if (num==2)
       
    76 		apType = _L("wap");
       
    77 	else
       
    78 		apType = _L("internet");
       
    79 
       
    80 	TBuf<160> company = aEngine.RandomString(CCreatorEngine::ECompany);
       
    81 
       
    82 	iConnectionName->Des() = KCreatorAccessPointsPrefixName;
       
    83 	iConnectionName->Des().Append( company );
       
    84 	iConnectionName->Des().Append(_L(" "));
       
    85 	iConnectionName->Des().Append(apType);
       
    86 	}
       
    87 
       
    88 void CAccessPointsParameters::SetRandomLoginNameL(CCreatorEngine& aEngine)
       
    89 	{
       
    90 	iIspLoginName->Des() = aEngine.RandomString(CCreatorEngine::EFirstName);
       
    91 	iIspLoginName->Des().LowerCase();
       
    92 	}
       
    93 
       
    94 void CAccessPointsParameters::SetRandomLoginPassL(CCreatorEngine& /*aEngine*/)
       
    95 	{}
       
    96 
       
    97 void CAccessPointsParameters::SetRandomSecureAuthenticationL(CCreatorEngine& /*aEngine*/)
       
    98 	{}
       
    99 
       
   100 void CAccessPointsParameters::SetRandomPromptPasswordL(CCreatorEngine& /*aEngine*/)
       
   101 	{}
       
   102 
       
   103 void CAccessPointsParameters::SetRandomProxyAddressL(CCreatorEngine& /*aEngine*/)
       
   104 	{}
       
   105 
       
   106 void CAccessPointsParameters::SetRandomProxyPortL(CCreatorEngine& /*aEngine*/)
       
   107 	{}
       
   108 
       
   109 void CAccessPointsParameters::SetRandomStartPageL(CCreatorEngine& /*aEngine*/)
       
   110 	{}
       
   111 
       
   112 void CAccessPointsParameters::SetRandomIPAddressL(CCreatorEngine& /*aEngine*/)
       
   113 	{}
       
   114 
       
   115 void CAccessPointsParameters::SetRandomIP4NameServer1L(CCreatorEngine& /*aEngine*/)
       
   116 	{}
       
   117 
       
   118 void CAccessPointsParameters::SetRandomIP4NameServer2L(CCreatorEngine& /*aEngine*/)
       
   119 	{}
       
   120 
       
   121 void CAccessPointsParameters::SetRandomTelephoneNumberL(CCreatorEngine& /*aEngine*/)
       
   122 	{}
       
   123 
       
   124 void CAccessPointsParameters::SetRandomBearerTypeIsdnL(CCreatorEngine& /*aEngine*/)
       
   125 	{}
       
   126 
       
   127 void CAccessPointsParameters::SetRandomBearerSpeedL(CCreatorEngine& /*aEngine*/)
       
   128 	{}
       
   129 
       
   130 void CAccessPointsParameters::SetRandomWapWspOptionL(CCreatorEngine& /*aEngine*/)
       
   131 	{}
       
   132 
       
   133 void CAccessPointsParameters::SetRandomGatewayAddressL(CCreatorEngine& /*aEngine*/)
       
   134 	{}
       
   135 
       
   136 //----------------------------------------------------------------------------
       
   137 
       
   138 CCreatorAccessPoints* CCreatorAccessPoints::NewL(CCreatorEngine* aEngine)
       
   139     {
       
   140     CCreatorAccessPoints* self = CCreatorAccessPoints::NewLC(aEngine);
       
   141     CleanupStack::Pop(self);
       
   142     return self;
       
   143     }
       
   144 
       
   145 CCreatorAccessPoints* CCreatorAccessPoints::NewLC(CCreatorEngine* aEngine)
       
   146     {
       
   147     CCreatorAccessPoints* self = new (ELeave) CCreatorAccessPoints;
       
   148     CleanupStack::PushL(self);
       
   149     self->ConstructL(aEngine);
       
   150     return self;
       
   151     }
       
   152 
       
   153 CCreatorAccessPoints::CCreatorAccessPoints()
       
   154     {
       
   155     }
       
   156 
       
   157 void CCreatorAccessPoints::ConstructL(CCreatorEngine* aEngine)
       
   158     {
       
   159     LOGSTRING("Creator: CCreatorAccessPoints::ConstructL");
       
   160 
       
   161     iEngine = aEngine;
       
   162 
       
   163     iCommsDb = CCommsDatabase::NewL();;
       
   164     iApDataHandler = CApDataHandler::NewLC(*iCommsDb);
       
   165     CleanupStack::Pop();
       
   166     iApUtils = CApUtils::NewLC(*iCommsDb);
       
   167     CleanupStack::Pop();
       
   168     }
       
   169 
       
   170 CCreatorAccessPoints::~CCreatorAccessPoints()
       
   171     {
       
   172     LOGSTRING("Creator: CCreatorAccessPoints::~CCreatorAccessPoints");
       
   173 
       
   174     if ( iEngine && iEntryIds.Count() )
       
   175         {
       
   176         TRAP_IGNORE( iEngine->WriteEntryIdsToStoreL( iEntryIds, KUidDictionaryUidIAP ) );
       
   177         }
       
   178     iEntryIds.Reset();
       
   179     iEntryIds.Close();
       
   180     
       
   181     delete iApUtils;
       
   182     delete iApDataHandler;
       
   183     delete iCommsDb;
       
   184 
       
   185     if (iParameters)
       
   186         delete iParameters;
       
   187     }
       
   188 
       
   189 //----------------------------------------------------------------------------
       
   190 
       
   191 TBool CCreatorAccessPoints::AskDataFromUserL(TInt aCommand)
       
   192     {
       
   193     LOGSTRING("Creator: CCreatorAccessPoints::AskDataFromUserL");
       
   194     
       
   195     CCreatorModuleBase::AskDataFromUserL( aCommand );//ignore retval
       
   196     
       
   197     if( aCommand == ECmdDeleteIAPs )
       
   198         {
       
   199         return iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Delete all Access Points?"), this, ECreatorModuleDelete );
       
   200         }
       
   201     else if( aCommand == ECmdDeleteCreatorIAPs )
       
   202         {
       
   203         return iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Delete all Access Points created with Creator?"), this, ECreatorModuleDelete );
       
   204         }
       
   205 
       
   206     return iEngine->GetEngineWrapper()->EntriesQueryDialog(&iEntriesToBeCreated, _L("How many entries to create?"), EFalse, this, ECreatorModuleStart );
       
   207     }
       
   208 
       
   209 
       
   210 //----------------------------------------------------------------------------
       
   211 
       
   212 TInt CCreatorAccessPoints::CreateConnectionSettingsEntryL(CCreatorModuleBaseParameters *aParameters)
       
   213     {
       
   214     LOGSTRING("Creator: CCreatorAccessPoints::CreateAccessPointEntryL");
       
   215 
       
   216     CAccessPointsParameters* parameters = (CAccessPointsParameters*) aParameters;
       
   217     
       
   218     // clear any existing parameter definations
       
   219     delete iParameters;
       
   220     iParameters = NULL;
       
   221     
       
   222     
       
   223             
       
   224     // random data needed if no predefined data available
       
   225     if (!parameters)
       
   226         {
       
   227         TBuf<160> company = iEngine->RandomString(CCreatorEngine::ECompany);
       
   228         TInt num = iEngine->RandomNumber(1, 3);
       
   229         TBuf<10> apType;
       
   230         
       
   231         if (num==1)
       
   232             apType = _L("mms");
       
   233         else if (num==2)
       
   234             apType = _L("wap");
       
   235         else
       
   236             apType = _L("internet");
       
   237         
       
   238         iParameters = new(ELeave) CAccessPointsParameters;
       
   239         parameters = iParameters;
       
   240 
       
   241         parameters->SetRandomCMNameL(*iEngine);
       
   242 
       
   243         // in random mode just create GPRS access points
       
   244         parameters->iBearerType = EApBearerTypeGPRS;
       
   245 
       
   246         parameters->SetRandomLoginNameL(*iEngine);
       
   247 
       
   248         iParameters->iIspLoginPass->Des() = iEngine->RandomString(CCreatorEngine::ESurname);
       
   249         iParameters->iIspLoginPass->Des().LowerCase();
       
   250 
       
   251         iParameters->iSecureAuthentication = EFalse;
       
   252         iParameters->iPromptPassword = EFalse;
       
   253 
       
   254         iParameters->iProxyServerAddress->Des() = _L("127.0.0.1");
       
   255         iParameters->iProxyPortNumber = 80;
       
   256 
       
   257         iParameters->iWapStartPage->Des() = _L("http://");
       
   258         iParameters->iWapStartPage->Des().Append(apType);
       
   259         iParameters->iWapStartPage->Des().Append(_L("."));
       
   260         iParameters->iWapStartPage->Des().Append(company);
       
   261         iParameters->iWapStartPage->Des().Append(_L(".com"));
       
   262         iParameters->iWapStartPage->Des().LowerCase();
       
   263 
       
   264         iParameters->iIspIPAddr->Des() = KZeroIP;
       
   265         iParameters->iIspIPNameServer1->Des() = KZeroIP;
       
   266         iParameters->iIspIPNameServer1->Des() = KZeroIP;
       
   267         iParameters->iGprsAcessPointName->Des() = apType;
       
   268         iParameters->iIspDefaultTelNumber->Des() = iEngine->RandomString(CCreatorEngine::EPhoneNumber);
       
   269         iParameters->iIspBearerCallTypeIsdn = ECallTypeISDNv110;
       
   270         iParameters->iIspBearerSpeed = KSpeed14400;
       
   271 
       
   272         iParameters->iWapWspOption = EWapWspOptionConnectionOriented;
       
   273         iParameters->iWapGatewayAddress->Des() = KZeroIP;
       
   274         }
       
   275     else
       
   276         {
       
   277         // otherwise replace the parameters object
       
   278         iParameters = parameters;
       
   279         }
       
   280 
       
   281     TInt err = KErrNone;
       
   282 
       
   283     // access point item
       
   284     CApAccessPointItem* apItem = CApAccessPointItem::NewLC();
       
   285 
       
   286     // set the bearer type, if it fails try to set a default type
       
   287     TRAPD(bearerErr, apItem->SetBearerTypeL(iParameters->iBearerType));
       
   288     if (bearerErr != KErrNone)
       
   289         {
       
   290         iParameters->iBearerType = EApBearerTypeGPRS;
       
   291         TRAPD(bearerErr2, apItem->SetBearerTypeL(iParameters->iBearerType));
       
   292         bearerErr2=bearerErr2;
       
   293         }
       
   294 
       
   295     if (iParameters->iBearerType == EApBearerTypeGPRS) // GPRS
       
   296         {
       
   297         err = apItem->WriteLongTextL(EApGprsAccessPointName, iParameters->iGprsAcessPointName->Des());
       
   298         }
       
   299     else  // CSD or HCSD
       
   300         {
       
   301         err = apItem->WriteTextL(EApIspDefaultTelNumber, iParameters->iIspDefaultTelNumber->Des());
       
   302         err = apItem->WriteUint(EApIspBearerCallTypeIsdn, iParameters->iIspBearerCallTypeIsdn);
       
   303         err = apItem->WriteUint(EApIspBearerSpeed, iParameters->iIspBearerSpeed);
       
   304         }
       
   305 
       
   306     err = apItem->WriteTextL(EApIspLoginName, iParameters->iIspLoginName->Des());
       
   307     err = apItem->WriteTextL(EApIspIfAuthName, iParameters->iIspLoginName->Des());
       
   308     err = apItem->WriteTextL(EApIspLoginPass, iParameters->iIspLoginPass->Des());
       
   309     err = apItem->WriteTextL(EApIspIfAuthPass, iParameters->iIspLoginPass->Des());
       
   310     err = apItem->WriteTextL(EApGprsIfAuthPassword, iParameters->iIspLoginPass->Des());
       
   311     err = apItem->WriteBool(EApIspDisablePlainTextAuth, iParameters->iSecureAuthentication);
       
   312     err = apItem->WriteBool(EApIspPromptForLogin, iParameters->iPromptPassword);
       
   313     err = apItem->WriteTextL(EApWapGatewayAddress, iParameters->iWapGatewayAddress->Des());
       
   314     err = apItem->WriteLongTextL(EApProxyServerAddress, iParameters->iProxyServerAddress->Des());
       
   315     err = apItem->WriteUint(EApProxyPortNumber, iParameters->iProxyPortNumber);
       
   316     err = apItem->WriteLongTextL(EApWapStartPage, iParameters->iWapStartPage->Des());
       
   317     err = apItem->WriteUint(EApWapWspOption, iParameters->iWapWspOption);
       
   318     err = apItem->WriteTextL(EApGprsIPNameServer1, iParameters->iIspIPNameServer1->Des());
       
   319     err = apItem->WriteTextL(EApGprsIPNameServer2, iParameters->iIspIPNameServer2->Des());
       
   320     err = apItem->WriteTextL(EApIspIPAddr, iParameters->iIspIPAddr->Des());
       
   321 
       
   322 
       
   323     TUint32 uid = iApDataHandler->CreateFromDataL(*apItem);  // save the access point, returns the uid of the AP
       
   324 
       
   325     // id has been generated, store it for being able to delete
       
   326     // entries created only with Creator
       
   327     iEntryIds.Append( uid );
       
   328         
       
   329     TBuf<256> name = iParameters->iConnectionName->Des();
       
   330     iApUtils->SetNameL(name, uid); // sets the AP name
       
   331 
       
   332 
       
   333     // if no defaults set, set the created AP as a default
       
   334 
       
   335     // MMS access point
       
   336     if (iParameters->iWapStartPage->Des().FindF(_L("mms")) >=0  ||  iParameters->iConnectionName->Des().FindF(_L("mms")) >=0 )
       
   337         {
       
   338         //User::Panic(_L("Not done yet..."), 123);
       
   339         }
       
   340 
       
   341 
       
   342     // WAP access point
       
   343     else if (iParameters->iConnectionName->Des().FindF(_L("wap")) >=0  ||  iParameters->iGprsAcessPointName->Des().FindF(_L("wap")) >= 0)
       
   344         {
       
   345         TUint32 defID = 0;
       
   346         TRAP( err, defID = iApDataHandler->DefaultL(ETrue) );  // ETrue==WAP
       
   347 
       
   348         if (defID <= 1)
       
   349             TRAP( err, iApDataHandler->SetAsDefaultL(uid, EIspTypeWAPOnly) );
       
   350 
       
   351         }
       
   352 
       
   353     // Internet access point
       
   354     else if (iParameters->iConnectionName->Des().FindF(_L("internet")) >=0  ||  iParameters->iGprsAcessPointName->Des().FindF(_L("internet")) >= 0)
       
   355         {
       
   356         TUint32 defID = 0;
       
   357         TRAP( err, defID = iApDataHandler->DefaultL(EFalse) );  // EFalse==IAP
       
   358 
       
   359         if (defID <= 1)
       
   360             TRAP( err, iApDataHandler->SetAsDefaultL(uid, EIspTypeInternetOnly) );  //  <--  POSSIBLY NOT CORRECT, NEEDS MORE TESTING
       
   361         }
       
   362 
       
   363 
       
   364 
       
   365     CleanupStack::PopAndDestroy(); //apItem
       
   366 
       
   367     return err;
       
   368     }
       
   369 
       
   370 //----------------------------------------------------------------------------
       
   371 
       
   372 TUint32 CCreatorAccessPoints::AccessPointNameToIdL(const TDesC& aAPName, TBool /*aAnyIfNotFound*/ )
       
   373     {
       
   374     LOGSTRING("Creator: CCreatorEngine::AccessPointNameToIdL");
       
   375 
       
   376     TBuf<256> apName = aAPName.Left(256);
       
   377     apName.Trim();
       
   378 
       
   379     TUint32 APId = iEngine->GetDefaultIAPL();
       
   380 
       
   381     // return default IAP if requested
       
   382     if (apName.CompareF(_L("DEFAULT-IAP")) == 0 || apName.CompareF(_L("DEFAULT")) == 0)
       
   383         {
       
   384         return APId;
       
   385         }
       
   386 
       
   387     CCommsDatabase* db = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   388     CleanupStack::PushL(db);
       
   389     CApUtils* apUtils = CApUtils::NewLC(*db);
       
   390     CApSelect* apSelect = CApSelect::NewLC(*db, KEApIspTypeAll, EApBearerTypeAll, KEApSortNameAscending);
       
   391 
       
   392 
       
   393     // loop through all access points and try to find a matching name
       
   394     if (apSelect->MoveToFirst())
       
   395         {
       
   396         do
       
   397             {
       
   398             TBuf<256> apName2;
       
   399             apUtils->NameL(apSelect->Uid(), apName2);
       
   400             apName2.Trim();
       
   401 
       
   402             if (apName2.CompareF( apName ) == 0)
       
   403                 {
       
   404                 // match found, get uid and break the loop
       
   405                 TRAPD( err, APId = apUtils->IapIdFromWapIdL(apSelect->Uid()) );
       
   406                 err=err;
       
   407                 break;
       
   408                 }
       
   409             }
       
   410         while (apSelect->MoveNext());
       
   411         }
       
   412 
       
   413     CleanupStack::PopAndDestroy(3);  //apSelect, apUtils, db
       
   414 
       
   415     return APId;
       
   416     }
       
   417 
       
   418 //----------------------------------------------------------------------------
       
   419 
       
   420 void CCreatorAccessPoints::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) // from MMsvSessionObserver
       
   421     {
       
   422     }
       
   423 
       
   424 //----------------------------------------------------------------------------
       
   425 void CCreatorAccessPoints::DeleteAllL()
       
   426     {
       
   427     LOGSTRING("Creator: CCreatorEngine::DeleteAllL");
       
   428     
       
   429     CApSelect* selector = CApSelect::NewLC( *iCommsDb, 
       
   430                                             KEApIspTypeAll,
       
   431                                             EApBearerTypeAllBearers,
       
   432                                             KEApSortUidAscending );
       
   433     
       
   434     CApListItemList* list = new (ELeave) CApListItemList();
       
   435     CleanupStack::PushL( list );
       
   436     TInt count = selector->AllListItemDataL( *list );
       
   437     for ( TInt i = 0; i < count; i++ )
       
   438         {
       
   439         TRAP_IGNORE( iApDataHandler->RemoveAPL( (*list)[i]->Uid() ) );
       
   440         }
       
   441 
       
   442     CleanupStack::PopAndDestroy( list );
       
   443     CleanupStack::PopAndDestroy( selector );
       
   444 
       
   445     // reset must be done here, because iEntryIds is stored in destructor
       
   446     iEntryIds.Reset();
       
   447     
       
   448     // all entries deleted, remove the Logs related registry
       
   449     iEngine->RemoveStoreL( KUidDictionaryUidIAP );
       
   450     }
       
   451 
       
   452 //----------------------------------------------------------------------------
       
   453 
       
   454 void CCreatorAccessPoints::DeleteAllCreatedByCreatorL()
       
   455     {
       
   456     LOGSTRING("Creator: CCreatorEngine::DeleteAllCreatedByCreatorL");
       
   457     iEntryIds.Reset();
       
   458     
       
   459     // fetch ids of entries created by Creator
       
   460     iEngine->ReadEntryIdsFromStoreL( iEntryIds, KUidDictionaryUidIAP );
       
   461     
       
   462     // delete entries
       
   463     for ( TInt i = 0; i < iEntryIds.Count(); i++ )
       
   464         {
       
   465         TRAP_IGNORE( iApDataHandler->RemoveAPL( iEntryIds[i] ) );
       
   466         }
       
   467     
       
   468     // reset must be done here, because iEntryIds is stored in destructor
       
   469     iEntryIds.Reset();
       
   470     
       
   471     // all entries deleted, remove the Logs related registry
       
   472     iEngine->RemoveStoreL( KUidDictionaryUidIAP );
       
   473     }