apengine/apeng/src/APUtils.cpp
changeset 0 5a93021fdf25
child 66 ed07dcc72692
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Declaration of the class CApUtils
       
    15 *     Contains utility functions for access point handling
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "APEngineVariant.hrh"
       
    22 
       
    23 #include "ApUtils.h"
       
    24 #include "ApAccessPointItem.h"
       
    25 #include "ApDataHandler.h"
       
    26 #include "ApEngineCommons.h"
       
    27 #include "ApEngineLogger.h"
       
    28 #include <e32des16.h>
       
    29 #include <es_sock.h>
       
    30 #include <es_enum.h>
       
    31 
       
    32 #include    <featmgr.h>
       
    33 
       
    34 #include <WlanCdbCols.h>
       
    35 
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 
       
    39 // MODULE DATA STRUCTURES
       
    40 
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // construct/destruct/copy
       
    45 // ---------------------------------------------------------
       
    46 // CApUtils::NewLC
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CApUtils* CApUtils::NewLC( CCommsDatabase& aDb )
       
    50     {
       
    51     CLOG( ( EUtil, 0, _L( "-> CApUtils::NewLC" ) ) );
       
    52 
       
    53     CApUtils* db = new( ELeave ) CApUtils;
       
    54     CleanupStack::PushL( db );
       
    55     db->ConstructL( aDb );
       
    56 
       
    57     CLOG( ( EUtil, 1, _L( "<- CApUtils::NewLC" ) ) );
       
    58     return db;
       
    59     }
       
    60 
       
    61 
       
    62 
       
    63 // Destructor
       
    64 // ---------------------------------------------------------
       
    65 // CApUtils::~CApUtils
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 EXPORT_C CApUtils::~CApUtils()
       
    69     {
       
    70     if ( iExt )
       
    71         {
       
    72         if ( iExt->iIsFeatureManagerInitialised )
       
    73             {
       
    74             FeatureManager::UnInitializeLib();
       
    75             }
       
    76         }    
       
    77     delete iExt;
       
    78     CLOG( ( EUtil, 0, _L( "<-> CApUtils::~CApUtils" ) ) );
       
    79     }
       
    80 
       
    81 
       
    82 // C++ default constructor can NOT contain any code that
       
    83 // might leave.
       
    84 //
       
    85 // ---------------------------------------------------------
       
    86 // CApUtils::CApUtils
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CApUtils::CApUtils()
       
    90     {
       
    91     }
       
    92 
       
    93 
       
    94 // Symbian OS default constructor can leave.
       
    95 // ---------------------------------------------------------
       
    96 // CApUtils::ConstructL
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void CApUtils::ConstructL( CCommsDatabase& aDb )
       
   100     {
       
   101     CLOG( ( EUtil, 0, _L( "-> CApUtils::ConstructL" ) ) );
       
   102 
       
   103     iDb = &aDb;
       
   104     iExt = new ( ELeave )TUtilsExtra;
       
   105     
       
   106     FeatureManager::InitializeLibL();
       
   107     iExt->iIsFeatureManagerInitialised = ETrue;    
       
   108 
       
   109     iExt->iVariant = ApCommons::GetVariantL();
       
   110 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   111     iExt->iVariant |= KApUiEditOnlyVPNs;
       
   112 #endif // __TEST_CDMA_WRITE_PROTECT
       
   113 
       
   114     iExt->iWlanSupported = 
       
   115         FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );
       
   116     
       
   117     
       
   118 #ifdef __TEST_WLAN_SUPPORT
       
   119     iExt->iWlanSupported = ETrue;
       
   120 #endif // __TEST_WLAN_SUPPORT
       
   121     
       
   122     CLOG( ( EUtil, 1, _L( "<- CApUtils::ConstructL" ) ) );
       
   123     }
       
   124 
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 // utilities
       
   130 
       
   131 // ---------------------------------------------------------
       
   132 // CApUtils::IsAPInUseL
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 EXPORT_C TBool CApUtils::IsAPInUseL( TUint32 aUid )
       
   136     {
       
   137     CLOG( ( EUtil, 0, _L( "-> CApUtils::IsAPInUseL" ) ) );
       
   138 
       
   139 
       
   140 
       
   141     TBool retval( EFalse );
       
   142 #ifdef __WINS__
       
   143     // just to satisfy compiler...
       
   144     aUid++;
       
   145 #else // 
       
   146     RSocketServ rs;
       
   147     RConnection rc;
       
   148 
       
   149     TUint32 iap( 0 );
       
   150     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb, ETrue );
       
   151     TRAP_IGNORE( iap = IapIdFromWapIdL( aUid ) );
       
   152 
       
   153     User::LeaveIfError( rs.Connect() );    
       
   154     User::LeaveIfError( rc.Open( rs ) );
       
   155 
       
   156     TUint count( 0 );
       
   157     User::LeaveIfError( rc.EnumerateConnections( count ) );
       
   158     // Go on only if there is any
       
   159     if ( count )
       
   160         {
       
   161         for( TUint i = 1; i <= count; i++)
       
   162             {
       
   163             TPckgBuf<TConnectionInfo> connInfo;
       
   164             User::LeaveIfError( rc.GetConnectionInfo( i, connInfo ) );
       
   165             if ( iap == connInfo().iIapId )
       
   166                 { 
       
   167                 // IAP is in use, break
       
   168                 retval = ETrue;
       
   169                 break;
       
   170                 }
       
   171             }
       
   172         }
       
   173 
       
   174     rc.Close();
       
   175     rs.Close();    
       
   176 
       
   177     if ( ownTransaction )
       
   178         {
       
   179         ApCommons::CommitTransaction( *iDb );
       
   180         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   181         }
       
   182 #endif // __WINS__     
       
   183 
       
   184     CLOG( ( EUtil, 1, _L( "<- CApUtils::IsAPInUseL" ) ) );
       
   185     return ( retval );
       
   186     }
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CApUtils::WapBearerTypeL
       
   193 // ---------------------------------------------------------
       
   194 //
       
   195 EXPORT_C void CApUtils::WapBearerTypeL( TUint32 aUid, TDes& aBearer )
       
   196     {
       
   197     CLOG( ( EUtil, 0, _L( "-> CApUtils::WapBearerTypeL" ) ) );
       
   198     
       
   199     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   200 
       
   201     DoWapBearerTypeL( aUid, aBearer );
       
   202 
       
   203     if ( ownTransaction )
       
   204         {
       
   205         ApCommons::CommitTransaction( *iDb );
       
   206         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   207         }
       
   208 
       
   209     CLOG( ( EUtil, 1, _L( "<- CApUtils::WapBearerTypeL" ) ) );
       
   210     }
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------
       
   214 // CApUtils::BearerTypeL
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 EXPORT_C TApBearerType CApUtils::BearerTypeL( TUint32 aUid )
       
   218     {
       
   219     CLOG( ( EUtil, 0, _L( "-> CApUtils::BearerTypeL" ) ) );
       
   220     
       
   221     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   222     TApBearerType retval = EApBearerTypeAllBearers;
       
   223     retval = DoBearerTypeL( aUid );
       
   224     if ( ownTransaction )
       
   225         {
       
   226         ApCommons::CommitTransaction( *iDb );
       
   227         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   228         }
       
   229 
       
   230     CLOG( ( EUtil, 1, _L( "<- CApUtils::BearerTypeL" ) ) );
       
   231     return retval;
       
   232     }
       
   233 
       
   234 
       
   235 // ---------------------------------------------------------
       
   236 // CApUtils::ISPTypeL
       
   237 // ---------------------------------------------------------
       
   238 //
       
   239 EXPORT_C void CApUtils::ISPTypeL( TUint32 aUid, TCommsDbIspType& aIspType )
       
   240     {
       
   241     CLOG( ( EUtil, 0, _L( "-> CApUtils::ISPTypeL" ) ) );
       
   242 
       
   243     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   244     DoISPTypeL( aUid, aIspType );
       
   245     if ( ownTransaction )
       
   246         {
       
   247         ApCommons::CommitTransaction( *iDb );
       
   248         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   249         }
       
   250 
       
   251     CLOG( ( EUtil, 1, _L( "<- CApUtils::ISPTypeL" ) ) );
       
   252     }
       
   253 
       
   254 
       
   255 
       
   256 // ---------------------------------------------------------
       
   257 // CApUtils::IsValidNameL
       
   258 // ---------------------------------------------------------
       
   259 //
       
   260 EXPORT_C TBool CApUtils::IsValidNameL( const TDesC& aNameText )
       
   261     {
       
   262     CLOG( ( EUtil, 0, _L( "<-> CApUtils::IsValidNameL" ) ) );
       
   263     
       
   264     return IsValidNameL( aNameText, 0 );
       
   265     }
       
   266 
       
   267 
       
   268 // ---------------------------------------------------------
       
   269 // CApUtils::MakeValidName
       
   270 // ---------------------------------------------------------
       
   271 //
       
   272 EXPORT_C TBool CApUtils::MakeValidNameL( TDes& aNameText )
       
   273     {
       
   274     CLOG( ( EUtil, 0, _L( "-> CApUtils::MakeValidNameL" ) ) );
       
   275    
       
   276     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   277 
       
   278     HBufC* buf = HBufC::NewLC( KModifiableTextLength );
       
   279     TPtr ptr( buf->Des() );
       
   280     ptr.Copy( aNameText );
       
   281     TBool nameChanged( EFalse );
       
   282     HBufC* sgd = ApCommons::DoMakeValidNameL( *iDb,
       
   283                                                nameChanged,
       
   284                                                buf,
       
   285                                                0,
       
   286                                                EFalse );
       
   287 
       
   288     if ( nameChanged )
       
   289         {
       
   290         aNameText.Copy( *sgd );
       
   291         }
       
   292     CleanupStack::PopAndDestroy( buf ); // buf
       
   293     delete sgd;
       
   294     if ( ownTransaction )
       
   295         {
       
   296         ApCommons::CommitTransaction( *iDb );
       
   297         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   298         }
       
   299 
       
   300     CLOG( ( EUtil, 1, _L( "<- CApUtils::MakeValidNameL" ) ) );
       
   301     return nameChanged;
       
   302     }
       
   303 
       
   304 
       
   305 // ---------------------------------------------------------
       
   306 // CApUtils::NameL
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 EXPORT_C void CApUtils::NameL( TUint32 aUid, TDes& aName )
       
   310     {
       
   311     CLOG( ( EUtil, 0, _L( "-> CApUtils::NameL" ) ) );
       
   312 
       
   313     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   314     DoNameL( aUid, aName );
       
   315     if ( ownTransaction )
       
   316         {
       
   317         ApCommons::CommitTransaction( *iDb );
       
   318         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   319         }
       
   320 
       
   321     CLOG( ( EUtil, 1, _L( "<- CApUtils::NameL" ) ) );
       
   322     }
       
   323 
       
   324 
       
   325 
       
   326 // ---------------------------------------------------------
       
   327 // CApUtils::SetNameL
       
   328 // ---------------------------------------------------------
       
   329 //
       
   330 EXPORT_C void CApUtils::SetNameL( TDes& aName, TUint32 aUid )
       
   331     {
       
   332     CLOG( ( EUtil, 0, _L( "-> CApUtils::SetNameL" ) ) );
       
   333 
       
   334     if ( iExt->iVariant & KApUiEditOnlyVPNs )
       
   335         {
       
   336         User::Leave( KErrNotSupported );
       
   337         }
       
   338 
       
   339     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   340     DoSetNameL( aName, aUid );
       
   341     if ( ownTransaction )
       
   342         {
       
   343         ApCommons::CommitTransaction( *iDb );
       
   344         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   345         }
       
   346 
       
   347     CLOG( ( EUtil, 1, _L( "<- CApUtils::SetNameL" ) ) );
       
   348     }
       
   349 
       
   350 
       
   351 
       
   352 // ---------------------------------------------------------
       
   353 // CApUtils::SetISPTypeL
       
   354 // ---------------------------------------------------------
       
   355 //
       
   356 EXPORT_C void CApUtils::SetISPTypeL( TUint32 aUid, TCommsDbIspType aIspType )
       
   357     {
       
   358     CLOG( ( EUtil, 0, _L( "-> CApUtils::SetISPTypeL" ) ) );
       
   359 
       
   360     if ( iExt->iVariant & KApUiEditOnlyVPNs )
       
   361         {
       
   362         User::Leave( KErrNotSupported );
       
   363         }
       
   364     
       
   365     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   366     DoSetISPTypeL( aUid, aIspType );
       
   367     if ( ownTransaction )
       
   368         {
       
   369         ApCommons::CommitTransaction( *iDb );
       
   370         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   371         }
       
   372 
       
   373     CLOG( ( EUtil, 1, _L( "<- CApUtils::SetISPTypeL" ) ) );
       
   374     }
       
   375 
       
   376 
       
   377 
       
   378 // ---------------------------------------------------------
       
   379 // CApUtils::IapIdFromWapIdL
       
   380 // ---------------------------------------------------------
       
   381 //
       
   382 EXPORT_C TUint32 CApUtils::IapIdFromWapIdL( TUint32 aUid )
       
   383     {
       
   384     CLOG( ( EUtil, 0, _L( "-> CApUtils::IapIdFromWapIdL" ) ) );
       
   385     
       
   386     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   387     TUint32 retval( 0 );
       
   388 
       
   389     CCommsDbTableView* wapt;
       
   390     wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT),
       
   391                                        TPtrC(COMMDB_ID), aUid );
       
   392     User::LeaveIfError( wapt->GotoFirstRecord() );
       
   393 
       
   394     HBufC* wapBearer = ApCommons::ReadText16ValueLC
       
   395                                                 (
       
   396                                                 wapt,
       
   397                                                 TPtrC(WAP_CURRENT_BEARER)
       
   398                                                 );
       
   399 
       
   400     if ( *wapBearer == TPtrC(WAP_IP_BEARER) )
       
   401         {
       
   402         CCommsDbTableView* bearert;
       
   403         bearert = iDb->OpenViewMatchingUintLC( TPtrC(*wapBearer),
       
   404                                             TPtrC(WAP_ACCESS_POINT_ID), aUid );
       
   405         User::LeaveIfError( bearert->GotoFirstRecord() );
       
   406         ApCommons::ReadUintL( bearert, TPtrC(WAP_IAP), retval );
       
   407         CleanupStack::PopAndDestroy( bearert ); // bearert
       
   408         }
       
   409     else
       
   410         {
       
   411         User::Leave( KErrInvalidBearerType );
       
   412         }
       
   413     CleanupStack::PopAndDestroy( 2, wapt ); // wapBearer, wapt
       
   414     if ( ownTransaction )
       
   415         {
       
   416         ApCommons::CommitTransaction( *iDb );
       
   417         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   418         }
       
   419 
       
   420     CLOG( ( EUtil, 1, _L( "<- CApUtils::IapIdFromWapIdL" ) ) );
       
   421     return retval;
       
   422     }
       
   423 
       
   424 
       
   425 // ---------------------------------------------------------
       
   426 // CApUtils::WapIdFromIapIdL
       
   427 // ---------------------------------------------------------
       
   428 //
       
   429 EXPORT_C TUint32 CApUtils::WapIdFromIapIdL( TUint32 aUid )
       
   430     {
       
   431     CLOG( ( EUtil, 0, _L( "-> CApUtils::WapIdFromIapIdL" ) ) );
       
   432 
       
   433     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb );
       
   434     TUint32 retval( 0 );
       
   435 
       
   436     CCommsDbTableView* bearert;
       
   437     bearert = iDb->OpenViewMatchingUintLC( TPtrC(WAP_IP_BEARER),
       
   438                                           TPtrC(WAP_IAP), aUid );
       
   439     User::LeaveIfError( bearert->GotoFirstRecord() );
       
   440     ApCommons::ReadUintL( bearert, TPtrC(WAP_ACCESS_POINT_ID), retval );
       
   441     CleanupStack::PopAndDestroy( bearert ); // bearert
       
   442 
       
   443     if ( ownTransaction )
       
   444         {
       
   445         ApCommons::CommitTransaction( *iDb );
       
   446         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   447         }
       
   448 
       
   449     CLOG( ( EUtil, 1, _L( "<- CApUtils::WapIdFromIapIdL" ) ) );
       
   450     return retval;
       
   451     }
       
   452 
       
   453 
       
   454 // ---------------------------------------------------------
       
   455 // CApUtils::HasMandatoryFieldsFilledL
       
   456 // ---------------------------------------------------------
       
   457 //
       
   458 EXPORT_C TBool CApUtils::HasMandatoryFieldsFilledL( TUint32 aUid )
       
   459     {
       
   460     CLOG( ( EUtil, 0, _L( "-> CApUtils::HasMandatoryFieldsFilledL" ) ) );
       
   461 
       
   462     TBool retval( EFalse );
       
   463     TBool isOwn = ApCommons::StartPushedTransactionLC( *iDb );
       
   464     retval= DoHasMandatoryFieldsFilledL( aUid );
       
   465     if ( isOwn )
       
   466         {
       
   467         ApCommons::CommitTransaction( *iDb );
       
   468         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   469         }
       
   470 
       
   471     CLOG( ( EUtil, 1, _L( "<- CApUtils::HasMandatoryFieldsFilledL" ) ) );
       
   472     return retval;
       
   473     }
       
   474 
       
   475 
       
   476 
       
   477 // ---------------------------------------------------------
       
   478 // CApUtils::IAPExistsL
       
   479 // ---------------------------------------------------------
       
   480 //
       
   481 EXPORT_C TBool CApUtils::IAPExistsL( TUint32 aUid )
       
   482     {
       
   483     CLOG( ( EUtil, 0, _L( "<-> CApUtils::IAPExistsL" ) ) );
       
   484 
       
   485     return DoesExistsL( TPtrC( IAP ), aUid );
       
   486     }
       
   487 
       
   488 
       
   489 // ---------------------------------------------------------
       
   490 // CApUtils::WapApExistsL
       
   491 // ---------------------------------------------------------
       
   492 //
       
   493 EXPORT_C TBool CApUtils::WapApExistsL( TUint32 aUid )
       
   494     {
       
   495     CLOG( ( EUtil, 0, _L( "<-> CApUtils::WapApExistsL" ) ) );
       
   496 
       
   497     return DoesExistsL( TPtrC( WAP_ACCESS_POINT ), aUid );
       
   498     }
       
   499 
       
   500 
       
   501 
       
   502 // ---------------------------------------------------------
       
   503 // CApUtils::DoHasMandatoryFieldsFilledL
       
   504 // ---------------------------------------------------------
       
   505 //
       
   506 EXPORT_C TBool CApUtils::DoHasMandatoryFieldsFilledL(
       
   507                                                   TUint32 aUid,
       
   508                                                   CCommsDbTableView* aWapt,
       
   509                                                   TApBearerType aBearertype )
       
   510     {
       
   511     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoHasMandatoryFieldsFilledL" ) ) );
       
   512     
       
   513     TBool retval( EFalse );
       
   514     TInt need2pop( 0 );
       
   515     // if not contains, retval = False...
       
   516     // Mandatory WAP settings are:
       
   517     // CSD: StartPage, GatewayAddr
       
   518     // Note: SMS bearer had been dropped.
       
   519     // SMS: ServerNumber, ServiceNumber
       
   520     // Gprs: StartPage, GatewayAddr
       
   521     // Cdma: StartPage, GatewayAddr
       
   522     // Start with CSD/GPRS:
       
   523 
       
   524     if ( aBearertype == EApBearerTypeAllBearers )
       
   525         {
       
   526         aBearertype = BearerTypeL( aUid );
       
   527         }
       
   528     if ( aBearertype == EApBearerTypeAllBearers )
       
   529         {
       
   530         User::Leave( KErrInvalidBearerType );
       
   531         }
       
   532 
       
   533     if ( !aWapt )
       
   534         {
       
   535         aWapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT ),
       
   536                                              TPtrC( COMMDB_ID ), aUid );
       
   537         need2pop++;
       
   538         TInt res = aWapt->GotoFirstRecord();
       
   539         if ( res != KErrNone )
       
   540             {
       
   541             aWapt = NULL;
       
   542             User::Leave( res );
       
   543             }
       
   544         }
       
   545     switch ( aBearertype )
       
   546         {
       
   547         case EApBearerTypeCSD:
       
   548         case EApBearerTypeHSCSD:
       
   549         case EApBearerTypeGPRS:
       
   550         case EApBearerTypeCDMA:
       
   551             {
       
   552             TInt aLength( 0 );
       
   553             aWapt->ReadColumnLengthL( TPtrC(WAP_START_PAGE), aLength );
       
   554             if ( aLength )
       
   555                 {
       
   556                 CCommsDbTableView* bearert = iDb->OpenViewMatchingUintLC(
       
   557                                                 TPtrC(WAP_IP_BEARER),
       
   558                                                 TPtrC(WAP_ACCESS_POINT_ID),
       
   559                                                 aUid );
       
   560                 User::LeaveIfError( bearert->GotoFirstRecord() );
       
   561                 bearert->ReadColumnLengthL( TPtrC(WAP_GATEWAY_ADDRESS),
       
   562                                             aLength );
       
   563                 if ( aLength )
       
   564                     {
       
   565                     HBufC* txtbuf = HBufC::NewLC( aLength );
       
   566                     TPtr16 txt = txtbuf->Des();
       
   567                     bearert->ReadTextL( TPtrC(WAP_GATEWAY_ADDRESS), txt );
       
   568                     if ( txt.Compare( KDynIpAddress ) )
       
   569                         {
       
   570                         retval = ETrue;
       
   571                         }
       
   572                     }
       
   573                 CleanupStack::PopAndDestroy( 2, bearert ); // txtbuf,bearert
       
   574                 }
       
   575             break;
       
   576             }
       
   577         default:
       
   578             {
       
   579             User::Leave( KErrInvalidBearerType );
       
   580             break;
       
   581             }
       
   582         }
       
   583     if ( need2pop )
       
   584         {
       
   585         CleanupStack::PopAndDestroy( need2pop );
       
   586         }
       
   587 
       
   588     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoHasMandatoryFieldsFilledL" ) ) );
       
   589     return retval;
       
   590     }
       
   591 
       
   592 
       
   593 
       
   594 // ---------------------------------------------------------
       
   595 // CApUtils::IsValidNameL
       
   596 // ---------------------------------------------------------
       
   597 //
       
   598 EXPORT_C TBool CApUtils::IsValidNameL( const TDesC& aNameText,
       
   599                                        TUint32 aAcceptUid )
       
   600     {
       
   601     CLOG( ( EUtil, 0, _L( "-> CApUtils::IsValidNameL" ) ) );
       
   602 
       
   603     // Valid name: it means the name of the Connection,
       
   604     // that is the COMMDB_NAME in WAP_ACCESS_POINT table
       
   605     //
       
   606     TBool ret( ETrue ) ;
       
   607     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb, ETrue );
       
   608 
       
   609     HBufC* esc = ApCommons::EscapeTextLC( aNameText );
       
   610     CCommsDbTableView* wapt;
       
   611     wapt = iDb->OpenViewMatchingTextLC( TPtrC(WAP_ACCESS_POINT), 
       
   612                                         TPtrC(COMMDB_NAME), 
       
   613                                         *esc );
       
   614 
       
   615     TInt res;
       
   616     res = wapt->GotoFirstRecord(); // OK
       
   617     do
       
   618         {
       
   619         if ( res == KErrNone )
       
   620             {
       
   621             // Check UID
       
   622             TUint32 arecid;
       
   623             ApCommons::ReadUintL( wapt, TPtrC(COMMDB_ID), arecid);
       
   624             if ( arecid != aAcceptUid )
       
   625                 {
       
   626                 // some other record is already using this name,
       
   627                 // need to change it
       
   628                 ret = EFalse;
       
   629                 }
       
   630             }
       
   631         else
       
   632             {
       
   633             if ( res == KErrNotFound )
       
   634                 {
       
   635                 ret = ETrue;
       
   636                 }
       
   637             else
       
   638                 {
       
   639                 User::Leave( res );
       
   640                 }
       
   641             }
       
   642         if ( ret && ( res == KErrNone ) )
       
   643             {
       
   644             res = wapt->GotoNextRecord();
       
   645             }
       
   646         }while ( ( res == KErrNone ) && ( ret ) );
       
   647 
       
   648     CleanupStack::PopAndDestroy( wapt ); // wapt
       
   649     CleanupStack::PopAndDestroy( esc ); // esc
       
   650 
       
   651     if ( ownTransaction )
       
   652         {
       
   653         ApCommons::CommitTransaction( *iDb );
       
   654         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   655         }
       
   656 
       
   657     CLOG( ( EUtil, 1, _L( "<- CApUtils::IsValidNameL" ) ) );
       
   658     return ret;
       
   659     }
       
   660 
       
   661 
       
   662 // ---------------------------------------------------------
       
   663 // CApUtils::IsReadOnlyL
       
   664 // ---------------------------------------------------------
       
   665 //
       
   666 EXPORT_C TBool CApUtils::IsReadOnlyL( TUint32 aUid )
       
   667     {
       
   668     CLOG( ( EUtil, 0, _L( "-> CApUtils::IsReadOnlyL" ) ) );
       
   669     
       
   670     TBool retval( EFalse );
       
   671     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb, ETrue );
       
   672     CCommsDbTableView* wapt;
       
   673     wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT),
       
   674                                        TPtrC(COMMDB_ID), aUid );
       
   675     User::LeaveIfError( wapt->GotoFirstRecord() );
       
   676     retval = ApCommons::DoGetReadOnlyL( *wapt );
       
   677     CleanupStack::PopAndDestroy( wapt ); // wapt
       
   678     if ( ownTransaction )
       
   679         {
       
   680         ApCommons::CommitTransaction( *iDb );
       
   681         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   682         }
       
   683 
       
   684     CLOG( ( EUtil, 1, _L( "<- CApUtils::IsReadOnlyL" ) ) );
       
   685     return retval;
       
   686     }
       
   687 
       
   688 
       
   689 
       
   690 
       
   691 // ---------------------------------------------------------
       
   692 // CApUtils::IsWlanL
       
   693 // ---------------------------------------------------------
       
   694 //
       
   695 TBool CApUtils::IsWlanL( TUint32 aLanCommdbId )
       
   696     {
       
   697     CLOG( ( EUtil, 0, _L( "-> CApUtils::IsWlanL" ) ) );
       
   698     
       
   699     TBool retval( EFalse );
       
   700     TRAPD( err, retval = DoIsWlanL( aLanCommdbId ) );
       
   701     
       
   702     if ( err == KErrNotFound )
       
   703         {
       
   704         retval = EFalse;
       
   705         }
       
   706     else
       
   707         {
       
   708         User::LeaveIfError( err );
       
   709         }
       
   710     
       
   711     CLOG( ( EUtil, 1, _L( "<- CApUtils::IsWlanL" ) ) );
       
   712     return retval;
       
   713     }
       
   714 
       
   715 
       
   716 
       
   717 // ---------------------------------------------------------
       
   718 // CApUtils::HasWlanSSIDL
       
   719 // ---------------------------------------------------------
       
   720 //
       
   721 TBool CApUtils::HasWlanSSIDL( TUint32 aLanCommdbId )
       
   722     {
       
   723     CLOG( ( EUtil, 0, _L( "-> CApUtils::HasWlanSSIDL" ) ) );
       
   724     
       
   725     TBool retval( EFalse );
       
   726     CCommsDbTableView* wlantable = NULL;
       
   727 
       
   728     // WLAN settings table backlinks to LAN service, 
       
   729     // so we query WLAN settings for a record 
       
   730     // where WLAN_SERVICE_ID is LAN_SERVICE's COMMDB_ID, 
       
   731     // which is aApItem.iIapServiceId...
       
   732     wlantable = iDb->OpenViewMatchingUintLC( TPtrC(WLAN_SERVICE),
       
   733                                              TPtrC(WLAN_SERVICE_ID),
       
   734                                              aLanCommdbId );
       
   735     TInt err = wlantable->GotoFirstRecord();
       
   736     if ( err == KErrNotFound )
       
   737         {
       
   738         retval = EFalse;
       
   739         }
       
   740     else
       
   741         {
       
   742         User::LeaveIfError( err );
       
   743         HBufC* wlanssid = ApCommons::ReadText16ValueLC
       
   744                             ( wlantable, TPtrC(NU_WLAN_SSID) );
       
   745         if ( wlanssid->Compare( KEmpty ) != 0 )
       
   746             {            
       
   747             retval = ETrue;
       
   748             }
       
   749         CleanupStack::PopAndDestroy( wlanssid );
       
   750         }
       
   751     CleanupStack::PopAndDestroy( wlantable );
       
   752     
       
   753     CLOG( ( EUtil, 1, _L( "<- CApUtils::HasWlanSSIDL" ) ) );
       
   754     return retval;
       
   755     }
       
   756 
       
   757 
       
   758 // ==== OTHER PRIVATE/protected, NON-EXPORTED FUNCTIONS ====
       
   759 
       
   760 // ---------------------------------------------------------
       
   761 // CApUtils::DoWapBearerTypeL
       
   762 // ---------------------------------------------------------
       
   763 //
       
   764 void CApUtils::DoWapBearerTypeL( TUint32 aUid, TDes& aBearer )
       
   765     {
       
   766     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoWapBearerTypeL" ) ) );
       
   767     
       
   768     CCommsDbTableView* wapt;
       
   769     wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT),
       
   770                                        TPtrC(COMMDB_ID), aUid );
       
   771     User::LeaveIfError( wapt->GotoFirstRecord() );
       
   772     HBufC* wapBearer = ApCommons::ReadText16ValueLC
       
   773                                             (
       
   774                                             wapt,
       
   775                                             TPtrC(WAP_CURRENT_BEARER)
       
   776                                             );
       
   777     if ( aBearer.MaxLength() < wapBearer->Length() )
       
   778         {
       
   779         User::Leave( KErrDescOverflow );
       
   780         }
       
   781     else
       
   782         {
       
   783         aBearer.SetLength( wapBearer->Length() );
       
   784         aBearer.Format( KFormat, &*wapBearer );
       
   785         }
       
   786     CleanupStack::PopAndDestroy( 2, wapt );   // wapBearer, wapt
       
   787 
       
   788     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoWapBearerTypeL" ) ) );
       
   789     }
       
   790 
       
   791 
       
   792 
       
   793 // ---------------------------------------------------------
       
   794 // CApUtils::DoBearerTypeL
       
   795 // ---------------------------------------------------------
       
   796 //
       
   797 TApBearerType CApUtils::DoBearerTypeL( TUint32 aUid )
       
   798     {
       
   799     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoBearerTypeL" ) ) );
       
   800     
       
   801     TApBearerType retval = EApBearerTypeAllBearers;
       
   802 
       
   803     CCommsDbTableView* wapt;
       
   804     wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT), 
       
   805                                         TPtrC(COMMDB_ID), 
       
   806                                         aUid );
       
   807     
       
   808     // TRAPped for some record that doesn't have a WAP -table. 
       
   809     // If KErrNotFound, then just return EApBearerTypeWLAN
       
   810     TInt wapErr = wapt->GotoFirstRecord();
       
   811     if ( wapErr == KErrNotFound )
       
   812         {
       
   813         CleanupStack::PopAndDestroy( wapt );
       
   814         return EApBearerTypeWLAN;
       
   815         }
       
   816     else
       
   817     	{
       
   818     	User::LeaveIfError( wapErr );
       
   819     	}
       
   820     
       
   821     HBufC* wapBearer = ApCommons::ReadText16ValueLC
       
   822                                             (
       
   823                                             wapt,
       
   824                                             TPtrC(WAP_CURRENT_BEARER)
       
   825                                             );
       
   826 
       
   827     CCommsDbTableView* bearert = iDb->OpenViewMatchingUintLC( *wapBearer,
       
   828                                           TPtrC(WAP_ACCESS_POINT_ID), aUid );
       
   829 
       
   830     User::LeaveIfError( bearert->GotoFirstRecord() );
       
   831     // decide which bearer, read bearer spec. data.
       
   832     if ( *wapBearer == TPtrC(WAP_IP_BEARER) )
       
   833         {
       
   834         TUint32 wapIap;
       
   835         ApCommons::ReadUintL( bearert, TPtrC(WAP_IAP), wapIap );
       
   836 
       
   837         CCommsDbTableView* iapt = iDb->OpenViewMatchingUintLC( TPtrC(IAP),
       
   838                                                TPtrC(COMMDB_ID), wapIap );
       
   839 
       
   840         User::LeaveIfError( iapt->GotoFirstRecord() );
       
   841         HBufC* aIapServiceType = ApCommons::ReadText16ValueLC
       
   842                                         (
       
   843                                         iapt,
       
   844                                         TPtrC(IAP_SERVICE_TYPE)
       
   845                                         );
       
   846         if ( ( *aIapServiceType == TPtrC(DIAL_OUT_ISP) ) ||
       
   847              ( *aIapServiceType == TPtrC(DIAL_IN_ISP) ) )
       
   848             {
       
   849             // need to get 'speed' data ( HS or normal CSD )
       
   850             TUint32 wapIsp;
       
   851             ApCommons::ReadUintL( iapt, TPtrC(IAP_SERVICE), wapIsp );
       
   852             CCommsDbTableView* ispt = iDb->OpenViewMatchingUintLC(
       
   853                                             *aIapServiceType,
       
   854                                             TPtrC(COMMDB_ID),
       
   855                                             wapIsp );
       
   856             User::LeaveIfError( ispt->GotoFirstRecord() );
       
   857             TUint32 bear;
       
   858             if ( ApCommons::ReadUintL( ispt, TPtrC(ISP_BEARER_TYPE), bear )
       
   859                                   == KErrUnknown )
       
   860                 {
       
   861                 bear = EBearerTypeCSD;
       
   862                 }
       
   863             if ( bear == EBearerTypeCSD )
       
   864                 {
       
   865                 retval = EApBearerTypeCSD;
       
   866                 }
       
   867             else
       
   868                 {
       
   869                 if ( bear == EBearerTypeHSCSD )
       
   870                     {
       
   871                     retval = EApBearerTypeHSCSD;
       
   872                     }
       
   873                 else
       
   874                     {
       
   875                     User::Leave( KErrInvalidBearer );
       
   876                     }
       
   877                 }
       
   878             CleanupStack::PopAndDestroy( ispt ); // ispt
       
   879             }
       
   880         else
       
   881             {
       
   882             if ( ( *aIapServiceType == TPtrC(OUTGOING_WCDMA) ) ||
       
   883                  ( *aIapServiceType == TPtrC(INCOMING_WCDMA) ) )
       
   884                 {
       
   885                 retval = EApBearerTypeGPRS;
       
   886                 }
       
   887             else
       
   888                 { // some other bearer, currently it might be VPN or WLAN
       
   889                 if ( *aIapServiceType == TPtrC(VPN_SERVICE) ) 
       
   890                     { // Get real VPN bearertype...
       
   891                     TUint32 service;
       
   892                     ApCommons::ReadUintL( iapt, TPtrC(IAP_SERVICE), service );
       
   893 
       
   894                     CCommsDbTableView* ispt;
       
   895                     ispt = iDb->OpenViewMatchingUintLC( TPtrC(VPN_SERVICE),
       
   896                                                         TPtrC(COMMDB_ID), 
       
   897                                                         service );
       
   898                     User::LeaveIfError( ispt->GotoFirstRecord() );
       
   899                     TUint32 tempint;
       
   900                     HBufC* buf = NULL;
       
   901                     // get the real iap
       
   902                     ApCommons::ReadUintL( ispt, 
       
   903                                           TPtrC(VPN_SERVICE_IAP), 
       
   904                                           tempint );
       
   905 
       
   906                     // now open the real IAP an get it's bearer...
       
   907                     CCommsDbTableView* iapt2 = NULL;
       
   908                     iapt2 = iDb->OpenViewMatchingUintLC( TPtrC(IAP),
       
   909                                                          TPtrC(COMMDB_ID), 
       
   910                                                          tempint );                                                         
       
   911                     User::LeaveIfError( iapt2->GotoFirstRecord() );
       
   912 
       
   913                     buf = ApCommons::ReadText16ValueLC( iapt2, 
       
   914                                                  TPtrC(IAP_SERVICE_TYPE) );
       
   915                     TUint32 service2;
       
   916                     ApCommons::ReadUintL( iapt2, TPtrC(IAP_SERVICE), 
       
   917                                           service2 );
       
   918 
       
   919                     if ( ( buf->Compare( TPtrC(OUTGOING_WCDMA ) ) == 0 ) ||
       
   920                         ( buf->Compare( TPtrC(INCOMING_WCDMA ) ) == 0 ) )
       
   921                         {
       
   922                         retval = EApBearerTypeGPRS;
       
   923                         }
       
   924                     else
       
   925                         {
       
   926                         if ( ( buf->Compare( TPtrC(DIAL_OUT_ISP ) ) == 0 ) ||
       
   927                             ( buf->Compare( TPtrC(DIAL_IN_ISP ) ) == 0 ) )
       
   928                             {
       
   929                             // need to get ISP,
       
   930                             CCommsDbTableView* doutt = NULL;
       
   931                             doutt = iDb->OpenViewMatchingUintLC( 
       
   932                                             *buf,
       
   933                                             TPtrC(COMMDB_ID), 
       
   934                                             service2 );
       
   935                                             
       
   936                             User::LeaveIfError( doutt ->GotoFirstRecord() );
       
   937                             ApCommons::ReadUintL( doutt , 
       
   938                                                   TPtrC(ISP_BEARER_TYPE), 
       
   939                                                   tempint );
       
   940                             if ( tempint == EBearerTypeCSD )
       
   941                                 {
       
   942                                 retval  = EApBearerTypeCSD;
       
   943                                 }
       
   944                             else
       
   945                                 {
       
   946                                 retval = EApBearerTypeHSCSD;
       
   947                                 }
       
   948                             CleanupStack::PopAndDestroy( doutt ); // doutt
       
   949                             }
       
   950                         else
       
   951                             { 
       
   952                             // VPN, having a bearer something 
       
   953                             // else than CSD, HSCSD & GPRS?
       
   954                             // check for WLAN
       
   955                             if ( iExt->iWlanSupported )
       
   956                                 {
       
   957                                 if ( buf->Compare( TPtrC(LAN_SERVICE) ) == 0 )
       
   958                                     { // LAN or WLAN
       
   959                                     if ( IsWlanL( service2 ) )
       
   960                                         {
       
   961                                         retval = EApBearerTypeWLAN;
       
   962                                         }
       
   963                                     else
       
   964                                         {
       
   965                                         User::Leave( KErrInvalidBearer );
       
   966                                         }
       
   967                                     }
       
   968                                 else
       
   969                                     {
       
   970                                     User::Leave( KErrInvalidBearer );
       
   971                                     }
       
   972                                 }
       
   973                             else
       
   974                                 {
       
   975                                 User::Leave( KErrInvalidBearer );
       
   976                                 }
       
   977                             }
       
   978                         }
       
   979                     CleanupStack::PopAndDestroy( 3, ispt ); // buf, iapt2, ispt
       
   980                     }
       
   981                 else
       
   982                     { // other, but not VPN, check for WLAN
       
   983                     if ( iExt->iWlanSupported )
       
   984                         {
       
   985                         if ( *aIapServiceType == TPtrC(LAN_SERVICE) ) 
       
   986                             { // check existence...
       
   987                             TUint32 service;
       
   988                             TUint32 bearer;
       
   989                             ApCommons::ReadUintL( iapt, TPtrC(IAP_SERVICE), 
       
   990                                                   service );
       
   991                             ApCommons::ReadUintL( iapt, TPtrC(IAP_BEARER), 
       
   992                                                   bearer );
       
   993 
       
   994 
       
   995                             CCommsDbTableView* ispt;
       
   996                             ispt = iDb->OpenViewMatchingUintLC( 
       
   997                                                     TPtrC(LAN_SERVICE),
       
   998                                                     TPtrC(COMMDB_ID), 
       
   999                                                     service );
       
  1000                             User::LeaveIfError( ispt->GotoFirstRecord() );
       
  1001                             // now we know it is either WLAN or some kinda LAN
       
  1002                             if ( IsWlanL( service ) )
       
  1003                                 {
       
  1004                                 retval = EApBearerTypeWLAN;
       
  1005                                 }
       
  1006                             else
       
  1007                                 { // other, 
       
  1008                                 // check for LANModem first, then for LAN
       
  1009                                 CCommsDbTableView* lanbearer;
       
  1010                                 lanbearer = 
       
  1011                                     iDb->OpenViewMatchingUintLC( 
       
  1012                                                 TPtrC(LAN_BEARER),
       
  1013                                                 TPtrC(COMMDB_ID), 
       
  1014                                                 bearer );
       
  1015                                 User::LeaveIfError( 
       
  1016                                         lanbearer->GotoFirstRecord() );
       
  1017                                 // LANMODEM? check commdb_name
       
  1018                                 HBufC* lbuf;
       
  1019                                 lbuf = ApCommons::ReadText16ValueLC( lanbearer,
       
  1020                                                          TPtrC(COMMDB_NAME) );
       
  1021                                 // if it is KModemBearerLANModem, 
       
  1022                                 // it is LANModem
       
  1023                                 if ( *lbuf == KModemBearerLANModem )
       
  1024                                     {
       
  1025                                     retval = EApBearerTypeLANModem;
       
  1026                                     }
       
  1027                                 else
       
  1028                                     {
       
  1029     #ifdef __TEST_LAN_BEARER
       
  1030                                     // LAN?
       
  1031                                     if ( *lbuf == KModemBearerLAN )
       
  1032                                         {                                
       
  1033                                         retval = EApBearerTypeLAN;
       
  1034                                         }
       
  1035                                     else
       
  1036                                         {
       
  1037                                         // other, but not VPN, or not supported
       
  1038                                         User::Leave( KErrInvalidBearer );
       
  1039                                         }
       
  1040     #else
       
  1041                                 // other, but not VPN, or not supported
       
  1042                                 User::Leave( KErrInvalidBearer );
       
  1043     #endif // __TEST_LAN_BEARER           
       
  1044                                     }
       
  1045                                 CleanupStack::PopAndDestroy( lbuf );
       
  1046                                 CleanupStack::PopAndDestroy( lanbearer );
       
  1047                                 }
       
  1048                             CleanupStack::PopAndDestroy( ispt );
       
  1049                             }
       
  1050                         }
       
  1051                     else
       
  1052                         {                        
       
  1053     #ifdef __TEST_LAN_BEARER
       
  1054                         if ( *aIapServiceType == TPtrC(LAN_SERVICE) ) 
       
  1055                             { // check existence...
       
  1056                             TUint32 service;
       
  1057                             TUint32 bearer;
       
  1058                             ApCommons::ReadUintL( iapt, TPtrC(IAP_SERVICE), 
       
  1059                                                   service );
       
  1060                             ApCommons::ReadUintL( iapt, TPtrC(IAP_BEARER), 
       
  1061                                                   bearer );
       
  1062 
       
  1063                             CCommsDbTableView* ispt;
       
  1064                             ispt = iDb->OpenViewMatchingUintLC( 
       
  1065                                                     TPtrC(LAN_SERVICE),
       
  1066                                                     TPtrC(COMMDB_ID), 
       
  1067                                                     service );
       
  1068                             User::LeaveIfError( ispt->GotoFirstRecord() );
       
  1069                             // now we know it is some kinda LAN
       
  1070                             // check for LANModem first, then for LAN
       
  1071                             CCommsDbTableView* lanbearer;
       
  1072                             lanbearer = 
       
  1073                                 iDb->OpenViewMatchingUintLC( 
       
  1074                                             TPtrC(LAN_BEARER),
       
  1075                                             TPtrC(COMMDB_ID), 
       
  1076                                             bearer );
       
  1077                             User::LeaveIfError( 
       
  1078                                     lanbearer->GotoFirstRecord() );
       
  1079                             // LANMODEM? check commdb_name
       
  1080                             HBufC* lbuf;
       
  1081                             lbuf = ApCommons::ReadText16ValueLC( lanbearer,
       
  1082                                                          TPtrC(COMMDB_NAME) );
       
  1083                             // if it is KModemBearerLANModem, it is LANModem
       
  1084                             if ( *lbuf == KModemBearerLANModem )
       
  1085                                 {
       
  1086                                 retval = EApBearerTypeLANModem;
       
  1087                                 }
       
  1088                             else
       
  1089                                 {
       
  1090                                 // LAN?
       
  1091                                 if ( *lbuf == KModemBearerLANModem )
       
  1092                                     {                                
       
  1093                                     retval = EApBearerTypeLAN;
       
  1094                                     }
       
  1095                                 else
       
  1096                                     {
       
  1097                                     // other, but not VPN, or not supported
       
  1098                                     User::Leave( KErrInvalidBearer );
       
  1099                                     }
       
  1100                                 }
       
  1101                             CleanupStack::PopAndDestroy( lbuf );
       
  1102                             CleanupStack::PopAndDestroy( lanbearer );
       
  1103                             CleanupStack::PopAndDestroy( ispt );
       
  1104                             }
       
  1105                         else
       
  1106                             {// other, but not LAN
       
  1107                             User::Leave( KErrInvalidBearer );
       
  1108                             }
       
  1109     #endif // __TEST_LAN_BEARER 
       
  1110                         }
       
  1111                     }
       
  1112                 }
       
  1113             }
       
  1114         CleanupStack::PopAndDestroy( 2, iapt );// aIapServiceType, iapt
       
  1115         }
       
  1116     else
       
  1117         {
       
  1118         User::Leave( KErrInvalidBearer );
       
  1119         }
       
  1120 
       
  1121     CleanupStack::PopAndDestroy( bearert ); // bearert
       
  1122     CleanupStack::Pop( wapBearer );    // wapBearer,
       
  1123     // cannot PopAndDestroy because it has been re-allocated !
       
  1124     delete wapBearer;
       
  1125     CleanupStack::PopAndDestroy( wapt );    // wapt
       
  1126 
       
  1127     if ( retval == EApBearerTypeAllBearers )
       
  1128         {
       
  1129         User::Leave( KErrInvalidBearer );
       
  1130         }
       
  1131 
       
  1132     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoBearerTypeL" ) ) );
       
  1133     return retval;
       
  1134     }
       
  1135 
       
  1136 
       
  1137 
       
  1138 // ---------------------------------------------------------
       
  1139 // CApUtils::DoISPTypeL
       
  1140 // ---------------------------------------------------------
       
  1141 //
       
  1142 void CApUtils::DoISPTypeL( TUint32 aUid, TCommsDbIspType& aIspType )
       
  1143     {
       
  1144     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoISPTypeL" ) ) );
       
  1145     
       
  1146     TCommsDbIspType retval = EIspTypeInternetAndWAP;
       
  1147 
       
  1148     CCommsDbTableView* wapt;
       
  1149     wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT), 
       
  1150                                         TPtrC(COMMDB_ID), 
       
  1151                                         aUid );
       
  1152 
       
  1153     User::LeaveIfError( wapt->GotoFirstRecord() );
       
  1154     HBufC* wapBearer = ApCommons::ReadText16ValueLC
       
  1155                                         (
       
  1156                                         wapt,
       
  1157                                         TPtrC(WAP_CURRENT_BEARER)
       
  1158                                         );
       
  1159 
       
  1160     if ( *wapBearer == TPtrC(WAP_IP_BEARER) )
       
  1161         {
       
  1162         CCommsDbTableView* bearert;
       
  1163         bearert = iDb->OpenViewMatchingUintLC( TPtrC(*wapBearer), 
       
  1164                                                TPtrC(WAP_ACCESS_POINT_ID), 
       
  1165                                                aUid );
       
  1166 
       
  1167         User::LeaveIfError( bearert->GotoFirstRecord() );
       
  1168         TUint32 aWapIap;
       
  1169         ApCommons::ReadUintL( bearert, TPtrC(WAP_IAP), aWapIap );
       
  1170         // now we have IAP uid, can go for Service type, ID
       
  1171 
       
  1172         CCommsDbTableView* iapt;
       
  1173         iapt = iDb->OpenViewMatchingUintLC( TPtrC(IAP), 
       
  1174                                             TPtrC(COMMDB_ID), 
       
  1175                                             aWapIap );
       
  1176 
       
  1177         User::LeaveIfError( iapt->GotoFirstRecord() );
       
  1178         HBufC* aIapServiceType = ApCommons::ReadText16ValueLC
       
  1179                                     (
       
  1180                                     iapt,
       
  1181                                     TPtrC(IAP_SERVICE_TYPE)
       
  1182                                     );
       
  1183         // decide which bearer, read bearer spec. data.
       
  1184         TUint32 aIsp;
       
  1185         ApCommons::ReadUintL( iapt, TPtrC(IAP_SERVICE), aIsp );
       
  1186 
       
  1187         // No need to be defensive, if *aIapServiceType is invalid,
       
  1188         // it shall Leave,
       
  1189         // otherwise, we will handle the difference...
       
  1190         CCommsDbTableView* ispt = iDb->OpenViewMatchingUintLC(
       
  1191                                         *aIapServiceType,
       
  1192                                         TPtrC(COMMDB_ID), aIsp );
       
  1193         User::LeaveIfError( ispt->GotoFirstRecord() );
       
  1194         TUint32 sgd;
       
  1195         if ( ( *aIapServiceType == TPtrC(DIAL_OUT_ISP) ) ||
       
  1196              ( *aIapServiceType == TPtrC(DIAL_IN_ISP) ) )
       
  1197             { // get real IspType
       
  1198             ApCommons::ReadUintL( ispt, TPtrC(ISP_TYPE), sgd );
       
  1199             }
       
  1200         else
       
  1201             {
       
  1202             // OUTGOING_WCDMA/INCOMING_WCDMA
       
  1203             // read ISP type
       
  1204             ApCommons::ReadUintL( ispt, TPtrC(GPRS_AP_TYPE), sgd );
       
  1205             }
       
  1206         retval = TCommsDbIspType( sgd );
       
  1207         CleanupStack::PopAndDestroy( ispt ); // ispt
       
  1208         CleanupStack::Pop( aIapServiceType );// aIapServiceType,
       
  1209         // cannot PopAndDestroy because it has been re-allocated !
       
  1210         delete aIapServiceType;
       
  1211         CleanupStack::PopAndDestroy( 2, bearert ); // iapt, bearert
       
  1212         }
       
  1213     else
       
  1214         {
       
  1215         User::Leave( KErrInvalidBearer );
       
  1216         }
       
  1217 
       
  1218     CleanupStack::Pop( wapBearer );    // wapBearer,
       
  1219     // cannot PopAndDestroy because it has been re-allocated !
       
  1220     delete wapBearer;
       
  1221     CleanupStack::PopAndDestroy( wapt );    // wapt
       
  1222     aIspType = retval;
       
  1223 
       
  1224     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoISPTypeL" ) ) );
       
  1225     }
       
  1226 
       
  1227 
       
  1228 // ---------------------------------------------------------
       
  1229 // CApUtils::DoNameL
       
  1230 // ---------------------------------------------------------
       
  1231 //
       
  1232 void CApUtils::DoNameL( TUint32 aUid, TDes& aName )
       
  1233     {
       
  1234     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoNameL" ) ) );
       
  1235 
       
  1236     CCommsDbTableView* wapt = iDb->OpenViewMatchingUintLC(
       
  1237                                     TPtrC(WAP_ACCESS_POINT),
       
  1238                                     TPtrC(COMMDB_ID), aUid );
       
  1239     User::LeaveIfError( wapt->GotoFirstRecord() );
       
  1240     HBufC* sgd = ApCommons::ReadText16ValueLC( wapt, TPtrC(COMMDB_NAME) );
       
  1241 
       
  1242     if ( aName.MaxLength() < sgd->Length()  )
       
  1243         {
       
  1244         User::Leave( KErrDescOverflow );
       
  1245         }
       
  1246     else
       
  1247         {
       
  1248         aName.SetLength( sgd->Length() );
       
  1249         aName.Format( KFormat, &*sgd );
       
  1250         }
       
  1251     CleanupStack::PopAndDestroy( 2, wapt );   //  sgd, wapt
       
  1252 
       
  1253     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoNameL" ) ) );
       
  1254     }
       
  1255 
       
  1256 
       
  1257 // ---------------------------------------------------------
       
  1258 // CApUtils::DoSetNameL
       
  1259 // ---------------------------------------------------------
       
  1260 //
       
  1261 void CApUtils::DoSetNameL( TDes& aName, TUint32 aUid )
       
  1262     {
       
  1263     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoSetNameL" ) ) );
       
  1264 
       
  1265     if ( iExt->iVariant & KApUiEditOnlyVPNs )
       
  1266         {
       
  1267         User::Leave( KErrNotSupported );
       
  1268         }
       
  1269 
       
  1270     CCommsDbTableView* wapt;
       
  1271 
       
  1272     wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT),
       
  1273                                        TPtrC(COMMDB_ID), aUid );
       
  1274     User::LeaveIfError( wapt->GotoFirstRecord() );
       
  1275     HBufC* aCurrent = ApCommons::ReadText16ValueLC( wapt,
       
  1276                                                      TPtrC(COMMDB_NAME) );
       
  1277     if ( *aCurrent != aName )
       
  1278         {
       
  1279         TBool aNameChanged( EFalse );
       
  1280         HBufC* namebuf = aName.AllocL();
       
  1281         CleanupStack::PushL( namebuf );
       
  1282         HBufC* sgd = ApCommons::DoMakeValidNameL
       
  1283                                         (
       
  1284                                         *iDb,
       
  1285                                         aNameChanged,
       
  1286                                         namebuf,
       
  1287                                         aUid,
       
  1288                                         EFalse
       
  1289                                         );
       
  1290         if ( aNameChanged )
       
  1291             {
       
  1292             aName.Copy( *sgd );
       
  1293             delete sgd;
       
  1294             }
       
  1295         CleanupStack::PopAndDestroy( namebuf ); // namebuf
       
  1296         User::LeaveIfError( wapt->UpdateRecord() );
       
  1297         wapt->WriteTextL( TPtrC(COMMDB_NAME), aName );
       
  1298         User::LeaveIfError( wapt->PutRecordChanges() );
       
  1299         }
       
  1300     CleanupStack::PopAndDestroy( 2, wapt );   // aCurrent,wapt
       
  1301 
       
  1302     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoSetNameL" ) ) );
       
  1303     }
       
  1304 
       
  1305 
       
  1306 // ---------------------------------------------------------
       
  1307 // CApUtils::DoSetISPTypeL
       
  1308 // ---------------------------------------------------------
       
  1309 //
       
  1310 void CApUtils::DoSetISPTypeL( TUint32 aUid, TCommsDbIspType aIspType )
       
  1311     {
       
  1312     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoSetISPTypeL" ) ) );
       
  1313 
       
  1314     if ( iExt->iVariant & KApUiEditOnlyVPNs )
       
  1315         {
       
  1316         User::Leave( KErrNotSupported );
       
  1317         }
       
  1318 
       
  1319     // first check requested ISP-type validity
       
  1320     if ( ( aIspType == EIspTypeInternetOnly ) ||
       
  1321         ( aIspType == EIspTypeWAPOnly ) ||
       
  1322         ( aIspType == EIspTypeInternetAndWAP ) )
       
  1323         {
       
  1324         CCommsDbTableView* wapt;
       
  1325         wapt = iDb->OpenViewMatchingUintLC( TPtrC(WAP_ACCESS_POINT),
       
  1326                                            TPtrC(COMMDB_ID), aUid );
       
  1327         User::LeaveIfError( wapt->GotoFirstRecord() );
       
  1328         HBufC* wapBearer = ApCommons::ReadText16ValueLC
       
  1329                                             (
       
  1330                                             wapt,
       
  1331                                             TPtrC(WAP_CURRENT_BEARER)
       
  1332                                             );
       
  1333         if ( *wapBearer == TPtrC(WAP_IP_BEARER) )
       
  1334             {
       
  1335             CCommsDbTableView* bearert;
       
  1336             bearert = iDb->OpenViewMatchingUintLC(
       
  1337                             *wapBearer,
       
  1338                             TPtrC(WAP_ACCESS_POINT_ID), aUid );
       
  1339 
       
  1340             User::LeaveIfError( bearert->GotoFirstRecord() );
       
  1341             TUint32 aWapIap;
       
  1342             ApCommons::ReadUintL( bearert, TPtrC(WAP_IAP), aWapIap );
       
  1343             // now we have IAP uid, can go for Service type, ID
       
  1344 
       
  1345             CCommsDbTableView* iapt;
       
  1346             iapt = iDb->OpenViewMatchingUintLC( TPtrC(IAP),
       
  1347                                                 TPtrC(COMMDB_ID),
       
  1348                                                 aWapIap );
       
  1349             User::LeaveIfError( iapt->GotoFirstRecord() );
       
  1350 
       
  1351             HBufC* aIapServiceType = ApCommons::ReadText16ValueLC
       
  1352                                             (
       
  1353                                             iapt,
       
  1354                                             TPtrC(IAP_SERVICE_TYPE)
       
  1355                                             );
       
  1356 
       
  1357             // get ISP ID
       
  1358             TUint32 aIsp;
       
  1359             ApCommons::ReadUintL( iapt, TPtrC(IAP_SERVICE), aIsp );
       
  1360 
       
  1361             CCommsDbTableView* ispt;
       
  1362             ispt = iDb->OpenViewMatchingUintLC( *aIapServiceType,
       
  1363                                                 TPtrC(COMMDB_ID), aIsp );
       
  1364             User::LeaveIfError( ispt->GotoFirstRecord() );
       
  1365             // now we have it, just write:
       
  1366             User::LeaveIfError( ispt->UpdateRecord() );
       
  1367             // decide which bearer, write into bearer spec. column.
       
  1368             if ( ( *aIapServiceType == TPtrC(DIAL_OUT_ISP) ) ||
       
  1369                  ( *aIapServiceType == TPtrC(DIAL_IN_ISP) ) )
       
  1370                 { // write real IspType
       
  1371                 ispt->WriteUintL( TPtrC(ISP_TYPE), aIspType );
       
  1372                 }
       
  1373             else
       
  1374                 {
       
  1375                 // OUTGOING_WCDMA / INCOMING_WCDMA
       
  1376                 ispt->WriteUintL( TPtrC(GPRS_AP_TYPE), aIspType );
       
  1377                 }
       
  1378             User::LeaveIfError( ispt->PutRecordChanges( EFalse, EFalse ) );
       
  1379             // ispt, aIapServiceType, iapt, bearert
       
  1380             CleanupStack::PopAndDestroy( 4, bearert );
       
  1381             }
       
  1382         else
       
  1383             {
       
  1384             User::Leave( KErrInvalidBearer );
       
  1385             }
       
  1386         CleanupStack::PopAndDestroy( 2, wapt );    // wapBearer, wapt
       
  1387         }
       
  1388     else
       
  1389         {
       
  1390         User::Leave( KErrInvalidIspRequest );
       
  1391         }
       
  1392 
       
  1393     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoSetISPTypeL" ) ) );
       
  1394     }
       
  1395 
       
  1396 
       
  1397 // ---------------------------------------------------------
       
  1398 // CApUtils::DoesExistsL
       
  1399 // ---------------------------------------------------------
       
  1400 //
       
  1401 TBool CApUtils::DoesExistsL( TPtrC aTable, TUint32 aUid )
       
  1402     {
       
  1403     CLOG( ( EUtil, 0, _L( "-> CApUtils::DoesExistsL" ) ) );
       
  1404     
       
  1405     TBool retval( EFalse );
       
  1406     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *iDb, ETrue );
       
  1407     CCommsDbTableView* table;
       
  1408     table = iDb->OpenViewMatchingUintLC( aTable,
       
  1409                                        TPtrC(COMMDB_ID), aUid );
       
  1410     TInt res = table->GotoFirstRecord();
       
  1411     CleanupStack::PopAndDestroy( table ); // table
       
  1412     if ( res == KErrNone )
       
  1413         {
       
  1414         retval = ETrue;
       
  1415         }
       
  1416     if ( res != KErrNotFound )
       
  1417         {
       
  1418         User::LeaveIfError( res );
       
  1419         }
       
  1420     if ( ownTransaction )
       
  1421         {
       
  1422         ApCommons::CommitTransaction( *iDb );
       
  1423         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
  1424         }
       
  1425 
       
  1426     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoesExistsL" ) ) );
       
  1427     return retval;
       
  1428     }
       
  1429 
       
  1430 
       
  1431 
       
  1432 // ---------------------------------------------------------
       
  1433 // CApUtils::DoIsWlanL
       
  1434 // ---------------------------------------------------------
       
  1435 //
       
  1436 TBool CApUtils::DoIsWlanL( TUint32 aLanCommdbId )
       
  1437     {
       
  1438     CLOG( ( EUtil, 1, _L( "-> CApUtils::DoIsWlanL" ) ) );
       
  1439     
       
  1440     TBool retval( EFalse );
       
  1441     
       
  1442     CCommsDbTableView* wlantable = NULL;
       
  1443 
       
  1444     // WLAN settings table backlinks to LAN service, 
       
  1445     // so we query WLAN settings for a record 
       
  1446     // where WLAN_SERVICE_ID is LAN_SERVICE's COMMDB_ID, 
       
  1447     // which is aApItem.iIapServiceId...
       
  1448     wlantable = iDb->OpenViewMatchingUintLC( TPtrC(WLAN_SERVICE),
       
  1449                                              TPtrC(WLAN_SERVICE_ID),
       
  1450                                              aLanCommdbId );
       
  1451                                              
       
  1452     TInt err = wlantable->GotoFirstRecord();        
       
  1453     if ( err == KErrNotFound )
       
  1454         {
       
  1455         retval = EFalse;
       
  1456         }
       
  1457     else
       
  1458         {
       
  1459         User::LeaveIfError( err );
       
  1460         retval = ETrue;
       
  1461         }
       
  1462 
       
  1463     CleanupStack::PopAndDestroy( wlantable );
       
  1464     
       
  1465     CLOG( ( EUtil, 1, _L( "<- CApUtils::DoIsWlanL" ) ) );
       
  1466     return retval;
       
  1467     }
       
  1468 
       
  1469 //  End of File