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