creator/engine/src/creator_accesspoint.cpp
changeset 17 4f2773374eff
child 19 4b22a598b890
equal deleted inserted replaced
15:e11368ed4880 17:4f2773374eff
       
     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, TInt& aNumberOfEntries)
       
   192     {
       
   193     LOGSTRING("Creator: CCreatorAccessPoints::AskDataFromUserL");
       
   194 
       
   195     if( aCommand == ECmdDeleteIAPs )
       
   196         {
       
   197         return iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Delete all Access Points?") );
       
   198         }
       
   199     else if( aCommand == ECmdDeleteCreatorIAPs )
       
   200         {
       
   201         return iEngine->GetEngineWrapper()->YesNoQueryDialog(_L("Delete all Access Points created with Creator?") );
       
   202         }
       
   203 
       
   204     return iEngine->GetEngineWrapper()->EntriesQueryDialog(aNumberOfEntries, _L("How many entries to create?"));
       
   205     }
       
   206 
       
   207 
       
   208 //----------------------------------------------------------------------------
       
   209 
       
   210 TInt CCreatorAccessPoints::CreateConnectionSettingsEntryL(CCreatorModuleBaseParameters *aParameters)
       
   211     {
       
   212     LOGSTRING("Creator: CCreatorAccessPoints::CreateAccessPointEntryL");
       
   213 
       
   214     CAccessPointsParameters* parameters = (CAccessPointsParameters*) aParameters;
       
   215     
       
   216     // clear any existing parameter definations
       
   217     delete iParameters;
       
   218     iParameters = NULL;
       
   219     
       
   220     
       
   221             
       
   222     // random data needed if no predefined data available
       
   223     if (!parameters)
       
   224         {
       
   225         TBuf<160> company = iEngine->RandomString(CCreatorEngine::ECompany);
       
   226         TInt num = iEngine->RandomNumber(1, 3);
       
   227         TBuf<10> apType;
       
   228         
       
   229         if (num==1)
       
   230             apType = _L("mms");
       
   231         else if (num==2)
       
   232             apType = _L("wap");
       
   233         else
       
   234             apType = _L("internet");
       
   235         
       
   236         iParameters = new(ELeave) CAccessPointsParameters;
       
   237         parameters = iParameters;
       
   238 
       
   239         parameters->SetRandomCMNameL(*iEngine);
       
   240 
       
   241         // in random mode just create GPRS access points
       
   242         parameters->iBearerType = EApBearerTypeGPRS;
       
   243 
       
   244         parameters->SetRandomLoginNameL(*iEngine);
       
   245 
       
   246         iParameters->iIspLoginPass->Des() = iEngine->RandomString(CCreatorEngine::ESurname);
       
   247         iParameters->iIspLoginPass->Des().LowerCase();
       
   248 
       
   249         iParameters->iSecureAuthentication = EFalse;
       
   250         iParameters->iPromptPassword = EFalse;
       
   251 
       
   252         iParameters->iProxyServerAddress->Des() = _L("127.0.0.1");
       
   253         iParameters->iProxyPortNumber = 80;
       
   254 
       
   255         iParameters->iWapStartPage->Des() = _L("http://");
       
   256         iParameters->iWapStartPage->Des().Append(apType);
       
   257         iParameters->iWapStartPage->Des().Append(_L("."));
       
   258         iParameters->iWapStartPage->Des().Append(company);
       
   259         iParameters->iWapStartPage->Des().Append(_L(".com"));
       
   260         iParameters->iWapStartPage->Des().LowerCase();
       
   261 
       
   262         iParameters->iIspIPAddr->Des() = KZeroIP;
       
   263         iParameters->iIspIPNameServer1->Des() = KZeroIP;
       
   264         iParameters->iIspIPNameServer1->Des() = KZeroIP;
       
   265         iParameters->iGprsAcessPointName->Des() = apType;
       
   266         iParameters->iIspDefaultTelNumber->Des() = iEngine->RandomString(CCreatorEngine::EPhoneNumber);
       
   267         iParameters->iIspBearerCallTypeIsdn = ECallTypeISDNv110;
       
   268         iParameters->iIspBearerSpeed = KSpeed14400;
       
   269 
       
   270         iParameters->iWapWspOption = EWapWspOptionConnectionOriented;
       
   271         iParameters->iWapGatewayAddress->Des() = KZeroIP;
       
   272         }
       
   273     else
       
   274         {
       
   275         // otherwise replace the parameters object
       
   276         iParameters = parameters;
       
   277         }
       
   278 
       
   279     TInt err = KErrNone;
       
   280 
       
   281     // access point item
       
   282     CApAccessPointItem* apItem = CApAccessPointItem::NewLC();
       
   283 
       
   284     // set the bearer type, if it fails try to set a default type
       
   285     TRAPD(bearerErr, apItem->SetBearerTypeL(iParameters->iBearerType));
       
   286     if (bearerErr != KErrNone)
       
   287         {
       
   288         iParameters->iBearerType = EApBearerTypeGPRS;
       
   289         TRAPD(bearerErr2, apItem->SetBearerTypeL(iParameters->iBearerType));
       
   290         bearerErr2=bearerErr2;
       
   291         }
       
   292 
       
   293     if (iParameters->iBearerType == EApBearerTypeGPRS) // GPRS
       
   294         {
       
   295         err = apItem->WriteLongTextL(EApGprsAccessPointName, iParameters->iGprsAcessPointName->Des());
       
   296         }
       
   297     else  // CSD or HCSD
       
   298         {
       
   299         err = apItem->WriteTextL(EApIspDefaultTelNumber, iParameters->iIspDefaultTelNumber->Des());
       
   300         err = apItem->WriteUint(EApIspBearerCallTypeIsdn, iParameters->iIspBearerCallTypeIsdn);
       
   301         err = apItem->WriteUint(EApIspBearerSpeed, iParameters->iIspBearerSpeed);
       
   302         }
       
   303 
       
   304     err = apItem->WriteTextL(EApIspLoginName, iParameters->iIspLoginName->Des());
       
   305     err = apItem->WriteTextL(EApIspIfAuthName, iParameters->iIspLoginName->Des());
       
   306     err = apItem->WriteTextL(EApIspLoginPass, iParameters->iIspLoginPass->Des());
       
   307     err = apItem->WriteTextL(EApIspIfAuthPass, iParameters->iIspLoginPass->Des());
       
   308     err = apItem->WriteTextL(EApGprsIfAuthPassword, iParameters->iIspLoginPass->Des());
       
   309     err = apItem->WriteBool(EApIspDisablePlainTextAuth, iParameters->iSecureAuthentication);
       
   310     err = apItem->WriteBool(EApIspPromptForLogin, iParameters->iPromptPassword);
       
   311     err = apItem->WriteTextL(EApWapGatewayAddress, iParameters->iWapGatewayAddress->Des());
       
   312     err = apItem->WriteLongTextL(EApProxyServerAddress, iParameters->iProxyServerAddress->Des());
       
   313     err = apItem->WriteUint(EApProxyPortNumber, iParameters->iProxyPortNumber);
       
   314     err = apItem->WriteLongTextL(EApWapStartPage, iParameters->iWapStartPage->Des());
       
   315     err = apItem->WriteUint(EApWapWspOption, iParameters->iWapWspOption);
       
   316     err = apItem->WriteTextL(EApGprsIPNameServer1, iParameters->iIspIPNameServer1->Des());
       
   317     err = apItem->WriteTextL(EApGprsIPNameServer2, iParameters->iIspIPNameServer2->Des());
       
   318     err = apItem->WriteTextL(EApIspIPAddr, iParameters->iIspIPAddr->Des());
       
   319 
       
   320 
       
   321     TUint32 uid = iApDataHandler->CreateFromDataL(*apItem);  // save the access point, returns the uid of the AP
       
   322 
       
   323     // id has been generated, store it for being able to delete
       
   324     // entries created only with Creator
       
   325     iEntryIds.Append( uid );
       
   326         
       
   327     TBuf<256> name = iParameters->iConnectionName->Des();
       
   328     iApUtils->SetNameL(name, uid); // sets the AP name
       
   329 
       
   330 
       
   331     // if no defaults set, set the created AP as a default
       
   332 
       
   333     // MMS access point
       
   334     if (iParameters->iWapStartPage->Des().FindF(_L("mms")) >=0  ||  iParameters->iConnectionName->Des().FindF(_L("mms")) >=0 )
       
   335         {
       
   336         //User::Panic(_L("Not done yet..."), 123);
       
   337         }
       
   338 
       
   339 
       
   340     // WAP access point
       
   341     else if (iParameters->iConnectionName->Des().FindF(_L("wap")) >=0  ||  iParameters->iGprsAcessPointName->Des().FindF(_L("wap")) >= 0)
       
   342         {
       
   343         TUint32 defID = 0;
       
   344         TRAP( err, defID = iApDataHandler->DefaultL(ETrue) );  // ETrue==WAP
       
   345 
       
   346         if (defID <= 1)
       
   347             TRAP( err, iApDataHandler->SetAsDefaultL(uid, EIspTypeWAPOnly) );
       
   348 
       
   349         }
       
   350 
       
   351     // Internet access point
       
   352     else if (iParameters->iConnectionName->Des().FindF(_L("internet")) >=0  ||  iParameters->iGprsAcessPointName->Des().FindF(_L("internet")) >= 0)
       
   353         {
       
   354         TUint32 defID = 0;
       
   355         TRAP( err, defID = iApDataHandler->DefaultL(EFalse) );  // EFalse==IAP
       
   356 
       
   357         if (defID <= 1)
       
   358             TRAP( err, iApDataHandler->SetAsDefaultL(uid, EIspTypeInternetOnly) );  //  <--  POSSIBLY NOT CORRECT, NEEDS MORE TESTING
       
   359         }
       
   360 
       
   361 
       
   362 
       
   363     CleanupStack::PopAndDestroy(); //apItem
       
   364 
       
   365     return err;
       
   366     }
       
   367 
       
   368 //----------------------------------------------------------------------------
       
   369 
       
   370 TUint32 CCreatorAccessPoints::AccessPointNameToIdL(const TDesC& aAPName, TBool /*aAnyIfNotFound*/ )
       
   371     {
       
   372     LOGSTRING("Creator: CCreatorEngine::AccessPointNameToIdL");
       
   373 
       
   374     TBuf<256> apName = aAPName.Left(256);
       
   375     apName.Trim();
       
   376 
       
   377     TUint32 APId = iEngine->GetDefaultIAPL();
       
   378 
       
   379     // return default IAP if requested
       
   380     if (apName.CompareF(_L("DEFAULT-IAP")) == 0 || apName.CompareF(_L("DEFAULT")) == 0)
       
   381         {
       
   382         return APId;
       
   383         }
       
   384 
       
   385     CCommsDatabase* db = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   386     CleanupStack::PushL(db);
       
   387     CApUtils* apUtils = CApUtils::NewLC(*db);
       
   388     CApSelect* apSelect = CApSelect::NewLC(*db, KEApIspTypeAll, EApBearerTypeAll, KEApSortNameAscending);
       
   389 
       
   390 
       
   391     // loop through all access points and try to find a matching name
       
   392     if (apSelect->MoveToFirst())
       
   393         {
       
   394         do
       
   395             {
       
   396             TBuf<256> apName2;
       
   397             apUtils->NameL(apSelect->Uid(), apName2);
       
   398             apName2.Trim();
       
   399 
       
   400             if (apName2.CompareF( apName ) == 0)
       
   401                 {
       
   402                 // match found, get uid and break the loop
       
   403                 TRAPD( err, APId = apUtils->IapIdFromWapIdL(apSelect->Uid()) );
       
   404                 err=err;
       
   405                 break;
       
   406                 }
       
   407             }
       
   408         while (apSelect->MoveNext());
       
   409         }
       
   410 
       
   411     CleanupStack::PopAndDestroy(3);  //apSelect, apUtils, db
       
   412 
       
   413     return APId;
       
   414     }
       
   415 
       
   416 //----------------------------------------------------------------------------
       
   417 
       
   418 void CCreatorAccessPoints::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) // from MMsvSessionObserver
       
   419     {
       
   420     }
       
   421 
       
   422 //----------------------------------------------------------------------------
       
   423 void CCreatorAccessPoints::DeleteAllL()
       
   424     {
       
   425     LOGSTRING("Creator: CCreatorEngine::DeleteAllL");
       
   426     
       
   427     CApSelect* selector = CApSelect::NewLC( *iCommsDb, 
       
   428                                             KEApIspTypeAll,
       
   429                                             EApBearerTypeAllBearers,
       
   430                                             KEApSortUidAscending );
       
   431     
       
   432     CApListItemList* list = new (ELeave) CApListItemList();
       
   433     CleanupStack::PushL( list );
       
   434     TInt count = selector->AllListItemDataL( *list );
       
   435     for ( TInt i = 0; i < count; i++ )
       
   436         {
       
   437         TRAP_IGNORE( iApDataHandler->RemoveAPL( (*list)[i]->Uid() ) );
       
   438         }
       
   439 
       
   440     CleanupStack::PopAndDestroy( list );
       
   441     CleanupStack::PopAndDestroy( selector );
       
   442 
       
   443     // reset must be done here, because iEntryIds is stored in destructor
       
   444     iEntryIds.Reset();
       
   445     
       
   446     // all entries deleted, remove the Logs related registry
       
   447     iEngine->RemoveStoreL( KUidDictionaryUidIAP );
       
   448     }
       
   449 
       
   450 //----------------------------------------------------------------------------
       
   451 
       
   452 void CCreatorAccessPoints::DeleteAllCreatedByCreatorL()
       
   453     {
       
   454     LOGSTRING("Creator: CCreatorEngine::DeleteAllCreatedByCreatorL");
       
   455     iEntryIds.Reset();
       
   456     
       
   457     // fetch ids of entries created by Creator
       
   458     iEngine->ReadEntryIdsFromStoreL( iEntryIds, KUidDictionaryUidIAP );
       
   459     
       
   460     // delete entries
       
   461     for ( TInt i = 0; i < iEntryIds.Count(); i++ )
       
   462         {
       
   463         TRAP_IGNORE( iApDataHandler->RemoveAPL( iEntryIds[i] ) );
       
   464         }
       
   465     
       
   466     // reset must be done here, because iEntryIds is stored in destructor
       
   467     iEntryIds.Reset();
       
   468     
       
   469     // all entries deleted, remove the Logs related registry
       
   470     iEngine->RemoveStoreL( KUidDictionaryUidIAP );
       
   471     }